Changeset 4087 in josm for trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
- Timestamp:
- 2011-05-15T23:51:25+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r4072 r4087 13 13 import java.awt.Rectangle; 14 14 import java.awt.event.ActionEvent; 15 import java.awt.event.ActionListener;16 15 import java.awt.event.KeyEvent; 17 16 import java.awt.event.MouseEvent; … … 28 27 29 28 import javax.swing.AbstractAction; 30 import javax.swing.DefaultButtonModel;31 29 import javax.swing.DefaultListSelectionModel; 32 30 import javax.swing.JCheckBox; … … 99 97 JLabel wfLabel = new JLabel(tr("Wireframe View"), ImageProvider.get("dialogs/mappaint", "wireframe_small"), JLabel.HORIZONTAL); 100 98 wfLabel.setFont(wfLabel.getFont().deriveFont(Font.PLAIN)); 101 102 cbWireframe.setModel(new DefaultButtonModel() { 103 @Override 104 public void setSelected(boolean b) { 105 super.setSelected(b); 106 tblStyles.setEnabled(!b); 107 onoffAction.updateEnabledState(); 108 upAction.updateEnabledState(); 109 downAction.updateEnabledState(); 110 } 111 }); 112 cbWireframe.addActionListener(new ActionListener() { 113 public void actionPerformed(ActionEvent e) { 114 Main.main.menu.wireFrameToggleAction.actionPerformed(null); 115 } 116 }); 99 cbWireframe.setFont(cbWireframe.getFont().deriveFont(Font.PLAIN)); 100 cbWireframe.setAction(Main.main.menu.wireFrameToggleAction); 117 101 cbWireframe.setBorder(new EmptyBorder(new Insets(1,1,1,1))); 118 102 cbWireframe.setText(""); 119 103 tblStyles = new StylesTable(model); 120 104 tblStyles.setSelectionModel(selectionModel= new DefaultListSelectionModel()); … … 130 114 tblStyles.setShowGrid(false); 131 115 tblStyles.setIntercellSpacing(new Dimension(0, 0)); 116 cbWireframe.addChangeListener(tblStyles); 132 117 133 118 JPanel p = new JPanel(new GridBagLayout()); … … 137 122 138 123 pnl.add(new JScrollPane(p), BorderLayout.CENTER); 139 140 124 pnl.add(buildButtonRow(), BorderLayout.SOUTH); 141 142 125 add(pnl, BorderLayout.CENTER); 143 126 } 144 127 145 protected static class StylesTable extends JTable{128 protected class StylesTable extends JTable implements ChangeListener{ 146 129 147 130 public StylesTable(TableModel dm) { … … 157 140 rect.setLocation(rect.x - pt.x, rect.y - pt.y); 158 141 viewport.scrollRectToVisible(rect); 142 } 143 144 @Override 145 public void stateChanged(ChangeEvent e) { 146 setEnabled(!cbWireframe.isSelected()); 159 147 } 160 148 } … … 170 158 selectionModel.addListSelectionListener(upAction); 171 159 selectionModel.addListSelectionListener(downAction); 160 cbWireframe.addChangeListener(onoffAction); 161 cbWireframe.addChangeListener(upAction); 162 cbWireframe.addChangeListener(downAction); 163 172 164 p.add(new SideButton(onoffAction)); 173 165 p.add(new SideButton(upAction)); … … 180 172 @Override 181 173 public void showNotify() { 174 cbWireframe.setAction(Main.main.menu.wireFrameToggleAction); 182 175 MapPaintStyles.addMapPaintSylesUpdateListener(model); 183 Main.main.menu.wireFrameToggleAction.addButtonModel(cbWireframe.getModel());184 176 } 185 177 186 178 @Override 187 179 public void hideNotify() { 188 Main.main.menu.wireFrameToggleAction.removeButtonModel(cbWireframe.getModel());180 cbWireframe.setAction(null); 189 181 MapPaintStyles.removeMapPaintSylesUpdateListener(model); 190 182 } … … 304 296 } 305 297 306 protected class OnOffAction extends AbstractAction implements ListSelectionListener { 298 protected abstract class EventListeningAction extends AbstractAction implements ListSelectionListener, ChangeListener { 299 300 protected abstract void updateEnabledState(); 301 302 @Override 303 public void valueChanged(ListSelectionEvent e) { 304 updateEnabledState(); 305 } 306 307 @Override 308 public void stateChanged(ChangeEvent e) { 309 updateEnabledState(); 310 } 311 } 312 313 protected class OnOffAction extends EventListeningAction { 307 314 public OnOffAction() { 308 315 putValue(SHORT_DESCRIPTION, tr("Turn selected styles on or off")); … … 311 318 } 312 319 320 @Override 313 321 protected void updateEnabledState() { 314 322 setEnabled(!cbWireframe.isSelected() && tblStyles.getSelectedRowCount() > 0); 315 }316 317 @Override318 public void valueChanged(ListSelectionEvent e) {319 updateEnabledState();320 323 } 321 324 … … 334 337 * The action to move down the currently selected entries in the list. 335 338 */ 336 protected class MoveUpDownAction extends AbstractAction implements ListSelectionListener{339 protected class MoveUpDownAction extends EventListeningAction { 337 340 338 341 final int increment; … … 345 348 } 346 349 350 @Override 347 351 public void updateEnabledState() { 348 352 int[] sel = tblStyles.getSelectedRows(); … … 360 364 } 361 365 model.ensureSelectedIsVisible(); 362 }363 364 public void valueChanged(ListSelectionEvent e) {365 updateEnabledState();366 366 } 367 367 } … … 503 503 error = true; 504 504 } finally { 505 if (bis != null) { 506 try { 507 bis.close(); 508 } catch (IOException e) { 509 e.printStackTrace(); 510 } 511 } 512 if (bos != null) { 513 try { 514 bos.close(); 515 } catch (IOException e) { 516 e.printStackTrace(); 517 } 518 } 505 Utils.close(bis); 506 Utils.close(bos); 519 507 } 520 508 } … … 648 636 txtSource.append("<ERROR: failed to read file!>"); 649 637 } finally { 650 try { 651 is.close(); 652 } catch (IOException ex) { 653 } 638 Utils.close(is); 654 639 } 655 640 }
Note:
See TracChangeset
for help on using the changeset viewer.