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.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
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;
public static TemplateThemeGridControlPane<FormTheme> createFormThemesManagerPane() {
private final Window window;
public static TemplateThemeGridControlPane<FormTheme> createFormThemesManagerPane(Window window) {
FormThemeConfig config = FormThemeConfig.getInstance();
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();
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.profilePane = profilePane;
this.themeListPane = new TemplateThemeGridPane<>(true, config, profilePane);
this.themeListPane = new TemplateThemeGridPane<>(window, true, config, profilePane);
this.removeAction = new RemoveThemeAction(false);
this.setTheme4NewTemplateButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Template_Theme_Manager_Pane_Default_Setting"));
this.asyncThemeFetcher = new AsyncThemeFetcher<>(1, config);
initializePane();
registerWindowListener();
}
public TemplateThemeConfig<T> getConfig() {
@ -117,6 +123,16 @@ public class TemplateThemeGridControlPane<T extends TemplateTheme> extends Basic
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) {
if (selectedTheme == null) {
removeAction.setEnabled(false);
@ -254,7 +270,6 @@ public class TemplateThemeGridControlPane<T extends TemplateTheme> extends Basic
setName(name);
setMnemonic('R');
this.prototypeThemeName = prototypeThemeName;
asyncThemeFetcher.submit(prototypeThemeName, null);
}
@Override
@ -308,17 +323,4 @@ public class TemplateThemeGridControlPane<T extends TemplateTheme> extends Basic
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.RenderingHints;
import java.awt.Stroke;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
@ -61,11 +62,11 @@ public class TemplateThemeGridPagesPane extends JPanel {
private PageChangeListener pageChangeListener;
private TemplateThemeGridPagePane currentTemplateThemeGridPagePane;
public TemplateThemeGridPagesPane() {
initializePane();
public TemplateThemeGridPagesPane(Window window) {
initializePane(window);
}
private void initializePane() {
private void initializePane(Window window) {
setLayout(new BorderLayout());
setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
@ -82,9 +83,9 @@ public class TemplateThemeGridPagesPane extends JPanel {
add(contentPane, BorderLayout.CENTER);
themeUsingPane = new TemplateThemeUsingPane();
themeUsingPane = new TemplateThemeUsingPane(window);
contentPane.add(themeUsingPane, themeUsingPane.getTitle());
themeManagingPane = new TemplateThemeManagingPane();
themeManagingPane = new TemplateThemeManagingPane(window);
contentPane.add(themeManagingPane, themeManagingPane.getTitle());
showThemeUsingPane();
@ -189,11 +190,6 @@ public class TemplateThemeGridPagesPane extends JPanel {
return button;
}
public void exit() {
themeUsingPane.exit();
themeManagingPane.exit();
}
public void setPageChangeListener(PageChangeListener changeListener) {
this.pageChangeListener = changeListener;
}
@ -232,15 +228,13 @@ public class TemplateThemeGridPagesPane extends JPanel {
public abstract static class TemplateThemeGridPagePane extends BasicPane {
public abstract TemplateThemeConfig<? extends TemplateTheme> getConfig();
public void exit() { }
}
public static class TemplateThemeUsingPane extends TemplateThemeGridPagePane {
private final JTemplate<?,?> template;
public final TemplateThemeGridPane<? extends TemplateTheme> themeListPane;
public TemplateThemeUsingPane() {
public TemplateThemeUsingPane(Window window) {
super();
setLayout(new BorderLayout());
setBorder(new CompoundBorder(
@ -249,9 +243,7 @@ public class TemplateThemeGridPagesPane extends JPanel {
template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
TemplateThemeConfig<? extends TemplateTheme> config = template.getUsingTemplateThemeConfig();
themeListPane = new TemplateThemeGridPane<>(false, config, null);
themeListPane.startListenThemeConfig();
themeListPane = new TemplateThemeGridPane<>(window, false, config, null);
themeListPane.setSelectedChangeListener(new ChangeListener() {
@Override
@ -272,12 +264,6 @@ public class TemplateThemeGridPagesPane extends JPanel {
return template.getUsingTemplateThemeConfig();
}
@Override
public void exit() {
themeListPane.stopListenThemeConfig();
themeListPane.stopAsyncFetchTheme();
}
@Override
protected String title4PopupWindow() {
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 {
private final UITabbedPane tabbedPane;
private final TemplateThemeGridControlPane<FormTheme> formThemesManagerPane;
private final TemplateThemeGridControlPane<ReportTheme> reportThemesManagerPane;
public TemplateThemeManagingPane() {
public TemplateThemeManagingPane(Window window) {
setLayout(FRGUIPaneFactory.createBorderLayout());
tabbedPane = new UITabbedPane();
tabbedPane.setTabBorderColor(new Color(0xE0E0E1));
add(tabbedPane, BorderLayout.CENTER);
formThemesManagerPane = TemplateThemeGridControlPane.createFormThemesManagerPane();
formThemesManagerPane.startListenThemeConfig();
reportThemesManagerPane = TemplateThemeGridControlPane.createReportThemesManagerPane();
reportThemesManagerPane.startListenThemeConfig();
TemplateThemeGridControlPane<FormTheme> formThemesManagerPane = TemplateThemeGridControlPane.createFormThemesManagerPane(window);
TemplateThemeGridControlPane<ReportTheme> reportThemesManagerPane = TemplateThemeGridControlPane.createReportThemesManagerPane(window);
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);
@ -321,14 +303,6 @@ public class TemplateThemeGridPagesPane extends JPanel {
}
}
@Override
public void exit() {
formThemesManagerPane.stopListenThemeConfig();
formThemesManagerPane.stopAsyncFetchTheme();
reportThemesManagerPane.stopListenThemeConfig();
reportThemesManagerPane.stopAsyncFetchTheme();
}
@Override
protected String title4PopupWindow() {
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.gui.icontainer.UIScrollPane;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.widget.FRWidgetFactory;
import com.fr.design.widget.WidgetBoundsPaneFactory;
import com.fr.stable.StringUtils;
import javax.swing.BorderFactory;
@ -18,8 +16,11 @@ import javax.swing.ScrollPaneConstants;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Window;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -53,13 +54,17 @@ public class TemplateThemeGridPane<T extends TemplateTheme> extends BasicPane {
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.config = config;
this.profilePane = profilePane;
this.contentListPane = new JPanel();
this.asyncThemeFetcher = new AsyncThemeFetcher<>(ASYNC_FETCH_THEME_THREAD_COUNT, config);
initializePane();
registerWindowListener();
}
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() {
contentListPane.removeAll();
List<String> names = config.getThemeNames();
@ -97,6 +120,7 @@ public class TemplateThemeGridPane<T extends TemplateTheme> extends BasicPane {
}
}
}
private TemplateThemeBlock<T> createCachedTemplateThemeBlock(String name) {
TemplateThemeBlock<T> block = blockCache.get(name);
if (block == null) {
@ -115,19 +139,6 @@ public class TemplateThemeGridPane<T extends TemplateTheme> extends BasicPane {
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;
}
@ -154,6 +165,15 @@ public class TemplateThemeGridPane<T extends TemplateTheme> extends BasicPane {
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
protected String title4PopupWindow() {
return null;
@ -163,7 +183,7 @@ public class TemplateThemeGridPane<T extends TemplateTheme> extends BasicPane {
return selectedBlock != null ? selectedBlock.getTheme() : null;
}
public void startListenThemeConfig() {
private void startListenThemeConfig() {
if (themeConfigChangeListener == null) {
themeConfigChangeListener = new TemplateThemeConfig.ThemeConfigChangeListener() {
@Override
@ -219,17 +239,13 @@ public class TemplateThemeGridPane<T extends TemplateTheme> extends BasicPane {
}
}
public void stopListenThemeConfig() {
private void stopListenThemeConfig() {
if (themeConfigChangeListener != null) {
config.removeThemeConfigChangeListener(themeConfigChangeListener);
themeConfigChangeListener = null;
}
}
public void stopAsyncFetchTheme() {
asyncThemeFetcher.shutdown();
}
private class AsyncThemeListItemFetchCallback extends AsyncThemeFetcher.AsyncThemeFetchCallbackAdapter<T> {
private final 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
protected JPanel createContentPane() {
overallPane = new TemplateThemeGridPagesPane();
overallPane = new TemplateThemeGridPagesPane(this);
overallPane.setPageChangeListener(this);
return overallPane;
}
@ -43,12 +43,6 @@ public class TemplateThemeGridPagesDialog extends TemplateThemeDialog implements
return overallPane.createRightButtons();
}
@Override
public void exit() {
overallPane.exit();
super.exit();
}
@Override
public void onPageChangeListener() {
setupActionButtons();

Loading…
Cancel
Save