You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HelpMenu.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (c) 2006-2014 DMDirc Developers
  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.components.menubar;
  23. import com.dmdirc.addons.ui_swing.Apple;
  24. import com.dmdirc.addons.ui_swing.dialogs.about.AboutDialog;
  25. import com.dmdirc.addons.ui_swing.dialogs.feedback.FeedbackDialog;
  26. import com.dmdirc.addons.ui_swing.injection.DialogProvider;
  27. import com.dmdirc.interfaces.ConnectionManager;
  28. import java.awt.event.ActionEvent;
  29. import java.awt.event.ActionListener;
  30. import javax.inject.Inject;
  31. import javax.inject.Singleton;
  32. import javax.swing.JMenu;
  33. import javax.swing.JMenuItem;
  34. /**
  35. * A menu providing help commands to the menu bar.
  36. */
  37. @Singleton
  38. public class HelpMenu extends JMenu implements ActionListener {
  39. /** Serial version UID. */
  40. private static final long serialVersionUID = 1;
  41. /** Server manager to use to join dev chat. */
  42. private final ConnectionManager connectionManager;
  43. /** Provider of feedback dialogs. */
  44. private final DialogProvider<FeedbackDialog> feedbackDialogProvider;
  45. /** Provider of about dialogs. */
  46. private final DialogProvider<AboutDialog> aboutDialogProvider;
  47. /**
  48. * Instantiates a new help menu.
  49. *
  50. * @param connectionManager The manager to use to join dev chat.
  51. * @param feedbackDialogProvider Provider of feedback dialogs.
  52. * @param aboutDialogProvider Provider of about dialogs.
  53. */
  54. @Inject
  55. public HelpMenu(
  56. final ConnectionManager connectionManager,
  57. final DialogProvider<FeedbackDialog> feedbackDialogProvider,
  58. final DialogProvider<AboutDialog> aboutDialogProvider) {
  59. super("Help");
  60. this.connectionManager = connectionManager;
  61. this.feedbackDialogProvider = feedbackDialogProvider;
  62. this.aboutDialogProvider = aboutDialogProvider;
  63. setMnemonic('h');
  64. initHelpMenu();
  65. }
  66. /**
  67. * Initialises the help menu.
  68. */
  69. private void initHelpMenu() {
  70. JMenuItem menuItem;
  71. menuItem = new JMenuItem();
  72. menuItem.setMnemonic('j');
  73. menuItem.setText("Join Dev channel");
  74. menuItem.setActionCommand("JoinDevChat");
  75. menuItem.addActionListener(this);
  76. add(menuItem);
  77. menuItem = new JMenuItem();
  78. menuItem.setMnemonic('f');
  79. menuItem.setText("Send Feedback");
  80. menuItem.setActionCommand("feedback");
  81. menuItem.addActionListener(this);
  82. add(menuItem);
  83. if (!Apple.isAppleUI()) {
  84. menuItem = new JMenuItem();
  85. menuItem.setMnemonic('a');
  86. menuItem.setText("About");
  87. menuItem.setActionCommand("About");
  88. menuItem.addActionListener(this);
  89. add(menuItem);
  90. }
  91. }
  92. @Override
  93. public void actionPerformed(final ActionEvent e) {
  94. switch (e.getActionCommand()) {
  95. case "About":
  96. aboutDialogProvider.displayOrRequestFocus();
  97. break;
  98. case "JoinDevChat":
  99. connectionManager.joinDevChat();
  100. break;
  101. case "feedback":
  102. feedbackDialogProvider.displayOrRequestFocus();
  103. break;
  104. }
  105. }
  106. }