Example usage for javax.swing JCheckBox setEnabled

List of usage examples for javax.swing JCheckBox setEnabled

Introduction

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

Prototype

public void setEnabled(boolean b) 

Source Link

Document

Enables (or disables) the button.

Usage

From source file:AppearanceExplorer.java

RenderingAttributesEditor(RenderingAttributes init) {
    renderingAttr = init;//from  w  w  w  .j  a va  2 s .c  om
    visible = renderingAttr.getVisible();
    depthBufferEnable = renderingAttr.getDepthBufferEnable();
    depthBufferWriteEnable = renderingAttr.getDepthBufferWriteEnable();
    ignoreVertexColors = renderingAttr.getIgnoreVertexColors();
    rasterOpEnable = renderingAttr.getRasterOpEnable();
    rasterOp = renderingAttr.getRasterOp();
    alphaTestFunction = renderingAttr.getAlphaTestFunction();
    alphaTestValue = renderingAttr.getAlphaTestValue();

    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    JCheckBox visibleCheckBox = new JCheckBox("Visible", visible);
    visibleCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JCheckBox checkbox = (JCheckBox) e.getSource();
            visible = checkbox.isSelected();
            renderingAttr.setVisible(visible);
        }
    });
    // add the checkbox to the panel
    add(new LeftAlignComponent(visibleCheckBox));

    JCheckBox ignoreVertexColorsCheckBox = new JCheckBox("Ignore Vertex Colors", ignoreVertexColors);
    ignoreVertexColorsCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JCheckBox checkbox = (JCheckBox) e.getSource();
            ignoreVertexColors = checkbox.isSelected();
            renderingAttr.setIgnoreVertexColors(ignoreVertexColors);
        }
    });
    // add the checkbox to the panel
    add(new LeftAlignComponent(ignoreVertexColorsCheckBox));

    JCheckBox depthBufferEnableCheckBox = new JCheckBox("Depth Buffer Enable", depthBufferEnable);
    depthBufferEnableCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JCheckBox checkbox = (JCheckBox) e.getSource();
            depthBufferEnable = checkbox.isSelected();
            renderingAttr.setDepthBufferEnable(depthBufferEnable);
        }
    });
    // add the checkbox to the panel
    add(new LeftAlignComponent(depthBufferEnableCheckBox));
    // no cap bit for depth buffer enable
    depthBufferEnableCheckBox.setEnabled(false);

    JCheckBox depthBufferWriteEnableCheckBox = new JCheckBox("Depth Buffer Write Enable",
            depthBufferWriteEnable);
    depthBufferWriteEnableCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JCheckBox checkbox = (JCheckBox) e.getSource();
            depthBufferWriteEnable = checkbox.isSelected();
            renderingAttr.setDepthBufferWriteEnable(depthBufferWriteEnable);
        }
    });
    // add the checkbox to the panel
    add(new LeftAlignComponent(depthBufferWriteEnableCheckBox));
    // no cap bit for depth buffer enable
    depthBufferWriteEnableCheckBox.setEnabled(false);

    JCheckBox rasterOpEnableCheckBox = new JCheckBox("Raster Operation Enable", rasterOpEnable);
    rasterOpEnableCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JCheckBox checkbox = (JCheckBox) e.getSource();
            rasterOpEnable = checkbox.isSelected();
            renderingAttr.setRasterOpEnable(rasterOpEnable);
        }
    });
    // add the checkbox to the panel
    add(new LeftAlignComponent(rasterOpEnableCheckBox));

    String[] rasterOpNames = { "ROP_COPY", "ROP_XOR", };
    int[] rasterOpValues = { RenderingAttributes.ROP_COPY, RenderingAttributes.ROP_XOR, };
    IntChooser rasterOpChooser = new IntChooser("Raster Operation:", rasterOpNames, rasterOpValues, rasterOp);
    rasterOpChooser.addIntListener(new IntListener() {
        public void intChanged(IntEvent event) {
            rasterOp = event.getValue();
            renderingAttr.setRasterOp(rasterOp);
        }
    });
    add(rasterOpChooser);

    String[] alphaTestFunctionNames = { "ALWAYS", "NEVER", "EQUAL", "NOT_EQUAL", "LESS", "LESS_OR_EQUAL",
            "GREATER", "GREATER_OR_EQUAL", };
    int[] alphaTestFunctionValues = { RenderingAttributes.ALWAYS, RenderingAttributes.NEVER,
            RenderingAttributes.EQUAL, RenderingAttributes.NOT_EQUAL, RenderingAttributes.LESS,
            RenderingAttributes.LESS_OR_EQUAL, RenderingAttributes.GREATER,
            RenderingAttributes.GREATER_OR_EQUAL, };
    IntChooser alphaTestFunctionChooser = new IntChooser("Alpha Test Function:", alphaTestFunctionNames,
            alphaTestFunctionValues, alphaTestFunction);
    alphaTestFunctionChooser.addIntListener(new IntListener() {
        public void intChanged(IntEvent event) {
            alphaTestFunction = event.getValue();
            renderingAttr.setAlphaTestFunction(alphaTestFunction);
        }
    });
    add(alphaTestFunctionChooser);

    FloatLabelJSlider alphaTestValueSlider = new FloatLabelJSlider("Alpha Test Value: ", 0.1f, 0.0f, 1.0f,
            alphaTestValue);
    alphaTestValueSlider.setMajorTickSpacing(1.0f);
    alphaTestValueSlider.setPaintTicks(true);
    alphaTestValueSlider.addFloatListener(new FloatListener() {
        public void floatChanged(FloatEvent e) {
            alphaTestValue = e.getValue();
            renderingAttr.setAlphaTestValue(alphaTestValue);
        }
    });
    add(alphaTestValueSlider);

}

From source file:org.formic.wizard.step.gui.FeatureListStep.java

/**
 * {@inheritDoc}/*from   w  ww.  ja  v a2s . c  o  m*/
 * @see org.formic.wizard.step.GuiStep#init()
 */
