Browse Source

REPORT-934颜色记住正确但是显示错误修复和部分代码调整

master
yaoh.wu 8 years ago
parent
commit
a5769fe467
  1. 190
      designer_base/src/com/fr/design/style/color/ColorSelectDetailPane.java
  2. 243
      designer_base/src/com/fr/design/style/color/ColorSelectPane.java
  3. 386
      designer_base/src/com/fr/design/style/color/NewColorSelectPane.java
  4. 91
      designer_base/src/com/fr/design/style/color/RecentUseColorPane.java
  5. 219
      designer_base/src/com/fr/design/style/color/UsedColorPane.java

190
designer_base/src/com/fr/design/style/color/ColorSelectDetailPane.java

@ -1,112 +1,104 @@
package com.fr.design.style.color;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import com.fr.design.dialog.BasicPane;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.general.Inter;
import javax.swing.JColorChooser;
import javax.swing.JPanel;
import javax.swing.*;
import javax.swing.colorchooser.AbstractColorChooserPanel;
import javax.swing.colorchooser.ColorSelectionModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import com.fr.design.dialog.BasicPane;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.general.Inter;
import java.awt.*;
/**
* 颜色选择器更多颜色面板
* @author focus
*
* @author focus
*/
public class ColorSelectDetailPane extends BasicPane{
private static final int SELECT_PANEL_HEIGHT = 245;
// Selected color
private Color color;
// 颜色选择器面板
JColorChooser selectedPanel;
// 最近使用颜色面板
JPanel recentUsePanel;
// 预览
JPanel previewPanel;
public JColorChooser getSelectedPanel() {
return selectedPanel;
}
public void setSelectedPanel(JColorChooser selectedPanel) {
this.selectedPanel = selectedPanel;
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
public ColorSelectDetailPane() {
super();
}
public ColorSelectDetailPane(Color color){
if(color == null){
color = Color.white;
}
this.color = color;
initComponents();
}
@Override
protected String title4PopupWindow() {
return null;
}
protected void initComponents() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
// 颜色选择器面板
selectedPanel = new JColorChooser(this.color);
selectedPanel.setPreferredSize(new Dimension(selectedPanel.getWidth(),SELECT_PANEL_HEIGHT));
AbstractColorChooserPanel[] choosers = selectedPanel.getChooserPanels();
for(int i=0;i<choosers.length;i++){
selectedPanel.removeChooserPanel(choosers[i]);
}
selectedPanel.setPreviewPanel(new JPanel());
AbstractColorChooserPanel swatchChooserPanel = new SwatchChooserPanel();
AbstractColorChooserPanel customChooserPanel = new CustomChooserPanel();
selectedPanel.addChooserPanel(swatchChooserPanel);
selectedPanel.addChooserPanel(customChooserPanel);
this.add(selectedPanel, BorderLayout.NORTH);
// 最近使用面板
recentUsePanel = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("FR-Designer_Used"));
RecentUseColorPane recent = new RecentUseColorPane(selectedPanel);
recentUsePanel.add(recent);
this.add(recentUsePanel,BorderLayout.CENTER);
selectedPanel.setPreviewPanel(new JPanel());
// 预览
previewPanel = FRGUIPaneFactory.createTitledBorderPaneCenter(Inter.getLocText("FR-Designer_Preview"));
final ColorChooserPreview colorChooserPreview = new ColorChooserPreview();
ColorSelectionModel model = selectedPanel.getSelectionModel();
model.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
ColorSelectionModel model = (ColorSelectionModel) e.getSource();
colorChooserPreview.setMyColor(model.getSelectedColor());
colorChooserPreview.paint(colorChooserPreview.getGraphics());
}
});
previewPanel.add(colorChooserPreview);
this.add(previewPanel, BorderLayout.SOUTH);
}
public class ColorSelectDetailPane extends BasicPane {
private static final int SELECT_PANEL_HEIGHT = 245;
// Selected color
private Color color;
// 颜色选择器面板
private JColorChooser selectedPanel;
// 最近使用颜色面板
private JPanel recentUsePanel;
// 预览
private JPanel previewPanel;
public JColorChooser getSelectedPanel() {
return selectedPanel;
}
public void setSelectedPanel(JColorChooser selectedPanel) {
this.selectedPanel = selectedPanel;
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
public ColorSelectDetailPane(Color color) {
if (color == null) {
color = Color.white;
}
this.color = color;
initComponents();
}
@Override
protected String title4PopupWindow() {
return null;
}
protected void initComponents() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
// 颜色选择器面板
selectedPanel = new JColorChooser(this.color);
selectedPanel.setPreferredSize(new Dimension(selectedPanel.getWidth(), SELECT_PANEL_HEIGHT));
AbstractColorChooserPanel[] choosers = selectedPanel.getChooserPanels();
for (int i = 0; i < choosers.length; i++) {
selectedPanel.removeChooserPanel(choosers[i]);
}
selectedPanel.setPreviewPanel(new JPanel());
AbstractColorChooserPanel swatchChooserPanel = new SwatchChooserPanel();
AbstractColorChooserPanel customChooserPanel = new CustomChooserPanel();
selectedPanel.addChooserPanel(swatchChooserPanel);
selectedPanel.addChooserPanel(customChooserPanel);
this.add(selectedPanel, BorderLayout.NORTH);
// 最近使用面板
recentUsePanel = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("FR-Designer_Used"));
RecentUseColorPane recent = new RecentUseColorPane(selectedPanel);
recentUsePanel.add(recent);
this.add(recentUsePanel, BorderLayout.CENTER);
selectedPanel.setPreviewPanel(new JPanel());
// 预览
previewPanel = FRGUIPaneFactory.createTitledBorderPaneCenter(Inter.getLocText("FR-Designer_Preview"));
final ColorChooserPreview colorChooserPreview = new ColorChooserPreview();
ColorSelectionModel model = selectedPanel.getSelectionModel();
model.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
ColorSelectionModel model = (ColorSelectionModel) e.getSource();
colorChooserPreview.setMyColor(model.getSelectedColor());
colorChooserPreview.paint(colorChooserPreview.getGraphics());
}
});
previewPanel.add(colorChooserPreview);
this.add(previewPanel, BorderLayout.SOUTH);
}
}

