List of usage examples for javax.swing JFileChooser showSaveDialog
public int showSaveDialog(Component parent) throws HeadlessException
From source file:net.sf.keystore_explorer.gui.dialogs.DViewCertCsrPem.java
private void exportPressed() { File chosenFile = null;/* w w w . ja v a 2 s. c o m*/ FileWriter fw = null; String title; if (cert != null) { title = res.getString("DViewCertCsrPem.ExportPemCertificate.Title"); } else { title = res.getString("DViewCertCsrPem.ExportPemCsr.Title"); } try { String certPem = jtaPem.getText(); JFileChooser chooser = FileChooserFactory.getX509FileChooser(); chooser.setCurrentDirectory(CurrentDirectory.get()); chooser.setDialogTitle(title); chooser.setMultiSelectionEnabled(false); int rtnValue = JavaFXFileChooser.isFxAvailable() ? chooser.showSaveDialog(this) : chooser.showDialog(this, res.getString("DViewCertCsrPem.ChooseExportFile.button")); if (rtnValue != JFileChooser.APPROVE_OPTION) { return; } chosenFile = chooser.getSelectedFile(); CurrentDirectory.updateForFile(chosenFile); if (chosenFile.isFile()) { String message = MessageFormat.format(res.getString("DViewCertCsrPem.OverWriteFile.message"), chosenFile); int selected = JOptionPane.showConfirmDialog(this, message, title, JOptionPane.YES_NO_OPTION); if (selected != JOptionPane.YES_OPTION) { return; } } fw = new FileWriter(chosenFile); fw.write(certPem); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(this, MessageFormat.format(res.getString("DViewCertCsrPem.NoWriteFile.message"), chosenFile), title, JOptionPane.WARNING_MESSAGE); return; } catch (Exception ex) { DError.displayError(this, ex); return; } finally { IOUtils.closeQuietly(fw); } JOptionPane.showMessageDialog(this, res.getString("DViewCertCsrPem.ExportPemCertificateSuccessful.message"), title, JOptionPane.INFORMATION_MESSAGE); }
From source file:lu.lippmann.cdb.ext.hydviga.ui.GapsOverviewPanel.java
public void refresh(final Instances dataSet, final int dateIdx) { final Instances gapsDescriptionsDataset = GapsUtil.buildGapsDescription(gcp, dataSet, dateIdx); final JXTable gapsDescriptionsTable = new JXTable(); final InstanceTableModel gapsDescriptionsTableModel = new InstanceTableModel(false); gapsDescriptionsTableModel.setDataset(gapsDescriptionsDataset); gapsDescriptionsTable.setModel(gapsDescriptionsTableModel); gapsDescriptionsTable.setEditable(true); gapsDescriptionsTable.setShowHorizontalLines(false); gapsDescriptionsTable.setShowVerticalLines(false); gapsDescriptionsTable.setVisibleRowCount(5); gapsDescriptionsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); gapsDescriptionsTable.setSortable(false); gapsDescriptionsTable.packAll();/* ww w .j a va2 s .c om*/ gapsDescriptionsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); gapsDescriptionsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { int modelRow = gapsDescriptionsTable.getSelectedRow(); if (modelRow < 0) modelRow = 0; final String attrname = gapsDescriptionsTableModel.getValueAt(modelRow, 1).toString(); final Attribute attr = dataSet.attribute(attrname); final int gapsize = (int) Double .valueOf(gapsDescriptionsTableModel.getValueAt(modelRow, 5).toString()).doubleValue(); final int position = (int) Double .valueOf(gapsDescriptionsTableModel.getValueAt(modelRow, 6).toString()).doubleValue(); try { final ChartPanel cp = GapsUIUtil.buildGapChartPanel(dataSet, dateIdx, attr, gapsize, position); visualOverviewPanel.removeAll(); visualOverviewPanel.add(cp, BorderLayout.CENTER); geomapPanel.removeAll(); geomapPanel.add(gcp.getMapPanel(Arrays.asList(attrname), new ArrayList<String>(), false)); jxp.updateUI(); } catch (Exception ee) { ee.printStackTrace(); } } } }); gapsDescriptionsTable.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(final MouseEvent e) { final InstanceTableModel instanceTableModel = (InstanceTableModel) gapsDescriptionsTable.getModel(); final int row = gapsDescriptionsTable.rowAtPoint(e.getPoint()); //final int row=gapsDescriptionsTable.getSelectedRow(); final int modelRow = gapsDescriptionsTable.convertRowIndexToModel(row); //final int modelRow=(int)Double.valueOf(instanceTableModel.getValueAt(row,0).toString()).doubleValue(); //System.out.println(row+" "+modelRow); final String attrname = instanceTableModel.getValueAt(modelRow, 1).toString(); final Attribute attr = dataSet.attribute(attrname); final int gapsize = (int) Double.valueOf(instanceTableModel.getValueAt(modelRow, 5).toString()) .doubleValue(); final int position = (int) Double.valueOf(instanceTableModel.getValueAt(modelRow, 6).toString()) .doubleValue(); if (!e.isPopupTrigger()) { // nothing? } else { final JPopupMenu jPopupMenu = new JPopupMenu("feur"); final JMenuItem interactiveFillMenuItem = new JMenuItem("Fill this gap (interactively)"); interactiveFillMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final GapFillingFrame jxf = new GapFillingFrame(atv, dataSet, attr, dateIdx, GapsUtil.getCountOfValuesBeforeAndAfter(gapsize), position, gapsize, gcp, false); jxf.setSize(new Dimension(900, 700)); //jxf.setExtendedState(Frame.MAXIMIZED_BOTH); jxf.setLocationRelativeTo(jPopupMenu); jxf.setVisible(true); //jxf.setResizable(false); } }); jPopupMenu.add(interactiveFillMenuItem); final JMenuItem lookupInKnowledgeDBMenuItem = new JMenuItem( "Show the most similar cases from KnowledgeDB"); lookupInKnowledgeDBMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final double x = gcp.getCoordinates(attrname)[0]; final double y = gcp.getCoordinates(attrname)[1]; final String season = instanceTableModel.getValueAt(modelRow, 3).toString() .split("/")[0]; final boolean isDuringRising = instanceTableModel.getValueAt(modelRow, 11).toString() .equals("true"); try { final Calendar cal = Calendar.getInstance(); final String dateAsString = instanceTableModel.getValueAt(modelRow, 2).toString() .replaceAll("'", ""); cal.setTime(FormatterUtil.DATE_FORMAT.parse(dateAsString)); final int year = cal.get(Calendar.YEAR); new SimilarCasesFrame(dataSet, dateIdx, gcp, attrname, gapsize, position, x, y, year, season, isDuringRising); } catch (Exception e1) { e1.printStackTrace(); } } }); jPopupMenu.add(lookupInKnowledgeDBMenuItem); final JMenuItem mExport = new JMenuItem("Export this table as CSV"); mExport.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final JFileChooser fc = new JFileChooser(); fc.setAcceptAllFileFilterUsed(false); final int returnVal = fc.showSaveDialog(gapsDescriptionsTable); if (returnVal == JFileChooser.APPROVE_OPTION) { try { final File file = fc.getSelectedFile(); WekaDataAccessUtil.saveInstancesIntoCSVFile(gapsDescriptionsDataset, file); } catch (Exception ee) { ee.printStackTrace(); } } } }); jPopupMenu.add(mExport); jPopupMenu.show(gapsDescriptionsTable, e.getX(), e.getY()); } } }); final int tableWidth = (int) gapsDescriptionsTable.getPreferredSize().getWidth() + 30; final JScrollPane scrollPane = new JScrollPane(gapsDescriptionsTable); scrollPane.setPreferredSize(new Dimension(Math.min(tableWidth, 500), 500)); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); this.tablePanel.removeAll(); this.tablePanel.add(scrollPane, BorderLayout.CENTER); this.visualOverviewPanel.removeAll(); /* automatically compute the most similar series and the 'rising' flag */ new AbstractSimpleAsync<Void>(false) { @Override public Void execute() throws Exception { final int rc = gapsDescriptionsTableModel.getRowCount(); for (int i = 0; i < rc; i++) { final int modelRow = i; try { final String attrname = gapsDescriptionsTableModel.getValueAt(modelRow, 1).toString(); final Attribute attr = dataSet.attribute(attrname); final int gapsize = (int) Double .valueOf(gapsDescriptionsTableModel.getValueAt(modelRow, 5).toString()) .doubleValue(); final int position = (int) Double .valueOf(gapsDescriptionsTableModel.getValueAt(modelRow, 6).toString()) .doubleValue(); /* most similar */ gapsDescriptionsTableModel.setValueAt("...", modelRow, 7); final int cvba = GapsUtil.getCountOfValuesBeforeAndAfter(gapsize); Instances gapds = WekaDataProcessingUtil.buildFilteredDataSet(dataSet, 0, dataSet.numAttributes() - 1, Math.max(0, position - cvba), Math.min(position + gapsize + cvba, dataSet.numInstances() - 1)); final String mostsimilar = WekaTimeSeriesSimilarityUtil.findMostSimilarTimeSerie(gapds, attr, WekaTimeSeriesUtil.getNamesOfAttributesWithoutGap(gapds), false); gapsDescriptionsTableModel.setValueAt(mostsimilar, modelRow, 7); /* 'rising' flag */ gapsDescriptionsTableModel.setValueAt("...", modelRow, 11); final List<String> attributeNames = WekaDataStatsUtil.getAttributeNames(dataSet); attributeNames.remove("timestamp"); final String nearestStationName = gcp.findNearestStation(attr.name(), attributeNames); final Attribute nearestStationAttr = dataSet.attribute(nearestStationName); //System.out.println(nearestStationName+" "+nearestStationAttr); final boolean isDuringRising = GapsUtil.isDuringRising(dataSet, position, gapsize, new int[] { dateIdx, attr.index(), nearestStationAttr.index() }); gapsDescriptionsTableModel.setValueAt(isDuringRising, modelRow, 11); gapsDescriptionsTableModel.fireTableDataChanged(); } catch (Exception e) { gapsDescriptionsTableModel.setValueAt("n/a", modelRow, 7); gapsDescriptionsTableModel.setValueAt("n/a", modelRow, 11); e.printStackTrace(); } } return null; } @Override public void onSuccess(Void result) { } @Override public void onFailure(Throwable caught) { caught.printStackTrace(); } }.start(); /* select the first row */ gapsDescriptionsTable.setRowSelectionInterval(0, 0); }
From source file:lu.lippmann.cdb.ext.hydviga.ui.GapFillingKnowledgeDBExplorerFrame.java
/** * Constructor./*from ww w . java 2s . c o m*/ */ GapFillingKnowledgeDBExplorerFrame(final Instances ds, final int dateIdx, final StationsDataProvider gcp) throws Exception { LogoHelper.setLogo(this); this.setTitle("KnowledgeDB: explorer"); this.gcp = gcp; this.tablePanel = new JXPanel(); this.tablePanel.setBorder(new TitledBorder("Cases")); final JXPanel highPanel = new JXPanel(); highPanel.setLayout(new BoxLayout(highPanel, BoxLayout.X_AXIS)); highPanel.add(this.tablePanel); this.geomapPanel = new JXPanel(); this.geomapPanel.add(buildGeoMapChart(new ArrayList<String>(), new ArrayList<String>())); highPanel.add(this.geomapPanel); this.caseChartPanel = new JXPanel(); this.caseChartPanel.setBorder(new TitledBorder("Inspected fake gap")); this.mostSimilarChartPanel = new JXPanel(); this.mostSimilarChartPanel.setBorder(new TitledBorder("Most similar")); this.nearestChartPanel = new JXPanel(); this.nearestChartPanel.setBorder(new TitledBorder("Nearest")); this.downstreamChartPanel = new JXPanel(); this.downstreamChartPanel.setBorder(new TitledBorder("Downstream")); this.upstreamChartPanel = new JXPanel(); this.upstreamChartPanel.setBorder(new TitledBorder("Upstream")); getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS)); //getContentPane().add(new JCheckBox("Use incomplete series")); getContentPane().add(highPanel); //getContentPane().add(new JXButton("Export")); getContentPane().add(caseChartPanel); getContentPane().add(mostSimilarChartPanel); getContentPane().add(nearestChartPanel); getContentPane().add(downstreamChartPanel); getContentPane().add(upstreamChartPanel); //final Instances kdbDS=GapFillingKnowledgeDB.getKnowledgeDBWithBestCasesOnly(); final Instances kdbDS = GapFillingKnowledgeDB.getKnowledgeDB(); final JXTable gapsTable = buidJXTable(kdbDS); final JScrollPane tableScrollPane = new JScrollPane(gapsTable); tableScrollPane.setPreferredSize( new Dimension(COMPONENT_WIDTH - 100, 40 + (int) (tableScrollPane.getPreferredSize().getHeight()))); this.tablePanel.add(tableScrollPane); gapsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); gapsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { final int modelRow = gapsTable.getSelectedRow(); final String attrname = gapsTable.getModel().getValueAt(modelRow, 1).toString(); final int gapsize = (int) Double .valueOf(gapsTable.getModel().getValueAt(modelRow, 4).toString()).doubleValue(); final int position = (int) Double .valueOf(gapsTable.getModel().getValueAt(modelRow, 5).toString()).doubleValue(); final String mostSimilarFlag = gapsTable.getModel().getValueAt(modelRow, 14).toString(); final String nearestFlag = gapsTable.getModel().getValueAt(modelRow, 15).toString(); final String downstreamFlag = gapsTable.getModel().getValueAt(modelRow, 16).toString(); final String upstreamFlag = gapsTable.getModel().getValueAt(modelRow, 17).toString(); final String algoname = gapsTable.getModel().getValueAt(modelRow, 12).toString(); final boolean useDiscretizedTime = Boolean .valueOf(gapsTable.getModel().getValueAt(modelRow, 13).toString()); try { geomapPanel.removeAll(); caseChartPanel.removeAll(); mostSimilarChartPanel.removeAll(); nearestChartPanel.removeAll(); downstreamChartPanel.removeAll(); upstreamChartPanel.removeAll(); final Set<String> selected = new HashSet<String>(); final Instances tmpds = WekaDataProcessingUtil.buildFilteredDataSet(ds, 0, ds.numAttributes() - 1, Math.max(0, position - GapsUtil.getCountOfValuesBeforeAndAfter(gapsize)), Math.min(position + gapsize + GapsUtil.getCountOfValuesBeforeAndAfter(gapsize), ds.numInstances() - 1)); final List<String> attributeNames = WekaTimeSeriesUtil .getNamesOfAttributesWithoutGap(tmpds); //final List<String> attributeNames=WekaDataStatsUtil.getAttributeNames(ds); attributeNames.remove(attrname); attributeNames.remove("timestamp"); if (Boolean.valueOf(mostSimilarFlag)) { final String mostSimilarStationName = WekaTimeSeriesSimilarityUtil .findMostSimilarTimeSerie(tmpds, tmpds.attribute(attrname), attributeNames, false); selected.add(mostSimilarStationName); final Attribute mostSimilarStationAttr = tmpds.attribute(mostSimilarStationName); final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, mostSimilarStationAttr, gapsize, position); cp0.getChart().removeLegend(); cp0.setPreferredSize(CHART_DIMENSION); mostSimilarChartPanel.add(cp0); } if (Boolean.valueOf(nearestFlag)) { final String nearestStationName = gcp.findNearestStation(attrname, attributeNames); selected.add(nearestStationName); final Attribute nearestStationAttr = ds.attribute(nearestStationName); final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, nearestStationAttr, gapsize, position); cp0.getChart().removeLegend(); cp0.setPreferredSize(CHART_DIMENSION); nearestChartPanel.add(cp0); } if (Boolean.valueOf(downstreamFlag)) { final String downstreamStationName = gcp.findDownstreamStation(attrname, attributeNames); selected.add(downstreamStationName); final Attribute downstreamStationAttr = ds.attribute(downstreamStationName); final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, downstreamStationAttr, gapsize, position); cp0.getChart().removeLegend(); cp0.setPreferredSize(CHART_DIMENSION); downstreamChartPanel.add(cp0); } if (Boolean.valueOf(upstreamFlag)) { final String upstreamStationName = gcp.findUpstreamStation(attrname, attributeNames); selected.add(upstreamStationName); final Attribute upstreamStationAttr = ds.attribute(upstreamStationName); final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, upstreamStationAttr, gapsize, position); cp0.getChart().removeLegend(); cp0.setPreferredSize(CHART_DIMENSION); upstreamChartPanel.add(cp0); } final GapFiller gapFiller = GapFillerFactory.getGapFiller(algoname, useDiscretizedTime); final ChartPanel cp = GapsUIUtil.buildGapChartPanelWithCorrection(ds, dateIdx, ds.attribute(attrname), gapsize, position, gapFiller, selected); cp.getChart().removeLegend(); cp.setPreferredSize(new Dimension((int) CHART_DIMENSION.getWidth(), (int) (CHART_DIMENSION.getHeight() * 1.5))); caseChartPanel.add(cp); geomapPanel.add(buildGeoMapChart(Arrays.asList(attrname), selected)); getContentPane().repaint(); pack(); } catch (Exception e1) { e1.printStackTrace(); } } } }); gapsTable.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(final MouseEvent e) { if (!e.isPopupTrigger()) { // nothing? } else { final JPopupMenu jPopupMenu = new JPopupMenu("feur"); final JMenuItem mExport = new JMenuItem("Export this table as CSV"); mExport.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final JFileChooser fc = new JFileChooser(); fc.setAcceptAllFileFilterUsed(false); final int returnVal = fc.showSaveDialog(gapsTable); if (returnVal == JFileChooser.APPROVE_OPTION) { try { final File file = fc.getSelectedFile(); WekaDataAccessUtil.saveInstancesIntoCSVFile(kdbDS, file); } catch (Exception ee) { ee.printStackTrace(); } } } }); jPopupMenu.add(mExport); jPopupMenu.show(gapsTable, e.getX(), e.getY()); } } }); setPreferredSize(new Dimension(FRAME_WIDTH, 1000)); pack(); setVisible(true); /* select the first row */ gapsTable.setRowSelectionInterval(0, 0); }
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 www. ja v a2s. 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:Compare.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: String userDir = System.getProperty("user.home"); JFileChooser folder = new JFileChooser(userDir + "/Desktop"); folder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); folder.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Excel Files (*.xls)", "xls"); folder.setFileFilter(xmlfilter);//from ww w . j av a2s. c o m int returnvalue = folder.showSaveDialog(this); File myfolder = null; if (returnvalue == JFileChooser.APPROVE_OPTION) { myfolder = folder.getSelectedFile(); // System.out.println(myfolder); } if (myfolder != null) { JOptionPane.showMessageDialog(null, "The current choosen file directory is : " + myfolder); } listofFiles(myfolder); sortByName(); DefaultTableModel model = (DefaultTableModel) FileDetails.getModel(); int count = 1; for (Files filename : filenames1) { String size = Long.toString(filename.Filesize) + "Bytes"; model.addRow(new Object[] { count++, filename.Filename, size, filename.FileLocation }); } }
From source file:ru.develgame.jflickrorganizer.MainForm.java
private void jButtonChooseBackupFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonChooseBackupFolderActionPerformed JFileChooser jFileChooserSaveBackup = new JFileChooser(); jFileChooserSaveBackup.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = jFileChooserSaveBackup.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { jTextFieldBackupFolder.setText(jFileChooserSaveBackup.getSelectedFile().getAbsolutePath()); }//from w w w . ja v a 2s .co m }
From source file:Compare.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: String userDir = System.getProperty("user.home"); JFileChooser folder = new JFileChooser(userDir + "/Desktop"); folder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); folder.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter xmlfilter = new FileNameExtensionFilter("Excel Files (*.xls)", "xls"); folder.setFileFilter(xmlfilter);/* w ww . j a va 2 s. c om*/ int returnvalue = folder.showSaveDialog(this); File myfolder = null; if (returnvalue == JFileChooser.APPROVE_OPTION) { myfolder = folder.getSelectedFile(); // System.out.println(myfolder); } if (myfolder != null) { JOptionPane.showMessageDialog(null, "The current choosen file directory is : " + myfolder); listofFiles1(myfolder); sortByName1(); } DefaultTableModel model = (DefaultTableModel) FileDetails1.getModel(); int count = 1; System.out.println(filenames2.size()); for (Files filename : filenames2) { String size = Long.toString(filename.Filesize) + "Bytes"; model.addRow(new Object[] { count++, filename.Filename, size, filename.FileLocation }); } }
From source file:de.fhbingen.wbs.wpOverview.tabs.APCalendarPanel.java
/** * Initialize the work package calendar panel inclusive the listeners. */// w w w . ja v a 2 s . co m private void init() { List<Workpackage> userWp = new ArrayList<Workpackage>(WpManager.getUserWp(WPOverview.getUser())); Collections.sort(userWp, new APLevelComparator()); dataset = createDataset(userWp); chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); final JPopupMenu popup = new JPopupMenu(); JMenuItem miSave = new JMenuItem(LocalizedStrings.getButton().save(LocalizedStrings.getWbs().timeLine())); miSave.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent arg0) { JFileChooser chooser = new JFileChooser(); chooser.setFileFilter(new ExtensionAndFolderFilter("jpg", "jpeg")); //NON-NLS chooser.setSelectedFile(new File("chart-" //NON-NLS + System.currentTimeMillis() + ".jpg")); int returnVal = chooser.showSaveDialog(reference); if (returnVal == JFileChooser.APPROVE_OPTION) { try { File outfile = chooser.getSelectedFile(); ChartUtilities.saveChartAsJPEG(outfile, chart, chartPanel.getWidth(), chartPanel.getWidth()); Controller.showMessage( LocalizedStrings.getMessages().timeLineSaved(outfile.getCanonicalPath())); } catch (IOException e) { Controller.showError(LocalizedStrings.getErrorMessages().timeLineExportError()); } } } }); popup.add(miSave); chartPanel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(final MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { popup.show(e.getComponent(), e.getX(), e.getY()); } } }); chartPanel.setMinimumDrawHeight(50 + 15 * userWp.size()); chartPanel.setMaximumDrawHeight(50 + 15 * userWp.size()); chartPanel.setMaximumDrawWidth(9999); chartPanel.setPreferredSize( new Dimension((int) chartPanel.getPreferredSize().getWidth(), 50 + 15 * userWp.size())); chartPanel.setPopupMenu(null); this.setLayout(new BorderLayout()); this.removeAll(); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weightx = 1; constraints.weighty = 1; constraints.anchor = GridBagConstraints.NORTHWEST; panel.add(chartPanel, constraints); panel.setBackground(Color.white); this.add(panel, BorderLayout.CENTER); GanttRenderer.setDefaultShadowsVisible(false); GanttRenderer.setDefaultBarPainter(new BarPainter() { @Override public void paintBar(final Graphics2D g, final BarRenderer arg1, final int row, final int col, final RectangularShape rect, final RectangleEdge arg5) { String wpName = (String) dataset.getColumnKey(col); int i = 0; int spaceCount = 0; while (wpName.charAt(i++) == ' ' && spaceCount < 17) { spaceCount++; } g.setColor(new Color(spaceCount * 15, spaceCount * 15, spaceCount * 15)); g.fill(rect); g.setColor(Color.black); g.setStroke(new BasicStroke()); g.draw(rect); } @Override public void paintBarShadow(final Graphics2D arg0, final BarRenderer arg1, final int arg2, final int arg3, final RectangularShape arg4, final RectangleEdge arg5, final boolean arg6) { } }); ((CategoryPlot) chart.getPlot()).setRenderer(new GanttRenderer() { private static final long serialVersionUID = -6078915091070733812L; public void drawItem(final Graphics2D g2, final CategoryItemRendererState state, final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis, final ValueAxis rangeAxis, final CategoryDataset dataset, final int row, final int column, final int pass) { super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column, pass); } }); }
From source file:fr.eurecom.hybris.demogui.HybrisDemoGui.java
public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (cmd.equals("Get")) { if (lstHybris.getSelectedIndex() >= 0) { try { System.out.println("Retrieving " + lstHybris.getSelectedValue() + "..."); byte[] retrieved = cm.hybris.get(lstHybris.getSelectedValue()); if (retrieved != null) { JFileChooser fc = new JFileChooser( System.getProperty("user.home") + File.separator + "Desktop"); fc.setSelectedFile(new File("RETRIEVED_" + lstHybris.getSelectedValue())); int returnVal = fc.showSaveDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); FileUtils.writeByteArrayToFile(file, retrieved); System.out.println("Saved: " + file.getName() + "."); }//from ww w .j av a 2 s .c om } else JOptionPane.showMessageDialog(frame, "Hybris could not download the file.", "Error", JOptionPane.ERROR_MESSAGE); } catch (Exception e1) { e1.printStackTrace(); } } } if (cmd.equals("Put")) { JFileChooser fc = new JFileChooser(System.getProperty("user.home") + File.separator + "Desktop"); int returnVal = fc.showOpenDialog(frame); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); System.out.println("Putting: " + file.getName() + "."); byte[] array; try { array = FileUtils.readFileToByteArray(file); new Thread(cm.new BackgroundWorker(OperationType.PUT, ClientType.HYBRIS, file.getName(), array)) .start(); } catch (Exception e1) { e1.printStackTrace(); } } } if (cmd.equals("Delete")) { if (lstHybris.getSelectedIndex() >= 0) { new Thread(cm.new BackgroundWorker(OperationType.DELETE, ClientType.HYBRIS, lstHybris.getSelectedValue(), null)).start(); System.out.println("Removed " + lstHybris.getSelectedValue() + " from Hybris."); } } }
From source file:com.socrata.datasync.ui.MetadataJobTab.java
public void saveJob() { populateJobFromFields();//w w w .ja v a 2 s . c o m // TODO If an existing file was selected WARN user of overwriting // if first time saving this job: Open dialog box to select "Save as..." location // otherwise save to existing file boolean updateJobCommandTextField = false; String selectedJobFileLocation = jobFileLocation; if (selectedJobFileLocation.equals("")) { JFileChooser savedJobFileChooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter( JOB_FILE_NAME + " (*." + JOB_FILE_EXTENSION + ")", JOB_FILE_EXTENSION); savedJobFileChooser.setFileFilter(filter); int returnVal = savedJobFileChooser.showSaveDialog(mainFrame); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = savedJobFileChooser.getSelectedFile(); selectedJobFileLocation = file.getAbsolutePath(); if (!selectedJobFileLocation.endsWith("." + JOB_FILE_EXTENSION)) { selectedJobFileLocation += "." + JOB_FILE_EXTENSION; } jobFileLocation = selectedJobFileLocation; metadataJob.setPathToSavedFile(selectedJobFileLocation); jobTabTitleLabel.setText(metadataJob.getJobFilename()); updateJobCommandTextField = true; } } // actually save the job file (may overwrite) try { metadataJob.writeToFile(selectedJobFileLocation); // Update job tab title label jobTabTitleLabel.setText(metadataJob.getJobFilename()); // Update the textfield with new command if (updateJobCommandTextField) { String runJobCommand = Utils.getRunJobCommand(metadataJob.getPathToSavedFile()); runCommandTextField.setText(runJobCommand); } } catch (IOException e) { JOptionPane.showMessageDialog(mainFrame, "Error saving " + selectedJobFileLocation + ": " + e.getMessage()); } }