1 30 31 32 package org.hsqldb.util; 33 34 import java.awt.Color ; 35 import java.awt.Container ; 36 import java.awt.Dimension ; 37 import java.awt.FlowLayout ; 38 import java.awt.Font ; 39 import java.awt.GraphicsEnvironment ; 40 import java.awt.event.ActionEvent ; 41 import java.awt.event.ActionListener ; 42 import java.awt.event.ItemEvent ; 43 import java.awt.event.ItemListener ; 44 45 import javax.swing.ImageIcon ; 46 import javax.swing.JButton ; 47 import javax.swing.JCheckBox ; 48 import javax.swing.JColorChooser ; 49 import javax.swing.JComboBox ; 50 import javax.swing.JDialog ; 51 import javax.swing.JFrame ; 52 53 public class FontDialogSwing extends JDialog { 58 59 private static boolean isRunning = false; 60 private static final String BACKGROUND = "Background"; 61 private static String defaultFont = "Dialog"; 62 private static final String FOREGROUND = "Foreground"; 63 private static JButton bgColorButton; 64 private static JCheckBox ckbbold; 65 private static JButton closeButton; 66 private static JButton fgColorButton; 67 private static JComboBox fontsComboBox; 68 69 private static JComboBox fontSizesComboBox; 71 private static final String [] fontSizes = { 72 "8", "9", "10", "11", "12", "13", "14", "16", "18", "24", "36" 73 }; 74 75 private static DatabaseManagerSwing fOwner; 79 private static JFrame frame = 80 new JFrame ("DataBaseManagerSwing Font Selection Dialog"); 81 private static JCheckBox ckbitalic; 82 83 87 public static void CreatFontDialog(DatabaseManagerSwing owner) { 88 89 if (isRunning) { 90 frame.setVisible(true); 91 } else { 92 CommonSwing.setSwingLAF(frame, CommonSwing.Native); 93 94 fOwner = owner; 95 96 frame.setIconImage(CommonSwing.getIcon("Frame")); 97 98 isRunning = true; 99 100 frame.setSize(600, 100); 101 CommonSwing.setFramePositon(frame); 102 103 ckbitalic = new JCheckBox ( 104 new ImageIcon (CommonSwing.getIcon("ItalicFont"))); 105 106 ckbitalic.putClientProperty("is3DEnabled", Boolean.TRUE); 107 ckbitalic.addActionListener(new ActionListener () { 108 109 public void actionPerformed(ActionEvent e) { 110 setStyle(); 111 } 112 }); 113 114 ckbbold = 115 new JCheckBox (new ImageIcon (CommonSwing.getIcon("BoldFont"))); 116 117 ckbbold.putClientProperty("is3DEnabled", Boolean.TRUE); 118 ckbbold.addActionListener(new ActionListener () { 119 120 public void actionPerformed(ActionEvent e) { 121 setStyle(); 122 } 123 }); 124 125 fgColorButton = new JButton ( 126 "Foreground", 127 new ImageIcon (CommonSwing.getIcon("ColorSelection"))); 128 129 fgColorButton.putClientProperty("is3DEnabled", Boolean.TRUE); 130 fgColorButton.addActionListener(new ActionListener () { 131 132 public void actionPerformed(ActionEvent e) { 133 setColor(FOREGROUND); 134 } 135 }); 136 137 bgColorButton = new JButton ( 138 "Background", 139 new ImageIcon (CommonSwing.getIcon("ColorSelection"))); 140 141 bgColorButton.putClientProperty("is3DEnabled", Boolean.TRUE); 142 bgColorButton.addActionListener(new ActionListener () { 143 144 public void actionPerformed(ActionEvent e) { 145 setColor(BACKGROUND); 146 } 147 }); 148 149 closeButton = 150 new JButton ("Close", 151 new ImageIcon (CommonSwing.getIcon("Close"))); 152 153 closeButton.putClientProperty("is3DEnabled", Boolean.TRUE); 154 closeButton.addActionListener(new ActionListener () { 155 156 public void actionPerformed(ActionEvent e) { 157 frame.setVisible(false); 158 } 159 }); 160 161 GraphicsEnvironment ge = 162 GraphicsEnvironment.getLocalGraphicsEnvironment(); 163 String [] fontNames = ge.getAvailableFontFamilyNames(); 164 Dimension fontsComboBoxDimension = new Dimension (160, 25); 165 166 fontsComboBox = new JComboBox (fontNames); 167 168 fontsComboBox.putClientProperty("is3DEnabled", Boolean.TRUE); 169 fontsComboBox.setMaximumSize(fontsComboBoxDimension); 170 fontsComboBox.setPreferredSize(fontsComboBoxDimension); 171 fontsComboBox.setMaximumSize(fontsComboBoxDimension); 172 fontsComboBox.setEditable(false); 173 fontsComboBox.setSelectedItem(defaultFont); 174 fontsComboBox.addActionListener(new ActionListener () { 175 176 public void actionPerformed(ActionEvent e) { 177 setFont(); 178 } 179 }); 180 181 fontSizesComboBox = new JComboBox (fontSizes); 183 184 Dimension spinnerDimension = new Dimension (45, 25); 185 186 fontSizesComboBox.putClientProperty("is3DEnabled", Boolean.TRUE); 187 fontSizesComboBox.setMinimumSize(spinnerDimension); 188 fontSizesComboBox.setPreferredSize(spinnerDimension); 189 fontSizesComboBox.setMaximumSize(spinnerDimension); 190 fontSizesComboBox.addItemListener(new ItemListener () { 191 192 public void itemStateChanged(ItemEvent evt) { 193 194 if (evt.getStateChange() == ItemEvent.SELECTED) { 195 setFontSize((String ) evt.getItem()); 196 } 197 } 198 }); 199 200 Container contentPane = frame.getContentPane(); 215 216 contentPane.setLayout(new FlowLayout ()); 217 contentPane.add(fontsComboBox); 218 219 contentPane.add(fontSizesComboBox); 223 contentPane.add(ckbbold); 224 contentPane.add(ckbitalic); 225 contentPane.add(fgColorButton); 226 contentPane.add(bgColorButton); 227 contentPane.add(closeButton); 228 frame.pack(); 229 frame.setVisible(false); 230 } 231 } 232 233 public static void setFont() { 234 235 Font txtResultFont = fOwner.txtResult.getFont(); 236 237 fOwner.txtResult.setFont( 238 new Font ( 239 fontsComboBox.getSelectedItem().toString(), 240 txtResultFont.getStyle(), txtResultFont.getSize())); 241 242 Font txtCommandFont = fOwner.txtResult.getFont(); 243 244 fOwner.txtCommand.setFont( 245 new Font ( 246 fontsComboBox.getSelectedItem().toString(), 247 txtCommandFont.getStyle(), txtCommandFont.getSize())); 248 249 Font txtTreeFont = fOwner.txtResult.getFont(); 250 251 fOwner.tTree.setFont( 252 new Font ( 253 fontsComboBox.getSelectedItem().toString(), 254 txtTreeFont.getStyle(), txtTreeFont.getSize())); 255 } 256 257 260 public static void setFontSize(String inFontSize) { 261 262 Float stageFloat = new Float (inFontSize); 265 float fontSize = stageFloat.floatValue(); 266 Font fonttTree = fOwner.tTree.getFont().deriveFont(fontSize); 267 268 fOwner.tTree.setFont(fonttTree); 269 270 Font fontTxtCommand = 271 fOwner.txtCommand.getFont().deriveFont(fontSize); 272 273 fOwner.txtCommand.setFont(fontTxtCommand); 274 275 Font fontTxtResult = fOwner.txtResult.getFont().deriveFont(fontSize); 276 277 fOwner.txtResult.setFont(fontTxtResult); 278 } 279 280 284 public static void setStyle() { 285 286 int style = Font.PLAIN; 287 288 if (ckbbold.isSelected()) { 289 style |= Font.BOLD; 290 } 291 292 if (ckbitalic.isSelected()) { 293 style |= Font.ITALIC; 294 } 295 296 fOwner.tTree.setFont(fOwner.txtCommand.getFont().deriveFont(style)); 297 fOwner.txtCommand.setFont( 298 fOwner.txtCommand.getFont().deriveFont(style)); 299 fOwner.txtResult.setFont( 300 fOwner.txtResult.getFont().deriveFont(style)); 301 } 302 303 public static void setColor(String inTarget) { 304 305 if (inTarget.equals(BACKGROUND)) { 306 Color backgroundColor = JColorChooser.showDialog(null, 307 "DataBaseManagerSwing Choose Background Color", 308 fOwner.txtResult.getBackground()); 309 310 if (backgroundColor != null) { 311 bgColorButton.setBackground(backgroundColor); 312 fOwner.txtCommand.setBackground(backgroundColor); 313 fOwner.txtResult.setBackground(backgroundColor); 314 } 315 } else { 316 Color foregroundColor = JColorChooser.showDialog(null, 317 "DataBaseManagerSwing Choose Foreground Color", 318 fOwner.txtResult.getForeground()); 319 320 if (foregroundColor != null) { 321 fgColorButton.setBackground(foregroundColor); 322 fOwner.txtCommand.setForeground(foregroundColor); 323 fOwner.txtResult.setForeground(foregroundColor); 324 } 325 } 326 } 327 } 328 | Popular Tags |