public Component init() {
    featureInfo = new JEditorPane("text/html", StringUtils.EMPTY);
    featureInfo.setEditable(false);
    featureInfo.addHyperlinkListener(new HyperlinkListener());

    Feature[] features = provider.getFeatures();
    JTable table = new JTable(features.length, 1) {
        private static final long serialVersionUID = 1L;

        public Class getColumnClass(int column) {
            return getValueAt(0, column).getClass();
        }

        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    table.setBackground(new javax.swing.JList().getBackground());

    GuiForm form = createForm();

    for (int ii = 0; ii < features.length; ii++) {
        final Feature feature = (Feature) features[ii];
        final JCheckBox box = new JCheckBox();

        String name = getName() + '.' + feature.getKey();
        form.bind(name, box);

        box.putClientProperty("feature", feature);
        featureMap.put(feature.getKey(), box);

        if (feature.getInfo() == null) {
            feature.setInfo(Installer.getString(getName() + "." + feature.getKey() + ".html"));
        }
        feature.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent event) {
                if (Feature.ENABLED_PROPERTY.equals(event.getPropertyName())) {
                    if (box.isSelected() != feature.isEnabled()) {
                        box.setSelected(feature.isEnabled());
                    }
                }
            }
        });

        box.setText(Installer.getString(name));
        box.setBackground(table.getBackground());
        if (!feature.isAvailable()) {
            box.setSelected(false);
            box.setEnabled(false);
        }
        table.setValueAt(box, ii, 0);
    }

    FeatureListMouseListener mouseListener = new FeatureListMouseListener();
    for (int ii = 0; ii < features.length; ii++) {
        Feature feature = (Feature) features[ii];
        if (feature.isEnabled() && feature.isAvailable()) {
            JCheckBox box = (JCheckBox) featureMap.get(feature.getKey());
            box.setSelected(true);
            mouseListener.processDependencies(feature);
            mouseListener.processExclusives(feature);
        }
    }

    table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setShowHorizontalLines(false);
    table.setShowVerticalLines(false);
    table.setDefaultRenderer(JCheckBox.class, new ComponentTableCellRenderer());

    table.addKeyListener(new FeatureListKeyListener());
    table.addMouseListener(mouseListener);
    table.getSelectionModel().addListSelectionListener(new FeatureListSelectionListener(table));

    table.setRowSelectionInterval(0, 0);

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    JPanel container = new JPanel(new BorderLayout());
    container.add(table, BorderLayout.CENTER);
    panel.add(new JScrollPane(container), BorderLayout.CENTER);
    JScrollPane infoScroll = new JScrollPane(featureInfo);
    infoScroll.setMinimumSize(new Dimension(0, 50));
    infoScroll.setMaximumSize(new Dimension(0, 50));
    infoScroll.setPreferredSize(new Dimension(0, 50));
    panel.add(infoScroll, BorderLayout.SOUTH);

    return panel;
}

From source file:org.geworkbench.components.lincs.LincsInterface.java

public LincsInterface() {

    final String lincsCwbFileName = this.getClass().getPackage().getName().replace(".",
            FilePathnameUtils.FILE_SEPARATOR) + FilePathnameUtils.FILE_SEPARATOR + "Lincs.cwb.xml";
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));

    // temp do this, if data is there, then may be take out
    hideColumnList.add("P-value");

    add(queryTypePanel);//from w  ww  .j a  va 2 s.  co m
    add(queryConditionPanel1);
    add(queryConditionPanel2);

    add(queryCommandPanel);

    experimental.setSelected(true);

    ButtonGroup group = new ButtonGroup();
    group.add(experimental);
    group.add(computational);
    queryTypePanel.add(new JLabel("Query Type"));
    queryTypePanel.add(experimental);
    queryTypePanel.add(computational);
    queryTypePanel.add(new JLabel("                                              "));
    JLabel viewLicenseLabel = new JLabel("<html><font color=blue><u><b>View License</b></u></font></html>");
    ;
    queryTypePanel.add(viewLicenseLabel);
    viewLicenseLabel.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            viewLicense_actionPerformed(lincsCwbFileName);
        }
    });
    String url = getLincsWsdlUrl();
    // String url =
    // "http://localhost:8080/axis2/services/LincsService?wsdl";
    lincs = new Lincs(url, null, null);

    queryConditionPanel1.setLayout(new GridLayout(2, 7));

    final JLabel tissueTypeLabel = new JLabel("Tissue Type");
    final JLabel cellLineLabel = new JLabel("Cell Line");
    final JLabel drug1Label = new JLabel("Drug 1");
    final JLabel drug2Label = new JLabel("Drug 2");
    final JLabel assayTypeLabel = new JLabel("Assay Type");
    final JLabel synergyMeasurementLabel = new JLabel("Synergy Measurement Type");
    final JLabel similarityAlgorithmLabel = new JLabel("Similarity Algorithm");
    final JLabel blankLabel = new JLabel("");

    queryConditionPanel1.add(new JLabel(""));
    queryConditionPanel1.add(new JLabel(""));
    queryConditionPanel1.add(drug1Label);
    queryConditionPanel1.add(new JLabel(""));
    queryConditionPanel1.add(new JLabel(""));
    queryConditionPanel1.add(new JLabel(""));
    queryConditionPanel1.add(blankLabel);

    queryConditionPanel1.add(tissueTypeLabel);
    queryConditionPanel1.add(cellLineLabel);
    queryConditionPanel1.add(drug1Search);
    queryConditionPanel1.add(drug2Label);
    queryConditionPanel1.add(assayTypeLabel);
    queryConditionPanel1.add(synergyMeasurementLabel);
    queryConditionPanel1.add(new JLabel(""));

    queryConditionPanel2.setLayout(new GridLayout(1, 7));
    List<String> tissueTypeList = null;
    List<String> drug1List = null;
    List<String> assayTypeList = null;
    List<String> synergyMeasuremetnTypeList = null;
    List<String> similarityAlgorithmList = null;

    try {
        tissueTypeList = addAll(lincs.getAllTissueNames());
        drug1List = addAll(lincs.getCompound1NamesFromExperimental(null, null));
        assayTypeList = addAll(lincs.getAllAssayTypeNames());
        synergyMeasuremetnTypeList = addAll(lincs.getAllMeasurementTypeNames());
        similarityAlgorithmList = addAll(lincs.getALLSimilarAlgorithmNames());
    } catch (Exception ex) {
        log.error(ex.getMessage());
    }

    tissueTypeBox = new JList();
    final JScrollPane tissueTypeBoxPanel = buildJListPanel(tissueTypeList, tissueTypeBox);

    cellLineBox = new JList();
    final JScrollPane cellLineBoxPanel = buildJListPanel(null, cellLineBox);
    cellLineBox.setEnabled(false);

    final JScrollPane drug1BoxPanel = buildFilterJListPanel(drug1List, drug1Box);

    drug2Box = new JList();
    final JScrollPane drug2BoxPanel = buildJListPanel(null, drug2Box);
    drug2Box.setEnabled(false);

    assayTypeBox = new JList();
    final JScrollPane assayTypeBoxPanel = buildJListPanel(assayTypeList, assayTypeBox);

    synergyMeasurementTypeBox = new JList();
    final JScrollPane synergyMeasuremetnTypeBoxPanel = buildJListPanel(synergyMeasuremetnTypeList,
            synergyMeasurementTypeBox);

    similarityAlgorithmTypeBox = new JList();

    final JScrollPane similarityAlgorithmTypeBoxPanel = buildJListPanel(similarityAlgorithmList,
            similarityAlgorithmTypeBox);

    onlyTitration = new JCheckBox("Only with titration");
    queryConditionPanel2.add(tissueTypeBoxPanel);
    queryConditionPanel2.add(cellLineBoxPanel);
    queryConditionPanel2.add(drug1BoxPanel);
    queryConditionPanel2.add(drug2BoxPanel);
    queryConditionPanel2.add(assayTypeBoxPanel);
    queryConditionPanel2.add(synergyMeasuremetnTypeBoxPanel);
    queryConditionPanel2.add(onlyTitration);

    // dynamic dependency parts
    tissueTypeBox.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {

            if (e.getValueIsAdjusting()) {
                List<String> selectedTissueList = getSelectedValues(tissueTypeBox);
                List<String> cellLineDataList = null;
                List<String> drug1DataList = null;
                try {

                    cellLineDataList = addAll(lincs.getAllCellLineNamesForTissueTypes(selectedTissueList));

                    if (experimental.isSelected() == true)
                        drug1DataList = addAll(
                                lincs.getCompound1NamesFromExperimental(selectedTissueList, null));
                    else
                        drug1DataList = addAll(
                                lincs.getCompound1NamesFromComputational(selectedTissueList, null));

                } catch (Exception ex) {
                    log.error(ex.getMessage());
                }

                if (tissueTypeBox.getSelectedValues() != null && tissueTypeBox.getSelectedValues().length > 0)
                    cellLineBox.setModel(new LincsListModel(cellLineDataList));
                else
                    cellLineBox.setModel(new LincsListModel(null));
                cellLineBox.setEnabled(true);
                cellLineBox.clearSelection();
                drug1Box.removeAllItems();
                for (int i = 0; i < drug1DataList.size(); i++)
                    drug1Box.addItem(drug1DataList.get(i));
                drug1Box.clearSelection();
                drug2Box.clearSelection();
                drug2Box.setModel(new LincsListModel(null));
                drug2Box.setEnabled(false);
                cellLineBox.ensureIndexIsVisible(0);
                drug1Box.ensureIndexIsVisible(0);

            }
        }

    });

    // dynamic dependency parts
    cellLineBox.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                List<String> selectedTissueList = getSelectedValues(tissueTypeBox);
                List<String> selectedCellLineList = getSelectedValues(cellLineBox);

                List<String> drug1DataList = null;
                try {
                    if (experimental.isSelected() == true)
                        drug1DataList = addAll(lincs.getCompound1NamesFromExperimental(selectedTissueList,
                                selectedCellLineList));
                    else
                        drug1DataList = addAll(lincs.getCompound1NamesFromComputational(selectedTissueList,
                                selectedCellLineList));
                } catch (Exception ex) {
                    log.error(ex.getMessage());
                }
                drug1Box.removeAllItems();
                for (int i = 0; i < drug1DataList.size(); i++)
                    drug1Box.addItem(drug1DataList.get(i));
                drug1Box.ensureIndexIsVisible(0);
                drug1Box.clearSelection();
                drug2Box.clearSelection();
                drug2Box.setModel(new LincsListModel(null));
                drug2Box.setEnabled(false);
            }
        }

    });

    // dynamic dependency parts
    drug1Box.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                List<String> selectedTissueList = getSelectedValues(tissueTypeBox);
                List<String> selectedCellLineList = getSelectedValues(cellLineBox);
                List<String> selectedDrug1List = getSelectedValues(drug1Box);

                List<String> drug2DataList = null;
                try {

                    if (experimental.isSelected() == true)
                        drug2DataList = addAll(lincs.getCompound2NamesFromExperimental(selectedTissueList,
                                selectedCellLineList, selectedDrug1List));
                    else
                        drug2DataList = addAll(lincs.getCompound2NamesFromComputational(selectedTissueList,
                                selectedCellLineList, selectedDrug1List));

                } catch (Exception ex) {
                    log.error(ex.getMessage());
                }
                if (drug1Box.getSelectedValues() != null && drug1Box.getSelectedValues().length > 0)
                    drug2Box.setModel(new LincsListModel(drug2DataList));
                else
                    drug2Box.setModel(new LincsListModel(null));
                drug2Box.setEnabled(true);
                drug2Box.ensureIndexIsVisible(0);
            }
        }

    });

    maxResult = new JCheckBox("Max results");
    maxResultNumber = new JTextField("10", 10);
    searchButton = new JButton("Search");
    resetButton = new JButton("Reset");
    colorGradient = new JCheckBox("Color gradient for Score");
    queryCommandPanel.add(maxResult);
    queryCommandPanel.add(maxResultNumber);
    queryCommandPanel.add(searchButton);
    queryCommandPanel.add(resetButton);
    queryCommandPanel.add(colorGradient);
    resultTable = new TableViewer(experimentalColumnNames, null, hideColumnList);
    add(resultTable);
    add(resultProcessingPanel);
    queryResultPanel.setLayout(new BorderLayout());
    // queryResultPanel.add(new JScrollPane(resultTable),
    // BorderLayout.CENTER);

    plotOptions = new JComboBox(new String[] { HEATMAP, NETWORK });
    JButton plotButton = new JButton("Plot");
    final JCheckBox limitNetwork = new JCheckBox("Limit network to multiply-connected pairs");
    limitNetwork.setEnabled(false);
    limitNetwork.setVisible(false);
    JButton exportButton = new JButton("Export");
    exportButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent e) {
            List<String> hideColumns = new ArrayList<String>();
            hideColumns.add("Include");
            TableViewer.export(resultTable.getTable(), hideColumns, resultTable);
        }
    });

    resultProcessingPanel.add(new JLabel("Plot options:"));
    resultProcessingPanel.add(plotOptions);
    resultProcessingPanel.add(plotButton);
    resultProcessingPanel.add(limitNetwork);
    resultProcessingPanel.add(exportButton);

    plotOptions.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

            if (plotOptions.getSelectedItem().toString().equals(HEATMAP)) {
                limitNetwork.setEnabled(false);
            } else if (plotOptions.getSelectedItem().toString().equals(NETWORK)) {
                limitNetwork.setEnabled(true);
            }
        }
    });
    plotButton.addActionListener(plotListener);

    colorGradient.addActionListener(colorGradientListener);
    computational.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            queryConditionPanel1.remove(blankLabel);
            queryConditionPanel1.remove(assayTypeLabel);
            queryConditionPanel1.remove(synergyMeasurementLabel);
            queryConditionPanel2.remove(assayTypeBoxPanel);
            queryConditionPanel2.remove(synergyMeasuremetnTypeBoxPanel);
            queryConditionPanel1.add(similarityAlgorithmLabel, 10);
            queryConditionPanel2.add(similarityAlgorithmTypeBoxPanel, 4);

            queryConditionPanel1.updateUI();
            queryConditionPanel2.updateUI();
            onlyTitration.setEnabled(false);
            reset();

        }
    });

    experimental.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            queryConditionPanel1.remove(similarityAlgorithmLabel);
            queryConditionPanel2.remove(similarityAlgorithmTypeBoxPanel);
            queryConditionPanel1.add(blankLabel, 6);
            queryConditionPanel1.add(assayTypeLabel, 11);
            queryConditionPanel1.add(synergyMeasurementLabel, 12);
            queryConditionPanel2.add(assayTypeBoxPanel, 4);
            queryConditionPanel2.add(synergyMeasuremetnTypeBoxPanel, 5);
            queryConditionPanel1.updateUI();
            queryConditionPanel2.updateUI();
            onlyTitration.setEnabled(true);
            reset();
        }
    });

    searchButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            int rowLimit = 0;

            List<String> tissueTypes = getSelectedValues(tissueTypeBox);
            List<String> cellLineNames = getSelectedValues(cellLineBox);
            List<String> drug1Names = getSelectedValues(drug1Box);
            List<String> drug2Names = getSelectedValues(drug2Box);

            if (maxResult.isSelected()) {
                try {
                    rowLimit = new Integer(maxResultNumber.getText().trim()).intValue();
                } catch (NumberFormatException nbe) {
                    JOptionPane.showMessageDialog(null, "Please enter a number.");
                    maxResultNumber.requestFocus();
                    return;
                }
            }

            if ((drug1Names == null || drug1Names.isEmpty()) && (drug2Names == null || drug2Names.isEmpty())) {

                JOptionPane.showMessageDialog(null,
                        "Please select at least one drug constraint, multiple drugs can be selected.");
                return;

            }

            AbstractAnalysis selectedAnalysis = new LincsSearchAnalysis();
            String dataSetName = null;
            if (experimental.isSelected()) {
                selectedAnalysis.setLabel("LINCS Experimental Query");
                dataSetName = "LINCS Data";
            } else {
                selectedAnalysis.setLabel("LINCS Computational Query");
                dataSetName = "LINCS Data";
            }
            final AnalysisInvokedEvent invokeEvent = new AnalysisInvokedEvent(selectedAnalysis, dataSetName);
            publishAnalysisInvokedEvent(invokeEvent);

            try {

                if (experimental.isSelected()) {
                    List<String> assayTypes = getSelectedValues(assayTypeBox);
                    List<String> measurementTypes = getSelectedValues(synergyMeasurementTypeBox);
                    List<ExperimentalData> dataList = lincs.getExperimentalData(tissueTypes, cellLineNames,
                            drug1Names, drug2Names, measurementTypes, assayTypes, onlyTitration.isSelected(),
                            rowLimit);
                    Object[][] objects = convertExperimentalData(dataList);
                    updateResultTable(objects);
                } else {
                    List<String> similarityAlgorithmTypes = getSelectedValues(similarityAlgorithmTypeBox);

                    List<ComputationalData> dataList = lincs.getComputationalData(tissueTypes, cellLineNames,
                            drug1Names, drug2Names, similarityAlgorithmTypes, rowLimit);
                    Object[][] objects = convertComputationalData(dataList);
                    updateResultTable(objects);

                }

                publishAnalysisCompleteEvent(new AnalysisCompleteEvent(invokeEvent));

            } catch (Exception ex) {
                log.error(ex.getMessage());
                publishAnalysisAbortEvent(new AnalysisAbortEvent(invokeEvent));
            }

            if (resultTable.getData() == null || resultTable.getData().length == 0) {
                JOptionPane.showMessageDialog(null, "There is no row in the database for your query.",
                        "Empty Set", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            freeVariables = getFreeVariables();

        }

    });

    resetButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            reset();
        }

    });

}

From source file:org.languagetool.gui.ConfigurationDialog.java

private void createOfficeElements(GridBagConstraints cons, JPanel portPanel) {
    int numParaCheck = config.getNumParasToCheck();
    JRadioButton[] radioButtons = new JRadioButton[3];
    ButtonGroup numParaGroup = new ButtonGroup();
    radioButtons[0] = new JRadioButton(Tools.getLabel(messages.getString("guiCheckOnlyParagraph")));
    radioButtons[0].setActionCommand("ParagraphCheck");

    radioButtons[1] = new JRadioButton(Tools.getLabel(messages.getString("guiCheckFullText")));
    radioButtons[1].setActionCommand("FullTextCheck");

    radioButtons[2] = new JRadioButton(Tools.getLabel(messages.getString("guiCheckNumParagraphs")));
    radioButtons[2].setActionCommand("NParagraphCheck");
    radioButtons[2].setSelected(true);//from   w  ww  . ja v a 2 s .c  om

    JTextField numParaField = new JTextField(Integer.toString(5), 2);
    numParaField.setEnabled(radioButtons[2].isSelected());
    numParaField.setMinimumSize(new Dimension(30, 25));

    for (int i = 0; i < 3; i++) {
        numParaGroup.add(radioButtons[i]);
    }

    if (numParaCheck == 0) {
        radioButtons[0].setSelected(true);
        numParaField.setEnabled(false);
    } else if (numParaCheck < 0) {
        radioButtons[1].setSelected(true);
        numParaField.setEnabled(false);
    } else {
        radioButtons[2].setSelected(true);
        numParaField.setText(Integer.toString(numParaCheck));
        numParaField.setEnabled(true);
    }

    radioButtons[0].addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            numParaField.setEnabled(false);
            config.setNumParasToCheck(0);
        }
    });

    radioButtons[1].addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            numParaField.setEnabled(false);
            config.setNumParasToCheck(-1);
        }
    });

    radioButtons[2].addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int numParaCheck = Integer.parseInt(numParaField.getText());
            if (numParaCheck < 1)
                numParaCheck = 1;
            else if (numParaCheck > 99)
                numParaCheck = 99;
            config.setNumParasToCheck(numParaCheck);
            numParaField.setForeground(Color.BLACK);
            numParaField.setText(Integer.toString(numParaCheck));
            numParaField.setEnabled(true);
        }
    });

    numParaField.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            try {
                int numParaCheck = Integer.parseInt(numParaField.getText());
                if (numParaCheck > 0 && numParaCheck < 99) {
                    numParaField.setForeground(Color.BLACK);
                    config.setNumParasToCheck(numParaCheck);
                } else {
                    numParaField.setForeground(Color.RED);
                }
            } catch (NumberFormatException ex) {
                numParaField.setForeground(Color.RED);
            }
        }
    });

    JLabel textChangedLabel = new JLabel(Tools.getLabel(messages.getString("guiTextChangeLabel")));
    cons.gridy++;
    portPanel.add(textChangedLabel, cons);

    cons.gridy++;
    cons.insets = new Insets(0, 30, 0, 0);
    for (int i = 0; i < 3; i++) {
        portPanel.add(radioButtons[i], cons);
        if (i < 2)
            cons.gridy++;
    }
    cons.gridx = 1;
    portPanel.add(numParaField, cons);

    JCheckBox noMultiResetbox = new JCheckBox(Tools.getLabel(messages.getString("guiNoMultiReset")));
    noMultiResetbox.setSelected(config.isNoMultiReset());
    noMultiResetbox.setEnabled(config.isResetCheck());
    noMultiResetbox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            config.setNoMultiReset(noMultiResetbox.isSelected());
        }
    });

    JCheckBox resetCheckbox = new JCheckBox(Tools.getLabel(messages.getString("guiDoResetCheck")));
    resetCheckbox.setSelected(config.isResetCheck());
    resetCheckbox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            config.setDoResetCheck(resetCheckbox.isSelected());
            noMultiResetbox.setEnabled(resetCheckbox.isSelected());
        }
    });
    cons.insets = new Insets(0, 4, 0, 0);
    cons.gridx = 0;
    //    JLabel dummyLabel = new JLabel(" ");
    //    cons.gridy++;
    //    portPanel.add(dummyLabel, cons);
    cons.gridy++;
    portPanel.add(resetCheckbox, cons);

    cons.insets = new Insets(0, 30, 0, 0);
    cons.gridx = 0;
    cons.gridy++;
    portPanel.add(noMultiResetbox, cons);

    JCheckBox fullTextCheckAtFirstBox = new JCheckBox(
            Tools.getLabel(messages.getString("guiCheckFullTextAtFirst")));
    fullTextCheckAtFirstBox.setSelected(config.doFullCheckAtFirst());
    fullTextCheckAtFirstBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            config.setFullCheckAtFirst(fullTextCheckAtFirstBox.isSelected());
        }
    });
    cons.insets = new Insets(0, 4, 0, 0);
    cons.gridx = 0;
    //    cons.gridy++;
    //    JLabel dummyLabel2 = new JLabel(" ");
    //    portPanel.add(dummyLabel2, cons);
    cons.gridy++;
    portPanel.add(fullTextCheckAtFirstBox, cons);

    JCheckBox isMultiThreadBox = new JCheckBox(Tools.getLabel(messages.getString("guiIsMultiThread")));
    isMultiThreadBox.setSelected(config.isMultiThread());
    isMultiThreadBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            config.setMultiThreadLO(isMultiThreadBox.isSelected());
        }
    });
    cons.gridy++;
    JLabel dummyLabel3 = new JLabel(" ");
    portPanel.add(dummyLabel3, cons);
    cons.gridy++;
    portPanel.add(isMultiThreadBox, cons);

}

From source file:org.nuclos.client.dbtransfer.DBTransferImport.java

private PanelWizardStep newStep1(final MainFrameTab ifrm) {
    final SpringLocaleDelegate localeDelegate = getSpringLocaleDelegate();
    final PanelWizardStep step = new PanelWizardStep(
            localeDelegate.getMessage("dbtransfer.import.step1.1", "Konfigurationsdatei"),
            localeDelegate.getMessage("dbtransfer.import.step1.2",
                    "Bitte w\u00e4hlen Sie eine Konfigurationsdatei aus."));

    final JLabel lbFile = new JLabel(localeDelegate.getMessage("dbtransfer.import.step1.3", "Datei"));

    utils.initJPanel(step,/* w w  w.j a  v  a  2  s.c  o  m*/
            new double[] { TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED,
                    TableLayout.FILL },
            new double[] { 20, TableLayout.PREFERRED, lbFile.getPreferredSize().height, TableLayout.FILL });

    final JButton btnBrowse = new JButton("...");
    //final JProgressBar progressBar = new JProgressBar(0, 230);
    final JCheckBox chbxImportAsNuclon = new JCheckBox(
            localeDelegate.getMessage("configuration.transfer.import.as.nuclon", "Import als Nuclon"));
    chbxImportAsNuclon.setEnabled(false);
    final JEditorPane editWarnings = new JEditorPane();
    editWarnings.setContentType("text/html");
    editWarnings.setEditable(false);
    editWarnings.setBackground(Color.WHITE);

    final JScrollPane scrollWarn = new JScrollPane(editWarnings);
    scrollWarn.setPreferredSize(new Dimension(680, 250));
    scrollWarn.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    scrollWarn.getVerticalScrollBar().setUnitIncrement(20);
    scrollWarn.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollWarn.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    final JScrollPane scrollPrev = new JScrollPane(jpnPreviewContent);
    scrollPrev.setPreferredSize(new Dimension(680, 250));
    scrollPrev.setBorder(new LineBorder(Color.LIGHT_GRAY, 1));
    scrollPrev.getVerticalScrollBar().setUnitIncrement(20);
    scrollPrev.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPrev.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    final JPanel jpnPreview = new JPanel(new BorderLayout());
    jpnPreview.add(jpnPreviewHeader, BorderLayout.NORTH);
    jpnPreview.add(scrollPrev, BorderLayout.CENTER);
    jpnPreview.add(jpnPreviewFooter, BorderLayout.SOUTH);
    jpnPreview.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    jpnPreview.setBackground(Color.WHITE);
    jpnPreviewHeader.setBackground(Color.WHITE);
    jpnPreviewContent.setBackground(Color.WHITE);
    jpnPreviewFooter.setBackground(Color.WHITE);

    final JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab(localeDelegate.getMessage("configuration.transfer.prepare.warnings.tab", "Warnungen"),
            scrollWarn);
    final String sDefaultPreparePreviewTabText = localeDelegate
            .getMessage("configuration.transfer.prepare.preview.tab", "Vorschau der Schema Aenderungen");
    tabbedPane.addTab(sDefaultPreparePreviewTabText, jpnPreview);

    final JLabel lbNewUser = new JLabel();

    step.add(lbFile, "0,0");
    step.add(tfTransferFile, "1,0");
    step.add(btnBrowse, "2,0");
    step.add(chbxImportAsNuclon, "1,1");//step.add(progressBar, "1,1");
    step.add(lbNewUser, "0,2,3,2");
    step.add(tabbedPane, "0,3,3,3");

    tfTransferFile.setEditable(false);

    final ActionListener prepareImportAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            ifrm.lockLayerWithProgress(Transfer.TOPIC_CORRELATIONID_PREPARE);

            Thread t = new Thread() {
                @Override
                public void run() {
                    step.setComplete(false);
                    boolean blnTransferWithWarnings = false;
                    //progressBar.setValue(0);
                    //progressBar.setVisible(true);
                    try {
                        String fileName = tfTransferFile.getText();
                        if (StringUtils.isNullOrEmpty(fileName)) {
                            return;
                        }
                        File f = new File(fileName);
                        long size = f.length();

                        final InputStream fin = new BufferedInputStream(new FileInputStream(f));
                        final byte[] transferFile;
                        try {
                            transferFile = utils.getBytes(fin, (int) size);
                        } finally {
                            fin.close();
                        }

                        resetStep2();
                        importTransferObject = getTransferFacadeRemote().prepareTransfer(isNuclon,
                                transferFile);
                        chbxImportAsNuclon.setEnabled(importTransferObject.getTransferOptions()
                                .containsKey(TransferOption.IS_NUCLON_IMPORT_ALLOWED));

                        step.setComplete(!importTransferObject.result.hasCriticals());

                        if (!importTransferObject.result.hasCriticals()
                                && !importTransferObject.result.hasWarnings()) {
                            editWarnings.setText(localeDelegate.getMessage(
                                    "configuration.transfer.prepare.no.warnings", "Keine Warnungen"));
                        } else {
                            editWarnings.setText("<html><body><font color=\"#800000\">"
                                    + importTransferObject.result.getCriticals() + "</font>"
                                    + (importTransferObject.result.hasCriticals() ? "<br />" : "")
                                    + importTransferObject.result.getWarnings() + "</body></html>");
                        }

                        int iPreviewSize = importTransferObject.getPreviewParts().size();
                        blnTransferWithWarnings = setupPreviewPanel(importTransferObject.getPreviewParts());
                        tabbedPane.setTitleAt(1, sDefaultPreparePreviewTabText
                                + (iPreviewSize == 0 ? "" : " (" + iPreviewSize + ")"));
                        lbNewUser.setText(
                                "Neue Benutzer" + ": " + (importTransferObject.getNewUserCount() == 0 ? "keine"
                                        : importTransferObject.getNewUserCount()));
                    } catch (Exception e) {
                        //                              progressBar.setVisible(false);
                        Errors.getInstance().showExceptionDialog(ifrm, e);
                    } finally {
                        btnBrowse.setEnabled(true);
                        //                              progressBar.setVisible(false);
                        ifrm.unlockLayer();
                    }
                    if (blnTransferWithWarnings) {
                        JOptionPane.showMessageDialog(jpnPreviewContent, localeDelegate.getMessage(
                                "dbtransfer.import.step1.19",
                                "Nicht alle Statements knnen durchgefhrt werden!\nBitte kontrollieren Sie die mit rot markierten Eintrge!",
                                "Warning", JOptionPane.WARNING_MESSAGE));
                    }
                }

            };

            t.start();
        }
    };
    final ActionListener browseAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            final JFileChooser filechooser = utils.getFileChooser(
                    localeDelegate.getMessage("configuration.transfer.file.nuclet", "Nuclet-Dateien"),
                    ".nuclet");
            final int iBtn = filechooser.showOpenDialog(ifrm);

            if (iBtn == JFileChooser.APPROVE_OPTION) {

                final File file = filechooser.getSelectedFile();
                if (file != null) {
                    tfTransferFile.setText("");
                    btnBrowse.setEnabled(false);
                    //progressBar.setVisible(true);

                    String fileName = file.getPath();
                    if (StringUtils.isNullOrEmpty(fileName)) {
                        return;
                    }

                    tfTransferFile.setText(fileName);

                    prepareImportAction.actionPerformed(new ActionEvent(this, 0, "prepare"));
                }
            }
        }
    };
    final ActionListener importAsNuclonAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            isNuclon = chbxImportAsNuclon.isSelected();
            prepareImportAction.actionPerformed(new ActionEvent(this, 0, "prepare"));
        }
    };
    btnBrowse.addActionListener(browseAction);
    chbxImportAsNuclon.addActionListener(importAsNuclonAction);

    //      progressBar.setVisible(false);

    return step;
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.PropertiesUI.java

/**
  * Builds the panel hosting the information
  * //w ww  . j a va  2  s  .c  om
  * @param details The information to display.
  * @param image     The image of reference.
  * @return See above.
  */
private JPanel buildContentPanel(Map details, ImageData image) {
    JPanel content = new JPanel();
    content.setBackground(UIUtilities.BACKGROUND_COLOR);
    content.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    content.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(0, 2, 2, 0);
    c.gridy = 0;
    c.gridx = 0;
    JLabel l = new JLabel();
    Font font = l.getFont();
    int size = font.getSize() - 2;
    JLabel label = UIUtilities.setTextFont(EditorUtil.ARCHIVED, Font.BOLD, size);
    JCheckBox box = new JCheckBox();
    box.setEnabled(false);
    box.setBackground(UIUtilities.BACKGROUND);
    box.setSelected(model.isArchived());
    content.add(label, c);
    c.gridx = c.gridx + 2;
    content.add(box, c);
    c.gridy++;
    c.gridx = 0;
    label = UIUtilities.setTextFont(EditorUtil.ACQUISITION_DATE, Font.BOLD, size);
    JLabel value = UIUtilities.createComponent(null);
    String v = model.formatDate(image);
    value.setText(v);
    content.add(label, c);
    c.gridx = c.gridx + 2;
    content.add(value, c);
    c.gridy++;
    c.gridx = 0;
    try { //just to be on the save side
        label = UIUtilities.setTextFont(EditorUtil.IMPORTED_DATE, Font.BOLD, size);
        value = UIUtilities.createComponent(null);
        v = UIUtilities.formatShortDateTime(image.getInserted());
        value.setText(v);
        content.add(label, c);
        c.gridx = c.gridx + 2;
        content.add(value, c);
        c.gridy++;
    } catch (Exception e) {

    }
    label = UIUtilities.setTextFont(EditorUtil.XY_DIMENSION, Font.BOLD, size);
    value = UIUtilities.createComponent(null);
    v = (String) details.get(EditorUtil.SIZE_X);
    v += " x ";
    v += (String) details.get(EditorUtil.SIZE_Y);
    value.setText(v);
    c.gridx = 0;
    content.add(label, c);
    c.gridx = c.gridx + 2;
    content.add(value, c);
    c.gridy++;
    label = UIUtilities.setTextFont(EditorUtil.PIXEL_TYPE, Font.BOLD, size);
    value = UIUtilities.createComponent(null);
    value.setText((String) details.get(EditorUtil.PIXEL_TYPE));
    c.gridx = 0;
    content.add(label, c);
    c.gridx = c.gridx + 2;
    content.add(value, c);

    value = UIUtilities.createComponent(null);
    String s = formatPixelsSize(details, value);
    if (s != null) {
        c.gridy++;
        label = UIUtilities.setTextFont(s, Font.BOLD, size);
        c.gridx = 0;
        content.add(label, c);
        c.gridx = c.gridx + 2;
        content.add(value, c);
    }
    //parse modulo T.
    Map<Integer, ModuloInfo> modulo = model.getModulo();
    ModuloInfo moduloT = modulo.get(ModuloInfo.T);
    c.gridy++;
    label = UIUtilities.setTextFont(EditorUtil.Z_T_FIELDS, Font.BOLD, size);
    value = UIUtilities.createComponent(null);
    v = (String) details.get(EditorUtil.SECTIONS);
    v += " x ";
    if (moduloT != null) {
        String time = (String) details.get(EditorUtil.TIMEPOINTS);
        int t = Integer.parseInt(time);
        v += "" + (t / moduloT.getSize());
    } else {
        v += (String) details.get(EditorUtil.TIMEPOINTS);
    }
    value.setText(v);
    c.gridx = 0;
    content.add(label, c);
    c.gridx = c.gridx + 2;
    content.add(value, c);
    c.gridy++;
    if (moduloT != null) {
        label = UIUtilities.setTextFont(EditorUtil.SMALL_T_VARIABLE, Font.BOLD, size);
        value = UIUtilities.createComponent(null);
        value.setText("" + moduloT.getSize());
        c.gridx = 0;
        content.add(label, c);
        c.gridx = c.gridx + 2;
        content.add(value, c);
        c.gridy++;
    }
    if (!model.isNumerousChannel() && model.getRefObjectID() > 0) {
        label = UIUtilities.setTextFont(EditorUtil.CHANNELS, Font.BOLD, size);
        c.gridx = 0;
        c.anchor = GridBagConstraints.NORTHEAST;
        content.add(label, c);
        c.anchor = GridBagConstraints.CENTER;
        c.gridx++;
        content.add(editChannel, c);
        c.gridx++;
        content.add(channelsPane, c);
    }
    JPanel p = UIUtilities.buildComponentPanel(content);
    p.setBackground(UIUtilities.BACKGROUND_COLOR);
    return p;
}

From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java

private TableCellRenderer getCellRenderer(final SwingTreeCol col) {

    return new DefaultTableCellRenderer() {

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {

            ColumnType colType = col.getColumnType();
            if (colType == ColumnType.DYNAMIC) {
                colType = ColumnType.valueOf(extractDynamicColType(elements.toArray()[row], column));
            }//ww w.j  ava 2s .c  o m

            final XulTreeCell cell = getRootChildren().getItem(row).getRow().getCell(column);
            switch (colType) {
            case CHECKBOX:
                JCheckBox checkbox = new JCheckBox();
                if (value instanceof String) {
                    checkbox.setSelected(((String) value).equalsIgnoreCase("true")); //$NON-NLS-1$
                } else if (value instanceof Boolean) {
                    checkbox.setSelected((Boolean) value);
                } else if (value == null) {
                    checkbox.setSelected(false);
                }
                if (isSelected) {
                    checkbox.setBackground(Color.LIGHT_GRAY);
                }
                checkbox.setEnabled(!cell.isDisabled());
                return checkbox;
            case COMBOBOX:
            case EDITABLECOMBOBOX:
                Vector data;

                final JComboBox comboBox = new JComboBox();
                if (cell == null) {
                } else {
                    data = (cell.getValue() != null) ? (Vector) cell.getValue() : new Vector();

                    if (data == null) {
                        logger.debug("SwingTreeCell combobox data is null, passed in value: " + value); //$NON-NLS-1$
                        if (value instanceof Vector) {
                            data = (Vector) value;
                        }
                    }
                    if (data != null) {
                        comboBox.setModel(new DefaultComboBoxModel(data));
                        try {
                            comboBox.setSelectedIndex(cell.getSelectedIndex());
                        } catch (Exception e) {
                            logger.error("error setting selected index on the combobox editor"); //$NON-NLS-1$
                        }
                    }
                }

                if (colType == ColumnType.EDITABLECOMBOBOX) {
                    comboBox.setEditable(true);
                    ((JTextComponent) comboBox.getEditor().getEditorComponent()).setText(cell.getLabel());
                }

                if (isSelected) {
                    comboBox.setBackground(Color.LIGHT_GRAY);
                }
                comboBox.setEnabled(!cell.isDisabled());
                return comboBox;
            case CUSTOM:
                return new CustomCellEditorWrapper(cell, customEditors.get(col.getType()));
            default:
                JLabel label = new JLabel((String) value);

                if (isSelected) {
                    label.setOpaque(true);
                    label.setBackground(Color.LIGHT_GRAY);
                }
                return label;
            }

        }
    };

}

From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java

