Example usage for javax.swing JOptionPane showOptionDialog

List of usage examples for javax.swing JOptionPane showOptionDialog

Introduction

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

Prototype

@SuppressWarnings("deprecation")
public static int showOptionDialog(Component parentComponent, Object message, String title, int optionType,
        int messageType, Icon icon, Object[] options, Object initialValue) throws HeadlessException 

Source Link

Document

Brings up a dialog with a specified icon, where the initial choice is determined by the initialValue parameter and the number of choices is determined by the optionType parameter.

Usage

From source file:com.smanempat.controller.ControllerEvaluation.java

public void proccessMining(JTable tableDataSetModel, JTable tableDataSetTesting, JTextField txtNumberOfK,
        JLabel labelPesanError, JTabbedPane jTabbedPane1, JTable tableResult, JTable tableConfMatrix,
        JTable tableTahunTesting, JLabel totalAccuracy, JPanel panelChart, JPanel panelChart1,
        JPanel panelChart2, JRadioButton singleTesting, JRadioButton multiTesting, JTextArea txtArea)
        throws SQLException {
    Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
    modelEvaluation = new ModelEvaluation();
    int rowCountModel = tableDataSetModel.getRowCount();
    int rowCountTest = tableDataSetTesting.getRowCount();
    int[] tempK;//from w ww .  j av a  2 s.c  om
    double[][] tempEval;
    double[][] evalValue;
    boolean valid = false;

    /*Validasi Dataset Model dan Dataset Uji*/
    if (rowCountModel == 0) {
        JOptionPane.showMessageDialog(null, "Pilih dataset model terlebih dahulu!", "Error",
                JOptionPane.INFORMATION_MESSAGE,
                new ImageIcon(getClass().getResource("/com/smanempat/image/fail.png")));
        txtNumberOfK.requestFocus();
    } else if (rowCountTest == 0) {
        JOptionPane.showMessageDialog(null, "Pilih dataset uji terlebih dahulu!", "Error",
                JOptionPane.INFORMATION_MESSAGE,
                new ImageIcon(getClass().getResource("/com/smanempat/image/fail.png")));
        txtNumberOfK.requestFocus();
    } else {
        valid = true;
    }
    /*Validasi Dataset Model dan Dataset Uji*/

    if (valid == true) {
        if (multiTesting.isSelected()) {
            String iterasi = JOptionPane.showInputDialog("Input Jumlah Iterasi Pengujian :");
            boolean validMulti = false;

            if (iterasi != null) {

                /*Validasi Jumlah Iterasi*/
                if (Pattern.matches("[0-9]+", iterasi) == false && iterasi.length() > 0) {
                    JOptionPane.showMessageDialog(null, "Nilai iterasi tidak valid!", "Error",
                            JOptionPane.INFORMATION_MESSAGE,
                            new ImageIcon(getClass().getResource("/com/smanempat/image/fail.png")));
                } else if (iterasi.isEmpty()) {
                    JOptionPane.showMessageDialog(null, "Nilai iterasi tidak boleh kosong!", "Error",
                            JOptionPane.INFORMATION_MESSAGE,
                            new ImageIcon(getClass().getResource("/com/smanempat/image/fail.png")));
                } else if (iterasi.length() == 9) {
                    JOptionPane.showMessageDialog(null, "Nilai iterasi terlalu panjang!", "Error",
                            JOptionPane.INFORMATION_MESSAGE,
                            new ImageIcon(getClass().getResource("/com/smanempat/image/fail.png")));
                } else if (rowCountTest > rowCountModel) {

                    JOptionPane.showMessageDialog(null, "Data Uji tidak boleh lebih besar daripada data Model!",
                            "Error", JOptionPane.INFORMATION_MESSAGE,
                            new ImageIcon(getClass().getResource("/com/smanempat/image/fail.png")));
                } else {
                    validMulti = true;
                    System.out.println("valiMulti = " + validMulti + " Kok");
                }
                /*Validasi Jumlah Iterasi*/
            }

            if (validMulti == true) {
                tempK = new int[Integer.parseInt(iterasi)];
                evalValue = new double[3][tempK.length];
                for (int i = 0; i < Integer.parseInt(iterasi); i++) {
                    validMulti = false;
                    String k = JOptionPane
                            .showInputDialog("Input Nilai Nearest Neighbor (k) ke " + (i + 1) + " :");
                    if (k != null) {
                        /*Validasi Nilai K Tiap Iterasi*/
                        if (Pattern.matches("[0-9]+", k) == false && k.length() > 0) {
                            JOptionPane.showMessageDialog(null, "Nilai nearest neighbor (k) tidak valid!",
                                    "Error", JOptionPane.INFORMATION_MESSAGE,
                                    new ImageIcon(getClass().getResource("/com/smanempat/image/fail.png")));
                        } else if (k.isEmpty()) {
                            JOptionPane.showMessageDialog(null,
                                    "Nilai nearest neighbor (k) tidak boleh kosong!", "Error",
                                    JOptionPane.INFORMATION_MESSAGE,
                                    new ImageIcon(getClass().getResource("/com/smanempat/image/fail.png")));
                        } else if (k.length() == 9) {
                            JOptionPane.showMessageDialog(null, "Nilai nearest neighbor (k) terlalu panjang!",
                                    "Error", JOptionPane.INFORMATION_MESSAGE,
                                    new ImageIcon(getClass().getResource("/com/smanempat/image/fail.png")));
                        } else {
                            validMulti = true;
                        }
                        /*Validasi Nilai K Tiap Iterasi*/
                    }

                    if (validMulti == true) {
                        tempK[i] = Integer.parseInt(k);
                        System.out.println(tempK[i]);
                    } else {
                        break;
                    }
                }

                if (validMulti == true) {
                    for (int i = 0; i < tempK.length; i++) {
                        int kValue = tempK[i];
                        String[][] modelValue = getModelValue(rowCountModel, tableDataSetModel);
                        double[][] testValue = getTestvalue(rowCountTest, tableDataSetTesting);
                        String[] knnValue = getKNNValue(rowCountModel, rowCountTest, modelValue, testValue,
                                kValue);
                        tempEval = evaluationModel(tableResult, tableConfMatrix, totalAccuracy,
                                tableTahunTesting, tableDataSetTesting, knnValue, i, tempK, panelChart);
                        //Menampung nilai Accuracy
                        evalValue[0][i] = tempEval[0][i];
                        //Menampung nilai Recall
                        evalValue[1][i] = tempEval[1][i];
                        //Menampung nilai Precision
                        evalValue[2][i] = tempEval[2][i];
                        jTabbedPane1.setSelectedIndex(1);
                        txtArea.append(
                                "Tingkat Keberhasilan Sistem dengan Nilai Number of Nearest Neighbor (K) = "
                                        + tempK[i] + "\n");
                        txtArea.append("Akurasi\t\t: " + evalValue[0][i] * 100 + " %\n");
                        txtArea.append("Recall\t\t: " + evalValue[1][i] * 100 + " %\n");
                        txtArea.append("Precision\t: " + evalValue[2][i] * 100 + " %\n");
                        txtArea.append(
                                "=============================================================================\n");
                    }
                    showChart(tempK, evalValue, panelChart, panelChart1, panelChart2);
                }
            }
        } else if (singleTesting.isSelected()) {
            boolean validSingle = false;
            String k = txtNumberOfK.getText();
            int nilaiK = 0;
            evalValue = new double[3][1];

            /*Validasi Nilai Number of Nearest Neighbor*/
            if (Pattern.matches("[0-9]+", k) == false && k.length() > 0) {
                labelPesanError.setText("Number of Nearest Neighbor tidak valid");
                JOptionPane.showMessageDialog(null, "Number of Nearest Neighbor tidak valid!", "Error",
                        JOptionPane.INFORMATION_MESSAGE,
                        new ImageIcon(getClass().getResource("/com/smanempat/image/fail.png")));
                txtNumberOfK.requestFocus();
            } else if (k.isEmpty()) {
                JOptionPane.showMessageDialog(null, "Number of Nearest Neighbor tidak boleh kosong!", "Error",
                        JOptionPane.INFORMATION_MESSAGE,
                        new ImageIcon(getClass().getResource("/com/smanempat/image/fail.png")));
                labelPesanError.setText("Number of Nearest Neighbor tidak boleh kosong");
                txtNumberOfK.requestFocus();
            } else if (rowCountModel == 0 && Integer.parseInt(k) >= rowCountModel) {
                JOptionPane.showMessageDialog(null, "Pilih dataset model terlebih dahulu!", "Error",
                        JOptionPane.INFORMATION_MESSAGE,
                        new ImageIcon(getClass().getResource("/com/smanempat/image/fail.png")));
                txtNumberOfK.requestFocus();
            } else if (rowCountTest == 0 && Integer.parseInt(k) >= rowCountTest) {
                JOptionPane.showMessageDialog(null, "Pilih dataset uji terlebih dahulu!", "Error",
                        JOptionPane.INFORMATION_MESSAGE,
                        new ImageIcon(getClass().getResource("/com/smanempat/image/fail.png")));
                txtNumberOfK.requestFocus();
            } else if (Integer.parseInt(k) >= rowCountModel) {
                JOptionPane.showMessageDialog(null,
                        "Number of Nearest Neighbor tidak boleh lebih dari " + rowCountModel + " !", "Error",
                        JOptionPane.INFORMATION_MESSAGE,
                        new ImageIcon(getClass().getResource("/com/smanempat/image/fail.png")));
                txtNumberOfK.requestFocus();
            } else {
                validSingle = true;
                nilaiK = Integer.parseInt(k);
            }
            /*Validasi Nilai Number of Nearest Neighbor*/

            if (validSingle == true) {
                int confirm;
                int i = 0;
                confirm = JOptionPane.showOptionDialog(null, "Yakin ingin memproses data?",
                        "Proses Klasifikasi", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                        null, null);
                if (confirm == JOptionPane.OK_OPTION) {

                    int kValue = Integer.parseInt(txtNumberOfK.getText());
                    String[][] modelValue = getModelValue(rowCountModel, tableDataSetModel);
                    double[][] testValue = getTestvalue(rowCountTest, tableDataSetTesting);
                    String[] knnValue = getKNNValue(rowCountModel, rowCountTest, modelValue, testValue, kValue);
                    tempEval = evaluationModel(tableResult, tableConfMatrix, totalAccuracy, tableTahunTesting,
                            tableDataSetTesting, knnValue, nilaiK, panelChart);
                    evalValue[0][i] = tempEval[0][0];
                    evalValue[1][i] = tempEval[1][0];
                    evalValue[2][i] = tempEval[2][0];
                    jTabbedPane1.setSelectedIndex(1);
                }
                System.out.println("com.smanempat.controller.ControllerEvaluation.proccessMining()OKOKOK");
                showChart(nilaiK, evalValue, panelChart, panelChart1, panelChart2);
                Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
            }
        }
    }

}

