1 30 31 32 package org.hsqldb.util; 33 34 import java.awt.Dimension ; 35 import java.awt.Image ; 36 import java.awt.Toolkit ; 37 38 import javax.swing.ImageIcon ; 39 import javax.swing.JFrame ; 40 import javax.swing.JOptionPane ; 41 import javax.swing.SwingUtilities ; 42 import javax.swing.UIManager ; 43 44 51 58 class CommonSwing { 59 60 protected static String messagerHeader = "Database Manager Swing Error"; 61 protected static String Native = "Native"; 62 protected static String Java = "Java"; 63 protected static String Motif = "Motif"; 64 protected static String plaf = "plaf"; 65 protected static String GTK = "GTK"; 66 67 static Image getIcon(String target) { 69 70 if (target.equalsIgnoreCase("SystemCursor")) { 71 return (new ImageIcon ( 72 CommonSwing.class.getResource("Hourglass.gif")).getImage()); 73 } else if (target.equalsIgnoreCase("Frame")) { 74 return (new ImageIcon ( 75 CommonSwing.class.getResource("hsqldb.gif")).getImage()); 76 } else if (target.equalsIgnoreCase("Execute")) { 77 return (new ImageIcon ( 78 CommonSwing.class.getResource("run_exc.gif")).getImage()); 79 } else if (target.equalsIgnoreCase("StatusRunning")) { 80 return (new ImageIcon ( 81 CommonSwing.class.getResource("RedCircle.gif")).getImage()); 82 } else if (target.equalsIgnoreCase("StatusReady")) { 83 return (new ImageIcon ( 84 CommonSwing.class.getResource("GreenCircle.gif")).getImage()); 85 } else if (target.equalsIgnoreCase("Clear")) { 86 return (new ImageIcon ( 87 CommonSwing.class.getResource("Clear.png")).getImage()); 88 } else if (target.equalsIgnoreCase("Problem")) { 89 return (new ImageIcon ( 90 CommonSwing.class.getResource("problems.gif")).getImage()); 91 } else if (target.equalsIgnoreCase("BoldFont")) { 92 return (new ImageIcon ( 93 CommonSwing.class.getResource("Bold.gif")).getImage()); 94 } else if (target.equalsIgnoreCase("ItalicFont")) { 95 return (new ImageIcon ( 96 CommonSwing.class.getResource("Italic.gif")).getImage()); 97 } else if (target.equalsIgnoreCase("ColorSelection")) { 98 return (new ImageIcon ( 99 CommonSwing.class.getResource("Colors.png")).getImage()); 100 } else if (target.equalsIgnoreCase("Close")) { 101 return (new ImageIcon ( 102 CommonSwing.class.getResource("Close.png")).getImage()); 103 } else { 104 return (null); 105 } 106 } 107 108 protected static void errorMessage(String errorMessage) { 110 111 115 Object [] options = { "OK" }; 116 117 JOptionPane.showOptionDialog(null, errorMessage, messagerHeader, 118 JOptionPane.DEFAULT_OPTION, 119 JOptionPane.WARNING_MESSAGE, null, 120 options, options[0]); 121 122 } 124 125 public static void errorMessage(Exception exceptionMsg) { 126 errorMessage(exceptionMsg, false); 127 } 128 129 public static void errorMessage(Exception exceptionMsg, boolean quiet) { 131 132 136 Object [] options = { "OK", }; 137 138 JOptionPane.showOptionDialog(null, exceptionMsg, messagerHeader, 139 JOptionPane.DEFAULT_OPTION, 140 JOptionPane.ERROR_MESSAGE, null, 141 options, options[0]); 142 143 if (!quiet) { 144 exceptionMsg.printStackTrace(); 145 } 146 147 } 149 150 static void setFramePositon(JFrame inTargetFrame) { 152 153 Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); 154 Dimension size = inTargetFrame.getSize(); 155 156 if (d.width >= 640) { 158 inTargetFrame.setLocation((d.width - size.width) / 2, 159 (d.height - size.height) / 2); 160 } else { 161 inTargetFrame.setLocation(0, 0); 162 inTargetFrame.setSize(d); 163 } 164 } 165 166 static void setSwingLAF(java.awt.Component comp, String targetTheme) { 211 212 try { 213 if (targetTheme.equalsIgnoreCase(Native)) { 214 UIManager.setLookAndFeel( 215 UIManager.getSystemLookAndFeelClassName()); 216 } else if (targetTheme.equalsIgnoreCase(Java)) { 217 UIManager.setLookAndFeel( 218 UIManager.getCrossPlatformLookAndFeelClassName()); 219 } else if (targetTheme.equalsIgnoreCase(Motif)) { 220 UIManager.setLookAndFeel( 221 "com.sun.java.swing.plaf.motif.MotifLookAndFeel"); 222 } 223 224 SwingUtilities.updateComponentTreeUI(comp); 232 233 if (comp instanceof java.awt.Frame ) { 234 ((java.awt.Frame ) comp).pack(); 235 } 236 } catch (Exception e) { 237 errorMessage(e); 238 } 239 } 240 } 241 | Popular Tags |