Example usage for javax.swing JOptionPane OK_CANCEL_OPTION

List of usage examples for javax.swing JOptionPane OK_CANCEL_OPTION

Introduction

In this page you can find the example usage for javax.swing JOptionPane OK_CANCEL_OPTION.

Prototype

int OK_CANCEL_OPTION

To view the source code for javax.swing JOptionPane OK_CANCEL_OPTION.

Click Source Link

Document

Type used for showConfirmDialog.

Usage

From source file:org.smart.migrate.ui.MigrateMain.java

private void popDeletePlanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_popDeletePlanActionPerformed
    ////w w w .j a  v  a 2 s  . c o m
    if (listPlan.getSelectedIndex() >= 0) {
        if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(rootPane,
                bundle.getString("MigrateMain.alert.confirmDeletePlan"), "Confirm",
                JOptionPane.OK_CANCEL_OPTION)) {
            MigratePlanIO.deletePlan((String) listPlan.getSelectedValue());
            initModel();
            if (listPlan.getModel().getSize() > 0) {
                listPlan.setSelectedIndex(listPlan.getModel().getSize() - 1);
                setSelectedMigratePlan();
            }
        }
    }

}

From source file:org.smart.migrate.ui.MigrateMain.java

private void btnDeleteTargetDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteTargetDataActionPerformed

    if (tblTableMapping.getSelectedRowCount() == 0) {
        JOptionPane.showMessageDialog(rootPane, bundle.getString("MigrateMain.alert.deleteTargetData"));
    } else {/* w w w  . ja v  a2  s  .  co  m*/
        if (JOptionPane.showConfirmDialog(rootPane,
                bundle.getString("MigrateMain.alert.confirmDeleteTargetData"),
                UIManager.getString("OptionPane.titleText"),
                JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {

            importManager.setMigratePlan(migratePlan);
            importManager.connectToDataBase(false, true);

            importManager.deleteTargetData(
                    (String) tblTableMapping.getValueAt(tblTableMapping.getSelectedRow(), 1),
                    edtDeleteWhere.getText());

            importManager.closeConnection();
            JOptionPane.showMessageDialog(rootPane, bundle.getString("MigrateMain.message.deleteTarget"));
        }

    }

}

From source file:org.smart.migrate.ui.MigrateMain.java

private void btnRollBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRollBackActionPerformed
    if (JOptionPane.showConfirmDialog(rootPane, bundle.getString("MigrateMain.alert.confirmRollback"),
            UIManager.getString("OptionPane.titleText"),
            JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
        currentThread.deleteImportedData();
    }/*w  w w .  jav a 2s  .c  o m*/

}

From source file:org.smart.migrate.ui.MigrateMain.java

private void btnDeleteRelationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteRelationActionPerformed
    ////from w  ww.ja  v  a  2  s  .  c  o m
    if (tblTableRelations.getSelectedRowCount() == 0) {
        JOptionPane.showMessageDialog(rootPane, bundle.getString("MigrateMain.alert.deleteRelation"));
    } else {
        if (JOptionPane.showConfirmDialog(rootPane, bundle.getString("MigrateMain.alert.confirmDeleteRelation"),
                UIManager.getString("OptionPane.titleText"),
                JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {

            String fkTable = (String) tblTableRelations.getValueAt(tblTableRelations.getSelectedRow(), 0);
            String pkTable = (String) tblTableRelations.getValueAt(tblTableRelations.getSelectedRow(), 2);

            TableRelation relation = SettingUtils.getRelationByPKTableAndFKTable(migratePlan, pkTable, fkTable);

            if (relation != null) {
                migratePlan.getSourceRelations().remove(relation);
                tblTableRelations.remove(tblTableRelations.getSelectedRow());
            }

            //                
            //                TableSetting tableSetting = migratePlan.getTableSettingBySourceTable(sourceTable);
            //                if (tableSetting!=null){
            //                    migratePlan.getTableSettings().remove(tableSetting);
            //                    tblTableMapping.remove(tblTableMapping.getSelectedRow());
            //                }
        }

    }
}

From source file:org.squidy.designer.zoom.ContainerShape.java

@Override
public void initializeLayout() {
    super.initializeLayout();

    final ImageButton startProcessing = new ImageButton(
            ActionShape.class.getResource("/images/24x24/media_play_green.png"), "Start");
    final ImageButton stopProcessing = new ImageButton(
            ActionShape.class.getResource("/images/24x24/media_stop_red.png"), "Stop");
    stopProcessing.setEnabled(false);/* ww w  . j  a v a2s .  c o  m*/

    startProcessing.addZoomActionListener(new ZoomActionListener() {

        /**
         * @param e
         */
        public void actionPerformed(ZoomActionEvent e) {

            new Thread() {

                /*
                 * (non-Javadoc)
                 * 
                 * @see java.lang.Thread#run()
                 */
                @Override
                public void run() {
                    if (!getProcessable().isProcessing()) {
                        startProcessing.setEnabled(false);
                        stopProcessing.setEnabled(true);
                        invalidatePaint();
                        ContainerShape.this.start();
                        ContainerShape.this.doStart();

                        Manager.get().notify(getProcessable(), Action.START);
                    }
                }
            }.start();
        }
    });

    stopProcessing.addZoomActionListener(new ZoomActionListener() {

        /**
         * @param e
         */
        public void actionPerformed(ZoomActionEvent e) {
            new Thread() {

                /*
                 * (non-Javadoc)
                 * 
                 * @see java.lang.Thread#run()
                 */
                @Override
                public void run() {
                    // if (getProcessable().isProcessing()) {
                    startProcessing.setEnabled(true);
                    stopProcessing.setEnabled(false);
                    invalidatePaint();
                    ContainerShape.this.stop();
                    ContainerShape.this.doStop();
                    // }

                    Manager.get().notify(getProcessable(), Action.STOP);
                }
            }.start();
        }
    });

    ImageButton delete = new ImageButton(ActionShape.class.getResource("/images/24x24/delete2.png"), "Delete");
    delete.addZoomActionListener(new ZoomActionListener() {

        /*
         * (non-Javadoc)
         * 
         * @see
         * org.squidy.designer.event.ZoomActionListener#actionPerformed
         * (org.squidy.designer.event.ZoomActionEvent)
         */
        public void actionPerformed(ZoomActionEvent e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Pressed delete on " + getBreadcrumb());
            }

            int option = JOptionPane.showConfirmDialog(Designer.getInstance(),
                    "Would you like to delete " + getTitle() + "?", "Delete?", JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.QUESTION_MESSAGE,
                    new ImageIcon(ActionShape.class.getResource("/images/delete.png")));

            if (option == JOptionPane.OK_OPTION) {
                ZoomShape<?> zoomShape = null;
                if (currentZoomState == ZoomState.ZOOM_IN && getParent() instanceof ZoomShape<?>) {
                    zoomShape = (ZoomShape<?>) getParent();
                }
                delete();
                if (zoomShape != null) {
                    zoomShape.animateToCenterView(e.getCamera());

                    // Set pipe shapes visible and pickable.
                    for (Object child : zoomShape.getChildrenReference()) {
                        if (child instanceof PipeShape) {
                            ShapeUtils.setApparent((PipeShape) child, true);
                        }
                    }
                }

                Manager.get().notify(getProcessable(), Action.DELETE);
            }
        }
    });

    ImageButton duplicate = new ImageButton(ActionShape.class.getResource("/images/24x24/copy.png"),
            "Duplicate");
    duplicate.addZoomActionListener(new ZoomActionListener() {

        /*
         * (non-Javadoc)
         * 
         * @see
         * org.squidy.designer.event.ZoomActionListener#actionPerformed
         * (org.squidy.designer.event.ZoomActionEvent)
         */
        public void actionPerformed(ZoomActionEvent e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Duplicate has been pressed for " + getBreadcrumb());
            }

            Manager.get().notify(getProcessable(), Action.DUPLICATE);
        }
    });
    duplicate.setEnabled(false);

    ImageButton publish = new ImageButton(ActionShape.class.getResource("/images/24x24/export2.png"),
            "Publish");
    publish.addZoomActionListener(new ZoomActionListener() {

        /*
         * (non-Javadoc)
         * 
         * @see
         * org.squidy.designer.event.ZoomActionListener#actionPerformed
         * (org.squidy.designer.event.ZoomActionEvent)
         */
        public void actionPerformed(ZoomActionEvent e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Publish has been pressed for " + getBreadcrumb());
            }

            Storable storable = ShapeUtils.getObjectInHierarchy(Storable.class, ContainerShape.this);
            if (storable != null) {
                storable.store();
            }
        }
    });
    publish.setEnabled(false);

    ImageButton update = new ImageButton(ActionShape.class.getResource("/images/24x24/import1.png"), "Update");
    update.addZoomActionListener(new ZoomActionListener() {

        /*
         * (non-Javadoc)
         * 
         * @see
         * org.squidy.designer.event.ZoomActionListener#actionPerformed
         * (org.squidy.designer.event.ZoomActionEvent)
         */
        public void actionPerformed(ZoomActionEvent e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Update has been pressed for " + getBreadcrumb());
            }
        }
    });
    update.setEnabled(false);

    addPropertyChangeListener(Processable.PROPERTY_PROCESSING, new PropertyChangeListener() {

        /*
        * (non-Javadoc)
        * 
        * 
        * 
        * @seejava.beans.PropertyChangeListener#propertyChange(java.
        * beans. PropertyChangeEvent)
        */
        public void propertyChange(PropertyChangeEvent evt) {
            startProcessing.setEnabled(!(Boolean) evt.getNewValue());
            stopProcessing.setEnabled((Boolean) evt.getNewValue());

            if ((Boolean) evt.getNewValue())
                doStart();
            else
                doStop();
        }
    });

    //      addPropertyChangeListener(Processable.PROPERTY_PROCESSING_STOP,
    //            new PropertyChangeListener() {
    //
    //               /*
    //                * (non-Javadoc)
    //                * 
    //                * 
    //                * 
    //                * @seejava.beans.PropertyChangeListener#propertyChange(java.
    //                * beans. PropertyChangeEvent)
    //                */
    //               public void propertyChange(PropertyChangeEvent evt) {
    //                  // startProcessing.setToggleState(ZoomToggle.RELEASED);
    //                  // stopProcessing.setToggleState(ZoomToggle.PRESSED);
    //                  startProcessing.setEnabled(true);
    //                  stopProcessing.setEnabled(false);
    //                  doStop();
    //               }
    //            });

    ShapeUtils.setApparent(startProcessing, false);
    ShapeUtils.setApparent(stopProcessing, false);
    if (!(this instanceof WorkspaceShape)) {
        ShapeUtils.setApparent(delete, false);
        ShapeUtils.setApparent(duplicate, false);
        ShapeUtils.setApparent(publish, false);
        ShapeUtils.setApparent(update, false);
    }

    addAction(startProcessing);
    addAction(stopProcessing);
    if (!(this instanceof WorkspaceShape)) {
        addAction(delete);
        addAction(duplicate);
        addAction(publish);
        addAction(update);
    }
}

