Browse Source

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

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

18
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,10 +27,15 @@ 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);
listener.fireCreatorModified(evt); SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
listener.fireCreatorModified(evt);
}
});
} }
} }

16
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,16 +178,11 @@ 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() { if (evt.getCreatorEventID() != DesignerEvent.CREATOR_SELECTED) {
@Override paraDefinitePane.setParameterArray(
public void run() { paraDefinitePane.getNoRepeatParas(DesignModelAdapter.getCurrentModelAdapter().getParameters()));
if (evt.getCreatorEventID() != DesignerEvent.CREATOR_SELECTED) { paraDefinitePane.refreshParameter();
paraDefinitePane.setParameterArray( }
paraDefinitePane.getNoRepeatParas(DesignModelAdapter.getCurrentModelAdapter().getParameters()));
paraDefinitePane.refreshParameter();
}
}
});
} }
}); });
} }

30
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,24 +692,19 @@ 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 if (evt.getCreatorEventID() != DesignerEvent.CREATOR_SELECTED) {
public void run() { FormDesigner.this.fireTargetModified();
// 只有选择组件时不触发模版更新,其他都要触发 if (evt.getCreatorEventID() == DesignerEvent.CREATOR_DELETED) {
if (evt.getCreatorEventID() != DesignerEvent.CREATOR_SELECTED) { setParameterArray(getNoRepeatParas(getTarget().getParameters()));
FormDesigner.this.fireTargetModified(); refreshParameter();
if (evt.getCreatorEventID() == DesignerEvent.CREATOR_DELETED) {
setParameterArray(getNoRepeatParas(getTarget().getParameters()));
refreshParameter();
}
} else {
for (UpdateAction action : getActions()) {
action.update();
}
}
} }
}); } else {
for (UpdateAction action : getActions()) {
action.update();
}
}
} }
}); });

8
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,12 +102,7 @@ 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() { refreshComponentTree();
@Override
public void run() {
refreshComponentTree();
}
});
} }
}); });

Loading…
Cancel
Save