1 package net.matuschek.jobo; 2 3 import java.awt.GridBagConstraints ; 4 import java.awt.GridBagLayout ; 5 import java.util.Vector ; 6 7 import javax.swing.JButton ; 8 import javax.swing.JList ; 9 import javax.swing.JOptionPane ; 10 import javax.swing.JPanel ; 11 import javax.swing.JScrollPane ; 12 13 import net.matuschek.swing.JHideFrame; 14 import net.matuschek.swing.VerticalAlignPanel; 15 18 19 20 26 public class AllowedListFrame extends JHideFrame { 27 28 private static final long serialVersionUID = -5113419291037861467L; 29 30 31 private Vector <String > urls = null; 32 33 34 private JList urlList = null; 35 36 37 40 public AllowedListFrame(Vector <String > urls) { 41 super(); 42 this.urls = urls; 43 initComponents (); 44 pack (); 45 } 46 47 48 52 private void initComponents() { 53 this.setTitle("Allowed URLs"); 54 55 JPanel completePanel = new JPanel (); 56 completePanel.setLayout(new GridBagLayout ()); 57 58 59 JPanel leftPanel = new JPanel (); 60 GridBagConstraints consLeft = new GridBagConstraints (); 61 consLeft.gridx = 0; 62 consLeft.gridy = 0; 63 completePanel.add(leftPanel, consLeft); 64 65 66 VerticalAlignPanel rightPanel = new VerticalAlignPanel(); 67 GridBagConstraints consRight = new GridBagConstraints (); 68 consRight.gridx = 1; 69 consRight.gridy = 0; 70 completePanel.add(rightPanel, consRight); 71 72 73 JButton buttAdd = new JButton (); 77 buttAdd.setText("Add"); 78 buttAdd.addActionListener(new java.awt.event.ActionListener () { 79 public void actionPerformed(java.awt.event.ActionEvent evt) { 80 addURL(); 81 } 82 }); 83 rightPanel.add(buttAdd,1); 84 85 JButton buttDelete = new JButton (); 86 buttDelete.setText("Delete"); 87 buttDelete.addActionListener(new java.awt.event.ActionListener () { 88 public void actionPerformed(java.awt.event.ActionEvent evt) { 89 deleteURL(); 90 } 91 }); 92 rightPanel.add(buttDelete,1); 93 94 JButton buttClose = new JButton (); 95 buttClose.setText("Close"); 96 buttClose.addActionListener(new java.awt.event.ActionListener () { 97 public void actionPerformed(java.awt.event.ActionEvent evt) { 98 exitForm(); 99 } 100 }); 101 rightPanel.add(buttClose,1); 102 103 urlList = new JList (); 105 urlList.setVisibleRowCount(6); 106 urlList.setMinimumSize(new java.awt.Dimension (40,4)); 107 urlList.setListData(urls); 108 JScrollPane urlScroll = new JScrollPane (); 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 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 newURL = JOptionPane.showInputDialog("Add URL:"); 141 urls.add(newURL); 142 urlList.setListData(urls); 143 } 144 145 146 } 147 | Popular Tags |