From source file:course_generator.param.frmEditCurve.java

/**
 * Delete the selected line in the points table
 *///from w  ww  .  j av a 2s .c  o m
protected void DeleteLine() {
    if (!bEditMode)
        return;

    int r = TablePoints.getSelectedRow();
    if (r >= 0) {
        Object[] options = { " " + bundle.getString("frmEditCurve.DeleteYes") + " ",
                " " + bundle.getString("frmEditCurve.DeleteNo") + " " };
        int ret = JOptionPane.showOptionDialog(this, bundle.getString("frmEditCurve.DeleteLineMessage"),
                bundle.getString("frmEditCurve.DeleteLineTitle"), JOptionPane.YES_NO_OPTION,
                JOptionPane.WARNING_MESSAGE, null, options, options[1]);

        if (ret == JOptionPane.YES_OPTION) {
            param.data.remove(r);
            Collections.sort(param.data);
            RefreshView();
        }
    }
}

From source file:io.github.jeddict.reveng.klass.RevEngWizardDescriptor.java

private EntityMappings generateJPAModel(final ProgressReporter reporter, EntityMappings entityMappings,
        final FileObject sourcePackage, final Set<String> entities, final FileObject targetFilePath,
        final String targetFileName, final boolean includeReference, final boolean softWrite,
        final boolean autoOpen) throws IOException, ProcessInterruptedException {

    int progressIndex = 0;
    String progressMsg = getMessage(RevEngWizardDescriptor.class, "MSG_Progress_JPA_Model_Pre"); //NOI18N;
    reporter.progress(progressMsg, progressIndex++);

    List<String> missingEntities = new ArrayList<>();
    SourceExplorer source = new SourceExplorer(sourcePackage, entityMappings, entities, includeReference);
    for (String entityClassFQN : entities) {
        try {//  w ww. j  ava2s.c o m
            source.createClass(entityClassFQN);
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
            missingEntities.add(entityClassFQN);
        }
    }

    progressIndex = loadJavaClasses(reporter, progressIndex, source.getClasses(), entityMappings);
    List<ClassExplorer> classes = checkReferencedClasses(source, missingEntities, includeReference);
    while (!classes.isEmpty()) {
        progressIndex = loadJavaClasses(reporter, progressIndex, classes, entityMappings);
        classes = checkReferencedClasses(source, missingEntities, includeReference);
    }

    if (!missingEntities.isEmpty()) {
        final String title, _package;
        StringBuilder message = new StringBuilder();
        if (missingEntities.size() == 1) {
            title = "Conflict detected - Entity not found";
            message.append(JavaSourceParserUtil.simpleClassName(missingEntities.get(0))).append(" Entity is ");
        } else {
            title = "Conflict detected - Entities not found";
            message.append("Entities ").append(missingEntities.stream()
                    .map(e -> JavaSourceParserUtil.simpleClassName(e)).collect(toList())).append(" are ");
        }
        if (isEmpty(entityMappings.getPackage())) {
            _package = "<default_root_package>";
        } else {
            _package = entityMappings.getPackage();
        }
        message.append("missing in Project classpath[").append(_package)
                .append("]. \n Would like to cancel the process ?");
        SwingUtilities.invokeLater(() -> {
            JButton cancel = new JButton("Cancel import process (Recommended)");
            JButton procced = new JButton("Procced");
            cancel.addActionListener((ActionEvent e) -> {
                Window w = SwingUtilities.getWindowAncestor(cancel);
                if (w != null) {
                    w.setVisible(false);
                }
                StringBuilder sb = new StringBuilder();
                sb.append('\n').append("You have following option to resolve conflict :").append('\n')
                        .append('\n');
                sb.append(
                        "1- New File > Persistence > JPA Diagram from Reverse Engineering (Manually select entities)")
                        .append('\n');
                sb.append(
                        "2- Recover missing entities manually > Reopen diagram file >  Import entities again");
                NotifyDescriptor nd = new NotifyDescriptor.Message(sb.toString(),
                        NotifyDescriptor.INFORMATION_MESSAGE);
                DialogDisplayer.getDefault().notify(nd);
            });
            procced.addActionListener(e -> {
                Window window = SwingUtilities.getWindowAncestor(cancel);
                if (nonNull(window)) {
                    window.setVisible(false);
                }
                manageEntityMapping(entityMappings);
                if (nonNull(targetFilePath) && nonNull(targetFileName)) {
                    JPAModelerUtil.createNewModelerFile(entityMappings, targetFilePath, targetFileName,
                            softWrite, autoOpen);
                }
            });

            JOptionPane.showOptionDialog(WindowManager.getDefault().getMainWindow(), message.toString(), title,
                    OK_CANCEL_OPTION, ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon"),
                    new Object[] { cancel, procced }, cancel);
        });

    } else {
        manageEntityMapping(entityMappings);
        if (nonNull(targetFilePath) && nonNull(targetFileName)) {
            JPAModelerUtil.createNewModelerFile(entityMappings, targetFilePath, targetFileName, softWrite,
                    autoOpen);
        }
        return entityMappings;
    }

    throw new ProcessInterruptedException();
}