243
designer_base/src/com/fr/design/style/color/ColorSelectPane.java

@ -3,26 +3,23 @@
*/
package com.fr.design.style.color;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import com.fr.design.border.UIRoundedBorder;
import com.fr.design.constants.UIConstants;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.DesignerContext;
import com.fr.general.Inter;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.Inter;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
/**
* The pane used to select color
@ -30,94 +27,95 @@ import com.fr.design.utils.gui.GUICoreUtils;
public class ColorSelectPane extends TransparentPane implements ColorSelectable {
private static final long serialVersionUID = -8634152305687249392L;
private Color color = null; //color
private Color color = null; //color
//color setting action.
private ArrayList<ChangeListener> colorChangeListenerList = new ArrayList<ChangeListener>();
ColorSelectDetailPane pane;
/* default */ ColorSelectDetailPane pane;
/**
* Constructor.
*/
public ColorSelectPane() {
super(true);
initialCompents(true);
super(true);
initialCompents(true);
}
public ColorSelectPane(boolean isSupportTransparent) {
super(isSupportTransparent);
initialCompents(isSupportTransparent);
}
private void initialCompents(boolean isSupportTransparent) {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 5));
if (isSupportTransparent) {
UIButton transpanrentButton = new UIButton(Inter.getLocText("FR-Designer_ChartF-Transparency"));
this.add(transpanrentButton, BorderLayout.NORTH);
transpanrentButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doTransparent();
}
});
}
// center
JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane();
this.add(centerPane, BorderLayout.CENTER);
centerPane.add(getRow1Pane());
JPanel menuColorPane1 = getMenuColorPane();
centerPane.add(menuColorPane1);
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 5));
if (isSupportTransparent) {
UIButton transpanrentButton = new UIButton(Inter.getLocText("FR-Designer_ChartF-Transparency"));
this.add(transpanrentButton, BorderLayout.NORTH);
transpanrentButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doTransparent();
}
});
}
// center
JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane();
this.add(centerPane, BorderLayout.CENTER);
centerPane.add(getRow1Pane());
JPanel menuColorPane1 = getMenuColorPane();
centerPane.add(menuColorPane1);
Color[] colorArray = this.getColorArray();
for (int i = 0; i < colorArray.length; i++) {
Color color = colorArray[i] == null ? UsedColorPane.DEFAULT_COLOR : colorArray[i];
menuColorPane1.add(new ColorCell(color, this));
}
centerPane.add(Box.createVerticalStrut(1));
UIButton customButton = new UIButton(Inter.getLocText("FR-Designer-Basic_More_Color"));
customButton.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
customButtonPressed();
}
});
customButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
JPanel centerPane1 = FRGUIPaneFactory.createBorderLayout_S_Pane();
centerPane1.setBorder(BorderFactory.createEmptyBorder(2, 8, 8, 8));
centerPane1.add(customButton, BorderLayout.NORTH);
centerPane.add(centerPane1);
}
protected JPanel getMenuColorPane() {
JPanel menuColorPane = new JPanel();
menuColorPane.setLayout(new GridLayout(5, 8, 1, 1));
menuColorPane.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8));
return menuColorPane;
}
// 第一行,1个取色按钮 + 7个最近使用的颜色
protected JPanel getRow1Pane() {
JPanel row1Pane = new JPanel(FRGUIPaneFactory.createBorderLayout());
row1Pane.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 0));
row1Pane.setPreferredSize(new Dimension(135, 24)); // 宽度为 16 * 8 + 7
// 最近使用
UsedColorPane usedColorPane = new UsedColorPane(1, 8, 1, ColorSelectConfigManager.getInstance().getColors(), this, true, true);
usedColorPane.getPane().setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 8));
row1Pane.add(usedColorPane.getPane());
return row1Pane;
}
protected Color[] getColorArray(){
for (int i = 0; i < colorArray.length; i++) {
Color color = colorArray[i] == null ? UsedColorPane.DEFAULT_COLOR : colorArray[i];
menuColorPane1.add(new ColorCell(color, this));
}
centerPane.add(Box.createVerticalStrut(1));
UIButton customButton = new UIButton(Inter.getLocText("FR-Designer-Basic_More_Color"));
customButton.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
customButtonPressed();
}
});
customButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
JPanel centerPane1 = FRGUIPaneFactory.createBorderLayout_S_Pane();
centerPane1.setBorder(BorderFactory.createEmptyBorder(2, 8, 8, 8));
centerPane1.add(customButton, BorderLayout.NORTH);
centerPane.add(centerPane1);
}
protected JPanel getMenuColorPane() {
JPanel menuColorPane = new JPanel();
menuColorPane.setLayout(new GridLayout(5, 8, 1, 1));
menuColorPane.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8));
return menuColorPane;
}
// 第一行,1个取色按钮 + 1个留空的单元格 + 6个最近使用的颜色
protected JPanel getRow1Pane() {
JPanel row1Pane = new JPanel(FRGUIPaneFactory.createBorderLayout());
row1Pane.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 0));
row1Pane.setPreferredSize(new Dimension(135, 24)); // 宽度为 16 * 8 + 7
// 最近使用
UsedColorPane usedColorPane = new UsedColorPane(1, 8, 1, this, true, true);
usedColorPane.getPane().setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 8));
row1Pane.add(usedColorPane.getPane());
return row1Pane;
}
protected Color[] getColorArray() {
return ColorFactory.MenuColors;
}
@ -125,15 +123,16 @@ public class ColorSelectPane extends TransparentPane implements ColorSelectable
/**
* Add change listener.
* 增加监听
* @param 监听
*
* @param changeListener
*/
public void addChangeListener(ChangeListener changeListener) {
this.colorChangeListenerList.add(changeListener);
}
@Override
protected String title4PopupWindow() {
return "Color";
return "Color";
}
/**
@ -166,38 +165,36 @@ public class ColorSelectPane extends TransparentPane implements ColorSelectable
/**
* 选中颜色
* @param 颜色单元格
*
*/
@Override
public void colorSetted(ColorCell colorCell) {
colorCell.repaint();
}
/**
* 初始化中央面板
* @param centerPane 中央面板
*
*/
@Override
public void initCenterPaneChildren(JPanel centerPane) {
GUICoreUtils.initCenterPaneChildren(centerPane, this);
}
/**
* 透明
*/
@Override
public void doTransparent() {
this.setColor(null);
}
/**
* 更多颜色
*/
@Override
public void customButtonPressed() {
pane = new ColorSelectDetailPane(Color.WHITE);
ColorSelectDialog.showDialog(DesignerContext.getDesignerFrame(), pane, Color.WHITE, this);
}
@Override
public void colorSetted(ColorCell colorCell) {
colorCell.repaint();
}
/**
* 初始化中央面板
*
* @param centerPane 中央面板
*/
@Override
public void initCenterPaneChildren(JPanel centerPane) {
GUICoreUtils.initCenterPaneChildren(centerPane, this);
}
/**
* 透明
*/
@Override
public void doTransparent() {
this.setColor(null);
}
/**
* 更多颜色
*/
@Override
public void customButtonPressed() {
pane = new ColorSelectDetailPane(Color.WHITE);
ColorSelectDialog.showDialog(DesignerContext.getDesignerFrame(), pane, Color.WHITE, this);
}
}

