Browse Source

REPORT-61338 设计器主题-主题配色修改保存后出现异常空白提示框

【问题原因】
AlphaFine也会创建一个主题管列界面的面板,用于提
取可以搜索的问题,但是这个面板是不对外展示的,不
应该启用对主题配置数据的监听以及线程池异步加载。

应用启动时,AlphaFine在另一个线程通过反射调用
默认构造函数创建面板,注册了对主题配置数据的监听
器,导致遍历监听器列表时出现并发访问异常,同时
违反了按需加载的主题列表设计意图

【改动思路】
仅在主题管理窗口可见后,再添加监听器和异步加载数据
new-design
Starryi 3 years ago
parent
commit
bc5e51c8f5
  1. 42
      designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeGridControlPane.java
  2. 48
      designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeGridPagesPane.java
  3. 60
      designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeGridPane.java
  4. 8
      designer-base/src/main/java/com/fr/design/mainframe/theme/dialog/TemplateThemeGridPagesDialog.java

42
designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeGridControlPane.java

@ -43,6 +43,8 @@ import java.awt.Stroke;
import java.awt.Window; import java.awt.Window;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import static com.fr.design.i18n.Toolkit.i18nText; import static com.fr.design.i18n.Toolkit.i18nText;
@ -63,27 +65,31 @@ public class TemplateThemeGridControlPane<T extends TemplateTheme> extends Basic
private final AsyncThemeFetcher<T> asyncThemeFetcher; private final AsyncThemeFetcher<T> asyncThemeFetcher;
public static TemplateThemeGridControlPane<FormTheme> createFormThemesManagerPane() { private final Window window;
public static TemplateThemeGridControlPane<FormTheme> createFormThemesManagerPane(Window window) {
FormThemeConfig config = FormThemeConfig.getInstance(); FormThemeConfig config = FormThemeConfig.getInstance();
FormThemeProfilePane editPane = new FormThemeProfilePane(config); FormThemeProfilePane editPane = new FormThemeProfilePane(config);
return new TemplateThemeGridControlPane<>(config, editPane); return new TemplateThemeGridControlPane<>(window, config, editPane);
} }
public static TemplateThemeGridControlPane<ReportTheme> createReportThemesManagerPane() { public static TemplateThemeGridControlPane<ReportTheme> createReportThemesManagerPane(Window window) {
ReportThemeConfig config = ReportThemeConfig.getInstance(); ReportThemeConfig config = ReportThemeConfig.getInstance();
ReportThemeProfilePane editPane = new ReportThemeProfilePane(config); ReportThemeProfilePane editPane = new ReportThemeProfilePane(config);
return new TemplateThemeGridControlPane<>(config, editPane); return new TemplateThemeGridControlPane<>(window, config, editPane);
} }
public TemplateThemeGridControlPane(TemplateThemeConfig<T> config, TemplateThemeProfilePane<T> profilePane) { public TemplateThemeGridControlPane(Window window, TemplateThemeConfig<T> config, TemplateThemeProfilePane<T> profilePane) {
this.window = window;
this.config = config; this.config = config;
this.profilePane = profilePane; this.profilePane = profilePane;
this.themeListPane = new TemplateThemeGridPane<>(true, config, profilePane); this.themeListPane = new TemplateThemeGridPane<>(window, true, config, profilePane);
this.removeAction = new RemoveThemeAction(false); this.removeAction = new RemoveThemeAction(false);
this.setTheme4NewTemplateButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Manager_Pane_Default_Setting")); this.setTheme4NewTemplateButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Manager_Pane_Default_Setting"));
this.asyncThemeFetcher = new AsyncThemeFetcher<>(1, config); this.asyncThemeFetcher = new AsyncThemeFetcher<>(1, config);
initializePane(); initializePane();
registerWindowListener();
} }
public TemplateThemeConfig<T> getConfig() { public TemplateThemeConfig<T> getConfig() {
@ -117,6 +123,16 @@ public class TemplateThemeGridControlPane<T extends TemplateTheme> extends Basic
repaint(); repaint();
} }
private void registerWindowListener() {
window.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
super.windowClosed(e);
asyncThemeFetcher.shutdown();
}
});
}
private void resetEnableRemoveAction(T selectedTheme, RemoveThemeAction removeAction) { private void resetEnableRemoveAction(T selectedTheme, RemoveThemeAction removeAction) {
if (selectedTheme == null) { if (selectedTheme == null) {
removeAction.setEnabled(false); removeAction.setEnabled(false);
@ -254,7 +270,6 @@ public class TemplateThemeGridControlPane<T extends TemplateTheme> extends Basic
setName(name); setName(name);
setMnemonic('R'); setMnemonic('R');
this.prototypeThemeName = prototypeThemeName; this.prototypeThemeName = prototypeThemeName;
asyncThemeFetcher.submit(prototypeThemeName, null);
} }
@Override @Override
@ -308,17 +323,4 @@ public class TemplateThemeGridControlPane<T extends TemplateTheme> extends Basic
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
} }
} }
public void startListenThemeConfig() {
themeListPane.startListenThemeConfig();
}
public void stopListenThemeConfig() {
themeListPane.stopListenThemeConfig();
}
public void stopAsyncFetchTheme() {
asyncThemeFetcher.shutdown();
themeListPane.stopAsyncFetchTheme();
}
} }

