File Source: StringTransferable.java
/*
P/P * Method: com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable__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.actioneditor;
24
25 import com.dmdirc.logger.ErrorLevel;
26 import com.dmdirc.logger.Logger;
27
28 import java.awt.datatransfer.DataFlavor;
29 import java.awt.datatransfer.Transferable;
30 import java.awt.datatransfer.UnsupportedFlavorException;
31
32 /**
33 * String transfer handler.
34 */
35 public class StringTransferable implements Transferable {
36
37 /** Local tranfer flavour. */
38 private DataFlavor localStringFlavor;
39 /** Serial transfer flavour. */
40 private final DataFlavor serialStringFlavor;
41 /** Transferred string. */
42 private final String data;
43
44 /**
45 * Creates a new string transferable object.
46 *
47 * @param data String to transger
48 */
49 public StringTransferable(final String data) {
/*
P/P * Method: void com.dmdirc.addons.ui_swing.dialogs.actioneditor.StringTransferable(String)
*
* Presumptions:
* init'ed(com.dmdirc.logger.ErrorLevel.LOW)
*
* Postconditions:
* this.data == data
* init'ed(this.data)
* this.localStringFlavor in Addr_Set{null,&new DataFlavor(StringTransferable#1)}
* this.serialStringFlavor == &new DataFlavor(StringTransferable#3)
* new DataFlavor(StringTransferable#1) num objects <= 1
* new DataFlavor(StringTransferable#3) num objects == 1
*/
50 super();
51
52 this.data = data;
53
54 try {
55 localStringFlavor = new DataFlavor(
56 DataFlavor.javaJVMLocalObjectMimeType +
57 ";class=java.lang.String");
58 } catch (ClassNotFoundException e) {
59 Logger.userError(ErrorLevel.LOW, "unable to create data flavor: " +
60 e.getMessage());
61 }
62 serialStringFlavor = new DataFlavor(String.class, "String");
63 }
64
65 /** {@inheritDoc} */
66 @Override
67 public DataFlavor[] getTransferDataFlavors() {
/*
P/P * Method: DataFlavor[] getTransferDataFlavors()
*
* Preconditions:
* init'ed(this.localStringFlavor)
*
* Postconditions:
* return_value == &new DataFlavor[](getTransferDataFlavors#1)
* new DataFlavor[](getTransferDataFlavors#1) num objects == 1
* return_value.length == 2
* return_value[0] == this.localStringFlavor
* init'ed(return_value[0])
* return_value[1] == this.serialStringFlavor
* init'ed(return_value[1])
*/
68 return new DataFlavor[]{localStringFlavor, serialStringFlavor,};
69 }
70
71 /** {@inheritDoc} */
72 @Override
73 public boolean isDataFlavorSupported(final DataFlavor flavor) {
/*
P/P * Method: bool isDataFlavorSupported(DataFlavor)
*
* Preconditions:
* this.localStringFlavor != null
* (soft) this.serialStringFlavor != null
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* java.awt.datatransfer.DataFlavor:equals(...)@74: {0}, {1}
* java.awt.datatransfer.DataFlavor:equals(...)@78: {0}, {1}
*/
74 if (localStringFlavor.equals(flavor)) {
75 return true;
76 }
77
78 if (serialStringFlavor.equals(flavor)) {
79 return true;
80 }
81
82 return false;
83 }
84
85 /**
86 * {@inheritDoc}
87 *
88 * @return String to transfer
89 */
90 @Override
91 public Object getTransferData(final DataFlavor flavor) throws UnsupportedFlavorException {
/*
P/P * Method: Object getTransferData(DataFlavor)
*
* Preconditions:
* this.localStringFlavor != null
* (soft) this.serialStringFlavor != null
*
* Presumptions:
* java.awt.datatransfer.DataFlavor:equals(...)@74 != 0 | java.awt.datatransfer.DataFlavor:equals(...)@78 != 0
*
* Postconditions:
* return_value == this.data
* init'ed(return_value)
*/
92 if (!isDataFlavorSupported(flavor)) {
93 throw new UnsupportedFlavorException(flavor);
94 }
95
96 return data;
97 }
98 }
SofCheck Inspector Build Version : 2.17854
| StringTransferable.java |
2009-Jun-25 01:54:24 |
| StringTransferable.class |
2009-Sep-02 17:04:16 |