386
designer_base/src/com/fr/design/style/color/NewColorSelectPane.java

@ -1,215 +1,205 @@
package com.fr.design.style.color;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import com.fr.design.constants.UIConstants;
import com.fr.design.border.UIRoundedBorder;
import com.fr.design.constants.UIConstants;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.dialog.BasicPane;
import com.fr.general.Inter;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
/**
*
* @author zhou
* @since 2012-5-29上午10:39:35
*/
public class NewColorSelectPane extends BasicPane implements ColorSelectable {
private static final long serialVersionUID = -8634152305687249392L;
private Color color = null; // color
// color setting action.
private ArrayList<ChangeListener> colorChangeListenerList = new ArrayList<ChangeListener>();
// 颜色选择器
private ColorSelectDetailPane pane;
// 是否支持透明
private boolean isSupportTransparent;
private final static int TRANSPANENT_WINDOW_HEIGHT = 165;
private final static int WINDWO_HEIGHT = 150;
// 最近使用颜色
UsedColorPane usedColorPane;
/**
* Constructor.
*/
public NewColorSelectPane() {
this(false);
}
/**
* Constructor.
*/
public NewColorSelectPane(boolean isSupportTransparent) {
this.isSupportTransparent = isSupportTransparent;
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 5));
if (isSupportTransparent) {
UIButton transpanrentButton = new UIButton(Inter.getLocText("FR-Designer_ChartF-Transparency"));
this.add(transpanrentButton, BorderLayout.NORTH);
transpanrentButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doTransparent();
}
});
}
// center
JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane();
this.add(centerPane, BorderLayout.CENTER);
// 第一行
JPanel row1Pane = new JPanel(FRGUIPaneFactory.createBorderLayout());
row1Pane.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 0));
row1Pane.setPreferredSize(new Dimension(135, 16)); // 宽度为 16 * 8 + 7
centerPane.add(row1Pane);
// 最近使用
usedColorPane = new UsedColorPane(1, 8, 1, ColorSelectConfigManager.getInstance().getColors(), this, true, false);
usedColorPane.getPane().setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 8));
row1Pane.add(usedColorPane.getPane());
JPanel menuColorPane1 = new JPanel();
centerPane.add(menuColorPane1);
menuColorPane1.setLayout(new GridLayout(5, 8, 1, 1));
menuColorPane1.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8));
for (int i = 0; i < ColorFactory.MenuColors.length; i++) {
menuColorPane1.add(new ColorCell(ColorFactory.MenuColors[i], this));
}
centerPane.add(Box.createVerticalStrut(1));
// mod by anchore 16/11/16
UIButton customButton = new UIButton(Inter.getLocText("FR-Designer-Basic_More_Color"));
//UIButton customButton = new UIButton(Inter.getLocText(new String[]{"More", "Color"}) + "...");
customButton.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
customButtonPressed();
}
});
customButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
JPanel centerPane1 = FRGUIPaneFactory.createBorderLayout_S_Pane();
centerPane1.setBorder(BorderFactory.createEmptyBorder(2, 8, 0, 8));
centerPane1.add(customButton, BorderLayout.NORTH);
centerPane.add(centerPane1);
}
/**
* 添加监听
* @param 监听列表
* Add change listener.
*/
public void addChangeListener(ChangeListener changeListener) {
this.colorChangeListenerList.add(changeListener);
}
@Override
protected String title4PopupWindow() {
return "Color";
}
/**
* 获取颜色
* @return 颜色
* Return the color.
*/
public Color getColor() {
return color;
}
/**
* 获取颜色
*
* @return 颜色
*/
public Color getNotNoneColor() {
if (color == null) {
setColor(Color.WHITE);
return Color.WHITE;
}
return color;
}
/**
* Set the color.
*
* @param color
* the new color.
*/
@Override
public void setColor(Color color) {
this.color = color;
// fire color change.
if (!colorChangeListenerList.isEmpty()) {
ChangeEvent evt = new ChangeEvent(this);
for (int i = 0; i < colorChangeListenerList.size(); i++) {
this.colorChangeListenerList.get(i).stateChanged(evt);
}
}
ColorSelectConfigManager.getInstance().addToColorQueue(color);
this.repaint();
}
/**
* 设置颜色
* @param 颜色位置
*/
@Override
public void colorSetted(ColorCell colorCell) {
colorCell.repaint();
}
protected void doTransparent() {
setColor(null);
}
protected void customButtonPressed() {
pane = new ColorSelectDetailPane(Color.WHITE);
ColorSelectDialog.showDialog(DesignerContext.getDesignerFrame(), pane, Color.WHITE, this);
}
@Override
public Dimension getPreferredSize() {
if(isSupportTransparent){
return new Dimension(super.getPreferredSize().width, TRANSPANENT_WINDOW_HEIGHT);
}
return new Dimension(super.getPreferredSize().width, WINDWO_HEIGHT);
}
/**
* 更新最近使用颜色
*
*/
public void updateUsedColor(){
usedColorPane.updateUsedColor();
}
private static final long serialVersionUID = -8634152305687249392L;
private Color color = null; // color
// color setting action.
private ArrayList<ChangeListener> colorChangeListenerList = new ArrayList<ChangeListener>();
// 颜色选择器
private ColorSelectDetailPane pane;
// 是否支持透明
private boolean isSupportTransparent;
private final static int TRANSPANENT_WINDOW_HEIGHT = 165;
private final static int WINDWO_HEIGHT = 150;
// 最近使用颜色
private UsedColorPane usedColorPane;
/**
* Constructor.
*/
public NewColorSelectPane() {
this(false);
}
/**
* Constructor.
*/
public NewColorSelectPane(boolean isSupportTransparent) {
this.isSupportTransparent = isSupportTransparent;
this.setLayout(FRGUIPaneFactory.createBorderLayout());
this.setBorder(new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 5));
if (isSupportTransparent) {
UIButton transpanrentButton = new UIButton(Inter.getLocText("FR-Designer_ChartF-Transparency"));
this.add(transpanrentButton, BorderLayout.NORTH);
transpanrentButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doTransparent();
}
});
}
// center
JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane();
this.add(centerPane, BorderLayout.CENTER);
// 第一行
JPanel row1Pane = new JPanel(FRGUIPaneFactory.createBorderLayout());
row1Pane.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 0));
row1Pane.setPreferredSize(new Dimension(135, 16)); // 宽度为 16 * 8 + 7
centerPane.add(row1Pane);
// 最近使用
usedColorPane = new UsedColorPane(1, 8, 1, this, true, false);
usedColorPane.getPane().setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 8));
row1Pane.add(usedColorPane.getPane());
JPanel menuColorPane1 = new JPanel();
centerPane.add(menuColorPane1);
menuColorPane1.setLayout(new GridLayout(5, 8, 1, 1));
menuColorPane1.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8));
for (int i = 0; i < ColorFactory.MenuColors.length; i++) {
menuColorPane1.add(new ColorCell(ColorFactory.MenuColors[i], this));
}
centerPane.add(Box.createVerticalStrut(1));
// mod by anchore 16/11/16
UIButton customButton = new UIButton(Inter.getLocText("FR-Designer-Basic_More_Color"));
customButton.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
customButtonPressed();
}
});
customButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
JPanel centerPane1 = FRGUIPaneFactory.createBorderLayout_S_Pane();
centerPane1.setBorder(BorderFactory.createEmptyBorder(2, 8, 0, 8));
centerPane1.add(customButton, BorderLayout.NORTH);
centerPane.add(centerPane1);
}
/**
* 添加监听
*
* @param 监听列表 Add change listener.
*/
public void addChangeListener(ChangeListener changeListener) {
this.colorChangeListenerList.add(changeListener);
}
@Override
protected String title4PopupWindow() {
return "Color";
}
/**
* 获取颜色
*
* @return 颜色
* Return the color.
*/
public Color getColor() {
return color;
}
/**
* 获取颜色
*
* @return 颜色
*/
public Color getNotNoneColor() {
if (color == null) {
setColor(Color.WHITE);
return Color.WHITE;
}
return color;
}
/**
* Set the color.
*
* @param color the new color.
*/
@Override
public void setColor(Color color) {
this.color = color;
// fire color change.
if (!colorChangeListenerList.isEmpty()) {
ChangeEvent evt = new ChangeEvent(this);
for (int i = 0; i < colorChangeListenerList.size(); i++) {
this.colorChangeListenerList.get(i).stateChanged(evt);
}
}
ColorSelectConfigManager.getInstance().addToColorQueue(color);
this.repaint();
}
/**
* 设置颜色
*
* @param 颜色位置
*/
@Override
public void colorSetted(ColorCell colorCell) {
colorCell.repaint();
}
protected void doTransparent() {
setColor(null);
}
protected void customButtonPressed() {
pane = new ColorSelectDetailPane(Color.WHITE);
ColorSelectDialog.showDialog(DesignerContext.getDesignerFrame(), pane, Color.WHITE, this);
}
@Override
public Dimension getPreferredSize() {
if (isSupportTransparent) {
return new Dimension(super.getPreferredSize().width, TRANSPANENT_WINDOW_HEIGHT);
}
return new Dimension(super.getPreferredSize().width, WINDWO_HEIGHT);
}
/**
* 更新最近使用颜色
*/
public void updateUsedColor() {
usedColorPane.updateUsedColor();
}
}

