// File: SystemToolPanel.java // Classes: SystemToolPanel // Author: Kedar Patankar package edu.neu.ccs.demeter.tools.apstudio.graphedit; import java.awt.Panel; import java.awt.Toolkit; import java.awt.Insets; import java.awt.BorderLayout; import javax.swing.JToolBar; import javax.swing.JButton; import javax.swing.ImageIcon; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; /* Purpose : this class is responsible for displaying system toolbar and handling the events generated by the buttons on the toolbar */ public class SystemToolPanel extends Panel implements ActionListener { private Editor _editor; // reference private JToolBar _toolBar; private JButton newButton,openButton,saveButton,closeButton,closeallButton,printButton,reloadButton,saveallButton,windowlistButton; public SystemToolPanel(Editor editor) { _editor=editor; setLayout(new BorderLayout()); _toolBar = new JToolBar(); makeToolbar(); _toolBar.setFloatable(false); add("North",_toolBar); } public void switchon() { saveButton.setEnabled(true); saveallButton.setEnabled(true); closeButton.setEnabled(true); closeallButton.setEnabled(true); reloadButton.setEnabled(true); printButton.setEnabled(true); } public void switchoff() { saveButton.setEnabled(false); saveallButton.setEnabled(false); closeButton.setEnabled(false); closeallButton.setEnabled(false); reloadButton.setEnabled(false); printButton.setEnabled(false); } public Insets getInsets(){return new Insets(1,1,1,1);} private void makeToolbar() { String INSTALL_DIR=_editor.getInstallDir(); newButton = (JButton) _toolBar.add(new JButton(new ImageIcon(Toolkit.getDefaultToolkit().getImage(INSTALL_DIR+"/images/new.gif")))); newButton.setToolTipText("New CD"); newButton.setMargin(new Insets(0,0,0,0)); newButton.addActionListener(this); _toolBar.addSeparator(); openButton = (JButton) _toolBar.add(new JButton(new ImageIcon(Toolkit.getDefaultToolkit().getImage(INSTALL_DIR+"/images/open.gif")))); openButton.setToolTipText("Open CD"); openButton.setMargin(new Insets(0,0,0,0)); openButton.addActionListener(this); saveButton = (JButton) _toolBar.add(new JButton(new ImageIcon(Toolkit.getDefaultToolkit().getImage(INSTALL_DIR+"/images/save.gif")))); saveButton.setToolTipText("Save CD"); saveButton.setMargin(new Insets(0,0,0,0)); saveButton.setEnabled(false); saveButton.addActionListener(this); saveallButton = (JButton) _toolBar.add(new JButton(new ImageIcon(Toolkit.getDefaultToolkit().getImage(INSTALL_DIR+"/images/saveall.gif")))); saveallButton.setToolTipText("Save All"); saveallButton.setMargin(new Insets(0,0,0,0)); saveallButton.setEnabled(false); saveallButton.addActionListener(this); _toolBar.addSeparator(); closeButton = (JButton) _toolBar.add(new JButton(new ImageIcon(Toolkit.getDefaultToolkit().getImage(INSTALL_DIR+"/images/close.gif")))); closeButton.setToolTipText("Close CD"); closeButton.setMargin(new Insets(0,0,0,0)); closeButton.setEnabled(false); closeButton.addActionListener(this); closeallButton = (JButton) _toolBar.add(new JButton(new ImageIcon(Toolkit.getDefaultToolkit().getImage(INSTALL_DIR+"/images/closeall.gif")))); closeallButton.setToolTipText("Close All"); closeallButton.setMargin(new Insets(0,0,0,0)); closeallButton.setEnabled(false); closeallButton.addActionListener(this); _toolBar.addSeparator(); reloadButton = (JButton) _toolBar.add(new JButton(new ImageIcon(Toolkit.getDefaultToolkit().getImage(INSTALL_DIR+"/images/reload.gif")))); reloadButton.setToolTipText("Reload CD"); reloadButton.setMargin(new Insets(0,0,0,0)); reloadButton.setEnabled(false); reloadButton.addActionListener(this); printButton = (JButton) _toolBar.add(new JButton(new ImageIcon(Toolkit.getDefaultToolkit().getImage(INSTALL_DIR+"/images/print.gif")))); printButton.setToolTipText("Print CD"); printButton.setMargin(new Insets(0,0,0,0)); printButton.setEnabled(false); printButton.addActionListener(this); windowlistButton = (JButton) _toolBar.add(new JButton(new ImageIcon(Toolkit.getDefaultToolkit().getImage(INSTALL_DIR+"/images/windowlist.gif")))); windowlistButton.setToolTipText("Windows List"); windowlistButton.setMargin(new Insets(0,0,0,0)); windowlistButton.addActionListener(this); } public void actionPerformed(ActionEvent event) { if(_editor.curDocument()!=null) _editor.curDocument().requestFocus(); Object source = event.getSource(); if(source == newButton) { Action act=new ActionNew(_editor); act.doIt(); } else if(source == openButton) { Action act = new ActionOpen(_editor); act.doIt(); } else if(source == saveButton) { if(!_editor.curDocument().gcdNeedsSaving()&&(!_editor.curDocument().firstTime())) return; Action act = new ActionSave(_editor,_editor.curDocument()); act.doIt(); } else if(source == saveallButton) { Action act = new ActionSaveall(_editor); act.doIt(); } else if(source == closeButton) { Action act=new ActionClose(_editor,_editor.curDocument()); act.doIt(); } else if(source == closeallButton) { Action act=new ActionCloseall(_editor); act.doIt(); } else if (source == reloadButton) { Action act = new ActionReload(_editor,_editor.curDocument()); act.doIt(); } else if(source == printButton) { Action act = new ActionPrint(_editor); act.doIt(); } else { Action act = new ActionShowDocuments(_editor,_editor.get_openDocnames()); act.doIt(); } } } /* end class SystemToolPanel */