Browse Source

编辑器开发类

remotes/1611766341912730171/master
richie 5 years ago
parent
commit
90ad1f38e1
  1. 276
      src/main/java/com/fanruan/api/design/ui/component/UIDatePicker.java
  2. 20
      src/main/java/com/fanruan/api/design/ui/editor/BaseEditor.java
  3. 75
      src/main/java/com/fanruan/api/design/ui/editor/BaseNumberEditor.java
  4. 65
      src/main/java/com/fanruan/api/design/ui/editor/NoneEditor.java
  5. 14
      src/main/java/com/fanruan/api/design/ui/editor/TextEditor.java
  6. 89
      src/main/java/com/fanruan/api/design/ui/editor/TypeBooleanEditor.java
  7. 114
      src/main/java/com/fanruan/api/design/ui/editor/TypeColumnIndexEditor.java
  8. 78
      src/main/java/com/fanruan/api/design/ui/editor/TypeColumnNameEditor.java
  9. 150
      src/main/java/com/fanruan/api/design/ui/editor/TypeDateEditor.java
  10. 47
      src/main/java/com/fanruan/api/design/ui/editor/TypeDoubleEditor.java
  11. 47
      src/main/java/com/fanruan/api/design/ui/editor/TypeFloatEditor.java
  12. 161
      src/main/java/com/fanruan/api/design/ui/editor/TypeFormulaEditor.java
  13. 48
      src/main/java/com/fanruan/api/design/ui/editor/TypeIntegerEditor.java
  14. 43
      src/main/java/com/fanruan/api/design/ui/editor/TypeLongEditor.java
  15. 63
      src/main/java/com/fanruan/api/design/ui/editor/TypeParameterEditor.java
  16. 146
      src/main/java/com/fanruan/api/design/ui/editor/TypeTextEditor.java
  17. 57
      src/main/java/com/fanruan/api/design/work/component/IntComboBox.java
  18. 84
      src/main/java/com/fanruan/api/design/work/component/ParameterComboBox.java

276
src/main/java/com/fanruan/api/design/ui/component/UIDatePicker.java

