01: /*
02: * Created on Apr 27, 2004
03: */
04: package uk.org.ponder.swingutil;
05:
06: import java.awt.Font;
07: import java.util.ArrayList;
08:
09: import javax.swing.BorderFactory;
10: import javax.swing.JTree;
11: import javax.swing.ListModel;
12: import javax.swing.UIManager;
13: import javax.swing.border.Border;
14: import javax.swing.plaf.FontUIResource;
15:
16: /**
17: * The class
18: *
19: * @author Bosmon
20: */
21: public class SwingUtil {
22: static final Border empty10Border = BorderFactory
23: .createEmptyBorder(3, 2, 6, 2);
24: static final Border etchedBorder = BorderFactory
25: .createEtchedBorder();
26:
27: public static Border getTitledBorder(String title) {
28: return BorderFactory
29: .createCompoundBorder(BorderFactory.createTitledBorder(
30: etchedBorder, title), empty10Border);
31: }
32:
33: public static void expandJTree(JTree toexpand) {
34: // replace this with a sensible implementation if it fails
35: for (int row = 0; row < toexpand.getRowCount(); ++row) {
36: toexpand.expandRow(row);
37: }
38: }
39:
40: public static void setUIFont(Font f) {
41: //
42: // sets the default font for all Swing components.
43: // ex.
44: // setUIFont (new javax.swing.plaf.FontUIResource("Serif",Font.ITALIC,12));
45: //
46: FontUIResource fur = new FontUIResource(f);
47: java.util.Enumeration keys = UIManager.getDefaults().keys();
48: while (keys.hasMoreElements()) {
49: Object key = keys.nextElement();
50: Object value = UIManager.get(key);
51: if (value instanceof javax.swing.plaf.FontUIResource)
52: UIManager.put(key, fur);
53: }
54: }
55:
56: public static ArrayList listModelToList(ListModel listmodel) {
57: ArrayList togo = new ArrayList();
58: for (int i = 0; i < listmodel.getSize(); ++i) {
59: togo.add(listmodel.getElementAt(i));
60: }
61: return togo;
62: }
63: }
|