List of usage examples for javax.swing JFileChooser JFileChooser
public JFileChooser()
JFileChooser
pointing to the user's default directory. From source file:org.jfree.chart.demo.SuperDemo.java
private void exportToPDF() { java.awt.Component component = chartContainer.getComponent(0); if (component instanceof ChartPanel) { JFileChooser jfilechooser = new JFileChooser(); jfilechooser.setName("untitled.pdf"); jfilechooser.setFileFilter(new FileFilter() { public boolean accept(File file) { return file.isDirectory() || file.getName().endsWith(".pdf"); }//from ww w. j a v a2 s . c o m public String getDescription() { return "Portable Document Format (PDF)"; } }); int i = jfilechooser.showSaveDialog(this); if (i == 0) { ChartPanel chartpanel = (ChartPanel) component; try { JFreeChart jfreechart = (JFreeChart) chartpanel.getChart().clone(); PDFExportTask pdfexporttask = new PDFExportTask(jfreechart, chartpanel.getWidth(), chartpanel.getHeight(), jfilechooser.getSelectedFile()); Thread thread = new Thread(pdfexporttask); thread.start(); } catch (CloneNotSupportedException clonenotsupportedexception) { clonenotsupportedexception.printStackTrace(); } } } else { String s = "Unable to export the selected item. There is "; s = s + "either no chart selected,\nor else the chart is not "; s = s + "at the expected location in the component hierarchy\n"; s = s + "(future versions of the demo may include code to "; s = s + "handle these special cases)."; JOptionPane.showMessageDialog(this, s, "PDF Export", 1); } }
From source file:com.netscape.admin.certsrv.Console.java
/** * common initialization routine./* w ww . j ava 2 s.c om*/ * * @param language language string. For example, "en" for english */ protected static void common_init(String language) { Locale.setDefault(new Locale(language, Locale.getDefault().getCountry())); try { // bug 115085: init calls needs to be inside the try block as, on Unix, during // initialization any call to java.awt.* will cause an exception to be thrown // if Xserver is not accessable. The jvm prints correctly the error message about // unaccessable Xserver but exception stack trace makes it less readable if (_info == null) _info = new ConsoleInfo(); PreferenceManager.setLocalStorageFlag(_preferences.getBoolean(PREFERENCE_LOCAL, false)); if (!_useJavaLookAndFeel) { SuiLookAndFeel nmclf = new SuiLookAndFeel(); UIManager.setLookAndFeel(nmclf); // With JDK1.4 on Unix, the first instance of JFileChooser // has an incorrect layout for some of the buttons. Create // and discard an instance. if (!_isWindows) { new JFileChooser(); } } FontFactory.initializeLFFonts(); // load default customized fonts for login/splash } catch (InternalError ie) { System.err.println("Console: " + ie.getMessage()); System.exit(1); } catch (Exception e) { Debug.println("Console.common_init: Cannot init " + e); } }
From source file:com.seanmadden.net.fast.FastInterpretype.java
public boolean saveLogToFile() { JFileChooser jfc = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Text Files", "txt"); jfc.setFileFilter(filter);/*w w w .j a v a2s . co m*/ int retVal = jfc.showSaveDialog(null); if (retVal == JFileChooser.APPROVE_OPTION) { String filename = jfc.getSelectedFile().getPath(); mw.saveWindowToFile(filename); return true; } return false; }
From source file:com.floreantpos.ui.model.MenuItemForm.java
protected void doSelectImageFile() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setMultiSelectionEnabled(false); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = fileChooser.showOpenDialog(POSUtil.getBackOfficeWindow()); if (option == JFileChooser.APPROVE_OPTION) { File imageFile = fileChooser.getSelectedFile(); try {//from ww w . ja v a 2 s.com byte[] itemImage = FileUtils.readFileToByteArray(imageFile); int imageSize = itemImage.length / 1024; if (imageSize > 20) { POSMessageDialog.showMessage(Messages.getString("MenuItemForm.0")); //$NON-NLS-1$ itemImage = null; return; } ImageIcon imageIcon = new ImageIcon( new ImageIcon(itemImage).getImage().getScaledInstance(80, 80, Image.SCALE_SMOOTH)); lblImagePreview.setIcon(imageIcon); MenuItem menuItem = (MenuItem) getBean(); menuItem.setImageData(itemImage); } catch (IOException e) { PosLog.error(getClass(), e); } } }
From source file:firmadigital.Firma.java
private void cmdExaminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdExaminarActionPerformed JFileChooser fileChooser = new JFileChooser(); txtUbicacion.setText(""); lblNombreArchivo.setText(""); lblRutaArchivo.setText(""); String signFileName = txtUbicacion.getText(); File directory = new File(signFileName).getParentFile(); fileChooser.setCurrentDirectory(directory); FileNameExtensionFilter filter; filter = new FileNameExtensionFilter("XML file", "xml"); fileChooser.setFileFilter(filter);// www . j a v a2 s. co m fileChooser.setFileHidingEnabled(true); /*Remove All File option*/ fileChooser.setAcceptAllFileFilterUsed(false); if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { String selectedFile = fileChooser.getSelectedFile().getAbsolutePath(); txtUbicacion.setText(selectedFile); lblNombreArchivo.setText(fileChooser.getSelectedFile().getName()); lblRutaArchivo.setText(fileChooser.getSelectedFile().getParent()); } }
From source file:jpad.MainEditor.java
public void saveAs() { if (_isOSX || ostype == ostype.Linux || ostype == ostype.Other) { saveAs_OSX_Nix();//from www. j a va2 s. com saveFile(curFile); } else /* Windows */ { JFileChooser fc = new JFileChooser(); if (curFile != null) fc.setSelectedFile(new File(curFile)); else fc.setSelectedFile(new File("Untitled.txt")); fc.setDialogTitle("Save Text File"); fc.setFileFilter(new FileNameExtensionFilter("Plain Text Files", "txt")); int returnval = fc.showSaveDialog(this); if (returnval == 0) { curFile = fc.getSelectedFile().getAbsolutePath(); if (!curFile.endsWith(".txt")) curFile = curFile + ".txt"; hasChanges = false; hasSavedToFile = true; saveFile(curFile); } } }
From source file:edu.harvard.mcz.imagecapture.jobs.JobRepeatOCR.java
private List<File> getFileList() { String pathToCheck = ""; if (scan != SCAN_ALL) { // Find the path in which to include files. File imagebase = null; // place to start the scan from, imagebase directory for SCAN_ALL File startPoint = null;/*from www.ja v a2 s . c o m*/ // If it isn't null, retrieve the image base directory from properties, and test for read access. if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE) == null) { JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "Can't start scan. Don't know where images are stored. Set imagbase property.", "Can't Scan.", JOptionPane.ERROR_MESSAGE); } else { imagebase = new File(Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE)); if (imagebase != null) { if (imagebase.canRead()) { startPoint = imagebase; } else { // If it can't be read, null out imagebase imagebase = null; } } if (scan == SCAN_SPECIFIC && startPointSpecific != null && startPointSpecific.canRead()) { // A scan start point has been provided, don't launch a dialog. startPoint = startPointSpecific; } if (imagebase == null || scan == SCAN_SELECT) { // launch a file chooser dialog to select the directory to scan final JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (scan == SCAN_SELECT && startPointSpecific != null && startPointSpecific.canRead()) { fileChooser.setCurrentDirectory(startPointSpecific); } else { if (Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_LASTPATH) != null) { fileChooser .setCurrentDirectory(new File(Singleton.getSingletonInstance().getProperties() .getProperties().getProperty(ImageCaptureProperties.KEY_LASTPATH))); } } int returnValue = fileChooser.showOpenDialog(Singleton.getSingletonInstance().getMainFrame()); if (returnValue == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); log.debug("Selected base directory: " + file.getName() + "."); startPoint = file; } else { //TODO: handle error condition log.error("Directory selection cancelled by user."); } //TODO: Filechooser to pick path, then save (if SCAN_ALL) imagebase property. //Perhaps. Might be undesirable behavior. //Probably better to warn that imagebase is null; } // Check that startPoint is or is within imagebase. if (!ImageCaptureProperties.isInPathBelowBase(startPoint)) { String base = Singleton.getSingletonInstance().getProperties().getProperties() .getProperty(ImageCaptureProperties.KEY_IMAGEBASE); log.error("Tried to scan directory (" + startPoint.getPath() + ") outside of base image directory (" + base + ")"); String message = "Can't scan and database files outside of base image directory (" + base + ")"; JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), message, "Can't Scan outside image base directory.", JOptionPane.YES_NO_OPTION); } else { // run in separate thread and allow cancellation and status reporting // walk through directory tree if (!startPoint.canRead()) { JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "Can't start scan. Unable to read selected directory: " + startPoint.getPath(), "Can't Scan.", JOptionPane.YES_NO_OPTION); } else { pathToCheck = ImageCaptureProperties.getPathBelowBase(startPoint); } } } } // Retrieve a list of all specimens in state OCR SpecimenLifeCycle sls = new SpecimenLifeCycle(); Specimen pattern = new Specimen(); pattern.setWorkFlowStatus(WorkFlowStatus.STAGE_0); List<Specimen> specimens = sls.findByExample(pattern); ArrayList<File> files = new ArrayList<File>(); for (int i = 0; i < specimens.size(); i++) { Specimen s = specimens.get(i); Set<ICImage> images = s.getICImages(); Iterator<ICImage> iter = images.iterator(); while (iter.hasNext() && runStatus != RunStatus.STATUS_TERMINATED) { ICImage image = (ICImage) iter.next(); if (scan == SCAN_ALL || image.getPath().startsWith(pathToCheck)) { // Add image for specimen to list to check File imageFile = new File( ImageCaptureProperties.assemblePathWithBase(image.getPath(), image.getFilename())); files.add(imageFile); counter.incrementFilesSeen(); } } } String message = "Found " + files.size() + " Specimen records on which to repeat OCR."; log.debug(message); Singleton.getSingletonInstance().getMainFrame().setStatusMessage(message); return files; }
From source file:cnu.eslab.fileTest.NewJFrame.java
private void Myinit() { // ArrayList ?. mUidArrayList = new ArrayList<String>(); // ? ? ? ./*from w w w .j av a 2 s .c o m*/ mCFileStream = new FileStream(); mJFileChooser = new JFileChooser(); // ? ? ? . mFileBtn.addActionListener(this); // ? . mParsingBtn.addActionListener(this); mTotalPowerBtn.addActionListener(this); mBatteryCapacityBtn.addActionListener(this); mCpuBtn.addActionListener(this); mWifiBtn.addActionListener(this); mLedBtn.addActionListener(this); mGpsBtn.addActionListener(this); mAudioBtn.addActionListener(this); mUidPieDiagramBtn.addActionListener(this); m3DBarChartMean.addActionListener(this); mDevicesPowerButton.addActionListener(this); mAppTotalPowerBtn.addActionListener(this); mAppStackedPower.addActionListener(this); mUidList.addListSelectionListener(this); mGPSCheckBox.addActionListener(this); mAudioCheckBox.addActionListener(this); m3GBtn.addActionListener(this); //component ? ? . mComponentLEDBtn.addActionListener(this); mComponentCPUBtn.addActionListener(this); mComponentWIFIBtn.addActionListener(this); mComponentThreeGBtn.addActionListener(this); mPhoneTotalStackPowerBtn.addActionListener(this); mComponentPieBtn.addActionListener(this); mDeleteUidMoveBtn.addActionListener(this); // ? ? mDeleteOneBtn.addActionListener(this); // ? ? UID mDeleteAllBtn.addActionListener(this); // ? UID mCompareAppPowerBtn.addActionListener(this); mTotalCompareBtn.addActionListener(this); // ? ?? ? ? ?. // ? ? ? OFF . ComponetStateChanger(POWER_BUTTON_OFF); }
From source file:be.vds.jtbdive.client.view.core.dive.profile.DiveProfileGraphicDetailPanel.java
private Component createImportButton() { JButton b = new JButton(new AbstractAction(null, UIAgent.getInstance().getIcon(UIAgent.ICON_IMPORT_24)) { private static final long serialVersionUID = 985413615438877711L; @Override/*from w w w .j av a2 s . c om*/ public void actionPerformed(ActionEvent e) { JFileChooser ch = new JFileChooser(); ch.setFileFilter(new ExtensionFilter("xls", "Excel File")); int i = ch.showOpenDialog(null); if (i == JFileChooser.APPROVE_OPTION) { DiveProfileExcelParser p = new DiveProfileExcelParser(); try { File f = ch.getSelectedFile(); DiveProfile dp = p.read(f); I18nResourceManager i18n = I18nResourceManager.sharedInstance(); int yes = JOptionPane.showConfirmDialog(DiveProfileGraphicDetailPanel.this, i18n.getString("overwritte.diveprofile.confirm"), i18n.getString("confirmation"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (yes == JOptionPane.YES_OPTION) { currentDive.setDiveProfile(dp); setDiveProfile(dp, currentDive); logBookManagerFacade.setDiveChanged(currentDive); } } catch (IOException e1) { ExceptionDialog.showDialog(e1, DiveProfileGraphicDetailPanel.this); LOGGER.error(e1.getMessage()); } } } }); b.setToolTipText("Import"); return b; }
From source file:chibi.gemmaanalysis.cli.deprecated.ProbeMapperGui.java
/** * This method initializes InputFileBrowseButton * /*w w w.j a v a 2 s. co m*/ * @return javax.swing.JButton */ private JButton getInputFileBrowseButton() { if (inputFileBrowseButton == null) { inputFileBrowseButton = new JButton(); inputFileBrowseButton.setText("Browse..."); inputFileBrowseButton.setActionCommand("inputFileBrowse"); inputFileBrowseButton.setBounds(451, 8, 87, 26); inputFileBrowseButton.addActionListener(new ActionListener() { @Override @SuppressWarnings({ "synthetic-access" }) public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); fc.showOpenDialog(jContentPane.getParent()); File selectedFile = fc.getSelectedFile(); if (selectedFile != null) { getInputFileNameTextField().setText(selectedFile.getAbsolutePath()); if (!selectedFile.canRead()) { // error } else { inputFile = selectedFile; } } } }); } return inputFileBrowseButton; }