FeedbackWizardDialog.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
org.xnap.gui |
![]() |
![]() |
XNap 3 |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* XNap - A P2P framework and client.
*
* See the file AUTHORS for copyright information.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.xnap.gui;
import java.awt.Component;
import java.awt.GridBagLayout;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Locale;
import java.util.Properties;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
import org.apache.log4j.Logger;
import org.xnap.XNap;
import org.xnap.gui.component.DefaultWizardDialog;
import org.xnap.gui.util.GUIHelper;
import org.xnap.gui.util.GridBagHelper;
import org.xnap.gui.util.IconHelper;
import org.xnap.loader.XNapClassLoader;
import org.xnap.net.NetHelper;
import org.xnap.plugin.PluginManager;
/**
* The feedback dialog.
*/
public class FeedbackWizardDialog extends DefaultWizardDialog
{
//--- Constant(s) ---
//--- Data field(s) ---
protected static Logger logger
= Logger.getLogger(FeedbackWizardDialog.class);
private static FeedbackWizardDialog me = null;
private FeedbackPanel feedbackPanel;
//--- Constructor(s) ---
private FeedbackWizardDialog()
{
super(BUTTON_CANCEL);
feedbackPanel = new FeedbackPanel();
addPanel(new IntroPanel());
addPanel(feedbackPanel);
getFinishAction().putValue(Action.NAME, XNap.tr("Send"));
getFinishAction().putValue
(Action.SHORT_DESCRIPTION,
XNap.tr("Sends your feedback to the XNap team. :-)"));
pack();
}
//--- Method(s) ---
public void close()
{
dispose();
me = null;
}
public void finish()
{
feedbackPanel.send();
}
public static String getSystemInfo(boolean includeClasspath)
{
Properties p = System.getProperties();
StringBuffer sb = new StringBuffer();
sb.append("XNap ");
sb.append(PluginManager.getCoreVersion());
sb.append(" (");
sb.append(Locale.getDefault());
sb.append(")\nOS : ");
sb.append(p.get("os.name"));
sb.append(" ");
sb.append(p.get("os.version"));
sb.append(" (");
sb.append(p.get("os.arch"));
sb.append(")\nJRE: ");
sb.append(p.get("java.vendor"));
sb.append(" ");
sb.append(p.get("java.version"));
sb.append("\n");
if (includeClasspath) {
sb.append("Class-Path: ");
try {
sb.append(XNapClassLoader.getURLsAsString());
}
catch (Exception e) {
// might occur with older base releases (< 3.0-beta6)
// that do provide getURLsAsString()
}
sb.append("\n");
}
return sb.toString();
}
public static String getSystemInfo()
{
return getSystemInfo(true);
}
public static void showDialog(Component c)
{
if (me == null) {
me = new FeedbackWizardDialog();
}
me.show(c);
}
private class IntroPanel extends AbstractSettingsPanel
{
public IntroPanel()
{
setLayout(new GridBagLayout());
GridBagHelper.add(this, new JLabel(GUIHelper.label
(XNap.tr("There are several ways of contacting us:<br><br>First of all check, the <b>Frequently Asked Questions</b> (available from the help menu). For <b>bug reports</b> or <b>feature requests</b> please use the respective <b>trackers</b> on our homepage at http://xnap.org.<br><br>If you just want to praise us for developing XNap or if you want to verbally punish us for releasing such blatant crap to the public or if just want to tell us something else, select Next to advance to the feedback form. Please enter your email address if you think it might be necessary for us to ask further questions or if you would like a reply in general. Please also note that we might not be able to answer in a timely manner or even answer at all due to time constraints.<br><br>Visit <b>http://xnap.org/contact.html</b> for more detailed information."))));
}
public void apply()
{
}
public String getDescription()
{
return XNap.tr("Feedback is very important to us. Please read the following notes to make sure it is delivered to the right entity.");
}
public Icon getIcon()
{
return IconHelper.getWizardIcon("message2.png");
}
public String getTitle()
{
return XNap.tr("Send Feedback");
}
}
private class FeedbackPanel extends AbstractSettingsPanel
{
private JTextField jtName;
private JTextField jtEmail;
private JTextField jtSubject;
private JTextArea jtaText;
public FeedbackPanel()
{
// text
setLayout(new GridBagLayout());
GridBagHelper.addLabel(this, XNap.tr("Subject"));
jtSubject = new JTextField(20);
GridBagHelper.add(this, jtSubject);
GridBagHelper.addLabel(this, XNap.tr("Feedback"));
jtaText = new JTextArea(getSystemInfo(), 12, 40);
//jtaText = new CompletableTextArea(getSystemInfo(), 12, 40);
jtaText.setLineWrap(true);
jtaText.setWrapStyleWord(true);
jtaText.setEditable (true);
jtaText.setBorder(new EmptyBorder(5, 5, 5, 5));
JScrollPane jspText = new JScrollPane(jtaText);
GridBagHelper.addPanel(this, jspText);
GridBagHelper.addLabel(this, XNap.tr("Your Name"));
jtName = new JTextField(20);
GridBagHelper.add(this, jtName);
GridBagHelper.addLabel(this, XNap.tr("Your Email"));
jtEmail = new JTextField(20);
GridBagHelper.add(this, jtEmail);
if (prefs.getRememberFeedback()) {
jtEmail.setText(prefs.getFeedbackEmail());
jtName.setText(prefs.getFeedbackName());
}
}
public void apply()
{
// the sending is done in the FeedbackWizardDialog.close()
}
public boolean send()
{
if (jtaText.getText().trim().length() == 0
|| jtaText.getText().equals(getSystemInfo())) {
JOptionPane.showMessageDialog
(FeedbackWizardDialog.this,
XNap.tr("Cowardly refusing to send empty or unmodified feedback."),
XNap.tr("Send Feedback"), JOptionPane.ERROR_MESSAGE);
return false;
}
if (jtEmail.getText().trim().length() == 0) {
Object[] message = new Object[] {
XNap.tr("You did not provide an Email address. "),
XNap.tr("We will not be able to answer. "),
XNap.tr("Really send feedback?")
};
int response = JOptionPane.showConfirmDialog
(FeedbackWizardDialog.this, message,
XNap.tr("Send Feedback"),
JOptionPane.YES_NO_OPTION);
if (response == JOptionPane.NO_OPTION) {
return false;
}
}
getFinishAction().setEnabled(false);
getCancelAction().setEnabled(false);
setTitle(XNap.tr("Sending feedback") + "...");
Thread t = new Thread(new SendWorker(), "SendFeedback");
t.start();
return true;
}
public String getDescription()
{
return XNap.tr("Your feedback will be posted to a mailing list that is public to all XNap developers. As this list is hosted at SourceForge it maybe visible to others. We understand English, German and some French.");
}
public Icon getIcon()
{
return IconHelper.getWizardIcon("kwrite.png");
}
public String getTitle()
{
return XNap.tr("Enter Feedback");
}
private class SendWorker implements Runnable
{
private String encode(String s)
{
return (s != null) ? URLEncoder.encode(s.trim()) : "";
}
public void run()
{
// FIX: all getText() calls need to be Swing synchronized
if (prefs.getRememberFeedback()) {
prefs.setFeedbackEmail(jtEmail.getText());
prefs.setFeedbackName(jtName.getText());
}
StringBuffer sb = new StringBuffer();
sb.append("&noresponse=1");
sb.append("&from=" + encode(jtEmail.getText().trim()));
sb.append("&subject=" + encode(jtSubject.getText()));
sb.append("&name=" + encode(jtName.getText().trim()));
sb.append("&message=" + encode(jtaText.getText().trim()));
try {
logger.info("transmitting feedback");
URL url=new URL(prefs.getFeeedbackURL());
HttpURLConnection conn = (HttpURLConnection)(url.openConnection());
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setUseCaches(false);
conn.setAllowUserInteraction(false);
PrintWriter out=new PrintWriter(conn.getOutputStream());
out.println(sb);
out.flush();
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String s;
while ((s = in.readLine())!=null) {
logger.debug(s);
}
in.close();
conn.disconnect();
}
catch(final IOException e) {
logger.info("transmitting feedback failed");
Runnable runner = new Runnable()
{
public void run()
{
failed(NetHelper.getErrorMessage(e));
}
};
SwingUtilities.invokeLater(runner);
return;
}
Runnable runner = new Runnable()
{
public void run()
{
JOptionPane.showMessageDialog
(FeedbackWizardDialog.this,
XNap.tr("Thank you."),
XNap.tr("Feedback"),
JOptionPane.INFORMATION_MESSAGE);
close();
}
};
SwingUtilities.invokeLater(runner);
}
public void failed(String response)
{
JOptionPane.showMessageDialog
(FeedbackWizardDialog.this,
XNap.tr("Could not send feedback: {0}.", response),
XNap.tr("Feedback"),
JOptionPane.ERROR_MESSAGE);
setTitle(XNap.tr("Feedback"));
getFinishAction().setEnabled(true);
getCancelAction().setEnabled(true);
}
}
}
}
The table below shows all metrics for FeedbackWizardDialog.java.



