Browse Source

在上层统一处理 swing 线程同步问题

bugfix/10.0
yaoh.wu 6 years ago
parent
commit
f6f5da0f00
  1. 16
      designer-form/src/main/java/com/fr/design/designer/beans/events/CreatorEventListenerTable.java
  2. 6
      designer-form/src/main/java/com/fr/design/form/parameter/FormParaDesigner.java
  3. 8
      designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java
  4. 6
      designer-form/src/main/java/com/fr/design/mainframe/FormHierarchyTreePane.java

16
designer-form/src/main/java/com/fr/design/designer/beans/events/CreatorEventListenerTable.java

@ -1,10 +1,11 @@
package com.fr.design.designer.beans.events; package com.fr.design.designer.beans.events;
import java.util.ArrayList;
import com.fr.design.designer.creator.XComponent; import com.fr.design.designer.creator.XComponent;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import javax.swing.SwingUtilities;
import java.util.ArrayList;
public class CreatorEventListenerTable { public class CreatorEventListenerTable {
protected ArrayList<DesignerEditListener> listeners; protected ArrayList<DesignerEditListener> listeners;
@ -18,7 +19,7 @@ public class CreatorEventListenerTable {
return; return;
} }
for (int i = 0; i < listeners.size(); i++) { for (int i = 0; i < listeners.size(); i++) {
if (ComparatorUtils.equals(listener,listeners.get(i))) { if (ComparatorUtils.equals(listener, listeners.get(i))) {
listeners.set(i, listener); listeners.set(i, listener);
return; return;
} }
@ -26,11 +27,16 @@ public class CreatorEventListenerTable {
listeners.add(listener); listeners.add(listener);
} }
private void fireCreatorModified(DesignerEvent evt) { private void fireCreatorModified(final DesignerEvent evt) {
for (int i = 0; i < listeners.size(); i++) { for (int i = 0; i < listeners.size(); i++) {
DesignerEditListener listener = listeners.get(i); final DesignerEditListener listener = listeners.get(i);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
listener.fireCreatorModified(evt); listener.fireCreatorModified(evt);
} }
});
}
} }
public void fireCreatorModified(XComponent creator, int eventID) { public void fireCreatorModified(XComponent creator, int eventID) {

6
designer-form/src/main/java/com/fr/design/form/parameter/FormParaDesigner.java

@ -51,7 +51,6 @@ import com.fr.stable.ArrayUtils;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
@ -179,9 +178,6 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
@Override @Override
public void fireCreatorModified(final DesignerEvent evt) { public void fireCreatorModified(final DesignerEvent evt) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (evt.getCreatorEventID() != DesignerEvent.CREATOR_SELECTED) { if (evt.getCreatorEventID() != DesignerEvent.CREATOR_SELECTED) {
paraDefinitePane.setParameterArray( paraDefinitePane.setParameterArray(
paraDefinitePane.getNoRepeatParas(DesignModelAdapter.getCurrentModelAdapter().getParameters())); paraDefinitePane.getNoRepeatParas(DesignModelAdapter.getCurrentModelAdapter().getParameters()));
@ -190,8 +186,6 @@ public class FormParaDesigner extends FormDesigner implements ParameterDesignerP
} }
}); });
} }
});
}
/** /**
* 包裹一层FormArea * 包裹一层FormArea

8
designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java

@ -71,7 +71,6 @@ import javax.swing.Action;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.TransferHandler; import javax.swing.TransferHandler;
import javax.swing.border.Border; import javax.swing.border.Border;
import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionEvent;
@ -693,10 +692,7 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
getEditListenerTable().addListener(new DesignerEditListener() { getEditListenerTable().addListener(new DesignerEditListener() {
@Override @Override
public void fireCreatorModified(final DesignerEvent evt) { public void fireCreatorModified(DesignerEvent evt) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
// 只有选择组件时不触发模版更新,其他都要触发 // 只有选择组件时不触发模版更新,其他都要触发
if (evt.getCreatorEventID() != DesignerEvent.CREATOR_SELECTED) { if (evt.getCreatorEventID() != DesignerEvent.CREATOR_SELECTED) {
FormDesigner.this.fireTargetModified(); FormDesigner.this.fireTargetModified();
@ -710,8 +706,6 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
} }
} }
} }
});
}
}); });

6
designer-form/src/main/java/com/fr/design/mainframe/FormHierarchyTreePane.java

@ -23,7 +23,6 @@ import javax.swing.BorderFactory;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
@ -103,14 +102,9 @@ public class FormHierarchyTreePane extends FormDockView implements HierarchyTree
formDesigner.addDesignerEditListener(new DesignerEditListener() { formDesigner.addDesignerEditListener(new DesignerEditListener() {
@Override @Override
public void fireCreatorModified(DesignerEvent evt) { public void fireCreatorModified(DesignerEvent evt) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
refreshComponentTree(); refreshComponentTree();
} }
}); });
}
});
ComponentTreeModel treeModel = (ComponentTreeModel) componentTree.getModel(); ComponentTreeModel treeModel = (ComponentTreeModel) componentTree.getModel();
XCreator root = (XCreator) treeModel.getRoot(); XCreator root = (XCreator) treeModel.getRoot();

Loading…
Cancel
Save