Example usage for java.awt Desktop getDesktop

List of usage examples for java.awt Desktop getDesktop

Introduction

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

Prototype

public static synchronized Desktop getDesktop() 

Source Link

Document

Returns the Desktop instance of the current desktop context.

Usage

From source file:ch.algotrader.simulation.SimulationExecutorImpl.java

private void reportStatisticsToFile(SimulationResultVO resultVO) {

    if (!this.commonConfig.isDisableReports()) {

        try {/*ww  w.j av a2 s.c o  m*/

            File reportLocation = this.commonConfig.getReportLocation();
            File reportFile = new File(reportLocation != null ? reportLocation : new File("."),
                    "BackTestReport.csv");
            BackTestReport backTestReport = new BackTestReport(reportFile);

            backTestReport.write("dateTime", DateTimePatterns.LOCAL_DATE_TIME.format(LocalDateTime.now()));
            backTestReport.write("executionTime", resultVO.getMins());
            backTestReport.write("dataSet", this.commonConfig.getDataSet());

            if (resultVO.getAllTrades().getCount() == 0) {
                backTestReport.write("allTradesCount", 0);
                backTestReport.close();
                return;
            }

            double netLiqValue = resultVO.getNetLiqValue();
            backTestReport.write("netLiqValue", twoDigitFormat.format(netLiqValue));

            // monthlyPerformances
            Collection<PeriodPerformanceVO> monthlyPerformances = resultVO.getMonthlyPerformances();
            double maxDrawDownM = 0d;
            double bestMonthlyPerformance = Double.NEGATIVE_INFINITY;
            int positiveMonths = 0;
            int negativeMonths = 0;
            if ((monthlyPerformances != null)) {
                for (PeriodPerformanceVO monthlyPerformance : monthlyPerformances) {
                    maxDrawDownM = Math.min(maxDrawDownM, monthlyPerformance.getValue());
                    bestMonthlyPerformance = Math.max(bestMonthlyPerformance, monthlyPerformance.getValue());
                    if (monthlyPerformance.getValue() > 0) {
                        positiveMonths++;
                    } else {
                        negativeMonths++;
                    }
                }
            }

            // yearlyPerformances
            int positiveYears = 0;
            int negativeYears = 0;
            Collection<PeriodPerformanceVO> yearlyPerformances = resultVO.getYearlyPerformances();
            if ((yearlyPerformances != null)) {
                for (PeriodPerformanceVO yearlyPerformance : yearlyPerformances) {
                    if (yearlyPerformance.getValue() > 0) {
                        positiveYears++;
                    } else {
                        negativeYears++;
                    }
                }
            }

            if ((monthlyPerformances != null)) {
                backTestReport.write("posMonths", positiveMonths);
                backTestReport.write("negMonths", negativeMonths);
                if ((yearlyPerformances != null)) {
                    backTestReport.write("posYears", positiveYears);
                    backTestReport.write("negYears", negativeYears);
                }
            }

            PerformanceKeysVO performanceKeys = resultVO.getPerformanceKeys();
            MaxDrawDownVO maxDrawDownVO = resultVO.getMaxDrawDown();
            if (performanceKeys != null && maxDrawDownVO != null) {
                backTestReport.write("avgM", performanceKeys.getAvgM());
                backTestReport.write("stdM", performanceKeys.getStdM());
                backTestReport.write("avgY", performanceKeys.getAvgY());
                backTestReport.write("stdY", performanceKeys.getStdY());
                backTestReport.write("sharpeRatio", performanceKeys.getSharpeRatio());

                backTestReport.write("maxMonthlyDrawDown", -maxDrawDownM);
                backTestReport.write("bestMonthlyPerformance", bestMonthlyPerformance);
                backTestReport.write("maxDrawDown", maxDrawDownVO.getAmount());
                backTestReport.write("maxDrawDownPeriod", maxDrawDownVO.getPeriod() / 86400000);
                backTestReport.write("colmarRatio", performanceKeys.getAvgY() / maxDrawDownVO.getAmount());
            }

            reportTrades(backTestReport, "winningTrades", resultVO.getWinningTrades(),
                    resultVO.getAllTrades().getCount());
            reportTrades(backTestReport, "losingTrades", resultVO.getLoosingTrades(),
                    resultVO.getAllTrades().getCount());
            reportTrades(backTestReport, "allTrades", resultVO.getAllTrades(),
                    resultVO.getAllTrades().getCount());

            backTestReport.write("returns");
            if ((monthlyPerformances != null)) {
                for (PeriodPerformanceVO monthlyPerformance : monthlyPerformances) {
                    backTestReport.write(
                            DateTimePatterns.LOCAL_DATE
                                    .format(DateTimeLegacy.toLocalDate(monthlyPerformance.getDate())),
                            monthlyPerformance.getValue());
                }
            }

            backTestReport.close();

            // make sure BackTestReport.xlsx exists
            File excelReportFile = new File(reportLocation != null ? reportLocation : new File("."),
                    "BackTestReport.xlsm");
            if (!excelReportFile.exists()) {
                InputStream is = getClass().getResourceAsStream("/BackTestReport.xlsm");
                FileUtils.copyInputStreamToFile(is, excelReportFile);
            }

            if (this.commonConfig.isOpenBackTestReport()) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().open(excelReportFile);
                    } catch (IOException e) {
                        // no application registered to .xlsm files
                        RESULT_LOGGER.info("BackTestReport available at: " + excelReportFile);
                    }
                } else {
                    RESULT_LOGGER.info("BackTestReport available at: " + excelReportFile);
                }
            }

        } catch (IOException ex) {
            LOGGER.error(ex.getMessage(), ex);
        }
    }
}

From source file:com.edduarte.protbox.core.registry.PReg.java

public void openExplorerFolder(FolderOption folderToOpen) throws IOException {
    String path = "";
    if (folderToOpen.equals(FolderOption.SHARED))
        path = pair.getSharedFolderPath();
    else if (folderToOpen.equals(FolderOption.PROT))
        path = pair.getProtFolderPath();

    if (SystemUtils.IS_OS_WINDOWS) {
        Runtime.getRuntime().exec("explorer " + path);

    } else if (SystemUtils.IS_OS_MAC_OSX) {
        Runtime.getRuntime().exec("open " + path);

    } else {/* w  w  w .  ja  va 2s . c  om*/
        if (Desktop.isDesktopSupported()) {
            Desktop.getDesktop().open(new File(path));
        }
    }
}

From source file:org.jajuk.util.UtilSystem.java

/**
 * Opens a directory with the associated explorer program. <li>Start by trying
 * to open the directory with any provided explorer path</li> <li>Then, try to
 * use the JDIC Desktop class if supported by the platform</li>
 * //from   www  . ja  va  2s.c o  m
 * Inspired from an aTunes method
 * 
 * @param directory 
 */
