選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

FeedbackDialog.java 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /*
  2. * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.addons.ui_swing.dialogs;
  23. import com.dmdirc.Main;
  24. import com.dmdirc.Server;
  25. import com.dmdirc.ServerManager;
  26. import com.dmdirc.addons.ui_swing.SwingController;
  27. import com.dmdirc.addons.ui_swing.UIUtilities;
  28. import com.dmdirc.addons.ui_swing.components.SendWorker;
  29. import com.dmdirc.addons.ui_swing.components.text.TextLabel;
  30. import com.dmdirc.ui.core.util.Info;
  31. import java.awt.Insets;
  32. import java.awt.Window;
  33. import java.awt.event.ActionEvent;
  34. import java.awt.event.ActionListener;
  35. import javax.swing.BorderFactory;
  36. import javax.swing.JButton;
  37. import javax.swing.JCheckBox;
  38. import javax.swing.JLabel;
  39. import javax.swing.JScrollPane;
  40. import javax.swing.JTextArea;
  41. import javax.swing.JTextField;
  42. import javax.swing.event.DocumentEvent;
  43. import javax.swing.event.DocumentListener;
  44. import net.miginfocom.swing.MigLayout;
  45. /** Feedback form. */
  46. public final class FeedbackDialog extends StandardDialog implements
  47. ActionListener, DocumentListener {
  48. /**
  49. * A version number for this class. It should be changed whenever the class
  50. * structure is changed (or anything else that would prevent serialized
  51. * objects being unserialized with the new class).
  52. */
  53. private static final long serialVersionUID = 1;
  54. /** A previously created instance of FeedbackDialog. */
  55. private static FeedbackDialog me;
  56. /** Information label. */
  57. private TextLabel info;
  58. /** Name field. */
  59. private JTextField name;
  60. /** Email field. */
  61. private JTextField email;
  62. /** Feedback area. */
  63. private JTextArea feedback;
  64. /** Server info checkbox. */
  65. private JCheckBox serverCheckbox;
  66. /** DMDirc info checkbox. */
  67. private JCheckBox dmdircCheckbox;
  68. /** Sent. */
  69. private boolean sentReport = false;
  70. /**
  71. * Instantiates the feedback dialog.
  72. *
  73. * @param parentWindow Parent window
  74. */
  75. private FeedbackDialog(final Window parentWindow) {
  76. super(parentWindow, ModalityType.MODELESS);
  77. initComponents();
  78. layoutComponents();
  79. addListeners();
  80. setTitle("Feedback");
  81. setResizable(false);
  82. }
  83. /**
  84. * Creates the new feedback dialog if one doesn't exist, and displays it.
  85. *
  86. * @param parentWindow Parent window
  87. */
  88. public static void showFeedbackDialog(final Window parentWindow) {
  89. me = getFeedbackDialog(parentWindow);
  90. me.display();
  91. me.requestFocusInWindow();
  92. }
  93. /**
  94. * Returns the current instance of the FeedbackDialog.
  95. *
  96. * @param parentWindow Parent window
  97. *
  98. * @return The current FeedbackDialog instance
  99. */
  100. public static FeedbackDialog getFeedbackDialog(final Window parentWindow) {
  101. synchronized (FeedbackDialog.class) {
  102. if (me == null) {
  103. me = new FeedbackDialog(parentWindow);
  104. me.serverCheckbox.setEnabled(ServerManager.getServerManager().
  105. numServers() > 0);
  106. } else if (!me.isVisible()) {
  107. me = new FeedbackDialog(parentWindow);
  108. me.serverCheckbox.setEnabled(ServerManager.getServerManager().
  109. numServers() > 0);
  110. }
  111. }
  112. return me;
  113. }
  114. /** Initialises the components. */
  115. private void initComponents() {
  116. orderButtons(new JButton(), new JButton());
  117. getOkButton().setText("Send");
  118. getOkButton().setActionCommand("Send");
  119. getOkButton().setEnabled(false);
  120. getCancelButton().setActionCommand("Close");
  121. info = new TextLabel("Thank you for using DMDirc. If you have any "
  122. + "feedback about the client, such as bug reports or feature "
  123. + "requests, please send it to us using the form below. "
  124. + "The name and e-mail address fields are optional if you "
  125. + "don't want us to contact you about your feedback.\n\n"
  126. + "Please note that this is for feedback such as bug reports "
  127. + "and suggestions, not for technical support. For "
  128. + "technical support, please join #DMDirc using the button "
  129. + "in the help menu.");
  130. name = new JTextField();
  131. email = new JTextField();
  132. feedback = new JTextArea();
  133. serverCheckbox =
  134. new JCheckBox("Include information about connected servers.");
  135. dmdircCheckbox = new JCheckBox("Include information about DMDirc.");
  136. UIUtilities.addUndoManager(name);
  137. UIUtilities.addUndoManager(email);
  138. UIUtilities.addUndoManager(feedback);
  139. }
  140. /** Lays out the components. */
  141. private void layoutComponents() {
  142. serverCheckbox.setMargin(new Insets(0, 0, 0, 0));
  143. serverCheckbox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
  144. dmdircCheckbox.setMargin(new Insets(0, 0, 0, 0));
  145. dmdircCheckbox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
  146. setLayout(new MigLayout(
  147. "fill, wmin 600, wmax 600, hmin 400, hmax 400"));
  148. add(info, "span, growx, wrap, gapbottom unrel");
  149. add(new JLabel("Name: "), "aligny top, shrink");
  150. add(name, "growx, pushx, wrap");
  151. add(new JLabel("Email: "), "aligny top, shrink");
  152. add(email, "growx, pushx, wrap");
  153. add(new JLabel("Feedback: "), "aligny top, shrink");
  154. add(new JScrollPane(feedback), "grow, push, wrap");
  155. add(serverCheckbox, "skip 1, growx, wrap");
  156. add(dmdircCheckbox, "skip 1, growx, wrap");
  157. add(getCancelButton(), "skip, split 2, right, sg button");
  158. add(getOkButton(), "right, sg button");
  159. }
  160. /**
  161. * Lays out the components.
  162. *
  163. * @param error Did the submission error?
  164. */
  165. public void layoutComponents2(final StringBuilder error) {
  166. getContentPane().setVisible(false);
  167. getContentPane().removeAll();
  168. getOkButton().setEnabled(true);
  169. getOkButton().setText("Close");
  170. getOkButton().setActionCommand("Close");
  171. setLayout(new MigLayout(
  172. "fill, wmin 600, wmax 600, hmin 400, hmax 400"));
  173. info.setText(error.toString());
  174. add(info, "span 3, grow, push, wrap");
  175. add(getOkButton(), "skip, right, tag ok, sg button");
  176. getContentPane().setVisible(true);
  177. }
  178. /** Adds listeners to the components. */
  179. private void addListeners() {
  180. getOkButton().addActionListener(this);
  181. getCancelButton().addActionListener(this);
  182. feedback.getDocument().addDocumentListener(this);
  183. }
  184. /** Checks and sends the feedback. */
  185. private void send() {
  186. sentReport = true;
  187. getOkButton().setEnabled(false);
  188. getCancelButton().setEnabled(false);
  189. final StringBuilder serverInfo = new StringBuilder();
  190. final StringBuilder dmdircInfo = new StringBuilder();
  191. if (serverCheckbox.isSelected()) {
  192. for (Server server : ServerManager.getServerManager()
  193. .getServers()) {
  194. if (server.getState().isDisconnected()) {
  195. continue;
  196. }
  197. serverInfo.append("Server name: ").append(server.getName())
  198. .append("\n");
  199. serverInfo.append("Actual name: ").append(server.getParser()
  200. .getServerName()).append("\n");
  201. serverInfo.append("Network: ").append(server.getNetwork())
  202. .append("\n");
  203. serverInfo.append("IRCd: ").append(server.getParser()
  204. .getServerSoftware()).append(" - ");
  205. serverInfo.append(server.getParser().getServerSoftwareType())
  206. .append("\n");
  207. serverInfo.append("Modes: ").append(server.getParser()
  208. .getBooleanChannelModes()).append(" ");
  209. serverInfo.append(server.getParser().getListChannelModes())
  210. .append(" ");
  211. serverInfo.append(server.getParser().getParameterChannelModes())
  212. .append(" ");
  213. serverInfo.append(server.getParser().
  214. getDoubleParameterChannelModes());
  215. }
  216. }
  217. if (dmdircCheckbox.isSelected()) {
  218. dmdircInfo.append("DMDirc version: ").append(
  219. Info.getDMDircVersion()).append("\n");
  220. dmdircInfo.append("Profile directory: ").append(
  221. Main.getConfigDir()).append("\n");
  222. dmdircInfo.append("Java version: ").append(
  223. Info.getJavaVersion()).append("\n");
  224. dmdircInfo.append("OS Version: ").append(
  225. Info.getOSVersion()).append("\n");
  226. dmdircInfo.append("Look & Feel: ").append(
  227. SwingController.getLookAndFeel());
  228. }
  229. new SendWorker(me, name.getText().trim(), email.getText().trim(),
  230. feedback.getText().trim(), serverInfo.toString().trim(),
  231. dmdircInfo.toString().trim()).executeInExecutor();
  232. }
  233. /** Validates the input. */
  234. private void validateInput() {
  235. if (feedback.getDocument().getLength() > 0) {
  236. getOkButton().setEnabled(true);
  237. } else {
  238. getOkButton().setEnabled(false);
  239. }
  240. }
  241. /**
  242. * {@inheritDoc}
  243. *
  244. * @param e action event
  245. */
  246. @Override
  247. public void actionPerformed(final ActionEvent e) {
  248. if (e.getActionCommand().equals("Send")) {
  249. if (!sentReport) {
  250. send();
  251. }
  252. } else if (e.getActionCommand().equals("Close")) {
  253. dispose();
  254. }
  255. }
  256. /** {@inheritDoc} */
  257. @Override
  258. public void insertUpdate(final DocumentEvent e) {
  259. validateInput();
  260. }
  261. /** {@inheritDoc} */
  262. @Override
  263. public void removeUpdate(final DocumentEvent e) {
  264. validateInput();
  265. }
  266. /** {@inheritDoc} */
  267. @Override
  268. public void changedUpdate(final DocumentEvent e) {
  269. //Ignore
  270. }
  271. /** {@inheritDoc} */
  272. @Override
  273. public void dispose() {
  274. if (me == null) {
  275. return;
  276. }
  277. synchronized (me) {
  278. super.dispose();
  279. me = null;
  280. }
  281. }
  282. }