001: /*
002: * <copyright>
003: *
004: * Copyright 2000-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.tools.csmart.ui.console;
028:
029: import org.cougaar.tools.server.NodeEvent;
030:
031: import javax.swing.*;
032: import javax.swing.border.TitledBorder;
033: import java.awt.*;
034: import java.awt.event.ActionEvent;
035: import java.awt.event.ActionListener;
036:
037: /**
038: * Dialog for selecting what Node output to filter
039: **/
040: public class ConsoleNodeOutputFilter extends JDialog {
041: private static final String ALL = "All";
042: private static final String STANDARDOUT = "Standard Output";
043: private static final String ERRORMSGS = "Standard Error";
044: private static final String NODECREATION = "Node Created";
045: private static final String NODEDESTROYED = "Node Destroyed";
046: private static final String IDLENESS = "Idle";
047: Box box = new Box(BoxLayout.Y_AXIS);
048: private JPanel filterPanel;
049: private JCheckBox allCB;
050: private JCheckBox standardCB;
051: private JCheckBox errorCB;
052: private JCheckBox createCB;
053: private JCheckBox destroyCB;
054: private JCheckBox idlenessCB;
055: boolean[] msgArray = { false, false, false, false, false, false };
056: private boolean allSelected = true;
057:
058: public ConsoleNodeOutputFilter(boolean[] initialValues,
059: boolean acceptAll) {
060: super ((Frame) null, "Filter", true); // modal dialog
061: filterPanel = new JPanel(new BorderLayout());
062:
063: // ok and cancel buttons panel
064: JPanel buttonPanel = new JPanel();
065: JButton okButton = new JButton("OK");
066: // only update the filter if the user selects "OK"
067: okButton.addActionListener(new ActionListener() {
068: public void actionPerformed(ActionEvent e) {
069: allSelected = allCB.isSelected();
070: if (!allSelected) {
071: msgArray[NodeEvent.STANDARD_OUT] = standardCB
072: .isSelected();
073: msgArray[NodeEvent.STANDARD_ERR] = errorCB
074: .isSelected();
075: msgArray[NodeEvent.PROCESS_CREATED] = createCB
076: .isSelected();
077: msgArray[NodeEvent.PROCESS_DESTROYED] = destroyCB
078: .isSelected();
079: msgArray[NodeEvent.IDLE_UPDATE] = idlenessCB
080: .isSelected();
081: }
082: setVisible(false);
083: }
084: });
085: buttonPanel.add(okButton);
086: JButton cancelButton = new JButton("Cancel");
087: cancelButton.addActionListener(new ActionListener() {
088: public void actionPerformed(ActionEvent e) {
089: setVisible(false);
090: }
091: });
092: buttonPanel.add(cancelButton);
093:
094: // Message Types Panel
095: JPanel msgTypesPanel = new JPanel();
096: msgTypesPanel.setLayout(new GridBagLayout());
097: TitledBorder msgTypesTitledBorder = new TitledBorder(
098: "Message Types To Display");
099: Font msgfont = msgTypesTitledBorder.getTitleFont();
100: Font msgtitleFont = msgfont.deriveFont(Font.ITALIC);
101: msgTypesTitledBorder.setTitleFont(msgtitleFont);
102: msgTypesPanel.setBorder(msgTypesTitledBorder);
103:
104: allCB = new JCheckBox(ALL);
105: allCB.setSelected(acceptAll);
106: allCB.addActionListener(allCBSelected);
107: allSelected = acceptAll;
108:
109: standardCB = new JCheckBox(STANDARDOUT);
110: standardCB.addActionListener(unselectAllCB);
111: errorCB = new JCheckBox(ERRORMSGS);
112: errorCB.addActionListener(unselectAllCB);
113: createCB = new JCheckBox(NODECREATION);
114: createCB.addActionListener(unselectAllCB);
115: destroyCB = new JCheckBox(NODEDESTROYED);
116: destroyCB.addActionListener(unselectAllCB);
117: idlenessCB = new JCheckBox(IDLENESS);
118: idlenessCB.addActionListener(unselectAllCB);
119: int x = 0;
120: int y = 0;
121: msgTypesPanel.add(allCB, new GridBagConstraints(x, y++, 1, 1,
122: 0.0, 0.0, GridBagConstraints.WEST,
123: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
124: 0, 0));
125: msgTypesPanel.add(standardCB, new GridBagConstraints(x, y++, 1,
126: 1, 1.0, 0.0, GridBagConstraints.WEST,
127: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
128: 0, 0));
129: msgTypesPanel.add(errorCB, new GridBagConstraints(x, y++, 1, 1,
130: 0.0, 0.0, GridBagConstraints.WEST,
131: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
132: 0, 0));
133: msgTypesPanel.add(createCB, new GridBagConstraints(x, y++, 1,
134: 1, 1.0, 0.0, GridBagConstraints.WEST,
135: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
136: 0, 0));
137: msgTypesPanel.add(destroyCB, new GridBagConstraints(x, y++, 1,
138: 1, 0.0, 0.0, GridBagConstraints.WEST,
139: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
140: 0, 0));
141: msgTypesPanel.add(idlenessCB, new GridBagConstraints(x, y++, 1,
142: 1, 1.0, 0.0, GridBagConstraints.WEST,
143: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
144: 0, 0));
145: box.add(msgTypesPanel);
146:
147: filterPanel.add(buttonPanel, BorderLayout.SOUTH);
148: filterPanel.add(box, BorderLayout.CENTER);
149: getContentPane().add(filterPanel);
150: pack();
151: if (initialValues != null) {
152: msgArray = initialValues;
153: standardCB.setSelected(msgArray[NodeEvent.STANDARD_OUT]);
154: errorCB.setSelected(msgArray[NodeEvent.STANDARD_ERR]);
155: createCB.setSelected(msgArray[NodeEvent.PROCESS_CREATED]);
156: destroyCB
157: .setSelected(msgArray[NodeEvent.PROCESS_DESTROYED]);
158: idlenessCB.setSelected(msgArray[NodeEvent.IDLE_UPDATE]);
159: }
160: setSize(225, 300);
161: // make dialog display over the middle of the screen
162: Dimension screenSize = Toolkit.getDefaultToolkit()
163: .getScreenSize();
164: int w = getWidth();
165: int h = getHeight();
166: setLocation((screenSize.width - w) / 2,
167: (screenSize.height - h) / 2);
168: setVisible(true);
169: }
170:
171: /**
172: * Return whether or not the event should be displayed in the console.
173: */
174: public boolean includeEventInDisplay(NodeEvent event) {
175: if (allSelected)
176: return true;
177: else
178: return msgArray[event.getType()];
179: }
180:
181: /**
182: * Return whether or not the event type should be displayed in the
183: * console. Event types are defined in NodeEvent.
184: */
185: public boolean includeEventTypeInDisplay(int eventType) {
186: if (allSelected)
187: return true;
188: else
189: return msgArray[eventType];
190: }
191:
192: ActionListener allCBSelected = new ActionListener() {
193: public void actionPerformed(ActionEvent e) {
194: if (allCB.isSelected()) {
195: standardCB.setSelected(false);
196: errorCB.setSelected(false);
197: createCB.setSelected(false);
198: destroyCB.setSelected(false);
199: idlenessCB.setSelected(false);
200: }
201: }
202: };
203:
204: ActionListener unselectAllCB = new ActionListener() {
205: public void actionPerformed(ActionEvent e) {
206: if (allCB.isSelected())
207: allCB.setSelected(false);
208: }
209: };
210:
211: public boolean[] getValues() {
212: return msgArray;
213: }
214:
215: public boolean isAllSelected() {
216: return allSelected;
217: }
218: }
|