Example usage for java.awt Desktop isDesktopSupported

List of usage examples for java.awt Desktop isDesktopSupported

Introduction

In this page you can find the example usage for java.awt Desktop isDesktopSupported.

Prototype

public static boolean isDesktopSupported() 

Source Link

Document

Tests whether this class is supported on the current platform.

Usage

From source file:de.tor.tribes.ui.windows.DSWorkbenchMainFrame.java

/**
 * Creates new form MapFrame//from ww w .  ja  v a2s.  c  o  m
 */
DSWorkbenchMainFrame() {
    initComponents();
    setAlwaysOnTop(false);
    if (!GlobalOptions.isMinimal()) {
        setTitle("DS Workbench " + Constants.VERSION + Constants.VERSION_ADDITION);
    } else {
        setTitle("DS Workbench Mini " + Constants.VERSION + Constants.VERSION_ADDITION);
    }

    jExportDialog.pack();
    jAddROIDialog.pack();

    JOutlookBar outlookBar = new JOutlookBar();
    outlookBar.addBar("Navigation", jNavigationPanel);
    outlookBar.addBar("Information", jInformationPanel);
    outlookBar.addBar("Karte", jMapPanel);
    outlookBar.addBar("ROI", jROIPanel);
    outlookBar.setVisibleBar(1);
    jSettingsScrollPane.setViewportView(outlookBar);

    mAbout = new AboutDialog(this, true);
    mAbout.pack();
    chooser.setDialogTitle("Speichern unter...");
    chooser.addChoosableFileFilter(new javax.swing.filechooser.FileFilter() {

        @Override
        public boolean accept(File f) {
            return (f != null) && (f.isDirectory() || f.getName().endsWith(".png"));
        }

        @Override
        public String getDescription() {
            return "PNG Image (*.png)";
        }
    });

    chooser.addChoosableFileFilter(new javax.swing.filechooser.FileFilter() {

        @Override
        public boolean accept(File f) {
            return (f != null) && (f.isDirectory() || f.getName().endsWith(".jpeg"));
        }

        @Override
        public String getDescription() {
            return "JPEG Image (*.jpeg)";
        }
    });

    //Schedule Backup
    new Timer("BackupTimer", true).schedule(new BackupTask(), 60 * 10000, 60 * 10000);

    //give focus to map panel if mouse enters map
    jMapPanelHolder.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent e) {
            jMapPanelHolder.requestFocusInWindow();
        }
    });

    getContentPane().setBackground(Constants.DS_BACK);
    pack();
    capabilityInfoPanel1.addActionListener(MapPanel.getSingleton());

    // <editor-fold defaultstate="collapsed" desc=" Add global KeyListener ">
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {

        @Override
        public void eventDispatched(AWTEvent event) {
            if (event.getID() == KeyEvent.KEY_PRESSED) {
                KeyEvent e = (KeyEvent) event;
                if (DSWorkbenchMainFrame.getSingleton().isActive()) {
                    //move shortcuts
                    if (e.getKeyCode() == KeyEvent.VK_DOWN) {
                        scroll(0.0, 2.0);
                    } else if (e.getKeyCode() == KeyEvent.VK_UP) {
                        scroll(0.0, -2.0);
                    } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                        scroll(-2.0, 0.0);
                    } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                        scroll(2.0, 0.0);
                    } else if ((e.getKeyCode() == KeyEvent.VK_1) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //shot minimap tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_AXE);
                    } else if ((e.getKeyCode() == KeyEvent.VK_2) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //attack axe tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_RAM);
                    } else if ((e.getKeyCode() == KeyEvent.VK_3) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //attack ram tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_SNOB);
                    } else if ((e.getKeyCode() == KeyEvent.VK_4) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //attack snob tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_SPY);
                    } else if ((e.getKeyCode() == KeyEvent.VK_5) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //attack sword tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_LIGHT);
                    } else if ((e.getKeyCode() == KeyEvent.VK_6) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //attack light tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_HEAVY);
                    } else if ((e.getKeyCode() == KeyEvent.VK_7) && e.isShiftDown() && !e.isControlDown()
                            && !e.isAltDown()) {
                        //attack heavy tool shortcut
                        MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_SWORD);
                    } else if ((e.getKeyCode() == KeyEvent.VK_S) && e.isControlDown() && !e.isAltDown()) {
                        //search frame shortcut
                        DSWorkbenchSearchFrame.getSingleton()
                                .setVisible(!DSWorkbenchSearchFrame.getSingleton().isVisible());
                    }
                }

                //misc shortcuts
                if ((e.getKeyCode() == KeyEvent.VK_0) && e.isAltDown()) {
                    //no tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_DEFAULT);
                } else if ((e.getKeyCode() == KeyEvent.VK_1) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //measure tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_MEASURE);
                } else if ((e.getKeyCode() == KeyEvent.VK_2) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //mark tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_MARK);
                } else if ((e.getKeyCode() == KeyEvent.VK_3) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //tag tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_TAG);
                } else if ((e.getKeyCode() == KeyEvent.VK_4) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //attack ingame tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_SUPPORT);
                } else if ((e.getKeyCode() == KeyEvent.VK_5) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //attack ingame tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_SELECTION);
                } else if ((e.getKeyCode() == KeyEvent.VK_6) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //attack ingame tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_RADAR);
                } else if ((e.getKeyCode() == KeyEvent.VK_7) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //attack ingame tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ATTACK_INGAME);
                } else if ((e.getKeyCode() == KeyEvent.VK_8) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    //res ingame tool shortcut
                    MapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_SEND_RES_INGAME);
                } else if ((e.getKeyCode() == KeyEvent.VK_1) && e.isControlDown() && !e.isShiftDown()
                        && !e.isAltDown()) {
                    //move minimap tool shortcut
                    MinimapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_MOVE);
                } else if ((e.getKeyCode() == KeyEvent.VK_2) && e.isControlDown() && !e.isShiftDown()
                        && !e.isAltDown()) {
                    //zoom minimap tool shortcut
                    MinimapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_ZOOM);
                } else if ((e.getKeyCode() == KeyEvent.VK_3) && e.isControlDown() && !e.isShiftDown()
                        && !e.isAltDown()) {
                    //shot minimap tool shortcut
                    MinimapPanel.getSingleton().setCurrentCursor(ImageManager.CURSOR_SHOT);
                } else if ((e.getKeyCode() == KeyEvent.VK_T) && e.isControlDown() && !e.isShiftDown()
                        && !e.isAltDown()) {
                    //search time shortcut
                    ClockFrame.getSingleton().setVisible(!ClockFrame.getSingleton().isVisible());
                } else if ((e.getKeyCode() == KeyEvent.VK_S) && e.isAltDown() && !e.isShiftDown()
                        && !e.isControlDown()) {
                    planMapshot();
                } else if (e.getKeyCode() == KeyEvent.VK_F2) {
                    DSWorkbenchAttackFrame.getSingleton()
                            .setVisible(!DSWorkbenchAttackFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F3) {
                    DSWorkbenchMarkerFrame.getSingleton()
                            .setVisible(!DSWorkbenchMarkerFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F4) {
                    DSWorkbenchTroopsFrame.getSingleton()
                            .setVisible(!DSWorkbenchTroopsFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F5) {
                    DSWorkbenchRankFrame.getSingleton()
                            .setVisible(!DSWorkbenchRankFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F6) {
                    DSWorkbenchFormFrame.getSingleton()
                            .setVisible(!DSWorkbenchFormFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F7) {
                    if (ServerSettings.getSingleton().isChurch()) {
                        DSWorkbenchChurchFrame.getSingleton()
                                .setVisible(!DSWorkbenchChurchFrame.getSingleton().isVisible());
                    }
                } else if (e.getKeyCode() == KeyEvent.VK_F8) {
                    DSWorkbenchConquersFrame.getSingleton()
                            .setVisible(!DSWorkbenchConquersFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F9) {
                    DSWorkbenchNotepad.getSingleton()
                            .setVisible(!DSWorkbenchNotepad.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F10) {
                    DSWorkbenchTagFrame.getSingleton()
                            .setVisible(!DSWorkbenchTagFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F11) {
                    DSWorkbenchStatsFrame.getSingleton()
                            .setVisible(!DSWorkbenchStatsFrame.getSingleton().isVisible());
                } else if (e.getKeyCode() == KeyEvent.VK_F12) {
                    DSWorkbenchSettingsDialog.getSingleton().setVisible(true);
                } else if ((e.getKeyCode() == KeyEvent.VK_1) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 1
                    centerROI(0);
                } else if ((e.getKeyCode() == KeyEvent.VK_2) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 2
                    centerROI(1);
                } else if ((e.getKeyCode() == KeyEvent.VK_3) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 3
                    centerROI(2);
                } else if ((e.getKeyCode() == KeyEvent.VK_4) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 4
                    centerROI(3);
                } else if ((e.getKeyCode() == KeyEvent.VK_5) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 5
                    centerROI(4);
                } else if ((e.getKeyCode() == KeyEvent.VK_6) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 6
                    centerROI(5);
                } else if ((e.getKeyCode() == KeyEvent.VK_7) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 7
                    centerROI(6);
                } else if ((e.getKeyCode() == KeyEvent.VK_8) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 8
                    centerROI(7);
                } else if ((e.getKeyCode() == KeyEvent.VK_9) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 9
                    centerROI(8);
                } else if ((e.getKeyCode() == KeyEvent.VK_0) && e.isControlDown() && e.isAltDown()
                        && !e.isShiftDown()) {
                    //ROI 10
                    centerROI(9);
                } else if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                    jMapPanelHolder.requestFocusInWindow();
                    MapPanel.getSingleton().setSpaceDown(true);
                } else if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
                    jMapPanelHolder.requestFocusInWindow();
                    MapPanel.getSingleton().setShiftDown(true);
                }
            } else if (event.getID() == KeyEvent.KEY_RELEASED) {
                KeyEvent e = (KeyEvent) event;
                if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                    MapPanel.getSingleton().setSpaceDown(false);
                } else if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
                    MapPanel.getSingleton().setShiftDown(false);
                }
            }
        }
    }, AWTEvent.KEY_EVENT_MASK);
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc=" Load UI Icons ">
    try {
        jOnlineLabel.setIcon(new ImageIcon("./graphics/icons/online.png"));
        jEnableClipboardWatchButton.setIcon(new ImageIcon("./graphics/icons/watch_clipboard.png"));
        jCenterIngameButton
                .setIcon(new ImageIcon(DSWorkbenchMainFrame.class.getResource("/res/ui/center_ingame.png")));
        jRefreshButton.setIcon(new ImageIcon("./graphics/icons/refresh.png"));
        jCenterCoordinateIngame.setIcon(new ImageIcon("./graphics/icons/center.png"));
    } catch (Exception e) {
        logger.error("Failed to load status icon(s)", e);
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc=" Check for desktop support ">
    if (!Desktop.isDesktopSupported()) {
        jCenterIngameButton.setEnabled(false);
        jCenterCoordinateIngame.setEnabled(false);
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc=" Restore last map position ">
    try {
        String x = GlobalOptions.getSelectedProfile().getProperty("last.x");
        String y = GlobalOptions.getSelectedProfile().getProperty("last.y");
        centerPosition(Double.parseDouble(x), Double.parseDouble(y));
    } catch (Exception e) {
        centerPosition(ServerSettings.getSingleton().getMapDimension().getCenterX(),
                ServerSettings.getSingleton().getMapDimension().getCenterY());
    }

    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc=" Restore other settings ">
    jShowMapPopup.setSelected(GlobalOptions.getProperties().getBoolean("show.map.popup"));
    jShowMouseOverInfo.setSelected(GlobalOptions.getProperties().getBoolean("show.mouseover.info"));
    jIncludeSupport.setSelected(GlobalOptions.getProperties().getBoolean("include.support"));
    jHighlightTribeVillages.setSelected(GlobalOptions.getProperties().getBoolean("highlight.tribes.villages"));
    jShowRuler.setSelected(GlobalOptions.getProperties().getBoolean("show.ruler"));
    jDisplayChurch.setSelected(GlobalOptions.getProperties().getBoolean("show.church"));
    jDisplayWatchtower.setSelected(GlobalOptions.getProperties().getBoolean("show.watchtower"));
    jDisplayChurch.setEnabled(ServerSettings.getSingleton().isChurch());
    jDisplayWatchtower.setEnabled(ServerSettings.getSingleton().isWatchtower());
    ServerSettings.getSingleton().addListener(new ServerSettingsListener() {
        @Override
        public void fireServerSettingsChanged() {
            jDisplayChurch.setEnabled(ServerSettings.getSingleton().isChurch());
            jDisplayWatchtower.setEnabled(ServerSettings.getSingleton().isWatchtower());
        }
    });
    int r = GlobalOptions.getProperties().getInt("radar.size");
    int hour = r / 60;
    jHourField.setText(Integer.toString(hour));
    jMinuteField.setText(Integer.toString(r - hour * 60));
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Skin Setup">
    DefaultComboBoxModel gpModel = new DefaultComboBoxModel(GlobalOptions.getAvailableSkins());
    jGraphicPacks.setModel(gpModel);
    String skin = GlobalOptions.getProperty("default.skin");
    if (gpModel.getIndexOf(skin) != -1) {
        jGraphicPacks.setSelectedItem(skin);
    } else {
        jGraphicPacks.setSelectedItem("default");
    }
    //</editor-fold>

    minZoom = GlobalOptions.getProperties().getDouble("map.zoom.min");
    maxZoom = GlobalOptions.getProperties().getDouble("map.zoom.max");
    dZoomInOutFactor = GlobalOptions.getProperties().getDouble("map.zoom.in.out.factor");

    mNotificationHideThread = new NotificationHideThread();
    mNotificationHideThread.start();
    SystrayHelper.installSystrayIcon();
    //update online state
    onlineStateChanged();
    restoreProperties();
}

From source file:org.yccheok.jstock.gui.Utils.java

public static void launchWebBrowser(String address) {
    if (Desktop.isDesktopSupported()) {
        final Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.BROWSE)) {
            URL url = null;/*  ww w  . ja  v  a 2  s . c  om*/
            String string = address;
            try {
                url = new URL(string);
            } catch (MalformedURLException ex) {
                return;
            }
            try {
                desktop.browse(url.toURI());
            } catch (URISyntaxException ex) {
            } catch (IOException ex) {
            }
        }
    }
}

