forked from fanruan/design
Browse Source
* commit '3f3c67455862e0aa4dfc1a8dfd997a45edcb0903': CHART-11709 代码质量 CHART-11709 CHART-11709 自定义配色设置优化feature/big-screen
Bjorn
5 years ago
28 changed files with 1090 additions and 139 deletions
@ -0,0 +1,174 @@
|
||||
package com.fr.design.chartx.component.button; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.base.background.ColorBackground; |
||||
import com.fr.design.style.AbstractSelectBox; |
||||
import com.fr.design.style.color.ColorSelectPane; |
||||
|
||||
import javax.swing.JPanel; |
||||
import javax.swing.event.ChangeEvent; |
||||
import javax.swing.event.ChangeListener; |
||||
import java.awt.Color; |
||||
import java.awt.Dimension; |
||||
import java.awt.Graphics; |
||||
import java.awt.Graphics2D; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
import java.awt.event.MouseListener; |
||||
import java.awt.geom.Rectangle2D; |
||||
import java.awt.image.BufferedImage; |
||||
|
||||
/** |
||||
* @author Bjorn |
||||
* @version 10.0 |
||||
* Created by Bjorn on 2020-03-06 |
||||
*/ |
||||
public class ColorButton extends AbstractSelectBox<Color> { |
||||
|
||||
private static final double DEL_WIDTH = 7; |
||||
|
||||
public static final int WIDTH = 18; |
||||
|
||||
private BufferedImage closeIcon = BaseUtils.readImageWithCache("com/fr/design/images/toolbarbtn/chartChangeClose.png"); |
||||
|
||||
private Color color; |
||||
|
||||
private boolean isMoveOn = false; |
||||
|
||||
private ColorSelectPane colorPane; |
||||
|
||||
private boolean lastButton; |
||||
|
||||
private ChangeListener changeListener; |
||||
|
||||
public ColorButton(Color color) { |
||||
this.color = color; |
||||
addMouseListener(getMouseListener()); |
||||
} |
||||
|
||||
public Dimension getPreferredSize() { |
||||
return new Dimension(WIDTH, WIDTH); |
||||
} |
||||
|
||||
private void paintDeleteButton(Graphics g2d) { |
||||
Rectangle2D bounds = this.getBounds(); |
||||
|
||||
int x = (int) (bounds.getWidth() - DEL_WIDTH); |
||||
int y = 1; |
||||
|
||||
g2d.drawImage(closeIcon, x, y, closeIcon.getWidth(), closeIcon.getHeight(), null); |
||||
} |
||||
|
||||
public void setLastButton(boolean lastButton) { |
||||
this.lastButton = lastButton; |
||||
} |
||||
|
||||
@Override |
||||
public void paint(Graphics g) { |
||||
this.setSize(WIDTH, WIDTH); |
||||
Graphics2D g2d = (Graphics2D) g; |
||||
g2d.setPaint(color); |
||||
Rectangle2D rec = new Rectangle2D.Double(0, 0, WIDTH + 1, WIDTH + 1); |
||||
g2d.fill(rec); |
||||
|
||||
if (isMoveOn && !lastButton) { |
||||
paintDeleteButton(g); |
||||
} |
||||
} |
||||
|
||||
protected void deleteButton() { |
||||
|
||||
} |
||||
|
||||
|
||||
private void checkMoveOn(boolean moveOn) { |
||||
this.isMoveOn = moveOn; |
||||
repaint(); |
||||
} |
||||
|
||||
protected MouseListener getMouseListener() { |
||||
return new MouseAdapter() { |
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
mouseClick(e); |
||||
} |
||||
|
||||
public void mouseEntered(MouseEvent e) { |
||||
checkMoveOn(true); |
||||
} |
||||
|
||||
public void mouseExited(MouseEvent e) { |
||||
checkMoveOn(false); |
||||
} |
||||
}; |
||||
} |
||||
|
||||
|
||||
public void mouseClick(MouseEvent e) { |
||||
if (!lastButton) { |
||||
Rectangle2D bounds = this.getBounds(); |
||||
if (bounds == null) { |
||||
return; |
||||
} |
||||
if (e.getX() >= bounds.getWidth() - DEL_WIDTH && e.getY() <= DEL_WIDTH) { |
||||
deleteButton(); |
||||
hidePopupMenu(); |
||||
return; |
||||
} |
||||
} |
||||
//打开颜色选择面板
|
||||
showPopupMenu(); |
||||
} |
||||
|
||||
public JPanel initWindowPane(double preferredWidth) { |
||||
// 下拉的时候重新生成面板,刷新最近使用颜色
|
||||
colorPane = new ColorSelectPane(false) { |
||||
@Override |
||||
public void setVisible(boolean b) { |
||||
super.setVisible(b); |
||||
} |
||||
}; |
||||
colorPane.addChangeListener(new ChangeListener() { |
||||
public void stateChanged(ChangeEvent e) { |
||||
hidePopupMenu(); |
||||
color = ((ColorSelectPane) e.getSource()).getColor(); |
||||
fireDisplayComponent(ColorBackground.getInstance(color)); |
||||
ColorButton.this.stateChanged(); |
||||
} |
||||
}); |
||||
return colorPane; |
||||
} |
||||
|
||||
public void stateChanged() { |
||||
if (changeListener != null) { |
||||
changeListener.stateChanged(null); |
||||
} |
||||
} |
||||
|
||||
public void addChangeListener(ChangeListener changeListener) { |
||||
this.changeListener = changeListener; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 获取当前选中的颜色 |
||||
* |
||||
* @return 当前选中的颜色 |
||||
*/ |
||||
public Color getSelectObject() { |
||||
return this.color; |
||||
} |
||||
|
||||
/** |
||||
* 设置选中的颜色 |
||||
* |
||||
* @param color 颜色 |
||||
*/ |
||||
public void setSelectObject(Color color) { |
||||
this.color = color; |
||||
colorPane.setColor(color); |
||||
|
||||
fireDisplayComponent(ColorBackground.getInstance(color)); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,245 @@
|
||||
package com.fr.design.chartx.component.combobox; |
||||
|
||||
import com.fr.base.ChartColorMatching; |
||||
import com.fr.base.ChartPreStyleConfig; |
||||
import com.fr.design.gui.icombobox.UIComboBox; |
||||
import com.fr.design.gui.icombobox.UIComboBoxRenderer; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.general.GeneralUtils; |
||||
|
||||
import javax.swing.DefaultComboBoxModel; |
||||
import javax.swing.JLabel; |
||||
import javax.swing.JList; |
||||
import java.util.Iterator; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.awt.Color; |
||||
import java.awt.Component; |
||||
import java.awt.Dimension; |
||||
import java.awt.FontMetrics; |
||||
import java.awt.Graphics; |
||||
import java.awt.Graphics2D; |
||||
import java.awt.LinearGradientPaint; |
||||
import java.awt.geom.Rectangle2D; |
||||
|
||||
/** |
||||
* @author Bjorn |
||||
* @version 10.0 |
||||
* Created by Bjorn on 2020-03-05 |
||||
* 一个带颜色展示的配色选择下拉框 |
||||
*/ |
||||
public class ColorSchemeComboBox extends UIComboBox { |
||||
|
||||
private Map<String, ColorInfo> colorSchemes; |
||||
|
||||
public ColorSchemeComboBox() { |
||||
this(null); |
||||
} |
||||
|
||||
public ColorSchemeComboBox(Map<String, ColorInfo> colorSchemes) { |
||||
//通过配色方案的集合初始化下拉控件,如果参数为null,从配置中读取配色方案。
|
||||
if (colorSchemes == null) { |
||||
colorSchemes = getColorSchemesFromConfig(); |
||||
} |
||||
this.colorSchemes = colorSchemes; |
||||
|
||||
this.setModel(new DefaultComboBoxModel(colorSchemes.keySet().toArray())); |
||||
|
||||
this.setRenderer(new ColorSchemeCellRenderer()); |
||||
} |
||||
|
||||
private Map<String, ColorInfo> getColorSchemesFromConfig() { |
||||
Map<String, ColorInfo> colorSchemes = new LinkedHashMap<>(); |
||||
ChartPreStyleConfig config = ChartPreStyleConfig.getInstance(); |
||||
|
||||
//所有的样式名称
|
||||
Iterator names = config.names(); |
||||
|
||||
//添加默认的方案和第一个方案
|
||||
String defaultName = config.getCurrentStyle(); |
||||
ChartColorMatching defaultStyle = (ChartColorMatching) config.getPreStyle(defaultName); |
||||
Object firstName = names.next(); |
||||
ChartColorMatching firstStyle = (ChartColorMatching) config.getPreStyle(firstName); |
||||
if (defaultStyle == null) { |
||||
defaultStyle = firstStyle; |
||||
} |
||||
colorSchemes.put(Toolkit.i18nText("Fine-Design_Report_Default"), colorMatchingToColorInfo(defaultStyle)); |
||||
colorSchemes.put(firstStyle.getId(), colorMatchingToColorInfo(firstStyle)); |
||||
|
||||
//添加其他的配色方案
|
||||
while (names.hasNext()) { |
||||
Object key = names.next(); |
||||
ChartColorMatching colorMatching = (ChartColorMatching) config.getPreStyle(key); |
||||
colorSchemes.put(colorMatching.getId(), colorMatchingToColorInfo(colorMatching)); |
||||
} |
||||
|
||||
//添加自定义组合色和自定义渐变色
|
||||
colorSchemes.put(Toolkit.i18nText("Fine-Design_Chart_Custom_Combination_Color"), null); |
||||
colorSchemes.put(Toolkit.i18nText("Fine-Design_Chart_Custom_Gradient"), null); |
||||
|
||||
return colorSchemes; |
||||
} |
||||
|
||||
public ColorInfo getSelectColorInfo() { |
||||
String selectedItem = (String) getSelectedItem(); |
||||
return colorSchemes.get(selectedItem); |
||||
} |
||||
|
||||
private ColorInfo colorMatchingToColorInfo(ChartColorMatching colorMatching) { |
||||
ColorInfo colorInfo = new ColorInfo(); |
||||
colorInfo.setGradient(colorMatching.getGradient()); |
||||
colorInfo.setColors(colorMatching.getColorList()); |
||||
return colorInfo; |
||||
} |
||||
|
||||
public SelectType getSelectType() { |
||||
int selectedIndex = this.getSelectedIndex(); |
||||
int itemCount = this.getItemCount(); |
||||
if (selectedIndex == itemCount - 1) { |
||||
return SelectType.GRADATION_COLOR; |
||||
} |
||||
if (selectedIndex == itemCount - 2) { |
||||
return SelectType.COMBINATION_COLOR; |
||||
} |
||||
if (selectedIndex == 0) { |
||||
return SelectType.DEFAULT; |
||||
} |
||||
return SelectType.NORMAL; |
||||
} |
||||
|
||||
public void setSelectType(SelectType selectType) { |
||||
int itemCount = this.getItemCount(); |
||||
switch (selectType) { |
||||
case DEFAULT: |
||||
setSelectedIndex(0); |
||||
break; |
||||
case GRADATION_COLOR: |
||||
setSelectedIndex(itemCount - 1); |
||||
break; |
||||
case COMBINATION_COLOR: |
||||
setSelectedIndex(itemCount - 2); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
public enum SelectType { |
||||
DEFAULT, |
||||
COMBINATION_COLOR, |
||||
GRADATION_COLOR, |
||||
NORMAL |
||||
} |
||||
|
||||
|
||||
public class ColorInfo { |
||||
|
||||
private List<Color> colors; |
||||
|
||||
private boolean gradient; |
||||
|
||||
public List<Color> getColors() { |
||||
return colors; |
||||
} |
||||
|
||||
public void setColors(List<Color> colors) { |
||||
this.colors = colors; |
||||
} |
||||
|
||||
public boolean isGradient() { |
||||
return gradient; |
||||
} |
||||
|
||||
public void setGradient(boolean gradient) { |
||||
this.gradient = gradient; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* CellRenderer. |
||||
*/ |
||||
class ColorSchemeCellRenderer extends UIComboBoxRenderer { |
||||
|
||||
private String schemeName = Toolkit.i18nText("Fine-Design_Report_Default"); |
||||
|
||||
//左边距
|
||||
private static final double X = 4d; |
||||
|
||||
//上边距
|
||||
private static final double Y = 4d; |
||||
|
||||
private static final String BLANK_SPACE = " "; |
||||
|
||||
private static final int HEIGHT = 20; |
||||
|
||||
private static final int MAX_COUNT = 5; |
||||
|
||||
@Override |
||||
public Dimension getPreferredSize() { |
||||
Dimension preferredSize = super.getPreferredSize(); |
||||
preferredSize.setSize(super.getPreferredSize().getWidth(), HEIGHT); |
||||
return preferredSize; |
||||
} |
||||
|
||||
@Override |
||||
public Dimension getMinimumSize() { |
||||
return getPreferredSize(); |
||||
} |
||||
|
||||
public Component getListCellRendererComponent( |
||||
JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
||||
JLabel comp = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); |
||||
this.schemeName = GeneralUtils.objectToString(value); |
||||
ColorInfo colorInfo = colorSchemes.get(schemeName); |
||||
if (colorInfo == null) { |
||||
comp.setText(BLANK_SPACE + schemeName); |
||||
} else { |
||||
FontMetrics fontMetrics = comp.getFontMetrics(comp.getFont()); |
||||
double width = (HEIGHT - 2 * Y) * MAX_COUNT; |
||||
String fill = BLANK_SPACE; |
||||
//图形和文字之间留的宽度大于3倍的X
|
||||
while (fontMetrics.stringWidth(fill) < width + 3 * X) { |
||||
fill += BLANK_SPACE; |
||||
} |
||||
comp.setText(fill + schemeName); |
||||
} |
||||
comp.setToolTipText(schemeName); |
||||
return comp; |
||||
} |
||||
|
||||
public void paint(Graphics g) { |
||||
super.paint(g); |
||||
|
||||
Graphics2D g2d = (Graphics2D) g; |
||||
|
||||
ColorInfo colorInfo = colorSchemes.get(schemeName); |
||||
if (colorInfo != null) { |
||||
if (colorInfo.isGradient()) { |
||||
drawGradient(g2d, colorInfo.getColors()); |
||||
} else { |
||||
drawCombineColor(g2d, colorInfo.getColors()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private void drawGradient(Graphics2D g2d, List<Color> colors) { |
||||
//上下留4px,宽度等于5倍高
|
||||
double height = HEIGHT - 2 * Y; |
||||
double width = height * MAX_COUNT; |
||||
LinearGradientPaint linearGradientPaint = new LinearGradientPaint((float) X, (float) Y, (float) (X + width), (float) Y, new float[]{0f, 1f}, colors.toArray(new Color[colors.size()])); |
||||
g2d.setPaint(linearGradientPaint); |
||||
Rectangle2D rec = new Rectangle2D.Double(X, Y, width, height); |
||||
g2d.fill(rec); |
||||
} |
||||
|
||||
private void drawCombineColor(Graphics2D g2d, List<Color> colors) { |
||||
int size = Math.min(colors.size(), MAX_COUNT); |
||||
double height = HEIGHT - 2 * Y; |
||||
double width = height * MAX_COUNT / size; |
||||
for (int i = 0; i < size; i++) { |
||||
g2d.setPaint(colors.get(i)); |
||||
Rectangle2D rec = new Rectangle2D.Double(X + width * i, Y, width, height); |
||||
g2d.fill(rec); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,238 @@
|
||||
package com.fr.design.mainframe.chart.gui.style; |
||||
|
||||
import com.fr.base.BaseUtils; |
||||
import com.fr.base.background.ColorBackground; |
||||
import com.fr.design.chartx.component.button.ColorButton; |
||||
import com.fr.design.event.UIObserver; |
||||
import com.fr.design.event.UIObserverListener; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.layout.VerticalFlowLayout; |
||||
import com.fr.design.style.AbstractSelectBox; |
||||
import com.fr.design.style.color.ColorSelectPane; |
||||
|
||||
import javax.swing.JPanel; |
||||
import javax.swing.event.ChangeEvent; |
||||
import javax.swing.event.ChangeListener; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.awt.Color; |
||||
import java.awt.Dimension; |
||||
import java.awt.Graphics; |
||||
import java.awt.Graphics2D; |
||||
import java.awt.event.MouseAdapter; |
||||
import java.awt.event.MouseEvent; |
||||
import java.awt.event.MouseListener; |
||||
import java.awt.geom.Rectangle2D; |
||||
import java.awt.image.BufferedImage; |
||||
|
||||
/** |
||||
* 配色方案选择组合色之后,可以调整颜色的组件 |
||||
* |
||||
* @author Bjorn |
||||
* @version 10.0 |
||||
* Created by Bjorn on 2020-03-25 |
||||
*/ |
||||
public class ChartColorAdjustPane extends JPanel implements UIObserver { |
||||
|
||||
public static final Color[] DEFAULT_COLORS = { |
||||
new Color(99, 178, 238), |
||||
new Color(118, 218, 145), |
||||
new Color(248, 203, 127), |
||||
new Color(248, 149, 136), |
||||
new Color(124, 214, 207), |
||||
new Color(145, 146, 171), |
||||
new Color(120, 152, 225), |
||||
new Color(239, 166, 102), |
||||
new Color(237, 221, 134), |
||||
new Color(153, 135, 206), |
||||
}; |
||||
|
||||
private static final int COUNT_OF_ROW = 8; |
||||
|
||||
private static final int MAX_BUTTON = 40; |
||||
|
||||
private List<ColorButton> colorButtons = new ArrayList<>(); |
||||
|
||||
private List<UIObserverListener> uiObserverListener; |
||||
|
||||
private ChangeListener changeListener; |
||||
|
||||
|
||||
|
||||
|
||||
public ChartColorAdjustPane() { |
||||
this(DEFAULT_COLORS); |
||||
} |
||||
|
||||
public ChartColorAdjustPane(Color[] colors) { |
||||
iniListener(); |
||||
createColorButton(colors); |
||||
createContentPane(); |
||||
} |
||||
|
||||
public void updateColor() { |
||||
updateColor(DEFAULT_COLORS); |
||||
} |
||||
|
||||
public void updateColor(Color[] colors) { |
||||
createColorButton(colors); |
||||
relayout(); |
||||
} |
||||
|
||||
public Color[] getColors() { |
||||
int size = colorButtons.size(); |
||||
Color[] colors = new Color[size]; |
||||
for (int i = 0; i < size; i++) { |
||||
colors[i] = colorButtons.get(i).getSelectObject(); |
||||
} |
||||
return colors; |
||||
} |
||||
|
||||
private void relayout() { |
||||
this.removeAll(); |
||||
createContentPane(); |
||||
this.validate(); |
||||
this.repaint(); |
||||
} |
||||
|
||||
private void createContentPane() { |
||||
VerticalFlowLayout layout = new VerticalFlowLayout(0, 0, 0); |
||||
layout.setAlignLeft(true); |
||||
this.setLayout(layout); |
||||
|
||||
for (int i = 0, size = colorButtons.size(); i < size; i += COUNT_OF_ROW) { |
||||
JPanel panel = FRGUIPaneFactory.createLeftFlowZeroGapBorderPane(); |
||||
int count = i + COUNT_OF_ROW > colorButtons.size() ? colorButtons.size() : i + COUNT_OF_ROW; |
||||
for (int j = i; j < count; j++) { |
||||
colorButtons.get(j).setLastButton(false); |
||||
panel.add(colorButtons.get(j)); |
||||
} |
||||
if (i + COUNT_OF_ROW > colorButtons.size()) { |
||||
panel.add(new AddColorButton()); |
||||
this.add(panel); |
||||
} else if (i + COUNT_OF_ROW == colorButtons.size() && colorButtons.size() != MAX_BUTTON) { |
||||
this.add(panel); |
||||
this.add(new AddColorButton()); |
||||
} else { |
||||
this.add(panel); |
||||
} |
||||
} |
||||
if (colorButtons.size() == 1) { |
||||
colorButtons.get(0).setLastButton(true); |
||||
} |
||||
} |
||||
|
||||
private void createColorButton(Color[] colors) { |
||||
colorButtons.clear(); |
||||
for (Color color : colors) { |
||||
colorButtons.add(createColorButton(color)); |
||||
} |
||||
} |
||||
|
||||
private ColorButton createColorButton(Color color) { |
||||
ColorButton colorButton = new ColorButton(color) { |
||||
@Override |
||||
protected void deleteButton() { |
||||
colorButtons.remove(this); |
||||
stateChanged(); |
||||
relayout(); |
||||
} |
||||
}; |
||||
|
||||
colorButton.addChangeListener(changeListener); |
||||
return colorButton; |
||||
} |
||||
|
||||
private void iniListener() { |
||||
uiObserverListener = new ArrayList<>(); |
||||
if (shouldResponseChangeListener()) { |
||||
this.addChangeListener(new ChangeListener() { |
||||
@Override |
||||
public void stateChanged(ChangeEvent e) { |
||||
for (UIObserverListener observerListener : uiObserverListener) { |
||||
observerListener.doChange(); |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
} |
||||
|
||||
public void stateChanged() { |
||||
if (changeListener != null) { |
||||
changeListener.stateChanged(null); |
||||
} |
||||
} |
||||
|
||||
public void addChangeListener(ChangeListener changeListener) { |
||||
this.changeListener = changeListener; |
||||
} |
||||
|
||||
public void registerChangeListener(UIObserverListener listener) { |
||||
uiObserverListener.add(listener); |
||||
} |
||||
|
||||
public boolean shouldResponseChangeListener() { |
||||
return true; |
||||
} |
||||
|
||||
|
||||
private class AddColorButton extends AbstractSelectBox<Color> { |
||||
|
||||
BufferedImage image = BaseUtils.readImageWithCache("/com/fr/design/images/buttonicon/add.png"); |
||||
|
||||
public AddColorButton() { |
||||
addMouseListener(getMouseListener()); |
||||
} |
||||
|
||||
@Override |
||||
public void paint(Graphics g) { |
||||
this.setSize(ColorButton.WIDTH, ColorButton.WIDTH); |
||||
Graphics2D g2d = (Graphics2D) g; |
||||
g2d.setPaint(Color.WHITE); |
||||
Rectangle2D rec = new Rectangle2D.Double(0, 0, ColorButton.WIDTH + 1, ColorButton.WIDTH + 1); |
||||
g2d.fill(rec); |
||||
g2d.drawImage(image, 0, 0, ColorButton.WIDTH + 1, ColorButton.WIDTH + 1, null); |
||||
} |
||||
|
||||
public Dimension getPreferredSize() { |
||||
return new Dimension(ColorButton.WIDTH, ColorButton.WIDTH); |
||||
} |
||||
|
||||
protected MouseListener getMouseListener() { |
||||
return new MouseAdapter() { |
||||
@Override |
||||
public void mouseClicked(MouseEvent e) { |
||||
showPopupMenu(); |
||||
} |
||||
}; |
||||
} |
||||
|
||||
public JPanel initWindowPane(double preferredWidth) { |
||||
// 下拉的时候重新生成面板,刷新最近使用颜色
|
||||
ColorSelectPane colorPane = new ColorSelectPane(false) { |
||||
public void setVisible(boolean b) { |
||||
super.setVisible(b); |
||||
} |
||||
}; |
||||
colorPane.addChangeListener(new ChangeListener() { |
||||
public void stateChanged(ChangeEvent e) { |
||||
hidePopupMenu(); |
||||
Color color = ((ColorSelectPane) e.getSource()).getColor(); |
||||
fireDisplayComponent(ColorBackground.getInstance(color)); |
||||
colorButtons.add(createColorButton(color)); |
||||
ChartColorAdjustPane.this.stateChanged(); |
||||
relayout(); |
||||
} |
||||
}); |
||||
return colorPane; |
||||
} |
||||
|
||||
public Color getSelectObject() { |
||||
return null; |
||||
} |
||||
|
||||
public void setSelectObject(Color color) { |
||||
|
||||
} |
||||
} |
||||
} |
@ -1,42 +1,236 @@
|
||||
package com.fr.van.chart.designer.component; |
||||
|
||||
import com.fr.base.ChartColorMatching; |
||||
import com.fr.base.ChartPreStyleConfig; |
||||
import com.fr.base.Utils; |
||||
import com.fr.chart.base.AttrFillStyle; |
||||
import com.fr.chart.base.ChartConstants; |
||||
import com.fr.chart.base.ChartUtils; |
||||
import com.fr.design.beans.BasicBeanPane; |
||||
import com.fr.design.chartx.component.combobox.ColorSchemeComboBox; |
||||
import com.fr.design.event.UIObserverListener; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.design.layout.FRGUIPaneFactory; |
||||
import com.fr.design.layout.TableLayout; |
||||
import com.fr.design.mainframe.chart.gui.style.ChartFillStylePane; |
||||
|
||||
import com.fr.design.mainframe.chart.gui.style.ChartColorAdjustPane; |
||||
import com.fr.design.style.background.gradient.FixedGradientBar; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.van.chart.designer.TableLayout4VanChartHelper; |
||||
|
||||
import javax.swing.BorderFactory; |
||||
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.event.ActionEvent; |
||||
import java.awt.event.ActionListener; |
||||
|
||||
/** |
||||
* Created by mengao on 2017/8/17. |
||||
*/ |
||||
public class VanChartFillStylePane extends ChartFillStylePane { |
||||
public class VanChartFillStylePane extends BasicBeanPane<AttrFillStyle> { |
||||
|
||||
|
||||
protected ColorSchemeComboBox styleSelectBox; |
||||
protected JPanel customPane; |
||||
protected JPanel changeColorSetPane; |
||||
protected FixedGradientBar colorGradient; |
||||
|
||||
protected CardLayout cardLayout; |
||||
|
||||
protected ChartColorAdjustPane colorAdjustPane; |
||||
|
||||
private Color[] gradientColors; |
||||
private Color[] accColors; |
||||
|
||||
private boolean gradientSelect = false; |
||||
|
||||
public VanChartFillStylePane() { |
||||
this.setLayout(new BorderLayout()); |
||||
|
||||
styleSelectBox = new ColorSchemeComboBox(); |
||||
customPane = new JPanel(FRGUIPaneFactory.createBorderLayout()); |
||||
|
||||
changeColorSetPane = new JPanel(cardLayout = new CardLayout()); |
||||
changeColorSetPane.add(colorGradient = new FixedGradientBar(4, 130), "gradient"); |
||||
gradientColors = new Color[]{Color.WHITE, FixedGradientBar.NEW_CHARACTER}; |
||||
changeColorSetPane.add(colorAdjustPane = new ChartColorAdjustPane(), "acc"); |
||||
accColors = ChartColorAdjustPane.DEFAULT_COLORS; |
||||
cardLayout.show(changeColorSetPane, "acc"); |
||||
customPane.add(changeColorSetPane, BorderLayout.CENTER); |
||||
initListener(); |
||||
initLayout(); |
||||
} |
||||
|
||||
private void initListener() { |
||||
colorAdjustPane.registerChangeListener(new UIObserverListener() { |
||||
@Override |
||||
public void doChange() { |
||||
accColors = colorAdjustPane.getColors(); |
||||
if (styleSelectBox.getSelectType() != ColorSchemeComboBox.SelectType.COMBINATION_COLOR) { |
||||
styleSelectBox.setSelectType(ColorSchemeComboBox.SelectType.COMBINATION_COLOR); |
||||
} |
||||
VanChartFillStylePane.this.revalidate(); |
||||
} |
||||
}); |
||||
colorGradient.registerChangeListener(new UIObserverListener() { |
||||
@Override |
||||
protected JPanel getContentPane () { |
||||
public void doChange() { |
||||
gradientColors[0] = colorGradient.getSelectColorPointBtnP1().getColorInner(); |
||||
gradientColors[1] = colorGradient.getSelectColorPointBtnP2().getColorInner(); |
||||
if (styleSelectBox.getSelectType() != ColorSchemeComboBox.SelectType.GRADATION_COLOR) { |
||||
styleSelectBox.setSelectType(ColorSchemeComboBox.SelectType.GRADATION_COLOR); |
||||
} |
||||
} |
||||
}); |
||||
styleSelectBox.addActionListener(new ActionListener() { |
||||
@Override |
||||
public void actionPerformed(ActionEvent e) { |
||||
switch (styleSelectBox.getSelectType()) { |
||||
case COMBINATION_COLOR: |
||||
colorAdjustPane.updateColor(accColors); |
||||
cardLayout.show(changeColorSetPane, "acc"); |
||||
gradientSelect = false; |
||||
break; |
||||
case GRADATION_COLOR: |
||||
colorGradient.updateColor(gradientColors[0], gradientColors[1]); |
||||
cardLayout.show(changeColorSetPane, "gradient"); |
||||
gradientSelect = true; |
||||
break; |
||||
default: |
||||
ColorSchemeComboBox.ColorInfo selectColorInfo = styleSelectBox.getSelectColorInfo(); |
||||
if (selectColorInfo.isGradient()) { |
||||
colorGradient.updateColor(selectColorInfo.getColors().get(0), selectColorInfo.getColors().get(1)); |
||||
cardLayout.show(changeColorSetPane, "gradient"); |
||||
gradientSelect = true; |
||||
} else { |
||||
colorAdjustPane.updateColor(selectColorInfo.getColors().toArray(new Color[]{})); |
||||
cardLayout.show(changeColorSetPane, "acc"); |
||||
gradientSelect = false; |
||||
} |
||||
break; |
||||
} |
||||
VanChartFillStylePane.this.revalidate(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
protected void initLayout() { |
||||
this.setLayout(new BorderLayout()); |
||||
this.add(getContentPane(), BorderLayout.CENTER); |
||||
} |
||||
|
||||
@Override |
||||
public Dimension getPreferredSize() { |
||||
if (gradientSelect) { |
||||
return new Dimension(225, 80); |
||||
} |
||||
return super.getPreferredSize(); |
||||
} |
||||
|
||||
protected JPanel getContentPane() { |
||||
double p = TableLayout.PREFERRED; |
||||
double f = TableLayout.FILL; |
||||
double e = TableLayout4VanChartHelper.EDIT_AREA_WIDTH; |
||||
double[] columnSize = {f, e}; |
||||
double[] rowSize = {p, p}; |
||||
Component[][] components = new Component[][]{ |
||||
new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Color_Match")),styleSelectBox}, |
||||
new Component[]{null,customPane}, |
||||
new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Chart_Match_Color_Scheme")), styleSelectBox}, |
||||
new Component[]{null, customPane}, |
||||
|
||||
}; |
||||
JPanel panel = TableLayout4VanChartHelper.createGapTableLayoutPane(components,rowSize,columnSize); |
||||
panel.setBorder(BorderFactory.createEmptyBorder(5,5,0,0)); |
||||
JPanel panel = TableLayout4VanChartHelper.createGapTableLayoutPane(components, rowSize, columnSize); |
||||
panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0)); |
||||
return panel; |
||||
} |
||||
|
||||
@Override |
||||
public Dimension getPreferredSize() { |
||||
if(styleSelectBox.getSelectedIndex() != styleSelectBox.getItemCount() - 1) { |
||||
return new Dimension(styleSelectBox.getPreferredSize().width, 30); |
||||
protected String title4PopupWindow() { |
||||
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Chart_Color"); |
||||
} |
||||
|
||||
@Override |
||||
public void populateBean(AttrFillStyle condition) { |
||||
String fillStyleName = condition == null ? "" : condition.getFillStyleName(); |
||||
if (StringUtils.isBlank(fillStyleName)) {//兼容处理
|
||||
if (condition == null || condition.getColorStyle() == ChartConstants.COLOR_DEFAULT) { |
||||
styleSelectBox.setSelectType(ColorSchemeComboBox.SelectType.DEFAULT);//默认
|
||||
} else { |
||||
int colorStyle = condition.getColorStyle(); |
||||
if (colorStyle == ChartConstants.COLOR_GRADIENT) { |
||||
gradientColors[0] = condition.getColorIndex(0); |
||||
gradientColors[1] = condition.getColorIndex(1); |
||||
styleSelectBox.setSelectType(ColorSchemeComboBox.SelectType.GRADATION_COLOR); |
||||
} else { |
||||
int colorSize = condition.getColorSize(); |
||||
accColors = new Color[colorSize]; |
||||
for (int i = 0; i < colorSize; i++) { |
||||
accColors[i] = condition.getColorIndex(i); |
||||
} |
||||
styleSelectBox.setSelectType(ColorSchemeComboBox.SelectType.COMBINATION_COLOR); |
||||
} |
||||
} |
||||
} else { |
||||
styleSelectBox.setSelectedItem(fillStyleName); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public AttrFillStyle updateBean() { |
||||
switch (styleSelectBox.getSelectType()) { |
||||
case COMBINATION_COLOR: |
||||
return updateCombinationColor(); |
||||
case GRADATION_COLOR: |
||||
return updateGradationColor(); |
||||
case DEFAULT: |
||||
return updateDefaultColor(); |
||||
default: |
||||
return updateNormalColor(); |
||||
} |
||||
} |
||||
|
||||
private AttrFillStyle updateCombinationColor() { |
||||
AttrFillStyle condition = new AttrFillStyle(); |
||||
condition.clearColors(); |
||||
condition.setColorStyle(ChartConstants.COLOR_ACC); |
||||
for (int i = 0, length = accColors.length; i < length; i++) { |
||||
condition.addFillColor(accColors[i]); |
||||
} |
||||
condition.setCustomFillStyle(true); |
||||
return condition; |
||||
} |
||||
|
||||
private AttrFillStyle updateGradationColor() { |
||||
AttrFillStyle condition = new AttrFillStyle(); |
||||
condition.clearColors(); |
||||
condition.setColorStyle(ChartConstants.COLOR_GRADIENT); |
||||
Color start = gradientColors[0]; |
||||
Color end = gradientColors[1]; |
||||
condition.addFillColor(start); |
||||
condition.addFillColor(end); |
||||
condition.setCustomFillStyle(true); |
||||
return condition; |
||||
} |
||||
|
||||
private AttrFillStyle updateDefaultColor() { |
||||
AttrFillStyle condition = new AttrFillStyle(); |
||||
condition.clearColors(); |
||||
condition.setColorStyle(ChartConstants.COLOR_DEFAULT); |
||||
return condition; |
||||
} |
||||
|
||||
private AttrFillStyle updateNormalColor() { |
||||
ChartPreStyleConfig manager = ChartPreStyleConfig.getInstance(); |
||||
Object preStyle = manager.getPreStyle(styleSelectBox.getSelectedItem()); |
||||
if (preStyle instanceof ChartColorMatching) { |
||||
AttrFillStyle def = ChartUtils.chartColorMatching2AttrFillStyle((ChartColorMatching) preStyle); |
||||
def.setFillStyleName(Utils.objectToString(styleSelectBox.getSelectedItem())); |
||||
return def; |
||||
} else { |
||||
return updateDefaultColor(); |
||||
} |
||||
return super.getPreferredSize(); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue