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.

PerformTab.java 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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.dialogs.serversetting;
  18. import com.dmdirc.addons.ui_swing.UIUtilities;
  19. import com.dmdirc.addons.ui_swing.components.performpanel.PerformPanel;
  20. import com.dmdirc.addons.ui_swing.components.renderers.PerformRenderer;
  21. import com.dmdirc.commandparser.auto.AutoCommand;
  22. import com.dmdirc.commandparser.auto.AutoCommandManager;
  23. import com.dmdirc.interfaces.Connection;
  24. import com.dmdirc.config.provider.AggregateConfigProvider;
  25. import com.dmdirc.addons.ui_swing.components.IconManager;
  26. import com.dmdirc.ui.messages.ColourManagerFactory;
  27. import java.awt.event.ActionEvent;
  28. import java.awt.event.ActionListener;
  29. import java.util.ArrayList;
  30. import java.util.Collection;
  31. import java.util.Optional;
  32. import javax.swing.DefaultComboBoxModel;
  33. import javax.swing.JComboBox;
  34. import javax.swing.JPanel;
  35. import net.miginfocom.swing.MigLayout;
  36. /**
  37. * Perform panel.
  38. */
  39. public class PerformTab extends JPanel implements ActionListener {
  40. /** Serial version UID. */
  41. private static final long serialVersionUID = 1;
  42. /** Parent connection. */
  43. private final Connection connection;
  44. /** Command manager wrapper to read/write performs to. */
  45. private final AutoCommandManager autoCommandManager;
  46. /** Network/server combo box. */
  47. private JComboBox<AutoCommand> target;
  48. /** Perform panel. */
  49. private PerformPanel performPanel;
  50. public PerformTab(
  51. final IconManager iconManager,
  52. final ColourManagerFactory colourManagerFactory,
  53. final AggregateConfigProvider config,
  54. final AutoCommandManager autoCommandManager,
  55. final Connection connection) {
  56. this.autoCommandManager = autoCommandManager;
  57. this.connection = connection;
  58. setOpaque(UIUtilities.getTabbedPaneOpaque());
  59. initComponents(iconManager, colourManagerFactory, config);
  60. addListeners();
  61. }
  62. /**
  63. * Initialises the components.
  64. *
  65. * @param iconManager Icon manager
  66. * @param config Config to read settings from
  67. */
  68. private void initComponents(final IconManager iconManager,
  69. final ColourManagerFactory colourManagerFactory,
  70. final AggregateConfigProvider config) {
  71. setLayout(new MigLayout("fill"));
  72. final DefaultComboBoxModel<AutoCommand> model = new DefaultComboBoxModel<>();
  73. target = new JComboBox<>(model);
  74. add(target, "growx, pushx, wrap");
  75. final Collection<AutoCommand> performList = new ArrayList<>();
  76. final AutoCommand networkPerform = autoCommandManager.getOrCreateAutoCommand(
  77. Optional.of(connection.getNetwork()), Optional.empty(), Optional.empty());
  78. final AutoCommand networkProfilePerform = autoCommandManager.getOrCreateAutoCommand(
  79. Optional.of(connection.getNetwork()), Optional.empty(),
  80. Optional.of(connection.getProfile().getName()));
  81. final AutoCommand serverPerform = autoCommandManager.getOrCreateAutoCommand(
  82. Optional.empty(), Optional.of(connection.getAddress()), Optional.empty());
  83. final AutoCommand serverProfilePerform = autoCommandManager.getOrCreateAutoCommand(
  84. Optional.empty(), Optional.of(connection.getAddress()),
  85. Optional.of(connection.getProfile().getName()));
  86. model.addElement(networkPerform);
  87. model.addElement(networkProfilePerform);
  88. model.addElement(serverPerform);
  89. model.addElement(serverProfilePerform);
  90. target.setRenderer(new PerformRenderer(target.getRenderer()));
  91. performList.add(networkPerform);
  92. performList.add(networkProfilePerform);
  93. performList.add(serverPerform);
  94. performList.add(serverProfilePerform);
  95. performPanel = new PerformPanel(iconManager, colourManagerFactory, config,
  96. autoCommandManager, performList);
  97. performPanel.switchPerform(networkPerform);
  98. add(performPanel, "grow, push");
  99. }
  100. /** Adds listeners to the components. */
  101. private void addListeners() {
  102. target.addActionListener(this);
  103. }
  104. /** Saves the performs. */
  105. public void savePerforms() {
  106. performPanel.savePerform();
  107. }
  108. @Override
  109. public void actionPerformed(final ActionEvent e) {
  110. final AutoCommand perform = (AutoCommand) ((JComboBox<?>) e.getSource()).
  111. getSelectedItem();
  112. performPanel.switchPerform(perform);
  113. }
  114. }