|
@@ -22,6 +22,7 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.addons.nickcolours;
|
24
|
24
|
|
|
25
|
+import com.dmdirc.addons.ui_swing.components.GenericTableModel;
|
25
|
26
|
import com.dmdirc.addons.ui_swing.components.IconManager;
|
26
|
27
|
import com.dmdirc.addons.ui_swing.components.colours.ColourChooser;
|
27
|
28
|
import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
|
|
@@ -29,8 +30,6 @@ import com.dmdirc.ui.messages.ColourManager;
|
29
|
30
|
|
30
|
31
|
import java.awt.Color;
|
31
|
32
|
import java.awt.Window;
|
32
|
|
-import java.awt.event.ActionEvent;
|
33
|
|
-import java.awt.event.ActionListener;
|
34
|
33
|
|
35
|
34
|
import javax.swing.JButton;
|
36
|
35
|
import javax.swing.JLabel;
|
|
@@ -42,7 +41,7 @@ import net.miginfocom.swing.MigLayout;
|
42
|
41
|
/**
|
43
|
42
|
* New nick colour input dialog.
|
44
|
43
|
*/
|
45
|
|
-public class NickColourInputDialog extends StandardDialog implements ActionListener {
|
|
44
|
+public class NickColourInputDialog extends StandardDialog {
|
46
|
45
|
|
47
|
46
|
/** A version number for this class. */
|
48
|
47
|
private static final long serialVersionUID = 1;
|
|
@@ -50,8 +49,9 @@ public class NickColourInputDialog extends StandardDialog implements ActionListe
|
50
|
49
|
private boolean isnew;
|
51
|
50
|
/** The row we're editing, if this isn't a new entry. */
|
52
|
51
|
private final int row;
|
53
|
|
- /** The NickColourPanel we're reporting to. */
|
54
|
|
- private final NickColourPanel panel;
|
|
52
|
+ private final ColourManager colourManager;
|
|
53
|
+ /** The table model to modify entries in. */
|
|
54
|
+ private final GenericTableModel<NickColourEntry> model;
|
55
|
55
|
/** nickname textfield. */
|
56
|
56
|
private JTextField nickname;
|
57
|
57
|
/** network textfield. */
|
|
@@ -65,7 +65,7 @@ public class NickColourInputDialog extends StandardDialog implements ActionListe
|
65
|
65
|
* @param parentWindow The window that owns this dialog.
|
66
|
66
|
* @param colourManager The colour manager to use to retrieve colours.
|
67
|
67
|
* @param iconManager The icon manager to use for the dialog icon.
|
68
|
|
- * @param panel The panel that's opening this dialog
|
|
68
|
+ * @param model The table model to modify entries in
|
69
|
69
|
* @param row The row of the table we're editing
|
70
|
70
|
* @param nickname The nickname that's currently set
|
71
|
71
|
* @param network The network that's currently set
|
|
@@ -75,12 +75,13 @@ public class NickColourInputDialog extends StandardDialog implements ActionListe
|
75
|
75
|
final Window parentWindow,
|
76
|
76
|
final ColourManager colourManager,
|
77
|
77
|
final IconManager iconManager,
|
78
|
|
- final NickColourPanel panel, final int row,
|
|
78
|
+ final GenericTableModel<NickColourEntry> model, final int row,
|
79
|
79
|
final String nickname, final String network,
|
80
|
80
|
final Color textcolour) {
|
81
|
81
|
super(parentWindow, ModalityType.MODELESS);
|
|
82
|
+ this.colourManager = colourManager;
|
82
|
83
|
|
83
|
|
- this.panel = panel;
|
|
84
|
+ this.model = model;
|
84
|
85
|
this.row = row;
|
85
|
86
|
|
86
|
87
|
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
|
@@ -99,14 +100,14 @@ public class NickColourInputDialog extends StandardDialog implements ActionListe
|
99
|
100
|
* @param parentWindow The window that owns this dialog.
|
100
|
101
|
* @param colourManager The colour manager to use to retrieve colours.
|
101
|
102
|
* @param iconManager The icon manager to use for the dialog icon.
|
102
|
|
- * @param panel The panel that's opening this dialog
|
|
103
|
+ * @param model The table model to modify entries in
|
103
|
104
|
*/
|
104
|
105
|
public NickColourInputDialog(
|
105
|
106
|
final Window parentWindow,
|
106
|
107
|
final ColourManager colourManager,
|
107
|
108
|
final IconManager iconManager,
|
108
|
|
- final NickColourPanel panel) {
|
109
|
|
- this(parentWindow, colourManager, iconManager, panel, -1, "", "", null);
|
|
109
|
+ final GenericTableModel<NickColourEntry> model) {
|
|
110
|
+ this(parentWindow, colourManager, iconManager, model, -1, "", "", null);
|
110
|
111
|
|
111
|
112
|
isnew = true;
|
112
|
113
|
}
|
|
@@ -132,8 +133,8 @@ public class NickColourInputDialog extends StandardDialog implements ActionListe
|
132
|
133
|
|
133
|
134
|
/** Initialises the listeners. */
|
134
|
135
|
private void initListeners() {
|
135
|
|
- getOkButton().addActionListener(this);
|
136
|
|
- getCancelButton().addActionListener(this);
|
|
136
|
+ getOkButton().addActionListener(e -> saveSettings());
|
|
137
|
+ getCancelButton().addActionListener(e -> dispose());
|
137
|
138
|
}
|
138
|
139
|
|
139
|
140
|
/** Lays out the components. */
|
|
@@ -155,23 +156,18 @@ public class NickColourInputDialog extends StandardDialog implements ActionListe
|
155
|
156
|
pack();
|
156
|
157
|
}
|
157
|
158
|
|
158
|
|
- @Override
|
159
|
|
- public void actionPerformed(final ActionEvent e) {
|
160
|
|
- if (e.getSource() == getOkButton()) {
|
161
|
|
- saveSettings();
|
162
|
|
- }
|
163
|
|
- dispose();
|
164
|
|
- }
|
165
|
|
-
|
166
|
159
|
/** Saves settings. */
|
167
|
160
|
public void saveSettings() {
|
168
|
|
- if (!isnew) {
|
169
|
|
- panel.removeRow(row);
|
170
|
|
- }
|
171
|
|
-
|
172
|
|
- panel.addRow(network.getText().toLowerCase(),
|
173
|
|
- nickname.getText().toLowerCase(),
|
|
161
|
+ final Color colour = NickColourUtils.getColourFromString(colourManager,
|
174
|
162
|
textColour.getColour());
|
|
163
|
+ final NickColourEntry entry = NickColourEntry.create(network.getText().toLowerCase(),
|
|
164
|
+ nickname.getText().toLowerCase(),
|
|
165
|
+ new Color(colour.getRed(), colour.getGreen(), colour.getBlue()));
|
|
166
|
+ if (isnew) {
|
|
167
|
+ model.replaceValueAt(entry, row);
|
|
168
|
+ } else {
|
|
169
|
+ model.addValue(entry);
|
|
170
|
+ }
|
175
|
171
|
}
|
176
|
172
|
|
177
|
173
|
}
|