|
|
|
@ -1,14 +1,16 @@
|
|
|
|
|
package com.fr.design.widget.ui; |
|
|
|
|
|
|
|
|
|
import com.fine.theme.light.ui.FineRoundBorder; |
|
|
|
|
import com.formdev.flatlaf.ui.FlatUIUtils; |
|
|
|
|
import com.fr.base.FRContext; |
|
|
|
|
import com.fr.data.core.FormatField; |
|
|
|
|
import com.fr.design.constants.LayoutConstants; |
|
|
|
|
import com.fr.design.border.UIRoundedBorder; |
|
|
|
|
import com.fr.design.constants.UIConstants; |
|
|
|
|
import com.fr.design.designer.IntervalConstants; |
|
|
|
|
import com.fr.design.gui.ibutton.UIButtonGroup; |
|
|
|
|
import com.fr.design.gui.icombobox.UIComboBox; |
|
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
|
|
|
import com.fr.design.i18n.Toolkit; |
|
|
|
|
import com.fr.design.layout.FRGUIPaneFactory; |
|
|
|
|
import com.fr.design.layout.TableLayout; |
|
|
|
|
import com.fr.design.layout.TableLayoutHelper; |
|
|
|
|
import com.fr.design.widget.component.DateValuePane; |
|
|
|
|
import com.fr.design.widget.component.UIComboBoxNoArrow; |
|
|
|
|
import com.fr.design.widget.ui.designer.date.DateFormatCheckManager; |
|
|
|
@ -17,30 +19,29 @@ import com.fr.form.ui.DateEditor;
|
|
|
|
|
|
|
|
|
|
import com.fr.stable.ArrayUtils; |
|
|
|
|
|
|
|
|
|
import javax.swing.BorderFactory; |
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
import javax.swing.SwingConstants; |
|
|
|
|
import javax.swing.border.EmptyBorder; |
|
|
|
|
import javax.swing.plaf.BorderUIResource; |
|
|
|
|
import javax.swing.border.TitledBorder; |
|
|
|
|
import javax.swing.event.ChangeEvent; |
|
|
|
|
import javax.swing.event.ChangeListener; |
|
|
|
|
import java.awt.*; |
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
|
|
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.row; |
|
|
|
|
import static com.fine.swing.ui.layout.Layouts.flex; |
|
|
|
|
import static com.fr.design.constants.LayoutConstants.LEFT_WEIGHT; |
|
|
|
|
import static com.fr.design.constants.LayoutConstants.RIGHT_WEIGHT; |
|
|
|
|
|
|
|
|
|
public class DateEditorDefinePane extends DirectWriteEditorDefinePane<DateEditor> { |
|
|
|
|
private UIButtonGroup returnTypeButtonGroup; |
|
|
|
|
private UIButtonGroup returnTypeComboBox; |
|
|
|
|
|
|
|
|
|
private DateValuePane startDv; |
|
|
|
|
private DateValuePane endDv; |
|
|
|
|
|
|
|
|
|
private UIComboBox currentFormatComboBox; |
|
|
|
|
private UILabel currentSampleLabel; |
|
|
|
|
private UIButtonGroup formatButtonGroup; |
|
|
|
|
private UILabel currentSamplelabel; |
|
|
|
|
private UIButtonGroup fomatHeadGroup; |
|
|
|
|
private static final int SAMPLE_LABEL_PADDING = 4; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DateEditorDefinePane() { |
|
|
|
|
} |
|
|
|
@ -52,22 +53,33 @@ public class DateEditorDefinePane extends DirectWriteEditorDefinePane<DateEditor
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected JPanel setSecondContentPane() { |
|
|
|
|
returnTypeButtonGroup = new UIButtonGroup<>(new String[] {com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Date") , |
|
|
|
|
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_String")}); |
|
|
|
|
returnTypeComboBox = new UIButtonGroup<>(new String[] {com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Date") , com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_String")}); |
|
|
|
|
JPanel formatHead = createFormatHead(); |
|
|
|
|
startDv = new DateValuePane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_FS_Start_Date")); |
|
|
|
|
endDv = new DateValuePane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_FS_End_Date")); |
|
|
|
|
UILabel returnTypeLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Widget_Date_Selector_Return_Type")); |
|
|
|
|
startDv = new DateValuePane(); |
|
|
|
|
endDv = new DateValuePane(); |
|
|
|
|
double f = TableLayout.FILL; |
|
|
|
|
double p = TableLayout.PREFERRED; |
|
|
|
|
UILabel formatLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Engine_Format")); |
|
|
|
|
formatLabel.setVerticalAlignment(SwingConstants.TOP); |
|
|
|
|
UILabel startDateLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_FS_Start_Date")); |
|
|
|
|
startDateLabel.setVerticalAlignment(SwingConstants.TOP); |
|
|
|
|
UILabel endDateLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_FS_End_Date")); |
|
|
|
|
endDateLabel.setVerticalAlignment(SwingConstants.TOP); |
|
|
|
|
Component[][] components = new Component[][]{ |
|
|
|
|
new Component[]{formatLabel, formatHead}, |
|
|
|
|
new Component[]{startDateLabel, startDv}, |
|
|
|
|
new Component[]{endDateLabel, endDv}, |
|
|
|
|
new Component[]{waterMarkDictPane, null}, |
|
|
|
|
new Component[]{extraPane, null}, |
|
|
|
|
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Widget_Date_Selector_Return_Type")), returnTypeComboBox } |
|
|
|
|
}; |
|
|
|
|
double[] rowSize = {p, p, p, p, p, p, p, p}; |
|
|
|
|
double[] columnSize = {p, f}; |
|
|
|
|
int[][] rowCount = {{1, 3},{1, 1},{1, 1},{1, 1},{1, 1}, {1, 1}}; |
|
|
|
|
JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, IntervalConstants.INTERVAL_L2, IntervalConstants.INTERVAL_L1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return column(LayoutConstants.VERTICAL_GAP, |
|
|
|
|
cell(formatHead), |
|
|
|
|
cell(startDv), |
|
|
|
|
cell(endDv), |
|
|
|
|
cell(waterMarkDictPane), |
|
|
|
|
row( |
|
|
|
|
cell(returnTypeLabel).weight(LEFT_WEIGHT), cell(returnTypeButtonGroup).weight(1.4), flex(1.6) |
|
|
|
|
) |
|
|
|
|
).getComponent(); |
|
|
|
|
return panel; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -76,20 +88,20 @@ public class DateEditorDefinePane extends DirectWriteEditorDefinePane<DateEditor
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private JPanel createFormatPane(UIComboBox formatComboBox, UILabel sampleLabel){ |
|
|
|
|
JPanel previewPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
|
|
|
|
|
|
|
|
previewPane.setPreferredSize(formatComboBox.getPreferredSize()); |
|
|
|
|
previewPane.setBorder(new BorderUIResource.CompoundBorderUIResource( |
|
|
|
|
new FineRoundBorder(), |
|
|
|
|
new EmptyBorder(0, 8, 0, 0) |
|
|
|
|
)); |
|
|
|
|
JPanel previewPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
|
|
|
TitledBorder titledBorder = new TitledBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 5), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Base_StyleFormat_Sample"), 4, 2, this.getFont(), UIConstants.LINE_COLOR); |
|
|
|
|
previewPane.setBorder(titledBorder); |
|
|
|
|
|
|
|
|
|
previewPane.add(sampleLabel, BorderLayout.WEST); |
|
|
|
|
return column(LayoutConstants.VERTICAL_GAP, true, |
|
|
|
|
cell(formatComboBox), |
|
|
|
|
cell(previewPane).weight(1.0) |
|
|
|
|
JPanel sampleLabelWrapper = new JPanel(new BorderLayout()); |
|
|
|
|
sampleLabelWrapper.setBorder(BorderFactory.createEmptyBorder(0, SAMPLE_LABEL_PADDING, SAMPLE_LABEL_PADDING, SAMPLE_LABEL_PADDING)); |
|
|
|
|
sampleLabelWrapper.add(sampleLabel, BorderLayout.CENTER); |
|
|
|
|
|
|
|
|
|
).getComponent(); |
|
|
|
|
previewPane.add(sampleLabelWrapper, BorderLayout.CENTER); |
|
|
|
|
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
|
|
|
jPanel.add(previewPane, BorderLayout.NORTH); |
|
|
|
|
jPanel.add(formatComboBox, BorderLayout.CENTER); |
|
|
|
|
return jPanel; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private UILabel createSamplePane(){ |
|
|
|
@ -101,51 +113,58 @@ public class DateEditorDefinePane extends DirectWriteEditorDefinePane<DateEditor
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
sampleLabel.setHorizontalAlignment(SwingConstants.CENTER); |
|
|
|
|
sampleLabel.setFont(this.getFont()); |
|
|
|
|
sampleLabel.setForeground(FlatUIUtils.getUIColor("Label.tipColor", Color.GRAY)); |
|
|
|
|
sampleLabel.setFont(FRContext.getDefaultValues().getFRFont()); |
|
|
|
|
return sampleLabel; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private JPanel createFormatHead(){ |
|
|
|
|
UILabel formatLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Engine_Format")); |
|
|
|
|
String[] dateArray = FormatField.getInstance().getFormatArray(FormatField.FormatContents.DATE); |
|
|
|
|
String[] timeArray = FormatField.getInstance().getFormatArray(FormatField.FormatContents.TIME); |
|
|
|
|
final UIComboBox dateFormatComboBox = new UIComboBoxNoArrow(dateArray); |
|
|
|
|
final UIComboBox timeFormatComboBox = new UIComboBoxNoArrow(timeArray); |
|
|
|
|
dateFormatComboBox.addActionListener(e -> refreshPreviewLabel()); |
|
|
|
|
timeFormatComboBox.addActionListener(e -> refreshPreviewLabel()); |
|
|
|
|
dateFormatComboBox.addActionListener(new ActionListener(){ |
|
|
|
|
public void actionPerformed(ActionEvent e){ |
|
|
|
|
refreshPreviewLabel(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
timeFormatComboBox.addActionListener(new ActionListener(){ |
|
|
|
|
public void actionPerformed(ActionEvent e){ |
|
|
|
|
refreshPreviewLabel(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
final UILabel dateSampleLabel = createSamplePane(); |
|
|
|
|
final UILabel timeSampleLabel = createSamplePane(); |
|
|
|
|
JPanel fomatHeadPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
|
|
|
final CardLayout cardLayout = new CardLayout(); |
|
|
|
|
final JPanel customPane = new JPanel(cardLayout); |
|
|
|
|
JPanel dateFormatPane = createFormatPane(dateFormatComboBox, dateSampleLabel); |
|
|
|
|
JPanel timeFormatPane = createFormatPane(timeFormatComboBox, timeSampleLabel); |
|
|
|
|
customPane.add(dateFormatPane, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_StyleFormat_Date")); |
|
|
|
|
customPane.add(timeFormatPane, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_StyleFormat_Time")); |
|
|
|
|
final String[] tabTitles = new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_StyleFormat_Date"), |
|
|
|
|
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_StyleFormat_Time")}; |
|
|
|
|
formatButtonGroup = new UIButtonGroup<>(new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_StyleFormat_Date"), |
|
|
|
|
com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_StyleFormat_Time")}); |
|
|
|
|
formatButtonGroup.addChangeListener(e -> { |
|
|
|
|
int newSelectedIndex = formatButtonGroup.getSelectedIndex(); |
|
|
|
|
final String[] tabTitles = new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_StyleFormat_Date"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_StyleFormat_Time")}; |
|
|
|
|
fomatHeadGroup = new UIButtonGroup(new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_StyleFormat_Date"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_StyleFormat_Time")}); |
|
|
|
|
fomatHeadGroup.addChangeListener(new ChangeListener() { |
|
|
|
|
@Override |
|
|
|
|
public void stateChanged(ChangeEvent e) { |
|
|
|
|
int newSelectedIndex = fomatHeadGroup.getSelectedIndex(); |
|
|
|
|
cardLayout.show(customPane, tabTitles[newSelectedIndex]); |
|
|
|
|
if(newSelectedIndex == 0){ |
|
|
|
|
currentFormatComboBox = dateFormatComboBox; |
|
|
|
|
currentSampleLabel = dateSampleLabel; |
|
|
|
|
currentSamplelabel = dateSampleLabel; |
|
|
|
|
}else{ |
|
|
|
|
currentFormatComboBox = timeFormatComboBox; |
|
|
|
|
currentSampleLabel = timeSampleLabel; |
|
|
|
|
currentSamplelabel = timeSampleLabel; |
|
|
|
|
} |
|
|
|
|
refreshPreviewLabel(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
return column(LayoutConstants.VERTICAL_GAP, |
|
|
|
|
row( |
|
|
|
|
cell(formatLabel).weight(LEFT_WEIGHT), cell(formatButtonGroup).weight(1.4), flex(1.6) |
|
|
|
|
), |
|
|
|
|
row(flex(LEFT_WEIGHT), cell(customPane).weight(RIGHT_WEIGHT)) |
|
|
|
|
).getComponent(); |
|
|
|
|
fomatHeadPane.add(fomatHeadGroup, BorderLayout.NORTH); |
|
|
|
|
fomatHeadPane.add(customPane, BorderLayout.CENTER); |
|
|
|
|
return fomatHeadPane; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void refreshPreviewLabel() { |
|
|
|
|
String text = (String) currentFormatComboBox.getSelectedItem(); |
|
|
|
|
if (text != null && text.length() > 0) { |
|
|
|
@ -153,15 +172,14 @@ public class DateEditorDefinePane extends DirectWriteEditorDefinePane<DateEditor
|
|
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(text); |
|
|
|
|
String sample = simpleDateFormat.format(new Date()); |
|
|
|
|
DateFormatCheckResult result = DateFormatCheckManager.check(sample, text); |
|
|
|
|
currentSampleLabel.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Base_StyleFormat_Sample") + ":" + result.getSample()); |
|
|
|
|
currentSampleLabel.setForeground(result.getColor()); |
|
|
|
|
currentSamplelabel.setText(result.getSample()); |
|
|
|
|
currentSamplelabel.setForeground(result.getColor()); |
|
|
|
|
} catch (Exception exp) { |
|
|
|
|
currentSampleLabel.removeAll(); |
|
|
|
|
currentSampleLabel.setForeground(Color.red); |
|
|
|
|
currentSampleLabel.setText(exp.getMessage()); |
|
|
|
|
currentSamplelabel.setForeground(Color.red); |
|
|
|
|
currentSamplelabel.setText(exp.getMessage()); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
currentSampleLabel.setText(new Date().toString()); |
|
|
|
|
currentSamplelabel.setText(new Date().toString()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -181,11 +199,11 @@ public class DateEditorDefinePane extends DirectWriteEditorDefinePane<DateEditor
|
|
|
|
|
@Override |
|
|
|
|
protected void populateSubDirectWriteEditorBean(DateEditor e) { |
|
|
|
|
String formatText = e.getFormatText(); |
|
|
|
|
formatButtonGroup.setSelectedIndex(getDateType(e)); |
|
|
|
|
formatButtonGroup.populateBean(); |
|
|
|
|
fomatHeadGroup.setSelectedIndex(getDateType(e)); |
|
|
|
|
fomatHeadGroup.populateBean(); |
|
|
|
|
currentFormatComboBox.setSelectedItem(formatText); |
|
|
|
|
|
|
|
|
|
returnTypeButtonGroup.setSelectedIndex(e.isReturnDate() ? 0 : 1); |
|
|
|
|
returnTypeComboBox.setSelectedIndex(e.isReturnDate() ? 0 : 1); |
|
|
|
|
startDv.populate(e.getStartDate()); |
|
|
|
|
endDv.populate(e.getEndDate()); |
|
|
|
|
} |
|
|
|
@ -194,7 +212,7 @@ public class DateEditorDefinePane extends DirectWriteEditorDefinePane<DateEditor
|
|
|
|
|
protected DateEditor updateSubDirectWriteEditorBean() { |
|
|
|
|
DateEditor ob = new DateEditor(); |
|
|
|
|
ob.setFormatText(this.getSimpleDateFormat().toPattern()); |
|
|
|
|
ob.setReturnDate(returnTypeButtonGroup.getSelectedIndex() == 0); |
|
|
|
|
ob.setReturnDate(returnTypeComboBox.getSelectedIndex() == 0); |
|
|
|
|
ob.setStartDate(startDv.update()); |
|
|
|
|
ob.setEndDate(endDv.update()); |
|
|
|
|
|
|
|
|
|