Might fix game log watcher?

This commit is contained in:
huangyuhui
2016-02-16 18:57:26 +08:00
parent cb125b83cb
commit afecb87c6d
29 changed files with 280 additions and 223 deletions

View File

@@ -1,203 +0,0 @@
package org.jackhuang.hellominecraft.lookandfeel;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.util.Map;
import javax.imageio.ImageIO;
import javax.swing.plaf.synth.SynthContext;
import javax.swing.plaf.synth.SynthGraphicsUtils;
/**
* NimbusGraphicsUtils - extends SynthGraphicsUtils to force all Synth painted
* text to be antialiased and provides some static helper methods.
*
* @author Created by Jasper Potts (Jan 4, 2007)
* @version 1.0
*/
public class GraphicsUtils extends SynthGraphicsUtils {
private Map<?, ?> desktopHints;
/**
* Get rendering hints from a Graphics instance. "hintsToSave" is a Map of
* RenderingHint key-values. For each hint key present in that map, the
* value of that hint is obtained from the Graphics and stored as the value
* for the key in savedHints.
*
* @param g2d the graphics surface
* @param hintsToSave the list of rendering hints to set on the graphics
* @param savedHints a set where to save the previous rendering hints, might
* be null
* @return the previous set of rendering hints
*/
public static RenderingHints getRenderingHints(Graphics2D g2d,
Map<?, ?> hintsToSave,
RenderingHints savedHints) {
if (savedHints == null) {
savedHints = new RenderingHints(null);
} else {
savedHints.clear();
}
if (hintsToSave.isEmpty()) {
return savedHints;
}
/* RenderingHints.keySet() returns Set */
for (Object o : hintsToSave.keySet()) {
RenderingHints.Key key = (RenderingHints.Key) o;
Object value = g2d.getRenderingHint(key);
savedHints.put(key, value);
}
return savedHints;
}
/**
* Overrides paintText in SynthGraphicsUtils to force all Synth painted text
* to be antialiased
*/
@Override
public void paintText(SynthContext ss, Graphics g, String text, int x, int y, int mnemonicIndex) {
Graphics2D g2 = (Graphics2D) g;
// XXX: In Java SE 6, Synth already uses the desktop hints, this code should just check whether java.version < 1.6
if (desktopHints == null) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
desktopHints = (Map<?, ?>) (toolkit.getDesktopProperty("awt.font.desktophints"));
}
Object oldAA = null;
RenderingHints oldHints = null;
if (desktopHints != null) {
oldHints = getRenderingHints(g2, desktopHints, null);
g2.addRenderingHints(desktopHints);
} else {
oldAA = g2.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
super.paintText(ss, g, text, x, y, mnemonicIndex);
if (oldHints != null) {
g2.addRenderingHints(oldHints);
} else if (oldAA != null) {
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
oldAA);
}
}
/**
* Load an image using ImageIO from resource in
* org.jdesktop.swingx.plaf.nimbus.images. Catches and prints all Exceptions
* so that it can safely be used in a static context.
*
* @param imgName The name of the image to load, eg. "border.png"
* @return The loaded image
*/
public static BufferedImage loadImage(String imgName) {
try {
return ImageIO.read(GraphicsUtils.class.getClassLoader().getResource("org/jackhuang/hellominecraft/lookandfeel/images/" + imgName));
} catch (Exception e) {
System.err.println("Error loading image \"org/jackhuang/hellominecraft/lookandfeel/images/" + imgName + "\"");
e.printStackTrace();
}
return null;
}
/**
* Get a Color object from a web color string of the form "FF00AB" or
* "#FF00AB".
*
* @param c The color string
* @return The Color described
*/
public static Color getWebColor(String c) {
if (c.startsWith("#")) {
c = c.substring(1);
}
return new Color(
Integer.parseInt(c.substring(0, 2), 16),
Integer.parseInt(c.substring(2, 4), 16),
Integer.parseInt(c.substring(4, 6), 16)
);
}
/**
* Get a Color object from a web color string of the form "FF00AB" or
* "#FF00AB".
*
* @param c The color string
* @return The Color described
*/
public static Color getWebColorWithAlpha(String c) {
if (c.startsWith("#")) {
c = c.substring(1);
}
return new Color(
Integer.parseInt(c.substring(0, 2), 16),
Integer.parseInt(c.substring(2, 4), 16),
Integer.parseInt(c.substring(4, 6), 16),
Integer.parseInt(c.substring(6, 8), 16)
);
}
/**
* Get a Color that is 50% inbetween the two web colors given. The Web
* colors are of the form "FF00AB" or "#FF00AB".
*
* @param c1 The first color string
* @param c2 The second color string
* @return The Color middle color
*/
public static Color getMidWebColor(String c1, String c2) {
return getMidWebColor(c1, c2, 50);
}
/**
* Get a Color that is 50% inbetween the two web colors given. The Web
* colors are of the form "FF00AB" or "#FF00AB".
*
* @param c1 The first color string
* @param c2 The second color string
* @return The Color middle color
*/
public static Color getMidWebColor(String c1, String c2, int percent) {
if (c1.startsWith("#")) {
c1 = c1.substring(1);
}
if (c2.startsWith("#")) {
c2 = c2.substring(1);
}
int rTop = Integer.parseInt(c1.substring(0, 2), 16);
int gTop = Integer.parseInt(c1.substring(2, 4), 16);
int bTop = Integer.parseInt(c1.substring(4, 6), 16);
int rBot = Integer.parseInt(c2.substring(0, 2), 16);
int gBot = Integer.parseInt(c2.substring(2, 4), 16);
int bBot = Integer.parseInt(c2.substring(4, 6), 16);
int rMid = rTop + ((rBot - rTop) * percent / 100);
int gMid = gTop + ((gBot - gTop) * percent / 100);
int bMid = bTop + ((bBot - bTop) * percent / 100);
return new Color(rMid, gMid, bMid);
}
public static Color getMidWebColor(Color c1, Color c2, int percent) {
int rTop = c1.getRed();
int gTop = c1.getGreen();
int bTop = c1.getBlue();
int aTop = c1.getAlpha();
int rBot = c2.getRed();
int gBot = c2.getGreen();
int bBot = c2.getBlue();
int aBot = c2.getAlpha();
int rMid = rTop + ((rBot - rTop) * percent / 100);
int gMid = gTop + ((gBot - gTop) * percent / 100);
int bMid = bTop + ((bBot - bTop) * percent / 100);
int aMid = aTop + ((aBot - aTop) * percent / 100);
return new Color(rMid, gMid, bMid, aMid);
}
}

