File Source: PasteDialog.java
/*
P/P * Method: com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog__static_init
*/
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.paste;
24
25 import com.dmdirc.addons.ui_swing.SwingController;
26 import com.dmdirc.addons.ui_swing.UIUtilities;
27 import com.dmdirc.addons.ui_swing.components.frames.InputTextFrame;
28 import com.dmdirc.addons.ui_swing.components.StandardDialog;
29 import com.dmdirc.addons.ui_swing.components.SwingInputHandler;
30 import com.dmdirc.addons.ui_swing.components.TextAreaInputField;
31 import com.dmdirc.addons.ui_swing.components.text.TextLabel;
32
33 import java.awt.Window;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ActionListener;
36 import java.awt.event.KeyEvent;
37 import java.awt.event.KeyListener;
38
39 import javax.swing.AbstractAction;
40 import javax.swing.JButton;
41 import javax.swing.JComponent;
42 import javax.swing.JScrollPane;
43 import javax.swing.KeyStroke;
44 import javax.swing.SwingUtilities;
45 import javax.swing.WindowConstants;
46
47 import net.miginfocom.swing.MigLayout;
48
49 /**
50 * Allows the user to confirm and modify a multi-line paste.
51 *
52 * @author Greboid
53 */
/*
P/P * Method: Window access$000(PasteDialog)
*
* Preconditions:
* x0 != null
* init'ed(x0.parentWindow)
*
* Postconditions:
* return_value == x0.parentWindow
* init'ed(return_value)
*/
54 public final class PasteDialog extends StandardDialog implements ActionListener,
55 KeyListener {
56
57 /**
58 * A version number for this class. It should be changed whenever the class
59 * structure is changed (or anything else that would prevent serialized
60 * objects being unserialized with the new class).
61 */
62 private static final long serialVersionUID = 4;
63 /** Number of lines Label. */
64 private TextLabel infoLabel;
65 /** Text area scrollpane. */
66 private JScrollPane scrollPane;
67 /** Text area. */
68 private TextAreaInputField textField;
69 /** Parent frame. */
70 private final InputTextFrame parent;
71 /** Edit button. */
72 private JButton editButton;
73 /** Parent window. */
74 private Window parentWindow;
75
76 /**
77 * Creates a new instance of PreferencesDialog.
78 *
79 * @param newParent The frame that owns this dialog
80 * @param text text to show in the paste dialog
81 * @param parentWindow Parent window
82 */
83 public PasteDialog(final InputTextFrame newParent, final String text,
84 final Window parentWindow) {
/*
P/P * Method: void com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog(InputTextFrame, String, Window)
*
* Preconditions:
* newParent != null
*
* Presumptions:
* com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog:getOkButton(...)@97 != null
* com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog:getOkButton(...)@98 != null
* init'ed(java.awt.Dialog$ModalityType.MODELESS)
*
* Postconditions:
* this.editButton == &new JButton(initComponents#3)
* this.infoLabel == &new TextLabel(initComponents#4)
* this.parent == newParent
* this.parent != null
* this.parentWindow == parentWindow
* init'ed(this.parentWindow)
* this.scrollPane == &new JScrollPane(initComponents#1)
* this.textField == &new TextAreaInputField(initComponents#2)
* new JButton(initComponents#3) num objects == 1
* new JScrollPane(initComponents#1) num objects == 1
* ...
*/
85 super(parentWindow, ModalityType.MODELESS);
86
87 this.parent = newParent;
88 this.parentWindow = parentWindow;
89
90 initComponents(text);
91 initListeners();
92
93 setFocusTraversalPolicy(new PasteDialogFocusTraversalPolicy(
94 getCancelButton(), editButton, getOkButton()));
95
96 setFocusable(true);
97 getOkButton().requestFocusInWindow();
98 getOkButton().setSelected(true);
99
100 pack();
101 setLocationRelativeTo(parentWindow);
102 }
103
104 /**
105 * Initialises GUI components.
106 *
107 * @param text text to show in the dialog
108 */
109 private void initComponents(final String text) {
/*
P/P * Method: void initComponents(String)
*
* Preconditions:
* this.parent != null
*
* Presumptions:
* com.dmdirc.addons.ui_swing.components.frames.InputTextFrame:getContainer(...)@124 != null
* com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog:getContentPane(...)@137 != null
* com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog:getContentPane(...)@138 != null
* com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog:getContentPane(...)@139 != null
* com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog:getContentPane(...)@140 != null
* ...
*
* Postconditions:
* this.editButton == &new JButton(initComponents#3)
* this.infoLabel == &new TextLabel(initComponents#4)
* this.scrollPane == &new JScrollPane(initComponents#1)
* this.textField == &new TextAreaInputField(initComponents#2)
* new JButton(initComponents#3) num objects == 1
* new JScrollPane(initComponents#1) num objects == 1
* new SimpleAttributeSet(TextLabel#6) num objects == 1
* new TextAreaInputField(initComponents#2) num objects == 1
* new TextLabel(initComponents#4) num objects == 1
* this.infoLabel.sas == &new SimpleAttributeSet(TextLabel#6)
*/
110 scrollPane = new JScrollPane();
111 textField = new TextAreaInputField(text);
112 editButton = new JButton("Edit");
113 infoLabel = new TextLabel();
114
115 UIUtilities.addUndoManager(textField);
116
117 orderButtons(new JButton(), new JButton());
118 getOkButton().setText("Send");
119
120 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
121 setTitle("Multi-line paste");
122 setResizable(false);
123
124 infoLabel.setText("This will be sent as "
125 + parent.getContainer().getNumLines(textField.getText())
126 + " lines. Are you sure you want to continue?");
127
128 textField.setColumns(50);
129 textField.setRows(10);
130
131 new SwingInputHandler(textField, parent.getCommandParser(), parent)
132 .setTypes(false, false, true, false);
133
134 scrollPane.setViewportView(textField);
135 scrollPane.setVisible(false);
136
137 getContentPane().setLayout(new MigLayout("fill, hidemode 3"));
138 getContentPane().add(infoLabel, "wrap, growx, pushx, span 3");
139 getContentPane().add(scrollPane, "wrap, grow, push, span 3");
140 getContentPane().add(getLeftButton(), "right, sg button");
141 getContentPane().add(editButton, "right, sg button");
142 getContentPane().add(getRightButton(), "right, sg button");
143 }
144
145 /**
146 * Initialises listeners for this dialog.
147 */
148 private void initListeners() {
/*
P/P * Method: void initListeners()
*
* Preconditions:
* this.editButton != null
* this.textField != null
*
* Presumptions:
* com.dmdirc.addons.ui_swing.components.TextAreaInputField:getActionMap(...)@189 != null
* com.dmdirc.addons.ui_swing.components.TextAreaInputField:getInputMap(...)@200 != null
* com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog:getCancelButton(...)@150 != null
* com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog:getOkButton(...)@149 != null
* com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog:getRootPane(...)@154 != null
* ...
*/
149 getOkButton().addActionListener(this);
150 getCancelButton().addActionListener(this);
151 editButton.addActionListener(this);
152 textField.addKeyListener(this);
153
154 getRootPane().getActionMap().put("rightArrowAction",
/*
P/P * Method: void com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog$1(PasteDialog, String)
*/
155 new AbstractAction("rightArrowAction") {
156
157 private static final long serialVersionUID = 1;
158
159 /** {@inheritDoc} */
160 @Override
161 public void actionPerformed(final ActionEvent evt) {
/*
P/P * Method: void actionPerformed(ActionEvent)
*
* Presumptions:
* com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog:getFocusTraversalPolicy(...)@162 != null
* java.awt.FocusTraversalPolicy:getComponentAfter(...)@162 != null
*/
162 final JButton button = (JButton) getFocusTraversalPolicy().
163 getComponentAfter(PasteDialog.this, getFocusOwner());
164 button.requestFocusInWindow();
165 button.setSelected(true);
166 }
167 });
168
169 getRootPane().getActionMap().put("leftArrowAction",
/*
P/P * Method: void com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog$2(PasteDialog, String)
*/
170 new AbstractAction("leftArrowAction") {
171
172 private static final long serialVersionUID = 1;
173
174 /** {@inheritDoc} */
175 @Override
176 public void actionPerformed(final ActionEvent evt) {
/*
P/P * Method: void actionPerformed(ActionEvent)
*
* Presumptions:
* com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog:getFocusTraversalPolicy(...)@177 != null
* java.awt.FocusTraversalPolicy:getComponentBefore(...)@177 != null
*/
177 final JButton button = (JButton) getFocusTraversalPolicy().
178 getComponentBefore(PasteDialog.this, getFocusOwner());
179 button.requestFocusInWindow();
180 button.setSelected(true);
181 }
182 });
183
184 getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
185 KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), "rightArrowAction");
186 getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
187 KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), "leftArrowAction");
188
189 textField.getActionMap().put("ctrlEnterAction",
/*
P/P * Method: void com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog$3(PasteDialog, String)
*/
190 new AbstractAction("ctrlEnterAction") {
191
192 private static final long serialVersionUID = 1;
193
194 /** {@inheritDoc} */
195 @Override
196 public void actionPerformed(final ActionEvent evt) {
/*
P/P * Method: void actionPerformed(ActionEvent)
*
* Presumptions:
* com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog:getOkButton(...)@197 != null
*/
197 getOkButton().doClick();
198 }
199 });
200 textField.getInputMap(JComponent.WHEN_FOCUSED).put(
201 KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, UIUtilities.getCtrlDownMask()),
202 "ctrlEnterAction");
203
/*
P/P * Method: void com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog$4(PasteDialog)
*/
204 final ActionListener enterListener = new ActionListener() {
205
206 /** {@inheritDoc} */
207 @Override
208 public void actionPerformed(final ActionEvent actionEvent) {
/*
P/P * Method: void actionPerformed(ActionEvent)
*
* Presumptions:
* com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog:getOkButton(...)@209 != null
*/
209 getOkButton().doClick();
210 }
211 };
212 final KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
213 getRootPane().registerKeyboardAction(enterListener, enter,
214 JComponent.WHEN_IN_FOCUSED_WINDOW);
215 }
216
217 /**
218 * Handles the actions for the dialog.
219 *
220 * @param actionEvent Action event
221 */
222 @Override
223 public void actionPerformed(final ActionEvent actionEvent) {
/*
P/P * Method: void actionPerformed(ActionEvent)
*
* Preconditions:
* actionEvent != null
* (soft) this.editButton != null
* (soft) this.infoLabel != null
* (soft) init'ed(this.infoLabel.sas)
* (soft) this.parent != null
* (soft) this.scrollPane != null
* (soft) this.textField != null
*
* Presumptions:
* com.dmdirc.addons.ui_swing.components.TextAreaInputField:getText(...)@225 != null
* com.dmdirc.addons.ui_swing.components.TextAreaInputField:getText(...)@226 != null
* com.dmdirc.addons.ui_swing.components.frames.InputTextFrame:getContainer(...)@240 != null
* com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog:getCancelButton(...)@251 != null
* com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog:getOkButton(...)@224 != null
*
* Test Vectors:
* java.lang.Object:equals(...)@224: {0}, {1}
* java.lang.Object:equals(...)@236: {0}, {1}
* java.lang.Object:equals(...)@251: {0}, {1}
* java.lang.String:isEmpty(...)@225: {1}, {0}
*/
224 if (getOkButton().equals(actionEvent.getSource())) {
225 if (!textField.getText().isEmpty()) {
226 final String[] lines = textField.getText().split("(\n|\r\n|\r)",
227 Integer.MAX_VALUE);
228 for (String line : lines) {
229 if (!line.isEmpty()) {
230 parent.getContainer().sendLine(line);
231 parent.getInputHandler().addToBuffer(line);
232 }
233 }
234 }
235 dispose();
236 } else if (editButton.equals(actionEvent.getSource())) {
237 editButton.setEnabled(false);
238 setResizable(true);
239 scrollPane.setVisible(true);
240 infoLabel.setText("This will be sent as "
241 + parent.getContainer().getNumLines(textField.getText())
242 + " lines.");
243 pack();
/*
P/P * Method: void com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialog$5(PasteDialog)
*/
244 SwingUtilities.invokeLater(new Runnable(){
245
246 @Override
247 public void run() {
/*
P/P * Method: void run()
*
* Preconditions:
* init'ed(this.parentWindow)
*/
248 setLocationRelativeTo(parentWindow);
249 }
250 });
251 } else if (getCancelButton().equals(actionEvent.getSource())) {
252 dispose();
253 }
254 }
255
256 /**
257 * {@inheritDoc}
258 *
259 * @param e Key event
260 */
261 @Override
262 public void keyTyped(final KeyEvent e) {
/*
P/P * Method: void keyTyped(KeyEvent)
*
* Preconditions:
* this.infoLabel != null
* this.parent != null
* this.textField != null
* (soft) init'ed(this.infoLabel.sas)
*
* Presumptions:
* com.dmdirc.addons.ui_swing.components.frames.InputTextFrame:getContainer(...)@263 != null
*/
263 infoLabel.setText("This will be sent as "
264 + parent.getContainer().getNumLines(textField.getText())
265 + " lines.");
266 }
267
268 /**
269 * {@inheritDoc}
270 *
271 * @param e Key event
272 */
273 @Override
274 public void keyPressed(final KeyEvent e) {
275 //Ignore.
/*
P/P * Method: void keyPressed(KeyEvent)
*/
276 }
277
278 /**
279 * {@inheritDoc}
280 *
281 * @param e Key event
282 */
283 @Override
284 public void keyReleased(final KeyEvent e) {
285 //Ignore.
/*
P/P * Method: void keyReleased(KeyEvent)
*/
286 }
287 }
SofCheck Inspector Build Version : 2.17854
| PasteDialog.java |
2009-Jun-25 01:54:24 |
| PasteDialog.class |
2009-Sep-02 17:04:16 |
| PasteDialog$1.class |
2009-Sep-02 17:04:16 |
| PasteDialog$2.class |
2009-Sep-02 17:04:16 |
| PasteDialog$3.class |
2009-Sep-02 17:04:16 |
| PasteDialog$4.class |
2009-Sep-02 17:04:16 |
| PasteDialog$5.class |
2009-Sep-02 17:04:16 |