diff --git a/designer-base/src/main/java/com/fr/design/icon/BorderIcon.java b/designer-base/src/main/java/com/fr/design/icon/BorderIcon.java index 3afc423be1..8250cd7022 100644 --- a/designer-base/src/main/java/com/fr/design/icon/BorderIcon.java +++ b/designer-base/src/main/java/com/fr/design/icon/BorderIcon.java @@ -85,9 +85,9 @@ public class BorderIcon implements Icon { cellBorderStyle.getBottomColor()); drawLine(gr, x1, y1, x1, y2, cellBorderStyle.getLeftStyle(), cellBorderStyle.getLeftColor()); - drawLine(gr, defaultWidth / 2, y1, defaultWidth / 2, y2, + drawLine(gr, defaultWidth / 2.0, y1, defaultWidth / 2.0, y2, cellBorderStyle.getVerticalStyle(), cellBorderStyle.getVerticalColor()); - drawLine(gr, x1, defaultHeight / 2, x2, defaultHeight / 2, + drawLine(gr, x1, defaultHeight / 2.0, x2, defaultHeight / 2.0, cellBorderStyle.getHorizontalStyle(), cellBorderStyle.getHorizontalColor()); } diff --git a/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoTest.java b/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoTest.java index 19f6066ff8..426dba3b1d 100644 --- a/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoTest.java +++ b/designer-base/src/test/java/com/fr/design/mainframe/template/info/TemplateInfoTest.java @@ -54,7 +54,7 @@ public class TemplateInfoTest { TemplateInfo templateInfo = TemplateInfo.newInstance(templateID); assertEquals(templateID, templateInfo.getTemplateID()); assertEquals(StringUtils.EMPTY, Reflect.on(templateInfo).field("originID").get()); - assertEquals(0, Reflect.on(templateInfo).field("idleDayCount").get()); + assertEquals(0, (int) Reflect.on(templateInfo).field("idleDayCount").get()); assertEquals("{}", templateInfo.getProcessMapJsonString()); Map consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); @@ -77,7 +77,7 @@ public class TemplateInfoTest { TemplateInfo templateInfo = TemplateInfo.newInstance(templateID, originID, originTime); assertEquals(templateID, templateInfo.getTemplateID()); assertEquals(originID, Reflect.on(templateInfo).field("originID").get()); - assertEquals(0, Reflect.on(templateInfo).field("idleDayCount").get()); + assertEquals(0, (int) Reflect.on(templateInfo).field("idleDayCount").get()); assertEquals("{}", templateInfo.getProcessMapJsonString()); Map consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); diff --git a/designer-chart/src/main/java/com/fr/design/chartx/component/MapAreaMatchPane.java b/designer-chart/src/main/java/com/fr/design/chartx/component/MapAreaMatchPane.java new file mode 100644 index 0000000000..708b993652 --- /dev/null +++ b/designer-chart/src/main/java/com/fr/design/chartx/component/MapAreaMatchPane.java @@ -0,0 +1,301 @@ +package com.fr.design.chartx.component; + +import com.fr.base.BaseUtils; +import com.fr.base.ParameterMapNameSpace; +import com.fr.chartx.TwoTuple; +import com.fr.chartx.data.execute.ExecuteDataSetHelper; +import com.fr.data.TableDataSource; +import com.fr.data.TableDataSourceTailor; +import com.fr.data.core.DataCoreUtils; +import com.fr.data.impl.NameTableData; +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.data.DesignTableDataManager; +import com.fr.design.data.datapane.TableDataComboBox; +import com.fr.design.data.tabledata.wrapper.TableDataWrapper; +import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.file.HistoryTemplateListPane; +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.mainframe.DesignerContext; +import com.fr.design.mainframe.chart.gui.data.table.DataPaneHelper; +import com.fr.design.parameter.ParameterInputPane; +import com.fr.general.GeneralUtils; +import com.fr.general.data.DataModel; +import com.fr.general.data.TableDataException; +import com.fr.plugin.chart.map.MapMatchResult; +import com.fr.plugin.chart.map.server.ChartGEOJSONHelper; +import com.fr.script.Calculator; +import com.fr.stable.ArrayUtils; +import com.fr.stable.ParameterProvider; +import com.fr.stable.StringUtils; + +import javax.swing.BorderFactory; +import javax.swing.Icon; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.table.DefaultTableModel; +import javax.swing.tree.DefaultMutableTreeNode; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +/** + * @author Bjorn + * @version 10.0 + * Created by Bjorn on 2019-11-04 + */ +public class MapAreaMatchPane extends BasicBeanPane { + + private TableDataComboBox tableNameCombox; + private UIComboBox areaNameBox; + private UILabel refreshLabel; + + private MatchAreaTable matchAreaTable; + + private MatchResultTable matchResultTable; + + private static final Object[] HEADER = new Object[]{Toolkit.i18nText("Fine-Design_Chart_Area_Name"), Toolkit.i18nText("Fine-Design_Chart_Match_To")}; + + private static final Object[] HEADER_WITH_EMPTY = new Object[]{Toolkit.i18nText("Fine-Design_Chart_Area_Name"), Toolkit.i18nText("Fine-Design_Chart_Match_To"), ""}; + + + public MapAreaMatchPane(TwoTuple> treeNodeAndItems) { + initButtonGroup(); + initRefreshLabel(); + areaNameBox = new UIComboBox(); + this.setLayout(new BorderLayout(5, 10)); + this.add(createContentPane(), BorderLayout.NORTH); + initTable(treeNodeAndItems); + JScrollPane matchAreaScroll = new JScrollPane(matchAreaTable) { + @Override + public Dimension getPreferredSize() { + return new Dimension(400, 300); + } + }; + this.add(matchAreaScroll, BorderLayout.CENTER); + JScrollPane matchResultScroll = new JScrollPane(matchResultTable) { + @Override + public Dimension getPreferredSize() { + return new Dimension(400, 200); + } + }; + matchResultScroll.setBorder(BorderFactory.createTitledBorder(Toolkit.i18nText("Fine-Design_Chart_Custom_Match_List"))); + this.add(matchResultScroll, BorderLayout.SOUTH); + this.setBorder(BorderFactory.createEmptyBorder(5, 20, 5, 20)); + } + + private JPanel createContentPane() { + JPanel panel = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + + JPanel tableDataPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + panel.add(tableDataPane); + tableDataPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Chart_Table_Data") + ":")); + tableNameCombox.setPreferredSize(new Dimension(96, 20)); + tableDataPane.add(tableNameCombox); + + JPanel areaNamePane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + panel.add(areaNamePane); + areaNamePane.add(new UILabel(Toolkit.i18nText("Fine-Design_Chart_Area_Name") + ":")); + areaNamePane.add(areaNameBox); + areaNameBox.setPreferredSize(new Dimension(96, 20)); + panel.add(refreshLabel); + return panel; + } + + private void initTable(TwoTuple> treeNodeAndItems) { + matchAreaTable = new MatchAreaTable(new Object[0][2], HEADER); + matchAreaTable.setRoot(treeNodeAndItems.getFirst()); + matchAreaTable.setItems(treeNodeAndItems.getSecond()); + + matchResultTable = new MatchResultTable(new Object[0][3], HEADER_WITH_EMPTY); + + DefaultTableModel model = new DefaultTableModel(new Object[0][3], HEADER_WITH_EMPTY); + matchResultTable.setModel(model); + + matchAreaTable.setMatchResultTable(matchResultTable); + matchResultTable.setMatchAreaTable(matchAreaTable); + } + + private void initButtonGroup() { + tableNameCombox = new TableDataComboBox(DesignTableDataManager.getEditingTableDataSource()); + tableNameCombox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + if (e.getStateChange() == ItemEvent.SELECTED) { + refreshBox(); + } + } + }); + } + + private void initRefreshLabel() { + Icon refreshImage = BaseUtils.readIcon("/com/fr/design/images/control/refresh.png"); + refreshLabel = new UILabel(refreshImage); + refreshLabel.addMouseListener(new MouseAdapter() { + boolean mouseEntered = false; + boolean buttonPressed = false; + + public void mouseEntered(MouseEvent e) { // 当鼠标进入时候调用. + mouseEntered = true; + if (!buttonPressed) { + refreshLabel.setBackground(java.awt.Color.WHITE); + refreshLabel.setOpaque(true); + refreshLabel.setBorder(BorderFactory.createLineBorder(java.awt.Color.GRAY)); + } + } + + public void mouseExited(MouseEvent e) { + mouseEntered = false; + refreshLabel.setOpaque(false); + refreshLabel.setBorder(BorderFactory.createEmptyBorder()); + } + + public void mousePressed(MouseEvent e) { + buttonPressed = true; + refreshLabel.setBackground(java.awt.Color.lightGray); + } + + public void mouseReleased(MouseEvent e) { + buttonPressed = false; + if (mouseEntered) { + refreshLabel.setBackground(java.awt.Color.WHITE); + populateData(tableNameCombox.getSelectedItem().getTableDataName(), GeneralUtils.objectToString(areaNameBox.getSelectedItem())); + } + } + }); + } + + public void updateBean(MapMatchResult matchResult) { + if (matchResult == null) { + return; + } + if (tableNameCombox.getSelectedItem() != null) { + matchResult.setTableName(tableNameCombox.getSelectedItem().getTableDataName()); + } + matchResult.setColumnName(GeneralUtils.objectToString(areaNameBox.getSelectedItem())); + + matchResultTable.updateBean(matchResult); + } + + public void populateBean(MapMatchResult matchResult) { + + } + + public void populateBean(MapMatchResult matchResult, String tableName, String areaName) { + //先取保存的数据集名称和区域名,若不存在,就取数据集面板配置的数据集名称和区域名 + matchResultTable.populateBean(matchResult); + + if (matchResult != null && matchResult.getTableName() != null) { + tableName = matchResult.getTableName(); + areaName = matchResult.getColumnName(); + } + tableNameCombox.setSelectedTableDataByName(tableName); + if (StringUtils.isEmpty(areaName)) { + return; + } + areaNameBox.setSelectedItem(areaName); + populateData(tableName, areaName); + } + + private void populateData(String tableName, String columnName) { + Object[] columnData = getColumnData(tableName, columnName); + if (columnData == null) { + return; + } + populateMatchData(columnData); + } + + private Object[] getColumnData(String tableName, String columnName) { + NameTableData nameTableData = new NameTableData(tableName); + TableDataSource dataSource = TableDataSourceTailor.extractTableData(HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().getTarget()); + Calculator calculator = Calculator.createCalculator(); + calculator.setAttribute(TableDataSource.KEY, dataSource); + ParameterProvider[] parameters = nameTableData.getParameters(calculator); + final Map parameterMap = new HashMap<>(); + + if (ArrayUtils.isNotEmpty(parameters)) { + final ParameterInputPane pPane = new ParameterInputPane(parameters); + pPane.showSmallWindow(DesignerContext.getDesignerFrame(), new DialogActionAdapter() { + @Override + public void doOk() { + parameterMap.putAll(pPane.update()); + } + }).setVisible(true); + } + for (ParameterProvider parameter : parameters) { + if (parameterMap.containsKey(parameter.getName())) { + parameter.setValue(parameterMap.get(parameter.getName())); + } + } + ParameterMapNameSpace parameterMapNameSpace = ParameterMapNameSpace.create(parameterMap); + calculator.pushNameSpace(parameterMapNameSpace); + + try { + DataModel dataModel = ExecuteDataSetHelper.createDataModel(calculator, nameTableData); + int colIndex = DataCoreUtils.getColumnIndexByName(dataModel, columnName); + if (colIndex == DataModel.COLUMN_NAME_NOT_FOUND) { + return null; + } + int size = dataModel.getRowCount(); + HashSet columnData = new LinkedHashSet<>(); + for (int i = 0; i < size; i++) { + columnData.add(dataModel.getValueAt(i, colIndex)); + } + return columnData.toArray(); + } catch (TableDataException ignore) { + return null; + } + } + + private void populateMatchData(Object[] columnData) { + Set geoAreas = matchAreaTable.getItems(); + + Map resultMap = ChartGEOJSONHelper.matchArea(columnData, geoAreas, matchResultTable.getCustomResult()); + + Object[][] data = new Object[resultMap.size()][2]; + + //构造table的数据结构 + Map areaNameIndex = new HashMap<>(); + int i = 0; + for (Map.Entry entry : resultMap.entrySet()) { + areaNameIndex.put(entry.getKey(), i); + data[i++] = new Object[]{entry.getKey(), entry.getValue()}; + } + + matchAreaTable.setAreaNameIndex(areaNameIndex); + matchAreaTable.setModel(new DefaultTableModel(data, HEADER)); + } + + private void refreshBox() { + TableDataWrapper dataWrap = tableNameCombox.getSelectedItem(); + + if (dataWrap == null) { + return; + } + + List columnNameList = dataWrap.calculateColumnNameList(); + + DataPaneHelper.refreshBoxItems(areaNameBox, columnNameList); + areaNameBox.setSelectedItem(null); + } + + public MapMatchResult updateBean() { + return null; + } + + @Override + protected String title4PopupWindow() { + return Toolkit.i18nText("Fine-Design_Chart_Location_With_Area_Name"); + } +} diff --git a/designer-chart/src/main/java/com/fr/design/chartx/component/MatchAreaTable.java b/designer-chart/src/main/java/com/fr/design/chartx/component/MatchAreaTable.java new file mode 100644 index 0000000000..e8f98f2a3f --- /dev/null +++ b/designer-chart/src/main/java/com/fr/design/chartx/component/MatchAreaTable.java @@ -0,0 +1,148 @@ +package com.fr.design.chartx.component; + +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; +import com.fr.general.GeneralUtils; +import com.fr.plugin.chart.map.server.ChartGEOJSONHelper; + +import javax.swing.AbstractCellEditor; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.JTree; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumnModel; +import javax.swing.table.TableModel; +import javax.swing.tree.DefaultMutableTreeNode; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.awt.Color; +import java.awt.Component; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +/** + * @author Bjorn + * @version 10.0 + * Created by Bjorn on 2019-11-19 + */ +public class MatchAreaTable extends JTable { + + private Set items; + + private MatchResultTable matchResultTable; + + private Map areaNameIndex = new HashMap<>(); + + private DefaultMutableTreeNode root; + + public MatchAreaTable(Object[][] data, Object[] header) { + super(data, header); + this.getTableHeader().setReorderingAllowed(false); + } + + public void setItems(Set items) { + this.items = items; + } + + public Set getItems() { + return items; + } + + public void setRoot(DefaultMutableTreeNode root) { + this.root = root; + } + + public void setMatchResultTable(MatchResultTable matchResultTable) { + this.matchResultTable = matchResultTable; + } + + public void setAreaNameIndex(Map areaNameIndex) { + this.areaNameIndex = areaNameIndex; + } + + public void setModel(TableModel dataModel) { + super.setModel(dataModel); + + if (items == null) { + items = new HashSet<>(); + } + TableColumnModel columnModel = getColumnModel(); + columnModel.getColumn(0).setCellEditor(new UILabelEditor()); + columnModel.getColumn(1).setCellEditor(new UIComboBoxRenderAndEditor()); + columnModel.getColumn(1).setCellRenderer(new UIComboBoxRenderAndEditor()); + } + + public void reMatch(Object areaName) { + if (!areaNameIndex.containsKey(areaName)) { + return; + } + int index = areaNameIndex.get(areaName); + Map resultMap = ChartGEOJSONHelper.matchArea(new Object[]{areaName}, items); + String result = resultMap.get(areaName); + getColumnModel().getColumn(1).getCellEditor().stopCellEditing(); + this.setValueAt(result, index, 1); + } + + public class UIComboBoxRenderAndEditor extends AbstractCellEditor implements TableCellRenderer, TableCellEditor { + + TableTreeComboBox comboBox; + + public UIComboBoxRenderAndEditor() { + } + + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + initComboBox(value, false); + return comboBox; + } + + public Component getTableCellEditorComponent(final JTable table, Object value, boolean isSelected, final int row, int column) { + initComboBox(value, true); + comboBox.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + UIComboBoxRenderAndEditor.this.stopCellEditing(); + Object areaName = MatchAreaTable.this.getValueAt(row, 0); + Object result = MatchAreaTable.this.getValueAt(row, 1); + if (items.contains(result)) { + matchResultTable.dealMatch(areaName, result); + } + } + }); + return comboBox; + } + + private void initComboBox(Object value, boolean editor) { + comboBox = new TableTreeComboBox(new JTree(root)); + comboBox.setEditable(true); + + comboBox.setSelectedItem(value); + if (!editor && value == null) { + JTextField textField = (JTextField) (comboBox.getEditor().getEditorComponent()); + textField.setForeground(Color.RED); + textField.setText(Toolkit.i18nText("Fine-Design_Chart_Prompt_Not_Selected")); + } + } + + public Object getCellEditorValue() { + return comboBox.getSelectedItem(); + } + } + + public static class UILabelEditor extends AbstractCellEditor implements TableCellEditor { + + UILabel uiLabel; + + public Component getTableCellEditorComponent(JTable table, Object value, + boolean isSelected, + int row, int column) { + uiLabel = new UILabel(GeneralUtils.objectToString(value)); + return uiLabel; + } + + public Object getCellEditorValue() { + return uiLabel.getText(); + } + } +} diff --git a/designer-chart/src/main/java/com/fr/design/chartx/component/MatchResultTable.java b/designer-chart/src/main/java/com/fr/design/chartx/component/MatchResultTable.java new file mode 100644 index 0000000000..55287f00a7 --- /dev/null +++ b/designer-chart/src/main/java/com/fr/design/chartx/component/MatchResultTable.java @@ -0,0 +1,146 @@ +package com.fr.design.chartx.component; + +import com.fr.base.BaseUtils; +import com.fr.base.Utils; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.i18n.Toolkit; +import com.fr.general.ComparatorUtils; +import com.fr.plugin.chart.map.MapMatchResult; +import com.fr.stable.StringUtils; + +import javax.swing.AbstractCellEditor; +import javax.swing.JOptionPane; +import javax.swing.JTable; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumnModel; +import javax.swing.table.TableModel; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Vector; +import java.awt.Component; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +/** + * @author Bjorn + * @version 10.0 + * Created by Bjorn on 2019-11-20 + */ +public class MatchResultTable extends JTable { + + private MatchAreaTable matchAreaTable; + + public MatchResultTable(Object[][] data, Object[] header) { + super(data, header); + this.getTableHeader().setReorderingAllowed(false); + } + + public void setMatchAreaTable(MatchAreaTable matchAreaTable) { + this.matchAreaTable = matchAreaTable; + } + + public void setModel(TableModel dataModel) { + super.setModel(dataModel); + + TableColumnModel columnModel = getColumnModel(); + columnModel.getColumn(0).setCellEditor(new MatchAreaTable.UILabelEditor()); + columnModel.getColumn(1).setCellEditor(new MatchAreaTable.UILabelEditor()); + columnModel.getColumn(2).setCellEditor(new UIButtonEditorAndRender()); + columnModel.getColumn(2).setCellRenderer(new UIButtonEditorAndRender()); + columnModel.getColumn(2).setMaxWidth(20); + } + + public void dealMatch(Object areaName, Object result) { + int rowCount = this.getRowCount(); + for (int i = 0; i < rowCount; i++) { + if (ComparatorUtils.equals(this.getValueAt(i, 0), areaName)) { + getColumnModel().getColumn(1).getCellEditor().stopCellEditing(); + this.setValueAt(result, i, 1); + return; + } + } + DefaultTableModel model = (DefaultTableModel) this.getModel(); + Vector vector = new Vector(); + vector.add(areaName); + vector.add(result); + vector.add(""); + model.addRow(vector); + } + + public void populateBean(MapMatchResult matchResult) { + if (matchResult == null) { + return; + } + Map customResult = matchResult.getCustomResult(); + if (customResult == null) { + return; + } + DefaultTableModel model = (DefaultTableModel) this.getModel(); + for (Map.Entry entry : customResult.entrySet()) { + Vector vector = new Vector(); + vector.add(entry.getKey()); + vector.add(entry.getValue()); + vector.add(""); + model.addRow(vector); + } + } + + public void updateBean(MapMatchResult matchResult) { + matchResult.setCustomResult(getCustomResult()); + } + + public Map getCustomResult() { + Map customResult = new LinkedHashMap<>(); + DefaultTableModel model = (DefaultTableModel) this.getModel(); + for (int i = 0, rowCount = model.getRowCount(); i < rowCount; i++) { + customResult.put(Utils.objectToString(model.getValueAt(i, 0)), Utils.objectToString(model.getValueAt(i, 1))); + } + return customResult; + } + + public class UIButtonEditorAndRender extends AbstractCellEditor implements TableCellEditor, TableCellRenderer { + + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, final int row, int column) { + UIButton uiButton = new UIButton(BaseUtils.readIcon("com/fr/design/images/toolbarbtn/close.png")); + uiButton.addMouseListener(new MouseAdapter() { + boolean mouseEntered = false; + + public void mouseEntered(MouseEvent e) { // 当鼠标进入时候调用. + mouseEntered = true; + + } + + public void mouseExited(MouseEvent e) { + mouseEntered = false; + } + + public void mouseReleased(MouseEvent e) { + if (mouseEntered) { + MatchResultTable.this.getCellEditor().stopCellEditing(); + int val = JOptionPane.showConfirmDialog(MatchResultTable.this, Toolkit.i18nText("Fine-Design_Basic_Utils_Are_You_Sure_To_Remove_The_Selected_Item") + "?", + Toolkit.i18nText("Fine-Design_Basic_Remove"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); + if (val == JOptionPane.OK_OPTION) { + DefaultTableModel model = (DefaultTableModel) MatchResultTable.this.getModel(); + Object areaName = MatchResultTable.this.getValueAt(row, 0); + model.removeRow(row); + matchAreaTable.reMatch(areaName); + } + } + } + }); + return uiButton; + } + + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + UIButton button = new UIButton(BaseUtils.readIcon("com/fr/design/images/toolbarbtn/close.png")); + return button; + } + + public Object getCellEditorValue() { + return StringUtils.EMPTY; + } + } + +} diff --git a/designer-chart/src/main/java/com/fr/design/chartx/component/TableTreeComboBox.java b/designer-chart/src/main/java/com/fr/design/chartx/component/TableTreeComboBox.java new file mode 100644 index 0000000000..793b49b31e --- /dev/null +++ b/designer-chart/src/main/java/com/fr/design/chartx/component/TableTreeComboBox.java @@ -0,0 +1,100 @@ +package com.fr.design.chartx.component; + +import com.fr.design.gui.icombobox.FRTreeComboBox; +import com.fr.design.gui.itextfield.UITextField; +import com.fr.general.IOUtils; +import com.fr.plugin.chart.map.server.ChartGEOJSONHelper; + +import javax.swing.JTextField; +import javax.swing.JTree; +import javax.swing.MenuSelectionManager; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.tree.TreeCellRenderer; +import javax.swing.tree.TreeNode; +import javax.swing.tree.TreePath; +import java.util.Enumeration; +import java.awt.Component; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; + +/** + * @author Bjorn + * @version 10.0 + * Created by Bjorn on 2019-12-24 + */ +public class TableTreeComboBox extends FRTreeComboBox { + + private JTextField textField; + + public TableTreeComboBox(JTree tree) { + super(tree, null); + textField = (JTextField) (this.getEditor().getEditorComponent()); + textField.addKeyListener(treeKeyListener); + tree.setCellRenderer(tableNameTreeRenderer); + } + + @Override + protected void dealSamePath(TreePath parent, TreeNode node, UITextField textField) { + matchLeafNode(parent, node, textField); + } + + private boolean matchLeafNode(TreePath parent, TreeNode node, UITextField textField) { + for (Enumeration e = node.children(); e.hasMoreElements(); ) { + TreeNode n = (TreeNode) e.nextElement(); + TreePath path = parent.pathByAddingChild(n); + TreeNode pathNode = (TreeNode) path.getLastPathComponent(); + if (pathNode.getChildCount() == 0) { + if (pathToString(path).toUpperCase().contains(textField.getText().toUpperCase())) { + tree.scrollPathToVisible(path); + tree.setSelectionPath(path); + return true; + } + } else { + if (matchLeafNode(path, pathNode, textField)) { + return true; + } + } + } + return false; + } + + private KeyListener treeKeyListener = new KeyAdapter() { + public void keyPressed(KeyEvent e) { + int key = e.getKeyCode(); + if (key == KeyEvent.VK_ENTER) { + TreePath treePath = tree.getSelectionPath(); + if (treePath == null) { + return; + } + DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath + .getLastPathComponent(); + if (node.isLeaf()) { + TableTreeComboBox.this.setSelectedItem(treePath); + textField.setText(pathToString(treePath)); + MenuSelectionManager.defaultManager().clearSelectedPath(); + } + } + } + }; + + private TreeCellRenderer tableNameTreeRenderer = new DefaultTreeCellRenderer() { + @Override + public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { + super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); + if (value instanceof DefaultMutableTreeNode) { + DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; + Object userObj = node.getUserObject(); + if (node.getChildCount() > 0) { + this.setIcon(IOUtils.readIcon("com/fr/design/images/m_insert/expandCell.gif")); + } + if (userObj != null) { + this.setText(ChartGEOJSONHelper.getPresentNameWithPath(userObj.toString())); + } + } + return this; + } + }; + +} diff --git a/designer-chart/src/main/java/com/fr/design/chartx/data/drillMap/DrillMapChartDataPane.java b/designer-chart/src/main/java/com/fr/design/chartx/data/drillMap/DrillMapChartDataPane.java index ae52b401de..7d1d1c52a7 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/data/drillMap/DrillMapChartDataPane.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/data/drillMap/DrillMapChartDataPane.java @@ -37,7 +37,7 @@ public class DrillMapChartDataPane extends AbstractChartDataPane private EachLayerDataDefinitionPane eachLayerDataDefinitionPane;//各层级分别指定 - public DrillMapDataPane(VanChartDrillMapPlot drillMapPlot) { - bottomDataPane = new SingleDataPane(new AreaMapDataSetFieldsPane(), new AreaMapCellDataFieldsPane()); - eachLayerDataDefinitionPane = new EachLayerDataDefinitionPane(drillMapPlot); + public DrillMapDataPane(VanChart vanChart) { + AreaMapDataSetFieldsPane areaMapDataSetFieldsPane = new AreaMapDataSetFieldsPane(); + areaMapDataSetFieldsPane.setChart(vanChart); + areaMapDataSetFieldsPane.setLevel(ChartGEOJSONHelper.BOTTOM_LEVEL); + bottomDataPane = new SingleDataPane(areaMapDataSetFieldsPane, new AreaMapCellDataFieldsPane()); + eachLayerDataDefinitionPane = new EachLayerDataDefinitionPane(vanChart); dataDefinitionType = new UIComboBoxPane() { @Override diff --git a/designer-chart/src/main/java/com/fr/design/chartx/data/drillMap/DrillMapLayerPane.java b/designer-chart/src/main/java/com/fr/design/chartx/data/drillMap/DrillMapLayerPane.java index b12bf385a0..975faffca3 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/data/drillMap/DrillMapLayerPane.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/data/drillMap/DrillMapLayerPane.java @@ -8,6 +8,7 @@ import com.fr.design.i18n.Toolkit; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.plugin.chart.drillmap.VanChartDrillMapPlot; +import com.fr.plugin.chart.map.MapMatchResult; import com.fr.plugin.chart.map.server.CompatibleGeoJSONTreeHelper; import com.fr.plugin.chart.type.MapType; import com.fr.plugin.chart.type.ZoomLevel; @@ -18,10 +19,11 @@ import com.fr.van.chart.map.designer.type.VanChartMapSourceChoosePane; import javax.swing.BorderFactory; import javax.swing.JPanel; import javax.swing.tree.DefaultMutableTreeNode; -import java.awt.BorderLayout; -import java.awt.Component; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import java.awt.BorderLayout; +import java.awt.Component; /** * Created by Mitisky on 16/6/20. @@ -62,6 +64,7 @@ public class DrillMapLayerPane extends BasicBeanPane { java.util.List levelList = drillMapPlot.getLayerLevelList(); java.util.List mapTypeList = drillMapPlot.getLayerMapTypeList(); + List matchResultList = drillMapPlot.getMatchResultList(); //根据层级初始属性,一切以json那边读到的层级为准 int levelSize = levelList.size(); @@ -73,6 +76,11 @@ public class DrillMapLayerPane extends BasicBeanPane { for (int j = typeSize; j < depth; j++) { mapTypeList.add(mapType); } + + int matchSize = matchResultList.size(); + for (int k = matchSize; k < depth; k++) { + matchResultList.add(new MapMatchResult()); + } } } @@ -120,10 +128,10 @@ public class DrillMapLayerPane extends BasicBeanPane { return panel; } - private JPanel createTitlePane (String title, JPanel panel) { + private JPanel createTitlePane(String title, JPanel panel) { JPanel jPanel = TableLayout4VanChartHelper.createExpandablePaneWithTitle(title, panel); - panel.setBorder(BorderFactory.createEmptyBorder(10,5,0,0)); - jPanel.setBorder(BorderFactory.createEmptyBorder(0,5,0,0)); + panel.setBorder(BorderFactory.createEmptyBorder(10, 5, 0, 0)); + jPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); return jPanel; } diff --git a/designer-chart/src/main/java/com/fr/design/chartx/data/drillMap/EachLayerDataDefinitionPane.java b/designer-chart/src/main/java/com/fr/design/chartx/data/drillMap/EachLayerDataDefinitionPane.java index 02c6c4d089..a7180e4c5d 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/data/drillMap/EachLayerDataDefinitionPane.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/data/drillMap/EachLayerDataDefinitionPane.java @@ -13,6 +13,7 @@ import com.fr.design.i18n.Toolkit; import com.fr.general.ComparatorUtils; import com.fr.plugin.chart.drillmap.VanChartDrillMapPlot; import com.fr.plugin.chart.type.MapType; +import com.fr.plugin.chart.vanchart.VanChart; import java.util.ArrayList; import java.util.List; @@ -26,8 +27,11 @@ public class EachLayerDataDefinitionPane extends MultiTabPane oldTypeList; private VanChartDrillMapPlot plot; - public EachLayerDataDefinitionPane(VanChartDrillMapPlot drillMapPlot) { - this.plot = drillMapPlot; + private VanChart vanChart; + + public EachLayerDataDefinitionPane(VanChart vanChart) { + this.vanChart = vanChart; + this.plot = vanChart.getPlot(); initComps(); } @@ -52,17 +56,29 @@ public class EachLayerDataDefinitionPane extends MultiTabPane extends BasicBeanPane { + public String tableName; + public AbstractDataSetFieldsPane() { initComponents(); } + public String getTableName() { + return tableName; + } + + public void setTableName(String tableName) { + this.tableName = tableName; + } + protected void initComponents() { this.setLayout(new BorderLayout(0, 6)); diff --git a/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/AreaMapDataSetFieldsPane.java b/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/AreaMapDataSetFieldsPane.java index 2d8bba01a1..2f4dc37ea1 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/AreaMapDataSetFieldsPane.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/AreaMapDataSetFieldsPane.java @@ -4,12 +4,14 @@ import com.fr.chartx.data.field.diff.AreaMapColumnFieldCollection; import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.i18n.Toolkit; +import java.awt.Component; + /** * @author shine * @version 10.0 * Created by shine on 2019/11/7 */ -public class AreaMapDataSetFieldsPane extends AbstractDataSetFieldsWithSeriesValuePane { +public class AreaMapDataSetFieldsPane extends MapDataSetFieldsPane { private UIComboBox areaName; @@ -27,6 +29,13 @@ public class AreaMapDataSetFieldsPane extends AbstractDataSetFieldsWithSeriesVal }; } + @Override + protected Component[] fieldComponents() { + return new Component[]{ + createAreaPanel(createAreaName()) + }; + } + private UIComboBox createAreaName() { if (areaName == null) { areaName = new UIComboBox(); diff --git a/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/LineMapDataSetFieldsPane.java b/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/LineMapDataSetFieldsPane.java index 24220b9930..b1a0587830 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/LineMapDataSetFieldsPane.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/LineMapDataSetFieldsPane.java @@ -12,7 +12,7 @@ import javax.swing.JPanel; * @version 10.0 * Created by shine on 2019/11/11 */ -public class LineMapDataSetFieldsPane extends AbstractDataSetFieldsWithSeriesValuePane { +public class LineMapDataSetFieldsPane extends MapDataSetFieldsPane { private LineMapAreaLngLatPaneWithComboBox areaLngLatPane; private UIComboBox lineName; @@ -20,7 +20,7 @@ public class LineMapDataSetFieldsPane extends AbstractDataSetFieldsWithSeriesVal @Override protected JPanel createNorthPane() { if (areaLngLatPane == null) { - areaLngLatPane = new LineMapAreaLngLatPaneWithComboBox(); + areaLngLatPane = new LineMapAreaLngLatPaneWithComboBox(this); } return areaLngLatPane; } diff --git a/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/MapDataSetFieldsPane.java b/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/MapDataSetFieldsPane.java new file mode 100644 index 0000000000..bec4e78b7e --- /dev/null +++ b/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/MapDataSetFieldsPane.java @@ -0,0 +1,92 @@ +package com.fr.design.chartx.fields.diff; + +import com.fr.base.BaseUtils; +import com.fr.base.Utils; +import com.fr.chartx.TwoTuple; +import com.fr.chartx.data.field.diff.ColumnFieldCollectionWithSeriesValue; +import com.fr.design.chartx.component.MapAreaMatchPane; +import com.fr.design.dialog.BasicDialog; +import com.fr.design.dialog.DialogActionListener; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.plugin.chart.map.MapMatchResult; +import com.fr.plugin.chart.map.VanChartMapPlot; +import com.fr.plugin.chart.map.server.ChartGEOJSONHelper; +import com.fr.plugin.chart.vanchart.VanChart; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.tree.DefaultMutableTreeNode; +import java.util.Set; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * @author Bjorn + * @version 10.0 + * Created by Bjorn on 2019-12-25 + */ +public abstract class MapDataSetFieldsPane extends AbstractDataSetFieldsWithSeriesValuePane { + + private VanChart chart; + + //钻取地图有层级,默认-1代表无层级关系 + private int level = ChartGEOJSONHelper.DEFAULT_LEVEL; + + public int getLevel() { + return level; + } + + public void setLevel(int level) { + this.level = level; + } + + public void setChart(VanChart chart) { + this.chart = chart; + } + + public VanChart getChart() { + return chart; + } + + public JPanel createAreaPanel(final UIComboBox areaBox) { + JPanel areaPanel = new JPanel(new BorderLayout(10, 0)); + areaBox.setPreferredSize(new Dimension(91, 20)); + areaPanel.add(areaBox, BorderLayout.WEST); + UIButton uiButton = new UIButton(BaseUtils.readIcon("/com/fr/design/images/buttonicon/config.png")); + uiButton.addActionListener(new ActionListener() { + private TwoTuple> treeNodeAndItems; + + @Override + public void actionPerformed(ActionEvent e) { + VanChartMapPlot plot = chart.getPlot(); + if (treeNodeAndItems == null) { + treeNodeAndItems = ChartGEOJSONHelper.getTreeNodeAndItems(plot.getGeoUrl(), level); + } + final MapAreaMatchPane pane = new MapAreaMatchPane(treeNodeAndItems); + + String nameTable = getTableName(); + final MapMatchResult matchResult = plot.getMatchResult(level); + + pane.populateBean(matchResult, nameTable, Utils.objectToString(areaBox.getSelectedItem())); + BasicDialog dialog = pane.showWindow(new JFrame()); + dialog.addDialogActionListener(new DialogActionListener() { + @Override + public void doOk() { + pane.updateBean(matchResult); + } + + @Override + public void doCancel() { + + } + }); + dialog.setVisible(true); + } + }); + areaPanel.add(uiButton, BorderLayout.EAST); + return areaPanel; + } +} diff --git a/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/PointMapDataSetFieldsPane.java b/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/PointMapDataSetFieldsPane.java index 1771637abb..220f840d33 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/PointMapDataSetFieldsPane.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/PointMapDataSetFieldsPane.java @@ -11,13 +11,13 @@ import javax.swing.JPanel; * @version 10.0 * Created by shine on 2019/11/8 */ -public class PointMapDataSetFieldsPane extends AbstractDataSetFieldsWithSeriesValuePane { +public class PointMapDataSetFieldsPane extends MapDataSetFieldsPane { private PointMapAreaLngLatPaneWithComboBox areaLngLatPane; @Override protected JPanel createNorthPane() { if (areaLngLatPane == null) { - areaLngLatPane = new PointMapAreaLngLatPaneWithComboBox(); + areaLngLatPane = new PointMapAreaLngLatPaneWithComboBox(this); } return areaLngLatPane; } @@ -30,7 +30,7 @@ public class PointMapDataSetFieldsPane extends AbstractDataSetFieldsWithSeriesVa @Override protected UIComboBox[] filedComboBoxes() { if (areaLngLatPane == null) { - areaLngLatPane = new PointMapAreaLngLatPaneWithComboBox(); + areaLngLatPane = new PointMapAreaLngLatPaneWithComboBox(this); } return areaLngLatPane.allFieldComboBox(); } diff --git a/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/SingleCategoryDataSetFieldsPane.java b/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/SingleCategoryDataSetFieldsPane.java index 663daecdf2..9eb6d94e2d 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/SingleCategoryDataSetFieldsPane.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/fields/diff/SingleCategoryDataSetFieldsPane.java @@ -55,7 +55,10 @@ public class SingleCategoryDataSetFieldsPane label.setPreferredSize(new Dimension(ChartDataPane.LABEL_WIDTH, ChartDataPane.LABEL_HEIGHT)); JPanel northPane = new JPanel(new BorderLayout(HGAP, VGAP)); - northPane.add(GUICoreUtils.createBorderLayoutPane(new Component[]{categoryPane, null, null, label, null}), BorderLayout.NORTH); + northPane.add(GUICoreUtils.createBorderLayoutPane( + new Component[]{categoryPane, null, null, label, null}), + BorderLayout.NORTH + ); northPane.add(new JSeparator(), BorderLayout.CENTER); northPane.add(createCenterPane(), BorderLayout.SOUTH); northPane.setBorder(BorderFactory.createEmptyBorder(TOP, LEFT, BOTTOM, RIGHT)); diff --git a/designer-chart/src/main/java/com/fr/design/chartx/single/DataSetPane.java b/designer-chart/src/main/java/com/fr/design/chartx/single/DataSetPane.java index 87a3b50832..cfb9a2c18a 100644 --- a/designer-chart/src/main/java/com/fr/design/chartx/single/DataSetPane.java +++ b/designer-chart/src/main/java/com/fr/design/chartx/single/DataSetPane.java @@ -39,7 +39,7 @@ public class DataSetPane extends FurtherBasicBeanPane { tableDataPane = new DatabaseTableDataPane(label) { @Override protected void userEvent() { - refreshBoxList(); + refreshBoxListAndTableName(); checkBoxUse(); } }; @@ -67,7 +67,7 @@ public class DataSetPane extends FurtherBasicBeanPane { /** * 刷新字段下拉列表 */ - private void refreshBoxList() { + private void refreshBoxListAndTableName() { TableDataWrapper dataWrap = tableDataPane.getTableDataWrapper(); if (dataWrap == null) { @@ -78,6 +78,7 @@ public class DataSetPane extends FurtherBasicBeanPane { if (dataSetFieldsPane != null) { dataSetFieldsPane.refreshBoxListWithSelectTableData(columnNameList); + dataSetFieldsPane.setTableName(dataWrap.getTableDataName()); } } @@ -102,7 +103,7 @@ public class DataSetPane extends FurtherBasicBeanPane { return; } - refreshBoxList(); + refreshBoxListAndTableName(); tableDataPane.populateBean(ob.getNameTableData()); diff --git a/designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartHyperLinkPane.java b/designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartHyperLinkPane.java index af11a8b960..b5efad3b66 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartHyperLinkPane.java +++ b/designer-chart/src/main/java/com/fr/van/chart/custom/component/VanChartHyperLinkPane.java @@ -279,4 +279,4 @@ public class VanChartHyperLinkPane extends VanChartUIListControlPane { } -} +} \ No newline at end of file diff --git a/designer-chart/src/main/java/com/fr/van/chart/heatmap/designer/VanHeatMapChartTypeUI.java b/designer-chart/src/main/java/com/fr/van/chart/heatmap/designer/VanHeatMapChartTypeUI.java index 90926a106b..f3ad4e22d0 100644 --- a/designer-chart/src/main/java/com/fr/van/chart/heatmap/designer/VanHeatMapChartTypeUI.java +++ b/designer-chart/src/main/java/com/fr/van/chart/heatmap/designer/VanHeatMapChartTypeUI.java @@ -66,7 +66,9 @@ public class VanHeatMapChartTypeUI extends VanMapChartTypeUI { return new AbstractVanSingleDataPane(listener) { @Override protected SingleDataPane createSingleDataPane() { - return new SingleDataPane(new PointMapDataSetFieldsPane(), new PointMapCellDataFieldsPane()); + PointMapDataSetFieldsPane pointMapDataSetFieldsPane = new PointMapDataSetFieldsPane(); + pointMapDataSetFieldsPane.setChart(getVanChart()); + return new SingleDataPane(pointMapDataSetFieldsPane, new PointMapCellDataFieldsPane()); } }; } diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java index 5a7ae9817c..1cf1b944cb 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/cardlayout/XCardSwitchButton.java @@ -1,5 +1,5 @@ /** - * + * */ package com.fr.design.designer.creator.cardlayout; @@ -61,6 +61,8 @@ public class XCardSwitchButton extends XButton { private static final int MIN_SIZE = 1; + private static final int HALF_NUMBER = 2; + // 删除按钮识别区域偏移量 private static final int CLOSE_ICON_RIGHT_OFFSET = 15; private static final int CLOSE_ICON_TOP_OFFSET = 15; @@ -80,7 +82,7 @@ public class XCardSwitchButton extends XButton { private UILabel label; private Icon closeIcon = MOUSE_CLOSE; - + public XWCardTagLayout getTagLayout() { return tagLayout; } @@ -126,12 +128,12 @@ public class XCardSwitchButton extends XButton { /** * 响应点击事件 - * + * * @param editingMouseListener * 事件处理器 * @param e * 点击事件 - * + * */ @Override public void respondClick(EditingMouseListener editingMouseListener, @@ -143,12 +145,12 @@ public class XCardSwitchButton extends XButton { if(cardLayout == null){ initRelateLayout(); } - + //获取当前tab的index CardSwitchButton currentButton = (CardSwitchButton) this.toData(); int index = currentButton.getIndex(); int maxIndex = cardLayout.getComponentCount() - 1; - + //点击删除图标时 if (isSelectedClose(e, designer)) { //当删除到最后一个tab时,删除整个tab布局 @@ -235,8 +237,8 @@ public class XCardSwitchButton extends XButton { } } } - - + + //SwitchButton对应的XWCardLayout和XWCardTagLayout暂未存到xml中,重新打开时根据父子层关系获取 private void initRelateLayout(){ this.tagLayout = (XWCardTagLayout)this.getBackupParent(); @@ -244,28 +246,28 @@ public class XCardSwitchButton extends XButton { XWCardMainBorderLayout borderLayout = (XWCardMainBorderLayout)titleLayout.getBackupParent(); this.cardLayout = borderLayout.getCardPart(); } - + //是否进入点击关闭按钮区域 private boolean isSelectedClose(MouseEvent e, FormDesigner designer){ - + int diff = designer.getArea().getHorScrollBar().getValue(); - + // mouse position int ex = e.getX() + diff; int ey = e.getY(); - + //获取tab布局的位置,鼠标相对于tab按钮的位置 XLayoutContainer mainLayout = cardLayout.getBackupParent(); Point point = mainLayout.getLocation(); double mainX = point.getX(); double mainY = point.getY(); - + // 参数界面对坐标的影响 JForm jform = (JForm) HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); if(jform.getFormDesign().getParaComponent() != null){ ey -= jform.getFormDesign().getParaHeight(); } - + //减掉tab布局的相对位置 ex -= mainX; ey -= mainY; @@ -280,10 +282,10 @@ public class XCardSwitchButton extends XButton { // 鼠标进入按钮右侧删除图标区域 double recX = position.getX() + titlePoint.getX() + (width - CLOSE_ICON_RIGHT_OFFSET); double recY = position.getY() + titlePoint.getY() + CLOSE_ICON_TOP_OFFSET; - + return (recX < ex && ex < recX + CLOSE_ICON_RIGHT_OFFSET && ey < recY && ey > position.getY()); } - + //将当前switchButton改为选中状态 private void changeButtonState(int index) { for (int i = 0; i < this.tagLayout.getComponentCount(); i++) { @@ -292,7 +294,7 @@ public class XCardSwitchButton extends XButton { tempButton.setShowButton(tempButton.getIndex() == index); } } - + @Override public void paintComponent(Graphics g) { super.paintComponent(g); @@ -305,12 +307,12 @@ public class XCardSwitchButton extends XButton { this.getContentBackground().paint(g, new Rectangle2D.Double(0, 0, panelSize.getWidth(), panelSize.getHeight())); drawCloseIcon(g2d); } - + //画删除图标 private void drawCloseIcon(Graphics2D g2d){ closeIcon.paintIcon(this, g2d, this.getWidth() - LEFT_GAP, 0); } - + //画背景 private void drawBackground(CardSwitchButton button, TitlePacker widgetTitle){ Background background = widgetTitle.getBackground() == null ? ColorBackground.getInstance(NORMAL_GRAL) : widgetTitle.getBackground(); @@ -328,7 +330,7 @@ public class XCardSwitchButton extends XButton { this.setContentBackground(initialBackground == null ? background : initialBackground); } } - + //画标题 private void drawTitle(CardSwitchButton button, TitlePacker widgetTitle) { String titleText = button.getText(); @@ -348,7 +350,7 @@ public class XCardSwitchButton extends XButton { BorderPacker style = this.cardLayout.toData().getBorderStyle(); return style.getTitle(); } - + //删除tab布局 private void deleteTabLayout(SelectionModel selectionModel, FormDesigner designer){ String titleName = this.getContentLabel().getText(); @@ -455,7 +457,8 @@ public class XCardSwitchButton extends XButton { StringBuilder titleStringBuf = new StringBuilder(); TitlePacker title = getWidgetTitle(); FRFont font = title.getFrFont(); - FRFont newFont = FRFont.getInstance(font.getName(), font.getStyle(), font.getSize() + FONT_SIZE_ADJUST); + int fontSize = font.getSize() + FONT_SIZE_ADJUST; + FRFont newFont = FRFont.getInstance(font.getName(), font.getStyle(), fontSize); FontMetrics fm = GraphHelper.getFontMetrics(newFont); for (int i = 0; i < titleText.length(); i++) { titleStringBuf.append(titleText.charAt(i)); @@ -469,12 +472,13 @@ public class XCardSwitchButton extends XButton { for (int i = 0; i < verticalTextList.size(); i++) { String paint_str = (String) verticalTextList.get(i); - GraphHelper.drawString(g2d, paint_str, (width - fm.stringWidth(paint_str)) / 2, textY); + GraphHelper.drawString(g2d, paint_str, + (width - fm.stringWidth(paint_str)) / (HALF_NUMBER * 1.0D), textY); textY += textHeight; textY += PT.pt2pix(0, RESLUTION); if (textY > height - textHeight && i < verticalTextList.size() - 1) { textY -= DOTS_HEIGHT; - paintDots(g2d, textY, (width - fm.stringWidth(paint_str)) / 2); + paintDots(g2d, textY, (width - fm.stringWidth(paint_str)) / HALF_NUMBER); break; } }