1 /*
2 * Copyright (c) 1997, 2017, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
26
27 import java.awt.Component;
28 import java.awt.Container;
29 import java.awt.Rectangle;
30 import java.awt.Window;
31 import java.awt.event.ActionListener;
32 import java.io.File;
33
34 import javax.swing.ComboBoxModel;
35 import javax.swing.Icon;
36 import javax.swing.JButton;
37 import javax.swing.JComboBox;
38 import javax.swing.JComponent;
39 import javax.swing.JDialog;
40 import javax.swing.JFileChooser;
41 import javax.swing.JList;
42 import javax.swing.JTable;
43 import javax.swing.JTextField;
44 import javax.swing.JToggleButton;
45 import javax.swing.ListModel;
46 import javax.swing.filechooser.FileFilter;
47 import javax.swing.filechooser.FileSystemView;
48 import javax.swing.filechooser.FileView;
49 import javax.swing.plaf.FileChooserUI;
50 import javax.swing.table.TableModel;
51
52 import org.netbeans.jemmy.ComponentChooser;
53 import org.netbeans.jemmy.ComponentSearcher;
54 import org.netbeans.jemmy.JemmyException;
55 import org.netbeans.jemmy.JemmyProperties;
56 import org.netbeans.jemmy.Outputable;
57 import org.netbeans.jemmy.TestOut;
58 import org.netbeans.jemmy.Timeoutable;
59 import org.netbeans.jemmy.Timeouts;
60 import org.netbeans.jemmy.Waitable;
61 import org.netbeans.jemmy.Waiter;
62
63 /**
64 *
65 * Class provides methods to cover main JFileChooser component functionality.
323 }
324
325 @Override
326 public String getDescription() {
327 return "JTextField";
328 }
329
330 @Override
331 public String toString() {
332 return "JFileChooserOperator.getPathField.ComponentChooser{description = " + getDescription() + '}';
333 }
334 }));
335 }
336
337 /**
338 * Returns either a JList or JTable, depending on the implementation.
339 *
340 * @return a component being used to display directory content.
341 */
342 public Component getFileList() {
343 return innerSearcher.
344 findComponent(new ComponentChooser() {
345 @Override
346 public boolean checkComponent(Component comp) {
347 return (comp != null
348 && (comp instanceof JList || comp instanceof JTable));
349 }
350
351 @Override
352 public String getDescription() {
353 return "JList or JTable used to show list of files";
354 }
355
356 @Override
357 public String toString() {
358 return "JFileChooserOperator.getFileList.ComponentChooser{description = " + getDescription() + '}';
359 }
360 });
361 }
362
363 /**
364 * Pushes approve button.
365 */
366 public void approve() {
367 getQueueTool().waitEmpty();
368 output.printTrace("Push approve button in JFileChooser\n : "
369 + toStringSource());
370 JButtonOperator approveOper = new JButtonOperator(getApproveButton());
371 approveOper.copyEnvironment(this);
372 approveOper.setOutput(output.createErrorOutput());
373 approveOper.push();
374 }
375
376 /**
377 * Pushes cancel button.
378 */
379 public void cancel() {
380 output.printTrace("Push cancel button in JFileChooser\n : "
416 + toStringSource());
417 //workaround
418 setCurrentDirectory(getCurrentDirectory().getParentFile());
419 //JButtonOperator upOper = new JButtonOperator(getUpLevelButton());
420 //upOper.copyEnvironment(this);
421 //upOper.setOutput(output.createErrorOutput());
422 //upOper.push();
423 waitPainted(-1);
424 return getCurrentDirectory();
425 }
426
427 /**
428 * Pushes "Home" button.
429 *
430 * @return new current directory
431 */
432 public File goHome() {
433 getQueueTool().waitEmpty();
434 output.printTrace("Go home in JFileChooser\n : "
435 + toStringSource());
436 JButtonOperator homeOper = new JButtonOperator(getHomeButton());
437 homeOper.copyEnvironment(this);
438 homeOper.setOutput(output.createErrorOutput());
439 homeOper.push();
440 waitPainted(-1);
441 return getCurrentDirectory();
442 }
443
444 /**
445 * Clicks on file in the list.
446 *
447 * @param index Ordinal file index.
448 * @param clickCount click count
449 */
450 public void clickOnFile(int index, int clickCount) {
451 getQueueTool().waitEmpty();
452 output.printTrace("Click " + Integer.toString(clickCount)
453 + " times on " + Integer.toString(index)
454 + "`th file in JFileChooser\n : "
455 + toStringSource());
456 waitPainted(index);
|
1 /*
2 * Copyright (c) 1997, 2018, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
26
27 import java.awt.Component;
28 import java.awt.Container;
29 import java.awt.Rectangle;
30 import java.awt.Window;
31 import java.awt.event.ActionListener;
32 import java.io.File;
33
34 import javax.swing.ComboBoxModel;
35 import javax.swing.Icon;
36 import javax.swing.JButton;
37 import javax.swing.JComboBox;
38 import javax.swing.JComponent;
39 import javax.swing.JDialog;
40 import javax.swing.JFileChooser;
41 import javax.swing.JList;
42 import javax.swing.JTable;
43 import javax.swing.JTextField;
44 import javax.swing.JToggleButton;
45 import javax.swing.ListModel;
46 import javax.swing.UIManager;
47 import javax.swing.filechooser.FileFilter;
48 import javax.swing.filechooser.FileSystemView;
49 import javax.swing.filechooser.FileView;
50 import javax.swing.plaf.FileChooserUI;
51 import javax.swing.table.TableModel;
52
53 import org.netbeans.jemmy.ComponentChooser;
54 import org.netbeans.jemmy.ComponentSearcher;
55 import org.netbeans.jemmy.JemmyException;
56 import org.netbeans.jemmy.JemmyProperties;
57 import org.netbeans.jemmy.Outputable;
58 import org.netbeans.jemmy.TestOut;
59 import org.netbeans.jemmy.Timeoutable;
60 import org.netbeans.jemmy.Timeouts;
61 import org.netbeans.jemmy.Waitable;
62 import org.netbeans.jemmy.Waiter;
63
64 /**
65 *
66 * Class provides methods to cover main JFileChooser component functionality.
324 }
325
326 @Override
327 public String getDescription() {
328 return "JTextField";
329 }
330
331 @Override
332 public String toString() {
333 return "JFileChooserOperator.getPathField.ComponentChooser{description = " + getDescription() + '}';
334 }
335 }));
336 }
337
338 /**
339 * Returns either a JList or JTable, depending on the implementation.
340 *
341 * @return a component being used to display directory content.
342 */
343 public Component getFileList() {
344 int index = 0;
345 // In GTK and Motif L&F, there are two JLists, one is to list folders
346 // and second one one is to list files
347 if (UIManager.getLookAndFeel().getID().equals("Motif")
348 || UIManager.getLookAndFeel().getID().equals("GTK")) {
349 index =1;
350 }
351 return innerSearcher.
352 findComponent(new ComponentChooser() {
353 @Override
354 public boolean checkComponent(Component comp) {
355 return (comp != null
356 && (comp instanceof JList || comp instanceof JTable));
357 }
358
359 @Override
360 public String getDescription() {
361 return "JList or JTable used to show list of files";
362 }
363
364 @Override
365 public String toString() {
366 return "JFileChooserOperator.getFileList.ComponentChooser{description = " + getDescription() + '}';
367 }
368 }, index);
369 }
370
371 /**
372 * Pushes approve button.
373 */
374 public void approve() {
375 getQueueTool().waitEmpty();
376 output.printTrace("Push approve button in JFileChooser\n : "
377 + toStringSource());
378 JButtonOperator approveOper = new JButtonOperator(getApproveButton());
379 approveOper.copyEnvironment(this);
380 approveOper.setOutput(output.createErrorOutput());
381 approveOper.push();
382 }
383
384 /**
385 * Pushes cancel button.
386 */
387 public void cancel() {
388 output.printTrace("Push cancel button in JFileChooser\n : "
424 + toStringSource());
425 //workaround
426 setCurrentDirectory(getCurrentDirectory().getParentFile());
427 //JButtonOperator upOper = new JButtonOperator(getUpLevelButton());
428 //upOper.copyEnvironment(this);
429 //upOper.setOutput(output.createErrorOutput());
430 //upOper.push();
431 waitPainted(-1);
432 return getCurrentDirectory();
433 }
434
435 /**
436 * Pushes "Home" button.
437 *
438 * @return new current directory
439 */
440 public File goHome() {
441 getQueueTool().waitEmpty();
442 output.printTrace("Go home in JFileChooser\n : "
443 + toStringSource());
444 AbstractButtonOperator homeOper;
445 // In Windows and Windows Classic L&F, there is no 'Go Home' button,
446 // but there is a toggle button to go desktop. In Windows platform
447 // 'Go Home' button usually navigates to Desktop only.
448 if(UIManager.getLookAndFeel().getID().equals("Windows")) {
449 homeOper =new JToggleButtonOperator(this, 1);
450 } else {
451 homeOper = new JButtonOperator(getHomeButton());
452 }
453 homeOper.copyEnvironment(this);
454 homeOper.setOutput(output.createErrorOutput());
455 homeOper.push();
456 waitPainted(-1);
457 return getCurrentDirectory();
458 }
459
460 /**
461 * Clicks on file in the list.
462 *
463 * @param index Ordinal file index.
464 * @param clickCount click count
465 */
466 public void clickOnFile(int index, int clickCount) {
467 getQueueTool().waitEmpty();
468 output.printTrace("Click " + Integer.toString(clickCount)
469 + " times on " + Integer.toString(index)
470 + "`th file in JFileChooser\n : "
471 + toStringSource());
472 waitPainted(index);
|