View File

@@ -17,7 +17,7 @@
package org.jackhuang.hellominecraft.lookandfeel.comp;
import java.awt.Color;
import org.jackhuang.hellominecraft.lookandfeel.GraphicsUtils;
import org.jackhuang.hellominecraft.util.ui.GraphicsUtils;
/**
*

View File

@@ -30,7 +30,7 @@ import javax.swing.SwingUtilities;
import javax.swing.plaf.synth.SynthConstants;
import javax.swing.plaf.synth.SynthContext;
import javax.swing.plaf.synth.SynthPainter;
import org.jackhuang.hellominecraft.lookandfeel.GraphicsUtils;
import org.jackhuang.hellominecraft.util.ui.GraphicsUtils;
import org.jackhuang.hellominecraft.lookandfeel.comp.ConstomButton;
/**

View File

@@ -20,7 +20,7 @@
*/
package org.jackhuang.hellominecraft.lookandfeel.painter;
import org.jackhuang.hellominecraft.lookandfeel.GraphicsUtils;
import org.jackhuang.hellominecraft.util.ui.GraphicsUtils;
import javax.swing.plaf.synth.SynthContext;
import javax.swing.plaf.synth.SynthPainter;

View File

@@ -25,7 +25,7 @@ import javax.swing.plaf.synth.SynthPainter;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.plaf.synth.SynthConstants;
import org.jackhuang.hellominecraft.lookandfeel.GraphicsUtils;
import org.jackhuang.hellominecraft.util.ui.GraphicsUtils;
/**
* TextFieldPainter

View File

@@ -1,6 +1,6 @@
package org.jackhuang.hellominecraft.lookandfeel.ui;
import static org.jackhuang.hellominecraft.lookandfeel.GraphicsUtils.loadImage;
import static org.jackhuang.hellominecraft.util.ui.GraphicsUtils.loadImage;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicComboBoxUI;

View File

@@ -4,7 +4,7 @@
*/
package org.jackhuang.hellominecraft.lookandfeel.ui;
import static org.jackhuang.hellominecraft.lookandfeel.GraphicsUtils.loadImage;
import static org.jackhuang.hellominecraft.util.ui.GraphicsUtils.loadImage;
import javax.swing.JButton;
import javax.swing.JComponent;

View File

@@ -26,7 +26,7 @@
<color value="#9CC5D8" type="TEXT_BACKGROUND"/>
<font name="微软雅黑" size="12" />
</state>
<object id="GraphicsUtils" class="org.jackhuang.hellominecraft.lookandfeel.GraphicsUtils"/>
<object id="GraphicsUtils" class="org.jackhuang.hellominecraft.util.ui.GraphicsUtils"/>
<graphicsUtils idref="GraphicsUtils"/>
</style>
<bind style="default" type="region" key=".*"/>

View File

@@ -26,7 +26,7 @@
<color value="#9CC5D8" type="TEXT_BACKGROUND"/>
<font name="微软雅黑" size="12" />
</state>
<object id="GraphicsUtils" class="org.jackhuang.hellominecraft.lookandfeel.GraphicsUtils"/>
<object id="GraphicsUtils" class="org.jackhuang.hellominecraft.util.ui.GraphicsUtils"/>
<graphicsUtils idref="GraphicsUtils"/>
</style>
<bind style="default" type="region" key=".*"/>