Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JFileChooser/4150029/bug4150029.java
38854 views
/*1* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24bug 4150029 800608725summary BackSpace keyboard button does not lead to parent directory26author Oleg Mokhovikov27*/2829import javax.swing.*;30import java.io.File;31import java.io.IOException;3233public class bug4150029 extends JApplet {34private boolean res;3536public void init() {37if (sun.awt.OSInfo.getOSType() == sun.awt.OSInfo.OSType.MACOSX) {38try {39UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");40} catch (Exception e) {41throw new RuntimeException(e);42}43}4445String tmpDir = System.getProperty("java.io.tmpdir");4647if (tmpDir.length() == 0) {//'java.io.tmpdir' isn't guaranteed to be defined48tmpDir = System.getProperty("user.home");49}5051System.out.println("Temp directory: " + tmpDir);5253File testDir = new File(tmpDir, "testDir");5455testDir.mkdir();5657File subDir = new File(testDir, "subDir");5859subDir.mkdir();6061System.out.println("Created directory: " + testDir);62System.out.println("Created sub-directory: " + subDir);6364JFileChooser fileChooser = new JFileChooser(testDir);6566fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);6768try {69res = fileChooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION ||70testDir.getCanonicalPath().equals(fileChooser.getSelectedFile().getCanonicalPath());71} catch (IOException e) {72res = false;7374e.printStackTrace();75}7677try {78subDir.delete();79testDir.delete();80} catch (SecurityException e) {81e.printStackTrace();82}83}8485public void destroy() {86if (!res) {87throw new RuntimeException("BackSpace keyboard button does not lead to parent directory");88}89}90}919293