From source file:org.yccheok.jstock.gui.Utils.java

public static void launchWebBrowser(javax.swing.event.HyperlinkEvent evt) {
    if (HyperlinkEvent.EventType.ACTIVATED.equals(evt.getEventType())) {
        URL url = evt.getURL();/*  w ww.  j  av  a2 s.  c  o  m*/
        if (Desktop.isDesktopSupported()) {
            final Desktop desktop = Desktop.getDesktop();
            if (desktop.isSupported(Desktop.Action.BROWSE)) {
                if (url == null) {
                    // www.yahoo.com considered an invalid URL. Hence, evt.getURL() returns null.
                    String string = "http://" + evt.getDescription();
                    try {
                        url = new URL(string);
                    } catch (MalformedURLException ex) {
                        return;
                    }
                }
                try {
                    desktop.browse(url.toURI());
                } catch (URISyntaxException ex) {
                } catch (IOException ex) {
                }
            }
        }
    }
}

From source file:org.javaswift.cloudie.CloudiePanel.java

protected void onOpenInBrowserStoredObject() {
    Container container = getSelectedContainer();
    List<StoredObject> objects = getSelectedStoredObjects();
    if (container.isPublic()) {
        for (StoredObject obj : objects) {
            String publicURL = obj.getPublicURL();
            if (Desktop.isDesktopSupported()) {
                try {
                    Desktop.getDesktop().browse(new URI(publicURL));
                } catch (Exception e) {
                    e.printStackTrace();
                }/*w w w  .  j a va2s. c o  m*/
            }
        }
    }
}

From source file:rems.Global.java

public static void runSalesInvoice(String outputUsd, String outfileName, String jsprReportPath,
        String reportTitle, String rptSQL) {
    //String reportPath = "C:/1_DESIGNS/MYAPPS/REMSProcessRunner/reports/jasper2.jrxml";
    try {/*from w  w  w.  j  a  v  a 2s .c o m*/
        //Compile jrxml file.
        //System.out.println("Inside Jasper");
        //System.in.read();
        String orgNm = Global.getOrgName(Global.UsrsOrg_ID).replace("\r\n", " ").replace("\r", " ")
                .replace("\n", " ");
        String pstl = Global.getOrgPstlAddrs(Global.UsrsOrg_ID).replace("\r\n", " ").replace("\r", " ")
                .replace("\n", " ");
        //Contacts Nos
        String cntcts = Global.getOrgContactNos(Global.UsrsOrg_ID).replace("\r\n", " ").replace("\r", " ")
                .replace("\n", " ");
        //Email Address
        String email = Global.getOrgEmailAddrs(Global.UsrsOrg_ID).replace("\r\n", " ").replace("\r", " ")
                .replace("\n", " ");
        String website = Global.getOrgWebsite(Global.UsrsOrg_ID).replace("\r\n", " ").replace("\r", " ")
                .replace("\n", " ");

        String online = "";
        if (!email.trim().equals("")) {
            online += "Email: " + email;
            if (!website.equals("")) {
                online += " Website: " + website;
            }
        }
        String fileName = jsprReportPath;
        File theFile = new File(fileName);
        JasperDesign jasperDesign = JRXmlLoader.load(theFile);

        JRDesignBand band = new JRDesignBand();
        band.setHeight(90);

        JRDesignImage image = new JRDesignImage(jasperDesign);
        image.setX(1);
        image.setY(0);
        image.setHeight(70);
        image.setWidth(70);
        JRDesignExpression expression = new JRDesignExpression();
        //expression.setValueClass(java.lang.String.class);
        //C:/Users/richard.adjei-mensah/JaspersoftWorkspace/MyReports/1.png
        expression.setText("$P{ImageUrl}");
        image.setExpression(expression);
        band.addElement(image);

        JRDesignStaticText staticText = new JRDesignStaticText();
        staticText.setX(90);
        staticText.setY(2);
        staticText.setWidth(465);
        staticText.setHeight(15);
        //staticText.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);
        staticText.setText(orgNm);
        band.addElement(staticText);

        staticText = new JRDesignStaticText();
        staticText.setX(90);
        staticText.setY(16);
        staticText.setWidth(465);
        staticText.setHeight(15);
        //staticText.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);
        staticText.setText(pstl);
        band.addElement(staticText);

        staticText = new JRDesignStaticText();
        staticText.setX(90);
        staticText.setY(30);
        staticText.setWidth(465);
        staticText.setHeight(15);
        //staticText.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);
        staticText.setText(cntcts);
        band.addElement(staticText);

        staticText = new JRDesignStaticText();
        staticText.setX(90);
        staticText.setY(45);
        staticText.setWidth(465);
        staticText.setHeight(15);
        //staticText.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);
        staticText.setText(online);
        band.addElement(staticText);

        staticText = new JRDesignStaticText();
        staticText.setX(0);
        staticText.setY(73);
        staticText.setWidth(555);
        staticText.setHeight(15);
        staticText.setBold(true);
        staticText.setFontName("Arial");
        staticText.setUnderline(false);
        staticText.setFontSize(12F);
        staticText.setForecolor(Color.BLUE);
        staticText.setHorizontalTextAlign(HorizontalTextAlignEnum.CENTER);
        staticText.setText(reportTitle);
        band.addElement(staticText);

        JRDesignLine nwLine = new JRDesignLine();
        nwLine.setX(0);
        nwLine.setY(72);
        nwLine.setWidth(555);
        nwLine.setHeight(0);
        band.addElement(nwLine);

        nwLine = new JRDesignLine();
        nwLine.setX(0);
        nwLine.setY(88);
        nwLine.setWidth(555);
        nwLine.setHeight(0);
        band.addElement(nwLine);
        jasperDesign.setTitle(band);//setPageHeader

        //Build a new query
        //rptSQL
        String theQuery = "SELECT * FROM org.org_details WHERE org_name ilike '%%'";
        System.out.println(rptSQL);
        // update the data query
        JRDesignQuery newQuery = new JRDesignQuery();
        newQuery.setText(theQuery);
        jasperDesign.setQuery(newQuery);

        JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
        //JasperReport jasperReport = JasperCompileManager.compileReport(reportPath);            
        Map<String, Object> params = new HashMap<String, Object>();
        //"C:/Users/richard.adjei-mensah/JaspersoftWorkspace/MyReports/1.png"
        params.put("ImageUrl", Global.getOrgImgsDrctry() + "/" + String.valueOf(Global.UsrsOrg_ID) + ".png");
        Connection connection;

        Class.forName("org.postgresql.Driver");
        connection = DriverManager.getConnection(
                "jdbc:postgresql://" + Global.Hostnme + ":" + Global.Portnum + "/" + Global.Dbase, Global.Uname,
                Global.Pswd);

        System.out.println("Filling report...");
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, connection);

        if (outputUsd.equals("MICROSOFT EXCEL")) {
            JRXlsExporter xlsExporter = new JRXlsExporter();

            xlsExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
            xlsExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outfileName));
            SimpleXlsReportConfiguration xlsReportConfiguration = new SimpleXlsReportConfiguration();
            //SimpleXlsExporterConfiguration xlsExporterConfiguration = new SimpleXlsExporterConfiguration();
            xlsReportConfiguration.setOnePagePerSheet(false);
            xlsReportConfiguration.setRemoveEmptySpaceBetweenRows(true);
            xlsReportConfiguration.setDetectCellType(true);
            xlsReportConfiguration.setWhitePageBackground(false);
            xlsExporter.setConfiguration(xlsReportConfiguration);
            xlsExporter.exportReport();
        } else if (outputUsd.equals("PDF")) {
            JasperExportManager.exportReportToPdfFile(jasperPrint, outfileName);
        } else if (outputUsd.equals("HTML")) {
            JasperExportManager.exportReportToHtmlFile(jasperPrint, outfileName);
        } else if (outputUsd.equals("STANDARD")) {
            JasperExportManager.exportReportToPdfFile(jasperPrint, outfileName);
        } else if (outputUsd.equals("MICROSOFT WORD")) {
            JRRtfExporter rtfExporter = new JRRtfExporter();
            rtfExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
            rtfExporter.setExporterOutput(new SimpleWriterExporterOutput(outfileName));
            SimpleRtfReportConfiguration rtfReportConfiguration = new SimpleRtfReportConfiguration();
            //SimpleRtfExporterConfiguration xlsExporterConfiguration = new SimpleRtfExporterConfiguration();              
            rtfExporter.setConfiguration(rtfReportConfiguration);
            rtfExporter.exportReport();
        } else if (outputUsd.equals("CHARACTER SEPARATED FILE (CSV)")) {
            JRCsvExporter exporter = new JRCsvExporter();
            exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
            exporter.setExporterOutput(new SimpleWriterExporterOutput(outfileName));
            SimpleCsvReportConfiguration rtfReportConfiguration = new SimpleCsvReportConfiguration();
            //SimpleCsvExporterConfiguration xlsExporterConfiguration = new SimpleCsvExporterConfiguration();              
            exporter.setConfiguration(rtfReportConfiguration);
            exporter.exportReport();
        } else {
            JasperExportManager.exportReportToPdfFile(jasperPrint, outfileName);
        }

        //JasperViewer.viewReport(jasperPrint, false);
        System.out.println("Opening report");
        if (Desktop.isDesktopSupported()) {
            try {
                File myFile = new File(outfileName);
                Desktop.getDesktop().open(myFile);
            } catch (IOException ex) {
                // no application registered for PDFs
            }
        }
        //            Runtime runTime = Runtime.getRuntime();
        //            Process process = runTime
        //            .exec("C:/Users/richard.adjei-mensah/Desktop/Test1.pdf");
        //
        //            System.out.println("Closing report");
        //            process.destroy();
        connection.close();
    } catch (JRException ex) {
        System.out.println(ex.getMessage());
    } catch (ClassNotFoundException e) {
        System.out.println(e.getMessage());
    } catch (SQLException e) {
        System.out.println(e.getMessage());
    }
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        System.out.println(e.getMessage());
    }
}

