Ignore:
Timestamp:
2012-11-17T18:19:03+01:00 (11 years ago)
Author:
bastiK
Message:

check property 'min-josm-version' for custom styles and warn user if main version is too low

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r5576 r5586  
    1111import java.awt.GridBagConstraints;
    1212import java.awt.GridBagLayout;
     13import java.awt.Image;
    1314import java.awt.Insets;
    1415import java.awt.Rectangle;
     
    4546import javax.swing.DefaultListModel;
    4647import javax.swing.DefaultListSelectionModel;
     48import javax.swing.Icon;
     49import javax.swing.ImageIcon;
    4750import javax.swing.JButton;
    4851import javax.swing.JCheckBox;
     
    7578import org.openstreetmap.josm.Main;
    7679import org.openstreetmap.josm.actions.ExtensionFileFilter;
     80import org.openstreetmap.josm.data.Version;
    7781import org.openstreetmap.josm.gui.ExtendedDialog;
    7882import org.openstreetmap.josm.gui.HelpAwareOptionPane;
     
    8589import org.openstreetmap.josm.tools.ImageProvider;
    8690import org.openstreetmap.josm.tools.LanguageInfo;
     91import org.openstreetmap.josm.tools.Utils;
    8792import org.xml.sax.SAXException;
    8893
     
    628633        public String link;
    629634        public String description;
     635        public Integer minJosmVersion;
    630636
    631637        public ExtendedSourceEntry(String simpleFileName, String url) {
    632638            super(url, null, null, true);
    633639            this.simpleFileName = simpleFileName;
    634             version = author = link = description = title = null;
    635640        }
    636641
     
    661666            if (version != null) {
    662667                appendRow(s, tr("Version:"), version);
     668            }
     669            if (minJosmVersion != null) {
     670                appendRow(s, tr("Minimum JOSM Version:"), Integer.toString(minJosmVersion));
    663671            }
    664672            return "<html><style>th{text-align:right}td{width:400px}</style>"
     
    925933        public void actionPerformed(ActionEvent e) {
    926934            List<ExtendedSourceEntry> sources = availableSourcesModel.getSelected();
     935            int josmVersion = Version.getInstance().getVersion();
     936            if (josmVersion != Version.JOSM_UNKNOWN_VERSION) {
     937                Collection<String> messages = new ArrayList<String>();
     938                for (ExtendedSourceEntry entry : sources) {
     939                    if (entry.minJosmVersion != null && entry.minJosmVersion > josmVersion) {
     940                        messages.add(tr("Entry ''{0}'' requires JOSM Version {1}. (Currently running: {2})",
     941                                entry.title,
     942                                Integer.toString(entry.minJosmVersion),
     943                                Integer.toString(josmVersion))
     944                        );
     945                    }
     946                }
     947                if (!messages.isEmpty()) {
     948                    ExtendedDialog dlg = new ExtendedDialog(Main.parent, tr("Warning"), new String [] { tr("Cancel"), tr("Continue anyway") });
     949                    dlg.setButtonIcons(new Icon[] {
     950                        ImageProvider.get("cancel"),
     951                        ImageProvider.overlay(
     952                            ImageProvider.get("ok"),
     953                            new ImageIcon(ImageProvider.get("warning-small").getImage().getScaledInstance(12 , 12, Image.SCALE_SMOOTH)),
     954                            ImageProvider.OverlayPosition.SOUTHEAST)
     955                    });
     956                    dlg.setToolTipTexts(new String[] {
     957                        tr("Cancel and return to the previous dialog"),
     958                        tr("Ignore warning and install style anyway")});
     959                    dlg.setContent("<html>" + tr("Some entries have unmet dependencies:") +
     960                            "<br>" + Utils.join("<br>", messages) + "</html>");
     961                    dlg.setIcon(JOptionPane.WARNING_MESSAGE);
     962                    if (dlg.showDialog().getValue() != 2)
     963                        return;
     964                }
     965            }
    927966            activeSourcesModel.addExtendedSourceEntries(sources);
    928967        }
     
    12361275                            } else if ((lang + "description").equals(key)) {
    12371276                                last.description = value;
     1277                            } else if ("min-josm-version".equals(key)) {
     1278                                try {
     1279                                    last.minJosmVersion = Integer.parseInt(value);
     1280                                } catch (NumberFormatException e) {
     1281                                    // ignore
     1282                                }
    12381283                            }
    12391284                        }
Note: See TracChangeset for help on using the changeset viewer.