From c30278f28bf7f8f0169e6e20089210150078643b Mon Sep 17 00:00:00 2001 From: vito Date: Thu, 29 Feb 2024 16:19:39 +0800 Subject: [PATCH 1/3] =?UTF-8?q?REPORT-114888=20fix:=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E5=99=A8=E6=96=B0UI=E5=9B=BE=E8=A1=A8=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=89=93=E5=BC=80=E9=85=8D=E7=BD=AE=E9=9D=A2=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 +- .../fr/design/gui/imenutable/UIMenuTable.java | 408 ++++++------- .../com/fr/design/gui/itable/UITable.java | 549 +++++++++--------- 3 files changed, 492 insertions(+), 469 deletions(-) diff --git a/build.gradle b/build.gradle index 9cabeff69e..4ebe9558d3 100644 --- a/build.gradle +++ b/build.gradle @@ -87,9 +87,9 @@ allprojects { implementation 'com.fr.report:engine-chart:' + frDevVersion implementation 'com.fr.report:engine-i18n:' + frDevVersion implementation 'com.fr.design:design-i18n:' + frDevVersion - implementation 'com.formdev:flatlaf:3.2' - implementation 'com.formdev:flatlaf-extras:3.2.1' implementation 'com.github.weisj:jsvg:1.2.0' + implementation 'com.formdev:flatlaf:3.4' + implementation 'com.formdev:flatlaf-extras:3.4' implementation 'com.fanruan.vito:gui-inspector:1.0.1' implementation 'com.fine.swing.ui:layout:1.0-SNAPSHOT' testImplementation 'org.easymock:easymock:3.5.1' diff --git a/designer-base/src/main/java/com/fr/design/gui/imenutable/UIMenuTable.java b/designer-base/src/main/java/com/fr/design/gui/imenutable/UIMenuTable.java index 938e0caccc..488b449939 100644 --- a/designer-base/src/main/java/com/fr/design/gui/imenutable/UIMenuTable.java +++ b/designer-base/src/main/java/com/fr/design/gui/imenutable/UIMenuTable.java @@ -10,222 +10,238 @@ import com.fr.design.hyperlink.ReportletHyperlinkPane; import com.fr.design.hyperlink.WebHyperlinkPane; import com.fr.design.javascript.EmailPane; import com.fr.design.utils.gui.GUICoreUtils; - import com.fr.js.EmailJavaScript; import com.fr.js.ReportletHyperlink; import com.fr.js.WebHyperlink; +import org.jetbrains.annotations.NotNull; -import javax.swing.*; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JTable; +import javax.swing.SwingUtilities; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.plaf.TableUI; import javax.swing.table.TableCellRenderer; -import java.awt.*; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; import java.util.ArrayList; import java.util.List; public class UIMenuTable extends JTable { - protected int selectedRowIndex = -1; - protected int rollOverRowIndex = -1; - protected int draggingIndex = -1; + protected int selectedRowIndex = -1; + protected int rollOverRowIndex = -1; + protected int draggingIndex = -1; - public UIMenuTable() { - super(new UIMenuTableDataModel()); - initComponents(); - } + public UIMenuTable() { + super(new UIMenuTableDataModel()); + initComponents(); + } - public void populateBean(List values) { - ((UIMenuTableDataModel)dataModel).populateBean(values); - } + public void populateBean(List values) { + ((UIMenuTableDataModel) dataModel).populateBean(values); + } - public List updateBean() { - return ((UIMenuTableDataModel)dataModel).updateBean(); - } + public List updateBean() { + return ((UIMenuTableDataModel) dataModel).updateBean(); + } - public void editingEvent(int rowIndex, int mouseY) { - selectedRowIndex = rowIndex; - repaint(); + public void editingEvent(int rowIndex, int mouseY) { + selectedRowIndex = rowIndex; + repaint(); - final UIMenuNameableCreator nameObject = UIMenuTable.this.getLine(rowIndex); + final UIMenuNameableCreator nameObject = UIMenuTable.this.getLine(rowIndex); - final BasicBeanPane baseShowPane = nameObject.getPane(); + final BasicBeanPane baseShowPane = nameObject.getPane(); - final Object showValue = nameObject.getObj(); + final Object showValue = nameObject.getObj(); - baseShowPane.populateBean(showValue); + baseShowPane.populateBean(showValue); UIDialog dialog = baseShowPane.showUnsizedWindow(SwingUtilities.getWindowAncestor(new JPanel()), new DialogActionAdapter() { - public void doOk() { - baseShowPane.updateBean(showValue); - fireTargetChanged(); - } - }); - - dialog.setSize(500, 600); - GUICoreUtils.centerWindow(dialog); - - dialog.setVisible(true); - } - - protected Color getRenderBackground(int row) { - if(selectedRowIndex == row ) { - return UIConstants.SKY_BLUE; - } else { - return (rollOverRowIndex == row) ? UIConstants.LIGHT_BLUE : UIConstants.NORMAL_BACKGROUND; - } - } - - /** - * - * @param value 该行列的值(字符串) - * @param row - * @param column - * @return 列表中默认显示的东西,如果有很多内容,可以装载一个JPanel里再嵌进来 - */ - protected JComponent getRenderCompoment(Object value, int row,int column) { - UILabel text = new UILabel(); - if(value != null) { - text.setText(value.toString()); - } - return text; - } - - /** - * @param line 该行的内容 - * 在table底部增加一行内容 - */ - public void addLine(UIMenuNameableCreator line) { - ((UIMenuTableDataModel)dataModel).addLine(line); - } - - /** - * @param rowIndex - * @return 某一行的内容 - */ - public UIMenuNameableCreator getLine(int rowIndex) { - return ((UIMenuTableDataModel)dataModel).getLine(rowIndex); - } - - /** - * 删除某行内容 - * @param rowIndex - */ - public void removeLine(int rowIndex) { - ((UIMenuTableDataModel)dataModel).removeLine(rowIndex); - } - - /** - * 清除所有的内容 - */ - public void clearAll() { - int rowCount = dataModel.getRowCount(); - for(int i = 0; i < rowCount; i++) { - removeLine(i); - } - } - - /** - * 对某一行拖动时进行排序 - * @param rowIndex - * @param positive 鼠标移动的距离 - */ - public void dragSort(int rowIndex, boolean positive) { - ((UIMenuTableDataModel)dataModel).dragSort(rowIndex, positive); - } - - @Override - public boolean isCellEditable(int row, int column) { - if(column == 0) { - return false; - } else { - return super.isCellEditable(row, column); - } - } - - @Override - public TableUI getUI() { - return new UIMenuTableUI(); - } - - private void initComponents() { - setShowGrid(false); - setRowHeight(20); - setDragEnabled(false); - setDefaultRenderer(UITable.class, new UITableRender()); - setUI(getUI()); - } - - @Override - public TableCellRenderer getDefaultRenderer(Class columnClass) { - return super.getDefaultRenderer(UITable.class); - } - - private class UITableRender implements TableCellRenderer { - @Override - public Component getTableCellRendererComponent(JTable table, - Object value, boolean isSelected, boolean hasFocus, int row, - int column) { - JPanel pane = new JPanel(new BorderLayout(4,0)); - Color back = getRenderBackground(row); - pane.setBackground(back); - - if(draggingIndex == row) { - return pane; - } - pane.add(getRenderCompoment(value, row, column), BorderLayout.CENTER); - return pane; - } - } - - protected void setRollOverRowIndex(int rowIndex) { - this.rollOverRowIndex = rowIndex; - } - - protected void setDraggingRowIndex(int rowIndex) { - this.draggingIndex = rowIndex; - } - - public void fireTargetChanged() { - repaint(); - Object[] listeners = listenerList.getListenerList(); - - for (int i = listeners.length - 2; i >= 0; i -= 2) { - if (listeners[i] == ChangeListener.class) { - ((ChangeListener)listeners[i + 1]).stateChanged(new ChangeEvent(this)); - } - } - } - - public void addChangeListener(ChangeListener l) { - this.listenerList.add(ChangeListener.class, l); - } - - public void removeChangeListener(ChangeListener l) { - this.listenerList.remove(ChangeListener.class, l); - } - - public static void main(String... args) { - JFrame jf = new JFrame("test"); - jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - JPanel content = (JPanel)jf.getContentPane(); - content.setLayout(new BorderLayout()); - List data = new ArrayList(); - UIMenuNameableCreator reportlet = new UIMenuNameableCreator(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Reportlet"), - new ReportletHyperlink(), ReportletHyperlinkPane.class); - - UIMenuNameableCreator email = new UIMenuNameableCreator(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Email"), - new EmailJavaScript(), EmailPane.class); - - UIMenuNameableCreator web = new UIMenuNameableCreator(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Hyperlink_Web_Link"), - new WebHyperlink(), WebHyperlinkPane.class ); - data.add(reportlet); - data.add(email); - data.add(web); - UIMenuTable pane = new UIMenuTable(); - pane.populateBean(data); - content.add(pane, BorderLayout.CENTER); - GUICoreUtils.centerWindow(jf); - jf.setSize(400, 400); - jf.setVisible(true); - } + public void doOk() { + baseShowPane.updateBean(showValue); + fireTargetChanged(); + } + }); + + dialog.setSize(500, 600); + GUICoreUtils.centerWindow(dialog); + + dialog.setVisible(true); + } + + protected Color getRenderBackground(int row) { + if (selectedRowIndex == row) { + return UIConstants.SKY_BLUE; + } else { + return (rollOverRowIndex == row) ? UIConstants.LIGHT_BLUE : UIConstants.NORMAL_BACKGROUND; + } + } + + /** + * @param value 该行列的值(字符串) + * @param row + * @param column + * @return 列表中默认显示的东西,如果有很多内容,可以装载一个JPanel里再嵌进来 + */ + protected JComponent getRenderCompoment(Object value, int row, int column) { + UILabel text = new UILabel(); + if (value != null) { + text.setText(value.toString()); + } + return text; + } + + /** + * @param line 该行的内容 + * 在table底部增加一行内容 + */ + public void addLine(UIMenuNameableCreator line) { + ((UIMenuTableDataModel) dataModel).addLine(line); + } + + /** + * @param rowIndex + * @return 某一行的内容 + */ + public UIMenuNameableCreator getLine(int rowIndex) { + return ((UIMenuTableDataModel) dataModel).getLine(rowIndex); + } + + /** + * 删除某行内容 + * + * @param rowIndex + */ + public void removeLine(int rowIndex) { + ((UIMenuTableDataModel) dataModel).removeLine(rowIndex); + } + + /** + * 清除所有的内容 + */ + public void clearAll() { + int rowCount = dataModel.getRowCount(); + for (int i = 0; i < rowCount; i++) { + removeLine(i); + } + } + + /** + * 对某一行拖动时进行排序 + * + * @param rowIndex + * @param positive 鼠标移动的距离 + */ + public void dragSort(int rowIndex, boolean positive) { + ((UIMenuTableDataModel) dataModel).dragSort(rowIndex, positive); + } + + @Override + public boolean isCellEditable(int row, int column) { + if (column == 0) { + return false; + } else { + return super.isCellEditable(row, column); + } + } + + @Override + public TableUI getUI() { + return new UIMenuTableUI(); + } + + private void initComponents() { + setShowGrid(false); + setRowHeight(20); + setDragEnabled(false); + setDefaultRenderer(UITable.class, new UITableRender()); + setUI(getUI()); + } + + @Override + public TableCellRenderer getDefaultRenderer(Class columnClass) { + // 处理null的情况用于创建时未指定数据结构的情况 + if (columnClass == null) { + return createDefaultRenderer(); + } + return super.getDefaultRenderer(columnClass); + } + + private @NotNull TableCellRenderer createDefaultRenderer() { + Object renderer = defaultRenderersByColumnClass.get(UITable.class); + return renderer != null ? (TableCellRenderer) renderer : new UITableRender(); + } + + private class UITableRender implements TableCellRenderer { + @Override + public Component getTableCellRendererComponent(JTable table, + Object value, boolean isSelected, boolean hasFocus, int row, + int column) { + JPanel pane = new JPanel(new BorderLayout(4, 0)); + Color back = getRenderBackground(row); + pane.setBackground(back); + + if (draggingIndex == row) { + return pane; + } + pane.add(getRenderCompoment(value, row, column), BorderLayout.CENTER); + return pane; + } + } + + protected void setRollOverRowIndex(int rowIndex) { + this.rollOverRowIndex = rowIndex; + } + + protected void setDraggingRowIndex(int rowIndex) { + this.draggingIndex = rowIndex; + } + + public void fireTargetChanged() { + repaint(); + Object[] listeners = listenerList.getListenerList(); + + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == ChangeListener.class) { + ((ChangeListener) listeners[i + 1]).stateChanged(new ChangeEvent(this)); + } + } + } + + public void addChangeListener(ChangeListener l) { + this.listenerList.add(ChangeListener.class, l); + } + + public void removeChangeListener(ChangeListener l) { + this.listenerList.remove(ChangeListener.class, l); + } + + public static void main(String... args) { + JFrame jf = new JFrame("test"); + jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + JPanel content = (JPanel) jf.getContentPane(); + content.setLayout(new BorderLayout()); + List data = new ArrayList(); + UIMenuNameableCreator reportlet = new UIMenuNameableCreator(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Reportlet"), + new ReportletHyperlink(), ReportletHyperlinkPane.class); + + UIMenuNameableCreator email = new UIMenuNameableCreator(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Email"), + new EmailJavaScript(), EmailPane.class); + + UIMenuNameableCreator web = new UIMenuNameableCreator(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Hyperlink_Web_Link"), + new WebHyperlink(), WebHyperlinkPane.class); + data.add(reportlet); + data.add(email); + data.add(web); + UIMenuTable pane = new UIMenuTable(); + pane.populateBean(data); + content.add(pane, BorderLayout.CENTER); + GUICoreUtils.centerWindow(jf); + jf.setSize(400, 400); + jf.setVisible(true); + } } diff --git a/designer-base/src/main/java/com/fr/design/gui/itable/UITable.java b/designer-base/src/main/java/com/fr/design/gui/itable/UITable.java index 2ddb20a7d3..a883742e72 100644 --- a/designer-base/src/main/java/com/fr/design/gui/itable/UITable.java +++ b/designer-base/src/main/java/com/fr/design/gui/itable/UITable.java @@ -6,6 +6,7 @@ import com.fr.design.event.UIObserverListener; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.utils.gui.GUICoreUtils; +import org.jetbrains.annotations.NotNull; import javax.swing.BorderFactory; import javax.swing.JComponent; @@ -35,29 +36,29 @@ public class UITable extends JTable implements UIObserver { private static final int OFF_LEFT = 10; - private static final int DEFAULT_ROW_HEIGHT =20; + private static final int DEFAULT_ROW_HEIGHT = 20; private UIObserverListener uiObserverListener; - UITableEditor editor ; + UITableEditor editor; private boolean shouldResponseAwt; private boolean isEditingStopped; /** - * 在没有任何数据的时候,使用此构造函数,然后通过populate更新数据 - * - * @param columnSize 列表的列数 - */ - public UITable(int columnSize) { - - super(new UITableDataModel(columnSize)); - initComponents(); + * 在没有任何数据的时候,使用此构造函数,然后通过populate更新数据 + * + * @param columnSize 列表的列数 + */ + public UITable(int columnSize) { + + super(new UITableDataModel(columnSize)); + initComponents(); iniListener(); shouldResponseAwt = false; // kunsnat: 屏蔽: 对于下拉框, 无法等待选择结果之后在stop.. // Toolkit.getDefaultToolkit().addAWTEventListener(awt, AWTEvent.MOUSE_EVENT_MASK); - } + } - public UITable (int columnSize, boolean needAWTEventListener) { + public UITable(int columnSize, boolean needAWTEventListener) { this(columnSize); shouldResponseAwt = needAWTEventListener; isEditingStopped = true; @@ -71,180 +72,182 @@ public class UITable extends JTable implements UIObserver { } } - /** - * values不允许为空! - * - * @param values 一个列表,里面装有字符串数组,每个数组代表一行内容 - */ - public UITable(List values) { - super(new UITableDataModel(values)); - initComponents(); + /** + * values不允许为空! + * + * @param values 一个列表,里面装有字符串数组,每个数组代表一行内容 + */ + public UITable(List values) { + super(new UITableDataModel(values)); + initComponents(); iniListener(); - } - - public UITable() { + } - } + public UITable() { - public void populateBean(List values) { - getTableDataModel().populateBean(values); - } + } + public void populateBean(List values) { + getTableDataModel().populateBean(values); + } private AWTEventListener awt = new AWTEventListener() { - public void eventDispatched(AWTEvent event) { - if(!UITable.this.isShowing()){ - return; + public void eventDispatched(AWTEvent event) { + if (!UITable.this.isShowing()) { + return; + } + doSomeInAll(event); + } + }; + + private void doSomeInAll(AWTEvent event) { + Rectangle bounds = new Rectangle(getLocationOnScreen().x, getLocationOnScreen().y, getWidth(), getHeight()); + if (event instanceof MouseEvent) { + MouseEvent mv = (MouseEvent) event; + if (mv.getClickCount() > 0) { + Point point = new Point((int) (mv.getLocationOnScreen().getX()) - 2 * OFF_LEFT, (int) mv.getLocationOnScreen().getY()); + // 判断鼠标点击是否在边界内 + if (!bounds.contains(point) && shouldResponseAwt) { + if (!isEditingStopped) { + this.editor.stopCellEditing(); + isEditingStopped = true; + } } - doSomeInAll(event); - } - }; - - private void doSomeInAll(AWTEvent event) { - Rectangle bounds = new Rectangle(getLocationOnScreen().x, getLocationOnScreen().y, getWidth(), getHeight()); - if (event instanceof MouseEvent) { - MouseEvent mv = (MouseEvent) event; - if (mv.getClickCount() > 0) { - Point point = new Point((int) (mv.getLocationOnScreen().getX()) - 2 * OFF_LEFT, (int) mv.getLocationOnScreen().getY()); - // 判断鼠标点击是否在边界内 - if (!bounds.contains(point) && shouldResponseAwt) { - if (!isEditingStopped) { - this.editor.stopCellEditing(); - isEditingStopped = true; - } - } - } - } - } - - public List updateBean() { - return getTableDataModel().updateBean(); - } - - /** - * 在table底部增加一空行 - */ - public void addBlankLine() { - getTableDataModel().addBlankLine(); - } - - /** - * 在table底部增加一行内容 - * @param line 该行的内容 - */ - public void addLine(Object[] line) { - getTableDataModel().addLine(line); - } - - /** - * @param rowIndex - * @return 某一行的内容 - */ - public Object[] getLine(int rowIndex) { - return getTableDataModel().getLine(rowIndex); - } - - /** - * 删除某行内容 - * - * @param rowIndex 行号 - */ - public void removeLine(int rowIndex) { - getTableDataModel().removeLine(rowIndex); - } - - /** - * 对某一行拖动时进行排序 - * - * @param rowIndex 行号 - * @param positive 鼠标移动的距离 - */ - public void dragSort(int rowIndex, boolean positive) { - ((UITableDataModel) dataModel).dragSort(rowIndex, positive); - } - - - /** - *格子是否可编辑,可置顶某一列column不可编辑 - * @param row 行号 - * @param column 列号 - * @return 是否可编辑 - */ - public boolean isCellEditable(int row, int column) { - return true; - } - - /** - * 清空数据 - */ - public void clear() { - getTableDataModel().clear(); - } - - private UITableDataModel getTableDataModel() { - return (UITableDataModel) dataModel; - } - - /** - * @param value 该行列的值(字符串) - * @param row - * @param column - * @return 列表中默认显示的东西,如果有很多内容,可以装载一个JPanel里再嵌进来 - */ - protected JComponent getRenderCompoment(Object value, int row, int column) { - UILabel text = new UILabel(); - if (value != null) { - text.setText(value.toString()); - } - return text; - } - - protected void initComponents() { - setShowGrid(false); - setRowHeight(getRowHeight4Table()); - setDragEnabled(false); - editor = createTableEditor(); - editor.addCellEditorListener(new CellEditorListener() { - @Override - public void editingStopped(ChangeEvent e) { - tableCellEditingStopped(e); - } - - @Override - public void editingCanceled(ChangeEvent e) { - tableCellEditingCanceled(e); - } - - }); - - setBackground(UIConstants.NORMAL_BACKGROUND); - setDefaultEditor(UITable.class, editor); - setDefaultRenderer(UITable.class, new UITableRender()); + } + } + } + + public List updateBean() { + return getTableDataModel().updateBean(); + } + + /** + * 在table底部增加一空行 + */ + public void addBlankLine() { + getTableDataModel().addBlankLine(); + } + + /** + * 在table底部增加一行内容 + * + * @param line 该行的内容 + */ + public void addLine(Object[] line) { + getTableDataModel().addLine(line); + } + + /** + * @param rowIndex + * @return 某一行的内容 + */ + public Object[] getLine(int rowIndex) { + return getTableDataModel().getLine(rowIndex); + } + + /** + * 删除某行内容 + * + * @param rowIndex 行号 + */ + public void removeLine(int rowIndex) { + getTableDataModel().removeLine(rowIndex); + } + + /** + * 对某一行拖动时进行排序 + * + * @param rowIndex 行号 + * @param positive 鼠标移动的距离 + */ + public void dragSort(int rowIndex, boolean positive) { + ((UITableDataModel) dataModel).dragSort(rowIndex, positive); + } + + + /** + * 格子是否可编辑,可置顶某一列column不可编辑 + * + * @param row 行号 + * @param column 列号 + * @return 是否可编辑 + */ + public boolean isCellEditable(int row, int column) { + return true; + } + + /** + * 清空数据 + */ + public void clear() { + getTableDataModel().clear(); + } + + private UITableDataModel getTableDataModel() { + return (UITableDataModel) dataModel; + } + + /** + * @param value 该行列的值(字符串) + * @param row + * @param column + * @return 列表中默认显示的东西,如果有很多内容,可以装载一个JPanel里再嵌进来 + */ + protected JComponent getRenderCompoment(Object value, int row, int column) { + UILabel text = new UILabel(); + if (value != null) { + text.setText(value.toString()); + } + return text; + } + + protected void initComponents() { + setShowGrid(false); + setRowHeight(getRowHeight4Table()); + setDragEnabled(false); + editor = createTableEditor(); + editor.addCellEditorListener(new CellEditorListener() { + @Override + public void editingStopped(ChangeEvent e) { + tableCellEditingStopped(e); + } + + @Override + public void editingCanceled(ChangeEvent e) { + tableCellEditingCanceled(e); + } + + }); + + setBackground(UIConstants.NORMAL_BACKGROUND); + setDefaultEditor(UITable.class, editor); + setDefaultRenderer(UITable.class, new UITableRender()); // setUI(getUI()); - - TableColumn deleteTableColumn = new TableColumn(getTableDataModel().getColumnCount()); - deleteTableColumn.setCellEditor(null); - deleteTableColumn.setCellRenderer(null); - deleteTableColumn.setMaxWidth(20); - getColumnModel().addColumn(deleteTableColumn); - } - - /** - * 鼠标悬浮再某一行时触发的事件 - * @param index 行号 - */ - public void dealWithRollOver(int index){ - - } - - private void iniListener(){ - if(shouldResponseChangeListener()){ + + TableColumn deleteTableColumn = new TableColumn(getTableDataModel().getColumnCount()); + deleteTableColumn.setCellEditor(null); + deleteTableColumn.setCellRenderer(null); + deleteTableColumn.setMaxWidth(20); + getColumnModel().addColumn(deleteTableColumn); + } + + /** + * 鼠标悬浮再某一行时触发的事件 + * + * @param index 行号 + */ + public void dealWithRollOver(int index) { + + } + + private void iniListener() { + if (shouldResponseChangeListener()) { this.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { - if(uiObserverListener == null){ - return ; + if (uiObserverListener == null) { + return; } uiObserverListener.doChange(); } @@ -252,138 +255,142 @@ public class UITable extends JTable implements UIObserver { } } - protected int getRowHeight4Table() { - return DEFAULT_ROW_HEIGHT; - } + protected int getRowHeight4Table() { + return DEFAULT_ROW_HEIGHT; + } - /** - *停止编辑事件 - * @param e 事件 - */ - public void tableCellEditingStopped(ChangeEvent e) { + /** + * 停止编辑事件 + * + * @param e 事件 + */ + public void tableCellEditingStopped(ChangeEvent e) { - } + } /** - *取消编辑事件 + * 取消编辑事件 + * * @param e 事件 */ - public void tableCellEditingCanceled(ChangeEvent e) { + public void tableCellEditingCanceled(ChangeEvent e) { - } - - /** - * 编辑器 - * @return 编辑器 - */ - public UITableEditor createTableEditor() { - return new UIDefaultTableCellEditor(new UITextField()); - } + } - @Override /** + * 编辑器 * + * @return 编辑器 */ - public TableUI getUI() { - return new UITableUI(); - } + public UITableEditor createTableEditor() { + return new UIDefaultTableCellEditor(new UITextField()); + } -// @Override + @Override /** * */ -// public TableCellEditor getDefaultEditor(Class columnClass) { -// return super.getDefaultEditor(UITable.class); -// } + public TableUI getUI() { + return new UITableUI(); + } + + @Override + public TableCellRenderer getDefaultRenderer(Class columnClass) { + // 处理null的情况用于创建时未指定数据结构的情况 + if (columnClass == null) { + return createDefaultRenderer(); + } + return super.getDefaultRenderer(columnClass); + } + + private @NotNull TableCellRenderer createDefaultRenderer() { + Object renderer = defaultRenderersByColumnClass.get(UITable.class); + return renderer != null ? (TableCellRenderer) renderer : new UITableRender(); + } -// @Override /** + * 给组件登记一个观察者监听事件 * + * @param listener 观察者监听事件 */ -// public TableCellRenderer getDefaultRenderer(Class columnClass) { -// return super.getDefaultRenderer(UITable.class); -// } - - /** - * 给组件登记一个观察者监听事件 - * - * @param listener 观察者监听事件 - */ public void registerChangeListener(UIObserverListener listener) { uiObserverListener = listener; } - /** - * 组件是否需要响应添加的观察者事件 - * - * @return 如果需要响应观察者事件则返回true,否则返回false - */ + /** + * 组件是否需要响应添加的观察者事件 + * + * @return 如果需要响应观察者事件则返回true,否则返回false + */ public boolean shouldResponseChangeListener() { return true; } protected class UITableRender implements TableCellRenderer { - @Override - public Component getTableCellRendererComponent(JTable table, - Object value, boolean isSelected, boolean hasFocus, int row, - int column) { - JComponent comp = getRenderCompoment(value, row, column); - comp.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); - return comp; - } - } - - protected void fireTargetChanged() { - repaint(); - Object[] listeners = listenerList.getListenerList(); - - for (int i = listeners.length - 2; i >= 0; i -= 2) { - if (listeners[i] == ChangeListener.class) { - ((ChangeListener) listeners[i + 1]).stateChanged(new ChangeEvent(this)); - } - } - } - - /** - * 增加监听 - * @param l 监听 - */ - public void addChangeListener(ChangeListener l) { - this.listenerList.add(ChangeListener.class, l); - } + @Override + public Component getTableCellRendererComponent(JTable table, + Object value, boolean isSelected, boolean hasFocus, int row, + int column) { + JComponent comp = getRenderCompoment(value, row, column); + comp.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); + return comp; + } + } + + protected void fireTargetChanged() { + repaint(); + Object[] listeners = listenerList.getListenerList(); + + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == ChangeListener.class) { + ((ChangeListener) listeners[i + 1]).stateChanged(new ChangeEvent(this)); + } + } + } + + /** + * 增加监听 + * + * @param l 监听 + */ + public void addChangeListener(ChangeListener l) { + this.listenerList.add(ChangeListener.class, l); + } /** - *移除监听 + * 移除监听 + * * @param l 监听 */ - public void removeChangeListener(ChangeListener l) { - this.listenerList.remove(ChangeListener.class, l); - } + public void removeChangeListener(ChangeListener l) { + this.listenerList.remove(ChangeListener.class, l); + } /** - *测试主函数 + * 测试主函数 + * * @param args 参数 */ - public static void main(String... args) { - JFrame jf = new JFrame("test"); - jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - JPanel content = (JPanel) jf.getContentPane(); - content.setLayout(new BorderLayout()); - List data = new ArrayList(); - String[] a = {"1", "11"}; - String[] b = {"2", "22"}; - String[] c = {"3", "33"}; - String[] d = {"4", "44"}; - data.add(a); - data.add(b); - data.add(c); - data.add(d); - UITable pane = new UITable(2); - pane.populateBean(data); - content.add(pane, BorderLayout.CENTER); - GUICoreUtils.centerWindow(jf); - jf.setSize(400, 400); - jf.setVisible(true); - } + public static void main(String... args) { + JFrame jf = new JFrame("test"); + jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + JPanel content = (JPanel) jf.getContentPane(); + content.setLayout(new BorderLayout()); + List data = new ArrayList(); + String[] a = {"1", "11"}; + String[] b = {"2", "22"}; + String[] c = {"3", "33"}; + String[] d = {"4", "44"}; + data.add(a); + data.add(b); + data.add(c); + data.add(d); + UITable pane = new UITable(2); + pane.populateBean(data); + content.add(pane, BorderLayout.CENTER); + GUICoreUtils.centerWindow(jf); + jf.setSize(400, 400); + jf.setVisible(true); + } } \ No newline at end of file From f80e26f59506cd2d9ce0fcb6df80c25184d4f4d8 Mon Sep 17 00:00:00 2001 From: vito Date: Thu, 29 Feb 2024 17:34:34 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=97=A0jira=E4=BB=BB=E5=8A=A1=20=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=B4=A8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/gui/imenutable/UIMenuTable.java | 49 ++++------- .../com/fr/design/gui/itable/UITable.java | 85 +++++++------------ 2 files changed, 45 insertions(+), 89 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/imenutable/UIMenuTable.java b/designer-base/src/main/java/com/fr/design/gui/imenutable/UIMenuTable.java index 488b449939..ddee51dc5b 100644 --- a/designer-base/src/main/java/com/fr/design/gui/imenutable/UIMenuTable.java +++ b/designer-base/src/main/java/com/fr/design/gui/imenutable/UIMenuTable.java @@ -6,17 +6,10 @@ import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.UIDialog; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itable.UITable; -import com.fr.design.hyperlink.ReportletHyperlinkPane; -import com.fr.design.hyperlink.WebHyperlinkPane; -import com.fr.design.javascript.EmailPane; import com.fr.design.utils.gui.GUICoreUtils; -import com.fr.js.EmailJavaScript; -import com.fr.js.ReportletHyperlink; -import com.fr.js.WebHyperlink; import org.jetbrains.annotations.NotNull; import javax.swing.JComponent; -import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.SwingUtilities; @@ -27,10 +20,10 @@ import javax.swing.table.TableCellRenderer; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; -import java.util.ArrayList; import java.util.List; public class UIMenuTable extends JTable { + private static final int STEP = 2; protected int selectedRowIndex = -1; protected int rollOverRowIndex = -1; protected int draggingIndex = -1; @@ -201,47 +194,35 @@ public class UIMenuTable extends JTable { this.draggingIndex = rowIndex; } + /** + * 触发变更通知 + */ public void fireTargetChanged() { repaint(); Object[] listeners = listenerList.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { + for (int i = listeners.length - STEP; i >= 0; i -= STEP) { if (listeners[i] == ChangeListener.class) { ((ChangeListener) listeners[i + 1]).stateChanged(new ChangeEvent(this)); } } } + /** + * 添加变更监听 + * + * @param l 监听对象 + */ public void addChangeListener(ChangeListener l) { this.listenerList.add(ChangeListener.class, l); } + /** + * 删除变更监听 + * + * @param l 监听对象 + */ public void removeChangeListener(ChangeListener l) { this.listenerList.remove(ChangeListener.class, l); } - - public static void main(String... args) { - JFrame jf = new JFrame("test"); - jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - JPanel content = (JPanel) jf.getContentPane(); - content.setLayout(new BorderLayout()); - List data = new ArrayList(); - UIMenuNameableCreator reportlet = new UIMenuNameableCreator(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Reportlet"), - new ReportletHyperlink(), ReportletHyperlinkPane.class); - - UIMenuNameableCreator email = new UIMenuNameableCreator(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Email"), - new EmailJavaScript(), EmailPane.class); - - UIMenuNameableCreator web = new UIMenuNameableCreator(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Hyperlink_Web_Link"), - new WebHyperlink(), WebHyperlinkPane.class); - data.add(reportlet); - data.add(email); - data.add(web); - UIMenuTable pane = new UIMenuTable(); - pane.populateBean(data); - content.add(pane, BorderLayout.CENTER); - GUICoreUtils.centerWindow(jf); - jf.setSize(400, 400); - jf.setVisible(true); - } } diff --git a/designer-base/src/main/java/com/fr/design/gui/itable/UITable.java b/designer-base/src/main/java/com/fr/design/gui/itable/UITable.java index a883742e72..f66d483261 100644 --- a/designer-base/src/main/java/com/fr/design/gui/itable/UITable.java +++ b/designer-base/src/main/java/com/fr/design/gui/itable/UITable.java @@ -5,37 +5,33 @@ import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserverListener; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextfield.UITextField; -import com.fr.design.utils.gui.GUICoreUtils; import org.jetbrains.annotations.NotNull; import javax.swing.BorderFactory; import javax.swing.JComponent; -import javax.swing.JFrame; -import javax.swing.JPanel; import javax.swing.JTable; import javax.swing.event.CellEditorListener; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.plaf.TableUI; +import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; import java.awt.AWTEvent; -import java.awt.BorderLayout; import java.awt.Component; import java.awt.Point; import java.awt.Rectangle; import java.awt.Toolkit; -import java.awt.event.AWTEventListener; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.awt.event.MouseEvent; -import java.util.ArrayList; import java.util.List; public class UITable extends JTable implements UIObserver { private static final int OFF_LEFT = 10; + private static final int STEP = 2; private static final int DEFAULT_ROW_HEIGHT = 20; private UIObserverListener uiObserverListener; UITableEditor editor; @@ -54,8 +50,6 @@ public class UITable extends JTable implements UIObserver { initComponents(); iniListener(); shouldResponseAwt = false; - // kunsnat: 屏蔽: 对于下拉框, 无法等待选择结果之后在stop.. -// Toolkit.getDefaultToolkit().addAWTEventListener(awt, AWTEvent.MOUSE_EVENT_MASK); } public UITable(int columnSize, boolean needAWTEventListener) { @@ -63,7 +57,12 @@ public class UITable extends JTable implements UIObserver { shouldResponseAwt = needAWTEventListener; isEditingStopped = true; if (needAWTEventListener) { - Toolkit.getDefaultToolkit().addAWTEventListener(awt, AWTEvent.MOUSE_EVENT_MASK); + Toolkit.getDefaultToolkit().addAWTEventListener(event -> { + if (!UITable.this.isShowing()) { + return; + } + doSomeInAll(event); + }, AWTEvent.MOUSE_EVENT_MASK); this.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { isEditingStopped = false; @@ -87,20 +86,16 @@ public class UITable extends JTable implements UIObserver { } + /** + * 传入列表数据 + * + * @param values 数据 + */ public void populateBean(List values) { getTableDataModel().populateBean(values); } - private AWTEventListener awt = new AWTEventListener() { - public void eventDispatched(AWTEvent event) { - if (!UITable.this.isShowing()) { - return; - } - doSomeInAll(event); - } - }; - private void doSomeInAll(AWTEvent event) { Rectangle bounds = new Rectangle(getLocationOnScreen().x, getLocationOnScreen().y, getWidth(), getHeight()); if (event instanceof MouseEvent) { @@ -118,6 +113,11 @@ public class UITable extends JTable implements UIObserver { } } + /** + * 获取模型中数据 + * + * @return 数据 + */ public List updateBean() { return getTableDataModel().updateBean(); } @@ -223,7 +223,7 @@ public class UITable extends JTable implements UIObserver { setBackground(UIConstants.NORMAL_BACKGROUND); setDefaultEditor(UITable.class, editor); setDefaultRenderer(UITable.class, new UITableRender()); -// setUI(getUI()); + setUI(getUI()); TableColumn deleteTableColumn = new TableColumn(getTableDataModel().getColumnCount()); deleteTableColumn.setCellEditor(null); @@ -243,14 +243,11 @@ public class UITable extends JTable implements UIObserver { private void iniListener() { if (shouldResponseChangeListener()) { - this.addChangeListener(new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - if (uiObserverListener == null) { - return; - } - uiObserverListener.doChange(); + this.addChangeListener(e -> { + if (uiObserverListener == null) { + return; } + uiObserverListener.doChange(); }); } } @@ -295,6 +292,11 @@ public class UITable extends JTable implements UIObserver { return new UITableUI(); } + @Override + public TableCellEditor getDefaultEditor(Class columnClass) { + return super.getDefaultEditor(UITable.class); + } + @Override public TableCellRenderer getDefaultRenderer(Class columnClass) { // 处理null的情况用于创建时未指定数据结构的情况 @@ -342,7 +344,7 @@ public class UITable extends JTable implements UIObserver { repaint(); Object[] listeners = listenerList.getListenerList(); - for (int i = listeners.length - 2; i >= 0; i -= 2) { + for (int i = listeners.length - STEP; i >= 0; i -= STEP) { if (listeners[i] == ChangeListener.class) { ((ChangeListener) listeners[i + 1]).stateChanged(new ChangeEvent(this)); } @@ -366,31 +368,4 @@ public class UITable extends JTable implements UIObserver { public void removeChangeListener(ChangeListener l) { this.listenerList.remove(ChangeListener.class, l); } - - /** - * 测试主函数 - * - * @param args 参数 - */ - public static void main(String... args) { - JFrame jf = new JFrame("test"); - jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - JPanel content = (JPanel) jf.getContentPane(); - content.setLayout(new BorderLayout()); - List data = new ArrayList(); - String[] a = {"1", "11"}; - String[] b = {"2", "22"}; - String[] c = {"3", "33"}; - String[] d = {"4", "44"}; - data.add(a); - data.add(b); - data.add(c); - data.add(d); - UITable pane = new UITable(2); - pane.populateBean(data); - content.add(pane, BorderLayout.CENTER); - GUICoreUtils.centerWindow(jf); - jf.setSize(400, 400); - jf.setVisible(true); - } -} \ No newline at end of file +} From fed17e839b50bddf8a30d41c76d4806e97ac7a12 Mon Sep 17 00:00:00 2001 From: vito Date: Thu, 29 Feb 2024 18:21:05 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=97=A0jira=E4=BB=BB=E5=8A=A1=20=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=B4=A8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/gui/imenutable/UIMenuTable.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/designer-base/src/main/java/com/fr/design/gui/imenutable/UIMenuTable.java b/designer-base/src/main/java/com/fr/design/gui/imenutable/UIMenuTable.java index ddee51dc5b..764085a709 100644 --- a/designer-base/src/main/java/com/fr/design/gui/imenutable/UIMenuTable.java +++ b/designer-base/src/main/java/com/fr/design/gui/imenutable/UIMenuTable.java @@ -33,14 +33,30 @@ public class UIMenuTable extends JTable { initComponents(); } + /** + * 传入列表数据 + * + * @param values 数据 + */ public void populateBean(List values) { ((UIMenuTableDataModel) dataModel).populateBean(values); } + /** + * 获取模型中数据 + * + * @return 数据 + */ public List updateBean() { return ((UIMenuTableDataModel) dataModel).updateBean(); } + /** + * 编辑事件 + * + * @param rowIndex 行索引 + * @param mouseY mouseY + */ public void editingEvent(int rowIndex, int mouseY) { selectedRowIndex = rowIndex; repaint();