@ -0,0 +1,276 @@
package com.fanruan.api.design.ui.component;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.AssistKit;
import com.fanruan.api.util.StringKit;
import com.fr.design.gui.date.JDateDocument;
import com.fr.design.gui.date.SingleObjectComboBoxModel;
import com.fr.design.gui.date.UICalendarPanel;
import com.fr.design.gui.icombobox.UIComboBoxUI;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.plaf.ComboBoxUI;
import javax.swing.plaf.basic.BasicComboPopup;
import javax.swing.plaf.basic.ComboPopup;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/1
*/
public class UIDatePicker extends UIComboBox implements Serializable {
/**
* 日期格式类型
*/
public static final int STYLE_CN_DATE = 0;
public static final int STYLE_CN_DATE1 = 1;
public static final int STYLE_CN_DATETIME = 2;
public static final int STYLE_CN_DATETIME1 = 3;
public static final int STYLE_EN_DATE = 4;
public boolean isWillHide = false;
/**
* 日期格式类型
*/
private int formatStyle = STYLE_CN_DATETIME;
/**
* 当前设置日期格式
*/
private SimpleDateFormat dateFormat = null;
/**
* 只有一个值的ComboBoxModel
*/
private SingleObjectComboBoxModel model = new SingleObjectComboBoxModel();
private JDateDocument dateDocument = null;
public UIDatePicker() throws UnsupportedOperationException {
this(STYLE_CN_DATE);
}
public UIDatePicker(int formatStyle) throws UnsupportedOperationException {
this(formatStyle, new Date());
}
public UIDatePicker(int formatStyle, Date initialDatetime) throws UnsupportedOperationException {
this.setStyle(formatStyle);
//设置可编辑
this.setEditable(true);
this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
//设置编辑器属性(只能输入正确日期)
JTextField textField = ((JTextField) getEditor().getEditorComponent());
textField.setHorizontalAlignment(SwingConstants.CENTER);
dateDocument = new JDateDocument(textField, this.dateFormat);
textField.setDocument(dateDocument);
//设置Model为单值Model
this.setModel(model);
//设置当前选择日期
this.setSelectedItem(initialDatetime == null ? new Date() : initialDatetime);
updateUI();
}
/**
* 设置日期格式
* STYLE_CN_DATE
* STYLE_CN_DATE1
* STYLE_CN_DATETIME
* STYLE_CN_DATETIME1
*
* @param formatStyle int
*/
public void setStyle(int formatStyle) throws UnsupportedOperationException {
this.formatStyle = formatStyle;
dateFormat = getDateFormat(formatStyle);
model.setDateFormat(dateFormat);
if (dateDocument != null) {
dateDocument.setDateFormat(dateFormat);
}
}
/**
* 取得指定类型的日期格式
*
* @param formatStyle int
* @return SimpleDateFormat
* @throws UnsupportedOperationException
*/
private static SimpleDateFormat getDateFormat(int formatStyle) throws
UnsupportedOperationException {
switch (formatStyle) {
case STYLE_CN_DATE:
return new SimpleDateFormat("yyyy/MM/dd");
case STYLE_CN_DATE1:
return new SimpleDateFormat("yyyy-MM-dd");
case STYLE_CN_DATETIME:
return new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
case STYLE_CN_DATETIME1:
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
case STYLE_EN_DATE:
return new SimpleDateFormat("MM/dd/yyyy");
default:
throw new UnsupportedOperationException(
"invalid formatStyle parameter!");
}
}
/**
* 取得日期格式
* STYLE_CN_DATE
* STYLE_CN_DATE1
* STYLE_CN_DATETIME
* STYLE_CN_DATETIME1
*
* @return int
*/
public int getStyle() {
return formatStyle;
}
/**
* 取得当前选择的日期
*
* @return Date
*/
public Date getSelectedDate() throws ParseException {
synchronized (this) {
return dateFormat.parse(getSelectedItem().toString());
}
}
/**
* 设置当前选择的日期
*/
public synchronized void setSelectedDate(Date date) throws ParseException {
if (date == null) {
this.setSelectedItem(null);
} else {
this.setSelectedItem(dateFormat.format(date));
}
}
@Override
public void setSelectedItem(Object anObject) {
model.setSelectedItem(anObject);
super.setSelectedItem(anObject);
}
class DatePopup extends BasicComboPopup implements ChangeListener {
UICalendarPanel calendarPanel = null;
public DatePopup(JComboBox box) {
super(box);
setLayout(new BorderLayout());
calendarPanel = new UICalendarPanel(formatStyle > 1);
calendarPanel.addDateChangeListener(this);
add(calendarPanel, BorderLayout.CENTER);
setBorder(BorderFactory.createEmptyBorder());
}
@Override
public void hide() {
if (isWillHide) {
super.hide();
}
}
@Override
public void show() {
if (isWillHide || !UIDatePicker.this.isEnabled()) {
return;
}
if (calendarPanel != null) {
calendarPanel.resetHMSPaneSelectedNumberField();
}
super.show();
}
/**
* 显示弹出面板
*/
@Override
protected void firePropertyChange(String propertyName,
Object oldValue,
Object newValue) {
if (AssistKit.equals(propertyName, "visible")) {
if (oldValue == Boolean.FALSE && newValue == Boolean.TRUE) { //SHOW
try {
String strDate = comboBox.getSelectedItem().toString();
synchronized (this) {
Date selectionDate = new Date();
if (StringKit.isNotBlank(strDate)) {
selectionDate = dateFormat.parse(strDate);
}
calendarPanel.setSelectedDate(selectionDate);
calendarPanel.updateHMS();
}
} catch (Exception e) {
LogKit.error(e.getMessage(), e);
}
} else if (oldValue == Boolean.TRUE
&& newValue == Boolean.FALSE) {
}
}
super.firePropertyChange(propertyName, oldValue, newValue);
}
public void stateChanged(ChangeEvent e) {
if (calendarPanel.getSelectedDate() != null && dateFormat != null) {
String strDate = dateFormat.format(calendarPanel.getSelectedDate());
if (comboBox.isEditable() && comboBox.getEditor() != null) {
comboBox.configureEditor(comboBox.getEditor(), strDate);
}
comboBox.setSelectedItem(strDate);
}
comboBox.repaint();
setVisible(false);
}
}
@Override
protected ComboBoxUI getUIComboBoxUI() {
return new UIComboBoxUI() {
@Override
protected ComboPopup createPopup() {
return new UIDatePicker.DatePopup(comboBox);
}
@Override
public void mousePressed(MouseEvent e) {
if (UIDatePicker.this.isPopupVisible()) {
isWillHide = true;
UIDatePicker.this.hidePopup();
} else {
isWillHide = false;
UIDatePicker.this.showPopup();
}
}
};
}
//设置dataFormat
public void setDateFormat(SimpleDateFormat format) {
this.dateFormat = format;
}
//获取dateFormat
public SimpleDateFormat getDateFormat() {
return this.dateFormat;
}
public JDateDocument getDateDocument() {
return this.dateDocument;
}
}

20
src/main/java/com/fanruan/api/design/ui/editor/BaseEditor.java

@ -0,0 +1,20 @@
package com.fanruan.api.design.ui.editor;
import com.fr.design.editor.editor.Editor;
import javax.swing.*;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/1
*/
public abstract class BaseEditor<T> extends Editor<T> {
/**
* 返回用于编辑和展示值的swing控件
*
* @return swing控件
*/
public abstract JComponent getSwingComponent();
}

