// File: PropertyWindow.java // Classes: PropertyWindow // Author: Kedar Patankar package edu.neu.ccs.demeter.tools.apstudio.graphedit; import java.awt.Dialog; import java.awt.Frame; import java.awt.Panel; import java.awt.Label; import java.awt.CardLayout; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Point; import java.awt.Dimension; import java.awt.ScrollPane; import java.awt.Adjustable; import java.awt.event.WindowListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JScrollPane; /* Purpose : Display and let modify the properties of vertices and edges of class graph */ public class PropertyWindow extends Frame { private Panel _propertyPanel,_defaultPanel,_vertPanel,_constEdgePanel,_inheritPanel,_statusPanel; private String _title; private Editor _editor; private CardLayout _cardLayout; private Label _statusInfo; public void setDefaultMessage() { showMessage("Ready"); } public void showMessage(String message) { _statusInfo.setText(message); invalidate(); } public PropertyWindow(Editor parent) { // super(parent,"Properties",false); super("Properties"); _editor = parent; initialisePanel(); _cardLayout.show(_propertyPanel,"Default"); // jdk 1.1 type window event handling addWindowListener(new PWAdapter()); // using inner class for window handling. _statusInfo = new Label("Ready "); _statusPanel = new Panel(); _statusPanel.setLayout(new BorderLayout()); _statusPanel.add("West",_statusInfo); _statusPanel.setBackground(Color.lightGray); add("South",_statusPanel); pack(); setSize(300,500); setVisible(true); } private void initialisePanel() { _propertyPanel=new Panel(); _cardLayout=new CardLayout(); _propertyPanel.setLayout(_cardLayout); ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED); Adjustable vadjust = sp.getVAdjustable(); Adjustable hadjust = sp.getHAdjustable(); vadjust.setUnitIncrement( 50 ); hadjust.setUnitIncrement( 50 ); sp.add(_defaultPanel = new DefaultPanel(_editor,this)); _propertyPanel.add("Default",sp); sp = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED); vadjust = sp.getVAdjustable(); hadjust = sp.getHAdjustable(); vadjust.setUnitIncrement( 50 ); hadjust.setUnitIncrement( 50 ); sp.add(_vertPanel = new VertPanel(_editor,this)); _propertyPanel.add("Vert",sp); // _propertyPanel.add("TermVert",new TermPanel(_editor)); // _propertyPanel.add("InterfaceVert",new InterfacePanel(_editor)); sp = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED); vadjust = sp.getVAdjustable(); hadjust = sp.getHAdjustable(); vadjust.setUnitIncrement( 50 ); hadjust.setUnitIncrement( 50 ); sp.add(_constEdgePanel = new ConstEdgePanel(_editor,this)); _propertyPanel.add("ConstEdge",sp); sp = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED); vadjust = sp.getVAdjustable(); hadjust = sp.getHAdjustable(); vadjust.setUnitIncrement( 50 ); hadjust.setUnitIncrement( 50 ); sp.add(_inheritPanel = new InheritEdgePanel(_editor)); _propertyPanel.add("InheritanceEdge",sp); _propertyPanel.add("BlankSheet",new Panel()); add("Center",_propertyPanel); pack(); } public void showBlankPropertySheet() { _cardLayout.show(_propertyPanel,"BlankSheet"); } public void showDefault(Document d) { _cardLayout.show(_propertyPanel,"Default"); ((DefaultPanel)_defaultPanel).setValues(d); } public void showVert(Perspective p) { _cardLayout.show(_propertyPanel,"Vert"); UVertex u = (UVertex) p.owner(); Point location = p.position(); Point size = p.get_figure().get_dimensions(); if(u instanceof UConstVertex) ((VertPanel)_vertPanel).setValues((UConstVertex)u,location, size); else ((VertPanel)_vertPanel).setValues((UAltVertex)u,location,size); } // Private methods these are called from above method using case analysis private void showTermVert() { _cardLayout.show(_propertyPanel,"TermVert"); } private void showInterfaceVert() { _cardLayout.show(_propertyPanel,"InterfaceVert"); } public void showEdge(ArcPerspective a) { UEdge u = (UEdge) a.owner(); if(u instanceof UConstEdge) showConstEdge(((UConstEdge)u),a); else if(u instanceof UAltEdge) showAltEdge(a); else showInheritEdge(a); } // Private methods these are called from above method using case analysis private void showConstEdge(UConstEdge u,ArcPerspective a) { _cardLayout.show(_propertyPanel,"ConstEdge"); String cardinality = ((FigConstEdge)a.get_figure()).get_cardinality(); String before = u.get_beforeSyntax(); String after = u.get_afterSyntax(); String name = ((FigConstEdge)a.get_figure()).get_label(); String from = a.get_SourceName(); String to = a.get_DestinationName(); ((ConstEdgePanel)_constEdgePanel).setValues(u,name,cardinality,before,after,from,to); } private void showInheritEdge(ArcPerspective a) { _cardLayout.show(_propertyPanel,"InheritanceEdge"); String from = a.get_SourceName(); String to = a.get_DestinationName(); ((InheritEdgePanel)_inheritPanel).setValues(from,to); } private void showAltEdge(ArcPerspective a) { _cardLayout.show(_propertyPanel,"InheritanceEdge"); String from = a.get_SourceName(); String to = a.get_DestinationName(); ((InheritEdgePanel)_inheritPanel).setValues(to,from); } // inner class PWAdapter class PWAdapter extends WindowAdapter { public void windowClosing(WindowEvent event) { _editor.setMenuPropertySheetState(false); setVisible(false); } } } /* end class PropertyWindow */