1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.bugreport;
|
---|
3 |
|
---|
4 | import java.awt.Dimension;
|
---|
5 |
|
---|
6 | import javax.swing.JScrollPane;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.actions.ShowStatusReportAction;
|
---|
9 | import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
|
---|
10 | import org.openstreetmap.josm.gui.widgets.JosmTextArea;
|
---|
11 | import org.openstreetmap.josm.tools.Utils;
|
---|
12 | import 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 | */
|
---|
19 | public 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 | }
|
---|