01: /*
02: * <copyright>
03: *
04: * Copyright 2000-2004 BBNT Solutions, LLC
05: * under sponsorship of the Defense Advanced Research Projects
06: * Agency (DARPA).
07: *
08: * You can redistribute this software and/or modify it under the
09: * terms of the Cougaar Open Source License as published on the
10: * Cougaar Open Source Website (www.cougaar.org).
11: *
12: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
15: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
16: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
17: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23: *
24: * </copyright>
25: */
26:
27: package org.cougaar.tools.csmart.ui.console;
28:
29: import javax.swing.*;
30: import javax.swing.border.TitledBorder;
31: import java.awt.*;
32: import java.awt.event.ActionEvent;
33: import java.awt.event.ActionListener;
34:
35: public class Legend extends JDialog {
36: Box box = new Box(BoxLayout.Y_AXIS);
37: JPanel colorPanel;
38:
39: int x = 0;
40: int y = 0;
41:
42: public Legend() {
43: JPanel legendPanel = new JPanel(new BorderLayout());
44:
45: JPanel buttonPanel = new JPanel();
46: JButton okButton = new JButton("OK");
47: okButton.addActionListener(new ActionListener() {
48: public void actionPerformed(ActionEvent e) {
49: setVisible(false);
50: }
51: });
52: buttonPanel.add(okButton);
53:
54: colorPanel = new JPanel();
55: colorPanel.setLayout(new GridBagLayout());
56: TitledBorder colorPanelTitledBorder = new TitledBorder(
57: "Status Legend");
58: colorPanel.setBorder(colorPanelTitledBorder);
59: String[] descriptions = NodeStatusButton
60: .getStatusDescriptions();
61: Color[] colors = NodeStatusButton.getStatusColors();
62: for (int i = 0; i < descriptions.length; i++)
63: makeLegend(descriptions[i], colors[i]);
64: box.add(colorPanel);
65:
66: legendPanel.add(buttonPanel, BorderLayout.SOUTH);
67: legendPanel.add(box, BorderLayout.CENTER);
68: getContentPane().add(legendPanel);
69: pack();
70: }
71:
72: public static void main(String[] args) {
73: Legend legend = new Legend();
74: legend.setVisible(true);
75: }
76:
77: private void makeLegend(String s, Color color) {
78: JButton newButton = new JButton(s);
79: newButton.setBackground(color);
80: colorPanel.add(newButton, new GridBagConstraints(x, y++, 1, 1,
81: 0.0, 0.0, GridBagConstraints.CENTER,
82: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
83: 0, 0));
84: }
85: }
|