From source file:org.tmpotter.ui.ActionHandler.java

/**
 * Save project as specified filename.//from  www .j  a  va  2  s.co  m
 */
private void saveProjectAs() {
    File outFile = new File(modelMediator.getProjectName().concat(".tmpx"));
    try {
        boolean save = false;
        boolean cancel = false;
        while (!save && !cancel) {
            final JFileChooser fc = new JFileChooser();
            FileNameExtensionFilter filter = new FileNameExtensionFilter("TMX File", "tmpx");
            fc.setFileFilter(filter);
            boolean nameOfUser = false;
            while (!nameOfUser) {
                fc.setLocation(230, 300);
                fc.setCurrentDirectory(RuntimePreferences.getUserHome());
                fc.setDialogTitle(getString("DLG.SAVEAS"));
                fc.setMultiSelectionEnabled(false);
                fc.setSelectedFile(outFile);
                fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
                RuntimePreferences.setUserHome(fc.getCurrentDirectory());
                int returnVal;
                returnVal = fc.showSaveDialog(parent);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    outFile = fc.getSelectedFile();
                    if (!outFile.getName().endsWith(".tmpx")) {
                        outFile = new File(outFile.getName().concat(".tmpx"));
                    }
                    nameOfUser = true;
                } else {
                    nameOfUser = true;
                    cancel = true;
                }
            }
            int selected;
            if (nameOfUser && !cancel) {
                if (outFile.exists()) {
                    final Object[] options = { getString("BTN.SAVE"), getString("BTN.CANCEL") };
                    selected = JOptionPane.showOptionDialog(parent, getString("MSG.FILE_EXISTS"),
                            getString("MSG.WARNING"), JOptionPane.OK_CANCEL_OPTION,
                            JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
                    if (selected == 0) {
                        save = true;
                    }
                } else {
                    save = true;
                }
            }
        }
        if (save) {
            cleanTmData();
            ProjectProperties prop = modelMediator.getProjectProperties();
            prop.setFilePathProject(outFile);
            TmxpWriter.writeTmxp(prop, tmData.getDocumentOriginal(), tmData.getDocumentTranslation());
        }
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(parent, JOptionPane.ERROR_MESSAGE);
    }
}

