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 (c) 1998-2001 by Sun Microsystems, Inc. 26 * All rights reserved. 27 */ 28 package com.sun.dhcpmgr.client; 29 30 import javax.swing.*; 31 import javax.swing.table.*; 32 import javax.swing.border.*; 33 import javax.swing.event.*; 34 35 import java.awt.*; 36 import java.awt.event.*; 37 import java.text.*; 38 import java.util.*; 39 import java.net.*; 40 41 import com.sun.dhcpmgr.server.*; 42 import com.sun.dhcpmgr.data.*; 43 import com.sun.dhcpmgr.ui.*; 44 45 /** 46 * Dialog to configure the server as a BOOTP relay. 47 */ 48 public class ConfigureRelayDialog extends DhcpmgrDialog { 49 private IPAddressList serverList; 50 51 public ConfigureRelayDialog(Frame f) { 52 super(f, false); 53 54 setTitle(ResourceStrings.getString("configure_relay_title")); 55 buttonPanel.setOkEnabled(true); 56 } 57 58 protected JPanel getMainPanel() { 59 JPanel panel = new JPanel(new BorderLayout()); 60 panel.setBorder( 61 BorderFactory.createCompoundBorder( 62 BorderFactory.createEtchedBorder(), 63 BorderFactory.createEmptyBorder(10, 20, 10, 20))); 64 65 // Put some explanatory text at the top. 66 panel.add(Wizard.createTextArea( 67 ResourceStrings.getString("configure_relay_explain"), 3, 30), 68 BorderLayout.NORTH); 69 70 // Control for entering a list of servers 71 serverList = new IPAddressList(); 72 Border tb = BorderFactory.createTitledBorder( 73 BorderFactory.createLineBorder(Color.black), 74 ResourceStrings.getString("dhcp_servers")); 75 serverList.setBorder(BorderFactory.createCompoundBorder(tb, 76 BorderFactory.createEmptyBorder(5, 5, 5, 5))); 77 panel.add(serverList, BorderLayout.SOUTH); 78 79 return panel; 80 } 81 82 protected void doOk() { 83 if (serverList.getListSize() == 0) { 84 // Must enter at least one DHCP server 85 JOptionPane.showMessageDialog(this, 86 ResourceStrings.getString("configure_relay_err_server_list"), 87 ResourceStrings.getString("input_error"), 88 JOptionPane.ERROR_MESSAGE); 89 return; 90 } 91 DhcpdOptions options = new DhcpdOptions(); 92 options.setDaemonEnabled(true); 93 options.setRelay(true, serverList.getAddressListString()); 94 /* 95 * Now write the options to the defaults file, enable the relay, 96 * and start it up. 97 */ 98 try { 99 DataManager.get().getDhcpServiceMgr().writeDefaults(options); 100 DataManager.get().getDhcpServiceMgr().startup(); 101 fireActionPerformed(this, DialogActions.OK); 102 setVisible(false); 103 dispose(); 104 } catch (Throwable e) { 105 e.printStackTrace(); 106 } 107 } 108 109 protected void doCancel() { 110 fireActionPerformed(this, DialogActions.CANCEL); 111 super.doCancel(); 112 } 113 114 protected String getHelpKey() { 115 return "configure_relay"; 116 } 117 118 protected void fireActionPerformed() { 119 // Do nothing; this is here just to satisfy the abstractness in super 120 } 121 }