Changeset 6836 in josm for trunk/src


Ignore:
Timestamp:
2014-02-11T01:23:37+01:00 (10 years ago)
Author:
Don-vip
Message:

fix #9659 - prefix changeset and source by "c:" or "s:" to distinguish them in history dialog

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/history/VersionInfoPanel.java

    r6827 r6836  
    2929import org.openstreetmap.josm.gui.widgets.UrlLabel;
    3030import org.openstreetmap.josm.tools.CheckParameterUtil;
     31import org.openstreetmap.josm.tools.GBC;
     32import org.openstreetmap.josm.tools.Utils;
    3133
    3234/**
     
    4143    private UrlLabel lblUser;
    4244    private UrlLabel lblChangeset;
     45    private JPanel pnlChangesetComment;
     46    private JPanel pnlChangesetSource;
     47    private JLabel lblComment;
     48    private JLabel lblSource;
    4349    private JTextArea lblChangesetComment;
    4450    private JTextArea lblChangesetSource;
     
    5460    }
    5561
     62    protected static JLabel buildLabel(String text, String tooltip, JTextArea textArea) {
     63        // We need text field to be a JTextArea for line wrapping but cannot put HTML code in here,
     64        // so create a separate JLabel with same characteristics (margin, font)
     65        JLabel lbl = new JLabel("<html><p style='margin-top:"+textArea.getMargin().top+"'>"+text+"</html>");
     66        lbl.setFont(textArea.getFont());
     67        lbl.setToolTipText(tooltip);
     68        return lbl;
     69    }
     70
     71    protected static JPanel buildTextPanel(JLabel label, JTextArea textArea) {
     72        JPanel pnl = new JPanel(new GridBagLayout());
     73        pnl.add(label, GBC.std().anchor(GBC.NORTHWEST));
     74        pnl.add(textArea, GBC.eol().fill());
     75        return pnl;
     76    }
     77
    5678    protected void build() {
    57         JPanel pnl1 = new JPanel();
    58         pnl1.setLayout(new BorderLayout());
     79        JPanel pnl1 = new JPanel(new BorderLayout());
    5980        lblInfo = new JMultilineLabel("");
    6081        pnl1.add(lblInfo, BorderLayout.CENTER);
    6182
    62         JPanel pnlUserAndChangeset = new JPanel();
    63         pnlUserAndChangeset.setLayout(new GridLayout(2,2));
     83        JPanel pnlUserAndChangeset = new JPanel(new GridLayout(2,2));
    6484        lblUser = new UrlLabel("", 2);
    6585        pnlUserAndChangeset.add(new JLabel(tr("User:")));
     
    7191        lblChangesetComment = buildTextArea(tr("Changeset comment"));
    7292        lblChangesetSource = buildTextArea(tr("Changeset source"));
     93       
     94        lblComment = buildLabel(/*I18n: comment*/tr("<b>c</b>:"), tr("comment"), lblChangesetComment);
     95        lblSource = buildLabel(/*I18n: source*/tr("<b>s</b>:"), tr("source"), lblChangesetSource);
     96       
     97        pnlChangesetComment = buildTextPanel(lblComment, lblChangesetComment);
     98        pnlChangesetSource = buildTextPanel(lblSource, lblChangesetSource);
    7399
    74100        setLayout(new GridBagLayout());
     
    83109        add(pnlUserAndChangeset, gc);
    84110        gc.gridy = 2;
    85         add(lblChangesetComment, gc);
     111        add(pnlChangesetComment, gc);
    86112        gc.gridy = 3;
    87         add(lblChangesetSource, gc);
     113        add(pnlChangesetSource, gc);
    88114    }
    89115
     
    195221        }
    196222
    197         final String comment = cs != null ? cs.get("comment") : null;
    198         final String source = cs != null ? cs.get("source") : null;
    199         lblChangesetComment.setText(comment);
    200         lblChangesetSource.setText(source);
    201 
    202         // Hide comment / source if both values are empty
    203223        final Changeset oppCs = model.getPointInTime(pointInTimeType.opposite()).getChangeset();
    204         lblChangesetComment.setVisible(comment != null || (oppCs != null && oppCs.get("comment") != null));
    205         lblChangesetSource.setVisible(source != null || (oppCs != null && oppCs.get("source") != null));
     224        updateText(cs, "comment", lblChangesetComment, lblComment, oppCs, pnlChangesetComment);
     225        updateText(cs, "source", lblChangesetSource, lblSource, oppCs, pnlChangesetSource);
     226    }
     227   
     228    protected static void updateText(Changeset cs, String attr, JTextArea textArea, JLabel label, Changeset oppCs, JPanel panel) {
     229        final String text = cs != null ? cs.get(attr) : null;
     230        // Update text, hide prefixing label if empty
     231        label.setVisible(text != null && !Utils.strip(text).isEmpty());
     232        textArea.setText(text);
     233        // Hide panel if values of both versions are empty
     234        panel.setVisible(text != null || (oppCs != null && oppCs.get(attr) != null));
    206235    }
    207236}
Note: See TracChangeset for help on using the changeset viewer.