1998-09-09 04:52:38 +04:00
|
|
|
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License
|
|
|
|
* Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS"
|
|
|
|
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
|
|
|
* the License for the specific language governing rights and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Grendel mail/news client.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
* Corporation. Portions created by Netscape are Copyright (C) 1997
|
|
|
|
* Netscape Communications Corporation. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Created: Will Scullin <scullin@netscape.com>, 26 Nov 1997.
|
1999-03-07 22:58:40 +03:00
|
|
|
*
|
|
|
|
* Contributors: Jeff Galyan <talisman@anamorphic.com>
|
|
|
|
* Giao Nguyen <grail@cafebabe.org>
|
1998-09-09 04:52:38 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
package grendel.ui;
|
|
|
|
|
|
|
|
import java.awt.Dimension;
|
|
|
|
import java.awt.Frame;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.beans.PropertyChangeEvent;
|
|
|
|
import java.beans.PropertyChangeListener;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.text.MessageFormat;
|
|
|
|
import java.util.Hashtable;
|
|
|
|
import java.util.ResourceBundle;
|
|
|
|
|
1999-02-18 13:11:44 +03:00
|
|
|
import java.io.IOException;
|
|
|
|
|
1998-09-09 04:52:38 +04:00
|
|
|
import javax.mail.URLName;
|
|
|
|
|
1999-01-09 06:55:32 +03:00
|
|
|
import javax.swing.JOptionPane;
|
1999-02-18 13:11:44 +03:00
|
|
|
import javax.swing.JPanel;
|
1998-09-09 04:52:38 +04:00
|
|
|
|
1999-01-09 06:55:32 +03:00
|
|
|
//import netscape.orion.dialogs.AttrNotFoundException;
|
|
|
|
//import netscape.orion.dialogs.PageModel;
|
|
|
|
//import netscape.orion.dialogs.PageUI;
|
1998-09-09 04:52:38 +04:00
|
|
|
|
1999-01-09 06:55:32 +03:00
|
|
|
//import xml.tree.XMLNode;
|
|
|
|
//import xml.tree.TreeBuilder;
|
1998-09-09 04:52:38 +04:00
|
|
|
|
|
|
|
public class EditHostDialog extends GeneralDialog {
|
|
|
|
static final String kIMAPRadioKey="imapRadio";
|
|
|
|
static final String kPOPRadioKey="popRadio";
|
|
|
|
static final String kOtherRadioKey="otherRadio";
|
|
|
|
static final String kOtherFieldKey="otherField";
|
|
|
|
static final String kHostFieldKey="hostField";
|
|
|
|
static final String kUserFieldKey="userField";
|
|
|
|
|
|
|
|
URLName fResult = null;
|
|
|
|
|
|
|
|
Hashtable fValues = null;
|
|
|
|
|
1999-02-19 12:05:00 +03:00
|
|
|
PageUI fPanel;
|
1999-02-18 13:11:44 +03:00
|
|
|
|
|
|
|
EditHostModel model;
|
1998-09-09 04:52:38 +04:00
|
|
|
|
|
|
|
class EditHostModel extends PageModel {
|
|
|
|
public EditHostModel(URLName aURL) {
|
|
|
|
String proto = "imap";
|
|
|
|
String host = "mail";
|
|
|
|
String user = "";
|
|
|
|
|
|
|
|
if (aURL != null) {
|
|
|
|
proto = aURL.getProtocol();
|
|
|
|
host = aURL.getHost();
|
|
|
|
user = aURL.getUsername();
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean other = (!proto.equalsIgnoreCase("imap") &&
|
|
|
|
!proto.equalsIgnoreCase("pop3"));
|
|
|
|
|
|
|
|
fValues = new Hashtable();
|
|
|
|
fValues.put(kIMAPRadioKey, proto.equalsIgnoreCase("imap") ?
|
|
|
|
Boolean.TRUE : Boolean.FALSE);
|
|
|
|
fValues.put(kPOPRadioKey, proto.equalsIgnoreCase("pop3") ?
|
|
|
|
Boolean.TRUE : Boolean.FALSE);
|
|
|
|
fValues.put(kOtherRadioKey, other ? Boolean.TRUE : Boolean.FALSE);
|
|
|
|
fValues.put(kOtherFieldKey, other ? proto : "");
|
|
|
|
fValues.put(kHostFieldKey, host == null ? "" : host);
|
|
|
|
fValues.put(kUserFieldKey, user == null ? "" : user);
|
1999-02-18 13:11:44 +03:00
|
|
|
setStore(fValues);
|
1998-09-09 04:52:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public void actionPerformed(ActionEvent aEvent) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public EditHostDialog(Frame aParent, URLName aURL) {
|
|
|
|
super(aParent);
|
|
|
|
|
|
|
|
setModal(true);
|
1999-02-18 13:11:44 +03:00
|
|
|
model = new EditHostModel(aURL);
|
1998-09-09 04:52:38 +04:00
|
|
|
|
1999-06-21 13:54:08 +04:00
|
|
|
XMLPageBuilder builder = new XMLPageBuilder("id", "editHost", model);
|
1998-09-09 04:52:38 +04:00
|
|
|
URL url = getClass().getResource("dialogs.xml");
|
1999-02-18 13:11:44 +03:00
|
|
|
|
1999-06-21 13:54:08 +04:00
|
|
|
try {
|
|
|
|
fPanel = (PageUI)builder.buildFrom(url.openStream());
|
|
|
|
} catch (Exception e) {
|
|
|
|
return;
|
|
|
|
}
|
1998-09-09 04:52:38 +04:00
|
|
|
|
|
|
|
JOptionPane actionPanel = new JOptionPane(fPanel,
|
|
|
|
JOptionPane.PLAIN_MESSAGE,
|
|
|
|
JOptionPane.OK_CANCEL_OPTION);
|
|
|
|
actionPanel.addPropertyChangeListener(new OptionListener());
|
1999-02-18 13:11:44 +03:00
|
|
|
getContentPane().add(actionPanel);
|
1999-02-25 10:44:11 +03:00
|
|
|
fPanel.initAll();
|
1998-09-09 04:52:38 +04:00
|
|
|
|
|
|
|
// XXX This is a stupid hack because PageUI doesn't to a resource lookup
|
|
|
|
// on it's title. Bleh.
|
1999-02-19 12:05:00 +03:00
|
|
|
String title = fPanel.getTitle();
|
1998-09-09 04:52:38 +04:00
|
|
|
if (title.charAt(0) == '$') {
|
1999-02-18 13:11:44 +03:00
|
|
|
title = (String) model.getAttribute(title.substring(1));
|
1998-09-09 04:52:38 +04:00
|
|
|
}
|
|
|
|
setTitle(title);
|
|
|
|
|
|
|
|
Dimension size = getPreferredSize();
|
|
|
|
Dimension screenSize = getToolkit().getScreenSize();
|
|
|
|
setBounds((screenSize.width - size.width - 10) / 2,
|
|
|
|
(screenSize.height - size.height - 32) / 2,
|
|
|
|
size.width + 10, size.height + 32);
|
|
|
|
pack();
|
|
|
|
setVisible(true);
|
|
|
|
requestFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
public URLName getURLName() {
|
|
|
|
return fResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
class OptionListener implements PropertyChangeListener {
|
|
|
|
public void propertyChange(PropertyChangeEvent aEvent) {
|
|
|
|
if (aEvent.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)){
|
|
|
|
int value = ((Integer) aEvent.getNewValue()).intValue();
|
|
|
|
|
|
|
|
if (value == JOptionPane.OK_OPTION) {
|
|
|
|
// Grab all the values
|
1999-02-19 12:05:00 +03:00
|
|
|
fPanel.saveAll();
|
1998-09-09 04:52:38 +04:00
|
|
|
|
|
|
|
String proto;
|
1999-02-18 13:11:44 +03:00
|
|
|
Boolean imap = (Boolean) model.getAttribute(kIMAPRadioKey);
|
|
|
|
Boolean pop3 = (Boolean) model.getAttribute(kPOPRadioKey);
|
1998-09-09 04:52:38 +04:00
|
|
|
if (imap.booleanValue()) {
|
|
|
|
proto = "imap";
|
|
|
|
} else if (pop3.booleanValue()) {
|
|
|
|
proto = "pop3";
|
|
|
|
} else {
|
1999-02-18 13:11:44 +03:00
|
|
|
proto = (String) model.getAttribute(kOtherFieldKey);
|
1998-09-09 04:52:38 +04:00
|
|
|
}
|
1999-02-18 13:11:44 +03:00
|
|
|
String host = (String) model.getAttribute(kHostFieldKey);
|
|
|
|
String user = (String) model.getAttribute(kUserFieldKey);
|
1998-09-09 04:52:38 +04:00
|
|
|
|
|
|
|
if (user.equals("")) {
|
|
|
|
user = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (proto.length() > 0 &&
|
|
|
|
host.length() > 0) {
|
|
|
|
fResult = new URLName(proto, host, -1, null, user, null);
|
|
|
|
setVisible(false);
|
|
|
|
} else {
|
|
|
|
getToolkit().beep();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
setVisible(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-02-18 13:11:44 +03:00
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
javax.swing.JFrame frame = new javax.swing.JFrame("Foo bar");
|
|
|
|
EditHostDialog d = new EditHostDialog(frame, null);
|
|
|
|
frame.pack();
|
|
|
|
frame.setVisible(true);
|
|
|
|
}
|
1998-09-09 04:52:38 +04:00
|
|
|
}
|