forked from fanruan/design
superman
9 years ago
6 changed files with 294 additions and 305 deletions
@ -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<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()); |
||||
} |
||||
|
||||
/** |
||||
* 事件监听 |
||||
* @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<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 事件 |
||||
*/ |
||||
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()); |
||||
} |
||||
|
||||
} |
@ -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<Integer> 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<Integer>(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<Integer> 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<Integer>(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"); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue