Browse Source

REPORT-1096 完成基本功能

master
plough 8 years ago
parent
commit
cc5d8edec9
  1. 0
      designer_base/src/com/fr/design/images/gui/colorSelectPane/colorPicker16.png
  2. 0
      designer_base/src/com/fr/design/images/gui/colorSelectPane/colorPicker18.png
  3. 45
      designer_base/src/com/fr/design/style/color/ColorPicker.java
  4. 2
      designer_base/src/com/fr/design/style/color/ColorSelectDialog.java
  5. 36
      designer_base/src/com/fr/design/style/color/CustomChooserPanel.java
  6. 13
      designer_base/src/com/fr/design/style/color/NewColorSelectPane.java
  7. 33
      designer_base/src/com/fr/design/style/color/PickColorButton.java

0
designer_base/src/com/fr/design/images/gui/colorSelectPane/colorPicker.png → designer_base/src/com/fr/design/images/gui/colorSelectPane/colorPicker16.png

Before

Width:  |  Height:  |  Size: 332 B

After

Width:  |  Height:  |  Size: 332 B

0
designer_base/src/com/fr/design/images/gui/colorSelectPane/colorPickerCustom.png → designer_base/src/com/fr/design/images/gui/colorSelectPane/colorPicker18.png

Before

Width:  |  Height:  |  Size: 432 B

After

Width:  |  Height:  |  Size: 432 B

45
designer_base/src/com/fr/design/style/color/ColorPicker.java

@ -3,6 +3,8 @@ package com.fr.design.style.color;
/**
* Created by plough on 2016/12/22.
*/
//import com.fr.design.dialog.UIDialog;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.Ellipse2D;
@ -28,10 +30,17 @@ public class ColorPicker extends JDialog implements ActionListener
private Point mousePos; // 鼠标的绝对坐标
private Color colorToSet; // 暂存要设置的颜色值
private Boolean setColorRealTime; // 实时设定颜色值
// private UIDialog modalDialog; // 对上层模态对话框的引用
/**
* 构造函数创建一个取色框窗体
*/
public ColorPicker(ColorSelectable colorSelectable)
public ColorPicker(ColorSelectable colorSelectable) {
this(colorSelectable, false);
}
public ColorPicker(ColorSelectable colorSelectable, Boolean setColorRealTime)
{
setUndecorated(true); // 去掉窗体边缘
setResizable(false);
@ -39,17 +48,29 @@ public class ColorPicker extends JDialog implements ActionListener
setShape(shape);
container.add(colorPickerPanel);
addMouseListener(new MouseFunctions());
addMouseMotionListener(new MouseMotionFunctions());
updateSize(colorPickerSize);
this.colorSelectable = colorSelectable;
this.setColorRealTime = setColorRealTime;
this.setAlwaysOnTop(true);
this.setVisible(true);
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
System.out.println("Construced ColorPicker.");
}
public void start() {
timer = new Timer(1000/FPS, this);
timer.start();
// if (!this.hasFocus()) {
// // 此时的焦点应该在模态对话框上
// modalDialog = (UIDialog)KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
// System.out.println("1 modalDialog is modal? " + modalDialog.isModal());
// modalDialog.setModal(false);
// System.out.println("2 modalDialog is modal? " + modalDialog.isModal());
// System.out.println("1 has focus? " + this.hasFocus());
// modalDialog.transferFocus();
// System.out.println("2 has focus? " + this.hasFocus());
// System.out.println("current focus: " + KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow());
// }
}
/**
@ -59,6 +80,10 @@ public class ColorPicker extends JDialog implements ActionListener
public void actionPerformed(ActionEvent e) {
updateLocation();
colorToSet = colorPickerPanel.getPixelColor(mousePos);
if (setColorRealTime) {
colorSelectable.setColor(colorToSet);
}
// System.out.println("hasFocus? " + this.hasFocus());
}
public void updateLocation() {
@ -85,6 +110,9 @@ public class ColorPicker extends JDialog implements ActionListener
public void pickComplete() {
timer.stop();
colorSelectable.setColor(colorToSet);
// if (modalDialog != null) {
// modalDialog.setModal(true);
// }
this.dispose();
}
@ -102,16 +130,10 @@ public class ColorPicker extends JDialog implements ActionListener
{
public void mousePressed(MouseEvent e)
{
System.out.println("Mouse Pressed!");
pickComplete();
}
}
private class MouseMotionFunctions extends MouseMotionAdapter
{
// public void mouseMoved(MouseEvent e) {
// hideCursor();
// }
}
}
class ColorPickerPanel extends JPanel
@ -187,12 +209,11 @@ class ColorPickerPanel extends JPanel
this
);
g2d.setColor(Color.black);
g2d.drawOval(0, 0, 190, 190);
g2d.setColor(Color.white);
g2d.drawOval(1, 1, 188, 188);
g2d.drawOval(2, 2, 186, 186);
g2d.setColor(Color.black);
g2d.drawOval(0, 0, 190, 190);
g2d.drawOval(3, 3, 184, 184);
g2d.setColor(Color.white);
@ -200,6 +221,4 @@ class ColorPickerPanel extends JPanel
g2d.setColor(Color.black);
g2d.drawRect(87, 87, 16, 16);
}
}

2
designer_base/src/com/fr/design/style/color/ColorSelectDialog.java

@ -137,7 +137,7 @@ public class ColorSelectDialog extends MiddleChartDialog{
public static void showDialog(Frame owner,ColorSelectDetailPane pane,Color initialColor,ColorSelectable selectePane){
ColorTracker okListener = new ColorTracker(pane);
ColorSelectDialog dialog = new ColorSelectDialog(owner,pane,initialColor,okListener,selectePane);
dialog.setModal(true);
// dialog.setModal(true);
dialog.show();
}

36
designer_base/src/com/fr/design/style/color/CustomChooserPanel.java

@ -10,10 +10,9 @@ import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.event.*;
import java.awt.image.MemoryImageSource;
import javax.swing.Timer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -45,7 +44,7 @@ import com.fr.general.Inter;
*
* @author focus
*/
class CustomChooserPanel extends AbstractColorChooserPanel {
class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelectable {
/**
* The gradient image displayed.
*/
@ -118,6 +117,8 @@ class CustomChooserPanel extends AbstractColorChooserPanel {
private transient UITextField field;
// private transient PickColorButton pickColorButton;
/**
* The default width of the gradient image.
@ -709,6 +710,14 @@ class CustomChooserPanel extends AbstractColorChooserPanel {
hexPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 8, 0));
hexPanel.add(new UILabel("#"));
hexPanel.add(field);
PickColorButton pickColorButton = new PickColorButton(PickColorButton.IconType.ICON18);
pickColorButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doPickColor();
}
});
hexPanel.add(pickColorButton);
mainPanel.add(hslAndRgbPanel, BorderLayout.CENTER);
mainPanel.add(hexPanel, BorderLayout.SOUTH);
@ -1062,4 +1071,23 @@ class CustomChooserPanel extends AbstractColorChooserPanel {
trackPix, 0, TRACK_WIDTH));
}
public Color getColor() {
return getColorSelectionModel().getSelectedColor();
}
public void setColor(Color color) {
getColorSelectionModel().setSelectedColor(color);
}
public void colorSetted(ColorCell cc) {
}
/**
* 打开取色框开始取色
*/
public void doPickColor() {
ColorPicker colorPicker = new ColorPicker(this, true);
colorPicker.start();
}
}

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

@ -87,7 +87,13 @@ public class NewColorSelectPane extends BasicPane implements ColorSelectable {
centerPane.add(row1Pane);
// 取色按钮
PickColorButton pickColorButton = new PickColorButton(this);
PickColorButton pickColorButton = new PickColorButton(PickColorButton.IconType.ICON18);
pickColorButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doPickColor();
}
});
row1Pane.add(pickColorButton, BorderLayout.WEST);
// 最近使用
@ -216,4 +222,9 @@ public class NewColorSelectPane extends BasicPane implements ColorSelectable {
usedColorPane.updateUsedColor();
}
public void doPickColor() {
ColorPicker colorPicker = new ColorPicker(this);
colorPicker.start();
}
}

