Browse Source

使用内部类代替重复的方法

feature/big-screen
Qinghui.Liu 3 years ago
parent
commit
3b2df49744
  1. 45
      designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldButton.java

45
designer-chart/src/main/java/com/fr/van/chart/designer/component/richText/VanChartFieldButton.java

@ -2,7 +2,6 @@ package com.fr.van.chart.designer.component.richText;
import com.fr.base.BaseUtils;
import com.fr.data.util.function.DataFunction;
import com.fr.design.constants.UIConstants;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ibutton.UIButtonUI;
import com.fr.design.gui.ibutton.UIToggleButton;
@ -32,6 +31,7 @@ import java.text.Format;
public class VanChartFieldButton extends JPanel {
private static final Icon ADD_ICON = BaseUtils.readIcon("/com/fr/base/images/cell/control/add.png");
private static final Color HOVER_COLOR = new Color(232, 232, 232);
private static final int W = 200;
private static final int H = 24;
@ -126,10 +126,6 @@ public class VanChartFieldButton extends JPanel {
}
private void initComponents(String fieldName, VanChartFieldListener listener) {
Color pressedColor = UIConstants.ATTRIBUTE_PRESS;
Color hoverColor = new Color(232, 232, 232);
Color normalColor = UIConstants.ATTRIBUTE_NORMAL;
fieldButton = new UIToggleButton(fieldName) {
protected MouseListener getMouseListener() {
@ -146,35 +142,13 @@ public class VanChartFieldButton extends JPanel {
}
public ButtonUI getUI() {
return new UIButtonUI() {
protected void doExtraPainting(UIButton b, Graphics2D g2d, int w, int h, String selectedRoles) {
if (isPressed(b) && b.isPressedPainted()) {
GUIPaintUtils.fillPressed(g2d, 0, 0, w, h, b.isRoundBorder(), b.getRectDirection(), b.isDoneAuthorityEdited(selectedRoles), pressedColor);
} else if (isRollOver(b)) {
GUIPaintUtils.fillRollOver(g2d, 0, 0, w, h, b.isRoundBorder(), b.getRectDirection(), b.isDoneAuthorityEdited(selectedRoles), b.isPressedPainted(), hoverColor);
} else if (b.isNormalPainted()) {
GUIPaintUtils.fillNormal(g2d, 0, 0, w, h, b.isRoundBorder(), b.getRectDirection(), b.isDoneAuthorityEdited(selectedRoles), b.isPressedPainted(), normalColor);
}
}
};
return new FieldButtonUI();
}
};
addButton = new UIButton(ADD_ICON) {
public ButtonUI getUI() {
return new UIButtonUI() {
protected void doExtraPainting(UIButton b, Graphics2D g2d, int w, int h, String selectedRoles) {
if (isPressed(b) && b.isPressedPainted()) {
GUIPaintUtils.fillPressed(g2d, 0, 0, w, h, b.isRoundBorder(), b.getRectDirection(), b.isDoneAuthorityEdited(selectedRoles), pressedColor);
} else if (isRollOver(b)) {
GUIPaintUtils.fillRollOver(g2d, 0, 0, w, h, b.isRoundBorder(), b.getRectDirection(), b.isDoneAuthorityEdited(selectedRoles), b.isPressedPainted(), hoverColor);
} else if (b.isNormalPainted()) {
GUIPaintUtils.fillNormal(g2d, 0, 0, w, h, b.isRoundBorder(), b.getRectDirection(), b.isDoneAuthorityEdited(selectedRoles), b.isPressedPainted(), normalColor);
}
}
};
return new FieldButtonUI();
}
};
@ -212,4 +186,17 @@ public class VanChartFieldButton extends JPanel {
public void setSelectedState(boolean selected) {
fieldButton.setSelected(selected);
}
private static class FieldButtonUI extends UIButtonUI {
protected void doExtraPainting(UIButton b, Graphics2D g2d, int w, int h, String selectedRoles) {
if (isPressed(b) && b.isPressedPainted()) {
GUIPaintUtils.fillPressed(g2d, 0, 0, w, h, b.isRoundBorder(), b.getRectDirection(), b.isDoneAuthorityEdited(selectedRoles));
} else if (isRollOver(b)) {
GUIPaintUtils.fillRollOver(g2d, 0, 0, w, h, b.isRoundBorder(), b.getRectDirection(), b.isDoneAuthorityEdited(selectedRoles), b.isPressedPainted(), HOVER_COLOR);
} else if (b.isNormalPainted()) {
GUIPaintUtils.fillNormal(g2d, 0, 0, w, h, b.isRoundBorder(), b.getRectDirection(), b.isDoneAuthorityEdited(selectedRoles), b.isPressedPainted());
}
}
}
}

Loading…
Cancel
Save