75
src/main/java/com/fanruan/api/design/ui/editor/BaseNumberEditor.java

@ -0,0 +1,75 @@
package com.fanruan.api.design.ui.editor;
import com.fanruan.api.design.ui.component.UINumberField;
import com.fanruan.api.util.StringKit;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/1
* 用于编辑和展示数值的编辑器该类是一个抽象类
*/
public abstract class BaseNumberEditor<T extends Number> extends BaseEditor<T> {
private static final long serialVersionUID = 1L;
protected UINumberField numberField;
protected String oldValue = StringKit.EMPTY;
public BaseNumberEditor() {
this(null, StringKit.EMPTY);
}
public BaseNumberEditor(T value, String name) {
this.setLayout(new BorderLayout());
numberField = new UINumberField();
this.add(numberField, BorderLayout.CENTER);
KeyListener textKeyListener = new KeyAdapter() {
public void keyReleased(KeyEvent evt) {
int code = evt.getKeyCode();
if (code == KeyEvent.VK_ESCAPE) {
numberField.setText(oldValue);
}
if (code == KeyEvent.VK_ENTER) {
fireEditingStopped();
} else {
fireStateChanged();
}
}
};
this.numberField.addKeyListener(textKeyListener);
this.numberField.setHorizontalAlignment(SwingConstants.RIGHT);
this.setValue(value);
this.setName(name);
}
@Override
public UINumberField getSwingComponent() {
return numberField;
}
public void setEnabled(boolean enabled) {
this.numberField.setEnabled(enabled);
}
public void selected() {
this.requestFocus();
}
public String getIconName() {
return "type_double";
}
public void requestFocus() {
this.numberField.requestFocus();
}
}

65
src/main/java/com/fanruan/api/design/ui/editor/NoneEditor.java

@ -0,0 +1,65 @@
package com.fanruan.api.design.ui.editor;
import com.fanruan.api.design.ui.component.UITextField;
import com.fanruan.api.util.StringKit;
import java.awt.*;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/1
* 这是一个占位符编辑器表示不选择值类型
*/
public class NoneEditor extends BaseEditor {
private UITextField textField;
private String displayValue;
public NoneEditor() {
this(null);
}
public NoneEditor(String displayValue, String name) {
this.setLayout(new BorderLayout());
this.displayValue = displayValue;
textField = new UITextField();
this.add(textField, BorderLayout.CENTER);
if (displayValue != null) {
textField.setText(displayValue);
}
textField.setEditable(false);
this.setName(name);
}
public NoneEditor(String displayValue) {
this(displayValue, StringKit.EMPTY);
}
@Override
public UITextField getSwingComponent() {
return textField;
}
@Override
public boolean accept(Object object) {
return false;
}
@Override
public Object getValue() {
return null;
}
@Override
public void setValue(Object value) {
if (displayValue != null) {
textField.setText(displayValue);
textField.setEditable(false);
}
}
public String getIconName() {
return "type_none";
}
}

14
src/main/java/com/fanruan/api/design/ui/editor/TextEditor.java

@ -1,14 +0,0 @@
package com.fanruan.api.design.ui.editor;
/**
* 文本编辑器
* */
public class TextEditor extends com.fr.design.editor.editor.TextEditor{
public TextEditor(){
}
public TextEditor(String value) {
super(value);
}
}

89
src/main/java/com/fanruan/api/design/ui/editor/TypeBooleanEditor.java

@ -0,0 +1,89 @@
package com.fanruan.api.design.ui.editor;
import com.fanruan.api.design.DesignKit;
import com.fanruan.api.design.ui.component.UICheckBox;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/1
* 用于编辑和展示布尔值的编辑器
* TODO:待补充文档
*/
public class TypeBooleanEditor extends BaseEditor<Boolean> {
private UICheckBox booleanCheckBox;
public TypeBooleanEditor() {
this(Boolean.TRUE);
}
public TypeBooleanEditor(boolean b) {
this(Boolean.valueOf(b));
}
public TypeBooleanEditor(Boolean value) {
this.setLayout(new BorderLayout());
booleanCheckBox = new UICheckBox("true");
this.add(booleanCheckBox, BorderLayout.CENTER);
this.setValue(value);
this.setName(DesignKit.i18nText("Fine-Design_Basic_Parameter_Boolean"));
booleanCheckBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
fireStateChanged();
}
});
}
public UICheckBox getSwingComponent() {
return booleanCheckBox;
}
@Override
public Boolean getValue() {
return this.booleanCheckBox.isSelected();
}
@Override
public void setValue(Boolean value) {
if (value == null) {
value = true;
}
this.booleanCheckBox.setSelected(value);
}
@Override
public void setEnabled(boolean enabled) {
this.booleanCheckBox.setEnabled(enabled);
}
@Override
public void requestFocus() {
this.booleanCheckBox.requestFocus();
}
@Override
protected void fireEditingStopped() {
this.setValue(this.booleanCheckBox.isSelected());
super.fireEditingStopped();
}
public String getIconName() {
return "type_bool";
}
@Override
public boolean accept(Object object) {
return object instanceof Boolean;
}
}

