used findbugs

This commit is contained in:
huangyuhui
2016-02-05 13:10:22 +08:00
parent cd972f5945
commit d4dccd1391
39 changed files with 388 additions and 427 deletions

View File

@@ -18,11 +18,9 @@ package org.jackhuang.hellominecraft.lookandfeel;
import java.awt.Color;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.text.ParseException;
import java.util.Map;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.plaf.synth.SynthLookAndFeel;
import org.jackhuang.hellominecraft.util.logging.HMCLog;
import org.jackhuang.hellominecraft.util.NetUtils;

View File

@@ -42,22 +42,22 @@ import org.jackhuang.hellominecraft.lookandfeel.comp.ConstomButton;
public class ButtonPainter extends SynthPainter {
private static final String DEFAULT_NORMAL = "D5D5D5";
private static final Color[] DEFAULT_NORMAL_FG = new Color[]{
private static final Color[] DEFAULT_NORMAL_FG = new Color[] {
GraphicsUtils.getWebColor(DEFAULT_NORMAL),
GraphicsUtils.getWebColor(DEFAULT_NORMAL)
};
private static final String DEFAULT_PRELIGHT = "A9A9A9";
private static final Color[] DEFAULT_PRELIGHT_FG = new Color[]{
private static final Color[] DEFAULT_PRELIGHT_FG = new Color[] {
GraphicsUtils.getWebColor(DEFAULT_PRELIGHT),
GraphicsUtils.getWebColor(DEFAULT_PRELIGHT)
};
private static final String DEFAULT_ACTIVE = "222222";
private static final Color[] DEFAULT_ACTIVE_FG = new Color[]{
private static final Color[] DEFAULT_ACTIVE_FG = new Color[] {
GraphicsUtils.getWebColor(DEFAULT_ACTIVE),
GraphicsUtils.getWebColor(DEFAULT_ACTIVE)
};
private static final Color[] DISABLED_BG = new Color[]{
private static final Color[] DISABLED_BG = new Color[] {
GraphicsUtils.getWebColor("E3EFE9"),
GraphicsUtils.getMidWebColor("E3EFE9", "DFE2E6"),
GraphicsUtils.getWebColor("DFE2E6"),
@@ -68,7 +68,7 @@ public class ButtonPainter extends SynthPainter {
GraphicsUtils.getWebColor("D8DBE1"),
GraphicsUtils.getWebColor("DADDE3")
};
private static final Color[] DISABLED_FG = new Color[]{
private static final Color[] DISABLED_FG = new Color[] {
GraphicsUtils.getWebColor("C9CCD2"),
GraphicsUtils.getWebColor("C9CCD2"),
GraphicsUtils.getWebColor("BCBFC5"),
@@ -79,18 +79,12 @@ public class ButtonPainter extends SynthPainter {
if (System.currentTimeMillis() > c.lastDrawTime) {
c.lastDrawTime = System.currentTimeMillis();
c.drawPercent += add;
if (c.drawPercent > 100 && add > 0) {
if (c.drawPercent > 100 && add > 0)
c.drawPercent = 100;
} else if (c.drawPercent < 0 && add < 0) {
else if (c.drawPercent < 0 && add < 0)
c.drawPercent = 0;
} else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
c.updateUI();
}
});
}
else
SwingUtilities.invokeLater(c::updateUI);
}
return true;
}
@@ -103,98 +97,84 @@ public class ButtonPainter extends SynthPainter {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Color[] fg, bg;
if ((context.getComponentState() & SynthConstants.DEFAULT) != 0) {
if ((context.getComponentState() & SynthConstants.PRESSED) != 0) {
if ((context.getComponentState() & SynthConstants.DEFAULT) != 0)
if ((context.getComponentState() & SynthConstants.PRESSED) != 0)
if (context.getComponent() instanceof ConstomButton) {
ConstomButton c = (ConstomButton) context.getComponent();
fg = new Color[]{c.activeFg, c.activeFg};
bg = new Color[]{c.activeFg, c.activeFg};
fg = new Color[] { c.activeFg, c.activeFg };
bg = new Color[] { c.activeFg, c.activeFg };
} else {
fg = DEFAULT_ACTIVE_FG;
bg = DEFAULT_ACTIVE_FG;
}
} else if ((context.getComponentState() & SynthConstants.DISABLED) != 0) {
return;
//fg = DISABLED_FG;
//bg = DISABLED_BG;
} else if ((context.getComponentState() & SynthConstants.MOUSE_OVER) != 0) {
else if ((context.getComponentState() & SynthConstants.DISABLED) != 0)
return; //fg = DISABLED_FG;
//bg = DISABLED_BG;
else if ((context.getComponentState() & SynthConstants.MOUSE_OVER) != 0)
if (context.getComponent() instanceof ConstomButton) {
final ConstomButton c = (ConstomButton) context.getComponent();
if (!processCustomButton(c, 1)) {
if (!processCustomButton(c, 1))
return;
}
Color fgs = GraphicsUtils.getMidWebColor(c.normalFg, c.prelightFg, c.drawPercent);
Color bgs = GraphicsUtils.getMidWebColor(c.normalBg, c.prelightBg, c.drawPercent);
fg = new Color[]{fgs, fgs};
bg = new Color[]{bgs, bgs};
fg = new Color[] { fgs, fgs };
bg = new Color[] { bgs, bgs };
} else {
fg = DEFAULT_PRELIGHT_FG;
bg = DEFAULT_PRELIGHT_FG;
}
else if (context.getComponent() instanceof ConstomButton) {
final ConstomButton c = (ConstomButton) context.getComponent();
if (!processCustomButton(c, -1))
return;
Color fgs = GraphicsUtils.getMidWebColor(c.normalFg, c.prelightFg, c.drawPercent);
Color bgs = GraphicsUtils.getMidWebColor(c.normalBg, c.prelightBg, c.drawPercent);
fg = new Color[] { fgs, fgs };
bg = new Color[] { bgs, bgs };
} else {
if (context.getComponent() instanceof ConstomButton) {
final ConstomButton c = (ConstomButton) context.getComponent();
if (!processCustomButton(c, -1)) {
return;
}
Color fgs = GraphicsUtils.getMidWebColor(c.normalFg, c.prelightFg, c.drawPercent);
Color bgs = GraphicsUtils.getMidWebColor(c.normalBg, c.prelightBg, c.drawPercent);
fg = new Color[]{fgs, fgs};
bg = new Color[]{bgs, bgs};
} else {
fg = DEFAULT_NORMAL_FG;
bg = DEFAULT_NORMAL_FG;
}
fg = DEFAULT_NORMAL_FG;
bg = DEFAULT_NORMAL_FG;
}
} else {
if ((context.getComponentState() & SynthConstants.PRESSED) != 0) {
if (context.getComponent() instanceof ConstomButton) {
ConstomButton c = (ConstomButton) context.getComponent();
fg = new Color[]{c.activeFg, c.activeFg};
bg = new Color[]{c.activeFg, c.activeFg};
} else {
fg = DEFAULT_ACTIVE_FG;
bg = DEFAULT_ACTIVE_FG;
}
} else if ((context.getComponentState() & SynthConstants.DISABLED) != 0) {
else if ((context.getComponentState() & SynthConstants.PRESSED) != 0)
if (context.getComponent() instanceof ConstomButton) {
ConstomButton c = (ConstomButton) context.getComponent();
fg = new Color[] { c.activeFg, c.activeFg };
bg = new Color[] { c.activeFg, c.activeFg };
} else {
fg = DEFAULT_ACTIVE_FG;
bg = DEFAULT_ACTIVE_FG;
}
else if ((context.getComponentState() & SynthConstants.DISABLED) != 0)
return; //fg = DISABLED_FG;
//bg = DISABLED_BG;
else if ((context.getComponentState() & SynthConstants.MOUSE_OVER) != 0)
if (context.getComponent() instanceof ConstomButton) {
final ConstomButton c = (ConstomButton) context.getComponent();
if (!processCustomButton(c, 1))
return;
Color fgs = GraphicsUtils.getMidWebColor(c.normalFg, c.prelightFg, c.drawPercent);
Color bgs = GraphicsUtils.getMidWebColor(c.normalBg, c.prelightBg, c.drawPercent);
fg = new Color[] { fgs, fgs };
bg = new Color[] { bgs, bgs };
} else if (context.getComponent() instanceof ConstomButton) {
ConstomButton c = (ConstomButton) context.getComponent();
fg = new Color[] { c.prelightFg, c.prelightFg };
bg = new Color[] { c.prelightBg, c.prelightBg };
} else {
fg = DEFAULT_PRELIGHT_FG;
bg = DEFAULT_PRELIGHT_FG;
}
else if (context.getComponent() instanceof ConstomButton) {
final ConstomButton c = (ConstomButton) context.getComponent();
if (!processCustomButton(c, -1))
return;
//fg = DISABLED_FG;
//bg = DISABLED_BG;
} else if ((context.getComponentState() & SynthConstants.MOUSE_OVER) != 0) {
if (context.getComponent() instanceof ConstomButton) {
final ConstomButton c = (ConstomButton) context.getComponent();
if (!processCustomButton(c, 1)) {
return;
}
Color fgs = GraphicsUtils.getMidWebColor(c.normalFg, c.prelightFg, c.drawPercent);
Color bgs = GraphicsUtils.getMidWebColor(c.normalBg, c.prelightBg, c.drawPercent);
fg = new Color[]{fgs, fgs};
bg = new Color[]{bgs, bgs};
} else {
if (context.getComponent() instanceof ConstomButton) {
ConstomButton c = (ConstomButton) context.getComponent();
fg = new Color[]{c.prelightFg, c.prelightFg};
bg = new Color[]{c.prelightBg, c.prelightBg};
} else {
fg = DEFAULT_PRELIGHT_FG;
bg = DEFAULT_PRELIGHT_FG;
}
}
} else {
if (context.getComponent() instanceof ConstomButton) {
final ConstomButton c = (ConstomButton) context.getComponent();
if (!processCustomButton(c, -1)) {
return;
}
Color fgs = GraphicsUtils.getMidWebColor(c.normalFg, c.prelightFg, c.drawPercent);
Color bgs = GraphicsUtils.getMidWebColor(c.normalBg, c.prelightBg, c.drawPercent);
fg = new Color[]{fgs, fgs};
bg = new Color[]{bgs, bgs};
} else {
fg = DEFAULT_NORMAL_FG;
bg = DEFAULT_NORMAL_FG;
}
}
Color fgs = GraphicsUtils.getMidWebColor(c.normalFg, c.prelightFg, c.drawPercent);
Color bgs = GraphicsUtils.getMidWebColor(c.normalBg, c.prelightBg, c.drawPercent);
fg = new Color[] { fgs, fgs };
bg = new Color[] { bgs, bgs };
} else {
fg = DEFAULT_NORMAL_FG;
bg = DEFAULT_NORMAL_FG;
}
/*w = w - 2;
h = h - 2;
@@ -222,7 +202,7 @@ public class ButtonPainter extends SynthPainter {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Color[] fg, bg;
if ((context.getComponentState() & SynthConstants.DEFAULT) != 0) {
if ((context.getComponentState() & SynthConstants.DEFAULT) != 0)
if ((context.getComponentState() & SynthConstants.PRESSED) != 0 || (context.getComponentState() & SynthConstants.SELECTED) != 0) {
fg = DEFAULT_ACTIVE_FG;
bg = DEFAULT_ACTIVE_FG;
@@ -236,20 +216,18 @@ public class ButtonPainter extends SynthPainter {
fg = DEFAULT_NORMAL_FG;
bg = DEFAULT_NORMAL_FG;
}
else if ((context.getComponentState() & SynthConstants.PRESSED) != 0 || (context.getComponentState() & SynthConstants.SELECTED) != 0) {
fg = DEFAULT_ACTIVE_FG;
bg = DEFAULT_ACTIVE_FG;
} else if ((context.getComponentState() & SynthConstants.DISABLED) != 0) {
fg = DISABLED_FG;
bg = DISABLED_BG;
} else if ((context.getComponentState() & SynthConstants.MOUSE_OVER) != 0) {
fg = DEFAULT_PRELIGHT_FG;
bg = DEFAULT_PRELIGHT_FG;
} else {
if ((context.getComponentState() & SynthConstants.PRESSED) != 0 || (context.getComponentState() & SynthConstants.SELECTED) != 0) {
fg = DEFAULT_ACTIVE_FG;
bg = DEFAULT_ACTIVE_FG;
} else if ((context.getComponentState() & SynthConstants.DISABLED) != 0) {
fg = DISABLED_FG;
bg = DISABLED_BG;
} else if ((context.getComponentState() & SynthConstants.MOUSE_OVER) != 0) {
fg = DEFAULT_PRELIGHT_FG;
bg = DEFAULT_PRELIGHT_FG;
} else {
fg = DEFAULT_NORMAL_FG;
bg = DEFAULT_NORMAL_FG;
}
fg = DEFAULT_NORMAL_FG;
bg = DEFAULT_NORMAL_FG;
}
g2.setColor(fg[0]);
Rectangle2D fgshape = new Rectangle2D.Float(x, y, w, h);
@@ -261,7 +239,7 @@ public class ButtonPainter extends SynthPainter {
/*g2.setPaint(new LinearGradientPaint(x, y, x, y + h,
new float[]{0, 1}, bg));
g2.fillRect(x, y, w, h);
g2.setPaint(new LinearGradientPaint(x, y, x, y + h,
new float[]{0, 1}, fg));
g2.drawRect(x, y, w, h);*/

View File

@@ -17,7 +17,7 @@
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
*/
package org.jackhuang.hellominecraft.lookandfeel.painter;
import javax.swing.plaf.synth.SynthContext;
@@ -36,18 +36,19 @@ import org.jackhuang.hellominecraft.lookandfeel.GraphicsUtils;
public class TextFieldPainter extends SynthPainter {
private boolean fill = true;
private static final Color disabled = GraphicsUtils.getWebColor("F3F3F3"),
normal = GraphicsUtils.getWebColor("CCCCCC"),
focused = GraphicsUtils.getWebColor("000000"),
over = GraphicsUtils.getWebColor("7F7F7F");
public TextFieldPainter() {}
private static final Color DISABLED = GraphicsUtils.getWebColor("F3F3F3"),
NORMAL = GraphicsUtils.getWebColor("CCCCCC"),
FOCUSED = GraphicsUtils.getWebColor("000000"),
OVER = GraphicsUtils.getWebColor("7F7F7F");
public TextFieldPainter() {
}
public TextFieldPainter(boolean fill) {
this.fill = fill;
}
private void paintFieldBackground(SynthContext context, Graphics g, int x, int y, int w, int h) {
w--;
h--;
@@ -55,16 +56,15 @@ public class TextFieldPainter extends SynthPainter {
g.setColor(Color.WHITE);
g.fillRect(x, y, w, h);
}
Color color = null;
if((context.getComponentState() & SynthConstants.MOUSE_OVER) != 0) {
color = over;
} else if((context.getComponentState() & SynthConstants.DISABLED) != 0) {
color = disabled;
} else if((context.getComponentState() & SynthConstants.FOCUSED) != 0) {
color = focused;
} else {
color = normal;
}
Color color;
if ((context.getComponentState() & SynthConstants.MOUSE_OVER) != 0)
color = OVER;
else if ((context.getComponentState() & SynthConstants.DISABLED) != 0)
color = DISABLED;
else if ((context.getComponentState() & SynthConstants.FOCUSED) != 0)
color = FOCUSED;
else
color = NORMAL;
g.setColor(color);
g.drawLine(x, y, x + w, y);
g.drawLine(x, y, x, y + w);

View File

@@ -27,10 +27,10 @@ import java.awt.event.MouseEvent;
*/
public class ComboBoxUI extends BasicComboBoxUI implements MouseListener {
private static final BufferedImage combo_normal = loadImage("combo_normal.png");
private static final BufferedImage combo_over = loadImage("combo_over.png");
private static final BufferedImage combo_pressed = loadImage("combo_pressed.png");
private static final BufferedImage combo_disabled = loadImage("combo_disabled.png");
private static final BufferedImage COMBO_NORMAL = loadImage("combo_normal.png");
private static final BufferedImage COMBO_OVER = loadImage("combo_over.png");
private static final BufferedImage COMBO_PRESSED = loadImage("combo_pressed.png");
private static final BufferedImage COMBO_DISABLED = loadImage("combo_disabled.png");
private static final Dimension BTN_SIZE = new Dimension(17, 20);
private final Dimension btnSize = new Dimension(BTN_SIZE);
@@ -39,6 +39,7 @@ public class ComboBoxUI extends BasicComboBoxUI implements MouseListener {
* method that all UI deligates must have.
*
* @param c The component that the UI is for
*
* @return a new instance of NimbusComboBoxUI
*/
public static ComponentUI createUI(JComponent c) {
@@ -66,13 +67,13 @@ public class ComboBoxUI extends BasicComboBoxUI implements MouseListener {
/**
* The minumum size is the size of the display area plus insets plus the
* button.
*
* @return the size yeah.
*/
@Override
public Dimension getMinimumSize(JComponent c) {
if (!isMinimumSizeDirty) {
if (!isMinimumSizeDirty)
return new Dimension(cachedMinimumSize);
}
Dimension size = getDisplaySize();
Insets insets = getInsets();
btnSize.height = size.height = Math.max(size.height, BTN_SIZE.height);
@@ -92,17 +93,16 @@ public class ComboBoxUI extends BasicComboBoxUI implements MouseListener {
@Override
protected void paintComponent(Graphics g) {
if (comboBox.isEditable()) {
BufferedImage img = combo_normal;
if (mouseDown) {
img = combo_pressed;
} else if (!comboBox.isEnabled()) {
img = combo_normal;
} else if (mouseInside) {
img = combo_over;
}
BufferedImage img = COMBO_NORMAL;
if (mouseDown)
img = COMBO_PRESSED;
else if (!comboBox.isEnabled())
img = COMBO_NORMAL;
else if (mouseInside)
img = COMBO_OVER;
g.drawImage(img,
0, 0, getWidth(), getHeight(),
0, 0, img.getWidth(), img.getHeight(), comboBox);
0, 0, getWidth(), getHeight(),
0, 0, img.getWidth(), img.getHeight(), comboBox);
}
}
};
@@ -125,32 +125,30 @@ public class ComboBoxUI extends BasicComboBoxUI implements MouseListener {
((JComponent) renderer).setForeground(comboBox.getForeground());
}
paintCurrentValue(g, rectangleForCurrentValue(), false);
if (renderer instanceof JComponent) {
if (renderer instanceof JComponent)
((JComponent) renderer).setOpaque(true);
}
}
}
@Override
public void paintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus) {
if (!comboBox.isEditable()) {
BufferedImage img = combo_normal;
if (!comboBox.isEnabled()) {
img = combo_disabled;
} else if (mouseDown) {
img = combo_pressed;
} else if (mouseInside) {
img = combo_over;
}
BufferedImage img = COMBO_NORMAL;
if (!comboBox.isEnabled())
img = COMBO_DISABLED;
else if (mouseDown)
img = COMBO_PRESSED;
else if (mouseInside)
img = COMBO_OVER;
g.drawImage(img,
bounds.x, bounds.y, bounds.x + 4, bounds.y + bounds.height,
0, 0, 1, 26, comboBox);
bounds.x, bounds.y, bounds.x + 4, bounds.y + bounds.height,
0, 0, 1, 26, comboBox);
g.drawImage(img,
bounds.x + 1, bounds.y, bounds.x + bounds.width - 25, bounds.y + bounds.height,
1, 0, 3, 26, comboBox);
bounds.x + 1, bounds.y, bounds.x + bounds.width - 25, bounds.y + bounds.height,
1, 0, 3, 26, comboBox);
g.drawImage(img,
bounds.x + bounds.width - 25, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height,
4, 0, 29, 26, comboBox);
bounds.x + bounds.width - 25, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height,
4, 0, 29, 26, comboBox);
} else {
/*g.setColor(Color.WHITE);
g.fillRect(bounds.x, bounds.y, bounds.width - btnSize.width, bounds.height - 1);
@@ -194,9 +192,8 @@ public class ComboBoxUI extends BasicComboBoxUI implements MouseListener {
@Override
public void mouseEntered(MouseEvent e) {
if (comboBox.isEditable()) {
if (e.getComponent() == arrowButton) {
if (e.getComponent() == arrowButton)
mouseInside = true;
}
} else {
mouseInside = true;
comboBox.repaint();
@@ -206,9 +203,8 @@ public class ComboBoxUI extends BasicComboBoxUI implements MouseListener {
@Override
public void mouseExited(MouseEvent e) {
if (comboBox.isEditable()) {
if (e.getComponent() == arrowButton) {
if (e.getComponent() == arrowButton)
mouseInside = false;
}
} else {
mouseInside = false;
comboBox.repaint();
@@ -218,9 +214,8 @@ public class ComboBoxUI extends BasicComboBoxUI implements MouseListener {
@Override
public void mousePressed(MouseEvent e) {
if (comboBox.isEditable()) {
if (e.getComponent() == arrowButton) {
if (e.getComponent() == arrowButton)
mouseDown = true;
}
} else {
mouseDown = true;
comboBox.repaint();
@@ -230,9 +225,8 @@ public class ComboBoxUI extends BasicComboBoxUI implements MouseListener {
@Override
public void mouseReleased(MouseEvent e) {
if (comboBox.isEditable()) {
if (e.getComponent() == arrowButton) {
if (e.getComponent() == arrowButton)
mouseDown = false;
}
} else {
mouseDown = false;
comboBox.repaint();
@@ -269,16 +263,14 @@ public class ComboBoxUI extends BasicComboBoxUI implements MouseListener {
Insets insets = getInsets();
Rectangle cvb;
if (arrowButton != null) {
if (cb.getComponentOrientation().isLeftToRight()) {
if (arrowButton != null)
if (cb.getComponentOrientation().isLeftToRight())
arrowButton.setBounds(width - (insets.right + btnSize.width),
insets.top,
btnSize.width, btnSize.height);
} else {
insets.top,
btnSize.width, btnSize.height);
else
arrowButton.setBounds(insets.left, insets.top,
btnSize.width, btnSize.height);
}
}
btnSize.width, btnSize.height);
if (editor != null) {
cvb = rectangleForCurrentValue();
editor.setBounds(cvb.x, cvb.y, cvb.width, cvb.height);