|
@@ -0,0 +1,80 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (c) 2006-2009 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
|
+
|
|
23
|
+package com.dmdirc.addons.ui_swing.dialogs;
|
|
24
|
+
|
|
25
|
+import javax.swing.JDialog;
|
|
26
|
+import javax.swing.JOptionPane;
|
|
27
|
+
|
|
28
|
+/**
|
|
29
|
+ * Extension of JOptionPane to allow Word Wrapping.
|
|
30
|
+ *
|
|
31
|
+ * @author shane
|
|
32
|
+ */
|
|
33
|
+public class DMDircJOptionPane extends JOptionPane {
|
|
34
|
+ /** Maximum characters per line. */
|
|
35
|
+ private int maxCharactersPerLineCount = Integer.MAX_VALUE;
|
|
36
|
+
|
|
37
|
+ /** Title of Dialog. */
|
|
38
|
+ private String title = "";
|
|
39
|
+
|
|
40
|
+ /**
|
|
41
|
+ * Create a DMDircJOptionPane.
|
|
42
|
+ *
|
|
43
|
+ * @param title Title to use
|
|
44
|
+ * @param message Message to show
|
|
45
|
+ * @param messageType Message Type.
|
|
46
|
+ * @param optionType Options.
|
|
47
|
+ */
|
|
48
|
+ public DMDircJOptionPane(final String title, final String message, final int messageType, final int optionType) {
|
|
49
|
+ super(message, messageType, optionType);
|
|
50
|
+ this.title = title;
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+ /**
|
|
54
|
+ * Set the maximum number of characters per line.
|
|
55
|
+ *
|
|
56
|
+ * @param maxCharactersPerLineCount
|
|
57
|
+ */
|
|
58
|
+ public void setMaxCharactersPerLineCount(final int maxCharactersPerLineCount) {
|
|
59
|
+ this.maxCharactersPerLineCount = maxCharactersPerLineCount;
|
|
60
|
+ }
|
|
61
|
+
|
|
62
|
+ /** {@inheritDoc} */
|
|
63
|
+ @Override
|
|
64
|
+ public int getMaxCharactersPerLineCount() {
|
|
65
|
+ return this.maxCharactersPerLineCount;
|
|
66
|
+ }
|
|
67
|
+
|
|
68
|
+ /** Show this dialog. */
|
|
69
|
+ public void showDialog() {
|
|
70
|
+ // Recalculate width, because JOptionPane calculates it before the
|
|
71
|
+ // constructor gets a chance to finish, and so gets a max chars of 0.
|
|
72
|
+ final Object oldMessage = this.getMessage();
|
|
73
|
+ this.setMessage("");
|
|
74
|
+ this.setMessage(oldMessage);
|
|
75
|
+
|
|
76
|
+ final JDialog dialog = createDialog(title);
|
|
77
|
+ dialog.setVisible(true);
|
|
78
|
+ dialog.dispose();
|
|
79
|
+ }
|
|
80
|
+}
|