@ -3,34 +3,31 @@
* /
* /
package com.fr.design.style ;
package com.fr.design.style ;
import com.fine.theme.utils.FineUIScale ;
import com.fr.base.FRContext ;
import com.fr.base.FRContext ;
import com.fr.design.dialog.BasicPane ;
import com.fr.design.dialog.BasicPane ;
import com.fr.design.gui.icheckbox.UICheckBox ;
import com.fr.design.gui.icheckbox.UICheckBox ;
import com.fr.design.gui.icombobox.LineComboBox ;
import com.fr.design.gui.icombobox.LineComboBox ;
import com.fr.design.gui.icombobox.UIComboBox ;
import com.fr.design.gui.ilable.UILabel ;
import com.fr.design.gui.ilable.UILabel ;
import com.fr.design.gui.itextfield.UITextField ;
import com.fr.design.gui.itextfield.UITextField ;
import com.fr.design.layout.FRGUIPaneFactory ;
import com.fr.design.layout.FRGUIPaneFactory ;
import com.fr.design.style.color.ColorSelectBox ;
import com.fr.design.style.color.ColorSelectBox ;
import com.fr.design.utils.gui.GUICore Utils ;
import com.fr.design.utils.Design Utils ;
import com.fr.general.DefaultValues ;
import com.fr.general.DefaultValues ;
import com.fr.general.FRFont ;
import com.fr.general.FRFont ;
import com.fr.stable.CoreConstants ;
import com.fr.stable.CoreConstants ;
import javax.swing.BorderFactory ;
import javax.swing.BorderFactory ;
import javax.swing.Box ;
import javax.swing.Box ;
import javax.swing.JComponent ;
import javax.swing.JList ;
import javax.swing.JList ;
import javax.swing.JPanel ;
import javax.swing.JPanel ;
import javax.swing.JScrollPane ;
import javax.swing.JScrollPane ;
import javax.swing.event.ChangeEvent ;
import javax.swing.event.ChangeEvent ;
import javax.swing.event.ChangeListener ;
import javax.swing.event.ChangeListener ;
import javax.swing.event.DocumentEvent ;
import javax.swing.event.DocumentListener ;
import javax.swing.event.EventListenerList ;
import javax.swing.event.EventListenerList ;
import javax.swing.event.ListSelectionEvent ;
import javax.swing.event.ListSelectionListener ;
import java.awt.BorderLayout ;
import java.awt.Component ;
import java.awt.Component ;
import java.awt.Dimension ;
import java.awt.GridBagConstraints ;
import java.awt.GridBagConstraints ;
import java.awt.GridBagLayout ;
import java.awt.GridBagLayout ;
import java.awt.event.ActionEvent ;
import java.awt.event.ActionEvent ;
@ -38,17 +35,24 @@ import java.awt.event.ActionListener;
import java.awt.event.ItemEvent ;
import java.awt.event.ItemEvent ;
import java.awt.event.ItemListener ;
import java.awt.event.ItemListener ;
import static com.fine.swing.ui.layout.Layouts.cell ;
import static com.fine.swing.ui.layout.Layouts.column ;
import static com.fine.swing.ui.layout.Layouts.fix ;
import static com.fine.swing.ui.layout.Layouts.flex ;
import static com.fine.swing.ui.layout.Layouts.row ;
/ * *
/ * *
* Pane to edit Font .
* Pane to edit Font .
* /
* /
public class FRFontPane extends BasicPane {
public class FRFontPane extends BasicPane {
private FontFamilyPane familyPane ;
private FontSizeStylePane fontSizeStylePane ;
private FontSizeStylePane fontSizeStylePane ;
//foreground.
//foreground.
private ColorSelectBox foregroundColorPane ;
private ColorSelectBox foregroundColorPane ;
private UIComboBox fontNameComboBox ;
//underline
//underline
private LineComboBox underlineCombo ;
private LineComboBox underlineCombo ;
@ -77,87 +81,36 @@ public class FRFontPane extends BasicPane {
this . setLayout ( FRGUIPaneFactory . createBorderLayout ( ) ) ;
this . setLayout ( FRGUIPaneFactory . createBorderLayout ( ) ) ;
this . setBorder ( BorderFactory . createEmptyBorder ( 4 , 4 , 4 , 4 ) ) ;
this . setBorder ( BorderFactory . createEmptyBorder ( 4 , 4 , 4 , 4 ) ) ;
// 纵向布局 放置list 和 下划线 颜色
JPanel listVPane = FRGUIPaneFactory . createY_AXISBoxInnerContainer_S_Pane ( ) ;
this . add ( listVPane , BorderLayout . NORTH ) ;
JPanel listHPane = FRGUIPaneFactory . createNColumnGridInnerContainer_S_Pane ( 2 ) ;
listVPane . add ( listHPane ) ;
// 名字
// 名字
familyPan e = new FontFamilyPane ( ) ;
fontNameComboBox = new UIComboBox ( DesignUtils . getAvailableFontFamilyNames4Report ( ) ) ;
listHPane . add ( familyPane ) ;
this . fontNameComboBox . addActionListener ( actionListener ) ;
// 字形和大小
// 字形和大小
fontSizeStylePane = new FontSizeStylePane ( ) ;
fontSizeStylePane = new FontSizeStylePane ( ) ;
listHPane . add ( fontSizeStylePane ) ;
fontSizeStylePane . getStyleList ( ) . addListSelectionListener ( listSelectionListener ) ;
//Richie:直接输入FRFont的size.
fontSizeStylePane . getSizeField ( ) . getDocument ( ) . addDocumentListener ( documentListener ) ;
fontSizeStylePane . getSizeField ( ) . getDocument ( ) . addDocumentListener ( new DocumentListener ( ) {
public void changedUpdate ( DocumentEvent e ) { // 这是更改操作的处理
updatePreviewLabel ( ) ;
}
public void insertUpdate ( DocumentEvent e ) { // 这是插入操作的处理
updatePreviewLabel ( ) ;
}
public void removeUpdate ( DocumentEvent e ) { // 这是删除操作的处理
updatePreviewLabel ( ) ;
}
} ) ;
fontSizeStylePane . getSizeList ( ) . addListSelectionListener ( listSelectionListener ) ;
// 下划线 和 颜色
// 下划线 和 颜色
JPanel listVBottomPane = FRGUIPaneFactory . createNColumnGridInnerContainer_S_Pane ( 2 ) ;
listVPane . add ( listVBottomPane ) ;
// underline pane
JPanel underlinePane = FRGUIPaneFactory . createBorderLayout_S_Pane ( ) ;
listVBottomPane . add ( underlinePane ) ;
underlinePane . setBorder ( GUICoreUtils . createTitledBorder ( com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_FRFont_Underline" ) , null ) ) ;
this . underlineCombo = new LineComboBox ( CoreConstants . UNDERLINE_STYLE_ARRAY ) ;
this . underlineCombo = new LineComboBox ( CoreConstants . UNDERLINE_STYLE_ARRAY ) ;
this . underlineCombo . addActionListener ( actionListener ) ;
this . underlineCombo . addActionListener ( actionListener ) ;
underlinePane . add ( this . underlineCombo , BorderLayout . CENTER ) ;
// foreground
JPanel foregroundPane = FRGUIPaneFactory . createBorderLayout_S_Pane ( ) ;
listVBottomPane . add ( foregroundPane ) ;
foregroundPane . setBorder ( GUICoreUtils . createTitledBorder ( com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Font_Foreground" ) , null ) ) ;
foregroundColorPane = new ColorSelectBox ( 140 ) ;
foregroundColorPane = new ColorSelectBox ( 140 ) ;
foregroundColorPane . addSelectChangeListener ( new ChangeListener ( ) {
foregroundColorPane . addSelectChangeListener ( new ChangeListener ( ) {
public void stateChanged ( ChangeEvent e ) {
public void stateChanged ( ChangeEvent e ) {
fireStateChanged ( ) ;
fireStateChanged ( ) ;
}
}
} ) ;
} ) ;
foregroundPane . add ( foregroundColorPane , BorderLayout . WEST ) ;
// center pane
JPanel centerPane = FRGUIPaneFactory . createBorderLayout_S_Pane ( ) ;
this . add ( centerPane , BorderLayout . CENTER ) ;
centerPane . setLayout ( FRGUIPaneFactory . createM_BorderLayout ( ) ) ;
// other reportFont dialog
initCheckbox ( ) ;
JPanel otherFontPane = FRGUIPaneFactory . createBorderLayout_S_Pane ( ) ;
// preview pane.
centerPane . add ( otherFontPane , BorderLayout . WEST ) ;
preview = new FRFontPreviewArea ( ) ;
// otherFontPane.setLayout(FRGUIPaneFactory.createBorderLayout());
preview . setPreferredSize ( FineUIScale . scale ( new Dimension ( 640 , 240 ) ) ) ;
// effects pane
//peteter:这里主动从Context, 获得默认的FRFont的值.
JPanel effectsPane = FRGUIPaneFactory . createBorderLayout_S_Pane ( ) ;
DefaultValues defaultValues = FRContext . getDefaultValues ( ) ;
otherFontPane . add ( effectsPane , BorderLayout . CENTER ) ;
populate ( defaultValues . getFRFont ( ) ) ;
// effectsPane.setLayout(FRGUIPaneFactory.createBorderLayout());
effectsPane . setBorder ( GUICoreUtils . createTitledBorder ( com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Font_Effects" ) , null ) ) ;
JPanel effectsPane2 = FRGUIPaneFactory . createNColumnGridInnerContainer_S_Pane ( 1 ) ;
addCenterPanel ( ) ;
effectsPane . add ( effectsPane2 , BorderLayout . NORTH ) ;
}
private void initCheckbox ( ) {
isStrikethroughCheckBox = new UICheckBox ( com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Font_Strikethrough" ) + " " ) ;
isStrikethroughCheckBox = new UICheckBox ( com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Font_Strikethrough" ) + " " ) ;
isStrikethroughCheckBox . addChangeListener ( changeListener ) ;
isStrikethroughCheckBox . addChangeListener ( changeListener ) ;
isStrikethroughCheckBox . setMnemonic ( 'K' ) ;
isStrikethroughCheckBox . setMnemonic ( 'K' ) ;
@ -170,23 +123,6 @@ public class FRFontPane extends BasicPane {
isSubscriptCheckBox = new UICheckBox ( com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Font_Subscript" ) ) ;
isSubscriptCheckBox = new UICheckBox ( com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Font_Subscript" ) ) ;
isSubscriptCheckBox . addChangeListener ( changeListener ) ;
isSubscriptCheckBox . addChangeListener ( changeListener ) ;
isSubscriptCheckBox . setMnemonic ( 'B' ) ;
isSubscriptCheckBox . setMnemonic ( 'B' ) ;
effectsPane2 . add ( this . getLeftJustPane ( isStrikethroughCheckBox ) ) ;
effectsPane2 . add ( this . getLeftJustPane ( isShadowCheckBox ) ) ;
effectsPane2 . add ( this . getLeftJustPane ( isSuperscriptCheckBox ) ) ;
effectsPane2 . add ( this . getLeftJustPane ( isSubscriptCheckBox ) ) ;
// right pane
JPanel rightPane = FRGUIPaneFactory . createBorderLayout_S_Pane ( ) ;
centerPane . add ( rightPane , BorderLayout . CENTER ) ;
// rightPane.setLayout(FRGUIPaneFactory.createBorderLayout());
// preview pane.
preview = new FRFontPreviewArea ( ) ;
preview . setBorder ( BorderFactory . createTitledBorder ( com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Preview" ) ) ) ;
rightPane . add ( preview , BorderLayout . CENTER ) ;
// Cannot select superscript and subscript in the same time.
// Cannot select superscript and subscript in the same time.
this . isSuperscriptCheckBox . addChangeListener ( changeListener ) ;
this . isSuperscriptCheckBox . addChangeListener ( changeListener ) ;
this . isSuperscriptCheckBox . addChangeListener ( new ChangeListener ( ) {
this . isSuperscriptCheckBox . addChangeListener ( new ChangeListener ( ) {
@ -204,10 +140,34 @@ public class FRFontPane extends BasicPane {
}
}
}
}
} ) ;
} ) ;
}
//peteter:这里主动从Context, 获得默认的FRFont的值.
private void addCenterPanel ( ) {
DefaultValues defaultValues = FRContext . getDefaultValues ( ) ;
add ( column ( 10 ,
populate ( defaultValues . getFRFont ( ) ) ;
row ( cell ( new UILabel ( com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_FRFont_Family" ) ) ) . weight ( 0 . 1 ) ,
cell ( fontNameComboBox ) . weight ( 0 . 2 ) ,
flex ( 0 . 4 )
) ,
row ( cell ( new UILabel ( com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Style_Font_Size" ) ) ) . weight ( 0 . 1 ) ,
cell ( fontSizeStylePane . fontComboBox ) . weight ( 0 . 25 ) ,
fix ( 5 ) ,
cell ( fontSizeStylePane . fontSizeComboBox ) . weight ( 0 . 2 ) ,
flex ( 0 . 15 )
) ,
row ( cell ( new UILabel ( com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_FRFont_Underline" ) ) ) . weight ( 0 . 1 ) ,
cell ( underlineCombo ) . weight ( 0 . 2 ) ,
flex ( 0 . 4 )
) ,
row ( cell ( new UILabel ( com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Font_Foreground" ) ) ) . weight ( 0 . 1 ) ,
cell ( foregroundColorPane ) . weight ( 0 . 2 ) ,
flex ( 0 . 4 )
) ,
row ( cell ( new UILabel ( com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Font_Effects" ) ) ) . weight ( 0 . 1 ) ,
row ( cell ( this . isStrikethroughCheckBox ) , fix ( 5 ) , cell ( this . isShadowCheckBox ) , fix ( 5 ) ,
cell ( this . isSuperscriptCheckBox ) , fix ( 5 ) , cell ( this . isSubscriptCheckBox ) , flex ( ) ) . weight ( 0 . 6 )
) ,
column ( 5 , cell ( new UILabel ( com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Preview" ) ) ) , cell ( preview ) )
) . getComponent ( ) ) ;
}
}
public void addChangeListener ( ChangeListener changeListener ) {
public void addChangeListener ( ChangeListener changeListener ) {
@ -242,37 +202,6 @@ public class FRFontPane extends BasicPane {
}
}
} ;
} ;
ListSelectionListener listSelectionListener = new ListSelectionListener ( ) {
public void valueChanged ( ListSelectionEvent e ) {
fireStateChanged ( ) ;
}
} ;
DocumentListener documentListener = new DocumentListener ( ) {
public void changedUpdate ( DocumentEvent e ) {
fireStateChanged ( ) ;
}
public void insertUpdate ( DocumentEvent e ) {
fireStateChanged ( ) ;
}
public void removeUpdate ( DocumentEvent e ) {
fireStateChanged ( ) ;
}
} ;
//use the method to make all checkbox donot margin == 0.
private JPanel getLeftJustPane ( JComponent comp ) {
JPanel leftJustPane = FRGUIPaneFactory . createBorderLayout_S_Pane ( ) ;
// leftJustPane.setLayout(FRGUIPaneFactory.createBorderLayout());
leftJustPane . add ( comp , BorderLayout . CENTER ) ;
leftJustPane . setBorder ( BorderFactory . createEmptyBorder ( 0 , 4 , 0 , 0 ) ) ;
return leftJustPane ;
}
@Override
@Override
protected String title4PopupWindow ( ) {
protected String title4PopupWindow ( ) {
return com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Sytle_FRFont" ) ;
return com . fr . design . i18n . Toolkit . i18nText ( "Fine-Design_Basic_Sytle_FRFont" ) ;
@ -282,9 +211,24 @@ public class FRFontPane extends BasicPane {
* Use font to populate pane .
* Use font to populate pane .
* /
* /
public void populate ( FRFont frFont ) {
public void populate ( FRFont frFont ) {
familyPane . populate ( frFont ) ;
fontSizeStylePane . populate ( frFont ) ;
this . fontNameComboBox . addItemListener ( new ItemListener ( ) {
public void itemStateChanged ( ItemEvent e ) {
updatePreviewLabel ( ) ;
}
} ) ;
this . fontSizeStylePane . fontComboBox . addItemListener ( new ItemListener ( ) {
public void itemStateChanged ( ItemEvent e ) {
updatePreviewLabel ( ) ;
}
} ) ;
this . fontSizeStylePane . fontSizeComboBox . addItemListener ( new ItemListener ( ) {
public void itemStateChanged ( ItemEvent e ) {
updatePreviewLabel ( ) ;
}
} ) ;
//foreground.
//foreground.
this . foregroundColorPane . setSelectObject ( frFont . getForeground ( ) ) ;
this . foregroundColorPane . setSelectObject ( frFont . getForeground ( ) ) ;
@ -297,12 +241,6 @@ public class FRFontPane extends BasicPane {
this . isSuperscriptCheckBox . setSelected ( frFont . isSuperscript ( ) ) ;
this . isSuperscriptCheckBox . setSelected ( frFont . isSuperscript ( ) ) ;
this . isSubscriptCheckBox . setSelected ( frFont . isSubscript ( ) ) ;
this . isSubscriptCheckBox . setSelected ( frFont . isSubscript ( ) ) ;
//添加ListHandler.
ListHandler listHandler = new ListHandler ( ) ;
familyPane . addListSelectionListener ( listHandler ) ;
fontSizeStylePane . getStyleList ( ) . addListSelectionListener ( listHandler ) ;
fontSizeStylePane . getSizeList ( ) . addListSelectionListener ( listHandler ) ;
//actionlistner
//actionlistner
ActionListener updatePreviewActionListener = new ActionListener ( ) {
ActionListener updatePreviewActionListener = new ActionListener ( ) {
@ -336,13 +274,13 @@ public class FRFontPane extends BasicPane {
* Update pane to get new font .
* Update pane to get new font .
* /
* /
public FRFont update ( ) {
public FRFont update ( ) {
double fs = fontSizeStylePane . getSizeField ( ) . getValue ( ) ;
double fs = ( double ) ( ( int ) fontSizeStylePane . fontSizeComboBox . getSelectedItem ( ) ) ;
if ( ! ( fs + "" ) . endsWith ( ".5" ) ) {
if ( ! ( fs + "" ) . endsWith ( ".5" ) ) {
fs = ( int ) fs ;
fs = ( int ) fs ;
}
}
return FRFont . getInstance ( this . familyPan e . getText ( ) ,
return FRFont . getInstance ( ( String ) this . fontN ameComboBox . getSelectedItem ( ) ,
this . fontSizeStylePane . getStyleList ( ) . getSelectedIndex ( ) ,
this . fontSizeStylePane . fontComboBox . getSelectedIndex ( ) ,
( float ) fs ,
( float ) ( ( int ) fontSizeStylePane . fontSizeComboBox . getSelectedItem ( ) ) ,
this . foregroundColorPane . getSelectObject ( ) ,
this . foregroundColorPane . getSelectObject ( ) ,
this . underlineCombo . getSelectedLineStyle ( ) ,
this . underlineCombo . getSelectedLineStyle ( ) ,
@ -393,10 +331,4 @@ public class FRFontPane extends BasicPane {
private void updatePreviewLabel ( ) {
private void updatePreviewLabel ( ) {
preview . setFontObject ( this . update ( ) ) ;
preview . setFontObject ( this . update ( ) ) ;
}
}
class ListHandler implements ListSelectionListener {
public void valueChanged ( ListSelectionEvent evt ) {
updatePreviewLabel ( ) ;
}
}
}
}