1 35 36 39 package demo.swingset; 40 import swingwtx.swing.*; 41 import swingwtx.swing.event.*; 42 import swingwtx.swing.border.*; 44 import swingwtx.swing.filechooser.*; 46 import javax.accessibility.*; 47 48 import swingwt.awt.*; 49 import swingwt.awt.event.*; 50 import java.beans.*; 51 import java.util.*; 52 import java.io.*; 53 import java.applet.*; 54 import java.net.*; 55 56 62 public class DemoModule extends JFrame { 63 64 private int PREFERRED_WIDTH = 680; 66 private int PREFERRED_HEIGHT = 600; 67 68 Border loweredBorder = new CompoundBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED), 69 new EmptyBorder(5,5,5,5)); 70 71 public static Dimension HGAP2 = new Dimension(2,1); 73 public static Dimension VGAP2 = new Dimension(1,2); 74 75 public static Dimension HGAP5 = new Dimension(5,1); 76 public static Dimension VGAP5 = new Dimension(1,5); 77 78 public static Dimension HGAP10 = new Dimension(10,1); 79 public static Dimension VGAP10 = new Dimension(1,10); 80 81 public static Dimension HGAP15 = new Dimension(15,1); 82 public static Dimension VGAP15 = new Dimension(1,15); 83 84 public static Dimension HGAP20 = new Dimension(20,1); 85 public static Dimension VGAP20 = new Dimension(1,20); 86 87 public static Dimension HGAP25 = new Dimension(25,1); 88 public static Dimension VGAP25 = new Dimension(1,25); 89 90 public static Dimension HGAP30 = new Dimension(30,1); 91 public static Dimension VGAP30 = new Dimension(1,30); 92 93 private SwingSet2 swingset = null; 94 private JPanel panel = null; 95 private String resourceName = null; 96 private String iconPath = null; 97 private String sourceCode = null; 98 99 private ResourceBundle bundle = null; 101 102 public DemoModule(SwingSet2 swingset) { 103 this(swingset, null, null); 104 } 105 106 public DemoModule(SwingSet2 swingset, String resourceName, String iconPath) { 107 panel = new JPanel(); 108 panel.setLayout(new BorderLayout()); 109 110 this.resourceName = resourceName; 111 this.iconPath = iconPath; 112 this.swingset = swingset; 113 114 loadSourceCode(); 115 } 116 117 public String getResourceName() { 118 return resourceName; 119 } 120 121 public JPanel getDemoPanel() { 122 return panel; 123 } 124 125 public SwingSet2 getSwingSet2() { 126 return swingset; 127 } 128 129 130 public String getString(String key) { 131 String value = "nada"; 132 if(bundle == null) { 133 if(getSwingSet2() != null) { 134 bundle = getSwingSet2().getResourceBundle(); 135 } else { 136 bundle = ResourceBundle.getBundle("resources.swingset"); 137 } 138 } 139 try { 140 value = bundle.getString(key); 141 } catch (MissingResourceException e) { 142 System.out.println("java.util.MissingResourceException: Couldn't find value for: " + key); 143 } 144 return value; 145 } 146 147 public char getMnemonic(String key) { 148 return (getString(key)).charAt(0); 149 } 150 151 public ImageIcon createImageIcon(String filename, String description) { 152 if(getSwingSet2() != null) { 153 return getSwingSet2().createImageIcon(filename, description); 154 } else { 155 String path = "/resources/images/" + filename; 156 return new ImageIcon(getClass().getResource(path), description); 157 } 158 } 159 160 161 public String getSourceCode() { 162 return sourceCode; 163 } 164 165 public void loadSourceCode() { 166 if(getResourceName() != null) { 167 String filename = "../demo/swingset/" + getResourceName() + ".java"; 168 sourceCode = new String ("<html><body bgcolor=\"#ffffff\"><pre>"); 169 char[] buff = new char[50000]; 170 InputStream is; 171 InputStreamReader isr; 172 CodeViewer cv = new CodeViewer(); 173 URL url; 174 File f; 175 176 try { 177 f = new File(filename); 181 is = new FileInputStream(f); 182 isr = new InputStreamReader(is); 183 BufferedReader reader = new BufferedReader(isr); 184 185 String line = reader.readLine(); 188 while(line != null) { 189 sourceCode += cv.syntaxHighlight(line) + " \n "; 190 line = reader.readLine(); 191 } 192 sourceCode += new String ("</pre></body></html>"); 193 } catch (Exception ex) { 194 sourceCode = "Could not load file: " + filename; 195 ex.printStackTrace(); 196 } 197 } 198 } 199 200 public String getName() { 201 return getString(getResourceName() + ".name"); 202 }; 203 204 public Icon getIcon() { 205 return createImageIcon(iconPath, getResourceName() + ".name"); 206 }; 207 208 public String getToolTip() { 209 return getString(getResourceName() + ".tooltip"); 210 }; 211 212 public void mainImpl() { 213 JFrame frame = new JFrame(getName()); 214 frame.getContentPane().setLayout(new BorderLayout()); 215 frame.getContentPane().add(getDemoPanel(), BorderLayout.CENTER); 216 getDemoPanel().setPreferredSize(new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT)); 217 frame.pack(); 218 frame.show(); 219 } 220 221 public JPanel createHorizontalPanel(boolean threeD) { 222 JPanel p = new JPanel(); 223 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); 224 p.setAlignmentY(TOP_ALIGNMENT); 225 p.setAlignmentX(LEFT_ALIGNMENT); 226 if(threeD) { 227 p.setBorder(loweredBorder); 228 } 229 return p; 230 } 231 public JPanel createVerticalPanel(boolean threeD) { 232 JPanel p = new JPanel(); 233 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); 234 p.setAlignmentY(TOP_ALIGNMENT); 235 p.setAlignmentX(LEFT_ALIGNMENT); 236 if(threeD) { 237 p.setBorder(loweredBorder); 238 } 239 return p; 240 } 241 242 public static void main(String [] args) { 243 DemoModule demo = new DemoModule(null); 244 demo.mainImpl(); 245 } 246 247 public void init() { 248 getContentPane().setLayout(new BorderLayout()); 249 getContentPane().add(getDemoPanel(), BorderLayout.CENTER); 250 } 251 } 252 253 | Popular Tags |