From source file:com.g2inc.scap.editor.gui.windows.EditorMainWindow.java

private void initFilemenu() {
    final EditorMainWindow parentWinRef = this;

    exitMenuItem.addActionListener(new ActionListener() {
        @Override/*from   ww w .j  a v a  2  s .  co m*/
        public void actionPerformed(ActionEvent e) {
            parentWinRef.dispose();
        }
    });

    openOvalMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            final JFileChooser fc = new JFileChooser();
            fc.setDialogType(JFileChooser.OPEN_DIALOG);

            File lastOpenedFrom = guiProps.getLastOpenedFromFile();

            // Set current directory
            fc.setCurrentDirectory(lastOpenedFrom);

            FileFilter ff = new OcilOrOvalFilesFilter("OVAL");
            fc.setFileFilter(ff);
            fc.setFileSelectionMode(JFileChooser.FILES_ONLY);

            int ret = fc.showOpenDialog(EditorMainWindow.getInstance());

            if (ret == JFileChooser.APPROVE_OPTION) {
                File f = fc.getSelectedFile();
                File parent = f.getAbsoluteFile().getParentFile();
                guiProps.setLastOpenedFrom(parent.getAbsolutePath());
                guiProps.save();

                openFile(f, SCAPDocumentClassEnum.OVAL);
            }
        }
    });

    saveMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            // get the currently open window
            JInternalFrame selectedWin = desktopPane.getSelectedFrame();

            if (selectedWin != null) {
                SCAPDocument scapDoc = null;

                Document dom = null;
                String filename = null;

                if (selectedWin instanceof OvalEditorForm) {
                    OvalEditorForm oef = (OvalEditorForm) selectedWin;
                    scapDoc = oef.getDocument();
                    dom = scapDoc.getDoc();
                    filename = scapDoc.getFilename();
                } else if (selectedWin instanceof CPEDictionaryEditorForm) {
                    CPEDictionaryEditorForm cef = (CPEDictionaryEditorForm) selectedWin;
                    scapDoc = cef.getDocument();
                    dom = scapDoc.getDoc();
                    filename = scapDoc.getFilename();
                }

                if (dom != null) {
                    // since this is a save operation, not save as, we won't
                    // prompt the user for where to store the file

                    try {
                        scapDoc.save();
                        ((EditorForm) selectedWin).setDirty(false);
                    } catch (Exception e) {
                        String message = "An error occured trying to save to file " + filename + ": "
                                + e.getMessage();
                        EditorUtil.showMessageDialog(parentWinRef, message,
                                EditorMessages.SAVE_ERROR_DIALOG_TITLE, JOptionPane.ERROR_MESSAGE);
                    }
                }
            }
        }
    });

    saveAsMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            // get the currently open window
            JInternalFrame selectedWin = desktopPane.getSelectedFrame();

            if (selectedWin != null) {
                SCAPDocument scapDoc = null;
                Document dom = null;
                String filename = null;
                String windowTitle = null;

                if (selectedWin instanceof OvalEditorForm) {
                    windowTitle = OvalEditorForm.WINDOW_TITLE_BASE;
                    OvalEditorForm oef = (OvalEditorForm) selectedWin;
                    scapDoc = oef.getDocument();
                    dom = scapDoc.getDoc();
                    filename = scapDoc.getFilename();
                } else if (selectedWin instanceof CPEDictionaryEditorForm) {
                    windowTitle = CPEDictionaryEditorForm.WINDOW_TITLE_BASE;
                    CPEDictionaryEditorForm cef = (CPEDictionaryEditorForm) selectedWin;
                    scapDoc = cef.getDocument();
                    dom = scapDoc.getDoc();
                    filename = scapDoc.getFilename();
                } else {
                    return;
                }

                if (dom != null) {
                    String newFilename = null;
                    SCAPDocumentTypeEnum docType = scapDoc.getDocumentType();

                    FileSaveAsWizard saveAsWiz = new FileSaveAsWizard(EditorMainWindow.getInstance(), true,
                            docType);

                    //saveAsWiz.pack();
                    saveAsWiz.setLocationRelativeTo(EditorMainWindow.getInstance());
                    saveAsWiz.setVisible(true);

                    if (saveAsWiz.wasCancelled()) {
                        return;
                    }

                    newFilename = saveAsWiz.getFilename();

                    try {
                        scapDoc.setFilename(newFilename);
                        scapDoc.saveAs(newFilename);

                        EditorUtil.markActiveWindowDirty(EditorMainWindow.getInstance(), false);
                        ((EditorForm) selectedWin).refreshRootNode();

                    } catch (Exception e) {
                        LOG.error(e.getMessage(), e);

                        EditorUtil.showMessageDialog(parentWinRef, "An error occured trying to save to file "
                                + newFilename + ": " + e.getMessage(), "Save Error", JOptionPane.ERROR_MESSAGE);
                        return;
                    }

                    SCAPContentManager scm = SCAPContentManager.getInstance();

                    if (scm != null) {
                        scm.removeDocument(filename);
                        scm.addDocument(newFilename, scapDoc);
                        selectedWin.setTitle(windowTitle + (new File(newFilename)).getAbsolutePath());
                    } else {
                        LOG.error("SCM instance is null here!");
                    }
                }
            }
        }
    });

    newXCCDFFromOvalMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            //generateXccdfFromOvalOrOcil("OVAL");
            final JFileChooser fc = new JFileChooser();
            fc.setDialogType(JFileChooser.OPEN_DIALOG);
            File lastOpenedFrom = guiProps.getLastOpenedFromFile();

            // Set current directory
            fc.setCurrentDirectory(lastOpenedFrom);
            FileFilter ff = new OcilOrOvalFilesFilter("OVAL");
            fc.setFileFilter(ff);
            fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
            int ret = fc.showOpenDialog(EditorMainWindow.getInstance());
            if (ret == JFileChooser.APPROVE_OPTION) {
                File f = fc.getSelectedFile();
                File parent = f.getAbsoluteFile().getParentFile();
                guiProps.setLastOpenedFrom(parent.getAbsolutePath());
                guiProps.save();
                try {
                    InputStream is = this.getClass().getClassLoader().getResourceAsStream("oval-to-xccdf.xsl");
                    File xsltfile = new File("oval-to-xccdf.xsl");
                    OutputStream outputStream = new FileOutputStream(xsltfile);
                    IOUtils.copy(is, outputStream);
                    outputStream.close();
                    OvalToXCCDF1.ovalToXccdf(f, xsltfile);
                    xsltfile.delete();
                    String reverseDNS = JOptionPane.showInputDialog("reverse_DNS:");
                    if (reverseDNS == null || reverseDNS.length() == 0) {
                        JOptionPane.showMessageDialog(null, "Enter the reverse_DNS", "alert",
                                JOptionPane.ERROR_MESSAGE);
                    } else {
                        JFileChooser fc1 = new JFileChooser();
                        fc1.setCurrentDirectory(f);
                        int ret1 = fc1.showSaveDialog(EditorMainWindow.getInstance());
                        if (ret1 == JFileChooser.APPROVE_OPTION) {
                            File savefile = fc1.getSelectedFile();
                            is = this.getClass().getClassLoader().getResourceAsStream("xccdf_1.1_to_1.2.xsl");
                            xsltfile = new File("oval-to-xccdf.xsl");
                            outputStream = new FileOutputStream(xsltfile);
                            IOUtils.copy(is, outputStream);
                            outputStream.close();
                            File temp = new File("temp.xml");
                            XCCDF1to2.xccdf12(savefile, reverseDNS, xsltfile, temp);
                            JOptionPane.showMessageDialog(null,
                                    "XCCDF File Created: " + savefile.getAbsolutePath(), "XCCDF Created",
                                    JOptionPane.PLAIN_MESSAGE);
                            xsltfile.delete();
                            temp.delete();
                            temp = null;
                        }

                    }

                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (URISyntaxException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (TransformerException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                //  openFile(f, SCAPDocumentClassEnum.OVAL);
            }

        }

    });

    newOvalMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            CreateOvalWizard wiz = new CreateOvalWizard(true);
            wiz.setName("create_oval_wizard");
            wiz.pack();
            wiz.setVisible(true);

            if (!wiz.wasCancelled()) {
                // User has been through the wizard to select
                // 1. an Oval schema version (eg, OVAL55)
                // 2. one or more platforms (eg, "windows", "solaris", etc)
                // 3. a file name for the new Oval file
                // Now we are ready to actually create the file
                String createdFilename = createNewOvalDocument(wiz);

                if (createdFilename == null) {
                    LOG.error("newOvalMenuItem.actionlistener: Created filename was null!");
                    return;
                }

                File f = new File(createdFilename);

                guiProps.setLastOpenedFromFile(f.getParentFile());
                guiProps.save();

                SCAPContentManager scm = SCAPContentManager.getInstance();

                if (scm != null) {
                    OvalDefinitionsDocument dd = (OvalDefinitionsDocument) scm.getDocument(f.getAbsolutePath());

                    openFile(dd);
                }
            }
            wiz.setVisible(false);
            wiz.dispose();
        }
    });

    /* wizModeMenuItem.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        WizardModeWindow wizModeWin = new WizardModeWindow();
            
        EditorMainWindow emw = EditorMainWindow.getInstance();
        JDesktopPane emwDesktopPane = emw.getDesktopPane();
            
        wizModeWin.setTitle("Wizard Mode");
        wizModeWin.pack();
            
        wizModeWin.addInternalFrameListener(new WeakInternalFrameListener(EditorMainWindow.getInstance()));
            
        Dimension dpDim = emwDesktopPane.getSize();
        int x = (dpDim.width - wizModeWin.getWidth()) / 2;
        int y = (dpDim.height - wizModeWin.getHeight()) / 2;
            
        wizModeWin.setLocation(x, y);
        emwDesktopPane.add(wizModeWin);
        wizModeWin.setVisible(true);
            
        setWizMode(true);
    }
     });*/

    ugMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (Desktop.isDesktopSupported()) {
                Desktop desktop = Desktop.getDesktop();
                InputStream resource = this.getClass().getResourceAsStream("/User_Guide.pdf");
                try {
                    File userGuideFile = File.createTempFile("UserGuide", ".pdf");
                    userGuideFile.deleteOnExit();
                    OutputStream out = new FileOutputStream(userGuideFile);
                    try {
                        // copy contents from resource to out
                        IOUtils.copy(resource, out);
                    } catch (IOException ex) {
                        JOptionPane.showMessageDialog(null, "Couldn't copy between streams.");
                    } finally {
                        out.close();
                    }
                    desktop.open(userGuideFile);
                } catch (IOException ex) {
                    JOptionPane.showMessageDialog(null, "Could not call Open on desktop object.");
                } finally {
                    try {
                        if (resource != null) {
                            resource.close();
                        }
                    } catch (IOException ex) {
                        LOG.error("Error displaying user guide", ex);
                        JOptionPane.showMessageDialog(null, "Desktop not supported. Cannot open user guide.");
                    }
                }
            } else {
                JOptionPane.showMessageDialog(null, "Desktop not supported. Cannot open user guide.");
            }
        }
    });

}

