richie
5 years ago
12 changed files with 976 additions and 5 deletions
@ -0,0 +1,35 @@ |
|||||||
|
package com.fanruan.api.design.ui.layout.macro; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richie |
||||||
|
* @version 10.0 |
||||||
|
* Created by richie on 2019/10/28 |
||||||
|
* 布局常数 |
||||||
|
*/ |
||||||
|
public class LayoutConstants { |
||||||
|
|
||||||
|
/** |
||||||
|
* 水平间隙 |
||||||
|
*/ |
||||||
|
public static final int HGAP_SMALL = 1; |
||||||
|
/** |
||||||
|
* 水平间隙 |
||||||
|
*/ |
||||||
|
public static final int HGAP_LARGE = 4; |
||||||
|
/** |
||||||
|
* 垂直间隙 |
||||||
|
*/ |
||||||
|
public static final int VGAP_SMALL = 4; |
||||||
|
/** |
||||||
|
* 垂直间隙 |
||||||
|
*/ |
||||||
|
public static final int VGAP_MEDIUM = 6; |
||||||
|
/** |
||||||
|
* 垂直间隙 |
||||||
|
*/ |
||||||
|
public static final int VGAP_LARGE = 10; |
||||||
|
/** |
||||||
|
* 垂直间隙 |
||||||
|
*/ |
||||||
|
public static final int VGAP_HUGER = 20; |
||||||
|
} |
@ -0,0 +1,366 @@ |
|||||||
|
package com.fanruan.api.design.work.component.container; |
||||||
|
|
||||||
|
|
||||||
|
import com.fanruan.api.design.DesignKit; |
||||||
|
import com.fanruan.api.design.macro.UIConstants; |
||||||
|
import com.fanruan.api.design.ui.component.UIColorButton; |
||||||
|
import com.fanruan.api.design.ui.component.UIComboBox; |
||||||
|
import com.fanruan.api.design.ui.component.UIToggleButton; |
||||||
|
import com.fanruan.api.design.ui.layout.TableLayoutKit; |
||||||
|
import com.fanruan.api.design.ui.layout.macro.LayoutConstants; |
||||||
|
import com.fanruan.api.design.util.GUICoreKit; |
||||||
|
import com.fanruan.api.design.work.component.LineComboBox; |
||||||
|
import com.fanruan.api.macro.LineConstants; |
||||||
|
import com.fanruan.api.util.AssistKit; |
||||||
|
import com.fanruan.api.util.GeneralKit; |
||||||
|
import com.fanruan.api.util.IOKit; |
||||||
|
import com.fanruan.api.util.MathKit; |
||||||
|
import com.fr.base.FRContext; |
||||||
|
import com.fr.base.Style; |
||||||
|
import com.fr.design.event.GlobalNameListener; |
||||||
|
import com.fr.design.event.GlobalNameObserver; |
||||||
|
import com.fr.design.gui.style.AbstractBasicStylePane; |
||||||
|
import com.fr.general.DefaultValues; |
||||||
|
import com.fr.general.FRFont; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import javax.swing.event.ChangeEvent; |
||||||
|
import javax.swing.event.ChangeListener; |
||||||
|
import java.awt.*; |
||||||
|
import java.util.Vector; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richie |
||||||
|
* @version 10.0 |
||||||
|
* Created by richie on 2019/10/28 |
||||||
|
* 用于编辑字体的面板容器 |
||||||
|
*/ |
||||||
|
public class FontPane extends AbstractBasicStylePane implements GlobalNameObserver { |
||||||
|
|
||||||
|
public static final Integer[] FONT_SIZES = { |
||||||
|
6, 8, 9, 10, 11, 12, 13, 14, 16, |
||||||
|
18, 20, 22, 24, 26, 28, 30, 32, 34, |
||||||
|
36, 38, 40, 48, 64, 72, 128 |
||||||
|
}; |
||||||
|
private static final int MAX_FONT_SIZE = 100; |
||||||
|
private static final Dimension BUTTON_SIZE = new Dimension(20, 18); |
||||||
|
private static final Dimension UNDER_LINE_SIZE = new Dimension(87, 20); |
||||||
|
private static final Dimension HIDE_SIZE = new Dimension(0, 0); |
||||||
|
private final String[] fontSizeStyles = {DesignKit.i18nText("Fine-Design_Basic_FR_Font_Plain"), DesignKit.i18nText("Fine-Design_Basic_FR_Font_Bold"), DesignKit.i18nText("Fine-Design_Basic_FR_Font_Italic"), DesignKit.i18nText("Fine-Design_Basic_FR_Font_Bolditalic")}; |
||||||
|
private JPanel buttonPane; |
||||||
|
private JPanel isSuperOrSubPane; |
||||||
|
private UIComboBox fontNameComboBox; |
||||||
|
private UIComboBox fontSizeStyleComboBox; |
||||||
|
private UIComboBox fontSizeComboBox; |
||||||
|
private UIToggleButton bold; |
||||||
|
private UIToggleButton italic; |
||||||
|
private UIToggleButton underline; |
||||||
|
private GlobalNameListener globalNameListener = null; |
||||||
|
|
||||||
|
private LineComboBox underlineCombo; |
||||||
|
private UIColorButton colorSelectPane; |
||||||
|
|
||||||
|
private UIToggleButton isStrikethroughCheckBox; |
||||||
|
private UIToggleButton isShadowCheckBox; |
||||||
|
private UIToggleButton superPane; |
||||||
|
private UIToggleButton subPane; |
||||||
|
private JPanel linePane; |
||||||
|
|
||||||
|
public FontPane() { |
||||||
|
this.initComponents(); |
||||||
|
} |
||||||
|
|
||||||
|
public static void main(String[] args) { |
||||||
|
JFrame jf = new JFrame("test"); |
||||||
|
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
||||||
|
JPanel content = (JPanel) jf.getContentPane(); |
||||||
|
content.setLayout(new BorderLayout()); |
||||||
|
content.add(new com.fr.design.gui.style.FRFontPane(), BorderLayout.CENTER); |
||||||
|
GUICoreKit.centerWindow(jf); |
||||||
|
jf.setSize(290, 400); |
||||||
|
jf.setVisible(true); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
|
return DesignKit.i18nText("Fine-Design_Report_Sytle_FRFont"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Use font to populate pane. |
||||||
|
*/ |
||||||
|
public void populateBean(FRFont frFont) { |
||||||
|
fontNameComboBox.setSelectedItem(frFont.getFamily()); |
||||||
|
fontSizeStyleComboBox.setSelectedIndex(frFont.getStyle()); |
||||||
|
fontSizeComboBox.setSelectedItem(MathKit.round5(frFont.getSize2D())); |
||||||
|
bold.setSelected(frFont.isBold()); |
||||||
|
italic.setSelected(frFont.isItalic()); |
||||||
|
|
||||||
|
this.colorSelectPane.setColor(frFont.getForeground()); |
||||||
|
this.colorSelectPane.repaint(); |
||||||
|
|
||||||
|
CardLayout cly = (CardLayout) linePane.getLayout(); |
||||||
|
int line = frFont.getUnderline(); |
||||||
|
if (line == LineConstants.LINE_NONE) { |
||||||
|
underline.setSelected(false); |
||||||
|
cly.show(linePane, "none"); |
||||||
|
linePane.setPreferredSize(HIDE_SIZE); |
||||||
|
} else { |
||||||
|
underline.setSelected(true); |
||||||
|
cly.show(linePane, "combobox"); |
||||||
|
linePane.setPreferredSize(UNDER_LINE_SIZE); |
||||||
|
this.underlineCombo.setSelectedLineStyle(line); |
||||||
|
} |
||||||
|
// effects
|
||||||
|
this.isStrikethroughCheckBox.setSelected(frFont.isStrikethrough()); |
||||||
|
this.isShadowCheckBox.setSelected(frFont.isShadow()); |
||||||
|
if (frFont.isSuperscript()) { |
||||||
|
this.superPane.setSelected(true); |
||||||
|
this.subPane.setSelected(false); |
||||||
|
} else if (frFont.isSubscript()) { |
||||||
|
this.superPane.setSelected(false); |
||||||
|
this.subPane.setSelected(true); |
||||||
|
} else { |
||||||
|
this.superPane.setSelected(false); |
||||||
|
this.subPane.setSelected(false); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Update pane to get new font. |
||||||
|
*/ |
||||||
|
public FRFont update(FRFont frFont) { |
||||||
|
|
||||||
|
if (AssistKit.equals(globalNameListener.getGlobalName(), DesignKit.i18nText("Fine-Design_Basic_Name"))) { |
||||||
|
frFont = frFont.applyName((String) fontNameComboBox.getSelectedItem()); |
||||||
|
} |
||||||
|
if (AssistKit.equals(globalNameListener.getGlobalName(), DesignKit.i18nText("Fine-Design_Basic_FR_Font_Style"))) { |
||||||
|
frFont = frFont.applyStyle(fontSizeStyleComboBox.getSelectedIndex()); |
||||||
|
} |
||||||
|
if (AssistKit.equals(globalNameListener.getGlobalName(), DesignKit.i18nText("Fine-Design_Form_FRFont_Size"))) { |
||||||
|
frFont = frFont.applySize(Float.parseFloat(fontSizeComboBox.getSelectedItem().toString())); |
||||||
|
} |
||||||
|
if (AssistKit.equals(globalNameListener.getGlobalName(), DesignKit.i18nText("Fine-Design_Basic_FR_Font_Foreground"))) { |
||||||
|
frFont = frFont.applyForeground(this.colorSelectPane.getColor()); |
||||||
|
} |
||||||
|
|
||||||
|
if (AssistKit.equals(globalNameListener.getGlobalName(), DesignKit.i18nText("Fine-Design_Basic_FR_Font_Underline"))) { |
||||||
|
|
||||||
|
int line = underline.isSelected() ? this.underlineCombo.getSelectedLineStyle() : LineConstants.LINE_NONE; |
||||||
|
frFont = frFont.applyUnderline(line); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
if (AssistKit.equals(globalNameListener.getGlobalName(), DesignKit.i18nText("Fine-Design_Form_FRFont_Line_Style"))) { |
||||||
|
frFont = frFont.applyUnderline(this.underlineCombo.getSelectedLineStyle()); |
||||||
|
} |
||||||
|
|
||||||
|
if (AssistKit.equals(globalNameListener.getGlobalName(), DesignKit.i18nText("Fine-Design_Basic_FR_Font_Strikethrough"))) { |
||||||
|
frFont = frFont.applyStrikethrough(isStrikethroughCheckBox.isSelected()); |
||||||
|
} |
||||||
|
if (AssistKit.equals(globalNameListener.getGlobalName(), DesignKit.i18nText("Fine-Design_Basic_FR_Font_Shadow"))) { |
||||||
|
frFont = frFont.applyShadow(isShadowCheckBox.isSelected()); |
||||||
|
} |
||||||
|
|
||||||
|
frFont = updateOthers(frFont); |
||||||
|
|
||||||
|
return frFont; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private FRFont updateOthers(FRFont frFont) { |
||||||
|
frFont = updateSubSuperscript(frFont); |
||||||
|
return frFont; |
||||||
|
} |
||||||
|
|
||||||
|
private FRFont updateSubSuperscript(FRFont frFont) { |
||||||
|
boolean isSuper = frFont.isSuperscript(); |
||||||
|
boolean isSub = frFont.isSubscript(); |
||||||
|
if (AssistKit.equals(globalNameListener.getGlobalName(), DesignKit.i18nText("Fine-Design_Basic_FR_Font_Superscript"))) { |
||||||
|
//如果上标没有选中,点击则选中上标,并且下标一定是不选中状态
|
||||||
|
//如果上标选中,点击则取消选中上标,字体回复正常
|
||||||
|
if (superPane.isSelected() && !isSuper) { |
||||||
|
frFont = frFont.applySuperscript(true); |
||||||
|
frFont = frFont.applySubscript(false); |
||||||
|
this.subPane.setSelected(false); |
||||||
|
} else if (!superPane.isSelected() && isSuper) { |
||||||
|
frFont = frFont.applySuperscript(false); |
||||||
|
} |
||||||
|
} |
||||||
|
if (AssistKit.equals(globalNameListener.getGlobalName(), DesignKit.i18nText("Fine-Design_Basic_FR_Font_Subscript"))) { |
||||||
|
if (subPane.isSelected() && !isSub) { |
||||||
|
frFont = frFont.applySubscript(true); |
||||||
|
frFont = frFont.applySuperscript(false); |
||||||
|
this.superPane.setSelected(false); |
||||||
|
} else if (!subPane.isSelected() && isSub) { |
||||||
|
frFont = frFont.applySubscript(false); |
||||||
|
} |
||||||
|
} |
||||||
|
return frFont; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void populateBean(Style style) { |
||||||
|
this.populateBean(style.getFRFont()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Style update(Style style) { |
||||||
|
FRFont frFont = style.getFRFont(); |
||||||
|
frFont = this.update(frFont); |
||||||
|
return style.deriveFRFont(frFont); |
||||||
|
} |
||||||
|
|
||||||
|
public static Vector<Integer> getFontSizes() { |
||||||
|
Vector<Integer> FONT_SIZES = new Vector<Integer>(); |
||||||
|
for (int i = 1; i < MAX_FONT_SIZE; i++) { |
||||||
|
FONT_SIZES.add(i); |
||||||
|
} |
||||||
|
return FONT_SIZES; |
||||||
|
} |
||||||
|
|
||||||
|
protected void initComponents() { |
||||||
|
fontSizeStyleComboBox = new UIComboBox<>(fontSizeStyles); |
||||||
|
fontNameComboBox = new UIComboBox<>(GeneralKit.getAvailableFontFamilyNames()); |
||||||
|
fontNameComboBox.setPreferredSize(new Dimension(144, 20)); |
||||||
|
fontSizeComboBox = new UIComboBox<>(getFontSizes()); |
||||||
|
fontSizeComboBox.setEditable(true); |
||||||
|
this.underlineCombo = new LineComboBox(UIConstants.BORDER_LINE_STYLE_ARRAY); |
||||||
|
colorSelectPane = new UIColorButton(); |
||||||
|
bold = new UIToggleButton(IOKit.readIcon("/com/fr/design/images/m_format/cellstyle/bold.png")); |
||||||
|
italic = new UIToggleButton(IOKit.readIcon("/com/fr/design/images/m_format/cellstyle/italic.png")); |
||||||
|
underline = new UIToggleButton(IOKit.readIcon("/com/fr/design/images/m_format/cellstyle/underline.png")); |
||||||
|
bold.setPreferredSize(BUTTON_SIZE); |
||||||
|
italic.setPreferredSize(BUTTON_SIZE); |
||||||
|
underline.setPreferredSize(BUTTON_SIZE); |
||||||
|
isStrikethroughCheckBox = new UIToggleButton(IOKit.readIcon("/com/fr/design/images/m_format/cellstyle/strikethrough.png")); |
||||||
|
isStrikethroughCheckBox.setPreferredSize(BUTTON_SIZE); |
||||||
|
isShadowCheckBox = new UIToggleButton(IOKit.readIcon("/com/fr/design/images/m_format/cellstyle/shadow.png")); |
||||||
|
isShadowCheckBox.setPreferredSize(BUTTON_SIZE); |
||||||
|
superPane = new UIToggleButton(IOKit.readIcon("/com/fr/design/images/m_format/cellstyle/sup.png")); |
||||||
|
superPane.setPreferredSize(BUTTON_SIZE); |
||||||
|
subPane = new UIToggleButton(IOKit.readIcon("/com/fr/design/images/m_format/cellstyle/sub.png")); |
||||||
|
subPane.setPreferredSize(BUTTON_SIZE); |
||||||
|
Component[] SuperOrSubComponents = new Component[]{ |
||||||
|
superPane, subPane |
||||||
|
}; |
||||||
|
isSuperOrSubPane = new JPanel(new BorderLayout()); |
||||||
|
isSuperOrSubPane.add(GUICoreKit.createFlowPane(SuperOrSubComponents, FlowLayout.LEFT, LayoutConstants.HGAP_SMALL)); |
||||||
|
Component[] components_font = new Component[]{ |
||||||
|
colorSelectPane, underline, isStrikethroughCheckBox, isShadowCheckBox |
||||||
|
}; |
||||||
|
buttonPane = new JPanel(new BorderLayout()); |
||||||
|
buttonPane.add(GUICoreKit.createFlowPane(components_font, FlowLayout.LEFT, LayoutConstants.HGAP_SMALL)); |
||||||
|
linePane = new JPanel(new CardLayout()); |
||||||
|
initAllNames(); |
||||||
|
setToolTips(); |
||||||
|
this.setLayout(new BorderLayout()); |
||||||
|
this.add(createPane(), BorderLayout.CENTER); |
||||||
|
DefaultValues defaultValues = FRContext.getDefaultValues(); |
||||||
|
populateBean(defaultValues.getFRFont()); |
||||||
|
} |
||||||
|
|
||||||
|
private void initAllNames() { |
||||||
|
fontSizeStyleComboBox.setGlobalName(DesignKit.i18nText("Fine-Design_Basic_FR_Font_Style")); |
||||||
|
fontNameComboBox.setGlobalName(DesignKit.i18nText("Fine-Design_Basic_Name")); |
||||||
|
fontSizeComboBox.setGlobalName(DesignKit.i18nText("Fine-Design_Form_FRFont_Size")); |
||||||
|
colorSelectPane.setGlobalName(DesignKit.i18nText("Fine-Design_Basic_FR_Font_Foreground")); |
||||||
|
italic.setGlobalName(DesignKit.i18nText("Fine-Design_Basic_FR_Font_Italic")); |
||||||
|
bold.setGlobalName(DesignKit.i18nText("Fine-Design_Basic_FR_Font_Bold")); |
||||||
|
underline.setGlobalName(DesignKit.i18nText("Fine-Design_Basic_FR_Font_Underline")); |
||||||
|
underlineCombo.setGlobalName(DesignKit.i18nText("Fine-Design_Form_FRFont_Line_Style")); |
||||||
|
isStrikethroughCheckBox.setGlobalName(DesignKit.i18nText("Fine-Design_Basic_FR_Font_Strikethrough")); |
||||||
|
isShadowCheckBox.setGlobalName(DesignKit.i18nText("Fine-Design_Basic_FR_Font_Shadow")); |
||||||
|
superPane.setGlobalName(DesignKit.i18nText("Fine-Design_Basic_FR_Font_Superscript")); |
||||||
|
subPane.setGlobalName(DesignKit.i18nText("Fine-Design_Basic_FR_Font_Subscript")); |
||||||
|
} |
||||||
|
|
||||||
|
private void setToolTips() { |
||||||
|
colorSelectPane.setToolTipText(DesignKit.i18nText("Fine-Design_Basic_FR_Font_Foreground")); |
||||||
|
italic.setToolTipText(DesignKit.i18nText("Fine-Design_Basic_FR_Font_Italic")); |
||||||
|
bold.setToolTipText(DesignKit.i18nText("Fine-Design_Basic_FR_Font_Bold")); |
||||||
|
underline.setToolTipText(DesignKit.i18nText("Fine-Design_Basic_FR_Font_Underline")); |
||||||
|
isStrikethroughCheckBox.setToolTipText(DesignKit.i18nText("Fine-Design_Basic_FR_Font_Strikethrough")); |
||||||
|
isShadowCheckBox.setToolTipText(DesignKit.i18nText("Fine-Design_Basic_FR_Font_Shadow")); |
||||||
|
superPane.setToolTipText(DesignKit.i18nText("Fine-Design_Basic_FR_Font_Superscript")); |
||||||
|
subPane.setToolTipText(DesignKit.i18nText("Fine-Design_Basic_FR_Font_Subscript")); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
private JPanel createLinePane() { |
||||||
|
linePane.add(new JPanel(), "none"); |
||||||
|
JPanel gap = new JPanel(new GridLayout(0, 1)); |
||||||
|
gap.add(underlineCombo); |
||||||
|
linePane.add(gap, "combobox"); |
||||||
|
underline.addChangeListener(new ChangeListener() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public void stateChanged(ChangeEvent e) { |
||||||
|
CardLayout cly = (CardLayout) linePane.getLayout(); |
||||||
|
cly.show(linePane, underline.isSelected() ? "combobox" : "none"); |
||||||
|
if (underline.isSelected()) { |
||||||
|
linePane.setPreferredSize(UNDER_LINE_SIZE); |
||||||
|
} else { |
||||||
|
linePane.setPreferredSize(HIDE_SIZE); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
return linePane; |
||||||
|
} |
||||||
|
|
||||||
|
private JPanel createLeftPane() { |
||||||
|
double p = TableLayoutKit.PREFERRED; |
||||||
|
double f = TableLayoutKit.FILL; |
||||||
|
double[] columnSize = {p}; |
||||||
|
double[] rowSize = {p, p, p}; |
||||||
|
int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}}; |
||||||
|
Component[][] components = new Component[][]{ |
||||||
|
new Component[]{fontSizeStyleComboBox}, |
||||||
|
new Component[]{buttonPane}, |
||||||
|
new Component[]{createLinePane()} |
||||||
|
}; |
||||||
|
return TableLayoutKit.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); |
||||||
|
} |
||||||
|
|
||||||
|
protected JPanel createRightPane() { |
||||||
|
double p = TableLayoutKit.PREFERRED; |
||||||
|
double f = TableLayoutKit.FILL; |
||||||
|
double[] columnSize = {f}; |
||||||
|
double[] rowSize = {p, p}; |
||||||
|
int[][] rowCount = {{1, 1}, {1, 1}}; |
||||||
|
Component[][] components = new Component[][]{ |
||||||
|
new Component[]{fontSizeComboBox}, |
||||||
|
new Component[]{isSuperOrSubPane} |
||||||
|
}; |
||||||
|
return TableLayoutKit.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_MEDIUM); |
||||||
|
} |
||||||
|
|
||||||
|
private JPanel createPane() { |
||||||
|
JPanel createPane = new JPanel(new BorderLayout()); |
||||||
|
createPane.add(fontNameComboBox, BorderLayout.NORTH); |
||||||
|
JPanel jPanel = TableLayoutKit.createGapTableLayoutPane( |
||||||
|
new Component[][]{new Component[]{createLeftPane(), createRightPane()}}, |
||||||
|
TableLayoutKit.FILL_LAST_COLUMN, |
||||||
|
LayoutConstants.VGAP_LARGE, |
||||||
|
LayoutConstants.VGAP_LARGE); |
||||||
|
jPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); |
||||||
|
createPane.add(jPanel, BorderLayout.CENTER); |
||||||
|
return createPane; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param listener 观察者监听事件 |
||||||
|
*/ |
||||||
|
public void registerNameListener(GlobalNameListener listener) { |
||||||
|
globalNameListener = listener; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean shouldResponseNameListener() { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
public void setGlobalName(String name) { |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,141 @@ |
|||||||
|
package com.fanruan.api.design.work.component.container; |
||||||
|
|
||||||
|
import com.fanruan.api.design.DesignKit; |
||||||
|
import com.fanruan.api.design.ui.component.UISpinner; |
||||||
|
import com.fanruan.api.util.StringKit; |
||||||
|
import com.fr.design.beans.BasicBeanPane; |
||||||
|
import com.fr.design.event.GlobalNameListener; |
||||||
|
import com.fr.design.event.GlobalNameObserver; |
||||||
|
import com.fr.design.gui.style.NumberDragBar; |
||||||
|
|
||||||
|
import javax.swing.event.ChangeEvent; |
||||||
|
import javax.swing.event.ChangeListener; |
||||||
|
import java.awt.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richie |
||||||
|
* @version 10.0 |
||||||
|
* Created by richie on 2019/10/28 |
||||||
|
* 可以通过拖动滑动条的方式设置数字的控件 |
||||||
|
*/ |
||||||
|
public class NumberDragPane extends BasicBeanPane<Double> implements GlobalNameObserver { |
||||||
|
private static final long serialVersionUID = -8681716725163358247L; |
||||||
|
private NumberDragBar dragBar; |
||||||
|
private UISpinner spinner; |
||||||
|
private boolean isEditing = false; |
||||||
|
private String numberDragPaneName = StringKit.EMPTY; |
||||||
|
private GlobalNameListener globalNameListener = null; |
||||||
|
|
||||||
|
public NumberDragPane(double minValue, double maxValue) { |
||||||
|
this(minValue, maxValue, 1); |
||||||
|
} |
||||||
|
|
||||||
|
public NumberDragPane(double minValue, double maxValue, double delta) { |
||||||
|
dragBar = new NumberDragBar((int) minValue, (int) maxValue); |
||||||
|
spinner = new UISpinner(minValue, maxValue, delta, minValue); |
||||||
|
spinner.setGlobalName(DesignKit.i18nText("Fine-Design_Basic_StyleAlignment_Text_Rotation")); |
||||||
|
this.setLayout(new BorderLayout(4, 0)); |
||||||
|
this.add(spinner, BorderLayout.EAST); |
||||||
|
this.add(dragBar, BorderLayout.CENTER); |
||||||
|
dragBar.addChangeListener(new ChangeListener() { |
||||||
|
@Override |
||||||
|
public void stateChanged(ChangeEvent e) { |
||||||
|
if (globalNameListener != null && shouldResponseNameListener()) { |
||||||
|
globalNameListener.setGlobalName(numberDragPaneName); |
||||||
|
} |
||||||
|
spinner.setValue(dragBar.getValue()); |
||||||
|
if (isEditing) { |
||||||
|
userEvent(updateBean()); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
spinner.addChangeListener(new ChangeListener() { |
||||||
|
@Override |
||||||
|
public void stateChanged(ChangeEvent e) { |
||||||
|
if (globalNameListener != null && shouldResponseNameListener()) { |
||||||
|
globalNameListener.setGlobalName(numberDragPaneName); |
||||||
|
} |
||||||
|
dragBar.setValue((int) spinner.getValue()); |
||||||
|
if (isEditing) { |
||||||
|
userEvent(updateBean()); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
public void userEvent(double value) { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 添加事件 |
||||||
|
* |
||||||
|
* @param l 事件 |
||||||
|
*/ |
||||||
|
public void addChangeListener(ChangeListener l) { |
||||||
|
spinner.addChangeListener(l); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 移除事件 |
||||||
|
* |
||||||
|
* @param l 事件 |
||||||
|
*/ |
||||||
|
public void removeChangeListener(ChangeListener l) { |
||||||
|
spinner.removeChangeListener(l); |
||||||
|
} |
||||||
|
|
||||||
|
public void setGlobalName(String name) { |
||||||
|
numberDragPaneName = name; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void populateBean(Double ob) { |
||||||
|
isEditing = false; |
||||||
|
dragBar.setValue(ob.intValue()); |
||||||
|
spinner.setValue(ob); |
||||||
|
isEditing = true; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Dimension getPreferredSize() { |
||||||
|
Dimension dim = new Dimension(); |
||||||
|
dim.width = super.getPreferredSize().width; |
||||||
|
dim.height = super.getPreferredSize().height + 2; |
||||||
|
return dim; |
||||||
|
} |
||||||
|
|
||||||
|
public void setEnabled(boolean enabled) { |
||||||
|
dragBar.setEnabled(enabled); |
||||||
|
spinner.setEnabled(enabled); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Double updateBean() { |
||||||
|
return spinner.getValue(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 注册 |
||||||
|
* |
||||||
|
* @param listener 观察者监听事件 |
||||||
|
*/ |
||||||
|
public void registerNameListener(GlobalNameListener listener) { |
||||||
|
globalNameListener = listener; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 是否应该响应 |
||||||
|
* |
||||||
|
* @return 是否应该响应 |
||||||
|
*/ |
||||||
|
public boolean shouldResponseNameListener() { |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,43 @@ |
|||||||
|
package com.fanruan.api.report.form; |
||||||
|
|
||||||
|
import com.fr.form.ui.LayoutBorderStyle; |
||||||
|
import com.fr.form.ui.WidgetTitle; |
||||||
|
import com.fr.general.act.BorderPacker; |
||||||
|
import com.fr.general.act.TitlePacker; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richie |
||||||
|
* @version 10.0 |
||||||
|
* Created by richie on 2019/10/28 |
||||||
|
* 控件相关工具类 |
||||||
|
*/ |
||||||
|
public class WidgetKit { |
||||||
|
|
||||||
|
/** |
||||||
|
* 创建一个空的控件标题对象 |
||||||
|
* |
||||||
|
* @return 控件标题 |
||||||
|
*/ |
||||||
|
public static TitlePacker newWidgetTitle() { |
||||||
|
return new WidgetTitle(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据指定的名字创建一个控件标题对象 |
||||||
|
* |
||||||
|
* @param title 标题内容 |
||||||
|
* @return 控件标题 |
||||||
|
*/ |
||||||
|
public static TitlePacker newWidgetTitle(String title) { |
||||||
|
return new WidgetTitle(title); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 创建一个空的边框样式对象 |
||||||
|
* |
||||||
|
* @return 边框样式 |
||||||
|
*/ |
||||||
|
public static BorderPacker newLayoutBorderStyle() { |
||||||
|
return new LayoutBorderStyle(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,19 @@ |
|||||||
|
package com.fanruan.api.util; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author richie |
||||||
|
* @version 10.0 |
||||||
|
* Created by richie on 2019/10/28 |
||||||
|
* 数学计算相关的工具类 |
||||||
|
*/ |
||||||
|
public class MathKit { |
||||||
|
|
||||||
|
/** |
||||||
|
* 四舍五入取靠近如11、11.5、12的值 |
||||||
|
* |
||||||
|
* @param number 值 |
||||||
|
*/ |
||||||
|
public static float round5(float number) { |
||||||
|
return (float) (Math.round(number * 2)) / 2; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue