帆软报表设计器源代码。
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.
 
 
 
 

363 lines
12 KiB

package com.fr.design.style.color;
import com.fr.base.FineColor;
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.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 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;
/**
* @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 float BRIGHTNESS_VALUE = 0.15F;
private static final float PURITY_VALUE = 0.1F;
private FineColor color = null; // color
// color setting action.
private final ArrayList<ChangeListener> colorChangeListenerList = new ArrayList<>();
// 是否支持透明
private boolean isSupportTransparent;
private boolean isSupportThemeColor;
public final static int TRANSPARENT_WINDOW_HEIGHT = 165;
public final static int WINDOW_HEIGHT = 150;
// 最近使用颜色
private final NewUsedColorPane usedColorPane;
public static NewColorSelectPane createColorSelectPaneWithTheme(boolean supportTheme){
return new NewColorSelectPane(true, supportTheme);
}
/**
* Constructor.
*/
public NewColorSelectPane() {
this(true);
}
public NewColorSelectPane(boolean isSupportTransparent) {
this(isSupportTransparent, true);
}
/**
* 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, 4, 0 ,4));
this.add(centerPane, BorderLayout.CENTER);
JPanel menuColorPane1 = getMenuColorPane();
centerPane.add(menuColorPane1);
if(isSupportThemeColor){
initThemeColorPane(menuColorPane1);
}else {
initMenuColorPane(menuColorPane1);
}
// 增加最近使用 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.NORTH);
centerPane.add(row1Pane);
// 最近使用
usedColorPane = new NewUsedColorPane(8, this, selectRealTime());
usedColorPane.setPreferredSize(new Dimension(168, 16));
row1Pane.add(usedColorPane.getPane(), BorderLayout.CENTER);
// 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(9, 0, 11, 0));
centerPane1.add(customButton, BorderLayout.CENTER);
customButton.setPreferredSize(new Dimension(197, 20));
centerPane.add(centerPane1);
}
private void initThemeColorPane(JPanel menuColorPane){
menuColorPane.setLayout(new GridLayout(1, 8, 3, 0));
//todo 暂时先写死,后续对接的时候从主体里面拿主题配色
Color[] colorArray = new Color[]{Color.decode("#FFFFFF"), Color.decode("#CCCCCC"),
Color.decode("#E6A48A"), Color.decode("#E68A8A"), Color.gray, Color.green, Color.DARK_GRAY, Color.CYAN, Color.YELLOW, Color.lightGray};
for (int i = 0; i < colorArray.length; i++) {
Color color = colorArray[i];
boolean isDefaultColor = (i == 0 || i ==1);
JPanel jPanel = new JPanel(new GridLayout(5, 1, 0, 3));
jPanel.add(new FineColorCell(color, this, i, 0));
jPanel.add(new FineColorCell(color = saturationDown(color, isDefaultColor), this, i, 1));
jPanel.add(new FineColorCell(color = saturationDown(color, isDefaultColor), this, i, 2));
jPanel.add(new FineColorCell(color = saturationDown(color, isDefaultColor), this, i, 3));
jPanel.add(new FineColorCell(saturationDown(color, isDefaultColor), this, i, 4));
menuColorPane.add(jPanel);
}
}
/**
* 调整明度和纯度,默认色只调整明度
* @param color
* @param isDefaultColor
* @return
*/
public static Color saturationDown(Color color, boolean isDefaultColor) {
float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), new float[3]);
if (!isDefaultColor) {
hsb[1] += PURITY_VALUE;
}
hsb[2] -= BRIGHTNESS_VALUE;
return Color.getHSBColor(hsb[0], hsb[1], hsb[2]);
}
private void initMenuColorPane(JPanel menuColorPane){
menuColorPane.setLayout(new GridLayout(5, 8, 1, 1));
menuColorPane.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 8));
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) {
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);
}
}
DesignerEnvManager.getEnvManager().getColorConfigManager().addToColorQueue(color);
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() {
if (isSupportTransparent) {
return new Dimension(197, 207);
}
return new Dimension(197, 192);
}
/**
* 更新最近使用颜色
*/
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 + 2, 3, 3));
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);
ColorCell cc = new ColorCell(UsedColorPane.DEFAULT_COLOR, selectable);
cc.setVisible(false);
panel.add(cc);
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;
}
}
}