Browse Source

CHART-2521 图表配色

master
zheng 6 years ago
parent
commit
f82eb21d59
  1. 7
      designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/style/ChartFillStylePane.java
  2. 149
      designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/style/ChartPreFillStylePane.java
  3. 5
      designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/AbstractChartTypePane.java
  4. 4
      designer-chart/src/main/java/com/fr/design/module/ChartPreStyleAction.java
  5. 29
      designer-chart/src/main/java/com/fr/design/module/ChartPreStyleManagerPane.java
  6. 22
      designer-chart/src/main/java/com/fr/design/module/ChartPreStylePane.java

7
designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/style/ChartFillStylePane.java

@ -1,10 +1,11 @@
package com.fr.design.mainframe.chart.gui.style; package com.fr.design.mainframe.chart.gui.style;
import com.fr.base.ChartColorMatching;
import com.fr.base.ChartPreStyleConfig; import com.fr.base.ChartPreStyleConfig;
import com.fr.base.Utils; import com.fr.base.Utils;
import com.fr.chart.base.AttrFillStyle; import com.fr.chart.base.AttrFillStyle;
import com.fr.chart.base.ChartConstants; import com.fr.chart.base.ChartConstants;
import com.fr.chart.base.ChartPreStyle; import com.fr.chart.base.ChartUtils;
import com.fr.design.beans.BasicBeanPane; import com.fr.design.beans.BasicBeanPane;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.icombobox.UIComboBox;
@ -199,8 +200,8 @@ public class ChartFillStylePane extends BasicBeanPane<AttrFillStyle>{
} else if(styleSelectBox.getSelectedIndex() < styleSelectBox.getItemCount() - 1){ } else if(styleSelectBox.getSelectedIndex() < styleSelectBox.getItemCount() - 1){
ChartPreStyleConfig manager = ChartPreStyleConfig.getInstance(); ChartPreStyleConfig manager = ChartPreStyleConfig.getInstance();
Object preStyle = manager.getPreStyle(styleSelectBox.getSelectedItem()); Object preStyle = manager.getPreStyle(styleSelectBox.getSelectedItem());
if(preStyle instanceof ChartPreStyle) { if (preStyle instanceof ChartColorMatching) {
AttrFillStyle def = ((ChartPreStyle) preStyle).getAttrFillStyle(); AttrFillStyle def = ChartUtils.chartColorMatching2AttrFillStyle((ChartColorMatching) preStyle);
def.setFillStyleName(Utils.objectToString(styleSelectBox.getSelectedItem())); def.setFillStyleName(Utils.objectToString(styleSelectBox.getSelectedItem()));
return def; return def;
}else{ }else{

149
designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/style/ChartPreFillStylePane.java

@ -1,26 +1,73 @@
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> {
private JPanel changeColorSetPane;
private CardLayout cardLayout;
private UIButton accButton;
private UIButton gradientButton;
private ChartAccColorPane colorAcc;
private FixedGradientBar colorGradient;
private ChartColorMatching chartColorMatching;
public ChartPreFillStylePane() { public ChartPreFillStylePane() {
initComponents();
initListener();
} }
protected void initLayout() {// 仅仅是服务器预定 风格界面布局, 和属性表 有所不同. 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)); customPane.setPreferredSize(new Dimension(200, 200));
colorGradient.setPreferredSize(new Dimension(120, 30)); colorGradient.setPreferredSize(new Dimension(120, 30));
@ -32,66 +79,92 @@ public class ChartPreFillStylePane extends ChartFillStylePane {
new Component[]{null, customPane}, new Component[]{null, customPane},
}; };
this.setLayout(new BorderLayout());
this.add(TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize), BorderLayout.WEST); this.add(TableLayoutHelper.createTableLayoutPane(components,rowSize,columnSize), BorderLayout.WEST);
} }
public void populateBean(AttrFillStyle condition) { private void initListener() {
styleSelectBox.setSelectedIndex(styleSelectBox.getItemCount()-1);
if(condition == null || condition.getColorStyle() == ChartConstants.COLOR_DEFAULT) { accButton.addActionListener(new ActionListener() {
colorAcc.populateBean(ChartConstants.CHART_COLOR_ARRAY);// 新建时 保持默认样式 @Override
public void actionPerformed(ActionEvent e) {
accButton.setSelected(true); accButton.setSelected(true);
gradientButton.setSelected(false); gradientButton.setSelected(false);
cardLayout.show(changeColorSetPane, "acc"); cardLayout.show(changeColorSetPane, "acc");
}
});
gradientButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
gradientButton.setSelected(true);
accButton.setSelected(false);
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.getSelectColorPointBtnP1().setColorInner(Color.WHITE);
colorGradient.getSelectColorPointBtnP2().setColorInner(Color.black);// 控件中的位置无效. colorGradient.getSelectColorPointBtnP2().setColorInner(Color.black);
} else { colorAcc.populateBean(ChartConstants.CHART_COLOR_ARRAY);
int colorStyle = condition.getColorStyle();
gradientButton.setSelected(colorStyle == ChartConstants.COLOR_GRADIENT); if (condition == null) {
accButton.setSelected(colorStyle == ChartConstants.COLOR_ACC); return;
}
int colorSize = condition.getColorSize(); boolean isGradient = condition.getGradient();
if(colorSize == 2 && gradientButton.isSelected() ) { List<Color> colorList = condition.getColorList();
if (isGradient) {
gradientButton.setSelected(true);
accButton.setSelected(false);
cardLayout.show(changeColorSetPane, "gradient"); cardLayout.show(changeColorSetPane, "gradient");
Color endColor = condition.getColorIndex(1); if (colorList.size() == 2) {
Color startColor = condition.getColorIndex(0); colorGradient.getSelectColorPointBtnP1().setColorInner(colorList.get(0));
colorGradient.getSelectColorPointBtnP1().setColorInner(startColor); colorGradient.getSelectColorPointBtnP2().setColorInner(colorList.get(1));
colorGradient.getSelectColorPointBtnP2().setColorInner(endColor);
colorGradient.repaint(); colorGradient.repaint();
} else if(colorSize > 2 && accButton.isSelected()){ }
} else {
accButton.setSelected(true);
gradientButton.setSelected(false);
cardLayout.show(changeColorSetPane, "acc"); 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;
} }
} }

5
designer-chart/src/main/java/com/fr/design/mainframe/chart/gui/type/AbstractChartTypePane.java

@ -1,12 +1,13 @@
package com.fr.design.mainframe.chart.gui.type; package com.fr.design.mainframe.chart.gui.type;
import com.fr.base.ChartColorMatching;
import com.fr.base.ChartPreStyleConfig; import com.fr.base.ChartPreStyleConfig;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.base.background.ColorBackground; import com.fr.base.background.ColorBackground;
import com.fr.chart.base.AttrContents; import com.fr.chart.base.AttrContents;
import com.fr.chart.base.AttrFillStyle; import com.fr.chart.base.AttrFillStyle;
import com.fr.chart.base.ChartConstants; import com.fr.chart.base.ChartConstants;
import com.fr.chart.base.ChartPreStyle; import com.fr.chart.base.ChartUtils;
import com.fr.chart.base.DataSeriesCondition; import com.fr.chart.base.DataSeriesCondition;
import com.fr.chart.base.TextAttr; import com.fr.chart.base.TextAttr;
import com.fr.chart.chartattr.Axis; import com.fr.chart.chartattr.Axis;
@ -243,7 +244,7 @@ public abstract class AbstractChartTypePane extends FurtherBasicBeanPane<Chart>{
if(preStyle == null){ if(preStyle == null){
plot.getPlotFillStyle().setColorStyle(ChartConstants.COLOR_DEFAULT); plot.getPlotFillStyle().setColorStyle(ChartConstants.COLOR_DEFAULT);
}else{ }else{
AttrFillStyle fillStyle = ((ChartPreStyle)preStyle).getAttrFillStyle(); AttrFillStyle fillStyle = ChartUtils.chartColorMatching2AttrFillStyle((ChartColorMatching) preStyle);
fillStyle.setFillStyleName(name); fillStyle.setFillStyleName(name);
plot.setPlotFillStyle(fillStyle); plot.setPlotFillStyle(fillStyle);
} }

4
designer-chart/src/main/java/com/fr/design/module/ChartPreStyleAction.java

@ -39,14 +39,10 @@ public class ChartPreStyleAction extends UpdateAction {
@Override @Override
public void doOk() { public void doOk() {
pane.updateBean(); pane.updateBean();
// ChartPreStyleManagerProvider manager = ChartPreStyleServerManager.getProviderInstance();
// manager.setStyleEditing(null);
} }
@Override @Override
public void doCancel() { public void doCancel() {
// ChartPreStyleManagerProvider manager = ChartPreStyleServerManager.getProviderInstance();
// manager.setStyleEditing(null);
} }
}); });