From source file:org.zaproxy.zap.authentication.FormBasedAuthenticationMethodType.java

/**
 * Gets the popup menu factory for flagging login requests.
 * /*www.  j a  v  a 2 s. com*/
 * @return the popup flag login request menu factory
 */
private PopupMenuItemSiteNodeContextMenuFactory getPopupFlagLoginRequestMenuFactory() {
    PopupMenuItemSiteNodeContextMenuFactory popupFlagLoginRequestMenuFactory = new PopupMenuItemSiteNodeContextMenuFactory(
            Constant.messages.getString("context.flag.popup")) {
        private static final long serialVersionUID = 8927418764L;

        @Override
        public PopupMenuItemContext getContextMenu(Context context, String parentMenu) {
            return new PopupMenuItemContext(context, parentMenu,
                    MessageFormat.format(
                            Constant.messages.getString("authentication.method.fb.popup.login.request"),
                            context.getName())) {

                private static final long serialVersionUID = 1967885623005183801L;
                private ExtensionUserManagement usersExtension;
                private Context uiSharedContext;

                /**
                 * Make sure the user acknowledges the Users corresponding to this context will
                 * be deleted.
                 * 
                 * @return true, if successful
                 */
                private boolean confirmUsersDeletion(Context uiSharedContext) {
                    usersExtension = (ExtensionUserManagement) Control.getSingleton().getExtensionLoader()
                            .getExtension(ExtensionUserManagement.NAME);
                    if (usersExtension != null) {
                        if (usersExtension.getSharedContextUsers(uiSharedContext).size() > 0) {
                            int choice = JOptionPane.showConfirmDialog(this,
                                    Constant.messages.getString("authentication.dialog.confirmChange.label"),
                                    Constant.messages.getString("authentication.dialog.confirmChange.title"),
                                    JOptionPane.OK_CANCEL_OPTION);
                            if (choice == JOptionPane.CANCEL_OPTION) {
                                return false;
                            }
                        }
                    }
                    return true;
                }

                @Override
                public void performAction(SiteNode sn) {
                    // Manually create the UI shared contexts so any modifications are done
                    // on an UI shared Context, so changes can be undone by pressing Cancel
                    SessionDialog sessionDialog = View.getSingleton().getSessionDialog();
                    sessionDialog.recreateUISharedContexts(Model.getSingleton().getSession());
                    uiSharedContext = sessionDialog.getUISharedContext(this.getContext().getIndex());

                    // Do the work/changes on the UI shared context
                    if (this.getContext().getAuthenticationMethod() instanceof FormBasedAuthenticationMethod) {
                        log.info(
                                "Selected new login request via PopupMenu. Changing existing Form-Based Authentication instance for Context "
                                        + getContext().getIndex());
                        FormBasedAuthenticationMethod method = (FormBasedAuthenticationMethod) uiSharedContext
                                .getAuthenticationMethod();

                        try {
                            method.setLoginRequest(sn);
                        } catch (Exception e) {
                            log.error("Failed to set login request: " + e.getMessage(), e);
                            return;
                        }

                        // Show the session dialog without recreating UI Shared contexts
                        View.getSingleton().showSessionDialog(Model.getSingleton().getSession(),
                                ContextAuthenticationPanel.buildName(this.getContext().getIndex()), false);
                    } else {
                        log.info(
                                "Selected new login request via PopupMenu. Creating new Form-Based Authentication instance for Context "
                                        + getContext().getIndex());
                        FormBasedAuthenticationMethod method = new FormBasedAuthenticationMethod();

                        try {
                            method.setLoginRequest(sn);
                        } catch (Exception e) {
                            log.error("Failed to set login request: " + e.getMessage(), e);
                            return;
                        }
                        if (!confirmUsersDeletion(uiSharedContext)) {
                            log.debug("Cancelled change of authentication type.");
                            return;
                        }
                        uiSharedContext.setAuthenticationMethod(method);

                        // Show the session dialog without recreating UI Shared contexts
                        // NOTE: First init the panels of the dialog so old users data gets
                        // loaded and just then delete the users
                        // from the UI data model, otherwise the 'real' users from the
                        // non-shared context would be loaded
                        // and would override any deletions made.
                        View.getSingleton().showSessionDialog(Model.getSingleton().getSession(),
                                ContextAuthenticationPanel.buildName(this.getContext().getIndex()), false,
                                new Runnable() {

                                    @Override
                                    public void run() {
                                        // Removing the users from the 'shared context' (the UI)
                                        // will cause their removal at
                                        // save as well
                                        if (usersExtension != null)
                                            usersExtension.removeSharedContextUsers(uiSharedContext);
                                    }
                                });
                    }
                }
            };
        }

        @Override
        public int getParentMenuIndex() {
            return 3;
        }
    };
    return popupFlagLoginRequestMenuFactory;
}

