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

Last change on this file since 13661 was 12770, checked in by bastiK, 7 years ago

see #15229 - remove GUI references from BugReport and BugReportQueue

signature of BugReport#getReportText changed without deprecation
(probably not used by any external plugin)

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