33
designer_base/src/com/fr/design/style/color/PickColorButton.java

@ -4,34 +4,27 @@ import com.fr.base.BaseUtils;
import com.fr.design.gui.ibutton.UIButton;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Created by plough on 2016/12/22.
*/
public class PickColorButton extends UIButton {
private ColorSelectable colorSelectable;
public PickColorButton(ColorSelectable colorSelectable) {
super(BaseUtils.readIcon("/com/fr/design/images/gui/colorSelectPane/colorPicker.png"));
public PickColorButton(IconType iconType) {
super();
this.colorSelectable = colorSelectable;
this.setPreferredSize(new Dimension(16, 16));
if (iconType == IconType.ICON16) {
this.setIcon(BaseUtils.readIcon("/com/fr/design/images/gui/colorSelectPane/colorPicker16.png"));
this.setPreferredSize(new Dimension(16, 16));
} else {
this.setIcon(BaseUtils.readIcon("/com/fr/design/images/gui/colorSelectPane/colorPicker18.png"));
this.setPreferredSize(new Dimension(18, 18));
}
this.setCursor(new Cursor(Cursor.HAND_CURSOR));
this.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doPickColor();
}
});
}
/**
* 打开取色框开始取色
*/
public void doPickColor() {
ColorPicker colorPicker = new ColorPicker(colorSelectable);
colorPicker.start();
// 取色器按钮使用的图标
public enum IconType {
ICON16, ICON18
}
}

Loading…
Cancel
Save