001: package net.matuschek.jobo;
002:
003: import java.awt.GridBagConstraints;
004: import java.awt.GridBagLayout;
005: import java.util.Vector;
006:
007: import javax.swing.JButton;
008: import javax.swing.JList;
009: import javax.swing.JOptionPane;
010: import javax.swing.JPanel;
011: import javax.swing.JScrollPane;
012:
013: import net.matuschek.swing.JHideFrame;
014: import net.matuschek.swing.VerticalAlignPanel;
015:
016: /*********************************************
017: Copyright (c) 2001 by Daniel Matuschek
018: *********************************************/
019:
020: /**
021: * Frame to manage lists of AllowedURLs
022: *
023: * @author Daniel Matuschek
024: * @version $Revision: 1.2 $
025: */
026: public class AllowedListFrame extends JHideFrame {
027:
028: private static final long serialVersionUID = -5113419291037861467L;
029:
030: /** a Vector containing the allowed URLs as Strings */
031: private Vector<String> urls = null;
032:
033: /** JList holding all URLs */
034: private JList urlList = null;
035:
036: /**
037: * Initializes the object with the given list of allowed URLs
038: */
039: public AllowedListFrame(Vector<String> urls) {
040: super ();
041: this .urls = urls;
042: initComponents();
043: pack();
044: }
045:
046: /**
047: * This method is called from within the constructor to
048: * initialize the form.
049: */
050: private void initComponents() {
051: this .setTitle("Allowed URLs");
052:
053: JPanel completePanel = new JPanel();
054: completePanel.setLayout(new GridBagLayout());
055:
056: JPanel leftPanel = new JPanel();
057: GridBagConstraints consLeft = new GridBagConstraints();
058: consLeft.gridx = 0;
059: consLeft.gridy = 0;
060: completePanel.add(leftPanel, consLeft);
061:
062: VerticalAlignPanel rightPanel = new VerticalAlignPanel();
063: GridBagConstraints consRight = new GridBagConstraints();
064: consRight.gridx = 1;
065: consRight.gridy = 0;
066: completePanel.add(rightPanel, consRight);
067:
068: //
069: // buttons
070: //
071: JButton buttAdd = new JButton();
072: buttAdd.setText("Add");
073: buttAdd.addActionListener(new java.awt.event.ActionListener() {
074: public void actionPerformed(java.awt.event.ActionEvent evt) {
075: addURL();
076: }
077: });
078: rightPanel.add(buttAdd, 1);
079:
080: JButton buttDelete = new JButton();
081: buttDelete.setText("Delete");
082: buttDelete
083: .addActionListener(new java.awt.event.ActionListener() {
084: public void actionPerformed(
085: java.awt.event.ActionEvent evt) {
086: deleteURL();
087: }
088: });
089: rightPanel.add(buttDelete, 1);
090:
091: JButton buttClose = new JButton();
092: buttClose.setText("Close");
093: buttClose
094: .addActionListener(new java.awt.event.ActionListener() {
095: public void actionPerformed(
096: java.awt.event.ActionEvent evt) {
097: exitForm();
098: }
099: });
100: rightPanel.add(buttClose, 1);
101:
102: // list
103: urlList = new JList();
104: urlList.setVisibleRowCount(6);
105: urlList.setMinimumSize(new java.awt.Dimension(40, 4));
106: urlList.setListData(urls);
107: JScrollPane urlScroll = new JScrollPane();
108: urlScroll.setViewportView(urlList);
109: leftPanel.add(urlScroll);
110:
111: getContentPane().add(completePanel);
112:
113: }
114:
115: protected void deleteURL() {
116: int selected = urlList.getMinSelectionIndex();
117: if (selected < 0) {
118: JOptionPane.showMessageDialog(this , "Please select an URL");
119: } else {
120: String deleteURL = urls.elementAt(selected);
121: int yes = JOptionPane.showConfirmDialog(this ,
122: "Do you really want to delete " + deleteURL + " ?",
123: "Confirm delete", JOptionPane.YES_NO_OPTION);
124: if (yes == 0) {
125: urls.removeElementAt(selected);
126: urlList.clearSelection();
127: }
128:
129: }
130: }
131:
132: protected void addURL() {
133: String newURL = JOptionPane.showInputDialog("Add URL:");
134: urls.add(newURL);
135: urlList.setListData(urls);
136: }
137:
138: }
|