List of usage examples for java.awt Desktop getDesktop
public static synchronized Desktop getDesktop()
From source file:com.lunix.cheata.gui.CheataMainMenu.java
/** * Called by the controls from the buttonList when activated. (Mouse pressed for buttons) *///from w w w. j a v a 2 s . c om protected void actionPerformed(GuiButton button) throws IOException { if (button.id == 0) { this.mc.displayGuiScreen(new GuiOptions(this, this.mc.gameSettings)); } if (button.id == 5) { this.mc.displayGuiScreen(new GuiLanguage(this, this.mc.gameSettings, this.mc.getLanguageManager())); } if (button.id == 1) { this.mc.displayGuiScreen(new GuiWorldSelection(this)); } if (button.id == 2) { this.mc.displayGuiScreen(new GuiMultiplayer(this)); } if (button.id == 4) { this.mc.shutdown(); } if (button.id == 11) { this.mc.launchIntegratedServer("Demo_World", "Demo_World", DemoWorldServer.demoWorldSettings); } if (button.id == 12) { ISaveFormat isaveformat = this.mc.getSaveLoader(); WorldInfo worldinfo = isaveformat.getWorldInfo("Demo_World"); if (worldinfo != null) { this.mc.displayGuiScreen( new GuiYesNo(this, I18n.format("selectWorld.deleteQuestion", new Object[0]), "\'" + worldinfo.getWorldName() + "\' " + I18n.format("selectWorld.deleteWarning", new Object[0]), I18n.format("selectWorld.deleteButton", new Object[0]), I18n.format("gui.cancel", new Object[0]), 12)); } } if (button.id == 21) { this.mc.displayGuiScreen(new CheataGui(this)); } if (button.id == 24) { try { final URL url = new URL("https://github.com/CheataClient/CheataClient"); URI uri = url.toURI(); Desktop.getDesktop().browse(uri); } catch (URISyntaxException e) { e.printStackTrace(); } } }
From source file:org.wandora.application.gui.OccurrenceTableSingleType.java
@Override public void openURLOccurrence() { try {/*from w w w . j a v a2 s . com*/ String errorMessage = null; Point p = getTableModelPoint(); if (p != null) { String occurrence = topic.getData(type, langs[p.y]); if (occurrence != null) { occurrence = occurrence.trim(); if (occurrence.length() > 0) { try { if (!DataURL.isDataURL(occurrence)) { Desktop desktop = Desktop.getDesktop(); desktop.browse(new URI(occurrence)); } else { errorMessage = "Due to security restrictions Wandora can't open data-urls with desktop browser. " + "Copy data-url to clipboard and paste it to browser's address field."; } } catch (IOException ioe) { errorMessage = "IOException occurred while starting external browser for occurrence: " + ioe.getMessage(); } catch (Exception e) { if (occurrence.length() > 80) occurrence = occurrence.substring(0, 80) + "..."; errorMessage = "Exception '" + e.getMessage() + "' occurred while starting external browser for occurrence. Check if the occurrence text is a valid URL."; e.printStackTrace(); } } } } if (errorMessage != null) { WandoraOptionPane.showMessageDialog(Wandora.getWandora(), errorMessage, "Error while opening URL"); } } catch (Exception e) { if (wandora != null) wandora.handleError(e); } }
From source file:com.nubits.nubot.utils.Utils.java
public static void launchBrowser(String url) { if (Desktop.isDesktopSupported()) { try {/*w ww .j a v a2 s . c o m*/ Desktop.getDesktop().browse(new URI(url)); } catch (IOException e) { LOG.error(e.toString()); } catch (URISyntaxException e) { LOG.error(e.toString()); } } else { LOG.warn("Can't launch browser: Desktop not supported."); } }
From source file:org.apache.hadoopts.app.bucketanalyser.TSOperationControlerPanel.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed if (Desktop.isDesktopSupported()) { try {/* ww w . java 2 s . c o m*/ Desktop.getDesktop().open(getPixNodeFolder().getParentFile()); } catch (IOException ex) { Logger.getLogger(TSOperationControlerPanel.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.qspin.qtaste.ui.MainPanel.java
private void viewQTasteUserManuel() { try {/*w w w . j a v a 2s .com*/ Desktop.getDesktop().open(new File(StaticConfiguration.QTASTE_USER_MANUAL_FILE)); } catch (IOException ex) { logger.error("Unable to open QTaste user manual document at the following location:'" + StaticConfiguration.QTASTE_USER_MANUAL_FILE + "'"); } }
From source file:localization.SplitterUI.java
private void logActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logActionPerformed // TODO add your handling code here: String folderpath = filepath.getText(); if (folderpath.length() > 0 && (folderpath.endsWith(".lpu") || folderpath.endsWith(".zip"))) { String logfile = folderpath.substring(0, folderpath.lastIndexOf(".")) + ".log"; File folder = new File(logfile); if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().open(folder); } catch (IOException ex) { Logger.getLogger(SplitterUI.class.getName()).log(Level.SEVERE, null, ex); }/* w ww. j a v a2 s . c o m*/ } } else if (folderpath.length() > 0) { JOptionPane.showMessageDialog(this, "Since you have input a folder path, you need to open it manually.", "Open Log File Warning", JOptionPane.WARNING_MESSAGE, null); return; } else { String home = System.getProperty("user.home") + "\\Desktop"; File folder = new File(home); if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().open(folder); } catch (IOException ex) { Logger.getLogger(SplitterUI.class.getName()).log(Level.SEVERE, null, ex); } } } }
From source file:org.agmip.ui.afsirs.frames.GraphOutput.java
private void summaryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_summaryButtonActionPerformed int index = outputFileOptions.getSelectedIndex(); String fileName = ""; switch (index) { case 0://from www .ja va2s . c o m fileName += utils.getSummaryFile(); break; case 1: fileName += utils.getSummaryFileExcel(); break; case 2: fileName += utils.getOutFile(); } File file = new File(fileName); // String fileName = utils.getSummaryFile(); // File file = new File(fileName); try { Desktop.getDesktop().open(file); } catch (IOException e) { System.out.println("Error Opening the outpt file !!"); } }
From source file:net.ftb.util.OSUtils.java
/** * Opens the given URL in the default browser * @param url The URL/*from w w w . j a v a 2s. co m*/ */ public static void browse(String url) { try { if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { Desktop.getDesktop().browse(new URI(url.replace(" ", "+"))); } else if (getCurrentOS() == OS.UNIX && (new File("/usr/bin/xdg-open").exists() || new File("/usr/local/bin/xdg-open").exists())) { // Work-around to support non-GNOME Linux desktop environments with xdg-open installed new ProcessBuilder("xdg-open", url).start(); } else { Logger.logWarn("Could not open Java Download url, not supported"); } } catch (Exception e) { Logger.logError("Could not open link: " + url, e); } }
From source file:org.cirdles.ambapo.userInterface.AmbapoUIController.java
@FXML private void openConvertedFileClicked(MouseEvent event) { try {//from w ww. j a v a2 s . co m // TODO add your handling code here: Desktop.getDesktop().open(convertedFile); } catch (IOException ex) { Logger.getLogger(AmbapoUIController.class.getName()).log(Level.SEVERE, null, ex); Alert alert = new Alert(AlertType.ERROR); alert.setTitle("Error"); alert.setHeaderText("Unable to open file."); alert.setContentText("Check if you have a valid file name."); alert.showAndWait(); } }
From source file:com.nbt.TreeFrame.java
private void createActions() { newAction = new NBTAction("New", "New", "New", KeyEvent.VK_N) { {/*w w w. j a va 2 s . co m*/ putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('N', Event.CTRL_MASK)); } @Override public void actionPerformed(ActionEvent e) { updateTreeTable(new CompoundTag("")); } }; browseAction = new NBTAction("Browse...", "Open", "Browse...", KeyEvent.VK_O) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('O', Event.CTRL_MASK)); } @Override public void actionPerformed(ActionEvent e) { JFileChooser fc = createFileChooser(); switch (fc.showOpenDialog(TreeFrame.this)) { case JFileChooser.APPROVE_OPTION: File file = fc.getSelectedFile(); Preferences prefs = getPreferences(); prefs.put(KEY_FILE, file.getAbsolutePath()); doImport(file); break; } } }; saveAction = new NBTAction("Save", "Save", "Save", KeyEvent.VK_S) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('S', Event.CTRL_MASK)); } @Override public void actionPerformed(ActionEvent e) { String path = textFile.getText(); File file = new File(path); if (file.canWrite()) { doExport(file); } else { saveAsAction.actionPerformed(e); } } }; saveAsAction = new NBTAction("Save As...", "SaveAs", "Save As...", KeyEvent.VK_UNDEFINED) { public void actionPerformed(ActionEvent e) { JFileChooser fc = createFileChooser(); switch (fc.showSaveDialog(TreeFrame.this)) { case JFileChooser.APPROVE_OPTION: File file = fc.getSelectedFile(); Preferences prefs = getPreferences(); prefs.put(KEY_FILE, file.getAbsolutePath()); doExport(file); break; } } }; refreshAction = new NBTAction("Refresh", "Refresh", "Refresh", KeyEvent.VK_F5) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("F5")); } public void actionPerformed(ActionEvent e) { String path = textFile.getText(); File file = new File(path); if (file.canRead()) doImport(file); else showErrorDialog("The file could not be read."); } }; exitAction = new NBTAction("Exit", "Exit", KeyEvent.VK_ESCAPE) { @Override public void actionPerformed(ActionEvent e) { // TODO: this should check to see if any changes have been made // before exiting System.exit(0); } }; cutAction = new DefaultEditorKit.CutAction() { { String name = "Cut"; putValue(NAME, name); putValue(SHORT_DESCRIPTION, name); putValue(MNEMONIC_KEY, KeyEvent.VK_X); putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('X', Event.CTRL_MASK)); ImageFactory factory = new ImageFactory(); try { putValue(SMALL_ICON, new ImageIcon(factory.readGeneralImage(name, NBTAction.smallIconSize))); } catch (IOException e) { e.printStackTrace(); } try { putValue(LARGE_ICON_KEY, new ImageIcon(factory.readGeneralImage(name, NBTAction.largeIconSize))); } catch (IOException e) { e.printStackTrace(); } } }; copyAction = new DefaultEditorKit.CopyAction() { { String name = "Copy"; putValue(NAME, name); putValue(SHORT_DESCRIPTION, name); putValue(MNEMONIC_KEY, KeyEvent.VK_C); putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('C', Event.CTRL_MASK)); ImageFactory factory = new ImageFactory(); try { putValue(SMALL_ICON, new ImageIcon(factory.readGeneralImage(name, NBTAction.smallIconSize))); } catch (IOException e) { e.printStackTrace(); } try { putValue(LARGE_ICON_KEY, new ImageIcon(factory.readGeneralImage(name, NBTAction.largeIconSize))); } catch (IOException e) { e.printStackTrace(); } } }; pasteAction = new DefaultEditorKit.CutAction() { { String name = "Paste"; putValue(NAME, name); putValue(SHORT_DESCRIPTION, name); putValue(MNEMONIC_KEY, KeyEvent.VK_V); putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('V', Event.CTRL_MASK)); ImageFactory factory = new ImageFactory(); try { putValue(SMALL_ICON, new ImageIcon(factory.readGeneralImage(name, NBTAction.smallIconSize))); } catch (IOException e) { e.printStackTrace(); } try { putValue(LARGE_ICON_KEY, new ImageIcon(factory.readGeneralImage(name, NBTAction.largeIconSize))); } catch (IOException e) { e.printStackTrace(); } } }; deleteAction = new NBTAction("Delete", "Delete", "Delete", KeyEvent.VK_DELETE) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("DELETE")); } public void actionPerformed(ActionEvent e) { int row = treeTable.getSelectedRow(); TreePath path = treeTable.getPathForRow(row); Object last = path.getLastPathComponent(); if (last instanceof NBTFileBranch) { NBTFileBranch branch = (NBTFileBranch) last; File file = branch.getFile(); String name = file.getName(); String message = "Are you sure you want to delete " + name + "?"; String title = "Continue?"; int option = JOptionPane.showConfirmDialog(TreeFrame.this, message, title, JOptionPane.OK_CANCEL_OPTION); switch (option) { case JOptionPane.CANCEL_OPTION: return; } if (!FileUtils.deleteQuietly(file)) { showErrorDialog(name + " could not be deleted."); return; } } TreePath parentPath = path.getParentPath(); Object parentLast = parentPath.getLastPathComponent(); NBTTreeTableModel model = treeTable.getTreeTableModel(); int index = model.getIndexOfChild(parentLast, last); if (parentLast instanceof Mutable<?>) { Mutable<?> mutable = (Mutable<?>) parentLast; if (last instanceof ByteWrapper) { ByteWrapper wrapper = (ByteWrapper) last; index = wrapper.getIndex(); } mutable.remove(index); } else { System.err.println(last.getClass()); return; } updateTreeTable(); treeTable.expandPath(parentPath); scrollTo(parentLast); treeTable.setRowSelectionInterval(row, row); } }; openAction = new NBTAction("Open...", "Open...", KeyEvent.VK_T) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('T', Event.CTRL_MASK)); final int diamondPickaxe = 278; SpriteRecord record = NBTTreeTable.register.getRecord(diamondPickaxe); BufferedImage image = record.getImage(); setSmallIcon(image); int width = 24, height = 24; Dimension size = new Dimension(width, height); Map<RenderingHints.Key, ?> hints = Thumbnail.createRenderingHints(Thumbnail.QUALITY); BufferedImage largeImage = Thumbnail.createThumbnail(image, size, hints); setLargeIcon(largeImage); } public void actionPerformed(ActionEvent e) { TreePath path = treeTable.getPath(); if (path == null) return; Object last = path.getLastPathComponent(); if (last instanceof Region) { Region region = (Region) last; createAndShowTileCanvas(new TileCanvas.TileWorld(region)); return; } else if (last instanceof World) { World world = (World) last; createAndShowTileCanvas(world); return; } if (last instanceof NBTFileBranch) { NBTFileBranch fileBranch = (NBTFileBranch) last; File file = fileBranch.getFile(); try { open(file); } catch (IOException ex) { ex.printStackTrace(); showErrorDialog(ex.getMessage()); } } } private void open(File file) throws IOException { if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.OPEN)) { desktop.open(file); } } } }; addByteAction = new NBTAction("Add Byte", NBTConstants.TYPE_BYTE, "Add Byte", KeyEvent.VK_1) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('1', Event.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { addTag(new ByteTag("new byte", (byte) 0)); } }; addShortAction = new NBTAction("Add Short", NBTConstants.TYPE_SHORT, "Add Short", KeyEvent.VK_2) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('2', Event.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { addTag(new ShortTag("new short", (short) 0)); } }; addIntAction = new NBTAction("Add Integer", NBTConstants.TYPE_INT, "Add Integer", KeyEvent.VK_3) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('3', Event.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { addTag(new IntTag("new int", 0)); } }; addLongAction = new NBTAction("Add Long", NBTConstants.TYPE_LONG, "Add Long", KeyEvent.VK_4) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('4', Event.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { addTag(new LongTag("new long", 0)); } }; addFloatAction = new NBTAction("Add Float", NBTConstants.TYPE_FLOAT, "Add Float", KeyEvent.VK_5) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('5', Event.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { addTag(new FloatTag("new float", 0)); } }; addDoubleAction = new NBTAction("Add Double", NBTConstants.TYPE_DOUBLE, "Add Double", KeyEvent.VK_6) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('6', Event.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { addTag(new DoubleTag("new double", 0)); } }; addByteArrayAction = new NBTAction("Add Byte Array", NBTConstants.TYPE_BYTE_ARRAY, "Add Byte Array", KeyEvent.VK_7) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('7', Event.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { addTag(new ByteArrayTag("new byte array")); } }; addStringAction = new NBTAction("Add String", NBTConstants.TYPE_STRING, "Add String", KeyEvent.VK_8) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('8', Event.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { addTag(new StringTag("new string", "...")); } }; addListAction = new NBTAction("Add List Tag", NBTConstants.TYPE_LIST, "Add List Tag", KeyEvent.VK_9) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('9', Event.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { Class<? extends Tag> type = queryType(); if (type != null) addTag(new ListTag("new list", null, type)); } private Class<? extends Tag> queryType() { Object[] items = { NBTConstants.TYPE_BYTE, NBTConstants.TYPE_SHORT, NBTConstants.TYPE_INT, NBTConstants.TYPE_LONG, NBTConstants.TYPE_FLOAT, NBTConstants.TYPE_DOUBLE, NBTConstants.TYPE_BYTE_ARRAY, NBTConstants.TYPE_STRING, NBTConstants.TYPE_LIST, NBTConstants.TYPE_COMPOUND }; JComboBox comboBox = new JComboBox(new DefaultComboBoxModel(items)); comboBox.setRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value instanceof Integer) { Integer i = (Integer) value; Class<? extends Tag> c = NBTUtils.getTypeClass(i); String name = NBTUtils.getTypeName(c); setText(name); } return this; } }); Object[] message = { new JLabel("Please select a type."), comboBox }; String title = "Title goes here"; int result = JOptionPane.showOptionDialog(TreeFrame.this, message, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); switch (result) { case JOptionPane.OK_OPTION: ComboBoxModel model = comboBox.getModel(); Object item = model.getSelectedItem(); if (item instanceof Integer) { Integer i = (Integer) item; return NBTUtils.getTypeClass(i); } } return null; } }; addCompoundAction = new NBTAction("Add Compound Tag", NBTConstants.TYPE_COMPOUND, "Add Compound Tag", KeyEvent.VK_0) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('0', Event.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { addTag(new CompoundTag()); } }; String name = "About " + TITLE; helpAction = new NBTAction(name, "Help", name, KeyEvent.VK_F1) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("F1")); } public void actionPerformed(ActionEvent e) { Object[] message = { new JLabel(TITLE + " " + VERSION), new JLabel("\u00A9 Copyright Taggart Spilman 2011. All rights reserved."), new Hyperlink("<html><a href=\"#\">NamedBinaryTag.com</a></html>", "http://www.namedbinarytag.com"), new Hyperlink("<html><a href=\"#\">Contact</a></html>", "mailto:tagadvance@gmail.com"), new JLabel(" "), new Hyperlink("<html><a href=\"#\">JNBT was written by Graham Edgecombe</a></html>", "http://jnbt.sf.net"), new Hyperlink("<html><a href=\"#\">Available open-source under the BSD license</a></html>", "http://jnbt.sourceforge.net/LICENSE.TXT"), new JLabel(" "), new JLabel("This product includes software developed by"), new Hyperlink("<html><a href=\"#\">The Apache Software Foundation</a>.</html>", "http://www.apache.org"), new JLabel(" "), new JLabel("Default texture pack:"), new Hyperlink("<html><a href=\"#\">SOLID COLOUR. SOLID STYLE.</a></html>", "http://www.minecraftforum.net/topic/72253-solid-colour-solid-style/"), new JLabel("Bundled with the permission of Trigger_Proximity."), }; String title = "About"; JOptionPane.showMessageDialog(TreeFrame.this, message, title, JOptionPane.INFORMATION_MESSAGE); } }; }