Changeset 6836 in josm
- Timestamp:
- 2014-02-11T01:23:37+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/history/VersionInfoPanel.java
r6827 r6836 29 29 import org.openstreetmap.josm.gui.widgets.UrlLabel; 30 30 import org.openstreetmap.josm.tools.CheckParameterUtil; 31 import org.openstreetmap.josm.tools.GBC; 32 import org.openstreetmap.josm.tools.Utils; 31 33 32 34 /** … … 41 43 private UrlLabel lblUser; 42 44 private UrlLabel lblChangeset; 45 private JPanel pnlChangesetComment; 46 private JPanel pnlChangesetSource; 47 private JLabel lblComment; 48 private JLabel lblSource; 43 49 private JTextArea lblChangesetComment; 44 50 private JTextArea lblChangesetSource; … … 54 60 } 55 61 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 56 78 protected void build() { 57 JPanel pnl1 = new JPanel(); 58 pnl1.setLayout(new BorderLayout()); 79 JPanel pnl1 = new JPanel(new BorderLayout()); 59 80 lblInfo = new JMultilineLabel(""); 60 81 pnl1.add(lblInfo, BorderLayout.CENTER); 61 82 62 JPanel pnlUserAndChangeset = new JPanel(); 63 pnlUserAndChangeset.setLayout(new GridLayout(2,2)); 83 JPanel pnlUserAndChangeset = new JPanel(new GridLayout(2,2)); 64 84 lblUser = new UrlLabel("", 2); 65 85 pnlUserAndChangeset.add(new JLabel(tr("User:"))); … … 71 91 lblChangesetComment = buildTextArea(tr("Changeset comment")); 72 92 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); 73 99 74 100 setLayout(new GridBagLayout()); … … 83 109 add(pnlUserAndChangeset, gc); 84 110 gc.gridy = 2; 85 add( lblChangesetComment, gc);111 add(pnlChangesetComment, gc); 86 112 gc.gridy = 3; 87 add( lblChangesetSource, gc);113 add(pnlChangesetSource, gc); 88 114 } 89 115 … … 195 221 } 196 222 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 empty203 223 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)); 206 235 } 207 236 }
Note:
See TracChangeset
for help on using the changeset viewer.