forked from fanruan/design
zack
9 years ago
37 changed files with 2435 additions and 2047 deletions
@ -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(); |
||||
} |
@ -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<? extends Background> targetClass(); |
||||
|
||||
/** |
||||
* 背景设置界面 |
||||
* @return 界面 |
||||
*/ |
||||
Class<? extends BackgroundDetailPane> targetUIClass(); |
||||
|
||||
/** |
||||
* 标题 |
||||
* @return 在设计界面上这个选项的显示标题 |
||||
*/ |
||||
String targetTitle(); |
||||
} |
@ -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(); |
||||
} |
||||
} |
@ -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(); |
||||
} |
||||
} |
@ -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.ExtraDesignClassManager; |
||||
import com.fr.design.fun.BackgroundQuickUIProvider; |
||||
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.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 List<BackgroundSettingPane> 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<BackgroundSettingPane>(); |
||||
paneList.add(new NullBackgroundPane()); |
||||
paneList.add(new ColorBackgroundPane()); |
||||
paneList.add(new TextureBackgroundPane()); |
||||
paneList.add(new PatternBackgroundPane()); |
||||
paneList.add(new ImageBackgroundPane()); |
||||
paneList.add(new GradientPane()); |
||||
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<BackgroundQuickPane> 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 事件 |
||||
* |
||||
* @param changeListener 事件 |
||||
*/ |
||||
public void addChangeListener(ChangeListener changeListener) { |
||||
listenerList.add(ChangeListener.class, 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); |
||||
} |
||||
} |
||||
} |
||||
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 名称 |
||||
* |
||||
* @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 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()); |
||||
} |
||||
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()); |
||||
} |
||||
|
||||
} |
@ -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); |
||||
} |
@ -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<Class<? extends Background>, BackgroundUIWrapper> map = new HashMap<>(); |
||||
private static Map<Class<? extends Background>, BackgroundUIWrapper> browser = new HashMap<>(); |
||||
|
||||
static { |
||||
registerUniversal(map); |
||||
registerImageBackground(map); |
||||
registerUniversal(browser); |
||||
registerBrowserImageBackground(browser); |
||||
registerExtra(map); |
||||
registerExtra(browser); |
||||
} |
||||
|
||||
private static void registerUniversal(Map<Class<? extends Background>, 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<Class<? extends Background>, BackgroundUIWrapper> map) { |
||||
map.put(ImageBackground.class, BackgroundUIWrapper.create() |
||||
.setType(ImageBackgroundPane.class).setTitle(Inter.getLocText("Image"))); |
||||
} |
||||
|
||||
private static void registerBrowserImageBackground(Map<Class<? extends Background>, BackgroundUIWrapper> map) { |
||||
map.put(ImageBackground.class, BackgroundUIWrapper.create() |
||||
.setType(ImageBackgroundPane4Browser.class).setTitle(Inter.getLocText("Image"))); |
||||
} |
||||
|
||||
private static void registerExtra(Map<Class<? extends Background>, BackgroundUIWrapper> map) { |
||||
for (BackgroundUIProvider provider : ExtraDesignClassManager.getInstance().getBackgroundUIProviders()) { |
||||
map.put(provider.targetClass(), BackgroundUIWrapper.create() |
||||
.setType(provider.targetUIClass()).setTitle(provider.targetTitle())); |
||||
} |
||||
} |
||||
|
||||
|
||||
public static Set<Class<? extends Background>> kindsOfKey() { |
||||
return map.keySet(); |
||||
} |
||||
|
||||
public static BackgroundUIWrapper getWrapper(Class<? extends Background> category) { |
||||
return map.get(category); |
||||
} |
||||
|
||||
public static BackgroundDetailPane createIfAbsent(Class<? extends Background> 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<Class<? extends Background>> browserKindsOfKey() { |
||||
return browser.keySet(); |
||||
} |
||||
|
||||
public static BackgroundUIWrapper getBrosweWrapper(Class<? extends Background> category) { |
||||
return browser.get(category); |
||||
} |
||||
|
||||
public static BackgroundDetailPane createBrowserIfAbsent(Class<? extends Background> 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<? extends BackgroundDetailPane> clazz = wrapper.getType(); |
||||
if (clazz == null) { |
||||
clazz = NullBackgroundPane.class; |
||||
} |
||||
BackgroundDetailPane quickPane; |
||||
try { |
||||
quickPane = clazz.newInstance(); |
||||
} catch (Exception e) { |
||||
quickPane = new NullBackgroundPane(); |
||||
} |
||||
return quickPane; |
||||
} |
||||
} |
@ -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<? extends Background> 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; |
||||
} |
||||
} |
@ -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<? extends BackgroundDetailPane> clazz; |
||||
|
||||
private BackgroundUIWrapper() { |
||||
|
||||
} |
||||
|
||||
public Class<? extends BackgroundDetailPane> getType() { |
||||
return clazz; |
||||
} |
||||
|
||||
public BackgroundUIWrapper setType(Class<? extends BackgroundDetailPane> 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; |
||||
} |
||||
} |
@ -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) { |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
@ -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)})); |
||||
} |
||||
} |
||||
}; |
||||
} |
@ -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, |
||||
}); |
||||
} |
||||
} |
@ -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.
|
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue