001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.tools.bugreport;
003
004import java.awt.Dimension;
005
006import javax.swing.JScrollPane;
007
008import org.openstreetmap.josm.gui.widgets.JosmTextArea;
009import org.openstreetmap.josm.tools.Utils;
010
011/**
012 * This is a text area that displays the debug text with scroll bars.
013 * @author Michael Zangl
014 * @since 10055
015 */
016public class DebugTextDisplay extends JScrollPane {
017    private final String text;
018
019    /**
020     * Creates a new text are with the fixed text
021     * @param textToDisplay The text to display.
022     */
023    public DebugTextDisplay(String textToDisplay) {
024        text = "{{{\n" + Utils.strip(textToDisplay) + "\n}}}";
025        JosmTextArea textArea = new JosmTextArea(text);
026        textArea.setCaretPosition(0);
027        textArea.setEditable(false);
028        setViewportView(textArea);
029        setPreferredSize(new Dimension(600, 300));
030    }
031
032    /**
033     * Copies the debug text to the clippboard.
034     * @return <code>true</code> if copy was successful
035     */
036    public boolean copyToClippboard() {
037        return Utils.copyToClipboard(text);
038    }
039}