private void findPresentation() { JFileChooser fileChooser = new JFileChooser(); if (lastDirectory_ != null) fileChooser.setCurrentDirectory(lastDirectory_); // if (imc.lecturnity.converter.ConverterWizard.USE_CUSTOM_COLORS) if (USE_CUSTOM_COLORS) fileChooser.setBackground(Wizard.BG_COLOR); LecturnityFileFilter lff = new LecturnityFileFilter(); fileChooser.addChoosableFileFilter(lff); LpdFileFilter lpf = new LpdFileFilter(); fileChooser.addChoosableFileFilter(lpf); EPresentationFileFilter eff = new EPresentationFileFilter(); fileChooser.addChoosableFileFilter(eff); AofFileFilter aff = new AofFileFilter(); fileChooser.addChoosableFileFilter(aff); fileChooser.addChoosableFileFilter(fileChooser.getAcceptAllFileFilter()); fileChooser.setFileFilter(lff); Dimension fcSize = fileChooser.getPreferredSize(); fileChooser.setPreferredSize(new Dimension(fcSize.width + 100, fcSize.height + 50)); int action = fileChooser.showOpenDialog(this); lastDirectory_ = fileChooser.getCurrentDirectory(); if (action == fileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); presentationFileField_.setText(selectedFile.getAbsolutePath()); } }
/** * Actions-handling method. * * @param e The event. */ public void actionPerformed(ActionEvent e) { // Prepares the file chooser JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(idata.getInstallPath())); fc.setMultiSelectionEnabled(false); fc.addChoosableFileFilter(fc.getAcceptAllFileFilter()); // fc.setCurrentDirectory(new File(".")); // Shows it try { if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { // We handle the xml data writing File file = fc.getSelectedFile(); FileOutputStream out = new FileOutputStream(file); BufferedOutputStream outBuff = new BufferedOutputStream(out, 5120); parent.writeXMLTree(idata.xmlData, outBuff); outBuff.flush(); outBuff.close(); autoButton.setEnabled(false); } } catch (Exception err) { err.printStackTrace(); JOptionPane.showMessageDialog( this, err.toString(), parent.langpack.getString("installer.error"), JOptionPane.ERROR_MESSAGE); } }
private void saveBin() { fileChooser.resetChoosableFileFilters(); fileChooser.addChoosableFileFilter(binFilter); fileChooser.setFileFilter(binFilter); if (fileChooser.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { try { File file = fileChooser.getSelectedFile(); if (fileChooser.getFileFilter() == binFilter && !binFilter.accept(file)) { file = new File(file.getAbsolutePath() + binFilter.getExtensions()[0]); } if (file.exists()) { if (JOptionPane.showConfirmDialog( frame, "File exists. Overwrite?", "Confirm", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) { return; } } FileOutputStream output = new FileOutputStream(file); for (char i : binary) { output.write(i & 0xff); output.write((i >> 8) & 0xff); } output.close(); } catch (IOException e1) { JOptionPane.showMessageDialog( frame, "Unable to open file", "Error", JOptionPane.ERROR_MESSAGE); e1.printStackTrace(); } } }
private void saveSrc() { fileChooser.resetChoosableFileFilters(); fileChooser.addChoosableFileFilter(asmFilter); fileChooser.setFileFilter(asmFilter); if (fileChooser.showSaveDialog(frame) == JFileChooser.APPROVE_OPTION) { try { File file = fileChooser.getSelectedFile(); if (fileChooser.getFileFilter() == asmFilter && !asmFilter.accept(file)) { file = new File(file.getAbsolutePath() + asmFilter.getExtensions()[0]); } if (file.exists()) { if (JOptionPane.showConfirmDialog( frame, "File exists. Overwrite?", "Confirm", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) { return; } } PrintStream output = new PrintStream(file); output.print(sourceTextarea.getText()); output.close(); } catch (IOException e1) { JOptionPane.showMessageDialog( frame, "Unable to open file", "Error", JOptionPane.ERROR_MESSAGE); e1.printStackTrace(); } } }
/** Show the save dialog to save the network file. */ private void saveEvent() { JFileChooser fileSaver = new JFileChooser(inpFile.getParent()); fileSaver.setFileSelectionMode(JFileChooser.FILES_ONLY); fileSaver.setAcceptAllFileFilterUsed(false); fileSaver.addChoosableFileFilter(new XLSXFilter()); fileSaver.addChoosableFileFilter(new XMLFilter()); fileSaver.addChoosableFileFilter(new INPFilter()); fileSaver.showSaveDialog(frame); if (fileSaver.getSelectedFile() == null) return; Network.FileType netType = Network.FileType.INP_FILE; if (fileSaver.getFileFilter() instanceof XLSXFilter) { netType = Network.FileType.EXCEL_FILE; } else if (fileSaver.getFileFilter() instanceof XMLFilter) { netType = Network.FileType.XML_FILE; JOptionPane.showMessageDialog(frame, "Not supported yet !", "Error", JOptionPane.OK_OPTION); return; } OutputComposer compose = OutputComposer.create(netType); String extension = ""; if (Utilities.getFileExtension(fileSaver.getSelectedFile().getName()).equals("")) switch (netType) { case INP_FILE: extension = ".inp"; break; case EXCEL_FILE: extension = ".xlsx"; break; case XML_FILE: extension = ".xml"; break; } try { compose.composer( epanetNetwork, new File(fileSaver.getSelectedFile().getAbsolutePath() + extension)); } catch (ENException e1) { e1.printStackTrace(); } }
public void showOpenDialog() { JFileChooser fc = new JFileChooser(Configuration.getUserHomeDirectory()); fc.addChoosableFileFilter(new VPFFileFilter()); int retVal = fc.showOpenDialog(this); if (retVal != JFileChooser.APPROVE_OPTION) return; File file = fc.getSelectedFile(); this.addVPFLayer(file); }
public void actionPerformed(ActionEvent e) { JFileChooser fileopen = new JFileChooser(); FileFilter filter = new FileNameExtensionFilter("c files", "c"); fileopen.addChoosableFileFilter(filter); int ret = fileopen.showDialog(null, "Open file"); if (ret == JFileChooser.APPROVE_OPTION) { File file = fileopen.getSelectedFile(); System.out.println(file); textfieldPoleTekstowe.setText("" + file); } }
private void showOpenFileDialog1() { JFileChooser fileChooser1 = new JFileChooser(); fileChooser1.setCurrentDirectory(new File(System.getProperty("user.home"))); fileChooser1.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser1.addChoosableFileFilter( new FileNameExtensionFilter("Microsoft Excel Documents", "xlsx", ".xls")); fileChooser1.setAcceptAllFileFilterUsed(true); int result1 = fileChooser1.showSaveDialog(this); if (result1 == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser1.getSelectedFile(); textField_1.setText(selectedFile.getAbsolutePath()); } }
public ScaleMainFrame() { super(new BorderLayout()); nameTF = new JTextField(); JPanel top = new JPanel(new BorderLayout()); top.add(new JLabel("Scale Name:"), BorderLayout.WEST); top.add(nameTF, BorderLayout.CENTER); PlayButton pb = new PlayButton("PLAY"); tempoP = new IntSetPanel(1, 10000, "Tempo"); tempoP.setValue(120); JPanel botL = new JPanel(new BorderLayout()); botL.add(pb, BorderLayout.EAST); botL.add(tempoP, BorderLayout.CENTER); PianoKeyB kb = new PianoKeyB(); kb.setPreferredSize(new Dimension(150, 40)); // JPanel botTop = new JPanel(new GridLayout(1, 2)); JPanel botTop = new JPanel(new FlowLayout()); botTop.add(botL); botTop.add(kb); JButton newB = new JButton("New"); saveB = new JButton("Save"); JButton loadB = new JButton("Load"); newB.addActionListener(this); saveB.addActionListener(this); loadB.addActionListener(this); pb.addActionListener(this); JPanel botBot = new JPanel(new GridLayout(1, 3)); botBot.add(newB); botBot.add(saveB); botBot.add(loadB); JPanel bottom = new JPanel(new BorderLayout()); bottom.add(botTop, BorderLayout.CENTER); bottom.add(botBot, BorderLayout.SOUTH); sp = new ScalePanel(this, kb); add(top, BorderLayout.NORTH); add(sp, BorderLayout.CENTER); add(bottom, BorderLayout.SOUTH); setPreferredSize(new Dimension(500, 300)); fileChooser = new JFileChooser(new File("Features/Scales")); filter = new ScaleFilter(); fileChooser.addChoosableFileFilter(filter); fileChooser.setFileFilter(filter); }
// creates a file open dialog. If you don't cancel it opens that file. public void OpenFileDialog() { // Note: source for ExampleFileFilter can be found in FileChooserDemo, // under the demo/jfc directory in the Java 2 SDK, Standard Edition. String filename = (recentFiles[0].length() > 0) ? filename = recentFiles[0] : ""; FileFilter filterImage = new FileNameExtensionFilter( "Images (jpg/bmp/png/gif)", "jpg", "jpeg", "png", "wbmp", "bmp", "gif"); FileFilter filterGCODE = new FileNameExtensionFilter("GCODE files (ngc)", "ngc"); JFileChooser fc = new JFileChooser(new File(filename)); fc.addChoosableFileFilter(filterImage); fc.addChoosableFileFilter(filterGCODE); if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { OpenFileOnDemand(fc.getSelectedFile().getAbsolutePath()); } }
private void openFile() { // opens a single file chooser (can select multiple), does not traverse folders. this.copyList = new ArrayList(); final JFileChooser fc = new JFileChooser(currentPath); fc.setMultiSelectionEnabled(true); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); FileNameExtensionFilter filterhtml = new FileNameExtensionFilter("HTML File (.html)", "html"); fc.addChoosableFileFilter(filterhtml); fc.setFileFilter(filterhtml); int result = fc.showOpenDialog(FrontEnd.this); dir = fc.getCurrentDirectory(); dirImp = dir.toString(); switch (result) { case JFileChooser.APPROVE_OPTION: for (File file1 : fc.getSelectedFiles()) { fileImp = file1.toString(); boolean exists = false; for (int i = 0; i < table.getRowCount(); i++) { dir = fc.getCurrentDirectory(); dirImp = dir.toString(); String copyC = dtm.getValueAt(i, 0).toString(); if (duplC.isSelected()) { if (fileImp.endsWith(copyC)) { exists = true; break; } } } if (!exists) { addRow(); dtm.setValueAt(fileImp.substring(67), curRow, 0); dtm.setValueAt(dirImp.substring(67), curRow, 1); curRow++; if (headC == 1) { if (fileImp.substring(67).endsWith(dirImp.substring(67) + ".html")) { curRow--; dtm.removeRow(curRow); } } } } case JFileChooser.CANCEL_OPTION: break; } }
{ fc.addChoosableFileFilter( new FileFilter() { public String getDescription() { return "MP3 music files (*.mp3)"; } public boolean accept(File f) { if (f.isDirectory()) { return true; } else { return f.getName().toLowerCase().endsWith(".mp3"); } } }); fc.setAcceptAllFileFilterUsed(false); }
private void openBin() { fileChooser.resetChoosableFileFilters(); fileChooser.addChoosableFileFilter(binFilter); fileChooser.setFileFilter(binFilter); if (fileChooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) { try { FileInputStream inbinf = new FileInputStream(fileChooser.getSelectedFile()); int len = inbinf.available(); if (len % 2 == 1) throw new IOException(String.format("Odd file size (0x%x)\n", len)); len /= 2; if (len > 0x10000) throw new IOException(String.format("Too large file (0x%x)\n", len)); binary = new char[len]; for (int i = 0; i < len; i++) { int lo = inbinf.read(); int hi = inbinf.read(); if (lo == -1 || hi == -1) throw new IOException("Unable to read\n"); binary[i] = (char) ((hi << 8) | lo); } asmMap = new AsmMap(); Disassembler dasm = new Disassembler(); dasm.init(binary); // TODO attach asmmap StringBuilder sb = new StringBuilder(); while (dasm.getAddress() < binary.length) { int addr = dasm.getAddress(); sb.append(String.format("%-26s ; [%04x] =", dasm.next(true), addr)); int addr2 = dasm.getAddress(); while (addr < addr2) { char i = binary[addr++]; sb.append( String.format(" %04x '%s'", (int) i, (i >= 0x20 && i < 0x7f) ? (char) i : '.')); } sb.append("\n"); } srcBreakpoints.clear(); sourceRowHeader.breakpointsChanged(); sourceTextarea.setText(sb.toString()); } catch (IOException e1) { JOptionPane.showMessageDialog( frame, "Unable to open file: %s" + e1.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); e1.printStackTrace(); } } }
private void openSrc() { fileChooser.resetChoosableFileFilters(); fileChooser.addChoosableFileFilter(asmFilter); fileChooser.setFileFilter(asmFilter); if (fileChooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) { try { FileInputStream input = new FileInputStream(fileChooser.getSelectedFile()); char[] csources = new char[input.available()]; new InputStreamReader(input).read(csources, 0, csources.length); srcBreakpoints.clear(); sourceRowHeader.breakpointsChanged(); sourceTextarea.setText(new String(csources)); asmMap = new AsmMap(); binary = new char[0]; } catch (IOException e1) { JOptionPane.showMessageDialog( frame, "Unable to open file", "Error", JOptionPane.ERROR_MESSAGE); e1.printStackTrace(); } } }
/** * Shows a file-open selection dialog for the given working directory. * * @param aOwner the owning window to show the dialog in; * @param aCurrentDirectory the working directory to start the dialog in, can be <code>null</code> * . * @return the selected file, or <code>null</code> if the user aborted the dialog. */ public static final File showFileOpenDialog( final Window aOwner, final String aCurrentDirectory, final javax.swing.filechooser.FileFilter... aFileFilters) { if (HostUtils.isMacOS()) { final FileDialog dialog; if (aOwner instanceof Dialog) { dialog = new FileDialog((Dialog) aOwner, "Open file", FileDialog.LOAD); } else { dialog = new FileDialog((Frame) aOwner, "Open file", FileDialog.LOAD); } dialog.setDirectory(aCurrentDirectory); if ((aFileFilters != null) && (aFileFilters.length > 0)) { dialog.setFilenameFilter(new FilenameFilterAdapter(aFileFilters)); } try { dialog.setVisible(true); final String selectedFile = dialog.getFile(); return selectedFile == null ? null : new File(dialog.getDirectory(), selectedFile); } finally { dialog.dispose(); } } else { final JFileChooser dialog = new JFileChooser(); dialog.setCurrentDirectory((aCurrentDirectory == null) ? null : new File(aCurrentDirectory)); for (javax.swing.filechooser.FileFilter filter : aFileFilters) { dialog.addChoosableFileFilter(filter); } File result = null; if (dialog.showOpenDialog(aOwner) == JFileChooser.APPROVE_OPTION) { result = dialog.getSelectedFile(); } return result; } }
@Override public void actionPerformed(ActionEvent arg0) { // Get the file JFileChooser fc = new JFileChooser(Driver.prefs.get("save_location", "")); File f; FileNameExtensionFilter filter = new FileNameExtensionFilter("JPokemon Files", "jpkmn"); fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.addChoosableFileFilter(filter); if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { f = fc.getSelectedFile(); try { // Make sure the file is of type .jpkmn if (!f.getName() .substring(f.getName().lastIndexOf('.'), f.getName().length()) .equalsIgnoreCase(".jpkmn")) { showFatalErrorMessage("not type .jpkmn"); } // Store the default save location Driver.prefs.put("save_location", f.getAbsolutePath()); Driver.prefs.flush(); // Load game Scanner scan = new Scanner(f); player = Player.fromFile(scan); splash.dispose(); new GameWindow(player); } catch (Exception e) { e.printStackTrace(); showFatalErrorMessage("General Error"); } } // End if }
@Override void mergeTiffs() { JFileChooser jf = new JFileChooser(); jf.setDialogTitle(bundle.getString("Select") + " Input Images"); jf.setCurrentDirectory(imageFolder); jf.setMultiSelectionEnabled(true); FileFilter tiffFilter = new SimpleFilter("tif;tiff", "TIFF"); FileFilter jpegFilter = new SimpleFilter("jpg;jpeg", "JPEG"); FileFilter gifFilter = new SimpleFilter("gif", "GIF"); FileFilter pngFilter = new SimpleFilter("png", "PNG"); FileFilter bmpFilter = new SimpleFilter("bmp", "Bitmap"); FileFilter allImageFilter = new SimpleFilter("tif;tiff;jpg;jpeg;gif;png;bmp", "All Image Files"); jf.addChoosableFileFilter(tiffFilter); jf.addChoosableFileFilter(jpegFilter); jf.addChoosableFileFilter(gifFilter); jf.addChoosableFileFilter(pngFilter); jf.addChoosableFileFilter(bmpFilter); jf.addChoosableFileFilter(allImageFilter); if (selectedFilter != null) { jf.setFileFilter(selectedFilter); } jf.setAcceptAllFileFilterUsed(false); if (jf.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { selectedFilter = jf.getFileFilter(); final File[] inputs = jf.getSelectedFiles(); imageFolder = jf.getCurrentDirectory(); jf = new JFileChooser(); jf.setDialogTitle(bundle.getString("Save") + " Multi-page TIFF Image"); jf.setCurrentDirectory(imageFolder); jf.setFileFilter(tiffFilter); jf.setAcceptAllFileFilterUsed(false); if (jf.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { File selectedFile = jf.getSelectedFile(); if (!(selectedFile.getName().endsWith(".tif") || selectedFile.getName().endsWith(".tiff"))) { selectedFile = new File(selectedFile.getParent(), selectedFile.getName() + ".tif"); } final File outputTiff = selectedFile; if (outputTiff.exists()) { outputTiff.delete(); } jLabelStatus.setText(bundle.getString("Merge_running...")); jProgressBar1.setIndeterminate(true); jProgressBar1.setString(bundle.getString("Merge_running...")); jProgressBar1.setVisible(true); getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); getGlassPane().setVisible(true); SwingWorker worker = new SwingWorker<File, Void>() { @Override protected File doInBackground() throws Exception { ImageIOHelper.mergeTiff(inputs, outputTiff); return outputTiff; } @Override protected void done() { jLabelStatus.setText(bundle.getString("Mergecompleted")); jProgressBar1.setIndeterminate(false); jProgressBar1.setString(bundle.getString("Mergecompleted")); try { File result = get(); JOptionPane.showMessageDialog( GuiWithTools.this, bundle.getString("Mergecompleted") + result.getName() + bundle.getString("created"), APP_NAME, JOptionPane.INFORMATION_MESSAGE); } catch (InterruptedException ignore) { ignore.printStackTrace(); } catch (java.util.concurrent.ExecutionException e) { String why = null; Throwable cause = e.getCause(); if (cause != null) { if (cause instanceof OutOfMemoryError) { why = bundle.getString("OutOfMemoryError"); } else { why = cause.getMessage(); } } else { why = e.getMessage(); } e.printStackTrace(); JOptionPane.showMessageDialog( GuiWithTools.this, why, APP_NAME, JOptionPane.ERROR_MESSAGE); } finally { jProgressBar1.setVisible(false); getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); getGlassPane().setVisible(false); } } }; worker.execute(); } } }
/** Show the open dialog and open the INP/XLSX and XML files. */ private void openEvent() { if (fileChooser == null) { // fileChooser = new FileDialog(frame); fileChooser = new JFileChooser(System.getProperty("user.dir")); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setAcceptAllFileFilterUsed(false); fileChooser.addChoosableFileFilter(new XLSXFilter()); fileChooser.addChoosableFileFilter(new XMLFilter()); fileChooser.addChoosableFileFilter(new MSXFilter()); fileChooser.addChoosableFileFilter(new INPFilter()); fileChooser.addChoosableFileFilter(new AllSuportedFilesFilter()); } if (fileChooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) { File netFile = fileChooser.getSelectedFile(); String fileExtension = Utilities.getFileExtension(netFile.getName()); if (fileExtension.equals("xlsx") || fileExtension.equals("inp") || fileExtension.equals("xml")) { inpFile = netFile; msxFile = null; msxName.setText(""); Network.FileType netType = Network.FileType.INP_FILE; if (fileExtension.equals("xlsx")) netType = Network.FileType.EXCEL_FILE; else if (fileExtension.equals("xml")) { netType = Network.FileType.XML_FILE; JOptionPane.showMessageDialog( frame, "Not supported yet !", "Error", JOptionPane.OK_OPTION); return; } epanetNetwork = new Network(); InputParser inpParser = InputParser.create(netType, log); try { inpParser.parse(epanetNetwork, inpFile); } catch (ENException en_ex) { JOptionPane.showMessageDialog( frame, en_ex.toString() + "\nCheck epanet.log for detailed error description", "Error", JOptionPane.OK_OPTION); clearInterface(); inpFile = null; return; } catch (Exception egen) { JOptionPane.showMessageDialog( frame, "Unable to parse network configuration file", "Error", JOptionPane.OK_OPTION); log.log(ENLevels.ERROR, "openEvent", egen); clearInterface(); inpFile = null; return; } int resrvCount = 0; int tanksCount = 0; for (Tank tank : epanetNetwork.getTanks()) if (tank.getArea() == 0.0) resrvCount++; else tanksCount++; textReservoirs.setText(Integer.toString(resrvCount)); textTanks.setText(Integer.toString(tanksCount)); textPipes.setText(Integer.toString(epanetNetwork.getLinks().size())); textNodes.setText(Integer.toString(epanetNetwork.getNodes().size())); try { textDuration.setText( Utilities.getClockTime(epanetNetwork.getPropertiesMap().getDuration())); textUnits.setText(epanetNetwork.getPropertiesMap().getUnitsflag().name()); textHeadloss.setText(epanetNetwork.getPropertiesMap().getFormflag().name()); textQuality.setText(epanetNetwork.getPropertiesMap().getQualflag().name()); textDemand.setText(epanetNetwork.getPropertiesMap().getDmult().toString()); textHydraulic.setText( Utilities.getClockTime(epanetNetwork.getPropertiesMap().getHstep())); textPattern.setText(Utilities.getClockTime(epanetNetwork.getPropertiesMap().getPstep())); } catch (ENException ex) { } frame.setTitle(APP_TITTLE + inpFile.getName()); inpName.setText(inpFile.getName()); runSimulationButton.setEnabled(true); saveButton.setEnabled(true); reportOptions = null; } else if (fileExtension.equals("msx")) { if (inpFile == null) { JOptionPane.showMessageDialog( frame, "Load an INP or XLSX file with network configuration before opening the MSX file.", "Error", JOptionPane.OK_OPTION); return; } msxFile = netFile; msxName.setText(fileChooser.getSelectedFile().getName()); // fileChooser.getFile()); reportOptions = null; } saveAction.setEnabled(true); runAction.setEnabled(true); } }
public void takeScreenshot(boolean flag) { BufferedImage bufferedimage; try { Robot robot = new Robot(); Point point = getLocationOnScreen(); Rectangle rectangle = new Rectangle(point.x, point.y, getWidth(), getHeight()); bufferedimage = robot.createScreenCapture(rectangle); } catch (Throwable throwable) { JOptionPane.showMessageDialog( frame, "An error occured while trying to create a screenshot!", "Screenshot Error", 0); return; } String s = null; try { s = getNearestScreenshotFilename(); } catch (IOException ioexception) { if (flag) { JOptionPane.showMessageDialog( frame, "A screenshot directory does not exist, and could not be created!", "No Screenshot Directory", 0); return; } } if (s == null && flag) { JOptionPane.showMessageDialog( frame, "There are too many screenshots in the screenshot directory!\n" + "Delete some screen\n" + "shots and try again.", "Screenshot Directory Full", 0); return; } if (!flag) { final JFileChooser fileChooser = new JFileChooser(); final JDialog fileDialog = createFileChooserDialog(fileChooser, "Save Screenshot", this); final BufferedImage si = bufferedimage; JFileChooser _tmp = fileChooser; fileChooser.setFileSelectionMode(0); fileChooser.addChoosableFileFilter(new imageFileFilter()); fileChooser.setCurrentDirectory(new File("C:/.hack3rClient/Scre/")); fileChooser.setSelectedFile(new File(s)); JFileChooser _tmp1 = fileChooser; fileChooser.setDialogType(1); fileChooser.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent actionevent) { String s1 = actionevent.getActionCommand(); if (s1.equals("ApproveSelection")) { File file = fileChooser.getSelectedFile(); if (file != null && file.isFile()) { int i = JOptionPane.showConfirmDialog( frame, (new StringBuilder()) .append(file.getAbsolutePath()) .append(" already exists.\n" + "Do you want to replace it?") .toString(), "Save Screenshot", 2); if (i != 0) { return; } } try { ImageIO.write(si, "png", file); // client.pushMessage("Screenshot taken.", 3, "@cr2@ Client"); // JOptionPane.showMessageDialog(frame,"Screenshot Taken"); } catch (IOException ioexception2) { JOptionPane.showMessageDialog( frame, "An error occured while trying to save the screenshot!\n" + "Please make sure you have\n" + " write access to the screenshot directory.", "Screenshot Error", 0); } fileDialog.dispose(); } else if (s1.equals("CancelSelection")) { fileDialog.dispose(); } } { } }); fileDialog.setVisible(true); } else { try { ImageIO.write( bufferedimage, "png", new File((new StringBuilder()).append("C:/.hack3rClient/Scre/").append(s).toString())); JOptionPane.showMessageDialog( frame, "Image has been saved to C:/.hack3rclient/Scre. You can view your images by pushing File>View Images in the menu dropdowns.", "Screenshot manager", JOptionPane.INFORMATION_MESSAGE); // client.pushMessage("Screenshot taken.", 3, "@cr2@ Client"); // JOptionPane.showMessageDialog(frame,"Screenshot taken."); } catch (IOException ioexception1) { JOptionPane.showMessageDialog( frame, "An error occured while trying to save the screenshot!\n" + "Please make sure you have\n" + " write access to the screenshot directory.", "Screenshot Error", 0); } } }
public AutoFocusator() { super(new BorderLayout()); taskList = new TaskList(); Task task0 = new Task("Use right click to change the states of the tasks."); taskList.add(task0); Task task1 = new Task("Just play araound with this small app."); taskList.add(task1); Task task2 = new Task("Check http://sourceforge.net/projects/autofocusator/"); taskList.add(task2); // task1.setState(State.crossed); // task0.setState(State.dismissed); table = new JTable(taskList); table.setPreferredScrollableViewportSize(new Dimension(500, 700)); table.setFillsViewportHeight(true); table.getColumnModel().getColumn(0).setPreferredWidth(300); table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); table.setRowSelectionAllowed(true); table.getColumnModel().getColumn(0).setCellRenderer(new TaskRenderer()); // TableCellRenderer renderer = table.getColumnModel().getColumn(0).getCellRenderer(); // double height = ((TaskRenderer)renderer).getRendererHeight(); // @todo: The height should be set dependent on the content table.setRowHeight(28); table.getModel().addTableModelListener(this); toolBar = new JToolBar("Autofocusator - Toolbar"); JButton buttonAddTask = new JButton("Add a Task", new ImageIcon(loadPics("res/list-add.png"))); buttonAddTask.setActionCommand("addTask"); buttonAddTask.addActionListener(this); toolBar.add(buttonAddTask); JButton buttonDeleteTask = new JButton("Delete a Task", new ImageIcon(loadPics("res/list-remove.png"))); buttonDeleteTask.setActionCommand("deleteTask"); buttonDeleteTask.addActionListener(this); toolBar.add(buttonDeleteTask); JButton buttonSave = new JButton("Save", new ImageIcon(loadPics("res/document-save-as.png"))); buttonSave.setActionCommand("save"); buttonSave.addActionListener(this); toolBar.add(buttonSave); JButton buttonOpen = new JButton("open", new ImageIcon(loadPics("res/document-open.png"))); buttonOpen.setActionCommand("open"); buttonOpen.addActionListener(this); toolBar.add(buttonOpen); add(toolBar, BorderLayout.NORTH); contextMenu = new JPopupMenu(); JMenuItem contextMenuItem; contextMenuItem = new JMenuItem("delete Task"); contextMenuItem.addActionListener(this); contextMenuItem.setActionCommand("deleteTask"); contextMenu.add(contextMenuItem); contextMenuItem = new JMenuItem("add Task"); contextMenuItem.addActionListener(this); contextMenuItem.setActionCommand("addTask"); contextMenu.add(contextMenuItem); contextMenu.addSeparator(); contextMenuItem = new JMenuItem("cross"); contextMenuItem.addActionListener(this); contextMenuItem.setActionCommand("cross"); contextMenu.add(contextMenuItem); contextMenuItem = new JMenuItem("dismiss"); contextMenuItem.addActionListener(this); contextMenuItem.setActionCommand("dismiss"); contextMenu.add(contextMenuItem); contextMenuItem = new JMenuItem("worked on"); contextMenuItem.addActionListener(this); contextMenuItem.setActionCommand("workedOn"); contextMenu.add(contextMenuItem); fileChooser = new JFileChooser(); FileFilter filter = new FileNameExtensionFilter("XML File", "xml"); fileChooser.addChoosableFileFilter(filter); table.addMouseListener(this); JScrollPane scrollPane = new JScrollPane(table); add(scrollPane, BorderLayout.CENTER); }