Changeset 5050 in josm for trunk/src/org


Ignore:
Timestamp:
2012-03-08T10:04:21+01:00 (8 years ago)
Author:
akks
Message:

UrlLabel class simplification by Zverik, better label layout in VersionInfoPanel (see #7450, #7326)

Location:
trunk/src/org/openstreetmap/josm
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AboutAction.java

    r4982 r5050  
    7171        info.add(GBC.glue(0,10), GBC.eol());
    7272        info.add(new JLabel(tr("Homepage")), GBC.std().insets(10,0,10,0));
    73         info.add(new UrlLabel("http://josm.openstreetmap.de"), GBC.eol().fill(GBC.HORIZONTAL));
     73        info.add(new UrlLabel("http://josm.openstreetmap.de",2), GBC.eol().fill(GBC.HORIZONTAL));
     74        info.add(GBC.glue(0,5), GBC.eol());
    7475        info.add(new JLabel(tr("Bug Reports")), GBC.std().insets(10,0,10,0));
    75         info.add(new UrlLabel("http://josm.openstreetmap.de/newticket"), GBC.eol().fill(GBC.HORIZONTAL));
     76        info.add(new UrlLabel("http://josm.openstreetmap.de/newticket",2), GBC.eol().fill(GBC.HORIZONTAL));
    7677
    7778        JTextArea revision = new JTextArea();
  • trunk/src/org/openstreetmap/josm/actions/Map_Rectifier_WMSmenuAction.java

    r4973 r5050  
    137137            if(!s.url.equals("")) {
    138138                panel.add(serviceBtn, GBC.std());
    139                 panel.add(new UrlLabel(s.url, tr("Visit Homepage")), GBC.eol().anchor(GridBagConstraints.EAST));
     139                panel.add(new UrlLabel(s.url, tr("Visit Homepage")), GBC.eol().anchor(GridBagConstraints.EAST), 2);
    140140            } else {
    141141                panel.add(serviceBtn, GBC.eol().anchor(GridBagConstraints.WEST));
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r4982 r5050  
    1212import java.awt.BasicStroke;
    1313import java.awt.Color;
     14import java.awt.Component;
    1415import java.awt.Cursor;
    1516import java.awt.Graphics2D;
     17import java.awt.KeyboardFocusManager;
    1618import java.awt.MenuItem;
    1719import java.awt.Point;
     
    3941
    4042import java.util.TreeSet;
    41 import javax.swing.AbstractAction;
    42 import javax.swing.JOptionPane;
    43 
    44 import javax.swing.JPopupMenu;
    45 import javax.swing.Timer;
     43import javax.swing.*;
    4644import org.openstreetmap.josm.Main;
    4745import org.openstreetmap.josm.actions.JosmAction;
     
    224222            return;
    225223        if (event instanceof KeyEvent) {
     224            Component focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
     225            Component wantedFocus = Main.map.mapView.getParent();
     226            boolean foundMapViewAncestor=false;
     227            while (focused!=null) {
     228                if (focused==wantedFocus) {
     229                    foundMapViewAncestor=true;
     230                }
     231                focused = focused.getParent();
     232            }
     233            // we accept only events that come from map or toggle dialogs, not from menu and dialogs
     234            if (!foundMapViewAncestor) return;
    226235            processKeyEvent((KeyEvent) event);
    227236        } //  toggle angle snapping
     
    238247    private Timer timer;
    239248    void processKeyEvent(KeyEvent e) {
    240         if (!snappingShortcut.isEvent(e))
     249        if (!snappingShortcut.isEvent(e) && !getShortcut().isEvent(e))
    241250            return;
    242251
     
    261270
    262271    private void doKeyPressEvent(KeyEvent e) {
    263         if (!snappingShortcut.isEvent(e))
    264             return;
    265272        snapHelper.setFixedMode();
    266273        computeHelperLine();
     
    268275    }
    269276    private void doKeyReleaseEvent(KeyEvent e) {
    270         if (!snappingShortcut.isEvent(e))
    271             return;
    272277        snapHelper.unFixOrTurnOff();
    273278        computeHelperLine();
  • trunk/src/org/openstreetmap/josm/gui/history/VersionInfoPanel.java

    r4602 r5050  
    22package org.openstreetmap.josm.gui.history;
    33
     4import java.awt.*;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56
    6 import java.awt.BorderLayout;
    7 import java.awt.FlowLayout;
    8 import java.awt.GridBagConstraints;
    9 import java.awt.GridBagLayout;
    107import java.io.UnsupportedEncodingException;
    118import java.net.URLEncoder;
     
    4845
    4946        pnlUserAndChangeset = new JPanel();
    50         pnlUserAndChangeset.setLayout(new FlowLayout(FlowLayout.LEFT));
    51         lblUser = new UrlLabel();
     47        pnlUserAndChangeset.setLayout(new GridLayout(2,2));
     48        lblUser = new UrlLabel("", 2);
    5249        pnlUserAndChangeset.add(new JLabel(tr("User:")));
    5350        pnlUserAndChangeset.add(lblUser);
    5451        pnlUserAndChangeset.add(new JLabel(tr("Changeset:")));
    55         lblChangeset = new UrlLabel();
     52        lblChangeset = new UrlLabel("", 2);
    5653        pnlUserAndChangeset.add(lblChangeset);
    5754
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r4968 r5050  
    839839                            tr("<html>Upload of unprocessed GPS data as map data is considered harmful.<br>If you want to upload traces, look here:</html>")),
    840840                            GBC.eol());
    841             msg.add(new UrlLabel(tr("http://www.openstreetmap.org/traces")), GBC.eop());
     841            msg.add(new UrlLabel(tr("http://www.openstreetmap.org/traces"),2), GBC.eop());
    842842            if (!ConditionalOptionPaneUtil.showConfirmationDialog("convert_to_data", Main.parent, msg, tr("Warning"),
    843843                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, JOptionPane.OK_OPTION))
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    r5021 r5050  
    854854            }
    855855            if (url != null) {
    856                 p.add(new UrlLabel(url, locale_text), GBC.eol().anchor(GBC.WEST));
     856                p.add(new UrlLabel(url, locale_text, 2), GBC.eol().anchor(GBC.WEST));
    857857            }
    858858            return false;
  • trunk/src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java

    r5013 r5050  
    126126                                    tr("You have encountered an error in JOSM. Before you file a bug report " +
    127127                                            "make sure you have updated to the latest version of JOSM here:")), GBC.eol());
    128                             p.add(new UrlLabel("http://josm.openstreetmap.de/#Download"), GBC.eop().insets(8,0,0,0));
     128                            p.add(new UrlLabel("http://josm.openstreetmap.de/#Download",2), GBC.eop().insets(8,0,0,0));
    129129                            p.add(new JMultilineLabel(
    130130                                    tr("You should also update your plugins. If neither of those help please " +
    131131                                            "file a bug report in our bugtracker using this link:")), GBC.eol());
    132                             p.add(new UrlLabel(url.toString(), "http://josm.openstreetmap.de/josmticket?..."), GBC.eop().insets(8,0,0,0));
     132                            p.add(new UrlLabel(url.toString(), "http://josm.openstreetmap.de/josmticket?...",2), GBC.eop().insets(8,0,0,0));
    133133                            p.add(new JMultilineLabel(
    134134                                    tr("There the error information provided below should already be " +
     
    138138                                    tr("Alternatively, if that does not work you can manually fill in the information " +
    139139                                            "below at this URL:")), GBC.eol());
    140                             p.add(new UrlLabel("http://josm.openstreetmap.de/newticket"), GBC.eop().insets(8,0,0,0));
     140                            p.add(new UrlLabel("http://josm.openstreetmap.de/newticket",2), GBC.eop().insets(8,0,0,0));
    141141                            if (Utils.copyToClipboard(text)) {
    142142                                p.add(new JLabel(tr("(The text has already been copied to your clipboard.)")), GBC.eop());
  • trunk/src/org/openstreetmap/josm/tools/UrlLabel.java

    r5019 r5050  
    22package org.openstreetmap.josm.tools;
    33
     4import java.awt.Cursor;
    45import java.awt.event.MouseEvent;
    56import java.awt.event.MouseListener;
    6 import javax.swing.JEditorPane;
    7 import javax.swing.event.HyperlinkEvent;
    8 import javax.swing.event.HyperlinkListener;
     7import javax.swing.JLabel;
     8import javax.swing.SwingUtilities;
    99import static org.openstreetmap.josm.tools.I18n.tr;
    1010
     
    1212 * Label that contains a clickable link.
    1313 * @author Imi
     14 * 5050: Simplifications by Zverikk included by akks
    1415 */
    15 public class UrlLabel extends JEditorPane implements HyperlinkListener, MouseListener {
     16public class UrlLabel extends JLabel implements MouseListener {
    1617
    1718    private String url = "";
    1819    private String description = "";
     20    private int fontPlus;
    1921
    2022    public UrlLabel() {
    21         addHyperlinkListener(this);
    2223        addMouseListener(this);
    23         setEditable(false);
    24         setOpaque(false);
     24        setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    2525    }
    2626
    2727    public UrlLabel(String url) {
    28         this (url, url);
     28        this (url, url, 0);
     29    }
     30   
     31    public UrlLabel(String url, int fontPlus) {
     32        this (url, url, fontPlus);
    2933    }
    3034
    3135    public UrlLabel(String url, String description) {
     36        this (url, url, 0);
     37    }
     38   
     39    public UrlLabel(String url, String description, int fontPlus) {
    3240        this();
    3341        setUrl(url);
    3442        setDescription(description);
     43        this.fontPlus = fontPlus;
     44        if (fontPlus!=0) setFont(getFont().deriveFont(0, getFont().getSize()+fontPlus));
    3545        refresh();
    3646    }
    3747
    3848    protected void refresh() {
    39         setContentType("text/html");
    4049        if (url != null) {
    4150            setText("<html><a href=\""+url+"\">"+description+"</a></html>");
     
    4453        }
    4554        setToolTipText(String.format("<html>%s<br/>%s</html>",url, tr("Right click = copy to clipboard")));
    46     }
    47 
    48     public void hyperlinkUpdate(HyperlinkEvent e) {
    49         if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
    50             OpenBrowser.displayUrl(url);
    51         }
    5255    }
    5356
     
    7578
    7679    @Override
    77     public void mouseClicked(MouseEvent e) {    }
     80    public void mouseClicked(MouseEvent e) {
     81        if( SwingUtilities.isLeftMouseButton(e) ) {
     82            OpenBrowser.displayUrl(url);
     83        } else if( SwingUtilities.isRightMouseButton(e) ) {
     84            Utils.copyToClipboard(url);
     85        }
     86    }
    7887    @Override
    7988    public void mousePressed(MouseEvent e) {    }
     
    8291    @Override
    8392    public void mouseExited(MouseEvent e) {    }
    84 
    8593    @Override
    86     public void mouseReleased(MouseEvent e) {
    87         if (e.getButton() == MouseEvent.BUTTON3) {
    88             Utils.copyToClipboard(url);
    89         }
    90     }
     94    public void mouseReleased(MouseEvent e) {    }
    9195
    9296}
Note: See TracChangeset for help on using the changeset viewer.