KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > rssreader > gui > ProxyDialog


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package org.lucane.applications.rssreader.gui;
21
22 import java.awt.*;
23 import java.awt.event.*;
24
25 import javax.swing.*;
26
27 import org.lucane.applications.rssreader.RssReader;
28 import org.lucane.client.Client;
29
30 public class ProxyDialog extends JDialog
31 implements ActionListener, KeyListener
32 {
33     private JButton btnOk;
34     private JButton btnCancel;
35     private JCheckBox proxy;
36     private JTextField host;
37     private JTextField port;
38     private RssReader plugin;
39     
40     public ProxyDialog(RssReader plugin)
41     {
42         super((JFrame)null, plugin.tr("setupProxy"));
43     
44         this.plugin = plugin;
45         
46         btnOk = new JButton(plugin.tr("btn.apply"), Client.getImageIcon("ok.png"));
47         btnOk.addActionListener(this);
48         btnCancel = new JButton(plugin.tr("btn.cancel"), Client.getImageIcon("cancel.png"));
49         btnCancel.addActionListener(this);
50         
51         proxy = new JCheckBox();
52         host = new JTextField();
53         port = new JTextField();
54         proxy.addKeyListener(this);
55         host.addKeyListener(this);
56         port.addKeyListener(this);
57             
58         initValues();
59         
60         JPanel labels = new JPanel(new GridLayout(3, 1));
61         labels.add(new JLabel(plugin.tr("lbl.useProxy")));
62         labels.add(new JLabel(plugin.tr("lbl.proxyHost")));
63         labels.add(new JLabel(plugin.tr("lbl.proxyPort")));
64
65         JPanel texts = new JPanel(new GridLayout(3, 1));
66         texts.add(proxy);
67         texts.add(host);
68         texts.add(port);
69         
70         JPanel buttons = new JPanel(new GridLayout(1, 2));
71         buttons.add(btnOk);
72         buttons.add(btnCancel);
73
74         JPanel config = new JPanel(new BorderLayout());
75         config.add(labels, BorderLayout.WEST);
76         config.add(texts, BorderLayout.CENTER);
77         
78         JPanel buttonContainer = new JPanel(new BorderLayout());
79         buttonContainer.add(buttons, BorderLayout.EAST);
80         
81         getContentPane().add(config, BorderLayout.CENTER);
82         getContentPane().add(buttonContainer, BorderLayout.SOUTH);
83         pack();
84     }
85
86     private void initValues()
87     {
88         String JavaDoc proxySet = plugin.getLocalConfig().get("proxySet", "false");
89         String JavaDoc proxyHost = plugin.getLocalConfig().get("proxyHost", "");
90         String JavaDoc proxyPort = plugin.getLocalConfig().get("proxyPort", "");
91         
92         this.proxy.setSelected(proxySet.equals("true"));
93         this.host.setText(proxyHost);
94         this.port.setText(proxyPort);
95     }
96     
97     private void setValuesAndApply()
98     {
99         plugin.getLocalConfig().set("proxySet", 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     {
107         if(ae.getSource().equals(btnOk))
108             setValuesAndApply();
109         dispose();
110     }
111
112     public void keyReleased(KeyEvent ke) {}
113     public void keyTyped(KeyEvent ke) {}
114     public void keyPressed(KeyEvent ke)
115     {
116         if(ke.getKeyCode() == KeyEvent.VK_ENTER)
117             actionPerformed(new ActionEvent(btnOk, 0, null));
118         else if(ke.getKeyCode() == KeyEvent.VK_ESCAPE)
119             actionPerformed(new ActionEvent(btnCancel, 0, null));
120     }
121 }
Popular Tags