forked from fanruan/design
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; |
||||||
|
|
||||||
/* |
|
||||||
* 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.base.Style; |
||||||
|
import com.fr.design.ExtraDesignClassManager; |
||||||
|
import com.fr.design.fun.BackgroundQuickUIProvider; |
||||||
import com.fr.design.gui.icombobox.UIComboBox; |
import com.fr.design.gui.icombobox.UIComboBox; |
||||||
import com.fr.design.mainframe.backgroundpane.BackgroundSettingPane; |
import com.fr.design.mainframe.backgroundpane.*; |
||||||
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.Background; |
||||||
import com.fr.general.Inter; |
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 |
* @author zhou |
||||||
* @since 2012-5-28下午6:22:09 |
* @since 2012-5-28下午6:22:09 |
||||||
*/ |
*/ |
||||||
public class BackgroundPane extends AbstractBasicStylePane { |
public class BackgroundPane extends AbstractBasicStylePane { |
||||||
|
|
||||||
private UIComboBox typeComboBox; |
private UIComboBox typeComboBox; |
||||||
|
|
||||||
protected List<BackgroundSettingPane> paneList; |
protected BackgroundQuickPane[] paneList; |
||||||
|
|
||||||
public BackgroundPane() { |
public BackgroundPane() { |
||||||
this.initComponents(); |
this.initComponents(); |
||||||
} |
} |
||||||
|
|
||||||
protected void initComponents() { |
protected void initComponents() { |
||||||
this.setLayout(new BorderLayout(0, 6)); |
this.setLayout(new BorderLayout(0, 6)); |
||||||
typeComboBox = new UIComboBox(); |
typeComboBox = new UIComboBox(); |
||||||
final CardLayout cardlayout = new CardLayout(); |
final CardLayout cardlayout = new CardLayout(); |
||||||
this.add(typeComboBox, BorderLayout.NORTH); |
this.add(typeComboBox, BorderLayout.NORTH); |
||||||
|
|
||||||
initPaneList(); |
paneList = supportKindsOfBackgroundUI(); |
||||||
final JPanel centerPane = new JPanel(cardlayout) { |
|
||||||
@Override |
final JPanel centerPane = new JPanel(cardlayout) { |
||||||
public Dimension getPreferredSize() {// AUGUST:使用当前面板的的高度
|
@Override |
||||||
int index = typeComboBox.getSelectedIndex(); |
public Dimension getPreferredSize() {// AUGUST:使用当前面板的的高度
|
||||||
return new Dimension(super.getPreferredSize().width, paneList.get(index).getPreferredSize().height); |
int index = typeComboBox.getSelectedIndex(); |
||||||
} |
return new Dimension(super.getPreferredSize().width, paneList[index].getPreferredSize().height); |
||||||
}; |
} |
||||||
for (int i = 0; i < paneList.size(); i++) { |
}; |
||||||
BackgroundSettingPane pane = paneList.get(i); |
for (BackgroundQuickPane pane : paneList) { |
||||||
typeComboBox.addItem(pane.title4PopupWindow()); |
typeComboBox.addItem(pane.title4PopupWindow()); |
||||||
centerPane.add(pane, pane.title4PopupWindow()); |
centerPane.add(pane, pane.title4PopupWindow()); |
||||||
} |
} |
||||||
this.add(centerPane, BorderLayout.CENTER); |
this.add(centerPane, BorderLayout.CENTER); |
||||||
typeComboBox.addItemListener(new ItemListener() { |
typeComboBox.addItemListener(new ItemListener() { |
||||||
|
|
||||||
@Override |
@Override |
||||||
public void itemStateChanged(ItemEvent e) { |
public void itemStateChanged(ItemEvent e) { |
||||||
cardlayout.show(centerPane, (String)typeComboBox.getSelectedItem()); |
cardlayout.show(centerPane, (String) typeComboBox.getSelectedItem()); |
||||||
fireStateChanged(); |
fireStateChanged(); |
||||||
} |
} |
||||||
}); |
}); |
||||||
} |
} |
||||||
|
|
||||||
protected void initPaneList(){ |
protected BackgroundQuickPane[] supportKindsOfBackgroundUI() { |
||||||
paneList = new ArrayList<BackgroundSettingPane>(); |
java.util.List<BackgroundQuickPane> kinds = new ArrayList<>(); |
||||||
paneList.add(new NullBackgroundPane()); |
kinds.add(new NullBackgroundQuickPane()); |
||||||
paneList.add(new ColorBackgroundPane()); |
kinds.add(new ColorBackgroundQuickPane()); |
||||||
paneList.add(new TextureBackgroundPane()); |
kinds.add(new TextureBackgroundQuickPane()); |
||||||
paneList.add(new PatternBackgroundPane()); |
kinds.add(new PatternBackgroundQuickPane()); |
||||||
paneList.add(new ImageBackgroundPane()); |
kinds.add(new ImageBackgroundQuickPane()); |
||||||
paneList.add(new GradientPane()); |
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) { |
public void addChangeListener(ChangeListener changeListener) { |
||||||
listenerList.add(ChangeListener.class, changeListener); |
listenerList.add(ChangeListener.class, changeListener); |
||||||
} |
} |
||||||
|
|
||||||
/** |
/** |
||||||
*/ |
*/ |
||||||
protected void fireStateChanged() { |
protected void fireStateChanged() { |
||||||
Object[] listeners = listenerList.getListenerList(); |
Object[] listeners = listenerList.getListenerList(); |
||||||
ChangeEvent e = null; |
ChangeEvent e = null; |
||||||
|
|
||||||
for (int i = listeners.length - 2; i >= 0; i -= 2) { |
for (int i = listeners.length - 2; i >= 0; i -= 2) { |
||||||
if (listeners[i] == ChangeListener.class) { |
if (listeners[i] == ChangeListener.class) { |
||||||
if (e == null) { |
if (e == null) { |
||||||
e = new ChangeEvent(this); |
e = new ChangeEvent(this); |
||||||
} |
} |
||||||
((ChangeListener)listeners[i + 1]).stateChanged(e); |
((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() { |
public Background update() { |
||||||
return Inter.getLocText("FR-Utils_Background"); |
return paneList[typeComboBox.getSelectedIndex()].updateBean(); |
||||||
} |
} |
||||||
|
|
||||||
/** |
@Override |
||||||
* Populate background. |
public void populateBean(Style style) { |
||||||
*/ |
this.populateBean(style.getBackground()); |
||||||
public void populateBean(Background background) { |
} |
||||||
for (int i = 0; i < paneList.size(); i++) { |
|
||||||
BackgroundSettingPane pane = paneList.get(i); |
@Override |
||||||
if (pane.accept(background)) { |
public Style update(Style style) { |
||||||
pane.populateBean(background); |
return style.deriveBackground(this.update()); |
||||||
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()); |
|
||||||
} |
|
||||||
|
|
||||||
} |
} |
Loading…
Reference in new issue