From source file:de.adv_online.aaa.profiltool.ProfilDialog.java

public void actionPerformed(ActionEvent e) {
    if (startButton == e.getSource()) {
        startTransformation();//from w  w w .  java 2s. c  om
    } else if (e.getSource() == viewLogButton) {
        try {
            if (Desktop.isDesktopSupported())
                Desktop.getDesktop().open(logfile);
            else if (SystemUtils.IS_OS_WINDOWS)
                Runtime.getRuntime().exec("cmd /c start " + logfile.getPath());
            else
                Runtime.getRuntime().exec("open " + logfile.getPath());
        } catch (IOException e1) {
            e1.printStackTrace();
            System.exit(1);
        }
    } else if (e.getSource() == exitButton) {
        closeDialog();
    }
}

From source file:com.codejumble.opentube.Main.java

/**
 * Opens http://www.codejumble.com at System's default browser
 *
 * @param evt Swing event//from w  ww.j  a v a  2s  .c  om
 */
private void helpPagesItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpPagesItemActionPerformed
    try {
        URI uri = new URL("http://www.codejumble.com").toURI();
        Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
        if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
            try {
                desktop.browse(uri);
            } catch (Exception e) {
                createErrorDialog(this, e.getMessage(), "Error!");
            }
        }
    } catch (Exception ex) {
        createErrorDialog(this, ex.getMessage(), "Unexpected error");
    }
}

