|
|
|
@ -3,10 +3,7 @@ package com.fr.design.widget.ui.designer;
|
|
|
|
|
import com.fr.base.FRContext; |
|
|
|
|
import com.fr.base.Formula; |
|
|
|
|
import com.fr.data.core.FormatField; |
|
|
|
|
import com.fr.design.constants.LayoutConstants; |
|
|
|
|
import com.fr.design.designer.creator.XCreator; |
|
|
|
|
import com.fr.design.editor.ValueEditorPane; |
|
|
|
|
import com.fr.design.editor.ValueEditorPaneFactory; |
|
|
|
|
import com.fr.design.gui.ibutton.UIHeadGroup; |
|
|
|
|
import com.fr.design.gui.icombobox.UIComboBox; |
|
|
|
|
import com.fr.design.gui.ilable.UILabel; |
|
|
|
@ -14,14 +11,13 @@ import com.fr.design.gui.ispinner.UISpinner;
|
|
|
|
|
import com.fr.design.layout.FRGUIPaneFactory; |
|
|
|
|
import com.fr.design.layout.TableLayout; |
|
|
|
|
import com.fr.design.layout.TableLayoutHelper; |
|
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
|
import com.fr.design.widget.component.DateValuePane; |
|
|
|
|
import com.fr.design.widget.ui.designer.component.FormWidgetValuePane; |
|
|
|
|
import com.fr.form.ui.DateEditor; |
|
|
|
|
import com.fr.general.DateUtils; |
|
|
|
|
import com.fr.general.Inter; |
|
|
|
|
import com.fr.script.Calculator; |
|
|
|
|
import com.fr.stable.ArrayUtils; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
import com.fr.stable.UtilEvalError; |
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
@ -32,15 +28,15 @@ import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
|
|
public class DateEditorDefinePane extends DirectWriteEditorDefinePane<DateEditor> { |
|
|
|
|
private UIComboBox returnTypeComboBox; |
|
|
|
|
private UILabel sampleLabel;// preview
|
|
|
|
|
private UIComboBox dateFormatComboBox; |
|
|
|
|
private ValueEditorPane startDv; |
|
|
|
|
private ValueEditorPane endDv; |
|
|
|
|
private UIHeadGroup returnTypeComboBox; |
|
|
|
|
private DateValuePane startDv; |
|
|
|
|
private DateValuePane endDv; |
|
|
|
|
private WaterMarkDictPane waterMarkDictPane; |
|
|
|
|
private FormWidgetValuePane formWidgetValuePane; |
|
|
|
|
private UISpinner fontSizePane; |
|
|
|
|
private UIHeadGroup formatHeader; |
|
|
|
|
private UIComboBox currentFormatComboBox; |
|
|
|
|
private UILabel currentSamplelabel; |
|
|
|
|
private UIHeadGroup fomatHeadGroup; |
|
|
|
|
|
|
|
|
|
public DateEditorDefinePane(XCreator xCreator) { |
|
|
|
|
super(xCreator); |
|
|
|
@ -59,35 +55,20 @@ public class DateEditorDefinePane extends DirectWriteEditorDefinePane<DateEditor
|
|
|
|
|
fontSizePane = new UISpinner(0, 20, 1, 0); |
|
|
|
|
JPanel returnTypePane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
|
|
|
returnTypePane.add(new UILabel(Inter.getLocText("Widget-Date_Selector_Return_Type") + ":"), BorderLayout.WEST); |
|
|
|
|
returnTypeComboBox = new UIComboBox(new String[]{Inter.getLocText("String"), Inter.getLocText("Date")}); |
|
|
|
|
returnTypeComboBox.setPreferredSize(new Dimension(70, 20)); |
|
|
|
|
// sample pane
|
|
|
|
|
sampleLabel = new UILabel(""); |
|
|
|
|
sampleLabel.setBorder(BorderFactory.createEmptyBorder(2, 4, 4, 4)); |
|
|
|
|
sampleLabel.setHorizontalAlignment(SwingConstants.CENTER); |
|
|
|
|
sampleLabel.setFont(FRContext.getDefaultValues().getFRFont()); |
|
|
|
|
JPanel previewPane = FRGUIPaneFactory.createTitledBorderPane("示例"); |
|
|
|
|
previewPane.add(sampleLabel); |
|
|
|
|
// content pane
|
|
|
|
|
String[] arr = getDateFormateArray(); |
|
|
|
|
dateFormatComboBox = new UIComboBox(arr); |
|
|
|
|
dateFormatComboBox.setPreferredSize(new Dimension(150, 20)); |
|
|
|
|
dateFormatComboBox.addActionListener(new ActionListener() { |
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
refreshPreviewLabel(); |
|
|
|
|
returnTypeComboBox = new UIHeadGroup(new String[] {Inter.getLocText("Date") , Inter.getLocText("String")}){ |
|
|
|
|
protected void tabChanged(int newSelectedIndex) { |
|
|
|
|
//todo
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
JPanel formatHead = createFormatHead(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
startDv = ValueEditorPaneFactory.createDateValueEditorPane(null, null); |
|
|
|
|
endDv = ValueEditorPaneFactory.createDateValueEditorPane(null, null); |
|
|
|
|
initFormatHeader(); |
|
|
|
|
|
|
|
|
|
startDv = new DateValuePane(); |
|
|
|
|
endDv = new DateValuePane(); |
|
|
|
|
double f = TableLayout.FILL; |
|
|
|
|
double p = TableLayout.PREFERRED; |
|
|
|
|
Component[][] components = new Component[][]{ |
|
|
|
|
new Component[]{new UILabel(Inter.getLocText("FR-Designer-Estate_Widget_Value")), formWidgetValuePane}, |
|
|
|
|
new Component[]{new UILabel(Inter.getLocText("FR-Engine_Format") + ":"), dateFormatComboBox}, |
|
|
|
|
new Component[]{null, previewPane}, |
|
|
|
|
new Component[]{new UILabel(Inter.getLocText("FR-Engine_Format") + ":"), formatHead}, |
|
|
|
|
new Component[]{new UILabel(Inter.getLocText("FS_Start_Date") + ":"), startDv}, |
|
|
|
|
new Component[]{new UILabel(Inter.getLocText("FS_End_Date") + ":"), endDv}, |
|
|
|
|
new Component[]{new UILabel(Inter.getLocText("FR-Designer_WaterMark") + ":"), waterMarkDictPane}, |
|
|
|
@ -95,43 +76,80 @@ public class DateEditorDefinePane extends DirectWriteEditorDefinePane<DateEditor
|
|
|
|
|
new Component[]{new UILabel(Inter.getLocText("Widget-Date_Selector_Return_Type") + ":"), returnTypeComboBox} |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
double[] rowSize = {p, p, p, p, p, p, p, p, p, p}; |
|
|
|
|
double[] rowSize = {p, 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}, {1, 1}, {1, 1}}; |
|
|
|
|
JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, 10, 7); |
|
|
|
|
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
|
|
|
|
|
|
|
|
|
return panel; |
|
|
|
|
int[][] rowCount = {{1, 3}, {1, 3}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}}; |
|
|
|
|
JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, 10, 10); |
|
|
|
|
JPanel boundsPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
|
|
|
panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0)); |
|
|
|
|
boundsPane.add(panel); |
|
|
|
|
return boundsPane; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void initFormatHeader() { |
|
|
|
|
String [] tabTitles = getDateFormateArray(); |
|
|
|
|
formatHeader = new UIHeadGroup(tabTitles){ |
|
|
|
|
protected void tabChanged(int newSelectedIndex) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
private JPanel createFormatPane(UIComboBox formatComboBox, UILabel sampleLabel){ |
|
|
|
|
JPanel previewPane = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("FR-Base_StyleFormat_Sample")); |
|
|
|
|
previewPane.add(sampleLabel); |
|
|
|
|
JPanel jPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); |
|
|
|
|
jPanel.add(previewPane, BorderLayout.NORTH); |
|
|
|
|
jPanel.add(formatComboBox, BorderLayout.CENTER); |
|
|
|
|
return jPanel; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String[] getDateFormateArray() { |
|
|
|
|
return FormatField.getInstance().getDateFormatArray(); |
|
|
|
|
private UILabel createSamplePane(){ |
|
|
|
|
UILabel sampleLabel = new UILabel(""); |
|
|
|
|
sampleLabel.setHorizontalAlignment(SwingConstants.CENTER); |
|
|
|
|
sampleLabel.setFont(FRContext.getDefaultValues().getFRFont()); |
|
|
|
|
return sampleLabel; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected JPanel initStartEndDatePane() { |
|
|
|
|
JPanel rangePane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); |
|
|
|
|
rangePane.add(new UILabel(Inter.getLocText("FS_Start_Date") + ":")); |
|
|
|
|
startDv = ValueEditorPaneFactory.createDateValueEditorPane(null, null); |
|
|
|
|
rangePane.add(startDv); |
|
|
|
|
rangePane.add(new UILabel(Inter.getLocText("FS_End_Date") + ":")); |
|
|
|
|
endDv = ValueEditorPaneFactory.createDateValueEditorPane(null, null); |
|
|
|
|
rangePane.add(endDv); |
|
|
|
|
|
|
|
|
|
return rangePane; |
|
|
|
|
private JPanel createFormatHead(){ |
|
|
|
|
String[] dateArray = FormatField.getInstance().getFormatArray(FormatField.FormatContents.DATE); |
|
|
|
|
String[] timeArray = FormatField.getInstance().getFormatArray(FormatField.FormatContents.TIME); |
|
|
|
|
final UIComboBox dateFormatComboBox = new UIComboBox(dateArray); |
|
|
|
|
final UIComboBox timeFormatComboBox = new UIComboBox(timeArray); |
|
|
|
|
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, Inter.getLocText("StyleFormat-Date")); |
|
|
|
|
customPane.add(timeFormatPane, Inter.getLocText("StyleFormat-Time")); |
|
|
|
|
final String[] tabTitles = new String[]{Inter.getLocText("StyleFormat-Date"), Inter.getLocText("StyleFormat-Time")}; |
|
|
|
|
fomatHeadGroup = new UIHeadGroup(new String[]{Inter.getLocText("StyleFormat-Date"), Inter.getLocText("StyleFormat-Time")}){ |
|
|
|
|
protected void tabChanged(int newSelectedIndex) { |
|
|
|
|
cardLayout.show(customPane, tabTitles[newSelectedIndex]); |
|
|
|
|
if(newSelectedIndex == 0){ |
|
|
|
|
currentFormatComboBox = dateFormatComboBox; |
|
|
|
|
currentSamplelabel = dateSampleLabel; |
|
|
|
|
}else{ |
|
|
|
|
currentFormatComboBox = timeFormatComboBox; |
|
|
|
|
currentSamplelabel = timeSampleLabel; |
|
|
|
|
} |
|
|
|
|
refreshPreviewLabel(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
fomatHeadPane.add(fomatHeadGroup, BorderLayout.NORTH); |
|
|
|
|
fomatHeadPane.add(customPane, BorderLayout.CENTER); |
|
|
|
|
return fomatHeadPane; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void refreshPreviewLabel() { |
|
|
|
|
String text = (String) dateFormatComboBox.getSelectedItem(); |
|
|
|
|
String text = (String) currentFormatComboBox.getSelectedItem(); |
|
|
|
|
if (text != null && text.length() > 0) { |
|
|
|
|
try { |
|
|
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(text); |
|
|
|
@ -141,25 +159,28 @@ public class DateEditorDefinePane extends DirectWriteEditorDefinePane<DateEditor
|
|
|
|
|
sample += " " + Inter.getLocText("DateFormat-Custom_Warning"); |
|
|
|
|
c = Color.red; |
|
|
|
|
} |
|
|
|
|
this.sampleLabel.setText(sample); |
|
|
|
|
this.sampleLabel.setForeground(c); |
|
|
|
|
currentSamplelabel.setText(sample); |
|
|
|
|
currentSamplelabel.setForeground(c); |
|
|
|
|
} catch (Exception exp) { |
|
|
|
|
this.sampleLabel.setForeground(Color.red); |
|
|
|
|
this.sampleLabel.setText(exp.getMessage()); |
|
|
|
|
currentSamplelabel.setForeground(Color.red); |
|
|
|
|
currentSamplelabel.setText(exp.getMessage()); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
this.sampleLabel.setText(new Date().toString()); |
|
|
|
|
currentSamplelabel.setText(new Date().toString()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void populateSubDirectWriteEditorBean(DateEditor e) { |
|
|
|
|
String formatText = e.getFormatText(); |
|
|
|
|
dateFormatComboBox.setSelectedItem(formatText); |
|
|
|
|
fomatHeadGroup.setSelectedIndex(getDateType(e)); |
|
|
|
|
currentFormatComboBox.setSelectedItem(formatText); |
|
|
|
|
|
|
|
|
|
returnTypeComboBox.setSelectedIndex(e.isReturnDate() ? 1 : 0); |
|
|
|
|
returnTypeComboBox.setSelectedIndex(e.isReturnDate() ? 0 : 1); |
|
|
|
|
formWidgetValuePane.populate(e); |
|
|
|
|
populateStartEnd(e); |
|
|
|
|
startDv.populate(e.getStartDate()); |
|
|
|
|
endDv.populate(e.getEndDate()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -167,34 +188,14 @@ public class DateEditorDefinePane extends DirectWriteEditorDefinePane<DateEditor
|
|
|
|
|
DateEditor ob = new DateEditor(); |
|
|
|
|
|
|
|
|
|
ob.setFormatText(this.getSimpleDateFormat().toPattern()); |
|
|
|
|
ob.setReturnDate(returnTypeComboBox.getSelectedIndex() == 1); |
|
|
|
|
ob.setReturnDate(returnTypeComboBox.getSelectedIndex() == 0); |
|
|
|
|
formWidgetValuePane.update(ob); |
|
|
|
|
updateStartEnd(ob); |
|
|
|
|
ob.setStartDate(startDv.update()); |
|
|
|
|
ob.setEndDate(endDv.update()); |
|
|
|
|
|
|
|
|
|
return ob; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 初始起止日期 |
|
|
|
|
* |
|
|
|
|
* @param dateWidgetEditor 日期控件 |
|
|
|
|
*/ |
|
|
|
|
public void populateStartEnd(DateEditor dateWidgetEditor) { |
|
|
|
|
Formula startFM = dateWidgetEditor.getStartDateFM(); |
|
|
|
|
Formula endFM = dateWidgetEditor.getEndDateFM(); |
|
|
|
|
if (startFM != null) { |
|
|
|
|
startDv.populate(startFM); |
|
|
|
|
} else { |
|
|
|
|
String startStr = dateWidgetEditor.getStartText(); |
|
|
|
|
startDv.populate(StringUtils.isEmpty(startStr) ? null : DateUtils.string2Date(startStr, true)); |
|
|
|
|
} |
|
|
|
|
if (endFM != null) { |
|
|
|
|
endDv.populate(endFM); |
|
|
|
|
} else { |
|
|
|
|
String endStr = dateWidgetEditor.getEndText(); |
|
|
|
|
endDv.populate(StringUtils.isEmpty(endStr) ? null : DateUtils.string2Date(endStr, true)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 更新日期控件的起止日期 |
|
|
|
@ -245,12 +246,12 @@ public class DateEditorDefinePane extends DirectWriteEditorDefinePane<DateEditor
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private SimpleDateFormat getSimpleDateFormat() { |
|
|
|
|
String text = (String) dateFormatComboBox.getSelectedItem(); |
|
|
|
|
String text = (String) currentFormatComboBox.getSelectedItem(); |
|
|
|
|
SimpleDateFormat simpleDateFormat; |
|
|
|
|
if (text != null && text.length() > 0) { |
|
|
|
|
try { |
|
|
|
|
simpleDateFormat = new SimpleDateFormat(text); |
|
|
|
|
this.sampleLabel.setText(simpleDateFormat.format(new Date())); |
|
|
|
|
this.currentSamplelabel.setText(simpleDateFormat.format(new Date())); |
|
|
|
|
} catch (Exception exp) { |
|
|
|
|
simpleDateFormat = new SimpleDateFormat(""); |
|
|
|
|
} |
|
|
|
@ -262,4 +263,16 @@ public class DateEditorDefinePane extends DirectWriteEditorDefinePane<DateEditor
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private int getDateType(DateEditor e){ |
|
|
|
|
String[] timeArray = FormatField.getInstance().getFormatArray(FormatField.FormatContents.TIME); |
|
|
|
|
if(e == null){ |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
String formatText = e.getFormatText(); |
|
|
|
|
if(ArrayUtils.contains(timeArray, formatText)){ |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |