001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.dialogs;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import java.awt.Dimension;
007import java.awt.Font;
008import java.awt.GridBagLayout;
009
010import javax.swing.JLabel;
011import javax.swing.JPanel;
012import javax.swing.JScrollPane;
013
014import org.openstreetmap.josm.gui.ExtendedDialog;
015import org.openstreetmap.josm.gui.MainApplication;
016import org.openstreetmap.josm.gui.widgets.JosmEditorPane;
017import org.openstreetmap.josm.tools.GBC;
018
019/**
020 * Generic dialog with message and scrolling area
021 * @author Alexei
022 * @since 5114
023 */
024public class LogShowDialog extends ExtendedDialog {
025
026    /**
027     * Constructs a new {@code LogShowDialog}.
028     * @param title The text that will be shown in the window titlebar
029     * @param msg Single-line Label
030     * @param log Multi-line log
031     */
032    public LogShowDialog(String title, String msg, String log) {
033        super(MainApplication.getMainFrame(), title, tr("OK"));
034        setButtonIcons("ok");
035        setContent(build(msg, log));
036    }
037
038    protected final JPanel build(String msg, String log) {
039        JPanel p = new JPanel(new GridBagLayout());
040        JLabel lbl = new JLabel(msg);
041
042        lbl.setFont(lbl.getFont().deriveFont(Font.PLAIN, 14));
043
044        p.add(lbl, GBC.eol().insets(5, 0, 5, 0));
045        JosmEditorPane txt = new JosmEditorPane();
046        txt.setContentType("text/html");
047        txt.setText(log);
048        txt.setEditable(false);
049        txt.setOpaque(false);
050
051        lbl.setLabelFor(txt);
052
053        JScrollPane sp = new JScrollPane(txt);
054        sp.setOpaque(false);
055        sp.setPreferredSize(new Dimension(600, 300));
056
057        p.add(sp, GBC.eop().insets(5, 15, 0, 0).fill(GBC.HORIZONTAL));
058
059        return p;
060    }
061}