001: /*
002: * Lucane - a collaborative platform
003: * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package org.lucane.applications.rssreader.gui;
021:
022: import java.awt.*;
023: import java.awt.event.*;
024:
025: import javax.swing.*;
026:
027: import org.lucane.applications.rssreader.RssReader;
028: import org.lucane.client.Client;
029:
030: public class ProxyDialog extends JDialog implements ActionListener,
031: KeyListener {
032: private JButton btnOk;
033: private JButton btnCancel;
034: private JCheckBox proxy;
035: private JTextField host;
036: private JTextField port;
037: private RssReader plugin;
038:
039: public ProxyDialog(RssReader plugin) {
040: super ((JFrame) null, plugin.tr("setupProxy"));
041:
042: this .plugin = plugin;
043:
044: btnOk = new JButton(plugin.tr("btn.apply"), Client
045: .getImageIcon("ok.png"));
046: btnOk.addActionListener(this );
047: btnCancel = new JButton(plugin.tr("btn.cancel"), Client
048: .getImageIcon("cancel.png"));
049: btnCancel.addActionListener(this );
050:
051: proxy = new JCheckBox();
052: host = new JTextField();
053: port = new JTextField();
054: proxy.addKeyListener(this );
055: host.addKeyListener(this );
056: port.addKeyListener(this );
057:
058: initValues();
059:
060: JPanel labels = new JPanel(new GridLayout(3, 1));
061: labels.add(new JLabel(plugin.tr("lbl.useProxy")));
062: labels.add(new JLabel(plugin.tr("lbl.proxyHost")));
063: labels.add(new JLabel(plugin.tr("lbl.proxyPort")));
064:
065: JPanel texts = new JPanel(new GridLayout(3, 1));
066: texts.add(proxy);
067: texts.add(host);
068: texts.add(port);
069:
070: JPanel buttons = new JPanel(new GridLayout(1, 2));
071: buttons.add(btnOk);
072: buttons.add(btnCancel);
073:
074: JPanel config = new JPanel(new BorderLayout());
075: config.add(labels, BorderLayout.WEST);
076: config.add(texts, BorderLayout.CENTER);
077:
078: JPanel buttonContainer = new JPanel(new BorderLayout());
079: buttonContainer.add(buttons, BorderLayout.EAST);
080:
081: getContentPane().add(config, BorderLayout.CENTER);
082: getContentPane().add(buttonContainer, BorderLayout.SOUTH);
083: pack();
084: }
085:
086: private void initValues() {
087: String proxySet = plugin.getLocalConfig().get("proxySet",
088: "false");
089: String proxyHost = plugin.getLocalConfig().get("proxyHost", "");
090: String proxyPort = plugin.getLocalConfig().get("proxyPort", "");
091:
092: this .proxy.setSelected(proxySet.equals("true"));
093: this .host.setText(proxyHost);
094: this .port.setText(proxyPort);
095: }
096:
097: private void setValuesAndApply() {
098: plugin.getLocalConfig().set("proxySet",
099: String.valueOf(proxy.isSelected()));
100: plugin.getLocalConfig().set("proxyHost", host.getText());
101: plugin.getLocalConfig().set("proxyPort", port.getText());
102: plugin.setProxyFromLocalConfig();
103: }
104:
105: public void actionPerformed(ActionEvent ae) {
106: if (ae.getSource().equals(btnOk))
107: setValuesAndApply();
108: dispose();
109: }
110:
111: public void keyReleased(KeyEvent ke) {
112: }
113:
114: public void keyTyped(KeyEvent ke) {
115: }
116:
117: public void keyPressed(KeyEvent ke) {
118: if (ke.getKeyCode() == KeyEvent.VK_ENTER)
119: actionPerformed(new ActionEvent(btnOk, 0, null));
120: else if (ke.getKeyCode() == KeyEvent.VK_ESCAPE)
121: actionPerformed(new ActionEvent(btnCancel, 0, null));
122: }
123: }
|