List of usage examples for java.awt Desktop getDesktop
public static synchronized Desktop getDesktop()
From source file:com.enderville.enderinstaller.ui.Installer.java
@Override public void hyperlinkUpdate(final HyperlinkEvent e) { if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) { return;//from w w w .ja v a 2 s .com } SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() { @Override protected Object doInBackground() throws Exception { try { String url = e.getURL().toExternalForm(); Desktop.getDesktop().browse(URI.create(url)); } catch (Exception e) { e.printStackTrace(); } return null; } }; worker.execute(); }
From source file:com.ejie.uda.jsonI18nEditor.Editor.java
public void showVersionDialog() { GithubReleaseData data = GithubRepoUtils.getLatestRelease(GITHUB_REPO); String content = ""; if (data != null && !VERSION.equals(data.getTagName())) { content = MessageBundle.get("dialogs.version.new", data.getTagName()) + "<br>" + "<a href=\"" + data.getHtmlUrl() + "\">" + MessageBundle.get("dialogs.version.link") + "</a>"; } else {//w ww .ja va 2s.com content = MessageBundle.get("dialogs.version.uptodate"); } Font font = getFont(); JEditorPane pane = new JEditorPane("text/html", "<html><body style=\"font-family:" + font.getFamily() + ";font-size:" + font.getSize() + "pt;text-align:center;width:200px;\">" + content + "</body></html>"); pane.addHyperlinkListener(e -> { if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) { try { Desktop.getDesktop().browse(e.getURL().toURI()); } catch (Exception e1) { // } } }); pane.setBackground(getBackground()); pane.setEditable(false); showMessage(MessageBundle.get("dialogs.version.title"), pane); }
From source file:com.jvms.i18neditor.editor.Editor.java
public void openProjectDirectory() { if (project == null) return;/*w w w.ja va2 s .co m*/ try { Desktop.getDesktop().open(project.getPath().toFile()); } catch (IOException ex) { log.error("Unable to open project directory " + project.getPath(), ex); } }
From source file:output.ExcelM3Upgrad.java
public boolean save() { dialStatus();/*from ww w . j av a 2 s .c o m*/ try { if (workbook instanceof HSSFWorkbook) { if (!filepath.endsWith("xls")) { filepath += ".xls"; } } else if (workbook instanceof XSSFWorkbook) { if (!filepath.endsWith("xlsx")) { filepath += ".xlsx"; } } busyDial.setText("Sauvegarde du fichier " + filepath); FileOutputStream out = new FileOutputStream(new File(filepath)); workbook.write(out); out.close(); if (endFile) { Object[] options = { i18n.Language.getLabel(140), i18n.Language.getLabel(23), i18n.Language.getLabel(130) }; int n = JOptionPane.showOptionDialog(busyDial, i18n.Language.getLabel(213), "Excel", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == 0) { busyDial.setText(i18n.Language.getLabel(214) + "..."); Desktop dt = Desktop.getDesktop(); dt.open(new File(filepath)); } else if (n == 1) { try { busyDial.setText(i18n.Language.getLabel(215) + "..."); GmailTLS mail = new GmailTLS(); Message msg = mail.writeMail("j.chaut@3kles-consulting.com", "M3Upgrader", "Rsultat de M3Upgrader"); msg = mail.addAttachment(msg, new File(filepath)); busyDial.setText(i18n.Language.getLabel(216) + "..."); mail.sendMail(msg); } catch (MessagingException ex) { Ressource.logger.error(ex.getLocalizedMessage(), ex); } } in.close(); } } catch (IOException e) { error(e.getMessage()); return false; } return true; }
From source file:gdt.jgui.entity.folder.JFolderPanel.java
/** * Get the context menu.// w w w .j a v a 2 s. com * @return the context menu. */ @Override public JMenu getContextMenu() { menu = super.getContextMenu(); mia = null; int cnt = menu.getItemCount(); if (cnt > 0) { mia = new JMenuItem[cnt]; for (int i = 0; i < cnt; i++) mia[i] = menu.getItem(i); } menu.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { //System.out.println("EntitiesPanel:getConextMenu:menu selected"); menu.removeAll(); if (mia != null) { for (JMenuItem mi : mia) menu.add(mi); menu.addSeparator(); } JMenuItem refreshItem = new JMenuItem("Refresh"); refreshItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JConsoleHandler.execute(console, locator$); } }); menu.add(refreshItem); JMenuItem openItem = new JMenuItem("Open folder"); openItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { File folder = new File(entihome$ + "/" + entityKey$); if (!folder.exists()) folder.mkdir(); Desktop.getDesktop().open(folder); } catch (Exception ee) { LOGGER.severe(ee.toString()); } } }); menu.add(openItem); JMenuItem importItem = new JMenuItem("Import"); importItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { File home = new File(System.getProperty("user.home")); Desktop.getDesktop().open(home); } catch (Exception ee) { LOGGER.severe(ee.toString()); } } }); menu.add(importItem); JMenuItem newItem = new JMenuItem("New text"); newItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { JTextEditor textEditor = new JTextEditor(); String teLocator$ = textEditor.getLocator(); teLocator$ = Locator.append(teLocator$, Entigrator.ENTIHOME, entihome$); String text$ = "New" + Identity.key().substring(0, 4) + ".txt"; teLocator$ = Locator.append(teLocator$, JTextEditor.TEXT, text$); JFolderPanel fp = new JFolderPanel(); String fpLocator$ = fp.getLocator(); fpLocator$ = Locator.append(fpLocator$, Entigrator.ENTIHOME, entihome$); fpLocator$ = Locator.append(fpLocator$, EntityHandler.ENTITY_KEY, entityKey$); fpLocator$ = Locator.append(fpLocator$, BaseHandler.HANDLER_METHOD, "response"); fpLocator$ = Locator.append(fpLocator$, JRequester.REQUESTER_ACTION, ACTION_CREATE_FILE); String requesterResponseLocator$ = Locator.compressText(fpLocator$); teLocator$ = Locator.append(teLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR, requesterResponseLocator$); JConsoleHandler.execute(console, teLocator$); } catch (Exception ee) { LOGGER.severe(ee.toString()); } } }); menu.add(newItem); //menu.addSeparator(); if (hasToInsert()) { menu.addSeparator(); JMenuItem insertItem = new JMenuItem("Insert"); insertItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable clipboardContents = systemClipboard.getContents(null); if (clipboardContents == null) return; Object transferData = clipboardContents .getTransferData(DataFlavor.javaFileListFlavor); List<File> files = (List<File>) transferData; for (int i = 0; i < files.size(); i++) { File file = (File) files.get(i); if (file.exists() && file.isFile()) { System.out.println("FolderPanel:insert:in=" + file.getPath()); File dir = new File(entihome$ + "/" + entityKey$); if (!dir.exists()) dir.mkdir(); File out = new File(entihome$ + "/" + entityKey$ + "/" + file.getName()); if (!out.exists()) out.createNewFile(); System.out.println("FolderPanel:insert:out=" + out.getPath()); FileExpert.copyFile(file, out); JConsoleHandler.execute(console, getLocator()); } // System.out.println("FolderPanel:import:file="+file.getPath()); } } catch (Exception ee) { LOGGER.severe(ee.toString()); } } }); menu.add(insertItem); } if (hasToPaste()) { menu.addSeparator(); JMenuItem pasteItem = new JMenuItem("Paste"); pasteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String[] sa = console.clipboard.getContent(); Properties locator; String file$; File file; File target; String dir$ = entihome$ + "/" + entityKey$; File dir = new File(dir$); if (!dir.exists()) dir.mkdir(); for (String aSa : sa) { try { locator = Locator.toProperties(aSa); if (LOCATOR_TYPE_FILE.equals(locator.getProperty(Locator.LOCATOR_TYPE))) { file$ = locator.getProperty(FILE_PATH); file = new File(file$); target = new File(dir$ + "/" + file.getName()); if (!target.exists()) target.createNewFile(); FileExpert.copyFile(file, target); } } catch (Exception ee) { LOGGER.info(ee.toString()); } } JConsoleHandler.execute(console, locator$); } }); menu.add(pasteItem); } if (hasSelectedItems()) { menu.addSeparator(); JMenuItem deleteItem = new JMenuItem("Delete"); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { String[] sa = JFolderPanel.this.listSelectedItems(); if (sa == null) return; Properties locator; String file$; File file; for (String aSa : sa) { locator = Locator.toProperties(aSa); file$ = locator.getProperty(FILE_PATH); file = new File(file$); try { if (file.isDirectory()) FileExpert.clear(file$); file.delete(); } catch (Exception ee) { LOGGER.info(ee.toString()); } } } JConsoleHandler.execute(console, locator$); } }); menu.add(deleteItem); JMenuItem copyItem = new JMenuItem("Copy"); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String[] sa = JFolderPanel.this.listSelectedItems(); console.clipboard.clear(); if (sa != null) for (String aSa : sa) console.clipboard.putString(aSa); } }); menu.add(copyItem); JMenuItem exportItem = new JMenuItem("Export"); exportItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { String[] sa = JFolderPanel.this.listSelectedItems(); Properties locator; String file$; File file; ArrayList<File> fileList = new ArrayList<File>(); for (String aSa : sa) { try { locator = Locator.toProperties(aSa); file$ = locator.getProperty(FILE_PATH); file = new File(file$); fileList.add(file); } catch (Exception ee) { LOGGER.severe(ee.toString()); } } File[] fa = fileList.toArray(new File[0]); if (fa.length < 1) return; // System.out.println("Folderpanel:finish:list="+fa.length); JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(System.getProperty("user.home"))); chooser.setDialogTitle("Export files"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showSaveDialog(JFolderPanel.this) == JFileChooser.APPROVE_OPTION) { String dir$ = chooser.getSelectedFile().getPath(); File target; for (File f : fa) { target = new File(dir$ + "/" + f.getName()); if (!target.exists()) target.createNewFile(); FileExpert.copyFile(f, target); } } else { Logger.getLogger(JMainConsole.class.getName()).info(" no selection"); } // System.out.println("Folderpanel:finish:list="+fileList.size()); } catch (Exception eee) { LOGGER.severe(eee.toString()); } } }); menu.add(exportItem); } } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); return menu; }
From source file:entity.files.SYSFilesTools.java
/** * Diese Methode ermittelt zu einer gebenen Datei und einer gewnschten Aktion das passende Anzeigeprogramm. * Falls die Desktop API nicht passendes hat, werdne die lokal definierten Anzeigeprogramme verwendet. * <p>/*from w w w . j a v a 2 s. c o m*/ * Bei Linux mssen dafr unbedingt die Gnome Libraries installiert sein. * apt-get install libgnome2-0 * * @param file * @param action */ public static void handleFile(File file, java.awt.Desktop.Action action) { if (file == null) { return; } Desktop desktop = null; if (getLocalDefinedApp(file) != null) { try { Runtime.getRuntime().exec(getLocalDefinedApp(file)); } catch (IOException ex) { OPDE.getLogger().error(ex); } } else { if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); if (action == Desktop.Action.OPEN && desktop.isSupported(Desktop.Action.OPEN)) { try { desktop.open(file); } catch (IOException ex) { OPDE.getDisplayManager().addSubMessage( new DisplayMessage(SYSTools.xx("misc.msg.noviewer"), DisplayMessage.WARNING)); } } else if (action == Desktop.Action.PRINT && desktop.isSupported(Desktop.Action.PRINT)) { try { desktop.print(file); } catch (IOException ex) { OPDE.getDisplayManager().addSubMessage( new DisplayMessage(SYSTools.xx("misc.msg.noprintprog"), DisplayMessage.WARNING)); } } else { OPDE.getDisplayManager().addSubMessage( new DisplayMessage(SYSTools.xx("misc.msg.nofilehandler"), DisplayMessage.WARNING)); } } else { OPDE.getDisplayManager().addSubMessage( new DisplayMessage(SYSTools.xx("misc.msg.nojavadesktop"), DisplayMessage.WARNING)); } } }
From source file:coreferenceresolver.gui.MainGUI.java
private void markupBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_markupBtnActionPerformed JFileChooser inputFileChooser = new JFileChooser(defaulPath); inputFileChooser.setDialogTitle("Choose where your markup file saved"); inputFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (inputFileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { String[] inputFilePath = inputFilePathTF.getText().split("\\\\"); String inputFileName = inputFilePath[inputFilePath.length - 1]; markupFilePathTF.setText(inputFileChooser.getSelectedFile().getAbsolutePath() + File.separator + inputFileName + ".markup"); noteTF.setText("Markup waiting ..."); new Thread(new Runnable() { @Override// ww w .j a v a 2s .com public void run() { try { MarkupMain.markup(inputFilePathTF.getText(), markupFilePathTF.getText()); noteTF.setText("Markup done!"); String folderPathOpen = markupFilePathTF.getText().substring(0, markupFilePathTF.getText().lastIndexOf(File.separatorChar)); Desktop.getDesktop().open(new File(folderPathOpen)); } catch (IOException ex) { Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex); } } }).start(); } else { return; } }
From source file:org.interreg.docexplore.authoring.AuthoringMenu.java
public AuthoringMenu(final AuthoringToolFrame authoringTool) { this.tool = authoringTool; this.recent = new LinkedList<String>(); readRecent();/*from ww w . java 2s . c o m*/ this.file = new JMenu(XMLResourceBundle.getBundledString("generalMenuFile")); add(file); newItem = new JMenuItem(new AbstractAction(XMLResourceBundle.getBundledString("generalMenuNew")) { public void actionPerformed(ActionEvent arg0) { newFile(); } }); loadItem = new JMenuItem(new AbstractAction(XMLResourceBundle.getBundledString("generalMenuLoad")) { public void actionPerformed(ActionEvent arg0) { load(); } }); saveItem = new JMenuItem(new AbstractAction(XMLResourceBundle.getBundledString("generalMenuSave")) { public void actionPerformed(ActionEvent arg0) { save(); } }); saveAsItem = new JMenuItem(new AbstractAction(XMLResourceBundle.getBundledString("generalMenuSaveAs")) { public void actionPerformed(ActionEvent arg0) { saveAs(); } }); exportItem = new JMenuItem( new AbstractAction(XMLResourceBundle.getBundledString("generalMenuExport") + "...") { public void actionPerformed(ActionEvent arg0) { GuiUtils.blockUntilComplete(new ProgressRunnable() { public void run() { try { authoringTool.readerExporter.doExport(authoringTool.editor.link); } catch (Exception ex) { ErrorHandler.defaultHandler.submit(ex); } } public float getProgress() { return (float) authoringTool.readerExporter.progress[0]; } }, authoringTool.editor); } }); webExportItem = new JMenuItem( new AbstractAction(XMLResourceBundle.getBundledString("generalMenuWebExport") + "...") { public void actionPerformed(ActionEvent arg0) { GuiUtils.blockUntilComplete(new ProgressRunnable() { public void run() { try { authoringTool.webExporter.doExport(authoringTool.editor.link); } catch (Exception ex) { ErrorHandler.defaultHandler.submit(ex); } } public float getProgress() { return (authoringTool.webExporter.copyComplete ? .5f : 0f) + (float) (.5 * authoringTool.webExporter.progress[0]); } }, authoringTool.editor); } }); // webExportItem = new JMenuItem(new AbstractAction("Web export") {public void actionPerformed(ActionEvent arg0) // { // GuiUtils.blockUntilComplete(new Runnable() {public void run() // { // try // { // new WebStaticExporter().doExport(authoringTool.editor.link.getBook(authoringTool.editor.link.getLink().getAllBookIds().get(0))); // } // catch (Exception ex) {ErrorHandler.defaultHandler.submit(ex);} // }}, authoringTool.editor); // }}); // webExportItem.setEnabled(false); quitItem = new JMenuItem(new AbstractAction(XMLResourceBundle.getBundledString("generalMenuQuit")) { public void actionPerformed(ActionEvent arg0) { authoringTool.quit(); } }); buildFileMenu(); JMenu edit = new JMenu(XMLResourceBundle.getBundledString("generalMenuEdit")); this.undoItem = new JMenuItem(); undoItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { authoringTool.historyManager.undo(); } catch (Exception ex) { ErrorHandler.defaultHandler.submit(ex); } } }); edit.add(undoItem); this.redoItem = new JMenuItem(); redoItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { authoringTool.historyManager.redo(); } catch (Exception ex) { ErrorHandler.defaultHandler.submit(ex); } } }); edit.add(redoItem); JMenuItem viewHistory = new JMenuItem(XMLResourceBundle.getBundledString("generalMenuEditViewHistory")); viewHistory.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { authoringTool.historyDialog.setVisible(true); } }); edit.add(viewHistory); edit.addSeparator(); edit.add(new JMenuItem(new AbstractAction(XMLResourceBundle.getBundledString("fixChars")) { public void actionPerformed(ActionEvent arg0) { Object res = JOptionPane.showInputDialog(tool, XMLResourceBundle.getBundledString("fixCharsMsg"), XMLResourceBundle.getBundledString("fixChars"), JOptionPane.QUESTION_MESSAGE, null, new Object[] { XMLResourceBundle.getBundledString("fixCharsWin"), XMLResourceBundle.getBundledString("fixCharsMac") }, XMLResourceBundle.getBundledString("fixCharsWin")); if (res == null) return; try { convertPresentation(tool.defaultFile, res.equals(XMLResourceBundle.getBundledString("fixCharsWin")) ? "ISO-8859-1" : "x-MacRoman"); } catch (Exception e) { ErrorHandler.defaultHandler.submit(e); } try { tool.editor.reset(); } catch (Exception e) { e.printStackTrace(); } } })); //TODO: remove! // edit.add(new JMenuItem(new AbstractAction("hack!") // { // public void actionPerformed(ActionEvent e) {try // { // BookEditorView be = null; // for (ExplorerView view : tool.editor.views) // if (view instanceof BookEditorView) // be = (BookEditorView)view; // Book book = be.curBook; // int lastPage = book.getLastPageNumber(); // for (int pageNum = 1;pageNum <= lastPage;pageNum++) // { // Page page = book.getPage(pageNum); // Set<Region> regions = page.getRegions(); // if (regions.size() > 2) // { // Region highest = null; // int max = -1; // for (Region region : regions) // for (Point point : region.getOutline()) // if (max < 0 || point.y < max) // {max = point.y; highest = region;} // Region middle = null; // max = -1; // for (Region region : regions) // if (region != highest) // for (Point point : region.getOutline()) // if (max < 0 || point.y < max) // {max = point.y; middle = region;} // if (regions.size() > 3) // { // max = -1; // Region newMiddle = null; // for (Region region : regions) // if (region != highest && region != middle) // for (Point point : region.getOutline()) // if (max < 0 || point.y < max) // {max = point.y; newMiddle = region;} // middle = newMiddle; // } // MetaDataKey display = book.getLink().getKey("display", ""); // for (Map.Entry<MetaDataKey, List<MetaData>> entry : highest.getMetaData().entrySet()) // for (MetaData md : entry.getValue()) // if (md.getType().equals(MetaData.textType)) // { // String val = "<b>"+md.getString()+"</b>\n"; // for (Map.Entry<MetaDataKey, List<MetaData>> entry2 : middle.getMetaData().entrySet()) // for (MetaData md2 : entry2.getValue()) // if (md2.getType().equals(MetaData.textType) && TextElement.getStyle(md, tool.styleManager) == TextElement.getStyle(md2, tool.styleManager)) // val = val+"\n"+md2.getString(); // md.setString(val); // } // boolean hasImage = false; // for (Map.Entry<MetaDataKey, List<MetaData>> entry2 : middle.getMetaData().entrySet()) // for (MetaData md2 : entry2.getValue()) // if (md2.getType().equals(MetaData.imageType)) // { // MetaData imageMd = new MetaData(book.getLink(), display, md2.getType(), md2.getValue()); // if (!hasImage) // BookImporter.insert(imageMd, highest, 0); // else BookImporter.insert(imageMd, highest, BookImporter.getHighestRank(highest)+1); // hasImage = true; // } // page.removeRegion(middle); // } // } // } // catch (Exception ex) {ex.printStackTrace();}System.out.println("done");} // })); // edit.add(new JMenuItem(new AbstractAction("hack!") // { // public void actionPerformed(ActionEvent e) {try // { // BookEditorView be = null; // for (ExplorerView view : tool.editor.views) // if (view instanceof BookEditorView) // be = (BookEditorView)view; // Book book = be.curBook; // int lastPage = book.getLastPageNumber(); // MetaDataKey display = book.getLink().getKey("display", ""); // for (int pageNum = 1;pageNum <= lastPage;pageNum++) // { // Page page = book.getPage(pageNum); // Set<Region> regions = page.getRegions(); // for (Region region : regions) // { // List<MetaData> mds = region.getMetaDataListForKey(display); // for (MetaData md : mds) // if (md.getType().equals(MetaData.textType)) // { // String val = md.getString().trim(); // if (!val.startsWith("<i>") || !val.endsWith("</i>")) // continue; // TextElement.getStyleMD(md).setString("4"); // md.setString(val.substring(3, val.length()-4)); // System.out.println(md.getString()); // } // } // } // } // catch (Exception ex) {ex.printStackTrace();}System.out.println("done");} // })); // edit.add(new JMenuItem(new AbstractAction("hack!") // { // public void actionPerformed(ActionEvent e) {try // { // BookEditorView be = null; // for (ExplorerView view : tool.editor.views) // if (view instanceof BookEditorView) // be = (BookEditorView)view; // Book book = be.curBook; // int lastPage = book.getLastPageNumber(); // MetaDataKey display = book.getLink().getKey("display", ""); // for (int pageNum = 1;pageNum <= lastPage;pageNum++) // { // Page page = book.getPage(pageNum); // Set<Region> regions = page.getRegions(); // for (Region region : regions) // { // int max = BookImporter.getHighestRank(region); // for (int i=0;i<max;i++) // { // MetaData md1 = BookImporter.getAtRank(region, i); // if (md1 == null || !md1.getType().equals(MetaData.textType)) // continue; // MetaData style1 = TextElement.getStyleMD(md1); // if (!style1.getString().equals("0")) // continue; // MetaData md2 = BookImporter.getAtRank(region, i+1); // if (md2 == null || !md2.getType().equals(MetaData.textType)) // continue; // MetaData style2 = TextElement.getStyleMD(md2); // if (!style2.getString().equals("1")) // continue; // BookImporter.setRank(md1, i+1); // BookImporter.setRank(md2, i); // i++; // } // } // } // } // catch (Exception ex) {ex.printStackTrace();}System.out.println("done");} // })); // edit.add(new JMenuItem(new AbstractAction("hack!") // { // public void actionPerformed(ActionEvent e) {try // { // BookEditorView be = null; // for (ExplorerView view : tool.editor.views) // if (view instanceof BookEditorView) // be = (BookEditorView)view; // Book book = be.curBook; // MetaDataKey mini = book.getLink().getOrCreateKey("mini", ""); // MetaDataKey dim = book.getLink().getOrCreateKey("dimension", ""); // int lastPage = book.getLastPageNumber(); // for (int pageNum = 1;pageNum <= lastPage;pageNum++) // { // Page page = book.getPage(pageNum); // List<MetaData> mds = page.getMetaDataListForKey(mini); // if (mds != null) // for (MetaData md : mds) // page.removeMetaData(md); // mds = page.getMetaDataListForKey(dim); // if (mds != null) // for (MetaData md : mds) // page.removeMetaData(md); // DocExploreDataLink.getImageDimension(page, true); // DocExploreDataLink.getImageMini(page, false); // } // } // catch (Exception ex) {ex.printStackTrace();}System.out.println("done");} // })); add(edit); JMenu view = new JMenu(XMLResourceBundle.getBundledString("generalMenuView")); add(view); JMenuItem styles = new JMenuItem(XMLResourceBundle.getBundledString("styleEdit") + "...", ImageUtils.getIcon("pencil-24x24.png")); styles.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { authoringTool.styleManager.styleDialog.setVisible(true); } }); view.add(styles); helpToggle = new JCheckBoxMenuItem( new AbstractAction(XMLResourceBundle.getBundledString("viewHelpToggle")) { public void actionPerformed(ActionEvent arg0) { authoringTool.displayHelp = helpToggle.isSelected(); authoringTool.repaint(); } }); helpToggle.setSelected(tool.startup.showHelp); view.add(helpToggle); JMenu helpMenu = new JMenu(XMLResourceBundle.getString("management-lrb", "generalMenuHelp")); if (Desktop.isDesktopSupported()) { final Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.OPEN)) { helpMenu.add(new AbstractAction( XMLResourceBundle.getString("management-lrb", "generalMenuHelpContents")) { public void actionPerformed(ActionEvent e) { try { File doc = new File(DocExploreTool.getExecutableDir(), "MMT documentation.htm"); desktop.open(doc); } catch (Exception ex) { ErrorHandler.defaultHandler.submit(ex, true); } } }); helpMenu.add(new AbstractAction( XMLResourceBundle.getString("management-lrb", "generalMenuHelpWebsite")) { public void actionPerformed(ActionEvent e) { try { File link = new File(DocExploreTool.getExecutableDir(), "website.url"); desktop.open(link); } catch (Exception ex) { ErrorHandler.defaultHandler.submit(ex, true); } } }); } } helpMenu.add(new AbstractAction(XMLResourceBundle.getString("management-lrb", "generalMenuHelpAbout")) { public void actionPerformed(ActionEvent e) { final JDialog splash = new JDialog(tool, true); splash.setLayout(new BorderLayout()); SplashScreen screen = new SplashScreen("logoAT.png"); splash.add(screen, BorderLayout.NORTH); screen.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { splash.setVisible(false); } }); splash.setUndecorated(true); screen.setText( "<html>DocExplore 2009-2014" + "<br/>Released under the CeCILL v2.1 license" + "</html>"); splash.pack(); splash.setAlwaysOnTop(true); GuiUtils.centerOnScreen(splash); splash.setVisible(true); } }); add(helpMenu); historyChanged(authoringTool.historyManager); authoringTool.historyManager.addHistoryListener(this); }
From source file:SdkUnitTests.java
@Test public void DownLoadEnvelopeDocumentsTest() { byte[] fileBytes = null; try {//from w w w .j av a 2s . co m // String currentDir = new java.io.File(".").getCononicalPath(); String currentDir = System.getProperty("user.dir"); Path path = Paths.get(currentDir + SignTest1File); fileBytes = Files.readAllBytes(path); } catch (IOException ioExcp) { Assert.assertEquals(null, ioExcp); } // create an envelope to be signed EnvelopeDefinition envDef = new EnvelopeDefinition(); envDef.setEmailSubject("DownLoadEnvelopeDocumentsTest"); envDef.setEmailBlurb("Hello, Please sign my Java SDK Envelope."); // add a document to the envelope Document doc = new Document(); String base64Doc = Base64.getEncoder().encodeToString(fileBytes); doc.setDocumentBase64(base64Doc); doc.setName("TestFile.pdf"); doc.setDocumentId("1"); List<Document> docs = new ArrayList<Document>(); docs.add(doc); envDef.setDocuments(docs); // Add a recipient to sign the document Signer signer = new Signer(); signer.setEmail(UserName); String name = "Pat Developer"; signer.setName(name); signer.setRecipientId("1"); // this value represents the client's unique identifier for the signer String clientUserId = "2939"; signer.setClientUserId(clientUserId); // Create a SignHere tab somewhere on the document for the signer to sign SignHere signHere = new SignHere(); signHere.setDocumentId("1"); signHere.setPageNumber("1"); signHere.setRecipientId("1"); signHere.setXPosition("100"); signHere.setYPosition("100"); List<SignHere> signHereTabs = new ArrayList<SignHere>(); signHereTabs.add(signHere); Tabs tabs = new Tabs(); tabs.setSignHereTabs(signHereTabs); signer.setTabs(tabs); // Above causes issue envDef.setRecipients(new Recipients()); envDef.getRecipients().setSigners(new ArrayList<Signer>()); envDef.getRecipients().getSigners().add(signer); // send the envelope (otherwise it will be "created" in the Draft folder envDef.setStatus("sent"); try { ApiClient apiClient = new ApiClient(); apiClient.setBasePath(BaseUrl); String creds = createAuthHeaderCreds(UserName, Password, IntegratorKey); apiClient.addDefaultHeader("X-DocuSign-Authentication", creds); Configuration.setDefaultApiClient(apiClient); AuthenticationApi authApi = new AuthenticationApi(); LoginInformation loginInfo = authApi.login(); Assert.assertNotSame(null, loginInfo); Assert.assertNotNull(loginInfo.getLoginAccounts()); Assert.assertTrue(loginInfo.getLoginAccounts().size() > 0); List<LoginAccount> loginAccounts = loginInfo.getLoginAccounts(); Assert.assertNotNull(loginAccounts.get(0).getAccountId()); String accountId = loginInfo.getLoginAccounts().get(0).getAccountId(); EnvelopesApi envelopesApi = new EnvelopesApi(); EnvelopeSummary envelopeSummary = envelopesApi.createEnvelope(accountId, envDef); Assert.assertNotNull(envelopeSummary); EnvelopeId = envelopeSummary.getEnvelopeId(); Assert.assertNotNull(EnvelopeId); System.out.println("EnvelopeSummary: " + envelopeSummary); byte[] pdfBytes = envelopesApi.getDocument(accountId, EnvelopeId, "combined"); try { File pdfFile = File.createTempFile("ds_", "pdf", null); FileOutputStream fos = new FileOutputStream(pdfFile); fos.write(pdfBytes); // show the PDF Desktop.getDesktop().open(pdfFile); } catch (Exception ex) { Assert.fail("Could not create pdf File"); } } catch (ApiException ex) { System.out.println("Exception: " + ex); Assert.assertEquals(null, ex); } }
From source file:dsfixgui.FileIO.DSFixFileController.java
public void uninstallDSPW() { ui.printConsole(UNINSTALLING_DSPW);// w ww . j a va 2 s .co m File fileToDelete = null; boolean deleteError = false; for (int i = DSPW_FILES.length - 1; i >= 0; i--) { String file = DSPW_FILES[i]; fileToDelete = new File(ui.getDataFolder().getPath() + "\\" + file); if (fileToDelete.exists()) { fileToDelete.delete(); if (fileToDelete.exists()) { deleteError = true; ui.printConsole(FAILED_FILE_DELETE_ERR + file); } else { ui.printConsole(FILE_DELETED + file); } } else { ui.printConsole(DSF_FILE_NOT_FOUND + file); } } if (ui.getCurrentTab() == 8) { ui.setSelectedTab(0); } if (!deleteError) { if (ui.getDSFStatus() != 0) { uninstallFPSFix(); } else { File renameFile = new File(ui.getDataFolder().getPath() + "\\" + FPS_FIX_FILES[0]); if (renameFile.exists()) { ui.printConsole(RENAMING_FILE[0] + FPS_FIX_FILES[0] + RENAMING_FILE[1] + DSPW_FILES[1] + RENAMING_FILE[2]); renameFile.renameTo(new File(ui.getDataFolder().getPath() + "\\" + DSPW_FILES[1])); } } ui.printConsole(DSPW_UNINSTALLED_SUCCESS); } else { if (ui.getDSFStatus() != 0) { uninstallFPSFix(); } else { File renameFile = new File(ui.getDataFolder().getPath() + "\\" + FPS_FIX_FILES[0]); if (renameFile.exists()) { ui.printConsole(RENAMING_FILE[0] + FPS_FIX_FILES[0] + RENAMING_FILE[1] + DSPW_FILES[1] + RENAMING_FILE[2]); renameFile.renameTo(new File(ui.getDataFolder().getPath() + "\\" + DSPW_FILES[1])); } } ui.printConsole(DSPW_UNINSTALLED_ERRORS); ContinueDialog cD = new ContinueDialog(300.0, 80.0, DIALOG_TITLE_OPEN_FOLDER_PROMPT, DIALOG_MSG_DELETE_ERRORS_PROMPT, DIALOG_BUTTON_TEXTS[2], DIALOG_BUTTON_TEXTS[3]); if (cD.show()) { try { Desktop.getDesktop().open(ui.getDataFolder()); } catch (IOException ex) { //Logger.getLogger(DSFixFileController.class.getName()).log(Level.SEVERE, null, ex); ui.printConsole(FAILED_OPEN_FOLDER_ERR); } } } ui.checkForDSPW(); }