From bf588b70c9549cb73be8f1ba07be74973a24a628 Mon Sep 17 00:00:00 2001 From: MoMeak Date: Tue, 10 Oct 2017 16:20:26 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-4999=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=E7=9A=84=E5=B0=8F=E9=97=AE=E9=A2=98-?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E9=9D=A0=E5=B7=A6=E6=88=96=E9=9D=A0=E5=8F=B3?= =?UTF-8?q?=E7=AD=89=E8=AE=BE=E7=BD=AE=E6=97=B6=EF=BC=8C=E4=B9=8B=E5=89=8D?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E7=9A=84=E5=9C=B0=E6=96=B9=E4=BC=9A=E5=8F=98?= =?UTF-8?q?=E6=88=90=E7=A9=BA=E7=99=BD=E5=86=8D=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit REPORT-4888 设计器交互修改-优化加粗、倾斜、下划线点击触发效果 --- .../fr/design/actions/ButtonGroupAction.java | 4 +- .../actions/cell/style/AlignmentAction.java | 40 ++++------ .../cell/style/ReportFontBoldAction.java | 76 +++++++++---------- .../cell/style/ReportFontItalicAction.java | 9 +-- .../cell/style/ReportFontUnderlineAction.java | 8 +- .../com/fr/design/actions/UpdateAction.java | 4 + .../fr/design/gui/ibutton/UIToggleButton.java | 14 +++- .../fr/design/gui/style/AlignmentPane.java | 14 ++-- .../com/fr/design/utils/gui/GUICoreUtils.java | 27 +++++++ 9 files changed, 106 insertions(+), 90 deletions(-) diff --git a/designer/src/com/fr/design/actions/ButtonGroupAction.java b/designer/src/com/fr/design/actions/ButtonGroupAction.java index e3f20f70bf..b45a5d34a1 100644 --- a/designer/src/com/fr/design/actions/ButtonGroupAction.java +++ b/designer/src/com/fr/design/actions/ButtonGroupAction.java @@ -6,12 +6,12 @@ import com.fr.design.gui.ibutton.UIButtonGroup; import com.fr.design.mainframe.ElementCasePane; public abstract class ButtonGroupAction extends ElementCaseAction{ - protected Icon[] iconArray; + protected Icon[][] iconArray; protected Integer[] valueArray; private UIButtonGroup group; - protected ButtonGroupAction(ElementCasePane t, Icon[] iconArray, Integer[] valueArray) { + protected ButtonGroupAction(ElementCasePane t, Icon[][] iconArray, Integer[] valueArray) { super(t); this.iconArray = iconArray; this.valueArray = valueArray; diff --git a/designer/src/com/fr/design/actions/cell/style/AlignmentAction.java b/designer/src/com/fr/design/actions/cell/style/AlignmentAction.java index c3b690c97e..b7857fb7ee 100644 --- a/designer/src/com/fr/design/actions/cell/style/AlignmentAction.java +++ b/designer/src/com/fr/design/actions/cell/style/AlignmentAction.java @@ -21,20 +21,16 @@ import javax.swing.*; public class AlignmentAction extends ButtonGroupAction implements StyleActionInterface { - private static final Icon[] normalBlackIcon = new Icon[]{ - BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_left_normal.png"), - BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_center_normal.png"), - BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_right_normal.png")}; + private static final Icon[][] icons = new Icon[][]{ + {BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_left_normal.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_left_normal_white.png")}, + {BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_center_normal.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_center_normal_white.png")}, + {BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_right_normal.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_right_normal_white.png")}}; - private static final Icon[] toggleWhiteIcon = new Icon[]{ - BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_left_normal_white.png"), - BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_center_normal_white.png"), - BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_right_normal_white.png")}; private static final Integer[] valueArray = new Integer[]{Constants.LEFT, Constants.CENTER, Constants.RIGHT}; public AlignmentAction(ElementCasePane t) { - super(t, normalBlackIcon, valueArray); + super(t, icons, valueArray); } @@ -49,24 +45,14 @@ public class AlignmentAction extends ButtonGroupAction implements StyleActionInt return style.deriveHorizontalAlignment(getSelectedValue()); } - /** - * 更新Style - * - * @param style style - */ - public void updateStyle(Style style) { - UIButtonGroup buttonGroup = createToolBarComponent(); - int selected = BaseUtils.getAlignment4Horizontal(style); - for (int i = 0; i < normalBlackIcon.length; i++) { - UIToggleButton button = buttonGroup.getButton(i); - Icon currentIcon = button.getIcon(); - Icon newIcon = selected == valueArray[i] ? toggleWhiteIcon[i] : normalBlackIcon[i]; - if (newIcon != currentIcon) { - button.setIcon(newIcon); - } - } - setSelectedIndex(selected); - } + /** + * 更新Style + * + * @param style style + */ + public void updateStyle(Style style) { + setSelectedIndex(BaseUtils.getAlignment4Horizontal(style)); + } /** * executeActionReturnUndoRecordNeeded diff --git a/designer/src/com/fr/design/actions/cell/style/ReportFontBoldAction.java b/designer/src/com/fr/design/actions/cell/style/ReportFontBoldAction.java index 0abe5ff4b2..0c1af52b0c 100644 --- a/designer/src/com/fr/design/actions/cell/style/ReportFontBoldAction.java +++ b/designer/src/com/fr/design/actions/cell/style/ReportFontBoldAction.java @@ -21,42 +21,36 @@ import javax.swing.*; public class ReportFontBoldAction extends AbstractStyleAction implements ToggleButtonUpdateAction { private UIToggleButton button; protected Style style; - private final static Icon blackIcon = BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/bold.png"); - private final static Icon whiteIcon = BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/bold_white.png"); + private final static Icon[] icons = {BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/bold.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/bold_white.png")}; public ReportFontBoldAction(ElementCasePane t) { super(t); this.setName(Inter.getLocText("FRFont-bold")); - this.setSmallIcon(blackIcon); + this.setSmallIcon(icons, true); } - /** - * 根据按钮状态获取格式 - * - * @param style - * @param defStyle - * @return - */ - @Override - public Style executeStyle(Style style, Style defStyle) { - button = createToolBarComponent(); - button.setIcon(getToggleButtonIcon(button.isSelected())); - button.setSelected(!button.isSelected()); - if (button.isSelected()) { - setSelectedFont(style); - button.setSelected(false); - } else { - setUnselectedFont(style); - button.setSelected(true); - } + /** + * 根据按钮状态获取格式 + * + * @param style + * @param defStyle + * @return + */ + @Override + public Style executeStyle(Style style, Style defStyle) { + createToolBarComponent().setSelected(!createToolBarComponent().isSelected()); + if (createToolBarComponent().isSelected()) { + setSelectedFont(style); + createToolBarComponent().setSelected(false); + } else { + setUnselectedFont(style); + createToolBarComponent().setSelected(true); + } return this.style; } - protected Icon getToggleButtonIcon(boolean isSelected) { - return isSelected ? blackIcon : whiteIcon; - } protected void setSelectedFont(Style style) { this.style = StyleUtils.boldReportFont(style); @@ -66,22 +60,20 @@ public class ReportFontBoldAction extends AbstractStyleAction implements ToggleB this.style = StyleUtils.unBoldReportFont(style); } - /** - * Update Style. - */ - @Override - public void updateStyle(Style style) { - if (style == null) { - return; - } - FRFont frFont = style.getFRFont(); - if (frFont == null) { - return; - } - button = createToolBarComponent(); - button.setSelected(isStyle(frFont)); - button.setIcon(getToggleButtonIcon(!button.isSelected())); - } + /** + * Update Style. + */ + @Override + public void updateStyle(Style style) { + if (style == null) { + return; + } + FRFont frFont = style.getFRFont(); + if (frFont == null) { + return; + } + createToolBarComponent().setSelected(isStyle(frFont)); + } protected boolean isStyle(FRFont frFont) { return frFont.isBold(); @@ -95,7 +87,7 @@ public class ReportFontBoldAction extends AbstractStyleAction implements ToggleB @Override public UIToggleButton createToolBarComponent() { if (button == null) { - button = GUICoreUtils.createToolBarComponent(this); + button = GUICoreUtils.createToolBarComponentWhiteIcon(this); button.setEventBannded(true); } return button; diff --git a/designer/src/com/fr/design/actions/cell/style/ReportFontItalicAction.java b/designer/src/com/fr/design/actions/cell/style/ReportFontItalicAction.java index 7857cefe8b..9f9f218859 100644 --- a/designer/src/com/fr/design/actions/cell/style/ReportFontItalicAction.java +++ b/designer/src/com/fr/design/actions/cell/style/ReportFontItalicAction.java @@ -17,14 +17,13 @@ import javax.swing.*; */ public class ReportFontItalicAction extends ReportFontBoldAction { - private final static Icon blackIcon = BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/italic.png"); - private final static Icon whiteIcon = BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/italic_white.png"); + private final static Icon[] icons = {BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/italic.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/italic_white.png")}; public ReportFontItalicAction(ElementCasePane t) { super(t); this.setName(Inter.getLocText("FRFont-italic")); - this.setSmallIcon(blackIcon); + this.setSmallIcon(icons, true); } @@ -36,10 +35,6 @@ public class ReportFontItalicAction extends ReportFontBoldAction { this.style = StyleUtils.unItalicReportFont(style); } - protected Icon getToggleButtonIcon(boolean isSelected) { - return isSelected ? blackIcon : whiteIcon; - } - protected boolean isStyle(FRFont frFont) { return frFont.isItalic(); } diff --git a/designer/src/com/fr/design/actions/cell/style/ReportFontUnderlineAction.java b/designer/src/com/fr/design/actions/cell/style/ReportFontUnderlineAction.java index 96369867db..dc4fbe7880 100644 --- a/designer/src/com/fr/design/actions/cell/style/ReportFontUnderlineAction.java +++ b/designer/src/com/fr/design/actions/cell/style/ReportFontUnderlineAction.java @@ -18,14 +18,13 @@ import javax.swing.*; */ public class ReportFontUnderlineAction extends ReportFontBoldAction { - private final static Icon blackIcon = BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/underline.png"); - private final static Icon whiteIcon = BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/underline_white.png"); + private final static Icon[] icons = {BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/underline.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/underline_white.png")}; public ReportFontUnderlineAction(ElementCasePane t) { super(t); this.setName(Inter.getLocText("FRFont-Underline")); - this.setSmallIcon(blackIcon); + this.setSmallIcon(icons, true); } protected void setSelectedFont (Style style) { @@ -36,9 +35,6 @@ public class ReportFontUnderlineAction extends ReportFontBoldAction { this.style = StyleUtils.setReportFontUnderline(style, false); } - protected Icon getToggleButtonIcon(boolean isSelected) { - return isSelected ? blackIcon : whiteIcon; - } protected boolean isStyle(FRFont frFont) { return frFont.getUnderline() != Constants.LINE_NONE; diff --git a/designer_base/src/com/fr/design/actions/UpdateAction.java b/designer_base/src/com/fr/design/actions/UpdateAction.java index eb0ede5fa4..8c458b53f7 100644 --- a/designer_base/src/com/fr/design/actions/UpdateAction.java +++ b/designer_base/src/com/fr/design/actions/UpdateAction.java @@ -139,6 +139,10 @@ public abstract class UpdateAction extends ShortCut implements Action { this.putValue(Action.SMALL_ICON, smallIcon); } + public void setSmallIcon(Icon[] smallIcon, boolean white) { + this.putValue(Action.SMALL_ICON, smallIcon); + } + /** * Returns the mnemonic property setting. * diff --git a/designer_base/src/com/fr/design/gui/ibutton/UIToggleButton.java b/designer_base/src/com/fr/design/gui/ibutton/UIToggleButton.java index c51a72acdf..0a5351048d 100644 --- a/designer_base/src/com/fr/design/gui/ibutton/UIToggleButton.java +++ b/designer_base/src/com/fr/design/gui/ibutton/UIToggleButton.java @@ -48,7 +48,7 @@ public class UIToggleButton extends UIButton implements GlobalNameObserver{ } /** - * 需要反白的按钮接口 + * 需要反白的按钮接口(组合按钮情况-UIButtonGroup) * support icons[normalIcon, selectedIcon] * @param icons */ @@ -67,6 +67,18 @@ public class UIToggleButton extends UIButton implements GlobalNameObserver{ addMouseListener(getMouseListener()); } + /** + * 需要反白的按钮接口(单个按钮情况)-再次点击取消选中状态 + * support icons[normalIcon, selectedIcon] + * @param icons + */ + public UIToggleButton(Icon[] icons, boolean needRelease) { + super(icons[0], null, icons[1]); + setSelectedIcon(icons[1]); + setExtraPainted(true); + addMouseListener(getMouseListener()); + } + public void setGlobalName(String name){ toggleButtonName = name ; } diff --git a/designer_base/src/com/fr/design/gui/style/AlignmentPane.java b/designer_base/src/com/fr/design/gui/style/AlignmentPane.java index 116c853424..f0e760cfd0 100644 --- a/designer_base/src/com/fr/design/gui/style/AlignmentPane.java +++ b/designer_base/src/com/fr/design/gui/style/AlignmentPane.java @@ -80,11 +80,15 @@ public class AlignmentPane extends AbstractBasicStylePane implements GlobalNameO imageLayoutComboBox = new UIComboBox(LAYOUT); initTextRotationCombox(); - Icon[] hAlignmentIconArray = {BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_left_normal.png"), - BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_center_normal.png"), - BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_right_normal.png"), - BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_s_normal.png"), - BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/defaultAlignment.png")}; + Icon[][] hAlignmentIconArray = {{BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_left_normal.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_left_normal_white.png")}, + {BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_center_normal.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_center_normal_white.png")}, + {BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_right_normal.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_right_normal_white.png")}, + {BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_s_normal.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_s_normal.png")}, + {BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/defaultAlignment.png"), BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/defaultAlignment.png")}}; +// BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_center_normal.png"), +// BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_right_normal.png"), +// BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/h_s_normal.png"), +// BaseUtils.readIcon("/com/fr/design/images/m_format/cellstyle/defaultAlignment.png")}; Integer[] hAlignment = new Integer[]{Constants.LEFT, Constants.CENTER, Constants.RIGHT, Integer.valueOf(Constants.DISTRIBUTED), Constants.NULL}; hAlignmentPane = new UIButtonGroup(hAlignmentIconArray, hAlignment); hAlignmentPane.setAllToolTips(new String[]{Inter.getLocText("FR-Designer-StyleAlignment_Tooltips_Left"), Inter.getLocText("FR-Designer-StyleAlignment_Tooltips_Center"), Inter.getLocText("FR-Designer-StyleAlignment_Tooltips_Right"), diff --git a/designer_base/src/com/fr/design/utils/gui/GUICoreUtils.java b/designer_base/src/com/fr/design/utils/gui/GUICoreUtils.java index b68418cc35..0225cf5424 100644 --- a/designer_base/src/com/fr/design/utils/gui/GUICoreUtils.java +++ b/designer_base/src/com/fr/design/utils/gui/GUICoreUtils.java @@ -221,6 +221,33 @@ public abstract class GUICoreUtils{ return (UIToggleButton) object; } + /** + * 创建工具栏组件-反白icon + * @param updateAction 更新动作 + * @return UIToggleButton 按钮 + * + */ + public static UIToggleButton createToolBarComponentWhiteIcon(UpdateAction updateAction) { + UIToggleButton button = new UIToggleButton((Icon[]) updateAction.getValue(Action.SMALL_ICON), true); + button.set4ToolbarButton(); + Integer mnemonicInteger = (Integer) updateAction.getValue(Action.MNEMONIC_KEY); + if (mnemonicInteger != null) { + button.setMnemonic((char) mnemonicInteger.intValue()); + } + + button.addActionListener(updateAction); + + button.registerKeyboardAction(updateAction, updateAction.getAccelerator(), JComponent.WHEN_IN_FOCUSED_WINDOW); + + updateAction.putValue(UIToggleButton.class.getName(), button); + button.setText(StringUtils.EMPTY); + button.setEnabled(updateAction.isEnabled()); + + button.setToolTipText(ActionFactory.createButtonToolTipText(updateAction)); + + return button; + } + /** * 设置一个窗口 *