kuangshuai
5 years ago
2 changed files with 171 additions and 15 deletions
@ -0,0 +1,95 @@ |
|||||||
|
package com.fr.design.mainframe.mobile.ui; |
||||||
|
|
||||||
|
import com.fr.base.BaseUtils; |
||||||
|
import com.fr.design.constants.LayoutConstants; |
||||||
|
import com.fr.design.gui.ibutton.UIColorButton; |
||||||
|
import com.fr.design.gui.ibutton.UIToggleButton; |
||||||
|
import com.fr.design.gui.icombobox.UIComboBox; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.design.utils.gui.GUICoreUtils; |
||||||
|
import com.fr.general.FRFont; |
||||||
|
import com.fr.stable.Constants; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import java.awt.*; |
||||||
|
import java.util.Vector; |
||||||
|
|
||||||
|
public class MobileStyleFontConfigPane extends JPanel { |
||||||
|
private static final int MAX_FONT_SIZE = 18; |
||||||
|
private static final int MIN_FONT_SIZE = 12; |
||||||
|
private static final Dimension BUTTON_SIZE = new Dimension(20, 18); |
||||||
|
|
||||||
|
public static Vector<Integer> getFontSizes() { |
||||||
|
Vector<Integer> FONT_SIZES = new Vector<Integer>(); |
||||||
|
for (int i = MIN_FONT_SIZE; i <= MAX_FONT_SIZE; i++) { |
||||||
|
FONT_SIZES.add(i); |
||||||
|
} |
||||||
|
return FONT_SIZES; |
||||||
|
} |
||||||
|
|
||||||
|
private UIComboBox fontSizeComboBox; |
||||||
|
private UIToggleButton underline; |
||||||
|
private UIToggleButton italic; |
||||||
|
private UIToggleButton bold; |
||||||
|
|
||||||
|
public MobileStyleFontConfigPane() { |
||||||
|
this.initComponent(); |
||||||
|
} |
||||||
|
|
||||||
|
private void initComponent() { |
||||||
|
|
||||||
|
fontSizeComboBox = new UIComboBox(getFontSizes()); |
||||||
|
fontSizeComboBox.setSelectedItem(16); |
||||||
|
fontSizeComboBox.setPreferredSize(new Dimension(60, 20)); |
||||||
|
fontSizeComboBox.setEditable(true); |
||||||
|
underline = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/underline.png")); |
||||||
|
italic = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/italic.png")); |
||||||
|
bold = new UIToggleButton(BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/bold.png")); |
||||||
|
|
||||||
|
this.setButtonsTips(); |
||||||
|
this.setButtonsSize(BUTTON_SIZE); |
||||||
|
|
||||||
|
Component[] components_font = new Component[]{ |
||||||
|
fontSizeComboBox, underline, italic, bold |
||||||
|
}; |
||||||
|
|
||||||
|
JPanel buttonPane = new JPanel(new BorderLayout()); |
||||||
|
buttonPane.add(GUICoreUtils.createFlowPane(components_font, FlowLayout.LEFT, LayoutConstants.HGAP_LARGE)); |
||||||
|
|
||||||
|
this.setLayout(new BorderLayout(0,0)); |
||||||
|
this.add(buttonPane, BorderLayout.CENTER); |
||||||
|
} |
||||||
|
|
||||||
|
private void setButtonsTips() { |
||||||
|
underline.setToolTipText(Toolkit.i18nText("Fine-Design_Report_Underline")); |
||||||
|
italic.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Italic")); |
||||||
|
bold.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Bold")); |
||||||
|
} |
||||||
|
|
||||||
|
private void setButtonsSize(Dimension size) { |
||||||
|
underline.setPreferredSize(size); |
||||||
|
italic.setPreferredSize(size); |
||||||
|
bold.setPreferredSize(size); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public void populateBean(FRFont frFont) { |
||||||
|
fontSizeComboBox.setSelectedItem(frFont.getSize()); |
||||||
|
bold.setSelected(frFont.isBold()); |
||||||
|
italic.setSelected(frFont.isItalic()); |
||||||
|
underline.setSelected(frFont.getUnderline() != Constants.LINE_NONE); |
||||||
|
} |
||||||
|
|
||||||
|
public FRFont updateBean() { |
||||||
|
int style = Font.PLAIN; |
||||||
|
style += this.bold.isSelected() ? Font.BOLD : Font.PLAIN; |
||||||
|
style += this.italic.isSelected() ? Font.ITALIC : Font.PLAIN; |
||||||
|
return FRFont.getInstance( |
||||||
|
FRFont.DEFAULT_FONTNAME, |
||||||
|
style, |
||||||
|
Float.parseFloat(fontSizeComboBox.getSelectedItem().toString()), |
||||||
|
Color.BLACK, |
||||||
|
underline.isSelected() ? Constants.LINE_THIN : Constants.LINE_NONE |
||||||
|
); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue