Example usage for javax.swing JSpinner JSpinner

List of usage examples for javax.swing JSpinner JSpinner

Introduction

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

Prototype

public JSpinner(SpinnerModel model) 

Source Link

Document

Constructs a spinner for the given model.

Usage

From source file:org.pentaho.reporting.ui.datasources.jdbc.ui.JdbcDataSourceDialog.java

/**
 * Creates the panel which holds the main content of the dialog
 *///from w w  w  .ja v a  2  s .  c  om
private void initDialog(final DesignTimeContext designTimeContext) {
    this.designTimeContext = designTimeContext;

    setTitle(Messages.getString("JdbcDataSourceDialog.Title"));
    setModal(true);

    globalTemplateAction = new GlobalTemplateAction();
    queryTemplateAction = new QueryTemplateAction();

    dialogModel = new NamedDataSourceDialogModel();
    dialogModel.addPropertyChangeListener(new ConfirmValidationHandler());

    connectionComponent = new JdbcConnectionPanel(dialogModel, designTimeContext);
    maxPreviewRowsSpinner = new JSpinner(new SpinnerNumberModel(10000, 1, Integer.MAX_VALUE, 1));

    final QueryNameTextFieldDocumentListener updateHandler = new QueryNameTextFieldDocumentListener();
    dialogModel.getQueries().addListDataListener(updateHandler);

    queryNameList = new JList(dialogModel.getQueries());
    queryNameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    queryNameList.setVisibleRowCount(5);
    queryNameList.addListSelectionListener(new QuerySelectedHandler());

    queryNameTextField = new JTextField();
    queryNameTextField.setColumns(35);
    queryNameTextField.setEnabled(dialogModel.isQuerySelected());
    queryNameTextField.getDocument().addDocumentListener(updateHandler);

    queryTextArea = new RSyntaxTextArea();
    queryTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SQL);
    queryTextArea.setEnabled(dialogModel.isQuerySelected());
    queryTextArea.getDocument().addDocumentListener(new QueryDocumentListener());

    globalScriptTextArea = new RSyntaxTextArea();
    globalScriptTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE);

    globalLanguageField = new SmartComboBox<ScriptEngineFactory>(
            new DefaultComboBoxModel(DataFactoryEditorSupport.getScriptEngineLanguages()));
    globalLanguageField.setRenderer(new QueryLanguageListCellRenderer());
    globalLanguageField.addActionListener(new UpdateScriptLanguageHandler());

    queryScriptTextArea = new RSyntaxTextArea();
    queryScriptTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE);
    queryScriptTextArea.getDocument().addDocumentListener(new QueryScriptDocumentListener());

    queryLanguageListCellRenderer = new QueryLanguageListCellRenderer();

    queryLanguageField = new SmartComboBox<ScriptEngineFactory>(
            new DefaultComboBoxModel(DataFactoryEditorSupport.getScriptEngineLanguages()));
    queryLanguageField.setRenderer(queryLanguageListCellRenderer);
    queryLanguageField.addActionListener(new UpdateScriptLanguageHandler());

    super.init();
}

From source file:org.pentaho.reporting.ui.datasources.mondrian.MondrianDataSourceEditor.java

protected void init(final DesignTimeContext context) {
    if (context == null) {
        throw new NullPointerException();
    }//ww w.j a  va  2 s. c om

    securityDialog = new MondrianSecurityDialog(this, context);

    setModal(true);

    this.context = context;

    globalTemplateAction = new GlobalTemplateAction();
    queryTemplateAction = new QueryTemplateAction();

    final QueryNameTextFieldDocumentListener updateHandler = new QueryNameTextFieldDocumentListener();
    final ConfirmEnableHandler confirmAction = new ConfirmEnableHandler();

    dialogModel = new NamedDataSourceDialogModel();
    dialogModel.getQueries().addListDataListener(updateHandler);
    dialogModel.addPropertyChangeListener(confirmAction);

    maxPreviewRowsSpinner = new JSpinner(new SpinnerNumberModel(10000, 1, Integer.MAX_VALUE, 1));

    cubeConnectionNameField = new JTextField(null, 0);
    cubeConnectionNameField.setColumns(30);
    cubeConnectionNameField.getDocument().addDocumentListener(confirmAction);

    filenameField = new JTextField(null, 0);
    filenameField.setColumns(30);
    filenameField.getDocument().addDocumentListener(confirmAction);
    dialogModel.setSchemaFileNameField(filenameField);

    queryNameTextField = new JTextField(null, 0);
    queryNameTextField.setColumns(35);
    queryNameTextField.setEnabled(dialogModel.isQuerySelected());
    queryNameTextField.getDocument().addDocumentListener(updateHandler);

    queryTextArea = new JTextArea((String) null);
    queryTextArea.setWrapStyleWord(true);
    queryTextArea.setLineWrap(true);
    queryTextArea.setRows(5);
    queryTextArea.getDocument().addDocumentListener(new QueryDocumentListener());

    queryNameList = new JList(getDialogModel().getQueries());
    queryNameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    queryNameList.setVisibleRowCount(5);
    queryNameList.addListSelectionListener(new QuerySelectedHandler());

    globalScriptTextArea = new RSyntaxTextArea();
    globalScriptTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE);

    globalLanguageField = new SmartComboBox<ScriptEngineFactory>(
            new DefaultComboBoxModel(DataFactoryEditorSupport.getScriptEngineLanguages()));
    globalLanguageField.setRenderer(new QueryLanguageListCellRenderer());
    globalLanguageField.addActionListener(new UpdateScriptLanguageHandler());

    queryScriptTextArea = new RSyntaxTextArea();
    queryScriptTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE);
    queryScriptTextArea.getDocument().addDocumentListener(new QueryScriptDocumentListener());

    queryLanguageListCellRenderer = new QueryLanguageListCellRenderer();

    queryLanguageField = new SmartComboBox<ScriptEngineFactory>(
            new DefaultComboBoxModel(DataFactoryEditorSupport.getScriptEngineLanguages()));
    queryLanguageField.setRenderer(queryLanguageListCellRenderer);
    queryLanguageField.addActionListener(new UpdateScriptLanguageHandler());

    // Return the center panel
    super.init();
}

From source file:org.pentaho.reporting.ui.datasources.olap4j.Olap4JDataSourceEditor.java

protected void init(final DesignTimeContext designTimeContext) {
    setModal(true);/*from  ww  w  .j  a  v  a2  s  .c om*/

    this.context = designTimeContext;

    final QueryNameTextFieldDocumentListener updateHandler = new QueryNameTextFieldDocumentListener();

    globalTemplateAction = new GlobalTemplateAction();
    queryTemplateAction = new QueryTemplateAction();

    dialogModel = new NamedDataSourceDialogModel(
            new JdbcConnectionDefinitionManager("org/pentaho/reporting/ui/datasources/olap4j/Settings"));
    dialogModel.addPropertyChangeListener(NamedDataSourceDialogModel.CONNECTION_SELECTED,
            new ConfirmEnableHandler());
    dialogModel.getQueries().addListDataListener(updateHandler);

    connectionComponent = new OlapConnectionPanel(dialogModel, designTimeContext);
    connectionComponent.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 8));

    maxPreviewRowsSpinner = new JSpinner(new SpinnerNumberModel(10000, 1, Integer.MAX_VALUE, 1));

    queryNameTextField = new JTextField();
    queryNameTextField.setColumns(35);
    queryNameTextField.setEnabled(dialogModel.isQuerySelected());
    queryNameTextField.getDocument().addDocumentListener(updateHandler);

    queryTextArea = new JTextArea((String) null);
    queryTextArea.setWrapStyleWord(true);
    queryTextArea.setLineWrap(true);
    queryTextArea.setRows(10);
    queryTextArea.setColumns(50);
    queryTextArea.setEnabled(dialogModel.isQuerySelected());
    queryTextArea.getDocument().addDocumentListener(new QueryDocumentListener());

    queryNameList = new JList(dialogModel.getQueries());
    queryNameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    queryNameList.setVisibleRowCount(5);
    queryNameList.addListSelectionListener(new QuerySelectedHandler());

    globalScriptTextArea = new RSyntaxTextArea();
    globalScriptTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE);

    globalLanguageField = new SmartComboBox<ScriptEngineFactory>(
            new DefaultComboBoxModel(DataFactoryEditorSupport.getScriptEngineLanguages()));
    globalLanguageField.setRenderer(new QueryLanguageListCellRenderer());
    globalLanguageField.addActionListener(new UpdateScriptLanguageHandler());

    queryScriptTextArea = new RSyntaxTextArea();
    queryScriptTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE);
    queryScriptTextArea.getDocument().addDocumentListener(new QueryScriptDocumentListener());

    queryLanguageListCellRenderer = new QueryLanguageListCellRenderer();

    queryLanguageField = new SmartComboBox<ScriptEngineFactory>(
            new DefaultComboBoxModel(DataFactoryEditorSupport.getScriptEngineLanguages()));
    queryLanguageField.setRenderer(queryLanguageListCellRenderer);
    queryLanguageField.addActionListener(new UpdateScriptLanguageHandler());

    super.init();
    // Return the center panel
}

From source file:org.pentaho.reporting.ui.datasources.pmd.PmdDataSourceEditor.java

private void init(final DesignTimeContext context) {
    if (context == null) {
        throw new NullPointerException();
    }//from   w  ww.ja  v a2  s  . c  o  m

    this.context = context;
    setModal(true);
    setTitle(Messages.getString("PmdDataSourceEditor.Title"));

    maxPreviewRowsSpinner = new JSpinner(new SpinnerNumberModel(10000, 1, Integer.MAX_VALUE, 1));
    previewAction = new PreviewAction();
    globalTemplateAction = new GlobalTemplateAction();
    queryTemplateAction = new QueryTemplateAction();

    filenameField = new JTextField(null, 0);
    filenameField.setColumns(30);
    filenameField.getDocument().addDocumentListener(new FilenameDocumentListener());

    queryNameList = new JList();
    queryNameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    queryNameList.setVisibleRowCount(5);
    queryNameList.addListSelectionListener(new QueryNameListSelectionListener());
    queryNameList.setCellRenderer(new QueryNameListCellRenderer());

    queryAddButton = new BorderlessButton(new AddQueryAction());
    queryRemoveButton = new BorderlessButton(new RemoveQueryAction());

    queryNameTextField = new JTextField(null, 0);
    queryNameTextField.setColumns(35);
    queryNameTextField.getDocument().addDocumentListener(new QueryNameTextFieldDocumentListener());

    domainIdTextField = new JTextField(null, 0);
    domainIdTextField.setColumns(35);
    domainIdTextField.getDocument().addDocumentListener(new DomainTextFieldDocumentListener());

    queryTextArea = new RSyntaxTextArea();
    queryTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
    queryTextArea.setWrapStyleWord(true);
    queryTextArea.setLineWrap(true);
    queryTextArea.setRows(5);
    queryTextArea.getDocument().addDocumentListener(new QueryDocumentListener());

    queryDesignerButton = new JButton(new QueryDesignerAction());
    queryDesignerButton.setEnabled(false);
    queryDesignerButton.setBorder(new EmptyBorder(0, 0, 0, 0));

    globalScriptTextArea = new RSyntaxTextArea();
    globalScriptTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE);

    globalLanguageField = new SmartComboBox(new DefaultComboBoxModel(getScriptEngineLanguages()));
    globalLanguageField.setRenderer(new QueryLanguageListCellRenderer());
    globalLanguageField.addActionListener(new UpdateScriptLanguageHandler());

    queryScriptTextArea = new RSyntaxTextArea();
    queryScriptTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE);
    queryScriptTextArea.getDocument().addDocumentListener(new QueryScriptDocumentListener());

    queryLanguageListCellRenderer = new QueryLanguageListCellRenderer();

    queryLanguageField = new SmartComboBox(new DefaultComboBoxModel(getScriptEngineLanguages()));
    queryLanguageField.setRenderer(queryLanguageListCellRenderer);
    queryLanguageField.addActionListener(new UpdateScriptLanguageHandler());

    super.init();
}

From source file:org.processmining.framework.log.filter.LogEventLogFilterEnh.java

/**
 * Returns a Panel for the setting of parameters. When a LogFilter can be
 * added to a list in the framework. This panel is shown, and parameters can
 * be set. When the dialog is closed, a new instance of a LogFilter is
 * created by the framework by calling the <code>getNewLogFilter</code>
 * method of the dialog./*from   w w w . j  av a 2s . c o  m*/
 * 
 * @param summary
 *            A LogSummary to be used for setting parameters.
 * @return JPanel
 */
public LogFilterParameterDialog getParameterDialog(LogSummary summary) {
    return new LogFilterParameterDialog(summary, LogEventLogFilterEnh.this) {

        LogEventCheckBoxEnh[] checks;
        JSpinner percTaskSpinner;
        JSpinner percPiSpinner;
        JComboBox choiceBox;

        /**
         * Keep the statistics for all the tasks
         */
        SummaryStatistics taskStatistics = null;

        /**
         * Keep the statistics for the occurrence of tasks in process
         * instances
         */
        SummaryStatistics piStatistics = null;

        public LogFilter getNewLogFilter() {
            LogEvents e = new LogEvents();
            for (int i = 0; i < checks.length; i++) {
                if (checks[i].isSelected()) {
                    e.add(checks[i].getLogEvent());
                }
            }
            return new LogEventLogFilterEnh(e, getDoubleValueFromSpinner(percTaskSpinner.getValue()),
                    getDoubleValueFromSpinner(percPiSpinner.getValue()),
                    choiceBox.getSelectedItem().toString());
        }

        protected JPanel getPanel() {
            // add message to the test log for this plugin
            Message.add("<EnhEvtLogFilter>", Message.TEST);
            // statistics
            taskStatistics = SummaryStatistics.newInstance();
            piStatistics = SummaryStatistics.newInstance();
            // Set up an percentformatter
            NumberFormat percentFormatter = NumberFormat.getPercentInstance();
            percentFormatter.setMinimumFractionDigits(2);
            percentFormatter.setMaximumFractionDigits(2);
            // Instantiate the spinners
            percTaskSpinner = new JSpinner(new SpinnerNumberModel(5.0, 0.0, 100.0, 1.0));
            percPiSpinner = new JSpinner(new SpinnerNumberModel(5.0, 0.0, 100.0, 1.0));
            // generate the buttons that are needed
            JButton jButtonCalculate = new JButton("Calculate");
            JButton jButtonInvert = new JButton("Invert selection");
            // set up a choicebox to indicate whether the relationship
            // between the two
            // percentages is AND or OR.

            percTaskSpinner.setValue(new Double(percentageTask));
            percPiSpinner.setValue(new Double(percentagePI));

            choiceBox = new JComboBox();
            choiceBox.addItem("AND");
            choiceBox.addItem("OR");
            choiceBox.setSelectedItem(selectedItemComboBox);

            // Some values that are needed for the sequel.
            int size = summary.getLogEvents().size();
            // For the new log reader sumATEs should be calculated in
            // another way
            int sumATEs = 0;
            if (summary instanceof ExtendedLogSummary) {
                sumATEs = summary.getNumberOfAuditTrailEntries();
            } else if (summary instanceof LightweightLogSummary) {
                HashSet<ProcessInstance> pis = new HashSet<ProcessInstance>();
                Iterator logEvents = summary.getLogEvents().iterator();
                while (logEvents.hasNext()) {
                    LogEvent evt = (LogEvent) logEvents.next();
                    pis.addAll(summary.getInstancesForEvent(evt));
                }
                Iterator pis2 = pis.iterator();
                while (pis2.hasNext()) {
                    ProcessInstance pi = (ProcessInstance) pis2.next();
                    int simPis = MethodsForWorkflowLogDataStructures.getNumberSimilarProcessInstances(pi);
                    int numberATEs = pi.getAuditTrailEntryList().size();
                    sumATEs += simPis * numberATEs;
                    pi.isEmpty();
                }
            } else {

            }
            // calculate the number of process Instances, taking into
            // account
            // the number of similar instances
            int sumPIs = 0;
            if (summary instanceof LightweightLogSummary) {
                sumPIs = calculateSumPIs(summary);
            }
            checks = new LogEventCheckBoxEnh[size];

            // create panels and labels
            JPanel global = new JPanel(new BorderLayout());
            JPanel sub2 = new JPanel(new BorderLayout());
            sub2.setBackground(Color.white);
            JLabel labelPercTask = new JLabel("percentage task");
            JLabel labelPercPI = new JLabel("percentage PI");

            // create panel sub1 to put the checkboxes on
            JPanel sub1 = new JPanel(new SpringLayout());
            sub1.setBackground(Color.lightGray);

            // Get percentage of task in the log and percentage of in how
            // many
            // different PIs it appears.
            Iterator it = summary.getLogEvents().iterator();
            int i = 0;
            while (it.hasNext()) {
                LogEvent evt = (LogEvent) it.next();
                double percent = 0.0;
                if (summary instanceof ExtendedLogSummary) {
                    percent = ((double) evt.getOccurrenceCount() / (double) sumATEs);
                } else if (summary instanceof LightweightLogSummary) {
                    Set instances = summary.getInstancesForEvent(evt);
                    // getFrequencyTasks(evt, instances)
                    percent = (double) getFrequencyTasks(evt, instances) / (double) sumATEs;
                } else {

                }
                // String percString = percentFormatter.format(percent);
                LogEventCheckBoxEnh check = new LogEventCheckBoxEnh(evt);
                check.setPercentageTask(percent * 100);
                // add percentage to the statistics for the tasks
                taskStatistics.addValue(percent);
                // Get percentage of in how many different PIs a task
                // appears,
                // taking into account whether the new or old logreader is
                // used
                if (summary instanceof LightweightLogSummary) {
                    Set<ProcessInstance> pis = summary.getInstancesForEvent(evt);
                    int numberInstancesTask = 0;
                    Iterator it2 = pis.iterator();
                    while (it2.hasNext()) {
                        ProcessInstance pi = (ProcessInstance) it2.next();
                        numberInstancesTask += MethodsForWorkflowLogDataStructures
                                .getNumberSimilarProcessInstances(pi);
                    }
                    double fPI = (double) numberInstancesTask / (double) sumPIs;

                    check.setPercentagePI(fPI * 100);
                    // add percentage to the statistics for the PIs
                    piStatistics.addValue(fPI);
                } else if (summary instanceof ExtendedLogSummary) {
                    double percPIcheck = getPercentagePI(evt);
                    check.setPercentagePI(percPIcheck);
                    piStatistics.addValue(percPIcheck / 100);
                } else {
                    // raise exception, unknown logreader
                }
                // add to the checks array
                checks[i++] = check;
            }
            // fill sub1 with statistics information
            sub1.add(new JLabel(" Statistics    ( #tasks = " + taskStatistics.getN() + " )"));
            sub1.add(new JLabel(" "));
            sub1.add(new JLabel(" "));
            sub1.add(new JLabel(" Arithmetic Mean "));
            sub1.add(new JLabel(percentFormatter.format(taskStatistics.getMean())));
            sub1.add(new JLabel(percentFormatter.format(piStatistics.getMean())));
            sub1.add(new JLabel(" Geometric Mean "));
            sub1.add(new JLabel(percentFormatter.format(taskStatistics.getGeometricMean())));
            sub1.add(new JLabel(percentFormatter.format(piStatistics.getGeometricMean())));
            sub1.add(new JLabel(" Standard Deviation "));
            sub1.add(new JLabel(percentFormatter.format(taskStatistics.getStandardDeviation())));
            sub1.add(new JLabel(percentFormatter.format(piStatistics.getStandardDeviation())));
            sub1.add(new JLabel(" Min "));
            sub1.add(new JLabel(percentFormatter.format(taskStatistics.getMin())));
            sub1.add(new JLabel(percentFormatter.format(piStatistics.getMin())));
            sub1.add(new JLabel(" Max "));
            sub1.add(new JLabel(percentFormatter.format(taskStatistics.getMax())));
            sub1.add(new JLabel(percentFormatter.format(piStatistics.getMax())));
            sub1.add(new JLabel(" ------------------ "));
            sub1.add(new JLabel(" --------------- "));
            sub1.add(new JLabel(" --------------- "));
            sub1.add(new JLabel(" Tasks "));
            sub1.add(new JLabel(" percentage task "));
            sub1.add(new JLabel(" percentage PI "));
            // generate messages for the test case for this plugin
            Message.add("number tasks: " + taskStatistics.getN(), Message.TEST);
            Message.add("<percentage task>", Message.TEST);
            Message.add("arithmetic mean: " + taskStatistics.getMean(), Message.TEST);
            Message.add("geometric mean: " + taskStatistics.getGeometricMean(), Message.TEST);
            Message.add("standard deviation: " + taskStatistics.getStandardDeviation(), Message.TEST);
            Message.add("min: " + taskStatistics.getMin(), Message.TEST);
            Message.add("max: " + taskStatistics.getMax(), Message.TEST);
            Message.add("<percentage task/>", Message.TEST);
            Message.add("<percentage PI>", Message.TEST);
            Message.add("arithmetic mean: " + piStatistics.getMean(), Message.TEST);
            Message.add("geometric mean: " + piStatistics.getGeometricMean(), Message.TEST);
            Message.add("standard deviation: " + piStatistics.getStandardDeviation(), Message.TEST);
            Message.add("min: " + piStatistics.getMin(), Message.TEST);
            Message.add("max: " + piStatistics.getMax(), Message.TEST);
            Message.add("<percentage PI/>", Message.TEST);
            // add the checkboxes to the GUI.
            Arrays.sort(checks);
            for (i = 0; i < checks.length; i++) {
                sub1.add(checks[i]);
                if ((eventsToKeep != null) && (!eventsToKeep.contains(checks[i].getLogEvent()))) {
                    checks[i].setSelected(false);
                }
                // put the percentages on the GUI
                sub1.add(new JLabel(percentFormatter.format(checks[i].getPercentageTask() / 100)));
                sub1.add(new JLabel(percentFormatter.format(checks[i].getPercentagePI() / 100)));
            }
            //
            SpringUtilities util = new SpringUtilities();
            util.makeCompactGrid(sub1, checks.length + 8, 3, 3, 3, 8, 3);
            // put the contents on the respective panels
            global.add(sub2, java.awt.BorderLayout.CENTER);
            global.add(sub1, java.awt.BorderLayout.SOUTH);
            //
            JPanel sub21 = new JPanel(new SpringLayout());
            // sub21.setLayout(new BoxLayout(sub21, BoxLayout.PAGE_AXIS));
            sub2.setBackground(Color.red);
            JPanel textPanel = new JPanel(new BorderLayout());
            textPanel.setBackground(Color.yellow);
            JPanel sub221 = new JPanel(new FlowLayout());
            sub221.setBackground(Color.yellow);
            JPanel sub222 = new JPanel(new FlowLayout());
            sub222.setBackground(Color.yellow);
            // two different panels to be places on sub21
            // JPanel sub21First = new JPanel();
            // sub21First.setLayout(new BoxLayout(sub21First,
            // BoxLayout.LINE_AXIS));
            // sub21First.setMaximumSize(new Dimension(1000, 25));
            // sub21First.add(Box.createHorizontalGlue());
            // sub21First.add(labelPercTask);
            // sub21First.add(percTaskSpinner, null);
            // percTaskSpinner.setMaximumSize(new Dimension(10, 20));
            // sub21First.add(jButtonCalculate);
            // jButtonCalculate.setMaximumSize(new Dimension(10, 20));
            // sub21First.add(labelPercPI);
            // sub21First.add(percPiSpinner, null);
            // percPiSpinner.setMaximumSize(new Dimension(10, 20));
            // sub21First.add(choiceBox);
            // choiceBox.setMaximumSize(new Dimension(10, 20));
            // sub21First.add(Box.createHorizontalGlue());
            // JPanel sub21Second = new JPanel();
            // sub21Second.setLayout(new BoxLayout(sub21Second,
            // BoxLayout.LINE_AXIS));
            // sub21Second.setMaximumSize(new Dimension(1000, 25));
            // sub21Second.add(Box.createHorizontalGlue());
            // sub21Second.add(jButtonInvert);
            // sub21Second.add(Box.createHorizontalGlue());
            //
            // sub21.add(sub21First);
            // sub21.add(sub21Second);

            sub21.add(labelPercTask);
            sub21.add(percTaskSpinner, null);
            sub21.add(jButtonCalculate);
            sub21.add(labelPercPI);
            sub21.add(percPiSpinner, null);
            sub21.add(choiceBox);
            // add the invert button
            sub21.add(new JLabel(" "));
            sub21.add(new JLabel(" "));
            sub21.add(jButtonInvert);
            sub21.add(new JLabel(" "));
            sub21.add(new JLabel(" "));
            sub21.add(new JLabel(" "));
            sub21.setMaximumSize(sub21.getPreferredSize());
            sub2.add(sub21, java.awt.BorderLayout.CENTER);
            sub2.add(textPanel, java.awt.BorderLayout.SOUTH);
            textPanel.add(new JLabel(
                    "The Calculate button needs to be clicked to calculate which tasks need to be selected!!!"),
                    java.awt.BorderLayout.CENTER);
            textPanel.add(
                    new JLabel("Clicking the OK button only accepts, but nothing is again calculated!!!!"),
                    java.awt.BorderLayout.SOUTH);
            util.makeCompactGrid(sub21, 2, 6, 3, 3, 8, 3);
            //

            // specify button action for the button ButtonPreview
            jButtonCalculate.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    // The preview button is clicked
                    buttonClicked();
                    // end for
                }
            });

            // specify button action for the button Invert
            jButtonInvert.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    invertButtonClicked();
                }
            });

            return global;

        }

        /**
         * When the preview button is clicked
         */
        public void buttonClicked() {
            for (int k = 0; k < checks.length; k++) {
                boolean firstCheck = false;
                boolean secondCheck = false;
                LogEventCheckBoxEnh c = checks[k];
                // check for the task in c whether its percentage is higher
                // than
                // perc
                firstCheck = checkTask(c, percTaskSpinner.getValue());

                // Also check whether the task occurs in more than percTr
                // percent of the traces
                secondCheck = checkPI(c, percPiSpinner.getValue());

                // Check whether for choiceBox OR or AND is selected
                boolean logicalResult = true;
                if (((String) choiceBox.getSelectedItem()).equals("AND")) {
                    logicalResult = firstCheck && secondCheck;
                } else if (((String) choiceBox.getSelectedItem()).equals("OR")) {
                    logicalResult = firstCheck || secondCheck;
                }
                // set the checkbox selected or not
                if (logicalResult == true) {
                    c.setSelected(true);
                } else {
                    c.setSelected(false);
                }
            }
            // add messages to the test log for this case
            int numberCheckedBoxes = 0;
            for (int i = 0; i < checks.length; i++) {
                if (checks[i].isSelected()) {
                    numberCheckedBoxes++;
                }
            }
            Message.add("number of selected tasks: " + numberCheckedBoxes, Message.TEST);
            Message.add("<EnhEvtLogFilter/>", Message.TEST);
        }

        /**
         *
         */
        public void invertButtonClicked() {
            for (int i = 0; i < checks.length; i++) {
                checks[i].setSelected(!checks[i].isSelected());
            }
        }

        /**
         * Checks whether the task in c occurs with a lower percentage in
         * the log than the percentage given by percTask.
         * 
         * @param c
         *            LogEventCheckBoxEnh the checkbox that contains the
         *            task.
         * @param percTask
         *            Object the percentage
         * @return boolean True if the percentage of which the task in c
         *         occurs in the log is greater or equal than percTaks,
         *         false otherwise.
         */
        private boolean checkTask(LogEventCheckBoxEnh c, Object percTask) {
            boolean returnBoolean = false;
            double percT = 0.0;
            percT = getDoubleValueFromSpinner(percTask);
            // check whether its percentage is higher than percT
            if (c.getPercentageTask() >= percT) {
                returnBoolean = true;
            } else {
                returnBoolean = false;
            }

            return returnBoolean;
        }

        /**
         * Checks whether the task in c occurs with a lower percentage in
         * different process instances than the percentage given by
         * percTrace.
         * 
         * @param c
         *            LogEventCheckBoxEnh the checkbox that contains the
         *            task.
         * @param percTrace
         *            Object the percentage.
         * @return boolean True, if the percentage of which the task in
         *         different process instances occurs in the log is greater
         *         or equal than percTrace, false otherwise.
         */
        private boolean checkPI(LogEventCheckBoxEnh c, Object percPIobj) {
            boolean returnBoolean = false;
            double percPI = 0.0;

            percPI = getDoubleValueFromSpinner(percPIobj);
            // check whether its percentage is higher than percPI
            if (c.getPercentagePI() >= percPI) {
                returnBoolean = true;
            } else {
                returnBoolean = false;
            }

            return returnBoolean;
        }

        /**
         * Get the percentage of that this task occurs in different PIs
         * 
         * @param evt
         *            LogEvent the logEvent in which the task can be found
         * @return double the percentage of which this task in the log
         *         occurs
         */
        private double getPercentagePI(LogEvent evt) {
            double returnPercent = 0.0;
            HashMap mapping = ((ExtendedLogSummary) summary).getMappingAtesToNumberPIs();
            int numberPI = summary.getNumberOfProcessInstances();

            // Get the frequency of PI in which the task occurs
            Object value = null;
            Iterator it = mapping.keySet().iterator();
            while (it.hasNext()) {
                Object keyObj = it.next();
                String key = (String) keyObj;
                if (key.equals(
                        evt.getModelElementName().trim() + " " + "(" + evt.getEventType().trim() + ")")) {
                    value = mapping.get(keyObj);
                    break;
                }
            }

            if (value != null) {
                // calculate frequency
                returnPercent = (((Integer) value).doubleValue() / new Double(numberPI).doubleValue()) * 100;
            }

            return returnPercent;
        }

        private int getFrequencyTasks(LogEvent evt, Set instances) {
            int returnFrequency = 0;
            Iterator instIterator = instances.iterator();
            while (instIterator.hasNext()) {
                ProcessInstance pi = (ProcessInstance) instIterator.next();
                Iterator ates = pi.getAuditTrailEntryList().iterator();
                while (ates.hasNext()) {
                    AuditTrailEntry ate = (AuditTrailEntry) ates.next();
                    if (ate.getElement().trim().equals(evt.getModelElementName().trim())
                            && ate.getType().equals(evt.getEventType())) {
                        returnFrequency += MethodsForWorkflowLogDataStructures
                                .getNumberSimilarProcessInstances(pi);
                    }
                }
            }
            return returnFrequency;
        }

        /**
         * Gets the double value of an object, provided that value is a
         * Double or Long object
         * 
         * @param value
         *            Object
         * @return double the double value
         */
        private double getDoubleValueFromSpinner(Object value) {
            double returnDouble = 0.0;

            if (value instanceof Long) {
                returnDouble = (((Long) value).doubleValue());
            } else if (value instanceof Double) {
                returnDouble = (((Double) value).doubleValue());
            }

            return returnDouble;
        }

        /**
         * Returns the number of process instances, taking into account the
         * number of similar instances
         * 
         * @param summary
         *            LogSummary the log summary
         * @return int the number of process instances
         */
        private int calculateSumPIs(LogSummary summary) {
            int returnSum = 0;
            HashSet pis = new HashSet<ProcessInstance>();
            Iterator it = summary.getLogEvents().iterator();
            while (it.hasNext()) {
                LogEvent evt = (LogEvent) it.next();
                pis.addAll(summary.getInstancesForEvent(evt));
            }
            // for each process instance in pis, get the number of similar
            // instances
            Iterator it2 = pis.iterator();
            while (it2.hasNext()) {
                ProcessInstance pi = (ProcessInstance) it2.next();
                returnSum += MethodsForWorkflowLogDataStructures.getNumberSimilarProcessInstances(pi);
            }
            return returnSum;
        }

        protected boolean getAllParametersSet() {
            // calculate values
            // buttonClicked();
            return true;
        }

    };
}