114
src/main/java/com/fanruan/api/design/ui/editor/TypeColumnIndexEditor.java

@ -0,0 +1,114 @@
package com.fanruan.api.design.ui.editor;
import com.fanruan.api.design.DesignKit;
import com.fanruan.api.design.work.component.IntComboBox;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/1
* 列序号编辑器里面是一排连续的整数(0-n)
*/
public class TypeColumnIndexEditor extends BaseEditor<Object> {
IntComboBox valueColumnIndexComboBox;
public TypeColumnIndexEditor() {
this(0);
}
/**
* 默认名字是列序号也可以通过第二个构造函数改变
*
* @param value 边界值
*/
public TypeColumnIndexEditor(int value) {
this(value, DesignKit.i18nText("Fine-Design_Basic_Datasource_Column_Index"));
}
public TypeColumnIndexEditor(int value, String name) {
this.setLayout(new BorderLayout(0, 0));
valueColumnIndexComboBox = new IntComboBox();
for (int i = 1; i <= value; i++) {
valueColumnIndexComboBox.addItem(i);
}
if (value > 0) {
valueColumnIndexComboBox.setSelectedInt(1);
}
this.add(valueColumnIndexComboBox, BorderLayout.CENTER);
this.setName(name);
valueColumnIndexComboBox.setBorder(null);
}
@Override
public IntComboBox getSwingComponent() {
return valueColumnIndexComboBox;
}
@Override
public Integer getValue() {
return valueColumnIndexComboBox.getSelectedInt();
}
@Override
public void setValue(Object value) {
valueColumnIndexComboBox.setSelectedInt(value == null ? 0 : Integer.parseInt(value.toString()));
}
public String getIconName() {
return "ds_column_index";
}
/**
* object参数是否是Integer
*
* @param object 传进来用于判断的参数
* @return 返回是否是Index
*/
public boolean accept(Object object) {
return object instanceof Integer;
}
/**
* 增加一个ItemListener
*
* @param l 用于增加的Listener
*/
public void addItemListener(ItemListener l) {
valueColumnIndexComboBox.addItemListener(l);
}
/**
* 增加一个ActionListener
*
* @param l 用于增加的Listener
*/
public void addActionListener(ActionListener l) {
valueColumnIndexComboBox.addActionListener(l);
}
/**
* 重置
*/
public void reset() {
valueColumnIndexComboBox.setSelectedIndex(-1);
}
/**
* 清除所有项
*/
public void clearData() {
valueColumnIndexComboBox.removeAllItems();
}
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
valueColumnIndexComboBox.setEnabled(enabled);
}
}

78
src/main/java/com/fanruan/api/design/ui/editor/TypeColumnNameEditor.java

@ -0,0 +1,78 @@
package com.fanruan.api.design.ui.editor;
import com.fanruan.api.design.DesignKit;
import com.fanruan.api.util.ArrayKit;
import com.fanruan.api.util.StringKit;
import com.fr.design.gui.icombobox.UIComboBoxRenderer;
import javax.swing.*;
import java.awt.*;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/1
* 列编辑器里面是数据集的列名
*/
public class TypeColumnNameEditor extends TypeColumnIndexEditor {
private String[] columnNames;
public TypeColumnNameEditor() {
this(ArrayKit.EMPTY_STRING_ARRAY);
}
public TypeColumnNameEditor(String[] columnNames) {
this(columnNames, DesignKit.i18nText("Fine-Design_Basic_Column_Name"));
}
public TypeColumnNameEditor(final String[] columnNames, String name) {
super(columnNames.length, name);
this.columnNames = columnNames;
valueColumnIndexComboBox.setRenderer(new UIComboBoxRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value == null) {
this.setText("");
} else {
this.setText(columnNames[((Integer) value).intValue() - 1]);
}
return this;
}
});
}
@Override
public void setValue(Object value) {
for (int i = 0; i < columnNames.length; i++) {
if (columnNames[i].equalsIgnoreCase(String.valueOf(value))) {
super.setValue(i + 1);
return;
}
}
super.reset();
}
@Override
public boolean accept(Object object) {
return object instanceof String;
}
public String getColumnName() {
int index = this.getValue() - 1;
return getColumnNameAtIndex(index);
}
public String getColumnNameAtIndex(int index) {
return index >= 0 && columnNames.length > index ? columnNames[index] : StringKit.EMPTY;
}
public String getIconName() {
return "ds_column_name";
}
}

