Changeset 3855 in josm
- Timestamp:
- 2011-02-05T10:40:39+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r3843 r3855 335 335 jb.add(toolBarActions); 336 336 337 jb.addSeparator(new Dimension(0,1 0));337 jb.addSeparator(new Dimension(0,18)); 338 338 toolBarToggle.setAlignmentX(0.5f); 339 339 jb.add(toolBarToggle); -
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r3848 r3855 7 7 import java.awt.Dimension; 8 8 import java.awt.Point; 9 import java.awt.Rectangle; 9 10 import java.awt.event.ActionEvent; 10 11 import java.awt.event.KeyEvent; 11 12 import java.awt.event.MouseEvent; 12 import java.util.ArrayList;13 import java.util.Collection;14 import java.util.List;15 13 16 14 import javax.swing.AbstractAction; … … 20 18 import javax.swing.JScrollPane; 21 19 import javax.swing.JTable; 20 import javax.swing.JViewport; 22 21 import javax.swing.ListSelectionModel; 23 22 import javax.swing.SwingUtilities; … … 26 25 import javax.swing.event.ListSelectionListener; 27 26 import javax.swing.table.AbstractTableModel; 27 import javax.swing.table.TableModel; 28 28 29 29 import org.openstreetmap.josm.Main; 30 30 import org.openstreetmap.josm.gui.SideButton; 31 31 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 32 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintS tyleLoader;32 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener; 33 33 import org.openstreetmap.josm.gui.mappaint.StyleSource; 34 import org.openstreetmap.josm.gui.preferences.PreferenceDialog; 34 35 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 35 36 import org.openstreetmap.josm.tools.ImageProvider; … … 38 39 public class MapPaintDialog extends ToggleDialog { 39 40 40 protected JTable tblStyles;41 protected StylesTable tblStyles; 41 42 protected StylesModel model; 42 43 protected DefaultListSelectionModel selectionModel; … … 47 48 public MapPaintDialog() { 48 49 super(tr("Map Paint Styles"), "mapstyle", tr("configure the map painting style"), 49 Shortcut.registerShortcut("subwindow:authors", tr("Toggle: {0}", tr("Authors")), KeyEvent.VK_M, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 250);50 Shortcut.registerShortcut("subwindow:authors", tr("Toggle: {0}", tr("Authors")), KeyEvent.VK_M, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150); 50 51 build(); 51 52 } … … 56 57 57 58 model = new StylesModel(); 58 model.setStyles(MapPaintStyles.getStyles().getStyleSources());59 59 60 tblStyles = new JTable(model);60 tblStyles = new StylesTable(model); 61 61 tblStyles.setSelectionModel(selectionModel= new DefaultListSelectionModel()); 62 62 tblStyles.addMouseListener(new PopupMenuHandler()); … … 77 77 } 78 78 79 protected static class StylesTable extends JTable { 80 81 public StylesTable(TableModel dm) { 82 super(dm); 83 } 84 85 public void scrollToVisible(int row, int col) { 86 if (!(getParent() instanceof JViewport)) 87 return; 88 JViewport viewport = (JViewport) getParent(); 89 Rectangle rect = getCellRect(row, col, true); 90 Point pt = viewport.getViewPosition(); 91 rect.setLocation(rect.x - pt.x, rect.y - pt.y); 92 viewport.scrollRectToVisible(rect); 93 } 94 } 95 79 96 protected JPanel buildButtonRow() { 80 JPanel p = getButtonPanel( 1);97 JPanel p = getButtonPanel(4); 81 98 reloadAction = new ReloadAction(); 82 99 onoffAction = new OnOffAction(); 100 MoveUpDownAction up = new MoveUpDownAction(false); 101 MoveUpDownAction down = new MoveUpDownAction(true); 83 102 selectionModel.addListSelectionListener(onoffAction); 84 103 selectionModel.addListSelectionListener(reloadAction); 104 selectionModel.addListSelectionListener(up); 105 selectionModel.addListSelectionListener(down); 85 106 p.add(new SideButton(onoffAction)); 107 p.add(new SideButton(up)); 108 p.add(new SideButton(down)); 109 p.add(new SideButton(new LaunchMapPaintPreferencesAction())); 110 86 111 return p; 87 112 } 88 89 protected class StylesModel extends AbstractTableModel { 90 List<StyleSource> data; 91 92 public StylesModel() { 93 this.data = new ArrayList<StyleSource>(); 113 114 @Override 115 public void showNotify() { 116 MapPaintStyles.addMapPaintSylesUpdateListener(model); 117 } 118 119 @Override 120 public void hideNotify() { 121 MapPaintStyles.removeMapPaintSylesUpdateListener(model); 122 } 123 124 protected class StylesModel extends AbstractTableModel implements MapPaintSylesUpdateListener { 125 126 private StyleSource getRow(int i) { 127 return MapPaintStyles.getStyles().getStyleSources().get(i); 94 128 } 95 129 … … 101 135 @Override 102 136 public int getRowCount() { 103 return data.size();137 return MapPaintStyles.getStyles().getStyleSources().size(); 104 138 } 105 139 … … 107 141 public Object getValueAt(int row, int column) { 108 142 if (column == 0) 109 return data.get(row).active;143 return getRow(row).active; 110 144 else 111 return data.get(row).getDisplayString();145 return getRow(row).getDisplayString(); 112 146 } 113 147 … … 129 163 return; 130 164 if (column == 0) { 131 toggleOnOff(row); 132 } 133 } 134 135 public void setStyles(Collection<? extends StyleSource> styles) { 136 data.clear(); 137 if (styles !=null) { 138 data.addAll(styles); 139 } 165 MapPaintStyles.toggleStyleActive(row); 166 } 167 } 168 169 /** 170 * Make sure the first of the selected entry is visible in the 171 * views of this model. 172 */ 173 protected void ensureSelectedIsVisible() { 174 int index = selectionModel.getMinSelectionIndex(); 175 if (index < 0) return; 176 if (index >= getRowCount()) return; 177 tblStyles.scrollToVisible(index, 0); 178 tblStyles.repaint(); 179 } 180 181 /** 182 * MapPaintSylesUpdateListener interface 183 */ 184 185 @Override 186 public void mapPaintStylesUpdated() { 140 187 fireTableDataChanged(); 141 } 142 143 public void toggleOnOff(int... rows) { 144 for (Integer p : rows) { 145 StyleSource s = model.data.get(p); 146 s.active = !s.active; 147 } 148 if (rows.length == 1) { 149 model.fireTableCellUpdated(rows[0], 0); 150 } else { 151 model.fireTableDataChanged(); 152 } 153 MapPaintStyles.getStyles().clearCached(); 154 Main.map.mapView.preferenceChanged(null); 155 Main.map.mapView.repaint(); 188 tblStyles.repaint(); 189 } 190 191 @Override 192 public void mapPaintStyleEntryUpdated(int idx) { 193 fireTableRowsUpdated(idx, idx); 194 tblStyles.repaint(); 156 195 } 157 196 } … … 176 215 public void actionPerformed(ActionEvent e) { 177 216 int[] pos = tblStyles.getSelectedRows(); 178 model.toggleOnOff(pos); 217 MapPaintStyles.toggleStyleActive(pos); 218 selectionModel.clearSelection(); 219 for (int p: pos) { 220 selectionModel.addSelectionInterval(p, p); 221 } 222 } 223 } 224 225 /** 226 * The action to move down the currently selected entries in the list. 227 */ 228 class MoveUpDownAction extends AbstractAction implements ListSelectionListener { 229 final int increment; 230 public MoveUpDownAction(boolean isDown) { 231 increment = isDown ? 1 : -1; 232 putValue(SMALL_ICON, isDown ? ImageProvider.get("dialogs", "down") : ImageProvider.get("dialogs", "up")); 233 putValue(SHORT_DESCRIPTION, isDown ? tr("Move the selected entry one row down.") : tr("Move the selected entry one row up.")); 234 updateEnabledState(); 235 } 236 237 public void updateEnabledState() { 238 int[] sel = tblStyles.getSelectedRows(); 239 setEnabled(MapPaintStyles.canMoveStyles(sel, increment)); 240 } 241 242 @Override 243 public void actionPerformed(ActionEvent e) { 244 int[] sel = tblStyles.getSelectedRows(); 245 MapPaintStyles.moveStyles(sel, increment); 246 247 selectionModel.clearSelection(); 248 for (int row: sel) { 249 selectionModel.addSelectionInterval(row + increment, row + increment); 250 } 251 model.ensureSelectedIsVisible(); 252 } 253 254 public void valueChanged(ListSelectionEvent e) { 255 updateEnabledState(); 256 } 257 } 258 259 /** 260 * Opens preferences window and selects the mappaint tab. 261 */ 262 class LaunchMapPaintPreferencesAction extends AbstractAction { 263 public LaunchMapPaintPreferencesAction() { 264 putValue(SMALL_ICON, ImageProvider.get("dialogs", "mappaintpreference")); 265 } 266 267 @Override 268 public void actionPerformed(ActionEvent e) { 269 final PreferenceDialog p =new PreferenceDialog(Main.parent); 270 p.selectMapPaintPreferenceTab(); 271 p.setVisible(true); 179 272 } 180 273 } … … 192 285 boolean e = pos.length > 0; 193 286 for (int i : pos) { 194 if (!model. data.get(i).isLocal()) {287 if (!model.getRow(i).isLocal()) { 195 288 e = false; 196 289 break; … … 207 300 @Override 208 301 public void actionPerformed(ActionEvent e) { 209 210 302 final int[] rows = tblStyles.getSelectedRows(); 211 List<StyleSource> sources = new ArrayList<StyleSource>(); 212 for (int p : rows) { 213 sources.add(model.data.get(p)); 214 } 215 Main.worker.submit(new MapPaintStyleLoader(sources)); 303 MapPaintStyles.reloadStyles(rows); 216 304 Main.worker.submit(new Runnable() { 217 305 @Override … … 220 308 @Override 221 309 public void run() { 222 if (rows.length == 1) { 223 model.fireTableCellUpdated(rows[0], 1); 224 } else { 225 model.fireTableDataChanged(); 310 selectionModel.clearSelection(); 311 for (int r: rows) { 312 selectionModel.addSelectionInterval(r, r); 226 313 } 227 MapPaintStyles.getStyles().clearCached();228 Main.map.mapView.preferenceChanged(null);229 Main.map.mapView.repaint();230 314 } 231 315 }); 316 232 317 } 233 318 }); -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r3854 r3855 35 35 } 36 36 37 public void add(StyleSource style) { 38 styleSources.add(style); 39 } 40 41 public Collection<StyleSource> getStyleSources() { 42 return Collections.<StyleSource>unmodifiableCollection(styleSources); 37 public List<StyleSource> getStyleSources() { 38 return Collections.<StyleSource>unmodifiableList(styleSources); 43 39 } 44 40 … … 241 237 this.drawMultipolygon = drawMultipolygon; 242 238 } 239 240 /** 241 * remove all style sources; only accessed from MapPaintStyles 242 */ 243 void clear() { 244 styleSources.clear(); 245 } 246 247 /** 248 * add a style source; only accessed from MapPaintStyles 249 */ 250 void add(StyleSource style) { 251 styleSources.add(style); 252 } 253 254 /** 255 * set the style sources; only accessed from MapPaintStyles 256 */ 257 void setStyleSources(Collection<StyleSource> sources) { 258 styleSources.clear(); 259 styleSources.addAll(sources); 260 } 261 243 262 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r3853 r3855 6 6 import java.io.IOException; 7 7 import java.io.InputStream; 8 import java.util.ArrayList; 9 import java.util.Arrays; 8 10 import java.util.Collection; 9 11 import java.util.Collections; 10 12 import java.util.LinkedList; 11 13 import java.util.List; 14 import java.util.concurrent.CopyOnWriteArrayList; 12 15 13 16 import javax.swing.ImageIcon; 17 import javax.swing.SwingUtilities; 14 18 15 19 import org.openstreetmap.josm.Main; … … 23 27 import org.openstreetmap.josm.tools.ImageProvider; 24 28 29 /** 30 * This class manages the ElemStyles instance. The object you get with 31 * getStyles() is read only, any manipulation happens via one of 32 * the wrapper methods here. (readFromPreferences, moveStyles, ...) 33 * 34 * On change, mapPaintSylesUpdated() is fired for all listeners. 35 */ 25 36 public class MapPaintStyles { 26 37 … … 71 82 } 72 83 73 @SuppressWarnings("null")74 84 public static void readFromPreferences() { 85 styles.clear(); 75 86 iconDirs = Main.pref.getCollection("mappaint.icon.sources", Collections.<String>emptySet()); 76 87 if(Main.pref.getBoolean("mappaint.icon.enable-defaults", true)) … … 83 94 } 84 95 85 Collection<? extends SourceEntry> sourceEntries = (new MapPaintPrefMigration()).get();96 Collection<? extends SourceEntry> sourceEntries = MapPaintPrefMigration.INSTANCE.get(); 86 97 87 98 for (SourceEntry entry : sourceEntries) { … … 120 131 s.loadStyleSource(); 121 132 } 133 fireMapPaintSylesUpdated(); 134 } 135 136 /** 137 * reload styles 138 * preferences are the same, but the file source may have changed 139 * @param sel the indices of styles to reload 140 */ 141 public static void reloadStyles(final int... sel) { 142 List<StyleSource> toReload = new ArrayList<StyleSource>(); 143 List<StyleSource> data = styles.getStyleSources(); 144 for (int i : sel) { 145 toReload.add(data.get(i)); 146 } 147 Main.worker.submit(new MapPaintStyleLoader(toReload)); 122 148 } 123 149 … … 138 164 @Override 139 165 protected void finish() { 166 SwingUtilities.invokeLater(new Runnable() { 167 @Override 168 public void run() { 169 fireMapPaintSylesUpdated(); 170 styles.clearCached(); 171 Main.map.mapView.preferenceChanged(null); 172 Main.map.mapView.repaint(); 173 } 174 }); 140 175 } 141 176 … … 154 189 } 155 190 191 /** 192 * Move position of entries in the current list of StyleSources 193 * @param sele The indices of styles to be moved. 194 * @param delta The number of lines it should move. positive int moves 195 * down and negative moves up. 196 */ 197 public static void moveStyles(int[] sel, int delta) { 198 if (!canMoveStyles(sel, delta)) 199 return; 200 int[] selSorted = Arrays.copyOf(sel, sel.length); 201 Arrays.sort(selSorted); 202 List<StyleSource> data = new ArrayList<StyleSource>(styles.getStyleSources()); 203 for (int row: selSorted) { 204 StyleSource t1 = data.get(row); 205 StyleSource t2 = data.get(row + delta); 206 data.set(row, t2); 207 data.set(row + delta, t1); 208 } 209 styles.setStyleSources(data); 210 MapPaintPrefMigration.INSTANCE.put(data); 211 fireMapPaintSylesUpdated(); 212 styles.clearCached(); 213 Main.map.mapView.repaint(); 214 } 215 216 public static boolean canMoveStyles(int[] sel, int i) { 217 if (sel.length == 0) 218 return false; 219 int[] selSorted = Arrays.copyOf(sel, sel.length); 220 Arrays.sort(selSorted); 221 222 if (i < 0) { // Up 223 return selSorted[0] >= -i; 224 } else 225 if (i > 0) { // Down 226 return selSorted[selSorted.length-1] <= styles.getStyleSources().size() - 1 - i; 227 } else 228 return true; 229 } 230 231 public static void toggleStyleActive(int... sel) { 232 List<StyleSource> data = styles.getStyleSources(); 233 for (int p : sel) { 234 StyleSource s = data.get(p); 235 s.active = !s.active; 236 } 237 MapPaintPrefMigration.INSTANCE.put(data); 238 if (sel.length == 1) { 239 fireMapPaintStyleEntryUpdated(sel[0]); 240 } else { 241 fireMapPaintSylesUpdated(); 242 } 243 styles.clearCached(); 244 Main.map.mapView.repaint(); 245 } 246 247 /*********************************** 248 * MapPaintSylesUpdateListener & related code 249 * (get informed when the list of MapPaint StyleSources changes) 250 */ 251 252 public interface MapPaintSylesUpdateListener { 253 public void mapPaintStylesUpdated(); 254 public void mapPaintStyleEntryUpdated(int idx); 255 } 256 257 protected static final CopyOnWriteArrayList<MapPaintSylesUpdateListener> listeners 258 = new CopyOnWriteArrayList<MapPaintSylesUpdateListener>(); 259 260 public static void addMapPaintSylesUpdateListener(MapPaintSylesUpdateListener listener) { 261 if (listener != null) { 262 listeners.addIfAbsent(listener); 263 } 264 } 265 266 public static void removeMapPaintSylesUpdateListener(MapPaintSylesUpdateListener listener) { 267 listeners.remove(listener); 268 } 269 270 public static void fireMapPaintSylesUpdated() { 271 for (MapPaintSylesUpdateListener l : listeners) { 272 l.mapPaintStylesUpdated(); 273 } 274 } 275 276 public static void fireMapPaintStyleEntryUpdated(int idx) { 277 for (MapPaintSylesUpdateListener l : listeners) { 278 l.mapPaintStyleEntryUpdated(idx); 279 } 280 } 156 281 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
r3836 r3855 97 97 } 98 98 } 99 } else if (primitive instanceof Relation ) {99 } else if (primitive instanceof Relation && icon != null) { 100 100 painter.drawRestriction((Relation) primitive, this); 101 101 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r3848 r3855 41 41 public void loadStyleSource() { 42 42 rules.clear(); 43 hasError = false; 43 44 try { 44 45 MirroredInputStream in = new MirroredInputStream(url); -
trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSource.java
r3848 r3855 50 50 51 51 protected void init() { 52 hasError = false; 52 53 icons.clear(); 53 54 lines.clear(); -
trunk/src/org/openstreetmap/josm/gui/preferences/MapPaintPreference.java
r3854 r3855 68 68 69 69 public MapPaintSourceEditor() { 70 super( "http://josm.openstreetmap.de/styles");70 super(true, "http://josm.openstreetmap.de/styles"); 71 71 } 72 72 73 73 @Override 74 74 public Collection<? extends SourceEntry> getInitialSourcesList() { 75 return (new MapPaintPrefMigration()).get();75 return MapPaintPrefMigration.INSTANCE.get(); 76 76 } 77 77 … … 80 80 List<SourceEntry> activeStyles = activeSourcesModel.getSources(); 81 81 82 boolean changed = (new MapPaintPrefMigration()).put(activeStyles);82 boolean changed = MapPaintPrefMigration.INSTANCE.put(activeStyles); 83 83 84 84 if (tblIconPaths != null) { … … 98 98 @Override 99 99 public Collection<ExtendedSourceEntry> getDefault() { 100 return (new MapPaintPrefMigration()).getDefault();100 return MapPaintPrefMigration.INSTANCE.getDefault(); 101 101 } 102 102 … … 143 143 144 144 public boolean ok() { 145 Boolean restart = false; 146 if(Main.pref.put("mappaint.icon.enable-defaults", enableIconDefault.isSelected())) { 147 restart = true; 145 boolean reload = Main.pref.put("mappaint.icon.enable-defaults", enableIconDefault.isSelected()); 146 reload |= sources.finish(); 147 if (reload) { 148 MapPaintStyles.readFromPreferences(); 148 149 } 149 if(sources.finish()) { 150 restart = true; 151 } 152 if(Main.isDisplayingMapView()) 150 if (Main.isDisplayingMapView()) 153 151 { 154 152 MapPaintStyles.getStyles().clearCached(); 155 153 } 156 return restart;154 return false; 157 155 } 158 156 … … 165 163 166 164 public static class MapPaintPrefMigration extends SourceEditor.SourcePrefMigration { 165 166 public final static MapPaintPrefMigration INSTANCE = new MapPaintPrefMigration(); 167 167 168 168 public MapPaintPrefMigration() { -
trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceDialog.java
r3501 r3855 131 131 } 132 132 } 133 134 public void selectMapPaintPreferenceTab() { 135 tpPreferences.setSelectedComponent(tpPreferences.map); 136 tpPreferences.mapcontent.setSelectedIndex(1); 137 } 133 138 } -
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java
r3816 r3855 12 12 import java.awt.GridBagLayout; 13 13 import java.awt.Insets; 14 import java.awt.Rectangle; 14 15 import java.awt.event.ActionEvent; 15 16 import java.awt.event.FocusAdapter; … … 43 44 import javax.swing.DefaultListSelectionModel; 44 45 import javax.swing.JButton; 46 import javax.swing.JCheckBox; 45 47 import javax.swing.JComponent; 46 48 import javax.swing.JFileChooser; … … 81 83 public abstract class SourceEditor extends JPanel { 82 84 85 final protected boolean isMapPaint; 86 83 87 protected JTable tblActiveSources; 84 88 protected ActiveSourcesModel activeSourcesModel; … … 92 96 /** 93 97 * constructor 98 * @param isMapPaint true for MapPaintPreference subclass, false 99 * for TaggingPresetPreference subclass 94 100 * @param availableSourcesUrl the URL to the list of available sources 95 101 */ 96 public SourceEditor(final String availableSourcesUrl) { 97 102 public SourceEditor(final boolean isMapPaint, final String availableSourcesUrl) { 103 104 this.isMapPaint = isMapPaint; 98 105 DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); 99 106 lstAvailableSources = new JList(availableSourcesModel = new AvailableSourcesListModel(selectionModel)); … … 103 110 104 111 selectionModel = new DefaultListSelectionModel(); 105 tblActiveSources = new JTable(activeSourcesModel = new ActiveSourcesModel(selectionModel)); 112 tblActiveSources = new JTable(activeSourcesModel = new ActiveSourcesModel(selectionModel)) { 113 // some kind of hack to prevent the table from scrolling slightly to the 114 // right when clicking on the text 115 public void scrollRectToVisible(Rectangle aRect) { 116 super.scrollRectToVisible(new Rectangle(0, aRect.y, aRect.width, aRect.height)); 117 } 118 }; 106 119 tblActiveSources.putClientProperty("terminateEditOnFocusLost", true); 107 120 tblActiveSources.setSelectionModel(selectionModel); … … 112 125 tblActiveSources.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 113 126 SourceEntryTableCellRenderer sourceEntryRenderer = new SourceEntryTableCellRenderer(); 114 tblActiveSources.getColumnModel().getColumn(0).setCellRenderer(sourceEntryRenderer); 127 if (isMapPaint) { 128 tblActiveSources.getColumnModel().getColumn(0).setMaxWidth(1); 129 tblActiveSources.getColumnModel().getColumn(0).setResizable(false); 130 tblActiveSources.getColumnModel().getColumn(1).setCellRenderer(sourceEntryRenderer); 131 } else { 132 tblActiveSources.getColumnModel().getColumn(0).setCellRenderer(sourceEntryRenderer); 133 } 134 115 135 activeSourcesModel.addTableModelListener(new TableModelListener() { 116 136 // Force swing to show horizontal scrollbars for the JTable … … 118 138 @Override 119 139 public void tableChanged(TableModelEvent e) { 120 adjustColumnWidth(tblActiveSources, 0);140 adjustColumnWidth(tblActiveSources, isMapPaint ? 1 : 0); 121 141 } 122 142 }); … … 130 150 if (e.getClickCount() == 2) { 131 151 int row = tblActiveSources.rowAtPoint(e.getPoint()); 152 int col = tblActiveSources.columnAtPoint(e.getPoint()); 132 153 if (row < 0 || row >= tblActiveSources.getRowCount()) 154 return; 155 if (isMapPaint && col != 1) 133 156 return; 134 157 editActiveSourceAction.actionPerformed(null); … … 141 164 tblActiveSources.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0), "delete"); 142 165 tblActiveSources.getActionMap().put("delete", removeActiveSourcesAction); 166 167 MoveUpDownAction moveUp = null; 168 MoveUpDownAction moveDown = null; 169 if (isMapPaint) { 170 moveUp = new MoveUpDownAction(false); 171 moveDown = new MoveUpDownAction(true); 172 tblActiveSources.getSelectionModel().addListSelectionListener(moveUp); 173 tblActiveSources.getSelectionModel().addListSelectionListener(moveDown); 174 activeSourcesModel.addTableModelListener(moveUp); 175 activeSourcesModel.addTableModelListener(moveDown); 176 } 143 177 144 178 ActivateSourcesAction activateSourcesAction = new ActivateSourcesAction(); … … 209 243 sideButtonTB.add(editActiveSourceAction); 210 244 sideButtonTB.add(removeActiveSourcesAction); 245 sideButtonTB.addSeparator(new Dimension(12, 30)); 246 if (isMapPaint) { 247 sideButtonTB.add(moveUp); 248 sideButtonTB.add(moveDown); 249 } 211 250 add(sideButtonTB, gbc); 212 251 … … 435 474 } 436 475 437 protected staticclass ActiveSourcesModel extends AbstractTableModel {476 protected class ActiveSourcesModel extends AbstractTableModel { 438 477 private List<SourceEntry> data; 439 478 private DefaultListSelectionModel selectionModel; … … 445 484 446 485 public int getColumnCount() { 447 return 1;486 return isMapPaint ? 2 : 1; 448 487 } 449 488 … … 453 492 454 493 @Override 455 public SourceEntry getValueAt(int rowIndex, int columnIndex) { 456 return data.get(rowIndex); 494 public Object getValueAt(int rowIndex, int columnIndex) { 495 if (isMapPaint && columnIndex == 0) 496 return data.get(rowIndex).active; 497 else 498 return data.get(rowIndex); 457 499 } 458 500 459 501 @Override 460 502 public boolean isCellEditable(int rowIndex, int columnIndex) { 461 return false; 462 } 503 return isMapPaint && columnIndex == 0; 504 } 505 506 Class<?>[] columnClasses = {Boolean.class, SourceEntry.class}; 463 507 464 508 @Override 465 public void setValueAt(Object aValue, int rowIndex, int columnIndex) { 466 updateSource(rowIndex, (String)aValue); 509 public Class<?> getColumnClass(int column) { 510 return isMapPaint ? columnClasses[column] : SourceEntry.class; 511 } 512 513 @Override 514 public void setValueAt(Object aValue, int row, int column) { 515 if (row < 0 || row >= getRowCount() || aValue == null) 516 return; 517 if (isMapPaint && column == 0) { 518 data.get(row).active = ! data.get(row).active; 519 } 467 520 } 468 521 … … 470 523 data.clear(); 471 524 if (sources != null) { 472 data.addAll(sources); 525 for (SourceEntry e : sources) { 526 data.add(new SourceEntry(e)); 527 } 473 528 } 474 529 fireTableDataChanged(); … … 485 540 } 486 541 487 public void updateSource(int pos, String src) {488 if (src == null) return;489 if (pos < 0 || pos >= getRowCount()) return;490 data.get(pos).url = src;491 fireTableDataChanged();492 int idx = data.indexOf(src);493 if (idx >= 0) {494 selectionModel.setSelectionInterval(idx, idx);495 }496 }497 498 542 public void removeSelected() { 499 543 Iterator<SourceEntry> it = data.iterator(); … … 538 582 return new ArrayList<SourceEntry>(data); 539 583 } 584 585 public boolean canMove(int i) { 586 int[] sel = tblActiveSources.getSelectedRows(); 587 if (sel.length == 0) 588 return false; 589 if (i < 0) { // Up 590 return sel[0] >= -i; 591 } else if (i > 0) { // Down 592 return sel[sel.length-1] <= getRowCount()-1 - i; 593 } else 594 return true; 595 } 596 597 public void move(int i) { 598 if (!canMove(i)) return; 599 int[] sel = tblActiveSources.getSelectedRows(); 600 for (int row: sel) { 601 SourceEntry t1 = data.get(row); 602 SourceEntry t2 = data.get(row + i); 603 data.set(row, t2); 604 data.set(row + i, t1); 605 } 606 selectionModel.clearSelection(); 607 for (int row: sel) { 608 selectionModel.addSelectionInterval(row + i, row + i); 609 } 610 } 540 611 } 541 612 … … 590 661 private JTextField tfName; 591 662 private JTextField tfURL; 663 private JCheckBox cbActive; 592 664 593 665 public EditSourceEntryDialog(Component parent, String title, SourceEntry e) { … … 604 676 tfURL = new JTextField(60); 605 677 p.add(new JLabel(tr("URL / File:")), GBC.std().insets(15, 0, 5, 0)); 606 p.add(tfURL, GBC.std().insets(0, 0, 5, 0));678 p.add(tfURL, GBC.std().insets(0, 0, 5, 5)); 607 679 JButton fileChooser = new JButton(new LaunchFileChooserAction()); 608 680 fileChooser.setMargin(new Insets(0, 0, 0, 0)); 609 p.add(fileChooser, GBC.eol().insets(0, 0, 5, 0));681 p.add(fileChooser, GBC.eol().insets(0, 0, 5, 5)); 610 682 611 683 if (e != null) { … … 616 688 } 617 689 690 if (isMapPaint) { 691 cbActive = new JCheckBox(tr("active"), e != null ? e.active : true); 692 p.add(cbActive, GBC.eol().insets(15, 0, 5, 0)); 693 } 618 694 setButtonIcons(new String[] {"ok", "cancel"}); 619 695 setContent(p); … … 669 745 return tfURL.getText(); 670 746 } 747 748 public boolean active() { 749 if (!isMapPaint) 750 throw new UnsupportedOperationException(); 751 return cbActive.isSelected(); 752 } 671 753 } 672 754 … … 685 767 editEntryDialog.showDialog(); 686 768 if (editEntryDialog.getValue() == 1) { 769 boolean active = true; 770 if (isMapPaint) { 771 active = editEntryDialog.active(); 772 } 687 773 activeSourcesModel.addSource(new SourceEntry( 688 774 editEntryDialog.getURL(), 689 null, editEntryDialog.getShortdescription(), true));775 null, editEntryDialog.getShortdescription(), active)); 690 776 activeSourcesModel.fireTableDataChanged(); 691 777 } … … 736 822 return; 737 823 738 SourceEntry e = activeSourcesModel.getValueAt(pos, 0);824 SourceEntry e = (SourceEntry) activeSourcesModel.getValueAt(pos, 1); 739 825 740 826 EditSourceEntryDialog editEntryDialog = new EditSourceEntryDialog( … … 749 835 } 750 836 e.url = editEntryDialog.getURL(); 751 activeSourcesModel.fireTableCellUpdated(pos, 0); 752 } 837 if (isMapPaint) { 838 e.active = editEntryDialog.active(); 839 } 840 activeSourcesModel.fireTableRowsUpdated(pos, pos); 841 } 842 } 843 } 844 845 /** 846 * The action to move the currently selected entries up or down in the list. 847 */ 848 class MoveUpDownAction extends AbstractAction implements ListSelectionListener, TableModelListener { 849 final int increment; 850 public MoveUpDownAction(boolean isDown) { 851 increment = isDown ? 1 : -1; 852 putValue(SMALL_ICON, isDown ? ImageProvider.get("dialogs", "down") : ImageProvider.get("dialogs", "up")); 853 putValue(SHORT_DESCRIPTION, isDown ? tr("Move the selected entry one row down.") : tr("Move the selected entry one row up.")); 854 updateEnabledState(); 855 } 856 857 public void updateEnabledState() { 858 setEnabled(activeSourcesModel.canMove(increment)); 859 } 860 861 @Override 862 public void actionPerformed(ActionEvent e) { 863 activeSourcesModel.move(increment); 864 } 865 866 public void valueChanged(ListSelectionEvent e) { 867 updateEnabledState(); 868 } 869 870 public void tableChanged(TableModelEvent e) { 871 updateEnabledState(); 753 872 } 754 873 } … … 1107 1226 } 1108 1227 s.append(entry.url); 1109 if (entry. name!= null) {1228 if (entry.shortdescription != null) { 1110 1229 s.append(")"); 1111 1230 } -
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEntry.java
r3843 r3855 46 46 this.shortdescription = equal(shortdescription, "") ? null : shortdescription; 47 47 this.active = active; 48 } 49 50 public SourceEntry(SourceEntry e) { 51 this.url = e.url; 52 this.name = e.name; 53 this.shortdescription = e.shortdescription; 54 this.active = e.active; 48 55 } 49 56 -
trunk/src/org/openstreetmap/josm/gui/preferences/TaggingPresetPreference.java
r3797 r3855 166 166 167 167 public TaggingPresetSourceEditor() { 168 super( "http://josm.openstreetmap.de/presets");168 super(false, "http://josm.openstreetmap.de/presets"); 169 169 } 170 170 171 171 @Override 172 172 public Collection<? extends SourceEntry> getInitialSourcesList() { 173 return (new PresetPrefMigration()).get();173 return PresetPrefMigration.INSTANCE.get(); 174 174 } 175 175 … … 178 178 List<SourceEntry> activeStyles = activeSourcesModel.getSources(); 179 179 180 boolean changed = (new PresetPrefMigration()).put(activeStyles);180 boolean changed = PresetPrefMigration.INSTANCE.put(activeStyles); 181 181 182 182 if (tblIconPaths != null) { … … 196 196 @Override 197 197 public Collection<ExtendedSourceEntry> getDefault() { 198 return (new PresetPrefMigration()).getDefault();198 return PresetPrefMigration.INSTANCE.getDefault(); 199 199 } 200 200 … … 291 291 public static class PresetPrefMigration extends SourceEditor.SourcePrefMigration { 292 292 293 public final static PresetPrefMigration INSTANCE = new PresetPrefMigration(); 294 293 295 public PresetPrefMigration() { 294 296 super("taggingpreset.sources",
Note:
See TracChangeset
for help on using the changeset viewer.