@ -7,7 +7,6 @@ import com.fr.base.TextFormat;
import com.fr.data.core.FormatField ;
import com.fr.data.core.FormatField ;
import com.fr.data.core.FormatField.FormatContents ;
import com.fr.data.core.FormatField.FormatContents ;
import com.fr.design.border.UIRoundedBorder ;
import com.fr.design.border.UIRoundedBorder ;
import com.fr.design.constants.LayoutConstants ;
import com.fr.design.constants.UIConstants ;
import com.fr.design.constants.UIConstants ;
import com.fr.design.event.GlobalNameListener ;
import com.fr.design.event.GlobalNameListener ;
import com.fr.design.event.GlobalNameObserver ;
import com.fr.design.event.GlobalNameObserver ;
@ -18,21 +17,18 @@ import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.icombobox.UIComboBoxRenderer ;
import com.fr.design.gui.icombobox.UIComboBoxRenderer ;
import com.fr.design.gui.ilable.UILabel ;
import com.fr.design.gui.ilable.UILabel ;
import com.fr.design.i18n.Toolkit ;
import com.fr.design.i18n.Toolkit ;
import com.fr.design.layout.TableLayout ;
import com.fr.design.layout.TableLayoutHelper ;
import com.fr.general.ComparatorUtils ;
import com.fr.general.ComparatorUtils ;
import com.fr.stable.StringUtils ;
import com.fr.stable.StringUtils ;
import javax.swing.BorderFactory ;
import javax.swing.BorderFactory ;
import javax.swing.JComponent ;
import javax.swing.JLabel ;
import javax.swing.JLabel ;
import javax.swing.JList ;
import javax.swing.JList ;
import javax.swing.JPanel ;
import javax.swing.JPanel ;
import javax.swing.SwingConstants ;
import javax.swing.UIManager ;
import javax.swing.UIManager ;
import javax.swing.border.Border ;
import javax.swing.border.Border ;
import javax.swing.border.TitledBorder ;
import javax.swing.border.TitledBorder ;
import java.awt.BorderLayout ;
import java.awt.BorderLayout ;
import java.awt.CardLayout ;
import java.awt.Color ;
import java.awt.Color ;
import java.awt.Component ;
import java.awt.Component ;
import java.awt.Dimension ;
import java.awt.Dimension ;
@ -43,7 +39,6 @@ import java.awt.event.ItemListener;
import java.math.RoundingMode ;
import java.math.RoundingMode ;
import java.text.Format ;
import java.text.Format ;
import java.text.SimpleDateFormat ;
import java.text.SimpleDateFormat ;
import java.util.Arrays ;
/ * *
/ * *
* @author Starryi
* @author Starryi
@ -68,69 +63,45 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName
private static final Integer [ ] DATE_TYPES = new Integer [ ] { FormatContents . NULL , FormatContents . DATE , FormatContents . TIME } ;
private static final Integer [ ] DATE_TYPES = new Integer [ ] { FormatContents . NULL , FormatContents . DATE , FormatContents . TIME } ;
private Format format ;
protected UIComboBox typeComboBox ;
protected TextFontComboBox < String > textField ;
private UIComboBox typeComboBox ;
protected UICheckBox roundingBox ;
private TextFontComboBox textField ;
protected UILabel previewLabel ;
private UILabel sampleLabel ;
private JPanel contentPane ;
private JPanel txtCenterPane ;
private JPanel centerPane ;
private JPanel optionPane ;
private UICheckBox roundingBox ;
private JPanel formatFontPane ;
private boolean isRightFormat ;
private boolean isRightFormat ;
private boolean isDate = false ;
private boolean isDate = false ;
private GlobalNameListener globalNameListener = null ;
private GlobalNameListener globalNameListener = null ;
/ * *
* Constructor .
* /
public TextFormatPane ( ) {
public TextFormatPane ( ) {
this . initComponents ( TYPES ) ;
}
protected UIComboBox getTypeComboBox ( ) {
initFormatTypesComboBox ( ) ;
return typeComboBox ;
initTextFontComboBox4GeneralFormats ( ) ;
initRoundingCheckBox4PercentFormat ( ) ;
initPreviewLabel4GeneralFormat ( ) ;
initLayout ( ) ;
setTextFieldVisible ( false ) ;
setRoundingBoxVisible ( false ) ;
setPreviewLabelVisible ( false ) ;
}
}
protected void initComponents ( Integer [ ] types ) {
private void initFormatTypesComboBox ( ) {
this . setLayout ( new BorderLayout ( 0 , 4 ) ) ;
typeComboBox = new UIComboBox ( TextFormatPane . TYPES ) ;
initSampleLabel ( ) ;
typeComboBox . setRenderer ( createComBoxRender ( ) ) ;
contentPane = new JPanel ( new BorderLayout ( 0 , 4 ) ) {
@Override
public Dimension getPreferredSize ( ) {
return new Dimension ( super . getPreferredSize ( ) . width , 65 ) ;
}
} ;
typeComboBox = new UIComboBox ( types ) ;
UIComboBoxRenderer render = createComBoxRender ( ) ;
typeComboBox . setRenderer ( render ) ;
typeComboBox . addItemListener ( itemListener ) ;
typeComboBox . addItemListener ( itemListener ) ;
typeComboBox . setGlobalName ( "typeComboBox" ) ;
typeComboBox . setGlobalName ( "typeComboBox" ) ;
contentPane . add ( sampleLabel , BorderLayout . NORTH ) ;
typeComboBox . setPreferredSize ( new Dimension ( 155 , 20 ) ) ;
}
txtCenterPane = new JPanel ( new BorderLayout ( ) ) ;
private void initTextFontComboBox4GeneralFormats ( ) {
textField = new TextFontComboBox ( ) ;
textField = new TextFontComboBox < > ( ) ;
textField . addItemListener ( textFieldItemListener ) ;
textField . addItemListener ( textFieldItemListener ) ;
textField . setEditable ( true ) ;
textField . setEditable ( true ) ;
textField . setGlobalName ( "textField" ) ;
textField . setGlobalName ( "textField" ) ;
txtCenterPane . add ( textField , BorderLayout . NORTH ) ;
}
contentPane . add ( txtCenterPane , BorderLayout . CENTER ) ;
centerPane = new JPanel ( new CardLayout ( ) ) ;
centerPane . add ( new JPanel ( ) , "hide" ) ;
centerPane . setPreferredSize ( new Dimension ( 0 , 0 ) ) ;
centerPane . add ( contentPane , "show" ) ;
typeComboBox . setPreferredSize ( new Dimension ( 155 , 20 ) ) ;
JPanel typePane = new JPanel ( new BorderLayout ( ) ) ;
typePane . add ( typeComboBox , BorderLayout . CENTER ) ;
typePane . setBorder ( BorderFactory . createEmptyBorder ( 0 , 20 , 0 , 0 ) ) ;
JPanel option = new JPanel ( new BorderLayout ( ) ) ;
private void initRoundingCheckBox4PercentFormat ( ) {
option . add ( new UILabel ( Toolkit . i18nText ( "Fine-Design_Report_Base_Option" ) , SwingConstants . LEFT ) , BorderLayout . WEST ) ;
roundingBox = new UICheckBox ( Toolkit . i18nText ( "Fine-Design_Report_Base_Option_Half_Up" ) ) ;
roundingBox = new UICheckBox ( Toolkit . i18nText ( "Fine-Design_Report_Base_Option_Half_Up" ) ) ;
roundingBox . setBorder ( BorderFactory . createEmptyBorder ( 0 , 30 , 0 , 0 ) ) ;
roundingBox . setBorder ( BorderFactory . createEmptyBorder ( 0 , 30 , 0 , 0 ) ) ;
roundingBox . addItemListener ( new ItemListener ( ) {
roundingBox . addItemListener ( new ItemListener ( ) {
@ -139,54 +110,13 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName
}
}
} ) ;
} ) ;
roundingBox . setGlobalName ( "roundingBox" ) ;
roundingBox . setGlobalName ( "roundingBox" ) ;
option . add ( roundingBox , BorderLayout . CENTER ) ;
optionPane = new JPanel ( new CardLayout ( ) ) ;
optionPane . add ( new JPanel ( ) , "hide" ) ;
optionPane . setPreferredSize ( new Dimension ( 0 , 0 ) ) ;
optionPane . add ( option , "show" ) ;
Component [ ] [ ] components = getComponent ( centerPane , typePane ) ;
this . add ( createContentPane ( components ) , BorderLayout . CENTER ) ;
}
}
protected JPanel createContentPane ( Component [ ] [ ] components ) {
private void initPreviewLabel4GeneralFormat ( ) {
double f = TableLayout . FILL ;
double p = TableLayout . PREFERRED ;
double [ ] rowSize = new double [ components . length ] ;
Arrays . fill ( rowSize , p ) ;
double [ ] columnSize = { p , f } ;
int [ ] [ ] rowCount = new int [ components . length ] [ 2 ] ;
Arrays . fill ( rowCount , new int [ ] { 1 , 1 } ) ;
return TableLayoutHelper . createGapTableLayoutPane ( components , rowSize , columnSize , rowCount , LayoutConstants . VGAP_LARGE , LayoutConstants . VGAP_MEDIUM ) ;
}
protected Component [ ] [ ] getComponent ( JPanel centerPane , JPanel typePane ) {
return new Component [ ] [ ] {
new Component [ ] { new UILabel ( Toolkit . i18nText ( "Fine-Design_Report_Base_Format" ) , SwingConstants . LEFT ) , typePane } ,
new Component [ ] { centerPane , null } ,
new Component [ ] { optionPane , null } ,
} ;
}
protected UIComboBoxRenderer createComBoxRender ( ) {
return new UIComboBoxRenderer ( ) {
@Override
public Component getListCellRendererComponent ( JList list , Object value , int index , boolean isSelected , boolean cellHasFocus ) {
JLabel label = ( JLabel ) super . getListCellRendererComponent ( list , value , index , isSelected , cellHasFocus ) ;
if ( value instanceof Integer ) {
label . setText ( " " + FormatField . getInstance ( ) . getName ( ( Integer ) value ) ) ;
}
return label ;
}
} ;
}
private void initSampleLabel ( ) {
Border interBorder = new UIRoundedBorder ( UIConstants . LINE_COLOR , 1 , 4 ) ;
Border interBorder = new UIRoundedBorder ( UIConstants . LINE_COLOR , 1 , 4 ) ;
String title = Toolkit . i18nText ( "Fine-Design_Report_Base_StyleFormat_Sample" ) ;
String title = Toolkit . i18nText ( "Fine-Design_Report_Base_StyleFormat_Sample" ) ;
Border border = BorderFactory . createTitledBorder ( interBorder , title , TitledBorder . LEFT , 0 , null , UIConstants . LINE_COLOR ) ;
Border border = BorderFactory . createTitledBorder ( interBorder , title , TitledBorder . LEFT , 0 , null , UIConstants . LINE_COLOR ) ;
sample Label = new UILabel ( FormatField . getInstance ( ) . getFormatValue ( ) ) {
previewLabel = new UILabel ( FormatField . getInstance ( ) . getFormatValue ( ) ) {
@Override
@Override
public void paint ( Graphics g ) {
public void paint ( Graphics g ) {
@ -198,12 +128,65 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName
g . setColor ( UIConstants . LINE_COLOR ) ;
g . setColor ( UIConstants . LINE_COLOR ) ;
FontMetrics cellFM = g . getFontMetrics ( ) ;
FontMetrics cellFM = g . getFontMetrics ( ) ;
int textWidth = cellFM . stringWidth ( getText ( ) ) ;
int textWidth = cellFM . stringWidth ( getText ( ) ) ;
GraphHelper . drawString ( g , getText ( ) , ( width - textWidth ) / 2 , 26 ) ;
GraphHelper . drawString ( g , getText ( ) , ( width - textWidth ) / 2F , 26 ) ;
g . setColor ( original ) ;
g . setColor ( original ) ;
}
}
} ;
} ;
sampleLabel . setHorizontalAlignment ( UILabel . CENTER ) ;
previewLabel . setHorizontalAlignment ( UILabel . CENTER ) ;
sampleLabel . setBorder ( border ) ;
previewLabel . setBorder ( border ) ;
}
protected void initLayout ( ) {
JPanel labeledFormatTypeComboBoxPane = new JPanel ( new BorderLayout ( 20 , 0 ) ) ;
labeledFormatTypeComboBoxPane . add ( new UILabel ( Toolkit . i18nText ( "Fine-Design_Report_Base_Format" ) ) , BorderLayout . WEST ) ;
labeledFormatTypeComboBoxPane . add ( typeComboBox , BorderLayout . CENTER ) ;
JPanel labeledRoundingCheckboxPane = new JPanel ( new BorderLayout ( 0 , 0 ) ) ;
labeledRoundingCheckboxPane . add ( new UILabel ( Toolkit . i18nText ( "Fine-Design_Report_Base_Option" ) ) , BorderLayout . WEST ) ;
labeledRoundingCheckboxPane . add ( roundingBox , BorderLayout . CENTER ) ;
addComponents ( 4 , new JComponent [ ] { labeledFormatTypeComboBoxPane , textField , labeledRoundingCheckboxPane , previewLabel } ) ;
}
protected void setTextFieldVisible ( boolean visible ) {
textField . setVisible ( visible ) ;
}
protected void setRoundingBoxVisible ( boolean visible ) {
roundingBox . getParent ( ) . setVisible ( visible ) ;
}
protected void setPreviewLabelVisible ( boolean visible ) {
previewLabel . setVisible ( visible ) ;
}
protected void addComponents ( int gap , JComponent [ ] components ) {
JPanel container = this ;
container . setLayout ( new BorderLayout ( 0 , gap ) ) ;
for ( JComponent component : components ) {
if ( component ! = null ) {
container . add ( component , BorderLayout . NORTH ) ;
JPanel nextContainer = new JPanel ( new BorderLayout ( 0 , gap ) ) ;
container . add ( nextContainer , BorderLayout . CENTER ) ;
container = nextContainer ;
}
}
if ( container . getComponentCount ( ) = = 0 ) {
container . getParent ( ) . remove ( container ) ;
}
}
protected UIComboBoxRenderer createComBoxRender ( ) {
return new UIComboBoxRenderer ( ) {
@Override
public Component getListCellRendererComponent ( JList list , Object value , int index , boolean isSelected , boolean cellHasFocus ) {
JLabel label = ( JLabel ) super . getListCellRendererComponent ( list , value , index , isSelected , cellHasFocus ) ;
if ( value instanceof Integer ) {
label . setText ( " " + FormatField . getInstance ( ) . getName ( ( Integer ) value ) ) ;
}
return label ;
}
} ;
}
}
@ -231,8 +214,6 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName
* Populate
* Populate
* /
* /
public void populateBean ( Format format ) {
public void populateBean ( Format format ) {
this . format = format ;
if ( format = = null ) {
if ( format = = null ) {
this . typeComboBox . setSelectedIndex ( FormatContents . NULL ) ;
this . typeComboBox . setSelectedIndex ( FormatContents . NULL ) ;
} else {
} else {
@ -325,17 +306,17 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName
* Refresh preview label .
* Refresh preview label .
* /
* /
private void refreshPreviewLabel ( ) {
private void refreshPreviewLabel ( ) {
this . sample Label. setText ( FormatField . getInstance ( ) . getFormatValue ( ) ) ;
this . preview Label. setText ( FormatField . getInstance ( ) . getFormatValue ( ) ) ;
this . sample Label. setForeground ( UIManager . getColor ( "Label.foreground" ) ) ;
this . preview Label. setForeground ( UIManager . getColor ( "Label.foreground" ) ) ;
try {
try {
isRightFormat = true ;
isRightFormat = true ;
if ( StringUtils . isEmpty ( String . valueOf ( textField . getSelectedItem ( ) ) ) ) {
if ( StringUtils . isEmpty ( String . valueOf ( textField . getSelectedItem ( ) ) ) ) {
return ;
return ;
}
}
this . sample Label. setText ( FormatField . getInstance ( ) . getFormatValue ( getFormatContents ( ) , String . valueOf ( textField . getSelectedItem ( ) ) ) ) ;
this . preview Label. setText ( FormatField . getInstance ( ) . getFormatValue ( getFormatContents ( ) , String . valueOf ( textField . getSelectedItem ( ) ) ) ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
this . sample Label. setForeground ( Color . red ) ;
this . preview Label. setForeground ( Color . red ) ;
this . sample Label. setText ( e . getMessage ( ) ) ;
this . preview Label. setText ( e . getMessage ( ) ) ;
isRightFormat = false ;
isRightFormat = false ;
}
}
}
}
@ -354,28 +335,16 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName
public void itemStateChanged ( ItemEvent e ) {
public void itemStateChanged ( ItemEvent e ) {
if ( e . getStateChange ( ) = = ItemEvent . SELECTED ) {
if ( e . getStateChange ( ) = = ItemEvent . SELECTED ) {
int contents = getFormatContents ( ) ;
int contents = getFormatContents ( ) ;
String [ ] items = FormatField . getInstance ( ) . getFormatArray ( contents , false ) ;
CardLayout cardLayout = ( CardLayout ) centerPane . getLayout ( ) ;
if ( isTextOrNull ( ) ) {
if ( ! isTextOrNull ( ) ) {
centerPane . setPreferredSize ( new Dimension ( 0 , 0 ) ) ;
cardLayout . show ( centerPane , "hide" ) ;
} else {
textField . removeAllItems ( ) ;
textField . removeAllItems ( ) ;
String [ ] items = FormatField . getInstance ( ) . getFormatArray ( contents , false ) ;
textField . setItemArray ( items ) ;
textField . setItemArray ( items ) ;
textField . setSelectedIndex ( 0 ) ;
textField . setSelectedIndex ( 0 ) ;
centerPane . setPreferredSize ( new Dimension ( 270 , 65 ) ) ;
cardLayout . show ( centerPane , "show" ) ;
}
CardLayout optionLayout = ( ( CardLayout ) optionPane . getLayout ( ) ) ;
if ( getFormatContents ( ) = = FormatContents . PERCENT ) {
optionPane . setPreferredSize ( new Dimension ( 100 , 20 ) ) ;
optionLayout . show ( optionPane , "show" ) ;
} else {
optionPane . setPreferredSize ( new Dimension ( 0 , 0 ) ) ;
optionLayout . show ( optionPane , "hide" ) ;
roundingBox . setSelected ( false ) ;
}
}
setTextFieldVisible ( ! isTextOrNull ( ) ) ;
setPreviewLabelVisible ( ! isTextOrNull ( ) ) ;
setRoundingBoxVisible ( getFormatContents ( ) = = FormatContents . PERCENT ) ;
}
}
}
}