29
designer-chart/src/main/java/com/fr/design/module/ChartPreStyleManagerPane.java

@ -1,8 +1,8 @@
package com.fr.design.module; package com.fr.design.module;
import com.fr.base.ChartColorMatching;
import com.fr.base.ChartPreStyleConfig; import com.fr.base.ChartPreStyleConfig;
import com.fr.base.Utils; import com.fr.base.Utils;
import com.fr.chart.base.ChartPreStyle;
import com.fr.design.gui.controlpane.JListControlPane; import com.fr.design.gui.controlpane.JListControlPane;
import com.fr.design.gui.controlpane.NameObjectCreator; import com.fr.design.gui.controlpane.NameObjectCreator;
import com.fr.design.gui.controlpane.NameableCreator; import com.fr.design.gui.controlpane.NameableCreator;
@ -10,11 +10,11 @@ import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.DesignerFrame; import com.fr.design.mainframe.DesignerFrame;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.general.NameObject; import com.fr.general.NameObject;
import com.fr.stable.ListMap;
import com.fr.stable.Nameable; import com.fr.stable.Nameable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap;
/** /**
@ -32,10 +32,18 @@ public class ChartPreStyleManagerPane extends JListControlPane {
public NameableCreator[] createNameableCreators() { public NameableCreator[] createNameableCreators() {
return new NameableCreator[]{ return new NameableCreator[]{
new NameObjectCreator(Inter.getLocText("FR-Designer_PreStyle"), new NameObjectCreator(Inter.getLocText("FR-Designer_PreStyle"),
ChartPreStyle.class, ChartPreStylePane.class) ChartColorMatching.class, ChartPreStylePane.class)
}; };
} }
@Override
public void addNameable(Nameable nameable, int index) {
super.addNameable(nameable, index);
if (!ChartPreStyleConfig.getInstance().containsName(nameable.getName())) {
ChartPreStyleConfig.getInstance().putPreStyle(nameable.getName(), ((NameObject) nameable).getObject());
}
}
@Override @Override
protected String title4PopupWindow() { protected String title4PopupWindow() {
return Inter.getLocText("FR-Designer_Chart-PreStyle"); return Inter.getLocText("FR-Designer_Chart-PreStyle");
@ -49,7 +57,7 @@ public class ChartPreStyleManagerPane extends JListControlPane {
Iterator keys = config.names(); Iterator keys = config.names();
while(keys.hasNext()) { while(keys.hasNext()) {
Object key = keys.next(); Object key = keys.next();
ChartPreStyle value = (ChartPreStyle)config.getPreStyle(key); ChartColorMatching value = (ChartColorMatching) config.getPreStyle(key);
list.add(new NameObject(Utils.objectToString(key), value)); list.add(new NameObject(Utils.objectToString(key), value));
} }
@ -65,15 +73,20 @@ public class ChartPreStyleManagerPane extends JListControlPane {
public void updateBean() { public void updateBean() {
ChartPreStyleConfig config = ChartPreStyleConfig.getInstance(); ChartPreStyleConfig config = ChartPreStyleConfig.getInstance();
config.setPreStyleMap(new ListMap()); config.setCurrentStyle(getSelectedName());
Nameable[] values = this.update(); Nameable[] values = this.update();
config.setPreStyleMap(new LinkedHashMap());
config.setCurrentStyle(getSelectedName());
for(int i = 0; i < values.length; i++) { for(int i = 0; i < values.length; i++) {
Nameable value = values[i]; Nameable value = values[i];
config.putPreStyle(value.getName(), ((NameObject)value).getObject()); ChartColorMatching chartColorMatching = (ChartColorMatching) ((NameObject) value).getObject();
try {
chartColorMatching = (ChartColorMatching) chartColorMatching.clone();
} catch (CloneNotSupportedException e) {
//do nothing
}
config.putPreStyle(value.getName(), chartColorMatching);
} }
// 通知报表整个刷新. // 通知报表整个刷新.

22
designer-chart/src/main/java/com/fr/design/module/ChartPreStylePane.java

@ -1,9 +1,11 @@
package com.fr.design.module; package com.fr.design.module;
import com.fr.chart.base.ChartPreStyle; import com.fr.base.ChartColorMatching;
import com.fr.chart.base.ChartUtils;
import com.fr.chart.chartattr.Bar2DPlot; import com.fr.chart.chartattr.Bar2DPlot;
import com.fr.chart.chartattr.Chart; import com.fr.chart.chartattr.Chart;
import com.fr.chart.chartattr.ChartCollection; import com.fr.chart.chartattr.ChartCollection;
import com.fr.chart.chartattr.Plot;
import com.fr.design.beans.BasicBeanPane; import com.fr.design.beans.BasicBeanPane;
import com.fr.design.chart.gui.ChartComponent; import com.fr.design.chart.gui.ChartComponent;
import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserver;
@ -25,7 +27,7 @@ import java.awt.FlowLayout;
* @author kunsnat E-mail:kunsnat@gmail.com * @author kunsnat E-mail:kunsnat@gmail.com
* @version 创建时间2013-8-20 下午05:02:00 * @version 创建时间2013-8-20 下午05:02:00
*/ */
public class ChartPreStylePane extends BasicBeanPane<ChartPreStyle>{ public class ChartPreStylePane extends BasicBeanPane<ChartColorMatching> {
private ChartPreFillStylePane fillStylePane; private ChartPreFillStylePane fillStylePane;
private ChartComponent chartComponent; private ChartComponent chartComponent;
@ -79,27 +81,25 @@ public class ChartPreStylePane extends BasicBeanPane<ChartPreStyle>{
} }
} }
private void refreshWhenStyleChange(ChartPreStyle preStyle) { private void refreshWhenStyleChange(ChartColorMatching preStyle) {
// ChartPreStyleManagerProvider manager = ChartPreStyleServerManager.getProviderInstance();
// manager.setStyleEditing(preStyle);
if(chartComponent != null) { if(chartComponent != null) {
Plot plot = (Plot) chartComponent.getEditingChart().getBasePlot();
plot.setPlotFillStyle(ChartUtils.chartColorMatching2AttrFillStyle(preStyle));
chartComponent.reset(); chartComponent.reset();
} }
} }
@Override @Override
public void populateBean(ChartPreStyle preStyle) { public void populateBean(ChartColorMatching preStyle) {
fillStylePane.populateBean(preStyle.getAttrFillStyle()); fillStylePane.populateBean(preStyle);
refreshWhenStyleChange(preStyle); refreshWhenStyleChange(preStyle);
} }
@Override @Override
public ChartPreStyle updateBean() { public ChartColorMatching updateBean() {
ChartPreStyle preStyle = new ChartPreStyle(); return fillStylePane.updateBean();
preStyle.setAttrFillStyle(fillStylePane.updateBean());
return preStyle;
} }
@Override @Override

Loading…
Cancel
Save