Sorry for the late reply - just got back from vacation. :-)
Not the most elegant solution, but it seems to work for me:
Code:
import org.springframework.richclient.command.support.ApplicationWindowAwareCommand;
import java.awt.Font;
import javax.swing.UIManager;
import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.plaf.FontUIResource;
public class FontAdjustActionCommand extends ApplicationWindowAwareCommand
{
private double fontAdjustment = +1.0d;
public double getFontAdjustment()
{
return this.fontAdjustment;
}
public void setFontAdjustment(final double fontAdjustment)
{
this.fontAdjustment = fontAdjustment;
}
protected void adjustFont(final double adjustAmount)
{
final Object[] objs = UIManager.getLookAndFeel().getDefaults().keySet().toArray();
for(int i = 0;i < objs.length;i++) {
if(objs[i].toString().toUpperCase().indexOf("FONT") != -1) {
final Font font = UIManager.getFont(objs[i]);
UIManager.put(objs[i], new FontUIResource(font.deriveFont((float)(font.getSize() + adjustAmount))));
}
}
final JFrame applicationWindow = getParentWindowControl();
SwingUtilities.updateComponentTreeUI(applicationWindow);
applicationWindow.repaint();
}
//
// METHODS FROM CLASS ActionCommand
//
protected void doExecuteCommand()
{
final double fontAdjustment;
final Object fontAdjustmentParam = getParameter("fontAdjustment");
if(fontAdjustmentParam != null) {
if(fontAdjustmentParam instanceof Number) {
fontAdjustment = ((Number)fontAdjustmentParam).doubleValue();
} else {
fontAdjustment = Double.parseDouble(fontAdjustmentParam.toString());
}
} else {
fontAdjustment = getFontAdjustment();
}
adjustFont(fontAdjustment);
}
}
Setting the fontAdjustment property will allow you to create both "increase font" and "decrease font" command instances from this single class.
I'm not sure off the top of my head how long ago I checked out spring-rich - so this code may need to be revised a little if things have changed. I should note that the font adjustment loop was borrowed from a forum discussion on java.sun.com - though I can no longer remember who was the original author. Though I have modified the loop a little, if I do come across the info on the original author I'll post it in this thread to give proper credit.
- Andy