Changeset 4175 in josm for trunk/src/org/openstreetmap/josm
- Timestamp:
- 2011-06-26T16:56:36+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/WireframeToggleAction.java
r4139 r4175 6 6 import java.awt.event.ActionEvent; 7 7 import java.awt.event.KeyEvent; 8 import java.util.ArrayList; 9 import java.util.List; 10 11 import javax.swing.ButtonModel; 8 12 9 13 import org.openstreetmap.josm.Main; … … 14 18 15 19 public class WireframeToggleAction extends JosmAction { 20 private final List<ButtonModel> buttonModels = new ArrayList<ButtonModel>(); 21 //FIXME: replace with property Action.SELECTED_KEY when migrating to 22 // Java 6 23 private boolean selected; 16 24 public WireframeToggleAction() { 17 25 super( … … 20 28 tr("Enable/disable rendering the map as wireframe only"), 21 29 Shortcut.registerShortcut("menu:view:wireframe", tr("Toggle Wireframe view"),KeyEvent.VK_W, Shortcut.GROUP_MENU), 22 false /* register toolbar*/30 true /* register shortcut */ 23 31 ); 24 putValue("toolbar", "wireframe"); 25 Main.toolbar.register(this); 26 putValue(SELECTED_KEY, MapRendererFactory.getInstance().isWireframeMapRendererActive()); 32 selected = MapRendererFactory.getInstance().isWireframeMapRendererActive(); 33 notifySelectedState(); 27 34 } 28 35 29 public void toggleSelectedState() { 30 boolean selected = (Boolean)getValue(SELECTED_KEY); 36 public void addButtonModel(ButtonModel model) { 37 if (model != null && !buttonModels.contains(model)) { 38 buttonModels.add(model); 39 model.setSelected(selected); 40 } 41 } 31 42 32 if (selected){ 33 MapRendererFactory.getInstance().activate(WireframeMapRenderer.class); 34 } else { 35 MapRendererFactory.getInstance().activate(StyledMapRenderer.class); 43 public void removeButtonModel(ButtonModel model) { 44 if (model != null && buttonModels.contains(model)) { 45 buttonModels.remove(model); 36 46 } 47 } 48 49 protected void notifySelectedState() { 50 for (ButtonModel model: buttonModels) { 51 if (model.isSelected() != selected) { 52 model.setSelected(selected); 53 } 54 } 55 } 56 57 protected void toggleSelectedState() { 58 selected = !selected; 59 //Main.pref.put("draw.wireframe", selected); 60 if (selected){ 61 MapRendererFactory.getInstance().activate(WireframeMapRenderer.class); 62 } else { 63 MapRendererFactory.getInstance().activate(StyledMapRenderer.class); 64 } 65 66 notifySelectedState(); 37 67 if (Main.map != null) { 38 68 Main.map.mapView.repaint(); 39 69 } 40 70 } 41 71 42 72 public void actionPerformed(ActionEvent e) { 43 73 toggleSelectedState(); … … 46 76 @Override 47 77 protected void updateEnabledState() { 48 setEnabled(Main.main.getEditLayer() != null); 78 setEnabled(Main.map != null && Main.main.getEditLayer() != null); 79 } 80 81 public boolean isSelected() { 82 return selected; 49 83 } 50 84 } -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r4139 r4175 277 277 viewMenu.add(wireframe); 278 278 wireframe.setAccelerator(wireFrameToggleAction.getShortcut().getKeyStroke()); 279 wireFrameToggleAction.addButtonModel(wireframe.getModel()); 279 280 280 281 viewMenu.addSeparator(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r4087 r4175 13 13 import java.awt.Rectangle; 14 14 import java.awt.event.ActionEvent; 15 import java.awt.event.ActionListener; 15 16 import java.awt.event.KeyEvent; 16 17 import java.awt.event.MouseEvent; … … 27 28 28 29 import javax.swing.AbstractAction; 30 import javax.swing.DefaultButtonModel; 29 31 import javax.swing.DefaultListSelectionModel; 30 32 import javax.swing.JCheckBox; … … 97 99 JLabel wfLabel = new JLabel(tr("Wireframe View"), ImageProvider.get("dialogs/mappaint", "wireframe_small"), JLabel.HORIZONTAL); 98 100 wfLabel.setFont(wfLabel.getFont().deriveFont(Font.PLAIN)); 99 cbWireframe.setFont(cbWireframe.getFont().deriveFont(Font.PLAIN)); 100 cbWireframe.setAction(Main.main.menu.wireFrameToggleAction); 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 }); 101 117 cbWireframe.setBorder(new EmptyBorder(new Insets(1,1,1,1))); 102 cbWireframe.setText(""); 118 103 119 tblStyles = new StylesTable(model); 104 120 tblStyles.setSelectionModel(selectionModel= new DefaultListSelectionModel()); … … 114 130 tblStyles.setShowGrid(false); 115 131 tblStyles.setIntercellSpacing(new Dimension(0, 0)); 116 cbWireframe.addChangeListener(tblStyles);117 132 118 133 JPanel p = new JPanel(new GridBagLayout()); … … 122 137 123 138 pnl.add(new JScrollPane(p), BorderLayout.CENTER); 139 124 140 pnl.add(buildButtonRow(), BorderLayout.SOUTH); 141 125 142 add(pnl, BorderLayout.CENTER); 126 143 } 127 144 128 protected class StylesTable extends JTable implements ChangeListener{145 protected static class StylesTable extends JTable { 129 146 130 147 public StylesTable(TableModel dm) { … … 140 157 rect.setLocation(rect.x - pt.x, rect.y - pt.y); 141 158 viewport.scrollRectToVisible(rect); 142 }143 144 @Override145 public void stateChanged(ChangeEvent e) {146 setEnabled(!cbWireframe.isSelected());147 159 } 148 160 } … … 158 170 selectionModel.addListSelectionListener(upAction); 159 171 selectionModel.addListSelectionListener(downAction); 160 cbWireframe.addChangeListener(onoffAction);161 cbWireframe.addChangeListener(upAction);162 cbWireframe.addChangeListener(downAction);163 164 172 p.add(new SideButton(onoffAction)); 165 173 p.add(new SideButton(upAction)); … … 172 180 @Override 173 181 public void showNotify() { 174 cbWireframe.setAction(Main.main.menu.wireFrameToggleAction);175 182 MapPaintStyles.addMapPaintSylesUpdateListener(model); 183 Main.main.menu.wireFrameToggleAction.addButtonModel(cbWireframe.getModel()); 176 184 } 177 185 178 186 @Override 179 187 public void hideNotify() { 180 cbWireframe.setAction(null);188 Main.main.menu.wireFrameToggleAction.removeButtonModel(cbWireframe.getModel()); 181 189 MapPaintStyles.removeMapPaintSylesUpdateListener(model); 182 190 } … … 296 304 } 297 305 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 { 306 protected class OnOffAction extends AbstractAction implements ListSelectionListener { 314 307 public OnOffAction() { 315 308 putValue(SHORT_DESCRIPTION, tr("Turn selected styles on or off")); … … 318 311 } 319 312 320 @Override321 313 protected void updateEnabledState() { 322 314 setEnabled(!cbWireframe.isSelected() && tblStyles.getSelectedRowCount() > 0); 315 } 316 317 @Override 318 public void valueChanged(ListSelectionEvent e) { 319 updateEnabledState(); 323 320 } 324 321 … … 337 334 * The action to move down the currently selected entries in the list. 338 335 */ 339 protected class MoveUpDownAction extends EventListeningAction{336 protected class MoveUpDownAction extends AbstractAction implements ListSelectionListener { 340 337 341 338 final int increment; … … 348 345 } 349 346 350 @Override351 347 public void updateEnabledState() { 352 348 int[] sel = tblStyles.getSelectedRows(); … … 364 360 } 365 361 model.ensureSelectedIsVisible(); 362 } 363 364 public void valueChanged(ListSelectionEvent e) { 365 updateEnabledState(); 366 366 } 367 367 }
Note:
See TracChangeset
for help on using the changeset viewer.