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

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

see #11390, fix #12905 - Add more information to the bug report (patch by michael2402) - gsoc-core - requires java 8

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