List of usage examples for com.intellij.openapi.fileChooser FileChooserFactory getInstance
public static FileChooserFactory getInstance()
From source file:com.android.tools.idea.actions.AndroidImportProjectAction.java
License:Apache License
@Nullable private AddModuleWizard selectFileAndCreateWizard(@NotNull FileChooserDescriptor descriptor) throws IOException, ConfigurationException { FileChooserDialog chooser = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null); VirtualFile toSelect = null;//from w ww . jav a2 s.c o m String lastLocation = PropertiesComponent.getInstance().getValue(LAST_IMPORTED_LOCATION); if (lastLocation != null) { toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(lastLocation); } VirtualFile[] files = chooser.choose(null, toSelect); if (files.length == 0) { return null; } VirtualFile file = files[0]; PropertiesComponent.getInstance().setValue(LAST_IMPORTED_LOCATION, file.getPath()); return createImportWizard(file); }
From source file:com.android.tools.idea.actions.ConvertToNinePatchAction.java
License:Apache License
@Override public void actionPerformed(AnActionEvent e) { final VirtualFile pngFile = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext()); if (!isPngFile(pngFile)) { return;/*from w w w . ja va2 s .co m*/ } FileSaverDescriptor descriptor = new FileSaverDescriptor( AndroidBundle.message("android.9patch.creator.save.title"), "", SdkConstants.EXT_PNG); FileSaverDialog saveFileDialog = FileChooserFactory.getInstance().createSaveFileDialog(descriptor, (Project) null); VirtualFileWrapper fileWrapper = saveFileDialog.save(pngFile.getParent(), pngFile.getNameWithoutExtension().concat(SdkConstants.DOT_9PNG)); if (fileWrapper == null) { return; } final File patchFile = fileWrapper.getFile(); new Task.Modal(null, "Creating 9-Patch File", false) { private IOException myException; @Override public void run(@NotNull ProgressIndicator indicator) { indicator.setIndeterminate(true); try { BufferedImage pngImage = ImageIO.read(VfsUtilCore.virtualToIoFile(pngFile)); BufferedImage patchImage = ImageUtils.addMargin(pngImage, 1); ImageIO.write(patchImage, SdkConstants.EXT_PNG, patchFile); LocalFileSystem.getInstance().refreshAndFindFileByIoFile(patchFile); } catch (IOException e) { myException = e; } } @Override public void onSuccess() { if (myException != null) { Messages.showErrorDialog( AndroidBundle.message("android.9patch.creator.error", myException.getMessage()), AndroidBundle.message("android.9patch.creator.error.title")); } } }.queue(); }
From source file:com.android.tools.idea.avdmanager.ExportDeviceAction.java
License:Apache License
@Override public void actionPerformed(ActionEvent e) { FileSaverDescriptor descriptor = new FileSaverDescriptor("Export Location", "Select a location for the exported device", "xml"); String homePath = System.getProperty("user.home"); File parentPath = homePath == null ? new File("/") : new File(homePath); VirtualFile parent = LocalFileSystem.getInstance().findFileByIoFile(parentPath); VirtualFileWrapper fileWrapper = FileChooserFactory.getInstance() .createSaveFileDialog(descriptor, (Project) null).save(parent, "device.xml"); Device device = myProvider.getDevice(); if (device != null && fileWrapper != null) { DeviceManagerConnection.writeDevicesToFile(ImmutableList.of(device), fileWrapper.getFile()); }/*from w w w . j a v a2 s . c o m*/ }
From source file:com.android.tools.idea.avdmanager.ImportDevicesAction.java
License:Apache License
@Override public void actionPerformed(ActionEvent e) { FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, true); String homePath = System.getProperty("user.home"); File parentPath = homePath == null ? new File("/") : new File(homePath); VirtualFile parent = LocalFileSystem.getInstance().findFileByIoFile(parentPath); VirtualFile[] files = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null) .choose(parent, null);/*from w w w .j a v a2 s .c o m*/ List<Device> importedDevices = Lists.newArrayList(); for (VirtualFile vf : files) { for (Device d : DeviceManagerConnection.getDevicesFromFile(VfsUtilCore.virtualToIoFile(vf))) { importedDevices.add(d); } } if (!importedDevices.isEmpty()) { DeviceManagerConnection.getDefaultDeviceManagerConnection().createDevices(importedDevices); myProvider.refreshDevices(); } }
From source file:com.android.tools.idea.ddms.screenshot.ScreenshotViewer.java
License:Apache License
@Override protected void doOKAction() { FileSaverDescriptor descriptor = new FileSaverDescriptor( AndroidBundle.message("android.ddms.screenshot.save.title"), "", SdkConstants.EXT_PNG); FileSaverDialog saveFileDialog = FileChooserFactory.getInstance().createSaveFileDialog(descriptor, myProject);/*from w ww .j a v a 2 s.c o m*/ VirtualFile baseDir = ourLastSavedFolder != null ? ourLastSavedFolder : myProject.getBaseDir(); VirtualFileWrapper fileWrapper = saveFileDialog.save(baseDir, getDefaultFileName()); if (fileWrapper == null) { return; } myScreenshotFile = fileWrapper.getFile(); try { ImageIO.write(myDisplayedImageRef.get(), SdkConstants.EXT_PNG, myScreenshotFile); } catch (IOException e) { Messages.showErrorDialog(myProject, AndroidBundle.message("android.ddms.screenshot.save.error", e), AndroidBundle.message("android.ddms.actions.screenshot")); return; } VirtualFile virtualFile = fileWrapper.getVirtualFile(); if (virtualFile != null) { //noinspection AssignmentToStaticFieldFromInstanceMethod ourLastSavedFolder = virtualFile.getParent(); } super.doOKAction(); }
From source file:com.android.tools.idea.npw.deprecated.ConfigureAndroidProjectStep.java
License:Apache License
private void browseForFile() { FileSaverDescriptor fileSaverDescriptor = new FileSaverDescriptor("Project location", "Please choose a location for your project"); File currentPath = new File(myProjectLocation.getText()); File parentPath = currentPath.getParentFile(); if (parentPath == null) { String homePath = System.getProperty("user.home"); parentPath = new File(homePath == null ? "/" : homePath); }/* w w w . jav a 2 s .co m*/ VirtualFile parent = LocalFileSystem.getInstance().findFileByIoFile(parentPath); String filename = currentPath.getName(); VirtualFileWrapper fileWrapper = FileChooserFactory.getInstance() .createSaveFileDialog(fileSaverDescriptor, (Project) null).save(parent, filename); if (fileWrapper != null) { myProjectLocation.setText(fileWrapper.getFile().getAbsolutePath()); } }
From source file:com.android.tools.idea.structure.AndroidHomeConfigurable.java
License:Apache License
private void createUIComponents() { JTextField textField = new JTextField(); FileChooserDescriptor outputPathsChooserDescriptor = FileChooserDescriptorFactory .createSingleFolderDescriptor(); InsertPathAction.addTo(textField, outputPathsChooserDescriptor); BrowseFilesListener listener = new BrowseFilesListener(textField, "", "Please choose an Android SDK location", outputPathsChooserDescriptor); //noinspection ConstantConditions myAndroidHomeLocation = new FieldPanel(textField, null, null, listener, EmptyRunnable.getInstance()); FileChooserFactory fileChooserFactory = FileChooserFactory.getInstance(); fileChooserFactory.installFileCompletion(myAndroidHomeLocation.getTextField(), outputPathsChooserDescriptor, true, null);//from ww w . j ava 2 s. c o m textField = new JTextField(); outputPathsChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); InsertPathAction.addTo(textField, outputPathsChooserDescriptor); listener = new BrowseFilesListener(textField, "", "Please choose a JDK location", outputPathsChooserDescriptor); //noinspection ConstantConditions myJavaHomeLocation = new FieldPanel(textField, null, null, listener, EmptyRunnable.getInstance()); fileChooserFactory.installFileCompletion(myJavaHomeLocation.getTextField(), outputPathsChooserDescriptor, true, null); }
From source file:com.android.tools.idea.wizard.ConfigureAndroidModuleStep.java
License:Apache License
public ConfigureAndroidModuleStep(TemplateWizardState state, @Nullable Project project, @Nullable Icon sidePanelIcon, UpdateListener updateListener) { super(state, project, sidePanelIcon, updateListener); IAndroidTarget[] targets = getCompilationTargets(); if (AndroidSdkUtils.isAndroidSdkAvailable()) { String[] knownVersions = TemplateUtils.getKnownVersions(); for (int i = 0; i < knownVersions.length; i++) { AndroidTargetComboBoxItem targetInfo = new AndroidTargetComboBoxItem(knownVersions[i], i + 1); myMinSdk.addItem(targetInfo); myTargetSdk.addItem(targetInfo); }// w w w. j a va2 s .c o m } for (IAndroidTarget target : targets) { AndroidTargetComboBoxItem targetInfo = new AndroidTargetComboBoxItem(target); myTemplateState.put(ATTR_BUILD_API, targetInfo.apiLevel); myCompileWith.addItem(targetInfo); if (target.getVersion().isPreview()) { myMinSdk.addItem(targetInfo); myTargetSdk.addItem(targetInfo); } } registerUiElements(); myProjectLocation.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { FileSaverDescriptor fileSaverDescriptor = new FileSaverDescriptor("Project location", "Please choose a location for your project"); File currentPath = new File(myProjectLocation.getText()); File parentPath = currentPath.getParentFile(); if (parentPath == null) { parentPath = new File("/"); } VirtualFile parent = LocalFileSystem.getInstance().findFileByIoFile(parentPath); String filename = currentPath.getName(); VirtualFileWrapper fileWrapper = FileChooserFactory.getInstance() .createSaveFileDialog(fileSaverDescriptor, (Project) null).save(parent, filename); if (fileWrapper != null && fileWrapper.getFile() != null) { myProjectLocation.setText(fileWrapper.getFile().getAbsolutePath()); } } }); myProjectLocation.getTextField().addFocusListener(this); myProjectLocation.getTextField().getDocument().addDocumentListener(this); if (myTemplateState.myHidden.contains(ATTR_PROJECT_LOCATION)) { myProjectLocation.setVisible(false); myProjectLocationLabel.setVisible(false); } if (myTemplateState.myHidden.contains(ATTR_IS_LIBRARY_MODULE)) { myLibraryCheckBox.setVisible(false); } if (myTemplateState.myHidden.contains(ATTR_MODULE_NAME)) { myModuleName.setVisible(false); myModuleNameLabel.setVisible(false); } }
From source file:com.android.tools.idea.wizard.ConfigureAndroidProjectStep.java
License:Apache License
private void browseForFile() { FileSaverDescriptor fileSaverDescriptor = new FileSaverDescriptor("Project location", "Please choose a location for your project"); File currentPath = new File(myProjectLocation.getText()); File parentPath = currentPath.getParentFile(); if (parentPath == null) { String homePath = System.getProperty("user.home"); parentPath = homePath == null ? new File("/") : new File(homePath); }/*from w ww. j a v a2s . c o m*/ VirtualFile parent = LocalFileSystem.getInstance().findFileByIoFile(parentPath); String filename = currentPath.getName(); VirtualFileWrapper fileWrapper = FileChooserFactory.getInstance() .createSaveFileDialog(fileSaverDescriptor, (Project) null).save(parent, filename); if (fileWrapper != null) { myProjectLocation.setText(fileWrapper.getFile().getAbsolutePath()); } }
From source file:com.android.tools.idea.wizard.GetSdkStep.java
License:Apache License
@Nullable private String getSaveLocation(@Nullable String currentPath) { VirtualFile currentFile = null;//from w w w.j a v a 2 s . c om if (currentPath != null && !currentPath.isEmpty()) { currentFile = VfsUtil.findFileByIoFile(new File(currentPath), false); } FileSaverDescriptor fileSaverDescriptor = new FileSaverDescriptor("SDK location", "Please choose an installation location for your SDK"); VirtualFileWrapper fileWrapper = FileChooserFactory.getInstance() .createSaveFileDialog(fileSaverDescriptor, (Project) null).save(currentFile, "android_sdk"); if (fileWrapper != null) { return fileWrapper.getFile().getPath(); } else { return null; } }