You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
465 lines
16 KiB
465 lines
16 KiB
package com.fr.design.style.color; |
|
|
|
import com.fr.base.FineColor; |
|
import com.fr.base.theme.TemplateTheme; |
|
import com.fr.design.DesignerEnvManager; |
|
import com.fr.design.border.UIRoundedBorder; |
|
import com.fr.design.constants.UIConstants; |
|
import com.fr.design.dialog.BasicPane; |
|
import com.fr.design.file.HistoryTemplateListCache; |
|
import com.fr.design.fun.DefaultValueAdjustProvider; |
|
import com.fr.design.gui.ibutton.UIButton; |
|
import com.fr.design.gui.ilable.UILabel; |
|
import com.fr.design.i18n.Toolkit; |
|
import com.fr.design.layout.FRGUIPaneFactory; |
|
import com.fr.design.mainframe.DesignerContext; |
|
import com.fr.design.mainframe.JTemplate; |
|
import com.fr.design.mainframe.theme.dialog.TemplateThemeProfileDialog; |
|
import com.fr.design.utils.DesignUtils; |
|
|
|
import javax.swing.BorderFactory; |
|
import javax.swing.JButton; |
|
import javax.swing.JPanel; |
|
import javax.swing.event.ChangeEvent; |
|
import javax.swing.event.ChangeListener; |
|
import java.awt.BorderLayout; |
|
import java.awt.Color; |
|
import java.awt.Cursor; |
|
import java.awt.Dimension; |
|
import java.awt.GridLayout; |
|
import java.awt.event.MouseAdapter; |
|
import java.awt.event.MouseEvent; |
|
import java.util.ArrayList; |
|
import java.util.List; |
|
|
|
|
|
/** |
|
* @author zhou |
|
* @since 2012-5-29上午10:39:35 |
|
*/ |
|
public class NewColorSelectPane extends BasicPane implements ColorSelectable { |
|
private static final long serialVersionUID = -8634152305687249392L; |
|
|
|
private static final int WIDTH = 216; |
|
private static final int HEIGHT = 230; |
|
|
|
private static final int DEFAULT_COLOR_HOR_INTERVAL = 4; |
|
//颜色衍生的数量 |
|
private static final int DEFAULT_DERIVE_COUNT = 5; |
|
|
|
private FineColor color = null; // color |
|
// color setting action. |
|
private final ArrayList<ChangeListener> colorChangeListenerList = new ArrayList<>(); |
|
|
|
// 是否支持透明 |
|
private boolean isSupportTransparent; |
|
|
|
private boolean isSupportThemeColor; |
|
|
|
// 最近使用颜色 |
|
private final NewUsedColorPane usedColorPane; |
|
private final JPanel menuColorPane; |
|
private ColorCell[][] themeColorCellGrid; |
|
|
|
private List<ColorConfig> colorSelector ; |
|
|
|
public static NewColorSelectPane createColorSelectPaneWithTheme(boolean supportTheme) { |
|
return new NewColorSelectPane(true, supportTheme); |
|
} |
|
|
|
/** |
|
* Constructor. |
|
*/ |
|
public NewColorSelectPane() { |
|
this(true); |
|
} |
|
|
|
public NewColorSelectPane(boolean isSupportTransparent) { |
|
this(isSupportTransparent, !DesignerContext.getDesignerFrame().isServerConfig()); |
|
} |
|
|
|
/** |
|
* Constructor. |
|
*/ |
|
public NewColorSelectPane(boolean isSupportTransparent, boolean isSupportThemeColor) { |
|
this.isSupportThemeColor = isSupportThemeColor; |
|
initSelectButton(isSupportTransparent); |
|
// center |
|
JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); |
|
centerPane.setBorder(BorderFactory.createEmptyBorder(10, 6, 0, 6)); |
|
this.add(centerPane, BorderLayout.CENTER); |
|
|
|
menuColorPane = getMenuColorPane(); |
|
|
|
if (isSupportThemeColor) { |
|
JPanel themePane = initThemeColorPane(); |
|
centerPane.add(themePane); |
|
} else { |
|
centerPane.add(menuColorPane); |
|
initMenuColorPane(); |
|
} |
|
|
|
JPanel standardColorPane = new JPanel(new BorderLayout(0, 5)); |
|
standardColorPane.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); |
|
standardColorPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Standard_Color")), BorderLayout.CENTER); |
|
centerPane.add(standardColorPane); |
|
JPanel colorSelectPane = createStandardColorPane(); |
|
standardColorPane.add(colorSelectPane, BorderLayout.SOUTH); |
|
|
|
// 增加最近使用 pane |
|
JPanel row1Pane = new JPanel(new BorderLayout(0, 5)); |
|
row1Pane.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0)); |
|
row1Pane.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Used")), BorderLayout.CENTER); |
|
centerPane.add(row1Pane); |
|
// 最近使用 |
|
usedColorPane = new NewUsedColorPane(9, this, selectRealTime()); |
|
row1Pane.add(usedColorPane.getPane(), BorderLayout.SOUTH); |
|
|
|
// mod by anchore 16/11/16 |
|
final UIButton customButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_More_Color")); |
|
|
|
// 不能使用 ActionListener,否则设计器工具栏中的"更多颜色"按钮会有问题(REPORT-13654) |
|
customButton.addMouseListener(new MouseAdapter() { |
|
@Override |
|
public void mousePressed(MouseEvent e) { |
|
if (!customButton.isEnabled()) { |
|
return; |
|
} |
|
customButtonPressed(); |
|
} |
|
}); |
|
|
|
customButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
|
JPanel centerPane1 = new JPanel(new BorderLayout(0, 0)); |
|
centerPane1.setBorder(BorderFactory.createEmptyBorder(8, 0, 9, 0)); |
|
centerPane1.add(customButton, BorderLayout.CENTER); |
|
customButton.setPreferredSize(new Dimension(197, 20)); |
|
centerPane.add(centerPane1); |
|
} |
|
|
|
private JPanel createStandardColorPane() { |
|
JPanel jPanel = new JPanel(new GridLayout(1, 10, DEFAULT_COLOR_HOR_INTERVAL, 0)); |
|
Color[] colorArray = ColorFactory.STANDARD_COLORS; |
|
for (int i = 0; i < colorArray.length; i++) { |
|
jPanel.add(new ColorCell(colorArray[i], this)); |
|
} |
|
return jPanel; |
|
} |
|
|
|
private JPanel initThemeColorPane() { |
|
menuColorPane.removeAll(); |
|
JPanel themeColorPane = new JPanel(new BorderLayout(0, 5)); |
|
themeColorPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
|
themeColorPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Theme_Color")), BorderLayout.CENTER); |
|
|
|
themeColorPane.add(menuColorPane, BorderLayout.SOUTH); |
|
|
|
menuColorPane.setLayout(new BorderLayout(0, 10)); |
|
JPanel northPane = new JPanel(new GridLayout(1, 8, DEFAULT_COLOR_HOR_INTERVAL, 0)); |
|
JPanel centerPane = new JPanel(new GridLayout(1, 8, DEFAULT_COLOR_HOR_INTERVAL, 0)); |
|
menuColorPane.add(northPane, BorderLayout.NORTH); |
|
menuColorPane.add(centerPane, BorderLayout.CENTER); |
|
this.colorSelector = FRColorSelectorStyle.COLOR_CONFIG; |
|
DefaultValueAdjustProvider valueAdjust = DesignUtils.getValueAdjust(); |
|
if (valueAdjust != null) { |
|
this.colorSelector = valueAdjust.getColorSelector(); |
|
} |
|
Color[] colorArray = new Color[]{ |
|
// 8列主题色 |
|
Color.decode("#FFFFFF"), |
|
Color.decode("#CCCCCC"), |
|
Color.decode("#FFFFFF"), |
|
Color.decode("#CCCCCC"), |
|
Color.decode("#FFFFFF"), |
|
Color.decode("#CCCCCC"), |
|
Color.decode("#FFFFFF"), |
|
Color.decode("#CCCCCC"), |
|
|
|
// 2列灰度色 |
|
Color.decode("#000000"), |
|
Color.decode("#FFFFFF"), |
|
}; |
|
|
|
if (themeColorCellGrid == null) { |
|
themeColorCellGrid = new ColorCell[colorArray.length][DEFAULT_DERIVE_COUNT]; |
|
for (int i = 0; i < colorArray.length; i++) { |
|
ColorCell[] colorCellColumn = new ColorCell[DEFAULT_DERIVE_COUNT]; |
|
ColorConfig colorConfig = getColorConfig(colorSelector, i); |
|
Color color = colorArray[i]; |
|
Color[] deriveColorArr = colorConfig.getDeriveColorArr(color, DEFAULT_DERIVE_COUNT); |
|
for (int j = 0; j < deriveColorArr.length; j++) { |
|
colorCellColumn[j] = createFineColorCell(deriveColorArr[j], !colorConfig.isSupportTheme(), i, j); |
|
} |
|
themeColorCellGrid[i] = colorCellColumn; |
|
} |
|
} |
|
|
|
for (int i = 0; i < colorArray.length; i++) { |
|
northPane.add(themeColorCellGrid[i][0]); |
|
} |
|
for (int i = 0; i < colorArray.length; i++) { |
|
JPanel columnPane = new JPanel(new GridLayout(DEFAULT_DERIVE_COUNT - 1, 1, 0, 0)); |
|
for (int j = 1; j < DEFAULT_DERIVE_COUNT; j++) { |
|
columnPane.add(themeColorCellGrid[i][j]); |
|
} |
|
centerPane.add(columnPane); |
|
} |
|
|
|
refreshThemeMenuColorPane(); |
|
return themeColorPane; |
|
} |
|
|
|
private void refreshThemeMenuColorPane() { |
|
List<Color> standardColors = null; |
|
if (TemplateThemeProfileDialog.isEditingTheme()) { |
|
standardColors = TemplateThemeProfileDialog.getEditingColorScheme(); |
|
} else { |
|
JTemplate<?, ?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
if (template != null) { |
|
TemplateTheme theme = template.getTemplateTheme(); |
|
if (theme != null) { |
|
standardColors = theme.getColorScheme().getColors(); |
|
} |
|
} |
|
} |
|
if (standardColors == null || standardColors.size() < 8) { |
|
return; |
|
} |
|
for (int i = 0; i < standardColors.size(); i++) { |
|
Color standardColor = standardColors.get(i); |
|
ColorConfig colorConfig = getColorConfig(colorSelector, i); |
|
Color[] deriveColorArr = colorConfig.getDeriveColorArr(standardColor, DEFAULT_DERIVE_COUNT); |
|
for (int j = 0; j < deriveColorArr.length; j++) { |
|
themeColorCellGrid[i][j].setColor(deriveColorArr[j]); |
|
} |
|
} |
|
} |
|
|
|
|
|
private FineColorCell createFineColorCell(Color color, boolean isDefaultColor, int x, int y) { |
|
return isDefaultColor ? new FineColorCell(color, this) : new FineColorCell(color, this, x, y); |
|
} |
|
|
|
|
|
private void initMenuColorPane() { |
|
menuColorPane.setLayout(new GridLayout(5, 8, DEFAULT_COLOR_HOR_INTERVAL, 0)); |
|
Color[] colorArray = this.getColorArray(); |
|
for (int i = 0; i < colorArray.length; i++) { |
|
Color color = colorArray[i] == null ? UsedColorPane.DEFAULT_COLOR : colorArray[i]; |
|
menuColorPane.add(new ColorCell(color, this)); |
|
} |
|
|
|
} |
|
|
|
public boolean isSupportTransparent() { |
|
return isSupportTransparent; |
|
} |
|
|
|
public void setSupportTransparent(boolean supportTransparent) { |
|
isSupportTransparent = supportTransparent; |
|
} |
|
|
|
protected boolean selectRealTime() { |
|
return true; |
|
} |
|
|
|
protected void initSelectButton(boolean isSupportTransparent) { |
|
this.isSupportTransparent = isSupportTransparent; |
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
|
this.setBorder(new UIRoundedBorder(UIConstants.TOOLBAR_BORDER_COLOR, 1, 5)); |
|
if (isSupportTransparent) { |
|
UIButton transparentButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_ChartF_Transparency")); |
|
this.add(transparentButton, BorderLayout.NORTH); |
|
transparentButton.addActionListener(e -> doTransparent()); |
|
} |
|
} |
|
|
|
|
|
/** |
|
* 添加监听 |
|
* |
|
* @param changeListener 监听 |
|
*/ |
|
public void addChangeListener(ChangeListener changeListener) { |
|
this.colorChangeListenerList.add(changeListener); |
|
} |
|
|
|
@Override |
|
protected String title4PopupWindow() { |
|
return "Color"; |
|
} |
|
|
|
/** |
|
* 获取颜色 |
|
* |
|
* @return 颜色 |
|
* Return the color. |
|
*/ |
|
public FineColor getColor() { |
|
return color; |
|
} |
|
|
|
/** |
|
* 获取颜色 |
|
* |
|
* @return 颜色 |
|
*/ |
|
public Color getNotNoneColor() { |
|
if (color == null) { |
|
setColor(Color.WHITE); |
|
} |
|
return color; |
|
} |
|
|
|
/** |
|
* Set the color. |
|
* |
|
* @param color the new color. |
|
*/ |
|
@Override |
|
public void setColor(Color color) { |
|
if (isSupportThemeColor) { |
|
refreshThemeMenuColorPane(); |
|
} |
|
FineColor fineColor; |
|
if (color == null) { |
|
fineColor = null; |
|
} else { |
|
fineColor = color instanceof FineColor ? (FineColor) color : new FineColor(color); |
|
} |
|
setFineColor(fineColor); |
|
} |
|
|
|
private void setFineColor(FineColor fineColor) { |
|
this.color = fineColor; |
|
|
|
// fire color change. |
|
if (!colorChangeListenerList.isEmpty()) { |
|
ChangeEvent evt = new ChangeEvent(this); |
|
|
|
for (ChangeListener changeListener : colorChangeListenerList) { |
|
changeListener.stateChanged(evt); |
|
} |
|
} |
|
|
|
this.repaint(); |
|
} |
|
|
|
@Override |
|
public void colorSetted(ColorCell colorCell) { |
|
this.updateUsedColor(); |
|
colorCell.repaint(); |
|
} |
|
|
|
protected void doTransparent() { |
|
setColor(null); |
|
} |
|
|
|
protected Color[] getColorArray() { |
|
return ColorFactory.MenuColors; |
|
} |
|
|
|
protected JPanel getMenuColorPane() { |
|
return new JPanel(); |
|
} |
|
|
|
|
|
protected void customButtonPressed() { |
|
// 颜色选择器 |
|
ColorSelectDetailPane pane = new ColorSelectDetailPane(Color.WHITE); |
|
Color color = getColor() == null ? Color.WHITE : getColor().getColor(); |
|
ColorSelectDialog.showDialog(DesignerContext.getDesignerFrame(), pane, color, this); |
|
} |
|
|
|
@Override |
|
public Dimension getPreferredSize() { |
|
int height = HEIGHT; |
|
if (isSupportTransparent) { |
|
height += 15; |
|
} |
|
if (isSupportThemeColor) { |
|
height += 25; |
|
} |
|
return new Dimension(WIDTH, height); |
|
} |
|
|
|
/** |
|
* 更新最近使用颜色 |
|
*/ |
|
public void updateUsedColor() { |
|
usedColorPane.updateUsedColor(); |
|
} |
|
|
|
class NewUsedColorPane extends BasicPane { |
|
|
|
// 最近使用面板列数 |
|
private int columns; |
|
|
|
// 最近使用面板 |
|
private JPanel pane; |
|
|
|
private ColorSelectable selectable; |
|
|
|
private boolean setColorRealTime; |
|
|
|
public JPanel getPane() { |
|
return this.pane; |
|
} |
|
|
|
|
|
public NewUsedColorPane(int columns, ColorSelectable selectable, boolean setColorRealTime) { |
|
this.columns = columns; |
|
this.selectable = selectable; |
|
this.setColorRealTime = setColorRealTime; |
|
initialComponents(); |
|
} |
|
|
|
|
|
private void initialComponents() { |
|
int total = columns; |
|
JPanel panel = new JPanel(); |
|
panel.setLayout(new GridLayout(1, columns + 1, DEFAULT_COLOR_HOR_INTERVAL, 0)); |
|
panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); |
|
//最近使用颜色 |
|
Color[] colors = DesignerEnvManager.getEnvManager().getColorConfigManager().getColors(); |
|
int size = colors.length; |
|
for (int i = 0; i < total; i++) { |
|
Color color = i < size ? colors[size - i - 1] : |
|
UsedColorPane.DEFAULT_COLOR; |
|
panel.add(new ColorCell(color == null ? UsedColorPane.DEFAULT_COLOR : color, selectable)); |
|
} |
|
// 取色按钮 |
|
JButton pickColorButton = PickColorButtonFactory.getPickColorButton(selectable, PickColorButtonFactory.IconType.ICON16, setColorRealTime); |
|
panel.add(pickColorButton); |
|
this.pane = panel; |
|
} |
|
|
|
/** |
|
* 更新最近使用颜色 |
|
*/ |
|
public void updateUsedColor() { |
|
int total = columns; |
|
Color[] colors = DesignerEnvManager.getEnvManager().getColorConfigManager().getColors(); |
|
int size = colors.length; |
|
for (int i = 0; i < total; i++) { |
|
ColorCell cell = (ColorCell) this.pane.getComponent(i); |
|
Color color = i < size ? colors[size - i - 1] : UsedColorPane.DEFAULT_COLOR; |
|
cell.setColor(color == null ? UsedColorPane.DEFAULT_COLOR : color); |
|
} |
|
} |
|
|
|
@Override |
|
protected String title4PopupWindow() { |
|
return null; |
|
} |
|
} |
|
|
|
|
|
public ColorConfig getColorConfig(List<ColorConfig> colorConfigs, int i) { |
|
if (i < 0 || i >= colorConfigs.size()) { |
|
return colorConfigs.get(0); |
|
} |
|
return colorConfigs.get(i); |
|
} |
|
|
|
}
|
|
|