// File: WindowDialog.java // Classes: WindowDialog // Author: Kedar Patankar package edu.neu.ccs.demeter.tools.apstudio.graphedit; import java.awt.Button; import java.awt.Event; import java.awt.List; import java.awt.Panel; import java.awt.Label; import java.awt.Color; import java.awt.BorderLayout; import java.util.Vector; import java.util.Enumeration; import java.awt.Point; import java.awt.Dimension; import java.awt.Dialog; import java.awt.event.ActionListener; import java.awt.event.ItemListener; import java.awt.event.ActionEvent; import java.awt.event.ItemEvent; import java.awt.event.WindowEvent; import java.awt.event.WindowAdapter; /* Purpose : To show the list of all open documents(class dictionaries) and then lets user close multiple files or view interesting one */ public class WindowDialog extends Dialog implements ActionListener,ItemListener { private Button _show,_close,_cancel; private List _documentList; private Vector _selectedFiles; private Editor _editor; private String actionRequested; public WindowDialog(Editor frame,String title,Vector v) { super(frame,title,true); _editor=frame; _close = new Button("Close Window"); _cancel = new Button("Cancel"); _show = new Button("Activate"); _documentList = new List(); Panel topicPanel = new Panel(); topicPanel.setLayout(new BorderLayout()); Label l = new Label("Select the Window"); topicPanel.add("North",l); topicPanel.add("Center",_documentList ); topicPanel.setBackground(Color.lightGray); _documentList .setBackground(Color.white); Panel _buttonPanel= new Panel(); _buttonPanel.add(_show); _buttonPanel.add(_close); _buttonPanel.add(_cancel); _buttonPanel.setBackground(Color.lightGray); setLayout(new BorderLayout()); add("Center",topicPanel); add("South",_buttonPanel); fillList(v); pack(); _documentList.setMultipleMode(true); if(_documentList.getItemCount()<1) { _show.setEnabled(false); _close.setEnabled(false); } else _documentList .select(0); // Addition for jdk 1.1 _close.addActionListener(this); _cancel.addActionListener(this); _show.addActionListener(this); _documentList.addItemListener(this); addWindowListener(new WDAdapter()); // using inner class for window handling. } private void fillList(Vector v) { Enumeration items=v.elements(); while (items.hasMoreElements()) { String s=(String)items.nextElement(); if(_editor.get_outStanding().contains(s)) s+=" *"; _documentList.addItem(s); } } public void setVisible(boolean status) { if(status) { _documentList.requestFocus(); Dimension frameSize = getParent().getSize(); Point frameLoc = getParent().getLocation(); Dimension mySize = getSize(); int x,y; x = frameLoc.x + (frameSize.width/2) -(mySize.width/2); y = frameLoc.y + (frameSize.height/2)-(mySize.height/2); setBounds(x,y,getSize().width,getSize().height); } super.setVisible(status); } private void checkButtons() { int[] items=_documentList.getSelectedIndexes(); if(items.length>1) { _close.setEnabled(true); _show.setEnabled(false); } else if(items.length==0) { _close.setEnabled(false); _show.setEnabled(false); } else { _close.setEnabled(true); _show.setEnabled(true); } } public void actionPerformed(ActionEvent event) { Object source = event.getSource(); if(source == _cancel) { actionRequested = "CANCEL"; close(); } else if (source == _close) { actionRequested="CLOSE"; executeCommand(); } else { actionRequested="SHOW"; executeCommand(); } } private void close() {setVisible(false); _editor.setVisible(true); dispose(); } private void executeCommand() { int[] items = _documentList.getSelectedIndexes(); _selectedFiles = new Vector(items.length); for(int i=0;i0) name = name.substring(0,a); _selectedFiles.addElement(name); } close(); } public Vector getSelection(){return _selectedFiles;} public String getRequest(){return actionRequested;} public void itemStateChanged(ItemEvent event) { checkButtons(); } // inner class VDAdapter class WDAdapter extends WindowAdapter { public void windowClosing(WindowEvent event) { close(); } } } /* end class WindowDialog */