91
designer_base/src/com/fr/design/style/color/RecentUseColorPane.java

@ -1,55 +1,48 @@
package com.fr.design.style.color;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JColorChooser;
import javax.swing.JPanel;
import com.fr.design.dialog.BasicPane;
import com.fr.design.layout.FRGUIPaneFactory;
public class RecentUseColorPane extends BasicPane implements ColorSelectable{
JColorChooser chooser;
@Override
protected String title4PopupWindow() {
return null;
}
public RecentUseColorPane() {
}
public RecentUseColorPane(JColorChooser chooser) {
this.chooser = chooser;
// center
JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane();
this.add(centerPane, BorderLayout.CENTER);
// 最近使用
UsedColorPane pane = new UsedColorPane(2, 10, ColorSelectConfigManager.getInstance().getColors(),this);
centerPane.add(pane.getPane());
}
/**
* 选中颜色
*
* @param 颜色
*/
@Override
public void colorSetted(ColorCell color) {
}
@Override
public Color getColor() {
return null;
}
@Override
public void setColor(Color color) {
chooser.getSelectionModel().setSelectedColor(color);
}
import javax.swing.*;
import java.awt.*;
public class RecentUseColorPane extends BasicPane implements ColorSelectable {
private JColorChooser chooser;
@Override
protected String title4PopupWindow() {
return null;
}
public RecentUseColorPane(JColorChooser chooser) {
this.chooser = chooser;
// center
JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane();
this.add(centerPane, BorderLayout.CENTER);
// 最近使用
UsedColorPane pane = new UsedColorPane(2, 10, this);
centerPane.add(pane.getPane());
}
/**
* 选中颜色
*/
@Override
public void colorSetted(ColorCell color) {
}
@Override
public Color getColor() {
return null;
}
@Override
public void setColor(Color color) {
chooser.getSelectionModel().setSelectedColor(color);
}
}

219
designer_base/src/com/fr/design/style/color/UsedColorPane.java

@ -1,119 +1,112 @@
package com.fr.design.style.color;
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import com.fr.design.dialog.BasicPane;
import com.fr.design.gui.ibutton.SpecialUIButton;
public class UsedColorPane extends BasicPane{
public static final Color DEFAULT_COLOR = new Color(222,222,222);
// 最近使用面板列数
private int columns;
// 最近使用面板行数
private int rows;
// 留白的单元格数量
private int reserveCells;
// 是否需要取色器按钮
private boolean needPickColorButton;
// 是否在取色时实时设定颜色
private boolean setColorRealTime;
// 最近使用颜色
private Object[] colors;
// 最近使用面板
private JPanel pane;
private ColorSelectable selectable;
public JPanel getPane() {
return pane;
}
public void setPane(JPanel pane) {
this.pane = pane;
}
public UsedColorPane(){
}
/**
* 构造函数
*
* @param rows
* @param columns
* @param reserveCells 留白的单元格个数
* @param colors 最近使用的颜色
* @param needPickColorButton 是否需要加上取色器按钮
* @param setColorRealTime 取色器是否实时设定颜色
*/
public UsedColorPane(int rows,int columns,int reserveCells, Object[] colors, ColorSelectable selectable, boolean needPickColorButton, boolean setColorRealTime){
this.columns = columns;
this.rows = rows;
this.reserveCells = reserveCells;
this.colors = colors;
this.selectable = selectable;
this.needPickColorButton = needPickColorButton;
this.setColorRealTime = setColorRealTime;
initialComponents();
}
public UsedColorPane(int rows,int columns, Object[] colors,ColorSelectable selectable){
this(rows, columns, 0, colors, selectable, false, false);
}
private void initialComponents(){
int total = columns * rows;
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(rows,columns, 1, 1));
panel.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8));
Color[] colors = ColorSelectConfigManager.getInstance().getColors();
int size = colors.length;
int i = 0;
if (needPickColorButton) {
// 取色按钮
SpecialUIButton pickColorButton = PickColorButtonFactory.getPickColorButton(selectable, PickColorButtonFactory.IconType.ICON16, setColorRealTime);
panel.add(pickColorButton);
i++;
this.reserveCells += 1;
}
while (i < this.reserveCells) {
ColorCell cc = new ColorCell(DEFAULT_COLOR, selectable);
cc.setVisible(false);
panel.add(cc);
i++;
}
while (i < total) {
Color color = i < size ? colors[size-1-i]: DEFAULT_COLOR;
panel.add(new ColorCell(color == null ? DEFAULT_COLOR : color, selectable));
i++;
}
this.pane = panel;
}
/**
* 更新最近使用颜色
*
*/
public void updateUsedColor(){
int total = columns * rows;
Color[] colors = ColorSelectConfigManager.getInstance().getColors();
int size = colors.length;
for(int i=this.reserveCells; i<total; i++){
ColorCell cell = (ColorCell) this.pane.getComponent(i);
Color color = i < size ? colors[size-1-i]: DEFAULT_COLOR;
cell.setColor(color == null ? DEFAULT_COLOR : color);
}
}
@Override
protected String title4PopupWindow() {
return null;
}
import javax.swing.*;
import java.awt.*;
public class UsedColorPane extends BasicPane {
// 默认显示颜色
public static final Color DEFAULT_COLOR = new Color(222, 222, 222);
// 最近使用面板列数
private int columns;
// 最近使用面板行数
private int rows;
// 留白的单元格数量
private int reserveCells;
// 是否需要取色器按钮
private boolean needPickColorButton;
// 是否在取色时实时设定颜色
private boolean setColorRealTime;
// 最近使用面板
private JPanel pane;
private ColorSelectable selectable;
public JPanel getPane() {
return pane;
}
public void setPane(JPanel pane) {
this.pane = pane;
}
/**
* 构造函数
*
* @param rows
* @param columns
* @param reserveCells 留白的单元格个数
* @param colors 最近使用的颜色
* @param needPickColorButton 是否需要加上取色器按钮
* @param setColorRealTime 取色器是否实时设定颜色
*/
public UsedColorPane(int rows, int columns, int reserveCells, ColorSelectable selectable, boolean needPickColorButton, boolean setColorRealTime) {
this.columns = columns;
this.rows = rows;
this.reserveCells = reserveCells;
this.selectable = selectable;
this.needPickColorButton = needPickColorButton;
this.setColorRealTime = setColorRealTime;
initialComponents();
}
public UsedColorPane(int rows, int columns, ColorSelectable selectable) {
this(rows, columns, 0, selectable, false, false);
}
private void initialComponents() {
int total = columns * rows;
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(rows, columns, 1, 1));
panel.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8));
//最近使用颜色
Color[] colors = ColorSelectConfigManager.getInstance().getColors();
int size = colors.length;
int i = 0;
if (needPickColorButton) {
// 取色按钮
SpecialUIButton pickColorButton = PickColorButtonFactory.getPickColorButton(selectable, PickColorButtonFactory.IconType.ICON16, setColorRealTime);
panel.add(pickColorButton);
i++;
this.reserveCells += 1;
}
while (i < this.reserveCells) {
ColorCell cc = new ColorCell(DEFAULT_COLOR, selectable);
cc.setVisible(false);
panel.add(cc);
i++;
}
while (i < total) {
Color color = i < size ? colors[size - (i - this.reserveCells) - 1] : DEFAULT_COLOR;
panel.add(new ColorCell(color == null ? DEFAULT_COLOR : color, selectable));
i++;
}
this.pane = panel;
}
/**
* 更新最近使用颜色
*/
public void updateUsedColor() {
int total = columns * rows;
Color[] colors = ColorSelectConfigManager.getInstance().getColors();
int size = colors.length;
for (int i = this.reserveCells; i < total; i++) {
ColorCell cell = (ColorCell) this.pane.getComponent(i);
Color color = i < size ? colors[size - (i - this.reserveCells) - 1] : DEFAULT_COLOR;
cell.setColor(color == null ? DEFAULT_COLOR : color);
}
}
@Override
protected String title4PopupWindow() {
return null;
}
}
Loading…
Cancel
Save