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

151 lines
3.8 KiB

package com.fr.design.style.color;
import com.fr.base.BaseUtils;
import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.DesignerContext;
import javax.swing.JComponent;
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 JComponent implements ColorSelectable {
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 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();
return;
}
}
//打开颜色选择面板
showDialog();
}
private void showDialog() {
ColorSelectDetailPane pane = new ColorSelectDetailPane(getColor());
ColorSelectDialog.showDialog(DesignerContext.getDesignerFrame(), pane, getColor(), this, true);
Color color = this.getColor();
if (color != null) {
DesignerEnvManager.getEnvManager().getColorConfigManager().addToColorQueue(color);
}
}
public void stateChanged() {
if (changeListener != null) {
changeListener.stateChanged(null);
}
}
public void addChangeListener(ChangeListener changeListener) {
this.changeListener = changeListener;
}
@Override
public void setColor(Color color) {
this.color = color;
this.stateChanged();
}
@Override
public Color getColor() {
return this.color;
}
@Override
public void colorSetted(ColorCell colorCell) {
}
}