Example usage for javax.swing JOptionPane CLOSED_OPTION

List of usage examples for javax.swing JOptionPane CLOSED_OPTION

Introduction

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

Prototype

int CLOSED_OPTION

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

Click Source Link

Document

Return value from class method if user closes window without selecting anything, more than likely this should be treated as either a CANCEL_OPTION or NO_OPTION.

Usage

From source file:ro.nextreports.designer.util.NextReportsUtil.java

public static boolean saveYesNoCancel(String titleMessage, int options) {
    final QueryBuilderPanel builderPanel = Globals.getMainFrame().getQueryBuilderPanel();
    if (!builderPanel.isCleaned()) {
        String message;//from   ww  w .  j a  v a 2 s  .  co  m
        if (Globals.isChartLoaded()) {
            if (!chartModification()) {
                return true;
            }
            message = I18NSupport.getString("existing.chart.save");
        } else if (Globals.isReportLoaded()) {
            if (!reportModification()) {
                return true;
            }
            message = I18NSupport.getString("existing.report.save");
        } else {
            if (!queryModification()) {
                return true;
            }
            message = I18NSupport.getString("existing.query.save");
        }

        int option = JOptionPane.showConfirmDialog(Globals.getMainFrame(), message, titleMessage, options);
        if ((option == JOptionPane.CANCEL_OPTION) || (option == JOptionPane.CLOSED_OPTION)) {
            return false;
        } else if (option == JOptionPane.YES_OPTION) {
            if (Globals.isChartLoaded()) {
                new SaveChartAction().actionPerformed(null);
            } else if (Globals.isReportLoaded()) {
                new SaveReportAction().actionPerformed(null);
            } else {
                new SaveQueryAction().actionPerformed(null);
            }
        }
    }
    return true;
}

From source file:ro.nextreports.designer.util.NextReportsUtil.java

public static boolean saveYesNoCancel() {
    QueryBuilderPanel builderPanel = Globals.getMainFrame().getQueryBuilderPanel();
    if (!builderPanel.isCleaned()) {
        String message;//from  www.  j  av a 2s.c  om
        if (Globals.isChartLoaded()) {
            if (!chartModification()) {
                return true;
            }
            message = I18NSupport.getString("existing.chart.save");
        } else if (Globals.isReportLoaded()) {
            if (!reportModification()) {
                return true;
            }
            message = I18NSupport.getString("existing.report.save");
        } else {
            if (!queryModification()) {
                return true;
            }
            message = I18NSupport.getString("existing.query.save");
        }

        int option = JOptionPane.showConfirmDialog(Globals.getMainFrame(), message,
                I18NSupport.getString("exit"), JOptionPane.YES_NO_CANCEL_OPTION);
        if ((option == JOptionPane.CANCEL_OPTION) || (option == JOptionPane.CLOSED_OPTION)) {
            return false;
        } else if (option == JOptionPane.YES_OPTION) {
            if (Globals.isChartLoaded()) {
                SaveChartAction action = new SaveChartAction();
                action.actionPerformed(null);
                if (action.isCancel()) {
                    return false;
                }
            } else if (Globals.isReportLoaded()) {
                SaveReportAction action = new SaveReportAction();
                action.actionPerformed(null);
                if (action.isCancel()) {
                    return false;
                }
            } else {
                SaveQueryAction action = new SaveQueryAction();
                action.actionPerformed(null);
                if (action.isCancel()) {
                    return false;
                }
            }
        }
    }
    return true;
}

From source file:ro.nextreports.designer.util.NextReportsUtil.java

public static boolean saveReportForInserting(String message) {
    QueryBuilderPanel builderPanel = Globals.getMainFrame().getQueryBuilderPanel();
    if (!builderPanel.isCleaned()) {
        if (Globals.isReportLoaded()) {
            if (!reportModification()) {
                return true;
            }//from w ww .  j ava 2 s  .  c  om
            int option = JOptionPane.showConfirmDialog(Globals.getMainFrame(), message,
                    I18NSupport.getString("exit"), JOptionPane.YES_NO_OPTION);
            if ((option == JOptionPane.NO_OPTION) || (option == JOptionPane.CLOSED_OPTION)) {
                return false;
            } else if (option == JOptionPane.YES_OPTION) {
                SaveReportAction action = new SaveReportAction();
                action.actionPerformed(null);
                if (action.isCancel()) {
                    return false;
                }
            }
        }
    }
    return true;
}

From source file:storybook.action.ActionHandler.java

public void handleText2Html() {
    int n = SwingUtil.showBetaDialog(mainFrame);
    if (n == JOptionPane.NO_OPTION || n == JOptionPane.CLOSED_OPTION) {
        return;//from www . jav a2 s.com
    }
    mainFrame.setWaitingCursor();
    EntityUtil.convertPlainTextToHtml(mainFrame);
    mainFrame.refresh();
    mainFrame.setDefaultCursor();
}

