KickJava   Java API By Example, From Geeks To Geeks.

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


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.applications.rssreader.rss.ChannelInfo;
29 import org.lucane.client.Client;
30
31 public class ChannelDialog extends JDialog
32 implements ActionListener, KeyListener
33 {
34     private JButton btnAdd;
35     private JButton btnCancel;
36     private JTextField name;
37     private JTextField url;
38     private MainFrame main;
39     private RssReader plugin;
40     
41     public ChannelDialog(MainFrame main, RssReader plugin)
42     {
43         super((JFrame)null, plugin.tr("addChannel"));
44     
45         this.main = main;
46         this.plugin = plugin;
47         
48         btnAdd = new JButton(plugin.tr("btn.add"), Client.getImageIcon("add.png"));
49         btnAdd.addActionListener(this);
50         btnCancel = new JButton(plugin.tr("btn.cancel"), Client.getImageIcon("cancel.png"));
51         btnCancel.addActionListener(this);
52         name = new JTextField();
53         url = new JTextField();
54         name.addKeyListener(this);
55         url.addKeyListener(this);
56             
57         JPanel labels = new JPanel(new GridLayout(2, 1));
58         labels.add(new JLabel(plugin.tr("lbl.channelName")));
59         labels.add(new JLabel(plugin.tr("lbl.channelUrl")));
60
61         JPanel texts = new JPanel(new GridLayout(2, 1));
62         texts.add(name);
63         texts.add(url);
64         
65         JPanel buttons = new JPanel(new GridLayout(1, 2));
66         buttons.add(btnAdd);
67         buttons.add(btnCancel);
68
69         JPanel channel = new JPanel(new BorderLayout());
70         channel.add(labels, BorderLayout.WEST);
71         channel.add(texts, BorderLayout.CENTER);
72         
73         JPanel buttonContainer = new JPanel(new BorderLayout());
74         buttonContainer.add(buttons, BorderLayout.EAST);
75         
76         getContentPane().add(channel, BorderLayout.CENTER);
77         getContentPane().add(buttonContainer, BorderLayout.SOUTH);
78         setSize(400, 100);
79     }
80
81     public void actionPerformed(ActionEvent ae)
82     {
83         if(ae.getSource().equals(btnAdd))
84         {
85             ChannelInfo ci = new ChannelInfo(name.getText(), url.getText());
86             plugin.addChannel(ci);
87             main.refreshChannelList();
88         }
89         dispose();
90     }
91
92     public void keyReleased(KeyEvent ke) {}
93     public void keyTyped(KeyEvent ke) {}
94     public void keyPressed(KeyEvent ke)
95     {
96         if(ke.getKeyCode() == KeyEvent.VK_ENTER)
97             actionPerformed(new ActionEvent(btnAdd, 0, null));
98         else if(ke.getKeyCode() == KeyEvent.VK_ESCAPE)
99             actionPerformed(new ActionEvent(btnCancel, 0, null));
100     }
101 }
Popular Tags