protected void fileOpened(final DocumentView documentView, File file, Object value) { final DocumentOrientedApplication application = getApplication(); if (value == null) { documentView.setFile(file); documentView.setEnabled(true); Frame w = (Frame) SwingUtilities.getWindowAncestor(documentView.getComponent()); if (w != null) { w.setExtendedState(w.getExtendedState() & ~Frame.ICONIFIED); w.toFront(); } documentView.getComponent().requestFocus(); application.addRecentFile(file); application.setEnabled(true); } else { if (value instanceof Throwable) { ((Throwable) value).printStackTrace(); } JSheet.showMessageSheet( documentView.getComponent(), "<html>" + UIManager.getString("OptionPane.css") + "<b>Couldn't open the file \"" + file + "\".</b><br>" + value, JOptionPane.ERROR_MESSAGE, new SheetListener() { public void optionSelected(SheetEvent evt) { // application.dispose(documentView); } }); } }
public void doIt(DocumentView documentView) { JFileChooser fileChooser = documentView.getOpenChooser(); if (fileChooser.showOpenDialog(documentView.getComponent()) == JFileChooser.APPROVE_OPTION) { openFile(documentView, fileChooser); } else { documentView.setEnabled(true); } }
public void actionPerformed(ActionEvent evt) { final DocumentOrientedApplication application = getApplication(); if (application.isEnabled()) { application.setEnabled(false); // Search for an empty documentView DocumentView emptyProject = application.getCurrentView(); if (emptyProject == null || emptyProject.getFile() != null || emptyProject.isModified()) { emptyProject = null; /* for (DocumentView aProject : application.getViews()) { if (aProject.getFile() == null && ! aProject.isModified()) { emptyProject = aProject; break; } }*/ } final DocumentView p; boolean removeMe; if (emptyProject == null) { p = application.createView(); application.add(p); removeMe = true; removeMe = true; } else { p = emptyProject; removeMe = false; } JFileChooser fileChooser = p.getOpenChooser(); if (fileChooser.showOpenDialog(application.getComponent()) == JFileChooser.APPROVE_OPTION) { application.show(p); openFile(fileChooser, p); } else { if (removeMe) { application.remove(p); } application.setEnabled(true); } } }
protected void openFile(final DocumentView documentView, JFileChooser fileChooser) { final File file = fileChooser.getSelectedFile(); documentView.setEnabled(false); // Open the file documentView.execute( new Worker() { public Object construct() { try { documentView.read(file); return null; } catch (IOException e) { return e; } } public void finished(Object value) { fileOpened(documentView, file, value); } }); }
protected void openFile(JFileChooser fileChooser, final DocumentView documentView) { final DocumentOrientedApplication application = getApplication(); final File file = fileChooser.getSelectedFile(); application.setEnabled(true); documentView.setEnabled(false); // Open the file documentView.execute( new Worker() { public Object construct() { try { documentView.read(file); return null; } catch (Throwable e) { return e; } } public void finished(Object value) { fileOpened(documentView, file, value); } }); }
protected void fileOpened(final DocumentView documentView, File file, Object value) { if (value == null) { documentView.setFile(file); documentView.setEnabled(true); getApplication().addRecentFile(file); } else { JSheet.showMessageSheet( documentView.getComponent(), "<html>" + UIManager.getString("OptionPane.css") + "<b>Couldn't open the file \"" + file + "\".</b><br>" + value, JOptionPane.ERROR_MESSAGE, new SheetListener() { public void optionSelected(SheetEvent evt) { documentView.execute( new Worker() { public Object construct() { try { documentView.clear(); return null; } catch (IOException ex) { return ex; } } public void finished(Object result) { documentView.setEnabled(true); } }); } }); } }