Ok, I know this must be funny for most of you, but there are still some desktop Java applications that require updates, e.g. patching (some of us aren’t using web technologies, you know). So, when you have to patch some client application out there, size of your patch matters. If you, on the other hand, have large number of warnings in your source code (let me say, for example 40.000), you can’t just go around your classes and furiously removing warnings since it will create big patch. In that situations, you have three options:
- See no warnings, hear no warnings, speak no warnings – for mediocre, but it actually works;)
- When you commit something, make sure no warnings are commited – e.g. at least clear warnings from classes that will end up in patch anyway – this Eclipse plugin can help
- Be a man! Have balls and clear as much warnings as you can before you get fired!
OK, we’re interested in third solution. If you’re already going to clear as much warnings as possible, it would make sense to first clear warnings from those classes that have them most (remember patch problem). So, if you have 100 classes with 1 warning and 1 class with 100 warnings, you should choose to clear 100 warnings from one class. In ideal world, you wouldn’t mind, but in reality you will not manage to clear all the warnings (unless you really badly want to be fired). So, without further ado, I present you small Eclipse plugin that will show you count of warnings in workspace grouped by Java resource. Created in under 2 hours and then 2 more hours to put it on GitHub (well, what do you want – first time creating GitHub account) and there you have it:
http://stalker314314.github.com/groupwarnings/
You can download plugin directly here and just copy it to plugins/ directory of your Eclipse 3.5+ installation. If you’re lazy enough not to click on my super duper extra site I created on GitHub, then you can see screenshot here (actually, blog post will look much cooler if I put picture here, so I had to make up reason).

Enjoy!
code, eclipse, java, plugin, warning, warnings
Gnome have nifty little feature to show warning icon in the right part of entry box when CAPS LOCK key is on. Actually, it’s part of GtkEntry widget. Warning icon is shown when widget gain focus and disappear when focus is lost. You can see how that looks like:

This is my take to replicate this behavior in Java:
public class WarningPasswordField extends JPasswordField {
private static final long serialVersionUID = -4334432525061916434L;
private final int verticalInsets = 5;
private final int rightOffset = 4;
private BufferedImage warning = null;
public WarningPasswordField() {
super();
try {
InputStream is = this.getClass()
.getResourceAsStream("/warning.png");
if (is != null) {
warning = ImageIO.read(is);
}
} catch (IOException e) {
}
}
@Override
public void paint(Graphics g) {
super.paint(g);
if (warning == null) {
/* image is not loaded, behave like a normal password field */
return;
}
if (!this.isFocusOwner()) {
/* don't paint warning icon if we don't have focus */
return;
}
boolean capsLockOn = false;
try {
capsLockOn = Toolkit.getDefaultToolkit().getLockingKeyState(
KeyEvent.VK_CAPS_LOCK);
} catch (UnsupportedOperationException e) {
/* workaround sun java bug 5100701 when using XToolkit */
}
if (capsLockOn) {
int width = this.getWidth();
int height = this.getHeight();
int iconSize = height - 2 * verticalInsets;
int dx1 = width - (iconSize + rightOffset);
int dy1 = verticalInsets;
/*
* fill white rectangle where image will be, so password stars are
* not visible if image is transparent
*/
g.setColor(Color.WHITE);
g.fillRect(dx1, dy1, iconSize, iconSize);
/* draw warning image */
g.drawImage(warning, dx1, dy1, dx1 + iconSize, dy1 + iconSize, 0,
0, warning.getWidth(), warning.getHeight(), null);
}
}
}
As you can see, paint method is overridden and that’s basically it. Because warning icon’s position is dependent on used look & feel, I left two constants so you can tweak its position. If warning icon can’t be loaded, this code fails silently. I used warning icon from Gnome project, but it could (obviously) be any icon. So here is how it looks (this is nimbus L&F):

Hope you like it and hope it will integrate quickly and nicely into your code;)
Note: RTL languages are not supported, icon there should probably go to the left!
Gnome, GtkEntry, java, JPasswordField, password, swing, warning