diff --git a/designer/src/com/fr/design/actions/ButtonGroupAction.java b/designer/src/com/fr/design/actions/ButtonGroupAction.java index e3f20f70b..b45a5d34a 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 c3b690c97..b7857fb7e 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 0abe5ff4b..0c1af52b0 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 7857cefe8..9f9f21885 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 96369867d..dc4fbe788 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 eb0ede5fa..8c458b53f 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 c51a72acd..0a5351048 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 116c85342..f0e760cfd 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 b68418cc3..0225cf542 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; + } + /** * 设置一个窗口 *