Browse Source

Pull request #13612: REPORT-114888 fix:设计器新UI图表无法打开配置面板

Merge in DESIGN/design from ~VITO/c-design:newui to newui

* commit 'fed17e839b50bddf8a30d41c76d4806e97ac7a12':
  无jira任务 代码质量
  无jira任务 代码质量
  REPORT-114888 fix:设计器新UI图表无法打开配置面板
newui
vito-刘恒霖 9 months ago
parent
commit
60691c0446
  1. 4
      build.gradle
  2. 89
      designer-base/src/main/java/com/fr/design/gui/imenutable/UIMenuTable.java
  3. 112
      designer-base/src/main/java/com/fr/design/gui/itable/UITable.java

4
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'

89
designer-base/src/main/java/com/fr/design/gui/imenutable/UIMenuTable.java

@ -6,25 +6,24 @@ 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 org.jetbrains.annotations.NotNull;
import com.fr.js.EmailJavaScript;
import com.fr.js.ReportletHyperlink;
import com.fr.js.WebHyperlink;
import javax.swing.*;
import javax.swing.JComponent;
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.util.ArrayList;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
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;
@ -34,14 +33,30 @@ public class UIMenuTable extends JTable {
initComponents();
}
/**
* 传入列表数据
*
* @param values 数据
*/
public void populateBean(List<UIMenuNameableCreator> values) {
((UIMenuTableDataModel) dataModel).populateBean(values);
}
/**
* 获取模型中数据
*
* @return 数据
*/
public List<UIMenuNameableCreator> updateBean() {
return ((UIMenuTableDataModel) dataModel).updateBean();
}
/**
* 编辑事件
*
* @param rowIndex 行索引
* @param mouseY mouseY
*/
public void editingEvent(int rowIndex, int mouseY) {
selectedRowIndex = rowIndex;
repaint();
@ -76,7 +91,6 @@ public class UIMenuTable extends JTable {
}
/**
*
* @param value 该行列的值(字符串)
* @param row
* @param column
@ -108,6 +122,7 @@ public class UIMenuTable extends JTable {
/**
* 删除某行内容
*
* @param rowIndex
*/
public void removeLine(int rowIndex) {
@ -126,6 +141,7 @@ public class UIMenuTable extends JTable {
/**
* 对某一行拖动时进行排序
*
* @param rowIndex
* @param positive 鼠标移动的距离
*/
@ -157,7 +173,16 @@ public class UIMenuTable extends JTable {
@Override
public TableCellRenderer getDefaultRenderer(Class<?> columnClass) {
return super.getDefaultRenderer(UITable.class);
// 处理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 {
@ -185,47 +210,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<UIMenuNameableCreator> data = new ArrayList<UIMenuNameableCreator>();
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);
}
}

112
designer-base/src/main/java/com/fr/design/gui/itable/UITable.java

@ -5,36 +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;
@ -53,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) {
@ -62,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;
@ -86,21 +86,16 @@ public class UITable extends JTable implements UIObserver {
}
/**
* 传入列表数据
*
* @param values 数据
*/
public void populateBean(List<Object[]> 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<Object[]> updateBean() {
return getTableDataModel().updateBean();
}
@ -131,6 +131,7 @@ public class UITable extends JTable implements UIObserver {
/**
* 在table底部增加一行内容
*
* @param line 该行的内容
*/
public void addLine(Object[] line) {
@ -167,6 +168,7 @@ public class UITable extends JTable implements UIObserver {
/**
* 格子是否可编辑可置顶某一列column不可编辑
*
* @param row 行号
* @param column 列号
* @return 是否可编辑
@ -221,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);
@ -232,6 +234,7 @@ public class UITable extends JTable implements UIObserver {
/**
* 鼠标悬浮再某一行时触发的事件
*
* @param index 行号
*/
public void dealWithRollOver(int index) {
@ -240,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) {
this.addChangeListener(e -> {
if (uiObserverListener == null) {
return;
}
uiObserverListener.doChange();
}
});
}
}
@ -259,6 +259,7 @@ public class UITable extends JTable implements UIObserver {
/**
* 停止编辑事件
*
* @param e 事件
*/
public void tableCellEditingStopped(ChangeEvent e) {
@ -267,6 +268,7 @@ public class UITable extends JTable implements UIObserver {
/**
* 取消编辑事件
*
* @param e 事件
*/
public void tableCellEditingCanceled(ChangeEvent e) {
@ -275,6 +277,7 @@ public class UITable extends JTable implements UIObserver {
/**
* 编辑器
*
* @return 编辑器
*/
public UITableEditor createTableEditor() {
@ -289,21 +292,24 @@ public class UITable extends JTable implements UIObserver {
return new UITableUI();
}
// @Override
/**
*
*/
// public TableCellEditor getDefaultEditor(Class<?> columnClass) {
// return super.getDefaultEditor(UITable.class);
// }
@Override
public TableCellEditor getDefaultEditor(Class<?> columnClass) {
return super.getDefaultEditor(UITable.class);
}
// @Override
/**
*
*/
// public TableCellRenderer getDefaultRenderer(Class<?> columnClass) {
// return super.getDefaultRenderer(UITable.class);
// }
@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();
}
/**
* 给组件登记一个观察者监听事件
@ -338,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));
}
@ -347,6 +353,7 @@ public class UITable extends JTable implements UIObserver {
/**
* 增加监听
*
* @param l 监听
*/
public void addChangeListener(ChangeListener l) {
@ -355,35 +362,10 @@ public class UITable extends JTable implements UIObserver {
/**
* 移除监听
*
* @param 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<Object[]> data = new ArrayList<Object[]>();
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);
}
}
Loading…
Cancel
Save