1 56 57 package org.objectstyle.cayenne.modeler.util; 58 59 import java.awt.Color ; 60 import java.awt.Font ; 61 import java.awt.Insets ; 62 import java.awt.event.ActionEvent ; 63 import java.awt.event.ActionListener ; 64 import java.util.Arrays ; 65 import java.util.Collection ; 66 67 import javax.swing.DefaultComboBoxModel ; 68 import javax.swing.JButton ; 69 import javax.swing.JComboBox ; 70 import javax.swing.JComponent ; 71 import javax.swing.JLabel ; 72 import javax.swing.JTextField ; 73 import javax.swing.SwingConstants ; 74 75 81 82 public class CayenneWidgetFactory { 85 86 89 protected CayenneWidgetFactory() { 90 super(); 91 } 92 93 96 public static JComboBox createComboBox(Collection model, boolean sort) { 97 return createComboBox(model.toArray(), sort); 98 } 99 100 103 public static JComboBox createComboBox(Object [] model, boolean sort) { 104 JComboBox comboBox = CayenneWidgetFactory.createComboBox(); 105 106 if (sort) { 107 Arrays.sort(model); 108 } 109 110 comboBox.setModel(new DefaultComboBoxModel (model)); 111 return comboBox; 112 } 113 114 117 public static JComboBox createComboBox() { 118 JComboBox comboBox = new JComboBox (); 119 initFormWidget(comboBox); 120 comboBox.setBackground(Color.WHITE); 121 return comboBox; 122 } 123 124 127 public static JTextField createTextField() { 128 return createTextField(20); 129 } 130 131 134 public static JTextField createTextField(int columns) { 135 final JTextField textField = new JTextField (columns); 136 initFormWidget(textField); 137 initTextField(textField); 138 return textField; 139 } 140 141 public static JLabel createLabel(String text) { 142 return new JLabel (text); 143 } 144 145 protected static void initTextField(final JTextField textField) { 146 textField.addActionListener(new ActionListener () { 148 149 public void actionPerformed(ActionEvent e) { 150 textField.transferFocus(); 152 } 153 }); 154 } 155 156 159 protected static void initFormWidget(JComponent component) { 160 component.setFont(component.getFont().deriveFont(Font.PLAIN, 12)); 161 162 167 } 168 169 172 public static JButton createLabelButton(String text) { 173 JButton but = createButton(text); 174 but.setBorderPainted(false); 175 but.setHorizontalAlignment(SwingConstants.LEFT); 176 but.setFocusPainted(false); 177 but.setMargin(new Insets (0, 0, 0, 0)); 178 but.setBorder(null); 179 return but; 180 } 181 182 185 public static JButton createButton(String text) { 186 return new JButton (text); 187 } 188 } | Popular Tags |