From source file:org.prom5.framework.log.filter.LogEventLogFilterEnh.java

/**
 * Returns a Panel for the setting of parameters. When a LogFilter can be
 * added to a list in the framework. This panel is shown, and parameters can
 * be set. When the dialog is closed, a new instance of a LogFilter is
 * created by the framework by calling the <code>getNewLogFilter</code> method
 * of the dialog.//ww w .  j av a 2s  .  co m
 *
 * @param summary A LogSummary to be used for setting parameters.
 * @return JPanel
 */
public LogFilterParameterDialog getParameterDialog(LogSummary summary) {
    return new LogFilterParameterDialog(summary, LogEventLogFilterEnh.this) {

        LogEventCheckBoxEnh[] checks;
        JSpinner percTaskSpinner;
        JSpinner percPiSpinner;
        JComboBox choiceBox;

        /**
         * Keep the statistics for all the tasks
         */
        SummaryStatistics taskStatistics = null;

        /**
         * Keep the statistics for the occurrence of tasks in process instances
         */
        SummaryStatistics piStatistics = null;

        public LogFilter getNewLogFilter() {
            LogEvents e = new LogEvents();
            for (int i = 0; i < checks.length; i++) {
                if (checks[i].isSelected()) {
                    e.add(checks[i].getLogEvent());
                }
            }
            return new LogEventLogFilterEnh(e, getDoubleValueFromSpinner(percTaskSpinner.getValue()),
                    getDoubleValueFromSpinner(percPiSpinner.getValue()),
                    choiceBox.getSelectedItem().toString());
        }

        protected JPanel getPanel() {
            // add message to the test log for this plugin
            Message.add("<EnhEvtLogFilter>", Message.TEST);
            // statistics
            taskStatistics = SummaryStatistics.newInstance();
            piStatistics = SummaryStatistics.newInstance();
            // Set up an percentformatter
            NumberFormat percentFormatter = NumberFormat.getPercentInstance();
            percentFormatter.setMinimumFractionDigits(2);
            percentFormatter.setMaximumFractionDigits(2);
            // Instantiate the spinners
            percTaskSpinner = new JSpinner(new SpinnerNumberModel(5.0, 0.0, 100.0, 1.0));
            percPiSpinner = new JSpinner(new SpinnerNumberModel(5.0, 0.0, 100.0, 1.0));
            // generate the buttons that are needed
            JButton jButtonCalculate = new JButton("Calculate");
            JButton jButtonInvert = new JButton("Invert selection");
            // set up a choicebox to indicate whether the relationship between the two
            // percentages is AND or OR.

            percTaskSpinner.setValue(new Double(percentageTask));
            percPiSpinner.setValue(new Double(percentagePI));

            choiceBox = new JComboBox();
            choiceBox.addItem("AND");
            choiceBox.addItem("OR");
            choiceBox.setSelectedItem(selectedItemComboBox);

            // Some values that are needed for the sequel.
            int size = summary.getLogEvents().size();
            // For the new log reader sumATEs should be calculated in another way
            int sumATEs = 0;
            if (summary instanceof ExtendedLogSummary) {
                sumATEs = summary.getNumberOfAuditTrailEntries();
            } else if (summary instanceof LightweightLogSummary) {
                HashSet<ProcessInstance> pis = new HashSet<ProcessInstance>();
                Iterator logEvents = summary.getLogEvents().iterator();
                while (logEvents.hasNext()) {
                    LogEvent evt = (LogEvent) logEvents.next();
                    pis.addAll(summary.getInstancesForEvent(evt));
                }
                Iterator pis2 = pis.iterator();
                while (pis2.hasNext()) {
                    ProcessInstance pi = (ProcessInstance) pis2.next();
                    int simPis = MethodsForWorkflowLogDataStructures.getNumberSimilarProcessInstances(pi);
                    int numberATEs = pi.getAuditTrailEntryList().size();
                    sumATEs += simPis * numberATEs;
                    pi.isEmpty();
                }
            } else {

            }
            // calculate the number of process Instances, taking into account
            // the number of similar instances
            int sumPIs = 0;
            if (summary instanceof LightweightLogSummary) {
                sumPIs = calculateSumPIs(summary);
            }
            checks = new LogEventCheckBoxEnh[size];

            // create panels and labels
            JPanel global = new JPanel(new BorderLayout());
            JPanel sub2 = new JPanel(new BorderLayout());
            sub2.setBackground(Color.white);
            JLabel labelPercTask = new JLabel("percentage task");
            JLabel labelPercPI = new JLabel("percentage PI");

            // create panel sub1 to put the checkboxes on
            JPanel sub1 = new JPanel(new SpringLayout());
            sub1.setBackground(Color.lightGray);

            // Get percentage of task in the log and percentage of in how many
            // different PIs it appears.
            Iterator it = summary.getLogEvents().iterator();
            int i = 0;
            while (it.hasNext()) {
                LogEvent evt = (LogEvent) it.next();
                double percent = 0.0;
                if (summary instanceof ExtendedLogSummary) {
                    percent = ((double) evt.getOccurrenceCount() / (double) sumATEs);
                } else if (summary instanceof LightweightLogSummary) {
                    Set instances = summary.getInstancesForEvent(evt);
                    // getFrequencyTasks(evt, instances)
                    percent = (double) getFrequencyTasks(evt, instances) / (double) sumATEs;
                } else {

                }
                //String percString = percentFormatter.format(percent);
                LogEventCheckBoxEnh check = new LogEventCheckBoxEnh(evt);
                check.setPercentageTask(percent * 100);
                // add percentage to the statistics for the tasks
                taskStatistics.addValue(percent);
                // Get percentage of in how many different PIs a task appears,
                // taking into account whether the new or old logreader is used
                if (summary instanceof LightweightLogSummary) {
                    Set<ProcessInstance> pis = summary.getInstancesForEvent(evt);
                    int numberInstancesTask = 0;
                    Iterator it2 = pis.iterator();
                    while (it2.hasNext()) {
                        ProcessInstance pi = (ProcessInstance) it2.next();
                        numberInstancesTask += MethodsForWorkflowLogDataStructures
                                .getNumberSimilarProcessInstances(pi);
                    }
                    double fPI = (double) numberInstancesTask / (double) sumPIs;

                    check.setPercentagePI(fPI * 100);
                    // add percentage to the statistics for the PIs
                    piStatistics.addValue(fPI);
                } else if (summary instanceof ExtendedLogSummary) {
                    double percPIcheck = getPercentagePI(evt);
                    check.setPercentagePI(percPIcheck);
                    piStatistics.addValue(percPIcheck / 100);
                } else {
                    // raise exception, unknown logreader
                }
                // add to the checks array
                checks[i++] = check;
            }
            // fill sub1 with statistics information
            sub1.add(new JLabel(" Statistics    ( #tasks = " + taskStatistics.getN() + " )"));
            sub1.add(new JLabel(" "));
            sub1.add(new JLabel(" "));
            sub1.add(new JLabel(" Arithmetic Mean "));
            sub1.add(new JLabel(percentFormatter.format(taskStatistics.getMean())));
            sub1.add(new JLabel(percentFormatter.format(piStatistics.getMean())));
            sub1.add(new JLabel(" Geometric Mean "));
            sub1.add(new JLabel(percentFormatter.format(taskStatistics.getGeometricMean())));
            sub1.add(new JLabel(percentFormatter.format(piStatistics.getGeometricMean())));
            sub1.add(new JLabel(" Standard Deviation "));
            sub1.add(new JLabel(percentFormatter.format(taskStatistics.getStandardDeviation())));
            sub1.add(new JLabel(percentFormatter.format(piStatistics.getStandardDeviation())));
            sub1.add(new JLabel(" Min "));
            sub1.add(new JLabel(percentFormatter.format(taskStatistics.getMin())));
            sub1.add(new JLabel(percentFormatter.format(piStatistics.getMin())));
            sub1.add(new JLabel(" Max "));
            sub1.add(new JLabel(percentFormatter.format(taskStatistics.getMax())));
            sub1.add(new JLabel(percentFormatter.format(piStatistics.getMax())));
            sub1.add(new JLabel(" ------------------ "));
            sub1.add(new JLabel(" --------------- "));
            sub1.add(new JLabel(" --------------- "));
            sub1.add(new JLabel(" Tasks "));
            sub1.add(new JLabel(" percentage task "));
            sub1.add(new JLabel(" percentage PI "));
            // generate messages for the test case for this plugin
            Message.add("number tasks: " + taskStatistics.getN(), Message.TEST);
            Message.add("<percentage task>", Message.TEST);
            Message.add("arithmetic mean: " + taskStatistics.getMean(), Message.TEST);
            Message.add("geometric mean: " + taskStatistics.getGeometricMean(), Message.TEST);
            Message.add("standard deviation: " + taskStatistics.getStandardDeviation(), Message.TEST);
            Message.add("min: " + taskStatistics.getMin(), Message.TEST);
            Message.add("max: " + taskStatistics.getMax(), Message.TEST);
            Message.add("<percentage task/>", Message.TEST);
            Message.add("<percentage PI>", Message.TEST);
            Message.add("arithmetic mean: " + piStatistics.getMean(), Message.TEST);
            Message.add("geometric mean: " + piStatistics.getGeometricMean(), Message.TEST);
            Message.add("standard deviation: " + piStatistics.getStandardDeviation(), Message.TEST);
            Message.add("min: " + piStatistics.getMin(), Message.TEST);
            Message.add("max: " + piStatistics.getMax(), Message.TEST);
            Message.add("<percentage PI/>", Message.TEST);
            // add the checkboxes to the GUI.
            Arrays.sort(checks);
            for (i = 0; i < checks.length; i++) {
                sub1.add(checks[i]);
                if ((eventsToKeep != null) && (!eventsToKeep.contains(checks[i].getLogEvent()))) {
                    checks[i].setSelected(false);
                }
                // put the percentages on the GUI
                sub1.add(new JLabel(percentFormatter.format(checks[i].getPercentageTask() / 100)));
                sub1.add(new JLabel(percentFormatter.format(checks[i].getPercentagePI() / 100)));
            }
            //
            SpringUtilities util = new SpringUtilities();
            util.makeCompactGrid(sub1, checks.length + 8, 3, 3, 3, 8, 3);
            // put the contents on the respective panels
            global.add(sub2, java.awt.BorderLayout.CENTER);
            global.add(sub1, java.awt.BorderLayout.SOUTH);
            //
            JPanel sub21 = new JPanel(new SpringLayout());
            //sub21.setLayout(new BoxLayout(sub21, BoxLayout.PAGE_AXIS));
            sub2.setBackground(Color.red);
            JPanel textPanel = new JPanel(new BorderLayout());
            textPanel.setBackground(Color.yellow);
            JPanel sub221 = new JPanel(new FlowLayout());
            sub221.setBackground(Color.yellow);
            JPanel sub222 = new JPanel(new FlowLayout());
            sub222.setBackground(Color.yellow);
            // two different panels to be places on sub21
            //JPanel sub21First = new JPanel();
            //sub21First.setLayout(new BoxLayout(sub21First, BoxLayout.LINE_AXIS));
            //sub21First.setMaximumSize(new Dimension(1000, 25));
            //sub21First.add(Box.createHorizontalGlue());
            //sub21First.add(labelPercTask);
            //sub21First.add(percTaskSpinner, null);
            //percTaskSpinner.setMaximumSize(new Dimension(10, 20));
            //sub21First.add(jButtonCalculate);
            //jButtonCalculate.setMaximumSize(new Dimension(10, 20));
            //sub21First.add(labelPercPI);
            //sub21First.add(percPiSpinner, null);
            //percPiSpinner.setMaximumSize(new Dimension(10, 20));
            //sub21First.add(choiceBox);
            //choiceBox.setMaximumSize(new Dimension(10, 20));
            //sub21First.add(Box.createHorizontalGlue());
            //JPanel sub21Second = new JPanel();
            //sub21Second.setLayout(new BoxLayout(sub21Second, BoxLayout.LINE_AXIS));
            //sub21Second.setMaximumSize(new Dimension(1000, 25));
            //sub21Second.add(Box.createHorizontalGlue());
            //sub21Second.add(jButtonInvert);
            //sub21Second.add(Box.createHorizontalGlue());
            //
            //sub21.add(sub21First);
            //sub21.add(sub21Second);

            sub21.add(labelPercTask);
            sub21.add(percTaskSpinner, null);
            sub21.add(jButtonCalculate);
            sub21.add(labelPercPI);
            sub21.add(percPiSpinner, null);
            sub21.add(choiceBox);
            // add the invert button
            sub21.add(new JLabel(" "));
            sub21.add(new JLabel(" "));
            sub21.add(jButtonInvert);
            sub21.add(new JLabel(" "));
            sub21.add(new JLabel(" "));
            sub21.add(new JLabel(" "));
            sub21.setMaximumSize(sub21.getPreferredSize());
            sub2.add(sub21, java.awt.BorderLayout.CENTER);
            sub2.add(textPanel, java.awt.BorderLayout.SOUTH);
            textPanel.add(new JLabel(
                    "The Calculate button needs to be clicked to calculate which tasks need to be selected!!!"),
                    java.awt.BorderLayout.CENTER);
            textPanel.add(
                    new JLabel("Clicking the OK button only accepts, but nothing is again calculated!!!!"),
                    java.awt.BorderLayout.SOUTH);
            util.makeCompactGrid(sub21, 2, 6, 3, 3, 8, 3);
            //

            // specify button action for the button ButtonPreview
            jButtonCalculate.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    // The preview button is clicked
                    buttonClicked();
                    // end for
                }
            });

            // specify button action for the button Invert
            jButtonInvert.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    invertButtonClicked();
                }
            });

            return global;

        }

        /**
         * When the preview button is clicked
         */
        public void buttonClicked() {
            for (int k = 0; k < checks.length; k++) {
                boolean firstCheck = false;
                boolean secondCheck = false;
                LogEventCheckBoxEnh c = checks[k];
                // check for the task in c whether its percentage is higher than
                // perc
                firstCheck = checkTask(c, percTaskSpinner.getValue());

                // Also check whether the task occurs in more than percTr
                // percent of the traces
                secondCheck = checkPI(c, percPiSpinner.getValue());

                // Check whether for choiceBox OR or AND is selected
                boolean logicalResult = true;
                if (((String) choiceBox.getSelectedItem()).equals("AND")) {
                    logicalResult = firstCheck && secondCheck;
                } else if (((String) choiceBox.getSelectedItem()).equals("OR")) {
                    logicalResult = firstCheck || secondCheck;
                }
                // set the checkbox selected or not
                if (logicalResult == true) {
                    c.setSelected(true);
                } else {
                    c.setSelected(false);
                }
            }
            // add messages to the test log for this case
            int numberCheckedBoxes = 0;
            for (int i = 0; i < checks.length; i++) {
                if (checks[i].isSelected()) {
                    numberCheckedBoxes++;
                }
            }
            Message.add("number of selected tasks: " + numberCheckedBoxes, Message.TEST);
            Message.add("<EnhEvtLogFilter/>", Message.TEST);
        }

        /**
         *
         */
        public void invertButtonClicked() {
            for (int i = 0; i < checks.length; i++) {
                checks[i].setSelected(!checks[i].isSelected());
            }
        }

        /**
         * Checks whether the task in c occurs with a lower percentage in the log
         * than the percentage given by percTask.
         * @param c LogEventCheckBoxEnh the checkbox that contains the task.
         * @param percTask Object the percentage
         * @return boolean True if the percentage of which the task in c occurs
         * in the log is greater or equal than percTaks, false otherwise.
         */
        private boolean checkTask(LogEventCheckBoxEnh c, Object percTask) {
            boolean returnBoolean = false;
            double percT = 0.0;
            percT = getDoubleValueFromSpinner(percTask);
            // check whether its percentage is higher than percT
            if (c.getPercentageTask() >= percT) {
                returnBoolean = true;
            } else {
                returnBoolean = false;
            }

            return returnBoolean;
        }

        /**
         * Checks whether the task in c occurs with a lower percentage in different
         * process instances than the percentage given by percTrace.
         * @param c LogEventCheckBoxEnh the checkbox that contains the task.
         * @param percTrace Object the percentage.
         * @return boolean True, if the percentage of which the task in different
         * process instances occurs in the log is greater or equal than percTrace,
         * false otherwise.
         */
        private boolean checkPI(LogEventCheckBoxEnh c, Object percPIobj) {
            boolean returnBoolean = false;
            double percPI = 0.0;

            percPI = getDoubleValueFromSpinner(percPIobj);
            // check whether its percentage is higher than percPI
            if (c.getPercentagePI() >= percPI) {
                returnBoolean = true;
            } else {
                returnBoolean = false;
            }

            return returnBoolean;
        }

        /**
         * Get the percentage of that this task occurs in different PIs
         * @param evt LogEvent the logEvent in which the task can be found
         * @return double the percentage of which this task in the log occurs
         */
        private double getPercentagePI(LogEvent evt) {
            double returnPercent = 0.0;
            HashMap mapping = ((ExtendedLogSummary) summary).getMappingAtesToNumberPIs();
            int numberPI = summary.getNumberOfProcessInstances();

            // Get the frequency of PI in which the task occurs
            Object value = null;
            Iterator it = mapping.keySet().iterator();
            while (it.hasNext()) {
                Object keyObj = it.next();
                String key = (String) keyObj;
                if (key.equals(
                        evt.getModelElementName().trim() + " " + "(" + evt.getEventType().trim() + ")")) {
                    value = mapping.get(keyObj);
                    break;
                }
            }

            if (value != null) {
                // calculate frequency
                returnPercent = (((Integer) value).doubleValue() / new Double(numberPI).doubleValue()) * 100;
            }

            return returnPercent;
        }

        private int getFrequencyTasks(LogEvent evt, Set instances) {
            int returnFrequency = 0;
            Iterator instIterator = instances.iterator();
            while (instIterator.hasNext()) {
                ProcessInstance pi = (ProcessInstance) instIterator.next();
                Iterator ates = pi.getAuditTrailEntryList().iterator();
                while (ates.hasNext()) {
                    AuditTrailEntry ate = (AuditTrailEntry) ates.next();
                    if (ate.getElement().trim().equals(evt.getModelElementName().trim())
                            && ate.getType().equals(evt.getEventType())) {
                        returnFrequency += MethodsForWorkflowLogDataStructures
                                .getNumberSimilarProcessInstances(pi);
                    }
                }
            }
            return returnFrequency;
        }

        /**
         * Gets the double value of an object, provided that value is a
         * Double or Long object
         * @param value Object
         * @return double the double value
         */
        private double getDoubleValueFromSpinner(Object value) {
            double returnDouble = 0.0;

            if (value instanceof Long) {
                returnDouble = (((Long) value).doubleValue());
            } else if (value instanceof Double) {
                returnDouble = (((Double) value).doubleValue());
            }

            return returnDouble;
        }

        /**
         * Returns the number of process instances, taking into account the
         * number of similar instances
         * @param summary LogSummary the log summary
         * @return int the number of process instances
         */
        private int calculateSumPIs(LogSummary summary) {
            int returnSum = 0;
            HashSet pis = new HashSet<ProcessInstance>();
            Iterator it = summary.getLogEvents().iterator();
            while (it.hasNext()) {
                LogEvent evt = (LogEvent) it.next();
                pis.addAll(summary.getInstancesForEvent(evt));
            }
            // for each process instance in pis, get the number of similar instances
            Iterator it2 = pis.iterator();
            while (it2.hasNext()) {
                ProcessInstance pi = (ProcessInstance) it2.next();
                returnSum += MethodsForWorkflowLogDataStructures.getNumberSimilarProcessInstances(pi);
            }
            return returnSum;
        }

        protected boolean getAllParametersSet() {
            // calculate values
            //buttonClicked();
            return true;
        }

    };
}

