Browse Source

Pull request #1823: CHART-12123 图表预定义配色

Merge in DESIGN/design from ~BJORN/design:release/10.0 to release/10.0

* commit '2dc9d95653a042033a30329409dbdb6e314543fb':
  CHART-12123 图表预定义配色
feature/big-screen
Bjorn 4 years ago
parent
commit
f85fac5df6
  1. 13
      designer-chart/src/main/java/com/fr/design/chartx/component/combobox/ColorSchemeComboBox.java
  2. 142
      designer-chart/src/main/java/com/fr/design/module/ChartPreStyleListPane.java
  3. 155
      designer-chart/src/main/java/com/fr/design/module/ChartPreStyleManagerPane.java
  4. 2
      designer-chart/src/main/java/com/fr/design/module/ChartPreStylePane.java

13
designer-chart/src/main/java/com/fr/design/chartx/component/combobox/ColorSchemeComboBox.java

@ -52,7 +52,7 @@ public class ColorSchemeComboBox extends UIComboBox {
this.setRenderer(new ColorSchemeCellRenderer());
}
private Map<String, ColorInfo> getColorSchemesFromConfig() {
protected Map<String, ColorInfo> getColorSchemesFromConfig() {
Map<String, ColorInfo> colorSchemes = new LinkedHashMap<>();
ChartPreStyleConfig config = ChartPreStyleConfig.getInstance();
@ -92,7 +92,14 @@ public class ColorSchemeComboBox extends UIComboBox {
}
public void refresh() {
this.colorSchemes = getColorSchemesFromConfig();
refresh(null);
}
public void refresh(Map<String, ColorInfo> colorSchemes) {
if (colorSchemes == null) {
colorSchemes = getColorSchemesFromConfig();
}
this.colorSchemes = colorSchemes;
this.setModel(new DefaultComboBoxModel(colorSchemes.keySet().toArray()));
}
@ -149,7 +156,7 @@ public class ColorSchemeComboBox extends UIComboBox {
return colorSchemes.keySet();
}
public class ColorInfo {
public static class ColorInfo {
private List<Color> colors;

142
designer-chart/src/main/java/com/fr/design/module/ChartPreStyleListPane.java

@ -0,0 +1,142 @@
package com.fr.design.module;
import com.fr.base.ChartColorMatching;
import com.fr.base.ChartPreStyleConfig;
import com.fr.base.Utils;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.gui.controlpane.JListControlPane;
import com.fr.design.gui.controlpane.NameObjectCreator;
import com.fr.design.gui.controlpane.NameableCreator;
import com.fr.design.gui.controlpane.ShortCut4JControlPane;
import com.fr.design.gui.ilist.ModNameActionListener;
import com.fr.design.menu.ShortCut;
import com.fr.general.NameObject;
import com.fr.stable.Nameable;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.util.ArrayList;
import java.util.Iterator;
/**
* @author Bjorn
* @version 10.0
* Created by Bjorn on 2020-07-08
*/
public class ChartPreStyleListPane extends JListControlPane {
ChartPreStyleManagerPane chartPreStyleManagerPane;
public ChartPreStyleListPane(ChartPreStyleManagerPane chartPreStyleManagerPane) {
super();
this.chartPreStyleManagerPane = chartPreStyleManagerPane;
initListener();
}
/**
* 创建有名字的creator
*
* @return 有名字的creator数组
*/
@Override
public NameableCreator[] createNameableCreators() {
return new NameableCreator[]{
new NameObjectCreator(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_PreStyle_Duplicate"),
ChartColorMatching.class, ChartPreStylePane.class)
};
}
@Override
protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_PreStyle");
}
@Override
public BasicBeanPane createPaneByCreators(NameableCreator creator) {
return new ChartPreStylePane() {
@Override
protected void refreshWhenStyleChange(ChartColorMatching preStyle) {
super.refreshWhenStyleChange(preStyle);
chartPreStyleManagerPane.refreshDefaultColorBox();
}
};
}
protected ShortCut4JControlPane[] createShortcuts() {
return new ShortCut4JControlPane[]{
shortCutFactory.addItemShortCut(),
createRemoveItemShortCut(),
shortCutFactory.copyItemShortCut(),
shortCutFactory.moveUpItemShortCut(),
shortCutFactory.moveDownItemShortCut(),
shortCutFactory.sortItemShortCut()
};
}
private ShortCut4JControlPane createRemoveItemShortCut() {
ShortCut4JControlPane shortCut4JControlPane = shortCutFactory.removeItemShortCut();
//替换删除按钮的check事件。
ShortCut shortCut = shortCut4JControlPane.getShortCut();
shortCut4JControlPane = new MoreThanOneShortCut(shortCut);
return shortCut4JControlPane;
}
public void initListener() {
nameableList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
chartPreStyleManagerPane.refreshDefaultColorBox();
}
});
nameableList.addModNameActionListener(new ModNameActionListener() {
@Override
public void nameModed(int index, String oldName, String newName) {
chartPreStyleManagerPane.refreshDefaultColorBox(oldName, newName);
}
});
}
public void populateBean() {
ChartPreStyleConfig config = ChartPreStyleConfig.getInstance().mirror();
ArrayList list = new ArrayList();
Iterator keys = config.names();
while (keys.hasNext()) {
Object key = keys.next();
ChartColorMatching value = (ChartColorMatching) config.getPreStyle(key);
list.add(new NameObject(Utils.objectToString(key), value));
}
Nameable[] values = (Nameable[]) list.toArray(new Nameable[list.size()]);
populate(values);
if (config.containsName(config.getCurrentStyle())) {
this.setSelectedName(config.getCurrentStyle());
}
}
public void updateBean() {
ChartPreStyleConfig config = ChartPreStyleConfig.getInstance();
Nameable[] values = update();
config.clearAllPreStyle();
for (Nameable value : values) {
config.putPreStyle(value.getName(), ((NameObject) value).getObject());
}
}
private class MoreThanOneShortCut extends ShortCut4JControlPane {
public MoreThanOneShortCut(ShortCut shortCut) {
this.shortCut = shortCut;
}
@Override
public void checkEnable() {
this.shortCut.setEnabled(nameableList.getModel().getSize() > 1);
}
}
}

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