From source file:Panels.LocationPanel.java

public void locationFromInternetLabelMouseClicked(MouseEvent e) {
    try {/*from  www.j a  v a  2  s .  co  m*/
        if (getLocationFromIP()) {
            this.locationFromInternet.setEnabled(true);
            this.locationFromInternet.setIcon(locationfromInternetIcon);
            int result = JOptionPane.showConfirmDialog(null,
                    PropertiesHandler.getSingleton().getValue(1049) + " : " + country + "\n"
                            + PropertiesHandler.getSingleton().getValue(1050) + " : " + city + "\n"
                            + PropertiesHandler.getSingleton().getValue(1051) + " : " + longitude + "\n"
                            + PropertiesHandler.getSingleton().getValue(1052) + " : " + latitude + "\n"
                            + PropertiesHandler.getSingleton().getValue(1053) + " : " + timezone,
                    PropertiesHandler.getSingleton().getValue(1049) + "-"
                            + PropertiesHandler.getSingleton().getValue(1050) + "-"
                            + PropertiesHandler.getSingleton().getValue(1051) + "-"
                            + PropertiesHandler.getSingleton().getValue(1052),
                    JOptionPane.OK_CANCEL_OPTION);

            if (result == JOptionPane.OK_OPTION) {
                UserConfig.getSingleton().setCountry(country);
                UserConfig.getSingleton().setCity(city);
                UserConfig.getSingleton().setLongitude(longitude);
                UserConfig.getSingleton().setLatitude(latitude);
                UserConfig.getSingleton().setTimezone(timezone);

                countriesModel.add(0, country);
                citiesModel.add(0, city);

                citiesList.setSelectedIndex(0);
                countriesList.setSelectedIndex(0);

                XmlHandler.getSingleton().addUserConfig(UserConfig.getSingleton());

                longitudeValue.setText(longitude);
                latitudeValue.setText(latitude);
                timezoneValue.setText(timezone);
            } else {
                this.locationFromInternet.setEnabled(true);
                this.locationFromInternet.setIcon(locationfromInternetIcon);
            }
        } else {
            this.locationFromInternet.setEnabled(true);
            this.locationFromInternet.setIcon(locationfromInternetIcon);
            JOptionPane.showMessageDialog(null, PropertiesHandler.getSingleton().getValue(1104),
                    PropertiesHandler.getSingleton().getValue(1069), JOptionPane.ERROR_MESSAGE);
        }
    } catch (Exception ex) {
        this.locationFromInternet.setEnabled(true);
        this.locationFromInternet.setIcon(locationfromInternetIcon);
    }
}

From source file:parsegui.Window.java

private void buyTicketActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buyTicketActionPerformed
    int ticketCount = 0;
    long phone = 0;

    //eventList.setSelectedItem(evt);
    String festSelection = (String) eventList.getSelectedItem();

    String personName = (String) nameTextField.getText();
    String email = (String) mailTextField.getText();

    //ParseObject rel = new ParseObject("Attendee");
    ParseObject aObj = new ParseObject("Attendee");
    try {/*from   www  .  j  a va2  s  .c  om*/
        int length = String.valueOf(phoneTextField.getText()).length();
        if (length == 0 || length < 10 || length > 10) {
            JOptionPane.showConfirmDialog(null, "Please enter a valid 10 digit phone number", "Error",
                    JOptionPane.CLOSED_OPTION);
            return;
        } else {
            phone = Long.parseLong(phoneTextField.getText());

        }
        ticketCount = Integer.parseInt(ticketNoField.getText());
        if (ticketCount <= 0) {
            JOptionPane.showConfirmDialog(null, "Number of tickets should be atleast 1", "Error",
                    JOptionPane.CLOSED_OPTION);
            return;
        }

    } catch (NumberFormatException e) {
        System.out.println("Exception" + e);
        JOptionPane.showConfirmDialog(null, "Please fill all the fields", "Error", JOptionPane.CLOSED_OPTION);
        return;

    }

    int b = JOptionPane.showConfirmDialog(null, "Confirm " + ticketCount + " tickets", "Confirm",
            JOptionPane.OK_CANCEL_OPTION);

    if (b == 0) {
        System.out.println("Phone number: " + phone);
        System.out.println("number of tickets: " + ticketCount);
        System.out.println("name: " + personName);
        System.out.println("Email-ID: " + email);
        System.out.println("festival selected: " + festSelection);

        aObj.put("Name", personName);
        aObj.put("PhoneNo", phone);
        aObj.put("EmailID", email);

        aObj.put("Tickets_purchased", ticketCount);

        /* fest selection*/
        ParseQuery festquery = new ParseQuery("Festival");
        ParseObject festObj = new ParseObject("Festival");
        // String id = festObj.getString("Rockathon");// id = null.. should be in loop nd use list/array
        System.out.println(eventList.getSelectedItem());

        //festquery.whereEqualTo(festSelection, festObj.getString("Rockathon"));
        /*
         festquery.findInBackground(new FindCallback() {
                
         @Override
         public void done(List<ParseObject> objects, ParseException e) {
                   
         if(e == null){
         System.out.println("QUERRIED ATLAST!!!!");
         }
         else{
         System.out.println("NOOOOOOOOOO");
         }
         }
         });*/
        festquery.findInBackground(new FindCallback() {

            @Override
            public void done(List<ParseObject> objects, almonds.ParseException e) {
                if (e == null) {
                    List<ParseObject> res = new ArrayList<>(objects);
                    HashMap<String, String> hm = new HashMap<>();
                    System.out.println(res.size());
                    /*for (ParseObject re : res) {
                     System.out.println("IDS: " + re.getString("Festival_name"));
                     }*/
                    ParseObject re1 = new ParseObject("Festival");
                    for (ParseObject re : res) {
                        System.out.println("festival name: " + re.getString("Festival_name") + " festivalID : "
                                + re.getObjectId());
                        ;
                        // n.add(re.getObjectId());
                        hm.put(re.getObjectId(), re.getString("Festival_name"));
                    }

                    if (hm.containsValue(festSelection)) {

                        for (Map.Entry entry : hm.entrySet()) {

                            if (festSelection.equals(entry.getValue())) {
                                System.out.println("Selected festival key is " + entry.getKey());

                            }
                        }
                    }
                } else {
                    System.out.println("error");
                }
            }

        });

        try {
            aObj.save();
        } catch (ParseException ex) {
            Logger.getLogger(Window.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showConfirmDialog(null, "ERROR: " + ex, "Error", JOptionPane.OK_CANCEL_OPTION);
        }
    } else {
        return;
    }

    System.exit(0);

}

From source file:patientmanagerv1.HomeController.java

@Override
public void initialize(URL url, ResourceBundle rb) {

    //start with the forum and the common questions page, add-on the profile page and private messaging features

    //passLoaded = false;

    //sets the current Patient
    try {//from   ww w.j av  a2  s  .  c o  m
        String entireFileText = new Scanner(new File(installationPath + "/currentpatient.txt"))
                .useDelimiter("//A").next();
        String[] nameArray = entireFileText.split(",");

        firstName = nameArray[0].toLowerCase();
        lastName = nameArray[1].toLowerCase();
        dob = nameArray[2];
    } catch (Exception e) {
    }

    //checks the signed status
    try {
        FileReader reader = new FileReader(
                installationPath + "/userdata/" + firstName + lastName + dob + "/EvaluationForm/signed.txt");
        //+ "/userdata/" + get.currentPatientFirstName + get.currentPatientLastName + "/EvaluationForm/first.txt");
        BufferedReader br = new BufferedReader(reader);
        String signedStatus = br.readLine();
        br.close();
        reader.close();

        if (signedStatus.equalsIgnoreCase("true")) {
            dccSigned = true;
        } else {
            dccSigned = false;
        }

        FileReader reader2 = new FileReader(installationPath + "/userdata/" + firstName + lastName + dob
                + "/EvaluationForm/assistantsigned.txt");
        //+ "/userdata/" + get.currentPatientFirstName + get.currentPatientLastName + "/EvaluationForm/first.txt");
        BufferedReader br2 = new BufferedReader(reader2);
        String assistantSigned = br2.readLine();
        br2.close();
        reader2.close();

        if (assistantSigned.equalsIgnoreCase("true")) {
            partnerSigned = true;
        } else {
            partnerSigned = false;
        }

        /*saveButton.setDisable(false);
        sign.setVisible(true);
        sign.setDisable(true);
        signature.setVisible(false);*/

        if (signedStatus.equalsIgnoreCase("false") && (assistantSigned.equalsIgnoreCase("false"))) {
            saveButton.setDisable(false);
            sign.setVisible(true);
            sign.setDisable(false);
            assistantsign.setVisible(true);
            assistantsign.setDisable(false);
            assistantsignature.setVisible(false);
            signature.setVisible(false);
            signature2.setVisible(false);
            ap.setDisable(false);
        } else if (signedStatus.equalsIgnoreCase("true") && (assistantSigned.equalsIgnoreCase("false"))) {
            saveButton.setDisable(true);
            sign.setVisible(false);
            assistantsign.setVisible(true);
            assistantsign.setDisable(false);
            assistantsignature.setVisible(false);
            signature.setVisible(true);
            signature2.setVisible(true);
            signature.setText("This document has been digitally signed by David Zhvikov MD");
            ap.setDisable(true);
        } else if (signedStatus.equalsIgnoreCase("false") && (assistantSigned.equalsIgnoreCase("true"))) {
            saveButton.setDisable(true);
            sign.setVisible(true);
            assistantsign.setVisible(false);
            assistantsign.setDisable(true);
            assistantsignature.setVisible(true);
            signature.setVisible(false);
            signature2.setVisible(false);
            signature.setText("This document has been digitally signed by David Zhvikov MD");
            ap.setDisable(true);
        } else {
            saveButton.setDisable(true);
            sign.setVisible(false);
            assistantsign.setVisible(false);
            assistantsign.setDisable(true);
            assistantsignature.setVisible(true);
            signature.setVisible(true);
            signature2.setVisible(true);
            signature.setText("This document has been digitally signed by David Zhvikov MD");
            ap.setDisable(true);
        }
    } catch (Exception e) {
    }

    //loads the ListView

    try {
        FileReader r2 = new FileReader(
                installationPath + "/userdata/" + firstName + lastName + dob + "/ProgressReports.txt");
        BufferedReader b2 = new BufferedReader(r2);

        String s;
        ArrayList progressNotes = new ArrayList();

        while ((s = b2.readLine()) != null) {
            //System.out.println(s);
            progressNotes.add(s);
        }

        b2.close();
        r2.close();

        //Adds the Progress Notes to the ListView

        ObservableList<String> items = FXCollections.observableArrayList("Single", "Double");
        items.clear();

        for (int counter = 0; counter < progressNotes.size(); counter++) {
            items.add(progressNotes.get(counter).toString());
        }

        listOfProgressReports.setItems(items);

        //String[] ethnicityArray = ethnicity.split(",");
    } catch (Exception e) {
        //System.out.println("file not found");
    }

    //initializes the evaluation form [with the new patient's name] for the current patient
    fillName();

    fillDOB();

    fillAge(loaded);

    fillGender();

    fillMaritalStatus();

    fillEthnicity();

    fillReferredBy();

    fillReasonForReferral();

    fillSourceOfInformation();

    fillReliabilityOfInformation();

    fillHistoryOfPresentIllness();

    fillSignsSymptoms();

    fillCurrentMedications();

    fillPastPsychiatricHistory();

    fillPastHistoryOf();

    fillHistoryOfMedicationTrialsInThePast();

    fillSubstanceUseHistory();

    fillDeniesHistoryOf();

    fillSocialHistory();

    fillParentsSiblingsChildren();

    fillFamilyHistoryOfMentalIllness();

    fillEducation();

    fillEmployment();

    fillLegalHistory();

    fillPastMedicalHistory();

    fillAllergies();

    fillAppearance();

    fillEyeContact();

    fillAttitude();

    fillMotorActivity();

    fillAffect();

    fillMood();

    fillSpeech();

    fillThoughtProcess();

    fillThoughtContent();

    fillPerception();

    fillSuicidality();

    fillHomicidality();

    fillOrientation();

    fillShortTermMemory();

    fillLongTermMemory();

    fillGeneralFundOfKnowledge();

    fillIntellect();

    fillAbstraction();

    fillJudgementAndInsight();

    fillClinicalNotes();

    fillTreatmentPlan();

    fillSideEffects();

    fillLabs();

    fillEnd();

    fillSignatureZone();

    //        currentPatientFirstName = get.currentPatientFirstName;
    //        currentPatientLastName = get.currentPatientLastName;

    //sets the current patient
    /*try
    {
    String entireFileText = new Scanner(new File(installationPath + "/Patients.txt")).useDelimiter("//A").next();
    String[] arrayOfNames = entireFileText.split(";");
            
            
    System.out.println("Patient Name: " + arrayOfNames[arrayOfNames.length - 1]);
            
    String nameWithComma = arrayOfNames[arrayOfNames.length - 1];
    String[] nameArray = nameWithComma.split(",");
            
    firstName = nameArray[0].toLowerCase();
    lastName = nameArray[1].toLowerCase();
            
            
            
    }
    catch(Exception e)
    {}*/

    /*ArrayList progressNotes = new ArrayList();
            
    for(int i = 0; i < listOfProgressReports.getItems().size(); i++)
    {
        progressNotes.add(listOfProgressReports.getItems().get(i));
    }*/

    //broken and betrayed
    //of the ecsts's you've shown me.
    //...for me, italicsmaster, she put emphasis/lingered on the word. "M"

    menu.getMenus().removeAll();
    Menu file = new Menu("File");
    Menu edit = new Menu("Edit");
    Menu view = new Menu("View");
    Menu help = new Menu("About");
    Menu speech = new Menu("Speech Options");

    MenuItem save = new MenuItem("Save");
    MenuItem print = new MenuItem("Print");
    MenuItem printWithSettings = new MenuItem("Print With Settings");
    MenuItem export = new MenuItem("Export to");
    MenuItem logout = new MenuItem("Return to Patient Selection");
    MenuItem deleteThisPatient = new MenuItem("Delete This Patient");
    MenuItem exit = new MenuItem("Exit");

    MenuItem undo = new MenuItem("Undo (ctrl+z)");
    MenuItem redo = new MenuItem("Redo (ctrl+y)");
    MenuItem selectAll = new MenuItem("Select All (ctrl+A)");
    MenuItem cut = new MenuItem("Cut (ctrl+x)");
    MenuItem copy = new MenuItem("Copy (ctrl+c)");
    MenuItem paste = new MenuItem("Paste (ctrl+v)");
    MenuItem enableBackdoorModifications = new MenuItem("Enable Modification of this Evaluation Post-Signing");

    Menu submenu1 = new Menu("Create");
    Menu submenu2 = new Menu("Load");
    Menu submenu3 = new Menu("New");
    MenuItem createProgressReport = new MenuItem("Progress Report");
    MenuItem loadProgressReport = new MenuItem("Progress Report");
    MenuItem deleteProgressReport = new MenuItem("Delete selected progress report");
    submenu1.getItems().add(submenu3);
    submenu3.getItems().add(createProgressReport);
    submenu2.getItems().add(loadProgressReport);

    MenuItem howToUse = new MenuItem("How to use patient manager");
    MenuItem versionInfo = new MenuItem("About Patient Manager/Version Info");

    /*MenuItem read = new MenuItem("Read to me");
    MenuItem launch = new MenuItem("Launch Dictation");*/
    //read to me menu, dictation menu- select a document to read aloud, read this passage aloud, launch windows in-built dictation, download brainac dictation online
    Menu read = new Menu("Read to me");
    Menu launch = new Menu("Dictation");

    Menu readPassageOrFormStartStop = new Menu("Read this passage/read this form");

    MenuItem startReading1 = new MenuItem("Start");
    MenuItem stopReading1 = new MenuItem("Stop");
    MenuItem startReading2 = new MenuItem("Start");
    MenuItem stopReading2 = new MenuItem("Stop");
    Menu readUploadedDocument = new Menu("Select a document to read");
    MenuItem launchWindowsDictation = new MenuItem("Launch Windows' Built-In Dictation");
    MenuItem launchBrainacDictation = new MenuItem("Download Brainac Dictation");

    startReading1.setDisable(true);
    stopReading1.setDisable(true);
    startReading2.setDisable(true);
    stopReading2.setDisable(true);

    readPassageOrFormStartStop.getItems().add(startReading1);
    readPassageOrFormStartStop.getItems().add(stopReading1);
    readUploadedDocument.getItems().add(startReading2);
    readUploadedDocument.getItems().add(stopReading2);

    readPassageOrFormStartStop.setDisable(true);
    readUploadedDocument.setDisable(true);

    launchBrainacDictation.setDisable(true);

    read.getItems().add(readPassageOrFormStartStop);
    read.getItems().add(readUploadedDocument);
    launch.getItems().add(launchWindowsDictation);
    launch.getItems().add(launchBrainacDictation);

    file.getItems().add(save);
    file.getItems().add(print);
    file.getItems().add(printWithSettings);
    file.getItems().add(export);
    file.getItems().add(logout);
    file.getItems().add(deleteThisPatient);
    file.getItems().add(exit);

    edit.getItems().add(undo);
    edit.getItems().add(redo);
    edit.getItems().add(selectAll);
    edit.getItems().add(cut);
    edit.getItems().add(copy);
    edit.getItems().add(paste);
    edit.getItems().add(enableBackdoorModifications);

    view.getItems().add(submenu1);
    view.getItems().add(submenu2);
    view.getItems().add(deleteProgressReport);

    help.getItems().add(howToUse);
    help.getItems().add(versionInfo);

    speech.getItems().add(read);
    speech.getItems().add(launch);

    menu.prefWidthProperty().bind(masterPane.widthProperty());
    //menu.setStyle("-fx-padding: 0 20 0 20;");

    //menu.getMenus().addAll(file, edit, view, help, speech);
    menu.getMenus().add(file);
    menu.getMenus().add(edit);
    menu.getMenus().add(view);
    menu.getMenus().add(speech);
    menu.getMenus().add(help);

    undo.setDisable(true);
    redo.setDisable(true);
    cut.setDisable(true);
    copy.setDisable(true);
    paste.setDisable(true);
    selectAll.setDisable(true);

    deleteThisPatient.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent e) {

            int result = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete this patient?",
                    "Warning", JOptionPane.OK_CANCEL_OPTION);

            if (result == 2) {

            }

            if (result == 0) {
                int result2 = JOptionPane.showConfirmDialog(null,
                        "Are you ABSOLUTELY sure you want to delete this patient?", "Warning",
                        JOptionPane.OK_CANCEL_OPTION);

                if (result2 == 2) {

                }
                if (result2 == 0) {
                    String patientToDelete = firstName + "," + lastName + "," + dob; //listOfProgressReports.getSelectionModel().getSelectedItem().toString();

                    //            String currRepNoColons = currRep.replace(":", "");
                    //        currRepNoColons = currRepNoColons.trim();

                    //1) removes the report from the list in the file
                    try {
                        FileReader r2 = new FileReader(installationPath + "/patients.txt");
                        BufferedReader b2 = new BufferedReader(r2);

                        String s = b2.readLine();
                        String[] patients = s.split(";"); //String[] ssArray = ss.split(",");

                        /*for(int i = 0; i < patients.size(); i++)
                        {
                                
                        }*/

                        /*while((s = b2.readLine()) != null)
                        {
                            //System.out.println(s);
                                
                            if(!s.equalsIgnoreCase(patientToDelete))
                            {patients.add(s);}
                        }*/

                        b2.close();
                        r2.close();

                        File fff = new File(installationPath + "/patients.txt");
                        FileWriter ddd = new FileWriter(fff, false);
                        BufferedWriter bw = new BufferedWriter(ddd);
                        ddd.append("");
                        bw.close();
                        ddd.close();

                        for (int i = 0; i < patients.length; i++) {
                            File openProgressReportsList = new File(installationPath + "/patients.txt");
                            FileWriter fw = new FileWriter(openProgressReportsList, true);
                            BufferedWriter bufferedwriter = new BufferedWriter(fw);
                            if (!(patients[i].equalsIgnoreCase(patientToDelete))) {
                                fw.append(patients[i].toLowerCase() + ";");
                            }
                            bufferedwriter.close();
                            fw.close();
                        }
                    } catch (Exception ex) {

                    }

                    /*try{
                            FileReader reader = new FileReader(installationPath + "/userdata/" + firstName + lastName + dob + "/ProgressReports.txt");
                            BufferedReader br = new BufferedReader(reader); 
                            String fileContents = br.readLine();
                            br.close();
                            reader.close();
                            
                            fileContents = fileContents.replace(currRep, "");
                            //System.out.println("fc:" + fileContents);
                            
                            //writes the new contents to the file:
                            //writes the new report to the list
                            File openProgressReportsList = new File(installationPath + "/userdata/" + firstName + lastName + dob + "/ProgressReports.txt");
                            FileWriter fw = new FileWriter(openProgressReportsList, false);           
                            BufferedWriter bufferedwriter = new BufferedWriter(fw);
                            fw.append(fileContents);
                            bufferedwriter.close();
                            fw.close();
                    }
                    catch(Exception e)
                    {
                            
                    }*/

                    //2) Deletes the folder for that progress report
                    try {
                        File directory = new File(installationPath + "/userdata/" + firstName + lastName + dob
                                + "/ProgressNotes");
                        File[] subdirs = directory.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);
                        for (File dir : subdirs) {
                            File deleteThis = new File(installationPath + "/userdata/" + firstName + lastName
                                    + dob + "/ProgressNotes/" + dir.getName());
                            //System.out.println("Directory: " + dir.getName());
                            File[] filez = deleteThis.listFiles();

                            for (int i = 0; i < filez.length; i++) {
                                filez[i].delete();
                            }
                            //the wedding nightmare: red, red, dark purple-brown; big-ol red wrap/red jacket
                            deleteThis.delete();
                        }
                        File path3 = new File(installationPath + "/userdata/" + firstName + lastName + dob
                                + "/ProgressNotes");
                        File[] files3 = path3.listFiles();

                        for (int i = 0; i < files3.length; i++) {
                            files3[i].delete();
                        }
                        //the wedding nightmare: red, red, dark purple-brown; big-ol red wrap/red jacket
                        path3.delete();

                        File path2 = new File(installationPath + "/userdata/" + firstName + lastName + dob
                                + "/EvaluationForm");
                        File[] files2 = path2.listFiles();

                        for (int i = 0; i < files2.length; i++) {
                            files2[i].delete();
                        }
                        //the wedding nightmare: red, red, dark purple-brown; big-ol red wrap/red jacket
                        path2.delete();

                        File path = new File(installationPath + "/userdata/" + firstName + lastName + dob);
                        File[] files = path.listFiles();

                        for (int i = 0; i < files.length; i++) {
                            files[i].delete();
                        }
                        //the wedding nightmare: red, red, dark purple-brown; big-ol red wrap/red jacket
                        path.delete();
                        //deleteDirectory(installationPath + "/userdata/" + firstName + lastName + dob + "/ProgressNotes/" + currRepNoColons);
                        //Files.delete(installationPath + "/userdata/" + firstName + lastName + dob + "/ProgressNotes/" + currRepNoColons);

                        //PUT A MESSAGE SAYING "DELETED" HERE
                        JOptionPane.showMessageDialog(null, "Deleted!");

                        toPatientSelectionNoDialog.fire();
                    } catch (Exception exception) {
                    }
                }

            }

        }
    });

    save.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent e) {
            save();
        }
    });

    versionInfo.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent e) {
            JOptionPane.showMessageDialog(null, "Patient Manager Version 5.0.6 \n Compatible with: Windows 7");
        }
    });

    howToUse.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent e) {
            JOptionPane.showMessageDialog(null,
                    "Help: \n\n\n Print- sends the document to the default printer. Requires no passwords. \n\n Print with Settings- opens the evaluation or progress report in word so that the document can be printed using word's built-in dialog. Because the word document will be open to modification, 'print with settings' requires the physician's password. \n\n Export to- save an evaluation or progress note to the location of your choice, rather than to the default location. Requires the physician/admin's password. \n\n Enable Backdoor Modifications- allows the physician or physician's assistant(s) to reopen the forms for modification post-signing. If the physician's password is used, only his signature will become undone. If the physician's assistant(s)' password is used, both the physician's signature (if relevant) and the assitant's signature will become undone (since the physician will need to review the new modifications before re-signing his approval). \n\n Create/Load/Delete a progress note- the create & load functions are accessible directly from the interface. Deletion can only be accessed from the drop-down menu. Select a progress report prior to clicking 'load' or 'delete' \n\n Speech Options- most speech options are still a WIP, HOWEVER, you can click 'launch windows 7 native dictation' from either the interface OR the menu bar, in order to quickly access Windows' built-in dictation capabilities. \n\n Version info can be found in 'About' in the 'Help' drop-down menu on the main menu bar.");
        }
    });

    launchWindowsDictation.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent e) {
            launchSpeechRecognition();
        }
    });

    exit.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent e) {
            int result = JOptionPane.showConfirmDialog(null,
                    "Do you want to save any unsaved changes before exiting?", "Save changes?",
                    JOptionPane.YES_NO_CANCEL_OPTION);

            if (result == 0) {
                saveEval();

                //some idiocy goes here
                /*try
                {
                    Audio audio = Audio.getInstance();
                    InputStream sound = audio.getAudio("Have a nice day!", Language.ENGLISH);
                    audio.play(sound);
                }
                catch(Exception excep)
                {System.out.println(excep);}*/

                System.exit(0);
            }
            if (result == 1) {
                //some idiocy goes here
                /*try
                {
                    Audio audio = Audio.getInstance();
                    InputStream sound = audio.getAudio("Have a nice day!", Language.ENGLISH);
                    audio.play(sound);
                }
                catch(Exception excep)
                {System.out.println(excep);}*/

                System.exit(0);
            }
            if (result == 2) {

            }

        }
    });

    enableBackdoorModifications.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent e) {
            enableBackdoorModifications();
        }
    });

    deleteProgressReport.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent e) {
            deleteProgressReport();
        }
    });

    //<MenuItem fx:id="loadProgressReport" onAction="#loadProgressReport" />

    loadProgressReport.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent e) {
            load.fire();
        }
    });

    createProgressReport.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent e) {
            createPN.fire();
        }
    }); //read to me menu, dictation menu- select a document to read aloud, read this passage aloud, launch windows in-built dictation, download brainac dictation online

    export.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent e) {
            final Stage dialog = new Stage();
            dialog.initModality(Modality.APPLICATION_MODAL);

            final TextField textField = new TextField();
            Button submit = new Button();
            Button cancel = new Button();
            final Label label = new Label();

            cancel.setText("Cancel");
            cancel.setAlignment(Pos.CENTER);
            submit.setText("Submit");
            submit.setAlignment(Pos.BOTTOM_RIGHT);

            final VBox dialogVbox = new VBox(20);
            dialogVbox.getChildren().add(new Text("Enter the master password: "));
            dialogVbox.getChildren().add(textField);
            dialogVbox.getChildren().add(submit);
            dialogVbox.getChildren().add(cancel);
            dialogVbox.getChildren().add(label);

            Scene dialogScene = new Scene(dialogVbox, 300, 200);
            dialog.setScene(dialogScene);
            dialog.setTitle("Security/Physician Authentication");
            dialog.show();

            submit.setOnAction(new EventHandler<ActionEvent>() {

                public void handle(ActionEvent anEvent) {
                    String password = textField.getText();

                    if (password.equalsIgnoreCase("protooncogene")) {
                        dialog.close();

                        export();

                    } else {
                        label.setText("The password you entered is incorrect. Please try again.");
                    }

                }
            });

            cancel.setOnAction(new EventHandler<ActionEvent>() {

                public void handle(ActionEvent anEvent) {
                    dialog.close();
                    //close the window here
                }
            });

        }
    });

    print.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent e) {
            print();
        }
    });
    printWithSettings.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent e) {
            printAdv();
        }
    });
    logout.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent e) {
            toPatientSelection.fire();
        }
    });

    ///"sometime during s-y lol."

}