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.

NickColourInputDialog.java 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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.nickcolours;
  23. import com.dmdirc.Main;
  24. import com.dmdirc.addons.ui_swing.MainFrame;
  25. import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
  26. import com.dmdirc.addons.ui_swing.components.colours.ColourChooser;
  27. import java.awt.event.ActionEvent;
  28. import java.awt.event.ActionListener;
  29. import javax.swing.JButton;
  30. import javax.swing.JLabel;
  31. import javax.swing.JTextField;
  32. import javax.swing.WindowConstants;
  33. import net.miginfocom.swing.MigLayout;
  34. /**
  35. * New nick colour input dialog.
  36. */
  37. public class NickColourInputDialog extends StandardDialog
  38. implements ActionListener {
  39. /**
  40. * A version number for this class. It should be changed whenever the class
  41. * structure is changed (or anything else that would prevent serialized
  42. * objects being unserialized with the new class).
  43. */
  44. private static final long serialVersionUID = 1;
  45. /** Whether or not this is a new entry (as opposed to editing an old one). */
  46. private boolean isnew;
  47. /** The row we're editing, if this isn't a new entry. */
  48. private int row;
  49. /** The NickColourPanel we're reporting to. */
  50. private final NickColourPanel panel;
  51. /** nickname textfield. */
  52. private JTextField nickname;
  53. /** network textfield. */
  54. private JTextField network;
  55. /** text colour input. */
  56. private ColourChooser textColour;
  57. /** nicklist colour input. */
  58. private ColourChooser nicklistColour;
  59. /**
  60. * Creates a new instance of NickColourInputDialog.
  61. *
  62. * @param panel The panel that's opening this dialog
  63. * @param row The row of the table we're editing
  64. * @param nickname The nickname that's currently set
  65. * @param network The network that's currently set
  66. * @param textcolour The text colour that's currently set
  67. * @param nickcolour The nicklist colour that's currently set
  68. */
  69. public NickColourInputDialog(final NickColourPanel panel, final int row,
  70. final String nickname, final String network,
  71. final String textcolour, final String nickcolour) {
  72. super((MainFrame) Main.getUI().getMainWindow(), false);
  73. this.panel = panel;
  74. this.row = row;
  75. setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  76. initComponents(nickname, network, textcolour, nickcolour);
  77. initListeners();
  78. layoutComponents();
  79. setTitle("Nick colour editor");
  80. display();
  81. }
  82. /**
  83. * Creates a new instance of NickColourInputDialog.
  84. *
  85. * @param panel The panel that's opening this dialog
  86. */
  87. public NickColourInputDialog(final NickColourPanel panel) {
  88. this(panel, -1, "", "", "", "");
  89. isnew = true;
  90. }
  91. /**
  92. * Initialises the components.
  93. *
  94. * @param defaultNickname The default value for the nickname text field
  95. * @param defaultNetwork The default value for the network text field
  96. * @param defaultTextColour The default value for the text colour option
  97. * @param defaultNickColour The default value for the nick colour option
  98. */
  99. private void initComponents(final String defaultNickname,
  100. final String defaultNetwork, final String defaultTextColour,
  101. final String defaultNickColour) {
  102. orderButtons(new JButton(), new JButton());
  103. nickname = new JTextField(defaultNickname);
  104. network = new JTextField(defaultNetwork);
  105. textColour = new ColourChooser(defaultTextColour, true, true);
  106. nicklistColour = new ColourChooser(defaultNickColour, true, true);
  107. }
  108. /** Initialises the listeners. */
  109. private void initListeners() {
  110. getOkButton().addActionListener(this);
  111. getCancelButton().addActionListener(this);
  112. }
  113. /** Lays out the components. */
  114. private void layoutComponents() {
  115. setLayout(new MigLayout("wrap 2"));
  116. add(new JLabel("Nickname: "));
  117. add(nickname, "growx");
  118. add(new JLabel("Network: "));
  119. add(network, "growx");
  120. add(new JLabel("Text colour: "));
  121. add(textColour, "growx");
  122. add(new JLabel("Nicklist colour: "));
  123. add(nicklistColour, "growx");
  124. add(getLeftButton(), "right");
  125. add(getRightButton(), "right");
  126. pack();
  127. }
  128. /**
  129. * {@inheritDoc}
  130. *
  131. * @param e Action event
  132. */
  133. @Override
  134. public void actionPerformed(final ActionEvent e) {
  135. if (e.getSource() == getOkButton()) {
  136. saveSettings();
  137. }
  138. dispose();
  139. }
  140. /** Saves settings. */
  141. public void saveSettings() {
  142. final String myNetwork = network.getText().toLowerCase();
  143. final String myNickname = nickname.getText().toLowerCase();
  144. final String myTextColour = textColour.getColour();
  145. final String myNickColour = nicklistColour.getColour();
  146. if (!isnew) {
  147. panel.removeRow(row);
  148. }
  149. panel.addRow(myNetwork, myNickname, myTextColour, myNickColour);
  150. }
  151. }