public static void openInExplorer(File directory) {
    final File directoryToOpen;
    /*
     * Needed for UNC filenames with spaces -> http://bugs.sun.com/view_bug.do?bug_id=6550588
     */
    if (isUnderWindows()) {
        String shortPath = getShortPathNameW(directory.getAbsolutePath());
        // If shortnames conversion doesn't work, try the initial path
        if (shortPath == null || !new File(shortPath).exists()) {
            directoryToOpen = directory;
        } else {
            directoryToOpen = new File(shortPath);
        }
    } else {
        directoryToOpen = directory;
    }
    // Try to open the location using the forced explorer path of provided
    if (StringUtils.isNotBlank(Conf.getString(Const.CONF_EXPLORER_PATH))) {
        new Thread("Explorer Open Thread 1") {
            @Override
            public void run() {
                try {
                    ProcessBuilder pb = new ProcessBuilder(Conf.getString(Const.CONF_EXPLORER_PATH),
                            directoryToOpen.getAbsolutePath());
                    pb.start();
                } catch (Exception e) {
                    Log.error(e);
                    Messages.showErrorMessage(179, directoryToOpen.getAbsolutePath());
                }
            }
        }.start();
    }
    // Try to open the location using the JDIC/JDK Desktop.open method
    // This is not supported on some platforms (Linux/XFCE for ie)
    else if (Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
        new Thread("Explorer Open Thread 2") {
            @Override
            public void run() {
                try {
                    Desktop.getDesktop().open(directoryToOpen);
                } catch (Exception e) {
                    Log.error(e);
                    Messages.showErrorMessage(179, directoryToOpen.getAbsolutePath());
                }
            }
        }.start();
    }
    // Else, display a warning message: we don't support this platform
    else {
        Messages.showErrorMessage(179);
    }
}

From source file:gtu._work.ui.DirectoryCompareUI.java

private void openFile(File file) {
    if (!file.exists()) {
        JCommonUtil._jOptionPane_showMessageDialog_error("?!");
        return;//from www . j  a  va2 s .c o  m
    }
    try {
        Desktop.getDesktop().browse(file.toURI());
    } catch (IOException e1) {
        JCommonUtil.handleException(e1, false);
    }
}

From source file:org.agmip.ui.afsirs.frames.SWFrame.java

private void jButtonMapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMapActionPerformed
    // TODO add your handling code here:
    try {/*from w w  w  .  j a va  2 s  .  c o  m*/

        String siteName = utils.getSITE();
        //siteName = siteName.replaceFirst(".txt", "");
        Desktop.getDesktop().browse(new URL("http://abe.ufl.edu/bmpmodel/Shivam/v3_shivam_jin/index.html?site="
                + siteName + "&unit=" + utils.getUNIT() + "#").toURI());
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:se.llbit.chunky.renderer.ui.RenderControls.java

private JPanel buildGeneralPane() {
    JLabel canvasSizeLbl = new JLabel("Canvas size:");
    JLabel canvasSizeAdvisory = new JLabel("Note: Actual image size may not be the same as the window size!");

    canvasSizeCB.setEditable(true);//from  w w w.java 2s .  co m
    canvasSizeCB.addItem("400x400");
    canvasSizeCB.addItem("1024x768");
    canvasSizeCB.addItem("960x540");
    canvasSizeCB.addItem("1920x1080");
    canvasSizeCB.addActionListener(canvasSizeListener);
    final JTextField canvasSizeEditor = (JTextField) canvasSizeCB.getEditor().getEditorComponent();
    canvasSizeEditor.addFocusListener(new FocusListener() {
        @Override
        public void focusLost(FocusEvent e) {
        }

        @Override
        public void focusGained(FocusEvent e) {
            canvasSizeEditor.selectAll();
        }
    });

    updateCanvasSizeField();

    loadSceneBtn.setText("Load Scene");
    loadSceneBtn.setIcon(Icon.load.imageIcon());
    loadSceneBtn.addActionListener(loadSceneListener);

    JButton loadSelectedChunksBtn = new JButton("Load Selected Chunks");
    loadSelectedChunksBtn.setToolTipText("Load the chunks that are currently selected in the map view");
    loadSelectedChunksBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            sceneMan.loadChunks(chunky.getWorld(), chunky.getSelectedChunks());
        }
    });

    JButton reloadChunksBtn = new JButton("Reload Chunks");
    reloadChunksBtn.setIcon(Icon.reload.imageIcon());
    reloadChunksBtn.setToolTipText("Reload all chunks in the scene");
    reloadChunksBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            sceneMan.reloadChunks();
        }
    });

    openSceneDirBtn.setText("Open Scene Directory");
    openSceneDirBtn.setToolTipText("Open the directory where Chunky stores scene descriptions and renders");
    openSceneDirBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {
                if (Desktop.isDesktopSupported()) {
                    Desktop.getDesktop().open(context.getSceneDirectory());
                }
            } catch (IOException e) {
                Log.warn("Failed to open scene directory", e);
            }
        }
    });
    openSceneDirBtn.setVisible(Desktop.isDesktopSupported());

    loadSceneBtn.setToolTipText("This replaces the current scene!");
    JButton setCanvasSizeBtn = new JButton("Apply");
    setCanvasSizeBtn.setToolTipText("Set the canvas size to the value in the field");
    setCanvasSizeBtn.addActionListener(canvasSizeListener);

    JButton halveCanvasSizeBtn = new JButton("Halve");
    halveCanvasSizeBtn.setToolTipText("Halve the canvas width and height");
    halveCanvasSizeBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int width = renderMan.scene().canvasWidth() / 2;
            int height = renderMan.scene().canvasHeight() / 2;
            setCanvasSize(width, height);
        }
    });
    JButton doubleCanvasSizeBtn = new JButton("Double");
    doubleCanvasSizeBtn.setToolTipText("Double the canvas width and height");
    doubleCanvasSizeBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int width = renderMan.scene().canvasWidth() * 2;
            int height = renderMan.scene().canvasHeight() * 2;
            setCanvasSize(width, height);
        }
    });

    JButton makeDefaultBtn = new JButton("Make Default");
    makeDefaultBtn.setToolTipText("Make the current canvas size the default");
    makeDefaultBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            PersistentSettings.set3DCanvasSize(renderMan.scene().canvasWidth(),
                    renderMan.scene().canvasHeight());
        }
    });

    JSeparator sep1 = new JSeparator();
    JSeparator sep2 = new JSeparator();

    biomeColorsCB.setText("enable biome colors");
    updateBiomeColorsCB();

    saveDumpsCB.setText("save dump once every ");
    saveDumpsCB.addActionListener(saveDumpsListener);
    updateSaveDumpsCheckBox();

    String[] frequencyStrings = new String[dumpFrequencies.length];
    for (int i = 0; i < dumpFrequencies.length; ++i) {
        frequencyStrings[i] = Integer.toString(dumpFrequencies[i]);
    }
    dumpFrequencyCB.setModel(new DefaultComboBoxModel(frequencyStrings));
    dumpFrequencyCB.setEditable(true);
    dumpFrequencyCB.addActionListener(dumpFrequencyListener);
    updateDumpFrequencyField();

    saveSnapshotsCB.addActionListener(saveSnapshotListener);
    updateSaveSnapshotCheckBox();

    yCutoff.update();

    JPanel panel = new JPanel();
    GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);
    layout.setHorizontalGroup(layout.createSequentialGroup().addContainerGap()
            .addGroup(layout.createParallelGroup()
                    .addGroup(layout.createSequentialGroup().addComponent(loadSceneBtn)
                            .addPreferredGap(ComponentPlacement.RELATED).addComponent(openSceneDirBtn))
                    .addGroup(layout.createSequentialGroup().addComponent(loadSelectedChunksBtn)
                            .addPreferredGap(ComponentPlacement.RELATED).addComponent(reloadChunksBtn))
                    .addComponent(sep1)
                    .addGroup(layout.createSequentialGroup().addComponent(canvasSizeLbl)
                            .addPreferredGap(ComponentPlacement.RELATED)
                            .addComponent(canvasSizeCB, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(ComponentPlacement.RELATED).addComponent(setCanvasSizeBtn)
                            .addPreferredGap(ComponentPlacement.RELATED).addComponent(makeDefaultBtn))
                    .addGroup(layout.createSequentialGroup().addComponent(halveCanvasSizeBtn)
                            .addPreferredGap(ComponentPlacement.RELATED).addComponent(doubleCanvasSizeBtn))
                    .addComponent(canvasSizeAdvisory).addComponent(sep2).addComponent(biomeColorsCB)
                    .addGroup(layout.createSequentialGroup().addComponent(saveDumpsCB)
                            .addComponent(dumpFrequencyCB, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(dumpFrequencyLbl).addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(saveSnapshotsCB).addGroup(yCutoff.horizontalGroup(layout)))
            .addContainerGap());
    layout.setVerticalGroup(layout.createSequentialGroup().addContainerGap()
            .addGroup(layout.createParallelGroup().addComponent(loadSceneBtn).addComponent(openSceneDirBtn))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(layout
                    .createParallelGroup().addComponent(loadSelectedChunksBtn).addComponent(reloadChunksBtn))
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addComponent(
                    sep1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(canvasSizeLbl)
                    .addComponent(canvasSizeCB, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addComponent(setCanvasSizeBtn).addComponent(makeDefaultBtn))
            .addPreferredGap(ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup().addComponent(halveCanvasSizeBtn)
                    .addComponent(doubleCanvasSizeBtn))
            .addPreferredGap(ComponentPlacement.RELATED).addComponent(canvasSizeAdvisory)
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addComponent(sep2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                    GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(biomeColorsCB)
            .addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(saveDumpsCB)
                    .addComponent(dumpFrequencyCB).addComponent(dumpFrequencyLbl))
            .addComponent(saveSnapshotsCB).addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(yCutoff.verticalGroup(layout)).addContainerGap());
    return panel;
}

From source file:Clavis.Windows.WShedule.java

public void createXLSDocument(String nome, String[][] valores) {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet(nome);
    HSSFRow row;//from   w w w.ja va 2s.com
    HSSFCell cell;
    for (int i = 0; i < valores.length; i++) {
        row = sheet.createRow(i);
        for (int j = 0; j < valores[i].length; j++) {
            cell = row.createCell(j);
            cell.setCellValue(valores[i][j]);
            if (valores[i][j] != null) {
                sheet.setColumnWidth(j, 255 * valores[i][j].length() + 4);
                CellUtil.setAlignment(cell, wb, CellStyle.ALIGN_CENTER);
            }
        }
    }
    wb.setPrintArea(0, 0, valores[0].length, 0, valores.length);
    sheet.getPrintSetup().setPaperSize(XSSFPrintSetup.A4_PAPERSIZE);
    FileOutputStream out;
    String sfile = new File("").getAbsolutePath() + System.getProperty("file.separator") + nome;
    File file = new File(sfile);
    if (!file.exists()) {
        try {
            file.createNewFile();
        } catch (IOException ex) {
            Logger.getLogger(WShedule.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    if (file.canWrite()) {
        try {
            out = new FileOutputStream(file);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(WShedule.class.getName()).log(Level.SEVERE, null, ex);
            out = null;
        }
        if (out != null) {
            try {
                wb.write(out);
                out.close();
                if (Desktop.isDesktopSupported()) {
                    Desktop.getDesktop().open(file);
                } else {
                    Components.MessagePane mensagem = new Components.MessagePane(this,
                            Components.MessagePane.INFORMACAO, painelcor, lingua.translate("Nota"), 400, 200,
                            lingua.translate("O documento \"doc.xls\" foi criado na pasta raiz do programa")
                                    + ".",
                            new String[] { lingua.translate("Voltar") });
                    mensagem.showMessage();
                }
            } catch (IOException ex) {
                Logger.getLogger(WShedule.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

From source file:Report_PRCR_New_EPF_Excel_File_Generator.java

private void view1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_view1ActionPerformed
    try {//from  w w  w . java  2 s . c  o m

        DatabaseManager dbm = DatabaseManager.getDbCon();
        Date_Handler dt = new Date_Handler();

        String year = yearfield.getText();
        String month = dt.return_month_as_num(monthfield.getText());

        String employee_detail_file_location = dbm.checknReturnData("file_locations", "id", "7", "location")
                + "/" + year + month + ".xls";
        System.out.println(employee_detail_file_location);
        copyFileUsingApacheCommonsIO(new File(dbm.checknReturnData("file_locations", "id", "6", "location")),
                new File(employee_detail_file_location));

        InputStream inp = new FileInputStream(employee_detail_file_location);

        Workbook wb = WorkbookFactory.create(inp);

        org.apache.poi.ss.usermodel.Sheet sheet = wb.getSheetAt(0);

        String payment_date_year_month_date = null;

        String table_name = "pr_workdata_" + year + "_" + month;

        String epf_backup_year_month = year + "_" + month;

        String previous_table_name = null;

        if (Integer.parseInt(month) == 1) {
            previous_table_name = "pr_workdata_" + (Integer.parseInt(year) - 1) + "_" + 12;
        } else {
            if ((Integer.parseInt(month) - 1) < 10) {
                previous_table_name = "pr_workdata_" + year + "_0" + (Integer.parseInt(month) - 1);
            } else {
                previous_table_name = "pr_workdata_" + year + "_" + (Integer.parseInt(month) - 1);
            }
        }

        double employee_contribution_percentage = Math.round(Double.parseDouble(
                dbm.checknReturnData("prcr_new_epf_details", "name", "employee_contribution", "value")) * 100.0)
                / 100.0;
        double employer_contribution_percentage = Math.round(Double.parseDouble(
                dbm.checknReturnData("prcr_new_epf_details", "name", "employer_contribution", "value")) * 100.0)
                / 100.0;

        String nic = null;
        String surname = null;
        String initials = null;
        int member_no = 0;
        double tot_contribution = 0;
        double employers_contribution = 0;
        double member_contribution = 0;
        double tot_earnings = 0;
        String member_status = null;
        String zone = null;
        int employer_number = 0;
        int contribution_period = 0;
        int data_submission_no = 0;
        double no_of_days_worked = 0;
        int occupation_classification_grade = 0;

        int payment_mode = 0;
        int payment_date = 0;
        String payment_reference = null;
        int d_o_code = 0;

        member_status = "E";
        zone = dbm.checknReturnData("prcr_new_epf_details", "name", "zone", "value");
        employer_number = Integer
                .parseInt(dbm.checknReturnData("prcr_new_epf_details", "name", "employer_number", "value"));
        contribution_period = Integer.parseInt(year + month);
        data_submission_no = 1;
        occupation_classification_grade = Integer.parseInt(dbm.checknReturnData("prcr_new_epf_details", "name",
                "occupation_classification_grade", "value"));

        int normal_days = 0;
        int sundays = 0;

        double ot_before = 0;
        double ot_after = 0;
        double hours_as_decimal = 0;

        int count = 0;
        double total_member_contribution = 0;
        int need_both_reports = 1;
        if (chk.isSelected()) {
            need_both_reports = 0;
        } else {
            need_both_reports = 1;
        }

        ResultSet query = dbm
                .query("SELECT * FROM `" + table_name + "` WHERE `register_or_casual` = 1 AND `total_pay` > 0");
        while (query.next()) {
            ResultSet query1 = dbm
                    .query("SELECT * FROM `personal_info` WHERE `code` = '" + query.getInt("code") + "' ");
            while (query1.next()) {

                nic = query1.getString("nic").replaceAll("\\s+", "");

                surname = split_name(query1.getString("name"))[1];
                initials = split_name(query1.getString("name"))[0];

                member_no = Integer.parseInt(query1.getString("code"));
                occupation_classification_grade = Integer.parseInt(query1.getString("occupation_grade"));

                tot_earnings = Math.round(query.getDouble("total_pay") * 100.0) / 100.0;

                if (dbm.checkWhetherDataExistsTwoColumns("prcr_epf_etf_backup", "month", epf_backup_year_month,
                        "code", member_no) == 1) {
                    tot_earnings = tot_earnings
                            + Double.parseDouble(dbm.checknReturnDatafor2checks("prcr_epf_etf_backup", "month",
                                    epf_backup_year_month, "code", member_no, "total_pay"));
                }

                employers_contribution = Math.round(tot_earnings * employer_contribution_percentage * 100.0)
                        / 100.0;
                member_contribution = Math.round(tot_earnings * employee_contribution_percentage * 100.0)
                        / 100.0;
                tot_contribution = employers_contribution + member_contribution;
                total_member_contribution = total_member_contribution + tot_contribution;

                normal_days = query.getInt("normal_days");
                sundays = query.getInt("sundays");
                ot_before = query.getDouble("ot_before_hours");
                ot_after = query.getDouble("ot_after_hours");
                if ((ot_before + ot_after) > 0) {
                    hours_as_decimal = (ot_before + ot_after) / 100;
                } else {
                    hours_as_decimal = 0;
                }
                if ((normal_days + sundays + hours_as_decimal) > 0) {
                    no_of_days_worked = Math.round((normal_days + sundays + hours_as_decimal) * 100.0) / 100.0;
                } else {
                    no_of_days_worked = 0;
                }

                if (dbm.checkWhetherDataExists(previous_table_name, "code", query1.getString("code")) == 1) {
                    member_status = "E";
                } else {
                    member_status = "N";
                }

                Row row = sheet.getRow(4 + count);
                if (row == null) {
                    row = sheet.createRow(4 + count);
                }

                for (int k = 0; k < 15; k++) {

                    Cell cell = row.getCell(k);

                    switch (k) {
                    case 0:
                        cell.setCellType(Cell.CELL_TYPE_STRING);
                        cell.setCellValue(nic);
                        break;
                    case 1:
                        cell.setCellType(Cell.CELL_TYPE_STRING);
                        cell.setCellValue(surname);
                        break;
                    case 2:
                        cell.setCellType(Cell.CELL_TYPE_STRING);
                        cell.setCellValue(initials);
                        break;
                    case 3:
                        cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                        cell.setCellValue(member_no);
                        break;
                    case 4:
                        cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                        cell.setCellValue(tot_contribution);
                        break;
                    case 5:
                        cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                        cell.setCellValue(employers_contribution);
                        break;
                    case 6:
                        cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                        cell.setCellValue(member_contribution);
                        break;
                    case 7:
                        cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                        cell.setCellValue(tot_earnings);
                        break;
                    case 8:
                        cell.setCellType(Cell.CELL_TYPE_STRING);
                        cell.setCellValue(member_status);
                        break;
                    case 9:
                        cell.setCellType(Cell.CELL_TYPE_STRING);
                        cell.setCellValue(zone);
                        break;
                    case 10:
                        cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                        cell.setCellValue(employer_number);
                        break;
                    case 11:
                        cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                        cell.setCellValue(contribution_period);
                        break;
                    case 12:
                        cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                        cell.setCellValue(data_submission_no);
                        break;
                    case 13:
                        cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                        cell.setCellValue(no_of_days_worked);
                        break;
                    case 14:
                        cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                        cell.setCellValue(occupation_classification_grade);
                        break;
                    default:
                        break;
                    }

                }
                count++;
            }
            query1.close();
        }
        query.close();

        FileOutputStream fileOut = new FileOutputStream(employee_detail_file_location);
        wb.write(fileOut);
        fileOut.close();

        Desktop.getDesktop().open(new File(employee_detail_file_location));

        if (need_both_reports == 1) {

            if (Integer.parseInt(dayfield.getText()) < 10) {
                payment_date_year_month_date = yearfield1.getText()
                        + dt.return_month_as_num(monthfield1.getText()) + "0" + dayfield.getText();
            } else {
                payment_date_year_month_date = yearfield1.getText()
                        + dt.return_month_as_num(monthfield1.getText()) + dayfield.getText();
            }
            payment_date = Integer.parseInt(payment_date_year_month_date);
            payment_mode = payment_mode_combo.getSelectedIndex() + 1;

            payment_reference = payment_referrence_textFiield.getText();

            d_o_code = Integer
                    .parseInt(dbm.checknReturnData("prcr_new_epf_details", "name", "d_o_code", "value"));

            String total_contribution_file_location = dbm.checknReturnData("file_locations", "id", "9",
                    "location") + "/" + year + month + "_total_contribution.xls";

            copyFileUsingApacheCommonsIO(
                    new File(dbm.checknReturnData("file_locations", "id", "8", "location")),
                    new File(total_contribution_file_location));

            InputStream inp2 = new FileInputStream(total_contribution_file_location);

            Workbook wb2 = WorkbookFactory.create(inp2);

            org.apache.poi.ss.usermodel.Sheet sheet2 = wb2.getSheetAt(0);

            Row row = sheet2.getRow(17);
            if (row == null) {
                row = sheet.createRow(17);
            }

            for (int k = 0; k < 10; k++) {

                Cell cell = row.getCell(k);

                switch (k) {
                case 0:
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    cell.setCellValue(zone);
                    break;
                case 1:
                    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                    cell.setCellValue(employer_number);
                    break;
                case 2:
                    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                    cell.setCellValue(contribution_period);
                    break;
                case 3:
                    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                    cell.setCellValue(data_submission_no);
                    break;
                case 4:
                    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                    cell.setCellValue(total_member_contribution);
                    break;
                case 5:
                    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                    cell.setCellValue(count);
                    break;
                case 6:
                    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                    cell.setCellValue(payment_mode);
                    break;
                case 7:
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    cell.setCellValue(payment_reference);
                    break;
                case 8:
                    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                    cell.setCellValue(payment_date);
                    break;
                case 9:
                    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                    cell.setCellValue(d_o_code);
                    break;
                default:
                    break;
                }

            }

            FileOutputStream fileOut2 = new FileOutputStream(total_contribution_file_location);
            wb2.write(fileOut2);
            fileOut2.close();

            Desktop.getDesktop().open(new File(total_contribution_file_location));

        }

    } catch (Exception ex) {
        System.out.println(ex);
        msg.showMessage(
                "Problem Occured.Check whether the Excel file is alredy opened.Please close it and try again..",
                "Error", "error");

    }
}

From source file:UserInfo_Frame.java

private void btn_openFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_openFileActionPerformed
    try {/*from  w ww .jav a  2s . c  o  m*/
        File Selection = new File(Jtreevar);
        if (Selection.exists()) {
            if (Desktop.isDesktopSupported()) {
                Desktop.getDesktop().open(Selection);
            } else {
                JOptionPane.showMessageDialog(this, "Awt Desktop is not supported", "Error",
                        JOptionPane.INFORMATION_MESSAGE);
            }
        } else {
            JOptionPane.showMessageDialog(this, "File does not exist", "Error",
                    JOptionPane.INFORMATION_MESSAGE);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.itemanalysis.jmetrik.gui.Jmetrik.java

private JMenuBar createMenuBar() {
    final JMenuBar menuBar = new JMenuBar();
    JMenuItem mItem = null;//from   w w w  .  j  a  va 2s . co  m
    String urlString;
    URL url;

    //============================================================================================
    // File Menu
    //============================================================================================
    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic('f');
    menuBar.add(fileMenu);

    urlString = "/org/tango-project/tango-icon-theme/16x16/actions/document-new.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconNew = new ImageIcon(url, "New");
    mItem = new JMenuItem(new NewTextFileAction("New", iconNew));
    fileMenu.add(mItem);

    urlString = "/org/tango-project/tango-icon-theme/16x16/actions/document-open.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconOpen = new ImageIcon(url, "Open");
    mItem = new JMenuItem(new OpenFileAction("Open...", iconOpen, new Integer(KeyEvent.VK_A)));
    fileMenu.add(mItem);

    urlString = "/org/tango-project/tango-icon-theme/16x16/actions/document-save.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconSave = new ImageIcon(url, "Save");
    mItem = new JMenuItem(new SaveAction("Save", iconSave, new Integer(KeyEvent.VK_S)));
    fileMenu.add(mItem);

    urlString = "/org/tango-project/tango-icon-theme/16x16/actions/document-save-as.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconSaveAs = new ImageIcon(url, "Save As");
    mItem = new JMenuItem(new SaveAsAction("Save As...", iconSaveAs));
    fileMenu.add(mItem);

    urlString = "/org/tango-project/tango-icon-theme/16x16/status/folder-visiting.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconClose = new ImageIcon(url, "Close All Tabs");
    mItem = new JMenuItem(new CloseAllTabsAction("Close All Tabs...", iconClose, new Integer(KeyEvent.VK_C)));
    fileMenu.add(mItem);

    fileMenu.addSeparator();

    urlString = "/org/tango-project/tango-icon-theme/16x16/actions/document-print.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconPrint = new ImageIcon(url, "Print");
    mItem = new JMenuItem(new PrintAction("Print...", iconPrint));
    fileMenu.add(mItem);

    fileMenu.addSeparator();

    //      exit menu item
    urlString = "/org/tango-project/tango-icon-theme/16x16/actions/system-log-out.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconExit = new ImageIcon(url, "Exit");
    mItem = new JMenuItem(new ExitAction("Exit", iconExit));
    fileMenu.add(mItem);

    //============================================================================================
    // Edit Menu
    //============================================================================================
    JMenu editMenu = new JMenu("Edit");
    editMenu.setMnemonic(KeyEvent.VK_E);

    urlString = "/org/tango-project/tango-icon-theme/16x16/actions/edit-cut.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconCut = new ImageIcon(url, "Cut");
    mItem = new JMenuItem(new DefaultEditorKit.CutAction());
    mItem.setText("Cut");
    mItem.setIcon(iconCut);
    mItem.setMnemonic(KeyEvent.VK_X);
    editMenu.add(mItem);

    urlString = "/org/tango-project/tango-icon-theme/16x16/actions/edit-copy.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconCopy = new ImageIcon(url, "Copy");
    mItem = new JMenuItem(new DefaultEditorKit.CopyAction());
    mItem.setText("Copy");
    mItem.setIcon(iconCopy);
    mItem.setMnemonic(KeyEvent.VK_C);
    editMenu.add(mItem);

    urlString = "/org/tango-project/tango-icon-theme/16x16/actions/edit-paste.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconPaste = new ImageIcon(url, "Paste");
    mItem = new JMenuItem(new DefaultEditorKit.PasteAction());
    mItem.setText("Paste");
    mItem.setIcon(iconPaste);
    mItem.setMnemonic(KeyEvent.VK_V);
    editMenu.add(mItem);

    editMenu.addSeparator();

    urlString = "/org/tango-project/tango-icon-theme/16x16/actions/edit-undo.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconUndo = new ImageIcon(url, "Undo");
    mItem = new JMenuItem(new UndoAction("Undo", iconUndo, new Integer(KeyEvent.VK_Z)));
    editMenu.add(mItem);

    urlString = "/org/tango-project/tango-icon-theme/16x16/actions/edit-redo.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconRedo = new ImageIcon(url, "Redo");
    mItem = new JMenuItem(new RedoAction("Redo", iconRedo, new Integer(KeyEvent.VK_Y)));
    editMenu.add(mItem);

    editMenu.addSeparator();

    urlString = "/org/tango-project/tango-icon-theme/16x16/categories/preferences-system.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconView = new ImageIcon(url, "Preferences");
    mItem = new JMenuItem("Preferences");
    mItem.setIcon(iconView);
    mItem.setToolTipText("Edit jMetrik preferences");
    mItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JmetrikPreferencesManager prefs = new JmetrikPreferencesManager();
            prefs.addPropertyChangeListener(new ErrorOccurredPropertyChangeListener());
            prefs.addPropertyChangeListener(statusBar.getStatusListener());
            JmetrikPreferencesDialog propDialog = new JmetrikPreferencesDialog(Jmetrik.this, prefs);
            //                propDialog.loadPreferences();
            propDialog.setVisible(true);
        }
    });
    editMenu.setMnemonic('e');
    editMenu.add(mItem);

    menuBar.add(editMenu);

    //============================================================================================
    // Log Menu
    //============================================================================================
    JMenu logMenu = new JMenu("Log");

    urlString = "/org/tango-project/tango-icon-theme/16x16/actions/document-properties.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconLog = new ImageIcon(url, "View Log");
    mItem = new JMenuItem(new ViewLogAction("View Log", iconLog));
    logMenu.setMnemonic('l');
    logMenu.add(mItem);

    urlString = "/org/tango-project/tango-icon-theme/16x16/mimetypes/text-x-generic.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconCommand = new ImageIcon(url, "Script Log");
    mItem = new JMenuItem(new ViewScriptLogAction("Script Log", iconCommand));
    logMenu.setMnemonic('c');
    logMenu.add(mItem);

    menuBar.add(logMenu);

    //============================================================================================
    // Manage Menu
    //============================================================================================
    JMenu manageMenu = new JMenu("Manage");
    manageMenu.setMnemonic('m');

    mItem = new JMenuItem("New Database...");//create db
    mItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            NewDatabaseDialog newDatabaseDialog = new NewDatabaseDialog(Jmetrik.this);
            newDatabaseDialog.setVisible(true);
            if (newDatabaseDialog.canRun()) {
                if (workspace == null) {
                    //                        workspace = new Workspace(workspaceTree, tabbedPane, dataTable, variableTable);
                    workspace = new Workspace(workspaceList, tabbedPane, dataTable, variableTable);
                    workspace.addPropertyChangeListener(statusBar.getStatusListener());
                    workspace.addPropertyChangeListener(new ErrorOccurredPropertyChangeListener());
                }
                workspace.runProcess(newDatabaseDialog.getCommand());
                //                    workspace.createDatabase(newDatabaseDialog.getCommand());
            }
        }
    });
    manageMenu.add(mItem);

    mItem = new JMenuItem("Open Database...");
    mItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            OpenDatabaseDialog openDbDialog = new OpenDatabaseDialog(Jmetrik.this, "Open");
            JList l = openDbDialog.getDatabaseList();
            workspace.setDatabaseListModel(l);
            openDbDialog.setVisible(true);
            if (openDbDialog.canRun()) {
                openWorkspace(openDbDialog.getDatabaseName());
            }
        }
    });
    manageMenu.add(mItem);

    urlString = "/org/tango-project/tango-icon-theme/16x16/actions/edit-delete.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconDelete = new ImageIcon(url, "Delete");
    mItem = new JMenuItem("Delete Database...");
    mItem.setIcon(iconDelete);
    mItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            OpenDatabaseDialog selectDialog = new OpenDatabaseDialog(Jmetrik.this, "Delete");
            JList l = selectDialog.getDatabaseList();
            workspace.setDatabaseListModel(l);
            selectDialog.setVisible(true);
            if (selectDialog.canRun()) {
                int answer = JOptionPane.showConfirmDialog(Jmetrik.this,
                        "Do you want to delete " + selectDialog.getDatabaseName()
                                + " and all of its contents? \n"
                                + "All data will be permanently deleted. You cannot undo this action.",
                        "Delete Database", JOptionPane.WARNING_MESSAGE, JOptionPane.YES_NO_OPTION);

                if (answer == JOptionPane.YES_OPTION) {
                    DatabaseCommand command = new DatabaseCommand();
                    DatabaseName dbName = new DatabaseName(selectDialog.getDatabaseName());
                    command.getFreeOption("name").add(dbName.getName());
                    command.getSelectOneOption("action").setSelected("delete-db");

                    DatabaseName currentDb = workspace.getDatabaseName();
                    if (currentDb.getName().equals(dbName.getName())) {
                        JOptionPane.showMessageDialog(Jmetrik.this,
                                "You cannot delete the current database.\n"
                                        + "Close the database before attempting to delete it.",
                                "Database Delete Error", JOptionPane.WARNING_MESSAGE);
                    } else {
                        workspace.runProcess(command);
                    }

                }

            }
        }
    });
    manageMenu.add(mItem);

    manageMenu.addSeparator();

    urlString = "/org/tango-project/tango-icon-theme/16x16/apps/accessories-text-editor.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconDesc = new ImageIcon(url, "Descriptions");
    mItem = new JMenuItem("Table Descriptions...");
    mItem.setIcon(iconDesc);
    mItem.addActionListener(new TableDescriptionActionListener());
    manageMenu.add(mItem);

    urlString = "/org/tango-project/tango-icon-theme/16x16/actions/list-add.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconImport = new ImageIcon(url, "Import");
    mItem = new JMenuItem("Import Data...");
    mItem.setIcon(iconImport);
    mItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (workspace.databaseOpened()) {
                ImportDialog importDialog = new ImportDialog(Jmetrik.this, workspace.getDatabaseName(),
                        importExportPath);
                importDialog.setVisible(true);

                if (importDialog.canRun()) {
                    importExportPath = importDialog.getCurrentDirectory();
                    workspace.runProcess(importDialog.getCommand());
                }
            } else {
                JOptionPane.showMessageDialog(Jmetrik.this, "You must open a database before importing data.",
                        "No Open Database", JOptionPane.ERROR_MESSAGE);
            }

        }
    });
    manageMenu.add(mItem);

    urlString = "/org/tango-project/tango-icon-theme/16x16/actions/format-indent-less.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconExport = new ImageIcon(url, "Export");
    mItem = new JMenuItem("Export Data...");
    mItem.setIcon(iconExport);
    mItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            DataTableName tableName = (DataTableName) workspaceList.getSelectedValue();
            if (!workspace.databaseOpened()) {
                JOptionPane.showMessageDialog(Jmetrik.this, "You must open a database before exporting data.",
                        "No Open Database", JOptionPane.ERROR_MESSAGE);
            } else if (tableName == null) {
                JOptionPane.showMessageDialog(Jmetrik.this,
                        "You must select a table in the workspace list. \n "
                                + "Select a table to continue the export.",
                        "No Table Selected", JOptionPane.ERROR_MESSAGE);
            } else {
                ExportDataDialog exportDialog = new ExportDataDialog(Jmetrik.this, workspace.getDatabaseName(),
                        tableName, importExportPath);
                if (exportDialog.canRun()) {
                    importExportPath = exportDialog.getCurrentDirectory();
                    workspace.runProcess(exportDialog.getCommand());
                }
            }
        }
    });
    manageMenu.add(mItem);

    urlString = "/org/tango-project/tango-icon-theme/16x16/actions/edit-delete.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconDeleteTable = new ImageIcon(url, "Delete");
    mItem = new JMenuItem("Delete Table...");
    mItem.setIcon(iconDeleteTable);
    mItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (workspace.databaseOpened()) {
                DeleteTableDialog deleteDialog = new DeleteTableDialog(Jmetrik.this,
                        workspace.getDatabaseName(), (SortedListModel<DataTableName>) workspaceList.getModel());
                deleteDialog.setVisible(true);
                if (deleteDialog.canRun()) {
                    int nSelected = deleteDialog.getNumberOfSelectedTables();
                    int answer = JOptionPane.NO_OPTION;
                    if (nSelected > 1) {
                        answer = JOptionPane.showConfirmDialog(Jmetrik.this,
                                "Do you want to delete these " + nSelected + " tables? \n"
                                        + "All data will be permanently deleted. You cannot undo this action.",
                                "Delete Database", JOptionPane.WARNING_MESSAGE, JOptionPane.YES_NO_OPTION);
                    } else {
                        ArrayList<DataTableName> dList = deleteDialog.getSelectedTables();
                        answer = JOptionPane.showConfirmDialog(Jmetrik.this,
                                "Do you want to delete the table " + dList.get(0).getTableName() + "? \n"
                                        + "All data will be permanently deleted. You cannot undo this action.",
                                "Delete Database", JOptionPane.WARNING_MESSAGE, JOptionPane.YES_NO_OPTION);
                    }
                    if (answer == JOptionPane.YES_OPTION) {
                        workspace.runProcess(deleteDialog.getCommand());
                    }

                }
            } else {
                JOptionPane.showMessageDialog(Jmetrik.this, "You must open a database before deleting a table.",
                        "No Open Database", JOptionPane.ERROR_MESSAGE);
            }

        }
    });
    manageMenu.add(mItem);

    manageMenu.addSeparator();

    SubsetCasesProcess subsetCasesProcess = new SubsetCasesProcess();
    subsetCasesProcess.addMenuItem(Jmetrik.this, manageMenu, dialogs, workspace, workspaceList);

    SubsetVariablesProcess subsetVariablesProcess = new SubsetVariablesProcess();
    subsetVariablesProcess.addMenuItem(Jmetrik.this, manageMenu, dialogs, workspace, workspaceList);

    urlString = "/org/tango-project/tango-icon-theme/16x16/actions/edit-delete.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconDeleteVariables = new ImageIcon(url, "Delete Variables");
    mItem = new JMenuItem("Delete Variables...");
    mItem.setIcon(iconDeleteVariables);
    mItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            DataTableName tableName = (DataTableName) workspaceList.getSelectedValue();
            if (!workspace.databaseOpened()) {
                JOptionPane.showMessageDialog(Jmetrik.this, "You must open a database before subsetting data.",
                        "No Open Database", JOptionPane.ERROR_MESSAGE);
            } else if (tableName == null) {
                JOptionPane.showMessageDialog(Jmetrik.this,
                        "You must select a table in the workspace list. \n " + "Select a table to continue.",
                        "No Table Selected", JOptionPane.ERROR_MESSAGE);
            } else if (workspace.tableOpen()) {
                DeleteVariableDialog deleteVariableDialog = new DeleteVariableDialog(Jmetrik.this,
                        workspace.getDatabaseName(), workspace.getCurrentDataTable(), workspace.getVariables());
                deleteVariableDialog.setVisible(true);
                if (deleteVariableDialog.canRun()) {
                    int nSelected = deleteVariableDialog.getNumberOfSelectedVariables();
                    int answer = JOptionPane.NO_OPTION;
                    if (nSelected > 1) {
                        answer = JOptionPane.showConfirmDialog(Jmetrik.this,
                                "Do you want to delete these " + nSelected + " variables? \n"
                                        + "All data will be permanently deleted. You cannot undo this action.",
                                "Delete Variables", JOptionPane.WARNING_MESSAGE, JOptionPane.YES_NO_OPTION);
                    } else {
                        VariableAttributes v = deleteVariableDialog.getSelectedVariable();
                        answer = JOptionPane.showConfirmDialog(Jmetrik.this,
                                "Do you want to delete the variable " + v.getName().toString() + "? \n"
                                        + "All data will be permanently deleted. You cannot undo this action.",
                                "Delete Database", JOptionPane.WARNING_MESSAGE, JOptionPane.YES_NO_OPTION);
                    }
                    if (answer == JOptionPane.YES_OPTION) {
                        workspace.runProcess(deleteVariableDialog.getCommand());
                    }
                }
            }

        }
    });
    manageMenu.add(mItem);

    menuBar.add(manageMenu);

    //============================================================================================
    // Transform Menu
    //============================================================================================
    JMenu transformMenu = new JMenu("Transform");
    transformMenu.setMnemonic('t');

    BasicScoringProcess basicScoringProcess = new BasicScoringProcess();
    basicScoringProcess.addMenuItem(Jmetrik.this, transformMenu, dialogs, workspace, workspaceList);

    ScoringProcess scoringProcess = new ScoringProcess();
    scoringProcess.addMenuItem(Jmetrik.this, transformMenu, dialogs, workspace, workspaceList);

    transformMenu.addSeparator();

    RankingProcess rankingProcess = new RankingProcess();
    rankingProcess.addMenuItem(Jmetrik.this, transformMenu, dialogs, workspace, workspaceList);

    TestScalingProcess testScalingProcess = new TestScalingProcess();
    testScalingProcess.addMenuItem(Jmetrik.this, transformMenu, dialogs, workspace, workspaceList);

    LinearTransformationProcess linearTransformationProcess = new LinearTransformationProcess();
    linearTransformationProcess.addMenuItem(Jmetrik.this, transformMenu, dialogs, workspace, workspaceList);

    transformMenu.addSeparator();

    IrtLinkingProcess irtLinkingProcess = new IrtLinkingProcess();
    irtLinkingProcess.addMenuItem(Jmetrik.this, transformMenu, dialogs, workspace, workspaceList);

    IrtEquatingProcess irtEquatingProcess = new IrtEquatingProcess();
    irtEquatingProcess.addMenuItem(Jmetrik.this, transformMenu, dialogs, workspace, workspaceList);

    menuBar.add(transformMenu);

    //============================================================================================
    // Analyze Menu
    //============================================================================================
    JMenu analyzeMenu = new JMenu("Analyze");
    analyzeMenu.setMnemonic('a');

    FrequencyProcess frequencyProcess = new FrequencyProcess();
    frequencyProcess.addMenuItem(Jmetrik.this, analyzeMenu, dialogs, workspace, workspaceList);

    DescriptiveProcess descriptiveProcess = new DescriptiveProcess();
    descriptiveProcess.addMenuItem(Jmetrik.this, analyzeMenu, dialogs, workspace, workspaceList);

    CorrelationProcess correlationProcess = new CorrelationProcess();
    correlationProcess.addMenuItem(Jmetrik.this, analyzeMenu, dialogs, workspace, workspaceList);

    analyzeMenu.addSeparator();

    ItemAnalysisProcess itemAnalysisProcess = new ItemAnalysisProcess();
    itemAnalysisProcess.addMenuItem(Jmetrik.this, analyzeMenu, dialogs, workspace, workspaceList);

    CmhProcess cmhProcess = new CmhProcess();
    cmhProcess.addMenuItem(Jmetrik.this, analyzeMenu, dialogs, workspace, workspaceList);

    analyzeMenu.addSeparator();

    RaschAnalysisProcess raschAnalysisProcess = new RaschAnalysisProcess();
    raschAnalysisProcess.addMenuItem(Jmetrik.this, analyzeMenu, dialogs, workspace, workspaceList);

    IrtItemCalibrationProcess irtItemCalibrationProcess = new IrtItemCalibrationProcess();
    irtItemCalibrationProcess.addMenuItem(Jmetrik.this, analyzeMenu, dialogs, workspace, workspaceList);

    IrtPersonScoringProcess irtPersonScoringProcess = new IrtPersonScoringProcess();
    irtPersonScoringProcess.addMenuItem(Jmetrik.this, analyzeMenu, dialogs, workspace, workspaceList);

    menuBar.add(analyzeMenu);

    //============================================================================================
    // Graph Menu
    //============================================================================================
    JMenu graphMenu = new JMenu("Graph");
    graphMenu.setMnemonic('g');

    BarChartProcess barchartProcess = new BarChartProcess();
    barchartProcess.addMenuItem(Jmetrik.this, graphMenu, dialogs, workspace, workspaceList);

    PieChartProcess piechartProcess = new PieChartProcess();
    piechartProcess.addMenuItem(Jmetrik.this, graphMenu, dialogs, workspace, workspaceList);

    graphMenu.addSeparator();

    HistogramProcess histogramProcess = new HistogramProcess();
    histogramProcess.addMenuItem(Jmetrik.this, graphMenu, dialogs, workspace, workspaceList);

    DensityProcess densityProcess = new DensityProcess();
    densityProcess.addMenuItem(Jmetrik.this, graphMenu, dialogs, workspace, workspaceList);

    LineChartProcess lineChartProcess = new LineChartProcess();
    lineChartProcess.addMenuItem(Jmetrik.this, graphMenu, dialogs, workspace, workspaceList);

    ScatterplotProcess scatterplotProcess = new ScatterplotProcess();
    scatterplotProcess.addMenuItem(Jmetrik.this, graphMenu, dialogs, workspace, workspaceList);

    graphMenu.addSeparator();

    NonparametricCurveProcess nonparametricCurveProcess = new NonparametricCurveProcess();
    nonparametricCurveProcess.addMenuItem(Jmetrik.this, graphMenu, dialogs, workspace, workspaceList);

    mItem = new JMenuItem("Irt Plot...");
    mItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            DataTableName tableName = (DataTableName) workspaceList.getSelectedValue();
            if (tableName == null) {
                JOptionPane.showMessageDialog(Jmetrik.this,
                        "You must open a database and select a table. \n "
                                + "Select a table to continue scoring.",
                        "No Table Selected", JOptionPane.ERROR_MESSAGE);
            } else {
                if (irtPlotDialog == null && workspace.tableOpen()) {

                    //Note that starting this dialog is different because variables
                    //names must be obtained from the rows of a table.

                    DatabaseAccessObject dao = workspace.getDatabaseFactory().getDatabaseAccessObject();

                    try {
                        ArrayList<VariableAttributes> tempVar = dao.getVariableAttributesFromColumn(
                                workspace.getConnection(), workspace.getCurrentDataTable(),
                                new VariableName("name"));
                        irtPlotDialog = new IrtPlotDialog(Jmetrik.this, workspace.getDatabaseName(), tableName,
                                tempVar, (SortedListModel<DataTableName>) workspaceList.getModel());
                    } catch (SQLException ex) {
                        logger.fatal(ex.getMessage(), ex);
                        firePropertyChange("error", "", "Error - Check log for details.");
                    }
                }
                if (irtPlotDialog != null)
                    irtPlotDialog.setVisible(true);
            }

            if (irtPlotDialog != null && irtPlotDialog.canRun()) {
                workspace.runProcess(irtPlotDialog.getCommand());
            }
        }
    });
    graphMenu.add(mItem);

    ItemMapProcess itemMapProcess = new ItemMapProcess();
    itemMapProcess.addMenuItem(Jmetrik.this, graphMenu, dialogs, workspace, workspaceList);

    menuBar.add(graphMenu);

    //============================================================================================
    // Command Menu
    //============================================================================================

    JMenu commandMenu = new JMenu("Commands");
    commandMenu.setMnemonic('c');
    mItem = new JMenuItem("Run command");
    mItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JScrollPane pain = (JScrollPane) tabbedPane.getSelectedComponent();
            JViewport vp = pain.getViewport();
            Component c = vp.getComponent(0);
            if (c instanceof JmetrikTextFile) {
                JmetrikTab tempTab = (JmetrikTab) tabbedPane.getTabComponentAt(tabbedPane.getSelectedIndex());
                JmetrikTextFile textFile = (JmetrikTextFile) c;
                workspace.runFromSyntax(textFile.getText());
            }
        }
    });
    commandMenu.add(mItem);

    mItem = new JMenuItem("Stop command");
    mItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            //add something
        }
    });
    mItem.setEnabled(false);
    commandMenu.add(mItem);

    mItem = new JMenuItem("Command Reference...");
    mItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            //add something
        }
    });
    mItem.setEnabled(false);
    commandMenu.add(mItem);

    menuBar.add(commandMenu);

    //============================================================================================
    // Help Menu
    //============================================================================================
    JMenu helpMenu = new JMenu("Help");
    helpMenu.setMnemonic('h');
    mItem = new JMenuItem("Quick Start Guide");
    mItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Desktop deskTop = Desktop.getDesktop();
            try {
                URI uri = new URI("http://www.itemanalysis.com/quick-start-guide.php");
                deskTop.browse(uri);
            } catch (URISyntaxException ex) {
                logger.fatal(ex.getMessage(), ex);
                firePropertyChange("error", "", "Error - Check log for details.");
            } catch (IOException ex) {
                logger.fatal(ex.getMessage(), ex);
                firePropertyChange("error", "", "Error - Check log for details.");
            }
        }
    });
    helpMenu.add(mItem);

    urlString = "/org/tango-project/tango-icon-theme/16x16/apps/help-browser.png";
    url = this.getClass().getResource(urlString);
    ImageIcon iconAbout = new ImageIcon(url, "About");
    mItem = new JMenuItem("About");
    mItem.setIcon(iconAbout);
    mItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JmetrikAboutDialog aboutDialog = new JmetrikAboutDialog(Jmetrik.this, APP_NAME, VERSION, AUTHOR,
                    RELEASE_DATE, COPYRIGHT_YEAR, BETA_VERSION);
            aboutDialog.setVisible(true);
        }
    });
    helpMenu.add(mItem);

    menuBar.add(helpMenu);

    return menuBar;
}