import java.awt.*;
import java.awt.event.*;
import java.util.Properties;
public class NSIInitialContextFrame extends Frame
implements WindowListener,
ActionListener
{
public static final int width = 350;
public static final int height = 75;
TextField initCtxField;
Button okButton = new Button ("Apply");
Button cancelButton = new Button ("Cancel");
String jndiInitCtxProp = "java.naming.factory.initial";
NSIBrowserFrame parent;
public NSIInitialContextFrame
(
NSIBrowserFrame parent
)
{
super ("Initial Context Implementation");
this.parent = parent;
NSIForm f = new NSIForm (this);
initCtxField = f.addRow ("Class name:");
String initPropVal = System.getProperty (jndiInitCtxProp);
if (null != initPropVal)
initCtxField.setText (initPropVal);
Panel p = new Panel ();
p.setLayout (new GridLayout (1, 0));
p.add (okButton);
p.add (cancelButton);
f.addRow (p);
addWindowListener (this);
okButton.addActionListener (this);
cancelButton.addActionListener (this);
}
public void actionPerformed (
ActionEvent evt)
{
Object target = evt.getSource();
if (target == okButton)
{
String classname = initCtxField.getText ();
Properties props = System.getProperties ();
if (classname == null || (true == classname.equals ("")))
{
props.remove (jndiInitCtxProp);
}
else
{
props.put (jndiInitCtxProp, classname);
System.setProperties (props);
}
parent.resetInitCtx ();
dispose();
}
else if (target == cancelButton)
{
dispose();
}
}
public void windowClosed (
WindowEvent event)
{
}
public void windowDeiconified (
WindowEvent event)
{
}
public void windowIconified (
WindowEvent event)
{
}
public void windowActivated (
WindowEvent event)
{
}
public void windowDeactivated (
WindowEvent event)
{
}
public void windowOpened (
WindowEvent event)
{
}
public void windowClosing (
WindowEvent event)
{
dispose ();
}
}