Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

TopicPane.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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.dialogs.channelsetting;
  23. import com.dmdirc.Channel;
  24. import com.dmdirc.addons.ui_swing.UIUtilities;
  25. import java.awt.event.ActionEvent;
  26. import java.awt.event.ActionListener;
  27. import javax.swing.JPanel;
  28. import net.miginfocom.swing.MigLayout;
  29. /** Topic panel. */
  30. public final class TopicPane extends JPanel implements ActionListener {
  31. /**
  32. * A version number for this class. It should be changed whenever the class
  33. * structure is changed (or anything else that would prevent serialized
  34. * objects being unserialized with the new class).
  35. */
  36. private static final long serialVersionUID = 2;
  37. /** Parent channel. */
  38. private final Channel channel;
  39. /** Parent dialog. */
  40. private final ChannelSettingsDialog parent;
  41. /** Topic history panel. */
  42. private TopicHistoryPane topicHistoryPane;
  43. /** Topic display pane. */
  44. private TopicDisplayPane topicDisplayPane;
  45. /**
  46. * Creates a new instance of TopicModesPane.
  47. *
  48. * @param channel Parent channel
  49. * @param parent Parent dialog
  50. */
  51. public TopicPane(final Channel channel,
  52. final ChannelSettingsDialog parent) {
  53. super();
  54. this.setOpaque(UIUtilities.getTabbedPaneOpaque());
  55. this.channel = channel;
  56. this.parent = parent;
  57. update();
  58. }
  59. /** Updates the panel. */
  60. public void update() {
  61. setVisible(false);
  62. removeAll();
  63. initTopicsPanel();
  64. layoutComponents();
  65. topicHistoryPane.addActionListener(this);
  66. setVisible(true);
  67. }
  68. /** Initialises the topic panel. */
  69. private void initTopicsPanel() {
  70. topicDisplayPane = new TopicDisplayPane(channel, parent);
  71. topicHistoryPane = new TopicHistoryPane(channel);
  72. }
  73. /** Lays out the components. */
  74. private void layoutComponents() {
  75. setLayout(new MigLayout("wrap 1, fill, wmax 450"));
  76. add(topicDisplayPane, "grow, push");
  77. add(topicHistoryPane, "grow, pushy");
  78. }
  79. /** Processes the topic and changes it if necessary. */
  80. protected void setChangedTopic() {
  81. final String topic = topicDisplayPane.getTopic();
  82. if (!channel.getChannelInfo().getTopic().equals(topic)) {
  83. channel.setTopic(topic);
  84. }
  85. }
  86. /**
  87. * {@inheritDoc}.
  88. *
  89. * @param e Action event
  90. */
  91. @Override
  92. public void actionPerformed(final ActionEvent e) {
  93. if (e != null && e.getSource() == topicHistoryPane) {
  94. topicDisplayPane.setTopic(topicHistoryPane.getSelectedTopic());
  95. }
  96. }
  97. }