001: /*
002: * <copyright>
003: *
004: * Copyright 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: package org.cougaar.tools.csmart.ui.console;
027:
028: import javax.swing.*;
029: import java.awt.*;
030: import java.awt.event.ActionEvent;
031: import java.awt.event.ActionListener;
032:
033: /**
034: * org.cougaar.tools.csmart.ui.console
035: *
036: */
037: public class ExitConsole extends JPanel implements ActionListener {
038:
039: public static final String SOCIETY_DETACH = "Detach from Society but leave running (default)";
040: public static final String KILL_NODES = "Stop all Attached Nodes (old behavior)";
041:
042: private String action = SOCIETY_DETACH;
043:
044: public ExitConsole() {
045: }
046:
047: public String getResult() {
048: return this .action;
049: }
050:
051: public boolean reallyExit() {
052: int x = 0;
053: int y = 0;
054: this .setLayout(new GridBagLayout());
055: JLabel instr = new JLabel(
056: "Exit Console: Detach from Nodes (leaving them running), kill the Nodes, or Cancel?\n");
057: JRadioButton detachButton = new JRadioButton(SOCIETY_DETACH);
058: detachButton.setActionCommand(SOCIETY_DETACH);
059: detachButton.setSelected(true);
060: JRadioButton killButton = new JRadioButton(KILL_NODES);
061: killButton.setActionCommand(KILL_NODES);
062: killButton.setSelected(false);
063:
064: ButtonGroup exitButtonGroup = new ButtonGroup();
065: exitButtonGroup.add(detachButton);
066: exitButtonGroup.add(killButton);
067:
068: detachButton.addActionListener(this );
069: killButton.addActionListener(this );
070:
071: add(instr, new GridBagConstraints(x, y++, 1, 1, 0.0, 0.0,
072: GridBagConstraints.WEST, GridBagConstraints.NONE,
073: new Insets(10, 0, 5, 5), 0, 0));
074: add(detachButton, new GridBagConstraints(x, y++, 1, 1, 0.0,
075: 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
076: new Insets(10, 0, 5, 5), 0, 0));
077: add(killButton, new GridBagConstraints(x, y, 1, 1, 0.0, 0.0,
078: GridBagConstraints.WEST, GridBagConstraints.NONE,
079: new Insets(0, 0, 5, 5), 0, 0));
080:
081: int result = JOptionPane.showConfirmDialog(null, this ,
082: "Exit Console", JOptionPane.OK_CANCEL_OPTION,
083: JOptionPane.QUESTION_MESSAGE, null);
084: if (result == JOptionPane.OK_OPTION) {
085: return true;
086: }
087: return false;
088: }
089:
090: public void actionPerformed(ActionEvent e) {
091: if (e.getActionCommand().equals(SOCIETY_DETACH)) {
092: this .action = SOCIETY_DETACH;
093: } else if (e.getActionCommand().equals(KILL_NODES)) {
094: this .action = KILL_NODES;
095: }
096: }
097:
098: public static void main(String[] args) {
099: ExitConsole ec = new ExitConsole();
100: ec.reallyExit();
101: }
102: }
|