@Override public JPopupMenu getComponentPopupMenu() { if (popupMenu == null) { popupMenu = new JPopupMenu(Messages.CHART_COLON); timeRangeMenu = new JMenu(Messages.PLOTTER_TIME_RANGE_MENU); timeRangeMenu.setMnemonic(Resources.getMnemonicInt(Messages.PLOTTER_TIME_RANGE_MENU)); popupMenu.add(timeRangeMenu); menuRBs = new JRadioButtonMenuItem[rangeNames.length]; ButtonGroup rbGroup = new ButtonGroup(); for (int i = 0; i < rangeNames.length; i++) { menuRBs[i] = new JRadioButtonMenuItem(rangeNames[i]); rbGroup.add(menuRBs[i]); menuRBs[i].addActionListener(this); if (viewRange == rangeValues[i]) { menuRBs[i].setSelected(true); } timeRangeMenu.add(menuRBs[i]); } popupMenu.addSeparator(); saveAsMI = new JMenuItem(Messages.PLOTTER_SAVE_AS_MENU_ITEM); saveAsMI.setMnemonic(Resources.getMnemonicInt(Messages.PLOTTER_SAVE_AS_MENU_ITEM)); saveAsMI.addActionListener(this); popupMenu.add(saveAsMI); } return popupMenu; }
@Override public String getAccessibleName() { String name = super.getAccessibleName(); if (seqs.size() > 0 && seqs.get(0).size > 0) { String keyValueList = ""; for (Sequence seq : seqs) { if (seq.isPlotted) { String value = "null"; if (seq.size > 0) { if (unit == Unit.BYTES) { value = Resources.format(Messages.SIZE_BYTES, seq.value(seq.size - 1)); } else { value = getFormattedValue(seq.value(seq.size - 1), false) + ((unit == Unit.PERCENT) ? "%" : ""); } } // Assume format string ends with newline keyValueList += Resources.format(Messages.PLOTTER_ACCESSIBLE_NAME_KEY_AND_VALUE, seq.key, value); } } name += "\n" + keyValueList + "."; } else { name += "\n" + Messages.PLOTTER_ACCESSIBLE_NAME_NO_DATA; } return name; }
private void saveDataToFile(File file) { try { PrintStream out = new PrintStream(new FileOutputStream(file)); // Print header line out.print("Time"); for (Sequence seq : seqs) { out.print("," + seq.name); } out.println(); // Print data lines if (seqs.size() > 0 && seqs.get(0).size > 0) { for (int i = 0; i < seqs.get(0).size; i++) { double excelTime = toExcelTime(times.time(i)); out.print(String.format(Locale.ENGLISH, "%.6f", excelTime)); for (Sequence seq : seqs) { out.print("," + getFormattedValue(seq.value(i), false)); } out.println(); } } out.close(); JOptionPane.showMessageDialog( this, Resources.format( Messages.FILE_CHOOSER_SAVED_FILE, file.getAbsolutePath(), file.length())); } catch (IOException ex) { String msg = ex.getLocalizedMessage(); String path = file.getAbsolutePath(); if (msg.startsWith(path)) { msg = msg.substring(path.length()).trim(); } JOptionPane.showMessageDialog( this, Resources.format(Messages.FILE_CHOOSER_SAVE_FAILED_MESSAGE, path, msg), Messages.FILE_CHOOSER_SAVE_FAILED_TITLE, JOptionPane.ERROR_MESSAGE); } }
@Override public void approveSelection() { File file = getSelectedFile(); if (file != null) { FileFilter filter = getFileFilter(); if (filter != null && filter instanceof FileNameExtensionFilter) { String[] extensions = ((FileNameExtensionFilter) filter).getExtensions(); boolean goodExt = false; for (String ext : extensions) { if (file.getName().toLowerCase().endsWith("." + ext.toLowerCase())) { goodExt = true; break; } } if (!goodExt) { file = new File(file.getParent(), file.getName() + "." + extensions[0]); } } if (file.exists()) { String okStr = Messages.FILE_CHOOSER_FILE_EXISTS_OK_OPTION; String cancelStr = Messages.FILE_CHOOSER_FILE_EXISTS_CANCEL_OPTION; int ret = JOptionPane.showOptionDialog( this, Resources.format(Messages.FILE_CHOOSER_FILE_EXISTS_MESSAGE, file.getName()), Messages.FILE_CHOOSER_FILE_EXISTS_TITLE, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, new Object[] {okStr, cancelStr}, okStr); if (ret != JOptionPane.OK_OPTION) { return; } } setSelectedFile(file); } super.approveSelection(); }