From source file:org.rdv.ui.ControlPanel.java

/**
 * Setup the UI.//from   w  ww  . j  a va2s  .co m
 */
private void initPanel() {
    setLayout(new BorderLayout());

    GridBagConstraints c = new GridBagConstraints();

    JPanel container = new JPanel();
    container.setLayout(new GridBagLayout());

    Box firstRowPanel = new Box(BoxLayout.LINE_AXIS);

    beginButton = new JButton();
    beginButton.setName("beginButton");
    beginButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setLocationBegin();
        }
    });
    firstRowPanel.add(beginButton);

    rtButton = new JButton();
    rtButton.setName("rtButton");
    rtButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (rtButton.isSelected()) {
                rbnbController.pause();
            } else {
                rbnbController.monitor();
            }
        }
    });
    firstRowPanel.add(rtButton);

    playButton = new JButton();
    playButton.setName("playButton");
    playButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (playButton.isSelected()) {
                rbnbController.pause();
            } else {
                rbnbController.play();
            }
        }
    });
    firstRowPanel.add(playButton);

    endButton = new JButton();
    endButton.setName("endButton");
    endButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setLocationEnd();
        }
    });
    firstRowPanel.add(endButton);

    firstRowPanel.add(Box.createHorizontalStrut(8));

    SpinnerListModel playbackRateModel = new SpinnerListModel(playbackRates);
    playbackRateSpinner = new JSpinner(playbackRateModel);
    playbackRateSpinner.setName("playbackRateSpinner");
    JSpinner.ListEditor playbackRateEditor = new JSpinner.ListEditor(playbackRateSpinner);
    playbackRateEditor.getTextField().setEditable(false);
    playbackRateSpinner.setEditor(playbackRateEditor);
    playbackRateSpinner.setPreferredSize(new Dimension(80, playbackRateSpinner.getPreferredSize().height));
    playbackRateSpinner.setMinimumSize(playbackRateSpinner.getPreferredSize());
    playbackRateSpinner.setMaximumSize(playbackRateSpinner.getPreferredSize());
    playbackRateSpinner.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            playbackRateChanged();
        }
    });
    firstRowPanel.add(playbackRateSpinner);

    firstRowPanel.add(Box.createHorizontalStrut(8));

    timeScaleComboBox = new JComboBox();
    timeScaleComboBox.setName("timeScaleComboBox");
    timeScaleComboBox.setEditable(true);
    timeScaleComboBox.setPreferredSize(new Dimension(96, timeScaleComboBox.getPreferredSize().height));
    timeScaleComboBox.setMinimumSize(timeScaleComboBox.getPreferredSize());
    timeScaleComboBox.setMaximumSize(timeScaleComboBox.getPreferredSize());
    for (int i = 0; i < timeScales.length; i++) {
        timeScaleComboBox.addItem(DataViewer.formatSeconds(timeScales[i]));
    }
    timeScaleComboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            timeScaleChange();
        }
    });
    firstRowPanel.add(timeScaleComboBox);

    firstRowPanel.add(Box.createHorizontalGlue());

    locationButton = new JButton();
    locationButton.setName("locationButton");
    locationButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            TimeRange timeRange = RBNBHelper.getChannelsTimeRange();
            double time = DateTimeDialog.showDialog(ControlPanel.this, rbnbController.getLocation(),
                    timeRange.start, timeRange.end);
            if (time >= 0) {
                rbnbController.setLocation(time);
            }
        }
    });
    firstRowPanel.add(locationButton);

    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1;
    c.weighty = 0;
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.gridheight = 1;
    c.ipadx = 0;
    c.ipady = 0;
    c.insets = new java.awt.Insets(8, 8, 8, 8);
    c.anchor = GridBagConstraints.NORTHWEST;
    container.add(firstRowPanel, c);

    zoomTimeSlider = new TimeSlider();
    zoomTimeSlider.setRangeChangeable(false);
    zoomTimeSlider.addTimeAdjustmentListener(this);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1;
    c.weighty = 0;
    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.gridheight = 1;
    c.ipadx = 0;
    c.ipady = 0;
    c.insets = new java.awt.Insets(0, 8, 0, 8);
    c.anchor = GridBagConstraints.NORTHWEST;
    container.add(zoomTimeSlider, c);

    JPanel zoomTimePanel = new JPanel();
    zoomTimePanel.setLayout(new BorderLayout());

    zoomMinimumLabel = new JLabel();
    zoomMinimumLabel.setName("zoomMinimumLabel");
    zoomTimePanel.add(zoomMinimumLabel, BorderLayout.WEST);

    zoomRangeLabel = new JLabel();
    zoomRangeLabel.setName("zoomRangeLabel");
    zoomRangeLabel.setHorizontalAlignment(JLabel.CENTER);
    zoomTimePanel.add(zoomRangeLabel, BorderLayout.CENTER);

    zoomMaximumLabel = new JLabel();
    zoomMaximumLabel.setName("zoomMaximumLabel");
    zoomTimePanel.add(zoomMaximumLabel, BorderLayout.EAST);

    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1;
    c.weighty = 0;
    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.gridheight = 1;
    c.ipadx = 0;
    c.ipady = 0;
    c.insets = new java.awt.Insets(8, 8, 0, 8);
    c.anchor = GridBagConstraints.NORTHWEST;
    container.add(zoomTimePanel, c);

    globalTimeSlider = new TimeSlider();
    globalTimeSlider.setValueChangeable(false);
    globalTimeSlider.addTimeAdjustmentListener(this);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1;
    c.weighty = 1;
    c.gridx = 0;
    c.gridy = 3;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.gridheight = 1;
    c.ipadx = 0;
    c.ipady = 0;
    c.insets = new java.awt.Insets(8, 8, 8, 8);
    c.anchor = GridBagConstraints.NORTHWEST;
    container.add(globalTimeSlider, c);

    add(container, BorderLayout.CENTER);

    log.info("Initialized control panel.");
}

