Search in sources :

Example 1 with JOptionPane

use of javax.swing.JOptionPane in project jna by java-native-access.

the class Excelautomation_KB_219151_Mod method displayQuaterlySales.

private static void displayQuaterlySales(ComIWorksheet sheet) {
    // Determine how many quarters to display data for.
    int iNumQtrs = 4;
    for (; iNumQtrs >= 2; iNumQtrs--) {
        JOptionPane pane = new JOptionPane(String.format("Enter sales data for %d quarter(s)?", iNumQtrs), JOptionPane.QUESTION_MESSAGE);
        pane.setOptionType(JOptionPane.YES_NO_OPTION);
        JDialog dialog = pane.createDialog("Input...");
        dialog.setAlwaysOnTop(true);
        dialog.show();
        if (((Integer) pane.getValue()) == JOptionPane.YES_OPTION) {
            break;
        }
    }
    JOptionPane.showMessageDialog(null, String.format("Displaying data for %d quarter(s).", iNumQtrs));
    // Starting at E1, fill headers for the number of columns selected.
    ComIRange oResizeRange = sheet.getRange("E1", "E1").getResize(VARIANT_MISSING, iNumQtrs);
    oResizeRange.setFormula("=\"Q\" & COLUMN() - 4 & CHAR(10) & \"Sales\"");
    // Change the Orientation and WrapText properties for the headers.
    oResizeRange.setOrientation(38);
    oResizeRange.setWrapText(true);
    // Fill the interior color of the headers.
    oResizeRange.getInterior().setColorIndex(36);
    // Fill the columns with a formula and apply a number format.
    oResizeRange = sheet.getRange("E2", "E6").getResize(VARIANT_MISSING, iNumQtrs);
    oResizeRange.setFormula("=RAND()*100");
    oResizeRange.setNumberFormat("$0.00");
    // Apply borders to the Sales data and headers.
    oResizeRange = sheet.getRange("E1", "E6").getResize(VARIANT_MISSING, iNumQtrs);
    oResizeRange.getBorders().setWeight(XlBorderWeight.xlThin);
    // Add a Totals formula for the sales data and apply a border.
    oResizeRange = sheet.getRange("E8", "E8").getResize(VARIANT_MISSING, iNumQtrs);
    oResizeRange.setFormula("=SUM(E2:E6)");
    Borders oResizeRangeBorders = oResizeRange.getBorders();
    oResizeRangeBorders.setLineStyle(XlLineStyle.xlDouble);
    oResizeRangeBorders.setWeight(XlBorderWeight.xlThick);
    // Add a Chart for the selected data
    oResizeRange = sheet.getRange("E2:E6").getResize(VARIANT_MISSING, iNumQtrs);
    Chart chart = sheet.getParent().getCharts().Add(VARIANT_MISSING, VARIANT_MISSING, VARIANT_MISSING, VARIANT_MISSING);
    // Java note: Assumption is, that VARIANT_MISSING is the correct indicator
    // for missing values, it turns out, NULL is correct in this case...
    chart.ChartWizard(oResizeRange, XlChartType.xl3DColumn, VARIANT_MISSING, XlRowCol.xlColumns, null, null, null, null, null, null, null);
    chart.SeriesCollection(1).setXValues(sheet.getRange("C2", "C6"));
    for (int i = 1; i <= iNumQtrs; i++) {
        chart.SeriesCollection(i).setName("=\"Q" + Integer.toString(i) + "\"");
    }
    chart.Location(XlChartLocation.xlLocationAsObject, sheet.getName());
    // Move the chart so as not to cover your data.
    Shape shape = sheet.getShapes().Item(1);
    shape.setTop(sheet.getRows(10).getTop());
    shape.setLeft(sheet.getColumns(2).getLeft());
}
Also used : ComIRange(com.sun.jna.platform.win32.COM.util.office.excel.ComIRange) Shape(com.sun.jna.platform.win32.COM.util.office.excel.Shape) JOptionPane(javax.swing.JOptionPane) Borders(com.sun.jna.platform.win32.COM.util.office.excel.Borders) JDialog(javax.swing.JDialog) Chart(com.sun.jna.platform.win32.COM.util.office.excel.Chart)

Example 2 with JOptionPane

use of javax.swing.JOptionPane in project processing by processing.

the class Messages method showYesNoCancelQuestion.

// ...................................................................
// incomplete
public static int showYesNoCancelQuestion(Editor editor, String title, String primary, String secondary) {
    if (!Platform.isMacOS()) {
        int result = JOptionPane.showConfirmDialog(null, primary + "\n" + secondary, title, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
        return result;
    //    if (result == JOptionPane.YES_OPTION) {
    //
    //    } else if (result == JOptionPane.NO_OPTION) {
    //      return true;  // ok to continue
    //
    //    } else if (result == JOptionPane.CANCEL_OPTION) {
    //      return false;
    //
    //    } else {
    //      throw new IllegalStateException();
    //    }
    } else {
        // Pane formatting adapted from the Quaqua guide
        // http://www.randelshofer.ch/quaqua/guide/joptionpane.html
        JOptionPane pane = new JOptionPane("<html> " + "<head> <style type=\"text/css\">" + "b { font: 13pt \"Lucida Grande\" }" + "p { font: 11pt \"Lucida Grande\"; margin-top: 8px; width: 300px }" + "</style> </head>" + "<b>" + Language.text("save.title") + "</b>" + "<p>" + Language.text("save.hint") + "</p>", JOptionPane.QUESTION_MESSAGE);
        String[] options = new String[] { Language.text("save.btn.save"), Language.text("prompt.cancel"), Language.text("save.btn.dont_save") };
        pane.setOptions(options);
        // highlight the safest option ala apple hig
        pane.setInitialValue(options[0]);
        // on macosx, setting the destructive property places this option
        // away from the others at the lefthand side
        pane.putClientProperty("Quaqua.OptionPane.destructiveOption", Integer.valueOf(2));
        JDialog dialog = pane.createDialog(editor, null);
        dialog.setVisible(true);
        Object result = pane.getValue();
        if (result == options[0]) {
            return JOptionPane.YES_OPTION;
        } else if (result == options[1]) {
            return JOptionPane.CANCEL_OPTION;
        } else if (result == options[2]) {
            return JOptionPane.NO_OPTION;
        } else {
            return JOptionPane.CLOSED_OPTION;
        }
    }
}
Also used : JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog)