From source file:storybook.action.ActionHandler.java

public void handleHtml2Text() {
    int n = SwingUtil.showBetaDialog(mainFrame);
    if (n == JOptionPane.NO_OPTION || n == JOptionPane.CLOSED_OPTION) {
        return;/*from w w  w . j  ava2 s.  com*/
    }
    mainFrame.setWaitingCursor();
    EntityUtil.convertHtmlToPlainText(mainFrame);
    mainFrame.refresh();
    mainFrame.setDefaultCursor();
}

From source file:storybook.model.oldModel.ModelMigration.java

public boolean checkAndAlterModel() throws Exception {
    oldDbVersion = InternalPeer.getDbModelVersion();
    if (oldDbVersion == null) {
        return true;
    }/*www  . ja v  a 2  s.  c  om*/
    newDbVersion = SbConstants.Storybook.DB_VERSION.toString();

    if (oldDbVersion.equals(newDbVersion)) {
        // model matches, nothing to do
        return true;
    }

    // alter models
    stmt = ModelMigration.getInstance().getConnection().createStatement();
    // old versions
    if (oldDbVersion.equals("0") || oldDbVersion.equals("0.1") || oldDbVersion.equals("0.1")
            || oldDbVersion.equals("0.2") || oldDbVersion.equals("0.3") || oldDbVersion.equals("0.4")
            || oldDbVersion.equals("0.5") || oldDbVersion.equals("0.6") || oldDbVersion.equals("0.7")
            || oldDbVersion.equals("0.8") || oldDbVersion.equals("0.9") || oldDbVersion.equals("1.0")
            || oldDbVersion.equals("1.1") || oldDbVersion.equals("1.2") || oldDbVersion.equals("1.3")
            || oldDbVersion.equals("1.4")) {
        throw new Exception("File version too old. Update to the latest version of Storybook 3 first.");
    }

    // backup current file
    String fn = FilenameUtils.removeExtension(file.getAbsolutePath());
    fn = fn + ".bak";
    File backupFile = new File(fn);
    try {
        if (backupFile.exists()) {
            backupFile.delete();
        }
        FileUtils.copyFile(file, backupFile);
    } catch (IOException e1) {
        int n = JOptionPane.showConfirmDialog(mainFrame,
                I18N.getMsg("msg.migration.error.backup") + "\n" + backupFile.getAbsolutePath() + "\n"
                        + I18N.getMsg("msg.migration.wanttocontinue"),
                "Backup failed", JOptionPane.YES_NO_OPTION);
        if (n == JOptionPane.NO_OPTION || n == JOptionPane.CLOSED_OPTION) {
            return false;
        }
    }

    if (oldDbVersion.equals("1.5")) {
        // 1.5 -> 4.0
        alterFrom1_5to4_0();
    }

    return true;
}

From source file:storybook.SbApp.java

public void exit() {
    trace("SbApp.exit()");
    if (mainFrames.size() > 0) {
        Preference pref = PrefUtil.get(PreferenceKey.CONFIRM_EXIT, true);
        if (pref.getBooleanValue()) {
            int n = JOptionPane.showConfirmDialog(null, I18N.getMsg("msg.mainframe.want.exit"),
                    I18N.getMsg("msg.common.exit"), JOptionPane.YES_NO_OPTION);
            if (n == JOptionPane.NO_OPTION || n == JOptionPane.CLOSED_OPTION) {
                return;
            }//w w  w  . j  a  v  a2s.co  m
        }
        saveAll();
    }
    System.exit(0);
}

From source file:su.fmi.photoshareclient.ui.PhotoViewDialog.java