150
src/main/java/com/fanruan/api/design/ui/editor/TypeDateEditor.java

@ -0,0 +1,150 @@
package com.fanruan.api.design.ui.editor;
import com.fanruan.api.design.ui.component.UIDatePicker;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.GeneralKit;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/1
* 用于编辑和展示日期值的编辑器
* TODO:待补充文档
*/
public class TypeDateEditor extends BaseEditor<Date> {
private UIDatePicker uiDatePicker;
public TypeDateEditor() {
this(null);
}
public TypeDateEditor(boolean es) {
this(null, es);
}
public TypeDateEditor(boolean es, String name) {
this(null, es, name);
}
public TypeDateEditor(Date value) {
this(value, false);
}
public TypeDateEditor(Date value, boolean format) {
this(value, format, "");
}
public TypeDateEditor(Date value, boolean format, String name) {
this.setLayout(new BorderLayout());
uiDatePicker = new UIDatePicker();
if (format) {
int dateStyle = (GeneralKit.getLocale() == Locale.ENGLISH
|| GeneralKit.getLocale() == Locale.US
|| GeneralKit.getLocale() == Locale.UK) ? UIDatePicker.STYLE_EN_DATE : UIDatePicker.STYLE_CN_DATE;
uiDatePicker.setStyle(dateStyle);
uiDatePicker.setEditable(false);
}
uiDatePicker.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
fireStateChanged();
}
});
this.uiDatePicker.setFocusTraversalKeysEnabled(false);
this.add(uiDatePicker, BorderLayout.CENTER);
this.setValue(value);
this.setName(name);
}
public TypeDateEditor(Date value, boolean format, String name, int dateFormat) {
this.setLayout(new BorderLayout());
uiDatePicker = new UIDatePicker(dateFormat);
if (format) {
uiDatePicker.setEditable(false);
}
uiDatePicker.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
fireStateChanged();
}
});
this.uiDatePicker.setFocusTraversalKeysEnabled(false);
this.add(uiDatePicker, BorderLayout.CENTER);
this.setValue(value);
this.setName(name);
}
@Override
public UIDatePicker getSwingComponent() {
return uiDatePicker;
}
@Override
public boolean accept(Object object) {
return object instanceof Date;
}
@Override
public Date getValue() {
try {
return this.uiDatePicker.getSelectedDate();
} catch (ParseException parseException) {
LogKit.error(parseException.getMessage(), parseException);
return new Date();
}
}
@Override
public void setValue(Date value) {
if (value == null) {
return;
}
try {
this.uiDatePicker.setSelectedDate(value);
} catch (ParseException parseException) {
LogKit.error(parseException.getMessage(), parseException);
}
}
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
this.uiDatePicker.setEnabled(enabled);
}
public void selected() {
this.uiDatePicker.setSelectedItem(new Date());
}
@Override
public void requestFocus() {
this.uiDatePicker.requestFocus();
}
public String getIconName() {
return "type_date";
}
public void setUIDatePickerStyle(int style) {
this.uiDatePicker.setStyle(style);
}
public SimpleDateFormat getUIDatePickerFormat() {
return this.uiDatePicker.getDateFormat();
}
}

47
src/main/java/com/fanruan/api/design/ui/editor/TypeDoubleEditor.java

@ -0,0 +1,47 @@
package com.fanruan.api.design.ui.editor;
import com.fanruan.api.design.DesignKit;
import com.fr.base.Utils;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/1
* 用于编辑和展示双精度浮点型数值的编辑器
* TODO:待补充文档
*/
public class TypeDoubleEditor extends BaseNumberEditor<Double> {
public TypeDoubleEditor() {
this(0.0);
}
public TypeDoubleEditor(Double value) {
super(value, DesignKit.i18nText("Fine-Design_Basic_Parameter_Double"));
}
@Override
public boolean accept(Object object) {
return object instanceof Double;
}
@Override
public Double getValue() {
return this.numberField.getValue();
}
@Override
public void setValue(Double value) {
if (value == null) {
value = (double) 0;
}
this.numberField.setInteger(false);
this.numberField.setValue(value);
oldValue = Utils.objectToString(value);
}
public String getIconName() {
return "type_double";
}
}

47
src/main/java/com/fanruan/api/design/ui/editor/TypeFloatEditor.java