From source file:com.nbt.TreeFrame.java

private void createActions() {
    newAction = new NBTAction("New", "New", "New", KeyEvent.VK_N) {

        {//from  w w  w.ja v  a2 s .  com
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('N', Event.CTRL_MASK));
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            updateTreeTable(new CompoundTag(""));
        }

    };

    browseAction = new NBTAction("Browse...", "Open", "Browse...", KeyEvent.VK_O) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('O', Event.CTRL_MASK));
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser fc = createFileChooser();
            switch (fc.showOpenDialog(TreeFrame.this)) {
            case JFileChooser.APPROVE_OPTION:
                File file = fc.getSelectedFile();
                Preferences prefs = getPreferences();
                prefs.put(KEY_FILE, file.getAbsolutePath());
                doImport(file);
                break;
            }
        }

    };

    saveAction = new NBTAction("Save", "Save", "Save", KeyEvent.VK_S) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('S', Event.CTRL_MASK));
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            String path = textFile.getText();
            File file = new File(path);
            if (file.canWrite()) {
                doExport(file);
            } else {
                saveAsAction.actionPerformed(e);
            }
        }

    };

    saveAsAction = new NBTAction("Save As...", "SaveAs", "Save As...", KeyEvent.VK_UNDEFINED) {

        public void actionPerformed(ActionEvent e) {
            JFileChooser fc = createFileChooser();
            switch (fc.showSaveDialog(TreeFrame.this)) {
            case JFileChooser.APPROVE_OPTION:
                File file = fc.getSelectedFile();
                Preferences prefs = getPreferences();
                prefs.put(KEY_FILE, file.getAbsolutePath());
                doExport(file);
                break;
            }
        }

    };

    refreshAction = new NBTAction("Refresh", "Refresh", "Refresh", KeyEvent.VK_F5) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("F5"));
        }

        public void actionPerformed(ActionEvent e) {
            String path = textFile.getText();
            File file = new File(path);
            if (file.canRead())
                doImport(file);
            else
                showErrorDialog("The file could not be read.");
        }

    };

    exitAction = new NBTAction("Exit", "Exit", KeyEvent.VK_ESCAPE) {

        @Override
        public void actionPerformed(ActionEvent e) {
            // TODO: this should check to see if any changes have been made
            // before exiting
            System.exit(0);
        }

    };

    cutAction = new DefaultEditorKit.CutAction() {

        {
            String name = "Cut";
            putValue(NAME, name);
            putValue(SHORT_DESCRIPTION, name);
            putValue(MNEMONIC_KEY, KeyEvent.VK_X);
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('X', Event.CTRL_MASK));

            ImageFactory factory = new ImageFactory();
            try {
                putValue(SMALL_ICON, new ImageIcon(factory.readGeneralImage(name, NBTAction.smallIconSize)));
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                putValue(LARGE_ICON_KEY,
                        new ImageIcon(factory.readGeneralImage(name, NBTAction.largeIconSize)));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    };

    copyAction = new DefaultEditorKit.CopyAction() {

        {
            String name = "Copy";
            putValue(NAME, name);
            putValue(SHORT_DESCRIPTION, name);
            putValue(MNEMONIC_KEY, KeyEvent.VK_C);
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('C', Event.CTRL_MASK));

            ImageFactory factory = new ImageFactory();
            try {
                putValue(SMALL_ICON, new ImageIcon(factory.readGeneralImage(name, NBTAction.smallIconSize)));
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                putValue(LARGE_ICON_KEY,
                        new ImageIcon(factory.readGeneralImage(name, NBTAction.largeIconSize)));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    };

    pasteAction = new DefaultEditorKit.CutAction() {

        {
            String name = "Paste";
            putValue(NAME, name);
            putValue(SHORT_DESCRIPTION, name);
            putValue(MNEMONIC_KEY, KeyEvent.VK_V);
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('V', Event.CTRL_MASK));

            ImageFactory factory = new ImageFactory();
            try {
                putValue(SMALL_ICON, new ImageIcon(factory.readGeneralImage(name, NBTAction.smallIconSize)));
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                putValue(LARGE_ICON_KEY,
                        new ImageIcon(factory.readGeneralImage(name, NBTAction.largeIconSize)));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    };

    deleteAction = new NBTAction("Delete", "Delete", "Delete", KeyEvent.VK_DELETE) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("DELETE"));
        }

        public void actionPerformed(ActionEvent e) {
            int row = treeTable.getSelectedRow();
            TreePath path = treeTable.getPathForRow(row);
            Object last = path.getLastPathComponent();

            if (last instanceof NBTFileBranch) {
                NBTFileBranch branch = (NBTFileBranch) last;
                File file = branch.getFile();
                String name = file.getName();
                String message = "Are you sure you want to delete " + name + "?";
                String title = "Continue?";
                int option = JOptionPane.showConfirmDialog(TreeFrame.this, message, title,
                        JOptionPane.OK_CANCEL_OPTION);
                switch (option) {
                case JOptionPane.CANCEL_OPTION:
                    return;
                }
                if (!FileUtils.deleteQuietly(file)) {
                    showErrorDialog(name + " could not be deleted.");
                    return;
                }
            }

            TreePath parentPath = path.getParentPath();
            Object parentLast = parentPath.getLastPathComponent();
            NBTTreeTableModel model = treeTable.getTreeTableModel();
            int index = model.getIndexOfChild(parentLast, last);
            if (parentLast instanceof Mutable<?>) {
                Mutable<?> mutable = (Mutable<?>) parentLast;
                if (last instanceof ByteWrapper) {
                    ByteWrapper wrapper = (ByteWrapper) last;
                    index = wrapper.getIndex();
                }
                mutable.remove(index);
            } else {
                System.err.println(last.getClass());
                return;
            }

            updateTreeTable();
            treeTable.expandPath(parentPath);
            scrollTo(parentLast);
            treeTable.setRowSelectionInterval(row, row);
        }

    };

    openAction = new NBTAction("Open...", "Open...", KeyEvent.VK_T) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('T', Event.CTRL_MASK));

            final int diamondPickaxe = 278;
            SpriteRecord record = NBTTreeTable.register.getRecord(diamondPickaxe);
            BufferedImage image = record.getImage();
            setSmallIcon(image);

            int width = 24, height = 24;
            Dimension size = new Dimension(width, height);
            Map<RenderingHints.Key, ?> hints = Thumbnail.createRenderingHints(Thumbnail.QUALITY);
            BufferedImage largeImage = Thumbnail.createThumbnail(image, size, hints);
            setLargeIcon(largeImage);
        }

        public void actionPerformed(ActionEvent e) {
            TreePath path = treeTable.getPath();
            if (path == null)
                return;

            Object last = path.getLastPathComponent();
            if (last instanceof Region) {
                Region region = (Region) last;
                createAndShowTileCanvas(new TileCanvas.TileWorld(region));
                return;
            } else if (last instanceof World) {
                World world = (World) last;
                createAndShowTileCanvas(world);
                return;
            }

            if (last instanceof NBTFileBranch) {
                NBTFileBranch fileBranch = (NBTFileBranch) last;
                File file = fileBranch.getFile();
                try {
                    open(file);
                } catch (IOException ex) {
                    ex.printStackTrace();
                    showErrorDialog(ex.getMessage());
                }
            }
        }

        private void open(File file) throws IOException {
            if (Desktop.isDesktopSupported()) {
                Desktop desktop = Desktop.getDesktop();
                if (desktop.isSupported(Desktop.Action.OPEN)) {
                    desktop.open(file);
                }
            }
        }

    };

    addByteAction = new NBTAction("Add Byte", NBTConstants.TYPE_BYTE, "Add Byte", KeyEvent.VK_1) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('1', Event.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            addTag(new ByteTag("new byte", (byte) 0));
        }

    };

    addShortAction = new NBTAction("Add Short", NBTConstants.TYPE_SHORT, "Add Short", KeyEvent.VK_2) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('2', Event.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            addTag(new ShortTag("new short", (short) 0));
        }

    };

    addIntAction = new NBTAction("Add Integer", NBTConstants.TYPE_INT, "Add Integer", KeyEvent.VK_3) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('3', Event.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            addTag(new IntTag("new int", 0));
        }

    };

    addLongAction = new NBTAction("Add Long", NBTConstants.TYPE_LONG, "Add Long", KeyEvent.VK_4) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('4', Event.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            addTag(new LongTag("new long", 0));
        }

    };

    addFloatAction = new NBTAction("Add Float", NBTConstants.TYPE_FLOAT, "Add Float", KeyEvent.VK_5) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('5', Event.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            addTag(new FloatTag("new float", 0));
        }

    };

    addDoubleAction = new NBTAction("Add Double", NBTConstants.TYPE_DOUBLE, "Add Double", KeyEvent.VK_6) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('6', Event.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            addTag(new DoubleTag("new double", 0));
        }

    };

    addByteArrayAction = new NBTAction("Add Byte Array", NBTConstants.TYPE_BYTE_ARRAY, "Add Byte Array",
            KeyEvent.VK_7) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('7', Event.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            addTag(new ByteArrayTag("new byte array"));
        }

    };

    addStringAction = new NBTAction("Add String", NBTConstants.TYPE_STRING, "Add String", KeyEvent.VK_8) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('8', Event.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            addTag(new StringTag("new string", "..."));
        }

    };

    addListAction = new NBTAction("Add List Tag", NBTConstants.TYPE_LIST, "Add List Tag", KeyEvent.VK_9) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('9', Event.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            Class<? extends Tag> type = queryType();
            if (type != null)
                addTag(new ListTag("new list", null, type));
        }

        private Class<? extends Tag> queryType() {
            Object[] items = { NBTConstants.TYPE_BYTE, NBTConstants.TYPE_SHORT, NBTConstants.TYPE_INT,
                    NBTConstants.TYPE_LONG, NBTConstants.TYPE_FLOAT, NBTConstants.TYPE_DOUBLE,
                    NBTConstants.TYPE_BYTE_ARRAY, NBTConstants.TYPE_STRING, NBTConstants.TYPE_LIST,
                    NBTConstants.TYPE_COMPOUND };
            JComboBox comboBox = new JComboBox(new DefaultComboBoxModel(items));
            comboBox.setRenderer(new DefaultListCellRenderer() {

                @Override
                public Component getListCellRendererComponent(JList list, Object value, int index,
                        boolean isSelected, boolean cellHasFocus) {
                    super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

                    if (value instanceof Integer) {
                        Integer i = (Integer) value;
                        Class<? extends Tag> c = NBTUtils.getTypeClass(i);
                        String name = NBTUtils.getTypeName(c);
                        setText(name);
                    }

                    return this;
                }

            });
            Object[] message = { new JLabel("Please select a type."), comboBox };
            String title = "Title goes here";
            int result = JOptionPane.showOptionDialog(TreeFrame.this, message, title,
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
            switch (result) {
            case JOptionPane.OK_OPTION:
                ComboBoxModel model = comboBox.getModel();
                Object item = model.getSelectedItem();
                if (item instanceof Integer) {
                    Integer i = (Integer) item;
                    return NBTUtils.getTypeClass(i);
                }
            }
            return null;
        }

    };

    addCompoundAction = new NBTAction("Add Compound Tag", NBTConstants.TYPE_COMPOUND, "Add Compound Tag",
            KeyEvent.VK_0) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('0', Event.CTRL_MASK));
        }

        public void actionPerformed(ActionEvent e) {
            addTag(new CompoundTag());
        }

    };

    String name = "About " + TITLE;
    helpAction = new NBTAction(name, "Help", name, KeyEvent.VK_F1) {

        {
            putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("F1"));
        }

        public void actionPerformed(ActionEvent e) {
            Object[] message = { new JLabel(TITLE + " " + VERSION),
                    new JLabel("\u00A9 Copyright Taggart Spilman 2011.  All rights reserved."),
                    new Hyperlink("<html><a href=\"#\">NamedBinaryTag.com</a></html>",
                            "http://www.namedbinarytag.com"),
                    new Hyperlink("<html><a href=\"#\">Contact</a></html>", "mailto:tagadvance@gmail.com"),
                    new JLabel(" "),
                    new Hyperlink("<html><a href=\"#\">JNBT was written by Graham Edgecombe</a></html>",
                            "http://jnbt.sf.net"),
                    new Hyperlink("<html><a href=\"#\">Available open-source under the BSD license</a></html>",
                            "http://jnbt.sourceforge.net/LICENSE.TXT"),
                    new JLabel(" "), new JLabel("This product includes software developed by"),
                    new Hyperlink("<html><a href=\"#\">The Apache Software Foundation</a>.</html>",
                            "http://www.apache.org"),
                    new JLabel(" "), new JLabel("Default texture pack:"),
                    new Hyperlink("<html><a href=\"#\">SOLID COLOUR. SOLID STYLE.</a></html>",
                            "http://www.minecraftforum.net/topic/72253-solid-colour-solid-style/"),
                    new JLabel("Bundled with the permission of Trigger_Proximity."),

            };
            String title = "About";
            JOptionPane.showMessageDialog(TreeFrame.this, message, title, JOptionPane.INFORMATION_MESSAGE);
        }

    };

}

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

