/* Author: Jeff Dalton * Updated: Tue Dec 4 00:17:37 2001 by Jeff Dalton * Copyright: (c) 2001, AIAI, University of Edinburgh */ package ix.ideel; import javax.swing.*; import java.awt.Container; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.Dimension; import java.awt.event.*; import ix.ip2.*; import ix.ichat.ChatFrame; import ix.iview.*; import ix.iface.util.LogoPanel; import ix.util.*; /** * The main frame of the I-DEEL user interface. */ public class IdeelFrame extends Ip2Frame implements ActionListener { Container contentPane; ChatFrame chatFrame; IssueViewingTable issueViewer; // s.b. just IssueViewer? /\/ BasicIdeel ideel; // /\/: May want some way to find menus my looking at the menu bar // components, rather than storing the menus as fields in the frame. JMenu fileMenu = new JMenu("File"); JMenu issueMenu = new JMenu("Issue"); JMenu toolsMenu = new JMenu("Tools"); JMenu testMenu = new JMenu("Test", true); // tear-off "Test" menu public IdeelFrame(BasicIdeel ideel) { super(ideel.displayName); this.ideel = ideel; } protected void setUp() { issueViewer = new IssueViewingTable(ideel); contentPane = getContentPane(); setSize(500, 300); setJMenuBar(makeMenuBar()); // Layout manager defaults to BorderLayout. // contentPane.setLayout(new FlowLayout()); // probably not too clever // Add issue Viewer { JPanel issuePanel = new JPanel(); issuePanel.add(issueViewer); JScrollPane scroll = new JScrollPane(issuePanel); scroll.setBorder(BorderFactory.createTitledBorder("Issues")); contentPane.add(scroll, BorderLayout.CENTER); } // Add something that identifies the system etc. contentPane.add(ideel.makeLogoPanel(), BorderLayout.SOUTH); } protected void becomeVisible() { // sep method so can do it last // Find the "packed" width, then change the height. pack(); { Dimension size = getSize(); setSize(new Dimension((int)size.getWidth(), 300)); } setVisible(true); } protected void ensureDomainEditor() { if (domainEditor == null) { domainEditor = makeDomainEditor(ideel, ideel.domain); // domainEditor.setLocation(getX() + 100, getY() + 100); } domainEditor.setVisible(true); } public void ensureChat() { if (chatFrame == null) { chatFrame = new ChatFrame(ideel, ideel.symbolName + " I-Chat"); } chatFrame.setVisible(true); } /* * Menu bar */ protected JMenuBar makeMenuBar() { JMenuBar bar = new JMenuBar(); // File menu bar.add(fileMenu); fileMenu.add(makeMenuItem("Load or Edit Domain")); fileMenu.add(makeMenuItem("Reset")); fileMenu.addSeparator(); fileMenu.add(makeMenuItem("Exit")); // Issue menu bar.add(issueMenu); issueMenu.add(makeMenuItem("New Issue")); issueMenu.add(makeMenuItem("New Issue Expansion")); // Tools menu bar.add(toolsMenu); toolsMenu.add(makeMenuItem("Domain Editor")); toolsMenu.add(makeMenuItem("Chat")); bar.add(Box.createHorizontalGlue()); // let later items move right // Test menu bar.add(testMenu); ideel.addTestMenuItems(); return bar; } protected JMenuItem makeMenuItem(String text) { JMenuItem item = new JMenuItem(text); item.addActionListener(this); return item; } /* * Action interpreter */ public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); Debug.noteln("I-DEEL action:", command); if (command.equals("Exit")) { System.exit(0); } else if (command.equals("Reset")) { ideel.reset(); } else if (command.equals("Load or Edit Domain")) { ensureDomainEditor(); } else if (command.equals("New Issue")) { issueViewer.newIssue(); } else if (command.equals("New Issue Expansion")) { ensureDomainEditor(); } else if (command.equals("Domain Editor")) { ensureDomainEditor(); } else if (command.equals("Chat")) { ensureChat(); } else Debug.noteln("Nothing to do for", command); } /** * Adds a menu item to the "File" menu. */ public void addFileMenuItem(String text, ActionListener listener) { JMenuItem item = new JMenuItem(text); item.addActionListener(listener); // Add it before the separator before "Exit". fileMenu.insert(item, fileMenu.getItemCount() - 2); } /** * Adds a test by adding a menu item to the "Test" menu. */ public void addTest(String text, ActionListener listener) { JMenuItem item = new JMenuItem(text); item.addActionListener(listener); testMenu.add(item); } /** * Adds a test that adds an issue to I-DEEL's issue list. * The menu text will be "Add issue" followed by the issue * text in quotes. */ public void addTestIssue(int priority, String issueText) { String menuText = "Add issue " + Util.quote(issueText); addTestIssue(priority, issueText, menuText); } /** * Adds a test that adds an issue to I-DEEL's issue list. */ public void addTestIssue(final int priority, final String issueText, String menuText) { addTest(menuText, new ActionListener() { public void actionPerformed(ActionEvent e) { issueViewer.addIssue(priority, issueText); } }); } } // Issues: // * Perhaps a more abstract name, such as IdeelUserInterface, instead of // IdeelFrame.