List of usage examples for javax.swing.filechooser FileNameExtensionFilter FileNameExtensionFilter
public FileNameExtensionFilter(String description, String... extensions)
From source file:edu.umich.robot.ViewerApplication.java
private Config promptForConfig() { JFileChooser fc = new JFileChooser("config"); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); FileFilter filter = new FileNameExtensionFilter("Text Config File", "txt"); fc.setFileFilter(filter);/*from w w w . j a v a 2s . c om*/ fc.setMultiSelectionEnabled(false); int ret = fc.showOpenDialog(frame); if (ret == JFileChooser.APPROVE_OPTION) { try { return new ConfigFile(fc.getSelectedFile().getAbsolutePath()); } catch (IOException e) { logger.error(e.getMessage()); } } return null; }
From source file:com.wcmc.Software.excel.ExportCMAPoints.java
@Override public void run() { Date now = new Date(); SimpleDateFormat date = new SimpleDateFormat("yyyy"); String year = date.format(now); JFileChooser saveAs = new JFileChooser(System.getProperty("user.home")); saveAs.setDialogTitle("Save Standings For The " + year + " Season"); saveAs.setFileFilter(new FileNameExtensionFilter("Excel 2003 (*.xls)", "xls")); if (saveAs.showSaveDialog(Client.window) == JFileChooser.APPROVE_OPTION) { File exportFile = null;/*from w ww .ja va 2 s . c o m*/ if (!saveAs.getSelectedFile().toString().endsWith(".xls")) { exportFile = new File(saveAs.getSelectedFile().getAbsolutePath() + ".xls"); } else { exportFile = saveAs.getSelectedFile(); } try { WritableWorkbook excelFile = Workbook.createWorkbook(exportFile); System.out.println("Exporting Standings..."); int sheetNumber = 0; ArrayList<ClassItem> classes = Client.ms.rS.classes.getClasses(); Client.ms.trS.prgExport.setVisible(true); Client.ms.trS.prgExport.setPercent(0); Client.ms.trS.prgClass.setVisible(true); Client.ms.trS.prgClass.setPercent(0); Client.ms.trS.overall.setVisible(true); Client.ms.trS.classSpecific.setVisible(true); for (int i = 0; i < classes.size(); i++) { ClassItem c = classes.get(i); Client.ms.trS.classSpecific.setText("Class: " + c.getText()); WritableSheet classSheet = excelFile.createSheet(c.getText().toString(), sheetNumber); classSheet.mergeCells(1, 1, 13, 1); classSheet.addCell(new Label(1, 1, c.getText().toString() + " - Niagara Motorcycle Raceway - " + year + " Season", headerGrey)); classSheet.addCell(new Label(1, 3, "Plate #", headerBold)); classSheet.addCell(new Label(2, 3, "CMA", headerBold)); classSheet.addCell(new Label(3, 3, "First Name", headerBold)); classSheet.addCell(new Label(4, 3, "Last Name", headerBold)); classSheet.addCell(new Label(5, 3, "Total Points", headerBold)); Client.sc.send(CONST.GET_RACE_DATES + " " + year + CONST.seperator + c.getID()); String jsonData = null; while ((jsonData = Client.sc.getInfo()) == null) { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } if (jsonData != null) { JSONParser parse = new JSONParser(); JSONObject jsonDates = (JSONObject) parse.parse(jsonData); if (jsonDates != null) { JSONArray jsonDatesArray = (JSONArray) jsonDates.get("dates"); JSONArray riderDataArray = (JSONArray) jsonDates.get("riders"); if (riderDataArray.size() == 0) { excelFile.removeSheet(sheetNumber); continue; } for (int d = 0; d < jsonDatesArray.size(); d++) { String dateString = (String) jsonDatesArray.get(d); classSheet.mergeCells(6 + (d * 2), 3, 6 + (d * 2) + 1, 3); DateFormat customDateFormat = new DateFormat("MMMM dd"); WritableCellFormat dateFormat = new WritableCellFormat(customDateFormat); dateFormat.setBorder(Border.ALL, BorderLineStyle.THICK); dateFormat.setAlignment(Alignment.CENTRE); dateFormat.setFont(arial10bold); SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-M-d"); Date eventDate = dateParser.parse(dateString); jxl.write.DateTime dateFormatCell = new jxl.write.DateTime(6 + (d * 2), 3, eventDate, dateFormat); classSheet.addCell(dateFormatCell); classSheet.addCell(new Label(6 + (d * 2), 5, "POS", dataCenter)); classSheet.addCell(new Label(6 + (d * 2) + 1, 5, "Points", dataCenter)); classSheet.setColumnView(6 + (d * 2), 10); classSheet.setColumnView(6 + (d * 2) + 1, 10); } classSheet.addCell(new Label(6 + jsonDatesArray.size() * 2, 3, "City", headerBold)); classSheet.addCell(new Label(7 + jsonDatesArray.size() * 2, 3, "Sponsors", headerBold)); classSheet.setColumnView(6 + jsonDatesArray.size() * 2, 25); classSheet.setColumnView(7 + jsonDatesArray.size() * 2, 75); for (int r = 0; r < riderDataArray.size(); r++) { JSONObject rider = (JSONObject) riderDataArray.get(r); JSONObject bike = (JSONObject) rider.get("bike"); if (bike != null) { classSheet.addCell(new Number(1, 6 + r, (long) bike.get("plate"), pointsBold)); } classSheet.addCell(new Label(2, 6 + r, (String) rider.get("license"), pointsBold)); classSheet .addCell(new Label(3, 6 + r, (String) rider.get("first_name"), dataCenter)); classSheet .addCell(new Label(4, 6 + r, (String) rider.get("last_name"), dataCenter)); classSheet .addCell(new Number(5, 6 + r, (long) rider.get("totalPoints"), pointsBold)); JSONArray events = (JSONArray) rider.get("events"); boolean hasEvent = false; for (int d = 0; d < jsonDatesArray.size(); d++) { hasEvent = false; for (int e = 0; e < events.size(); e++) { String dateString = (String) jsonDatesArray.get(d); JSONObject event = (JSONObject) events.get(e); if (event.get("date").equals(dateString)) { classSheet.addCell(new Number(6 + (d * 2), 6 + r, (long) event.get("position"), dataCenter)); classSheet.addCell(new Number(6 + (d * 2) + 1, 6 + r, (long) event.get("points"), dataCenter)); hasEvent = true; } } if (!hasEvent) { classSheet.addCell(new Label(6 + (d * 2), 6 + r, "", dataCenter)); classSheet.addCell(new Label(6 + (d * 2) + 1, 6 + r, "", dataCenter)); } } classSheet.addCell(new Label(6 + (jsonDatesArray.size() * 2), 6 + r, (String) rider.get("city"), dataCenter)); classSheet.addCell(new Label(7 + (jsonDatesArray.size() * 2), 6 + r, (String) rider.get("sponsors"), dataWrapped)); Client.ms.trS.prgClass .setPercent(((double) r / (double) riderDataArray.size()) * 100); } } } // Set Widths classSheet.setRowView(3, 300); classSheet.setColumnView(1, 10); classSheet.setColumnView(2, 10); classSheet.setColumnView(3, 18); classSheet.setColumnView(4, 18); classSheet.setColumnView(5, 15); sheetNumber++; Client.ms.trS.prgExport .setPercent(((double) i / (double) Client.ms.rS.classes.getClasses().size()) * 100); } excelFile.write(); excelFile.close(); WorkBook sortedWorkbook = new WorkBook(); try { sortedWorkbook.read(new FileInputStream(exportFile)); for (int i = 0; i < sheetNumber; i++) { sortedWorkbook.setSheet(i); sortedWorkbook.sort(6, 1, 60, 60, true, -5, 0, 0); } sortedWorkbook.setSheet(0); FileOutputStream out = new FileOutputStream(exportFile); sortedWorkbook.write(out); out.close(); } catch (Exception e) { e.printStackTrace(); } Client.ms.trS.prgExport.setVisible(false); Client.ms.trS.prgClass.setVisible(false); Client.ms.trS.overall.setVisible(false); Client.ms.trS.classSpecific.setVisible(false); } catch (IOException | WriteException | ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (java.text.ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:kindleclippings.quizlet.QuizletSync.java
private static Map<String, List<Clipping>> readClippingsFile() throws IOException { // try to find it File cl = new File("/Volumes/Kindle/documents/My Clippings.txt"); if (!cl.canRead()) { JFileChooser fc = new JFileChooser(); fc.setFileFilter(new FileNameExtensionFilter("Kindle Clippings", "txt")); int result = fc.showOpenDialog(null); if (result != JFileChooser.APPROVE_OPTION) { return null; }//from ww w. jav a 2 s . c o m cl = fc.getSelectedFile(); } Reader f = new InputStreamReader(new FileInputStream(cl), "UTF-8"); try { MyClippingsReader r = new MyClippingsReader(f); Map<String, List<Clipping>> books = new TreeMap<String, List<Clipping>>(); Clipping l; while ((l = r.readClipping()) != null) { if (l.getType() != ClippingType.highlight && l.getType() != ClippingType.note) { System.err.println("ignored " + l.getType() + " [" + l.getBook() + "]"); continue; } String lct = l.getContent().trim(); if (lct.length() == 0) { System.err.println("ignored empty " + l.getType() + " [" + l.getBook() + "]"); continue; } if (lct.length() < 10 || !lct.contains(" ")) { System.err.println( "ignored too short " + l.getType() + " " + l.getContent() + " [" + l.getBook() + "]"); continue; } List<Clipping> clippings = books.get(l.getBook()); if (clippings == null) { clippings = new ArrayList<Clipping>(); books.put(l.getBook(), clippings); } clippings.add(l); } return books; } finally { f.close(); } }
From source file:hspc.submissionsprogram.AppDisplay.java
AppDisplay() { this.setTitle("Dominion High School Programming Contest"); this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); this.setResizable(false); WindowListener exitListener = new WindowAdapter() { @Override//from w ww . ja v a2s . c o m public void windowClosing(WindowEvent e) { System.exit(0); } }; this.addWindowListener(exitListener); JTabbedPane pane = new JTabbedPane(); this.add(pane); JPanel submitPanel = new JPanel(null); submitPanel.setPreferredSize(new Dimension(500, 500)); UIManager.put("FileChooser.readOnly", true); JFileChooser fileChooser = new JFileChooser(); fileChooser.setBounds(0, 0, 500, 350); fileChooser.setVisible(true); FileNameExtensionFilter javaFilter = new FileNameExtensionFilter("Java files (*.java)", "java"); fileChooser.setFileFilter(javaFilter); fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.setControlButtonsAreShown(false); submitPanel.add(fileChooser); JSeparator separator1 = new JSeparator(); separator1.setBounds(12, 350, 476, 2); separator1.setForeground(new Color(122, 138, 152)); submitPanel.add(separator1); JLabel problemChooserLabel = new JLabel("Problem:"); problemChooserLabel.setBounds(12, 360, 74, 25); submitPanel.add(problemChooserLabel); String[] listOfProblems = Main.Configuration.get("problem_names") .split(Main.Configuration.get("name_delimiter")); JComboBox problems = new JComboBox<>(listOfProblems); problems.setBounds(96, 360, 393, 25); submitPanel.add(problems); JButton submit = new JButton("Submit"); submit.setBounds(170, 458, 160, 30); submit.addActionListener(e -> { try { File file = fileChooser.getSelectedFile(); try { CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost uploadFile = new HttpPost(Main.Configuration.get("submit_url")); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.addTextBody("accountID", Main.accountID, ContentType.TEXT_PLAIN); builder.addTextBody("problem", String.valueOf(problems.getSelectedItem()), ContentType.TEXT_PLAIN); builder.addBinaryBody("submission", file, ContentType.APPLICATION_OCTET_STREAM, file.getName()); HttpEntity multipart = builder.build(); uploadFile.setEntity(multipart); CloseableHttpResponse response = httpClient.execute(uploadFile); HttpEntity responseEntity = response.getEntity(); String inputLine; BufferedReader br = new BufferedReader(new InputStreamReader(responseEntity.getContent())); try { if ((inputLine = br.readLine()) != null) { int rowIndex = Integer.parseInt(inputLine); new ResultWatcher(rowIndex); } br.close(); } catch (IOException ex) { ex.printStackTrace(); } } catch (Exception ex) { ex.printStackTrace(); } } catch (NullPointerException ex) { JOptionPane.showMessageDialog(this, "No file selected.\nPlease select a java file.", "Error", JOptionPane.WARNING_MESSAGE); } }); submitPanel.add(submit); JPanel clarificationsPanel = new JPanel(null); clarificationsPanel.setPreferredSize(new Dimension(500, 500)); cList = new JList<>(); cList.setBounds(12, 12, 476, 200); cList.setBorder(new CompoundBorder(BorderFactory.createLineBorder(new Color(122, 138, 152)), BorderFactory.createEmptyBorder(8, 8, 8, 8))); cList.setBackground(new Color(254, 254, 255)); clarificationsPanel.add(cList); JButton viewC = new JButton("View"); viewC.setBounds(12, 224, 232, 25); viewC.addActionListener(e -> { if (cList.getSelectedIndex() != -1) { int id = Integer.parseInt(cList.getSelectedValue().split("\\.")[0]); clarificationDatas.stream().filter(data -> data.getId() == id).forEach( data -> new ClarificationDisplay(data.getProblem(), data.getText(), data.getResponse())); } }); clarificationsPanel.add(viewC); JButton refreshC = new JButton("Refresh"); refreshC.setBounds(256, 224, 232, 25); refreshC.addActionListener(e -> updateCList(true)); clarificationsPanel.add(refreshC); JSeparator separator2 = new JSeparator(); separator2.setBounds(12, 261, 476, 2); separator2.setForeground(new Color(122, 138, 152)); clarificationsPanel.add(separator2); JLabel problemChooserLabelC = new JLabel("Problem:"); problemChooserLabelC.setBounds(12, 273, 74, 25); clarificationsPanel.add(problemChooserLabelC); JComboBox problemsC = new JComboBox<>(listOfProblems); problemsC.setBounds(96, 273, 393, 25); clarificationsPanel.add(problemsC); JTextArea textAreaC = new JTextArea(); textAreaC.setLineWrap(true); textAreaC.setWrapStyleWord(true); textAreaC.setBorder(new CompoundBorder(BorderFactory.createLineBorder(new Color(122, 138, 152)), BorderFactory.createEmptyBorder(8, 8, 8, 8))); textAreaC.setBackground(new Color(254, 254, 255)); JScrollPane areaScrollPane = new JScrollPane(textAreaC); areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); areaScrollPane.setBounds(12, 312, 477, 134); clarificationsPanel.add(areaScrollPane); JButton submitC = new JButton("Submit Clarification"); submitC.setBounds(170, 458, 160, 30); submitC.addActionListener(e -> { if (textAreaC.getText().length() > 2048) { JOptionPane.showMessageDialog(this, "Clarification body is too long.\nMaximum of 2048 characters allowed.", "Error", JOptionPane.WARNING_MESSAGE); } else if (textAreaC.getText().length() < 20) { JOptionPane.showMessageDialog(this, "Clarification body is too short.\nClarifications must be at least 20 characters, but no more than 2048.", "Error", JOptionPane.WARNING_MESSAGE); } else { Connection conn = null; PreparedStatement stmt = null; try { Class.forName(JDBC_DRIVER); conn = DriverManager.getConnection(Main.Configuration.get("jdbc_mysql_address"), Main.Configuration.get("mysql_user"), Main.Configuration.get("mysql_pass")); String sql = "INSERT INTO clarifications (team, problem, text) VALUES (?, ?, ?)"; stmt = conn.prepareStatement(sql); stmt.setInt(1, Integer.parseInt(String.valueOf(Main.accountID))); stmt.setString(2, String.valueOf(problemsC.getSelectedItem())); stmt.setString(3, String.valueOf(textAreaC.getText())); textAreaC.setText(""); stmt.executeUpdate(); stmt.close(); conn.close(); updateCList(false); } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (stmt != null) { stmt.close(); } } catch (Exception ex2) { ex2.printStackTrace(); } try { if (conn != null) { conn.close(); } } catch (Exception ex2) { ex2.printStackTrace(); } } } }); clarificationsPanel.add(submitC); pane.addTab("Submit", submitPanel); pane.addTab("Clarifications", clarificationsPanel); Timer timer = new Timer(); TimerTask updateTask = new TimerTask() { @Override public void run() { updateCList(false); } }; timer.schedule(updateTask, 10000, 10000); updateCList(false); this.pack(); this.setLocationRelativeTo(null); this.setVisible(true); }
From source file:com.bwc.ora.OraUtils.java
public static File selectFile(boolean openDialog, Component parent, int selectorType, String selectDescription, String extensionDescription, String... extentions) { File prevLocation = fc.getSelectedFile() != null ? fc.getSelectedFile().getParentFile() : null; fc = new JFileChooser(prevLocation); fc.setMultiSelectionEnabled(false);//from w ww. j a va 2s . co m fc.setFileSelectionMode(selectorType); if (selectorType == JFileChooser.FILES_ONLY) { fc.setFileFilter(new FileNameExtensionFilter(extensionDescription, extentions)); } fc.setAcceptAllFileFilterUsed(false); fc.setApproveButtonText("Select"); fc.setDialogTitle("Select " + selectDescription + "..."); int returnVal = openDialog ? fc.showOpenDialog(parent) : fc.showSaveDialog(parent); if (returnVal == JFileChooser.APPROVE_OPTION) { if (selectorType == JFileChooser.FILES_ONLY) { System.out.println("pwd: " + fc.getCurrentDirectory()); return openDialog ? loadFile(fc.getSelectedFile()) : fc.getSelectedFile(); } else if (selectorType == JFileChooser.DIRECTORIES_ONLY) { return loadDir(fc.getSelectedFile()); } else { throw new IllegalArgumentException( "Can't handle loading of files or directories at the same time!"); } } else { return null; } }
From source file:table.FrequencyTablePanel.java
public String doSaveAs(File f) throws IOException { JFileChooser fileChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF Files", "pdf"); fileChooser.addChoosableFileFilter(filter); fileChooser.setFileFilter(filter);/*from w w w .j a va2s .c om*/ String filename = ""; int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { filename = fileChooser.getSelectedFile().getPath(); if (!filename.endsWith(".png")) { filename = filename + ".png"; } saveTableAsPNG(new File(filename), this.table, getWidth(), getHeight()); } return filename; }
From source file:aldenjava.opticalmapping.data.mappingresult.ResultFormat.java
public static final FileNameExtensionFilter[] getFileNameExtensionFilter(boolean allowAllSupport) { FileNameExtensionFilter[] filters = new FileNameExtensionFilter[ResultFormat.values().length + (allowAllSupport ? 1 : 0)]; int index = 0; if (allowAllSupport) filters[index++] = new FileNameExtensionFilter("All supported format", ResultFormat.getExtensions()); for (ResultFormat rformat : ResultFormat.values()) filters[index++] = new FileNameExtensionFilter(rformat.description, rformat.extension); return filters; }
From source file:ImageIOTest.java
/** * Open a file and load the images./*from w ww . j av a 2 s .c o m*/ */ public void openFile() { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(".")); String[] extensions = ImageIO.getReaderFileSuffixes(); chooser.setFileFilter(new FileNameExtensionFilter("Image files", extensions)); int r = chooser.showOpenDialog(this); if (r != JFileChooser.APPROVE_OPTION) return; File f = chooser.getSelectedFile(); Box box = Box.createVerticalBox(); try { String name = f.getName(); String suffix = name.substring(name.lastIndexOf('.') + 1); Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix); ImageReader reader = iter.next(); ImageInputStream imageIn = ImageIO.createImageInputStream(f); reader.setInput(imageIn); int count = reader.getNumImages(true); images = new BufferedImage[count]; for (int i = 0; i < count; i++) { images[i] = reader.read(i); box.add(new JLabel(new ImageIcon(images[i]))); } } catch (IOException e) { JOptionPane.showMessageDialog(this, e); } setContentPane(new JScrollPane(box)); validate(); }
From source file:de.fhg.igd.mapviewer.server.file.MapFileServerFactory.java
/** * Default constructor/* w w w . j ava2s.c o m*/ */ public MapFileServerFactory() { fileChooser.setFileFilter(new FileNameExtensionFilter(Messages.getString("MapFileServerFactory.1"), //$NON-NLS-1$ FileTiler.MAP_ARCHIVE_EXTENSION.substring(1))); }
From source file:ca.uviccscu.lp.server.main.MainFrame.java
/** Creates new form MainFrame */ public MainFrame() { initComponents();// w ww. j av a 2s .com this.addWindowListener(new ShutdownListener()); setupTablePopup(); setupOther(); jFileChooser1.setFileFilter(new FileNameExtensionFilter("uTorrent executable(.exe)", "exe")); }