Ignore:
Timestamp:
2010-06-24T22:08:15+02:00 (15 years ago)
Author:
bastik
Message:

minor improvements

Location:
applications/editors/josm/plugins/roadsigns/src/org/openstreetmap/josm/plugins/roadsigns
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/roadsigns/src/org/openstreetmap/josm/plugins/roadsigns/RoadSignInputDialog.java

    r21967 r21995  
    3333import javax.swing.Scrollable;
    3434import javax.swing.SwingConstants;
     35import javax.swing.SwingUtilities;
    3536import javax.swing.border.Border;
    3637import javax.swing.border.EtchedBorder;
    3738import javax.swing.event.DocumentEvent;
    3839import javax.swing.event.DocumentListener;
     40import javax.swing.event.HyperlinkEvent;
     41import javax.swing.event.HyperlinkListener;
    3942import javax.swing.table.AbstractTableModel;
    4043
     
    4952import org.openstreetmap.josm.plugins.roadsigns.Sign.SignParameter;
    5053import org.openstreetmap.josm.plugins.roadsigns.Sign.Tag;
     54import org.openstreetmap.josm.tools.OpenBrowser;
    5155import org.openstreetmap.josm.tools.Pair;
    5256
     
    7478    private JPanel pnlPossibleSupplements;
    7579    private JEditorPane info;
     80    private JScrollPane scrollInfo;
    7681
    7782    public RoadSignInputDialog(List<Sign> signs) {
     
    126131        pnlSignSelection.setLayout(fLayout);
    127132
    128        
    129133        pnlPossibleSigns = new FixedWidthPanel();
    130134        pnlPossibleSupplements = new FixedWidthPanel();
     
    146150        info.setEditable(false);
    147151        info.setContentType("text/html");
    148         info.setText("");
     152        info.setText(" ");
    149153        info.setBackground(this.getBackground());
    150         JScrollPane scroll3 = new JScrollPane(info, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    151         multiSplitPane.add(scroll3, "bottom");
     154        info.addHyperlinkListener(new HyperlinkListener() {
     155            public void hyperlinkUpdate(HyperlinkEvent e) {
     156                if (e == null || e.getURL() == null)
     157                    return;
     158                System.err.println(e.getURL());
     159                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
     160                    OpenBrowser.displayUrl(e.getURL().toString());
     161                }
     162            }
     163        });
     164
     165        scrollInfo = new JScrollPane(info, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
     166        multiSplitPane.add(scrollInfo, "bottom");
    152167
    153168        return multiSplitPane;
     
    162177        for (Sign s : signs) {
    163178            JLabel lbl = new JLabel(s.getIcon());
     179            String tt = "<html>"+s.name;
     180            String ref = s.getDefaultRef();
     181            if (ref != null) {
     182                tt += "  <i><small>("+ref+")</small></i>";
     183            }
     184            tt += "</html>";
     185            lbl.setToolTipText(tt);
    164186            s.label = lbl;
    165187            lbl.addMouseListener(new SignClickListener(s));
     
    621643        @Override
    622644        public void mouseClicked(MouseEvent e) {
     645            info.setText(longText());
     646            /* scroll up again */
     647            SwingUtilities.invokeLater(new Runnable(){
     648                public void run() {
     649                    scrollInfo.getVerticalScrollBar().setValue(0);
     650                }
     651            });
    623652            sel.add(sign);
    624653        }
    625654
    626         @Override
    627         public void mouseEntered(MouseEvent e) {
     655        private String longText() {
    628656            StringBuilder txt = new StringBuilder();
    629             txt.append("<p><b><large>");
    630             txt.append(sign.name);
    631             txt.append("</large></b>");
     657            txt.append(sign.long_name == null ? sign.name : sign.long_name);
    632658            String ref = sign.getDefaultRef();
    633659            if (ref != null) {
    634660                txt.append("  <i><small>("+ref+")</small></i>");
    635661            }
    636             txt.append("</p>");
    637 //            if (sign.long_name != null) {
    638 //                txt.append("<i><smaller>("+sign.long_name+")</smaller></i>");
    639 //            }
    640             info.setText(txt.toString());
    641         }
    642 
    643         @Override
    644         public void mouseExited(MouseEvent e) {
    645             info.setText("");
     662
     663            if (sign.help != null) {
     664                txt.append("<p>");
     665                txt.append(sign.help);
     666                txt.append("</p>");
     667            }
     668
     669            if (sign.wiki != null || sign.loc_wiki != null) {
     670                String wikiPrefix = "http://wiki.openstreetmap.org/wiki/";
     671                txt.append("<p>");
     672                if (sign.loc_wiki != null) {
     673                    String link = wikiPrefix+sign.loc_wiki;
     674                    txt.append("<a href=\""+link+"\">"+link+"</a>");
     675                    txt.append("<br>");
     676                }
     677                if (sign.wiki != null && ! sign.wiki.equals(sign.loc_wiki)) {
     678                    String link = wikiPrefix+sign.wiki;
     679                    txt.append("<a href=\""+link+"\">"+link+"</a>");
     680                }
     681                txt.append("</p>");
     682            }
     683            return txt.toString();
    646684        }
    647685    }
     
    660698        @Override
    661699        public void setBounds(int x, int y, int width, int height) {
    662                         super.setBounds(x, y, getParent().getWidth(), height);
    663                 }
     700            super.setBounds(x, y, getParent().getWidth(), height);
     701        }
    664702
    665703        @Override
    666                 public Dimension getPreferredSize() {
    667                         return new Dimension(getWidth(), getPreferredHeight());
    668                 }
    669 
    670                 public Dimension getPreferredScrollableViewportSize() {
    671                         return super.getPreferredSize();
    672                 }
    673 
    674                 public int getScrollableUnitIncrement( Rectangle visibleRect, int orientation, int direction ) {
     704        public Dimension getPreferredSize() {
     705            return new Dimension(getWidth(), getPreferredHeight());
     706        }
     707
     708        public Dimension getPreferredScrollableViewportSize() {
     709            return super.getPreferredSize();
     710        }
     711
     712        public int getScrollableUnitIncrement( Rectangle visibleRect, int orientation, int direction ) {
    675713            final int FRAC = 20;
    676                         int inc = (orientation == SwingConstants.VERTICAL ? getParent().getHeight() : getParent().getWidth()) / FRAC;
    677                         return Math.max(inc, 1);
    678                 }
    679 
    680                 public int getScrollableBlockIncrement( Rectangle visibleRect, int orientation, int direction ) {
    681                         return orientation == SwingConstants.VERTICAL ? getParent().getHeight() : getParent().getWidth();
    682                 }
    683 
    684                 public boolean getScrollableTracksViewportWidth() {
    685                         return true;
    686                 }
    687 
    688                 public boolean getScrollableTracksViewportHeight() {
    689                         return false;
    690                 }
    691 
    692                 private int getPreferredHeight() {
    693                         int prefH = 0;
     714            int inc = (orientation == SwingConstants.VERTICAL ? getParent().getHeight() : getParent().getWidth()) / FRAC;
     715            return Math.max(inc, 1);
     716        }
     717
     718        public int getScrollableBlockIncrement( Rectangle visibleRect, int orientation, int direction ) {
     719            return orientation == SwingConstants.VERTICAL ? getParent().getHeight() : getParent().getWidth();
     720        }
     721
     722        public boolean getScrollableTracksViewportWidth() {
     723            return true;
     724        }
     725
     726        public boolean getScrollableTracksViewportHeight() {
     727            return false;
     728        }
     729
     730        private int getPreferredHeight() {
     731            int prefH = 0;
    694732            int num = getComponentCount();
    695                         for (int i = 0; i < num; ++i) {
    696                                 Rectangle rect = getComponent(i).getBounds();
    697                                 int h = rect.y + rect.height;
    698                                 if (h > prefH) {
    699                                         prefH = h;
    700                 }
    701                         }
    702                         prefH += ((FlowLayout) getLayout()).getVgap();
    703                         return prefH;
    704                 }
     733            for (int i = 0; i < num; ++i) {
     734                Rectangle rect = getComponent(i).getBounds();
     735                int h = rect.y + rect.height;
     736                if (h > prefH) {
     737                    prefH = h;
     738                }
     739            }
     740            prefH += ((FlowLayout) getLayout()).getVgap();
     741            return prefH;
     742        }
    705743    }
    706744}
  • applications/editors/josm/plugins/roadsigns/src/org/openstreetmap/josm/plugins/roadsigns/RoadSignsPlugin.java

    r21967 r21995  
    3131
    3232public class RoadSignsPlugin extends Plugin {
    33 
    3433    private static boolean presetsLoaded = false;
    3534    public static List<Sign> signs;
     35    static List<String> iconDirs;
    3636
    3737    public RoadSignsPlugin(PluginInformation info) {
     
    6868        presetsLoaded=true;
    6969        List<String> files = new ArrayList<String>(
    70                                    Main.pref.getCollection("plugin.roadsign.sources",
    71                                         Collections.<String>singletonList("resource://data/defaultroadsignpreset.xml")));
     70                Main.pref.getCollection("plugin.roadsign.sources",
     71                    Collections.<String>singletonList("resource://data/defaultroadsignpreset.xml")));
     72        iconDirs = new ArrayList<String>(
     73                Main.pref.getCollection("plugin.roadsign.icon.sources", Collections.<String>emptySet()));
     74
     75        if (Main.pref.getBoolean("plugin.roadsign.use_default_icon_source", true)) {
     76            iconDirs.add("resource://images/");
     77        }
     78
    7279        for (String source : files) {
    7380            try {
  • applications/editors/josm/plugins/roadsigns/src/org/openstreetmap/josm/plugins/roadsigns/RoadSignsReader.java

    r21967 r21995  
    107107                    curSign.isSupplementing = true;
    108108                }
     109
     110                curSign.wiki = atts.getValue("wiki");
     111                curSign.loc_wiki = getLocalized(atts, "wiki");
     112
     113                curSign.help = getLocalized(atts, "help");
    109114
    110115            } else if (curSign != null && qname.equals("tag")) {
  • applications/editors/josm/plugins/roadsigns/src/org/openstreetmap/josm/plugins/roadsigns/Sign.java

    r21967 r21995  
    3030    public List<SignParameter> params = new ArrayList<SignParameter>();
    3131    public boolean isSupplementing;
     32    public String loc_wiki;
     33    public String wiki;
     34    public String help;
    3235
    3336    public JLabel label; // FIXME: don't put gui stuff here
     
    7881    public ImageIcon getIcon() {
    7982        if (icon == null) {
    80             icon = ImageProvider.get(iconURL);
     83            icon = ImageProvider.getIfAvailable(RoadSignsPlugin.iconDirs, "plugin.sign."+id, null, iconURL, null);
    8184        }
    8285        return icon;
Note: See TracChangeset for help on using the changeset viewer.