001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.mlm.debug.ui;
028:
029: import java.awt.Color;
030: import java.awt.Component;
031: import java.awt.FlowLayout;
032: import java.awt.event.ActionListener;
033: import java.awt.event.WindowAdapter;
034: import java.awt.event.WindowEvent;
035: import java.awt.event.WindowListener;
036:
037: import javax.swing.JButton;
038: import javax.swing.JFrame;
039: import javax.swing.JPanel;
040: import javax.swing.JScrollPane;
041:
042: /** Create a JFrame to display information requested by the user.
043: Used for all displays generated from the main display.
044: */
045:
046: public class UIFrame extends JFrame {
047: private static int WIDTH = 500;// width and height of initial frame
048: private static int HEIGHT = 300;
049: public static String UPDATE_COMMAND = "Update";
050: public static String SAVE_COMMAND = "Save";
051: public static String EXPAND_COMMAND = "Expand";
052:
053: /** Create a frame with the specified title and containing the
054: specified component, which is either a tree or a bar graph.
055: Optionally creates buttons for updating display (with info from
056: a remote cluster), saving the display (for tree displays only),
057: fully expanding the display (for tree displays only).
058: @param title the string to display at the top of the frame
059: @param component the component to put in the frame
060: @param actionListener object to notify when buttons are pressed
061: @param provideUpdateFunction true to provide update button
062: @param provideSaveFunction true to provide save button
063: @param provideExpandFunction true to provide expand button
064: */
065:
066: public UIFrame(String title, Component component,
067: ActionListener actionListener,
068: boolean provideUpdateFunction, boolean provideSaveFunction,
069: boolean provideExpandFunction) {
070: super (title);
071: setForeground(Color.black);
072: setBackground(Color.lightGray);
073:
074: // cleanup for this display only, for example
075: // remove any listeners that we've set up!!!
076: WindowListener windowListener = new WindowAdapter() {
077: public void windowClosing(WindowEvent e) {
078: e.getWindow().dispose();
079: }
080: };
081:
082: addWindowListener(windowListener);
083: setSize(WIDTH, HEIGHT);
084: JScrollPane scrollPane = new JScrollPane();
085: scrollPane.setViewportView(component);
086: getContentPane().add("Center", scrollPane);
087:
088: // add buttons if needed to provide save function and
089: // update display
090: if (provideSaveFunction || provideUpdateFunction
091: || provideExpandFunction) {
092: JPanel buttonPanel = new JPanel(new FlowLayout(
093: FlowLayout.LEFT));
094: if (provideSaveFunction) {
095: JButton saveButton = new JButton(SAVE_COMMAND);
096: saveButton
097: .setToolTipText("Save displayed information to a file.");
098: saveButton.addActionListener(actionListener);
099: saveButton.setActionCommand(SAVE_COMMAND);
100: buttonPanel.add(saveButton);
101: }
102: if (provideUpdateFunction) {
103: buttonPanel.setBackground(Color.blue); // signifies remote cluster
104: JButton updateButton = new JButton(UPDATE_COMMAND);
105: updateButton
106: .setToolTipText("Retrieve new information from remote cluster.");
107: updateButton.addActionListener(actionListener);
108: updateButton.setActionCommand(UPDATE_COMMAND);
109: buttonPanel.add(updateButton);
110: }
111: if (provideExpandFunction) {
112: JButton expandButton = new JButton(EXPAND_COMMAND);
113: getContentPane().add("North", buttonPanel);
114: expandButton.setToolTipText("Expand information.");
115: expandButton.addActionListener(actionListener);
116: expandButton.setActionCommand(EXPAND_COMMAND);
117: buttonPanel.add(expandButton);
118: }
119: }
120: // create display at the upper left corner of the window
121: setLocation(0, 0);
122: // and display it
123: setVisible(true);
124: }
125:
126: }
|