001/*
002 * Copyright 2010-2015 Institut Pasteur.
003 * 
004 * This file is part of Icy.
005 * 
006 * Icy is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 * 
011 * Icy is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 * GNU General Public License for more details.
015 * 
016 * You should have received a copy of the GNU General Public License
017 * along with Icy. If not, see <http://www.gnu.org/licenses/>.
018 */
019package icy.gui.plugin;
020
021import icy.gui.frame.TitledFrame;
022import icy.gui.frame.error.ErrorReportFrame;
023import icy.gui.frame.progress.ProgressFrame;
024import icy.plugin.PluginDescriptor;
025import icy.system.IcyExceptionHandler;
026import icy.util.StringUtil;
027
028import java.awt.BorderLayout;
029import java.awt.Dimension;
030import java.awt.event.ActionEvent;
031import java.awt.event.ActionListener;
032
033import javax.swing.text.BadLocationException;
034import javax.swing.text.Document;
035
036/**
037 * @deprecated Use {@link ErrorReportFrame} instead.
038 */
039@Deprecated
040public class PluginErrorReportFrame extends TitledFrame
041{
042    // GUI
043    PluginErrorReportPanel panel;
044
045    /**
046     * Create the panel.
047     */
048    PluginErrorReportFrame(PluginDescriptor plugin, String devId, String title, String message)
049    {
050        super("Bug report", true, true, true, true);
051
052        panel = new PluginErrorReportPanel(plugin, devId, title, message);
053
054        panel.reportButton.addActionListener(new ActionListener()
055        {
056            @Override
057            public void actionPerformed(ActionEvent e)
058            {
059                final ProgressFrame progressFrame = new ProgressFrame("Sending report...");
060
061                try
062                {
063                    final Document commentDoc = panel.commentTextPane.getDocument();
064                    final String comment = commentDoc.getText(0, commentDoc.getLength());
065
066                    String error;
067
068                    if (!StringUtil.isEmpty(comment))
069                        error = "Comment:\n" + comment;
070                    else
071                        error = "";
072
073                    final Document errorDoc = panel.errorMessageTextPane.getDocument();
074                    error = error + "\n\n" + errorDoc.getText(0, errorDoc.getLength());
075
076                    IcyExceptionHandler.report(panel.plugin, panel.devId, error);
077                }
078                catch (BadLocationException ex)
079                {
080                    System.err.println("Error while reporting error :");
081                    IcyExceptionHandler.showErrorMessage(ex, true);
082                }
083                finally
084                {
085                    progressFrame.close();
086                }
087
088                close();
089            }
090        });
091        panel.closeButton.addActionListener(new ActionListener()
092        {
093            @Override
094            public void actionPerformed(ActionEvent e)
095            {
096                close();
097            }
098        });
099
100        mainPanel.add(panel, BorderLayout.CENTER);
101
102        addToDesktopPane();
103        setSize(new Dimension(520, 450));
104        setVisible(true);
105        requestFocus();
106        center();
107    }
108
109    /**
110     * @return the plugin
111     */
112    public PluginDescriptor getPlugin()
113    {
114        return panel.plugin;
115    }
116
117    public String getDevId()
118    {
119        return panel.devId;
120    }
121}