List of usage examples for javax.swing JFileChooser FILES_ONLY
int FILES_ONLY
To view the source code for javax.swing JFileChooser FILES_ONLY.
Click Source Link
From source file:net.rptools.maptool.client.macro.impl.SaveAliasesMacro.java
public void execute(MacroContext context, String macro, MapToolMacroContext executionContext) { File aliasFile = null;//from w ww .jav a2 s . co m if (macro.length() > 0) { aliasFile = new File(macro); } else { JFileChooser chooser = MapTool.getFrame().getSaveFileChooser(); chooser.setDialogTitle("savealiases.dialogTitle"); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (chooser.showOpenDialog(MapTool.getFrame()) != JFileChooser.APPROVE_OPTION) { return; } aliasFile = chooser.getSelectedFile(); } if (aliasFile.getName().indexOf(".") < 0) { aliasFile = new File(aliasFile.getAbsolutePath() + ".alias"); } if (aliasFile.exists() && !MapTool.confirm(I18N.getText("msg.confirm.fileExists"))) { return; } try { StringBuilder builder = new StringBuilder(); builder.append("# ").append(I18N.getText("savealiases.created")).append(" ") .append(new SimpleDateFormat().format(new Date())).append("\n\n"); Map<String, String> aliasMap = MacroManager.getAliasMap(); List<String> aliasList = new ArrayList<String>(); aliasList.addAll(aliasMap.keySet()); Collections.sort(aliasList); for (String key : aliasList) { String value = aliasMap.get(key); builder.append(key).append(":").append(value).append("\n"); // LATER: this character should be externalized and shared with the load alias macro } FileUtils.writeByteArrayToFile(aliasFile, builder.toString().getBytes("UTF-8")); MapTool.addLocalMessage(I18N.getText("aliases.saved")); } catch (FileNotFoundException fnfe) { MapTool.addLocalMessage( I18N.getText("savealiases.couldNotSave", I18N.getText("msg.error.fileNotFound"))); } catch (IOException ioe) { MapTool.addLocalMessage(I18N.getText("savealiases.couldNotSave", ioe)); } }
From source file:ihm.mainActivity.java
/** * Creates new form testBuild/* w ww .j a v a 2 s.c o m*/ */ public mainActivity() { dataList = new DataList(); dataList.addObserver(this); chart = ChartFactory.createXYLineChart("Graphique", "x", "Value", createDataset(), PlotOrientation.VERTICAL, true, true, false); fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter filter = new FileNameExtensionFilter("CSV Files", "csv"); fileChooser.setFileFilter(filter); initComponents(); }
From source file:rework.MainFrame.java
/** * Creates new form MainFrame// w ww . j a v a 2s .co m */ public MainFrame() { chart = ChartFactory.createXYLineChart("Graphique", "x", "Value", createDataset(), PlotOrientation.VERTICAL, true, true, false); initComponents(); fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter filter = new FileNameExtensionFilter("CSV Files", "csv"); fileChooser.setFileFilter(filter); layerStack1.initComponents(transfList); layerStack1.updateLayerStack(); datalist.addObserver(this); transfList.addObserver(layerStack1); datalist.add(new Point(new Date(), 1, 5.0)); datalist.add(new Point(new Date(), 2, 15.0)); datalist.add(new Point(new Date(), 3, 25.0)); datalist.add(new Point(new Date(), 4, 20.0)); datalist.add(new Point(new Date(), 5, 25.0)); datalist.add(new Point(new Date(), 6, 35.0)); datalist.add(new Point(new Date(), 7, 5.0)); datalist.add(new Point(new Date(), 8, 15.0)); datalist.add(new Point(new Date(), 9, 25.0)); datalist.add(new Point(new Date(), 10, 20.0)); datalist.add(new Point(new Date(), 11, 25.0)); datalist.add(new Point(new Date(), 12, 35.0)); datalist.add(new Point(new Date(), 13, 5.0)); datalist.add(new Point(new Date(), 14, 15.0)); datalist.add(new Point(new Date(), 15, 25.0)); datalist.add(new Point(new Date(), 16, 20.0)); datalist.add(new Point(new Date(), 17, 25.0)); datalist.add(new Point(new Date(), 18, 35.0)); tabStack.revalidate(); }
From source file:com.mgmtp.perfload.loadprofiles.ui.util.SwingUtils.java
public static JFileChooser createFileChooser(final File dir, final String description, final String extension) { JFileChooser fc = new JFileChooser(dir); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.setMultiSelectionEnabled(false);// w w w .jav a 2 s . c o m fc.setAcceptAllFileFilterUsed(false); fc.addChoosableFileFilter(new FileFilter() { @Override public String getDescription() { return description; } @Override public boolean accept(final File f) { return f.isDirectory() || FilenameUtils.isExtension(f.getName(), extension); } }); return fc; }
From source file:eu.apenet.dpt.standalone.gui.XsltAdderActionListener.java
public void actionPerformed(ActionEvent e) { JFileChooser xsltChooser = new JFileChooser(); xsltChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (xsltChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { File file = xsltChooser.getSelectedFile(); if (isXSLT(file)) { if (saveXslt(file)) { JRadioButton newButton = new JRadioButton(file.getName()); newButton.addActionListener(new XsltSelectorListener(dataPreparationToolGUI)); dataPreparationToolGUI.getGroupXslt().add(newButton); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().addToXsltPanel(newButton); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane() .addToXsltPanel(Box.createRigidArea(new Dimension(0, 10))); JOptionPane.showMessageDialog(parent, labels.getString("xsltSaved") + ".", labels.getString("fileSaved"), JOptionPane.INFORMATION_MESSAGE, Utilities.icon); } else { JOptionPane.showMessageDialog(parent, labels.getString("xsltNotSaved") + ".", labels.getString("fileNotSaved"), JOptionPane.ERROR_MESSAGE, Utilities.icon); }/*from w ww . j av a2s .c o m*/ } else { JOptionPane.showMessageDialog(parent, labels.getString("xsltNotSaved") + ".", labels.getString("fileNotSaved"), JOptionPane.ERROR_MESSAGE, Utilities.icon); } } }
From source file:courseapplication.CourseApplication1.java
/** * Creates new form CourseApplication1/*from ww w . j a v a2 s . c o m*/ */ private CourseApplication1() { initComponents(); setContentPane(jPanel1); setVisible(true); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setLocationRelativeTo(null); setTitle("Interpolation"); pack(); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); }
From source file:gui.menubar.SaveCommand.java
/** * Passes the file to the LevelSaver, first ensuring it has the correct * file type suffix.//w w w . j av a 2 s .c o m */ @Override public void execute() { fileChooser.setCurrentDirectory(new File(SAVE_FILE_LOCATION)); fileChooser.setFileFilter(new XmlFileFilter()); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); if (selectedFile != null) { if (FilenameUtils.getExtension(selectedFile.getName()).equalsIgnoreCase("xml")) { levelSaver.save(level, selectedFile); } else { selectedFile = new File(selectedFile.getParentFile(), FilenameUtils.getBaseName(selectedFile.getName()) + ".xml"); levelSaver.save(level, selectedFile); } } } }
From source file:edu.clemson.lph.civet.addons.VspsCviFile.java
public void importVspsFile(Window parent) { String sVspsDir = CivetConfig.getVspsDirPath(); File fDir = new File(sVspsDir); JFileChooser open = new JFileChooser(fDir); Action details = open.getActionMap().get("viewTypeDetails"); details.actionPerformed(null);/*from ww w. j av a 2s . com*/ open.setDialogTitle("Civet: Open PDF File"); open.setFileSelectionMode(JFileChooser.FILES_ONLY); open.setFileFilter(new FileNameExtensionFilter("CSV Files", "csv")); open.setMultiSelectionEnabled(false); int resultOfFileSelect = open.showOpenDialog(parent); if (resultOfFileSelect == JFileChooser.APPROVE_OPTION) { File fIn = open.getSelectedFile(); saveme(parent, fIn); // vsps.printme(); } }
From source file:eu.apenet.dpt.standalone.gui.XsdAdderActionListener.java
public void actionPerformed(ActionEvent e) { JFileChooser xsdChooser = new JFileChooser(); xsdChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); if (xsdChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { File file = xsdChooser.getSelectedFile(); if (isXSD(file)) { XsdInfoQueryComponent xsdInfoQueryComponent = new XsdInfoQueryComponent(labels, file.getName()); int result = JOptionPane.showConfirmDialog(parent, xsdInfoQueryComponent, "title", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { if (StringUtils.isEmpty(xsdInfoQueryComponent.getName())) { errorMessage();//from w w w . ja v a 2 s.c o m } else { if (saveXsd(file, xsdInfoQueryComponent.getName(), false, xsdInfoQueryComponent.getXsdVersion(), xsdInfoQueryComponent.getFileType())) { JRadioButton newButton = new JRadioButton(xsdInfoQueryComponent.getName()); newButton.addActionListener(new XsdSelectorListener(dataPreparationToolGUI)); dataPreparationToolGUI.getGroupXsd().add(newButton); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane().addToXsdPanel(newButton); dataPreparationToolGUI.getAPEPanel().getApeTabbedPane() .addToXsdPanel(Box.createRigidArea(new Dimension(0, 10))); JOptionPane.showMessageDialog(parent, labels.getString("xsdSaved") + ".", labels.getString("fileSaved"), JOptionPane.INFORMATION_MESSAGE, Utilities.icon); } else { errorMessage(); } } } } else { errorMessage(); } } }
From source file:com.bright.json.PGS.java
public static void main(String[] args) throws FileNotFoundException { String fileBasename = null;/*from w ww. jav a2 s .c o m*/ JFileChooser chooser = new JFileChooser(); try { FileNameExtensionFilter filter = new FileNameExtensionFilter("Excel Spreadsheets", "xls", "xlsx"); chooser.setFileFilter(filter); chooser.setCurrentDirectory(new java.io.File(System.getProperty("user.home"))); chooser.setDialogTitle("Select the Excel file"); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory()); System.out.println("getSelectedFile() : " + chooser.getSelectedFile()); // String fileBasename = // chooser.getSelectedFile().toString().substring(chooser.getSelectedFile().toString().lastIndexOf(File.separator)+1,chooser.getSelectedFile().toString().lastIndexOf(".")); fileBasename = chooser.getSelectedFile().toString() .substring(chooser.getSelectedFile().toString().lastIndexOf(File.separator) + 1); System.out.println("Base name: " + fileBasename); } else { System.out.println("No Selection "); } } catch (Exception e) { System.out.println(e.toString()); } String fileName = chooser.getSelectedFile().toString(); InputStream inp = new FileInputStream(fileName); Workbook workbook = null; if (fileName.toLowerCase().endsWith("xlsx")) { try { workbook = new XSSFWorkbook(inp); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if (fileName.toLowerCase().endsWith("xls")) { try { workbook = new HSSFWorkbook(inp); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Sheet nodeSheet = workbook.getSheet("Devices"); Sheet interfaceSheet = workbook.getSheet("Interfaces"); System.out.println("Read nodes sheet."); // Row nodeRow = nodeSheet.getRow(1); // System.out.println(row.getCell(0).toString()); // System.exit(0); JTextField uiHost = new JTextField("demo.brightcomputing.com"); // TextPrompt puiHost = new // TextPrompt("demo.brightcomputing.com",uiHost); JTextField uiUser = new JTextField("root"); // TextPrompt puiUser = new TextPrompt("root", uiUser); JTextField uiPass = new JPasswordField(""); // TextPrompt puiPass = new TextPrompt("x5deix5dei", uiPass); JPanel myPanel = new JPanel(new GridLayout(5, 1)); myPanel.add(new JLabel("Bright HeadNode hostname:")); myPanel.add(uiHost); // myPanel.add(Box.createHorizontalStrut(1)); // a spacer myPanel.add(new JLabel("Username:")); myPanel.add(uiUser); myPanel.add(new JLabel("Password:")); myPanel.add(uiPass); int result = JOptionPane.showConfirmDialog(null, myPanel, "Please fill in all the fields.", JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { System.out.println("Input received."); } String rhost = uiHost.getText(); String ruser = uiUser.getText(); String rpass = uiPass.getText(); String cmURL = "https://" + rhost + ":8081/json"; List<Cookie> cookies = doLogin(ruser, rpass, cmURL); chkVersion(cmURL, cookies); Map<String, Long> categories = UniqueKeyMap(cmURL, "cmdevice", "getCategories", cookies); Map<String, Long> networks = UniqueKeyMap(cmURL, "cmnet", "getNetworks", cookies); Map<String, Long> partitions = UniqueKeyMap(cmURL, "cmpart", "getPartitions", cookies); Map<String, Long> racks = UniqueKeyMap(cmURL, "cmpart", "getRacks", cookies); Map<String, Long> switches = UniqueKeyMap(cmURL, "cmdevice", "getEthernetSwitches", cookies); // System.out.println(switches.get("switch01")); // System.out.println("Size of the map: "+ switches.size()); // System.exit(0); cmDevice newnode = new cmDevice(); cmDevice.deviceObject devObj = new cmDevice.deviceObject(); cmDevice.switchObject switchObj = new cmDevice.switchObject(); // cmDevice.netObject netObj = new cmDevice.netObject(); List<String> emptyslist = new ArrayList<String>(); // Row nodeRow = nodeSheet.getRow(1); // Row ifRow = interfaceSheet.getRow(1); // System.out.println(nodeRow.getCell(0).toString()); // nodeRow.getCell(3).getStringCellValue() Map<String, ArrayList<cmDevice.netObject>> ifmap = new HashMap<String, ArrayList<cmDevice.netObject>>(); // Map<String,netObject> helperMap = new HashMap<String,netObject>(); // Iterator<Row> rows = interfaceSheet.rowIterator (); // while (rows. < interfaceSheet.getPhysicalNumberOfRows()) { // List<netObject> netList = new ArrayList<netObject>(); for (int i = 0; i < interfaceSheet.getPhysicalNumberOfRows(); i++) { Row ifRow = interfaceSheet.getRow(i); if (ifRow.getRowNum() == 0) { continue; // just skip the rows if row number is 0 } System.out.println("Row nr: " + ifRow.getRowNum()); cmDevice.netObject netObj = new cmDevice.netObject(); ArrayList<cmDevice.netObject> helperList = new ArrayList<cmDevice.netObject>(); netObj.setBaseType("NetworkInterface"); netObj.setCardType(ifRow.getCell(3).getStringCellValue()); netObj.setChildType(ifRow.getCell(4).getStringCellValue()); netObj.setDhcp((ifRow.getCell(5).getNumericCellValue() > 0.1) ? true : false); netObj.setIp(ifRow.getCell(7).getStringCellValue()); // netObj.setMac(ifRow.getCell(0).toString()); //netObj.setModified(true); netObj.setName(ifRow.getCell(1).getStringCellValue()); netObj.setNetwork(networks.get(ifRow.getCell(6).getStringCellValue())); //netObj.setOldLocalUniqueKey(0L); netObj.setRevision(""); netObj.setSpeed(ifRow.getCell(8, Row.CREATE_NULL_AS_BLANK).getStringCellValue()); netObj.setStartIf("ALWAYS"); netObj.setToBeRemoved(false); netObj.setUniqueKey((long) ifRow.getCell(2).getNumericCellValue()); //netObj.setAdditionalHostnames(new ArrayList<String>(Arrays.asList(ifRow.getCell(9, Row.CREATE_NULL_AS_BLANK).getStringCellValue().split("\\s*,\\s*")))); //netObj.setMac(ifRow.getCell(10, Row.CREATE_NULL_AS_BLANK).getStringCellValue()); netObj.setMode((int) ifRow.getCell(11, Row.CREATE_NULL_AS_BLANK).getNumericCellValue()); netObj.setOptions(ifRow.getCell(12, Row.CREATE_NULL_AS_BLANK).getStringCellValue()); netObj.setMembers(new ArrayList<String>(Arrays .asList(ifRow.getCell(13, Row.CREATE_NULL_AS_BLANK).getStringCellValue().split("\\s*,\\s*")))); // ifmap.put(ifRow.getCell(0).getStringCellValue(), new // HashMap<String, cmDevice.netObject>()); // helperMap.put(ifRow.getCell(1).getStringCellValue(), netObj) ; // ifmap.get(ifRow.getCell(0).getStringCellValue()).putIfAbsent(ifRow.getCell(1).getStringCellValue(), // netObj); // ifmap.put(ifRow.getCell(0).getStringCellValue(), helperMap); if (!ifmap.containsKey(ifRow.getCell(0).getStringCellValue())) { ifmap.put(ifRow.getCell(0).getStringCellValue(), new ArrayList<cmDevice.netObject>()); } helperList = ifmap.get(ifRow.getCell(0).getStringCellValue()); helperList.add(netObj); ifmap.put(ifRow.getCell(0).getStringCellValue(), helperList); continue; } for (int i = 0; i < nodeSheet.getPhysicalNumberOfRows(); i++) { Row nodeRow = nodeSheet.getRow(i); if (nodeRow.getRowNum() == 0) { continue; // just skip the rows if row number is 0 } newnode.setService("cmdevice"); newnode.setCall("addDevice"); Map<String, Long> ifmap2 = new HashMap<String, Long>(); for (cmDevice.netObject j : ifmap.get(nodeRow.getCell(0).getStringCellValue())) ifmap2.put(j.getName(), j.getUniqueKey()); switchObj.setEthernetSwitch(switches.get(nodeRow.getCell(8).getStringCellValue())); System.out.println(nodeRow.getCell(8).getStringCellValue()); System.out.println(switches.get(nodeRow.getCell(8).getStringCellValue())); switchObj.setPrt((int) nodeRow.getCell(9).getNumericCellValue()); switchObj.setBaseType("SwitchPort"); devObj.setBaseType("Device"); // devObj.setCreationTime(0L); devObj.setCustomPingScript(""); devObj.setCustomPingScriptArgument(""); devObj.setCustomPowerScript(""); devObj.setCustomPowerScriptArgument(""); devObj.setCustomRemoteConsoleScript(""); devObj.setCustomRemoteConsoleScriptArgument(""); devObj.setDisksetup(""); devObj.setBmcPowerResetDelay(0L); devObj.setBurning(false); devObj.setEthernetSwitch(switchObj); devObj.setExcludeListFull(""); devObj.setExcludeListGrab(""); devObj.setExcludeListGrabnew(""); devObj.setExcludeListManipulateScript(""); devObj.setExcludeListSync(""); devObj.setExcludeListUpdate(""); devObj.setFinalize(""); devObj.setRack(racks.get(nodeRow.getCell(10).getStringCellValue())); devObj.setRackHeight((long) nodeRow.getCell(11).getNumericCellValue()); devObj.setRackPosition((long) nodeRow.getCell(12).getNumericCellValue()); devObj.setIndexInsideContainer(0L); devObj.setInitialize(""); devObj.setInstallBootRecord(false); devObj.setInstallMode(""); devObj.setIoScheduler(""); devObj.setLastProvisioningNode(0L); devObj.setMac(nodeRow.getCell(6).getStringCellValue()); devObj.setModified(true); devObj.setCategory(categories.get(nodeRow.getCell(1).getStringCellValue())); devObj.setChildType("PhysicalNode"); //devObj.setDatanode((nodeRow.getCell(5).getNumericCellValue() > 0.1) ? true // : false); devObj.setHostname(nodeRow.getCell(0).getStringCellValue()); devObj.setModified(true); devObj.setPartition(partitions.get(nodeRow.getCell(2).getStringCellValue())); devObj.setUseExclusivelyFor("Category"); devObj.setNextBootInstallMode(""); devObj.setNotes(""); devObj.setOldLocalUniqueKey(0L); devObj.setPowerControl(nodeRow.getCell(7).getStringCellValue()); // System.out.println(ifmap.get("excelnode001").size()); // System.out.println(ifmap.get(nodeRow.getCell(0).getStringCellValue()).get(nodeRow.getCell(3).getStringCellValue()).getUniqueKey()); devObj.setManagementNetwork(networks.get(nodeRow.getCell(3).getStringCellValue())); devObj.setProvisioningNetwork(ifmap2.get(nodeRow.getCell(4).getStringCellValue())); devObj.setProvisioningTransport("RSYNCDAEMON"); devObj.setPxelabel(""); // "rack": 90194313218, // "rackHeight": 1, // "rackPosition": 4, devObj.setRaidconf(""); devObj.setRevision(""); devObj.setSoftwareImageProxy(null); devObj.setStartNewBurn(false); devObj.setTag("00000000a000"); devObj.setToBeRemoved(false); // devObj.setUcsInfoConfigured(null); // devObj.setUniqueKey(12345L); devObj.setUserdefined1(""); devObj.setUserdefined2(""); ArrayList<Object> mylist = new ArrayList<Object>(); ArrayList<cmDevice.netObject> mylist2 = new ArrayList<cmDevice.netObject>(); ArrayList<Object> emptylist = new ArrayList<Object>(); devObj.setFsexports(emptylist); devObj.setFsmounts(emptylist); devObj.setGpuSettings(emptylist); devObj.setFspartAssociations(emptylist); devObj.setPowerDistributionUnits(emptyslist); devObj.setRoles(emptylist); devObj.setServices(emptylist); devObj.setStaticRoutes(emptylist); mylist2 = ifmap.get(nodeRow.getCell(0).getStringCellValue()); devObj.setNetworks(mylist2); mylist.add(devObj); mylist.add(1); newnode.setArgs(mylist); GsonBuilder builder = new GsonBuilder(); builder.enableComplexMapKeySerialization(); // Gson g = new Gson(); Gson g = builder.create(); String json2 = g.toJson(newnode); // To be used from a real console and not Eclipse String message = JSonRequestor.doRequest(json2, cmURL, cookies); continue; } JOptionPane optionPaneF = new JOptionPane("The nodes have been added!"); JDialog myDialogF = optionPaneF.createDialog(null, "Complete: "); myDialogF.setModal(false); myDialogF.setVisible(true); doLogout(cmURL, cookies); // System.exit(0); }