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) 2001 by Sun Microsystems, Inc.
26  * All rights reserved.
27  */
28 package com.sun.dhcpmgr.client;
29 
30 import java.awt.*;
31 
32 import javax.swing.*;
33 import javax.swing.text.*;
34 import javax.swing.event.*;
35 
36 import com.sun.dhcpmgr.ui.*;
37 
38 /**
39  * This class provides a skeletal implementation of a SUNW data store
40  * module to minimize the effort required to implement a SUNW data store.
41  */
42 public abstract class SUNWModule extends DSModule {
43 
44     /**
45      * The default path for the module.
46      */
47     protected String path;
48 
49     /**
50      * The description for the module.
51      */
52     protected String description;
53 
54     /**
55      * The component for the module.
56      */
57     protected Box box;
58 
59     /**
60      * The text field from which to retrieve the path.
61      */
62     protected JTextField directory;
63 
64     /**
65      * The datastore specific stuff.
66      */
67     protected String additionalInfo = null;
68 
69     // Defined in DSModule.
70     //
getDescription()71     public String getDescription() {
72 	return description;
73     } // getDescription
74 
75     // Defined in DSModule.
76     //
getComponent()77     public Component getComponent() {
78 	return box;
79     } // getComponent
80 
81     // Defined in DSModule.
82     //
getPath()83     public String getPath() {
84 	return directory.getText();
85     } // getPath
86 
87     // Defined in DSModule.
88     //
getAdditionalInfo()89     public String getAdditionalInfo() {
90 	return additionalInfo;
91     } // getAdditionalInfo
92 
93     /**
94      * This class implements a listener for the directory text field and sets
95      * the foward enabled button when the text field is valid (non-empty).
96      */
97     protected class PathListener implements DocumentListener {
98 
99 	/**
100 	 * Empty constructor.
101 	 */
PathListener()102 	public PathListener() {
103 	} // constructor
104 
105 	/**
106 	 * Called when a text update occurs in the text field.
107 	 * @param e the event.
108 	 */
insertUpdate(DocumentEvent e)109 	public void insertUpdate(DocumentEvent e) {
110 	    Document doc = e.getDocument();
111 	    int length = doc.getLength();
112 	    if (length == 0 && getForwardEnabled()) {
113 		setForwardEnabled(false);
114 	    } else if (length != 0 && !getForwardEnabled()) {
115 		setForwardEnabled(true);
116 	    }
117 	} // insertUpdate
118 
119 	/**
120 	 * Called when a text change occurs in the text field.
121 	 * @param e the event.
122 	 */
changedUpdate(DocumentEvent e)123 	public void changedUpdate(DocumentEvent e) {
124 	    insertUpdate(e);
125 	} // changedUpdate
126 
127 	/**
128 	 * Called when a text remove occurs in the text field.
129 	 * @param e the event.
removeUpdate(DocumentEvent e)130 	 */	public void removeUpdate(DocumentEvent e) {
131 	    insertUpdate(e);
132 	} // insertUpdate
133 
134     } // PathListener
135 
136 } // SUNWModule
137