Example 3 with JOptionPane

use of javax.swing.JOptionPane in project processing by processing.

the class Messages method showWarningTiered.

/**
   * Non-fatal error message with optional stack trace side dish.
   */
public static void showWarningTiered(String title, String primary, String secondary, Throwable e) {
    if (title == null)
        title = "Warning";
    final String message = primary + "\n" + secondary;
    if (Base.isCommandLine()) {
        System.out.println(title + ": " + message);
    } else {
        //                                    title, JOptionPane.WARNING_MESSAGE);
        if (!Platform.isMacOS()) {
            JOptionPane.showMessageDialog(new JFrame(), "<html><body>" + "<b>" + primary + "</b>" + "<br>" + secondary, title, JOptionPane.WARNING_MESSAGE);
        } else {
            // Pane formatting adapted from the Quaqua guide
            // http://www.randelshofer.ch/quaqua/guide/joptionpane.html
            JOptionPane pane = new JOptionPane("<html> " + "<head> <style type=\"text/css\">" + "b { font: 13pt \"Lucida Grande\" }" + "p { font: 11pt \"Lucida Grande\"; margin-top: 8px; width: 300px }" + "</style> </head>" + "<b>" + primary + "</b>" + "<p>" + secondary + "</p>", JOptionPane.WARNING_MESSAGE);
            //        String[] options = new String[] {
            //            "Yes", "No"
            //        };
            //        pane.setOptions(options);
            // highlight the safest option ala apple hig
            //        pane.setInitialValue(options[0]);
            JDialog dialog = pane.createDialog(new JFrame(), null);
            dialog.setVisible(true);
        //        Object result = pane.getValue();
        //        if (result == options[0]) {
        //          return JOptionPane.YES_OPTION;
        //        } else if (result == options[1]) {
        //          return JOptionPane.NO_OPTION;
        //        } else {
        //          return JOptionPane.CLOSED_OPTION;
        //        }
        }
    }
    if (e != null)
        e.printStackTrace();
}
Also used : JFrame(javax.swing.JFrame) JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog)

Example 4 with JOptionPane

use of javax.swing.JOptionPane in project processing by processing.

the class Messages method showYesNoQuestion.

public static int showYesNoQuestion(Frame editor, String title, String primary, String secondary) {
    if (!Platform.isMacOS()) {
        return JOptionPane.showConfirmDialog(editor, "<html><body>" + "<b>" + primary + "</b>" + "<br>" + secondary, title, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
    } else {
        // Pane formatting adapted from the Quaqua guide
        // http://www.randelshofer.ch/quaqua/guide/joptionpane.html
        JOptionPane pane = new JOptionPane("<html> " + "<head> <style type=\"text/css\">" + "b { font: 13pt \"Lucida Grande\" }" + "p { font: 11pt \"Lucida Grande\"; margin-top: 8px; width: 300px }" + "</style> </head>" + "<b>" + primary + "</b>" + "<p>" + secondary + "</p>", JOptionPane.QUESTION_MESSAGE);
        String[] options = new String[] { "Yes", "No" };
        pane.setOptions(options);
        // highlight the safest option ala apple hig
        pane.setInitialValue(options[0]);
        JDialog dialog = pane.createDialog(editor, null);
        dialog.setVisible(true);
        Object result = pane.getValue();
        if (result == options[0]) {
            return JOptionPane.YES_OPTION;
        } else if (result == options[1]) {
            return JOptionPane.NO_OPTION;
        } else {
            return JOptionPane.CLOSED_OPTION;
        }
    }
}
Also used : JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog)

Example 5 with JOptionPane

use of javax.swing.JOptionPane in project skype-java-api by taksan.

the class TestUtils method showCheckDialog.

public static void showCheckDialog(String message) {
    JOptionPane pane = new JOptionPane(message, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
    JDialog dialog = pane.createDialog(null, "Check by the tester");
    dialog.setVisible(true);
    int result = ((Integer) pane.getValue()).intValue();
    if (result != JOptionPane.YES_OPTION) {
        Assert.fail("\"" + message + "\" -> Failed");
    }
}
Also used : JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog)

Aggregations

JOptionPane (javax.swing.JOptionPane)19 JDialog (javax.swing.JDialog)12 JLabel (javax.swing.JLabel)10 JButton (javax.swing.JButton)6 JPanel (javax.swing.JPanel)6 JTextField (javax.swing.JTextField)5 JComboBox (javax.swing.JComboBox)4 Component (java.awt.Component)3 Dimension (java.awt.Dimension)3 BoxLayout (javax.swing.BoxLayout)3 JCheckBox (javax.swing.JCheckBox)3 BorderLayout (java.awt.BorderLayout)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 ArrayList (java.util.ArrayList)2 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)2 JColorChooser (javax.swing.JColorChooser)2 JFrame (javax.swing.JFrame)2 JScrollPane (javax.swing.JScrollPane)2 JTable (javax.swing.JTable)2