/* a window with a canvas in which connected nodes can be viewed and positioned author: p gray date: 21 june 98 */ import java.awt.*; import java.applet.*; // class which handles graf viewing public class VisualGraph extends Applet { GrafView grafView; String mode = ""; // constructor public void init() { setLayout(new BorderLayout()); // install graf view grafView = new GrafView(); grafView.setBackground(Color.white); add("Center", grafView); // install button panel add("West", new EditButtonPanel(this)); } public Insets getInsets() { return new Insets(10,10,10,10); } //public void paint(Graphics g) public void setMode(String s) { grafView.setMode(s); } } // utility classes class EditButtonPanel extends Panel { Button buttonList[] = new Button[3]; VisualGraph vga; public EditButtonPanel(VisualGraph vga) { this.vga = vga; setBackground(Color.lightGray); Button newNodeButton = new Button("Add Node"); newNodeButton.setBackground(Color.gray); Button newLinkButton = new Button("Add Link"); newLinkButton.setBackground(Color.gray); Button deleteNodeButton = new Button("Delete Node"); deleteNodeButton.setBackground(Color.gray); setLayout(new GridLayout(3,1)); buttonList[0] = (Button) add(newNodeButton); buttonList[1] = (Button) add(newLinkButton); buttonList[2] = (Button) add(deleteNodeButton); } public boolean action(Event event, Object arg) { if (event.target instanceof Button) { if (arg.equals("Add Node")) { System.out.println("New Node button pressed."); vga.setMode("Add Node"); } else if (arg.equals("Add Link")) { System.out.println("New Link button pressed."); vga.setMode("Add Link"); } else { System.out.println("Delete Node button pressed."); vga.setMode("Delete Node"); } } return(true); } }