Changeset 3797 in josm
- Timestamp:
- 2011-01-21T14:11:47+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/preferences
- Files:
-
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/MapPaintPreference.java
r3796 r3797 24 24 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 25 25 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 26 import org.openstreetmap.josm.gui.preferences.S tyleSourceEditor.StyleSourceInfo;26 import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry; 27 27 import org.openstreetmap.josm.tools.GBC; 28 28 29 29 public class MapPaintPreference implements PreferenceSetting { 30 private S tyleSourceEditor sources;30 private SourceEditor sources; 31 31 private JCheckBox enableIconDefault; 32 32 private JCheckBox enableDefault; … … 81 81 public void stateChanged(ChangeEvent e) { 82 82 if (gui.mapcontent.getSelectedComponent() == panel) { 83 sources.initiallyLoadAvailableS tyles();83 sources.initiallyLoadAvailableSources(); 84 84 } 85 85 } … … 88 88 } 89 89 90 class MapPaintSourceEditor extends S tyleSourceEditor {90 class MapPaintSourceEditor extends SourceEditor { 91 91 92 92 final private String iconpref = "mappaint.icon.sources"; … … 103 103 @Override 104 104 public boolean finish() { 105 List<SourceEntry> activeStyles = activeS tylesModel.getStyles();105 List<SourceEntry> activeStyles = activeSourcesModel.getSources(); 106 106 107 107 boolean changed = (new MapPaintPrefMigration()).put(activeStyles); … … 122 122 123 123 @Override 124 public Collection< StyleSourceInfo> getDefault() {124 public Collection<ExtendedSourceEntry> getDefault() { 125 125 return (new MapPaintPrefMigration()).getDefault(); 126 126 } … … 138 138 case ACTIVE_SOURCES: 139 139 return tr("Active styles:"); 140 case NEW_SOURCE_ENTRY_TOOLTIP: 141 return tr("Add a new style by entering filename or URL"); 140 142 case NEW_SOURCE_ENTRY: 141 143 return tr("New style entry:"); … … 194 196 } 195 197 196 public static class MapPaintPrefMigration extends S tyleSourceEditor.SourcePrefMigration {198 public static class MapPaintPrefMigration extends SourceEditor.SourcePrefMigration { 197 199 198 200 public MapPaintPrefMigration() { … … 203 205 204 206 @Override 205 public Collection< StyleSourceInfo> getDefault() {206 StyleSourceInfo i = new StyleSourceInfo("elemstyles.xml", "resource://data/elemstyles.xml");207 public Collection<ExtendedSourceEntry> getDefault() { 208 ExtendedSourceEntry i = new ExtendedSourceEntry("elemstyles.xml", "resource://data/elemstyles.xml"); 207 209 i.name = "standard"; 208 210 i.shortdescription = tr("Internal Style"); -
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java
r3796 r3797 79 79 import org.xml.sax.SAXException; 80 80 81 public abstract class S tyleSourceEditor extends JPanel {82 83 protected JTable tblActiveS tyles;84 protected ActiveS tylesModel activeStylesModel;85 protected JList lstAvailableS tyles;86 protected AvailableS tylesListModel availableStylesModel;81 public abstract class SourceEditor extends JPanel { 82 83 protected JTable tblActiveSources; 84 protected ActiveSourcesModel activeSourcesModel; 85 protected JList lstAvailableSources; 86 protected AvailableSourcesListModel availableSourcesModel; 87 87 protected JTable tblIconPaths = null; 88 88 protected IconPathTableModel iconPathsModel; 89 protected boolean s tylesInitiallyLoaded;90 protected String availableS tylesUrl;89 protected boolean sourcesInitiallyLoaded; 90 protected String availableSourcesUrl; 91 91 92 92 /** 93 93 * constructor 94 * @param availableS tylesUrl the URL to the list of available style sources94 * @param availableSourcesUrl the URL to the list of available sources 95 95 */ 96 public S tyleSourceEditor(final String availableStylesUrl) {96 public SourceEditor(final String availableSourcesUrl) { 97 97 98 98 DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); 99 lstAvailableS tyles = new JList(availableStylesModel = new AvailableStylesListModel(selectionModel));100 lstAvailableS tyles.setSelectionModel(selectionModel);101 lstAvailableS tyles.setCellRenderer(new StyleSourceCellRenderer());102 this.availableS tylesUrl = availableStylesUrl;99 lstAvailableSources = new JList(availableSourcesModel = new AvailableSourcesListModel(selectionModel)); 100 lstAvailableSources.setSelectionModel(selectionModel); 101 lstAvailableSources.setCellRenderer(new SourceEntryListCellRenderer()); 102 this.availableSourcesUrl = availableSourcesUrl; 103 103 104 104 selectionModel = new DefaultListSelectionModel(); 105 tblActiveS tyles = new JTable(activeStylesModel = new ActiveStylesModel(selectionModel));106 tblActiveS tyles.putClientProperty("terminateEditOnFocusLost", true);107 tblActiveS tyles.setSelectionModel(selectionModel);108 tblActiveS tyles.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);109 tblActiveS tyles.setShowGrid(false);110 tblActiveS tyles.setIntercellSpacing(new Dimension(0, 0));111 tblActiveS tyles.setTableHeader(null);112 tblActiveS tyles.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);113 SourceEntry Renderer sourceEntryRenderer = new SourceEntryRenderer();114 tblActiveS tyles.getColumnModel().getColumn(0).setCellRenderer(sourceEntryRenderer);115 activeS tylesModel.addTableModelListener(new TableModelListener() {105 tblActiveSources = new JTable(activeSourcesModel = new ActiveSourcesModel(selectionModel)); 106 tblActiveSources.putClientProperty("terminateEditOnFocusLost", true); 107 tblActiveSources.setSelectionModel(selectionModel); 108 tblActiveSources.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 109 tblActiveSources.setShowGrid(false); 110 tblActiveSources.setIntercellSpacing(new Dimension(0, 0)); 111 tblActiveSources.setTableHeader(null); 112 tblActiveSources.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 113 SourceEntryTableCellRenderer sourceEntryRenderer = new SourceEntryTableCellRenderer(); 114 tblActiveSources.getColumnModel().getColumn(0).setCellRenderer(sourceEntryRenderer); 115 activeSourcesModel.addTableModelListener(new TableModelListener() { 116 116 // Force swing to show horizontal scrollbars for the JTable 117 117 // Yes, this is a little ugly, but should work 118 118 @Override 119 119 public void tableChanged(TableModelEvent e) { 120 adjustColumnWidth(tblActiveS tyles, 0);120 adjustColumnWidth(tblActiveSources, 0); 121 121 } 122 122 }); 123 activeS tylesModel.setActiveStyles(getInitialSourcesList());123 activeSourcesModel.setActiveSources(getInitialSourcesList()); 124 124 125 final EditActiveS tyleAction editActiveStyleAction = new EditActiveStyleAction();126 tblActiveS tyles.getSelectionModel().addListSelectionListener(editActiveStyleAction);127 tblActiveS tyles.addMouseListener(new MouseAdapter() {125 final EditActiveSourceAction editActiveSourceAction = new EditActiveSourceAction(); 126 tblActiveSources.getSelectionModel().addListSelectionListener(editActiveSourceAction); 127 tblActiveSources.addMouseListener(new MouseAdapter() { 128 128 @Override 129 129 public void mouseClicked(MouseEvent e) { 130 130 if (e.getClickCount() == 2) { 131 int row = tblActiveS tyles.rowAtPoint(e.getPoint());132 if (row < 0 || row >= tblActiveS tyles.getRowCount())131 int row = tblActiveSources.rowAtPoint(e.getPoint()); 132 if (row < 0 || row >= tblActiveSources.getRowCount()) 133 133 return; 134 editActiveS tyleAction.actionPerformed(null);134 editActiveSourceAction.actionPerformed(null); 135 135 } 136 136 } 137 137 }); 138 138 139 RemoveActiveS tylesAction removeActiveStylesAction = new RemoveActiveStylesAction();140 tblActiveS tyles.getSelectionModel().addListSelectionListener(removeActiveStylesAction);141 tblActiveS tyles.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0), "delete");142 tblActiveS tyles.getActionMap().put("delete", removeActiveStylesAction);143 144 ActivateS tylesAction activateStylesAction = new ActivateStylesAction();145 lstAvailableS tyles.addListSelectionListener(activateStylesAction);146 JButton activate = new JButton(activateS tylesAction);139 RemoveActiveSourcesAction removeActiveSourcesAction = new RemoveActiveSourcesAction(); 140 tblActiveSources.getSelectionModel().addListSelectionListener(removeActiveSourcesAction); 141 tblActiveSources.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0), "delete"); 142 tblActiveSources.getActionMap().put("delete", removeActiveSourcesAction); 143 144 ActivateSourcesAction activateSourcesAction = new ActivateSourcesAction(); 145 lstAvailableSources.addListSelectionListener(activateSourcesAction); 146 JButton activate = new JButton(activateSourcesAction); 147 147 148 148 setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); … … 172 172 gbc.insets = new Insets(0, 11, 0, 0); 173 173 174 JScrollPane sp1 = new JScrollPane(lstAvailableS tyles);174 JScrollPane sp1 = new JScrollPane(lstAvailableSources); 175 175 add(sp1, gbc); 176 176 … … 193 193 gbc.fill = GBC.BOTH; 194 194 195 JScrollPane sp = new JScrollPane(tblActiveS tyles);195 JScrollPane sp = new JScrollPane(tblActiveSources); 196 196 add(sp, gbc); 197 197 sp.setColumnHeaderView(null); … … 206 206 sideButtonTB.setBorderPainted(false); 207 207 sideButtonTB.setOpaque(false); 208 sideButtonTB.add(new NewActiveS tyleAction());209 sideButtonTB.add(editActiveS tyleAction);210 sideButtonTB.add(removeActiveS tylesAction);208 sideButtonTB.add(new NewActiveSourceAction()); 209 sideButtonTB.add(editActiveSourceAction); 210 sideButtonTB.add(removeActiveSourcesAction); 211 211 add(sideButtonTB, gbc); 212 212 … … 223 223 bottomLeftTB.setBorderPainted(false); 224 224 bottomLeftTB.setOpaque(false); 225 bottomLeftTB.add(new ReloadS tylesAction(availableStylesUrl));225 bottomLeftTB.add(new ReloadSourcesAction(availableSourcesUrl)); 226 226 middleTB.add(Box.createHorizontalGlue()); 227 227 add(bottomLeftTB, gbc); … … 312 312 * Get the default list of entries (used when resetting the list). 313 313 */ 314 abstract public Collection< StyleSourceInfo> getDefault();314 abstract public Collection<ExtendedSourceEntry> getDefault(); 315 315 316 316 /** … … 328 328 * Identifiers for strings that need to be provided. 329 329 */ 330 protected enum I18nString { AVAILABLE_SOURCES, ACTIVE_SOURCES, NEW_SOURCE_ENTRY ,330 protected enum I18nString { AVAILABLE_SOURCES, ACTIVE_SOURCES, NEW_SOURCE_ENTRY_TOOLTIP, NEW_SOURCE_ENTRY, 331 331 REMOVE_SOURCE_TOOLTIP, EDIT_SOURCE_TOOLTIP, ACTIVATE_TOOLTIP, RELOAD_ALL_AVAILABLE, 332 332 LOADING_SOURCES_FROM, FAILED_TO_LOAD_SOURCES_FROM, FAILED_TO_LOAD_SOURCES_FROM_HELP_TOPIC, … … 348 348 } 349 349 350 public boolean hasActiveS tylesChanged() {350 public boolean hasActiveSourcesChanged() { 351 351 Collection<? extends SourceEntry> prev = getInitialSourcesList(); 352 List<SourceEntry> cur = activeS tylesModel.getStyles();352 List<SourceEntry> cur = activeSourcesModel.getSources(); 353 353 if (prev.size() != cur.size()) 354 354 return true; … … 364 364 } 365 365 366 public Collection<SourceEntry> getActiveS tyles() {367 return activeS tylesModel.getStyles();366 public Collection<SourceEntry> getActiveSources() { 367 return activeSourcesModel.getSources(); 368 368 } 369 369 370 370 public void removeSources(Collection<Integer> idxs) { 371 activeS tylesModel.removeIdxs(idxs);372 } 373 374 protected void reloadAvailableS tyles(String url) {375 Main.worker.submit(new S tyleSourceLoader(url));376 } 377 378 public void initiallyLoadAvailableS tyles() {379 if (!s tylesInitiallyLoaded) {380 reloadAvailableS tyles(this.availableStylesUrl);381 } 382 s tylesInitiallyLoaded = true;383 } 384 385 protected static class AvailableS tylesListModel extends DefaultListModel {386 private ArrayList< StyleSourceInfo> data;371 activeSourcesModel.removeIdxs(idxs); 372 } 373 374 protected void reloadAvailableSources(String url) { 375 Main.worker.submit(new SourceLoader(url)); 376 } 377 378 public void initiallyLoadAvailableSources() { 379 if (!sourcesInitiallyLoaded) { 380 reloadAvailableSources(this.availableSourcesUrl); 381 } 382 sourcesInitiallyLoaded = true; 383 } 384 385 protected static class AvailableSourcesListModel extends DefaultListModel { 386 private ArrayList<ExtendedSourceEntry> data; 387 387 private DefaultListSelectionModel selectionModel; 388 388 389 public AvailableS tylesListModel(DefaultListSelectionModel selectionModel) {390 data = new ArrayList< StyleSourceInfo>();389 public AvailableSourcesListModel(DefaultListSelectionModel selectionModel) { 390 data = new ArrayList<ExtendedSourceEntry>(); 391 391 this.selectionModel = selectionModel; 392 392 } 393 393 394 public void setS tyleSources(List<StyleSourceInfo> styleSources) {394 public void setSources(List<ExtendedSourceEntry> sources) { 395 395 data.clear(); 396 if (s tyleSources != null) {397 data.addAll(s tyleSources);396 if (sources != null) { 397 data.addAll(sources); 398 398 } 399 399 fireContentsChanged(this, 0, data.size()); … … 412 412 413 413 public void deleteSelected() { 414 Iterator< StyleSourceInfo> it = data.iterator();414 Iterator<ExtendedSourceEntry> it = data.iterator(); 415 415 int i=0; 416 416 while(it.hasNext()) { … … 424 424 } 425 425 426 public List< StyleSourceInfo> getSelected() {427 ArrayList< StyleSourceInfo> ret = new ArrayList<StyleSourceInfo>();426 public List<ExtendedSourceEntry> getSelected() { 427 ArrayList<ExtendedSourceEntry> ret = new ArrayList<ExtendedSourceEntry>(); 428 428 for(int i=0; i<data.size();i++) { 429 429 if (selectionModel.isSelectedIndex(i)) { … … 435 435 } 436 436 437 protected static class ActiveS tylesModel extends AbstractTableModel {437 protected static class ActiveSourcesModel extends AbstractTableModel { 438 438 private List<SourceEntry> data; 439 439 private DefaultListSelectionModel selectionModel; 440 440 441 public ActiveS tylesModel(DefaultListSelectionModel selectionModel) {441 public ActiveSourcesModel(DefaultListSelectionModel selectionModel) { 442 442 this.selectionModel = selectionModel; 443 443 this.data = new ArrayList<SourceEntry>(); … … 464 464 @Override 465 465 public void setValueAt(Object aValue, int rowIndex, int columnIndex) { 466 updateStyle(rowIndex, (String)aValue); 467 } 468 469 public void setActiveStyles(Collection<? extends SourceEntry> sources) { 470 //abstract public Collection<? extends StyleSourceEntry> getInitialStyleSources(); 466 updateSource(rowIndex, (String)aValue); 467 } 468 469 public void setActiveSources(Collection<? extends SourceEntry> sources) { 471 470 data.clear(); 472 471 if (sources != null) { … … 476 475 } 477 476 478 public void addS tyle(SourceEntry style) {479 if ( style== null) return;480 data.add( style);477 public void addSource(SourceEntry entry) { 478 if (entry == null) return; 479 data.add(entry); 481 480 fireTableDataChanged(); 482 int idx = data.indexOf( style);481 int idx = data.indexOf(entry); 483 482 if (idx >= 0) { 484 483 selectionModel.setSelectionInterval(idx, idx); … … 486 485 } 487 486 488 public void updateS tyle(int pos, String style) {489 if (s tyle== null) return;487 public void updateSource(int pos, String src) { 488 if (src == null) return; 490 489 if (pos < 0 || pos >= getRowCount()) return; 491 data.get(pos).url = s tyle;490 data.get(pos).url = src; 492 491 fireTableDataChanged(); 493 int idx = data.indexOf(s tyle);492 int idx = data.indexOf(src); 494 493 if (idx >= 0) { 495 494 selectionModel.setSelectionInterval(idx, idx); … … 521 520 } 522 521 523 public void add StylesFromSources(List<StyleSourceInfo> sources) {522 public void addExtendedSourceEntries(List<ExtendedSourceEntry> sources) { 524 523 if (sources == null) return; 525 for ( StyleSourceInfoinfo: sources) {524 for (ExtendedSourceEntry info: sources) { 526 525 data.add(new SourceEntry(info.url, info.name, info.getDisplayName(), true)); 527 526 } 528 527 fireTableDataChanged(); 529 528 selectionModel.clearSelection(); 530 for ( StyleSourceInfoinfo: sources) {529 for (ExtendedSourceEntry info: sources) { 531 530 int pos = data.indexOf(info); 532 531 if (pos >=0) { … … 536 535 } 537 536 538 public List<SourceEntry> getS tyles() {537 public List<SourceEntry> getSources() { 539 538 return new ArrayList<SourceEntry>(data); 540 539 } 541 540 } 542 541 543 public static class StyleSourceInfoextends SourceEntry {542 public static class ExtendedSourceEntry extends SourceEntry { 544 543 public String simpleFileName; 545 544 public String version; … … 548 547 public String description; 549 548 550 public StyleSourceInfo(String simpleFileName, String url) {549 public ExtendedSourceEntry(String simpleFileName, String url) { 551 550 super(url, null, null, true); 552 551 this.simpleFileName = simpleFileName; … … 656 655 JFileChooser fc= new JFileChooser(); 657 656 prepareFileChooser(tfURL.getText(), fc); 658 int ret = fc.showOpenDialog(JOptionPane.getFrameForComponent(S tyleSourceEditor.this));657 int ret = fc.showOpenDialog(JOptionPane.getFrameForComponent(SourceEditor.this)); 659 658 if (ret != JFileChooser.APPROVE_OPTION) 660 659 return; … … 672 671 } 673 672 674 class NewActiveS tyleAction extends AbstractAction {675 public NewActiveS tyleAction() {673 class NewActiveSourceAction extends AbstractAction { 674 public NewActiveSourceAction() { 676 675 putValue(NAME, tr("New")); 677 putValue(SHORT_DESCRIPTION, tr("Add a filename or an URL of an active style"));676 putValue(SHORT_DESCRIPTION, getStr(I18nString.NEW_SOURCE_ENTRY_TOOLTIP)); 678 677 putValue(SMALL_ICON, ImageProvider.get("dialogs", "add")); 679 678 } … … 681 680 public void actionPerformed(ActionEvent evt) { 682 681 EditSourceEntryDialog editEntryDialog = new EditSourceEntryDialog( 683 S tyleSourceEditor.this,682 SourceEditor.this, 684 683 getStr(I18nString.NEW_SOURCE_ENTRY), 685 684 null); 686 685 editEntryDialog.showDialog(); 687 686 if (editEntryDialog.getValue() == 1) { 688 activeS tylesModel.addStyle(new SourceEntry(687 activeSourcesModel.addSource(new SourceEntry( 689 688 editEntryDialog.getURL(), 690 689 null, editEntryDialog.getShortdescription(), true)); 691 activeS tylesModel.fireTableDataChanged();692 } 693 } 694 } 695 696 class RemoveActiveS tylesAction extends AbstractAction implements ListSelectionListener {697 698 public RemoveActiveS tylesAction() {690 activeSourcesModel.fireTableDataChanged(); 691 } 692 } 693 } 694 695 class RemoveActiveSourcesAction extends AbstractAction implements ListSelectionListener { 696 697 public RemoveActiveSourcesAction() { 699 698 putValue(NAME, tr("Remove")); 700 699 putValue(SHORT_DESCRIPTION, getStr(I18nString.REMOVE_SOURCE_TOOLTIP)); … … 704 703 705 704 protected void updateEnabledState() { 706 setEnabled(tblActiveS tyles.getSelectedRowCount() > 0);705 setEnabled(tblActiveSources.getSelectedRowCount() > 0); 707 706 } 708 707 … … 712 711 713 712 public void actionPerformed(ActionEvent e) { 714 activeS tylesModel.removeSelected();715 } 716 } 717 718 class EditActiveS tyleAction extends AbstractAction implements ListSelectionListener {719 public EditActiveS tyleAction() {713 activeSourcesModel.removeSelected(); 714 } 715 } 716 717 class EditActiveSourceAction extends AbstractAction implements ListSelectionListener { 718 public EditActiveSourceAction() { 720 719 putValue(NAME, tr("Edit")); 721 720 putValue(SHORT_DESCRIPTION, getStr(I18nString.EDIT_SOURCE_TOOLTIP)); … … 725 724 726 725 protected void updateEnabledState() { 727 setEnabled(tblActiveS tyles.getSelectedRowCount() == 1);726 setEnabled(tblActiveSources.getSelectedRowCount() == 1); 728 727 } 729 728 … … 733 732 734 733 public void actionPerformed(ActionEvent evt) { 735 int pos = tblActiveS tyles.getSelectedRow();736 if (pos < 0 || pos >= tblActiveS tyles.getRowCount())734 int pos = tblActiveSources.getSelectedRow(); 735 if (pos < 0 || pos >= tblActiveSources.getRowCount()) 737 736 return; 738 737 739 SourceEntry e = activeS tylesModel.getValueAt(pos, 0);738 SourceEntry e = activeSourcesModel.getValueAt(pos, 0); 740 739 741 740 EditSourceEntryDialog editEntryDialog = new EditSourceEntryDialog( 742 S tyleSourceEditor.this, tr("Edit source entry:"), e);741 SourceEditor.this, tr("Edit source entry:"), e); 743 742 editEntryDialog.showDialog(); 744 743 if (editEntryDialog.getValue() == 1) { … … 750 749 } 751 750 e.url = editEntryDialog.getURL(); 752 activeS tylesModel.fireTableCellUpdated(pos, 0);753 } 754 } 755 } 756 757 class ActivateS tylesAction extends AbstractAction implements ListSelectionListener {758 public ActivateS tylesAction() {751 activeSourcesModel.fireTableCellUpdated(pos, 0); 752 } 753 } 754 } 755 756 class ActivateSourcesAction extends AbstractAction implements ListSelectionListener { 757 public ActivateSourcesAction() { 759 758 putValue(SHORT_DESCRIPTION, getStr(I18nString.ACTIVATE_TOOLTIP)); 760 759 putValue(SMALL_ICON, ImageProvider.get("preferences", "activatestyle")); … … 763 762 764 763 protected void updateEnabledState() { 765 setEnabled(lstAvailableS tyles.getSelectedIndices().length > 0);764 setEnabled(lstAvailableSources.getSelectedIndices().length > 0); 766 765 } 767 766 … … 771 770 772 771 public void actionPerformed(ActionEvent e) { 773 List< StyleSourceInfo> styleSources = availableStylesModel.getSelected();774 activeS tylesModel.addStylesFromSources(styleSources);772 List<ExtendedSourceEntry> sources = availableSourcesModel.getSelected(); 773 activeSourcesModel.addExtendedSourceEntries(sources); 775 774 } 776 775 } … … 785 784 786 785 public void actionPerformed(ActionEvent e) { 787 activeS tylesModel.setActiveStyles(getDefault());788 } 789 } 790 791 class ReloadS tylesAction extends AbstractAction {786 activeSourcesModel.setActiveSources(getDefault()); 787 } 788 } 789 790 class ReloadSourcesAction extends AbstractAction { 792 791 private String url; 793 public ReloadS tylesAction(String url) {792 public ReloadSourcesAction(String url) { 794 793 putValue(NAME, tr("Reload")); 795 794 putValue(SHORT_DESCRIPTION, tr(getStr(I18nString.RELOAD_ALL_AVAILABLE), url)); … … 800 799 public void actionPerformed(ActionEvent e) { 801 800 MirroredInputStream.cleanup(url); 802 reloadAvailableS tyles(url);801 reloadAvailableSources(url); 803 802 } 804 803 } … … 835 834 } 836 835 837 public void setIconPaths(Collection<String> styles) {836 public void setIconPaths(Collection<String> paths) { 838 837 data.clear(); 839 if ( styles !=null) {840 data.addAll( styles);838 if (paths !=null) { 839 data.addAll(paths); 841 840 } 842 841 sort(); … … 957 956 } 958 957 959 static class S tyleSourceCellRenderer extends JLabel implements ListCellRenderer {958 static class SourceEntryListCellRenderer extends JLabel implements ListCellRenderer { 960 959 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, 961 960 boolean cellHasFocus) { … … 973 972 setFont(getFont().deriveFont(Font.PLAIN)); 974 973 setOpaque(true); 975 setToolTipText((( StyleSourceInfo) value).getTooltip());974 setToolTipText(((ExtendedSourceEntry) value).getTooltip()); 976 975 return this; 977 976 } 978 977 } 979 978 980 class S tyleSourceLoader extends PleaseWaitRunnable {979 class SourceLoader extends PleaseWaitRunnable { 981 980 private String url; 982 981 private BufferedReader reader; 983 982 private boolean canceled; 984 983 985 public S tyleSourceLoader(String url) {984 public SourceLoader(String url) { 986 985 super(tr(getStr(I18nString.LOADING_SOURCES_FROM), url)); 987 986 this.url = url; … … 1019 1018 @Override 1020 1019 protected void realRun() throws SAXException, IOException, OsmTransferException { 1021 LinkedList< StyleSourceInfo> styles = new LinkedList<StyleSourceInfo>();1020 LinkedList<ExtendedSourceEntry> sources = new LinkedList<ExtendedSourceEntry>(); 1022 1021 String lang = LanguageInfo.getLanguageCodeXML(); 1023 1022 try { 1024 s tyles.addAll(getDefault());1023 sources.addAll(getDefault()); 1025 1024 MirroredInputStream stream = new MirroredInputStream(url); 1026 1025 InputStreamReader r; … … 1033 1032 1034 1033 String line; 1035 StyleSourceInfolast = null;1034 ExtendedSourceEntry last = null; 1036 1035 1037 1036 while ((line = reader.readLine()) != null && !canceled) { … … 1074 1073 Matcher m = Pattern.compile("^(.+);(.+)$").matcher(line); 1075 1074 if (m.matches()) { 1076 s tyles.add(last = new StyleSourceInfo(m.group(1), m.group(2)));1075 sources.add(last = new ExtendedSourceEntry(m.group(1), m.group(2))); 1077 1076 } else { 1078 1077 System.err.println(tr(getStr(I18nString.ILLEGAL_FORMAT_OF_ENTRY), url, line)); … … 1089 1088 return; 1090 1089 } 1091 availableS tylesModel.setStyleSources(styles);1090 availableSourcesModel.setSources(sources); 1092 1091 } 1093 1092 } 1094 1093 1095 class SourceEntry Renderer extends DefaultTableCellRenderer {1094 class SourceEntryTableCellRenderer extends DefaultTableCellRenderer { 1096 1095 @Override 1097 1096 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { … … 1265 1264 JFileChooser fc = getFileChooser(); 1266 1265 prepareFileChooser(tfFileName.getText(), fc); 1267 int ret = fc.showOpenDialog(JOptionPane.getFrameForComponent(S tyleSourceEditor.this));1266 int ret = fc.showOpenDialog(JOptionPane.getFrameForComponent(SourceEditor.this)); 1268 1267 if (ret != JFileChooser.APPROVE_OPTION) 1269 1268 return; … … 1314 1313 } 1315 1314 1316 abstract public Collection< StyleSourceInfo> getDefault();1315 abstract public Collection<ExtendedSourceEntry> getDefault(); 1317 1316 1318 1317 abstract public Collection<String> serialize(SourceEntry entry); -
trunk/src/org/openstreetmap/josm/gui/preferences/TaggingPresetPreference.java
r3796 r3797 28 28 import org.openstreetmap.josm.gui.ExtendedDialog; 29 29 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane.ValidationListener; 30 import org.openstreetmap.josm.gui.preferences.S tyleSourceEditor.StyleSourceInfo;30 import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry; 31 31 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 32 32 import org.openstreetmap.josm.gui.tagging.TaggingPresetMenu; … … 46 46 47 47 public static Collection<TaggingPreset> taggingPresets; 48 private S tyleSourceEditor sources;48 private SourceEditor sources; 49 49 private JCheckBox sortMenu; 50 50 51 51 private ValidationListener validationListener = new ValidationListener() { 52 52 public boolean validatePreferences() { 53 if (sources.hasActiveS tylesChanged()) {53 if (sources.hasActiveSourcesChanged()) { 54 54 List<Integer> sourcesToRemove = new ArrayList<Integer>(); 55 55 int i = -1; 56 56 SOURCES: 57 for (SourceEntry source: sources.getActiveS tyles()) {57 for (SourceEntry source: sources.getActiveSources()) { 58 58 i++; 59 59 boolean canLoad = false; … … 153 153 public void stateChanged(ChangeEvent e) { 154 154 if (gui.mapcontent.getSelectedComponent() == panel) { 155 sources.initiallyLoadAvailableS tyles();155 sources.initiallyLoadAvailableSources(); 156 156 } 157 157 } … … 161 161 } 162 162 163 class TaggingPresetSourceEditor extends S tyleSourceEditor {163 class TaggingPresetSourceEditor extends SourceEditor { 164 164 165 165 final private String iconpref = "taggingpreset.icon.sources"; … … 176 176 @Override 177 177 public boolean finish() { 178 List<SourceEntry> activeStyles = activeS tylesModel.getStyles();178 List<SourceEntry> activeStyles = activeSourcesModel.getSources(); 179 179 180 180 boolean changed = (new PresetPrefMigration()).put(activeStyles); … … 195 195 196 196 @Override 197 public Collection< StyleSourceInfo> getDefault() {197 public Collection<ExtendedSourceEntry> getDefault() { 198 198 return (new PresetPrefMigration()).getDefault(); 199 199 } … … 211 211 case ACTIVE_SOURCES: 212 212 return tr("Active presets:"); 213 case NEW_SOURCE_ENTRY_TOOLTIP: 214 return tr("Add a new preset by entering filename or URL"); 213 215 case NEW_SOURCE_ENTRY: 214 216 return tr("New preset entry:"); … … 287 289 } 288 290 289 public static class PresetPrefMigration extends S tyleSourceEditor.SourcePrefMigration {291 public static class PresetPrefMigration extends SourceEditor.SourcePrefMigration { 290 292 291 293 public PresetPrefMigration() { … … 296 298 297 299 @Override 298 public Collection< StyleSourceInfo> getDefault() {299 StyleSourceInfo i = new StyleSourceInfo("defaultpresets.xml", "resource://data/defaultpresets.xml");300 public Collection<ExtendedSourceEntry> getDefault() { 301 ExtendedSourceEntry i = new ExtendedSourceEntry("defaultpresets.xml", "resource://data/defaultpresets.xml"); 300 302 i.shortdescription = tr("Internal Preset"); 301 303 i.description = tr("The default preset for JOSM");
Note:
See TracChangeset
for help on using the changeset viewer.