@ -0,0 +1,47 @@
package com.fanruan.api.design.ui.editor;
import com.fanruan.api.design.DesignKit;
import com.fr.base.Utils;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/1
* 用于编辑和展示单精度浮点型数值的编辑器
* TODO:待补充文档
*/
public class TypeFloatEditor extends BaseNumberEditor<Float> {
public TypeFloatEditor() {
this(0.0f);
}
public TypeFloatEditor(Float value) {
super(value, DesignKit.i18nText("Fine-Design_Basic_Parameter_Float"));
}
@Override
public boolean accept(Object object) {
return object instanceof Float;
}
@Override
public Float getValue() {
return (float) this.numberField.getValue();
}
@Override
public void setValue(Float value) {
if (value == null) {
value = (float) 0;
}
this.numberField.setInteger(false);
this.numberField.setValue(value.doubleValue());
oldValue = Utils.objectToString(value);
}
public String getIconName() {
return "type_double";
}
}

161
src/main/java/com/fanruan/api/design/ui/editor/TypeFormulaEditor.java

@ -0,0 +1,161 @@
package com.fanruan.api.design.ui.editor;
import com.fanruan.api.design.ui.component.UITextField;
import com.fanruan.api.util.StringKit;
import com.fr.base.BaseFormula;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.formula.FormulaFactory;
import com.fr.design.formula.UIFormula;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/1
* 用于编辑和展示公式的编辑器
* TODO:待补充文档
*/
public class TypeFormulaEditor extends BaseEditor<BaseFormula> {
private BaseFormula formula = BaseFormula.createFormulaBuilder().build();
private UITextField currentTextField;
private TypeFormulaEditor.ShowPaneListener listener = new TypeFormulaEditor.ShowPaneListener();
public TypeFormulaEditor() {
this(StringKit.EMPTY);
}
public TypeFormulaEditor(String name) {
this(name, null);
}
public TypeFormulaEditor(String name, BaseFormula formula) {
if (formula != null) {
this.formula = formula;
}
this.setLayout(new BorderLayout());
JPanel editPane = new JPanel(new BorderLayout());
currentTextField = new UITextField(28);
currentTextField.setText(this.formula.getContent());
editPane.add(currentTextField, BorderLayout.CENTER);
currentTextField.setEditable(false);
currentTextField.addMouseListener(listener);
this.add(editPane, BorderLayout.CENTER);
this.setName(name);
}
private class ShowPaneListener extends MouseAdapter {
public void mousePressed(MouseEvent e) {
if (currentTextField.isEnabled()) {
showFormulaPane();
}
}
}
/**
* 选中时弹出公式编辑框
*/
public void selected() {
showFormulaPane();
}
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
currentTextField.setEnabled(enabled);
}
private void showFormulaPane() {
final UIFormula formulaPane = FormulaFactory.createFormulaPaneWhenReserveFormula();
formulaPane.populate(formula);
formulaPane.showLargeWindow(SwingUtilities.getWindowAncestor(TypeFormulaEditor.this), new DialogActionAdapter() {
@Override
public void doOk() {
formula = formulaPane.update();
setValue(formula);
fireStateChanged();
}
}).setVisible(true);
}
public BaseFormula getFormula() {
return formula;
}
@Override
public UITextField getSwingComponent() {
return currentTextField;
}
/**
* object是否是公式类型对象
*
* @param object 需判断的对象
* @return 是公式类型则返回true
*/
public boolean accept(Object object) {
return object instanceof BaseFormula;
}
@Override
public BaseFormula getValue() {
if (formula != null && "=".equals(formula.getContent())) {
return null;
}
return formula;
}
@Override
public void setValue(BaseFormula value) {
if (value == null) {
value = BaseFormula.createFormulaBuilder().build();
}
this.formula = value;
currentTextField.setText(value.toString());
}
public String getIconName() {
return "type_formula";
}
/**
* 重置
*/
public void reset() {
currentTextField.setText("=");
formula = BaseFormula.createFormulaBuilder().build();
}
/**
* 清楚数据
*/
public void clearData() {
reset();
}
/**
* 是否可用
*
* @param flag 为true代表可用
*/
public void enableEditor(boolean flag) {
this.setEnabled(flag);
this.currentTextField.setEnabled(flag);
if (!flag) {
this.currentTextField.removeMouseListener(listener);
} else {
int listenerSize = this.currentTextField.getMouseListeners().length;
for (int i = 0; i < listenerSize; i++) {
this.currentTextField.removeMouseListener(listener);
}
this.currentTextField.addMouseListener(listener);
}
}
}

48
src/main/java/com/fanruan/api/design/ui/editor/TypeIntegerEditor.java

