Example usage for javax.swing JOptionPane CANCEL_OPTION

List of usage examples for javax.swing JOptionPane CANCEL_OPTION

Introduction

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

Prototype

int CANCEL_OPTION

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

Click Source Link

Document

Return value from class method if CANCEL is chosen.

Usage

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

private void addLink(int layer, V src, V dest) {
    boolean addConstraint = true;
    E edge = edgeFactory.create();/* www. j  a va2 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;
            }
        }
    }
}

From source file:volker.streaming.music.gui.NowPlayingFrame.java

public NowPlayingFrame(final File cfgFile) {
    this.cfgFile = cfgFile;

    frame = this;
    setTitle("NowPlaying - LastFM integration");
    setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

    lastfmConfig = LastFmConfig.fromFile(cfgFile);
    config = Config.fromFile(cfgFile);//from  ww  w . ja  v  a  2  s  . co m

    configPanel = new ConfigPanel(this, lastfmConfig);

    previewTrack = new Track("Beyonce", "Halo", "I Am... Sasha Fierce");
    formatter = new Formatter(Formatter.DEFAULT_EXCEPTIONS);
    formatPanel = new FormatPanel(this, config, formatter, previewTrack);

    apiPanel = new ApiPanel(config, lastfmConfig, formatter);

    saveButton = new JButton("Save configuration");
    saveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            saveConfig();
        }
    });
    savePanel = new JPanel(new GridBagLayout());
    savePanel.add(saveButton);

    layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);

    layout.setHorizontalGroup(layout.createSequentialGroup().addContainerGap()
            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER).addComponent(configPanel)
                    .addComponent(formatPanel).addComponent(apiPanel).addComponent(savePanel))
            .addContainerGap());

    layout.setVerticalGroup(layout.createSequentialGroup().addContainerGap().addComponent(configPanel)
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(formatPanel)
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(apiPanel)
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(savePanel).addContainerGap());

    pack();

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            LastFmConfig storedLfm = LastFmConfig.fromFile(cfgFile);
            Config stored = Config.fromFile(cfgFile);
            if (!stored.contentEquals(config) || !storedLfm.contentEquals(lastfmConfig)) {
                int opt = JOptionPane.showConfirmDialog(frame,
                        "You have unsaved configuration changes.\nDo you want to save them?", "Unsaved changes",
                        JOptionPane.YES_NO_CANCEL_OPTION);
                switch (opt) {
                case JOptionPane.YES_OPTION:
                    saveConfig();
                case JOptionPane.NO_OPTION:
                    System.exit(0);
                    break;
                case JOptionPane.CANCEL_OPTION:
                    break;
                default:
                    LOG.error("Unknown response to closing window");
                }
            } else {
                System.exit(0);
            }
        }
    });
}

From source file:wjhk.jupload2.policies.DefaultUploadPolicy.java

/**
 * The DefaultUpload accepts all file types: we just return an instance of
 * FileData, without any test./*from   ww  w  .  j a  va2s.c  o  m*/
 * 
 * @exception JUploadExceptionStopAddingFiles
 *                If the users choosed to stop adding. This occurs when the
 *                {@link #fileFilterAccept(File)} method returns false, and
 *                the user then choose to stop adding files.
 * @see UploadPolicy#createFileData(File, File)
 */
public FileData createFileData(File file, File root) throws JUploadExceptionStopAddingFiles {
    if (!fileFilterAccept(file)) {
        String msg = file.getName() + " : " + getLocalizedString("errForbiddenExtension");
        displayWarn(msg);
        if (confirmDialogStr(msg, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
            // The user want to stop to add files to the list. For instance,
            // when he/she added a whole directory, and it contains a lot of
            // files that don't match the allowed file extension.
            throw new JUploadExceptionStopAddingFiles("Stopped by the user");
        }
        return null;
    } else if (!file.canRead()) {
        displayInfo("Can't read file " + file.getName() + ". No DefaultFileData creation.");
        return null;
    } else {
        return new DefaultFileData(file, root, this);
    }
}