16705
|
1 |
/*
|
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
test
|
|
26 |
@bug 7075105
|
|
27 |
@summary WIN: Provide a way to format HTML on drop
|
|
28 |
@author Denis Fokin: area=datatransfer
|
|
29 |
@run applet/manual=yesno ManualHTMLDataFlavorTest
|
|
30 |
*/
|
|
31 |
|
|
32 |
import java.applet.Applet;
|
|
33 |
import java.awt.*;
|
|
34 |
import java.awt.datatransfer.DataFlavor;
|
|
35 |
import java.awt.datatransfer.Transferable;
|
|
36 |
import java.awt.datatransfer.UnsupportedFlavorException;
|
|
37 |
import java.awt.dnd.*;
|
|
38 |
import java.io.IOException;
|
|
39 |
|
|
40 |
public class ManualHTMLDataFlavorTest extends Applet {
|
|
41 |
|
|
42 |
class DropPane extends Panel implements DropTargetListener {
|
|
43 |
|
|
44 |
DropPane() {
|
|
45 |
requestFocus();
|
|
46 |
setBackground(Color.red);
|
|
47 |
setDropTarget(new DropTarget(this, DnDConstants.ACTION_COPY, this));
|
|
48 |
}
|
|
49 |
|
|
50 |
@Override
|
|
51 |
public Dimension getPreferredSize() {
|
|
52 |
return new Dimension(200,200);
|
|
53 |
}
|
|
54 |
|
|
55 |
@Override
|
|
56 |
public void dragEnter(DropTargetDragEvent dtde) {
|
|
57 |
dtde.acceptDrag(DnDConstants.ACTION_COPY);
|
|
58 |
}
|
|
59 |
|
|
60 |
@Override
|
|
61 |
public void dragOver(DropTargetDragEvent dtde) {
|
|
62 |
dtde.acceptDrag(DnDConstants.ACTION_COPY);
|
|
63 |
}
|
|
64 |
|
|
65 |
@Override
|
|
66 |
public void dropActionChanged(DropTargetDragEvent dtde) {
|
|
67 |
dtde.acceptDrag(DnDConstants.ACTION_COPY);
|
|
68 |
}
|
|
69 |
|
|
70 |
@Override
|
|
71 |
public void dragExit(DropTargetEvent dte) {}
|
|
72 |
|
|
73 |
@Override
|
|
74 |
public void drop(DropTargetDropEvent dtde) {
|
|
75 |
if (!dtde.isDataFlavorSupported(DataFlavor.allHtmlFlavor)) {
|
|
76 |
Sysout.println("DataFlavor.allHtmlFlavor is not present in the system clipboard");
|
|
77 |
dtde.rejectDrop();
|
|
78 |
return;
|
|
79 |
} else if (!dtde.isDataFlavorSupported(DataFlavor.fragmentHtmlFlavor)) {
|
|
80 |
Sysout.println("DataFlavor.fragmentHtmlFlavor is not present in the system clipboard");
|
|
81 |
dtde.rejectDrop();
|
|
82 |
return;
|
|
83 |
} else if (!dtde.isDataFlavorSupported(DataFlavor.selectionHtmlFlavor)) {
|
|
84 |
Sysout.println("DataFlavor.selectionHtmlFlavor is not present in the system clipboard");
|
|
85 |
dtde.rejectDrop();
|
|
86 |
return;
|
|
87 |
}
|
|
88 |
|
|
89 |
dtde.acceptDrop(DnDConstants.ACTION_COPY);
|
|
90 |
|
|
91 |
Transferable t = dtde.getTransferable();
|
|
92 |
try {
|
|
93 |
Sysout.println("ALL:");
|
|
94 |
Sysout.println(t.getTransferData(DataFlavor.allHtmlFlavor).toString());
|
|
95 |
Sysout.println("FRAGMENT:");
|
|
96 |
Sysout.println(t.getTransferData(DataFlavor.fragmentHtmlFlavor).toString());
|
|
97 |
Sysout.println("SELECTION:");
|
|
98 |
Sysout.println(t.getTransferData(DataFlavor.selectionHtmlFlavor).toString());
|
|
99 |
} catch (UnsupportedFlavorException e) {
|
|
100 |
e.printStackTrace();
|
|
101 |
} catch (IOException e) {
|
|
102 |
e.printStackTrace();
|
|
103 |
}
|
|
104 |
|
|
105 |
}
|
|
106 |
}
|
|
107 |
|
|
108 |
public void init() {
|
|
109 |
|
|
110 |
String[] instructions =
|
|
111 |
{
|
|
112 |
"1) The test contains a drop-aware panel with a red background",
|
|
113 |
"2) Open some page in a browser, select some text",
|
|
114 |
" Drag and drop it on the red panel",
|
|
115 |
" IMPORTANT NOTE: the page should be stored locally.",
|
|
116 |
" otherwise for instance iexplore can prohibit drag and drop from",
|
|
117 |
" the browser to other applications because of",
|
|
118 |
" the protected mode restrictions.",
|
|
119 |
"3) Check the data in the output area of this dialog",
|
|
120 |
"5) The output should not contain information that any of",
|
|
121 |
" flavors is not present in the system clipboard",
|
|
122 |
"6) The output should contain data in three different formats",
|
|
123 |
" provided by the system clipboard",
|
|
124 |
" - Data after the \"ALL:\" marker should include the data",
|
|
125 |
" from the the \"SELECTION:\" marker",
|
|
126 |
" - Data after the \"FRAGMENT\" marker should include the data",
|
|
127 |
" from the \"SELECTION:\" marker and may be some closing",
|
|
128 |
" tags could be added to the mark-up",
|
|
129 |
" - Data after the \"SELECTION:\" marker should correspond",
|
|
130 |
" to the data selected in the browser",
|
|
131 |
"7) If the above requirements are met, the test is passed"
|
|
132 |
};
|
|
133 |
|
|
134 |
add(new DropPane());
|
|
135 |
Sysout.createDialogWithInstructions( instructions );
|
|
136 |
|
|
137 |
new ManualHTMLDataFlavorTest();
|
|
138 |
}
|
|
139 |
|
|
140 |
public void start ()
|
|
141 |
{
|
|
142 |
setSize (200,200);
|
|
143 |
setVisible(true);
|
|
144 |
validate();
|
|
145 |
|
|
146 |
}// start()
|
|
147 |
|
|
148 |
}
|
|
149 |
|
|
150 |
|
|
151 |
/* Place other classes related to the test after this line */
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
/****************************************************
|
|
158 |
Standard Test Machinery
|
|
159 |
DO NOT modify anything below -- it's a standard
|
|
160 |
chunk of code whose purpose is to make user
|
|
161 |
interaction uniform, and thereby make it simpler
|
|
162 |
to read and understand someone else's test.
|
|
163 |
****************************************************/
|
|
164 |
|
|
165 |
/**
|
|
166 |
This is part of the standard test machinery.
|
|
167 |
It creates a dialog (with the instructions), and is the interface
|
|
168 |
for sending text messages to the user.
|
|
169 |
To print the instructions, send an array of strings to Sysout.createDialog
|
|
170 |
WithInstructions method. Put one line of instructions per array entry.
|
|
171 |
To display a message for the tester to see, simply call Sysout.println
|
|
172 |
with the string to be displayed.
|
|
173 |
This mimics System.out.println but works within the test harness as well
|
|
174 |
as standalone.
|
|
175 |
*/
|
|
176 |
|
|
177 |
class Sysout
|
|
178 |
{
|
|
179 |
private static TestDialog dialog;
|
|
180 |
|
|
181 |
public static void createDialogWithInstructions( String[] instructions )
|
|
182 |
{
|
|
183 |
dialog = new TestDialog( new Frame(), "Instructions" );
|
|
184 |
dialog.printInstructions( instructions );
|
|
185 |
dialog.setVisible(true);
|
|
186 |
println( "Any messages for the tester will display here." );
|
|
187 |
}
|
|
188 |
|
|
189 |
public static void createDialog( )
|
|
190 |
{
|
|
191 |
dialog = new TestDialog( new Frame(), "Instructions" );
|
|
192 |
String[] defInstr = { "Instructions will appear here. ", "" } ;
|
|
193 |
dialog.printInstructions( defInstr );
|
|
194 |
dialog.setVisible(true);
|
|
195 |
println( "Any messages for the tester will display here." );
|
|
196 |
}
|
|
197 |
|
|
198 |
|
|
199 |
public static void printInstructions( String[] instructions )
|
|
200 |
{
|
|
201 |
dialog.printInstructions( instructions );
|
|
202 |
}
|
|
203 |
|
|
204 |
|
|
205 |
public static void println( String messageIn )
|
|
206 |
{
|
|
207 |
dialog.displayMessage( messageIn );
|
|
208 |
}
|
|
209 |
|
|
210 |
}// Sysout class
|
|
211 |
|
|
212 |
/**
|
|
213 |
This is part of the standard test machinery. It provides a place for the
|
|
214 |
test instructions to be displayed, and a place for interactive messages
|
|
215 |
to the user to be displayed.
|
|
216 |
To have the test instructions displayed, see Sysout.
|
|
217 |
To have a message to the user be displayed, see Sysout.
|
|
218 |
Do not call anything in this dialog directly.
|
|
219 |
*/
|
|
220 |
class TestDialog extends Dialog
|
|
221 |
{
|
|
222 |
|
|
223 |
TextArea instructionsText;
|
|
224 |
TextArea messageText;
|
|
225 |
int maxStringLength = 80;
|
|
226 |
|
|
227 |
//DO NOT call this directly, go through Sysout
|
|
228 |
public TestDialog( Frame frame, String name )
|
|
229 |
{
|
|
230 |
super( frame, name );
|
|
231 |
int scrollBoth = TextArea.SCROLLBARS_BOTH;
|
|
232 |
instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
|
|
233 |
add( "North", instructionsText );
|
|
234 |
|
|
235 |
messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
|
|
236 |
add("Center", messageText);
|
|
237 |
|
|
238 |
pack();
|
|
239 |
|
|
240 |
setVisible(true);
|
|
241 |
}// TestDialog()
|
|
242 |
|
|
243 |
//DO NOT call this directly, go through Sysout
|
|
244 |
public void printInstructions( String[] instructions )
|
|
245 |
{
|
|
246 |
//Clear out any current instructions
|
|
247 |
instructionsText.setText( "" );
|
|
248 |
|
|
249 |
//Go down array of instruction strings
|
|
250 |
|
|
251 |
String printStr, remainingStr;
|
|
252 |
for( int i=0; i < instructions.length; i++ )
|
|
253 |
{
|
|
254 |
//chop up each into pieces maxSringLength long
|
|
255 |
remainingStr = instructions[ i ];
|
|
256 |
while( remainingStr.length() > 0 )
|
|
257 |
{
|
|
258 |
//if longer than max then chop off first max chars to print
|
|
259 |
if( remainingStr.length() >= maxStringLength )
|
|
260 |
{
|
|
261 |
//Try to chop on a word boundary
|
|
262 |
int posOfSpace = remainingStr.
|
|
263 |
lastIndexOf( ' ', maxStringLength - 1 );
|
|
264 |
|
|
265 |
if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
|
|
266 |
|
|
267 |
printStr = remainingStr.substring( 0, posOfSpace + 1 );
|
|
268 |
remainingStr = remainingStr.substring( posOfSpace + 1 );
|
|
269 |
}
|
|
270 |
//else just print
|
|
271 |
else
|
|
272 |
{
|
|
273 |
printStr = remainingStr;
|
|
274 |
remainingStr = "";
|
|
275 |
}
|
|
276 |
|
|
277 |
instructionsText.append( printStr + "\n" );
|
|
278 |
|
|
279 |
}// while
|
|
280 |
|
|
281 |
}// for
|
|
282 |
|
|
283 |
}//printInstructions()
|
|
284 |
|
|
285 |
//DO NOT call this directly, go through Sysout
|
|
286 |
public void displayMessage( String messageIn )
|
|
287 |
{
|
|
288 |
messageText.append( messageIn + "\n" );
|
|
289 |
System.out.println(messageIn);
|
|
290 |
}
|
|
291 |
|
|
292 |
}// TestDialog class
|