1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License, Version 1.0 only
   6  * (the "License").  You may not use this file except in compliance
   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * ident        "%Z%%M% %I%     %E% SMI"
  24  *
  25  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  26  * Use is subject to license terms.
  27  */
  28 package com.sun.dhcpmgr.client;
  29 
  30 import javax.swing.*;
  31 import javax.swing.border.*;
  32 import java.awt.event.*;
  33 import java.awt.*;
  34 
  35 import com.sun.dhcpmgr.ui.*;
  36 
  37 /**
  38  * Dialog to select which type of server we want: full DHCP or just a BOOTP
  39  * relay. This is implemented as a singleton modal so the caller can't do
  40  * anything until it returns a selection.
  41  */
  42 public class ConfigureChoiceDialog extends JDialog
  43         implements ButtonPanelListener {
  44     private ButtonPanel buttonPanel;
  45     private ButtonGroup buttonGroup;
  46     private JRadioButton dhcp, bootp;
  47     /**
  48      * Returned if user decides choice is "none of the above"
  49      */
  50     public static final int CANCELLED = 0;
  51     /**
  52      * Return value if user wants DHCP service
  53      */
  54     public static final int DHCP = 1;
  55     /**
  56      * Return value if user wants BOOTP relay
  57      */
  58     public static final int BOOTP = 2;
  59     private static int value = CANCELLED;
  60     
  61     // Must use the showDialog method to get one of these.
  62     private ConfigureChoiceDialog(Frame f) {
  63         super(f, true);
  64         setTitle(ResourceStrings.getString("configure_choice_title"));
  65         setLocationRelativeTo(f);
  66 
  67         getContentPane().setLayout(new BorderLayout());
  68         
  69         JPanel panel = new JPanel(new BorderLayout());
  70         panel.setBorder(
  71             BorderFactory.createCompoundBorder(
  72             BorderFactory.createEtchedBorder(), 
  73             BorderFactory.createEmptyBorder(10, 20, 10, 20)));
  74         
  75         // Explanatory text at the top
  76         panel.add(Wizard.createTextArea(
  77             ResourceStrings.getString("configure_choice_explain"), 5, 30), 
  78             BorderLayout.NORTH);
  79         
  80         // Just show the choices as a set of radio buttons
  81         buttonGroup = new ButtonGroup();
  82         dhcp = new JRadioButton(
  83             ResourceStrings.getString("configure_dhcp_server"), true);
  84         dhcp.setToolTipText(ResourceStrings.getString("configure_dhcp_server"));
  85         buttonGroup.add(dhcp);
  86         Box box = Box.createVerticalBox();
  87         box.add(dhcp);
  88         box.add(Box.createVerticalStrut(5));
  89         bootp = new JRadioButton(
  90             ResourceStrings.getString("configure_bootp_relay"), false);
  91         bootp.setToolTipText(
  92             ResourceStrings.getString("configure_bootp_relay"));
  93         buttonGroup.add(bootp);
  94         box.add(bootp);
  95         panel.add(box, BorderLayout.SOUTH);
  96         getContentPane().add(panel, BorderLayout.NORTH);
  97         
  98         buttonPanel = new ButtonPanel(false);
  99         buttonPanel.addButtonPanelListener(this);
 100         buttonPanel.setOkEnabled(true);
 101         getContentPane().add(buttonPanel, BorderLayout.SOUTH);
 102     }
 103     
 104     public void buttonPressed(int buttonId) {
 105         switch (buttonId) {
 106         case OK:
 107             if (dhcp.isSelected()) {
 108                 value = DHCP;
 109             } else {
 110                 value = BOOTP;
 111             }
 112             setVisible(false);
 113             break;
 114         case CANCEL:
 115             value = CANCELLED;
 116             setVisible(false);
 117             break;
 118         case HELP:
 119             DhcpmgrApplet.showHelp("server_config");
 120             break;
 121         }
 122     }
 123     
 124     public static int showDialog(Frame f) {
 125         ConfigureChoiceDialog d = new ConfigureChoiceDialog(f);
 126         d.pack();
 127         d.setVisible(true);
 128         d.dispose();
 129         return value;
 130     }
 131 }