diff --git a/designer/src/com/fr/design/webattr/ReportWebAttrPane.java b/designer/src/com/fr/design/webattr/ReportWebAttrPane.java index cd761199be..6330ee87fd 100644 --- a/designer/src/com/fr/design/webattr/ReportWebAttrPane.java +++ b/designer/src/com/fr/design/webattr/ReportWebAttrPane.java @@ -10,6 +10,7 @@ import javax.swing.JPanel; import com.fr.design.gui.frpane.LoadingBasicPane; import com.fr.design.gui.frpane.UITabbedPane; import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.style.background.BackgroundPane4Browser; import com.fr.general.Inter; import com.fr.design.style.background.BackgroundPane; import com.fr.web.attr.ReportWebAttr; @@ -50,7 +51,7 @@ public class ReportWebAttrPane extends LoadingBasicPane { tabbedPane.add(Inter.getLocText("WEB-Write_Setting"), writeWeb = new WriteWebSettingPane()); tabbedPane.add(Inter.getLocText("M-Data_Analysis_Settings"), viewWeb = new ViewWebSettingPane()); - tabbedPane.addTab(Inter.getLocText("ReportServerP-Browser_Background"), backgroundPane = new BackgroundPane(true)); + tabbedPane.addTab(Inter.getLocText("ReportServerP-Browser_Background"), backgroundPane = new BackgroundPane4Browser()); tabbedPane.addTab(Inter.getLocText("ReportServerP-Import_Css"), cssPane = new WebCssPane()); tabbedPane.addTab(Inter.getLocText("ReportServerP-Import_JavaScript"), jsPane = new WebJsPane()); } diff --git a/designer_base/src/com/fr/design/ExtraDesignClassManager.java b/designer_base/src/com/fr/design/ExtraDesignClassManager.java index a11ff53a6c..d676381678 100644 --- a/designer_base/src/com/fr/design/ExtraDesignClassManager.java +++ b/designer_base/src/com/fr/design/ExtraDesignClassManager.java @@ -134,6 +134,10 @@ public class ExtraDesignClassManager extends XMLFileManager implements ExtraDesi private Set exportAttrTabProviders; + private Set backgroundQuickUIProviders; + + private Set backgroundUIProviders; + public TableDataPaneProcessor getTableDataPaneProcessor() { return tableDataPaneProcessor; } @@ -770,6 +774,36 @@ public class ExtraDesignClassManager extends XMLFileManager implements ExtraDesi exportAttrTabProviders.add((ExportAttrTabProvider) level); } + public BackgroundQuickUIProvider[] getBackgroundQuickUIProviders() { + if (backgroundQuickUIProviders == null) { + return new BackgroundQuickUIProvider[0]; + } + return backgroundQuickUIProviders.toArray(new BackgroundQuickUIProvider[backgroundQuickUIProviders.size()]); + } + + public void addBackgroundQuickUIProvider(Level level, PluginSimplify simplify) throws Exception { + if (backgroundQuickUIProviders == null) { + backgroundQuickUIProviders = new HashSet<>(); + } + validAPILevel(level, BackgroundQuickUIProvider.CURRENT_LEVEL, simplify.getPluginName()); + backgroundQuickUIProviders.add((BackgroundQuickUIProvider) level); + } + + public BackgroundUIProvider[] getBackgroundUIProviders() { + if (backgroundUIProviders == null) { + return new BackgroundUIProvider[0]; + } + return backgroundUIProviders.toArray(new BackgroundUIProvider[backgroundUIProviders.size()]); + } + + public void addBackgroundUIProvider(Level level, PluginSimplify simplify) throws Exception { + if (backgroundUIProviders == null) { + backgroundUIProviders = new HashSet<>(); + } + validAPILevel(level, BackgroundUIProvider.CURRENT_LEVEL, simplify.getPluginName()); + backgroundUIProviders.add((BackgroundUIProvider) level); + } + /** * 文件名 * @@ -824,6 +858,8 @@ public class ExtraDesignClassManager extends XMLFileManager implements ExtraDesi readWidgetRelated(tagName, impl, simplify); //数据集, 数据连接 readTableDataRelated(tagName, className, simplify); + // 样式相关的 + readStyleRelated(tagName, impl, simplify); if (tagName.equals(ParameterWidgetOptionProvider.XML_TAG)) { addParameterWidgetOption(impl, simplify); } else if (tagName.equals(PreviewProvider.MARK_STRING)) { @@ -898,6 +934,14 @@ public class ExtraDesignClassManager extends XMLFileManager implements ExtraDesi } } + private void readStyleRelated(String tagName, Level impl, PluginSimplify simplify) throws Exception { + if (tagName.equals(BackgroundQuickUIProvider.MARK_STRING)) { + addBackgroundQuickUIProvider(impl, simplify); + } else if (tagName.equals(BackgroundUIProvider.MARK_STRING)) { + addBackgroundUIProvider(impl, simplify); + } + } + /** * 写xml * diff --git a/designer_base/src/com/fr/design/fun/BackgroundQuickUIProvider.java b/designer_base/src/com/fr/design/fun/BackgroundQuickUIProvider.java new file mode 100644 index 0000000000..257d257a3f --- /dev/null +++ b/designer_base/src/com/fr/design/fun/BackgroundQuickUIProvider.java @@ -0,0 +1,22 @@ +package com.fr.design.fun; + +import com.fr.design.mainframe.backgroundpane.BackgroundQuickPane; +import com.fr.stable.fun.Level; +import com.fr.stable.fun.Provider; + +/** + * Created by richie on 16/5/18. + * 背景设置界面接口,用于扩展设置更多类型的背景 + */ +public interface BackgroundQuickUIProvider extends Level, Provider { + + String MARK_STRING = "BackgroundQuickUIProvider"; + + int CURRENT_LEVEL = 1; + + /** + * 背景设置界面 + * @return 设置界面 + */ + BackgroundQuickPane appearanceForBackground(); +} diff --git a/designer_base/src/com/fr/design/fun/BackgroundUIProvider.java b/designer_base/src/com/fr/design/fun/BackgroundUIProvider.java new file mode 100644 index 0000000000..0ae87b9d7d --- /dev/null +++ b/designer_base/src/com/fr/design/fun/BackgroundUIProvider.java @@ -0,0 +1,34 @@ +package com.fr.design.fun; + +import com.fr.design.style.background.BackgroundDetailPane; +import com.fr.general.Background; +import com.fr.stable.fun.Level; +import com.fr.stable.fun.Provider; + +/** + * Created by richie on 16/5/18. + */ +public interface BackgroundUIProvider extends Level, Provider { + + String MARK_STRING = "BackgroundUIProvider"; + + int CURRENT_LEVEL = 1; + + /** + * 对应的背景具体类型 + * @return 背景 + */ + Class targetClass(); + + /** + * 背景设置界面 + * @return 界面 + */ + Class targetUIClass(); + + /** + * 标题 + * @return 在设计界面上这个选项的显示标题 + */ + String targetTitle(); +} diff --git a/designer_base/src/com/fr/design/fun/impl/AbstractBackgroundQuickUIProvider.java b/designer_base/src/com/fr/design/fun/impl/AbstractBackgroundQuickUIProvider.java new file mode 100644 index 0000000000..82da697c12 --- /dev/null +++ b/designer_base/src/com/fr/design/fun/impl/AbstractBackgroundQuickUIProvider.java @@ -0,0 +1,20 @@ +package com.fr.design.fun.impl; + +import com.fr.design.fun.BackgroundQuickUIProvider; +import com.fr.stable.fun.impl.AbstractProvider; + +/** + * Created by richie on 16/5/18. + */ +public abstract class AbstractBackgroundQuickUIProvider extends AbstractProvider implements BackgroundQuickUIProvider { + + @Override + public int currentAPILevel() { + return CURRENT_LEVEL; + } + + @Override + public String mark4Provider() { + return getClass().getName(); + } +} diff --git a/designer_base/src/com/fr/design/fun/impl/AbstractBackgroundUIProvider.java b/designer_base/src/com/fr/design/fun/impl/AbstractBackgroundUIProvider.java new file mode 100644 index 0000000000..ad95e3684f --- /dev/null +++ b/designer_base/src/com/fr/design/fun/impl/AbstractBackgroundUIProvider.java @@ -0,0 +1,20 @@ +package com.fr.design.fun.impl; + +import com.fr.design.fun.BackgroundUIProvider; +import com.fr.stable.fun.impl.AbstractProvider; + +/** + * Created by richie on 16/5/18. + */ +public abstract class AbstractBackgroundUIProvider extends AbstractProvider implements BackgroundUIProvider { + + @Override + public int currentAPILevel() { + return CURRENT_LEVEL; + } + + @Override + public String mark4Provider() { + return getClass().getName(); + } +} diff --git a/designer_base/src/com/fr/design/gui/style/BackgroundNoImagePane.java b/designer_base/src/com/fr/design/gui/style/BackgroundNoImagePane.java index 7e2680eef4..00465d83e5 100644 --- a/designer_base/src/com/fr/design/gui/style/BackgroundNoImagePane.java +++ b/designer_base/src/com/fr/design/gui/style/BackgroundNoImagePane.java @@ -1,10 +1,10 @@ package com.fr.design.gui.style; import com.fr.design.event.UIObserverListener; -import com.fr.design.mainframe.backgroundpane.BackgroundSettingPane; -import com.fr.design.mainframe.backgroundpane.ColorBackgroundPane; -import com.fr.design.mainframe.backgroundpane.NullBackgroundPane; -import java.util.ArrayList; +import com.fr.design.mainframe.backgroundpane.BackgroundQuickPane; +import com.fr.design.mainframe.backgroundpane.ColorBackgroundQuickPane; +import com.fr.design.mainframe.backgroundpane.GradientBackgroundQuickPane; +import com.fr.design.mainframe.backgroundpane.NullBackgroundQuickPane; /** * Created with IntelliJ IDEA. @@ -18,8 +18,9 @@ public class BackgroundNoImagePane extends BackgroundPane{ super(); } - protected void initPaneList(){ - ColorBackgroundPane colorBackgroundPane = new ColorBackgroundPane(); + @Override + protected BackgroundQuickPane[] supportKindsOfBackgroundUI() { + ColorBackgroundQuickPane colorBackgroundPane = new ColorBackgroundQuickPane(); colorBackgroundPane.registerChangeListener(new UIObserverListener() { @Override @@ -27,7 +28,7 @@ public class BackgroundNoImagePane extends BackgroundPane{ fireStateChanged(); } }); - GradientPane gradientPane = new GradientPane(); + GradientBackgroundQuickPane gradientPane = new GradientBackgroundQuickPane(); gradientPane.registerChangeListener(new UIObserverListener() { @Override @@ -35,10 +36,10 @@ public class BackgroundNoImagePane extends BackgroundPane{ fireStateChanged(); } }); - paneList = new ArrayList(); - paneList.add(new NullBackgroundPane()); - paneList.add(colorBackgroundPane); - paneList.add(gradientPane); - + return new BackgroundQuickPane[]{ + new NullBackgroundQuickPane(), + colorBackgroundPane, + gradientPane + }; } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/gui/style/BackgroundPane.java b/designer_base/src/com/fr/design/gui/style/BackgroundPane.java index 8c03e6202f..1bf6d7e4b2 100644 --- a/designer_base/src/com/fr/design/gui/style/BackgroundPane.java +++ b/designer_base/src/com/fr/design/gui/style/BackgroundPane.java @@ -1,148 +1,145 @@ -package com.fr.design.gui.style; - -/* - * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. - */ - -import java.awt.BorderLayout; -import java.awt.CardLayout; -import java.awt.Dimension; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.*; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; - -import com.fr.base.Style; -import com.fr.design.gui.icombobox.UIComboBox; -import com.fr.design.mainframe.backgroundpane.BackgroundSettingPane; -import com.fr.design.mainframe.backgroundpane.ColorBackgroundPane; -import com.fr.design.mainframe.backgroundpane.ImageBackgroundPane; -import com.fr.design.mainframe.backgroundpane.NullBackgroundPane; -import com.fr.design.mainframe.backgroundpane.PatternBackgroundPane; -import com.fr.design.mainframe.backgroundpane.TextureBackgroundPane; -import com.fr.general.Background; -import com.fr.general.Inter; - -/** - * - * @author zhou - * @since 2012-5-28下午6:22:09 - */ -public class BackgroundPane extends AbstractBasicStylePane { - - private UIComboBox typeComboBox; - - protected List paneList; - - public BackgroundPane() { - this.initComponents(); - } - - protected void initComponents() { - this.setLayout(new BorderLayout(0, 6)); - typeComboBox = new UIComboBox(); - final CardLayout cardlayout = new CardLayout(); - this.add(typeComboBox, BorderLayout.NORTH); - - initPaneList(); - final JPanel centerPane = new JPanel(cardlayout) { - @Override - public Dimension getPreferredSize() {// AUGUST:使用当前面板的的高度 - int index = typeComboBox.getSelectedIndex(); - return new Dimension(super.getPreferredSize().width, paneList.get(index).getPreferredSize().height); - } - }; - for (int i = 0; i < paneList.size(); i++) { - BackgroundSettingPane pane = paneList.get(i); - typeComboBox.addItem(pane.title4PopupWindow()); - centerPane.add(pane, pane.title4PopupWindow()); - } - this.add(centerPane, BorderLayout.CENTER); - typeComboBox.addItemListener(new ItemListener() { - - @Override - public void itemStateChanged(ItemEvent e) { - cardlayout.show(centerPane, (String)typeComboBox.getSelectedItem()); - fireStateChanged(); - } - }); - } - - protected void initPaneList(){ - paneList = new ArrayList(); - paneList.add(new NullBackgroundPane()); - paneList.add(new ColorBackgroundPane()); - paneList.add(new TextureBackgroundPane()); - paneList.add(new PatternBackgroundPane()); - paneList.add(new ImageBackgroundPane()); - paneList.add(new GradientPane()); - } - - /** - * 事件监听 - * @param changeListener 事件 - */ - public void addChangeListener(ChangeListener changeListener) { - listenerList.add(ChangeListener.class, changeListener); - } - - /** - */ - protected void fireStateChanged() { - Object[] listeners = listenerList.getListenerList(); - ChangeEvent e = null; - - for (int i = listeners.length - 2; i >= 0; i -= 2) { - if (listeners[i] == ChangeListener.class) { - if (e == null) { - e = new ChangeEvent(this); - } - ((ChangeListener)listeners[i + 1]).stateChanged(e); - } - } - } - - /** - * 名称 - * @return 名称 - */ - public String title4PopupWindow() { - return Inter.getLocText("FR-Utils_Background"); - } - - /** - * Populate background. - */ - public void populateBean(Background background) { - for (int i = 0; i < paneList.size(); i++) { - BackgroundSettingPane pane = paneList.get(i); - if (pane.accept(background)) { - pane.populateBean(background); - typeComboBox.setSelectedIndex(i); - return; - } - } - } - - /** - * Update background. - */ - public Background update() { - return paneList.get(typeComboBox.getSelectedIndex()).updateBean(); - } - - @Override - public void populateBean(Style style) { - this.populateBean(style.getBackground()); - } - - @Override - public Style update(Style style) { - return style.deriveBackground(this.update()); - } - +package com.fr.design.gui.style; + +import com.fr.base.Style; +import com.fr.design.ExtraDesignClassManager; +import com.fr.design.fun.BackgroundQuickUIProvider; +import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.mainframe.backgroundpane.*; +import com.fr.general.Background; +import com.fr.general.Inter; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.ArrayList; + +/** + * @author zhou + * @since 2012-5-28下午6:22:09 + */ +public class BackgroundPane extends AbstractBasicStylePane { + + private UIComboBox typeComboBox; + + protected BackgroundQuickPane[] paneList; + + public BackgroundPane() { + this.initComponents(); + } + + protected void initComponents() { + this.setLayout(new BorderLayout(0, 6)); + typeComboBox = new UIComboBox(); + final CardLayout cardlayout = new CardLayout(); + this.add(typeComboBox, BorderLayout.NORTH); + + paneList = supportKindsOfBackgroundUI(); + + final JPanel centerPane = new JPanel(cardlayout) { + @Override + public Dimension getPreferredSize() {// AUGUST:使用当前面板的的高度 + int index = typeComboBox.getSelectedIndex(); + return new Dimension(super.getPreferredSize().width, paneList[index].getPreferredSize().height); + } + }; + for (BackgroundQuickPane pane : paneList) { + typeComboBox.addItem(pane.title4PopupWindow()); + centerPane.add(pane, pane.title4PopupWindow()); + } + this.add(centerPane, BorderLayout.CENTER); + typeComboBox.addItemListener(new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent e) { + cardlayout.show(centerPane, (String) typeComboBox.getSelectedItem()); + fireStateChanged(); + } + }); + } + + protected BackgroundQuickPane[] supportKindsOfBackgroundUI() { + java.util.List kinds = new ArrayList<>(); + kinds.add(new NullBackgroundQuickPane()); + kinds.add(new ColorBackgroundQuickPane()); + kinds.add(new TextureBackgroundQuickPane()); + kinds.add(new PatternBackgroundQuickPane()); + kinds.add(new ImageBackgroundQuickPane()); + kinds.add(new GradientBackgroundQuickPane()); + BackgroundQuickUIProvider[] providers = ExtraDesignClassManager.getInstance().getBackgroundQuickUIProviders(); + for (BackgroundQuickUIProvider provider : providers) { + kinds.add(provider.appearanceForBackground()); + + } + return kinds.toArray(new BackgroundQuickPane[kinds.size()]); + } + + + /** + * 事件监听 + * + * @param changeListener 事件 + */ + public void addChangeListener(ChangeListener changeListener) { + listenerList.add(ChangeListener.class, changeListener); + } + + /** + */ + protected void fireStateChanged() { + Object[] listeners = listenerList.getListenerList(); + ChangeEvent e = null; + + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == ChangeListener.class) { + if (e == null) { + e = new ChangeEvent(this); + } + ((ChangeListener) listeners[i + 1]).stateChanged(e); + } + } + } + + /** + * 名称 + * + * @return 名称 + */ + public String title4PopupWindow() { + return Inter.getLocText("FR-Utils_Background"); + } + + /** + * Populate background. + */ + public void populateBean(Background background) { + for (int i = 0; i < paneList.length; i++) { + BackgroundQuickPane pane = paneList[i]; + if (pane.accept(background)) { + pane.populateBean(background); + typeComboBox.setSelectedIndex(i); + return; + } + } + } + + /** + * Update background. + */ + public Background update() { + return paneList[typeComboBox.getSelectedIndex()].updateBean(); + } + + @Override + public void populateBean(Style style) { + this.populateBean(style.getBackground()); + } + + @Override + public Style update(Style style) { + return style.deriveBackground(this.update()); + } + } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/gui/style/BackgroundSpecialPane.java b/designer_base/src/com/fr/design/gui/style/BackgroundSpecialPane.java index 59efe3a531..43c1d133c2 100644 --- a/designer_base/src/com/fr/design/gui/style/BackgroundSpecialPane.java +++ b/designer_base/src/com/fr/design/gui/style/BackgroundSpecialPane.java @@ -1,12 +1,7 @@ package com.fr.design.gui.style; import com.fr.design.event.UIObserverListener; -import com.fr.design.mainframe.backgroundpane.BackgroundSettingPane; -import com.fr.design.mainframe.backgroundpane.ColorBackgroundPane; -import com.fr.design.mainframe.backgroundpane.ImageBackgroundPane; -import com.fr.design.mainframe.backgroundpane.NullBackgroundPane; - -import java.util.ArrayList; +import com.fr.design.mainframe.backgroundpane.*; /** * Created with IntelliJ IDEA. @@ -20,8 +15,9 @@ public class BackgroundSpecialPane extends BackgroundPane{ super(); } - protected void initPaneList(){ - ColorBackgroundPane colorBackgroundPane = new ColorBackgroundPane(); + @Override + protected BackgroundQuickPane[] supportKindsOfBackgroundUI() { + ColorBackgroundQuickPane colorBackgroundPane = new ColorBackgroundQuickPane(); colorBackgroundPane.registerChangeListener(new UIObserverListener() { @Override @@ -29,7 +25,7 @@ public class BackgroundSpecialPane extends BackgroundPane{ fireStateChanged(); } }); - ImageBackgroundPane imageBackgroundPane = new ImageBackgroundPane(); + ImageBackgroundQuickPane imageBackgroundPane = new ImageBackgroundQuickPane(); imageBackgroundPane.registerChangeListener(new UIObserverListener() { @Override @@ -37,18 +33,18 @@ public class BackgroundSpecialPane extends BackgroundPane{ fireStateChanged(); } }); - GradientPane gradientPane = new GradientPane(); + GradientBackgroundQuickPane gradientPane = new GradientBackgroundQuickPane(); gradientPane.registerChangeListener(new UIObserverListener() { @Override public void doChange() { fireStateChanged(); } }); - paneList = new ArrayList(); - paneList.add(new NullBackgroundPane()); - paneList.add(colorBackgroundPane); - paneList.add(imageBackgroundPane); - paneList.add(gradientPane); - + return new BackgroundQuickPane[] { + new NullBackgroundQuickPane(), + colorBackgroundPane, + imageBackgroundPane, + gradientPane + }; } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/mainframe/backgroundpane/BackgroundSettingPane.java b/designer_base/src/com/fr/design/mainframe/backgroundpane/BackgroundQuickPane.java similarity index 83% rename from designer_base/src/com/fr/design/mainframe/backgroundpane/BackgroundSettingPane.java rename to designer_base/src/com/fr/design/mainframe/backgroundpane/BackgroundQuickPane.java index 82eafecb7c..1b796c438b 100644 --- a/designer_base/src/com/fr/design/mainframe/backgroundpane/BackgroundSettingPane.java +++ b/designer_base/src/com/fr/design/mainframe/backgroundpane/BackgroundQuickPane.java @@ -1,33 +1,33 @@ -package com.fr.design.mainframe.backgroundpane; - -import com.fr.design.beans.BasicBeanPane; -import com.fr.design.event.UIObserver; -import com.fr.general.Background; - -/** - * @author zhou - * @since 2012-5-29下午1:12:28 - */ -public abstract class BackgroundSettingPane extends BasicBeanPane implements UIObserver { - - public abstract boolean accept(Background background); - - @Override - public abstract void populateBean(Background background); - - @Override - public abstract Background updateBean(); - - @Override - public abstract String title4PopupWindow(); - - /** - * 组件是否需要响应添加的观察者事件 - * - * @return 如果需要响应观察者事件则返回true,否则返回false - */ - public boolean shouldResponseChangeListener() { - - return true; - } +package com.fr.design.mainframe.backgroundpane; + +import com.fr.design.beans.BasicBeanPane; +import com.fr.design.event.UIObserver; +import com.fr.general.Background; + +/** + * @author zhou + * @since 2012-5-29下午1:12:28 + */ +public abstract class BackgroundQuickPane extends BasicBeanPane implements UIObserver { + + public abstract boolean accept(Background background); + + @Override + public abstract void populateBean(Background background); + + @Override + public abstract Background updateBean(); + + @Override + public abstract String title4PopupWindow(); + + /** + * 组件是否需要响应添加的观察者事件 + * + * @return 如果需要响应观察者事件则返回true,否则返回false + */ + public boolean shouldResponseChangeListener() { + + return true; + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/mainframe/backgroundpane/ColorBackgroundPane.java b/designer_base/src/com/fr/design/mainframe/backgroundpane/ColorBackgroundQuickPane.java similarity index 91% rename from designer_base/src/com/fr/design/mainframe/backgroundpane/ColorBackgroundPane.java rename to designer_base/src/com/fr/design/mainframe/backgroundpane/ColorBackgroundQuickPane.java index 1b7fea0ebd..f08b0a89b2 100644 --- a/designer_base/src/com/fr/design/mainframe/backgroundpane/ColorBackgroundPane.java +++ b/designer_base/src/com/fr/design/mainframe/backgroundpane/ColorBackgroundQuickPane.java @@ -1,72 +1,72 @@ -package com.fr.design.mainframe.backgroundpane; - -import com.fr.base.background.ColorBackground; -import com.fr.design.event.UIObserverListener; -import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.general.Background; -import com.fr.general.Inter; -import com.fr.design.style.color.NewColorSelectPane; - -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import java.awt.*; - -/** - * @author zhou - * @since 2012-5-29下午1:12:14 - */ -public class ColorBackgroundPane extends BackgroundSettingPane { - - private NewColorSelectPane detailColorSelectPane; - - public ColorBackgroundPane() { - this.setLayout(FRGUIPaneFactory.createBorderLayout()); - - detailColorSelectPane = new NewColorSelectPane(); - this.add(detailColorSelectPane, BorderLayout.NORTH); - } - - public void populateBean(Background background) { - ColorBackground colorBackgroud = (ColorBackground) background; - this.detailColorSelectPane.setColor(colorBackgroud.getColor()); - } - - public Background updateBean() { - this.detailColorSelectPane.updateUsedColor(); - return ColorBackground.getInstance(this.detailColorSelectPane.getNotNoneColor()); - } - - /** - * 给组件登记一个观察者监听事件 - * - * @param listener 观察者监听事件 - */ - public void registerChangeListener(final UIObserverListener listener) { - detailColorSelectPane.addChangeListener(new ChangeListener() { - public void stateChanged(ChangeEvent e) { - listener.doChange(); - } - }); - } - - @Override - /** - * 是否为ColorBackground 类型 - * - * @param background 背景 - * @return 同上 - * - */ - public boolean accept(Background background) { - return background instanceof ColorBackground; - } - - @Override - /** - * 窗口名称 - * @return 同上 - */ - public String title4PopupWindow() { - return Inter.getLocText("Color"); - } +package com.fr.design.mainframe.backgroundpane; + +import com.fr.base.background.ColorBackground; +import com.fr.design.event.UIObserverListener; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.general.Background; +import com.fr.general.Inter; +import com.fr.design.style.color.NewColorSelectPane; + +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.*; + +/** + * @author zhou + * @since 2012-5-29下午1:12:14 + */ +public class ColorBackgroundQuickPane extends BackgroundQuickPane { + + private NewColorSelectPane detailColorSelectPane; + + public ColorBackgroundQuickPane() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + + detailColorSelectPane = new NewColorSelectPane(); + this.add(detailColorSelectPane, BorderLayout.NORTH); + } + + public void populateBean(Background background) { + ColorBackground colorBackgroud = (ColorBackground) background; + this.detailColorSelectPane.setColor(colorBackgroud.getColor()); + } + + public Background updateBean() { + this.detailColorSelectPane.updateUsedColor(); + return ColorBackground.getInstance(this.detailColorSelectPane.getNotNoneColor()); + } + + /** + * 给组件登记一个观察者监听事件 + * + * @param listener 观察者监听事件 + */ + public void registerChangeListener(final UIObserverListener listener) { + detailColorSelectPane.addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + listener.doChange(); + } + }); + } + + @Override + /** + * 是否为ColorBackground 类型 + * + * @param background 背景 + * @return 同上 + * + */ + public boolean accept(Background background) { + return background instanceof ColorBackground; + } + + @Override + /** + * 窗口名称 + * @return 同上 + */ + public String title4PopupWindow() { + return Inter.getLocText("Color"); + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/gui/style/GradientPane.java b/designer_base/src/com/fr/design/mainframe/backgroundpane/GradientBackgroundQuickPane.java similarity index 91% rename from designer_base/src/com/fr/design/gui/style/GradientPane.java rename to designer_base/src/com/fr/design/mainframe/backgroundpane/GradientBackgroundQuickPane.java index ed713ffe70..08ef9e61c4 100644 --- a/designer_base/src/com/fr/design/gui/style/GradientPane.java +++ b/designer_base/src/com/fr/design/mainframe/backgroundpane/GradientBackgroundQuickPane.java @@ -1,123 +1,122 @@ -package com.fr.design.gui.style; - -import com.fr.base.background.GradientBackground; -import com.fr.design.event.UIObserverListener; -import com.fr.design.gui.ibutton.UIButtonGroup; -import com.fr.design.gui.ilable.UILabel; -import com.fr.design.layout.TableLayout; -import com.fr.design.layout.TableLayoutHelper; -import com.fr.design.mainframe.backgroundpane.BackgroundSettingPane; -import com.fr.general.Background; -import com.fr.general.Inter; -import com.fr.design.style.background.gradient.GradientBar; - -import javax.swing.*; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import java.awt.*; - -/** - * @author zhou - * @since 2012-5-30上午10:36:21 - */ -public class GradientPane extends BackgroundSettingPane { - private static final long serialVersionUID = -6854603990673031897L; - - private static final int DEFAULT_GRADIENT_WIDTH = 185; - - private int gradientBarWidth = DEFAULT_GRADIENT_WIDTH; - - private GradientBar gradientBar; - private UIButtonGroup directionPane; - - public GradientPane() { - constructPane(); - } - - public GradientPane(int gradientBarWidth) { - this.gradientBarWidth = gradientBarWidth; - constructPane(); - } - - private void constructPane(){ - String[] textArray = {Inter.getLocText("Utils-Left_to_Right"), Inter.getLocText("Utils-Top_to_Bottom")}; - Integer[] valueArray = {GradientBackground.LEFT2RIGHT, GradientBackground.TOP2BOTTOM}; - directionPane = new UIButtonGroup(textArray, valueArray); - directionPane.setSelectedIndex(0); - gradientBar = new GradientBar(4, this.gradientBarWidth); - - double p = TableLayout.PREFERRED; - double f = TableLayout.FILL; - double[] columnSize = {p, f}; - double[] rowSize = {p, p,}; - - Component[][] components = new Component[][]{ - new Component[]{gradientBar, null}, - new Component[]{new UILabel(Inter.getLocText("Gradient-Direction") + ":"), directionPane} - }; - JPanel Gradient = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); - this.setLayout(new BorderLayout()); - this.add(Gradient, BorderLayout.CENTER); - } - - public void populateBean(Background background) { - GradientBackground bg = (GradientBackground) background; - this.gradientBar.getSelectColorPointBtnP1().setColorInner(bg.getStartColor()); - this.gradientBar.getSelectColorPointBtnP2().setColorInner(bg.getEndColor()); - directionPane.setSelectedItem(bg.getDirection()); - if (bg.isUseCell()) { - return; - } - double startValue = (double) bg.getBeginPlace(); - double endValue = (double) bg.getFinishPlace(); - gradientBar.setStartValue(startValue); - gradientBar.setEndValue(endValue); - if(this.gradientBar.getSelectColorPointBtnP1() != null && this.gradientBar.getSelectColorPointBtnP2() != null){ - this.gradientBar.getSelectColorPointBtnP1().setX(startValue); - this.gradientBar.getSelectColorPointBtnP2().setX(endValue); - } - this.gradientBar.repaint(); - } - - public GradientBackground updateBean() { - GradientBackground gb = new GradientBackground(gradientBar.getSelectColorPointBtnP1().getColorInner(), gradientBar.getSelectColorPointBtnP2().getColorInner()); - gb.setDirection(directionPane.getSelectedItem()); - if (gradientBar.isOriginalPlace()) { - gb.setUseCell(true); - } else { - gb.setUseCell(false); - gb.setBeginPlace((float) gradientBar.getStartValue()); - gb.setFinishPlace((float) gradientBar.getEndValue()); - } - return gb; - } - - /** - * 给组件登记一个观察者监听事件 - * - * @param listener 观察者监听事件 - */ - public void registerChangeListener(final UIObserverListener listener) { - gradientBar.addChangeListener(new ChangeListener() { - public void stateChanged(ChangeEvent e) { - listener.doChange(); - } - }); - directionPane.addChangeListener(new ChangeListener() { - public void stateChanged(ChangeEvent e) { - listener.doChange(); - } - }); - } - - @Override - public boolean accept(Background background) { - return background instanceof GradientBackground; - } - - @Override - public String title4PopupWindow() { - return Inter.getLocText("Gradient-Color"); - } - +package com.fr.design.mainframe.backgroundpane; + +import com.fr.base.background.GradientBackground; +import com.fr.design.event.UIObserverListener; +import com.fr.design.gui.ibutton.UIButtonGroup; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.style.background.gradient.GradientBar; +import com.fr.general.Background; +import com.fr.general.Inter; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.*; + +/** + * @author zhou + * @since 2012-5-30上午10:36:21 + */ +public class GradientBackgroundQuickPane extends BackgroundQuickPane { + private static final long serialVersionUID = -6854603990673031897L; + + private static final int DEFAULT_GRADIENT_WIDTH = 185; + + private int gradientBarWidth = DEFAULT_GRADIENT_WIDTH; + + private GradientBar gradientBar; + private UIButtonGroup directionPane; + + public GradientBackgroundQuickPane() { + constructPane(); + } + + public GradientBackgroundQuickPane(int gradientBarWidth) { + this.gradientBarWidth = gradientBarWidth; + constructPane(); + } + + private void constructPane(){ + String[] textArray = {Inter.getLocText("Utils-Left_to_Right"), Inter.getLocText("Utils-Top_to_Bottom")}; + Integer[] valueArray = {GradientBackground.LEFT2RIGHT, GradientBackground.TOP2BOTTOM}; + directionPane = new UIButtonGroup(textArray, valueArray); + directionPane.setSelectedIndex(0); + gradientBar = new GradientBar(4, this.gradientBarWidth); + + double p = TableLayout.PREFERRED; + double f = TableLayout.FILL; + double[] columnSize = {p, f}; + double[] rowSize = {p, p,}; + + Component[][] components = new Component[][]{ + new Component[]{gradientBar, null}, + new Component[]{new UILabel(Inter.getLocText("Gradient-Direction") + ":"), directionPane} + }; + JPanel Gradient = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); + this.setLayout(new BorderLayout()); + this.add(Gradient, BorderLayout.CENTER); + } + + public void populateBean(Background background) { + GradientBackground bg = (GradientBackground) background; + this.gradientBar.getSelectColorPointBtnP1().setColorInner(bg.getStartColor()); + this.gradientBar.getSelectColorPointBtnP2().setColorInner(bg.getEndColor()); + directionPane.setSelectedItem(bg.getDirection()); + if (bg.isUseCell()) { + return; + } + double startValue = (double) bg.getBeginPlace(); + double endValue = (double) bg.getFinishPlace(); + gradientBar.setStartValue(startValue); + gradientBar.setEndValue(endValue); + if(this.gradientBar.getSelectColorPointBtnP1() != null && this.gradientBar.getSelectColorPointBtnP2() != null){ + this.gradientBar.getSelectColorPointBtnP1().setX(startValue); + this.gradientBar.getSelectColorPointBtnP2().setX(endValue); + } + this.gradientBar.repaint(); + } + + public GradientBackground updateBean() { + GradientBackground gb = new GradientBackground(gradientBar.getSelectColorPointBtnP1().getColorInner(), gradientBar.getSelectColorPointBtnP2().getColorInner()); + gb.setDirection(directionPane.getSelectedItem()); + if (gradientBar.isOriginalPlace()) { + gb.setUseCell(true); + } else { + gb.setUseCell(false); + gb.setBeginPlace((float) gradientBar.getStartValue()); + gb.setFinishPlace((float) gradientBar.getEndValue()); + } + return gb; + } + + /** + * 给组件登记一个观察者监听事件 + * + * @param listener 观察者监听事件 + */ + public void registerChangeListener(final UIObserverListener listener) { + gradientBar.addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + listener.doChange(); + } + }); + directionPane.addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + listener.doChange(); + } + }); + } + + @Override + public boolean accept(Background background) { + return background instanceof GradientBackground; + } + + @Override + public String title4PopupWindow() { + return Inter.getLocText("Gradient-Color"); + } + } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/mainframe/backgroundpane/ImageBackgroundPane.java b/designer_base/src/com/fr/design/mainframe/backgroundpane/ImageBackgroundQuickPane.java similarity index 93% rename from designer_base/src/com/fr/design/mainframe/backgroundpane/ImageBackgroundPane.java rename to designer_base/src/com/fr/design/mainframe/backgroundpane/ImageBackgroundQuickPane.java index 7565d7d78a..114b704c05 100644 --- a/designer_base/src/com/fr/design/mainframe/backgroundpane/ImageBackgroundPane.java +++ b/designer_base/src/com/fr/design/mainframe/backgroundpane/ImageBackgroundQuickPane.java @@ -1,185 +1,185 @@ -package com.fr.design.mainframe.backgroundpane; - -import com.fr.base.BaseUtils; -import com.fr.base.Style; -import com.fr.base.background.ImageBackground; -import com.fr.design.constants.UIConstants; -import com.fr.design.border.UIRoundedBorder; -import com.fr.design.event.UIObserverListener; -import com.fr.design.gui.ibutton.UIButton; -import com.fr.design.gui.ibutton.UIButtonGroup; -import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.design.mainframe.DesignerContext; -import com.fr.general.Background; -import com.fr.general.Inter; -import com.fr.stable.Constants; -import com.fr.stable.CoreGraphHelper; -import com.fr.design.style.background.image.ImageFileChooser; - -import javax.swing.*; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; - -/** - * @author zhou - * @since 2012-5-29下午1:12:06 - */ -public class ImageBackgroundPane extends BackgroundSettingPane { - - private ImagePreviewPane previewPane; - private Style imageStyle = null; - private ChangeListener changeListener = null; - private ImageFileChooser imageFileChooser; - - private UIButtonGroup imageLayoutPane; - - public ImageBackgroundPane() { - this(true); - } - - public ImageBackgroundPane(boolean hasImageLayout) { - this.setLayout(new BorderLayout(0, 4)); - String[] nameArray = {Inter.getLocText("FR-Background_Image_Default"), Inter.getLocText("FR-Background_Image_Titled"), Inter.getLocText("FR-Background_Image_Adjust"), Inter.getLocText("FR-Background_Image_Extend")}; - Byte[] valueArray = {Constants.IMAGE_CENTER, Constants.IMAGE_TILED, Constants.IMAGE_EXTEND, Constants.IMAGE_ADJUST}; - imageLayoutPane = new UIButtonGroup(nameArray, valueArray); - imageLayoutPane.setSelectedIndex(0); - - previewPane = new ImagePreviewPane(); - JPanel borderPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - borderPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 5)); - borderPane.setPreferredSize(new Dimension(0, 145)); - borderPane.add(previewPane, BorderLayout.CENTER); - this.add(borderPane, BorderLayout.NORTH); - previewPane.addChangeListener(imageSizeChangeListener); - - JPanel southPane = new JPanel(new BorderLayout(0, 4)); - JPanel contentPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - contentPane.add(southPane, BorderLayout.NORTH); - this.add(contentPane, BorderLayout.CENTER); - - JPanel selectFilePane = new JPanel(new GridLayout(0, 2)); - - UIButton selectPictureButton = new UIButton(Inter.getLocText("Image-Select_Picture")); - selectFilePane.add(new JPanel()); - selectFilePane.add(selectPictureButton); - selectPictureButton.addActionListener(selectPictureActionListener); - - if(hasImageLayout){ - southPane.add(imageLayoutPane, BorderLayout.CENTER); - } - southPane.add(selectFilePane, BorderLayout.SOUTH); - - imageLayoutPane.addChangeListener(new ChangeListener() { - - @Override - public void stateChanged(ChangeEvent e) { - imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(imageLayoutPane.getSelectedItem()); - previewPane.setImageStyle(imageStyle); - previewPane.repaint(); - } - }); - } - - /** - * Select picture. - */ - ActionListener selectPictureActionListener = new ActionListener() { - - public void actionPerformed(ActionEvent evt) { - if (imageFileChooser == null) { - imageFileChooser = new ImageFileChooser(); - imageFileChooser.setMultiSelectionEnabled(false); - } - int returnVal = imageFileChooser.showOpenDialog(DesignerContext.getDesignerFrame()); - if (returnVal != JFileChooser.CANCEL_OPTION) { - File selectedFile = imageFileChooser.getSelectedFile(); - - if (selectedFile != null && selectedFile.isFile()) { - Image image = BaseUtils.readImage(selectedFile.getPath()); - CoreGraphHelper.waitForImage(image); - - previewPane.setImage(image); - imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(imageLayoutPane.getSelectedItem()); - previewPane.setImageStyle(imageStyle); - previewPane.repaint(); - } else { - previewPane.setImage(null); - } - fireChagneListener(); - } - - } - }; - - public void populateBean(Background background) { - - ImageBackground imageBackground = (ImageBackground) background; - imageLayoutPane.setSelectedItem((byte) imageBackground.getLayout()); - Style.DEFAULT_STYLE.deriveImageLayout(imageBackground.getLayout()); - - previewPane.setImageStyle(ImageBackgroundPane.this.imageStyle); - previewPane.setImage(imageBackground.getImage()); - previewPane.repaint(); - } - - public Background updateBean() { - ImageBackground imageBackground = new ImageBackground(previewPane.getImage()); - imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(imageLayoutPane.getSelectedItem()); - imageBackground.setLayout(imageStyle.getImageLayout()); - return imageBackground; - } - - /** - * 给组件登记一个观察者监听事件 - * - * @param listener 观察者监听事件 - */ - public void registerChangeListener(final UIObserverListener listener) { - changeListener = new ChangeListener() { - public void stateChanged(ChangeEvent e) { - listener.doChange(); - } - }; - imageLayoutPane.addChangeListener(changeListener); - } - - - private void fireChagneListener() { - if (this.changeListener != null) { - ChangeEvent evt = new ChangeEvent(this); - this.changeListener.stateChanged(evt); - } - } - - ChangeListener imageSizeChangeListener = new ChangeListener() { - - public void stateChanged(ChangeEvent evt) { - if (imageLayoutPane.getSelectedItem() != null) { - imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(imageLayoutPane.getSelectedItem()); - previewPane.setImageStyle(imageStyle); - previewPane.repaint(); - } - } - }; - - /** - * 判断是否是图片背景 - * @param background 背景 - * @return 判断是否是图片背景 - */ - public boolean accept(Background background) { - return background instanceof ImageBackground; - } - - /** - * 标题 - * @return 标题 - */ - public String title4PopupWindow() { - return Inter.getLocText("FR-Background_Image"); - } +package com.fr.design.mainframe.backgroundpane; + +import com.fr.base.BaseUtils; +import com.fr.base.Style; +import com.fr.base.background.ImageBackground; +import com.fr.design.constants.UIConstants; +import com.fr.design.border.UIRoundedBorder; +import com.fr.design.event.UIObserverListener; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ibutton.UIButtonGroup; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.mainframe.DesignerContext; +import com.fr.general.Background; +import com.fr.general.Inter; +import com.fr.stable.Constants; +import com.fr.stable.CoreGraphHelper; +import com.fr.design.style.background.image.ImageFileChooser; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; + +/** + * @author zhou + * @since 2012-5-29下午1:12:06 + */ +public class ImageBackgroundQuickPane extends BackgroundQuickPane { + + private ImagePreviewPane previewPane; + private Style imageStyle = null; + private ChangeListener changeListener = null; + private ImageFileChooser imageFileChooser; + + private UIButtonGroup imageLayoutPane; + + public ImageBackgroundQuickPane() { + this(true); + } + + public ImageBackgroundQuickPane(boolean hasImageLayout) { + this.setLayout(new BorderLayout(0, 4)); + String[] nameArray = {Inter.getLocText("FR-Background_Image_Default"), Inter.getLocText("FR-Background_Image_Titled"), Inter.getLocText("FR-Background_Image_Adjust"), Inter.getLocText("FR-Background_Image_Extend")}; + Byte[] valueArray = {Constants.IMAGE_CENTER, Constants.IMAGE_TILED, Constants.IMAGE_EXTEND, Constants.IMAGE_ADJUST}; + imageLayoutPane = new UIButtonGroup(nameArray, valueArray); + imageLayoutPane.setSelectedIndex(0); + + previewPane = new ImagePreviewPane(); + JPanel borderPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + borderPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 5)); + borderPane.setPreferredSize(new Dimension(0, 145)); + borderPane.add(previewPane, BorderLayout.CENTER); + this.add(borderPane, BorderLayout.NORTH); + previewPane.addChangeListener(imageSizeChangeListener); + + JPanel southPane = new JPanel(new BorderLayout(0, 4)); + JPanel contentPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + contentPane.add(southPane, BorderLayout.NORTH); + this.add(contentPane, BorderLayout.CENTER); + + JPanel selectFilePane = new JPanel(new GridLayout(0, 2)); + + UIButton selectPictureButton = new UIButton(Inter.getLocText("Image-Select_Picture")); + selectFilePane.add(new JPanel()); + selectFilePane.add(selectPictureButton); + selectPictureButton.addActionListener(selectPictureActionListener); + + if(hasImageLayout){ + southPane.add(imageLayoutPane, BorderLayout.CENTER); + } + southPane.add(selectFilePane, BorderLayout.SOUTH); + + imageLayoutPane.addChangeListener(new ChangeListener() { + + @Override + public void stateChanged(ChangeEvent e) { + imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(imageLayoutPane.getSelectedItem()); + previewPane.setImageStyle(imageStyle); + previewPane.repaint(); + } + }); + } + + /** + * Select picture. + */ + ActionListener selectPictureActionListener = new ActionListener() { + + public void actionPerformed(ActionEvent evt) { + if (imageFileChooser == null) { + imageFileChooser = new ImageFileChooser(); + imageFileChooser.setMultiSelectionEnabled(false); + } + int returnVal = imageFileChooser.showOpenDialog(DesignerContext.getDesignerFrame()); + if (returnVal != JFileChooser.CANCEL_OPTION) { + File selectedFile = imageFileChooser.getSelectedFile(); + + if (selectedFile != null && selectedFile.isFile()) { + Image image = BaseUtils.readImage(selectedFile.getPath()); + CoreGraphHelper.waitForImage(image); + + previewPane.setImage(image); + imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(imageLayoutPane.getSelectedItem()); + previewPane.setImageStyle(imageStyle); + previewPane.repaint(); + } else { + previewPane.setImage(null); + } + fireChagneListener(); + } + + } + }; + + public void populateBean(Background background) { + + ImageBackground imageBackground = (ImageBackground) background; + imageLayoutPane.setSelectedItem((byte) imageBackground.getLayout()); + Style.DEFAULT_STYLE.deriveImageLayout(imageBackground.getLayout()); + + previewPane.setImageStyle(ImageBackgroundQuickPane.this.imageStyle); + previewPane.setImage(imageBackground.getImage()); + previewPane.repaint(); + } + + public Background updateBean() { + ImageBackground imageBackground = new ImageBackground(previewPane.getImage()); + imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(imageLayoutPane.getSelectedItem()); + imageBackground.setLayout(imageStyle.getImageLayout()); + return imageBackground; + } + + /** + * 给组件登记一个观察者监听事件 + * + * @param listener 观察者监听事件 + */ + public void registerChangeListener(final UIObserverListener listener) { + changeListener = new ChangeListener() { + public void stateChanged(ChangeEvent e) { + listener.doChange(); + } + }; + imageLayoutPane.addChangeListener(changeListener); + } + + + private void fireChagneListener() { + if (this.changeListener != null) { + ChangeEvent evt = new ChangeEvent(this); + this.changeListener.stateChanged(evt); + } + } + + ChangeListener imageSizeChangeListener = new ChangeListener() { + + public void stateChanged(ChangeEvent evt) { + if (imageLayoutPane.getSelectedItem() != null) { + imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(imageLayoutPane.getSelectedItem()); + previewPane.setImageStyle(imageStyle); + previewPane.repaint(); + } + } + }; + + /** + * 判断是否是图片背景 + * @param background 背景 + * @return 判断是否是图片背景 + */ + public boolean accept(Background background) { + return background instanceof ImageBackground; + } + + /** + * 标题 + * @return 标题 + */ + public String title4PopupWindow() { + return Inter.getLocText("FR-Background_Image"); + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/mainframe/backgroundpane/NullBackgroundPane.java b/designer_base/src/com/fr/design/mainframe/backgroundpane/NullBackgroundQuickPane.java similarity index 89% rename from designer_base/src/com/fr/design/mainframe/backgroundpane/NullBackgroundPane.java rename to designer_base/src/com/fr/design/mainframe/backgroundpane/NullBackgroundQuickPane.java index 6edd7c7fcd..60d39ed2d6 100644 --- a/designer_base/src/com/fr/design/mainframe/backgroundpane/NullBackgroundPane.java +++ b/designer_base/src/com/fr/design/mainframe/backgroundpane/NullBackgroundQuickPane.java @@ -1,54 +1,54 @@ -package com.fr.design.mainframe.backgroundpane; - -import com.fr.design.event.UIObserverListener; -import com.fr.general.Background; -import com.fr.general.Inter; - -import java.awt.*; - -/** - * @author zhou - * @since 2012-5-29下午1:12:24 - */ -public class NullBackgroundPane extends BackgroundSettingPane { - - public Dimension getPreferredSize(){ - return new Dimension(0,0); - } - - public void populateBean(Background background) { - // do nothing. - } - - public Background updateBean() { - return null; - } - - /** - * 给组件登记一个观察者监听事件 - * - * @param listener 观察者监听事件 - */ - public void registerChangeListener(final UIObserverListener listener) { - - } - - - /** - * 是否接受 - * @param background 背景 - * @return 是则返回true - */ - public boolean accept(Background background) { - return background == null; - } - - /** - * 名称 - * @return 名称 - */ - public String title4PopupWindow() { - return Inter.getLocText("Background-Null"); - } - +package com.fr.design.mainframe.backgroundpane; + +import com.fr.design.event.UIObserverListener; +import com.fr.general.Background; +import com.fr.general.Inter; + +import java.awt.*; + +/** + * @author zhou + * @since 2012-5-29下午1:12:24 + */ +public class NullBackgroundQuickPane extends BackgroundQuickPane { + + public Dimension getPreferredSize(){ + return new Dimension(0,0); + } + + public void populateBean(Background background) { + // do nothing. + } + + public Background updateBean() { + return null; + } + + /** + * 给组件登记一个观察者监听事件 + * + * @param listener 观察者监听事件 + */ + public void registerChangeListener(final UIObserverListener listener) { + + } + + + /** + * 是否接受 + * @param background 背景 + * @return 是则返回true + */ + public boolean accept(Background background) { + return background == null; + } + + /** + * 名称 + * @return 名称 + */ + public String title4PopupWindow() { + return Inter.getLocText("Background-Null"); + } + } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/mainframe/backgroundpane/PatternBackgroundPane.java b/designer_base/src/com/fr/design/mainframe/backgroundpane/PatternBackgroundQuickPane.java similarity index 92% rename from designer_base/src/com/fr/design/mainframe/backgroundpane/PatternBackgroundPane.java rename to designer_base/src/com/fr/design/mainframe/backgroundpane/PatternBackgroundQuickPane.java index 7e3e150426..4e31405d11 100644 --- a/designer_base/src/com/fr/design/mainframe/backgroundpane/PatternBackgroundPane.java +++ b/designer_base/src/com/fr/design/mainframe/backgroundpane/PatternBackgroundQuickPane.java @@ -1,211 +1,211 @@ -package com.fr.design.mainframe.backgroundpane; - -import com.fr.base.GraphHelper; -import com.fr.base.background.PatternBackground; -import com.fr.design.constants.UIConstants; -import com.fr.design.border.UIRoundedBorder; -import com.fr.design.event.UIObserverListener; -import com.fr.design.gui.ilable.UILabel; -import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.general.Background; -import com.fr.general.Inter; -import com.fr.design.style.color.ColorSelectBox; - -import javax.swing.*; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.geom.Rectangle2D; - -/** - * @author zhou - * @since 2012-5-29下午1:12:33 - */ -public class PatternBackgroundPane extends BackgroundSettingPane { - - private int patternIndex = 0; // pattern index. - private ColorSelectBox foregroundColorPane; - private ColorSelectBox backgroundColorPane; - private PatternButton[] patternButtonArray; - - public PatternBackgroundPane() { - this.setLayout(new BorderLayout(0, 4)); - - JPanel contentPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); - this.add(contentPane, BorderLayout.NORTH); - contentPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 5)); - - JPanel typePane2 = new JPanel(); - contentPane.add(typePane2); - typePane2.setLayout(new GridLayout(0, 8, 1, 1)); - typePane2.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); - ButtonGroup patternButtonGroup = new ButtonGroup(); - patternButtonArray = new PatternButton[PatternBackground.PATTERN_COUNT]; - for (int i = 0; i < PatternBackground.PATTERN_COUNT; i++) { - patternButtonArray[i] = new PatternButton(i); - patternButtonGroup.add(patternButtonArray[i]); - typePane2.add(patternButtonArray[i]); - } - - JPanel colorPane = new JPanel(new GridLayout(0, 2)); - foregroundColorPane = new ColorSelectBox(70); - backgroundColorPane = new ColorSelectBox(70); - foregroundColorPane.setSelectObject(Color.lightGray); - backgroundColorPane.setSelectObject(Color.black); - - colorPane.add(this.createLabelColorPane(Inter.getLocText("Foreground") + ":", foregroundColorPane)); - colorPane.add(this.createLabelColorPane(Inter.getLocText("Background") + ":", backgroundColorPane)); - this.add(colorPane, BorderLayout.CENTER); - foregroundColorPane.addSelectChangeListener(colorChangeListener); - backgroundColorPane.addSelectChangeListener(colorChangeListener); - } - - @Override - public Dimension getPreferredSize() { - Dimension dim = super.getPreferredSize(); - dim.height = 190; - return dim; - } - - private JPanel createLabelColorPane(String text, JComponent colorPane) { - JPanel labelColorPane = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); - labelColorPane.add(new UILabel(text)); - labelColorPane.add(colorPane); - - return labelColorPane; - } - - public void populateBean(Background background) { - PatternBackground patternBackground = (PatternBackground) background; - int patternIndex = patternBackground.getPatternIndex(); - - if (patternIndex >= 0 && patternIndex < this.patternButtonArray.length) { - this.patternButtonArray[patternIndex].setSelected(true); - this.patternIndex = patternIndex; - } else { - this.patternIndex = 0; - } - - foregroundColorPane.setSelectObject(patternBackground.getForeground()); - backgroundColorPane.setSelectObject(patternBackground.getBackground()); - } - - public Background updateBean() { - return new PatternBackground(patternIndex, foregroundColorPane.getSelectObject(), backgroundColorPane.getSelectObject()); - } - - - /** - * 给组件登记一个观察者监听事件 - * - * @param listener 观察者监听事件 - */ - public void registerChangeListener(final UIObserverListener listener) { - foregroundColorPane.addSelectChangeListener(new ChangeListener() { - public void stateChanged(ChangeEvent e) { - listener.doChange(); - } - }); - backgroundColorPane.addSelectChangeListener(new ChangeListener() { - public void stateChanged(ChangeEvent e) { - listener.doChange(); - } - }); - for (int i = 0, count = patternButtonArray.length; i < count; i ++) { - patternButtonArray[i].addChangeListener(new ChangeListener() { - public void stateChanged(ChangeEvent e) { - listener.doChange(); - } - }); - } - } - - - // Foreground or Background changed. - ChangeListener colorChangeListener = new ChangeListener() { - - public void stateChanged(ChangeEvent e) { - for (int i = 0; i < patternButtonArray.length; i++) { - patternButtonArray[i].setPatternForeground(foregroundColorPane.getSelectObject()); - patternButtonArray[i].setPatternBackground(backgroundColorPane.getSelectObject()); - } - - PatternBackgroundPane.this.repaint();// repaint - } - }; - - /** - * Pattern type button. - */ - class PatternButton extends JToggleButton implements ActionListener { - - public PatternButton(int pIndex) { - this.pIndex = pIndex; - this.addActionListener(this); - - this.setCursor(new Cursor(Cursor.HAND_CURSOR)); - this.setBorder(null); - this.patternBackground = new PatternBackground(this.pIndex, Color.lightGray, Color.black); - } - - public void paintComponent(Graphics g) { - Graphics2D g2d = (Graphics2D) g; - - Dimension d = getSize(); - this.patternBackground.paint(g2d, new Rectangle2D.Double(0, 0, d.width - 1, d.height - 1)); - - if (this.pIndex == patternIndex) {// it's selected. - g2d.setPaint(UIConstants.LINE_COLOR); - GraphHelper.draw(g2d, new Rectangle2D.Double(0, 0, d.width - 1, d.height - 1)); - } - } - - public Dimension getPreferredSize() { - return new Dimension(super.getPreferredSize().width, 20); - } - - public void setPatternForeground(Color foreground) { - this.patternBackground.setForeground(foreground); - } - - public void setPatternBackground(Color background) { - this.patternBackground.setBackground(background); - } - - /** - * set Pattern index. - */ - public void actionPerformed(ActionEvent evt) { - PatternBackgroundPane.this.patternIndex = pIndex; - - fireChagneListener(); - PatternBackgroundPane.this.repaint();// repaint - } - - public void addChangeListener(ChangeListener changeListener) { - this.changeListener = changeListener; - } - - private void fireChagneListener() { - if (this.changeListener != null) { - ChangeEvent evt = new ChangeEvent(this); - this.changeListener.stateChanged(evt); - } - } - - private int pIndex = 0; - private PatternBackground patternBackground; - } - - @Override - public boolean accept(Background background) { - return background instanceof PatternBackground; - } - - @Override - public String title4PopupWindow() { - return Inter.getLocText("Background-Pattern"); - } +package com.fr.design.mainframe.backgroundpane; + +import com.fr.base.GraphHelper; +import com.fr.base.background.PatternBackground; +import com.fr.design.constants.UIConstants; +import com.fr.design.border.UIRoundedBorder; +import com.fr.design.event.UIObserverListener; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.general.Background; +import com.fr.general.Inter; +import com.fr.design.style.color.ColorSelectBox; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.geom.Rectangle2D; + +/** + * @author zhou + * @since 2012-5-29下午1:12:33 + */ +public class PatternBackgroundQuickPane extends BackgroundQuickPane { + + private int patternIndex = 0; // pattern setIndex. + private ColorSelectBox foregroundColorPane; + private ColorSelectBox backgroundColorPane; + private PatternButton[] patternButtonArray; + + public PatternBackgroundQuickPane() { + this.setLayout(new BorderLayout(0, 4)); + + JPanel contentPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); + this.add(contentPane, BorderLayout.NORTH); + contentPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 5)); + + JPanel typePane2 = new JPanel(); + contentPane.add(typePane2); + typePane2.setLayout(new GridLayout(0, 8, 1, 1)); + typePane2.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); + ButtonGroup patternButtonGroup = new ButtonGroup(); + patternButtonArray = new PatternButton[PatternBackground.PATTERN_COUNT]; + for (int i = 0; i < PatternBackground.PATTERN_COUNT; i++) { + patternButtonArray[i] = new PatternButton(i); + patternButtonGroup.add(patternButtonArray[i]); + typePane2.add(patternButtonArray[i]); + } + + JPanel colorPane = new JPanel(new GridLayout(0, 2)); + foregroundColorPane = new ColorSelectBox(70); + backgroundColorPane = new ColorSelectBox(70); + foregroundColorPane.setSelectObject(Color.lightGray); + backgroundColorPane.setSelectObject(Color.black); + + colorPane.add(this.createLabelColorPane(Inter.getLocText("Foreground") + ":", foregroundColorPane)); + colorPane.add(this.createLabelColorPane(Inter.getLocText("Background") + ":", backgroundColorPane)); + this.add(colorPane, BorderLayout.CENTER); + foregroundColorPane.addSelectChangeListener(colorChangeListener); + backgroundColorPane.addSelectChangeListener(colorChangeListener); + } + + @Override + public Dimension getPreferredSize() { + Dimension dim = super.getPreferredSize(); + dim.height = 190; + return dim; + } + + private JPanel createLabelColorPane(String text, JComponent colorPane) { + JPanel labelColorPane = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); + labelColorPane.add(new UILabel(text)); + labelColorPane.add(colorPane); + + return labelColorPane; + } + + public void populateBean(Background background) { + PatternBackground patternBackground = (PatternBackground) background; + int patternIndex = patternBackground.getPatternIndex(); + + if (patternIndex >= 0 && patternIndex < this.patternButtonArray.length) { + this.patternButtonArray[patternIndex].setSelected(true); + this.patternIndex = patternIndex; + } else { + this.patternIndex = 0; + } + + foregroundColorPane.setSelectObject(patternBackground.getForeground()); + backgroundColorPane.setSelectObject(patternBackground.getBackground()); + } + + public Background updateBean() { + return new PatternBackground(patternIndex, foregroundColorPane.getSelectObject(), backgroundColorPane.getSelectObject()); + } + + + /** + * 给组件登记一个观察者监听事件 + * + * @param listener 观察者监听事件 + */ + public void registerChangeListener(final UIObserverListener listener) { + foregroundColorPane.addSelectChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + listener.doChange(); + } + }); + backgroundColorPane.addSelectChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + listener.doChange(); + } + }); + for (int i = 0, count = patternButtonArray.length; i < count; i ++) { + patternButtonArray[i].addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + listener.doChange(); + } + }); + } + } + + + // Foreground or Background changed. + ChangeListener colorChangeListener = new ChangeListener() { + + public void stateChanged(ChangeEvent e) { + for (int i = 0; i < patternButtonArray.length; i++) { + patternButtonArray[i].setPatternForeground(foregroundColorPane.getSelectObject()); + patternButtonArray[i].setPatternBackground(backgroundColorPane.getSelectObject()); + } + + PatternBackgroundQuickPane.this.repaint();// repaint + } + }; + + /** + * Pattern type button. + */ + class PatternButton extends JToggleButton implements ActionListener { + + public PatternButton(int pIndex) { + this.pIndex = pIndex; + this.addActionListener(this); + + this.setCursor(new Cursor(Cursor.HAND_CURSOR)); + this.setBorder(null); + this.patternBackground = new PatternBackground(this.pIndex, Color.lightGray, Color.black); + } + + public void paintComponent(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + + Dimension d = getSize(); + this.patternBackground.paint(g2d, new Rectangle2D.Double(0, 0, d.width - 1, d.height - 1)); + + if (this.pIndex == patternIndex) {// it's selected. + g2d.setPaint(UIConstants.LINE_COLOR); + GraphHelper.draw(g2d, new Rectangle2D.Double(0, 0, d.width - 1, d.height - 1)); + } + } + + public Dimension getPreferredSize() { + return new Dimension(super.getPreferredSize().width, 20); + } + + public void setPatternForeground(Color foreground) { + this.patternBackground.setForeground(foreground); + } + + public void setPatternBackground(Color background) { + this.patternBackground.setBackground(background); + } + + /** + * set Pattern setIndex. + */ + public void actionPerformed(ActionEvent evt) { + PatternBackgroundQuickPane.this.patternIndex = pIndex; + + fireChagneListener(); + PatternBackgroundQuickPane.this.repaint();// repaint + } + + public void addChangeListener(ChangeListener changeListener) { + this.changeListener = changeListener; + } + + private void fireChagneListener() { + if (this.changeListener != null) { + ChangeEvent evt = new ChangeEvent(this); + this.changeListener.stateChanged(evt); + } + } + + private int pIndex = 0; + private PatternBackground patternBackground; + } + + @Override + public boolean accept(Background background) { + return background instanceof PatternBackground; + } + + @Override + public String title4PopupWindow() { + return Inter.getLocText("Background-Pattern"); + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/mainframe/backgroundpane/TextureBackgroundPane.java b/designer_base/src/com/fr/design/mainframe/backgroundpane/TextureBackgroundQuickPane.java similarity index 94% rename from designer_base/src/com/fr/design/mainframe/backgroundpane/TextureBackgroundPane.java rename to designer_base/src/com/fr/design/mainframe/backgroundpane/TextureBackgroundQuickPane.java index caff963d63..dcd386343e 100644 --- a/designer_base/src/com/fr/design/mainframe/backgroundpane/TextureBackgroundPane.java +++ b/designer_base/src/com/fr/design/mainframe/backgroundpane/TextureBackgroundQuickPane.java @@ -1,173 +1,173 @@ -package com.fr.design.mainframe.backgroundpane; - -import com.fr.base.GraphHelper; -import com.fr.base.background.TextureBackground; -import com.fr.design.constants.UIConstants; -import com.fr.design.border.UIRoundedBorder; -import com.fr.design.event.UIObserverListener; -import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.general.Background; -import com.fr.general.ComparatorUtils; -import com.fr.general.Inter; - -import javax.swing.*; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.geom.Rectangle2D; - -public class TextureBackgroundPane extends BackgroundSettingPane { - - private TexturePaint texturePaint; - private TextureButton[] textureButtonArray; - - public TextureBackgroundPane() { - this.setLayout(FRGUIPaneFactory.createBorderLayout()); - - JPanel borderPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - borderPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 5)); - JPanel contentPane = new JPanel(); - borderPane.add(contentPane, BorderLayout.NORTH); - this.add(borderPane, BorderLayout.NORTH); - contentPane.setLayout(new GridLayout(0, 8, 1, 1)); - contentPane.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); - borderPane.setPreferredSize(new Dimension(0, 145)); - ButtonGroup patternButtonGroup = new ButtonGroup(); - textureButtonArray = new TextureButton[EMBED_TEXTURE_PAINT_ARRAY.length]; - for (int i = 0; i < EMBED_TEXTURE_PAINT_ARRAY.length; i++) { - textureButtonArray[i] = new TextureButton(EMBED_TEXTURE_PAINT_ARRAY[i], EMBED_TEXTURE_PAINT_DES_ARRAY[i]); - patternButtonGroup.add(textureButtonArray[i]); - contentPane.add(textureButtonArray[i]); - } - } - - public void populateBean(Background background) { - TextureBackground textureBackground = (TextureBackground) background; - - this.texturePaint = textureBackground.getTexturePaint(); - - - for (int i = 0; i < textureButtonArray.length; i++) { - if (ComparatorUtils.equals(textureButtonArray[i].getTexturePaint(), this.texturePaint)) { - textureButtonArray[i].setSelected(true); - break; - } - } - } - - public Background updateBean() { - if (this.texturePaint == null) { - textureButtonArray[0].doClick(); - } - return new TextureBackground(this.texturePaint); - } - - /** - * 给组件登记一个观察者监听事件 - * - * @param listener 观察者监听事件 - */ - public void registerChangeListener(final UIObserverListener listener) { - for (int i = 0, count = textureButtonArray.length; i < count; i++) { - textureButtonArray[i].addChangeListener(new ChangeListener() { - public void stateChanged(ChangeEvent e) { - listener.doChange(); - } - }); - } - } - - - /** - * Texture type button. - */ - class TextureButton extends JToggleButton implements ActionListener { - - private TexturePaint buttonTexturePaint; - - public TextureButton(TexturePaint buttonTexturePaint, String tooltip) { - this.buttonTexturePaint = buttonTexturePaint; - this.setToolTipText(tooltip); - - this.setCursor(new Cursor(Cursor.HAND_CURSOR)); - this.addActionListener(this); - this.setBorder(null); - } - - public void paintComponent(Graphics g) { - Graphics2D g2d = (Graphics2D) g; - - Dimension d = getSize(); - - g2d.setPaint(this.buttonTexturePaint); - GraphHelper.fill(g2d, new Rectangle2D.Double(0, 0, d.width - 1, d.height - 1)); - - if (ComparatorUtils.equals(texturePaint, this.buttonTexturePaint)) {// it's - // selected. - g2d.setPaint(UIConstants.LINE_COLOR); - } else { - g2d.setPaint(null); - } - GraphHelper.draw(g2d, new Rectangle2D.Double(0, 0, d.width - 1, d.height - 1)); - } - - public Dimension getPreferredSize() { - return new Dimension(super.getPreferredSize().width, 20); - } - - public TexturePaint getTexturePaint() { - return this.buttonTexturePaint; - } - - /** - * set Pattern index. - */ - public void actionPerformed(ActionEvent evt) { - TextureBackgroundPane.this.texturePaint = this.getTexturePaint(); - - fireChagneListener(); - TextureBackgroundPane.this.repaint(); // repaint. - } - - public void addChangeListener(ChangeListener changeListener) { - this.changeListener = changeListener; - } - - private void fireChagneListener() { - if (this.changeListener != null) { - ChangeEvent evt = new ChangeEvent(this); - this.changeListener.stateChanged(evt); - } - } - } - - public static final TexturePaint[] EMBED_TEXTURE_PAINT_ARRAY = new TexturePaint[]{TextureBackground.NEWSPRINT_TEXTURE_PAINT, TextureBackground.RECYCLED_PAPER_TEXTURE_PAINT, - TextureBackground.PARCHMENT_TEXTURE_PAINT, TextureBackground.STATIONERY_TEXTURE_PAINT, TextureBackground.GREEN_MARBLE_TEXTURE_PAINT, - TextureBackground.WHITE_MARBLE_TEXTURE_PAINT, TextureBackground.BROWN_MARBLE_TEXTURE_PAINT, TextureBackground.GRANITE_TEXTURE_PAINT, - TextureBackground.BLUE_TISSUE_PAPER_TEXTURE_PAINT, TextureBackground.PINK_TISSUE_PAPER_TEXTURE_PAINT, TextureBackground.PURPLE_MESH_TEXTURE_PAINT, - TextureBackground.BOUQUET_TEXTURE_PAINT, TextureBackground.PAPYRUS_TEXTURE_PAINT, TextureBackground.CANVAS_TEXTURE_PAINT, TextureBackground.DENIM_TEXTURE_PAINT, - TextureBackground.WOVEN_MAT_TEXTURE_PAINT, TextureBackground.WATER_DROPLETS_TEXTURE_PAINT, TextureBackground.PAPER_BAG_TEXTURE_PAINT, TextureBackground.FISH_FOSSIL_TEXTURE_PAINT, - TextureBackground.SAND_TEXTURE_PAINT, TextureBackground.CORK_TEXTURE_PAINT, TextureBackground.WALNUT_TEXTURE_PAINT, TextureBackground.OAK_TEXTURE_PAINT, - TextureBackground.MEDIUM_WOOD_TEXTURE_PAINT}; - private static final String[] EMBED_TEXTURE_PAINT_DES_ARRAY = new String[]{Inter.getLocText("BackgroundTexture-Newsprint"), Inter.getLocText("BackgroundTexture-RecycledPaper"), - Inter.getLocText("BackgroundTexture-Parchment"), Inter.getLocText("BackgroundTexture-Stationery"), Inter.getLocText("BackgroundTexture-GreenMarble"), - Inter.getLocText("BackgroundTexture-WhiteMarble"), Inter.getLocText("BackgroundTexture-BrownMarble"), Inter.getLocText("BackgroundTexture-Granite"), - Inter.getLocText("BackgroundTexture-BlueTissuePaper"), Inter.getLocText("BackgroundTexture-PinkTissuePaper"), Inter.getLocText("BackgroundTexture-PurpleMesh"), - Inter.getLocText("BackgroundTexture-Bouquet"), Inter.getLocText("BackgroundTexture-Papyrus"), Inter.getLocText("BackgroundTexture-Canvas"), - Inter.getLocText("BackgroundTexture-Denim"), Inter.getLocText("BackgroundTexture-WovenMat"), Inter.getLocText("BackgroundTexture-WaterDroplets"), - Inter.getLocText("BackgroundTexture-PaperBag"), Inter.getLocText("BackgroundTexture-FishFossil"), Inter.getLocText("BackgroundTexture-Sand"), - Inter.getLocText("BackgroundTexture-Cork"), Inter.getLocText("BackgroundTexture-Walnut"), Inter.getLocText("BackgroundTexture-Oak"), - Inter.getLocText("BackgroundTexture-MediumWood")}; - - @Override - public boolean accept(Background background) { - return background instanceof TextureBackground; - } - - @Override - public String title4PopupWindow() { - return Inter.getLocText("Background-Texture"); - } +package com.fr.design.mainframe.backgroundpane; + +import com.fr.base.GraphHelper; +import com.fr.base.background.TextureBackground; +import com.fr.design.constants.UIConstants; +import com.fr.design.border.UIRoundedBorder; +import com.fr.design.event.UIObserverListener; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.general.Background; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.geom.Rectangle2D; + +public class TextureBackgroundQuickPane extends BackgroundQuickPane { + + private TexturePaint texturePaint; + private TextureButton[] textureButtonArray; + + public TextureBackgroundQuickPane() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + + JPanel borderPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); + borderPane.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 5)); + JPanel contentPane = new JPanel(); + borderPane.add(contentPane, BorderLayout.NORTH); + this.add(borderPane, BorderLayout.NORTH); + contentPane.setLayout(new GridLayout(0, 8, 1, 1)); + contentPane.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); + borderPane.setPreferredSize(new Dimension(0, 145)); + ButtonGroup patternButtonGroup = new ButtonGroup(); + textureButtonArray = new TextureButton[EMBED_TEXTURE_PAINT_ARRAY.length]; + for (int i = 0; i < EMBED_TEXTURE_PAINT_ARRAY.length; i++) { + textureButtonArray[i] = new TextureButton(EMBED_TEXTURE_PAINT_ARRAY[i], EMBED_TEXTURE_PAINT_DES_ARRAY[i]); + patternButtonGroup.add(textureButtonArray[i]); + contentPane.add(textureButtonArray[i]); + } + } + + public void populateBean(Background background) { + TextureBackground textureBackground = (TextureBackground) background; + + this.texturePaint = textureBackground.getTexturePaint(); + + + for (int i = 0; i < textureButtonArray.length; i++) { + if (ComparatorUtils.equals(textureButtonArray[i].getTexturePaint(), this.texturePaint)) { + textureButtonArray[i].setSelected(true); + break; + } + } + } + + public Background updateBean() { + if (this.texturePaint == null) { + textureButtonArray[0].doClick(); + } + return new TextureBackground(this.texturePaint); + } + + /** + * 给组件登记一个观察者监听事件 + * + * @param listener 观察者监听事件 + */ + public void registerChangeListener(final UIObserverListener listener) { + for (int i = 0, count = textureButtonArray.length; i < count; i++) { + textureButtonArray[i].addChangeListener(new ChangeListener() { + public void stateChanged(ChangeEvent e) { + listener.doChange(); + } + }); + } + } + + + /** + * Texture type button. + */ + class TextureButton extends JToggleButton implements ActionListener { + + private TexturePaint buttonTexturePaint; + + public TextureButton(TexturePaint buttonTexturePaint, String tooltip) { + this.buttonTexturePaint = buttonTexturePaint; + this.setToolTipText(tooltip); + + this.setCursor(new Cursor(Cursor.HAND_CURSOR)); + this.addActionListener(this); + this.setBorder(null); + } + + public void paintComponent(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + + Dimension d = getSize(); + + g2d.setPaint(this.buttonTexturePaint); + GraphHelper.fill(g2d, new Rectangle2D.Double(0, 0, d.width - 1, d.height - 1)); + + if (ComparatorUtils.equals(texturePaint, this.buttonTexturePaint)) {// it's + // selected. + g2d.setPaint(UIConstants.LINE_COLOR); + } else { + g2d.setPaint(null); + } + GraphHelper.draw(g2d, new Rectangle2D.Double(0, 0, d.width - 1, d.height - 1)); + } + + public Dimension getPreferredSize() { + return new Dimension(super.getPreferredSize().width, 20); + } + + public TexturePaint getTexturePaint() { + return this.buttonTexturePaint; + } + + /** + * set Pattern setIndex. + */ + public void actionPerformed(ActionEvent evt) { + TextureBackgroundQuickPane.this.texturePaint = this.getTexturePaint(); + + fireChagneListener(); + TextureBackgroundQuickPane.this.repaint(); // repaint. + } + + public void addChangeListener(ChangeListener changeListener) { + this.changeListener = changeListener; + } + + private void fireChagneListener() { + if (this.changeListener != null) { + ChangeEvent evt = new ChangeEvent(this); + this.changeListener.stateChanged(evt); + } + } + } + + public static final TexturePaint[] EMBED_TEXTURE_PAINT_ARRAY = new TexturePaint[]{TextureBackground.NEWSPRINT_TEXTURE_PAINT, TextureBackground.RECYCLED_PAPER_TEXTURE_PAINT, + TextureBackground.PARCHMENT_TEXTURE_PAINT, TextureBackground.STATIONERY_TEXTURE_PAINT, TextureBackground.GREEN_MARBLE_TEXTURE_PAINT, + TextureBackground.WHITE_MARBLE_TEXTURE_PAINT, TextureBackground.BROWN_MARBLE_TEXTURE_PAINT, TextureBackground.GRANITE_TEXTURE_PAINT, + TextureBackground.BLUE_TISSUE_PAPER_TEXTURE_PAINT, TextureBackground.PINK_TISSUE_PAPER_TEXTURE_PAINT, TextureBackground.PURPLE_MESH_TEXTURE_PAINT, + TextureBackground.BOUQUET_TEXTURE_PAINT, TextureBackground.PAPYRUS_TEXTURE_PAINT, TextureBackground.CANVAS_TEXTURE_PAINT, TextureBackground.DENIM_TEXTURE_PAINT, + TextureBackground.WOVEN_MAT_TEXTURE_PAINT, TextureBackground.WATER_DROPLETS_TEXTURE_PAINT, TextureBackground.PAPER_BAG_TEXTURE_PAINT, TextureBackground.FISH_FOSSIL_TEXTURE_PAINT, + TextureBackground.SAND_TEXTURE_PAINT, TextureBackground.CORK_TEXTURE_PAINT, TextureBackground.WALNUT_TEXTURE_PAINT, TextureBackground.OAK_TEXTURE_PAINT, + TextureBackground.MEDIUM_WOOD_TEXTURE_PAINT}; + private static final String[] EMBED_TEXTURE_PAINT_DES_ARRAY = new String[]{Inter.getLocText("BackgroundTexture-Newsprint"), Inter.getLocText("BackgroundTexture-RecycledPaper"), + Inter.getLocText("BackgroundTexture-Parchment"), Inter.getLocText("BackgroundTexture-Stationery"), Inter.getLocText("BackgroundTexture-GreenMarble"), + Inter.getLocText("BackgroundTexture-WhiteMarble"), Inter.getLocText("BackgroundTexture-BrownMarble"), Inter.getLocText("BackgroundTexture-Granite"), + Inter.getLocText("BackgroundTexture-BlueTissuePaper"), Inter.getLocText("BackgroundTexture-PinkTissuePaper"), Inter.getLocText("BackgroundTexture-PurpleMesh"), + Inter.getLocText("BackgroundTexture-Bouquet"), Inter.getLocText("BackgroundTexture-Papyrus"), Inter.getLocText("BackgroundTexture-Canvas"), + Inter.getLocText("BackgroundTexture-Denim"), Inter.getLocText("BackgroundTexture-WovenMat"), Inter.getLocText("BackgroundTexture-WaterDroplets"), + Inter.getLocText("BackgroundTexture-PaperBag"), Inter.getLocText("BackgroundTexture-FishFossil"), Inter.getLocText("BackgroundTexture-Sand"), + Inter.getLocText("BackgroundTexture-Cork"), Inter.getLocText("BackgroundTexture-Walnut"), Inter.getLocText("BackgroundTexture-Oak"), + Inter.getLocText("BackgroundTexture-MediumWood")}; + + @Override + public boolean accept(Background background) { + return background instanceof TextureBackground; + } + + @Override + public String title4PopupWindow() { + return Inter.getLocText("Background-Texture"); + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/style/AbstractPopBox.java b/designer_base/src/com/fr/design/style/AbstractPopBox.java index a9001b6b59..4630c51ae7 100644 --- a/designer_base/src/com/fr/design/style/AbstractPopBox.java +++ b/designer_base/src/com/fr/design/style/AbstractPopBox.java @@ -2,7 +2,7 @@ package com.fr.design.style; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.style.background.BackgroundJComponent; -import com.fr.design.style.background.gradient.GradientPane; +import com.fr.design.style.background.gradient.GradientBackgroundPane; import com.fr.general.Background; import javax.swing.*; @@ -96,8 +96,8 @@ public abstract class AbstractPopBox extends JPanel { mouseClick(evt); } }; - if (!this.isWindowEventInit && SwingUtilities.getAncestorOfClass(GradientPane.class, this) != null) { - SwingUtilities.getAncestorOfClass(GradientPane.class, this).addMouseListener(parentMouseListener); + if (!this.isWindowEventInit && SwingUtilities.getAncestorOfClass(GradientBackgroundPane.class, this) != null) { + SwingUtilities.getAncestorOfClass(GradientBackgroundPane.class, this).addMouseListener(parentMouseListener); this.isWindowEventInit = true; } } diff --git a/designer_base/src/com/fr/design/style/background/BackgroundDetailPane.java b/designer_base/src/com/fr/design/style/background/BackgroundDetailPane.java new file mode 100644 index 0000000000..694f2c8c17 --- /dev/null +++ b/designer_base/src/com/fr/design/style/background/BackgroundDetailPane.java @@ -0,0 +1,18 @@ +package com.fr.design.style.background; + +import com.fr.general.Background; + +import javax.swing.*; +import javax.swing.event.ChangeListener; + +/** + * Created by richie on 16/5/18. + */ +public abstract class BackgroundDetailPane extends JPanel { + + public abstract void populate(Background background); + + public abstract Background update() throws Exception; + + public abstract void addChangeListener(ChangeListener changeListener); +} diff --git a/designer_base/src/com/fr/design/style/background/BackgroundFactory.java b/designer_base/src/com/fr/design/style/background/BackgroundFactory.java new file mode 100644 index 0000000000..c41639c8a2 --- /dev/null +++ b/designer_base/src/com/fr/design/style/background/BackgroundFactory.java @@ -0,0 +1,121 @@ +package com.fr.design.style.background; + + +import com.fr.base.background.*; +import com.fr.design.ExtraDesignClassManager; +import com.fr.design.fun.BackgroundUIProvider; +import com.fr.design.style.background.gradient.GradientBackgroundPane; +import com.fr.design.style.background.impl.*; +import com.fr.general.Background; +import com.fr.general.Inter; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +/** + * Created by richie on 16/5/18. + */ +public class BackgroundFactory { + + private static Map, BackgroundUIWrapper> map = new HashMap<>(); + private static Map, BackgroundUIWrapper> browser = new HashMap<>(); + + static { + registerUniversal(map); + registerImageBackground(map); + registerUniversal(browser); + registerBrowserImageBackground(browser); + registerExtra(map); + registerExtra(browser); + } + + private static void registerUniversal(Map, BackgroundUIWrapper> map) { + map.put(null, BackgroundUIWrapper.create() + .setType(NullBackgroundPane.class).setTitle(Inter.getLocText("Background-Null"))); + map.put(ColorBackground.class, BackgroundUIWrapper.create() + .setType(ColorBackgroundPane.class).setTitle(Inter.getLocText("Color"))); + map.put(TextureBackground.class, BackgroundUIWrapper.create() + .setType(TextureBackgroundPane.class).setTitle(Inter.getLocText("Background-Texture"))); + map.put(PatternBackground.class, BackgroundUIWrapper.create() + .setType(PatternBackgroundPane.class).setTitle(Inter.getLocText("Background-Pattern"))); + map.put(GradientBackground.class, BackgroundUIWrapper.create() + .setType(GradientBackgroundPane.class).setTitle(Inter.getLocText("Gradient-Color"))); + } + + private static void registerImageBackground(Map, BackgroundUIWrapper> map) { + map.put(ImageBackground.class, BackgroundUIWrapper.create() + .setType(ImageBackgroundPane.class).setTitle(Inter.getLocText("Image"))); + } + + private static void registerBrowserImageBackground(Map, BackgroundUIWrapper> map) { + map.put(ImageBackground.class, BackgroundUIWrapper.create() + .setType(ImageBackgroundPane4Browser.class).setTitle(Inter.getLocText("Image"))); + } + + private static void registerExtra(Map, BackgroundUIWrapper> map) { + for (BackgroundUIProvider provider : ExtraDesignClassManager.getInstance().getBackgroundUIProviders()) { + map.put(provider.targetClass(), BackgroundUIWrapper.create() + .setType(provider.targetUIClass()).setTitle(provider.targetTitle())); + } + } + + + public static Set> kindsOfKey() { + return map.keySet(); + } + + public static BackgroundUIWrapper getWrapper(Class category) { + return map.get(category); + } + + public static BackgroundDetailPane createIfAbsent(Class category) { + BackgroundUIWrapper wrapper = map.get(category); + return createByWrapper(wrapper); + } + + public static BackgroundDetailPane createIfAbsent(int index) { + for (BackgroundUIWrapper wrapper : map.values()) { + if (wrapper.getIndex() == index) { + return createByWrapper(wrapper); + } + } + return new NullBackgroundPane(); + } + + public static Set> browserKindsOfKey() { + return browser.keySet(); + } + + public static BackgroundUIWrapper getBrosweWrapper(Class category) { + return browser.get(category); + } + + public static BackgroundDetailPane createBrowserIfAbsent(Class category) { + BackgroundUIWrapper wrapper = browser.get(category); + return createByWrapper(wrapper); + } + + public static BackgroundDetailPane createBrowerIfAbsent(int index) { + for (BackgroundUIWrapper wrapper : browser.values()) { + if (wrapper.getIndex() == index) { + return createByWrapper(wrapper); + } + } + return new NullBackgroundPane(); + } + + private static BackgroundDetailPane createByWrapper(BackgroundUIWrapper wrapper) { + Class clazz = wrapper.getType(); + if (clazz == null) { + clazz = NullBackgroundPane.class; + } + BackgroundDetailPane quickPane; + try { + quickPane = clazz.newInstance(); + } catch (Exception e) { + quickPane = new NullBackgroundPane(); + } + return quickPane; + } +} diff --git a/designer_base/src/com/fr/design/style/background/BackgroundPane.java b/designer_base/src/com/fr/design/style/background/BackgroundPane.java index 679a9a4a15..6a9c3d70f8 100644 --- a/designer_base/src/com/fr/design/style/background/BackgroundPane.java +++ b/designer_base/src/com/fr/design/style/background/BackgroundPane.java @@ -4,87 +4,32 @@ package com.fr.design.style.background; import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Cursor; import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.GridLayout; -import java.awt.Image; -import java.awt.LayoutManager; -import java.awt.TexturePaint; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.geom.Rectangle2D; -import java.io.File; - -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.ButtonGroup; -import javax.swing.JFileChooser; +import java.util.HashMap; +import java.util.Map; import com.fr.design.gui.frpane.UITabbedPane; -import com.fr.design.gui.ibutton.UIRadioButton; -import com.fr.design.gui.ilable.UILabel; -import javax.swing.JPanel; -import javax.swing.JRadioButton; -import javax.swing.JScrollPane; -import javax.swing.JToggleButton; -import javax.swing.SwingConstants; + import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.EventListenerList; -import com.fr.base.BaseUtils; -import com.fr.base.FRContext; -import com.fr.base.GraphHelper; -import com.fr.base.Style; -import com.fr.base.background.ColorBackground; -import com.fr.base.background.GradientBackground; -import com.fr.base.background.ImageBackground; -import com.fr.base.background.PatternBackground; -import com.fr.base.background.TextureBackground; -import com.fr.design.gui.ibutton.UIButton; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.dialog.BasicPane; import com.fr.general.Background; -import com.fr.general.ComparatorUtils; +import com.fr.general.FRLogger; import com.fr.general.Inter; -import com.fr.stable.Constants; -import com.fr.stable.CoreGraphHelper; -import com.fr.design.style.background.gradient.GradientPane; -import com.fr.design.style.background.image.ImageFileChooser; -import com.fr.design.style.background.image.ImagePreviewPane; -import com.fr.design.style.color.ColorSelectBox; -import com.fr.design.style.color.DetailColorSelectPane; -import com.fr.design.utils.gui.GUICoreUtils; public class BackgroundPane extends BasicPane { - private static final int BACKGROUND_NULL = 0; - private static final int BACKGROUND_COLOR = 1; - private static final int BACKGROUND_TEXTURE = 2; - private static final int BACKGROUND_PATTERN = 3; - private static final int BACKGROUND_IMAGE = 4; - private static final int BACKGROUND_GRADIENT_COLOR = 5; - private UITabbedPane tabbedPane = null; - private NullBackgroundPane nullBackgroundPane = null; - private ColorBackgroundPane colorBackgroundPane = null; - private TextureBackgroundPane textureBackgroundPane = null; - private PatternBackgroundPane patternBackgroundPane = null; - private ImageBackgroundPane imageBackgroundPane = null; - private GradientPane gradientPane = null; + protected UITabbedPane tabbedPane = null; + private EventListenerList eventChangeList = new EventListenerList(); - private static boolean isBrowserBackgroundPane; + protected Map cacheMap = new HashMap<>(); - public BackgroundPane(){ - this(false); - } //需求说: 如果是浏览器背景, 隐藏掉几个button - public BackgroundPane(boolean isBrowserBackgroundPane) { - BackgroundPane.isBrowserBackgroundPane = isBrowserBackgroundPane; + public BackgroundPane() { this.initComponents(); this.setPreferredSize(new Dimension(400, 300)); } @@ -103,16 +48,21 @@ public class BackgroundPane extends BasicPane { tabbedPane = new UITabbedPane(); this.add(tabbedPane, BorderLayout.CENTER); - tabbedPane.addTab(Inter.getLocText("Background-Null"), FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane()); - tabbedPane.addTab(Inter.getLocText("Color"), FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane()); - tabbedPane.addTab(Inter.getLocText("Background-Texture"),FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane()); - tabbedPane.addTab(Inter.getLocText("Background-Pattern"), FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane()); - tabbedPane.addTab(Inter.getLocText("Image"), FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane()); - tabbedPane.addTab(Inter.getLocText("Gradient-Color"), FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane()); + initTabPane(); + tabbedPane.addChangeListener(backgroundChangeListener); tabbedPane.setPreferredSize(new Dimension(200, 210)); } + protected void initTabPane() { + int index = 0; + for (Class key : BackgroundFactory.kindsOfKey()) { + BackgroundUIWrapper wrapper = BackgroundFactory.getWrapper(key); + wrapper.setIndex(index++); + tabbedPane.addTab(Inter.getLocText(wrapper.getTitle()), FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane()); + } + } + public void addChangeListener(ChangeListener changeListener) { eventChangeList.add(ChangeListener.class, changeListener); } @@ -138,86 +88,39 @@ public class BackgroundPane extends BasicPane { return Inter.getLocText("Background"); } - private NullBackgroundPane getNullBackgroundPane() { - if (this.nullBackgroundPane == null) { - this.nullBackgroundPane = new NullBackgroundPane(); - nullBackgroundPane.addChangeListener(backgroundChangeListener); - } - return this.nullBackgroundPane; - } - private ColorBackgroundPane getColorBackgroundPane() { - if (this.colorBackgroundPane == null) { - this.colorBackgroundPane = new ColorBackgroundPane(); - colorBackgroundPane.addChangeListener(backgroundChangeListener); + protected BackgroundDetailPane getTabItemPane(Background background, int index) { + BackgroundDetailPane quickPane = cacheMap.get(index); + if (quickPane == null) { + quickPane = BackgroundFactory.createIfAbsent(background == null ? null : background.getClass()); + quickPane.addChangeListener(backgroundChangeListener); + cacheMap.put(index, quickPane); } - return this.colorBackgroundPane; + tabbedPane.setComponentAt(index, quickPane); + tabbedPane.setSelectedIndex(index); + return quickPane; } - private TextureBackgroundPane getTextureBackgroundPane() { - if (this.textureBackgroundPane == null) { - this.textureBackgroundPane = new TextureBackgroundPane(); - textureBackgroundPane.addChangeListener(backgroundChangeListener); + protected BackgroundDetailPane getTabItemPaneByIndex(int index) { + BackgroundDetailPane quickPane = cacheMap.get(index); + if (quickPane == null) { + quickPane = BackgroundFactory.createIfAbsent(index); + tabbedPane.setComponentAt(index, quickPane); + cacheMap.put(index, quickPane); + quickPane.addChangeListener(backgroundChangeListener); } - return this.textureBackgroundPane; + return quickPane; } - private PatternBackgroundPane getPatternBackgroundPane() { - if (this.patternBackgroundPane == null) { - this.patternBackgroundPane = new PatternBackgroundPane(); - patternBackgroundPane.addChangeListener(backgroundChangeListener); - } - return this.patternBackgroundPane; - } - - private ImageBackgroundPane getImageBackgroundPane() { - if (this.imageBackgroundPane == null) { - this.imageBackgroundPane = new ImageBackgroundPane(); - imageBackgroundPane.addChangeListener(backgroundChangeListener); - } - return this.imageBackgroundPane; - } - - private GradientPane getGradientPane() { - if (this.gradientPane == null) { - this.gradientPane = new GradientPane(); - gradientPane.addChangeListener(backgroundChangeListener); - } - - return this.gradientPane; - } /** * Populate background. */ public void populate(Background background) { - if (background == null) { - tabbedPane.setComponentAt(0, this.getNullBackgroundPane()); - tabbedPane.setSelectedIndex(0); - nullBackgroundPane.populate(background); - } else { - if (background instanceof ColorBackground) { - tabbedPane.setComponentAt(1, this.getColorBackgroundPane()); - tabbedPane.setSelectedIndex(1); - colorBackgroundPane.populate(background); - } else if (background instanceof TextureBackground) { - tabbedPane.setComponentAt(2, this.getTextureBackgroundPane()); - tabbedPane.setSelectedIndex(2); - textureBackgroundPane.populate(background); - } else if (background instanceof PatternBackground) { - tabbedPane.setComponentAt(3, this.getPatternBackgroundPane()); - tabbedPane.setSelectedIndex(3); - patternBackgroundPane.populate(background); - } else if (background instanceof ImageBackground) { - tabbedPane.setComponentAt(4, this.getImageBackgroundPane()); - tabbedPane.setSelectedIndex(4); - imageBackgroundPane.populate(background); - } else if (background instanceof GradientBackground) { - tabbedPane.setComponentAt(5, this.getGradientPane()); - tabbedPane.setSelectedIndex(5); - gradientPane.populate(background); - } - } + BackgroundUIWrapper wrapper = BackgroundFactory.getWrapper(background == null ? null : background.getClass()); + int index = wrapper.getIndex(); + BackgroundDetailPane quickPane = getTabItemPane(background, index); + quickPane.populate(background); tabbedPane.doLayout(); tabbedPane.validate(); @@ -227,42 +130,19 @@ public class BackgroundPane extends BasicPane { * Update background. */ public Background update() { + int index = tabbedPane.getSelectedIndex(); + BackgroundDetailPane quickPane = getTabItemPaneByIndex(index); try { - Component selectComponent = tabbedPane.getSelectedComponent(); - if (selectComponent.getClass() == JPanel.class) {//需要初始化. - int selectedIndex = tabbedPane.getSelectedIndex(); - if (selectedIndex == BACKGROUND_NULL) { - selectComponent = this.getNullBackgroundPane(); - } else if (selectedIndex == BACKGROUND_COLOR) { - selectComponent = this.getColorBackgroundPane(); - } else if (selectedIndex == BACKGROUND_TEXTURE) { - selectComponent = this.getTextureBackgroundPane(); - } else if (selectedIndex == BACKGROUND_PATTERN) { - selectComponent = this.getPatternBackgroundPane(); - } else if (selectedIndex == BACKGROUND_IMAGE) { - selectComponent = this.getImageBackgroundPane(); - } else if (selectedIndex == BACKGROUND_GRADIENT_COLOR) { - selectComponent = this.getGradientPane(); - } - - tabbedPane.setComponentAt(selectedIndex, selectComponent); - } - - if (selectComponent instanceof BackgroundSettingPane) { - return ((BackgroundSettingPane) selectComponent).update(); - } else if (selectComponent instanceof GradientPane) { - return ((GradientPane) selectComponent).update(); - } + return quickPane.update(); } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); + FRLogger.getLogger().error(e.getMessage(), e); } - return null; } /** * Change listener. */ - private ChangeListener backgroundChangeListener = new ChangeListener() { + protected ChangeListener backgroundChangeListener = new ChangeListener() { public void stateChanged(ChangeEvent evt) { previewPane.setBackgroundObject(update()); @@ -271,687 +151,4 @@ public class BackgroundPane extends BasicPane { }; private BackgroundPreviewLabel previewPane = null; - public static abstract class BackgroundSettingPane extends JPanel { - - public abstract void populate(Background background); - - public abstract Background update() throws Exception; - - public abstract void addChangeListener(ChangeListener changeListener); - } - - /** - * Null background pane. - */ - private static class NullBackgroundPane extends BackgroundSettingPane { - - public NullBackgroundPane() { - this.setLayout(FRGUIPaneFactory.createBorderLayout()); - - UILabel centerLabel = new UILabel( - Inter.getLocText("Background-Background_is_NULL") + "..."); - this.add(centerLabel); - centerLabel.setHorizontalAlignment(SwingConstants.CENTER); - centerLabel.setBorder(BorderFactory.createLineBorder(GUICoreUtils.getTitleLineBorderColor())); - } - - public void populate(Background background) { - // do nothing. - } - - public Background update() throws Exception { - return null; - } - - public void addChangeListener(ChangeListener changeListener) { - // do nothing. - } - } - - /** - * Color background pane. - */ - private static class ColorBackgroundPane extends BackgroundSettingPane { - - private DetailColorSelectPane detailColorSelectPane; - - public ColorBackgroundPane() { - this.setLayout(FRGUIPaneFactory.createBorderLayout()); - - detailColorSelectPane = new DetailColorSelectPane(); - this.add(detailColorSelectPane, BorderLayout.CENTER); - } - - public void populate(Background background) { - if (background instanceof ColorBackground) { - ColorBackground colorBackgroud = (ColorBackground) background; - this.detailColorSelectPane.populate(colorBackgroud.getColor()); - } else { - this.detailColorSelectPane.populate(Color.white); - } - } - - public Background update() throws Exception { - return ColorBackground.getInstance(this.detailColorSelectPane.update()); - } - - public void addChangeListener(ChangeListener changeListener) { - detailColorSelectPane.addChangeListener(changeListener); - } - } - - private static abstract class BPane extends BackgroundSettingPane { - BPane(int nColumn) { - this.initComponents(nColumn); - } - - private void initComponents(int nColumn) { - this.setLayout(FRGUIPaneFactory.createBorderLayout()); - this.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); - - JPanel contentPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); - this.add(contentPane, BorderLayout.NORTH); -// contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); - - // type type. - - JPanel typePane=FRGUIPaneFactory.createTitledBorderPane(titleOfTypePane()); - contentPane.add(typePane); - JPanel typePane2 = new JPanel(); - typePane.add(typePane2); - typePane2.setLayout(layoutOfTypePane(nColumn)); - setChildrenOfTypePane(typePane2); - - setChildrenOfContentPane(contentPane); - } - - protected abstract String titleOfTypePane(); - protected abstract LayoutManager layoutOfTypePane(int nColumn); - protected abstract void setChildrenOfTypePane(JPanel typePane2); - protected void setChildrenOfContentPane(JPanel contentPane) {} - } - - /** - * Texture background pane. TODO kunsnat: 拆出去. 真特么的长.. - */ - public static class TextureBackgroundPane extends BPane { - - private TexturePaint texturePaint; - private TextureButton[] textureButtonArray; - - public TextureBackgroundPane() { - super(8);// 默认的. - } - - public TextureBackgroundPane(int colum) { - super(colum);// 自定义的. - } - - protected LayoutManager layoutOfTypePane(int nColumn) { - return FRGUIPaneFactory.createNColumnGridLayout(nColumn); - } - - protected String titleOfTypePane() { - return Inter.getLocText("Background-Texture"); - } - protected void setChildrenOfTypePane(JPanel typePane2) { - ButtonGroup patternButtonGroup = new ButtonGroup(); - textureButtonArray = new TextureButton[EMBED_TEXTURE_PAINT_ARRAY.length]; - for (int i = 0; i < EMBED_TEXTURE_PAINT_ARRAY.length; i++) { - textureButtonArray[i] = new TextureButton( - EMBED_TEXTURE_PAINT_ARRAY[i], EMBED_TEXTURE_PAINT_DES_ARRAY[i]); - patternButtonGroup.add(textureButtonArray[i]); - typePane2.add(textureButtonArray[i]); - } - } - - public void populate(Background background) { - if (background instanceof TextureBackground) { - TextureBackground textureBackground = (TextureBackground) background; - - this.texturePaint = textureBackground.getTexturePaint(); - - for (int i = 0; i < textureButtonArray.length; i++) { - if (ComparatorUtils.equals(textureButtonArray[i].getTexturePaint(), this.texturePaint)) { - textureButtonArray[i].setSelected(true); - break; - } - } - } else { - this.textureButtonArray[0].setSelected(true); - this.texturePaint = textureButtonArray[0].getTexturePaint(); - } - } - - public Background update() throws Exception { - return new TextureBackground(this.texturePaint); - } - - public void addChangeListener(ChangeListener changeListener) { - for (int i = 0; i < this.textureButtonArray.length; i++) { - this.textureButtonArray[i].addChangeListener(changeListener); - } - } - - /** - * Texture type button. - */ - class TextureButton extends JToggleButton implements ActionListener { - - private TexturePaint buttonTexturePaint; - - public TextureButton(TexturePaint buttonTexturePaint, String tooltip) { - this.buttonTexturePaint = buttonTexturePaint; - this.setToolTipText(tooltip); - - this.setCursor(new Cursor(Cursor.HAND_CURSOR)); - this.addActionListener(this); - this.setBorder(null); - } - - public void paintComponent(Graphics g) { - Graphics2D g2d = (Graphics2D) g; - - Dimension d = getSize(); - - g2d.setPaint(this.buttonTexturePaint); - GraphHelper.fill(g2d, new Rectangle2D.Double(0, 0, d.width - 1, - d.height - 1)); - - if (ComparatorUtils.equals(texturePaint, this.buttonTexturePaint)) {// it's - // selected. - g2d.setPaint(Color.black); - } else { - g2d.setPaint(Color.gray); - } - GraphHelper.draw(g2d, new Rectangle2D.Double(0, 0, d.width - 1, - d.height - 1)); - } - - public Dimension getPreferredSize() { - return new Dimension(36, 32); - } - - public TexturePaint getTexturePaint() { - return this.buttonTexturePaint; - } - - /** - * set Pattern index. - */ - public void actionPerformed(ActionEvent evt) { - TextureBackgroundPane.this.texturePaint = this.getTexturePaint(); - - fireChagneListener(); - TextureBackgroundPane.this.repaint(); // repaint. - } - - public void addChangeListener(ChangeListener changeListener) { - this.changeListener = changeListener; - } - - private void fireChagneListener() { - if (this.changeListener != null) { - ChangeEvent evt = new ChangeEvent(this); - this.changeListener.stateChanged(evt); - } - } - } - } - - public static class PatternBackgroundPaneNoFore extends PatternBackgroundPane { - - public PatternBackgroundPaneNoFore(int nColumn) { - super(nColumn); - } - - // 重载 不加载两个前后按钮 - protected void setChildrenOfContentPane(JPanel contentPane) { - foregroundColorPane = new ColorSelectBox(80); - backgroundColorPane = new ColorSelectBox(80); - foregroundColorPane.setSelectObject(Color.lightGray); - backgroundColorPane.setSelectObject(Color.black); - } - } - - /** - * Pattern background pane. - */ - public static class PatternBackgroundPane extends BPane { - - private int patternIndex = 0; // pattern index. - protected ColorSelectBox foregroundColorPane; - protected ColorSelectBox backgroundColorPane; - private PatternButton[] patternButtonArray; - - public PatternBackgroundPane() { - super(12); - - foregroundColorPane.addSelectChangeListener(colorChangeListener); - backgroundColorPane.addSelectChangeListener(colorChangeListener); - } - - public PatternBackgroundPane(int nColumn) { - super(nColumn); - - if(foregroundColorPane != null) { - foregroundColorPane.addSelectChangeListener(colorChangeListener); - } - if(backgroundColorPane != null) { - backgroundColorPane.addSelectChangeListener(colorChangeListener); - } - } - - protected String titleOfTypePane() { - return Inter.getLocText("Background-Pattern"); - } - protected LayoutManager layoutOfTypePane(int nColumn) { - return FRGUIPaneFactory.createNColumnGridLayout(nColumn); - } - - protected void setChildrenOfTypePane(JPanel typePane2) { - ButtonGroup patternButtonGroup = new ButtonGroup(); - patternButtonArray = new PatternButton[PatternBackground.PATTERN_COUNT]; - for (int i = 0; i < PatternBackground.PATTERN_COUNT; i++) { - patternButtonArray[i] = new PatternButton(i); - patternButtonGroup.add(patternButtonArray[i]); - typePane2.add(patternButtonArray[i]); - } - } - - protected void setChildrenOfContentPane(JPanel contentPane) { - // colors - JPanel colorPane = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("Colors")); - contentPane.add(colorPane); - - foregroundColorPane = new ColorSelectBox(80); - backgroundColorPane = new ColorSelectBox(80); - foregroundColorPane.setSelectObject(Color.lightGray); - backgroundColorPane.setSelectObject(Color.black); - - colorPane.add(Box.createHorizontalStrut(2)); - colorPane.add(this.createLabelColorPane(Inter.getLocText("Foreground") - + ":", foregroundColorPane)); - - colorPane.add(Box.createHorizontalStrut(8)); - - colorPane.add(this.createLabelColorPane(Inter.getLocText("Background") - + ":", backgroundColorPane)); - } - - private JPanel createLabelColorPane(String text, - ColorSelectBox colorPane) { - JPanel labelColorPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); - labelColorPane.add(new UILabel(text)); - labelColorPane.add(colorPane); - - return labelColorPane; - } - - public void populate(Background background) { - if (background != null && background instanceof PatternBackground) { - PatternBackground patternBackground = (PatternBackground) background; - int patternIndex = patternBackground.getPatternIndex(); - - if (patternIndex >= 0 - && patternIndex < this.patternButtonArray.length) { - this.patternButtonArray[patternIndex].setSelected(true); - this.patternIndex = patternIndex; - } else { - this.patternIndex = 0; - } - - foregroundColorPane.setSelectObject(patternBackground.getForeground()); - backgroundColorPane.setSelectObject(patternBackground.getBackground()); - } else { - patternIndex = 0; - this.patternButtonArray[0].setSelected(true); - - foregroundColorPane.setSelectObject(Color.lightGray); - backgroundColorPane.setSelectObject(Color.black); - } - } - - public Background update() throws Exception { - return new PatternBackground(patternIndex, foregroundColorPane.getSelectObject(), backgroundColorPane.getSelectObject()); - } - - public void addChangeListener(ChangeListener changeListener) { - foregroundColorPane.addSelectChangeListener(changeListener); - backgroundColorPane.addSelectChangeListener(changeListener); - - for (int i = 0; i < this.patternButtonArray.length; i++) { - this.patternButtonArray[i].addChangeListener(changeListener); - } - } - // Foreground or Background changed. - ChangeListener colorChangeListener = new ChangeListener() { - - public void stateChanged(ChangeEvent e) { - for (int i = 0; i < patternButtonArray.length; i++) { - patternButtonArray[i].setPatternForeground(foregroundColorPane.getSelectObject()); - patternButtonArray[i].setPatternBackground(backgroundColorPane.getSelectObject()); - } - - PatternBackgroundPane.this.repaint();// repaint - } - }; - - /** - * Pattern type button. - */ - class PatternButton extends JToggleButton implements ActionListener { - - public PatternButton(int pIndex) { - this.pIndex = pIndex; - this.addActionListener(this); - - this.setCursor(new Cursor(Cursor.HAND_CURSOR)); - this.setBorder(null); - this.patternBackground = new PatternBackground(this.pIndex, - Color.lightGray, Color.black); - } - - public void paintComponent(Graphics g) { - Graphics2D g2d = (Graphics2D) g; - - Dimension d = getSize(); - this.patternBackground.paint(g2d, new Rectangle2D.Double(0, 0, - d.width - 1, d.height - 1)); - - if (this.pIndex == patternIndex) {// it's selected. - g2d.setPaint(new Color(255, 51, 0)); - } else { - g2d.setPaint(Color.gray); - } - GraphHelper.draw(g2d, new Rectangle2D.Double(0, 0, d.width - 1, - d.height - 1)); - } - - public Dimension getPreferredSize() { - return new Dimension(24, 24); - } - - public void setPatternForeground(Color foreground) { - this.patternBackground.setForeground(foreground); - } - - public void setPatternBackground(Color background) { - this.patternBackground.setBackground(background); - } - - /** - * set Pattern index. - */ - public void actionPerformed(ActionEvent evt) { - PatternBackgroundPane.this.patternIndex = pIndex; - - fireChagneListener(); - PatternBackgroundPane.this.repaint();// repaint - } - - public void addChangeListener(ChangeListener changeListener) { - this.changeListener = changeListener; - } - - private void fireChagneListener() { - if (this.changeListener != null) { - ChangeEvent evt = new ChangeEvent(this); - this.changeListener.stateChanged(evt); - } - } - private int pIndex = 0; - private PatternBackground patternBackground; - } - } - - /** - * Image background pane. - */ - private static class ImageBackgroundPane extends BackgroundSettingPane { - - private ImagePreviewPane previewPane = null; - private Style imageStyle = null; - private ChangeListener changeListener = null; - private ImageFileChooser imageFileChooser = null; - private UILabel imageSizeLabel = new UILabel(); - - private JRadioButton defaultRadioButton = null; - private JRadioButton tiledRadioButton = null; - private JRadioButton extendRadioButton = null; - private JRadioButton adjustRadioButton = null; - - public ImageBackgroundPane() { - this.setLayout(FRGUIPaneFactory.createBorderLayout()); - - // preview pane - JPanel previewContainerPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); - this.add(previewContainerPane, BorderLayout.CENTER); - - JPanel previewOwnerPane = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("Preview")); - previewOwnerPane.setLayout(new BorderLayout()); - previewContainerPane.add(previewOwnerPane, BorderLayout.CENTER); - - - previewPane = new ImagePreviewPane(); - previewOwnerPane.add(new JScrollPane(previewPane)); - previewPane.addChangeListener(imageSizeChangeListener); - - JPanel selectFilePane = FRGUIPaneFactory.createBorderLayout_L_Pane(); - previewContainerPane.add(selectFilePane, BorderLayout.EAST); - selectFilePane.setBorder(BorderFactory.createEmptyBorder(8, 2, 4, 0)); - - UIButton selectPictureButton = new UIButton( - Inter.getLocText("Image-Select_Picture")); - selectFilePane.add(selectPictureButton, BorderLayout.NORTH); - selectPictureButton.setMnemonic('S'); - selectPictureButton.addActionListener(selectPictureActionListener); - JPanel layoutPane=FRGUIPaneFactory.createMediumHGapHighTopFlowInnerContainer_M_Pane(); - selectFilePane.add(layoutPane, BorderLayout.CENTER); - - //布局 - defaultRadioButton = new UIRadioButton(Inter.getLocText("Default")); - tiledRadioButton = new UIRadioButton(Inter.getLocText("Image-Titled")); - extendRadioButton = new UIRadioButton(Inter.getLocText("Image-Extend")); - adjustRadioButton = new UIRadioButton(Inter.getLocText("Image-Adjust")); - - defaultRadioButton.addActionListener(layoutActionListener); - tiledRadioButton.addActionListener(layoutActionListener); - extendRadioButton.addActionListener(layoutActionListener); - adjustRadioButton.addActionListener(layoutActionListener); - - JPanel jp = new JPanel(new GridLayout(4, 1, 15, 15)); - jp.add(defaultRadioButton); - jp.add(tiledRadioButton); - if(!isBrowserBackgroundPane){ - jp.add(extendRadioButton); - jp.add(adjustRadioButton); - } - layoutPane.add(jp); - - ButtonGroup layoutBG = new ButtonGroup(); - layoutBG.add(defaultRadioButton); - layoutBG.add(tiledRadioButton); - layoutBG.add(extendRadioButton); - layoutBG.add(adjustRadioButton); - - defaultRadioButton.setSelected(true); - - // init image file chooser. - imageFileChooser = new ImageFileChooser(); - imageFileChooser.setMultiSelectionEnabled(false); - } - /** - * Select picture. - */ - ActionListener selectPictureActionListener = new ActionListener() { - - public void actionPerformed(ActionEvent evt) { - int returnVal = imageFileChooser.showOpenDialog(ImageBackgroundPane.this); - if (returnVal != JFileChooser.CANCEL_OPTION) { - File selectedFile = imageFileChooser.getSelectedFile(); - - if (selectedFile != null && selectedFile.isFile()) { - Image image = BaseUtils.readImage(selectedFile.getPath()); - CoreGraphHelper.waitForImage(image); - - previewPane.setImage(image); - setImageStyle(); - previewPane.setImageStyle(imageStyle); - previewPane.repaint(); - } else { - previewPane.setImage(null); - } - } - - fireChagneListener(); - } - }; - - private void setImageStyle(){ - if(tiledRadioButton.isSelected()){ - imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_TILED); - }else if(adjustRadioButton.isSelected()){ - imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_ADJUST); - }else if(extendRadioButton.isSelected()){ - imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_EXTEND); - }else{ - imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_CENTER); - } - } - - ActionListener layoutActionListener = new ActionListener() { - - public void actionPerformed(ActionEvent evt) { - setImageStyle(); - changeImageStyle(); - } - - private void changeImageStyle() { - previewPane.setImageStyle(ImageBackgroundPane.this.imageStyle); - previewPane.repaint(); - } - }; - - public void populate(Background background) { - - if (background instanceof ImageBackground) { - ImageBackground imageBackground = (ImageBackground) background; - - if (imageBackground.getLayout() == Constants.IMAGE_CENTER) { - defaultRadioButton.setSelected(true); - imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_CENTER); - }else if(imageBackground.getLayout() == Constants.IMAGE_EXTEND){ - extendRadioButton.setSelected(true); - imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_EXTEND); - }else if(imageBackground.getLayout() == Constants.IMAGE_ADJUST){ - adjustRadioButton.setSelected(true); - imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_ADJUST); - }else { - tiledRadioButton.setSelected(true); - imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_TILED); - } - - previewPane.setImageStyle(ImageBackgroundPane.this.imageStyle); - if (imageBackground.getImage() != null) { - previewPane.setImage(imageBackground.getImage()); - imageSizeLabel.setText(previewPane.getImage().getWidth(null) - + " X " + previewPane.getImage().getHeight(null)); - } - - if (imageBackground.getImage() != null) { - previewPane.setImage(imageBackground.getImage()); - } - } else { - previewPane.setImage(null); - tiledRadioButton.setSelected(true); - - imageSizeLabel.setText(""); - } - - fireChagneListener(); - } - - public Background update() throws Exception { - ImageBackground imageBackground = new ImageBackground(previewPane.getImage()); - setImageStyle(); - imageBackground.setLayout(imageStyle.getImageLayout()); - return imageBackground; - } - - public void addChangeListener(ChangeListener changeListener) { - this.changeListener = changeListener; - } - - private void fireChagneListener() { - if (this.changeListener != null) { - ChangeEvent evt = new ChangeEvent(this); - this.changeListener.stateChanged(evt); - } - } - ChangeListener imageSizeChangeListener = new ChangeListener() { - - public void stateChanged(ChangeEvent evt) { - Image image = ((ImagePreviewPane) evt.getSource()).getImage(); - - if (image == null) { - imageSizeLabel.setText(""); - } else { - imageSizeLabel.setText(Inter.getLocText(new String[] {"Size", "px"}, new String[] {": " + image.getWidth(null) + "x" + image.getHeight(null)})); - } - } - }; - } - - public static final TexturePaint[] EMBED_TEXTURE_PAINT_ARRAY = new TexturePaint[]{ - TextureBackground.NEWSPRINT_TEXTURE_PAINT, - TextureBackground.RECYCLED_PAPER_TEXTURE_PAINT, - TextureBackground.PARCHMENT_TEXTURE_PAINT, - TextureBackground.STATIONERY_TEXTURE_PAINT, - TextureBackground.GREEN_MARBLE_TEXTURE_PAINT, - TextureBackground.WHITE_MARBLE_TEXTURE_PAINT, - TextureBackground.BROWN_MARBLE_TEXTURE_PAINT, - TextureBackground.GRANITE_TEXTURE_PAINT, - TextureBackground.BLUE_TISSUE_PAPER_TEXTURE_PAINT, - TextureBackground.PINK_TISSUE_PAPER_TEXTURE_PAINT, - TextureBackground.PURPLE_MESH_TEXTURE_PAINT, - TextureBackground.BOUQUET_TEXTURE_PAINT, - TextureBackground.PAPYRUS_TEXTURE_PAINT, - TextureBackground.CANVAS_TEXTURE_PAINT, - TextureBackground.DENIM_TEXTURE_PAINT, - TextureBackground.WOVEN_MAT_TEXTURE_PAINT, - TextureBackground.WATER_DROPLETS_TEXTURE_PAINT, - TextureBackground.PAPER_BAG_TEXTURE_PAINT, - TextureBackground.FISH_FOSSIL_TEXTURE_PAINT, - TextureBackground.SAND_TEXTURE_PAINT, - TextureBackground.CORK_TEXTURE_PAINT, - TextureBackground.WALNUT_TEXTURE_PAINT, - TextureBackground.OAK_TEXTURE_PAINT, - TextureBackground.MEDIUM_WOOD_TEXTURE_PAINT}; - private static final String[] EMBED_TEXTURE_PAINT_DES_ARRAY = new String[]{ - Inter.getLocText("BackgroundTexture-Newsprint"), - Inter.getLocText("BackgroundTexture-RecycledPaper"), - Inter.getLocText("BackgroundTexture-Parchment"), - Inter.getLocText("BackgroundTexture-Stationery"), - Inter.getLocText("BackgroundTexture-GreenMarble"), - Inter.getLocText("BackgroundTexture-WhiteMarble"), - Inter.getLocText("BackgroundTexture-BrownMarble"), - Inter.getLocText("BackgroundTexture-Granite"), - Inter.getLocText("BackgroundTexture-BlueTissuePaper"), - Inter.getLocText("BackgroundTexture-PinkTissuePaper"), - Inter.getLocText("BackgroundTexture-PurpleMesh"), - Inter.getLocText("BackgroundTexture-Bouquet"), - Inter.getLocText("BackgroundTexture-Papyrus"), - Inter.getLocText("BackgroundTexture-Canvas"), - Inter.getLocText("BackgroundTexture-Denim"), - Inter.getLocText("BackgroundTexture-WovenMat"), - Inter.getLocText("BackgroundTexture-WaterDroplets"), - Inter.getLocText("BackgroundTexture-PaperBag"), - Inter.getLocText("BackgroundTexture-FishFossil"), - Inter.getLocText("BackgroundTexture-Sand"), - Inter.getLocText("BackgroundTexture-Cork"), - Inter.getLocText("BackgroundTexture-Walnut"), - Inter.getLocText("BackgroundTexture-Oak"), - Inter.getLocText("BackgroundTexture-MediumWood") - }; } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/style/background/BackgroundPane4Browser.java b/designer_base/src/com/fr/design/style/background/BackgroundPane4Browser.java new file mode 100644 index 0000000000..490cb82e49 --- /dev/null +++ b/designer_base/src/com/fr/design/style/background/BackgroundPane4Browser.java @@ -0,0 +1,47 @@ +package com.fr.design.style.background; + +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.general.Background; +import com.fr.general.Inter; + +/** + * Created by richie on 16/5/18. + */ +public class BackgroundPane4Browser extends BackgroundPane { + + public BackgroundPane4Browser() { + super(); + } + + protected void initTabPane() { + int index = 0; + for (Class key : BackgroundFactory.browserKindsOfKey()) { + BackgroundUIWrapper wrapper = BackgroundFactory.getWrapper(key); + wrapper.setIndex(index++); + tabbedPane.addTab(Inter.getLocText(wrapper.getTitle()), FRGUIPaneFactory.createY_AXISBoxInnerContainer_L_Pane()); + } + } + + protected BackgroundDetailPane getTabItemPane(Background background, int index) { + BackgroundDetailPane quickPane = cacheMap.get(index); + if (quickPane == null) { + quickPane = BackgroundFactory.createBrowserIfAbsent(background == null ? null : background.getClass()); + quickPane.addChangeListener(backgroundChangeListener); + cacheMap.put(index, quickPane); + } + tabbedPane.setComponentAt(index, quickPane); + tabbedPane.setSelectedIndex(index); + return quickPane; + } + + protected BackgroundDetailPane getTabItemPaneByIndex(int index) { + BackgroundDetailPane quickPane = cacheMap.get(index); + if (quickPane == null) { + quickPane = BackgroundFactory.createBrowerIfAbsent(index); + tabbedPane.setComponentAt(index, quickPane); + cacheMap.put(index, quickPane); + quickPane.addChangeListener(backgroundChangeListener); + } + return quickPane; + } +} diff --git a/designer_base/src/com/fr/design/style/background/BackgroundSelectPane.java b/designer_base/src/com/fr/design/style/background/BackgroundSelectPane.java index 0dc68a8a2b..1262d2ab4e 100644 --- a/designer_base/src/com/fr/design/style/background/BackgroundSelectPane.java +++ b/designer_base/src/com/fr/design/style/background/BackgroundSelectPane.java @@ -13,7 +13,6 @@ import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.dialog.BasicPane; import com.fr.general.Background; import com.fr.general.Inter; -import com.fr.design.style.background.BackgroundPane.BackgroundSettingPane; /** * @author kunsnat E-mail:kunsnat@gmail.com @@ -26,9 +25,9 @@ public abstract class BackgroundSelectPane extends BasicPane { private Background background; private ArrayList listenerList = new ArrayList(); - public abstract BackgroundSettingPane getShowPane(double preWidth); + public abstract BackgroundDetailPane getShowPane(double preWidth); - protected void initBackgroundShowPane(final BackgroundSettingPane backgroundPane) { + protected void initBackgroundShowPane(final BackgroundDetailPane backgroundPane) { this.setLayout(FRGUIPaneFactory.createBorderLayout()); backgroundPane.addChangeListener(new ChangeListener() { diff --git a/designer_base/src/com/fr/design/style/background/BackgroundUIWrapper.java b/designer_base/src/com/fr/design/style/background/BackgroundUIWrapper.java new file mode 100644 index 0000000000..9502674a36 --- /dev/null +++ b/designer_base/src/com/fr/design/style/background/BackgroundUIWrapper.java @@ -0,0 +1,49 @@ +package com.fr.design.style.background; + +/** + * Created by richie on 16/5/18. + */ +public class BackgroundUIWrapper { + + public static BackgroundUIWrapper create() { + return new BackgroundUIWrapper(); + } + + private int index = -1; + private String title; + private Class clazz; + + private BackgroundUIWrapper() { + + } + + public Class getType() { + return clazz; + } + + public BackgroundUIWrapper setType(Class clazz) { + this.clazz = clazz; + return this; + } + + public String getTitle() { + return title; + } + + public BackgroundUIWrapper setTitle(String title) { + this.title = title; + return this; + } + + public int getIndex() { + return index; + } + + + public BackgroundUIWrapper setIndex(int index) { + if (this.index == -1) { + this.index = index; + } + return this; + } +} diff --git a/designer_base/src/com/fr/design/style/background/gradient/GradientPane.java b/designer_base/src/com/fr/design/style/background/gradient/GradientBackgroundPane.java similarity index 93% rename from designer_base/src/com/fr/design/style/background/gradient/GradientPane.java rename to designer_base/src/com/fr/design/style/background/gradient/GradientBackgroundPane.java index 232b7e225e..9ab11eb147 100644 --- a/designer_base/src/com/fr/design/style/background/gradient/GradientPane.java +++ b/designer_base/src/com/fr/design/style/background/gradient/GradientBackgroundPane.java @@ -1,135 +1,135 @@ -package com.fr.design.style.background.gradient; - -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.ButtonGroup; - -import com.fr.design.gui.ibutton.UIRadioButton; -import com.fr.design.gui.ilable.UILabel; -import javax.swing.JPanel; -import javax.swing.SwingConstants; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; - -import com.fr.base.background.GradientBackground; -import com.fr.design.layout.FRGUIPaneFactory; -import com.fr.general.Background; -import com.fr.general.Inter; -import com.fr.design.style.background.BackgroundPane.BackgroundSettingPane; - -/** - * 渐变色的面板,不是很pp,面板应用显得繁琐,有写可以写成控件类型,比如色彩选择的。。,可以做得花哨点 - * @author ben - */ -public class GradientPane extends BackgroundSettingPane { - private static final long serialVersionUID = -6854603990673031897L; - - private UIRadioButton left2right, top2bottom; - private GradientBar gradientBar; - private ChangeListener changeListener = null; - - public GradientPane() { - - // bug 5452 简化GradientPane - JPanel jpanel = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText(new String[]{"Gradient-Color", "Set"})); - jpanel.setPreferredSize(new Dimension(450, 320)); - jpanel.setLayout(new BorderLayout()); - - // neil:增加渐变色拖动条 - JPanel gradientPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); - JPanel blankJp = new JPanel(); - gradientBar = new GradientBar(4, 254); - blankJp.add(gradientBar); - UILabel jl = new UILabel(Inter.getLocText("Drag_to_select_gradient")); - jl.setHorizontalAlignment(SwingConstants.CENTER); - gradientPanel.add(jl, BorderLayout.NORTH); - gradientPanel.add(blankJp, BorderLayout.SOUTH); - jpanel.add(gradientPanel, BorderLayout.NORTH); - - JPanel centerPane = FRGUIPaneFactory.createNormalFlowInnerContainer_M_Pane(); - JPanel innercenterPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); - centerPane.add(new UILabel(" ")); - centerPane.add(innercenterPane); - innercenterPane.add(new UILabel(Inter.getLocText("Gradient-Direction") + ":")); - - left2right = new UIRadioButton(Inter.getLocText("PageSetup-Landscape")); - innercenterPane.add(left2right); - left2right.setSelected(true); - left2right.addActionListener(reviewListener); - - top2bottom = new UIRadioButton(Inter.getLocText("PageSetup-Portrait")); - innercenterPane.add(top2bottom); - top2bottom.addActionListener(reviewListener); - - ButtonGroup toggle = new ButtonGroup(); - toggle.add(left2right); - toggle.add(top2bottom); - jpanel.add(centerPane, BorderLayout.CENTER); - - this.add(jpanel); - } - - - public void populate(Background background) { - if (!(background instanceof GradientBackground)) { - return; - } - GradientBackground bg = (GradientBackground) background; - this.gradientBar.getSelectColorPointBtnP1().setColorInner(bg.getStartColor()); - this.gradientBar.getSelectColorPointBtnP2().setColorInner(bg.getEndColor()); - if (bg.getDirection() == GradientBackground.LEFT2RIGHT) { - left2right.setSelected(true); - } else { - top2bottom.setSelected(true); - } - if (bg.isUseCell()) { - return; - } - double startValue = (double) bg.getBeginPlace(); - double endValue = (double) bg.getFinishPlace(); - gradientBar.setStartValue(startValue); - gradientBar.setEndValue(endValue); - this.gradientBar.repaint(); - } - - public GradientBackground update() { - GradientBackground gb = new GradientBackground( - gradientBar.getSelectColorPointBtnP1().getColorInner(), - gradientBar.getSelectColorPointBtnP2().getColorInner()); - if (left2right.isSelected()) { - gb.setDirection(GradientBackground.LEFT2RIGHT); - } else { - gb.setDirection(GradientBackground.TOP2BOTTOM); - } - if (gradientBar.isOriginalPlace()) { - gb.setUseCell(true); - } else { - gb.setUseCell(false); - gb.setBeginPlace((float) gradientBar.getStartValue()); - gb.setFinishPlace((float) gradientBar.getEndValue()); - } - return gb; - } - - - ActionListener reviewListener = new ActionListener() { - public void actionPerformed(ActionEvent e) { - fireChagneListener(); - } - }; - - public void addChangeListener(ChangeListener changeListener) { - this.changeListener = changeListener; - gradientBar.addChangeListener(changeListener); - } - - public void fireChagneListener() { - if (this.changeListener != null) { - ChangeEvent evt = new ChangeEvent(this); - this.changeListener.stateChanged(evt); - } - } +package com.fr.design.style.background.gradient; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.ButtonGroup; + +import com.fr.design.gui.ibutton.UIRadioButton; +import com.fr.design.gui.ilable.UILabel; +import javax.swing.JPanel; +import javax.swing.SwingConstants; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import com.fr.base.background.GradientBackground; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.general.Background; +import com.fr.general.Inter; +import com.fr.design.style.background.BackgroundDetailPane; + +/** + * 渐变色的面板,不是很pp,面板应用显得繁琐,有写可以写成控件类型,比如色彩选择的。。,可以做得花哨点 + * @author ben + */ +public class GradientBackgroundPane extends BackgroundDetailPane { + private static final long serialVersionUID = -6854603990673031897L; + + private UIRadioButton left2right, top2bottom; + private GradientBar gradientBar; + private ChangeListener changeListener = null; + + public GradientBackgroundPane() { + + // bug 5452 简化GradientPane + JPanel jpanel = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText(new String[]{"Gradient-Color", "Set"})); + jpanel.setPreferredSize(new Dimension(450, 320)); + jpanel.setLayout(new BorderLayout()); + + // neil:增加渐变色拖动条 + JPanel gradientPanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); + JPanel blankJp = new JPanel(); + gradientBar = new GradientBar(4, 254); + blankJp.add(gradientBar); + UILabel jl = new UILabel(Inter.getLocText("Drag_to_select_gradient")); + jl.setHorizontalAlignment(SwingConstants.CENTER); + gradientPanel.add(jl, BorderLayout.NORTH); + gradientPanel.add(blankJp, BorderLayout.SOUTH); + jpanel.add(gradientPanel, BorderLayout.NORTH); + + JPanel centerPane = FRGUIPaneFactory.createNormalFlowInnerContainer_M_Pane(); + JPanel innercenterPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + centerPane.add(new UILabel(" ")); + centerPane.add(innercenterPane); + innercenterPane.add(new UILabel(Inter.getLocText("Gradient-Direction") + ":")); + + left2right = new UIRadioButton(Inter.getLocText("PageSetup-Landscape")); + innercenterPane.add(left2right); + left2right.setSelected(true); + left2right.addActionListener(reviewListener); + + top2bottom = new UIRadioButton(Inter.getLocText("PageSetup-Portrait")); + innercenterPane.add(top2bottom); + top2bottom.addActionListener(reviewListener); + + ButtonGroup toggle = new ButtonGroup(); + toggle.add(left2right); + toggle.add(top2bottom); + jpanel.add(centerPane, BorderLayout.CENTER); + + this.add(jpanel); + } + + + public void populate(Background background) { + if (!(background instanceof GradientBackground)) { + return; + } + GradientBackground bg = (GradientBackground) background; + this.gradientBar.getSelectColorPointBtnP1().setColorInner(bg.getStartColor()); + this.gradientBar.getSelectColorPointBtnP2().setColorInner(bg.getEndColor()); + if (bg.getDirection() == GradientBackground.LEFT2RIGHT) { + left2right.setSelected(true); + } else { + top2bottom.setSelected(true); + } + if (bg.isUseCell()) { + return; + } + double startValue = (double) bg.getBeginPlace(); + double endValue = (double) bg.getFinishPlace(); + gradientBar.setStartValue(startValue); + gradientBar.setEndValue(endValue); + this.gradientBar.repaint(); + } + + public GradientBackground update() { + GradientBackground gb = new GradientBackground( + gradientBar.getSelectColorPointBtnP1().getColorInner(), + gradientBar.getSelectColorPointBtnP2().getColorInner()); + if (left2right.isSelected()) { + gb.setDirection(GradientBackground.LEFT2RIGHT); + } else { + gb.setDirection(GradientBackground.TOP2BOTTOM); + } + if (gradientBar.isOriginalPlace()) { + gb.setUseCell(true); + } else { + gb.setUseCell(false); + gb.setBeginPlace((float) gradientBar.getStartValue()); + gb.setFinishPlace((float) gradientBar.getEndValue()); + } + return gb; + } + + + ActionListener reviewListener = new ActionListener() { + public void actionPerformed(ActionEvent e) { + fireChagneListener(); + } + }; + + public void addChangeListener(ChangeListener changeListener) { + this.changeListener = changeListener; + gradientBar.addChangeListener(changeListener); + } + + public void fireChagneListener() { + if (this.changeListener != null) { + ChangeEvent evt = new ChangeEvent(this); + this.changeListener.stateChanged(evt); + } + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/style/background/impl/BPane.java b/designer_base/src/com/fr/design/style/background/impl/BPane.java new file mode 100644 index 0000000000..9a9805a5cd --- /dev/null +++ b/designer_base/src/com/fr/design/style/background/impl/BPane.java @@ -0,0 +1,46 @@ +package com.fr.design.style.background.impl; + +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.style.background.BackgroundDetailPane; + +import javax.swing.*; +import java.awt.*; + +/** + * Created by richie on 16/5/18. + */ +public abstract class BPane extends BackgroundDetailPane { + + public BPane(int nColumn) { + this.initComponents(nColumn); + } + + private void initComponents(int nColumn) { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + this.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); + + JPanel contentPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); + this.add(contentPane, BorderLayout.NORTH); +// contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); + + // type type. + + JPanel typePane = FRGUIPaneFactory.createTitledBorderPane(titleOfTypePane()); + contentPane.add(typePane); + JPanel typePane2 = new JPanel(); + typePane.add(typePane2); + typePane2.setLayout(layoutOfTypePane(nColumn)); + setChildrenOfTypePane(typePane2); + + setChildrenOfContentPane(contentPane); + } + + protected abstract String titleOfTypePane(); + + protected abstract LayoutManager layoutOfTypePane(int nColumn); + + protected abstract void setChildrenOfTypePane(JPanel typePane2); + + protected void setChildrenOfContentPane(JPanel contentPane) { + } +} diff --git a/designer_base/src/com/fr/design/style/background/impl/ColorBackgroundPane.java b/designer_base/src/com/fr/design/style/background/impl/ColorBackgroundPane.java new file mode 100644 index 0000000000..effbe6328c --- /dev/null +++ b/designer_base/src/com/fr/design/style/background/impl/ColorBackgroundPane.java @@ -0,0 +1,42 @@ +package com.fr.design.style.background.impl; + +import com.fr.base.background.ColorBackground; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.style.background.BackgroundDetailPane; +import com.fr.design.style.color.DetailColorSelectPane; +import com.fr.general.Background; + +import javax.swing.event.ChangeListener; +import java.awt.*; + +/** + * Color background pane. + */ +public class ColorBackgroundPane extends BackgroundDetailPane { + + private DetailColorSelectPane detailColorSelectPane; + + public ColorBackgroundPane() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + + detailColorSelectPane = new DetailColorSelectPane(); + this.add(detailColorSelectPane, BorderLayout.CENTER); + } + + public void populate(Background background) { + if (background instanceof ColorBackground) { + ColorBackground colorBackgroud = (ColorBackground) background; + this.detailColorSelectPane.populate(colorBackgroud.getColor()); + } else { + this.detailColorSelectPane.populate(Color.white); + } + } + + public Background update() throws Exception { + return ColorBackground.getInstance(this.detailColorSelectPane.update()); + } + + public void addChangeListener(ChangeListener changeListener) { + detailColorSelectPane.addChangeListener(changeListener); + } +} diff --git a/designer_base/src/com/fr/design/style/background/impl/ImageBackgroundPane.java b/designer_base/src/com/fr/design/style/background/impl/ImageBackgroundPane.java new file mode 100644 index 0000000000..62ad05485f --- /dev/null +++ b/designer_base/src/com/fr/design/style/background/impl/ImageBackgroundPane.java @@ -0,0 +1,230 @@ +package com.fr.design.style.background.impl; + +import com.fr.base.BaseUtils; +import com.fr.base.Style; +import com.fr.base.background.ImageBackground; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ibutton.UIRadioButton; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.style.background.BackgroundDetailPane; +import com.fr.design.style.background.image.ImageFileChooser; +import com.fr.design.style.background.image.ImagePreviewPane; +import com.fr.general.Background; +import com.fr.general.Inter; +import com.fr.stable.Constants; +import com.fr.stable.CoreGraphHelper; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; + +/** + * Image background pane. + */ +public class ImageBackgroundPane extends BackgroundDetailPane { + + private ImagePreviewPane previewPane = null; + private Style imageStyle = null; + private ChangeListener changeListener = null; + private ImageFileChooser imageFileChooser = null; + private UILabel imageSizeLabel = new UILabel(); + + protected JRadioButton defaultRadioButton = null; + protected JRadioButton tiledRadioButton = null; + private JRadioButton extendRadioButton = null; + private JRadioButton adjustRadioButton = null; + + public ImageBackgroundPane() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + + // preview pane + JPanel previewContainerPane = FRGUIPaneFactory.createBorderLayout_L_Pane(); + this.add(previewContainerPane, BorderLayout.CENTER); + + JPanel previewOwnerPane = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("Preview")); + previewOwnerPane.setLayout(new BorderLayout()); + previewContainerPane.add(previewOwnerPane, BorderLayout.CENTER); + + + previewPane = new ImagePreviewPane(); + previewOwnerPane.add(new JScrollPane(previewPane)); + previewPane.addChangeListener(imageSizeChangeListener); + + JPanel selectFilePane = FRGUIPaneFactory.createBorderLayout_L_Pane(); + previewContainerPane.add(selectFilePane, BorderLayout.EAST); + selectFilePane.setBorder(BorderFactory.createEmptyBorder(8, 2, 4, 0)); + + UIButton selectPictureButton = new UIButton( + Inter.getLocText("Image-Select_Picture")); + selectFilePane.add(selectPictureButton, BorderLayout.NORTH); + selectPictureButton.setMnemonic('S'); + selectPictureButton.addActionListener(selectPictureActionListener); + JPanel layoutPane = FRGUIPaneFactory.createMediumHGapHighTopFlowInnerContainer_M_Pane(); + selectFilePane.add(layoutPane, BorderLayout.CENTER); + + //布局 + defaultRadioButton = new UIRadioButton(Inter.getLocText("Default")); + tiledRadioButton = new UIRadioButton(Inter.getLocText("Image-Titled")); + extendRadioButton = new UIRadioButton(Inter.getLocText("Image-Extend")); + adjustRadioButton = new UIRadioButton(Inter.getLocText("Image-Adjust")); + + defaultRadioButton.addActionListener(layoutActionListener); + tiledRadioButton.addActionListener(layoutActionListener); + extendRadioButton.addActionListener(layoutActionListener); + adjustRadioButton.addActionListener(layoutActionListener); + + JPanel jp = new JPanel(new GridLayout(4, 1, 15, 15)); + for (JRadioButton button : imageLayoutButtons()) { + jp.add(button); + } + layoutPane.add(jp); + + ButtonGroup layoutBG = new ButtonGroup(); + layoutBG.add(defaultRadioButton); + layoutBG.add(tiledRadioButton); + layoutBG.add(extendRadioButton); + layoutBG.add(adjustRadioButton); + + defaultRadioButton.setSelected(true); + + // init image file chooser. + imageFileChooser = new ImageFileChooser(); + imageFileChooser.setMultiSelectionEnabled(false); + } + + protected JRadioButton[] imageLayoutButtons() { + return new JRadioButton[]{ + defaultRadioButton, + tiledRadioButton, + extendRadioButton, + adjustRadioButton + }; + } + + /** + * Select picture. + */ + ActionListener selectPictureActionListener = new ActionListener() { + + public void actionPerformed(ActionEvent evt) { + int returnVal = imageFileChooser.showOpenDialog(ImageBackgroundPane.this); + if (returnVal != JFileChooser.CANCEL_OPTION) { + File selectedFile = imageFileChooser.getSelectedFile(); + + if (selectedFile != null && selectedFile.isFile()) { + Image image = BaseUtils.readImage(selectedFile.getPath()); + CoreGraphHelper.waitForImage(image); + + previewPane.setImage(image); + setImageStyle(); + previewPane.setImageStyle(imageStyle); + previewPane.repaint(); + } else { + previewPane.setImage(null); + } + } + + fireChagneListener(); + } + }; + + private void setImageStyle() { + if (tiledRadioButton.isSelected()) { + imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_TILED); + } else if (adjustRadioButton.isSelected()) { + imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_ADJUST); + } else if (extendRadioButton.isSelected()) { + imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_EXTEND); + } else { + imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_CENTER); + } + } + + ActionListener layoutActionListener = new ActionListener() { + + public void actionPerformed(ActionEvent evt) { + setImageStyle(); + changeImageStyle(); + } + + private void changeImageStyle() { + previewPane.setImageStyle(ImageBackgroundPane.this.imageStyle); + previewPane.repaint(); + } + }; + + public void populate(Background background) { + + if (background instanceof ImageBackground) { + ImageBackground imageBackground = (ImageBackground) background; + + if (imageBackground.getLayout() == Constants.IMAGE_CENTER) { + defaultRadioButton.setSelected(true); + imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_CENTER); + } else if (imageBackground.getLayout() == Constants.IMAGE_EXTEND) { + extendRadioButton.setSelected(true); + imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_EXTEND); + } else if (imageBackground.getLayout() == Constants.IMAGE_ADJUST) { + adjustRadioButton.setSelected(true); + imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_ADJUST); + } else { + tiledRadioButton.setSelected(true); + imageStyle = Style.DEFAULT_STYLE.deriveImageLayout(Constants.IMAGE_TILED); + } + + previewPane.setImageStyle(ImageBackgroundPane.this.imageStyle); + if (imageBackground.getImage() != null) { + previewPane.setImage(imageBackground.getImage()); + imageSizeLabel.setText(previewPane.getImage().getWidth(null) + + " X " + previewPane.getImage().getHeight(null)); + } + + if (imageBackground.getImage() != null) { + previewPane.setImage(imageBackground.getImage()); + } + } else { + previewPane.setImage(null); + tiledRadioButton.setSelected(true); + + imageSizeLabel.setText(""); + } + + fireChagneListener(); + } + + public Background update() throws Exception { + ImageBackground imageBackground = new ImageBackground(previewPane.getImage()); + setImageStyle(); + imageBackground.setLayout(imageStyle.getImageLayout()); + return imageBackground; + } + + public void addChangeListener(ChangeListener changeListener) { + this.changeListener = changeListener; + } + + private void fireChagneListener() { + if (this.changeListener != null) { + ChangeEvent evt = new ChangeEvent(this); + this.changeListener.stateChanged(evt); + } + } + + ChangeListener imageSizeChangeListener = new ChangeListener() { + + public void stateChanged(ChangeEvent evt) { + Image image = ((ImagePreviewPane) evt.getSource()).getImage(); + + if (image == null) { + imageSizeLabel.setText(""); + } else { + imageSizeLabel.setText(Inter.getLocText(new String[]{"Size", "px"}, new String[]{": " + image.getWidth(null) + "x" + image.getHeight(null)})); + } + } + }; +} diff --git a/designer_base/src/com/fr/design/style/background/impl/ImageBackgroundPane4Browser.java b/designer_base/src/com/fr/design/style/background/impl/ImageBackgroundPane4Browser.java new file mode 100644 index 0000000000..4d15f18ac3 --- /dev/null +++ b/designer_base/src/com/fr/design/style/background/impl/ImageBackgroundPane4Browser.java @@ -0,0 +1,25 @@ +package com.fr.design.style.background.impl; + +import com.fr.stable.ArrayUtils; + +import javax.swing.*; + +/** + * Created by richie on 16/5/18. + */ +public class ImageBackgroundPane4Browser extends ImageBackgroundPane { + + + public ImageBackgroundPane4Browser() { + super(); + } + + @Override + protected JRadioButton[] imageLayoutButtons() { + + return (JRadioButton[]) ArrayUtils.addAll(super.imageLayoutButtons(), new JRadioButton[] { + defaultRadioButton, + tiledRadioButton, + }); + } +} diff --git a/designer_base/src/com/fr/design/style/background/impl/NullBackgroundPane.java b/designer_base/src/com/fr/design/style/background/impl/NullBackgroundPane.java new file mode 100644 index 0000000000..ea108019ac --- /dev/null +++ b/designer_base/src/com/fr/design/style/background/impl/NullBackgroundPane.java @@ -0,0 +1,39 @@ +package com.fr.design.style.background.impl; + +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.style.background.BackgroundDetailPane; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.Background; +import com.fr.general.Inter; + +import javax.swing.*; +import javax.swing.event.ChangeListener; + +/** + * Null background pane. + */ +public class NullBackgroundPane extends BackgroundDetailPane { + + public NullBackgroundPane() { + this.setLayout(FRGUIPaneFactory.createBorderLayout()); + + UILabel centerLabel = new UILabel( + Inter.getLocText("Background-Background_is_NULL") + "..."); + this.add(centerLabel); + centerLabel.setHorizontalAlignment(SwingConstants.CENTER); + centerLabel.setBorder(BorderFactory.createLineBorder(GUICoreUtils.getTitleLineBorderColor())); + } + + public void populate(Background background) { + // do nothing. + } + + public Background update() throws Exception { + return null; + } + + public void addChangeListener(ChangeListener changeListener) { + // do nothing. + } +} diff --git a/designer_base/src/com/fr/design/style/background/impl/PatternBackgroundPane.java b/designer_base/src/com/fr/design/style/background/impl/PatternBackgroundPane.java new file mode 100644 index 0000000000..a1481e6d69 --- /dev/null +++ b/designer_base/src/com/fr/design/style/background/impl/PatternBackgroundPane.java @@ -0,0 +1,208 @@ +package com.fr.design.style.background.impl; + +import com.fr.base.GraphHelper; +import com.fr.base.background.PatternBackground; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.style.color.ColorSelectBox; +import com.fr.general.Background; +import com.fr.general.Inter; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.geom.Rectangle2D; + +/** + * Pattern background pane. + */ +public class PatternBackgroundPane extends BPane { + + private int patternIndex = 0; // pattern setIndex. + protected ColorSelectBox foregroundColorPane; + protected ColorSelectBox backgroundColorPane; + private PatternButton[] patternButtonArray; + + public PatternBackgroundPane() { + super(12); + + foregroundColorPane.addSelectChangeListener(colorChangeListener); + backgroundColorPane.addSelectChangeListener(colorChangeListener); + } + + public PatternBackgroundPane(int nColumn) { + super(nColumn); + + if(foregroundColorPane != null) { + foregroundColorPane.addSelectChangeListener(colorChangeListener); + } + if(backgroundColorPane != null) { + backgroundColorPane.addSelectChangeListener(colorChangeListener); + } + } + + protected String titleOfTypePane() { + return Inter.getLocText("Background-Pattern"); + } + protected LayoutManager layoutOfTypePane(int nColumn) { + return FRGUIPaneFactory.createNColumnGridLayout(nColumn); + } + + protected void setChildrenOfTypePane(JPanel typePane2) { + ButtonGroup patternButtonGroup = new ButtonGroup(); + patternButtonArray = new PatternButton[PatternBackground.PATTERN_COUNT]; + for (int i = 0; i < PatternBackground.PATTERN_COUNT; i++) { + patternButtonArray[i] = new PatternButton(i); + patternButtonGroup.add(patternButtonArray[i]); + typePane2.add(patternButtonArray[i]); + } + } + + protected void setChildrenOfContentPane(JPanel contentPane) { + // colors + JPanel colorPane = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("Colors")); + contentPane.add(colorPane); + + foregroundColorPane = new ColorSelectBox(80); + backgroundColorPane = new ColorSelectBox(80); + foregroundColorPane.setSelectObject(Color.lightGray); + backgroundColorPane.setSelectObject(Color.black); + + colorPane.add(Box.createHorizontalStrut(2)); + colorPane.add(this.createLabelColorPane(Inter.getLocText("Foreground") + + ":", foregroundColorPane)); + + colorPane.add(Box.createHorizontalStrut(8)); + + colorPane.add(this.createLabelColorPane(Inter.getLocText("Background") + + ":", backgroundColorPane)); + } + + private JPanel createLabelColorPane(String text, + ColorSelectBox colorPane) { + JPanel labelColorPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); + labelColorPane.add(new UILabel(text)); + labelColorPane.add(colorPane); + + return labelColorPane; + } + + public void populate(Background background) { + if (background != null && background instanceof PatternBackground) { + PatternBackground patternBackground = (PatternBackground) background; + int patternIndex = patternBackground.getPatternIndex(); + + if (patternIndex >= 0 + && patternIndex < this.patternButtonArray.length) { + this.patternButtonArray[patternIndex].setSelected(true); + this.patternIndex = patternIndex; + } else { + this.patternIndex = 0; + } + + foregroundColorPane.setSelectObject(patternBackground.getForeground()); + backgroundColorPane.setSelectObject(patternBackground.getBackground()); + } else { + patternIndex = 0; + this.patternButtonArray[0].setSelected(true); + + foregroundColorPane.setSelectObject(Color.lightGray); + backgroundColorPane.setSelectObject(Color.black); + } + } + + public Background update() throws Exception { + return new PatternBackground(patternIndex, foregroundColorPane.getSelectObject(), backgroundColorPane.getSelectObject()); + } + + public void addChangeListener(ChangeListener changeListener) { + foregroundColorPane.addSelectChangeListener(changeListener); + backgroundColorPane.addSelectChangeListener(changeListener); + + for (int i = 0; i < this.patternButtonArray.length; i++) { + this.patternButtonArray[i].addChangeListener(changeListener); + } + } + // Foreground or Background changed. + ChangeListener colorChangeListener = new ChangeListener() { + + public void stateChanged(ChangeEvent e) { + for (int i = 0; i < patternButtonArray.length; i++) { + patternButtonArray[i].setPatternForeground(foregroundColorPane.getSelectObject()); + patternButtonArray[i].setPatternBackground(backgroundColorPane.getSelectObject()); + } + + PatternBackgroundPane.this.repaint();// repaint + } + }; + + /** + * Pattern type button. + */ + class PatternButton extends JToggleButton implements ActionListener { + + public PatternButton(int pIndex) { + this.pIndex = pIndex; + this.addActionListener(this); + + this.setCursor(new Cursor(Cursor.HAND_CURSOR)); + this.setBorder(null); + this.patternBackground = new PatternBackground(this.pIndex, + Color.lightGray, Color.black); + } + + public void paintComponent(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + + Dimension d = getSize(); + this.patternBackground.paint(g2d, new Rectangle2D.Double(0, 0, + d.width - 1, d.height - 1)); + + if (this.pIndex == patternIndex) {// it's selected. + g2d.setPaint(new Color(255, 51, 0)); + } else { + g2d.setPaint(Color.gray); + } + GraphHelper.draw(g2d, new Rectangle2D.Double(0, 0, d.width - 1, + d.height - 1)); + } + + public Dimension getPreferredSize() { + return new Dimension(24, 24); + } + + public void setPatternForeground(Color foreground) { + this.patternBackground.setForeground(foreground); + } + + public void setPatternBackground(Color background) { + this.patternBackground.setBackground(background); + } + + /** + * set Pattern setIndex. + */ + public void actionPerformed(ActionEvent evt) { + PatternBackgroundPane.this.patternIndex = pIndex; + + fireChagneListener(); + PatternBackgroundPane.this.repaint();// repaint + } + + public void addChangeListener(ChangeListener changeListener) { + this.changeListener = changeListener; + } + + private void fireChagneListener() { + if (this.changeListener != null) { + ChangeEvent evt = new ChangeEvent(this); + this.changeListener.stateChanged(evt); + } + } + private int pIndex = 0; + private PatternBackground patternBackground; + } +} diff --git a/designer_base/src/com/fr/design/style/background/impl/PatternBackgroundPaneNoFore.java b/designer_base/src/com/fr/design/style/background/impl/PatternBackgroundPaneNoFore.java new file mode 100644 index 0000000000..79fdaf3898 --- /dev/null +++ b/designer_base/src/com/fr/design/style/background/impl/PatternBackgroundPaneNoFore.java @@ -0,0 +1,24 @@ +package com.fr.design.style.background.impl; + +import com.fr.design.style.color.ColorSelectBox; + +import javax.swing.*; +import java.awt.*; + +/** + * Created by richie on 16/5/18. + */ +public class PatternBackgroundPaneNoFore extends PatternBackgroundPane { + + public PatternBackgroundPaneNoFore(int nColumn) { + super(nColumn); + } + + // 重载 不加载两个前后按钮 + protected void setChildrenOfContentPane(JPanel contentPane) { + foregroundColorPane = new ColorSelectBox(80); + backgroundColorPane = new ColorSelectBox(80); + foregroundColorPane.setSelectObject(Color.lightGray); + backgroundColorPane.setSelectObject(Color.black); + } +} diff --git a/designer_base/src/com/fr/design/style/background/impl/TextureBackgroundPane.java b/designer_base/src/com/fr/design/style/background/impl/TextureBackgroundPane.java new file mode 100644 index 0000000000..9800675c1d --- /dev/null +++ b/designer_base/src/com/fr/design/style/background/impl/TextureBackgroundPane.java @@ -0,0 +1,197 @@ +package com.fr.design.style.background.impl; + +import com.fr.base.GraphHelper; +import com.fr.base.background.TextureBackground; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.general.Background; +import com.fr.general.ComparatorUtils; +import com.fr.general.Inter; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.geom.Rectangle2D; + +/** + * Texture background pane. TODO kunsnat: 拆出去. 真特么的长.. + */ +public class TextureBackgroundPane extends BPane { + + private static final TexturePaint[] EMBED_TEXTURE_PAINT_ARRAY = new TexturePaint[]{ + TextureBackground.NEWSPRINT_TEXTURE_PAINT, + TextureBackground.RECYCLED_PAPER_TEXTURE_PAINT, + TextureBackground.PARCHMENT_TEXTURE_PAINT, + TextureBackground.STATIONERY_TEXTURE_PAINT, + TextureBackground.GREEN_MARBLE_TEXTURE_PAINT, + TextureBackground.WHITE_MARBLE_TEXTURE_PAINT, + TextureBackground.BROWN_MARBLE_TEXTURE_PAINT, + TextureBackground.GRANITE_TEXTURE_PAINT, + TextureBackground.BLUE_TISSUE_PAPER_TEXTURE_PAINT, + TextureBackground.PINK_TISSUE_PAPER_TEXTURE_PAINT, + TextureBackground.PURPLE_MESH_TEXTURE_PAINT, + TextureBackground.BOUQUET_TEXTURE_PAINT, + TextureBackground.PAPYRUS_TEXTURE_PAINT, + TextureBackground.CANVAS_TEXTURE_PAINT, + TextureBackground.DENIM_TEXTURE_PAINT, + TextureBackground.WOVEN_MAT_TEXTURE_PAINT, + TextureBackground.WATER_DROPLETS_TEXTURE_PAINT, + TextureBackground.PAPER_BAG_TEXTURE_PAINT, + TextureBackground.FISH_FOSSIL_TEXTURE_PAINT, + TextureBackground.SAND_TEXTURE_PAINT, + TextureBackground.CORK_TEXTURE_PAINT, + TextureBackground.WALNUT_TEXTURE_PAINT, + TextureBackground.OAK_TEXTURE_PAINT, + TextureBackground.MEDIUM_WOOD_TEXTURE_PAINT}; + + private static final String[] EMBED_TEXTURE_PAINT_DES_ARRAY = new String[]{ + Inter.getLocText("BackgroundTexture-Newsprint"), + Inter.getLocText("BackgroundTexture-RecycledPaper"), + Inter.getLocText("BackgroundTexture-Parchment"), + Inter.getLocText("BackgroundTexture-Stationery"), + Inter.getLocText("BackgroundTexture-GreenMarble"), + Inter.getLocText("BackgroundTexture-WhiteMarble"), + Inter.getLocText("BackgroundTexture-BrownMarble"), + Inter.getLocText("BackgroundTexture-Granite"), + Inter.getLocText("BackgroundTexture-BlueTissuePaper"), + Inter.getLocText("BackgroundTexture-PinkTissuePaper"), + Inter.getLocText("BackgroundTexture-PurpleMesh"), + Inter.getLocText("BackgroundTexture-Bouquet"), + Inter.getLocText("BackgroundTexture-Papyrus"), + Inter.getLocText("BackgroundTexture-Canvas"), + Inter.getLocText("BackgroundTexture-Denim"), + Inter.getLocText("BackgroundTexture-WovenMat"), + Inter.getLocText("BackgroundTexture-WaterDroplets"), + Inter.getLocText("BackgroundTexture-PaperBag"), + Inter.getLocText("BackgroundTexture-FishFossil"), + Inter.getLocText("BackgroundTexture-Sand"), + Inter.getLocText("BackgroundTexture-Cork"), + Inter.getLocText("BackgroundTexture-Walnut"), + Inter.getLocText("BackgroundTexture-Oak"), + Inter.getLocText("BackgroundTexture-MediumWood") + }; + + private TexturePaint texturePaint; + private TextureButton[] textureButtonArray; + + public TextureBackgroundPane() { + super(8);// 默认的. + } + + public TextureBackgroundPane(int colum) { + super(colum);// 自定义的. + } + + protected LayoutManager layoutOfTypePane(int nColumn) { + return FRGUIPaneFactory.createNColumnGridLayout(nColumn); + } + + protected String titleOfTypePane() { + return Inter.getLocText("Background-Texture"); + } + protected void setChildrenOfTypePane(JPanel typePane2) { + ButtonGroup patternButtonGroup = new ButtonGroup(); + textureButtonArray = new TextureButton[EMBED_TEXTURE_PAINT_ARRAY.length]; + for (int i = 0; i < EMBED_TEXTURE_PAINT_ARRAY.length; i++) { + textureButtonArray[i] = new TextureButton( + EMBED_TEXTURE_PAINT_ARRAY[i], EMBED_TEXTURE_PAINT_DES_ARRAY[i]); + patternButtonGroup.add(textureButtonArray[i]); + typePane2.add(textureButtonArray[i]); + } + } + + public void populate(Background background) { + if (background instanceof TextureBackground) { + TextureBackground textureBackground = (TextureBackground) background; + + this.texturePaint = textureBackground.getTexturePaint(); + + for (int i = 0; i < textureButtonArray.length; i++) { + if (ComparatorUtils.equals(textureButtonArray[i].getTexturePaint(), this.texturePaint)) { + textureButtonArray[i].setSelected(true); + break; + } + } + } else { + this.textureButtonArray[0].setSelected(true); + this.texturePaint = textureButtonArray[0].getTexturePaint(); + } + } + + public Background update() throws Exception { + return new TextureBackground(this.texturePaint); + } + + public void addChangeListener(ChangeListener changeListener) { + for (int i = 0; i < this.textureButtonArray.length; i++) { + this.textureButtonArray[i].addChangeListener(changeListener); + } + } + + /** + * Texture type button. + */ + class TextureButton extends JToggleButton implements ActionListener { + + private TexturePaint buttonTexturePaint; + + public TextureButton(TexturePaint buttonTexturePaint, String tooltip) { + this.buttonTexturePaint = buttonTexturePaint; + this.setToolTipText(tooltip); + + this.setCursor(new Cursor(Cursor.HAND_CURSOR)); + this.addActionListener(this); + this.setBorder(null); + } + + public void paintComponent(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + + Dimension d = getSize(); + + g2d.setPaint(this.buttonTexturePaint); + GraphHelper.fill(g2d, new Rectangle2D.Double(0, 0, d.width - 1, + d.height - 1)); + + if (ComparatorUtils.equals(texturePaint, this.buttonTexturePaint)) {// it's + // selected. + g2d.setPaint(Color.black); + } else { + g2d.setPaint(Color.gray); + } + GraphHelper.draw(g2d, new Rectangle2D.Double(0, 0, d.width - 1, + d.height - 1)); + } + + public Dimension getPreferredSize() { + return new Dimension(36, 32); + } + + public TexturePaint getTexturePaint() { + return this.buttonTexturePaint; + } + + /** + * set Pattern setIndex. + */ + public void actionPerformed(ActionEvent evt) { + TextureBackgroundPane.this.texturePaint = this.getTexturePaint(); + + fireChagneListener(); + TextureBackgroundPane.this.repaint(); // repaint. + } + + public void addChangeListener(ChangeListener changeListener) { + this.changeListener = changeListener; + } + + private void fireChagneListener() { + if (this.changeListener != null) { + ChangeEvent evt = new ChangeEvent(this); + this.changeListener.stateChanged(evt); + } + } + } +} diff --git a/designer_base/src/com/fr/design/style/background/pattern/PatternSelectPane.java b/designer_base/src/com/fr/design/style/background/pattern/PatternSelectPane.java index b8f9ea3843..47a3524475 100644 --- a/designer_base/src/com/fr/design/style/background/pattern/PatternSelectPane.java +++ b/designer_base/src/com/fr/design/style/background/pattern/PatternSelectPane.java @@ -1,8 +1,8 @@ package com.fr.design.style.background.pattern; import com.fr.general.Inter; -import com.fr.design.style.background.BackgroundPane.BackgroundSettingPane; -import com.fr.design.style.background.BackgroundPane.PatternBackgroundPaneNoFore; +import com.fr.design.style.background.BackgroundDetailPane; +import com.fr.design.style.background.impl.PatternBackgroundPaneNoFore; import com.fr.design.style.background.BackgroundSelectPane; @@ -20,7 +20,7 @@ public class PatternSelectPane extends BackgroundSelectPane { } @Override - public BackgroundSettingPane getShowPane(double preWidth) { + public BackgroundDetailPane getShowPane(double preWidth) { // 最少6个. 因为项目太多了. 会拉的很长 int column = Math.max((int)preWidth / 25, 6); return new PatternBackgroundPaneNoFore(column); diff --git a/designer_base/src/com/fr/design/style/background/texture/TextureSelectPane.java b/designer_base/src/com/fr/design/style/background/texture/TextureSelectPane.java index 86d36bbfbd..ea7af5bc41 100644 --- a/designer_base/src/com/fr/design/style/background/texture/TextureSelectPane.java +++ b/designer_base/src/com/fr/design/style/background/texture/TextureSelectPane.java @@ -1,8 +1,8 @@ package com.fr.design.style.background.texture; import com.fr.general.Inter; -import com.fr.design.style.background.BackgroundPane.BackgroundSettingPane; -import com.fr.design.style.background.BackgroundPane.TextureBackgroundPane; +import com.fr.design.style.background.BackgroundDetailPane; +import com.fr.design.style.background.impl.TextureBackgroundPane; import com.fr.design.style.background.BackgroundSelectPane; @@ -19,7 +19,7 @@ public class TextureSelectPane extends BackgroundSelectPane { initBackgroundShowPane(getShowPane(preWidth)); } - public BackgroundSettingPane getShowPane(double preWidth) { + public BackgroundDetailPane getShowPane(double preWidth) { // 计算合适的列. 至少4个. 最多8个. int column = Math.max((int)preWidth / 40, 4); return new TextureBackgroundPane(column); diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/data/table/MeterPlotTableDataContentPane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/data/table/MeterPlotTableDataContentPane.java index 5ea4e8fe63..22deb51016 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/data/table/MeterPlotTableDataContentPane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/data/table/MeterPlotTableDataContentPane.java @@ -49,14 +49,7 @@ public class MeterPlotTableDataContentPane extends AbstractTableDataContentPane double[] columnSize = { p,f}; double[] rowSize = { p, p,p,p,p,p,p,p, p}; - Component[][] components = new Component[][]{ - new Component[]{new BoldFontTextLabel(METER_NAME, SwingConstants.RIGHT), nameBox}, - new Component[]{new BoldFontTextLabel(METER_VALUE, SwingConstants.RIGHT), valueBox}, - new Component[]{new JSeparator(), null}, - new Component[]{new BoldFontTextLabel(Inter.getLocText("Chart-Data_Filter"))}, - new Component[]{filterPane, null} - - } ; + Component[][] components = createComponents(); JPanel panel = TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize); this.add(panel,BorderLayout.CENTER); @@ -65,7 +58,17 @@ public class MeterPlotTableDataContentPane extends AbstractTableDataContentPane valueBox.addItemListener(tooltipListener); } - protected void refreshBoxListWithSelectTableData(List list) { + private Component[][] createComponents() { + return new Component[][]{ + new Component[]{new BoldFontTextLabel(METER_NAME, SwingConstants.RIGHT), getNameComponent()}, + new Component[]{new BoldFontTextLabel(METER_VALUE, SwingConstants.RIGHT), valueBox}, + new Component[]{new JSeparator(), null}, + new Component[]{new BoldFontTextLabel(Inter.getLocText("Chart-Data_Filter"))}, + new Component[]{filterPane, null} + }; + } + + protected void refreshBoxListWithSelectTableData(List list) { refreshBoxItems(nameBox, list); refreshBoxItems(valueBox, list); } @@ -84,14 +87,19 @@ public class MeterPlotTableDataContentPane extends AbstractTableDataContentPane public void populateBean(ChartCollection ob) { if(ob != null && ob.getSelectedChart().getFilterDefinition() instanceof MeterTableDefinition) { MeterTableDefinition meter = (MeterTableDefinition)ob.getSelectedChart().getFilterDefinition(); - - nameBox.setSelectedItem(meter.getName()); + + populateNameComponent(meter.getName()); + valueBox.setSelectedItem(meter.getValue()); filterPane.populateBean(ob); } } - /** + protected void populateNameComponent(String name) { + nameBox.setSelectedItem(name); + } + + /** * 保存界面属性. */ public void updateBean(ChartCollection ob) { @@ -99,13 +107,18 @@ public class MeterPlotTableDataContentPane extends AbstractTableDataContentPane MeterTableDefinition meter = new MeterTableDefinition(); ob.getSelectedChart().setFilterDefinition(meter); - meter.setName(Utils.objectToString(nameBox.getSelectedItem())); + updateNameComponent(meter); + meter.setValue(Utils.objectToString(valueBox.getSelectedItem())); filterPane.updateBean(ob); } } - /** + protected void updateNameComponent(MeterTableDefinition meter) { + meter.setName(Utils.objectToString(nameBox.getSelectedItem())); + } + + /** * 重新布局整个面板 */ public void redoLayoutPane(){ @@ -113,4 +126,7 @@ public class MeterPlotTableDataContentPane extends AbstractTableDataContentPane } + protected Component getNameComponent() { + return nameBox; + } } \ No newline at end of file diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartBackgroundNoImagePane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartBackgroundNoImagePane.java index 447ba1107e..439d2efe64 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartBackgroundNoImagePane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartBackgroundNoImagePane.java @@ -1,8 +1,8 @@ package com.fr.design.mainframe.chart.gui.style; -import com.fr.design.gui.style.GradientPane; -import com.fr.design.mainframe.backgroundpane.ColorBackgroundPane; -import com.fr.design.mainframe.backgroundpane.NullBackgroundPane; +import com.fr.design.mainframe.backgroundpane.ColorBackgroundQuickPane; +import com.fr.design.mainframe.backgroundpane.GradientBackgroundQuickPane; +import com.fr.design.mainframe.backgroundpane.NullBackgroundQuickPane; /** * 背景界面, 无图片和纹理选项. @@ -16,8 +16,8 @@ public class ChartBackgroundNoImagePane extends ChartBackgroundPane { } protected void initList() { - paneList.add(new NullBackgroundPane()); - paneList.add(new ColorBackgroundPane()); - paneList.add(new GradientPane(CHART_GRADIENT_WIDTH)); + paneList.add(new NullBackgroundQuickPane()); + paneList.add(new ColorBackgroundQuickPane()); + paneList.add(new GradientBackgroundQuickPane(CHART_GRADIENT_WIDTH)); } } \ No newline at end of file diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartBackgroundPane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartBackgroundPane.java index 7cbffadfdc..13c4269e8e 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartBackgroundPane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartBackgroundPane.java @@ -4,13 +4,9 @@ import com.fr.chart.chartglyph.GeneralInfo; import com.fr.design.gui.frpane.UINumberDragPane; import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.ilable.UILabel; -import com.fr.design.gui.style.GradientPane; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; -import com.fr.design.mainframe.backgroundpane.BackgroundSettingPane; -import com.fr.design.mainframe.backgroundpane.ColorBackgroundPane; -import com.fr.design.mainframe.backgroundpane.ImageBackgroundPane; -import com.fr.design.mainframe.backgroundpane.NullBackgroundPane; +import com.fr.design.mainframe.backgroundpane.*; import com.fr.design.dialog.BasicPane; import com.fr.general.Background; import com.fr.general.Inter; @@ -33,7 +29,7 @@ public class ChartBackgroundPane extends BasicPane{ private static final long serialVersionUID = 6955952013135176051L; private static final double ALPHA_V = 100.0; protected static final int CHART_GRADIENT_WIDTH = 150; - protected List paneList; + protected List paneList; private UIComboBox typeComboBox; private UINumberDragPane transparent; @@ -41,7 +37,7 @@ public class ChartBackgroundPane extends BasicPane{ public ChartBackgroundPane() { typeComboBox = new UIComboBox(); final CardLayout cardlayout = new CardLayout(); - paneList = new ArrayList(); + paneList = new ArrayList(); initList(); @@ -54,7 +50,7 @@ public class ChartBackgroundPane extends BasicPane{ } }; for (int i = 0; i < paneList.size(); i++) { - BackgroundSettingPane pane = paneList.get(i); + BackgroundQuickPane pane = paneList.get(i); typeComboBox.addItem(pane.title4PopupWindow()); centerPane.add(pane, pane.title4PopupWindow()); } @@ -89,10 +85,10 @@ public class ChartBackgroundPane extends BasicPane{ } protected void initList() { - paneList.add(new NullBackgroundPane()); - paneList.add(new ColorBackgroundPane()); - paneList.add(new ImageBackgroundPane()); - paneList.add(new GradientPane(CHART_GRADIENT_WIDTH)); + paneList.add(new NullBackgroundQuickPane()); + paneList.add(new ColorBackgroundQuickPane()); + paneList.add(new ImageBackgroundQuickPane()); + paneList.add(new GradientBackgroundQuickPane(CHART_GRADIENT_WIDTH)); } /** @@ -127,7 +123,7 @@ public class ChartBackgroundPane extends BasicPane{ double alpha = attr.getAlpha() * ALPHA_V; transparent.populateBean(alpha); for (int i = 0; i < paneList.size(); i++) { - BackgroundSettingPane pane = paneList.get(i); + BackgroundQuickPane pane = paneList.get(i); if (pane.accept(background)) { pane.populateBean(background); typeComboBox.setSelectedIndex(i);