diff --git a/designer/src/com/fr/design/actions/report/ReportBackgroundAction.java b/designer/src/com/fr/design/actions/report/ReportBackgroundAction.java index 6e8fd84f0..4a381d4d0 100644 --- a/designer/src/com/fr/design/actions/report/ReportBackgroundAction.java +++ b/designer/src/com/fr/design/actions/report/ReportBackgroundAction.java @@ -5,6 +5,7 @@ package com.fr.design.actions.report; import com.fr.base.BaseUtils; import com.fr.design.actions.ReportComponentAction; +import com.fr.design.dialog.BasicDialog; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.ReportComponent; import com.fr.design.menu.KeySetUtils; diff --git a/designer/src/com/fr/design/actions/report/ReportParameterAction.java b/designer/src/com/fr/design/actions/report/ReportParameterAction.java index 61507ebfe..ef8454a76 100644 --- a/designer/src/com/fr/design/actions/report/ReportParameterAction.java +++ b/designer/src/com/fr/design/actions/report/ReportParameterAction.java @@ -21,7 +21,7 @@ import com.fr.main.parameter.ReportParameterAttr; /** * Report Parameter */ -public class ReportParameterAction extends JWorkBookAction { +public class ReportParameterAction extends JWorkBookAction{ public ReportParameterAction(JWorkBook jwb) { super(jwb); @@ -62,6 +62,7 @@ public class ReportParameterAction extends JWorkBookAction { jwb.fireTargetModified(); jwb.updateReportParameterAttr(); jwb.populateReportParameterAttr(); + } }); parameterArrayDialog.setVisible(true); diff --git a/designer/src/com/fr/design/report/freeze/RepeatAndFreezeSettingPane.java b/designer/src/com/fr/design/report/freeze/RepeatAndFreezeSettingPane.java index 8e70675ee..46bc378ae 100644 --- a/designer/src/com/fr/design/report/freeze/RepeatAndFreezeSettingPane.java +++ b/designer/src/com/fr/design/report/freeze/RepeatAndFreezeSettingPane.java @@ -8,12 +8,14 @@ import javax.swing.*; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import com.fr.base.FRContext; import com.fr.design.dialog.BasicPane; import com.fr.design.extra.WebDialog; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.ilable.ActionLabel; import com.fr.design.gui.ilable.UILabel; import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.env.RemoteEnv; import com.fr.general.Inter; import com.fr.page.ReportPageAttrProvider; import com.fr.stable.ColumnRow; @@ -211,13 +213,13 @@ public class RepeatAndFreezeSettingPane extends BasicPane { JPanel freezePanel = FRGUIPaneFactory.createBorderLayout_S_Pane(); //自适应插件 - JPanel infoPane = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("FR-Designer_Attention")); - - BoxCenterAligmentPane actionLabel = getURLActionLabel(Inter.getLocText("FR-Designer_Form-Fit-Tip")); - infoPane.add(actionLabel, BorderLayout.SOUTH); - + if (shouldShowTip()) { + JPanel infoPane = FRGUIPaneFactory.createTitledBorderPane(Inter.getLocText("FR-Designer_Attention")); + BoxCenterAligmentPane actionLabel = getURLActionLabel(Inter.getLocText("FR-Designer_Form-Fit-Tip")); + infoPane.add(actionLabel, BorderLayout.SOUTH); + this.add(infoPane, BorderLayout.SOUTH); + } outfreezePanel.add(freezePanel); - this.add(infoPane, BorderLayout.SOUTH); // 重复打印部分 // 重复打印标题的起始行 JPanel labelPanel = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); @@ -241,6 +243,10 @@ public class RepeatAndFreezeSettingPane extends BasicPane { initWriteListener(); } + private boolean shouldShowTip() { + return !(FRContext.getCurrentEnv() instanceof RemoteEnv) && FRContext.isChineseEnv(); + } + protected void initWriteListener() { // 填报重复冻结行 useWriteFrozenCCheckBox.addChangeListener(useWriteFrozenCListener); diff --git a/designer_base/src/com/fr/design/beans/FurtherBasicBeanPane.java b/designer_base/src/com/fr/design/beans/FurtherBasicBeanPane.java index 9129c2b87..8c61c96db 100644 --- a/designer_base/src/com/fr/design/beans/FurtherBasicBeanPane.java +++ b/designer_base/src/com/fr/design/beans/FurtherBasicBeanPane.java @@ -1,5 +1,7 @@ package com.fr.design.beans; +import com.fr.stable.StringUtils; + /** * * @author zhou @@ -17,8 +19,10 @@ public abstract class FurtherBasicBeanPane extends BasicBeanPane { * title应该是一个属性,不只是对话框的标题时用到,与其他组件结合时,也会用得到 * @return 绥化狂标题 */ - @Override - public abstract String title4PopupWindow(); + @Deprecated + public String title4PopupWindow(){ + return StringUtils.EMPTY; + } /** * 重置 diff --git a/designer_base/src/com/fr/design/editor/ValueEditorPane.java b/designer_base/src/com/fr/design/editor/ValueEditorPane.java index 5efaf5d57..0a7600e2f 100644 --- a/designer_base/src/com/fr/design/editor/ValueEditorPane.java +++ b/designer_base/src/com/fr/design/editor/ValueEditorPane.java @@ -106,6 +106,15 @@ public class ValueEditorPane extends BasicPane implements UIObserver, GlobalName return currentEditor; } + public int getCurrentEditorIndex() { + for (int i = 0;i < cards.length; i++){ + if (cards[i].getClass() == currentEditor.getClass()){ + return i; + } + } + return 0; + } + public void setCurrentEditor(int i) { this.add(arrowButton, BorderLayout.WEST); currentEditor = this.cards[i]; diff --git a/designer_base/src/com/fr/design/gui/frpane/HyperlinkGroupPane.java b/designer_base/src/com/fr/design/gui/frpane/HyperlinkGroupPane.java index 4d1028e78..112fa54dc 100644 --- a/designer_base/src/com/fr/design/gui/frpane/HyperlinkGroupPane.java +++ b/designer_base/src/com/fr/design/gui/frpane/HyperlinkGroupPane.java @@ -13,12 +13,12 @@ import com.fr.js.JavaScript; import com.fr.js.NameJavaScript; import com.fr.js.NameJavaScriptGroup; import com.fr.plugin.PluginManager; -import com.fr.stable.ArrayUtils; import com.fr.stable.Nameable; import java.util.ArrayList; -import java.util.List; +import java.util.Map; import java.util.Set; +import java.util.TreeMap; /** * 超级链接 界面. @@ -34,23 +34,26 @@ public class HyperlinkGroupPane extends JListControlPane { * @return 返回Nameable按钮数组. */ public NameableCreator[] createNameableCreators() { + Map nameCreators = new TreeMap(); NameableCreator[] creators = DesignModuleFactory.getHyperlinkGroupType().getHyperlinkCreators(); + for (NameableCreator creator : creators) { + nameCreators.put(creator.menuName(), creator); + } PluginManager.getInstance().setExtensionPoint(HyperlinkPluginAction.XML_TAG); ArrayList templateArrayLisy = PluginManager.getInstance().getResultList(); // if (templateArrayLisy.isEmpty()) { // return creators; // } - NameableCreator[] pluginCreators = new NameableCreator[templateArrayLisy.size()]; for (int i = 0; i < templateArrayLisy.size(); i++) { - pluginCreators[i] = ((HyperlinkPluginAction) templateArrayLisy.get(i)).getHyperlinkCreator(); + NameableCreator nameableCreator = ((HyperlinkPluginAction) templateArrayLisy.get(i)).getHyperlinkCreator(); + nameCreators.put(nameableCreator.menuName(), nameableCreator); } Set providers = ExtraDesignClassManager.getInstance().getArray(HyperlinkProvider.XML_TAG); - List creatorList = new ArrayList(); for (HyperlinkProvider provider : providers) { NameableCreator nc = provider.createHyperlinkCreator(); - creatorList.add(nc); + nameCreators.put(nc.menuName(), nc); } - return ArrayUtils.addAll(creatorList.toArray(new NameableCreator[creatorList.size()]), ArrayUtils.addAll(creators, pluginCreators)); + return nameCreators.values().toArray(new NameableCreator[nameCreators.size()]); } /** diff --git a/designer_base/src/com/fr/design/gui/icombobox/FRTreeComboBox.java b/designer_base/src/com/fr/design/gui/icombobox/FRTreeComboBox.java index a60942229..ed8ffb16c 100644 --- a/designer_base/src/com/fr/design/gui/icombobox/FRTreeComboBox.java +++ b/designer_base/src/com/fr/design/gui/icombobox/FRTreeComboBox.java @@ -91,6 +91,15 @@ public class FRTreeComboBox extends UIComboBox { return this.tree; } + /** + * 自定义那些那些node可以选中,默认情况下所有node节点都可以选中 + * @param node + * @return + */ + protected boolean customSelectable(DefaultMutableTreeNode node){ + return true; + } + public void setTree(JTree tree) { this.tree = tree; if (tree != null) { @@ -403,6 +412,12 @@ public class FRTreeComboBox extends UIComboBox { if (comboBox.onlyLeafSelectable && !node.isLeaf()) { return; } + + //自定义node是否可选择 + if (!comboBox.customSelectable(node)){ + return; + } + comboBox.setSelectedItem(treePath); togglePopup(); MenuSelectionManager.defaultManager().clearSelectedPath(); diff --git a/designer_base/src/com/fr/design/gui/icombobox/UIComboBox.java b/designer_base/src/com/fr/design/gui/icombobox/UIComboBox.java index d6d149674..4840121b8 100644 --- a/designer_base/src/com/fr/design/gui/icombobox/UIComboBox.java +++ b/designer_base/src/com/fr/design/gui/icombobox/UIComboBox.java @@ -160,6 +160,10 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser uiObserverListener = listener; } + public void removeChangeListener(){ + uiObserverListener = null; + } + /** * @return */ diff --git a/designer_base/src/com/fr/design/hyperlink/AbstractHyperlinkPane.java b/designer_base/src/com/fr/design/hyperlink/AbstractHyperlinkPane.java index 36297d165..43f73b870 100644 --- a/designer_base/src/com/fr/design/hyperlink/AbstractHyperlinkPane.java +++ b/designer_base/src/com/fr/design/hyperlink/AbstractHyperlinkPane.java @@ -1,27 +1,19 @@ package com.fr.design.hyperlink; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.DefaultComboBoxModel; -import javax.swing.DefaultListCellRenderer; - -import com.fr.design.gui.ilable.UILabel; - -import javax.swing.JList; -import javax.swing.JPanel; - import com.fr.base.Utils; import com.fr.design.beans.BasicBeanPane; import com.fr.design.gui.icombobox.UIComboBox; +import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextfield.UINumberField; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.general.Inter; import com.fr.js.Hyperlink; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + public abstract class AbstractHyperlinkPane extends BasicBeanPane { public static final int NEW_WINDOW = 0; public static final int DIALOG = 1; @@ -46,7 +38,7 @@ public abstract class AbstractHyperlinkPane extends BasicBe headerPane = this.setHeaderPanel(); this.add(headerPane, BorderLayout.NORTH); this.add(centerPane, BorderLayout.CENTER); - targetFrameComboBox = new UIComboBox(new String[]{Inter.getLocText("Hyperlink-New_Window"), Inter.getLocText("FR-Hyperlink_Dialog"), Inter.getLocText("Hyperlink-Self_Window")}); + targetFrameComboBox = new UIComboBox(getTargetFrames()); targetFrameComboBox.setRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); @@ -86,6 +78,9 @@ public abstract class AbstractHyperlinkPane extends BasicBe this.add(this.setFootPanel(), BorderLayout.SOUTH); } + protected String[] getTargetFrames(){ + return new String[]{Inter.getLocText("Hyperlink-New_Window"), Inter.getLocText("FR-Hyperlink_Dialog"), Inter.getLocText("Hyperlink-Self_Window")}; + } protected abstract JPanel setHeaderPanel(); @@ -93,20 +88,34 @@ public abstract class AbstractHyperlinkPane extends BasicBe protected abstract void populateSubHyperlinkBean(T link); + public UIComboBox getTargetFrameComboBox() { + return targetFrameComboBox; + } + + public void setTargetFrameComboBox(UIComboBox targetFrameComboBox) { + this.targetFrameComboBox = targetFrameComboBox; + } + + public UINumberField getHeightTextFiled() { + return heightTextFiled; + } + + public void setHeightTextFiled(UINumberField heightTextFiled) { + this.heightTextFiled = heightTextFiled; + } + + public UINumberField getWidthTextFiled() { + return widthTextFiled; + } + + public void setWidthTextFiled(UINumberField widthTextFiled) { + this.widthTextFiled = widthTextFiled; + } + @Override public void populateBean(T link) { String name = link.getTargetFrame(); - if ("_self".equals(name)) { - targetFrameComboBox.setSelectedIndex(SELF); - } else if ("_dialog".equals(name)) { - targetFrameComboBox.setSelectedIndex(DIALOG); - } else if ("_blank".equals(name)) { - targetFrameComboBox.setSelectedIndex(NEW_WINDOW); - } else { - DefaultComboBoxModel model = (DefaultComboBoxModel) targetFrameComboBox.getModel(); - model.addElement(name); - targetFrameComboBox.setSelectedItem(name); - } + targetFrameComboBox.setSelectedIndex(HyperlinkTargetFrame.convert(name)); heightTextFiled.setText(String.valueOf(link.getHeight() == 0 ? DEFAULT_H_VALUE : link.getHeight())); widthTextFiled.setText(String.valueOf(link.getWidth() == 0 ? DEFAULT_V_VALUE : link.getWidth())); populateSubHyperlinkBean(link); diff --git a/designer_base/src/com/fr/design/hyperlink/HyperlinkTargetFrame.java b/designer_base/src/com/fr/design/hyperlink/HyperlinkTargetFrame.java index 80e9f21a0..f0b0543a4 100644 --- a/designer_base/src/com/fr/design/hyperlink/HyperlinkTargetFrame.java +++ b/designer_base/src/com/fr/design/hyperlink/HyperlinkTargetFrame.java @@ -1,5 +1,7 @@ package com.fr.design.hyperlink; +import com.fr.general.ComparatorUtils; + /** * Created by ibm on 2016/10/13. */ @@ -27,6 +29,18 @@ public enum HyperlinkTargetFrame { return BLANK_FRAME; } + public static int convert(String name) { + if (arrayOfValues == null) { + arrayOfValues = HyperlinkTargetFrame.values(); + } + for (HyperlinkTargetFrame hyperlinkTargetFrame : HyperlinkTargetFrame.values()) { + if (ComparatorUtils.equals(hyperlinkTargetFrame.getName(), name)) { + return hyperlinkTargetFrame.getIndex(); + } + } + return BLANK_FRAME.getIndex(); + } + public int getIndex() { return index; diff --git a/designer_base/src/com/fr/design/hyperlink/ReportletHyperlinkPane.java b/designer_base/src/com/fr/design/hyperlink/ReportletHyperlinkPane.java index 1cdb3dcbb..2664a746c 100644 --- a/designer_base/src/com/fr/design/hyperlink/ReportletHyperlinkPane.java +++ b/designer_base/src/com/fr/design/hyperlink/ReportletHyperlinkPane.java @@ -104,7 +104,7 @@ public class ReportletHyperlinkPane extends BasicBeanPane { } - private class HyperlinkParametersAction extends UITableEditAction { + protected class HyperlinkParametersAction extends UITableEditAction { public HyperlinkParametersAction() { this.setName(Inter.getLocText(new String[]{"Reportlet", "Parameter"})); this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/m_report/p.gif")); @@ -207,4 +207,27 @@ public class ReportletHyperlinkPane extends BasicBeanPane { } } + public ReporletHyperNorthPane getNorthPane() { + return northPane; + } + + public void setNorthPane(ReporletHyperNorthPane northPane) { + this.northPane = northPane; + } + + public ReportletParameterViewPane getParameterViewPane() { + return parameterViewPane; + } + + public void setParameterViewPane(ReportletParameterViewPane parameterViewPane) { + this.parameterViewPane = parameterViewPane; + } + + public UICheckBox getExtendParametersCheckBox() { + return extendParametersCheckBox; + } + + public void setExtendParametersCheckBox(UICheckBox extendParametersCheckBox) { + this.extendParametersCheckBox = extendParametersCheckBox; + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/hyperlink/WebHyperlinkPane.java b/designer_base/src/com/fr/design/hyperlink/WebHyperlinkPane.java index 88bff48fb..fda40217b 100644 --- a/designer_base/src/com/fr/design/hyperlink/WebHyperlinkPane.java +++ b/designer_base/src/com/fr/design/hyperlink/WebHyperlinkPane.java @@ -40,7 +40,7 @@ public class WebHyperlinkPane extends BasicBeanPane { parameterViewPane = new ReportletParameterViewPane(getChartParaType(), getValueEditorPane(), getValueEditorPane()); this.add(parameterViewPane, BorderLayout.CENTER); - parameterViewPane.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText("Parameters"), null)); + parameterViewPane.setBorder(GUICoreUtils.createTitledBorder(Inter.getLocText("FR-Designer_Parameters"), null)); useCJKCheckBox = new UICheckBox(Inter.getLocText("Hyperlink-Use_CJK_to_encode_parameter")); extendParametersCheckBox = new UICheckBox(Inter.getLocText("Hyperlink-Extends_Report_Parameters")); @@ -167,4 +167,36 @@ public class WebHyperlinkPane extends BasicBeanPane { return ParameterTableModel.CHART_METER_USE; } } + + public WebHyperNorthPane getNorthPane() { + return northPane; + } + + public void setNorthPane(WebHyperNorthPane northPane) { + this.northPane = northPane; + } + + public ReportletParameterViewPane getParameterViewPane() { + return parameterViewPane; + } + + public void setParameterViewPane(ReportletParameterViewPane parameterViewPane) { + this.parameterViewPane = parameterViewPane; + } + + public UICheckBox getUseCJKCheckBox() { + return useCJKCheckBox; + } + + public void setUseCJKCheckBox(UICheckBox useCJKCheckBox) { + this.useCJKCheckBox = useCJKCheckBox; + } + + public UICheckBox getExtendParametersCheckBox() { + return extendParametersCheckBox; + } + + public void setExtendParametersCheckBox(UICheckBox extendParametersCheckBox) { + this.extendParametersCheckBox = extendParametersCheckBox; + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/images/gui/colorPicker/colorPicker16.png b/designer_base/src/com/fr/design/images/gui/colorPicker/colorPicker16.png new file mode 100644 index 000000000..fc88b3bfc Binary files /dev/null and b/designer_base/src/com/fr/design/images/gui/colorPicker/colorPicker16.png differ diff --git a/designer_base/src/com/fr/design/images/gui/colorPicker/colorPicker18.png b/designer_base/src/com/fr/design/images/gui/colorPicker/colorPicker18.png new file mode 100644 index 000000000..afe0cd8eb Binary files /dev/null and b/designer_base/src/com/fr/design/images/gui/colorPicker/colorPicker18.png differ diff --git a/designer_base/src/com/fr/design/images/gui/colorPicker/colorPickerFrame.png b/designer_base/src/com/fr/design/images/gui/colorPicker/colorPickerFrame.png new file mode 100644 index 000000000..2772b7e20 Binary files /dev/null and b/designer_base/src/com/fr/design/images/gui/colorPicker/colorPickerFrame.png differ diff --git a/designer_base/src/com/fr/design/style/color/ColorPicker.java b/designer_base/src/com/fr/design/style/color/ColorPicker.java new file mode 100644 index 000000000..e616e08af --- /dev/null +++ b/designer_base/src/com/fr/design/style/color/ColorPicker.java @@ -0,0 +1,233 @@ +package com.fr.design.style.color; + +/** + * Created by plough on 2016/12/22. + */ + +import com.fr.base.BaseUtils; +import com.fr.general.FRLogger; + +import java.awt.*; +import java.awt.event.*; +import java.awt.geom.Ellipse2D; +import java.awt.image.BufferedImage; +import javax.swing.*; + +/** + * 取色框 + */ +public class ColorPicker extends JDialog implements ActionListener +{ + private Container container = getContentPane(); // 主容器 + private int setCoordinateX; // 取色框x坐标 + private int setCoordinateY; // 取色框y坐标 + private int colorPickerSize = 190; // 取色框尺寸 + private int scaleFactor = 16; // 放大倍数 + private ColorPickerPanel colorPickerPanel = new ColorPickerPanel(scaleFactor); // 取色框内容面板 + + private Timer timer; // 用于定时重绘 + private int FPS = 45; // 重绘取色器的频率 + private int timeCycle = 1000 / FPS; // 时钟周期 + + private ColorSelectable colorSelectable; + private Point mousePos; // 鼠标的绝对坐标 + private Color colorToSet; // 暂存要设置的颜色值 + private Color initColor; // 保存初始颜色。实时模式下,如果取消取色操作,则重设为初始颜色 + + private Boolean setColorRealTime; // 实时设定颜色值 + + + /** + * 构造函数,创建一个取色框窗体 + */ + public ColorPicker(ColorSelectable colorSelectable, Boolean setColorRealTime) + { + setUndecorated(true); // 去掉窗体边缘 + setResizable(false); + Shape shape = new Ellipse2D.Double(0, 0, colorPickerSize, colorPickerSize); + setShape(shape); + container.add(colorPickerPanel); + addMouseListener(new MouseFunctions()); + updateSize(colorPickerSize); + this.colorSelectable = colorSelectable; + this.setColorRealTime = setColorRealTime; + start(); + this.setModal(true); + this.setAlwaysOnTop(true); + updateLocation(); + this.setVisible(true); + this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + } + + public void start() { + timer = new Timer(timeCycle, this); + timer.start(); + hideCursor(); + + // 如果要求实时变化,确保先关闭弹窗,再截屏 + // 主要针对"图案"选项卡中的"前景"、"背景" + if (this.setColorRealTime) { + initColor = colorSelectable.getColor(); + colorSelectable.setColor(Color.WHITE); // setColor 可以关闭弹窗 + try { + Thread.sleep(100); // 等待弹窗关闭 + } catch (InterruptedException e) { + FRLogger.getLogger().error(e.getMessage()); + } + colorPickerPanel.captureScreen(); + } +// System.out.println(KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow()); + } + + /** + * 执行Timer要执行的部分, + */ + @Override + public void actionPerformed(ActionEvent e) { + updateLocation(); + colorToSet = colorPickerPanel.getPixelColor(mousePos); + if (setColorRealTime && (colorSelectable.getColor() == null || !colorSelectable.getColor().equals(colorToSet))) { + colorSelectable.setColor(colorToSet); + } + } + + public void updateLocation() { + mousePos = MouseInfo.getPointerInfo().getLocation(); + setCoordinateX = mousePos.x - getSize().width/2; + setCoordinateY = mousePos.y- getSize().height/2; + colorPickerPanel.setMagnifierLocation(setCoordinateX, + setCoordinateY); + setLocation(setCoordinateX, setCoordinateY); + } + + /** + * 更新窗体 + * + * @param colorPickerSize 取色框尺寸 + */ + public void updateSize(int colorPickerSize) + { + colorPickerPanel.setColorPickerSize(colorPickerSize); + setSize(colorPickerSize, colorPickerSize); + validate(); // 更新所有子控件 + } + + public void pickComplete(Color color) { + timer.stop(); + if (color != null) { + colorSelectable.setColor(color); + } + this.dispose(); + } + + // 隐藏鼠标光标 + public void hideCursor() { + Image imageCursor = Toolkit.getDefaultToolkit().getImage(""); + Cursor cu = Toolkit.getDefaultToolkit().createCustomCursor(imageCursor, new Point(0,0), "cursor"); + setCursor(cu); + } + + private class MouseFunctions extends MouseAdapter + { + public void mousePressed(MouseEvent e) + { + if (e.getButton() == e.BUTTON1) { // 左键确定 + pickComplete(colorToSet); + } else { + pickComplete(setColorRealTime ? initColor : null); + } + } + } +} + +class ColorPickerPanel extends JPanel +{ + private BufferedImage screenImage; + private Image colorPickerFrame; // 取色框的边框图案 + private int colorPickerSize; // 取色框尺寸 + private int locationX; // 取色框 x 坐标 + private int locationY; // 取色框 y 坐标 + private int scaleFactor; // 放大倍数 + private Robot robot; + + // getPixelColor 常数 + private static int SHIFT_STEP = 8; // 比特位右移步长 + private static int AND_R = 0xff0000; + private static int AND_G = 0xff00; + private static int AND_B = 0xff; + + /** + * 带参数的构造函数 + * @param scaleFactor 放大倍数 + */ + public ColorPickerPanel(int scaleFactor) + { + colorPickerFrame = BaseUtils.readImage("/com/fr/design/images/gui/colorPicker/colorPickerFrame.png"); + this.scaleFactor = scaleFactor; + captureScreen(); + } + + /** + * 截屏 + */ + public void captureScreen() { + try + { + robot = new Robot(); + } + catch (AWTException e) + { + } + // 截屏幕 + screenImage = robot.createScreenCapture(new Rectangle(0, 0, Toolkit + .getDefaultToolkit().getScreenSize().width, Toolkit + .getDefaultToolkit().getScreenSize().height)); + } + + /** + * 设置取色框的位置 + * @param locationX x坐标 + * @param locationY y坐标 + */ + public void setMagnifierLocation(int locationX, int locationY) + { + this.locationX = locationX; + this.locationY = locationY; + repaint(); // 注意重画控件 + } + + public Color getPixelColor(Point mousePos) { + int rgb = screenImage.getRGB(mousePos.x, mousePos.y); + int R = (rgb & AND_R) >> SHIFT_STEP * 2; + int G = (rgb & AND_G) >> SHIFT_STEP; + int B = (rgb & AND_B); + return new Color(R, G, B); + } + + public void setColorPickerSize(int colorPickerSize) + { + this.colorPickerSize = colorPickerSize; + } + + public void paintComponent(Graphics g) + { + Graphics2D g2d = (Graphics2D) g; + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); + + double pixelCount = (double)colorPickerSize / scaleFactor; // 取色器一条边上的放大后的像素点个数(可以是小数) + // 关键处理代码 + g2d.drawImage( + screenImage, // 要画的图片 + 0, // 目标矩形的第一个角的x坐标 + 0, // 目标矩形的第一个角的y坐标 + colorPickerSize, // 目标矩形的第二个角的x坐标 + colorPickerSize, // 目标矩形的第二个角的y坐标 + locationX + (int)((colorPickerSize - pixelCount) * 0.5) + 1, // 源矩形的第一个角的x坐标 + locationY + (int)((colorPickerSize - pixelCount) * 0.5) + 1, // 源矩形的第一个角的y坐标 + locationX + (int)((colorPickerSize + pixelCount) * 0.5) + 1, // 源矩形的第二个角的x坐标 + locationY + (int)((colorPickerSize + pixelCount) * 0.5) + 1, // 源矩形的第二个角的y坐标 + this + ); + g2d.drawImage(colorPickerFrame, 0, 0, this); + } +} \ No newline at end of file diff --git a/designer_base/src/com/fr/design/style/color/ColorSelectBox.java b/designer_base/src/com/fr/design/style/color/ColorSelectBox.java index f926775ee..2dd5d51c3 100644 --- a/designer_base/src/com/fr/design/style/color/ColorSelectBox.java +++ b/designer_base/src/com/fr/design/style/color/ColorSelectBox.java @@ -63,6 +63,7 @@ public class ColorSelectBox extends AbstractSelectBox implements UIObserv fireDisplayComponent(ColorBackground.getInstance(color)); } }); + colorPane.setColor(color); return colorPane; } diff --git a/designer_base/src/com/fr/design/style/color/ColorSelectDialog.java b/designer_base/src/com/fr/design/style/color/ColorSelectDialog.java index bee4b07d2..11a243b6c 100644 --- a/designer_base/src/com/fr/design/style/color/ColorSelectDialog.java +++ b/designer_base/src/com/fr/design/style/color/ColorSelectDialog.java @@ -91,8 +91,8 @@ public class ColorSelectDialog extends MiddleChartDialog{ this.add(buttonPane, BorderLayout.SOUTH); - ok = new UIButton(Inter.getLocText("OK")); - cancel = new UIButton(Inter.getLocText("Cancel")); + ok = new UIButton(Inter.getLocText("FR-Designer_Button_OK")); + cancel = new UIButton(Inter.getLocText("FR-Designer_Button_Cancel")); buttonPane.add(ok); buttonPane.add(cancel); 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 7370bfff7..743a71ce4 100644 --- a/designer_base/src/com/fr/design/style/color/ColorSelectPane.java +++ b/designer_base/src/com/fr/design/style/color/ColorSelectPane.java @@ -3,10 +3,7 @@ */ package com.fr.design.style.color; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Cursor; -import java.awt.GridLayout; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; @@ -71,10 +68,8 @@ public class ColorSelectPane extends TransparentPane implements ColorSelectable // center JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); this.add(centerPane, BorderLayout.CENTER); - - // 最近使用 - UsedColorPane pane = new UsedColorPane(1, 8, ColorSelectConfigManager.getInstance().getColors(),this); - centerPane.add(pane.getPane()); + + centerPane.add(getRow1Pane()); JPanel menuColorPane1 = new JPanel(); centerPane.add(menuColorPane1); @@ -104,6 +99,23 @@ public class ColorSelectPane extends TransparentPane implements ColorSelectable centerPane.add(centerPane1); } + // 第一行,1个取色按钮 + 7个最近使用的颜色 + private JPanel getRow1Pane() { + JPanel row1Pane = new JPanel(FRGUIPaneFactory.createBorderLayout()); + row1Pane.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 0)); + row1Pane.setPreferredSize(new Dimension(135, 24)); // 宽度为 16 * 8 + 7 + + // 取色按钮 + UIButton pickColorButton = PickColorButtonFactory.getPickColorButton(this, PickColorButtonFactory.IconType.ICON16, true); + row1Pane.add(pickColorButton, BorderLayout.WEST); + + // 最近使用 + UsedColorPane usedColorPane = new UsedColorPane(1, 7, ColorSelectConfigManager.getInstance().getColors(),this); + usedColorPane.getPane().setBorder(BorderFactory.createEmptyBorder(0, 1, 0, 8)); + row1Pane.add(usedColorPane.getPane()); + return row1Pane; + } + protected Color[] getColorArray(){ return ColorFactory.MenuColors; } 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 179e90abe..85363b0e6 100644 --- a/designer_base/src/com/fr/design/style/color/CustomChooserPanel.java +++ b/designer_base/src/com/fr/design/style/color/CustomChooserPanel.java @@ -10,9 +10,7 @@ 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 java.util.regex.Matcher; import java.util.regex.Pattern; @@ -21,7 +19,6 @@ import javax.swing.ButtonGroup; import javax.swing.Icon; import javax.swing.JColorChooser; import javax.swing.JPanel; -import javax.swing.JSlider; import javax.swing.SpinnerNumberModel; import javax.swing.SwingConstants; import javax.swing.colorchooser.AbstractColorChooserPanel; @@ -32,6 +29,7 @@ import javax.swing.event.DocumentListener; import javax.swing.text.BadLocationException; import javax.swing.text.Document; +import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIRadioButton; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.islider.UISlider; @@ -42,1031 +40,1039 @@ import com.fr.general.Inter; /** * 颜色选择器自定义面板 - * @author focus * + * @author focus */ -class CustomChooserPanel extends AbstractColorChooserPanel -{ - /** The gradient image displayed. */ - private transient Image gradientImage; +class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelectable { + /** + * The gradient image displayed. + */ + private transient Image gradientImage; - /** The Panel that holds the gradient image. */ - private transient JPanel gradientPanel; + /** + * The Panel that holds the gradient image. + */ + private transient JPanel gradientPanel; - /** The track gradient image. */ - private transient Image trackImage; + /** + * The track gradient image. + */ + private transient Image trackImage; - /** The panel that holds the track. */ - private transient JPanel trackPanel; + /** + * The panel that holds the track. + */ + private transient JPanel trackPanel; - /** The slider for the locked HSB value. */ - private transient UISlider slider; - - /** The RadioButton that controls the Hue. */ - private transient UIRadioButton hRadio; - - /** The RadioButton that controls the Saturation. */ - private transient UIRadioButton sRadio; - - /** The RadioButton that controls the Brightness. */ - private transient UIRadioButton bRadio; - - /** The UIBasicSpinner that controls the Hue. */ - private transient UIBasicSpinner hSpinner; - - /** The UIBasicSpinner that controls the Saturation. */ - private transient UIBasicSpinner sSpinner; - - /** The UIBasicSpinner that controls the Brightness. */ - private transient UIBasicSpinner bSpinner; - - /** The UIBasicSpinner that controls the Red. */ - private transient UIBasicSpinner rSpinner; - - /** The UIBasicSpinner that controls the Green. */ - private transient UIBasicSpinner gSpinner; - - /** The UIBasicSpinner that controls the Blue. */ - private transient UIBasicSpinner bbSpinner; - - private transient UITextField field; - - - /** The default width of the gradient image. */ - private static final int IMG_WIDTH = 200; - - /** The default height of the gradient image. */ - private static final int IMG_HEIGHT = 205; - - /** The default width of the track gradient. */ - private static final int TRACK_WIDTH = 20; - - /** The UILabel for Red. */ - private static final UILabel R = new UILabel("R"); - - /** The UILabel for Green. */ - private static final UILabel G = new UILabel("G"); - - /** The UILabel for Blue. */ - private static final UILabel B = new UILabel("B"); - - private static final int H_MAX = 365; - private static final int S_MAX = 100; - private static final int L_MAX = 100; - - private static final float HSPINNER_VALUE = 360f; - private static final float SSPINNER_VALUE = 100f; - private static final float LSPINNER_VALUE = 100f; - - private static final int BINARY_FOR_EIGHT = 255; - private static final int BINARY_FOR_FOUR = 16; - private static final int BINARY_FOR_THTEE = 8; - - private static final int TWENTY_FOUR = 24; - private static final int HEX_FF = 0xff; - - // 占位label - private static final UILabel PLACE_HOLDER_LABEL = new UILabel(); - - private ImageRGBScrollListener rgbScroll = new ImageRGBScrollListener(); - - - /** The point that is displayed in the gradient image. */ - private transient Point gradientPoint = new Point(); - - /** - * This indicates that the change to the slider or point is triggered - * internally. - */ - private transient boolean internalChange = false; - - /** This indicates that the change to the spinner is triggered internally. */ - private transient boolean spinnerTrigger = false; - - /** This int identifies which spinner is currently locked. */ - private transient int locked = -1; - - /** This value indicates that the Hue spinner is locked. */ - static final int HLOCKED = 0; - - /** This value indicates that the Saturation spinner is locked. */ - static final int SLOCKED = 1; - - /** This value indicates that the Brightness spinner is locked. */ - static final int BLOCKED = 2; - - /** - * This method indicates that the mouse event is in the process of being - * handled. - */ - private transient boolean handlingMouse; - - // 文本监听器,监听十六进制文本输入 - class TextDocumentListener implements DocumentListener{ - - // 十六进制颜色验证的正则表达式 - private static final String HEX_PATTERN = "([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$"; - private Pattern pattern; - private Matcher matcher; - @Override - public void insertUpdate(DocumentEvent e) { - Document doc = e.getDocument(); - updateColorForHex(doc); - } - - @Override - public void removeUpdate(DocumentEvent e) { - Document doc = e.getDocument(); - updateColorForHex(doc); - } - - @Override - public void changedUpdate(DocumentEvent e) { - - } - - private void updateColorForHex(Document doc){ - try { - String str = doc.getText(0, doc.getLength()); - pattern = Pattern.compile(HEX_PATTERN); - matcher = pattern.matcher(str); - if(matcher.matches()){ - Color color = new Color(Integer.parseInt(str, 16)); - CustomChooserPanel.this.getColorSelectionModel().setSelectedColor(color); - } - - } catch (BadLocationException e1) { - FRLogger.getLogger().error(e1.getMessage()); - } - } - } - - /** - * This helper class handles mouse events on the gradient image. - */ - class MainGradientMouseListener extends MouseAdapter - implements MouseMotionListener - { /** - * This method is called when the mouse is pressed over the gradient - * image. The JColorChooser is then updated with new HSB values. - * - * @param e The MouseEvent. + * The slider for the locked HSB value. + */ + private transient UISlider slider; + + /** + * The RadioButton that controls the Hue. + */ + private transient UIRadioButton hRadio; + + /** + * The RadioButton that controls the Saturation. + */ + private transient UIRadioButton sRadio; + + /** + * The RadioButton that controls the Brightness. + */ + private transient UIRadioButton bRadio; + + /** + * The UIBasicSpinner that controls the Hue. + */ + private transient UIBasicSpinner hSpinner; + + /** + * The UIBasicSpinner that controls the Saturation. + */ + private transient UIBasicSpinner sSpinner; + + /** + * The UIBasicSpinner that controls the Brightness. */ - public void mousePressed(MouseEvent e) - { - gradientPoint = e.getPoint(); - update(e.getPoint()); + private transient UIBasicSpinner bSpinner; + + /** + * The UIBasicSpinner that controls the Red. + */ + private transient UIBasicSpinner rSpinner; + + /** + * The UIBasicSpinner that controls the Green. + */ + private transient UIBasicSpinner gSpinner; + + /** + * The UIBasicSpinner that controls the Blue. + */ + private transient UIBasicSpinner bbSpinner; + + private transient UITextField field; + +// private transient PickColorButton pickColorButton; + + + /** + * The default width of the gradient image. + */ + private static final int IMG_WIDTH = 200; + + /** + * The default height of the gradient image. + */ + private static final int IMG_HEIGHT = 205; + + /** + * The default width of the track gradient. + */ + private static final int TRACK_WIDTH = 20; + + /** + * The UILabel for Red. + */ + private static final UILabel R = new UILabel("R"); + + /** + * The UILabel for Green. + */ + private static final UILabel G = new UILabel("G"); + + /** + * The UILabel for Blue. + */ + private static final UILabel B = new UILabel("B"); + + private static final int H_MAX = 365; + private static final int S_MAX = 100; + private static final int L_MAX = 100; + + private static final float HSPINNER_VALUE = 360f; + private static final float SSPINNER_VALUE = 100f; + private static final float LSPINNER_VALUE = 100f; + + private static final int BINARY_FOR_EIGHT = 255; + private static final int BINARY_FOR_FOUR = 16; + private static final int BINARY_FOR_THTEE = 8; + + private static final int TWENTY_FOUR = 24; + private static final int HEX_FF = 0xff; + + // 占位label + private static final UILabel PLACE_HOLDER_LABEL = new UILabel(); + + private ImageRGBScrollListener rgbScroll = new ImageRGBScrollListener(); + + + /** + * The point that is displayed in the gradient image. + */ + private transient Point gradientPoint = new Point(); + + /** + * This indicates that the change to the slider or point is triggered + * internally. + */ + private transient boolean internalChange = false; + + /** + * This indicates that the change to the spinner is triggered internally. + */ + private transient boolean spinnerTrigger = false; + + /** + * This int identifies which spinner is currently locked. + */ + private transient int locked = -1; + + /** + * This value indicates that the Hue spinner is locked. + */ + static final int HLOCKED = 0; + + /** + * This value indicates that the Saturation spinner is locked. + */ + static final int SLOCKED = 1; + + /** + * This value indicates that the Brightness spinner is locked. + */ + static final int BLOCKED = 2; + + /** + * This method indicates that the mouse event is in the process of being + * handled. + */ + private transient boolean handlingMouse; + + // 文本监听器,监听十六进制文本输入 + class TextDocumentListener implements DocumentListener { + + // 十六进制颜色验证的正则表达式 + private static final String HEX_PATTERN = "([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$"; + private Pattern pattern; + private Matcher matcher; + + @Override + public void insertUpdate(DocumentEvent e) { + Document doc = e.getDocument(); + updateColorForHex(doc); + } + + @Override + public void removeUpdate(DocumentEvent e) { + Document doc = e.getDocument(); + updateColorForHex(doc); + } + + @Override + public void changedUpdate(DocumentEvent e) { + + } + + private void updateColorForHex(Document doc) { + try { + String str = doc.getText(0, doc.getLength()); + pattern = Pattern.compile(HEX_PATTERN); + matcher = pattern.matcher(str); + if (matcher.matches()) { + Color color = new Color(Integer.parseInt(str, 16)); + CustomChooserPanel.this.getColorSelectionModel().setSelectedColor(color); + } + + } catch (BadLocationException e1) { + FRLogger.getLogger().error(e1.getMessage()); + } + } } /** - * This method is called when the mouse is dragged over the gradient - * image. The JColorChooser is then updated with the new HSB values. - * - * @param e The MouseEvent. + * This helper class handles mouse events on the gradient image. */ - public void mouseDragged(MouseEvent e) - { - Point p = e.getPoint(); - if (isMouseOutOfImage(p)){ - return; - } - - gradientPoint = p; - update(p); + class MainGradientMouseListener extends MouseAdapter + implements MouseMotionListener { + /** + * This method is called when the mouse is pressed over the gradient + * image. The JColorChooser is then updated with new HSB values. + * + * @param e The MouseEvent. + */ + public void mousePressed(MouseEvent e) { + gradientPoint = e.getPoint(); + update(e.getPoint()); + } + + /** + * This method is called when the mouse is dragged over the gradient + * image. The JColorChooser is then updated with the new HSB values. + * + * @param e The MouseEvent. + */ + public void mouseDragged(MouseEvent e) { + Point p = e.getPoint(); + if (isMouseOutOfImage(p)) { + return; + } + + gradientPoint = p; + update(p); + } + + private boolean isMouseOutOfImage(Point p) { + return (p.x < 0 || p.y < 0 || p.y > IMG_HEIGHT || p.x > IMG_WIDTH); + } + + /** + * This method is called when the mouse is moved over the gradient image. + * + * @param e The MouseEvent. + */ + public void mouseMoved(MouseEvent e) { + // Do nothing. + } + + /** + * This method updates the JColorChooser with the new values. + * + * @param p The Point where the MouseEvent occurred. + */ + private void update(Point p) { + handlingMouse = true; + if (hSpinner.isEnabled()) { + updateH(p); + } else if (sSpinner.isEnabled()) { + updateS(p); + } else { + updateB(p); + } + handlingMouse = false; + } + + /** + * This method updates the SB values if Hue is locked. + * + * @param p The point where the MouseEvent occurred. + */ + private void updateH(Point p) { + float s = (IMG_WIDTH - p.x * 1f) / IMG_WIDTH; + float b = (IMG_HEIGHT - p.y * 1f) / IMG_HEIGHT; + + // Avoid two changes to the model by changing internalChange to true. + internalChange = true; + sSpinner.setValue(new Integer((int) (s * S_MAX))); + internalChange = false; + bSpinner.setValue(new Integer((int) (b * L_MAX))); + + revalidate(); + } + + /** + * This method updates the HB values if Saturation is locked. + * + * @param p The point where the MouseEvent occurred. + */ + private void updateS(Point p) { + float h = p.x * 1f / IMG_WIDTH; + float b = (IMG_HEIGHT - p.y * 1f) / IMG_HEIGHT; + + internalChange = true; + hSpinner.setValue(new Integer((int) (h * H_MAX))); + internalChange = false; + bSpinner.setValue(new Integer((int) (b * L_MAX))); + + revalidate(); + } + + /** + * This method updates the HS values if Brightness is locked. + * + * @param p The point where the MouseEvent occurred. + */ + private void updateB(Point p) { + float h = p.x * 1f / IMG_WIDTH; + float s = (IMG_HEIGHT - p.y * 1f) / IMG_HEIGHT; + + internalChange = true; + hSpinner.setValue(new Integer((int) (h * H_MAX))); + internalChange = false; + sSpinner.setValue(new Integer((int) (s * S_MAX))); + + revalidate(); + } } - - private boolean isMouseOutOfImage(Point p){ - return (p.x < 0 || p.y < 0 || p.y > IMG_HEIGHT || p.x > IMG_WIDTH); + + /** + * This method listens for slider value changes. + */ + class SliderChangeListener implements ChangeListener { + /** + * This method is called when the slider value changes. It should change + * the color of the JColorChooser. + * + * @param e The ChangeEvent. + */ + public void stateChanged(ChangeEvent e) { + if (internalChange) { + return; + } + + + Integer value = new Integer(slider.getValue()); + + switch (locked) { + case HLOCKED: + hSpinner.setValue(value); + break; + case SLOCKED: + sSpinner.setValue(value); + break; + case BLOCKED: + bSpinner.setValue(value); + break; + } + updateImageAndTrack(); + } } /** - * This method is called when the mouse is moved over the gradient image. - * - * @param e The MouseEvent. + * This helper class determines the active UIBasicSpinner. */ - public void mouseMoved(MouseEvent e) - { - // Do nothing. + class RadioStateListener extends MouseAdapter + implements MouseMotionListener { + /** + * This method is called when there is a new UIRadioButton that was + * selected. As a result, it should activate the associated UIBasicSpinner. + * + * @param e The ChangeEvent. + */ + public void mousePressed(MouseEvent e) { + UIBasicSpinner change; + if (e.getSource() == hRadio) { + locked = HLOCKED; + change = hSpinner; + } else if (e.getSource() == sRadio) { + locked = SLOCKED; + change = sSpinner; + } else { + locked = BLOCKED; + change = bSpinner; + } + + hSpinner.setEnabled(false); + sSpinner.setEnabled(false); + bSpinner.setEnabled(false); + change.setEnabled(true); + updateSlider(); + updateTrack(); + updateImage(); + repaint(); + + } } /** - * This method updates the JColorChooser with the new values. - * - * @param p The Point where the MouseEvent occurred. + * hsl 监听 */ - private void update(Point p) - { - handlingMouse = true; - if (hSpinner.isEnabled()){ - updateH(p); - }else if (sSpinner.isEnabled()){ - updateS(p); - }else{ - updateB(p); - } - handlingMouse = false; + class ImageScrollListener implements ChangeListener { + /** + * This method is called whenever one of the UIBasicSpinner values change. The + * JColorChooser should be updated with the new HSB values. + * + * @param e The ChangeEvent. + */ + public void stateChanged(ChangeEvent e) { + if (internalChange) { + return; + } + updateImageAndTrack(); + updateSlider(); + } } /** - * This method updates the SB values if Hue is locked. - * - * @param p The point where the MouseEvent occurred. + * rgb 监听 */ - private void updateH(Point p) - { - float s = (IMG_WIDTH - p.x * 1f) / IMG_WIDTH; - float b = (IMG_HEIGHT - p.y * 1f) / IMG_HEIGHT; - - // Avoid two changes to the model by changing internalChange to true. - internalChange = true; - sSpinner.setValue(new Integer((int) (s * S_MAX))); - internalChange = false; - bSpinner.setValue(new Integer((int) (b * L_MAX))); - - revalidate(); + class ImageRGBScrollListener implements ChangeListener { + /** + * This method is called whenever one of the UIBasicSpinner values change. The + * JColorChooser should be updated with the new HSB values. + * + * @param e The ChangeEvent. + */ + public void stateChanged(ChangeEvent e) { + if (internalChange) { + return; + } + + + int r = (Integer) rSpinner.getValue(); + int g = (Integer) gSpinner.getValue(); + int bb = (Integer) bbSpinner.getValue(); + + spinnerTrigger = true; + getColorSelectionModel().setSelectedColor(new Color(r, g, bb)); + spinnerTrigger = false; + + updateChooser(); + repaint(); + } } /** - * This method updates the HB values if Saturation is locked. + * Creates a new DefaultHSBChooserPanel object. + */ + CustomChooserPanel() { + super(); + } + + /** + * This method returns the name displayed by the JColorChooser tab that + * holds this panel. * - * @param p The point where the MouseEvent occurred. + * @return The name displayed in the JColorChooser tab. */ - private void updateS(Point p) - { - float h = p.x * 1f / IMG_WIDTH; - float b = (IMG_HEIGHT - p.y * 1f) / IMG_HEIGHT; + public String getDisplayName() { + return Inter.getLocText("FR-Designer_Custom"); + } + + /** + * This method updates the various components inside the HSBPanel (the + * UIBasicSpinners, the JSlider, and the gradient image point) with updated + * values when the JColorChooser color value changes. + */ + public void updateChooser() { + Color c = getColorSelectionModel().getSelectedColor(); + float[] hsbVals = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), + null); + internalChange = true; + + adjustHSLValue(hsbVals); - internalChange = true; - hSpinner.setValue(new Integer((int) (h * H_MAX))); - internalChange = false; - bSpinner.setValue(new Integer((int) (b * L_MAX))); + internalChange = false; - revalidate(); + if (!handlingMouse && slider != null && !slider.getValueIsAdjusting()) { + updateImage(); + } + + if (!handlingMouse || locked != HLOCKED) { + updateTrack(); + } + updateTextFields(); + updateHexFields(); + } + + private void adjustHSLValue(float[] hsbVals) { + if (!spinnerTrigger) { + hSpinner.setValue(new Integer((int) (hsbVals[0] * HSPINNER_VALUE))); + sSpinner.setValue(new Integer((int) (hsbVals[1] * SSPINNER_VALUE))); + bSpinner.setValue(new Integer((int) (hsbVals[2] * LSPINNER_VALUE))); + } + switch (locked) { + case HLOCKED: + if (slider != null) { + slider.setValue(((Number) hSpinner.getValue()).intValue()); + } + if (!handlingMouse) { + gradientPoint.x = (int) ((1 + - ((Number) sSpinner.getValue()).intValue() / SSPINNER_VALUE) * IMG_WIDTH); + gradientPoint.y = (int) ((1 + - ((Number) bSpinner.getValue()).intValue() / LSPINNER_VALUE) * IMG_HEIGHT); + } + break; + case SLOCKED: + if (slider != null) { + slider.setValue(((Number) sSpinner.getValue()).intValue()); + } + if (!handlingMouse) { + gradientPoint.x = (int) (((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE * IMG_WIDTH); + gradientPoint.y = (int) ((1 + - ((Number) bSpinner.getValue()).intValue() / LSPINNER_VALUE) * IMG_HEIGHT); + } + break; + case BLOCKED: + if (slider != null) { + slider.setValue(((Number) bSpinner.getValue()).intValue()); + } + if (!handlingMouse) { + gradientPoint.x = (int) (((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE * IMG_WIDTH); + gradientPoint.y = (int) ((1 + - ((Number) sSpinner.getValue()).intValue() / SSPINNER_VALUE) * IMG_HEIGHT); + } + break; + } + } + + private void updateImageAndTrack() { + float h = ((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE; + float s = ((Number) sSpinner.getValue()).intValue() / SSPINNER_VALUE; + float b = ((Number) bSpinner.getValue()).intValue() / LSPINNER_VALUE; + + spinnerTrigger = true; + getColorSelectionModel().setSelectedColor(new Color(Color.HSBtoRGB(h, s, b))); + spinnerTrigger = false; + + if (!handlingMouse && slider != null && !slider.getValueIsAdjusting()) { + updateImage(); + updateTrack(); + } + updateTextFields(); + updateHexFields(); + repaint(); } /** - * This method updates the HS values if Brightness is locked. - * - * @param p The point where the MouseEvent occurred. + * This method builds the DefaultHSBChooserPanel. */ - private void updateB(Point p) - { - float h = p.x * 1f / IMG_WIDTH; - float s = (IMG_HEIGHT - p.y * 1f) / IMG_HEIGHT; + protected void buildChooser() { + setLayout(new BorderLayout()); + add(buildRightPanel(), BorderLayout.EAST); + JPanel container = new JPanel(); + container.setLayout(new BorderLayout()); + + gradientPanel = createGradientPanel(); + MouseAdapter ml = new MainGradientMouseListener(); + gradientPanel.addMouseListener(ml); + gradientPanel.addMouseMotionListener((MouseMotionListener) ml); + + trackPanel = createTrackPanel(); + + slider = new UISlider(); + slider.setPaintTrack(false); + slider.setPaintTicks(false); + + slider.setOrientation(SwingConstants.VERTICAL); + + updateSlider(); + + container.add(gradientPanel, BorderLayout.WEST); + container.add(slider, BorderLayout.CENTER); + container.add(trackPanel, BorderLayout.EAST); - internalChange = true; - hSpinner.setValue(new Integer((int) (h * H_MAX))); - internalChange = false; - sSpinner.setValue(new Integer((int) (s * S_MAX))); + add(container, BorderLayout.WEST); + slider.addChangeListener(new SliderChangeListener()); - revalidate(); + updateTextFields(); + updateHexFields(); + repaint(); + } + + private JPanel createGradientPanel() { + return new JPanel() { + public Dimension getPreferredSize() { + return new Dimension(IMG_WIDTH, IMG_HEIGHT); + } + + public void paint(Graphics g) { + if (gradientImage != null) { + g.drawImage(gradientImage, 0, 0, this); + } + + Color saved = g.getColor(); + g.setColor(Color.WHITE); + g.drawOval(gradientPoint.x - 3, gradientPoint.y - 3, 6, 6); + g.setColor(saved); + } + }; + } + + private JPanel createTrackPanel() { + return new JPanel() { + public Dimension getPreferredSize() { + return new Dimension(TRACK_WIDTH, IMG_HEIGHT); + } + + public void paint(Graphics g) { + if (trackImage != null) { + g.drawImage(trackImage, 0, 0, this); + } + + } + }; } - } - /** - * This method listens for slider value changes. - */ - class SliderChangeListener implements ChangeListener - { /** - * This method is called when the slider value changes. It should change - * the color of the JColorChooser. + * This method uninstalls the DefaultHSBPanel. * - * @param e The ChangeEvent. + * @param chooser The JColorChooser to remove this panel from. */ - public void stateChanged(ChangeEvent e) - { - if (internalChange){ - return; - } - - - Integer value = new Integer(slider.getValue()); - - switch (locked) - { - case HLOCKED: - hSpinner.setValue(value); - break; - case SLOCKED: - sSpinner.setValue(value); - break; - case BLOCKED: - bSpinner.setValue(value); - break; - } - updateImageAndTrack(); + public void uninstallChooserPanel(JColorChooser chooser) { + trackImage = null; + gradientImage = null; + gradientPanel = null; + slider = null; + + hSpinner = null; + sSpinner = null; + bSpinner = null; + + hRadio = null; + sRadio = null; + bRadio = null; + + removeAll(); + super.uninstallChooserPanel(chooser); } - } - - /** - * This helper class determines the active UIBasicSpinner. - */ - class RadioStateListener extends MouseAdapter - implements MouseMotionListener - { + /** - * This method is called when there is a new UIRadioButton that was - * selected. As a result, it should activate the associated UIBasicSpinner. + * This helper method creates the right side panel (the panel with the + * Spinners and TextFields). * - * @param e The ChangeEvent. + * @return The right side panel. */ - public void mousePressed(MouseEvent e) - { - UIBasicSpinner change; - if (e.getSource() == hRadio) - { - locked = HLOCKED; - change = hSpinner; - } - else if (e.getSource() == sRadio) - { - locked = SLOCKED; - change = sSpinner; - } - else - { - locked = BLOCKED; - change = bSpinner; - } - - hSpinner.setEnabled(false); + private Container buildRightPanel() { + JPanel container = new JPanel(); + container.setLayout(new FlowLayout(FlowLayout.RIGHT)); + + // 主面板 + JPanel mainPanel = new JPanel(); + mainPanel.setLayout(new BorderLayout(0, 10)); + UILabel label = new UILabel(); + label.setSize(200, 200); + container.add(label); + container.add(mainPanel); + + // hsl和rgb面板 + JPanel hslAndRgbPanel = new JPanel(); + hslAndRgbPanel.setLayout(new BorderLayout(0, 16)); + hslAndRgbPanel.add(initialHSLPanel(), BorderLayout.CENTER); + hslAndRgbPanel.add(initialRGBPanel(), BorderLayout.SOUTH); + + // 十六进制面板 + JPanel hexPanel = new JPanel(); + hexPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 8, 0)); + hexPanel.add(new UILabel("#")); + hexPanel.add(field); + UIButton pickColorButton = PickColorButtonFactory.getPickColorButton(this, PickColorButtonFactory.IconType.ICON18, true); + hexPanel.add(pickColorButton); + + mainPanel.add(hslAndRgbPanel, BorderLayout.CENTER); + mainPanel.add(hexPanel, BorderLayout.SOUTH); + + return container; + } + + //初始化HSL部分 + private JPanel initialHSLPanel() { + hRadio = new UIRadioButton("H"); + sRadio = new UIRadioButton("S"); + bRadio = new UIRadioButton("L"); + ButtonGroup group = new ButtonGroup(); + group.add(hRadio); + group.add(sRadio); + group.add(bRadio); + + hSpinner = new UIBasicSpinner(new SpinnerNumberModel(0, 0, 359, 1)); + sSpinner = new UIBasicSpinner(new SpinnerNumberModel(0, 0, 100, 1)); + bSpinner = new UIBasicSpinner(new SpinnerNumberModel(100, 0, 100, 1)); + hSpinner.setEnabled(true); sSpinner.setEnabled(false); bSpinner.setEnabled(false); - change.setEnabled(true); - updateSlider(); - updateTrack(); - updateImage(); - repaint(); - + + MouseAdapter cl = new RadioStateListener(); + locked = HLOCKED; + hRadio.setSelected(true); + hRadio.addMouseListener(cl); + sRadio.addMouseListener(cl); + bRadio.addMouseListener(cl); + + ChangeListener scroll = new ImageScrollListener(); + hSpinner.addChangeListener(scroll); + sSpinner.addChangeListener(scroll); + bSpinner.addChangeListener(scroll); + + JPanel hslPanel = new JPanel(); + hslPanel.setLayout(new GridLayout(3, 0, 0, 5)); + + JPanel hPanel = new JPanel(); + hPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0)); + hPanel.add(hRadio); + hPanel.add(hSpinner); + hslPanel.add(hPanel); + + JPanel sPanel = new JPanel(); + sPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0)); + sPanel.add(sRadio); + sPanel.add(sSpinner); + hslPanel.add(sPanel); + + JPanel lPanel = new JPanel(); + lPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0)); + lPanel.add(bRadio); + lPanel.add(bSpinner); + hslPanel.add(lPanel); + return hslPanel; + } + + private JPanel initialRGBPanel() { + // 初始化RGB部分 + rSpinner = new UIBasicSpinner(new SpinnerNumberModel(0, 0, 255, 1)); + gSpinner = new UIBasicSpinner(new SpinnerNumberModel(0, 0, 255, 1)); + bbSpinner = new UIBasicSpinner(new SpinnerNumberModel(0, 0, 255, 1)); + + rSpinner.setEnabled(true); + gSpinner.setEnabled(true); + bbSpinner.setEnabled(true); + + addRGBSpinnerChangeLisener(); + + TextDocumentListener listen = new TextDocumentListener(); + field = new UITextField(); + field.setPreferredSize(new Dimension(70, 18)); + field.getDocument().addDocumentListener(listen); + + JPanel rgbPanel = new JPanel(); + rgbPanel.setLayout(new GridLayout(3, 0, 0, 5)); + + JPanel rPanel = new JPanel(); + rPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0)); + rPanel.add(R); + rPanel.add(rSpinner); + rgbPanel.add(rPanel); + + JPanel gPanel = new JPanel(); + gPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0)); + gPanel.add(G); + gPanel.add(gSpinner); + rgbPanel.add(gPanel); + + JPanel bPanel = new JPanel(); + bPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0)); + bPanel.add(B); + bPanel.add(bbSpinner); + rgbPanel.add(bPanel); + + return rgbPanel; } - } - /** - * hsl 监听 - */ - class ImageScrollListener implements ChangeListener - { /** - * This method is called whenever one of the UIBasicSpinner values change. The - * JColorChooser should be updated with the new HSB values. + * This method returns the small display icon. * - * @param e The ChangeEvent. + * @return The small display icon. */ - public void stateChanged(ChangeEvent e) - { - if (internalChange){ - return; - } - updateImageAndTrack(); - updateSlider(); + public Icon getSmallDisplayIcon() { + return null; } - } - - /** - * rgb 监听 - */ - class ImageRGBScrollListener implements ChangeListener - { + /** - * This method is called whenever one of the UIBasicSpinner values change. The - * JColorChooser should be updated with the new HSB values. + * This method returns the large display icon. * - * @param e The ChangeEvent. + * @return The large display icon. */ - public void stateChanged(ChangeEvent e) - { - if (internalChange){ - return; - } - - - int r = (Integer) rSpinner.getValue(); - int g = (Integer) gSpinner.getValue(); - int bb = (Integer) bbSpinner.getValue(); - - spinnerTrigger = true; - getColorSelectionModel().setSelectedColor(new Color(r,g,bb)); - spinnerTrigger = false; - - updateChooser(); - repaint(); - } - } - - /** - * Creates a new DefaultHSBChooserPanel object. - */ - CustomChooserPanel() - { - super(); - } - - /** - * This method returns the name displayed by the JColorChooser tab that - * holds this panel. - * - * @return The name displayed in the JColorChooser tab. - */ - public String getDisplayName() - { - return Inter.getLocText("FR-Designer_Custom"); - } - - /** - * This method updates the various components inside the HSBPanel (the - * UIBasicSpinners, the JSlider, and the gradient image point) with updated - * values when the JColorChooser color value changes. - */ - public void updateChooser() - { - Color c = getColorSelectionModel().getSelectedColor(); - float[] hsbVals = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), - null); - internalChange = true; - - adjustHSLValue(hsbVals); - - internalChange = false; - - if (! handlingMouse && slider != null && ! slider.getValueIsAdjusting()){ - updateImage(); + public Icon getLargeDisplayIcon() { + return null; } - if (! handlingMouse || locked != HLOCKED){ - updateTrack(); + /** + * This method updates the gradient image with a new one taking the Hue + * value as the constant. + */ + private void updateHLockImage() { + int index = 0; + int[] pix = new int[IMG_WIDTH * IMG_HEIGHT]; + float hValue = ((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE; + + for (int j = 0; j < IMG_HEIGHT; j++) { + for (int i = 0; i < IMG_WIDTH; i++) { + pix[index++] = Color.HSBtoRGB(hValue, (IMG_WIDTH - i * 1f) / IMG_WIDTH, + (IMG_HEIGHT - j * 1f) / IMG_HEIGHT) | (BINARY_FOR_EIGHT << TWENTY_FOUR); + } + } + + gradientImage = createImage(new MemoryImageSource(IMG_WIDTH, IMG_HEIGHT, + pix, 0, IMG_WIDTH)); } - updateTextFields(); - updateHexFields(); - } - - private void adjustHSLValue(float[] hsbVals){ - if (! spinnerTrigger) - { - hSpinner.setValue(new Integer((int) (hsbVals[0] * HSPINNER_VALUE))); - sSpinner.setValue(new Integer((int) (hsbVals[1] * SSPINNER_VALUE))); - bSpinner.setValue(new Integer((int) (hsbVals[2] * LSPINNER_VALUE))); - } - switch (locked) - { - case HLOCKED: - if (slider != null){ - slider.setValue(((Number) hSpinner.getValue()).intValue()); - } - if (! handlingMouse) - { - gradientPoint.x = (int) ((1 - - ((Number) sSpinner.getValue()).intValue() / SSPINNER_VALUE) * IMG_WIDTH); - gradientPoint.y = (int) ((1 - - ((Number) bSpinner.getValue()).intValue() / LSPINNER_VALUE) * IMG_HEIGHT); - } - break; - case SLOCKED: - if (slider != null){ - slider.setValue(((Number) sSpinner.getValue()).intValue()); - } - if (! handlingMouse) - { - gradientPoint.x = (int) (((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE * IMG_WIDTH); - gradientPoint.y = (int) ((1 - - ((Number) bSpinner.getValue()).intValue() / LSPINNER_VALUE) * IMG_HEIGHT); - } - break; - case BLOCKED: - if (slider != null){ - slider.setValue(((Number) bSpinner.getValue()).intValue()); - } - if (! handlingMouse) - { - gradientPoint.x = (int) (((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE * IMG_WIDTH); - gradientPoint.y = (int) ((1 - - ((Number) sSpinner.getValue()).intValue() / SSPINNER_VALUE) * IMG_HEIGHT); - } - break; - } - } - - private void updateImageAndTrack(){ - float h = ((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE; - float s = ((Number) sSpinner.getValue()).intValue() / SSPINNER_VALUE; - float b = ((Number) bSpinner.getValue()).intValue() / LSPINNER_VALUE; - - spinnerTrigger = true; - getColorSelectionModel().setSelectedColor(new Color(Color.HSBtoRGB(h, s, b))); - spinnerTrigger = false; - - if (! handlingMouse && slider != null && ! slider.getValueIsAdjusting()) - { - updateImage(); - updateTrack(); + + /** + * This method updates the gradient image with a new one taking the + * Brightness value as the constant. + */ + private void updateBLockImage() { + int[] pix = new int[IMG_WIDTH * IMG_HEIGHT]; + float bValue = ((Number) bSpinner.getValue()).intValue() / LSPINNER_VALUE; + + int index = 0; + for (int j = 0; j < IMG_HEIGHT; j++) { + for (int i = 0; i < IMG_WIDTH; i++) { + pix[index++] = Color.HSBtoRGB(i * 1f / IMG_WIDTH, + (IMG_HEIGHT - j * 1f) / IMG_HEIGHT, bValue) | (BINARY_FOR_EIGHT << TWENTY_FOUR); + } } - updateTextFields(); - updateHexFields(); - repaint(); - } - - /** - * This method builds the DefaultHSBChooserPanel. - */ - protected void buildChooser() - { - setLayout(new BorderLayout()); - add(buildRightPanel(), BorderLayout.EAST); - JPanel container = new JPanel(); - container.setLayout(new BorderLayout()); - - gradientPanel = createGradientPanel(); - MouseAdapter ml = new MainGradientMouseListener(); - gradientPanel.addMouseListener(ml); - gradientPanel.addMouseMotionListener((MouseMotionListener) ml); - - trackPanel = createTrackPanel(); - - slider = new UISlider(); - slider.setPaintTrack(false); - slider.setPaintTicks(false); - - slider.setOrientation(SwingConstants.VERTICAL); - - updateSlider(); - - container.add(gradientPanel, BorderLayout.WEST); - container.add(slider, BorderLayout.CENTER); - container.add(trackPanel, BorderLayout.EAST); - - add(container, BorderLayout.WEST); - slider.addChangeListener(new SliderChangeListener()); - - updateTextFields(); - updateHexFields(); - repaint(); - } - - private JPanel createGradientPanel(){ - return new JPanel() - { - public Dimension getPreferredSize() - { - return new Dimension(IMG_WIDTH, IMG_HEIGHT); - } - - public void paint(Graphics g) - { - if (gradientImage != null){ - g.drawImage(gradientImage, 0, 0, this); - } - - Color saved = g.getColor(); - g.setColor(Color.WHITE); - g.drawOval(gradientPoint.x - 3, gradientPoint.y - 3, 6, 6); - g.setColor(saved); - } - }; - } - - private JPanel createTrackPanel(){ - return new JPanel() - { - public Dimension getPreferredSize() - { - return new Dimension(TRACK_WIDTH, IMG_HEIGHT); - } - - public void paint(Graphics g) - { - if (trackImage != null){ - g.drawImage(trackImage, 0, 0, this); - } - - } - }; - } - - /** - * This method uninstalls the DefaultHSBPanel. - * - * @param chooser The JColorChooser to remove this panel from. - */ - public void uninstallChooserPanel(JColorChooser chooser) - { - trackImage = null; - gradientImage = null; - gradientPanel = null; - slider = null; - - hSpinner = null; - sSpinner = null; - bSpinner = null; - - hRadio = null; - sRadio = null; - bRadio = null; - - removeAll(); - super.uninstallChooserPanel(chooser); - } - - /** - * This helper method creates the right side panel (the panel with the - * Spinners and TextFields). - * - * @return The right side panel. - */ - private Container buildRightPanel() - { - JPanel container = new JPanel(); - container.setLayout(new FlowLayout(FlowLayout.RIGHT)); - - // 主面板 - JPanel mainPanel = new JPanel(); - mainPanel.setLayout(new BorderLayout(0, 10)); - UILabel label = new UILabel(); - label.setSize(200,200); - container.add(label); - container.add(mainPanel); - - // hsl和rgb面板 - JPanel hslAndRgbPanel = new JPanel(); - hslAndRgbPanel.setLayout(new BorderLayout(0,16)); - hslAndRgbPanel.add(initialHSLPanel(),BorderLayout.CENTER); - hslAndRgbPanel.add(initialRGBPanel(),BorderLayout.SOUTH); - - // 十六进制面板 - JPanel hexPanel = new JPanel(); - hexPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 8, 0)); - hexPanel.add(new UILabel("#")); - hexPanel.add(field); - - mainPanel.add(hslAndRgbPanel,BorderLayout.CENTER); - mainPanel.add(hexPanel,BorderLayout.SOUTH); - - return container; - } - - //初始化HSL部分 - private JPanel initialHSLPanel(){ - hRadio = new UIRadioButton("H"); - sRadio = new UIRadioButton("S"); - bRadio = new UIRadioButton("L"); - ButtonGroup group = new ButtonGroup(); - group.add(hRadio); - group.add(sRadio); - group.add(bRadio); - - hSpinner = new UIBasicSpinner(new SpinnerNumberModel(0, 0, 359, 1)); - sSpinner = new UIBasicSpinner(new SpinnerNumberModel(0, 0, 100, 1)); - bSpinner = new UIBasicSpinner(new SpinnerNumberModel(100, 0, 100, 1)); - hSpinner.setEnabled(true); - sSpinner.setEnabled(false); - bSpinner.setEnabled(false); - - MouseAdapter cl = new RadioStateListener(); - locked = HLOCKED; - hRadio.setSelected(true); - hRadio.addMouseListener(cl); - sRadio.addMouseListener(cl); - bRadio.addMouseListener(cl); - - ChangeListener scroll = new ImageScrollListener(); - hSpinner.addChangeListener(scroll); - sSpinner.addChangeListener(scroll); - bSpinner.addChangeListener(scroll); - - JPanel hslPanel = new JPanel(); - hslPanel.setLayout(new GridLayout(3,0,0,5)); - - JPanel hPanel = new JPanel(); - hPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0)); - hPanel.add(hRadio); - hPanel.add(hSpinner); - hslPanel.add(hPanel); - - JPanel sPanel = new JPanel(); - sPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0)); - sPanel.add(sRadio); - sPanel.add(sSpinner); - hslPanel.add(sPanel); - - JPanel lPanel = new JPanel(); - lPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0)); - lPanel.add(bRadio); - lPanel.add(bSpinner); - hslPanel.add(lPanel); - return hslPanel; - } - - private JPanel initialRGBPanel(){ - // 初始化RGB部分 - rSpinner = new UIBasicSpinner(new SpinnerNumberModel(0, 0, 255, 1)); - gSpinner = new UIBasicSpinner(new SpinnerNumberModel(0, 0, 255, 1)); - bbSpinner = new UIBasicSpinner(new SpinnerNumberModel(0, 0, 255, 1)); - - rSpinner.setEnabled(true); - gSpinner.setEnabled(true); - bbSpinner.setEnabled(true); - - addRGBSpinnerChangeLisener(); - - TextDocumentListener listen = new TextDocumentListener(); - field = new UITextField(); - field.setPreferredSize(new Dimension(70,18)); - field.getDocument().addDocumentListener(listen); - - JPanel rgbPanel = new JPanel(); - rgbPanel.setLayout(new GridLayout(3,0,0,5)); - - JPanel rPanel = new JPanel(); - rPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0)); - rPanel.add(R); - rPanel.add(rSpinner); - rgbPanel.add(rPanel); - - JPanel gPanel = new JPanel(); - gPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0)); - gPanel.add(G); - gPanel.add(gSpinner); - rgbPanel.add(gPanel); - - JPanel bPanel = new JPanel(); - bPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0)); - bPanel.add(B); - bPanel.add(bbSpinner); - rgbPanel.add(bPanel); - - return rgbPanel; - } - - /** - * This method returns the small display icon. - * - * @return The small display icon. - */ - public Icon getSmallDisplayIcon() - { - return null; - } - - /** - * This method returns the large display icon. - * - * @return The large display icon. - */ - public Icon getLargeDisplayIcon() - { - return null; - } - - /** - * This method updates the gradient image with a new one taking the Hue - * value as the constant. - */ - private void updateHLockImage() - { - int index = 0; - int[] pix = new int[IMG_WIDTH * IMG_HEIGHT]; - float hValue = ((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE; - - for (int j = 0; j < IMG_HEIGHT; j++) - { - for (int i = 0; i < IMG_WIDTH; i++){ - pix[index++] = Color.HSBtoRGB(hValue, (IMG_WIDTH - i * 1f) / IMG_WIDTH, - (IMG_HEIGHT - j * 1f) / IMG_HEIGHT) | (BINARY_FOR_EIGHT << TWENTY_FOUR); + + gradientImage = createImage(new MemoryImageSource(IMG_WIDTH, IMG_HEIGHT, + pix, 0, IMG_WIDTH)); + } + + /** + * This method updates the gradient image with a new one taking the + * Saturation value as the constant. + */ + private void updateSLockImage() { + int[] pix = new int[IMG_WIDTH * IMG_HEIGHT]; + float sValue = ((Number) sSpinner.getValue()).intValue() / SSPINNER_VALUE; + + int index = 0; + for (int j = 0; j < IMG_HEIGHT; j++) { + for (int i = 0; i < IMG_WIDTH; i++) { + pix[index++] = Color.HSBtoRGB(i * 1f / IMG_WIDTH, sValue, + (IMG_HEIGHT - j * 1f) / IMG_HEIGHT) | (BINARY_FOR_EIGHT << TWENTY_FOUR); + } } + + gradientImage = createImage(new MemoryImageSource(IMG_WIDTH, IMG_HEIGHT, + pix, 0, IMG_WIDTH)); } - gradientImage = createImage(new MemoryImageSource(IMG_WIDTH, IMG_HEIGHT, - pix, 0, IMG_WIDTH)); - } - - /** - * This method updates the gradient image with a new one taking the - * Brightness value as the constant. - */ - private void updateBLockImage() - { - int[] pix = new int[IMG_WIDTH * IMG_HEIGHT]; - float bValue = ((Number) bSpinner.getValue()).intValue() / LSPINNER_VALUE; - - int index = 0; - for (int j = 0; j < IMG_HEIGHT; j++){ - for (int i = 0; i < IMG_WIDTH; i++){ - pix[index++] = Color.HSBtoRGB(i * 1f / IMG_WIDTH, - (IMG_HEIGHT - j * 1f) / IMG_HEIGHT, bValue) | (BINARY_FOR_EIGHT << TWENTY_FOUR); + /** + * This method calls the appropriate method to update the gradient image + * depending on which HSB value is constant. + */ + private void updateImage() { + switch (locked) { + case HLOCKED: + updateHLockImage(); + break; + case SLOCKED: + updateSLockImage(); + break; + case BLOCKED: + updateBLockImage(); + break; } } - gradientImage = createImage(new MemoryImageSource(IMG_WIDTH, IMG_HEIGHT, - pix, 0, IMG_WIDTH)); - } - - /** - * This method updates the gradient image with a new one taking the - * Saturation value as the constant. - */ - private void updateSLockImage() - { - int[] pix = new int[IMG_WIDTH * IMG_HEIGHT]; - float sValue = ((Number) sSpinner.getValue()).intValue() / SSPINNER_VALUE; - - int index = 0; - for (int j = 0; j < IMG_HEIGHT; j++){ - for (int i = 0; i < IMG_WIDTH; i++){ - pix[index++] = Color.HSBtoRGB(i * 1f / IMG_WIDTH, sValue, - (IMG_HEIGHT - j * 1f) / IMG_HEIGHT)| (BINARY_FOR_EIGHT << TWENTY_FOUR); + /** + * This method updates the TextFields with the correct RGB values. + */ + private void updateTextFields() { + int c = getColorSelectionModel().getSelectedColor().getRGB(); + + removeRGBSpinnerChangeLisener(); + rSpinner.setValue(Integer.parseInt("" + (c >> BINARY_FOR_FOUR & HEX_FF))); + gSpinner.setValue(Integer.parseInt("" + (c >> BINARY_FOR_THTEE & HEX_FF))); + bbSpinner.setValue(Integer.parseInt("" + (c & HEX_FF))); + addRGBSpinnerChangeLisener(); + + repaint(); + } + + private void removeRGBSpinnerChangeLisener() { + rSpinner.removeChangeListener(rgbScroll); + gSpinner.removeChangeListener(rgbScroll); + bbSpinner.removeChangeListener(rgbScroll); + } + + private void addRGBSpinnerChangeLisener() { + rSpinner.addChangeListener(rgbScroll); + gSpinner.addChangeListener(rgbScroll); + bbSpinner.addChangeListener(rgbScroll); + } + + private void updateHexFields() { + Color color = getColorSelectionModel().getSelectedColor(); + + String R = Integer.toHexString(color.getRed()); + R = R.length() < 2 ? ('0' + R) : R; + String B = Integer.toHexString(color.getBlue()); + B = B.length() < 2 ? ('0' + B) : B; + String G = Integer.toHexString(color.getGreen()); + G = G.length() < 2 ? ('0' + G) : G; + + try { + field.setText(R + G + B); + } catch (Exception e) { + // 因为有了DocumentListener的监听,导致setText()的时候报错但不影响使用 + // 所以只捕捉,不处理 } + repaint(); } - - gradientImage = createImage(new MemoryImageSource(IMG_WIDTH, IMG_HEIGHT, - pix, 0, IMG_WIDTH)); - } - - /** - * This method calls the appropriate method to update the gradient image - * depending on which HSB value is constant. - */ - private void updateImage() - { - switch (locked) - { - case HLOCKED: - updateHLockImage(); - break; - case SLOCKED: - updateSLockImage(); - break; - case BLOCKED: - updateBLockImage(); - break; - } - } - - /** - * This method updates the TextFields with the correct RGB values. - */ - private void updateTextFields() - { - int c = getColorSelectionModel().getSelectedColor().getRGB(); - - removeRGBSpinnerChangeLisener(); - rSpinner.setValue(Integer.parseInt("" + (c >> BINARY_FOR_FOUR & HEX_FF))); - gSpinner.setValue(Integer.parseInt("" + (c >> BINARY_FOR_THTEE & HEX_FF))); - bbSpinner.setValue(Integer.parseInt("" + (c & HEX_FF))); - addRGBSpinnerChangeLisener(); - - repaint(); - } - - private void removeRGBSpinnerChangeLisener(){ - rSpinner.removeChangeListener(rgbScroll); - gSpinner.removeChangeListener(rgbScroll); - bbSpinner.removeChangeListener(rgbScroll); - } - - private void addRGBSpinnerChangeLisener(){ - rSpinner.addChangeListener(rgbScroll); - gSpinner.addChangeListener(rgbScroll); - bbSpinner.addChangeListener(rgbScroll); - } - - private void updateHexFields() - { - Color color = getColorSelectionModel().getSelectedColor(); - - String R = Integer.toHexString(color.getRed()); - R = R.length() < 2 ? ('0' + R) : R; - String B = Integer.toHexString(color.getBlue()); - B = B.length() < 2 ? ('0' + B) : B; - String G = Integer.toHexString(color.getGreen()); - G = G.length() < 2 ? ('0' + G) : G; - - try{ - field.setText(R + G + B); - }catch(Exception e){ - // 因为有了DocumentListener的监听,导致setText()的时候报错但不影响使用 - // 所以只捕捉,不处理 + + /** + * This method updates the slider in response to making a different HSB + * property the constant. + */ + private void updateSlider() { + if (slider == null) { + return; + } + + slider.setMinimum(0); + if (locked == HLOCKED) { + internalChange = true; + slider.setValue(((Number) hSpinner.getValue()).intValue()); + slider.setMaximum(359); + internalChange = false; + slider.setInverted(true); + } else { + slider.setInverted(false); + if (locked == SLOCKED) { + slider.setValue(((Number) sSpinner.getValue()).intValue()); + } else { + slider.setValue(((Number) bSpinner.getValue()).intValue()); + } + slider.setMaximum(100); + slider.setInverted(false); + } + repaint(); } - repaint(); - } - - /** - * This method updates the slider in response to making a different HSB - * property the constant. - */ - private void updateSlider() - { - if (slider == null){ - return; + + /** + * This method updates the track gradient image depending on which HSB + * property is constant. + */ + private void updateTrack() { + switch (locked) { + case HLOCKED: + updateHTrack(); + break; + case SLOCKED: + updateSTrack(); + break; + case BLOCKED: + updateBTrack(); + break; + } } - - slider.setMinimum(0); - if (locked == HLOCKED) - { - internalChange = true; - slider.setValue(((Number) hSpinner.getValue()).intValue()); - slider.setMaximum(359); - internalChange = false; - slider.setInverted(true); - } - else - { - slider.setInverted(false); - if (locked == SLOCKED){ - slider.setValue(((Number) sSpinner.getValue()).intValue()); - }else{ - slider.setValue(((Number) bSpinner.getValue()).intValue()); - } - slider.setMaximum(100); - slider.setInverted(false); - } - repaint(); - } - - /** - * This method updates the track gradient image depending on which HSB - * property is constant. - */ - private void updateTrack() - { - switch (locked) - { - case HLOCKED: - updateHTrack(); - break; - case SLOCKED: - updateSTrack(); - break; - case BLOCKED: - updateBTrack(); - break; - } - } - - /** - * This method updates the track gradient image if the Hue value is allowed - * to change (according to the UIRadioButtons). - */ - private void updateHTrack() - { - int trackIndex = 0; - int[] trackPix = new int[TRACK_WIDTH * IMG_HEIGHT]; - - for (int j = 0; j < IMG_HEIGHT; j++){ - for (int i = 0; i < TRACK_WIDTH; i++){ - trackPix[trackIndex++] = Color.HSBtoRGB(j * 1f / IMG_HEIGHT, 1f, 1f) - | (BINARY_FOR_EIGHT << TWENTY_FOUR); + + /** + * This method updates the track gradient image if the Hue value is allowed + * to change (according to the UIRadioButtons). + */ + private void updateHTrack() { + int trackIndex = 0; + int[] trackPix = new int[TRACK_WIDTH * IMG_HEIGHT]; + + for (int j = 0; j < IMG_HEIGHT; j++) { + for (int i = 0; i < TRACK_WIDTH; i++) { + trackPix[trackIndex++] = Color.HSBtoRGB(j * 1f / IMG_HEIGHT, 1f, 1f) + | (BINARY_FOR_EIGHT << TWENTY_FOUR); + } } + + trackImage = createImage(new MemoryImageSource(TRACK_WIDTH, IMG_HEIGHT, + trackPix, 0, TRACK_WIDTH)); } - trackImage = createImage(new MemoryImageSource(TRACK_WIDTH, IMG_HEIGHT, - trackPix, 0, TRACK_WIDTH)); - } - - /** - * This method updates the track gradient image if the Saturation value is - * allowed to change (according to the UIRadioButtons). - */ - private void updateSTrack() - { - int[] trackPix = new int[TRACK_WIDTH * IMG_HEIGHT]; - - float hValue = ((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE; - float bValue = ((Number) bSpinner.getValue()).intValue() / LSPINNER_VALUE; - - int trackIndex = 0; - for (int j = 0; j < IMG_HEIGHT; j++){ - for (int i = 0; i < TRACK_WIDTH; i++){ - trackPix[trackIndex++] = Color.HSBtoRGB(hValue, - (IMG_HEIGHT - j * 1f) / IMG_HEIGHT, - bValue) | (BINARY_FOR_EIGHT << TWENTY_FOUR); + /** + * This method updates the track gradient image if the Saturation value is + * allowed to change (according to the UIRadioButtons). + */ + private void updateSTrack() { + int[] trackPix = new int[TRACK_WIDTH * IMG_HEIGHT]; + + float hValue = ((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE; + float bValue = ((Number) bSpinner.getValue()).intValue() / LSPINNER_VALUE; + + int trackIndex = 0; + for (int j = 0; j < IMG_HEIGHT; j++) { + for (int i = 0; i < TRACK_WIDTH; i++) { + trackPix[trackIndex++] = Color.HSBtoRGB(hValue, + (IMG_HEIGHT - j * 1f) / IMG_HEIGHT, + bValue) | (BINARY_FOR_EIGHT << TWENTY_FOUR); + } } + + trackImage = createImage(new MemoryImageSource(TRACK_WIDTH, IMG_HEIGHT, + trackPix, 0, TRACK_WIDTH)); } - trackImage = createImage(new MemoryImageSource(TRACK_WIDTH, IMG_HEIGHT, - trackPix, 0, TRACK_WIDTH)); - } - - /** - * This method updates the track gradient image if the Brightness value is - * allowed to change (according to the UIRadioButtons). - */ - private void updateBTrack() - { - int[] trackPix = new int[TRACK_WIDTH * IMG_HEIGHT]; - - float hValue = ((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE; - float sValue = ((Number) sSpinner.getValue()).intValue() / SSPINNER_VALUE; - - int trackIndex = 0; - for (int j = 0; j < IMG_HEIGHT; j++){ - for (int i = 0; i < TRACK_WIDTH; i++){ - trackPix[trackIndex++] = Color.HSBtoRGB(hValue, sValue, - (IMG_HEIGHT - j * 1f) / IMG_HEIGHT) | (BINARY_FOR_EIGHT << TWENTY_FOUR); + /** + * This method updates the track gradient image if the Brightness value is + * allowed to change (according to the UIRadioButtons). + */ + private void updateBTrack() { + int[] trackPix = new int[TRACK_WIDTH * IMG_HEIGHT]; + + float hValue = ((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE; + float sValue = ((Number) sSpinner.getValue()).intValue() / SSPINNER_VALUE; + + int trackIndex = 0; + for (int j = 0; j < IMG_HEIGHT; j++) { + for (int i = 0; i < TRACK_WIDTH; i++) { + trackPix[trackIndex++] = Color.HSBtoRGB(hValue, sValue, + (IMG_HEIGHT - j * 1f) / IMG_HEIGHT) | (BINARY_FOR_EIGHT << TWENTY_FOUR); + } } + + trackImage = createImage(new MemoryImageSource(TRACK_WIDTH, IMG_HEIGHT, + trackPix, 0, TRACK_WIDTH)); + } + + public Color getColor() { + return getColorSelectionModel().getSelectedColor(); } - trackImage = createImage(new MemoryImageSource(TRACK_WIDTH, IMG_HEIGHT, - trackPix, 0, TRACK_WIDTH)); - } + public void setColor(Color color) { + getColorSelectionModel().setSelectedColor(color); + } + + public void colorSetted(ColorCell cc) { + } } \ No newline at end of file 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 bbecf01d3..ba28b4201 100644 --- a/designer_base/src/com/fr/design/style/color/NewColorSelectPane.java +++ b/designer_base/src/com/fr/design/style/color/NewColorSelectPane.java @@ -78,10 +78,21 @@ public class NewColorSelectPane extends BasicPane implements ColorSelectable { // center JPanel centerPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_S_Pane(); this.add(centerPane, BorderLayout.CENTER); - + + // 第一行,1个取色按钮 + 7个最近使用的颜色 + JPanel row1Pane = new JPanel(FRGUIPaneFactory.createBorderLayout()); + row1Pane.setBorder(BorderFactory.createEmptyBorder(8, 8, 0, 0)); + row1Pane.setPreferredSize(new Dimension(135, 16)); // 宽度为 16 * 8 + 7 + centerPane.add(row1Pane); + + // 取色按钮 + UIButton pickColorButton = PickColorButtonFactory.getPickColorButton(this, PickColorButtonFactory.IconType.ICON16); + row1Pane.add(pickColorButton, BorderLayout.WEST); + // 最近使用 - usedColorPane = new UsedColorPane(1, 8, ColorSelectConfigManager.getInstance().getColors(),this); - centerPane.add(usedColorPane.getPane()); + usedColorPane = new UsedColorPane(1, 7, ColorSelectConfigManager.getInstance().getColors(),this); + usedColorPane.getPane().setBorder(BorderFactory.createEmptyBorder(0, 1, 0, 8)); + row1Pane.add(usedColorPane.getPane()); JPanel menuColorPane1 = new JPanel(); centerPane.add(menuColorPane1); @@ -204,4 +215,6 @@ public class NewColorSelectPane extends BasicPane implements ColorSelectable { usedColorPane.updateUsedColor(); } + + } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/style/color/PickColorButtonFactory.java b/designer_base/src/com/fr/design/style/color/PickColorButtonFactory.java new file mode 100644 index 000000000..32188ff4e --- /dev/null +++ b/designer_base/src/com/fr/design/style/color/PickColorButtonFactory.java @@ -0,0 +1,44 @@ +package com.fr.design.style.color; + +import com.fr.base.BaseUtils; +import com.fr.design.gui.ibutton.UIButton; + +import java.awt.*; +import java.awt.event.*; + +/** + * Created by plough on 2016/12/22. + */ +public class PickColorButtonFactory { + + public static UIButton 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(); + + if (iconType == IconType.ICON16) { + pickColorButton.setIcon(BaseUtils.readIcon("/com/fr/design/images/gui/colorPicker/colorPicker16.png")); + pickColorButton.setPreferredSize(new Dimension(16, 16)); + } else { + pickColorButton.setIcon(BaseUtils.readIcon("/com/fr/design/images/gui/colorPicker/colorPicker18.png")); + pickColorButton.setPreferredSize(new Dimension(18, 18)); + } + pickColorButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); + + pickColorButton.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + new ColorPicker(colorSelectable, setColorRealTime); + } + }); + + return pickColorButton; + } + + // 取色器按钮使用的图标 + public enum IconType { + ICON16, ICON18 + } +} diff --git a/designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java b/designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java index 90cc40e68..3bf990880 100644 --- a/designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java +++ b/designer_chart/src/com/fr/design/ChartTypeInterfaceManager.java @@ -38,7 +38,7 @@ import javax.swing.*; import java.util.*; /** - * Created by eason on 14/12/29. + * Created by eason on 14/12/29. */ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraChartDesignClassManagerProvider { @@ -259,7 +259,7 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh while (iterator.hasNext()){ Map.Entry entry = (Map.Entry) iterator.next(); IndependentChartUIProvider provider = (IndependentChartUIProvider) entry.getValue(); - names[i++] = provider.getPlotTypePane().title4PopupWindow(); + names[i++] = provider.getPlotTypeTitle4PopupWindow(); } return names; } @@ -274,7 +274,7 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh public String getTitle4PopupWindow(String priority, String plotID){ if (chartTypeInterfaces != null && chartTypeInterfaces.containsKey(priority) && chartTypeInterfaces.get(priority).containsKey(plotID)){ IndependentChartUIProvider provider = chartTypeInterfaces.get(priority).get(plotID); - return provider.getPlotTypePane().title4PopupWindow(); + return provider.getPlotTypeTitle4PopupWindow(); } //兼容老的插件 @@ -284,7 +284,7 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh Map.Entry entry = (Map.Entry) iterator.next(); String defaultPriority = (String) entry.getKey(); if (chartTypeInterfaces.get(defaultPriority).containsKey(plotID)) { - return chartTypeInterfaces.get(defaultPriority).get(plotID).getPlotTypePane().title4PopupWindow(); + return chartTypeInterfaces.get(defaultPriority).get(plotID).getPlotTypeTitle4PopupWindow(); } } } @@ -332,7 +332,7 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh while (chartUI.hasNext()) { Map.Entry chartUIEntry = (Map.Entry) chartUI.next(); IndependentChartUIProvider provider = (IndependentChartUIProvider) chartUIEntry.getValue(); - names[index++] = provider.getPlotTypePane().title4PopupWindow(); + names[index++] = provider.getPlotTypeTitle4PopupWindow(); } return index; } @@ -495,7 +495,7 @@ public class ChartTypeInterfaceManager extends XMLFileManager implements ExtraCh extraChartDesignInterfaceList.add(tagName); } if (IndependentChartUIProvider.XML_TAG.equals(tagName)) { - addChartInterface(reader.getAttrAsString("class", ""), reader.getAttrAsString("priority", ChartTypeManager.DEFAULT_PRIORITY),reader.getAttrAsString("plotID", ""), simplify); + addChartInterface(reader.getAttrAsString("class", ""), reader.getAttrAsString("priority", ChartTypeManager.CHART_PRIORITY),reader.getAttrAsString("plotID", ""), simplify); } } } diff --git a/designer_chart/src/com/fr/design/chart/fun/IndependentChartUIProvider.java b/designer_chart/src/com/fr/design/chart/fun/IndependentChartUIProvider.java index a91914396..1b90382d6 100644 --- a/designer_chart/src/com/fr/design/chart/fun/IndependentChartUIProvider.java +++ b/designer_chart/src/com/fr/design/chart/fun/IndependentChartUIProvider.java @@ -84,5 +84,10 @@ public interface IndependentChartUIProvider extends Level { */ String getIconPath(); + /** + * plot面板的标题 + */ + String getPlotTypeTitle4PopupWindow(); + } \ No newline at end of file diff --git a/designer_chart/src/com/fr/design/chart/fun/impl/AbstractIndependentChartUIWithAPILevel.java b/designer_chart/src/com/fr/design/chart/fun/impl/AbstractIndependentChartUIWithAPILevel.java index 2a1e6b4c4..ff0eaa81d 100644 --- a/designer_chart/src/com/fr/design/chart/fun/impl/AbstractIndependentChartUIWithAPILevel.java +++ b/designer_chart/src/com/fr/design/chart/fun/impl/AbstractIndependentChartUIWithAPILevel.java @@ -57,4 +57,12 @@ public abstract class AbstractIndependentChartUIWithAPILevel implements Independ public ConditionAttributesPane getPlotConditionPane(Plot plot){ return new DataSeriesConditionPane(); } + + /** + * plot面板的标题 + * 插件兼容 + */ + public String getPlotTypeTitle4PopupWindow(){ + return getPlotTypePane().title4PopupWindow(); + } } diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java index 6b6c9a427..4a18611fa 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypeButtonPane.java @@ -138,7 +138,7 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen private void checkoutChange(){ editingCollection.calculateMultiChartMode(); if (parent != null){ - parent.reactorChartTypePane(editingCollection); + parent.relayoutChartTypePane(editingCollection); } //检查是否可以配置切换 configButton.setEnabled(editingCollection.changeEnable()); @@ -425,6 +425,8 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen private void deleteAButton() { //先重构属性,在重构面板,否则面板在重构过程中,会重新将属性中的切换图表加到indexList中,导致面板无法删除 + //记录改变前的plotID + String lastPlotID = editingCollection == null ? StringUtils.EMPTY : editingCollection.getSelectedChart().getPlot().getPlotID(); if (editingCollection != null) { int count = editingCollection.getChartCount(); for (int i = 0; i < count; i++) { @@ -447,6 +449,11 @@ public class ChartTypeButtonPane extends BasicBeanPane implemen checkoutChange(); relayoutPane(); + + //重构面板 + if (parent != null ){ + parent.reLayoutEditPane(lastPlotID, editingCollection); + } } private void relayoutPane() { diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypePane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypePane.java index 6c747c9cc..172d040f3 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypePane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/ChartTypePane.java @@ -68,8 +68,13 @@ public class ChartTypePane extends AbstractChartAttrPane{ buttonPane = new ChartTypeButtonPane(this); content.add(buttonPane, BorderLayout.NORTH); - - chartTypePane = new ComboBoxPane(); + + if (editingCollection != null) { + relayoutChartTypePane(editingCollection); + }else { + chartTypePane = new ComboBoxPane(); + } + BasicScrollPane scrollPane = new BasicScrollPane() { @Override protected JPanel createContentPane() { @@ -192,7 +197,7 @@ public class ChartTypePane extends AbstractChartAttrPane{ }); } - public void reactor(ChartCollection collection){ + public void relayout(ChartCollection collection){ //重构需要重构下拉框选项和cardNames Chart chart = collection.getSelectedChart(); String chartID = chart.getPriority(); @@ -201,6 +206,8 @@ public class ChartTypePane extends AbstractChartAttrPane{ } //第一步就是重构cardNames cardNames = ChartTypeInterfaceManager.getInstance().getTitle4PopupWindow(chartID); + //下拉框重构开始。为了防止重构是触发update + ((FlexibleComboBox)jcb).setItemEvenType(ItemEventType.REACTOR); //重构下拉框选项 reactorComboBox(); //重新选择选中的下拉项 @@ -208,6 +215,8 @@ public class ChartTypePane extends AbstractChartAttrPane{ String plotID = chart.getPlot().getPlotID(); Object item = ChartTypeInterfaceManager.getInstance().getTitle4PopupWindow(chartID, plotID); jcb.setSelectedItem(item); + //下拉框重构结束 + ((FlexibleComboBox)jcb).setItemEvenType(ItemEventType.DEFAULT); //重新选中 checkPlotPane(); } @@ -218,13 +227,10 @@ public class ChartTypePane extends AbstractChartAttrPane{ } private void reactorComboBox() { - FlexibleComboBox fcb = (FlexibleComboBox)jcb; - fcb.setItemEvenType(ItemEventType.REACTOR); - fcb.removeAllItems(); + jcb.removeAllItems(); for (int i = 0; i < this.cardNames.length; i++) { - fcb.addItem(cardNames[i]); + jcb.addItem(cardNames[i]); } - fcb.setItemEvenType(ItemEventType.DEFAULT); } @Override @@ -278,9 +284,9 @@ public class ChartTypePane extends AbstractChartAttrPane{ } - public void reactorChartTypePane(ChartCollection collection){ - if (needReactor(collection)) { - chartTypePane.reactor(collection); + public void relayoutChartTypePane(ChartCollection collection){ + if (needRelayout(collection)) { + chartTypePane.relayout(collection); //设置面板切换状态 updatePaneState(collection); } @@ -292,7 +298,7 @@ public class ChartTypePane extends AbstractChartAttrPane{ } // TODO: 2016/11/17 因为现在populate面板时会重新构造面板,所以每次都需要重构 - private boolean needReactor(ChartCollection collection) { + private boolean needRelayout(ChartCollection collection) { /*return paneState.getChartID() != collection.getRepresentChartID() || paneState.getPaneState() != collection.getState();*/ return true; } @@ -301,14 +307,14 @@ public class ChartTypePane extends AbstractChartAttrPane{ * 更新界面属性 用于展示 */ public void populate(ChartCollection collection) { + editingCollection = collection; + Chart chart = collection.getSelectedChart(); this.remove(leftContentPane); initContentPane(); buttonPane.populateBean(collection); chartTypePane.populateBean(chart); - //remove面板之后,就需要重构下拉框 - reactorChartTypePane(collection); this.initAllListeners(); } diff --git a/designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartTextAttrPane.java b/designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartTextAttrPane.java index a52fe010d..1e383dede 100644 --- a/designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartTextAttrPane.java +++ b/designer_chart/src/com/fr/design/mainframe/chart/gui/style/ChartTextAttrPane.java @@ -71,6 +71,7 @@ public class ChartTextAttrPane extends BasicPane { } public void populate(FRFont frFont) { + removeAllComboBoxListener(); if (frFont == null) { return; } @@ -85,6 +86,11 @@ public class ChartTextAttrPane extends BasicPane { } } + private void removeAllComboBoxListener() { + fontNameComboBox.removeChangeListener(); + fontSizeComboBox.removeChangeListener(); + } + /** * 更新字 * @return 更新字 diff --git a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java index 6e68cc2d7..3d53eab01 100644 --- a/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java +++ b/designer_form/src/com/fr/design/designer/beans/adapters/layout/FRAbsoluteLayoutAdapter.java @@ -60,6 +60,13 @@ public class FRAbsoluteLayoutAdapter extends FRBodyLayoutAdapter { if (comp == null){ return false; } + //参数面板内的组件不允许拖往绝对布局中 + if (creator.getParent() != null && ((XCreator)creator.getParent()).acceptType(XWParameterLayout.class)){ + Rectangle rec = creator.getBounds(); + rec.y = creator.getParent().getHeight() - rec.height; + creator.setBounds(rec); + return false; + } //判断下组件能不能拖入绝对布局 if (!creator.canEnterIntoAbsolutePane()){ return false; diff --git a/designer_form/src/com/fr/design/designer/creator/XCreator.java b/designer_form/src/com/fr/design/designer/creator/XCreator.java index ed692cd42..f80f20b58 100644 --- a/designer_form/src/com/fr/design/designer/creator/XCreator.java +++ b/designer_form/src/com/fr/design/designer/creator/XCreator.java @@ -617,4 +617,5 @@ public abstract class XCreator extends JPanel implements XComponent, XCreatorToo public void adjustCompHeight(double percent) { return; } + } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/creator/XWAbsoluteBodyLayout.java b/designer_form/src/com/fr/design/designer/creator/XWAbsoluteBodyLayout.java index 291a0f88d..51ba4ef53 100644 --- a/designer_form/src/com/fr/design/designer/creator/XWAbsoluteBodyLayout.java +++ b/designer_form/src/com/fr/design/designer/creator/XWAbsoluteBodyLayout.java @@ -2,7 +2,9 @@ package com.fr.design.designer.creator; import com.fr.design.designer.beans.LayoutAdapter; import com.fr.design.designer.beans.adapters.layout.FRAbsoluteBodyLayoutAdapter; +import com.fr.design.designer.properties.mobile.BodyMobilePropertyUI; import com.fr.design.form.util.XCreatorConstants; +import com.fr.design.fun.WidgetPropertyUIProvider; import com.fr.design.mainframe.widget.editors.PaddingMarginEditor; import com.fr.design.mainframe.widget.editors.WLayoutBorderStyleEditor; import com.fr.design.mainframe.widget.renderer.LayoutBorderStyleRenderer; @@ -87,8 +89,14 @@ public class XWAbsoluteBodyLayout extends XWAbsoluteLayout { }; } + @Override + public WidgetPropertyUIProvider[] getWidgetPropertyUIProviders() { + return new WidgetPropertyUIProvider[]{ new BodyMobilePropertyUI(this)}; + } + @Override protected void initStyle() { initBorderStyle(); } + } diff --git a/designer_form/src/com/fr/design/designer/creator/XWFitLayout.java b/designer_form/src/com/fr/design/designer/creator/XWFitLayout.java index 682a19590..483b08fe5 100644 --- a/designer_form/src/com/fr/design/designer/creator/XWFitLayout.java +++ b/designer_form/src/com/fr/design/designer/creator/XWFitLayout.java @@ -25,6 +25,7 @@ import com.fr.form.ui.container.WBodyLayoutType; import com.fr.form.ui.container.WFitLayout; import com.fr.form.ui.container.WLayout; import com.fr.general.FRScreen; +import com.fr.general.Inter; import com.fr.stable.ArrayUtils; /** diff --git a/designer_form/src/com/fr/design/designer/creator/cardlayout/XWTabFitLayout.java b/designer_form/src/com/fr/design/designer/creator/cardlayout/XWTabFitLayout.java index 230e7671d..71df9b059 100644 --- a/designer_form/src/com/fr/design/designer/creator/cardlayout/XWTabFitLayout.java +++ b/designer_form/src/com/fr/design/designer/creator/cardlayout/XWTabFitLayout.java @@ -14,7 +14,9 @@ import com.fr.design.designer.creator.CRPropertyDescriptor; import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XWFitLayout; +import com.fr.design.designer.properties.mobile.BodyMobilePropertyUI; import com.fr.design.form.util.XCreatorConstants; +import com.fr.design.fun.WidgetPropertyUIProvider; import com.fr.design.mainframe.FormDesigner; import com.fr.design.mainframe.FormHierarchyTreePane; import com.fr.design.mainframe.widget.editors.PaddingMarginEditor; @@ -367,4 +369,13 @@ public class XWTabFitLayout extends XWFitLayout { public XLayoutContainer getTopLayout() { return this.getBackupParent().getTopLayout(); } + + /** + * 重写这个方法,解决tab块底下仍然显示手机重布局的bug + * @return + */ + @Override + public WidgetPropertyUIProvider[] getWidgetPropertyUIProviders() { + return new WidgetPropertyUIProvider[0]; + } } \ No newline at end of file diff --git a/designer_form/src/com/fr/design/designer/properties/BodyAppRelayoutTable.java b/designer_form/src/com/fr/design/designer/properties/BodyAppRelayoutTable.java index 6c10884a4..36bde25d8 100644 --- a/designer_form/src/com/fr/design/designer/properties/BodyAppRelayoutTable.java +++ b/designer_form/src/com/fr/design/designer/properties/BodyAppRelayoutTable.java @@ -53,7 +53,7 @@ public class BodyAppRelayoutTable extends AbstractPropertyTable { FRContext.getLogger().error(e.getMessage()); } - groups.add(new PropertyGroup(new ReportAppPropertyGroupModel(Inter.getLocText("FR-Designer-Layout_Adaptive_Layout"), xCreator, propertyTableEditor, designer))); + groups.add(new PropertyGroup(new ReportAppPropertyGroupModel(Inter.getLocText("FR-Designer_Properties_Mobile"), xCreator, propertyTableEditor, designer))); TableModel model = new BeanTableModel(); setModel(model); @@ -65,7 +65,7 @@ public class BodyAppRelayoutTable extends AbstractPropertyTable { * 单元格tooltip * 属性名悬浮提示 * - * @param 鼠标点击事件 + * @param event 鼠标点击事件 * @return 单元格tooltip */ public String getToolTipText(MouseEvent event) { diff --git a/designer_form/src/com/fr/design/designer/properties/mobile/BodyMobilePropertyUI.java b/designer_form/src/com/fr/design/designer/properties/mobile/BodyMobilePropertyUI.java index a64de4158..70b80bc99 100644 --- a/designer_form/src/com/fr/design/designer/properties/mobile/BodyMobilePropertyUI.java +++ b/designer_form/src/com/fr/design/designer/properties/mobile/BodyMobilePropertyUI.java @@ -1,6 +1,7 @@ package com.fr.design.designer.properties.mobile; import com.fr.design.designer.creator.XCreator; +import com.fr.design.designer.creator.XWAbsoluteBodyLayout; import com.fr.design.designer.creator.XWFitLayout; import com.fr.design.designer.properties.BodyAppRelayoutTable; import com.fr.design.fun.impl.AbstractWidgetPropertyUIProvider; @@ -18,6 +19,10 @@ public class BodyMobilePropertyUI extends AbstractWidgetPropertyUIProvider { this.xCreator = xwFitLayout; } + public BodyMobilePropertyUI(XWAbsoluteBodyLayout xwAbsoluteBodyLayout) { + this.xCreator = xwAbsoluteBodyLayout; + } + @Override public AbstractPropertyTable createWidgetAttrTable() { return new BodyAppRelayoutTable(xCreator); diff --git a/sonar-project.properties b/sonar-dev-project.properties similarity index 100% rename from sonar-project.properties rename to sonar-dev-project.properties