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.

AddonInfoLabel.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.addonbrowser;
  18. import com.dmdirc.addons.ui_swing.components.text.TextLabel;
  19. import java.awt.Color;
  20. import java.awt.Font;
  21. import javax.swing.BorderFactory;
  22. import javax.swing.JButton;
  23. import javax.swing.JLabel;
  24. import javax.swing.JPanel;
  25. import javax.swing.JSeparator;
  26. import net.miginfocom.swing.MigLayout;
  27. /**
  28. * Addon info label describing an addon.
  29. */
  30. public class AddonInfoLabel extends JPanel {
  31. /** A version number for this class. */
  32. private static final long serialVersionUID = 1;
  33. /** Addon info to be represented. */
  34. private final AddonInfo addonInfo;
  35. /** Parent window. */
  36. private final BrowserWindow parentWindow;
  37. /** Factory to use to create install workers. */
  38. private final InstallWorkerFactory workerFactory;
  39. /**
  40. * Creates a new addon info label to describe the specified addon info.
  41. *
  42. * @param addonInfo Addon to describe.
  43. * @param parentWindow Parent window.
  44. * @param workerFactory Factory to use to create install workers.
  45. */
  46. public AddonInfoLabel(
  47. final AddonInfo addonInfo,
  48. final BrowserWindow parentWindow,
  49. final InstallWorkerFactory workerFactory) {
  50. this.addonInfo = addonInfo;
  51. this.parentWindow = parentWindow;
  52. this.workerFactory = workerFactory;
  53. init();
  54. }
  55. /**
  56. * Initialises the components used in this addon info label.
  57. */
  58. private void init() {
  59. setLayout(new MigLayout("fillx, ins 0"));
  60. JLabel title = new JLabel(addonInfo.getTitle());
  61. title.setFont(title.getFont().deriveFont(16f).deriveFont(Font.BOLD));
  62. add(title, "wmin 165, wmax 165, gaptop 5, gapleft 5");
  63. title = new JLabel(addonInfo.getScreenshot());
  64. title.setBorder(BorderFactory.createLineBorder(Color.BLACK));
  65. add(title, "wmin 150, wmax 150, hmin 150, hmax 150, wrap, spany 5, "
  66. + "gapright 5, gaptop 5, gapbottom 5");
  67. title = new JLabel(addonInfo.getType().toString() + ", rated "
  68. + addonInfo.getRating() + "/10");
  69. add(title, "wrap, gapleft 5");
  70. add(new TextLabel(addonInfo.getDescription()),
  71. "wmax 100%-170, hmax 150, growy, wrap, pushy, gapleft 5");
  72. final JButton button = new JButton("Install");
  73. button.addActionListener(new InstallListener(workerFactory, addonInfo,
  74. parentWindow));
  75. final boolean installed = addonInfo.isInstalled();
  76. add(button, "split, gapleft 5");
  77. if (installed || !addonInfo.isDownloadable()) {
  78. button.setEnabled(false);
  79. title = new JLabel(installed ? "Already installed"
  80. : "No download available");
  81. title.setForeground(Color.GRAY);
  82. add(title);
  83. }
  84. add(new JSeparator(), "newline, span, growx, pushx, gaptop 5");
  85. }
  86. /**
  87. * Returns the addon info for this label.
  88. *
  89. * @return Addon info
  90. */
  91. public AddonInfo getAddonInfo() {
  92. return addonInfo;
  93. }
  94. @Override
  95. public void repaint() {
  96. //NOOP for performance reasons
  97. }
  98. @Override
  99. public void firePropertyChange(final String propertyName,
  100. final Object oldValue, final Object newValue) {
  101. //NOOP for performance reasons
  102. }
  103. @Override
  104. public void firePropertyChange(final String propertyName,
  105. final boolean oldValue, final boolean newValue) {
  106. //NOOP for performance reasons
  107. }
  108. @Override
  109. public void firePropertyChange(final String propertyName,
  110. final int oldValue, final int newValue) {
  111. //NOOP for performance reasons
  112. }
  113. }