source: josm/trunk/src/org/openstreetmap/josm/tools/bugreport/DebugTextDisplay.java@ 11107

Last change on this file since 11107 was 11102, checked in by Don-vip, 8 years ago

add more unit tests

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