Changeset 6670 in josm for trunk/src/org/openstreetmap/josm/gui
- Timestamp:
- 2014-01-11T02:21:08+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r6643 r6670 42 42 private static ElemStyles styles = new ElemStyles(); 43 43 44 /** 45 * Returns the {@link ElemStyles} instance. 46 * @return the {@code ElemStyles} instance 47 */ 44 48 public static ElemStyles getStyles() { 45 49 return styles; -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r6643 r6670 34 34 35 35 public class MapCSSStyleSource extends StyleSource { 36 final publicList<MapCSSRule> rules;36 public final List<MapCSSRule> rules; 37 37 private Color backgroundColorOverride; 38 38 private String css = null; -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r6623 r6670 346 346 347 347 public List<Condition> getConditions() { 348 if (conds == null) { 349 return Collections.emptyList(); 350 } 348 351 return Collections.unmodifiableList(conds); 349 352 } -
trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java
r6666 r6670 53 53 import org.openstreetmap.josm.gui.preferences.shortcut.ShortcutPreference; 54 54 import org.openstreetmap.josm.gui.preferences.validator.ValidatorPreference; 55 import org.openstreetmap.josm.gui.preferences.validator.ValidatorTagCheckerRulesPreference; 55 56 import org.openstreetmap.josm.gui.preferences.validator.ValidatorTestsPreference; 56 57 import org.openstreetmap.josm.plugins.PluginDownloadTask; … … 514 515 settingsFactory.add(new ValidatorPreference.Factory()); 515 516 settingsFactory.add(new ValidatorTestsPreference.Factory()); 517 settingsFactory.add(new ValidatorTagCheckerRulesPreference.Factory()); 516 518 settingsFactory.add(new RemoteControlPreference.Factory()); 517 519 settingsFactory.add(new ImageryPreference.Factory()); -
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java
r6552 r6670 33 33 import java.util.EventObject; 34 34 import java.util.HashMap; 35 import java.util.HashSet; 35 36 import java.util.Iterator; 36 37 import java.util.List; 37 38 import java.util.Map; 39 import java.util.Set; 38 40 import java.util.concurrent.CopyOnWriteArrayList; 39 41 import java.util.regex.Matcher; … … 64 66 import javax.swing.event.CellEditorListener; 65 67 import javax.swing.event.ChangeEvent; 68 import javax.swing.event.ChangeListener; 66 69 import javax.swing.event.ListSelectionEvent; 67 70 import javax.swing.event.ListSelectionListener; … … 93 96 public abstract class SourceEditor extends JPanel { 94 97 95 final protected boolean isMapPaint; 98 protected final SourceType sourceType; 99 protected final boolean canEnable; 96 100 97 101 protected final JTable tblActiveSources; … … 99 103 protected final JList lstAvailableSources; 100 104 protected final AvailableSourcesListModel availableSourcesModel; 101 protected final JTable tblIconPaths;102 protected final IconPathTableModel iconPathsModel;103 105 protected final String availableSourcesUrl; 104 106 protected final List<SourceProvider> sourceProviders; 105 107 108 protected JTable tblIconPaths; 109 protected IconPathTableModel iconPathsModel; 110 106 111 protected boolean sourcesInitiallyLoaded; 107 112 108 113 /** 109 * constructor 110 * @param isMapPaint true for MapPaintPreference subclass, false 111 * for TaggingPresetPreference subclass 114 * Constructs a new {@code SourceEditor}. 115 * @param sourceType the type of source managed by this editor 112 116 * @param availableSourcesUrl the URL to the list of available sources 113 117 * @param sourceProviders the list of additional source providers, from plugins 118 * @param handleIcons {@code true} if icons may be managed, {@code false} otherwise 114 119 */ 115 public SourceEditor(final boolean isMapPaint, final String availableSourcesUrl, final List<SourceProvider> sourceProviders) { 116 117 this.isMapPaint = isMapPaint; 120 public SourceEditor(SourceType sourceType, String availableSourcesUrl, List<SourceProvider> sourceProviders, boolean handleIcons) { 121 122 this.sourceType = sourceType; 123 this.canEnable = sourceType.equals(SourceType.MAP_PAINT_STYLE) || sourceType.equals(SourceType.TAGCHECKER_RULE); 124 118 125 DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); 119 this.lstAvailableSources = new JList(availableSourcesModel = new AvailableSourcesListModel(selectionModel)); 126 this.availableSourcesModel = new AvailableSourcesListModel(selectionModel); 127 this.lstAvailableSources = new JList(availableSourcesModel); 120 128 this.lstAvailableSources.setSelectionModel(selectionModel); 121 129 this.lstAvailableSources.setCellRenderer(new SourceEntryListCellRenderer()); … … 124 132 125 133 selectionModel = new DefaultListSelectionModel(); 126 tblActiveSources = new JTable(activeSourcesModel = new ActiveSourcesModel(selectionModel)) { 134 activeSourcesModel = new ActiveSourcesModel(selectionModel); 135 tblActiveSources = new JTable(activeSourcesModel) { 127 136 // some kind of hack to prevent the table from scrolling slightly to the 128 137 // right when clicking on the text … … 140 149 tblActiveSources.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 141 150 SourceEntryTableCellRenderer sourceEntryRenderer = new SourceEntryTableCellRenderer(); 142 if ( isMapPaint) {151 if (canEnable) { 143 152 tblActiveSources.getColumnModel().getColumn(0).setMaxWidth(1); 144 153 tblActiveSources.getColumnModel().getColumn(0).setResizable(false); … … 153 162 @Override 154 163 public void tableChanged(TableModelEvent e) { 155 TableHelper.adjustColumnWidth(tblActiveSources, isMapPaint? 1 : 0, 800);164 TableHelper.adjustColumnWidth(tblActiveSources, canEnable ? 1 : 0, 800); 156 165 } 157 166 }); … … 168 177 if (row < 0 || row >= tblActiveSources.getRowCount()) 169 178 return; 170 if ( isMapPaint&& col != 1)179 if (canEnable && col != 1) 171 180 return; 172 181 editActiveSourceAction.actionPerformed(null); … … 182 191 MoveUpDownAction moveUp = null; 183 192 MoveUpDownAction moveDown = null; 184 if ( isMapPaint) {193 if (sourceType.equals(SourceType.MAP_PAINT_STYLE)) { 185 194 moveUp = new MoveUpDownAction(false); 186 195 moveDown = new MoveUpDownAction(true); … … 259 268 sideButtonTB.add(removeActiveSourcesAction); 260 269 sideButtonTB.addSeparator(new Dimension(12, 30)); 261 if ( isMapPaint) {270 if (sourceType.equals(SourceType.MAP_PAINT_STYLE)) { 262 271 sideButtonTB.add(moveUp); 263 272 sideButtonTB.add(moveDown); … … 297 306 **/ 298 307 299 selectionModel = new DefaultListSelectionModel(); 300 tblIconPaths = new JTable(iconPathsModel = new IconPathTableModel(selectionModel)); 308 if (handleIcons) { 309 buildIcons(gbc); 310 } 311 } 312 313 private void buildIcons(GridBagConstraints gbc) { 314 DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); 315 iconPathsModel = new IconPathTableModel(selectionModel); 316 tblIconPaths = new JTable(iconPathsModel); 301 317 tblIconPaths.setSelectionModel(selectionModel); 302 318 tblIconPaths.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); … … 334 350 gbc.insets = new Insets(0, 11, 0, 0); 335 351 336 add(sp = new JScrollPane(tblIconPaths), gbc); 352 JScrollPane sp = new JScrollPane(tblIconPaths); 353 add(sp, gbc); 337 354 sp.setColumnHeaderView(null); 338 355 … … 485 502 @Override 486 503 public int getColumnCount() { 487 return isMapPaint? 2 : 1;504 return canEnable ? 2 : 1; 488 505 } 489 506 … … 495 512 @Override 496 513 public Object getValueAt(int rowIndex, int columnIndex) { 497 if ( isMapPaint&& columnIndex == 0)514 if (canEnable && columnIndex == 0) 498 515 return data.get(rowIndex).active; 499 516 else … … 503 520 @Override 504 521 public boolean isCellEditable(int rowIndex, int columnIndex) { 505 return isMapPaint&& columnIndex == 0;522 return canEnable && columnIndex == 0; 506 523 } 507 524 508 525 @Override 509 526 public Class<?> getColumnClass(int column) { 510 if ( isMapPaint&& column == 0)527 if (canEnable && column == 0) 511 528 return Boolean.class; 512 529 else return SourceEntry.class; … … 517 534 if (row < 0 || row >= getRowCount() || aValue == null) 518 535 return; 519 if ( isMapPaint&& column == 0) {536 if (canEnable && column == 0) { 520 537 data.get(row).active = ! data.get(row).active; 521 538 } … … 709 726 } 710 727 711 if ( isMapPaint) {728 if (canEnable) { 712 729 cbActive = new JCheckBox(tr("active"), e != null ? e.active : true); 713 730 p.add(cbActive, GBC.eol().insets(15, 0, 5, 0)); … … 752 769 public void actionPerformed(ActionEvent e) { 753 770 FileFilter ff; 754 if (isMapPaint) { 771 switch (sourceType) { 772 case MAP_PAINT_STYLE: 755 773 ff = new ExtensionFileFilter("xml,mapcss,css,zip", "xml", tr("Map paint style file (*.xml, *.mapcss, *.zip)")); 756 } else { 774 break; 775 case TAGGING_PRESET: 757 776 ff = new ExtensionFileFilter("xml,zip", "xml", tr("Preset definition file (*.xml, *.zip)")); 777 break; 778 case TAGCHECKER_RULE: 779 ff = new ExtensionFileFilter("validator.mapcss,zip", "validator.mapcss", tr("Tag checker rule (*.validator.mapcss, *.zip)")); 780 break; 781 default: 782 Main.error("Unsupported source type: "+sourceType); 783 return; 758 784 } 759 785 JFileChooserManager fcm = new JFileChooserManager(true) … … 777 803 778 804 public boolean active() { 779 if (! isMapPaint)805 if (!canEnable) 780 806 throw new UnsupportedOperationException(); 781 807 return cbActive.isSelected(); … … 799 825 if (editEntryDialog.getValue() == 1) { 800 826 boolean active = true; 801 if ( isMapPaint) {827 if (canEnable) { 802 828 active = editEntryDialog.active(); 803 829 } … … 870 896 } 871 897 e.url = editEntryDialog.getURL(); 872 if ( isMapPaint) {898 if (canEnable) { 873 899 e.active = editEntryDialog.active(); 874 900 } … … 1495 1521 private final String pref; 1496 1522 1523 /** 1524 * Constructs a new {@code SourcePrefHelper} for the given preference key. 1525 * @param pref The preference key 1526 */ 1497 1527 public SourcePrefHelper(String pref) { 1498 1528 this.pref = pref; 1499 1529 } 1500 1530 1531 /** 1532 * Returns the default sources provided by JOSM core. 1533 * @return the default sources provided by JOSM core 1534 */ 1501 1535 abstract public Collection<ExtendedSourceEntry> getDefault(); 1502 1536 … … 1505 1539 abstract public SourceEntry deserialize(Map<String, String> entryStr); 1506 1540 1541 /** 1542 * Returns the list of sources. 1543 * @return The list of sources 1544 */ 1507 1545 public List<SourceEntry> get() { 1508 1546 … … 1528 1566 return Main.pref.putListOfStructs(pref, setting); 1529 1567 } 1530 } 1531 1568 1569 /** 1570 * Returns the set of active source URLs. 1571 * @return The set of active source URLs. 1572 */ 1573 public final Set<String> getActiveUrls() { 1574 Set<String> urls = new HashSet<String>(); 1575 for (SourceEntry e : get()) { 1576 if (e.active) { 1577 urls.add(e.url); 1578 } 1579 } 1580 return urls; 1581 } 1582 } 1583 1584 /** 1585 * Defers loading of sources to the first time the adequate tab is selected. 1586 * @param tab The preferences tab 1587 * @param component The tab component 1588 * @since 6670 1589 */ 1590 public final void deferLoading(final DefaultTabPreferenceSetting tab, final Component component) { 1591 tab.getTabPane().addChangeListener( 1592 new ChangeListener() { 1593 @Override 1594 public void stateChanged(ChangeEvent e) { 1595 if (tab.getTabPane().getSelectedComponent() == component) { 1596 SourceEditor.this.initiallyLoadAvailableSources(); 1597 } 1598 } 1599 } 1600 ); 1601 } 1532 1602 } -
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEntry.java
r6248 r6670 50 50 51 51 /** 52 * active is a boolean flag that can be used to turn the style on or off 53 * at runtime. 52 * active is a boolean flag that can be used to turn the source on or off at runtime. 54 53 */ 55 54 public boolean active; -
trunk/src/org/openstreetmap/josm/gui/preferences/map/MapPaintPreference.java
r6529 r6670 26 26 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; 27 27 import org.openstreetmap.josm.gui.preferences.SourceEditor; 28 import org.openstreetmap.josm.gui.preferences.SourceType; 28 29 import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry; 29 30 import org.openstreetmap.josm.gui.preferences.SourceEntry; … … 41 42 private static final List<SourceProvider> styleSourceProviders = new ArrayList<SourceProvider>(); 42 43 44 /** 45 * Registers a new additional style source provider. 46 * @param provider The style source provider 47 * @return {@code true}, if the provider has been added, {@code false} otherwise 48 */ 43 49 public static boolean registerSourceProvider(SourceProvider provider) { 44 50 if (provider != null) … … 58 64 59 65 @Override 60 public void addGui( finalPreferenceTabbedPane gui) {66 public void addGui(PreferenceTabbedPane gui) { 61 67 enableIconDefault = new JCheckBox(tr("Enable built-in icon defaults"), 62 68 Main.pref.getBoolean("mappaint.icon.enable-defaults", true)); … … 70 76 panel.add(enableIconDefault, GBC.eol().insets(11,2,5,0)); 71 77 72 gui.getMapPreference().addSubTab(this, tr("Map Paint Styles"), panel); 73 74 // this defers loading of style sources to the first time the tab 75 // with the map paint preferences is selected by the user 76 // 77 gui.getMapPreference().getTabPane().addChangeListener( 78 new ChangeListener() { 79 @Override 80 public void stateChanged(ChangeEvent e) { 81 if (gui.getMapPreference().getTabPane().getSelectedComponent() == panel) { 82 sources.initiallyLoadAvailableSources(); 83 } 84 } 85 } 86 ); 78 final MapPreference mapPref = gui.getMapPreference(); 79 mapPref.addSubTab(this, tr("Map Paint Styles"), panel); 80 sources.deferLoading(mapPref, panel); 87 81 } 88 82 … … 92 86 93 87 public MapPaintSourceEditor() { 94 super( true, Main.JOSM_WEBSITE+"/styles", styleSourceProviders);88 super(SourceType.MAP_PAINT_STYLE, Main.JOSM_WEBSITE+"/styles", styleSourceProviders, true); 95 89 } 96 90 … … 186 180 } 187 181 182 /** 183 * Helper class for map paint styles preferences. 184 */ 188 185 public static class MapPaintPrefHelper extends SourceEditor.SourcePrefHelper { 189 186 -
trunk/src/org/openstreetmap/josm/gui/preferences/map/TaggingPresetPreference.java
r6605 r6670 35 35 import org.openstreetmap.josm.gui.preferences.SourceEntry; 36 36 import org.openstreetmap.josm.gui.preferences.SourceProvider; 37 import org.openstreetmap.josm.gui.preferences.SourceType; 37 38 import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting; 38 39 import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; … … 67 68 private JCheckBox sortMenu; 68 69 70 /** 71 * Registers a new additional preset source provider. 72 * @param provider The preset source provider 73 * @return {@code true}, if the provider has been added, {@code false} otherwise 74 */ 69 75 public static final boolean registerSourceProvider(SourceProvider provider) { 70 76 if (provider != null) … … 161 167 162 168 @Override 163 public void addGui( finalPreferenceTabbedPane gui) {169 public void addGui(PreferenceTabbedPane gui) { 164 170 sortMenu = new JCheckBox(tr("Sort presets menu"), 165 171 Main.pref.getBoolean("taggingpreset.sortmenu", false)); … … 170 176 sources = new TaggingPresetSourceEditor(); 171 177 panel.add(sources, GBC.eol().fill(GBC.BOTH)); 172 gui.getMapPreference().addSubTab(this, tr("Tagging Presets"), panel); 173 174 // this defers loading of tagging preset sources to the first time the tab 175 // with the tagging presets is selected by the user 176 // 177 gui.getMapPreference().getTabPane().addChangeListener( 178 new ChangeListener() { 179 @Override 180 public void stateChanged(ChangeEvent e) { 181 if (gui.getMapPreference().getTabPane().getSelectedComponent() == panel) { 182 sources.initiallyLoadAvailableSources(); 183 } 184 } 185 } 186 ); 178 final MapPreference mapPref = gui.getMapPreference(); 179 mapPref.addSubTab(this, tr("Tagging Presets"), panel); 180 sources.deferLoading(mapPref, panel); 187 181 gui.addValidationListener(validationListener); 188 182 } … … 193 187 194 188 public TaggingPresetSourceEditor() { 195 super( false, Main.JOSM_WEBSITE+"/presets", presetSourceProviders);189 super(SourceType.TAGGING_PRESET, Main.JOSM_WEBSITE+"/presets", presetSourceProviders, true); 196 190 } 197 191 … … 274 268 } 275 269 270 /** 271 * Initializes tagging presets from preferences. 272 */ 276 273 public static void readFromPreferences() { 277 274 taggingPresets = TaggingPresetReader.readFromPreferences(false); 278 275 } 279 276 280 281 282 277 /** 278 * Initialize the tagging presets (load and may display error) 279 */ 283 280 public static void initialize() { 284 281 readFromPreferences(); … … 315 312 } 316 313 314 /** 315 * Helper class for tagging presets preferences. 316 */ 317 317 public static class PresetPrefHelper extends SourceEditor.SourcePrefHelper { 318 318 -
trunk/src/org/openstreetmap/josm/gui/preferences/validator/ValidatorTestsPreference.java
r6666 r6670 7 7 import java.awt.event.ActionEvent; 8 8 import java.awt.event.ActionListener; 9 import java.util.ArrayList; 9 10 import java.util.Collection; 10 11 import java.util.LinkedList; 12 import java.util.List; 11 13 12 14 import javax.swing.BorderFactory; … … 18 20 import org.openstreetmap.josm.data.validation.OsmValidator; 19 21 import org.openstreetmap.josm.data.validation.Test; 22 import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker; 20 23 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 21 24 import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory; … … 108 111 testsBeforeUpload.add(name); 109 112 } 110 OsmValidator.initializeTests(allTests); 113 114 // Initializes all tests but MapCSSTagChecker because it is initialized 115 // later in ValidatorTagCheckerRulesPreference.ok(), 116 // after its list of rules has been saved to preferences 117 List<Test> testsToInitialize = new ArrayList<Test>(allTests); 118 testsToInitialize.remove(OsmValidator.getTest(MapCSSTagChecker.class)); 119 OsmValidator.initializeTests(testsToInitialize); 111 120 112 121 Main.pref.putCollection(ValidatorPreference.PREF_SKIP_TESTS, tests); -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetReader.java
r6572 r6670 17 17 import java.util.List; 18 18 import java.util.Map; 19 import java.util.Set; 19 20 import java.util.Stack; 20 21 … … 22 23 23 24 import org.openstreetmap.josm.Main; 24 import org.openstreetmap.josm.gui.preferences.SourceEntry;25 25 import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference; 26 26 import org.openstreetmap.josm.io.MirroredInputStream; … … 41 41 private static File zipIcons = null; 42 42 43 public static List<String> getPresetSources() {44 LinkedList<String> sources = new LinkedList<String>();45 46 for (SourceEntry e : (new TaggingPresetPreference.PresetPrefHelper()).get()) {47 sources.add(e.url);48 }49 50 return sources;51 }52 53 43 /** 54 * Holds a reference to a chunk of items/objects. 44 * Returns the set of preset source URLs. 45 * @return The set of preset source URLs. 46 */ 47 public static Set<String> getPresetSources() { 48 return new TaggingPresetPreference.PresetPrefHelper().getActiveUrls(); 49 } 50 51 /** 52 * Holds a reference to a chunk of items/objects. 55 53 */ 56 54 public static class Chunk { 55 /** The chunk id, can be referenced later */ 57 56 public String id; 58 57 } … … 62 61 */ 63 62 public static class Reference { 63 /** Reference matching a chunk id defined earlier **/ 64 64 public String ref; 65 65 }
Note:
See TracChangeset
for help on using the changeset viewer.