From 9421bfc288ff0198d933033ba6257568ed558fb6 Mon Sep 17 00:00:00 2001 From: plough Date: Thu, 19 Jan 2017 17:37:55 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-1096=20=E5=8F=96=E8=89=B2=E6=9D=BF=3D>?= =?UTF-8?q?=E5=B0=86=E2=80=9C=E6=9C=80=E8=BF=91=E4=BD=BF=E7=94=A8=E7=9A=84?= =?UTF-8?q?=E9=A2=9C=E8=89=B2=E2=80=9D=E9=9D=A2=E6=9D=BF=E7=9A=84=E8=89=B2?= =?UTF-8?q?=E5=9D=97=E6=94=B9=E4=B8=BA6=E4=B8=AA=EF=BC=9B=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=8F=96=E8=89=B2=20=E5=99=A8=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E4=B8=BA=E7=99=BD=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/style/color/ColorSelectPane.java | 2 +- .../style/color/CustomChooserPanel.java | 3 +- .../style/color/NewColorSelectPane.java | 2 +- .../style/color/PickColorButtonFactory.java | 48 +++++++++++++++---- .../fr/design/style/color/UsedColorPane.java | 16 ++++--- 5 files changed, 54 insertions(+), 17 deletions(-) diff --git a/designer_base/src/com/fr/design/style/color/ColorSelectPane.java b/designer_base/src/com/fr/design/style/color/ColorSelectPane.java index 851768f5a7..91d2b06dfb 100644 --- a/designer_base/src/com/fr/design/style/color/ColorSelectPane.java +++ b/designer_base/src/com/fr/design/style/color/ColorSelectPane.java @@ -111,7 +111,7 @@ public class ColorSelectPane extends TransparentPane implements ColorSelectable row1Pane.setPreferredSize(new Dimension(135, 24)); // 宽度为 16 * 8 + 7 // 最近使用 - UsedColorPane usedColorPane = new UsedColorPane(1, 8, 1, true, ColorSelectConfigManager.getInstance().getColors(),this); + 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; diff --git a/designer_base/src/com/fr/design/style/color/CustomChooserPanel.java b/designer_base/src/com/fr/design/style/color/CustomChooserPanel.java index 21f23b783c..2f22a9f8f2 100644 --- a/designer_base/src/com/fr/design/style/color/CustomChooserPanel.java +++ b/designer_base/src/com/fr/design/style/color/CustomChooserPanel.java @@ -21,6 +21,7 @@ import javax.swing.event.DocumentListener; import javax.swing.text.BadLocationException; import javax.swing.text.Document; +import com.fr.design.gui.ibutton.SpecialUIButton; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIRadioButton; import com.fr.design.gui.ilable.UILabel; @@ -706,7 +707,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec mainPanel.add(hexPanel, BorderLayout.SOUTH); JPanel rightPane = new JPanel(new BorderLayout()); - UIButton pickColorButton = PickColorButtonFactory.getPickColorButton(this, PickColorButtonFactory.IconType.ICON18, true); + SpecialUIButton pickColorButton = PickColorButtonFactory.getPickColorButton(this, PickColorButtonFactory.IconType.ICON18, true); JPanel blankArea = new JPanel(); blankArea.setPreferredSize(new Dimension(100, 175)); rightPane.add(blankArea, BorderLayout.CENTER); diff --git a/designer_base/src/com/fr/design/style/color/NewColorSelectPane.java b/designer_base/src/com/fr/design/style/color/NewColorSelectPane.java index b8cff5cde5..b9903a81f3 100644 --- a/designer_base/src/com/fr/design/style/color/NewColorSelectPane.java +++ b/designer_base/src/com/fr/design/style/color/NewColorSelectPane.java @@ -85,7 +85,7 @@ public class NewColorSelectPane extends BasicPane implements ColorSelectable { row1Pane.setPreferredSize(new Dimension(135, 16)); // 宽度为 16 * 8 + 7 centerPane.add(row1Pane); // 最近使用 - usedColorPane = new UsedColorPane(1, 8, 1, true, ColorSelectConfigManager.getInstance().getColors(),this); + 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()); diff --git a/designer_base/src/com/fr/design/style/color/PickColorButtonFactory.java b/designer_base/src/com/fr/design/style/color/PickColorButtonFactory.java index 0eb28af751..e393609b91 100644 --- a/designer_base/src/com/fr/design/style/color/PickColorButtonFactory.java +++ b/designer_base/src/com/fr/design/style/color/PickColorButtonFactory.java @@ -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); + } + } + } } diff --git a/designer_base/src/com/fr/design/style/color/UsedColorPane.java b/designer_base/src/com/fr/design/style/color/UsedColorPane.java index 26e0915542..c8dfdcaece 100644 --- a/designer_base/src/com/fr/design/style/color/UsedColorPane.java +++ b/designer_base/src/com/fr/design/style/color/UsedColorPane.java @@ -7,7 +7,7 @@ import javax.swing.BorderFactory; import javax.swing.JPanel; import com.fr.design.dialog.BasicPane; -import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ibutton.SpecialUIButton; public class UsedColorPane extends BasicPane{ @@ -21,6 +21,8 @@ public class UsedColorPane extends BasicPane{ private int reserveCells; // 是否需要取色器按钮 private boolean needPickColorButton; + // 是否在取色时实时设定颜色 + private boolean setColorRealTime; // 最近使用颜色 private Object[] colors; // 最近使用面板 @@ -46,21 +48,23 @@ public class UsedColorPane extends BasicPane{ * @param rows 行 * @param columns 列 * @param reserveCells 留白的单元格个数 - * @param needPickColorButton 是否需要加上取色器按钮 * @param colors 最近使用的颜色 + * @param needPickColorButton 是否需要加上取色器按钮 + * @param setColorRealTime 取色器是否实时设定颜色 */ - public UsedColorPane(int rows,int columns,int reserveCells, boolean needPickColorButton, Object[] colors,ColorSelectable selectable){ + 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.needPickColorButton = needPickColorButton; 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, false, colors, selectable); + this(rows, columns, 0, colors, selectable, false, false); } private void initialComponents(){ @@ -74,7 +78,7 @@ public class UsedColorPane extends BasicPane{ int i = 0; if (needPickColorButton) { // 取色按钮 - UIButton pickColorButton = PickColorButtonFactory.getPickColorButton(selectable, PickColorButtonFactory.IconType.ICON16, true); + SpecialUIButton pickColorButton = PickColorButtonFactory.getPickColorButton(selectable, PickColorButtonFactory.IconType.ICON16, setColorRealTime); panel.add(pickColorButton); i++; this.reserveCells += 1;