Changeset 20675 in osm for applications/editors/josm/plugins/turnrestrictions/src/org
- Timestamp:
- 2010-03-26T10:40:01+01:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions
- Files:
-
- 1 added
- 7 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/BasicEditorPanel.java
r20666 r20675 11 11 import javax.swing.JScrollPane; 12 12 13 import org.openstreetmap.josm.Main; 13 14 import org.openstreetmap.josm.data.Preferences; 14 15 import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel; … … 31 32 private TurnRestrictionLegEditor toEditor; 32 33 private ViaList lstVias; 34 private JLabel lblVias; 35 private JScrollPane spVias; 33 36 private TurnRestrictionComboBox cbTurnRestrictions; 34 37 private VehicleExceptionEditor vehicleExceptionsEditor; … … 78 81 gc.weightx = 0.0; 79 82 gc.insets = new Insets(0,0,5,5); 80 add( new JLabel("Vias:"), gc);83 add(lblVias = new JLabel("Vias:"), gc); 81 84 82 85 gc.gridx = 1; 83 86 gc.weightx = 1.0; 84 87 DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); 85 add(new JScrollPane(lstVias = new ViaList(new ViaListModel(model, selectionModel), selectionModel)),gc); 88 add(spVias = new JScrollPane(lstVias = new ViaList(new ViaListModel(model, selectionModel), selectionModel)),gc); 89 if (!Main.pref.getBoolean(PreferenceKeys.SHOW_VIAS_IN_BASIC_EDITOR, false)) { 90 lblVias.setVisible(false); 91 spVias.setVisible(false); 92 } 86 93 87 94 // the editor for vehicle exceptions … … 152 159 cbTurnRestrictions.initIconSetFromPreferences(prefs); 153 160 } 161 162 /** 163 * Initializes the visibility of the list of via-objects depending 164 * on values in the JOSM preferences 165 * 166 * @param prefs the JOSM preferences 167 */ 168 public void initViasVisibilityFromPreferences(Preferences prefs){ 169 boolean value = prefs.getBoolean(PreferenceKeys.SHOW_VIAS_IN_BASIC_EDITOR, false); 170 if (value != lblVias.isVisible()){ 171 lblVias.setVisible(value); 172 spVias.setVisible(value); 173 } 174 } 154 175 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/RelationMemberColumnModel.java
r20527 r20675 21 21 col.setHeaderValue(tr("Role")); 22 22 col.setResizable(true); 23 col.setPreferredWidth(100); 23 col.setPreferredWidth(100); 24 col.setCellEditor(new MemberRoleCellEditor()); 24 25 addColumn(col); 25 26 -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/RelationMemberEditorModel.java
r20606 r20675 2 2 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 4 6 import java.text.MessageFormat; 5 6 7 import java.util.ArrayList; 7 8 import java.util.Collection; … … 22 23 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 23 24 import org.openstreetmap.josm.tools.CheckParameterUtil; 24 import static org.openstreetmap.josm.tools.I18n.tr;25 25 26 26 public class RelationMemberEditorModel extends AbstractTableModel{ … … 353 353 } 354 354 355 protected List<Integer> getSelectedIndices() { 356 ArrayList<Integer> ret = new ArrayList<Integer>(); 357 for(int i =0; i < members.size(); i++){ 358 if (rowSelectionModel.isSelectedIndex(i)) 359 ret.add(i); 360 } 361 return ret; 362 } 363 364 public boolean canMoveUp() { 365 List<Integer> sel = getSelectedIndices(); 366 if (sel.isEmpty()) return false; 367 return sel.get(0) > 0; 368 } 369 370 public boolean canMoveDown() { 371 List<Integer> sel = getSelectedIndices(); 372 if (sel.isEmpty()) return false; 373 return sel.get(sel.size()-1) < members.size()-1; 374 } 375 376 public void moveUpSelected() { 377 if (!canMoveUp()) return; 378 List<Integer> sel = getSelectedIndices(); 379 for (int idx: sel){ 380 RelationMemberModel m = members.remove(idx); 381 members.add(idx-1, m); 382 } 383 fireTableDataChanged(); 384 rowSelectionModel.clearSelection(); 385 colSelectionModel.setSelectionInterval(0, 1); 386 for (int idx: sel){ 387 rowSelectionModel.addSelectionInterval(idx-1, idx-1); 388 } 389 } 390 391 public void moveDownSelected() { 392 if (!canMoveDown()) return; 393 List<Integer> sel = getSelectedIndices(); 394 for (int i = sel.size()-1; i>=0;i--){ 395 int idx = sel.get(i); 396 RelationMemberModel m = members.remove(idx); 397 members.add(idx+1, m); 398 } 399 fireTableDataChanged(); 400 rowSelectionModel.clearSelection(); 401 colSelectionModel.setSelectionInterval(0, 1); 402 for (int idx: sel){ 403 rowSelectionModel.addSelectionInterval(idx+1, idx+1); 404 } 405 } 406 355 407 /** 356 408 * Inserts a list of new relation members with the empty role for the primitives -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/RelationMemberTable.java
r20527 r20675 51 51 private DeleteAction actDelete; 52 52 private PasteAction actPaste; 53 private MoveUpAction actMoveUp; 54 private MoveDownAction actMoveDown; 53 55 private TransferHandler transferHandler; 54 56 … … 81 83 // the standard paste action for transfer handling) 82 84 actPaste = new PasteAction(); 85 86 actMoveUp = new MoveUpAction(); 87 model.getRelationMemberEditorModel().getRowSelectionModel().addListSelectionListener(actMoveUp); 88 registerKeyboardAction(actMoveUp,actMoveUp.getKeyStroke(), WHEN_FOCUSED); 89 90 actMoveDown = new MoveDownAction(); 91 model.getRelationMemberEditorModel().getRowSelectionModel().addListSelectionListener(actMoveDown); 92 registerKeyboardAction(actMoveDown, actMoveDown.getKeyStroke(), WHEN_FOCUSED); 83 93 } 84 94 … … 150 160 } 151 161 } 162 163 class MoveDownAction extends AbstractAction implements ListSelectionListener{ 164 private KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.ALT_DOWN_MASK); 165 public MoveDownAction(){ 166 putValue(NAME, tr("Move down")); 167 putValue(SHORT_DESCRIPTION, tr("Move the selected relation members down by one position")); 168 putValue(ACCELERATOR_KEY,keyStroke); 169 putValue(SMALL_ICON, ImageProvider.get("dialogs", "movedown")); 170 updateEnabledState(); 171 } 172 173 public void actionPerformed(ActionEvent e) { 174 model.getRelationMemberEditorModel().moveDownSelected(); 175 } 176 177 public void updateEnabledState(){ 178 setEnabled(model.getRelationMemberEditorModel().canMoveDown()); 179 } 180 181 public void valueChanged(ListSelectionEvent e) { 182 updateEnabledState(); 183 } 184 public KeyStroke getKeyStroke() { 185 return keyStroke; 186 } 187 } 188 189 class MoveUpAction extends AbstractAction implements ListSelectionListener{ 190 private KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_DOWN_MASK); 191 192 public MoveUpAction() { 193 putValue(NAME, tr("Move up")); 194 putValue(SHORT_DESCRIPTION, tr("Move the selected relation members up by one position")); 195 putValue(ACCELERATOR_KEY,keyStroke); 196 putValue(SMALL_ICON, ImageProvider.get("dialogs", "moveup")); 197 updateEnabledState(); 198 } 199 200 public void actionPerformed(ActionEvent e) { 201 model.getRelationMemberEditorModel().moveUpSelected(); 202 } 203 204 public void updateEnabledState(){ 205 setEnabled(model.getRelationMemberEditorModel().canMoveUp()); 206 } 207 208 public void valueChanged(ListSelectionEvent e) { 209 updateEnabledState(); 210 } 211 public KeyStroke getKeyStroke() { 212 return keyStroke; 213 } 214 } 152 215 153 216 class TablePopupLauncher extends PopupMenuLauncher { … … 170 233 addSeparator(); 171 234 add(actDelete); 235 addSeparator(); 236 add(actMoveUp); 237 add(actMoveDown); 172 238 } 173 239 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditor.java
r20666 r20675 866 866 867 867 /** 868 * Listens the changes of the preference {@see PreferenceKeys#ROAD_SIGNS} 869 * and refreshes the set of road icons 868 * Listens to changes of the preference {@see PreferenceKeys#ROAD_SIGNS} 869 * and refreshes the set of road icons. 870 * 871 * Listens to changes of the preference {@see PreferenceKeys#SHOW_VIAS_IN_BASIC_EDITOR} 872 * and toggles the visibility af the list of via-objects in the Basic 873 * Editor. 870 874 * 871 875 */ … … 876 880 877 881 public void preferenceChanged(PreferenceChangeEvent evt) { 878 if (!evt.getKey().equals(PreferenceKeys.ROAD_SIGNS)) return; 879 refreshIconSet(); 882 if (evt.getKey().equals(PreferenceKeys.ROAD_SIGNS)){ 883 refreshIconSet(); 884 } else if (evt.getKey().equals(PreferenceKeys.SHOW_VIAS_IN_BASIC_EDITOR)) { 885 pnlBasicEditor.initViasVisibilityFromPreferences(Main.pref); 886 } 880 887 } 881 888 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/preferences/PreferenceEditor.java
r20666 r20675 32 32 public class PreferenceEditor extends JPanel implements PreferenceSetting{ 33 33 34 private IconPreferencePanel pnlIconPreferences;34 private PreferencesPanel pnlIconPreferences; 35 35 36 36 /** … … 77 77 JPanel pnl = new JPanel(new BorderLayout()); 78 78 79 pnlIconPreferences = new IconPreferencePanel();79 pnlIconPreferences = new PreferencesPanel(); 80 80 pnlIconPreferences.initFromPreferences(Main.pref); 81 81 … … 93 93 tp.add(buildIconPreferencePanel()); 94 94 tp.add(buildCreditPanel()); 95 tp.setTitleAt(0, tr(" Road Signs"));96 tp.setToolTipTextAt(0,tr("Configure the set of road sign icons to be used inthe turnrestrictions plugin"));95 tp.setTitleAt(0, tr("Preferences")); 96 tp.setToolTipTextAt(0,tr("Configure the preferences for the turnrestrictions plugin")); 97 97 tp.setTitleAt(1, tr("Sponsor")); 98 98 add(tp, BorderLayout.CENTER); -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/preferences/PreferenceKeys.java
r20666 r20675 17 17 */ 18 18 String ROAD_SIGNS = "turnrestrictions.road-signs"; 19 20 /** 21 * Indicates whether the Basic Editor should include a widget for for displaying 22 * and editing the via-objects of a turn restriction. 23 * 24 * Supported values are: 25 * <ul> 26 * <li><tt>true</tt> - display the list of vias in the basic editor </li> 27 * <li><tt>false</tt> - don't display the list of vias in the basic editor </li> 28 * </ul> 29 */ 30 String SHOW_VIAS_IN_BASIC_EDITOR = "turnrestrictions.show-vias-in-basic-editor"; 19 31 } -
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/preferences/PreferencesPanel.java
r20666 r20675 12 12 import javax.swing.BorderFactory; 13 13 import javax.swing.ButtonGroup; 14 import javax.swing.JCheckBox; 14 15 import javax.swing.JLabel; 15 16 import javax.swing.JPanel; … … 27 28 * 28 29 */ 29 public class IconPreferencePanel extends VerticallyScrollablePanel {30 private static final Logger logger = Logger.getLogger( IconPreferencePanel.class.getName());30 public class PreferencesPanel extends VerticallyScrollablePanel { 31 private static final Logger logger = Logger.getLogger(PreferencesPanel.class.getName()); 31 32 private JRadioButton rbSetA; 32 33 private JRadioButton rbSetB; 33 34 private ButtonGroup bgIconSet; 34 35 private JCheckBox cbShowViaListInBasicEditor; 36 37 protected JPanel buildShowViaListInBasicEditorPanel() { 38 JPanel pnl = new JPanel(new GridBagLayout()); 39 GridBagConstraints gc = new GridBagConstraints(); 40 gc.anchor = GridBagConstraints.NORTHWEST; 41 gc.fill = GridBagConstraints.HORIZONTAL; 42 gc.weightx = 1.0; 43 gc.gridx = 0; 44 gc.gridy = 0; 45 46 HtmlPanel msg = new HtmlPanel(); 47 msg.setText("<html><body>" 48 + tr("The Basic Editor can optionally display the list of via-objects " 49 + "of a turn restrictions. If enabled, one can also edit them " 50 + "in the Basic editor. If disabled, editing of via-objects is only " 51 + "possible in the Advanced Editor." 52 ) 53 + "</body></html>" 54 ); 55 pnl.add(msg, gc); 56 57 gc.gridy++; 58 pnl.add(cbShowViaListInBasicEditor = new JCheckBox(tr("Display and edit list of via-objects in the Basic Editor")), gc); 59 return pnl; 60 } 61 35 62 /** 36 63 * Builds the panel for the icon set "set-a" … … 125 152 gc.gridy++; 126 153 add(buildSetBPanel(), gc); 154 gc.gridy++; 155 add(buildShowViaListInBasicEditorPanel(), gc); 127 156 128 157 // filler - just grab remaining space … … 157 186 rbSetB.setSelected(true); 158 187 } 188 189 boolean b = prefs.getBoolean(PreferenceKeys.SHOW_VIAS_IN_BASIC_EDITOR, false); 190 cbShowViaListInBasicEditor.setSelected(b); 159 191 } 160 192 … … 175 207 prefs.put(PreferenceKeys.ROAD_SIGNS, set); 176 208 } 177 } 178 179 public IconPreferencePanel() { 209 210 boolean newValue = cbShowViaListInBasicEditor.isSelected(); 211 boolean oldValue = prefs.getBoolean(PreferenceKeys.SHOW_VIAS_IN_BASIC_EDITOR, false); 212 if (newValue != oldValue){ 213 prefs.put(PreferenceKeys.SHOW_VIAS_IN_BASIC_EDITOR, newValue); 214 } 215 } 216 217 public PreferencesPanel() { 180 218 build(); 181 219 }
Note:
See TracChangeset
for help on using the changeset viewer.