protected void closeDialog() {
    try {//w w w  .  jav a 2s . com
        String msg = null;
        if (transformationRunning)
            msg = "Eine Profilerzeugung luft derzeit.\n";// Meldung

        if (msg != null) {
            msg += "Soll die Anwendung beendet werden?";
            Object[] options = { "Exit", "Cancel" };
            int val = JOptionPane.showOptionDialog(null, msg, "Confirmation", JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
            if (val == 1)
                return;
        }

        if (model != null)
            model.shutdown();

        System.exit(0);
    } catch (Exception e) {
        System.out.println("closeDialog - Exception: " + e.toString());
        //System.exit(1);
    }
}

From source file:edu.ku.brc.af.ui.forms.IconViewObj.java

/**
 * /*w  w w  .j  a  va2 s .c  o  m*/
 */
protected void doDelete() {
    FormDataObjIFace dataObj = iconTray.getSelection();
    if (dataObj != null) {
        Object[] delBtnLabels = { getResourceString("Delete"), getResourceString("CANCEL") };
        int rv = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(),
                UIRegistry.getLocalizedMessage("ASK_DELETE", dataObj.getIdentityTitle()),
                getResourceString("Delete"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                delBtnLabels, delBtnLabels[1]);
        if (rv == JOptionPane.YES_OPTION) {

            iconTray.removeItem(dataObj);
            parentDataObj.removeReference(dataObj, IconViewObj.this.cellName);
            if (mvParent != null) {
                MultiView topLvl = mvParent.getTopLevel();
                topLvl.addDeletedItem(dataObj);
                rootHasChanged();
            }
            iconTray.repaint();
            updateEnableUI();

            rootHasChanged();
        }
    }
}

From source file:net.sf.firemox.Magic.java

public void actionPerformed(ActionEvent e) {
    final String command = e.getActionCommand();
    final Object obj = e.getSource();
    if (obj == sendButton) {
        if (sendTxt.getText().length() != 0) {
            MChat.getInstance().sendMessage(sendTxt.getText() + "\n");
            sendTxt.setText("");
        }//w  w w .  j  ava  2s .c om
    } else if (command != null && command.startsWith("border-")) {
        for (int i = cardBorderMenu.getComponentCount(); i-- > 0;) {
            ((JRadioButtonMenuItem) cardBorderMenu.getComponent(i)).setSelected(false);
        }
        ((JRadioButtonMenuItem) obj).setSelected(true);
        CardFactory.updateColor(command.substring("border-".length()));
        CardFactory.updateAllCardsUI();
        magicForm.repaint();
    } else if ("menu_help_mailing".equals(command)) {
        try {
            WebBrowser.launchBrowser(
                    "http://lists.sourceforge.net/lists/listinfo/" + IdConst.PROJECT_NAME + "-user");
        } catch (Exception e1) {
            JOptionPane.showOptionDialog(this, LanguageManager.getString("error") + " : " + e1.getMessage(),
                    LanguageManager.getString("web-pb"), JOptionPane.OK_OPTION, JOptionPane.INFORMATION_MESSAGE,
                    UIHelper.getIcon("wiz_update_error.gif"), null, null);
        }
    } else if ("menu_options_settings".equals(command)) {
        // Setting panel
        final Wizard settingsPanel = new Settings();
        settingsPanel.setVisible(true);
    } else if ("menu_help_check-update".equals(command)) {
        VersionChecker.checkVersion(this);
    } else if ("menu_game_new_client".equals(command)) {
        new net.sf.firemox.ui.wizard.Client().setVisible(true);
    } else if ("menu_game_new_server".equals(command)) {
        new net.sf.firemox.ui.wizard.Server().setVisible(true);
    } else if ("menu_tools_log".equals(command)) {
        new net.sf.firemox.ui.wizard.Log().setVisible(true);
    } else if ("menu_tools_featurerequest".equals(command)) {
        new Feature().setVisible(true);
    } else if ("menu_tools_bugreport".equals(command)) {
        new Bug().setVisible(true);
    } else if ("menu_game_skip".equals(command)) {
        if (ConnectionManager.isConnected() && skipButton.isEnabled() && StackManager.idHandedPlayer == 0) {
            StackManager.noReplayToken.take();
            try {
                manualSkip();
            } catch (Throwable t) {
                t.printStackTrace();
            } finally {
                StackManager.noReplayToken.release();
            }
        }
    } else if ("menu_game_disconnect".equals(command)) {
        ConnectionManager.closeConnexions();
    } else if ("menu_tools_jdb".equals(command)) {
        DeckBuilder.loadFromMagic();
    } else if ("menu_game_exit".equals(command)) {
        exitForm(null);
    } else if (obj == autoManaMenu) {
        /*
         * invoked you click directly on the "auto-mana option" of the menu
         * "options". The opponent has to know that we are in "auto colorless mana
         * use", since player will no longer click on the mana icon to define
         * which colored mana active player has used as colorless mana, then the
         * opponent have not to wait for active player choice, but apply the same
         * Algorithm calculating which colored manas are used as colorless manas.
         * This information is not sent immediately, but will be sent with the
         * next action of active player.
         */
        MCommonVars.autoMana = autoManaMenu.isSelected();
    } else if (obj == autoPlayMenu) {
        /*
         * invoked you click directly on the "auto-play option" of the menu
         * "options".
         */
        MCommonVars.autoStack = autoPlayMenu.isSelected();
    } else if ("menu_tools_jcb".equals(command)) {
        // TODO cardBuilderMenu -> not yet implemented
        Log.info("cardBuilderMenu -> not yet implemented");
    } else if ("menu_game_proxy".equals(command)) {
        new ProxyConfiguration().setVisible(true);
    } else if ("menu_help_help".equals(command)) {
        /*
         * Invoked you click directly on youLabel. Opponent will receive this
         * information.
         */
        try {
            WebBrowser.launchBrowser("http://prdownloads.sourceforge.net/" + IdConst.PROJECT_NAME
                    + "/7e_rulebook_EN.pdf?download");
        } catch (Exception e1) {
            JOptionPane.showOptionDialog(this, LanguageManager.getString("error") + " : " + e1.getMessage(),
                    LanguageManager.getString("web-pb"), JOptionPane.OK_OPTION, JOptionPane.INFORMATION_MESSAGE,
                    UIHelper.getIcon("wiz_update_error.gif"), null, null);
        }
    } else if ("menu_help_about".equals(command)) {
        new About(this).setVisible(true);
    } else if ("menu_help_about.tbs".equals(command)) {
        new AboutMdb(this).setVisible(true);
    } else if (obj == reverseArtCheck || obj == reverseSideCheck) {
        Configuration.setProperty("reverseArt", reverseArtCheck.isSelected());
        Configuration.setProperty("reverseSide", reverseSideCheck.isSelected());
        ZoneManager.updateReversed();
        StackManager.PLAYERS[1].updateReversed();
        repaint();
        SwingUtilities.invokeLater(SkinLF.REFRESH_RUNNER);
    } else if (obj == soundMenu) {
        Configuration.setProperty("sound", soundMenu.isSelected());
        soundMenu.setIcon(
                soundMenu.isSelected() ? UIHelper.getIcon("sound.gif") : UIHelper.getIcon("soundoff.gif"));
    } else if ("menu_lf_randomAngle".equals(command)) {
        Configuration.setProperty("randomAngle", ((AbstractButton) e.getSource()).isSelected());
        CardFactory.updateAllCardsUI();
    } else if ("menu_lf_powerToughnessColor".equals(command)) {
        final Color powerToughnessColor = JColorChooser.showDialog(this,
                LanguageManager.getString("menu_lf_powerToughnessColor"), CardFactory.powerToughnessColor);
        if (powerToughnessColor != null) {
            Configuration.setProperty("powerToughnessColor", powerToughnessColor.getRGB());
            CardFactory.updateColor(null);
            repaint();
        }
    } else if (obj == initialdelayMenu) {
        // TODO factor this code with the one of Magic.class
        final ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
        new InputNumber(LanguageManager.getString("initialdelay"),
                LanguageManager.getString("initialdelay.tooltip"), 0, Integer.MAX_VALUE,
                toolTipManager.getInitialDelay()).setVisible(true);
        if (Wizard.optionAnswer == JOptionPane.YES_OPTION) {
            toolTipManager.setEnabled(Wizard.indexAnswer != 0);
            toolTipManager.setInitialDelay(Wizard.indexAnswer);
            initialdelayMenu.setText(LanguageManager.getString("initialdelay")
                    + (toolTipManager.isEnabled() ? " : " + Wizard.indexAnswer + " ms" : "(disabled)"));
            Configuration.setProperty("initialdelay", Wizard.indexAnswer);
        }
    } else if (obj == dismissdelayMenu) {
        // TODO factor this code with the one of Magic.class
        final ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
        new InputNumber(LanguageManager.getString("dismissdelay"),
                LanguageManager.getString("dismissdelay.tooltip"), 0, Integer.MAX_VALUE,
                toolTipManager.getDismissDelay()).setVisible(true);
        if (Wizard.optionAnswer == JOptionPane.YES_OPTION) {
            toolTipManager.setDismissDelay(Wizard.indexAnswer);
            Configuration.setProperty("dismissdelay", Wizard.indexAnswer);
            dismissdelayMenu.setText(LanguageManager.getString("dismissdelay") + Wizard.indexAnswer + " ms");
        }
    }

}

From source file:com.holycityaudio.SpinCAD.SpinCADFile.java

public void fileSaveSpj(SpinCADBank bank) {
    // Create a file chooser
    String savedPath = prefs.get("MRUSpjFolder", "");
    String[] spnFileNames = new String[8];

    final JFileChooser fc = new JFileChooser(savedPath);
    // In response to a button click:
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Spin Project Files", "spj");
    fc.setFileFilter(filter);/*  w w w  .  j  a  v a 2 s.  c o m*/
    // XXX debug
    fc.showSaveDialog(new JFrame());
    File fileToBeSaved = fc.getSelectedFile();

    if (!fc.getSelectedFile().getAbsolutePath().endsWith(".spj")) {
        fileToBeSaved = new File(fc.getSelectedFile() + ".spj");
    }
    int n = JOptionPane.YES_OPTION;
    if (fileToBeSaved.exists()) {
        JFrame frame1 = new JFrame();
        n = JOptionPane.showConfirmDialog(frame1, "Would you like to overwrite it?", "File already exists!",
                JOptionPane.YES_NO_OPTION);
    }
    if (n == JOptionPane.YES_OPTION) {
        // filePath points at the desired Spj file
        String filePath = fileToBeSaved.getPath();
        String folder = fileToBeSaved.getParent().toString();

        // export the individual SPN files
        for (int i = 0; i < 8; i++) {
            try {
                String asmFileNameRoot = FilenameUtils.removeExtension(bank.patch[i].patchFileName);
                String asmFileName = folder + "\\" + asmFileNameRoot + ".spn";
                if (bank.patch[i].patchFileName != "Untitled") {
                    fileSaveAsm(bank.patch[i], asmFileName);
                    spnFileNames[i] = asmFileName;
                }
            } catch (IOException e) {
                JOptionPane.showOptionDialog(null, "File save error!", "Error", JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE, null, null, null);

                e.printStackTrace();
            } finally {
            }
        }

        // now create the Spin Project file
        fileToBeSaved.delete();
        BufferedWriter writer = null;
        try {
            writer = new BufferedWriter(new FileWriter(fileToBeSaved, true));
        } catch (IOException e1) {
            e1.printStackTrace();
        }

        try {
            writer.write("NUMDOCS:8");
            writer.newLine();
        } catch (IOException e1) {
            e1.printStackTrace();
        }

        for (int i = 0; i < 8; i++) {
            try {
                if (bank.patch[i].patchFileName != "Untitled") {
                    writer.write(spnFileNames[i] + ",1");
                } else {
                    writer.write(",0");
                }
                writer.newLine();
            } catch (IOException e) {
                JOptionPane.showOptionDialog(null, "File save error!\n" + filePath, "Error",
                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);

                e.printStackTrace();
            }
        }
        // write the build flags
        try {
            writer.write(",1,1,1");
            writer.newLine();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        try {
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        saveMRUSpjFolder(filePath);
    }
}

From source file:com.sec.ose.osi.ui.frm.main.manage.JPanManageMain.java

/**
 * This method initializes jButtonSearch   
 *    //from   www.  j a  va 2s . c  om
 * @return javax.swing.JButton   
 */
private JButton getJButtonAdd() {
    if (jButtonAdd == null) {
        jButtonAdd = new JButton();
        jButtonAdd.setText("   Add   ");
        jButtonAdd.setPreferredSize(new Dimension(75, 28));
        jButtonAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
                log.debug("actionPerformed() : Add Button Clicked!");
                if (OSIProjectInfoMgr.getInstance().getAllProjects().size() > 0) {
                    JDlgProjectAdd dlgProjectList = new JDlgProjectAdd(frmOwner);
                    dlgProjectList.setManageMain(JPanManageMain.this);
                    dlgProjectList.setSize(600, 300);
                    WindowUtil.locateCenter(dlgProjectList);
                    dlgProjectList.setVisible(true);
                } else {
                    String[] buttonOK = { "OK" };
                    JOptionPane.showOptionDialog(null, "There is no project", "Search Project",
                            JOptionPane.OK_OPTION, JOptionPane.WARNING_MESSAGE, null, buttonOK, "OK");
                    return;
                }
            }
        });
    }
    return jButtonAdd;
}

From source file:de.adv_online.aaa.katalogtool.KatalogDialog.java

protected void closeDialog() {
    try {//from   www  .j  a  va 2s . com
        String msg = null;
        if (transformationRunning)
            msg = "Eine Katalogerzeugung luft derzeit.\n";// Meldung

        if (msg != null) {
            msg += "Soll die Anwendung beendet werden?";
            Object[] options = { "Exit", "Cancel" };
            int val = JOptionPane.showOptionDialog(null, msg, "Confirmation", JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
            if (val == 1)
                return;
        }

        if (model != null)
            model.shutdown();

        System.exit(0);
    } catch (Exception e) {
        System.out.println("closeDialog - Exception: " + e.toString());
        //System.exit(1);
    }
}