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.

Perform.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (c) 2006-2013 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.serverlistdialog;
  23. import com.dmdirc.addons.serverlists.ServerGroupItem;
  24. import com.dmdirc.addons.ui_swing.SwingController;
  25. import com.dmdirc.addons.ui_swing.components.performpanel.PerformPanel;
  26. import javax.swing.BorderFactory;
  27. import javax.swing.JPanel;
  28. import javax.swing.UIManager;
  29. import javax.swing.border.Border;
  30. import net.miginfocom.swing.MigLayout;
  31. /**
  32. * Panel to show and edit performs for a server group.
  33. */
  34. public class Perform extends JPanel implements ServerListListener {
  35. /** Serial version UID. */
  36. private static final long serialVersionUID = 2;
  37. /** Perform panel. */
  38. private final PerformPanel performPanel;
  39. /** Server list model. */
  40. private final ServerListModel model;
  41. /** Platform border. */
  42. private final Border border;
  43. /**
  44. * Creates a new perform panel backed by the specified model.
  45. *
  46. * @param controller Swing controller
  47. * @param model Backing model
  48. */
  49. public Perform(final SwingController controller, final ServerListModel model) {
  50. super();
  51. this.model = model;
  52. performPanel = new PerformPanel(controller);
  53. addListeners();
  54. if (model.getSelectedItemPerformDescription() != null) {
  55. performPanel.switchPerform(model
  56. .getSelectedItemPerformDescription());
  57. }
  58. border = UIManager.getBorder("TitledBorder.border");
  59. setBorder(BorderFactory.createTitledBorder(border, "Network perform"));
  60. setLayout(new MigLayout("fill"));
  61. add(performPanel, "grow");
  62. }
  63. /**
  64. * Adds required listeners.
  65. */
  66. private void addListeners() {
  67. model.addServerListListener(this);
  68. }
  69. /** {@inheritDoc} */
  70. @Override
  71. public void serverGroupAdded(final ServerGroupItem parent,
  72. final ServerGroupItem group) {
  73. //Ignore
  74. }
  75. /** {@inheritDoc} */
  76. @Override
  77. public void serverGroupRemoved(final ServerGroupItem parent,
  78. final ServerGroupItem group) {
  79. //Ignore
  80. }
  81. /** {@inheritDoc} */
  82. @Override
  83. public void serverGroupChanged(final ServerGroupItem item) {
  84. if (item == null) {
  85. performPanel.switchPerform(null);
  86. return;
  87. }
  88. if (item.getGroup() == item) {
  89. setBorder(BorderFactory.createTitledBorder(border,
  90. "Network perform"));
  91. } else {
  92. setBorder(BorderFactory.createTitledBorder(border,
  93. "Server perform"));
  94. }
  95. performPanel.switchPerform(model.getSelectedItemPerformDescription());
  96. }
  97. /** {@inheritDoc} */
  98. @Override
  99. public void dialogClosed(final boolean save) {
  100. if (save) {
  101. performPanel.savePerform();
  102. }
  103. }
  104. }