19 package com.generalrobotix.ui.util;
21 import java.awt.Color;
22 import java.awt.Component;
23 import java.awt.Container;
24 import java.awt.Dimension;
26 import java.awt.Frame;
27 import java.awt.Insets;
29 import java.util.HashMap;
30 import java.util.Iterator;
33 import javax.swing.AbstractButton;
34 import javax.swing.JButton;
35 import javax.swing.JCheckBox;
36 import javax.swing.JComponent;
37 import javax.swing.JFileChooser;
38 import javax.swing.JRadioButton;
39 import javax.swing.JTextField;
40 import javax.swing.JToggleButton;
41 import javax.swing.UIDefaults;
42 import javax.swing.UIManager;
43 import javax.swing.border.LineBorder;
44 import javax.swing.border.TitledBorder;
45 import javax.swing.filechooser.FileFilter;
46 import javax.swing.plaf.FontUIResource;
51 pane.setBorder(
new TitledBorder(
new LineBorder(Color.BLACK), title,
52 TitledBorder.LEFT, TitledBorder.TOP));
54 pane.setBorder(
new LineBorder(Color.BLACK));
59 FontUIResource fontUIResource =
new FontUIResource(f);
60 UIDefaults defaultTable = UIManager.getLookAndFeelDefaults();
61 Set<Object>
set = defaultTable.keySet();
62 Iterator<Object> it =
set.iterator();
63 while (it.hasNext()) {
65 if (o instanceof String) {
66 String s = (String) o;
67 if (s.endsWith(
"font") || s.endsWith(
"Font"))
68 UIManager.put(s, fontUIResource);
74 Component parent = c.getParent();
78 if (parent instanceof Frame) {
79 return (Frame) parent;
85 Container container) {
86 Component[] components = container.getComponents();
87 for (
int i = 0;
i < components.length;
i++) {
88 Component
c = components[
i];
89 if (c instanceof JButton || c instanceof JToggleButton) {
90 if (!(c instanceof JCheckBox) && !(c instanceof JRadioButton))
91 ((AbstractButton) c).setMargin(insets);
92 }
else if (c instanceof Container)
98 Container container) {
99 Component[] components = container.getComponents();
100 for (
int i = 0;
i < components.length;
i++) {
101 Component
c = components[
i];
102 if (c instanceof JButton || c instanceof JToggleButton) {
103 if (!(c instanceof JCheckBox) && !(c instanceof JRadioButton)) {
104 ((AbstractButton) c).setPreferredSize(size);
105 ((AbstractButton) c).setMaximumSize(size);
107 }
else if (c instanceof Container) {
118 JFileChooser jFileChooser =
new JFileChooser();
121 jFileChooser.setDialogTitle(title);
124 dir =
new File(System.getProperty(
"user.dir"));
125 jFileChooser.setCurrentDirectory(dir);
127 FileFilter[] ff = jFileChooser.getChoosableFileFilters();
128 for (
int i = 1;
i < ff.length;
i++)
129 jFileChooser.removeChoosableFileFilter(ff[
i]);
130 for (
int i = 0; i < filter.length; i++) {
131 if (filter[i] !=
null && !filter[i].equals(
""))
138 return new FileFilter() {
139 public boolean accept(
File f) {
141 String
path = f.getPath();
142 int idx = path.lastIndexOf(
'.');
144 ext = path.substring(idx + 1).toLowerCase();
145 if (ext.equals(filter))
148 return f.isDirectory();
151 public String getDescription() {
152 return filter +
" files (*." + filter +
")";
158 Component[] components = container.getComponents();
159 for (
int i=0;
i<components.length;
i++){
160 Component
c = components[
i];
161 if (!(c instanceof JCheckBox) &&
162 (c instanceof JButton || c instanceof JToggleButton)){
163 if (except ==
null || except.get(((AbstractButton)c).getText()) ==
null)
165 }
else if (c instanceof JTextField) {
167 }
else if (c instanceof Container) {
static void setWholeFont(Font f)
#define null
our own NULL pointer
static JFileChooser createFileChooser(String title, File dir, String[] filter)
static FileFilter createFileFilter(final String filter)
static Frame getParentFrame(Component c)
static void setTitleBorder(JComponent pane, String title)
static JFileChooser createFileChooser(String title, File dir, String filter)
static void setEnableRecursive(boolean e, Container container, HashMap except)
static void setButtonSizeRecursive(Dimension size, Container container)
static void setButtonInsetsRecursive(Insets insets, Container container)