From 74b990c046bcd5f0057e27a30ad6f278e7e9efe2 Mon Sep 17 00:00:00 2001 From: richie Date: Mon, 4 Nov 2019 09:26:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=B0=E7=9A=84=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=99=A8=E5=BC=80=E6=94=BE=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/ui/editor/TypeColumnRowEditor.java | 86 ++++++++++++++ .../ui/editor/TypeColumnRowGroupEditor.java | 86 ++++++++++++++ .../ui/editor/TypeColumnTableDataEditor.java | 111 ++++++++++++++++++ 3 files changed, 283 insertions(+) create mode 100644 src/main/java/com/fanruan/api/design/ui/editor/TypeColumnRowEditor.java create mode 100644 src/main/java/com/fanruan/api/design/ui/editor/TypeColumnRowGroupEditor.java create mode 100644 src/main/java/com/fanruan/api/design/ui/editor/TypeColumnTableDataEditor.java diff --git a/src/main/java/com/fanruan/api/design/ui/editor/TypeColumnRowEditor.java b/src/main/java/com/fanruan/api/design/ui/editor/TypeColumnRowEditor.java new file mode 100644 index 0000000..dd4d441 --- /dev/null +++ b/src/main/java/com/fanruan/api/design/ui/editor/TypeColumnRowEditor.java @@ -0,0 +1,86 @@ +package com.fanruan.api.design.ui.editor; + +import com.fanruan.api.util.StringKit; +import com.fr.design.gui.columnrow.ColumnRowPane; +import com.fr.stable.ColumnRow; + +import javax.swing.*; +import java.awt.*; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019/11/4 + * 用于编辑和展示单元格坐标的编辑器 + */ +public class TypeColumnRowEditor extends BaseEditor { + + private ColumnRowPane crPane; + + public TypeColumnRowEditor() { + this(StringKit.EMPTY); + } + + public TypeColumnRowEditor(String name) { + this(null, name); + } + + public TypeColumnRowEditor(ColumnRow value) { + this(value, StringKit.EMPTY); + } + + public TypeColumnRowEditor(ColumnRow value, String name) { + this.setLayout(new BorderLayout()); + crPane = new ColumnRowPane(); + this.add(crPane, BorderLayout.CENTER); + this.setValue(value); + this.setName(name); + } + + @Override + public JComponent getSwingComponent() { + return crPane; + } + + @Override + public ColumnRow getValue() { + return this.crPane.update(); + } + + @Override + public void setValue(ColumnRow value) { + if (value == null) { + value = ColumnRow.valueOf(0, 0); + } + + this.crPane.populate(value); + } + + @Override + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + + this.crPane.setEnabled(enabled); + } + + @Override + public void requestFocus() { + this.crPane.requestFocus(); + } + + @Override + public String getIconName() { + return "cell"; + } + + @Override + public boolean accept(Object object) { + return object instanceof ColumnRow; + } + + @Override + public void clearData() { + super.clearData(); + this.setValue(null); + } +} \ No newline at end of file diff --git a/src/main/java/com/fanruan/api/design/ui/editor/TypeColumnRowGroupEditor.java b/src/main/java/com/fanruan/api/design/ui/editor/TypeColumnRowGroupEditor.java new file mode 100644 index 0000000..d2f11d5 --- /dev/null +++ b/src/main/java/com/fanruan/api/design/ui/editor/TypeColumnRowGroupEditor.java @@ -0,0 +1,86 @@ +package com.fanruan.api.design.ui.editor; + +import com.fanruan.api.design.ui.component.UITextField; +import com.fanruan.api.util.StringKit; +import com.fr.stable.ColumnRowGroup; + +import javax.swing.*; +import java.awt.*; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019/11/4 + * 用于编辑和展示行列集合的编辑器 + */ +public class TypeColumnRowGroupEditor extends BaseEditor { + + private UITextField crEditor; + + public TypeColumnRowGroupEditor() { + this(StringKit.EMPTY); + } + + public TypeColumnRowGroupEditor(String name) { + this(null, name); + } + + public TypeColumnRowGroupEditor(ColumnRowGroup value) { + this(value, StringKit.EMPTY); + } + + public TypeColumnRowGroupEditor(ColumnRowGroup value, String name) { + this.setLayout(new BorderLayout()); + crEditor = new UITextField(); + this.add(crEditor, BorderLayout.CENTER); + this.setValue(value); + this.setName(name); + } + + @Override + public JComponent getSwingComponent() { + return crEditor; + } + + /** + * 是否接收/支持这个对象 + * + * @param object 检测对象 + * @return 是否支持 + */ + public boolean accept(Object object) { + return object instanceof ColumnRowGroup; + } + + @Override + public ColumnRowGroup getValue() { + return new ColumnRowGroup(this.crEditor.getText()); + } + + @Override + public void setValue(ColumnRowGroup value) { + if (value == null) { + this.crEditor.setText(StringKit.EMPTY); + } else { + this.crEditor.setText(value.toString()); + } + } + + @Override + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + + this.crEditor.setEnabled(enabled); + } + + /** + * 获取焦点 + */ + public void requestFocus() { + this.crEditor.requestFocus(); + } + + public String getIconName() { + return "cell_group"; + } +} diff --git a/src/main/java/com/fanruan/api/design/ui/editor/TypeColumnTableDataEditor.java b/src/main/java/com/fanruan/api/design/ui/editor/TypeColumnTableDataEditor.java new file mode 100644 index 0000000..92159f5 --- /dev/null +++ b/src/main/java/com/fanruan/api/design/ui/editor/TypeColumnTableDataEditor.java @@ -0,0 +1,111 @@ +package com.fanruan.api.design.ui.editor; + +import com.fanruan.api.design.DesignKit; +import com.fanruan.api.design.ui.component.UIComboBox; +import com.fanruan.api.util.StringKit; +import com.fr.data.SimpleDSColumn; +import com.fr.design.data.DesignTableDataManager; +import com.fr.design.data.datapane.TableDataComboBox; +import com.fr.design.data.tabledata.wrapper.TableDataWrapper; +import com.fr.general.data.TableDataColumn; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.List; +import java.util.regex.Pattern; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019/11/4 + * 用于编辑和展示数据集列的编辑器 + */ +public class TypeColumnTableDataEditor extends BaseEditor { + private TableDataComboBox tableDataComboBox; + private UIComboBox columnNameComboBox; + private String[] columnNames; + + public TypeColumnTableDataEditor() { + this.setName(DesignKit.i18nText("Fine-Design_Basic_DS_Column")); + this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); + tableDataComboBox = new TableDataComboBox(DesignTableDataManager.getEditingTableDataSource()); + columnNames = new String[0]; + tableDataComboBox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + if (tableDataComboBox.getSelectedItem() == null) { + return; + } + List nameList = tableDataComboBox.getSelectedItem().calculateColumnNameList(); + columnNames = new String[nameList.size()]; + columnNames = tableDataComboBox.getSelectedItem().calculateColumnNameList().toArray(columnNames); + columnNameComboBox.removeAllItems(); + for (int i = 0; i < columnNames.length; i++) { + columnNameComboBox.addItem(columnNames[i]); + } + columnNameComboBox.validate(); + } + }); + columnNameComboBox = new UIComboBox(); + tableDataComboBox.setPreferredSize(new Dimension(82, 20)); + this.add(tableDataComboBox); + columnNameComboBox.setPreferredSize(new Dimension(82, 20)); + this.add(columnNameComboBox); + } + + @Override + public JComponent getSwingComponent() { + return columnNameComboBox; + } + + @Override + public SimpleDSColumn getValue() { + if (this.tableDataComboBox.getSelectedItem() == null || this.columnNameComboBox.getSelectedItem() == null) { + return null; + } + SimpleDSColumn dsColumn = new SimpleDSColumn(); + TableDataWrapper item = this.tableDataComboBox.getSelectedItem(); + dsColumn.setDsName(item.getTableDataName()); + TableDataColumn column; + String columnExp = (String) this.columnNameComboBox.getSelectedItem(); + if (StringKit.isNotBlank(columnExp) && (columnExp.length() > 0 && columnExp.charAt(0) == '#') && !columnExp.endsWith("#")) { + String number = columnExp.substring(1); + Pattern pattern = Pattern.compile("[^\\d]"); + if (pattern.matcher(number).find()) { + column = TableDataColumn.createColumn(columnExp); + } else { + int serialNumber = Integer.parseInt(columnExp.substring(1)); + column = TableDataColumn.createColumn(serialNumber); + } + } else { + column = TableDataColumn.createColumn(columnExp); + } + dsColumn.setColumn(column); + return dsColumn; + } + + public String getIconName() { + return "ds_column"; + } + + @Override + public boolean accept(Object object) { + return object instanceof SimpleDSColumn; + } + + @Override + public void setValue(SimpleDSColumn value) { + if (value != null) { + tableDataComboBox.setSelectedTableDataByName(value.getDsName()); + columnNameComboBox.setSelectedItem(TableDataColumn.getColumnName(value.getColumn())); + } + } + + @Override + public void clearData() { + tableDataComboBox.setSelectedItem(null); + columnNameComboBox.setSelectedItem(null); + } +}