1 50 package com.lowagie.tools; 51 52 import java.awt.event.ActionEvent; 53 import java.awt.event.ActionListener; 54 import java.awt.event.KeyEvent; 55 import java.io.IOException; 56 import java.util.Iterator; 57 import java.util.Properties; 58 59 import javax.swing.JDesktopPane; 60 import javax.swing.JFrame; 61 import javax.swing.JInternalFrame; 62 import javax.swing.JMenu; 63 import javax.swing.JMenuBar; 64 import javax.swing.JMenuItem; 65 66 import com.lowagie.tools.plugins.AbstractTool; 67 68 71 public class Toolbox extends JFrame implements ToolMenuItems, ActionListener { 72 73 74 private JDesktopPane desktop; 75 76 private Properties toolmap = new Properties(); 77 78 81 public Toolbox() { 82 super(); 83 setSize(600, 400); 84 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 85 setResizable(true); 86 setTitle("iText Toolbox"); 87 setJMenuBar(getMenubar()); 88 desktop = new JDesktopPane(); 89 setContentPane(desktop); 90 setVisible(true); 91 } 92 93 97 public static void main(String[] args) { 98 JFrame.setDefaultLookAndFeelDecorated(true); 99 Toolbox toolbox = new Toolbox(); 100 } 101 102 106 private JMenuBar getMenubar() { 107 if (toolmap.size() == 0) { 108 try { 109 toolmap.load(Toolbox.class.getClassLoader().getResourceAsStream("com/lowagie/tools/plugins/tools.txt")); 110 } catch (IOException e) { 111 e.printStackTrace(); 112 } 113 } 114 JMenuBar menubar = new JMenuBar(); 115 JMenu file = new JMenu(FILE); 116 file.setMnemonic(KeyEvent.VK_F); 117 JMenuItem close = new JMenuItem(CLOSE); 118 close.setMnemonic(KeyEvent.VK_C); 119 close.addActionListener(this); 120 file.add(close); 121 JMenu tools = new JMenu(TOOLS); 122 file.setMnemonic(KeyEvent.VK_T); 123 JMenuItem item; 124 String name; 125 for (Iterator i = toolmap.keySet().iterator(); i.hasNext(); ) { 126 name = (String)i.next(); 127 item = new JMenuItem(name); 128 item.addActionListener(this); 129 tools.add(item); 130 } 131 menubar.add(file); 132 menubar.add(tools); 133 return menubar; 134 } 135 136 143 private void createFrame(String name) throws InstantiationException, IllegalAccessException, ClassNotFoundException { 144 AbstractTool ti = (AbstractTool)Class.forName((String)toolmap.get(name)).newInstance(); 145 JInternalFrame f = ti.getInternalFrame(); 146 f.setVisible(true); 147 desktop.add(f); 148 } 149 150 153 public void actionPerformed(ActionEvent evt) { 154 if (CLOSE.equals(evt.getActionCommand())) { 155 System.exit(0); 156 } 157 else { 158 try { 159 createFrame(evt.getActionCommand()); 160 } 161 catch(Exception e) { 162 e.printStackTrace(); 163 } 164 } 165 } 166 } | Popular Tags |