1 19 package org.openide.explorer.view; 20 21 import org.openide.explorer.ExplorerManager; 22 import org.openide.explorer.view.TableSheet.ControlledTableView; 23 import org.openide.nodes.Node; 24 import org.openide.nodes.Node.Property; 25 import org.openide.util.WeakListeners; 26 27 import java.awt.Dimension ; 28 import java.awt.event.FocusEvent ; 29 import java.awt.event.FocusListener ; 30 31 import java.beans.PropertyChangeEvent ; 32 import java.beans.PropertyChangeListener ; 33 34 import javax.swing.*; 35 import javax.swing.event.ListDataEvent ; 36 import javax.swing.event.ListDataListener ; 37 38 39 47 public @Deprecated class ListTableView extends ListView { 48 49 private boolean tableChanging = false; 50 51 52 private ExplorerManager manager; 53 54 55 private PropertyChangeListener wlpc; 56 57 58 private ControlledTableView controlledTableView; 59 60 61 private Listener listener; 62 63 64 private Dimension prefSize; 65 66 67 private JTable table; 68 69 71 public ListTableView() { 72 this(null); 73 } 74 75 78 public ListTableView(NodeTableModel ntm) { 79 setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); 81 setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 82 83 setViewportView(null); 85 86 JScrollPane listView = new JScrollPane(list); 88 listView.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); 89 listView.setBorder(null); 90 91 controlledTableView = (ntm == null) ? new TableSheet.ControlledTableView(listView) 93 : new TableSheet.ControlledTableView(listView, ntm); 94 setViewportView(controlledTableView.compoundScrollPane()); 95 96 listener = new Listener (); 97 delayedFireTableDataChanged(); 98 99 setPreferredSize(new Dimension (400, 400)); 100 101 table = controlledTableView.getTable(); 102 } 103 104 107 public void setProperties(Property[] props) { 108 controlledTableView.setProperties(props); 109 } 110 111 119 public final void setTableAutoResizeMode(int mode) { 120 controlledTableView.setAutoResizeMode(mode); 121 } 122 123 131 public final int getTableAutoResizeMode() { 132 return controlledTableView.getAutoResizeMode(); 133 } 134 135 139 public final void setTableColumnPreferredWidth(int index, int width) { 140 controlledTableView.setColumnPreferredWidth(index, width); 141 } 142 143 147 public final int getTableColumnPreferredWidth(int index) { 148 return controlledTableView.getColumnPreferredWidth(index); 149 } 150 151 154 public void setListPreferredWidth(int width) { 155 controlledTableView.setControllingViewWidth(width); 156 157 Dimension dim = getPreferredSize(); 158 159 table.setPreferredScrollableViewportSize(new Dimension (dim.width - width, dim.height)); 161 } 162 163 166 public final int getListPreferredWidth() { 167 return controlledTableView.getControllingViewWidth(); 168 } 169 170 public void setPreferredSize(Dimension dim) { 171 super.setPreferredSize(dim); 172 prefSize = dim; 173 } 174 175 public Dimension getPreferredSize() { 176 return prefSize; 177 } 178 179 public void addNotify() { 180 super.addNotify(); 181 182 ExplorerManager newManager = ExplorerManager.find(this); 183 184 if (newManager != manager) { 185 if (manager != null) { 186 manager.removePropertyChangeListener(wlpc); 187 } 188 189 manager = newManager; 190 manager.addPropertyChangeListener(wlpc = org.openide.util.WeakListeners.propertyChange(listener, manager)); 191 controlledTableView.setHeaderText(manager.getExploredContext().getDisplayName()); 192 } 193 194 list.getModel().addListDataListener(listener); 195 list.addFocusListener(listener); 196 delayedFireTableDataChanged(); 197 } 198 199 public void removeNotify() { 200 super.removeNotify(); 201 list.getModel().removeListDataListener(listener); 202 list.removeFocusListener(listener); 203 204 controlledTableView.setNodes(new Node[] { }); 206 } 207 208 209 private void delayedFireTableDataChanged() { 210 if (tableChanging) { 211 return; 212 } 213 214 tableChanging = true; 215 SwingUtilities.invokeLater( 216 new Runnable () { 217 public void run() { 218 if (list.getCellBounds(0, 0) != null) { 219 controlledTableView.setRowHeight(list.getCellBounds(0, 0).height); 220 } 221 222 changeTableModel(); 223 tableChanging = false; 224 } 225 } 226 ); 227 } 228 229 230 private void changeTableModel() { 231 Node[] nodes = new Node[list.getModel().getSize()]; 232 233 for (int i = 0; i < list.getModel().getSize(); i++) { 234 nodes[i] = Visualizer.findNode(list.getModel().getElementAt(i)); 235 } 236 237 controlledTableView.setNodes(nodes); 238 } 239 240 242 private class Listener implements PropertyChangeListener , FocusListener , ListDataListener { 243 Listener() { 244 } 245 246 253 public void intervalAdded(ListDataEvent e) { 254 delayedFireTableDataChanged(); 255 } 256 257 264 public void intervalRemoved(ListDataEvent e) { 265 delayedFireTableDataChanged(); 266 } 267 268 275 public void contentsChanged(ListDataEvent e) { 276 delayedFireTableDataChanged(); 277 } 278 279 public void focusGained(FocusEvent evt) { 280 } 281 282 public void focusLost(FocusEvent evt) { 283 if (evt.isTemporary()) { 284 return; 285 } 286 287 int selectedRow = list.getSelectedIndex(); 288 table.getSelectionModel().setAnchorSelectionIndex(selectedRow); 289 table.getColumnModel().getSelectionModel().setAnchorSelectionIndex(0); 290 } 291 292 295 public void propertyChange(PropertyChangeEvent evt) { 296 if (ExplorerManager.PROP_EXPLORED_CONTEXT.equals(evt.getPropertyName())) { 297 controlledTableView.setHeaderText(manager.getExploredContext().getDisplayName()); 298 } 299 } 300 } 301 302 350 } 351 | Popular Tags |