Browse Source

REPORT-29416 助记符是否在文本中标记,改为可配置(配置面板中不需要标记)

feature/big-screen
Hugh.C 5 years ago
parent
commit
cf6471ba04
  1. 16
      designer-base/src/main/java/com/fr/design/gui/ibutton/UIRadioButton.java
  2. 121
      designer-base/src/main/java/com/fr/design/gui/ibutton/UIRadioButtonUI.java
  3. 18
      designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBox.java
  4. 8
      designer-realize/src/main/java/com/fr/design/report/PageSetupPane.java

16
designer-base/src/main/java/com/fr/design/gui/ibutton/UIRadioButton.java

@ -22,6 +22,8 @@ public class UIRadioButton extends JRadioButton implements UIObserver, GlobalNam
private GlobalNameListener globalNameListener = null; private GlobalNameListener globalNameListener = null;
private String radioButtonName = StringUtils.EMPTY; private String radioButtonName = StringUtils.EMPTY;
private boolean markMnemonic = true;
public UIRadioButton() { public UIRadioButton() {
super(); super();
initListener(); initListener();
@ -58,6 +60,13 @@ public class UIRadioButton extends JRadioButton implements UIObserver, GlobalNam
initComponent(); initComponent();
} }
public UIRadioButton(String text, boolean selected, boolean markMnemonic) {
super(text, selected);
initListener();
initComponent();
this.markMnemonic = markMnemonic;
}
public UIRadioButton(String text, Icon icon) { public UIRadioButton(String text, Icon icon) {
super(text, icon); super(text, icon);
initListener(); initListener();
@ -70,6 +79,13 @@ public class UIRadioButton extends JRadioButton implements UIObserver, GlobalNam
initListener(); initListener();
} }
public void setMnemonic(char mnemonic) {
super.setMnemonic(mnemonic);
if (!markMnemonic) {
setDisplayedMnemonicIndex(-1);
}
}
private void initListener() { private void initListener() {
if (shouldResponseChangeListener()) { if (shouldResponseChangeListener()) {
this.addItemListener(new ItemListener() { this.addItemListener(new ItemListener() {

121
designer-base/src/main/java/com/fr/design/gui/ibutton/UIRadioButtonUI.java

@ -5,9 +5,12 @@ import com.fr.design.utils.ThemeUtils;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicHTML;
import javax.swing.plaf.metal.MetalRadioButtonUI; import javax.swing.plaf.metal.MetalRadioButtonUI;
import java.awt.*; import java.awt.*;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import javax.swing.text.View;
import sun.swing.SwingUtilities2;
/** /**
* Created by IntelliJ IDEA. * Created by IntelliJ IDEA.
@ -84,6 +87,124 @@ public class UIRadioButtonUI extends MetalRadioButtonUI {
return radioButton; return radioButton;
} }
// ********************************
// Paint Methods
// ********************************
public synchronized void paint(Graphics g, JComponent c) {
AbstractButton b = (AbstractButton) c;
ButtonModel model = b.getModel();
Dimension size = c.getSize();
int w = size.width;
int h = size.height;
Font f = c.getFont();
g.setFont(f);
FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f);
Rectangle viewRect = new Rectangle(size);
Rectangle iconRect = new Rectangle();
Rectangle textRect = new Rectangle();
Insets i = c.getInsets();
viewRect.x += i.left;
viewRect.y += i.top;
viewRect.width -= (i.right + viewRect.x);
viewRect.height -= (i.bottom + viewRect.y);
Icon altIcon = b.getIcon();
Icon selectedIcon = null;
Icon disabledIcon = null;
String text = SwingUtilities.layoutCompoundLabel(
c, fm, b.getText(), altIcon != null ? altIcon : getDefaultIcon(),
b.getVerticalAlignment(), b.getHorizontalAlignment(),
b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
viewRect, iconRect, textRect, b.getIconTextGap());
// fill background
if (c.isOpaque()) {
g.setColor(b.getBackground());
g.fillRect(0, 0, size.width, size.height);
}
// Paint the radio button
if (altIcon != null) {
if (!model.isEnabled()) {
if (model.isSelected()) {
altIcon = b.getDisabledSelectedIcon();
} else {
altIcon = b.getDisabledIcon();
}
} else if (model.isPressed() && model.isArmed()) {
altIcon = b.getPressedIcon();
if (altIcon == null) {
// Use selected icon
altIcon = b.getSelectedIcon();
}
} else if (model.isSelected()) {
if (b.isRolloverEnabled() && model.isRollover()) {
altIcon = b.getRolloverSelectedIcon();
if (altIcon == null) {
altIcon = b.getSelectedIcon();
}
} else {
altIcon = b.getSelectedIcon();
}
} else if (b.isRolloverEnabled() && model.isRollover()) {
altIcon = b.getRolloverIcon();
}
if (altIcon == null) {
altIcon = b.getIcon();
}
altIcon.paintIcon(c, g, iconRect.x, iconRect.y);
} else {
getDefaultIcon().paintIcon(c, g, iconRect.x, iconRect.y);
}
// Draw the Text
if (text != null) {
View v = (View) c.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
v.paint(g, textRect);
} else {
int mnemIndex = b.getDisplayedMnemonicIndex();
if (model.isEnabled()) {
// *** paint the text normally
g.setColor(b.getForeground());
} else {
// *** paint the text disabled
g.setColor(getDisabledTextColor());
}
if (markMnemonic(text, mnemIndex)) {
SwingUtilities2.drawStringUnderlineCharAt(c, g, text,
mnemIndex, textRect.x, textRect.y + fm.getAscent());
} else {
SwingUtilities2.drawString(c, g, text, textRect.x, textRect.y + fm.getAscent());
}
}
if (b.hasFocus() && b.isFocusPainted() &&
textRect.width > 0 && textRect.height > 0) {
paintFocus(g, textRect, size);
}
}
}
/**
* @param text
* @param mnemIndex 助记符在text中的索引
* @return true:需要给助记符画一个下划线
*/
private boolean markMnemonic(String text, int mnemIndex) {
return mnemIndex > 0 && text != null && text.length() > 0 && text.length() > mnemIndex;
}
/** /**
* Paints the focus for the radiobutton * Paints the focus for the radiobutton

18
designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBox.java

@ -34,6 +34,7 @@ public class UICheckBox extends JCheckBox implements UIObserver, GlobalNameObser
private UIObserverListener uiObserverListener; private UIObserverListener uiObserverListener;
private GlobalNameListener globalNameListener = null; private GlobalNameListener globalNameListener = null;
private String checkboxName = ""; private String checkboxName = "";
private boolean markMnemonic = true;
public UICheckBox(String string) { public UICheckBox(String string) {
super(string); super(string);
@ -53,6 +54,13 @@ public class UICheckBox extends JCheckBox implements UIObserver, GlobalNameObser
initListener(); initListener();
} }
public UICheckBox(String locText, boolean b, boolean markMnemonic) {
super(locText, b);
setUI(new UICheckBoxUI());
initListener();
this.markMnemonic=markMnemonic;
}
public UICheckBox(String text, Icon icon) { public UICheckBox(String text, Icon icon) {
super(text, icon); super(text, icon);
setUI(new UICheckBoxUI()); setUI(new UICheckBoxUI());
@ -189,14 +197,18 @@ public class UICheckBox extends JCheckBox implements UIObserver, GlobalNameObser
if (v != null) { if (v != null) {
v.paint(g, textRect); v.paint(g, textRect);
} else { } else {
int mnemIndex = b.getDisplayedMnemonicIndex();
if (model.isEnabled()) { if (model.isEnabled()) {
g.setColor(b.getForeground()); g.setColor(b.getForeground());
} else { } else {
g.setColor(getDisabledTextColor()); g.setColor(getDisabledTextColor());
} }
SwingUtilities2.drawStringUnderlineCharAt(c, g, text, if (markMnemonic) {
mnemIndex, textRect.x, textRect.y + fm.getAscent()); SwingUtilities2.drawStringUnderlineCharAt(c, g, text,
b.getDisplayedMnemonicIndex(), textRect.x, textRect.y + fm.getAscent());
} else {
SwingUtilities2.drawString(c, g, text, textRect.x, textRect.y + fm.getAscent());
}
} }
} }
} }

8
designer-realize/src/main/java/com/fr/design/report/PageSetupPane.java

@ -885,12 +885,12 @@ public class PageSetupPane extends BasicPane {
Icon topBottomIcon = BaseUtils.readIcon("/com/fr/base/images/dialog/pagesetup/down.png"); Icon topBottomIcon = BaseUtils.readIcon("/com/fr/base/images/dialog/pagesetup/down.png");
topBottomRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_PageSetup_Top_To_Bottom")); topBottomRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_PageSetup_Top_To_Bottom"),false,false);
pageOrderPane.add(FRGUIPaneFactory.createIconRadio_S_Pane(topBottomIcon, topBottomRadioButton)); pageOrderPane.add(FRGUIPaneFactory.createIconRadio_S_Pane(topBottomIcon, topBottomRadioButton));
topBottomRadioButton.setMnemonic('B'); topBottomRadioButton.setMnemonic('B');
Icon leftRightIcon = BaseUtils.readIcon("/com/fr/base/images/dialog/pagesetup/over.png"); Icon leftRightIcon = BaseUtils.readIcon("/com/fr/base/images/dialog/pagesetup/over.png");
leftRightRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_PageSetup_Left_To_Right")); leftRightRadioButton = new UIRadioButton(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_PageSetup_Left_To_Right"), false, false);
pageOrderPane.add(FRGUIPaneFactory.createIconRadio_S_Pane(leftRightIcon, leftRightRadioButton)); pageOrderPane.add(FRGUIPaneFactory.createIconRadio_S_Pane(leftRightIcon, leftRightRadioButton));
leftRightRadioButton.setMnemonic('R'); leftRightRadioButton.setMnemonic('R');
@ -907,9 +907,9 @@ public class PageSetupPane extends BasicPane {
defaultPane.add(outcenterOnPagePane); defaultPane.add(outcenterOnPagePane);
this.horizonalCenterCheckBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_PageSetup_Horizontally")); this.horizonalCenterCheckBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_PageSetup_Horizontally"), false, false);
this.horizonalCenterCheckBox.setMnemonic('H'); this.horizonalCenterCheckBox.setMnemonic('H');
this.verticalCenterCheckBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_PageSetup_Vertically")); this.verticalCenterCheckBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_PageSetup_Vertically"), false, false);
this.verticalCenterCheckBox.setMnemonic('V'); this.verticalCenterCheckBox.setMnemonic('V');
centerOnPagePane.add(GUICoreUtils.createFlowPane(horizonalCenterCheckBox, FlowLayout.CENTER)); centerOnPagePane.add(GUICoreUtils.createFlowPane(horizonalCenterCheckBox, FlowLayout.CENTER));

Loading…
Cancel
Save