// File: Editor.java // Classes: Editor // Original Author: Kedar Patankar // Date 15 Jan 1997 // // Modified Authors: Dave Boatwright and Kevin Carlson // Date 22 Feb 1997 package uci.graphedit; import java.util.Vector; import java.util.Hashtable; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Panel; import java.awt.CardLayout; import java.awt.Scrollbar; import java.awt.Dimension; public class CdPanel extends Panel { private UmlPalette _palette; private Editor _editor; private Panel _documentPanel; private Scrollpanel _documentScrollpanel; private int _documentCount; private int _noOfDocuments; private Vector _documentNames; private Vector _outStanding; private Hashtable _documentTable; private Document _document; private Dimension canvasSize; public Vector get_outStanding(){return _outStanding;} public void addInOutstanding(String s) { if(_outStanding.contains(s)) return; else _outStanding.addElement(s); } public void removeFromOutstanding(String s) { if(!_outStanding.contains(s)) return; else _outStanding.removeElement(s); } public int getNoOfOpenDocuments(){ return _noOfDocuments;} public void updateDocname(String previousName,String presentName) { Document d=(Document)_documentTable.remove(previousName); _documentNames.removeElement(previousName); _documentPanel.remove(d); get_outStanding().removeElement(previousName); d.setDocName(presentName); _documentPanel.add(presentName,d); _documentNames.addElement(presentName); _documentTable.put(presentName,d); } public boolean isPresent(String s) { Object o=_documentTable.get(s); if(o==null) return false; else return true; } public void showDocument(String s) { _documentPanel.remove(_document); _document=(Document)_documentTable.get(s); _documentPanel.add(_document); _documentScrollpanel.home(); show(); _document.setCursorType(_editor); } public Document getDocument(String s){return (Document)_documentTable.get(s);} public void attach(String name,Document d) { _documentPanel.add(name,d); _documentNames.addElement(name); _documentTable.put(name,d); _noOfDocuments +=1; _document=d; _document.resize(canvasSize.width, canvasSize.height); _document.setBackground( new Color(255,255,255) ); _documentScrollpanel.home(); show(); } public String detach(String name,Document d) { _documentPanel.remove(d); _documentTable.remove(name); _documentNames.removeElement(name); _noOfDocuments -=1; get_outStanding().removeElement(name); if(_noOfDocuments>=1) { String title=(String)_documentNames.elementAt(0); _document=(Document)_documentTable.get(title); _documentPanel.add(_document); _documentScrollpanel.home(); return title; } else { _document=null; return null; } } public int nextDocumentNumber() { _documentCount +=1; return _documentCount; } public void resizeCanvas( int width, int height ){ canvasSize.width = width; canvasSize.height = height; _documentScrollpanel.resizeCanvas( canvasSize ); if( _document != null ){ _document.resize( width, height ); } } public void refresh() { _palette.refresh(); } /** Construct a new Editor to edit the given NetList */ public CdPanel(Editor editor) { _editor=editor; setLayout(new BorderLayout()); canvasSize = new Dimension(); _documentScrollpanel = new Scrollpanel(2000,2000); this.resizeCanvas(2000,2000); _documentPanel = _documentScrollpanel.getPanel(); _documentPanel.setLayout( null ); add("Center",_documentScrollpanel); _palette=new UmlPalette(_editor); _palette.setBackground(Color.gray); add("West",_palette); _documentNames=new Vector(); _outStanding=new Vector(); _documentTable=new Hashtable(); _documentCount=0; _noOfDocuments=0; } public Document curDocument(){ return _document;} }