private TableCellEditor getCellEditor(final SwingTreeCol col) {
    return new DefaultCellEditor(new JComboBox()) {

        JComponent control;//from w  w w.  jav a 2  s .  com

        @Override
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
                final int row, final int column) {
            Component comp;
            ColumnType colType = col.getColumnType();
            if (colType == ColumnType.DYNAMIC) {
                colType = ColumnType.valueOf(extractDynamicColType(elements.toArray()[row], column));
            }

            final XulTreeCell cell = getRootChildren().getItem(row).getRow().getCell(column);
            switch (colType) {
            case CHECKBOX:
                final JCheckBox checkbox = new JCheckBox();
                final JTable tbl = table;
                checkbox.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent event) {
                        SwingTree.this.table.setValueAt(checkbox.isSelected(), row, column);
                        tbl.getCellEditor().stopCellEditing();
                    }
                });

                control = checkbox;
                if (value instanceof String) {
                    checkbox.setSelected(((String) value).equalsIgnoreCase("true")); //$NON-NLS-1$
                } else if (value instanceof Boolean) {
                    checkbox.setSelected((Boolean) value);
                } else if (value == null) {
                    checkbox.setSelected(false);
                }
                if (isSelected) {
                    checkbox.setBackground(Color.LIGHT_GRAY);
                }
                comp = checkbox;
                checkbox.setEnabled(!cell.isDisabled());
                break;
            case EDITABLECOMBOBOX:
            case COMBOBOX:
                Vector val = (value != null && value instanceof Vector) ? (Vector) value : new Vector();
                final JComboBox comboBox = new JComboBox(val);

                if (isSelected) {
                    comboBox.setBackground(Color.LIGHT_GRAY);
                }

                if (colType == ColumnType.EDITABLECOMBOBOX) {

                    comboBox.setEditable(true);
                    final JTextComponent textComp = (JTextComponent) comboBox.getEditor().getEditorComponent();

                    textComp.addKeyListener(new KeyListener() {
                        private String oldValue = ""; //$NON-NLS-1$

                        public void keyPressed(KeyEvent e) {
                            oldValue = textComp.getText();
                        }

                        public void keyReleased(KeyEvent e) {
                            if (oldValue != null && !oldValue.equals(textComp.getText())) {
                                SwingTree.this.table.setValueAt(textComp.getText(), row, column);

                                oldValue = textComp.getText();
                            } else if (oldValue == null) {
                                // AWT error where sometimes the keyReleased is fired before keyPressed.
                                oldValue = textComp.getText();
                            } else {
                                logger.debug("Special key pressed, ignoring"); //$NON-NLS-1$
                            }
                        }

                        public void keyTyped(KeyEvent e) {
                        }
                    });

                    comboBox.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent event) {
                            // if(textComp.hasFocus() == false && comboBox.hasFocus()){
                            SwingTree.logger.debug("Setting ComboBox value from editor: " //$NON-NLS-1$
                                    + comboBox.getSelectedItem() + ", " + row + ", " + column); //$NON-NLS-1$ //$NON-NLS-2$

                            SwingTree.this.table.setValueAt(comboBox.getSelectedIndex(), row, column);
                            // }
                        }
                    });
                } else {
                    comboBox.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent event) {

                            SwingTree.logger.debug("Setting ComboBox value from editor: " //$NON-NLS-1$
                                    + comboBox.getSelectedItem() + ", " + row + ", " + column); //$NON-NLS-1$ //$NON-NLS-2$

                            SwingTree.this.table.setValueAt(comboBox.getSelectedIndex(), row, column);
                        }
                    });
                }

                control = comboBox;
                comboBox.setEnabled(!cell.isDisabled());
                comp = comboBox;
                break;
            case LABEL:
                JLabel lbl = new JLabel(cell.getLabel());
                comp = lbl;
                control = lbl;
                break;
            case CUSTOM:
                return new CustomCellEditorWrapper(cell, customEditors.get(col.getType()));
            default:
                final JTextField label = new JTextField((String) value);

                label.getDocument().addDocumentListener(new DocumentListener() {

                    public void changedUpdate(DocumentEvent arg0) {
                        SwingTree.this.table.setValueAt(label.getText(), row, column);
                    }

                    public void insertUpdate(DocumentEvent arg0) {
                        SwingTree.this.table.setValueAt(label.getText(), row, column);
                    }

                    public void removeUpdate(DocumentEvent arg0) {
                        SwingTree.this.table.setValueAt(label.getText(), row, column);
                    }

                });
                if (isSelected) {
                    label.setOpaque(true);
                    // label.setBackground(Color.LIGHT_GRAY);
                }

                control = label;
                comp = label;
                label.setEnabled(!cell.isDisabled());
                label.setDisabledTextColor(Color.DARK_GRAY);
                break;
            }

            return comp;
        }

        @Override
        public Object getCellEditorValue() {
            if (control instanceof JCheckBox) {
                return ((JCheckBox) control).isSelected();
            } else if (control instanceof JComboBox) {
                JComboBox box = (JComboBox) control;
                if (box.isEditable()) {
                    return ((JTextComponent) box.getEditor().getEditorComponent()).getText();
                } else {
                    return box.getSelectedIndex();
                }
            } else if (control instanceof JTextField) {
                return ((JTextField) control).getText();
            } else {
                return ((JLabel) control).getText();
            }
        }

    };

}

From source file:org.zaproxy.zap.extension.ascan.CustomScanDialog.java

private void populateRequestField(SiteNode node) {
    try {/*ww  w.j av a  2 s. co m*/
        if (node == null || node.getHistoryReference() == null
                || node.getHistoryReference().getHttpMessage() == null) {
            this.getRequestField().setText("");

        } else {
            // Populate the custom vectors http pane
            HttpMessage msg = node.getHistoryReference().getHttpMessage();
            String header = msg.getRequestHeader().toString();
            StringBuilder sb = new StringBuilder();
            sb.append(header);
            this.headerLength = header.length();
            this.urlPathStart = header.indexOf("/", header.indexOf("://") + 2) + 1; // Ignore <METHOD> http(s)://host:port/
            sb.append(msg.getRequestBody().toString());
            this.getRequestField().setText(sb.toString());

            // Only set the recurse option if the node has children, and disable it otherwise
            JCheckBox recurseChk = (JCheckBox) this.getField(FIELD_RECURSE);
            recurseChk.setEnabled(node.getChildCount() > 0);
            recurseChk.setSelected(node.getChildCount() > 0);
        }

        this.setFieldStates();

    } catch (HttpMalformedHeaderException | DatabaseException e) {
        // 
        this.getRequestField().setText("");
    }

}

From source file:org.zaproxy.zap.extension.customFire.CustomFireDialog.java

/**
 * //from  www  .j  a  v a2s  . c o  m
 * @param node void `
 */
private void populateRequestField(SiteNode node) {
    try {
        if (node == null || node.getHistoryReference() == null
                || node.getHistoryReference().getHttpMessage() == null) {
            this.getRequestField().setText("");

        } else {
            // Populate the custom vectors http pane
            HttpMessage msg = node.getHistoryReference().getHttpMessage();
            String header = msg.getRequestHeader().toString();
            StringBuilder sb = new StringBuilder();
            sb.append(header);
            this.headerLength = header.length();
            this.urlPathStart = header.indexOf("/", header.indexOf("://") + 2) + 1; // Ignore <METHOD> http(s)://host:port/
            sb.append(msg.getRequestBody().toString());
            this.getRequestField().setText(sb.toString());

            // Only set the recurse option if the node has children, and disable it otherwise
            JCheckBox recurseChk = (JCheckBox) this.getField(FIELD_RECURSE);
            recurseChk.setEnabled(node.getChildCount() > 0);
            recurseChk.setSelected(node.getChildCount() > 0);
        }
        this.setFieldStates();
    } catch (HttpMalformedHeaderException | DatabaseException e) {
        this.getRequestField().setText("");
    }

}