|
|
|
@ -1,7 +1,10 @@
|
|
|
|
|
package com.fr.design.style.color; |
|
|
|
|
|
|
|
|
|
import com.fr.base.BaseUtils; |
|
|
|
|
import com.fr.design.gui.ibutton.UIButton; |
|
|
|
|
import com.fr.design.gui.ibutton.SpecialUIButton; |
|
|
|
|
|
|
|
|
|
import javax.swing.*; |
|
|
|
|
import javax.swing.plaf.ButtonUI; |
|
|
|
|
import java.awt.*; |
|
|
|
|
import java.awt.event.*; |
|
|
|
|
|
|
|
|
@ -9,22 +12,27 @@ import java.awt.event.*;
|
|
|
|
|
* Created by plough on 2016/12/22. |
|
|
|
|
*/ |
|
|
|
|
public class PickColorButtonFactory { |
|
|
|
|
private static int iconSize; |
|
|
|
|
private static IconType iconType; |
|
|
|
|
private static Image iconImage; |
|
|
|
|
|
|
|
|
|
public static UIButton getPickColorButton(ColorSelectable colorSelectable, IconType iconType) { |
|
|
|
|
public static SpecialUIButton getPickColorButton(ColorSelectable colorSelectable, IconType iconType) { |
|
|
|
|
return getPickColorButton(colorSelectable, iconType, false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static UIButton getPickColorButton(final ColorSelectable colorSelectable, IconType iconType, final Boolean setColorRealTime) { |
|
|
|
|
UIButton pickColorButton = new UIButton(); |
|
|
|
|
public static SpecialUIButton getPickColorButton(final ColorSelectable colorSelectable, IconType iconType, final boolean setColorRealTime) { |
|
|
|
|
SpecialUIButton pickColorButton = new SpecialUIButton(new WhiteButtonUI()); |
|
|
|
|
PickColorButtonFactory.iconType = iconType; |
|
|
|
|
|
|
|
|
|
if (iconType == IconType.ICON16) { |
|
|
|
|
pickColorButton.setIcon(BaseUtils.readIcon("/com/fr/design/images/gui/colorPicker/colorPicker16.png")); |
|
|
|
|
pickColorButton.setPreferredSize(new Dimension(16, 16)); |
|
|
|
|
iconImage = BaseUtils.readImage("/com/fr/design/images/gui/colorPicker/colorPicker16.png"); |
|
|
|
|
iconSize = 16; |
|
|
|
|
} else { |
|
|
|
|
pickColorButton.setIcon(BaseUtils.readIcon("/com/fr/design/images/gui/colorPicker/colorPicker18.png")); |
|
|
|
|
pickColorButton.setPreferredSize(new Dimension(18, 18)); |
|
|
|
|
iconImage = BaseUtils.readImage("/com/fr/design/images/gui/colorPicker/colorPicker18.png"); |
|
|
|
|
iconSize = 18; |
|
|
|
|
pickColorButton.setBorderPainted(false); |
|
|
|
|
} |
|
|
|
|
pickColorButton.setPreferredSize(new Dimension(iconSize, iconSize)); |
|
|
|
|
pickColorButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
|
|
|
|
|
|
|
|
|
pickColorButton.addMouseListener(new MouseAdapter() { |
|
|
|
@ -41,4 +49,28 @@ public class PickColorButtonFactory {
|
|
|
|
|
public enum IconType { |
|
|
|
|
ICON16, ICON18 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static class WhiteButtonUI extends ButtonUI { |
|
|
|
|
@Override |
|
|
|
|
public void paint(Graphics g, JComponent c) { |
|
|
|
|
super.paint(g, c); |
|
|
|
|
Dimension size = c.getSize(); |
|
|
|
|
g.setColor(Color.white); |
|
|
|
|
g.fillRoundRect(0, 0, size.width - 1, size.height - 1, 1, 1); |
|
|
|
|
g.setColor(new Color(153, 153, 153)); // #999999
|
|
|
|
|
g.drawRoundRect(0, 0, size.width - 1, size.height - 1, 1, 1); |
|
|
|
|
if (iconType == IconType.ICON16) { |
|
|
|
|
g.drawImage( |
|
|
|
|
iconImage, |
|
|
|
|
(size.width - iconImage.getWidth(null)) / 2, |
|
|
|
|
(size.height - iconImage.getHeight(null)) / 2, |
|
|
|
|
iconImage.getWidth(null), |
|
|
|
|
iconImage.getHeight(null), |
|
|
|
|
null |
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
g.drawImage(iconImage, 0, 0, iconSize, iconSize, null); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|