// File: UmlPalette.java // Classes: UmlPalette // 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 the Class Diagram toolbar and handling the events generated by the toolbar. */ public class UmlPalette extends Panel implements ActionListener { private JButton _selectButton; private JButton _constvert,_altvert; private JButton _constedge,_altedge; private Editor _editor; private JToolBar _toolBar; public UmlPalette(Editor editor) { _editor=editor; setLayout(new BorderLayout()); _toolBar = new JToolBar(); makeToolbar(); _toolBar.setFloatable(false); add("North",_toolBar); } public Insets getInsets(){return new Insets(1,1,1,1);} private void makeToolbar() { String INSTALL_DIR=_editor.getInstallDir(); _selectButton = (JButton) _toolBar.add(new JButton(new ImageIcon(Toolkit.getDefaultToolkit().getImage(INSTALL_DIR+"/images/select.gif")))); _selectButton.setToolTipText("Select Objects"); _selectButton.setMargin(new Insets(0,0,0,0)); _selectButton.addActionListener(this); _toolBar.addSeparator(); _constvert = (JButton) _toolBar.add(new JButton(new ImageIcon(Toolkit.getDefaultToolkit().getImage(INSTALL_DIR+"/images/cv.gif")))); _constvert.setToolTipText("Construction Class"); _constvert.setMargin(new Insets(0,0,0,0)); _constvert.addActionListener(this); _altvert = (JButton) _toolBar.add(new JButton(new ImageIcon(Toolkit.getDefaultToolkit().getImage(INSTALL_DIR+"/images/av.gif")))); _altvert.setToolTipText("Alternation Class"); _altvert.setMargin(new Insets(0,0,0,0)); _altvert.addActionListener(this); _constedge = (JButton) _toolBar.add(new JButton(new ImageIcon(Toolkit.getDefaultToolkit().getImage(INSTALL_DIR+"/images/ce.gif")))); _constedge.setToolTipText("Construction Edge"); _constedge.setMargin(new Insets(0,0,0,0)); _constedge.addActionListener(this); _altedge = (JButton) _toolBar.add(new JButton(new ImageIcon(Toolkit.getDefaultToolkit().getImage(INSTALL_DIR+"/images/ae.gif")))); _altedge.setToolTipText("Alternation Edge"); _altedge.setMargin(new Insets(0,0,0,0)); _altedge.addActionListener(this); } public void refresh() { int i=_editor.getNoOfOpenDocuments(); if(i<=0) switchoff(); else switchon(); } private void switchoff() { _selectButton.setEnabled(false); _constvert.setEnabled(false); _altvert.setEnabled(false); _constedge.setEnabled(false); _altedge.setEnabled(false); } private void switchon() { _selectButton.setEnabled(true); _constvert.setEnabled(true); _altvert.setEnabled(true); _constedge.setEnabled(true); _altedge.setEnabled(true); } public void actionPerformed(ActionEvent event) { _editor.curDocument().requestFocus(); Object source = event.getSource(); if(source == _selectButton) _editor.curDocument().mode(new ModeSelect(_editor.curDocument(),_editor),false); else if(source == _constvert) _editor.curDocument().mode(new ModeCreateConstVertex(_editor.curDocument(),_editor),false); else if(source == _altvert) _editor.curDocument().mode(new ModeCreateAltVertex(_editor.curDocument(),_editor),false); else if(source == _constedge) _editor.curDocument().mode(new ModeCreateConstEdge(_editor.curDocument(),_editor),false); else if(source == _altedge) _editor.curDocument().mode(new ModeCreateAltEdge(_editor.curDocument()),false); } } /* end class UmlPalette */