1 19 20 package org.netbeans.modules.j2ee.ddloaders.web; 21 22 import java.awt.Component ; 23 import java.util.List ; 24 import java.util.Iterator ; 25 26 import javax.swing.*; 27 import javax.swing.border.EmptyBorder ; 28 import javax.swing.event.ListSelectionListener ; 29 import javax.swing.event.ListSelectionEvent ; 30 31 import org.openide.util.NbBundle; 32 import org.openide.loaders.DataObject; 33 import org.openide.filesystems.FileStateInvalidException; 34 35 import org.netbeans.modules.j2ee.ddloaders.web.event.DDChangeEvent; 36 37 42 public class DDChangesPanel extends JPanel { 43 44 private JPanel changesPanel; 45 private JScrollPane jScrollPane1; 46 JList changesList; 47 48 DefaultListModel listModel; 49 50 51 public DDChangesPanel (String caption, final JButton processButton) { 52 setLayout (new java.awt.BorderLayout (0, 12)); 53 setBorder (new EmptyBorder (12, 12, 11, 0)); 54 55 JTextArea text = new JTextArea (); 56 text.setEnabled (false); 57 text.setEditable (false); 58 text.setDisabledTextColor (UIManager.getColor ("Label.foreground")); text.setBackground (UIManager.getColor ("Label.background")); text.setLineWrap (true); 61 text.setWrapStyleWord (true); 62 text.setText (caption); 63 add (text, "North"); 65 changesPanel = new JPanel (); 66 changesPanel.setLayout (new java.awt.BorderLayout (5, 5)); 67 68 JLabel changesLabel = new JLabel (); 69 changesLabel.setText (NbBundle.getMessage (DDChangesPanel.class, "LAB_ChangesList")); 70 changesLabel.getAccessibleContext ().setAccessibleDescription (NbBundle.getMessage (DDChangesPanel.class, "ACS_ChangesListA11yDesc")); changesPanel.add (changesLabel, "North"); 73 jScrollPane1 = new JScrollPane (); 74 75 listModel = new DefaultListModel (); 76 77 changesList = new JList (listModel); 78 changesList.setToolTipText (NbBundle.getMessage (DDChangesPanel.class, "HINT_ChangesList")); 79 changesList.setCellRenderer (new ChangesListCellRenderer ()); 80 changesList.addListSelectionListener (new ListSelectionListener () { 81 public void valueChanged (ListSelectionEvent e) { 82 processButton.setEnabled (!changesList.isSelectionEmpty ()); 83 } 84 }); 85 changesLabel.setLabelFor (changesList); 86 changesLabel.setDisplayedMnemonic (NbBundle.getMessage (DDChangesPanel.class, "LAB_ChangesList_Mnemonic").charAt (0)); 87 getAccessibleContext().setAccessibleDescription(NbBundle.getMessage (DDChangesPanel.class, "ACS_ChangesListA11yPanelDesc")); 88 89 jScrollPane1.setViewportView (changesList); 90 91 changesPanel.add (jScrollPane1, "Center"); 93 add (changesPanel, "Center"); } 95 96 public java.awt.Dimension getPreferredSize () { 97 return new java.awt.Dimension (600, 400); 98 } 99 100 synchronized void setChanges (List changes) { 101 listModel.clear (); 102 if (changes != null) { 103 Iterator it = changes.iterator (); 104 while (it.hasNext ()) 105 listModel.addElement (it.next ()); 106 } 107 } 108 109 static class ChangesListCellRenderer extends DefaultListCellRenderer { 110 111 public Component getListCellRendererComponent(JList list, Object value, 112 int index, boolean isSelected, 113 boolean cellHasFocus) { 114 Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 115 try { 116 if ((comp instanceof JLabel) && (value instanceof DDChangeEvent)) { 117 DDChangeEvent evt = (DDChangeEvent)value; 118 String label = ""; String clz = evt.getNewValue (); 120 if (evt.getType () == DDChangeEvent.SERVLET_ADDED) { 121 label = NbBundle.getMessage (DDChangesPanel.class, "LAB_addServletElement", clz); 122 } 123 else if (evt.getType () == DDChangeEvent.SERVLET_CHANGED) { 124 label = NbBundle.getMessage (DDChangesPanel.class, "LAB_changeServletElement", evt.getOldValue (), evt.getNewValue ()); 125 } 126 else if (evt.getType () == DDChangeEvent.SERVLET_DELETED) { 127 label = NbBundle.getMessage (DDChangesPanel.class, "LAB_deleteServletElement", evt.getNewValue ()); 128 } 129 else if (evt.getType () == DDChangeEvent.SERVLET_MOVED) { 130 String fsname; 131 try { 132 fsname = evt.getOldDD ().getPrimaryFile ().getFileSystem ().getDisplayName (); 133 } 134 catch (FileStateInvalidException e) { 135 fsname = ""; } 137 label = NbBundle.getMessage (DDChangesPanel.class, "LAB_moveServletElement", clz, fsname); 138 } 139 else if (evt.getType () == DDChangeEvent.FILTER_CHANGED) { 140 label = NbBundle.getMessage (DDChangesPanel.class, "LAB_changeFilterElement", evt.getOldValue (), evt.getNewValue ()); 141 } 142 else if (evt.getType () == DDChangeEvent.FILTER_DELETED) { 143 label = NbBundle.getMessage (DDChangesPanel.class, "LAB_deleteFilterElement", evt.getNewValue ()); 144 } 145 else if (evt.getType () == DDChangeEvent.LISTENER_CHANGED) { 146 label = NbBundle.getMessage (DDChangesPanel.class, "LAB_changeListenerElement", evt.getOldValue (), evt.getNewValue ()); 147 } 148 else if (evt.getType () == DDChangeEvent.LISTENER_DELETED) { 149 label = NbBundle.getMessage (DDChangesPanel.class, "LAB_deleteListenerElement", evt.getNewValue ()); 150 } 151 else if (evt.getType () == DDChangeEvent.JSP_CHANGED) { 152 label = NbBundle.getMessage (DDChangesPanel.class, "LAB_changeJspElement", evt.getOldValue (), evt.getNewValue ()); 153 } 154 else if (evt.getType () == DDChangeEvent.JSP_DELETED) { 155 label = NbBundle.getMessage (DDChangesPanel.class, "LAB_deleteJspElement", evt.getNewValue ()); 156 } 157 ((JLabel)comp).setText (label); 158 } 159 } 160 catch (Exception e) { 161 e.printStackTrace (); 162 } 163 return comp; 164 } 165 } 166 } 167 | Popular Tags |