|
|
|
@ -7,7 +7,6 @@ import com.fr.base.TextFormat;
|
|
|
|
|
import com.fr.data.core.FormatField; |
|
|
|
|
import com.fr.data.core.FormatField.FormatContents; |
|
|
|
|
import com.fr.design.border.UIRoundedBorder; |
|
|
|
|
import com.fr.design.constants.LayoutConstants; |
|
|
|
|
import com.fr.design.constants.UIConstants; |
|
|
|
|
import com.fr.design.event.GlobalNameListener; |
|
|
|
|
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.ilable.UILabel; |
|
|
|
|
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.stable.StringUtils; |
|
|
|
|
|
|
|
|
|
import javax.swing.BorderFactory; |
|
|
|
|
import javax.swing.JComponent; |
|
|
|
|
import javax.swing.JLabel; |
|
|
|
|
import javax.swing.JList; |
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
import javax.swing.SwingConstants; |
|
|
|
|
import javax.swing.UIManager; |
|
|
|
|
import javax.swing.border.Border; |
|
|
|
|
import javax.swing.border.TitledBorder; |
|
|
|
|
import java.awt.BorderLayout; |
|
|
|
|
import java.awt.CardLayout; |
|
|
|
|
import java.awt.Color; |
|
|
|
|
import java.awt.Component; |
|
|
|
|
import java.awt.Dimension; |
|
|
|
@ -43,7 +39,6 @@ import java.awt.event.ItemListener;
|
|
|
|
|
import java.math.RoundingMode; |
|
|
|
|
import java.text.Format; |
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @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 Format format; |
|
|
|
|
|
|
|
|
|
private UIComboBox typeComboBox; |
|
|
|
|
private TextFontComboBox textField; |
|
|
|
|
private UILabel sampleLabel; |
|
|
|
|
private JPanel contentPane; |
|
|
|
|
private JPanel txtCenterPane; |
|
|
|
|
private JPanel centerPane; |
|
|
|
|
private JPanel optionPane; |
|
|
|
|
private UICheckBox roundingBox; |
|
|
|
|
private JPanel formatFontPane; |
|
|
|
|
protected UIComboBox typeComboBox; |
|
|
|
|
protected TextFontComboBox<String> textField; |
|
|
|
|
protected UICheckBox roundingBox; |
|
|
|
|
protected UILabel previewLabel; |
|
|
|
|
|
|
|
|
|
private boolean isRightFormat; |
|
|
|
|
private boolean isDate = false; |
|
|
|
|
private GlobalNameListener globalNameListener = null; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Constructor. |
|
|
|
|
*/ |
|
|
|
|
public TextFormatPane() { |
|
|
|
|
this.initComponents(TYPES); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected UIComboBox getTypeComboBox() { |
|
|
|
|
return typeComboBox; |
|
|
|
|
initFormatTypesComboBox(); |
|
|
|
|
initTextFontComboBox4GeneralFormats(); |
|
|
|
|
initRoundingCheckBox4PercentFormat(); |
|
|
|
|
initPreviewLabel4GeneralFormat(); |
|
|
|
|
|
|
|
|
|
initLayout(); |
|
|
|
|
|
|
|
|
|
setTextFieldVisible(false); |
|
|
|
|
setRoundingBoxVisible(false); |
|
|
|
|
setPreviewLabelVisible(false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void initComponents(Integer[] types) { |
|
|
|
|
this.setLayout(new BorderLayout(0, 4)); |
|
|
|
|
initSampleLabel(); |
|
|
|
|
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); |
|
|
|
|
private void initFormatTypesComboBox() { |
|
|
|
|
typeComboBox = new UIComboBox(TextFormatPane.TYPES); |
|
|
|
|
typeComboBox.setRenderer(createComBoxRender()); |
|
|
|
|
typeComboBox.addItemListener(itemListener); |
|
|
|
|
typeComboBox.setGlobalName("typeComboBox"); |
|
|
|
|
contentPane.add(sampleLabel, BorderLayout.NORTH); |
|
|
|
|
typeComboBox.setPreferredSize(new Dimension(155,20)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
txtCenterPane = new JPanel(new BorderLayout()); |
|
|
|
|
textField = new TextFontComboBox(); |
|
|
|
|
private void initTextFontComboBox4GeneralFormats() { |
|
|
|
|
textField = new TextFontComboBox<>(); |
|
|
|
|
textField.addItemListener(textFieldItemListener); |
|
|
|
|
textField.setEditable(true); |
|
|
|
|
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()); |
|
|
|
|
option.add(new UILabel(Toolkit.i18nText("Fine-Design_Report_Base_Option"), SwingConstants.LEFT), BorderLayout.WEST); |
|
|
|
|
private void initRoundingCheckBox4PercentFormat() { |
|
|
|
|
roundingBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Report_Base_Option_Half_Up")); |
|
|
|
|
roundingBox.setBorder(BorderFactory.createEmptyBorder(0, 30, 0, 0)); |
|
|
|
|
roundingBox.addItemListener(new ItemListener() { |
|
|
|
@ -139,54 +110,13 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
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) { |
|
|
|
|
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() { |
|
|
|
|
private void initPreviewLabel4GeneralFormat() { |
|
|
|
|
Border interBorder = new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 4); |
|
|
|
|
String title = Toolkit.i18nText("Fine-Design_Report_Base_StyleFormat_Sample"); |
|
|
|
|
Border border = BorderFactory.createTitledBorder(interBorder, title, TitledBorder.LEFT, 0, null, UIConstants.LINE_COLOR); |
|
|
|
|
sampleLabel = new UILabel(FormatField.getInstance().getFormatValue()) { |
|
|
|
|
previewLabel = new UILabel(FormatField.getInstance().getFormatValue()) { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void paint(Graphics g) { |
|
|
|
@ -198,12 +128,65 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName
|
|
|
|
|
g.setColor(UIConstants.LINE_COLOR); |
|
|
|
|
FontMetrics cellFM = g.getFontMetrics(); |
|
|
|
|
int textWidth = cellFM.stringWidth(getText()); |
|
|
|
|
GraphHelper.drawString(g, getText(), (width - textWidth) / 2, 26); |
|
|
|
|
GraphHelper.drawString(g, getText(), (width - textWidth) / 2F, 26); |
|
|
|
|
g.setColor(original); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
sampleLabel.setHorizontalAlignment(UILabel.CENTER); |
|
|
|
|
sampleLabel.setBorder(border); |
|
|
|
|
previewLabel.setHorizontalAlignment(UILabel.CENTER); |
|
|
|
|
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 |
|
|
|
|
*/ |
|
|
|
|
public void populateBean(Format format) { |
|
|
|
|
this.format = format; |
|
|
|
|
|
|
|
|
|
if (format == null) { |
|
|
|
|
this.typeComboBox.setSelectedIndex(FormatContents.NULL); |
|
|
|
|
} else { |
|
|
|
@ -325,17 +306,17 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName
|
|
|
|
|
* Refresh preview label. |
|
|
|
|
*/ |
|
|
|
|
private void refreshPreviewLabel() { |
|
|
|
|
this.sampleLabel.setText(FormatField.getInstance().getFormatValue()); |
|
|
|
|
this.sampleLabel.setForeground(UIManager.getColor("Label.foreground")); |
|
|
|
|
this.previewLabel.setText(FormatField.getInstance().getFormatValue()); |
|
|
|
|
this.previewLabel.setForeground(UIManager.getColor("Label.foreground")); |
|
|
|
|
try { |
|
|
|
|
isRightFormat = true; |
|
|
|
|
if (StringUtils.isEmpty(String.valueOf(textField.getSelectedItem()))) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
this.sampleLabel.setText(FormatField.getInstance().getFormatValue(getFormatContents(), String.valueOf(textField.getSelectedItem()))); |
|
|
|
|
this.previewLabel.setText(FormatField.getInstance().getFormatValue(getFormatContents(), String.valueOf(textField.getSelectedItem()))); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
this.sampleLabel.setForeground(Color.red); |
|
|
|
|
this.sampleLabel.setText(e.getMessage()); |
|
|
|
|
this.previewLabel.setForeground(Color.red); |
|
|
|
|
this.previewLabel.setText(e.getMessage()); |
|
|
|
|
isRightFormat = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -354,28 +335,16 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName
|
|
|
|
|
public void itemStateChanged(ItemEvent e) { |
|
|
|
|
if (e.getStateChange() == ItemEvent.SELECTED) { |
|
|
|
|
int contents = getFormatContents(); |
|
|
|
|
String[] items = FormatField.getInstance().getFormatArray(contents, false); |
|
|
|
|
CardLayout cardLayout = (CardLayout) centerPane.getLayout(); |
|
|
|
|
|
|
|
|
|
if (isTextOrNull()) { |
|
|
|
|
centerPane.setPreferredSize(new Dimension(0, 0)); |
|
|
|
|
cardLayout.show(centerPane, "hide"); |
|
|
|
|
} else { |
|
|
|
|
if (!isTextOrNull()) { |
|
|
|
|
textField.removeAllItems(); |
|
|
|
|
String[] items = FormatField.getInstance().getFormatArray(contents, false); |
|
|
|
|
textField.setItemArray(items); |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|