KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > matuschek > jobo > AllowedListFrame


1 package net.matuschek.jobo;
2
3 import java.awt.GridBagConstraints JavaDoc;
4 import java.awt.GridBagLayout JavaDoc;
5 import java.util.Vector JavaDoc;
6
7 import javax.swing.JButton JavaDoc;
8 import javax.swing.JList JavaDoc;
9 import javax.swing.JOptionPane JavaDoc;
10 import javax.swing.JPanel JavaDoc;
11 import javax.swing.JScrollPane JavaDoc;
12
13 import net.matuschek.swing.JHideFrame;
14 import net.matuschek.swing.VerticalAlignPanel;
15 /*********************************************
16     Copyright (c) 2001 by Daniel Matuschek
17  *********************************************/

18
19
20 /**
21  * Frame to manage lists of AllowedURLs
22  *
23  * @author Daniel Matuschek
24  * @version $Revision: 1.2 $
25  */

26 public class AllowedListFrame extends JHideFrame {
27
28     private static final long serialVersionUID = -5113419291037861467L;
29
30     /** a Vector containing the allowed URLs as Strings */
31     private Vector JavaDoc<String JavaDoc> urls = null;
32
33     /** JList holding all URLs */
34     private JList JavaDoc urlList = null;
35
36
37     /**
38      * Initializes the object with the given list of allowed URLs
39      */

40     public AllowedListFrame(Vector JavaDoc<String JavaDoc> urls) {
41         super();
42         this.urls = urls;
43         initComponents ();
44         pack ();
45     }
46
47
48     /**
49      * This method is called from within the constructor to
50      * initialize the form.
51      */

52     private void initComponents() {
53         this.setTitle("Allowed URLs");
54
55         JPanel JavaDoc completePanel = new JPanel JavaDoc();
56         completePanel.setLayout(new GridBagLayout JavaDoc());
57
58
59         JPanel JavaDoc leftPanel = new JPanel JavaDoc();
60         GridBagConstraints JavaDoc consLeft = new GridBagConstraints JavaDoc();
61         consLeft.gridx = 0;
62         consLeft.gridy = 0;
63         completePanel.add(leftPanel, consLeft);
64
65
66         VerticalAlignPanel rightPanel = new VerticalAlignPanel();
67         GridBagConstraints JavaDoc consRight = new GridBagConstraints JavaDoc();
68         consRight.gridx = 1;
69         consRight.gridy = 0;
70         completePanel.add(rightPanel, consRight);
71
72
73         //
74
// buttons
75
//
76
JButton JavaDoc buttAdd = new JButton JavaDoc();
77         buttAdd.setText("Add");
78         buttAdd.addActionListener(new java.awt.event.ActionListener JavaDoc() {
79             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
80                 addURL();
81             }
82         });
83         rightPanel.add(buttAdd,1);
84
85         JButton JavaDoc buttDelete = new JButton JavaDoc();
86         buttDelete.setText("Delete");
87         buttDelete.addActionListener(new java.awt.event.ActionListener JavaDoc() {
88             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
89                 deleteURL();
90             }
91         });
92         rightPanel.add(buttDelete,1);
93
94         JButton JavaDoc buttClose = new JButton JavaDoc();
95         buttClose.setText("Close");
96         buttClose.addActionListener(new java.awt.event.ActionListener JavaDoc() {
97             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
98                 exitForm();
99             }
100         });
101         rightPanel.add(buttClose,1);
102
103         // list
104
urlList = new JList JavaDoc();
105         urlList.setVisibleRowCount(6);
106         urlList.setMinimumSize(new java.awt.Dimension JavaDoc(40,4));
107         urlList.setListData(urls);
108         JScrollPane JavaDoc urlScroll = new JScrollPane JavaDoc();
109         urlScroll.setViewportView(urlList);
110         leftPanel.add(urlScroll);
111
112
113         getContentPane().add(completePanel);
114
115     }
116
117     protected void deleteURL() {
118         int selected = urlList.getMinSelectionIndex();
119         if (selected < 0) {
120             JOptionPane.showMessageDialog(this,
121                     "Please select an URL");
122         } else {
123             String JavaDoc deleteURL = urls.elementAt(selected);
124             int yes =
125                 JOptionPane.showConfirmDialog(this,
126                         "Do you really want to delete "
127                         +deleteURL+" ?",
128                         "Confirm delete",
129                         JOptionPane.YES_NO_OPTION);
130             if (yes == 0) {
131                 urls.removeElementAt(selected);
132                 urlList.clearSelection();
133             }
134
135         }
136     }
137
138
139     protected void addURL() {
140         String JavaDoc newURL = JOptionPane.showInputDialog("Add URL:");
141         urls.add(newURL);
142         urlList.setListData(urls);
143     }
144
145
146 }
147
Popular Tags