private void SaveImageButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SaveImageButtonMouseClicked
    JFileChooser fileChooser = new JFileChooser() {
        // A warning for overweiting existing files
        @Override/*from   ww w.ja v a 2s . c o m*/
        public void approveSelection() {
            File f = getSelectedFile();
            if (f.exists() && getDialogType() == SAVE_DIALOG) {
                int result = JOptionPane.showConfirmDialog(this, "The file exists, overwrite?", "Existing file",
                        JOptionPane.YES_NO_CANCEL_OPTION);
                switch (result) {
                case JOptionPane.YES_OPTION:
                    super.approveSelection();
                    return;
                case JOptionPane.NO_OPTION:
                    return;
                case JOptionPane.CLOSED_OPTION:
                    return;
                case JOptionPane.CANCEL_OPTION:
                    cancelSelection();
                    return;
                }
            }
            super.approveSelection();
        }
    };
    fileChooser.setDialogTitle("Save image as...");
    File rootVolume = File.listRoots()[0];
    fileChooser.setSelectedFile(new File(rootVolume.getAbsolutePath(), this.imageLabel.getFileName()));

    int userSelection = fileChooser.showSaveDialog(this);

    if (userSelection == JFileChooser.APPROVE_OPTION) {
        try {
            File fileToSave = fileChooser.getSelectedFile();
            BufferedImage bi = (BufferedImage) this.imageLabel.getImage();
            String ext = FilenameUtils.getExtension(fileToSave.getAbsolutePath());
            ImageIO.write(bi, ext, fileToSave);
        } catch (IOException ex) {
            Logger.getLogger(PhotoViewDialog.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:vnreal.gui.control.MyEditingPopupGraphMousePlugin.java

@SuppressWarnings("unchecked")
@Override//w w w  .j ava  2  s  . c o m
protected void createGeneralMenuEntries(final Point point, final N graph, final LayerViewer<V, E> vv) {
    JMenuItem mi;
    // creating a node
    mi = new JMenuItem("Create node");
    final int layer = vv.getLayer().getLayer();
    mi.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // adding an resource/demand
            boolean addConstraint = true;
            V node = vertexFactory.create();
            Point2D p2 = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(point);
            node.setCoordinateX(p2.getX());
            node.setCoordinateY(p2.getY());

            while (addConstraint) {
                new AddConstraintDialog(node, layer, GUI.getInstance(), new Dimension(300, 150));
                // if a resource/demand has been added
                if (node.get().size() > 0) {
                    addConstraint = false;
                    @SuppressWarnings("rawtypes")
                    Network net = ToolKit.getScenario().getNetworkStack().getLayer(layer);
                    if ((net instanceof SubstrateNetwork
                            && ((SubstrateNetwork) net).addVertex((SubstrateNode) node))
                            || (net instanceof VirtualNetwork
                                    && ((VirtualNetwork) net).addVertex((VirtualNode) node))) {
                        vv.updateUI();
                    } else {
                        throw new AssertionError("Adding Node failed.");
                    }
                } else {
                    String cons = (layer == 0 ? "Resource" : "Demand");

                    int option = JOptionPane.showConfirmDialog(GUI.getInstance(),
                            "A " + cons + " must be added for the node to be created!", "Create Node",
                            JOptionPane.OK_CANCEL_OPTION);
                    if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
                        addConstraint = false;
                    }
                }
            }
        }
    });
    popup.add(mi);

    popup.addSeparator();

    @SuppressWarnings("rawtypes")
    final MyGraphPanel pnl = GUI.getInstance().getGraphPanel();
    if (pnl.getMaximized() == null) {
        mi = new JMenuItem("Maximize");
        mi.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                pnl.setMaximized(vv);
            }
        });
    } else {
        mi = new JMenuItem("Restore");
        mi.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                pnl.setMaximized(null);
            }
        });
    }
    popup.add(mi);

    if (pnl.getMaximized() != null) {
        mi = new JMenuItem("Hide");
        mi.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                vv.getParent().setVisible(false);
            }
        });
        popup.add(mi);
    }

    popup.addSeparator();

    // Copied from MuLaNEO
    mi = new JMenuItem("Export layer to SVG");
    mi.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int layer = vv.getLayer().getLayer();
            MyFileChooser fc = new MyFileChooser("Export layer " + layer + " to SVG", MyFileChooserType.MISC,
                    false);
            fc.addChoosableFileFilter(FileFilters.svgFilter);
            fc.setSelectedFile(new File("export-layer-" + layer + ".svg"));

            if (fc.showSaveDialog(GUI.getInstance()) == JFileChooser.APPROVE_OPTION)
                new SVGExporter().export(vv, fc.getSelectedFile());
        }
    });
    popup.add(mi);
}

From source file:vnreal.gui.control.MyEditingPopupGraphMousePlugin.java

private void addLink(int layer, V src, V dest) {
    boolean addConstraint = true;
    E edge = edgeFactory.create();//from  w w w  .  j a v a  2 s .co  m
    while (addConstraint) {
        new AddConstraintDialog(edge, layer, GUI.getInstance(), new Dimension(300, 150));
        // if a resource/demand has been added
        if (edge.get().size() > 0) {
            addConstraint = false;
            @SuppressWarnings("rawtypes")
            Network net = ToolKit.getScenario().getNetworkStack().getLayer(layer);
            if ((net instanceof SubstrateNetwork && ((SubstrateNetwork) net).addEdge((SubstrateLink) edge,
                    (SubstrateNode) src, (SubstrateNode) dest))
                    || (net instanceof VirtualNetwork && ((VirtualNetwork) net).addEdge((VirtualLink) edge,
                            (VirtualNode) src, (VirtualNode) dest))) {
                vv.updateUI();
            } else {
                throw new AssertionError("Adding link failed.");
            }
        } else {
            int option = JOptionPane.showConfirmDialog(GUI.getInstance(),
                    "A " + (layer == 0 ? "Resource" : "Demand") + " must be added for the link to be created!",
                    "Create Node", JOptionPane.OK_CANCEL_OPTION);
            if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
                addConstraint = false;
            }
        }
    }
}