48
designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeGridPagesPane.java

@ -38,6 +38,7 @@ import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.awt.Stroke; import java.awt.Stroke;
import java.awt.Window;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.ArrayList; import java.util.ArrayList;
@ -61,11 +62,11 @@ public class TemplateThemeGridPagesPane extends JPanel {
private PageChangeListener pageChangeListener; private PageChangeListener pageChangeListener;
private TemplateThemeGridPagePane currentTemplateThemeGridPagePane; private TemplateThemeGridPagePane currentTemplateThemeGridPagePane;
public TemplateThemeGridPagesPane() { public TemplateThemeGridPagesPane(Window window) {
initializePane(); initializePane(window);
} }
private void initializePane() { private void initializePane(Window window) {
setLayout(new BorderLayout()); setLayout(new BorderLayout());
setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10)); setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
@ -82,9 +83,9 @@ public class TemplateThemeGridPagesPane extends JPanel {
add(contentPane, BorderLayout.CENTER); add(contentPane, BorderLayout.CENTER);
themeUsingPane = new TemplateThemeUsingPane(); themeUsingPane = new TemplateThemeUsingPane(window);
contentPane.add(themeUsingPane, themeUsingPane.getTitle()); contentPane.add(themeUsingPane, themeUsingPane.getTitle());
themeManagingPane = new TemplateThemeManagingPane(); themeManagingPane = new TemplateThemeManagingPane(window);
contentPane.add(themeManagingPane, themeManagingPane.getTitle()); contentPane.add(themeManagingPane, themeManagingPane.getTitle());
showThemeUsingPane(); showThemeUsingPane();
@ -189,11 +190,6 @@ public class TemplateThemeGridPagesPane extends JPanel {
return button; return button;
} }
public void exit() {
themeUsingPane.exit();
themeManagingPane.exit();
}
public void setPageChangeListener(PageChangeListener changeListener) { public void setPageChangeListener(PageChangeListener changeListener) {
this.pageChangeListener = changeListener; this.pageChangeListener = changeListener;
} }
@ -232,15 +228,13 @@ public class TemplateThemeGridPagesPane extends JPanel {
public abstract static class TemplateThemeGridPagePane extends BasicPane { public abstract static class TemplateThemeGridPagePane extends BasicPane {
public abstract TemplateThemeConfig<? extends TemplateTheme> getConfig(); public abstract TemplateThemeConfig<? extends TemplateTheme> getConfig();
public void exit() { }
} }
public static class TemplateThemeUsingPane extends TemplateThemeGridPagePane { public static class TemplateThemeUsingPane extends TemplateThemeGridPagePane {
private final JTemplate<?,?> template; private final JTemplate<?,?> template;
public final TemplateThemeGridPane<? extends TemplateTheme> themeListPane; public final TemplateThemeGridPane<? extends TemplateTheme> themeListPane;
public TemplateThemeUsingPane() { public TemplateThemeUsingPane(Window window) {
super(); super();
setLayout(new BorderLayout()); setLayout(new BorderLayout());
setBorder(new CompoundBorder( setBorder(new CompoundBorder(
@ -249,9 +243,7 @@ public class TemplateThemeGridPagesPane extends JPanel {
template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
TemplateThemeConfig<? extends TemplateTheme> config = template.getUsingTemplateThemeConfig(); TemplateThemeConfig<? extends TemplateTheme> config = template.getUsingTemplateThemeConfig();
themeListPane = new TemplateThemeGridPane<>(false, config, null); themeListPane = new TemplateThemeGridPane<>(window, false, config, null);
themeListPane.startListenThemeConfig();
themeListPane.setSelectedChangeListener(new ChangeListener() { themeListPane.setSelectedChangeListener(new ChangeListener() {
@Override @Override
@ -272,12 +264,6 @@ public class TemplateThemeGridPagesPane extends JPanel {
return template.getUsingTemplateThemeConfig(); return template.getUsingTemplateThemeConfig();
} }
@Override
public void exit() {
themeListPane.stopListenThemeConfig();
themeListPane.stopAsyncFetchTheme();
}
@Override @Override
protected String title4PopupWindow() { protected String title4PopupWindow() {
return Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Using_Dialog_Title"); return Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Using_Dialog_Title");
@ -286,20 +272,16 @@ public class TemplateThemeGridPagesPane extends JPanel {
public static class TemplateThemeManagingPane extends TemplateThemeGridPagePane { public static class TemplateThemeManagingPane extends TemplateThemeGridPagePane {
private final UITabbedPane tabbedPane; private final UITabbedPane tabbedPane;
private final TemplateThemeGridControlPane<FormTheme> formThemesManagerPane;
private final TemplateThemeGridControlPane<ReportTheme> reportThemesManagerPane;
public TemplateThemeManagingPane() { public TemplateThemeManagingPane(Window window) {
setLayout(FRGUIPaneFactory.createBorderLayout()); setLayout(FRGUIPaneFactory.createBorderLayout());
tabbedPane = new UITabbedPane(); tabbedPane = new UITabbedPane();
tabbedPane.setTabBorderColor(new Color(0xE0E0E1)); tabbedPane.setTabBorderColor(new Color(0xE0E0E1));
add(tabbedPane, BorderLayout.CENTER); add(tabbedPane, BorderLayout.CENTER);
formThemesManagerPane = TemplateThemeGridControlPane.createFormThemesManagerPane(); TemplateThemeGridControlPane<FormTheme> formThemesManagerPane = TemplateThemeGridControlPane.createFormThemesManagerPane(window);
formThemesManagerPane.startListenThemeConfig(); TemplateThemeGridControlPane<ReportTheme> reportThemesManagerPane = TemplateThemeGridControlPane.createReportThemesManagerPane(window);
reportThemesManagerPane = TemplateThemeGridControlPane.createReportThemesManagerPane();
reportThemesManagerPane.startListenThemeConfig();
tabbedPane.addTab(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Manager_Dialog_Form_Tab"), formThemesManagerPane); tabbedPane.addTab(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Manager_Dialog_Form_Tab"), formThemesManagerPane);
tabbedPane.addTab(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Manager_Dialog_Report_Tab"), reportThemesManagerPane); tabbedPane.addTab(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Manager_Dialog_Report_Tab"), reportThemesManagerPane);
@ -321,14 +303,6 @@ public class TemplateThemeGridPagesPane extends JPanel {
} }
} }
@Override
public void exit() {
formThemesManagerPane.stopListenThemeConfig();
formThemesManagerPane.stopAsyncFetchTheme();
reportThemesManagerPane.stopListenThemeConfig();
reportThemesManagerPane.stopAsyncFetchTheme();
}
@Override @Override
protected String title4PopupWindow() { protected String title4PopupWindow() {
return Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Manager_Dialog_Title"); return Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Manager_Dialog_Title");

60
designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeGridPane.java

@ -8,8 +8,6 @@ import com.fr.design.event.ChangeEvent;
import com.fr.design.event.ChangeListener; import com.fr.design.event.ChangeListener;
import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.widget.FRWidgetFactory;
import com.fr.design.widget.WidgetBoundsPaneFactory;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
@ -18,8 +16,11 @@ import javax.swing.ScrollPaneConstants;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.GridLayout; import java.awt.GridLayout;
import java.awt.Window;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -53,13 +54,17 @@ public class TemplateThemeGridPane<T extends TemplateTheme> extends BasicPane {
private ChangeListener changeListener; private ChangeListener changeListener;
public TemplateThemeGridPane(boolean displayTheme4NewTemplateMarker, TemplateThemeConfig<T> config, TemplateThemeProfilePane<T> profilePane) { private final Window window;
public TemplateThemeGridPane(Window window, boolean displayTheme4NewTemplateMarker, TemplateThemeConfig<T> config, TemplateThemeProfilePane<T> profilePane) {
this.window = window;
this.displayTheme4NewTemplateMarker = displayTheme4NewTemplateMarker; this.displayTheme4NewTemplateMarker = displayTheme4NewTemplateMarker;
this.config = config; this.config = config;
this.profilePane = profilePane; this.profilePane = profilePane;
this.contentListPane = new JPanel(); this.contentListPane = new JPanel();
this.asyncThemeFetcher = new AsyncThemeFetcher<>(ASYNC_FETCH_THEME_THREAD_COUNT, config); this.asyncThemeFetcher = new AsyncThemeFetcher<>(ASYNC_FETCH_THEME_THREAD_COUNT, config);
initializePane(); initializePane();
registerWindowListener();
} }
private void initializePane() { private void initializePane() {
@ -84,6 +89,24 @@ public class TemplateThemeGridPane<T extends TemplateTheme> extends BasicPane {
} }
private void registerWindowListener() {
window.addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(WindowEvent e) {
super.windowOpened(e);
startListenThemeConfig();
asyncFetchThemes();
}
@Override
public void windowClosed(WindowEvent e) {
super.windowClosed(e);
stopListenThemeConfig();
asyncThemeFetcher.shutdown();
}
});
}
public void fillContentListPane() { public void fillContentListPane() {
contentListPane.removeAll(); contentListPane.removeAll();
List<String> names = config.getThemeNames(); List<String> names = config.getThemeNames();
@ -97,6 +120,7 @@ public class TemplateThemeGridPane<T extends TemplateTheme> extends BasicPane {
} }
} }
} }
private TemplateThemeBlock<T> createCachedTemplateThemeBlock(String name) { private TemplateThemeBlock<T> createCachedTemplateThemeBlock(String name) {
TemplateThemeBlock<T> block = blockCache.get(name); TemplateThemeBlock<T> block = blockCache.get(name);
if (block == null) { if (block == null) {
@ -115,19 +139,6 @@ public class TemplateThemeGridPane<T extends TemplateTheme> extends BasicPane {
setSelectedBlock(block); setSelectedBlock(block);
} }
}); });
asyncThemeFetcher.submit(name, new AsyncThemeFetcher.AsyncThemeFetchCallbackAdapter<T>() {
@Override
public void beforeCachedFetch() {
super.beforeCachedFetch();
block.setTheme(null);
}
@Override
public void afterCachedFetch(T theme) {
super.afterCachedFetch(theme);
block.setTheme(theme);
}
});
return block; return block;
} }
@ -154,6 +165,15 @@ public class TemplateThemeGridPane<T extends TemplateTheme> extends BasicPane {
asyncThemeFetcher.submit(themeName, new AsyncThemeListItemFetchCallback(themeName)); asyncThemeFetcher.submit(themeName, new AsyncThemeListItemFetchCallback(themeName));
} }
private void asyncFetchThemes() {
List<String> names = config.getThemeNames();
for (String name: names) {
if (config.contains(name)) {
asyncThemeFetcher.submit(name, new AsyncThemeListItemFetchCallback(name));
}
}
}
@Override @Override
protected String title4PopupWindow() { protected String title4PopupWindow() {
return null; return null;
@ -163,7 +183,7 @@ public class TemplateThemeGridPane<T extends TemplateTheme> extends BasicPane {
return selectedBlock != null ? selectedBlock.getTheme() : null; return selectedBlock != null ? selectedBlock.getTheme() : null;
} }
public void startListenThemeConfig() { private void startListenThemeConfig() {
if (themeConfigChangeListener == null) { if (themeConfigChangeListener == null) {
themeConfigChangeListener = new TemplateThemeConfig.ThemeConfigChangeListener() { themeConfigChangeListener = new TemplateThemeConfig.ThemeConfigChangeListener() {
@Override @Override
@ -219,17 +239,13 @@ public class TemplateThemeGridPane<T extends TemplateTheme> extends BasicPane {
} }
} }
public void stopListenThemeConfig() { private void stopListenThemeConfig() {
if (themeConfigChangeListener != null) { if (themeConfigChangeListener != null) {
config.removeThemeConfigChangeListener(themeConfigChangeListener); config.removeThemeConfigChangeListener(themeConfigChangeListener);
themeConfigChangeListener = null; themeConfigChangeListener = null;
} }
} }
public void stopAsyncFetchTheme() {
asyncThemeFetcher.shutdown();
}
private class AsyncThemeListItemFetchCallback extends AsyncThemeFetcher.AsyncThemeFetchCallbackAdapter<T> { private class AsyncThemeListItemFetchCallback extends AsyncThemeFetcher.AsyncThemeFetchCallbackAdapter<T> {
private final String themeName; private final String themeName;
public AsyncThemeListItemFetchCallback(String themeName) { public AsyncThemeListItemFetchCallback(String themeName) {

8
designer-base/src/main/java/com/fr/design/mainframe/theme/dialog/TemplateThemeGridPagesDialog.java

@ -28,7 +28,7 @@ public class TemplateThemeGridPagesDialog extends TemplateThemeDialog implements
@Override @Override
protected JPanel createContentPane() { protected JPanel createContentPane() {
overallPane = new TemplateThemeGridPagesPane(); overallPane = new TemplateThemeGridPagesPane(this);
overallPane.setPageChangeListener(this); overallPane.setPageChangeListener(this);
return overallPane; return overallPane;
} }
@ -43,12 +43,6 @@ public class TemplateThemeGridPagesDialog extends TemplateThemeDialog implements
return overallPane.createRightButtons(); return overallPane.createRightButtons();
} }
@Override
public void exit() {
overallPane.exit();
super.exit();
}
@Override @Override
public void onPageChangeListener() { public void onPageChangeListener() {
setupActionButtons(); setupActionButtons();

Loading…
Cancel
Save