richie
9 years ago
6 changed files with 294 additions and 305 deletions
@ -1,148 +1,145 @@ |
|||||||
package com.fr.design.gui.style; |
package com.fr.design.gui.style; |
||||||
|
|
||||||
/* |
import com.fr.base.Style; |
||||||
* Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved. |
import com.fr.design.ExtraDesignClassManager; |
||||||
*/ |
import com.fr.design.fun.BackgroundQuickUIProvider; |
||||||
|
import com.fr.design.gui.icombobox.UIComboBox; |
||||||
import java.awt.BorderLayout; |
import com.fr.design.mainframe.backgroundpane.*; |
||||||
import java.awt.CardLayout; |
import com.fr.general.Background; |
||||||
import java.awt.Dimension; |
import com.fr.general.Inter; |
||||||
import java.awt.event.ItemEvent; |
|
||||||
import java.awt.event.ItemListener; |
import javax.swing.*; |
||||||
import java.util.ArrayList; |
import javax.swing.event.ChangeEvent; |
||||||
import java.util.List; |
import javax.swing.event.ChangeListener; |
||||||
|
import java.awt.*; |
||||||
import javax.swing.*; |
import java.awt.event.ItemEvent; |
||||||
import javax.swing.event.ChangeEvent; |
import java.awt.event.ItemListener; |
||||||
import javax.swing.event.ChangeListener; |
import java.util.ArrayList; |
||||||
|
|
||||||
import com.fr.base.Style; |
/** |
||||||
import com.fr.design.gui.icombobox.UIComboBox; |
* @author zhou |
||||||
import com.fr.design.mainframe.backgroundpane.BackgroundSettingPane; |
* @since 2012-5-28下午6:22:09 |
||||||
import com.fr.design.mainframe.backgroundpane.ColorBackgroundPane; |
*/ |
||||||
import com.fr.design.mainframe.backgroundpane.ImageBackgroundPane; |
public class BackgroundPane extends AbstractBasicStylePane { |
||||||
import com.fr.design.mainframe.backgroundpane.NullBackgroundPane; |
|
||||||
import com.fr.design.mainframe.backgroundpane.PatternBackgroundPane; |
private UIComboBox typeComboBox; |
||||||
import com.fr.design.mainframe.backgroundpane.TextureBackgroundPane; |
|
||||||
import com.fr.general.Background; |
protected BackgroundQuickPane[] paneList; |
||||||
import com.fr.general.Inter; |
|
||||||
|
public BackgroundPane() { |
||||||
/** |
this.initComponents(); |
||||||
* |
} |
||||||
* @author zhou |
|
||||||
* @since 2012-5-28下午6:22:09 |
protected void initComponents() { |
||||||
*/ |
this.setLayout(new BorderLayout(0, 6)); |
||||||
public class BackgroundPane extends AbstractBasicStylePane { |
typeComboBox = new UIComboBox(); |
||||||
|
final CardLayout cardlayout = new CardLayout(); |
||||||
private UIComboBox typeComboBox; |
this.add(typeComboBox, BorderLayout.NORTH); |
||||||
|
|
||||||
protected List<BackgroundSettingPane> paneList; |
paneList = supportKindsOfBackgroundUI(); |
||||||
|
|
||||||
public BackgroundPane() { |
final JPanel centerPane = new JPanel(cardlayout) { |
||||||
this.initComponents(); |
@Override |
||||||
} |
public Dimension getPreferredSize() {// AUGUST:使用当前面板的的高度
|
||||||
|
int index = typeComboBox.getSelectedIndex(); |
||||||
protected void initComponents() { |
return new Dimension(super.getPreferredSize().width, paneList[index].getPreferredSize().height); |
||||||
this.setLayout(new BorderLayout(0, 6)); |
} |
||||||
typeComboBox = new UIComboBox(); |
}; |
||||||
final CardLayout cardlayout = new CardLayout(); |
for (BackgroundQuickPane pane : paneList) { |
||||||
this.add(typeComboBox, BorderLayout.NORTH); |
typeComboBox.addItem(pane.title4PopupWindow()); |
||||||
|
centerPane.add(pane, pane.title4PopupWindow()); |
||||||
initPaneList(); |
} |
||||||
final JPanel centerPane = new JPanel(cardlayout) { |
this.add(centerPane, BorderLayout.CENTER); |
||||||
@Override |
typeComboBox.addItemListener(new ItemListener() { |
||||||
public Dimension getPreferredSize() {// AUGUST:使用当前面板的的高度
|
|
||||||
int index = typeComboBox.getSelectedIndex(); |
@Override |
||||||
return new Dimension(super.getPreferredSize().width, paneList.get(index).getPreferredSize().height); |
public void itemStateChanged(ItemEvent e) { |
||||||
} |
cardlayout.show(centerPane, (String) typeComboBox.getSelectedItem()); |
||||||
}; |
fireStateChanged(); |
||||||
for (int i = 0; i < paneList.size(); i++) { |
} |
||||||
BackgroundSettingPane pane = paneList.get(i); |
}); |
||||||
typeComboBox.addItem(pane.title4PopupWindow()); |
} |
||||||
centerPane.add(pane, pane.title4PopupWindow()); |
|
||||||
} |
protected BackgroundQuickPane[] supportKindsOfBackgroundUI() { |
||||||
this.add(centerPane, BorderLayout.CENTER); |
java.util.List<BackgroundQuickPane> kinds = new ArrayList<>(); |
||||||
typeComboBox.addItemListener(new ItemListener() { |
kinds.add(new NullBackgroundQuickPane()); |
||||||
|
kinds.add(new ColorBackgroundQuickPane()); |
||||||
@Override |
kinds.add(new TextureBackgroundQuickPane()); |
||||||
public void itemStateChanged(ItemEvent e) { |
kinds.add(new PatternBackgroundQuickPane()); |
||||||
cardlayout.show(centerPane, (String)typeComboBox.getSelectedItem()); |
kinds.add(new ImageBackgroundQuickPane()); |
||||||
fireStateChanged(); |
kinds.add(new GradientBackgroundQuickPane()); |
||||||
} |
BackgroundQuickUIProvider[] providers = ExtraDesignClassManager.getInstance().getBackgroundQuickUIProviders(); |
||||||
}); |
for (BackgroundQuickUIProvider provider : providers) { |
||||||
} |
kinds.add(provider.appearanceForBackground()); |
||||||
|
|
||||||
protected void initPaneList(){ |
} |
||||||
paneList = new ArrayList<BackgroundSettingPane>(); |
return kinds.toArray(new BackgroundQuickPane[kinds.size()]); |
||||||
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); |
||||||
* @param changeListener 事件 |
} |
||||||
*/ |
|
||||||
public void addChangeListener(ChangeListener changeListener) { |
/** |
||||||
listenerList.add(ChangeListener.class, changeListener); |
*/ |
||||||
} |
protected void fireStateChanged() { |
||||||
|
Object[] listeners = listenerList.getListenerList(); |
||||||
/** |
ChangeEvent e = null; |
||||||
*/ |
|
||||||
protected void fireStateChanged() { |
for (int i = listeners.length - 2; i >= 0; i -= 2) { |
||||||
Object[] listeners = listenerList.getListenerList(); |
if (listeners[i] == ChangeListener.class) { |
||||||
ChangeEvent e = null; |
if (e == null) { |
||||||
|
e = new ChangeEvent(this); |
||||||
for (int i = listeners.length - 2; i >= 0; i -= 2) { |
} |
||||||
if (listeners[i] == ChangeListener.class) { |
((ChangeListener) listeners[i + 1]).stateChanged(e); |
||||||
if (e == null) { |
} |
||||||
e = new ChangeEvent(this); |
} |
||||||
} |
} |
||||||
((ChangeListener)listeners[i + 1]).stateChanged(e); |
|
||||||
} |
/** |
||||||
} |
* 名称 |
||||||
} |
* |
||||||
|
* @return 名称 |
||||||
/** |
*/ |
||||||
* 名称 |
public String title4PopupWindow() { |
||||||
* @return 名称 |
return Inter.getLocText("FR-Utils_Background"); |
||||||
*/ |
} |
||||||
public String title4PopupWindow() { |
|
||||||
return Inter.getLocText("FR-Utils_Background"); |
/** |
||||||
} |
* Populate background. |
||||||
|
*/ |
||||||
/** |
public void populateBean(Background background) { |
||||||
* Populate background. |
for (int i = 0; i < paneList.length; i++) { |
||||||
*/ |
BackgroundQuickPane pane = paneList[i]; |
||||||
public void populateBean(Background background) { |
if (pane.accept(background)) { |
||||||
for (int i = 0; i < paneList.size(); i++) { |
pane.populateBean(background); |
||||||
BackgroundSettingPane pane = paneList.get(i); |
typeComboBox.setSelectedIndex(i); |
||||||
if (pane.accept(background)) { |
return; |
||||||
pane.populateBean(background); |
} |
||||||
typeComboBox.setSelectedIndex(i); |
} |
||||||
return; |
} |
||||||
} |
|
||||||
} |
/** |
||||||
} |
* Update background. |
||||||
|
*/ |
||||||
/** |
public Background update() { |
||||||
* Update background. |
return paneList[typeComboBox.getSelectedIndex()].updateBean(); |
||||||
*/ |
} |
||||||
public Background update() { |
|
||||||
return paneList.get(typeComboBox.getSelectedIndex()).updateBean(); |
@Override |
||||||
} |
public void populateBean(Style style) { |
||||||
|
this.populateBean(style.getBackground()); |
||||||
@Override |
} |
||||||
public void populateBean(Style style) { |
|
||||||
this.populateBean(style.getBackground()); |
@Override |
||||||
} |
public Style update(Style style) { |
||||||
|
return style.deriveBackground(this.update()); |
||||||
@Override |
} |
||||||
public Style update(Style style) { |
|
||||||
return style.deriveBackground(this.update()); |
|
||||||
} |
|
||||||
|
|
||||||
} |
} |
@ -1,123 +1,122 @@ |
|||||||
package com.fr.design.gui.style; |
package com.fr.design.mainframe.backgroundpane; |
||||||
|
|
||||||
import com.fr.base.background.GradientBackground; |
import com.fr.base.background.GradientBackground; |
||||||
import com.fr.design.event.UIObserverListener; |
import com.fr.design.event.UIObserverListener; |
||||||
import com.fr.design.gui.ibutton.UIButtonGroup; |
import com.fr.design.gui.ibutton.UIButtonGroup; |
||||||
import com.fr.design.gui.ilable.UILabel; |
import com.fr.design.gui.ilable.UILabel; |
||||||
import com.fr.design.layout.TableLayout; |
import com.fr.design.layout.TableLayout; |
||||||
import com.fr.design.layout.TableLayoutHelper; |
import com.fr.design.layout.TableLayoutHelper; |
||||||
import com.fr.design.mainframe.backgroundpane.BackgroundSettingPane; |
import com.fr.design.style.background.gradient.GradientBar; |
||||||
import com.fr.general.Background; |
import com.fr.general.Background; |
||||||
import com.fr.general.Inter; |
import com.fr.general.Inter; |
||||||
import com.fr.design.style.background.gradient.GradientBar; |
|
||||||
|
import javax.swing.*; |
||||||
import javax.swing.*; |
import javax.swing.event.ChangeEvent; |
||||||
import javax.swing.event.ChangeEvent; |
import javax.swing.event.ChangeListener; |
||||||
import javax.swing.event.ChangeListener; |
import java.awt.*; |
||||||
import java.awt.*; |
|
||||||
|
/** |
||||||
/** |
* @author zhou |
||||||
* @author zhou |
* @since 2012-5-30上午10:36:21 |
||||||
* @since 2012-5-30上午10:36:21 |
*/ |
||||||
*/ |
public class GradientBackgroundQuickPane extends BackgroundQuickPane { |
||||||
public class GradientPane extends BackgroundSettingPane { |
private static final long serialVersionUID = -6854603990673031897L; |
||||||
private static final long serialVersionUID = -6854603990673031897L; |
|
||||||
|
private static final int DEFAULT_GRADIENT_WIDTH = 185; |
||||||
private static final int DEFAULT_GRADIENT_WIDTH = 185; |
|
||||||
|
private int gradientBarWidth = DEFAULT_GRADIENT_WIDTH; |
||||||
private int gradientBarWidth = DEFAULT_GRADIENT_WIDTH; |
|
||||||
|
private GradientBar gradientBar; |
||||||
private GradientBar gradientBar; |
private UIButtonGroup<Integer> directionPane; |
||||||
private UIButtonGroup<Integer> directionPane; |
|
||||||
|
public GradientBackgroundQuickPane() { |
||||||
public GradientPane() { |
constructPane(); |
||||||
constructPane(); |
} |
||||||
} |
|
||||||
|
public GradientBackgroundQuickPane(int gradientBarWidth) { |
||||||
public GradientPane(int gradientBarWidth) { |
this.gradientBarWidth = gradientBarWidth; |
||||||
this.gradientBarWidth = gradientBarWidth; |
constructPane(); |
||||||
constructPane(); |
} |
||||||
} |
|
||||||
|
private void constructPane(){ |
||||||
private void constructPane(){ |
String[] textArray = {Inter.getLocText("Utils-Left_to_Right"), Inter.getLocText("Utils-Top_to_Bottom")}; |
||||||
String[] textArray = {Inter.getLocText("Utils-Left_to_Right"), Inter.getLocText("Utils-Top_to_Bottom")}; |
Integer[] valueArray = {GradientBackground.LEFT2RIGHT, GradientBackground.TOP2BOTTOM}; |
||||||
Integer[] valueArray = {GradientBackground.LEFT2RIGHT, GradientBackground.TOP2BOTTOM}; |
directionPane = new UIButtonGroup<Integer>(textArray, valueArray); |
||||||
directionPane = new UIButtonGroup<Integer>(textArray, valueArray); |
directionPane.setSelectedIndex(0); |
||||||
directionPane.setSelectedIndex(0); |
gradientBar = new GradientBar(4, this.gradientBarWidth); |
||||||
gradientBar = new GradientBar(4, this.gradientBarWidth); |
|
||||||
|
double p = TableLayout.PREFERRED; |
||||||
double p = TableLayout.PREFERRED; |
double f = TableLayout.FILL; |
||||||
double f = TableLayout.FILL; |
double[] columnSize = {p, f}; |
||||||
double[] columnSize = {p, f}; |
double[] rowSize = {p, p,}; |
||||||
double[] rowSize = {p, p,}; |
|
||||||
|
Component[][] components = new Component[][]{ |
||||||
Component[][] components = new Component[][]{ |
new Component[]{gradientBar, null}, |
||||||
new Component[]{gradientBar, null}, |
new Component[]{new UILabel(Inter.getLocText("Gradient-Direction") + ":"), directionPane} |
||||||
new Component[]{new UILabel(Inter.getLocText("Gradient-Direction") + ":"), directionPane} |
}; |
||||||
}; |
JPanel Gradient = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
||||||
JPanel Gradient = TableLayoutHelper.createTableLayoutPane(components, rowSize, columnSize); |
this.setLayout(new BorderLayout()); |
||||||
this.setLayout(new BorderLayout()); |
this.add(Gradient, BorderLayout.CENTER); |
||||||
this.add(Gradient, BorderLayout.CENTER); |
} |
||||||
} |
|
||||||
|
public void populateBean(Background background) { |
||||||
public void populateBean(Background background) { |
GradientBackground bg = (GradientBackground) background; |
||||||
GradientBackground bg = (GradientBackground) background; |
this.gradientBar.getSelectColorPointBtnP1().setColorInner(bg.getStartColor()); |
||||||
this.gradientBar.getSelectColorPointBtnP1().setColorInner(bg.getStartColor()); |
this.gradientBar.getSelectColorPointBtnP2().setColorInner(bg.getEndColor()); |
||||||
this.gradientBar.getSelectColorPointBtnP2().setColorInner(bg.getEndColor()); |
directionPane.setSelectedItem(bg.getDirection()); |
||||||
directionPane.setSelectedItem(bg.getDirection()); |
if (bg.isUseCell()) { |
||||||
if (bg.isUseCell()) { |
return; |
||||||
return; |
} |
||||||
} |
double startValue = (double) bg.getBeginPlace(); |
||||||
double startValue = (double) bg.getBeginPlace(); |
double endValue = (double) bg.getFinishPlace(); |
||||||
double endValue = (double) bg.getFinishPlace(); |
gradientBar.setStartValue(startValue); |
||||||
gradientBar.setStartValue(startValue); |
gradientBar.setEndValue(endValue); |
||||||
gradientBar.setEndValue(endValue); |
if(this.gradientBar.getSelectColorPointBtnP1() != null && this.gradientBar.getSelectColorPointBtnP2() != null){ |
||||||
if(this.gradientBar.getSelectColorPointBtnP1() != null && this.gradientBar.getSelectColorPointBtnP2() != null){ |
this.gradientBar.getSelectColorPointBtnP1().setX(startValue); |
||||||
this.gradientBar.getSelectColorPointBtnP1().setX(startValue); |
this.gradientBar.getSelectColorPointBtnP2().setX(endValue); |
||||||
this.gradientBar.getSelectColorPointBtnP2().setX(endValue); |
} |
||||||
} |
this.gradientBar.repaint(); |
||||||
this.gradientBar.repaint(); |
} |
||||||
} |
|
||||||
|
public GradientBackground updateBean() { |
||||||
public GradientBackground updateBean() { |
GradientBackground gb = new GradientBackground(gradientBar.getSelectColorPointBtnP1().getColorInner(), gradientBar.getSelectColorPointBtnP2().getColorInner()); |
||||||
GradientBackground gb = new GradientBackground(gradientBar.getSelectColorPointBtnP1().getColorInner(), gradientBar.getSelectColorPointBtnP2().getColorInner()); |
gb.setDirection(directionPane.getSelectedItem()); |
||||||
gb.setDirection(directionPane.getSelectedItem()); |
if (gradientBar.isOriginalPlace()) { |
||||||
if (gradientBar.isOriginalPlace()) { |
gb.setUseCell(true); |
||||||
gb.setUseCell(true); |
} else { |
||||||
} else { |
gb.setUseCell(false); |
||||||
gb.setUseCell(false); |
gb.setBeginPlace((float) gradientBar.getStartValue()); |
||||||
gb.setBeginPlace((float) gradientBar.getStartValue()); |
gb.setFinishPlace((float) gradientBar.getEndValue()); |
||||||
gb.setFinishPlace((float) gradientBar.getEndValue()); |
} |
||||||
} |
return gb; |
||||||
return gb; |
} |
||||||
} |
|
||||||
|
/** |
||||||
/** |
* 给组件登记一个观察者监听事件 |
||||||
* 给组件登记一个观察者监听事件 |
* |
||||||
* |
* @param listener 观察者监听事件 |
||||||
* @param listener 观察者监听事件 |
*/ |
||||||
*/ |
public void registerChangeListener(final UIObserverListener listener) { |
||||||
public void registerChangeListener(final UIObserverListener listener) { |
gradientBar.addChangeListener(new ChangeListener() { |
||||||
gradientBar.addChangeListener(new ChangeListener() { |
public void stateChanged(ChangeEvent e) { |
||||||
public void stateChanged(ChangeEvent e) { |
listener.doChange(); |
||||||
listener.doChange(); |
} |
||||||
} |
}); |
||||||
}); |
directionPane.addChangeListener(new ChangeListener() { |
||||||
directionPane.addChangeListener(new ChangeListener() { |
public void stateChanged(ChangeEvent e) { |
||||||
public void stateChanged(ChangeEvent e) { |
listener.doChange(); |
||||||
listener.doChange(); |
} |
||||||
} |
}); |
||||||
}); |
} |
||||||
} |
|
||||||
|
@Override |
||||||
@Override |
public boolean accept(Background background) { |
||||||
public boolean accept(Background background) { |
return background instanceof GradientBackground; |
||||||
return background instanceof GradientBackground; |
} |
||||||
} |
|
||||||
|
@Override |
||||||
@Override |
public String title4PopupWindow() { |
||||||
public String title4PopupWindow() { |
return Inter.getLocText("Gradient-Color"); |
||||||
return Inter.getLocText("Gradient-Color"); |
} |
||||||
} |
|
||||||
|
|
||||||
} |
} |
Loading…
Reference in new issue