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.

AddonInfoPanel.java 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc.addons.ui_swing.components.addonpanel;
  18. import com.dmdirc.addons.ui_swing.components.text.TextLabel;
  19. import com.dmdirc.util.collections.ListenerList;
  20. import java.awt.event.ActionEvent;
  21. import java.awt.event.ActionListener;
  22. import javax.swing.JCheckBox;
  23. import javax.swing.JPanel;
  24. import net.miginfocom.swing.MigLayout;
  25. /**
  26. * Simple panel describing an addon toggle.
  27. */
  28. public class AddonInfoPanel extends JPanel implements ActionListener,
  29. AddonToggleListener {
  30. /** Java serialisation version UID. */
  31. private static final long serialVersionUID = 1L;
  32. /** Addon toggle. */
  33. private AddonToggle addonToggle;
  34. /** Plugin description text label. */
  35. private final TextLabel description;
  36. /** Status toggle button. */
  37. private final JCheckBox status;
  38. /** Label to describe status checkbox. */
  39. private final TextLabel statusLabel;
  40. /** Uninstall button. */
  41. //private final JButton uninstall;
  42. /** Should we check this addon for updates? */
  43. private final JCheckBox update;
  44. /** Label to describe update checkbox. */
  45. //private final TextLabel updateLabel;
  46. /** Listener list. */
  47. private final ListenerList listeners;
  48. /**
  49. * Creates a new addon info panel.
  50. */
  51. public AddonInfoPanel() {
  52. description = new TextLabel();
  53. status = new JCheckBox();
  54. statusLabel = new TextLabel("Enable this addon", false);
  55. //uninstall = new JButton("Uninstall");
  56. update = new JCheckBox();
  57. //updateLabel = new TextLabel("Check for updates for this addon", false);
  58. listeners = new ListenerList();
  59. status.setEnabled(false);
  60. layoutComponents();
  61. update.addActionListener(this);
  62. status.addActionListener(this);
  63. }
  64. /**
  65. * Lays out the components in this panel.
  66. */
  67. private void layoutComponents() {
  68. setLayout(new MigLayout("ins 0, fill", "[65%!][]", ""));
  69. add(description, "grow, spany 3");
  70. add(status, "aligny top");
  71. add(statusLabel, "grow, push, wrap");
  72. //add(update, "aligny top");
  73. //add(updateLabel, "grow, push, wrap, gapbottom rel");
  74. //add(uninstall, "grow, spanx 2, wrap");
  75. }
  76. /**
  77. * Sets the addon toggle this panel should display information about.
  78. *
  79. * @param addonToggle Addon toggle to display, or null
  80. */
  81. public void setAddonToggle(final AddonToggle addonToggle) {
  82. if (this.addonToggle != null) {
  83. this.addonToggle.removeListener(this);
  84. }
  85. this.addonToggle = addonToggle;
  86. if (addonToggle == null) {
  87. description.setText("");
  88. status.setEnabled(false);
  89. } else {
  90. addonToggle.addListener(this);
  91. status.setEnabled(true);
  92. description.setText("<b>" + addonToggle.getName() + "</b> "
  93. + addonToggle.getVersion() + " by "
  94. + addonToggle.getAuthor()
  95. + "<br><br>" + addonToggle.getDescription());
  96. status.setSelected(addonToggle.getState());
  97. update.setSelected(addonToggle.getUpdateState());
  98. }
  99. }
  100. /**
  101. * Adds an addon toggle listener to this panel, this proxies whatever addon listener is being
  102. * displayed.
  103. *
  104. * @param listener Listener to add
  105. */
  106. public void addListener(final AddonToggleListener listener) {
  107. listeners.add(AddonToggleListener.class, listener);
  108. }
  109. /**
  110. * Removes an addon toggle listener from this panel.
  111. *
  112. * @param listener Listener to remove
  113. */
  114. public void removeListener(final AddonToggleListener listener) {
  115. listeners.remove(AddonToggleListener.class, listener);
  116. }
  117. @Override
  118. public void addonToggled() {
  119. listeners.getCallable(AddonToggleListener.class).addonToggled();
  120. }
  121. @Override
  122. public void actionPerformed(final ActionEvent e) {
  123. if (addonToggle == null) {
  124. return;
  125. }
  126. if (e.getSource() == update) {
  127. addonToggle.setUpdateState(update.isSelected());
  128. } else if (e.getSource() == status) {
  129. addonToggle.setState(status.isSelected());
  130. }
  131. }
  132. }