Changeset 3797 in josm


Ignore:
Timestamp:
2011-01-21T14:11:47+01:00 (13 years ago)
Author:
bastiK
Message:

rename some stuff: StyleSourceEditor is generic editor for both MapPaint styles andd Tagging Presets

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  
    2424import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2525import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
    26 import org.openstreetmap.josm.gui.preferences.StyleSourceEditor.StyleSourceInfo;
     26import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry;
    2727import org.openstreetmap.josm.tools.GBC;
    2828
    2929public class MapPaintPreference implements PreferenceSetting {
    30     private StyleSourceEditor sources;
     30    private SourceEditor sources;
    3131    private JCheckBox enableIconDefault;
    3232    private JCheckBox enableDefault;
     
    8181                    public void stateChanged(ChangeEvent e) {
    8282                        if (gui.mapcontent.getSelectedComponent() == panel) {
    83                             sources.initiallyLoadAvailableStyles();
     83                            sources.initiallyLoadAvailableSources();
    8484                        }
    8585                    }
     
    8888    }
    8989
    90     class MapPaintSourceEditor extends StyleSourceEditor {
     90    class MapPaintSourceEditor extends SourceEditor {
    9191
    9292        final private String iconpref = "mappaint.icon.sources";
     
    103103        @Override
    104104        public boolean finish() {
    105             List<SourceEntry> activeStyles = activeStylesModel.getStyles();
     105            List<SourceEntry> activeStyles = activeSourcesModel.getSources();
    106106
    107107            boolean changed = (new MapPaintPrefMigration()).put(activeStyles);
     
    122122
    123123        @Override
    124         public Collection<StyleSourceInfo> getDefault() {
     124        public Collection<ExtendedSourceEntry> getDefault() {
    125125            return (new MapPaintPrefMigration()).getDefault();
    126126        }
     
    138138                case ACTIVE_SOURCES:
    139139                    return tr("Active styles:");
     140                case NEW_SOURCE_ENTRY_TOOLTIP:
     141                     return tr("Add a new style by entering filename or URL");
    140142                case NEW_SOURCE_ENTRY:
    141143                    return tr("New style entry:");
     
    194196    }
    195197
    196     public static class MapPaintPrefMigration extends StyleSourceEditor.SourcePrefMigration {
     198    public static class MapPaintPrefMigration extends SourceEditor.SourcePrefMigration {
    197199
    198200        public MapPaintPrefMigration() {
     
    203205
    204206        @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");
    207209            i.name = "standard";
    208210            i.shortdescription = tr("Internal Style");
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r3796 r3797  
    7979import org.xml.sax.SAXException;
    8080
    81 public abstract class StyleSourceEditor extends JPanel {
    82 
    83     protected JTable tblActiveStyles;
    84     protected ActiveStylesModel activeStylesModel;
    85     protected JList lstAvailableStyles;
    86     protected AvailableStylesListModel availableStylesModel;
     81public abstract class SourceEditor extends JPanel {
     82
     83    protected JTable tblActiveSources;
     84    protected ActiveSourcesModel activeSourcesModel;
     85    protected JList lstAvailableSources;
     86    protected AvailableSourcesListModel availableSourcesModel;
    8787    protected JTable tblIconPaths = null;
    8888    protected IconPathTableModel iconPathsModel;
    89     protected boolean stylesInitiallyLoaded;
    90     protected String availableStylesUrl;
     89    protected boolean sourcesInitiallyLoaded;
     90    protected String availableSourcesUrl;
    9191
    9292    /**
    9393     * constructor
    94      * @param availableStylesUrl the URL to the list of available style sources
     94     * @param availableSourcesUrl the URL to the list of available sources
    9595     */
    96     public StyleSourceEditor(final String availableStylesUrl) {
     96    public SourceEditor(final String availableSourcesUrl) {
    9797
    9898        DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
    99         lstAvailableStyles = new JList(availableStylesModel = new AvailableStylesListModel(selectionModel));
    100         lstAvailableStyles.setSelectionModel(selectionModel);
    101         lstAvailableStyles.setCellRenderer(new StyleSourceCellRenderer());
    102         this.availableStylesUrl = availableStylesUrl;
     99        lstAvailableSources = new JList(availableSourcesModel = new AvailableSourcesListModel(selectionModel));
     100        lstAvailableSources.setSelectionModel(selectionModel);
     101        lstAvailableSources.setCellRenderer(new SourceEntryListCellRenderer());
     102        this.availableSourcesUrl = availableSourcesUrl;
    103103
    104104        selectionModel = new DefaultListSelectionModel();
    105         tblActiveStyles = new JTable(activeStylesModel = new ActiveStylesModel(selectionModel));
    106         tblActiveStyles.putClientProperty("terminateEditOnFocusLost", true);
    107         tblActiveStyles.setSelectionModel(selectionModel);
    108         tblActiveStyles.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    109         tblActiveStyles.setShowGrid(false);
    110         tblActiveStyles.setIntercellSpacing(new Dimension(0, 0));
    111         tblActiveStyles.setTableHeader(null);
    112         tblActiveStyles.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    113         SourceEntryRenderer sourceEntryRenderer = new SourceEntryRenderer();
    114         tblActiveStyles.getColumnModel().getColumn(0).setCellRenderer(sourceEntryRenderer);
    115         activeStylesModel.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() {
    116116            // Force swing to show horizontal scrollbars for the JTable
    117117            // Yes, this is a little ugly, but should work
    118118            @Override
    119119            public void tableChanged(TableModelEvent e) {
    120                 adjustColumnWidth(tblActiveStyles, 0);
     120                adjustColumnWidth(tblActiveSources, 0);
    121121            }
    122122        });
    123         activeStylesModel.setActiveStyles(getInitialSourcesList());
     123        activeSourcesModel.setActiveSources(getInitialSourcesList());
    124124       
    125         final EditActiveStyleAction editActiveStyleAction = new EditActiveStyleAction();
    126         tblActiveStyles.getSelectionModel().addListSelectionListener(editActiveStyleAction);
    127         tblActiveStyles.addMouseListener(new MouseAdapter() {
     125        final EditActiveSourceAction editActiveSourceAction = new EditActiveSourceAction();
     126        tblActiveSources.getSelectionModel().addListSelectionListener(editActiveSourceAction);
     127        tblActiveSources.addMouseListener(new MouseAdapter() {
    128128            @Override
    129129            public void mouseClicked(MouseEvent e) {
    130130                if (e.getClickCount() == 2) {
    131                     int row = tblActiveStyles.rowAtPoint(e.getPoint());
    132                     if (row < 0 || row >= tblActiveStyles.getRowCount())
     131                    int row = tblActiveSources.rowAtPoint(e.getPoint());
     132                    if (row < 0 || row >= tblActiveSources.getRowCount())
    133133                        return;
    134                     editActiveStyleAction.actionPerformed(null);
     134                    editActiveSourceAction.actionPerformed(null);
    135135                }
    136136            }
    137137        });
    138138
    139         RemoveActiveStylesAction removeActiveStylesAction = new RemoveActiveStylesAction();
    140         tblActiveStyles.getSelectionModel().addListSelectionListener(removeActiveStylesAction);
    141         tblActiveStyles.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0), "delete");
    142         tblActiveStyles.getActionMap().put("delete", removeActiveStylesAction);
    143 
    144         ActivateStylesAction activateStylesAction = new ActivateStylesAction();
    145         lstAvailableStyles.addListSelectionListener(activateStylesAction);
    146         JButton activate = new JButton(activateStylesAction);
     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);
    147147
    148148        setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
     
    172172        gbc.insets = new Insets(0, 11, 0, 0);
    173173
    174         JScrollPane sp1 = new JScrollPane(lstAvailableStyles);
     174        JScrollPane sp1 = new JScrollPane(lstAvailableSources);
    175175        add(sp1, gbc);
    176176
     
    193193        gbc.fill = GBC.BOTH;
    194194
    195         JScrollPane sp = new JScrollPane(tblActiveStyles);
     195        JScrollPane sp = new JScrollPane(tblActiveSources);
    196196        add(sp, gbc);
    197197        sp.setColumnHeaderView(null);
     
    206206        sideButtonTB.setBorderPainted(false);
    207207        sideButtonTB.setOpaque(false);
    208         sideButtonTB.add(new NewActiveStyleAction());
    209         sideButtonTB.add(editActiveStyleAction);
    210         sideButtonTB.add(removeActiveStylesAction);
     208        sideButtonTB.add(new NewActiveSourceAction());
     209        sideButtonTB.add(editActiveSourceAction);
     210        sideButtonTB.add(removeActiveSourcesAction);
    211211        add(sideButtonTB, gbc);
    212212
     
    223223        bottomLeftTB.setBorderPainted(false);
    224224        bottomLeftTB.setOpaque(false);
    225         bottomLeftTB.add(new ReloadStylesAction(availableStylesUrl));
     225        bottomLeftTB.add(new ReloadSourcesAction(availableSourcesUrl));
    226226        middleTB.add(Box.createHorizontalGlue());
    227227        add(bottomLeftTB, gbc);
     
    312312     * Get the default list of entries (used when resetting the list).
    313313     */
    314     abstract public Collection<StyleSourceInfo> getDefault();
     314    abstract public Collection<ExtendedSourceEntry> getDefault();
    315315
    316316    /**
     
    328328     * Identifiers for strings that need to be provided.
    329329     */
    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,
    331331            REMOVE_SOURCE_TOOLTIP, EDIT_SOURCE_TOOLTIP, ACTIVATE_TOOLTIP, RELOAD_ALL_AVAILABLE,
    332332            LOADING_SOURCES_FROM, FAILED_TO_LOAD_SOURCES_FROM, FAILED_TO_LOAD_SOURCES_FROM_HELP_TOPIC,
     
    348348    }
    349349
    350     public boolean hasActiveStylesChanged() {
     350    public boolean hasActiveSourcesChanged() {
    351351        Collection<? extends SourceEntry> prev = getInitialSourcesList();
    352         List<SourceEntry> cur = activeStylesModel.getStyles();
     352        List<SourceEntry> cur = activeSourcesModel.getSources();
    353353        if (prev.size() != cur.size())
    354354            return true;
     
    364364    }
    365365
    366     public Collection<SourceEntry> getActiveStyles() {
    367         return activeStylesModel.getStyles();
     366    public Collection<SourceEntry> getActiveSources() {
     367        return activeSourcesModel.getSources();
    368368    }
    369369
    370370    public void removeSources(Collection<Integer> idxs) {
    371         activeStylesModel.removeIdxs(idxs);
    372     }
    373 
    374     protected void reloadAvailableStyles(String url) {
    375         Main.worker.submit(new StyleSourceLoader(url));
    376     }
    377 
    378     public void initiallyLoadAvailableStyles() {
    379         if (!stylesInitiallyLoaded) {
    380             reloadAvailableStyles(this.availableStylesUrl);
    381         }
    382         stylesInitiallyLoaded = true;
    383     }
    384 
    385     protected static class AvailableStylesListModel 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;
    387387        private DefaultListSelectionModel selectionModel;
    388388
    389         public AvailableStylesListModel(DefaultListSelectionModel selectionModel) {
    390             data = new ArrayList<StyleSourceInfo>();
     389        public AvailableSourcesListModel(DefaultListSelectionModel selectionModel) {
     390            data = new ArrayList<ExtendedSourceEntry>();
    391391            this.selectionModel = selectionModel;
    392392        }
    393393
    394         public void setStyleSources(List<StyleSourceInfo> styleSources) {
     394        public void setSources(List<ExtendedSourceEntry> sources) {
    395395            data.clear();
    396             if (styleSources != null) {
    397                 data.addAll(styleSources);
     396            if (sources != null) {
     397                data.addAll(sources);
    398398            }
    399399            fireContentsChanged(this, 0, data.size());
     
    412412
    413413        public void deleteSelected() {
    414             Iterator<StyleSourceInfo> it = data.iterator();
     414            Iterator<ExtendedSourceEntry> it = data.iterator();
    415415            int i=0;
    416416            while(it.hasNext()) {
     
    424424        }
    425425
    426         public List<StyleSourceInfo> getSelected() {
    427             ArrayList<StyleSourceInfo> ret = new ArrayList<StyleSourceInfo>();
     426        public List<ExtendedSourceEntry> getSelected() {
     427            ArrayList<ExtendedSourceEntry> ret = new ArrayList<ExtendedSourceEntry>();
    428428            for(int i=0; i<data.size();i++) {
    429429                if (selectionModel.isSelectedIndex(i)) {
     
    435435    }
    436436
    437     protected static class ActiveStylesModel extends AbstractTableModel {
     437    protected static class ActiveSourcesModel extends AbstractTableModel {
    438438        private List<SourceEntry> data;
    439439        private DefaultListSelectionModel selectionModel;
    440440
    441         public ActiveStylesModel(DefaultListSelectionModel selectionModel) {
     441        public ActiveSourcesModel(DefaultListSelectionModel selectionModel) {
    442442            this.selectionModel = selectionModel;
    443443            this.data = new ArrayList<SourceEntry>();
     
    464464        @Override
    465465        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) {
    471470            data.clear();
    472471            if (sources != null) {
     
    476475        }
    477476
    478         public void addStyle(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);
    481480            fireTableDataChanged();
    482             int idx = data.indexOf(style);
     481            int idx = data.indexOf(entry);
    483482            if (idx >= 0) {
    484483                selectionModel.setSelectionInterval(idx, idx);
     
    486485        }
    487486
    488         public void updateStyle(int pos, String style) {
    489             if (style == null) return;
     487        public void updateSource(int pos, String src) {
     488            if (src == null) return;
    490489            if (pos < 0 || pos >= getRowCount()) return;
    491             data.get(pos).url = style;
     490            data.get(pos).url = src;
    492491            fireTableDataChanged();
    493             int idx = data.indexOf(style);
     492            int idx = data.indexOf(src);
    494493            if (idx >= 0) {
    495494                selectionModel.setSelectionInterval(idx, idx);
     
    521520        }
    522521
    523         public void addStylesFromSources(List<StyleSourceInfo> sources) {
     522        public void addExtendedSourceEntries(List<ExtendedSourceEntry> sources) {
    524523            if (sources == null) return;
    525             for (StyleSourceInfo info: sources) {
     524            for (ExtendedSourceEntry info: sources) {
    526525                data.add(new SourceEntry(info.url, info.name, info.getDisplayName(), true));
    527526            }
    528527            fireTableDataChanged();
    529528            selectionModel.clearSelection();
    530             for (StyleSourceInfo info: sources) {
     529            for (ExtendedSourceEntry info: sources) {
    531530                int pos = data.indexOf(info);
    532531                if (pos >=0) {
     
    536535        }
    537536
    538         public List<SourceEntry> getStyles() {
     537        public List<SourceEntry> getSources() {
    539538            return new ArrayList<SourceEntry>(data);
    540539        }
    541540    }
    542541
    543     public static class StyleSourceInfo extends SourceEntry {
     542    public static class ExtendedSourceEntry extends SourceEntry {
    544543        public String simpleFileName;
    545544        public String version;
     
    548547        public String description;
    549548
    550         public StyleSourceInfo(String simpleFileName, String url) {
     549        public ExtendedSourceEntry(String simpleFileName, String url) {
    551550            super(url, null, null, true);
    552551            this.simpleFileName = simpleFileName;
     
    656655                JFileChooser fc= new JFileChooser();
    657656                prepareFileChooser(tfURL.getText(), fc);
    658                 int ret = fc.showOpenDialog(JOptionPane.getFrameForComponent(StyleSourceEditor.this));
     657                int ret = fc.showOpenDialog(JOptionPane.getFrameForComponent(SourceEditor.this));
    659658                if (ret != JFileChooser.APPROVE_OPTION)
    660659                    return;
     
    672671    }
    673672
    674     class NewActiveStyleAction extends AbstractAction {
    675         public NewActiveStyleAction() {
     673    class NewActiveSourceAction extends AbstractAction {
     674        public NewActiveSourceAction() {
    676675            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));
    678677            putValue(SMALL_ICON, ImageProvider.get("dialogs", "add"));
    679678        }
     
    681680        public void actionPerformed(ActionEvent evt) {
    682681            EditSourceEntryDialog editEntryDialog = new EditSourceEntryDialog(
    683                     StyleSourceEditor.this,
     682                    SourceEditor.this,
    684683                    getStr(I18nString.NEW_SOURCE_ENTRY),
    685684                    null);
    686685            editEntryDialog.showDialog();
    687686            if (editEntryDialog.getValue() == 1) {
    688                 activeStylesModel.addStyle(new SourceEntry(
     687                activeSourcesModel.addSource(new SourceEntry(
    689688                        editEntryDialog.getURL(),
    690689                        null, editEntryDialog.getShortdescription(), true));
    691                 activeStylesModel.fireTableDataChanged();
    692             }
    693         }
    694     }
    695 
    696     class RemoveActiveStylesAction extends AbstractAction implements ListSelectionListener {
    697 
    698         public RemoveActiveStylesAction() {
     690                activeSourcesModel.fireTableDataChanged();
     691            }
     692        }
     693    }
     694
     695    class RemoveActiveSourcesAction extends AbstractAction implements ListSelectionListener {
     696
     697        public RemoveActiveSourcesAction() {
    699698            putValue(NAME, tr("Remove"));
    700699            putValue(SHORT_DESCRIPTION, getStr(I18nString.REMOVE_SOURCE_TOOLTIP));
     
    704703
    705704        protected void updateEnabledState() {
    706             setEnabled(tblActiveStyles.getSelectedRowCount() > 0);
     705            setEnabled(tblActiveSources.getSelectedRowCount() > 0);
    707706        }
    708707
     
    712711
    713712        public void actionPerformed(ActionEvent e) {
    714             activeStylesModel.removeSelected();
    715         }
    716     }
    717 
    718     class EditActiveStyleAction extends AbstractAction implements ListSelectionListener {
    719         public EditActiveStyleAction() {
     713            activeSourcesModel.removeSelected();
     714        }
     715    }
     716
     717    class EditActiveSourceAction extends AbstractAction implements ListSelectionListener {
     718        public EditActiveSourceAction() {
    720719            putValue(NAME, tr("Edit"));
    721720            putValue(SHORT_DESCRIPTION, getStr(I18nString.EDIT_SOURCE_TOOLTIP));
     
    725724
    726725        protected void updateEnabledState() {
    727             setEnabled(tblActiveStyles.getSelectedRowCount() == 1);
     726            setEnabled(tblActiveSources.getSelectedRowCount() == 1);
    728727        }
    729728
     
    733732
    734733        public void actionPerformed(ActionEvent evt) {
    735             int pos = tblActiveStyles.getSelectedRow();
    736             if (pos < 0 || pos >= tblActiveStyles.getRowCount())
     734            int pos = tblActiveSources.getSelectedRow();
     735            if (pos < 0 || pos >= tblActiveSources.getRowCount())
    737736                return;
    738737
    739             SourceEntry e = activeStylesModel.getValueAt(pos, 0);
     738            SourceEntry e = activeSourcesModel.getValueAt(pos, 0);
    740739
    741740            EditSourceEntryDialog editEntryDialog = new EditSourceEntryDialog(
    742                     StyleSourceEditor.this, tr("Edit source entry:"), e);
     741                    SourceEditor.this, tr("Edit source entry:"), e);
    743742            editEntryDialog.showDialog();
    744743            if (editEntryDialog.getValue() == 1) {
     
    750749                }
    751750                e.url = editEntryDialog.getURL();
    752                 activeStylesModel.fireTableCellUpdated(pos, 0);
    753             }
    754         }
    755     }
    756 
    757     class ActivateStylesAction extends AbstractAction implements ListSelectionListener {
    758         public ActivateStylesAction() {
     751                activeSourcesModel.fireTableCellUpdated(pos, 0);
     752            }
     753        }
     754    }
     755
     756    class ActivateSourcesAction extends AbstractAction implements ListSelectionListener {
     757        public ActivateSourcesAction() {
    759758            putValue(SHORT_DESCRIPTION, getStr(I18nString.ACTIVATE_TOOLTIP));
    760759            putValue(SMALL_ICON, ImageProvider.get("preferences", "activatestyle"));
     
    763762
    764763        protected void updateEnabledState() {
    765             setEnabled(lstAvailableStyles.getSelectedIndices().length > 0);
     764            setEnabled(lstAvailableSources.getSelectedIndices().length > 0);
    766765        }
    767766
     
    771770
    772771        public void actionPerformed(ActionEvent e) {
    773             List<StyleSourceInfo> styleSources = availableStylesModel.getSelected();
    774             activeStylesModel.addStylesFromSources(styleSources);
     772            List<ExtendedSourceEntry> sources = availableSourcesModel.getSelected();
     773            activeSourcesModel.addExtendedSourceEntries(sources);
    775774        }
    776775    }
     
    785784
    786785        public void actionPerformed(ActionEvent e) {
    787             activeStylesModel.setActiveStyles(getDefault());
    788         }
    789     }
    790 
    791     class ReloadStylesAction extends AbstractAction {
     786            activeSourcesModel.setActiveSources(getDefault());
     787        }
     788    }
     789
     790    class ReloadSourcesAction extends AbstractAction {
    792791        private String url;
    793         public ReloadStylesAction(String url) {
     792        public ReloadSourcesAction(String url) {
    794793            putValue(NAME, tr("Reload"));
    795794            putValue(SHORT_DESCRIPTION, tr(getStr(I18nString.RELOAD_ALL_AVAILABLE), url));
     
    800799        public void actionPerformed(ActionEvent e) {
    801800            MirroredInputStream.cleanup(url);
    802             reloadAvailableStyles(url);
     801            reloadAvailableSources(url);
    803802        }
    804803    }
     
    835834        }
    836835
    837         public void setIconPaths(Collection<String> styles) {
     836        public void setIconPaths(Collection<String> paths) {
    838837            data.clear();
    839             if (styles !=null) {
    840                 data.addAll(styles);
     838            if (paths !=null) {
     839                data.addAll(paths);
    841840            }
    842841            sort();
     
    957956    }
    958957
    959     static class StyleSourceCellRenderer extends JLabel implements ListCellRenderer {
     958    static class SourceEntryListCellRenderer extends JLabel implements ListCellRenderer {
    960959        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
    961960                boolean cellHasFocus) {
     
    973972            setFont(getFont().deriveFont(Font.PLAIN));
    974973            setOpaque(true);
    975             setToolTipText(((StyleSourceInfo) value).getTooltip());
     974            setToolTipText(((ExtendedSourceEntry) value).getTooltip());
    976975            return this;
    977976        }
    978977    }
    979978
    980     class StyleSourceLoader extends PleaseWaitRunnable {
     979    class SourceLoader extends PleaseWaitRunnable {
    981980        private String url;
    982981        private BufferedReader reader;
    983982        private boolean canceled;
    984983
    985         public StyleSourceLoader(String url) {
     984        public SourceLoader(String url) {
    986985            super(tr(getStr(I18nString.LOADING_SOURCES_FROM), url));
    987986            this.url = url;
     
    10191018        @Override
    10201019        protected void realRun() throws SAXException, IOException, OsmTransferException {
    1021             LinkedList<StyleSourceInfo> styles = new LinkedList<StyleSourceInfo>();
     1020            LinkedList<ExtendedSourceEntry> sources = new LinkedList<ExtendedSourceEntry>();
    10221021            String lang = LanguageInfo.getLanguageCodeXML();
    10231022            try {
    1024                 styles.addAll(getDefault());
     1023                sources.addAll(getDefault());
    10251024                MirroredInputStream stream = new MirroredInputStream(url);
    10261025                InputStreamReader r;
     
    10331032
    10341033                String line;
    1035                 StyleSourceInfo last = null;
     1034                ExtendedSourceEntry last = null;
    10361035
    10371036                while ((line = reader.readLine()) != null && !canceled) {
     
    10741073                        Matcher m = Pattern.compile("^(.+);(.+)$").matcher(line);
    10751074                        if (m.matches()) {
    1076                             styles.add(last = new StyleSourceInfo(m.group(1), m.group(2)));
     1075                            sources.add(last = new ExtendedSourceEntry(m.group(1), m.group(2)));
    10771076                        } else {
    10781077                            System.err.println(tr(getStr(I18nString.ILLEGAL_FORMAT_OF_ENTRY), url, line));
     
    10891088                return;
    10901089            }
    1091             availableStylesModel.setStyleSources(styles);
     1090            availableSourcesModel.setSources(sources);
    10921091        }
    10931092    }
    10941093   
    1095     class SourceEntryRenderer extends DefaultTableCellRenderer {
     1094    class SourceEntryTableCellRenderer extends DefaultTableCellRenderer {
    10961095        @Override
    10971096        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
     
    12651264                JFileChooser fc = getFileChooser();
    12661265                prepareFileChooser(tfFileName.getText(), fc);
    1267                 int ret = fc.showOpenDialog(JOptionPane.getFrameForComponent(StyleSourceEditor.this));
     1266                int ret = fc.showOpenDialog(JOptionPane.getFrameForComponent(SourceEditor.this));
    12681267                if (ret != JFileChooser.APPROVE_OPTION)
    12691268                    return;
     
    13141313        }
    13151314
    1316         abstract public Collection<StyleSourceInfo> getDefault();
     1315        abstract public Collection<ExtendedSourceEntry> getDefault();
    13171316
    13181317        abstract public Collection<String> serialize(SourceEntry entry);
  • trunk/src/org/openstreetmap/josm/gui/preferences/TaggingPresetPreference.java

    r3796 r3797  
    2828import org.openstreetmap.josm.gui.ExtendedDialog;
    2929import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane.ValidationListener;
    30 import org.openstreetmap.josm.gui.preferences.StyleSourceEditor.StyleSourceInfo;
     30import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry;
    3131import org.openstreetmap.josm.gui.tagging.TaggingPreset;
    3232import org.openstreetmap.josm.gui.tagging.TaggingPresetMenu;
     
    4646
    4747    public static Collection<TaggingPreset> taggingPresets;
    48     private StyleSourceEditor sources;
     48    private SourceEditor sources;
    4949    private JCheckBox sortMenu;
    5050
    5151    private ValidationListener validationListener = new ValidationListener() {
    5252        public boolean validatePreferences() {
    53             if (sources.hasActiveStylesChanged()) {
     53            if (sources.hasActiveSourcesChanged()) {
    5454                List<Integer> sourcesToRemove = new ArrayList<Integer>();
    5555                int i = -1;
    5656                SOURCES:
    57                     for (SourceEntry source: sources.getActiveStyles()) {
     57                    for (SourceEntry source: sources.getActiveSources()) {
    5858                        i++;
    5959                        boolean canLoad = false;
     
    153153                    public void stateChanged(ChangeEvent e) {
    154154                        if (gui.mapcontent.getSelectedComponent() == panel) {
    155                             sources.initiallyLoadAvailableStyles();
     155                            sources.initiallyLoadAvailableSources();
    156156                        }
    157157                    }
     
    161161    }
    162162
    163     class TaggingPresetSourceEditor extends StyleSourceEditor {
     163    class TaggingPresetSourceEditor extends SourceEditor {
    164164
    165165        final private String iconpref = "taggingpreset.icon.sources";
     
    176176        @Override
    177177        public boolean finish() {
    178             List<SourceEntry> activeStyles = activeStylesModel.getStyles();
     178            List<SourceEntry> activeStyles = activeSourcesModel.getSources();
    179179
    180180            boolean changed = (new PresetPrefMigration()).put(activeStyles);
     
    195195
    196196        @Override
    197         public Collection<StyleSourceInfo> getDefault() {
     197        public Collection<ExtendedSourceEntry> getDefault() {
    198198            return (new PresetPrefMigration()).getDefault();
    199199        }
     
    211211                case ACTIVE_SOURCES:
    212212                    return tr("Active presets:");
     213                case NEW_SOURCE_ENTRY_TOOLTIP:
     214                     return tr("Add a new preset by entering filename or URL");
    213215                case NEW_SOURCE_ENTRY:
    214216                    return tr("New preset entry:");
     
    287289    }
    288290
    289     public static class PresetPrefMigration extends StyleSourceEditor.SourcePrefMigration {
     291    public static class PresetPrefMigration extends SourceEditor.SourcePrefMigration {
    290292
    291293        public PresetPrefMigration() {
     
    296298
    297299        @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");
    300302            i.shortdescription = tr("Internal Preset");
    301303            i.description = tr("The default preset for JOSM");
Note: See TracChangeset for help on using the changeset viewer.