001: /*
002: * <copyright>
003: *
004: * Copyright 2002-2007 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: package org.cougaar.qos.qrs.gui;
027:
028: import java.awt.Color;
029: import java.awt.Dimension;
030: import java.awt.Point;
031: import java.awt.event.ActionEvent;
032: import java.awt.event.ActionListener;
033: import java.awt.event.WindowAdapter;
034: import java.awt.event.WindowEvent;
035: import javax.swing.BorderFactory;
036: import javax.swing.JButton;
037: import javax.swing.JFrame;
038: import javax.swing.JPanel;
039: import javax.swing.JScrollPane;
040: import javax.swing.UIManager;
041: import javax.swing.JTree;
042: import javax.swing.border.Border;
043:
044: /**
045: * The main window class of the RSS visualization.
046: */
047: public class MainWindow extends JFrame {
048:
049: private static final Border RaisedBorder = BorderFactory
050: .createRaisedBevelBorder();
051:
052: private static final Dimension Size = new Dimension(200, 200);
053: private static final Point Location = new Point(20, 20);
054:
055: private final ResourceContextTreeModel dataTreeModel;
056: private final JTree dataTree;
057:
058: public MainWindow(String title) {
059: super (title);
060: addWindowListener(new CloseListener());
061: setSize(Size);
062: setLocation(Location);
063: setBackground(Color.lightGray);
064: UIManager.put("Label.foreground", Color.black);
065:
066: dataTreeModel = new ResourceContextTreeModel();
067: dataTree = new ResourceContextTree(dataTreeModel);
068: final JScrollPane dataSP = new JScrollPane();
069: dataSP.getViewport().add(dataTree);
070: dataSP.setBorder(RaisedBorder);
071:
072: getContentPane().add("Center", dataSP);
073: getContentPane().add("North", makeButtonBar());
074:
075: setVisible(true);
076:
077: }
078:
079: private JPanel makeButtonBar() {
080: JPanel panel = new JPanel();
081: JButton refresh = new JButton("Refresh");
082: refresh.addActionListener(new ActionListener() {
083: public void actionPerformed(ActionEvent e) {
084: refresh();
085: }
086: });
087: panel.add(refresh);
088: return panel;
089: }
090:
091: private void refresh() {
092: dataTreeModel.update();
093: dataTree.repaint();
094: }
095:
096: private class CloseListener extends WindowAdapter {
097: public void windowClosed(WindowEvent e) {
098: // ?
099: }
100:
101: public void windowClosing(WindowEvent e) {
102: setVisible(false);
103: dispose();
104: }
105: }
106:
107: }
|