From source file:convcao.com.agent.ConvcaoNeptusInteraction.java

private void jLabel1MouseClicked(MouseEvent evt) throws URISyntaxException, IOException {
    if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();

        if (desktop.isSupported(Desktop.Action.BROWSE)) {
            URI uri = new URI("http://www.noptilus-fp7.eu/default.asp?node=page&id=321&lng=2");
            desktop.browse(uri);/*  w w  w.j a  v  a  2s.co m*/
        }
    }
}

From source file:nl.mvdr.umvc3replayanalyser.controller.Umvc3ReplayManagerController.java

/** Handles the case where the user clicks the Open video button. */
@FXML/*  ww w .j  a  va  2s  .c  om*/
private void handleOpenVideoAction() {
    log.info("Open video button clicked.");

    Replay selectedReplay = replayTableView.getSelectionModel().getSelectedItem();
    if (selectedReplay == null) {
        throw new IllegalStateException("No replay selected; open video button should have been disabled!");
    }

    if (Desktop.isDesktopSupported()) {
        String videoFilePath = FilenameUtils.normalize(this.configuration.getDataDirectory().getAbsolutePath()
                + FileUtils.SEPARATOR + selectedReplay.getVideoLocation());
        log.info("Playing video: " + videoFilePath);
        File videoFile = new File(videoFilePath);
        try {
            Desktop.getDesktop().open(videoFile);
        } catch (IOException | IllegalArgumentException e) {
            log.error("Unable to play video for replay: " + selectedReplay, e);
            // Show an error message to the user.
            String errorMessage = "Unable to play video for game: "
                    + selectedReplay.getGame().getDescription(false);
            if (e.getMessage() != null) {
                errorMessage = errorMessage + " " + e.getMessage();
            }
            ErrorMessagePopup.show("Unable to play video", errorMessage, e);
        }
    } else {
        log.error("Unable to play video, desktop not supported!");
        // Show an error message to the user.
        ErrorMessagePopup.show("Unable to play video", "Unable to play video files.", null);
    }
}