@ -2,72 +2,111 @@ package com.fr.design.module;
import com.fr.base.ChartColorMatching;
import com.fr.base.ChartPreStyleConfig;
import com.fr.base.Utils;
import com.fr.design.gui.controlpane.JListControlPane;
import com.fr.design.gui.controlpane.NameObjectCreator;
import com.fr.design.gui.controlpane.NameableCreator;
import com.fr.design.chartx.component.combobox.ColorSchemeComboBox;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.general.ComparatorUtils;
import com.fr.general.GeneralUtils;
import com.fr.general.NameObject;
import com.fr.stable.Nameable;
import java.util.ArrayList;
import javax.swing.JPanel;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.awt.BorderLayout;
/**
* 图表预定义管理 界面, 在工具栏-服务器管理中.
*
* @author kunsnat E-mail:kunsnat@gmail.com
* @version 创建时间2013-8-21 下午02:33:48
*/
public class ChartPreStyleManagerPane extends JListControlPane {
@Override
/**
* 创建有名字的creator
* @return 有名字的creator数组
*/
public NameableCreator[] createNameableCreators() {
return new NameableCreator[]{
new NameObjectCreator(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_PreStyle_Duplicate"),
ChartColorMatching.class, ChartPreStylePane.class)
};
}
@Override
protected String title4PopupWindow() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_PreStyle");
}
public void populateBean() {
ChartPreStyleConfig config = ChartPreStyleConfig.getInstance().mirror();
ArrayList list = new ArrayList();
Iterator keys = config.names();
while(keys.hasNext()) {
Object key = keys.next();
ChartColorMatching value = (ChartColorMatching) config.getPreStyle(key);
list.add(new NameObject(Utils.objectToString(key), value));
}
Nameable[] values = (Nameable[])list.toArray(new Nameable[list.size()]);
populate(values);
if(config.containsName(config.getCurrentStyle())) {
this.setSelectedName(config.getCurrentStyle());
}
}
public void updateBean() {
ChartPreStyleConfig config = ChartPreStyleConfig.getInstance();
config.setCurrentStyle(getSelectedName());
Nameable[] values = update();
config.clearAllPreStyle();
for (Nameable value : values) {
config.putPreStyle(value.getName(), ((NameObject) value).getObject());
}
}
public class ChartPreStyleManagerPane extends BasicPane {
private ColorSchemeComboBox defaultColorBox;
private ChartPreStyleListPane chartPreStyleListPane;
public ChartPreStyleManagerPane() {
initComponent();
}
private void initComponent() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
JPanel colorBoxPane = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane();
chartPreStyleListPane = new ChartPreStyleListPane(this);
initDefaultColorBox();
colorBoxPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Chart_Match_Default_Color_Scheme") + ":"));
colorBoxPane.add(defaultColorBox);
this.add(colorBoxPane, BorderLayout.NORTH);
this.add(chartPreStyleListPane, BorderLayout.CENTER);
}
private void initDefaultColorBox() {
Map<String, ColorSchemeComboBox.ColorInfo> colorSchemes = new LinkedHashMap<>();
ChartPreStyleConfig config = ChartPreStyleConfig.getInstance();
Iterator names = config.names();
while (names.hasNext()) {
Object key = names.next();
ColorSchemeComboBox.ColorInfo colorInfo = new ColorSchemeComboBox.ColorInfo();
ChartColorMatching colorMatching = (ChartColorMatching) config.getPreStyle(key);
colorInfo.setGradient(colorMatching.getGradient());
colorInfo.setColors(colorMatching.getColorList());
colorSchemes.put(colorMatching.getId(), colorInfo);
}
defaultColorBox = new ColorSchemeComboBox(colorSchemes);
}
private void refreshColorSchemes() {
Nameable[] nameables = chartPreStyleListPane.update();
Map<String, ColorSchemeComboBox.ColorInfo> colorSchemes = new LinkedHashMap<>();
for (Nameable value : nameables) {
String name = value.getName();
ChartColorMatching colorMatching = (ChartColorMatching) ((NameObject) value).getObject();
ColorSchemeComboBox.ColorInfo colorInfo = new ColorSchemeComboBox.ColorInfo();
colorInfo.setGradient(colorMatching.getGradient());
colorInfo.setColors(colorMatching.getColorList());
colorSchemes.put(name, colorInfo);
}
defaultColorBox.refresh(colorSchemes);
}
public void refreshDefaultColorBox() {
Object selectedItem = defaultColorBox.getSelectedItem();
refreshColorSchemes();
defaultColorBox.setSelectedItem(selectedItem);
}
public void refreshDefaultColorBox(String oldName, String newName) {
Object selectedItem = defaultColorBox.getSelectedItem();
if (ComparatorUtils.equals(selectedItem, oldName)) {
selectedItem = newName;
}
refreshColorSchemes();
defaultColorBox.setSelectedItem(selectedItem);
}
@Override
protected String title4PopupWindow() {
return Toolkit.i18nText("Fine-Design_Report_ServerM_Predefined_Styles");
}
public void populateBean() {
ChartPreStyleConfig config = ChartPreStyleConfig.getInstance();
String currentStyle = config.getCurrentStyle();
defaultColorBox.setSelectedItem(currentStyle);
chartPreStyleListPane.populateBean();
}
public void updateBean() {
ChartPreStyleConfig config = ChartPreStyleConfig.getInstance();
config.setCurrentStyle(GeneralUtils.objectToString(defaultColorBox.getSelectedItem()));
chartPreStyleListPane.updateBean();
}
}

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

@ -80,7 +80,7 @@ public class ChartPreStylePane extends BasicBeanPane<ChartColorMatching> {
}
}
private void refreshWhenStyleChange(ChartColorMatching preStyle) {
protected void refreshWhenStyleChange(ChartColorMatching preStyle) {
if(chartComponent != null) {
demoPlot.setPlotFillStyle(ChartUtils.chartColorMatching2AttrFillStyle(preStyle));
chartComponent.reset();

Loading…
Cancel
Save