import javax.swing.*; import java.awt.event.*; import java.awt.*; import java.util.*; import java.beans.*; import java.io.*; public class desktop extends JFrame { /* copyright Tomasz Haupt 1999 */ public JDesktopPane desk; private IconPolice iconPolice = new IconPolice(); /* configuration */ public String selectedServer; private final int MASTER = 1; private final int WEBSERVER = 2; private final int WEBFLOWSERVER = 3; private final int AAD =4; private final int GATEWAY =5; public int n = 6; //# parameters in MasterServerPanel private String Display, ConfFile,IorFile,MyClassPath,servletURL,HashTableFile; public int n_WS = 5; //# parameters in WebServerPanel public String WS_host, WS_port, WS_docroot, WS_classes, WS_servlets; public int n_WF = 6; //#parameters in WebFlowServer public String RootHost, IORdir, IORfile, IORfileURL, WFconfDir, confFile; public int n_AAD = 3; //#parameters of AAD public String AADroot, AADdtd, AADxml; private String[] conf; /* end of configuration */ /* WebFlow server */ public desktop(String title) { /* create deskop, add menu bar and read configuration files */ desk = new JDesktopPane(); setContentPane(desk); desk.setDesktopManager(new DesktopMgr()); loadBackgroundImage(); createMenuBar(); /* if default server is defined read its configuration files */ String dFileName = "defaultServer.txt"; File dServer = new File(dFileName); if(dServer.exists()) { try { FileReader fr = new FileReader(dServer); BufferedReader in = new BufferedReader(fr); selectedServer = in.readLine(); in.close(); } catch (Exception e) {System.out.println(e+" while reading "+dFileName);} readConfigFile(selectedServer+".conf",n,MASTER); readConfigFile(selectedServer+"WS.conf",n_WS,WEBSERVER); readConfigFile(selectedServer+"WF.conf",n_WF,WEBFLOWSERVER); readConfigFile(selectedServer+"AAD.conf",n_AAD,AAD); } } protected void createMenuBar(){ /* menus menu name menu options menu listener =============================================================== File Exit fmbListener --------------------------------------------------------------- Server Select Server cfgListener Configure Server Status (start/stop) Connection --------------------------------------------------------------- Update Update All moduleListener Update module --------------------------------------------------------------- Test File Browser testListener Submit Job --------------------------------------------------------------- Applications Adcirc applListener --------------------------------------------------------------- Help Help helpListener ---------------------------------------------------------------- /* action listener for File menu */ ActionListener fmbListener = new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }; ActionListener cfgListener = new ActionListener() { public void actionPerformed(ActionEvent e) { String what = e.getActionCommand(); if(what.equals("Select Server")) { getSelectedServer(); } if(what.equals("Configure Server")) { getServerConfig(); } if(what.equals("Status")) { TestServer(); } if(what.equals("Connection")) { Connect(); } } }; ActionListener moduleListener = new ActionListener() { public void actionPerformed(ActionEvent e) { String what = e.getActionCommand(); getModule(what); /* what = All or selected package */ } }; /* to be included in next releases ActionListener xmlListener = new ActionListener() { public void actionPerformed(ActionEvent e) { String what = e.getActionCommand(); xmlFrame(what); } }; ActionListener applListener = new ActionListener() { public void actionPerformed(ActionEvent e) { String what = e.getActionCommand(); if(what.equals("Test"))runApplication(); if(what.equals("View"))runWebBrowser(); } }; */ ActionListener testListener = new ActionListener() { public void actionPerformed(ActionEvent e) { String what = e.getActionCommand(); if(what.equals("File Browser")) runFileBrowser(); if(what.equals("Submit Job")) runSubmitJob(); } }; ActionListener applListener = new ActionListener() { public void actionPerformed(ActionEvent e) { String what = e.getActionCommand(); if(what.equals("Adcirc")) runAdcirc(); } }; ActionListener crpcListener = new ActionListener() { public void actionPerformed(ActionEvent e) { String what = e.getActionCommand() ; if (what.equals("CRPC Portal")) runCrpc() ; } } ; ActionListener helpListener = new ActionListener() { public void actionPerformed(ActionEvent e) { String what = e.getActionCommand(); runWebBrowser(what); } }; JMenuBar mb = new JMenuBar(); JMenu FileMenu = new JMenu("File"); JMenuItem exitItem = new JMenuItem("Exit"); exitItem.addActionListener(fmbListener); FileMenu.add(exitItem); JMenu ServerMenu = new JMenu("Server"); JMenuItem selectItem = new JMenuItem("Select Server"); JMenuItem cfgItem = new JMenuItem("Configure Server"); JMenuItem statusItem = new JMenuItem("Status"); JMenuItem troubleItem = new JMenuItem("Connection"); selectItem.addActionListener(cfgListener); cfgItem.addActionListener(cfgListener); statusItem.addActionListener(cfgListener); troubleItem.addActionListener(cfgListener); ServerMenu.add(selectItem); ServerMenu.add(cfgItem); ServerMenu.add(statusItem); ServerMenu.add(troubleItem); JMenu UpdateMenu = new JMenu("Update"); JMenuItem updateAllItem = new JMenuItem("All"); updateAllItem.addActionListener(moduleListener); UpdateMenu.add(updateAllItem); /* add modules from the configuration file here */ JMenu TestMenu = new JMenu("Test"); JMenuItem fbItem = new JMenuItem("File Browser"); JMenuItem sjItem = new JMenuItem("Submit Job"); fbItem.addActionListener(testListener); sjItem.addActionListener(testListener); TestMenu.add(fbItem); TestMenu.add(sjItem); JMenu ApplMenu = new JMenu("Applications"); JMenuItem adcircItem = new JMenuItem("Adcirc"); adcircItem.addActionListener(applListener); ApplMenu.add(adcircItem); JMenuItem crpcItem = new JMenuItem("CRPC Portal") ; crpcItem.addActionListener(crpcListener) ; ApplMenu.add(crpcItem) ; JMenu HelpMenu = new JMenu("Help"); JMenuItem helpItem1 = new JMenuItem("index"); JMenuItem helpItem2 = new JMenuItem("server"); JMenuItem helpItem3 = new JMenuItem("update"); JMenuItem helpItem4 = new JMenuItem("applications"); JMenuItem helpItem5 = new JMenuItem("credentials"); helpItem1.addActionListener(helpListener); helpItem2.addActionListener(helpListener); helpItem3.addActionListener(helpListener); helpItem4.addActionListener(helpListener); helpItem5.addActionListener(helpListener); HelpMenu.add(helpItem1); HelpMenu.add(helpItem2); HelpMenu.add(helpItem3); HelpMenu.add(helpItem4); HelpMenu.add(helpItem5); /* to be added in the next release JMenu XMLmenu = new JMenu("XML"); JMenuItem aadItem = new JMenuItem("AAD"); aadItem.addActionListener(xmlListener); XMLmenu.add(aadItem); */ setJMenuBar(mb); mb.add(FileMenu); mb.add(ServerMenu); mb.add(UpdateMenu); mb.add(TestMenu); mb.add(ApplMenu); mb.add(HelpMenu); /*mb.add(XMLmenu);*/ } protected void loadBackgroundImage() { ImageIcon icon = new ImageIcon("planet.jpg"); JLabel l = new JLabel(icon); l.setBounds(0,0,icon.getIconWidth(),icon.getIconHeight()); desk.add(l, new Integer(Integer.MIN_VALUE)); } class AddFrameAction extends AbstractAction { public AddFrameAction(String name, String menuitem, Integer layer) { super(menuitem); this.name = name; this.layer= layer; } public void actionPerformed(ActionEvent ev) { JInternalFrame f = new JInternalFrame(name, true, true, true, true); f.addVetoableChangeListener(iconPolice); f.setBounds(0,0,200,300); desk.add(f,layer); } private Integer layer; private String name; } class IconPolice implements VetoableChangeListener { public void vetoableChange(PropertyChangeEvent ev) throws PropertyVetoException { String name = ev.getPropertyName(); if(name.equals(JInternalFrame.IS_ICON_PROPERTY) && (ev.getNewValue() == Boolean.TRUE)) { JInternalFrame[] frames = desk.getAllFrames(); int count = frames.length; int nonicons = 0; for (int i=0; i