source: josm/trunk/src/org/openstreetmap/josm/gui/bugreport/DebugTextDisplay.java@ 12649

Last change on this file since 12649 was 12649, checked in by Don-vip, 7 years ago

see #15182 - code refactoring to avoid dependence on GUI packages from Preferences

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.bugreport;
3
4import java.awt.Dimension;
5
6import javax.swing.JScrollPane;
7
8import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
9import org.openstreetmap.josm.gui.widgets.JosmTextArea;
10import org.openstreetmap.josm.tools.Utils;
11import org.openstreetmap.josm.tools.bugreport.BugReport;
12
13/**
14 * This is a text area that displays the debug text with scroll bars.
15 * @author Michael Zangl
16 * @since 10055
17 */
18public class DebugTextDisplay extends JScrollPane {
19 private static final String CODE_PATTERN = "{{{%n%s%n}}}";
20 private String text;
21 private JosmTextArea textArea;
22
23 /**
24 * Creates a new text area.
25 * @since 10585
26 */
27 private DebugTextDisplay() {
28 textArea = new JosmTextArea();
29 textArea.setCaretPosition(0);
30 textArea.setEditable(false);
31 setViewportView(textArea);
32 setPreferredSize(new Dimension(600, 270));
33 }
34
35 /**
36 * Creates a new text area with an inital text to display
37 * @param textToDisplay The text to display.
38 */
39 public DebugTextDisplay(String textToDisplay) {
40 this();
41 setCodeText(textToDisplay);
42 }
43
44 /**
45 * Creates a new text area that displays the bug report data
46 * @param report The bug report data to display.
47 * @since 10585
48 */
49 public DebugTextDisplay(BugReport report) {
50 this();
51 setCodeText(report.getReportText());
52 report.addChangeListener(e -> setCodeText(report.getReportText()));
53 }
54
55 /**
56 * Sets the text that should be displayed in this view.
57 * @param textToDisplay The text
58 */
59 private void setCodeText(String textToDisplay) {
60 text = Utils.strip(textToDisplay).replaceAll("\r", "");
61 textArea.setText(String.format(CODE_PATTERN, text));
62 textArea.setCaretPosition(0);
63 }
64
65 /**
66 * Copies the debug text to the clipboard. This includes the code tags for trac.
67 * @return <code>true</code> if copy was successful
68 * @since 11102 (typo)
69 */
70 public boolean copyToClipboard() {
71 return ClipboardUtils.copyString(String.format(CODE_PATTERN, text));
72 }
73
74 /**
75 * Gets the text this are displays, without the code tag.
76 * @return The stripped text set by {@link #setCodeText(String)}
77 * @since 10585
78 */
79 public String getCodeText() {
80 return text;
81 }
82}
Note: See TracBrowser for help on using the repository browser.