Browse Source

REPORT-14057 10.0日文国际化问题处理=>25 tab标题显示不全

bugfix/10.0
plough 6 years ago
parent
commit
e12025cf6c
  1. 63
      designer-base/src/main/java/com/fr/design/gui/ibutton/UIButton.java
  2. 17
      designer-base/src/main/java/com/fr/design/gui/ibutton/UIHeadGroup.java

63
designer-base/src/main/java/com/fr/design/gui/ibutton/UIButton.java

@ -6,22 +6,35 @@ import com.fr.base.GraphHelper;
import com.fr.design.constants.UIConstants; import com.fr.design.constants.UIConstants;
import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserver;
import com.fr.design.event.UIObserverListener; import com.fr.design.event.UIObserverListener;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.stable.Constants; import com.fr.stable.Constants;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.design.utils.gui.GUICoreUtils;
import javax.swing.*; import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.ToolTipManager;
import javax.swing.plaf.ButtonUI; import javax.swing.plaf.ButtonUI;
import java.awt.*; import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.geom.RoundRectangle2D; import java.awt.geom.RoundRectangle2D;
public class UIButton extends JButton implements UIObserver { public class UIButton extends JButton implements UIObserver {
private static final int TOOLTIP_INIT_DELAY = 300; // 延迟 0.3s 显示提示文字
public static final int OTHER_BORDER = 1; public static final int OTHER_BORDER = 1;
public static final int NORMAL_BORDER = 2; public static final int NORMAL_BORDER = 2;
private static final int HEIGH = 20; private static final int HEIGHT = 20;
private boolean isExtraPainted = true; private boolean isExtraPainted = true;
private boolean isRoundBorder = true; private boolean isRoundBorder = true;
private int rectDirection = Constants.NULL; private int rectDirection = Constants.NULL;
@ -36,7 +49,7 @@ public class UIButton extends JButton implements UIObserver {
private CellBorderStyle border = null; private CellBorderStyle border = null;
protected UIObserverListener uiObserverListener; protected UIObserverListener uiObserverListener;
private static final int TOOLTIP_INIT_DELAY = 300; // 延迟 0.3s 显示提示文字 private boolean fixedHeight = true; // 是否将按钮的高度固定为 HEIGHT
public UIButton() { public UIButton() {
this(StringUtils.EMPTY); this(StringUtils.EMPTY);
@ -112,7 +125,7 @@ public class UIButton extends JButton implements UIObserver {
public void set4ToolbarButton() { public void set4ToolbarButton() {
setNormalPainted(false); setNormalPainted(false);
Dimension dim = getPreferredSize(); Dimension dim = getPreferredSize();
dim.height = HEIGH; dim.height = HEIGHT;
setBackground(null); setBackground(null);
setOpaque(false); setOpaque(false);
setSize(dim); setSize(dim);
@ -170,7 +183,11 @@ public class UIButton extends JButton implements UIObserver {
//@Override //@Override
public Dimension getPreferredSize() { public Dimension getPreferredSize() {
return new Dimension(super.getPreferredSize().width, 20); Dimension dim = super.getPreferredSize();
if (isFixedHeight() || dim.height < HEIGHT) {
dim.height = HEIGHT;
}
return dim;
} }
@ -323,6 +340,38 @@ public class UIButton extends JButton implements UIObserver {
this.isBorderPaintedOnlyWhenPressed = value; this.isBorderPaintedOnlyWhenPressed = value;
} }
/**
* 到达指定宽度后换行
*/
public void setLineWrap(int width) {
insertPrefixToText("<html><body style='width: " + width + "px'>");
}
/**
* 自动换行
*/
public void setLineWrap() {
insertPrefixToText("<html><body>");
}
private void insertPrefixToText(String prefix) {
String text = this.getText();
if (StringUtils.isEmpty(text)) {
return;
}
this.setText(prefix + text);
// 如果文本过长,且允许换行的话,需要放开按钮高度的限制
this.setFixedHeight(false);
}
private boolean isFixedHeight() {
return fixedHeight;
}
private void setFixedHeight(boolean fixedHeight) {
this.fixedHeight = fixedHeight;
}
/** /**
* 主函数 * 主函数
* @param args 入口参数 * @param args 入口参数

17
designer-base/src/main/java/com/fr/design/gui/ibutton/UIHeadGroup.java

@ -4,8 +4,13 @@ import com.fr.base.BaseUtils;
import com.fr.design.constants.UIConstants; import com.fr.design.constants.UIConstants;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import javax.swing.*; import javax.swing.Icon;
import java.awt.*; import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
@ -13,6 +18,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class UIHeadGroup extends JPanel { public class UIHeadGroup extends JPanel {
private static final int MIN_HEIGHT = 25;
protected List<UIToggleButton> labelButtonList; protected List<UIToggleButton> labelButtonList;
private boolean isNeedLeftRightOutLine = true; private boolean isNeedLeftRightOutLine = true;
protected int selectedIndex = -1; protected int selectedIndex = -1;
@ -25,7 +31,6 @@ public class UIHeadGroup extends JPanel {
labelButtonList = new ArrayList<UIToggleButton>(textArray.length); labelButtonList = new ArrayList<UIToggleButton>(textArray.length);
this.setBackground(UIConstants.TREE_BACKGROUND); this.setBackground(UIConstants.TREE_BACKGROUND);
this.setLayout(new GridLayout(0, textArray.length, 0, 0)); this.setLayout(new GridLayout(0, textArray.length, 0, 0));
// this.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
for (int i = 0; i < textArray.length; i++) { for (int i = 0; i < textArray.length; i++) {
final int index = i; final int index = i;
String text = textArray[i]; String text = textArray[i];
@ -50,7 +55,6 @@ public class UIHeadGroup extends JPanel {
labelButtonList = new ArrayList<UIToggleButton>(iconArray.length); labelButtonList = new ArrayList<UIToggleButton>(iconArray.length);
this.setBackground(UIConstants.NORMAL_BACKGROUND); this.setBackground(UIConstants.NORMAL_BACKGROUND);
this.setLayout(new GridLayout(0, iconArray.length, 1, 0)); this.setLayout(new GridLayout(0, iconArray.length, 1, 0));
// this.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
for (int i = 0; i < iconArray.length; i++) { for (int i = 0; i < iconArray.length; i++) {
final int index = i; final int index = i;
Icon icon = iconArray[i]; Icon icon = iconArray[i];
@ -99,7 +103,9 @@ public class UIHeadGroup extends JPanel {
@Override @Override
public Dimension getPreferredSize() { public Dimension getPreferredSize() {
Dimension dim = super.getPreferredSize(); Dimension dim = super.getPreferredSize();
dim.height = 25; if (dim.height < MIN_HEIGHT) {
dim.height = MIN_HEIGHT;
}
return dim; return dim;
} }
@ -133,6 +139,7 @@ public class UIHeadGroup extends JPanel {
labelButton.setRoundBorder(false); labelButton.setRoundBorder(false);
labelButton.setBorderPainted(false); labelButton.setBorderPainted(false);
labelButton.setPressedPainted(false); labelButton.setPressedPainted(false);
labelButton.setLineWrap();
labelButtonList.add(labelButton); labelButtonList.add(labelButton);
this.add(labelButton); this.add(labelButton);
} }

Loading…
Cancel
Save