1 package SnowMailClient.view.addresses; 2 3 import javax.swing.*; 4 import javax.swing.border.*; 5 import javax.swing.event.*; 6 import java.awt.*; 7 import java.awt.event.*; 8 import java.util.*; 9 10 import SnowMailClient.model.*; 11 import snow.sortabletable.*; 12 import snow.utils.gui.*; 13 14 import SnowMailClient.*; 15 import SnowMailClient.Language.Language; 16 17 18 public class SpamBookView extends JDialog 19 { 20 final private AddressBook addressBook; 21 final private JTable table = new JTable(); 22 final private SortableTableModel sortableTableModel; 23 final private JTextField searchTF = new JTextField("",7); 24 final private JTextField searchTF2 = new JTextField("",7); 25 final private JButton moveToAddressBookButton = new JButton( 26 Language.translate(" Move to Address Book "), Icons.LeftArrow.shared14); 27 28 29 public int fontSize = UIManager.getFont("Label.font").getSize(); 30 31 private static String TITLE = Language.translate("Spam Book"); 32 33 public SpamBookView(AddressBookView ref) 34 { 35 super(ref, TITLE, true); 36 addressBook = SnowMailClientApp.getInstance().getSpamBook(); 37 38 setContentPane(new SnowBackgroundPanel(new BorderLayout())); 39 40 sortableTableModel = new SortableTableModel(addressBook); 41 table.setModel(sortableTableModel); 42 sortableTableModel.installGUI(table); 43 table.setOpaque(false); 44 table.getColumnModel().getColumn(2).setMaxWidth(fontSize*9); 45 table.getColumnModel().getColumn(3).setMaxWidth(fontSize*7); 46 49 50 JPanel northPanel = new JPanel(new BorderLayout()); 53 getContentPane().add(northPanel, BorderLayout.NORTH); 54 JPanel searchPanel = new JPanel(); 55 northPanel.add(searchPanel, BorderLayout.WEST); 56 searchPanel.add(new JLabel(Language.translate("Search")+": ")); 57 searchPanel.add(searchTF); 58 searchPanel.add(new JLabel(" & ")); 59 searchPanel.add(searchTF2); 60 KeyAdapter ska = new KeyAdapter() 61 { 62 @Override public void keyReleased(KeyEvent e) 63 { 64 sortableTableModel.search(searchTF.getText(), searchTF2.getText(), false); 65 updateTitle(); 66 } 67 }; 68 searchTF.addKeyListener(ska); 69 searchTF2.addKeyListener(ska); 70 71 72 JPanel centerPanel = new JPanel(new BorderLayout()); 74 getContentPane().add(centerPanel, BorderLayout.CENTER); 75 76 JScrollPane tableScrollPane = new JScrollPane(table); 77 centerPanel.add(tableScrollPane, BorderLayout.CENTER); 78 79 80 JPanel controlPanel = new JPanel(); 82 controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.X_AXIS)); 83 controlPanel.setBorder(new EmptyBorder(5,5,5,5)); 84 getContentPane().add(controlPanel, BorderLayout.SOUTH); 85 86 final JButton removeBT = new JButton(Language.translate("Remove"), Icons.CrossIcon.shared10); 87 GUIUtils.setSmallDimensions(removeBT); 88 controlPanel.add(removeBT); 89 removeBT.addActionListener(new ActionListener() 90 { 91 public void actionPerformed(ActionEvent e) 92 { 93 int[] sel = table.getSelectedRows(); 94 Vector<Address> addressesToRemove = new Vector<Address>(); 95 for(int i=0; i<sel.length; i++) 96 { 97 int pos = sortableTableModel.getIndexInUnsortedFromTablePos(sel[i]); 98 Address address = addressBook.getAddressAt(pos); 99 addressesToRemove.add(address); 100 } 101 102 int rep = JOptionPane.showConfirmDialog(SpamBookView.this, 103 "Do you want to delete the "+addressesToRemove.size()+" selected addresses ?"); 104 if(rep!=JOptionPane.OK_OPTION) return; 105 106 for(int i=0; i<addressesToRemove.size(); i++) 107 { 108 addressBook.removeAddress( addressesToRemove.elementAt(i) ); 109 } 110 updateTitle(); 111 } 112 }); 113 114 controlPanel.add(moveToAddressBookButton); 115 GUIUtils.setSmallDimensions(moveToAddressBookButton); 116 moveToAddressBookButton.addActionListener(new ActionListener() 117 { 118 public void actionPerformed(ActionEvent e) 119 { 120 int[] sel = table.getSelectedRows(); 121 Vector<Address> addressesToRemove = new Vector<Address>(); 122 for(int i=0; i<sel.length; i++) 123 { 124 int pos = sortableTableModel.getIndexInUnsortedFromTablePos(sel[i]); 125 Address address = addressBook.getAddressAt(pos); 126 addressesToRemove.add(address); 127 } 128 129 for(int i=0; i<addressesToRemove.size(); i++) 130 { 131 Address a = addressesToRemove.elementAt(i); 132 SnowMailClientApp.getInstance().getAddressBook().addAddress(a); 133 addressBook.removeAddress( a ); 134 } 135 updateTitle(); 136 } 137 }); 138 139 final JButton closeBT = new JButton(Language.translate("Close")); 140 GUIUtils.setSmallDimensions(closeBT); 141 controlPanel.add(Box.createHorizontalGlue()); 142 controlPanel.add(closeBT); 143 closeBT.setBackground(Color.orange); 144 closeBT.addActionListener(new ActionListener() 145 { 146 public void actionPerformed(ActionEvent e) 147 { 148 terminateFrame(); 149 setVisible(false); 150 } 151 }); 152 153 table.getSelectionModel().addListSelectionListener(new ListSelectionListener() 154 { 155 public void valueChanged(ListSelectionEvent e) 156 { 157 removeBT.setEnabled(table.getSelectedRowCount()>0); 158 } 159 }); 160 161 162 addWindowListener(new WindowAdapter() 163 { 164 @Override public void windowClosed(WindowEvent e) 165 { 166 terminateFrame(); 167 } 168 @Override public void windowClosing(WindowEvent e) 170 { 171 terminateFrame(); 172 } 173 }); 175 176 SnowMailClientApp.getInstance().getProperties().setComponentSizeFromINIFile(this, 177 "SpamBookEditor", fontSize*48,fontSize*50,200,100); 178 179 updateTitle(); 180 181 setVisible(true); 183 } 184 185 private void updateTitle() 186 { 187 int total = addressBook.getRowCount(); 188 int found = this.sortableTableModel.getRowCount(); 189 if(sortableTableModel.isSearchActive()) 190 { 191 setTitle(TITLE+" ["+total+Language.translate(" addresses")+", "+found 192 +Language.translate(" matching search")+"]"); 193 } 194 else 195 { 196 setTitle(TITLE+" ["+total+Language.translate(" addresses")+"]"); 197 } 198 } 199 200 201 private void terminateFrame() 202 { 203 SnowMailClientApp.getInstance().getProperties().saveComponentSizeInINIFile( 204 this, "SpamBookEditor"); 205 } 206 207 } | Popular Tags |