From source file:org.revager.gui.findings_list.FindingsListFrame.java

private void createBottomOrgPanel() {
    JLabel locationLbl = new JLabel(translate("Location:"));
    locationLbl.setFont(UI.VERY_LARGE_FONT_BOLD);

    JLabel dateLbl = new JLabel(translate("Date:"));
    dateLbl.setFont(UI.VERY_LARGE_FONT_BOLD);

    JLabel beginLbl = new JLabel(translate("Period of time:"));
    beginLbl.setFont(UI.VERY_LARGE_FONT_BOLD);

    JLabel tillLabel = new JLabel(translate("to"));
    tillLabel.setFont(UI.VERY_LARGE_FONT_BOLD);

    clockLabel.setFont(UI.VERY_LARGE_FONT_BOLD);

    dateTxtFld = new ObservingTextField();
    dateTxtFld.setFont(UI.VERY_LARGE_FONT);

    dateTxtFld.setFocusable(false);/* www. ja  va 2  s .  co  m*/
    dateTxtFld.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    dateTxtFld.setPreferredSize(new Dimension(190, (int) dateTxtFld.getPreferredSize().getHeight()));
    dateTxtFld.setMinimumSize(dateTxtFld.getPreferredSize());
    dateTxtFld.addMouseListener(new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent e) {
            // instantiate the DatePicker
            DatePicker dp = new DatePicker(UI.getInstance().getProtocolFrame(),
                    UI.getInstance().getProtocolFrame().getDateTxtFld());

            // previously selected date
            Date selectedDate = dp.parseDate(UI.getInstance().getProtocolFrame().getDateTxtFld().getText());
            dp.setSelectedDate(selectedDate);
            dp.start(UI.getInstance().getProtocolFrame().getDateTxtFld());
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }
    });

    dateTxtFld.addKeyListener(updateListener);

    /*
     * creating spinner panel
     */
    beginMSpinner = new JSpinner(new RotateSpinnerNumberModel(00, 00, 59, 1));
    beginHSpinner = new JSpinner(new RotateSpinnerNumberModel(00, 00, 23, 1));

    endMSpinner = new JSpinner(new RotateSpinnerNumberModel(00, 00, 59, 1));
    endHSpinner = new JSpinner(new RotateSpinnerNumberModel(00, 00, 23, 1));

    beginMSpinner.setFont(UI.VERY_LARGE_FONT);
    beginHSpinner.setFont(UI.VERY_LARGE_FONT);
    endHSpinner.setFont(UI.VERY_LARGE_FONT);
    endMSpinner.setFont(UI.VERY_LARGE_FONT);

    beginMSpinner.addChangeListener(spinnerChangeListener);
    beginHSpinner.addChangeListener(spinnerChangeListener);
    endHSpinner.addChangeListener(spinnerChangeListener);
    endMSpinner.addChangeListener(spinnerChangeListener);

    locationTxtFld = new JTextField();
    locationTxtFld.setFont(UI.VERY_LARGE_FONT);

    /*
     * Hide border if the application runs on Mac OS X
     */
    boolean hideBorder = UI.getInstance().getPlatform() == UI.Platform.MAC;

    GUITools.formatSpinner(endHSpinner, hideBorder);
    GUITools.formatSpinner(endMSpinner, hideBorder);
    GUITools.formatSpinner(beginHSpinner, hideBorder);
    GUITools.formatSpinner(beginMSpinner, hideBorder);

    // TODO: In some cases 'currentProt.getDate()' returns null.
    dateF.setTimeZone(currentProt.getDate().getTimeZone());
    dateTxtFld.setText(dateF.format(currentProt.getDate().getTime()));

    int beginHours = currentProt.getStart().get(Calendar.HOUR_OF_DAY);
    beginMSpinner.setValue(currentProt.getStart().get(Calendar.MINUTE));
    beginHSpinner.setValue(beginHours);

    int endHours = currentProt.getEnd().get(Calendar.HOUR_OF_DAY);
    endMSpinner.setValue(currentProt.getEnd().get(Calendar.MINUTE));
    endHSpinner.setValue(endHours);

    /*
     * Correct the leading zero's
     */
    if ((Integer) beginMSpinner.getValue() == 0) {
        ((NumberEditor) beginMSpinner.getEditor()).getTextField().setText("00");
    }

    if ((Integer) beginHSpinner.getValue() == 0) {
        ((NumberEditor) beginHSpinner.getEditor()).getTextField().setText("00");
    }

    if ((Integer) endMSpinner.getValue() == 0) {
        ((NumberEditor) endMSpinner.getEditor()).getTextField().setText("00");
    }

    if ((Integer) endHSpinner.getValue() == 0) {
        ((NumberEditor) endHSpinner.getEditor()).getTextField().setText("00");
    }

    locationTxtFld.setText(currentProt.getLocation().trim());

    JPanel spinnerPanel = new JPanel(gbl);
    spinnerPanel.setOpaque(false);

    JLabel labelDoubleDot1 = new JLabel(":");
    labelDoubleDot1.setFont(UI.VERY_LARGE_FONT_BOLD);

    JLabel labelDoubleDot2 = new JLabel(":");
    labelDoubleDot2.setFont(UI.VERY_LARGE_FONT_BOLD);

    GUITools.addComponent(spinnerPanel, gbl, beginHSpinner, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0,
            GridBagConstraints.VERTICAL, GridBagConstraints.NORTHWEST);
    GUITools.addComponent(spinnerPanel, gbl, labelDoubleDot1, 1, 0, 1, 1, 0, 0, 0, 5, 0, 0,
            GridBagConstraints.VERTICAL, GridBagConstraints.CENTER);
    GUITools.addComponent(spinnerPanel, gbl, beginMSpinner, 2, 0, 1, 1, 0, 0, 0, 5, 0, 0,
            GridBagConstraints.VERTICAL, GridBagConstraints.NORTHWEST);
    GUITools.addComponent(spinnerPanel, gbl, tillLabel, 3, 0, 1, 1, 1.0, 0, 0, 10, 0, 10,
            GridBagConstraints.VERTICAL, GridBagConstraints.CENTER);
    GUITools.addComponent(spinnerPanel, gbl, endHSpinner, 4, 0, 1, 1, 0, 0, 0, 0, 0, 0,
            GridBagConstraints.VERTICAL, GridBagConstraints.NORTHEAST);
    GUITools.addComponent(spinnerPanel, gbl, labelDoubleDot2, 5, 0, 1, 1, 0, 0, 0, 5, 0, 0,
            GridBagConstraints.VERTICAL, GridBagConstraints.CENTER);
    GUITools.addComponent(spinnerPanel, gbl, endMSpinner, 6, 0, 1, 1, 0, 0, 0, 5, 0, 0,
            GridBagConstraints.VERTICAL, GridBagConstraints.NORTHEAST);

    /*
     * adding created components to orgpanel
     */
    GUITools.addComponent(bottomOrgPanel, gbl, dateLbl, 2, 0, 1, 1, 0.0, 1.0, 10, 20, 0, 0,
            GridBagConstraints.NONE, GridBagConstraints.WEST);
    GUITools.addComponent(bottomOrgPanel, gbl, dateTxtFld, 3, 0, 1, 1, 0.0, 1.0, 10, 5, 0, 0,
            GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST);

    GUITools.addComponent(bottomOrgPanel, gbl, locationLbl, 0, 0, 1, 1, 0.0, 1.0, 10, 20, 0, 0,
            GridBagConstraints.NONE, GridBagConstraints.WEST);
    GUITools.addComponent(bottomOrgPanel, gbl, locationTxtFld, 1, 0, 1, 1, 1.0, 1.0, 10, 5, 0, 10,
            GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST);

    GUITools.addComponent(bottomOrgPanel, gbl, beginLbl, 5, 0, 1, 1, 0.0, 1.0, 10, 30, 0, 0,
            GridBagConstraints.NONE, GridBagConstraints.EAST);
    GUITools.addComponent(bottomOrgPanel, gbl, spinnerPanel, 6, 0, 1, 1, 0.0, 1.0, 10, 5, 0, 25,
            GridBagConstraints.VERTICAL, GridBagConstraints.WEST);

    updateAttButtons();
}

