6 changed files with 174 additions and 90 deletions
@ -1,97 +1,170 @@ |
|||||||
package com.fr.design.mainframe.chart.gui.style; |
package com.fr.design.mainframe.chart.gui.style; |
||||||
|
|
||||||
import java.awt.*; |
import com.fr.base.ChartColorMatching; |
||||||
|
|
||||||
import com.fr.chart.base.AttrFillStyle; |
|
||||||
import com.fr.chart.base.ChartConstants; |
import com.fr.chart.base.ChartConstants; |
||||||
|
import com.fr.design.beans.BasicBeanPane; |
||||||
|
import com.fr.design.gui.ibutton.UIButton; |
||||||
import com.fr.design.gui.ilable.UILabel; |
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
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.style.background.gradient.FixedGradientBar; |
||||||
import com.fr.general.Inter; |
import com.fr.general.Inter; |
||||||
|
|
||||||
|
import javax.swing.JPanel; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.CardLayout; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.FlowLayout; |
||||||
|
import java.awt.event.ActionEvent; |
||||||
|
import java.awt.event.ActionListener; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
|
||||||
/** |
/** |
||||||
* 预定义的图表配色界面, 其中和属性表中ChartFillStylePane 主要的不同就是标签的位置. |
* 预定义的图表配色界面. |
||||||
* @author kunsnat E-mail:kunsnat@gmail.com |
* @author kunsnat E-mail:kunsnat@gmail.com |
||||||
* @version 创建时间:2013-8-21 下午03:16:27 |
* @version 创建时间:2013-8-21 下午03:16:27 |
||||||
*/ |
*/ |
||||||
public class ChartPreFillStylePane extends ChartFillStylePane { |
public class ChartPreFillStylePane extends BasicBeanPane<ChartColorMatching> { |
||||||
|
|
||||||
public ChartPreFillStylePane() { |
private JPanel changeColorSetPane; |
||||||
|
private CardLayout cardLayout; |
||||||
} |
|
||||||
|
private UIButton accButton; |
||||||
protected void initLayout() {// 仅仅是服务器预定 风格界面布局, 和属性表 有所不同.
|
private UIButton gradientButton; |
||||||
customPane.setPreferredSize(new Dimension(200, 200)); |
|
||||||
colorGradient.setPreferredSize(new Dimension(120, 30)); |
private ChartAccColorPane colorAcc; |
||||||
|
private FixedGradientBar colorGradient; |
||||||
double p = TableLayout.PREFERRED; |
|
||||||
double[] columnSize = {p, p }; |
private ChartColorMatching chartColorMatching; |
||||||
double[] rowSize = { p, p, p}; |
|
||||||
|
public ChartPreFillStylePane() { |
||||||
|
|
||||||
|
initComponents(); |
||||||
|
|
||||||
|
initListener(); |
||||||
|
} |
||||||
|
|
||||||
|
private void initComponents() { |
||||||
|
|
||||||
|
JPanel customPane = new JPanel(FRGUIPaneFactory.createBorderLayout()); |
||||||
|
|
||||||
|
JPanel buttonPane = new JPanel(); |
||||||
|
buttonPane.setLayout(new FlowLayout(FlowLayout.LEFT)); |
||||||
|
buttonPane.add(accButton = new UIButton(Inter.getLocText("FR-Designer_Chart_Acc_Set"))); |
||||||
|
buttonPane.add(gradientButton = new UIButton(Inter.getLocText("FR-Designer_Gradient-Color"))); |
||||||
|
customPane.add(buttonPane, BorderLayout.NORTH); |
||||||
|
|
||||||
|
changeColorSetPane = new JPanel(cardLayout = new CardLayout()); |
||||||
|
changeColorSetPane.add(colorGradient = new FixedGradientBar(4, 130), "gradient"); |
||||||
|
changeColorSetPane.add(colorAcc = new ChartAccColorPane(), "acc"); |
||||||
|
cardLayout.show(changeColorSetPane, "acc"); |
||||||
|
customPane.add(changeColorSetPane, BorderLayout.CENTER); |
||||||
|
|
||||||
|
accButton.setSelected(true); |
||||||
|
|
||||||
|
customPane.setPreferredSize(new Dimension(200, 200)); |
||||||
|
colorGradient.setPreferredSize(new Dimension(120, 30)); |
||||||
|
|
||||||
|
double p = TableLayout.PREFERRED; |
||||||
|
double[] columnSize = {p, p}; |
||||||
|
double[] rowSize = {p, p, p}; |
||||||
Component[][] components = new Component[][]{ |
Component[][] components = new Component[][]{ |
||||||
new Component[]{new UILabel(" " + Inter.getLocText("ColorMatch")), null}, |
new Component[]{new UILabel(" " + Inter.getLocText("ColorMatch")), null}, |
||||||
new Component[]{null, customPane}, |
new Component[]{null, customPane}, |
||||||
}; |
}; |
||||||
|
|
||||||
this.add(TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize), BorderLayout.WEST); |
|
||||||
} |
|
||||||
|
|
||||||
public void populateBean(AttrFillStyle condition) { |
this.setLayout(new BorderLayout()); |
||||||
styleSelectBox.setSelectedIndex(styleSelectBox.getItemCount()-1); |
this.add(TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize), BorderLayout.WEST); |
||||||
|
} |
||||||
|
|
||||||
if(condition == null || condition.getColorStyle() == ChartConstants.COLOR_DEFAULT) { |
private void initListener() { |
||||||
colorAcc.populateBean(ChartConstants.CHART_COLOR_ARRAY);// 新建时 保持默认样式
|
|
||||||
accButton.setSelected(true); |
|
||||||
gradientButton.setSelected(false); |
|
||||||
cardLayout.show(changeColorSetPane, "acc"); |
|
||||||
|
|
||||||
colorGradient.getSelectColorPointBtnP1().setColorInner(Color.WHITE); |
accButton.addActionListener(new ActionListener() { |
||||||
colorGradient.getSelectColorPointBtnP2().setColorInner(Color.black);// 控件中的位置无效.
|
@Override |
||||||
} else { |
public void actionPerformed(ActionEvent e) { |
||||||
int colorStyle = condition.getColorStyle(); |
accButton.setSelected(true); |
||||||
gradientButton.setSelected(colorStyle == ChartConstants.COLOR_GRADIENT); |
gradientButton.setSelected(false); |
||||||
accButton.setSelected(colorStyle == ChartConstants.COLOR_ACC); |
cardLayout.show(changeColorSetPane, "acc"); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
int colorSize = condition.getColorSize(); |
gradientButton.addActionListener(new ActionListener() { |
||||||
if(colorSize == 2 && gradientButton.isSelected() ) { |
@Override |
||||||
|
public void actionPerformed(ActionEvent e) { |
||||||
|
gradientButton.setSelected(true); |
||||||
|
accButton.setSelected(false); |
||||||
cardLayout.show(changeColorSetPane, "gradient"); |
cardLayout.show(changeColorSetPane, "gradient"); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
|
return Inter.getLocText("ServerM-Predefined_Styles"); |
||||||
|
} |
||||||
|
|
||||||
|
public void populateBean(ChartColorMatching condition) { |
||||||
|
chartColorMatching = condition; |
||||||
|
|
||||||
|
colorGradient.getSelectColorPointBtnP1().setColorInner(Color.WHITE); |
||||||
|
colorGradient.getSelectColorPointBtnP2().setColorInner(Color.black); |
||||||
|
colorAcc.populateBean(ChartConstants.CHART_COLOR_ARRAY); |
||||||
|
|
||||||
|
if (condition == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
Color endColor = condition.getColorIndex(1); |
boolean isGradient = condition.getGradient(); |
||||||
Color startColor = condition.getColorIndex(0); |
List<Color> colorList = condition.getColorList(); |
||||||
colorGradient.getSelectColorPointBtnP1().setColorInner(startColor); |
if (isGradient) { |
||||||
colorGradient.getSelectColorPointBtnP2().setColorInner(endColor); |
gradientButton.setSelected(true); |
||||||
|
accButton.setSelected(false); |
||||||
|
cardLayout.show(changeColorSetPane, "gradient"); |
||||||
|
|
||||||
|
if (colorList.size() == 2) { |
||||||
|
colorGradient.getSelectColorPointBtnP1().setColorInner(colorList.get(0)); |
||||||
|
colorGradient.getSelectColorPointBtnP2().setColorInner(colorList.get(1)); |
||||||
colorGradient.repaint(); |
colorGradient.repaint(); |
||||||
} else if(colorSize > 2 && accButton.isSelected()){ |
} |
||||||
cardLayout.show(changeColorSetPane, "acc"); |
} else { |
||||||
|
accButton.setSelected(true); |
||||||
|
gradientButton.setSelected(false); |
||||||
|
cardLayout.show(changeColorSetPane, "acc"); |
||||||
|
|
||||||
Color[] colors = new Color[colorSize]; |
if (colorList.size() > 0) { |
||||||
for(int i = 0; i < colorSize; i++) { |
colorAcc.populateBean(colorList.toArray(new Color[colorList.size()])); |
||||||
colors[i] = condition.getColorIndex(i); |
|
||||||
} |
|
||||||
colorAcc.populateBean(colors); |
|
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
@Override |
@Override |
||||||
public AttrFillStyle updateBean() { |
public ChartColorMatching updateBean() { |
||||||
AttrFillStyle condition = new AttrFillStyle(); |
chartColorMatching = chartColorMatching == null ? new ChartColorMatching() : chartColorMatching; |
||||||
condition.clearColors(); |
|
||||||
|
List<Color> colorList = new ArrayList<Color>(); |
||||||
|
|
||||||
if(gradientButton.isSelected()) { |
if(gradientButton.isSelected()) { |
||||||
condition.setColorStyle(ChartConstants.COLOR_GRADIENT); |
chartColorMatching.setGradient(true); |
||||||
|
|
||||||
Color start = colorGradient.getSelectColorPointBtnP1().getColorInner(); |
Color start = colorGradient.getSelectColorPointBtnP1().getColorInner(); |
||||||
Color end = colorGradient.getSelectColorPointBtnP2().getColorInner(); |
Color end = colorGradient.getSelectColorPointBtnP2().getColorInner(); |
||||||
condition.addFillColor(start); |
colorList.add(start); |
||||||
condition.addFillColor(end); |
colorList.add(end); |
||||||
} else { |
} else { |
||||||
condition.setColorStyle(ChartConstants.COLOR_ACC); |
chartColorMatching.setGradient(false); |
||||||
|
|
||||||
Color[] colors = colorAcc.updateBean(); |
Color[] colors = colorAcc.updateBean(); |
||||||
for(int i = 0, length = colors.length; i < length; i++) { |
colorList = Arrays.asList(colors); |
||||||
condition.addFillColor(colors[i]); |
|
||||||
} |
|
||||||
} |
} |
||||||
|
|
||||||
return condition; |
chartColorMatching.setColorList(colorList); |
||||||
|
|
||||||
|
return chartColorMatching; |
||||||
} |
} |
||||||
} |
} |
Loading…
Reference in new issue