Browse Source

增加新的编辑器开放类

pull/29/head
richie 5 years ago
parent
commit
74b990c046
  1. 86
      src/main/java/com/fanruan/api/design/ui/editor/TypeColumnRowEditor.java
  2. 86
      src/main/java/com/fanruan/api/design/ui/editor/TypeColumnRowGroupEditor.java
  3. 111
      src/main/java/com/fanruan/api/design/ui/editor/TypeColumnTableDataEditor.java

86
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<ColumnRow> {
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);
}
}

86
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<ColumnRowGroup> {
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";
}
}

111
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<SimpleDSColumn> {
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<String> 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);
}
}
Loading…
Cancel
Save