@ -0,0 +1,48 @@
package com.fanruan.api.design.ui.editor;
import com.fanruan.api.design.DesignKit;
import com.fanruan.api.util.GeneralKit;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/1
* 用于编辑和展示整数值的编辑器
* TODO:待补充文档
*/
public class TypeIntegerEditor extends BaseNumberEditor<Integer> {
private static final long serialVersionUID = 1L;
public TypeIntegerEditor() {
this(0);
}
public TypeIntegerEditor(Integer value) {
super(value, DesignKit.i18nText("Fine-Design_Basic_Parameter_Integer"));
}
@Override
public boolean accept(Object object) {
return object instanceof Integer;
}
@Override
public Integer getValue() {
return (int) this.numberField.getValue();
}
@Override
public void setValue(Integer value) {
if (value == null) {
value = 0;
}
this.numberField.setInteger(true);
this.numberField.setValue(value);
oldValue = GeneralKit.objectToString(value);
}
public String getIconName() {
return "type_int";
}
}

43
src/main/java/com/fanruan/api/design/ui/editor/TypeLongEditor.java

@ -0,0 +1,43 @@
package com.fanruan.api.design.ui.editor;
import com.fanruan.api.util.GeneralKit;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/1
* 用于编辑和展示长整型数值的编辑器
* TODO:待补充文档
*/
public class TypeLongEditor extends BaseNumberEditor<Long> {
public TypeLongEditor() {
super();
}
public TypeLongEditor(Long value, String name) {
super(value, name);
}
@Override
public boolean accept(Object object) {
return object instanceof Long;
}
@Override
public Long getValue() {
return (long) (int) this.numberField.getValue();
}
@Override
public void setValue(Long value) {
if (value == null) {
value = 0L;
}
this.numberField.setInteger(true);
this.numberField.setValue(value.intValue());
oldValue = GeneralKit.objectToString(value);
}
}

63
src/main/java/com/fanruan/api/design/ui/editor/TypeParameterEditor.java

@ -0,0 +1,63 @@
package com.fanruan.api.design.ui.editor;
import com.fanruan.api.design.DesignKit;
import com.fanruan.api.design.work.component.ParameterComboBox;
import com.fr.design.editor.editor.Editor;
import com.fr.stable.ParameterProvider;
import java.awt.*;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/1
* 用于编辑和展示参数的编辑器
* TODO:待补充文档
*/
public class TypeParameterEditor extends Editor<ParameterProvider> {
private ParameterComboBox parameterCombobox;
public TypeParameterEditor() {
this(null);
}
public TypeParameterEditor(ParameterProvider parameter) {
parameterCombobox = new ParameterComboBox();
parameterCombobox.setEditable(true);
this.setLayout(new BorderLayout());
this.add(parameterCombobox, BorderLayout.CENTER);
this.setValue(parameter);
this.setName(DesignKit.i18nText("Fine-Design_Basic_Parameter"));
}
@Override
public boolean accept(Object object) {
return object instanceof ParameterProvider;
}
@Override
public ParameterProvider getValue() {
return parameterCombobox.getSelectedItem();
}
@Override
public void setValue(ParameterProvider value) {
parameterCombobox.setSelectedParameter(value);
}
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
parameterCombobox.setEnabled(enabled);
}
@Override
public void requestFocus() {
parameterCombobox.requestFocus();
}
public String getIconName() {
return "parameter";
}
}

146
src/main/java/com/fanruan/api/design/ui/editor/TypeTextEditor.java

@ -0,0 +1,146 @@
package com.fanruan.api.design.ui.editor;
import com.fanruan.api.design.DesignKit;
import com.fanruan.api.design.ui.component.UITextField;
import com.fanruan.api.util.StringKit;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-27
* 用于编辑和展示文本的编辑器
* com.fr.design.editor.editor.Editor是一个可靠的API类
*/
public class TypeTextEditor extends BaseEditor<String> {
private UITextField textField;
private String oldValue = StringKit.EMPTY;
/**
* 创建一个带空值的文本编辑器
*/
public TypeTextEditor() {
this(null);
}
/**
* 创建一个带指定文本值的编辑器
*
* @param value
*/
public TypeTextEditor(String value) {
this.setLayout(new BorderLayout());
textField = new UITextField();
textField.setBorder(null);
this.add(textField, BorderLayout.CENTER);
KeyListener textKeyListener = new KeyAdapter() {
@Override
public void keyReleased(KeyEvent evt) {
int code = evt.getKeyCode();
if (code == KeyEvent.VK_ESCAPE) {
textField.setText(oldValue);
}
if (code == KeyEvent.VK_ENTER) {
fireEditingStopped();
} else {
fireStateChanged();
}
}
};
this.textField.addKeyListener(textKeyListener);
this.setValue(value);
this.setName(DesignKit.i18nText("Fine-Design_Basic_Parameter_String"));
}
/**
* 获取用于编辑和展示文本的源控件是一个swing控件
*
* @return swing控件
*/
public final UITextField getSwingComponent() {
return this.textField;
}
/**
* 判断编辑器是否接受指定类型的值
*
* @param object 待接收的值
* @return 文本编辑器只接收文本类型的值如果该值为文本类型则返回true否则返回false
*/
@Override
public boolean accept(Object object) {
return object instanceof String;
}
/**
* 获取编辑器中的文本内容
*
* @return 编辑器的值
*/
@Override
public final String getValue() {
return this.textField.getText();
}
/**
* 设置编辑器的文本内容
*
* @param value 待设置的文本内容
*/
@Override
public final void setValue(String value) {
if (value == null) {
value = StringKit.EMPTY;
}
oldValue = value;
this.textField.setText(oldValue);
}
/**
* 设置编辑器的可用性
*
* @param enabled true表示可以使用false表示被禁用无法输入
*/
@Override
public final void setEnabled(boolean enabled) {
super.setEnabled(enabled);
this.textField.setEnabled(enabled);
}
@Override
public final void requestFocus() {
this.textField.requestFocus();
}
/**
* 被选中时文本输入框请求焦点
*/
@Override
public void selected() {
this.textField.requestFocus();
}
@Override
public String getIconName() {
return "type_string";
}
/**
* 清楚编辑器中的所有值
*/
@Override
public void clearData() {
super.clearData();
this.textField.setText(StringKit.EMPTY);
this.oldValue = StringKit.EMPTY;
}
}