From source file:org.squidy.designer.zoom.impl.VisualizationShape.java

/**
 * // www.j av a 2 s  . c  o  m
 */
private final void initTimeSpinner() {
    PBounds bounds = getBoundsReference();

    final JSpinner spinner = new JSpinner(new SpinnerNumberModel(sampleTime, 1000, 10000, 500));
    spinner.addChangeListener(new ChangeListener() {

        /*
         * (non-Javadoc)
         * 
         * @see
         * javax.swing.event.ChangeListener#stateChanged(javax.swing.event
         * .ChangeEvent)
         */
        public void stateChanged(ChangeEvent e) {
            sampleTime = ((Double) spinner.getValue()).longValue();
            invalidatePaint();
        }
    });

    timeSpinner = new JComponentWrapper(spinner);
    timeSpinner.setOffset((bounds.getWidth() * 0.25) - (timeSpinner.getWidth() / 2),
            bounds.getHeight() * 0.75 + 0.25);
    addChild(timeSpinner);
}

From source file:pl.otros.logview.exceptionshandler.ShowErrorDialogExceptionHandler.java

protected JComponent createDialogView() {
    JPanel jPanel = new JPanel(new MigLayout());
    JLabel label = new JLabel("Do you want to send error report?");
    label.setFont(label.getFont().deriveFont(Font.BOLD));
    jPanel.add(label, "span 4, wrap, center");
    jPanel.add(new JLabel("Comment:"));
    commentTextArea = new JTextArea(10, 30);
    commentTextArea.setWrapStyleWord(true);
    commentTextArea.setLineWrap(true);//from  ww  w  .j  a va 2 s  .c  o m
    JScrollPane jScrollPane = new JScrollPane(commentTextArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    jPanel.add(jScrollPane, "span 3, wrap");
    jPanel.add(new JLabel("Email (optional):"));
    emailTextField = new JTextField(30);
    jPanel.add(emailTextField, "span 3, wrap");

    jPanel.add(new JSeparator(), "span 4, wrap, grow");
    checkBoxUseProxy = new JCheckBox("Use HTTP proxy");
    proxyTf = new JTextField();
    proxyPortModel = new SpinnerNumberModel(80, 1, 256 * 256 - 1, 1);
    proxyUser = new JTextField();
    proxyPasswordField = new JPasswordField();
    proxySpinner = new JSpinner(proxyPortModel);

    jPanel.add(checkBoxUseProxy, "wrap");
    labelProxyHost = new JLabel("Proxy address");
    jPanel.add(labelProxyHost);
    jPanel.add(proxyTf, "wrap, span 3, grow");
    labelProxyPort = new JLabel("Proxy port");
    jPanel.add(labelProxyPort);
    jPanel.add(proxySpinner, "wrap");
    labelProxyUser = new JLabel("User");
    jPanel.add(labelProxyUser);
    jPanel.add(proxyUser, "grow");
    labelProxyPassword = new JLabel("Password");
    jPanel.add(labelProxyPassword);
    jPanel.add(proxyPasswordField, "grow");

    checkBoxUseProxy.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            setProxyEnabled(checkBoxUseProxy.isSelected());
        }
    });
    DataConfiguration c = otrosApplication.getConfiguration();
    proxyTf.setText(c.getString(ConfKeys.HTTP_PROXY_HOST, ""));
    proxyUser.setText(c.getString(ConfKeys.HTTP_PROXY_USER, ""));
    proxyPortModel.setValue(Integer.valueOf(c.getInt(ConfKeys.HTTP_PROXY_PORT, 80)));
    boolean useProxy = c.getBoolean(ConfKeys.HTTP_PROXY_USE, false);
    checkBoxUseProxy.setSelected(useProxy);
    setProxyEnabled(useProxy);

    return jPanel;
}