57
src/main/java/com/fanruan/api/design/work/component/IntComboBox.java

@ -0,0 +1,57 @@
package com.fanruan.api.design.work.component;
import com.fanruan.api.design.ui.component.UIComboBox;
import com.fr.design.gui.icombobox.UIComboBoxRenderer;
import javax.swing.*;
import java.awt.*;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/1
* 用于选择和展示整数的下拉框
*/
public class IntComboBox extends UIComboBox {
public IntComboBox() {
init();
}
public IntComboBox(Integer[] data) {
ComboBoxModel<Integer> model = new DefaultComboBoxModel<>(data);
setModel(model);
init();
}
private void init() {
this.setRenderer(new UIComboBoxRenderer() {
public Component getListCellRendererComponent(JList list,
Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof Integer) {
this.setText(" " + value + " ");
}
return this;
}
});
}
public int getSelectedInt() {
if (this.getSelectedItem() == null) {
return -1;
}
return (Integer) this.getSelectedItem();
}
public void setSelectedInt(int selectedInt) {
int index = -1;
for (int i = 0; i < this.getItemCount(); i++) {
if ((Integer) this.getItemAt(i) == selectedInt) {
index = i;
break;
}
}
this.setSelectedIndex(index);
}
}

84
src/main/java/com/fanruan/api/design/work/component/ParameterComboBox.java

@ -0,0 +1,84 @@
package com.fanruan.api.design.work.component;
import com.fanruan.api.cal.ParameterKit;
import com.fanruan.api.design.ui.component.UIComboBox;
import com.fanruan.api.util.AssistKit;
import com.fr.design.DesignModelAdapter;
import com.fr.stable.ParameterProvider;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
/**
* @author richie
* @version 10.0
* Created by richie on 2019/11/1
* 参数选择下拉框
*/
public class ParameterComboBox extends UIComboBox<ParameterProvider> {
public ParameterComboBox() {
this.initComponents();
}
private void initComponents() {
this.setRenderer(new DefaultListCellRenderer() {
public Component getListCellRendererComponent(JList list,
Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof ParameterProvider) {
this.setText(value.toString());
}
return this;
}
});
updateParaItems();
}
public void updateParaItems() {
DesignModelAdapter<?, ?> designModel = DesignModelAdapter.getCurrentModelAdapter();
this.removeAllItems();
if (designModel != null) {
ParameterProvider[] paras = designModel.getParameters();
List<String> paraNameList = new ArrayList<String>();
for (int i = 0; i < paras.length; i++) {
String paraName = paras[i].getName();
if (!paraNameList.contains(paraName)) {
paraNameList.add(paraName);
this.addItem(paras[i]);
}
}
}
}
@Override
public ParameterProvider getSelectedItem() {
if (super.getSelectedItem() instanceof ParameterProvider) {
return (ParameterProvider) super.getSelectedItem();
} else if (super.getSelectedItem() instanceof String && ((String) super.getSelectedItem()).startsWith("$")) {
return ParameterKit.newParameter(((String) super.getSelectedItem()).substring(1));
}
return ParameterKit.newParameter();
}
public void setSelectedParameter(ParameterProvider parameter) {
if (parameter == null) {
return;
}
for (int i = 0; i < this.getItemCount(); i++) {
if (AssistKit.equals(((ParameterProvider) this.getItemAt(i)).getName(), parameter.getName())) {
this.setSelectedIndex(i);
return;
}
}
this.addItem(parameter);
this.setSelectedItem(parameter);
}
}
Loading…
Cancel
Save