Example usage for weka.gui PropertyPanel PropertyPanel

List of usage examples for weka.gui PropertyPanel PropertyPanel

Introduction

In this page you can find the example usage for weka.gui PropertyPanel PropertyPanel.

Prototype

public PropertyPanel(PropertyEditor pe) 

Source Link

Document

Create the panel with the supplied property editor.

Usage

From source file:meka.gui.goe.GenericObjectEditor.java

License:Open Source License

/**
 * Tries to determine a view for the editor.
 *
 * @param editor   the editor to get the view for
 * @return      the view, null if failed to determine one
 *//* w  w w  .  ja v a 2  s .c  o  m*/
public static JComponent findView(PropertyEditor editor) {
    JComponent result;

    result = null;

    if (editor.supportsCustomEditor() && editor.isPaintable()) {
        result = new PropertyPanel(editor);
    } else if (editor.supportsCustomEditor() && (editor.getCustomEditor() instanceof JComponent)) {
        result = (JComponent) editor.getCustomEditor();
    } else if (editor.getTags() != null) {
        result = new PropertyValueSelector(editor);
    } else if (editor.getAsText() != null) {
        result = new PropertyText(editor);
    }

    return result;
}

From source file:org.knime.knip.suise.node.pixclassmodel.DialogComponentWekaClassifier.java

License:Open Source License

/**
 * @param model//from   www .  ja  va  2 s.c  om
 */
public DialogComponentWekaClassifier(SettingsModelWekaClassifier model, String label) {
    super(model);

    // Add Weka panel for selecting the classifier and its options
    m_ClassifierEditor = new GenericObjectEditor();
    PropertyPanel m_CEPanel = new PropertyPanel(m_ClassifierEditor);
    m_ClassifierEditor.setClassType(Classifier.class);

    JPanel panel = new JPanel(new FlowLayout());
    panel.add(new JLabel(label));
    panel.add(m_CEPanel);

    // add classifier editor panel
    getComponentPanel().add(panel);

}

From source file:sirius.trainer.step3.SelectFeaturePane.java

License:Open Source License

public SelectFeaturePane(JInternalFrame parent, JTabbedPane tabbedPane, ApplicationData applicationData) {
    this.parent = parent;
    this.applicationData = applicationData;
    this.statusPane = applicationData.getStatusPane();
    this.tabbedPane = tabbedPane;

    JPanel north = new JPanel(new BorderLayout());
    north.setBorder(BorderFactory.createTitledBorder("Filter Features"));
    applyFilterButton = new JButton("Apply Filter");
    applyFilterButton.addActionListener(this);
    filterEditor = new GenericObjectEditor();
    /** Filter configuration */
    PropertyPanel filterPanel = new PropertyPanel(filterEditor);
    filterEditor.setClassType(weka.filters.Filter.class);
    north.add(filterPanel, BorderLayout.CENTER);
    undoButton = new JButton("Undo (Remove/Filter)");
    undoButton.setEnabled(false);/*from   w  ww  . j  a va2 s  .  c  om*/
    undoButton.addActionListener(this);
    JPanel filterButtonsPanel = new JPanel(new GridLayout(1, 2));
    filterButtonsPanel.add(applyFilterButton);
    north.add(filterButtonsPanel, BorderLayout.EAST);

    JPanel center = new JPanel(new GridLayout(1, 2));
    //center_left   
    JPanel center_left = new JPanel(new BorderLayout());
    JPanel instancesSummaryPanel = new JPanel(new GridLayout(1, 2));
    instancesSummaryPanel.setBorder(BorderFactory.createTitledBorder("Current File"));
    numberOfInstancesLabel = new JLabel(" Instances: ");
    numberOfFeaturesLabel = new JLabel("Features: ");
    instancesSummaryPanel.add(numberOfInstancesLabel);
    instancesSummaryPanel.add(numberOfFeaturesLabel);
    JPanel center_left_center = new JPanel(new BorderLayout());
    center_left_center.setBorder(BorderFactory.createTitledBorder("Features"));
    myAttributeSelectionPanel = new MyAttributeSelectionPanel();
    center_left_center.add(myAttributeSelectionPanel, BorderLayout.CENTER);
    JPanel removeAttributePanel = new JPanel(new GridLayout(1, 1));
    removeAttributePanel.setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5));
    removeAttributeButton = new JButton("Remove Marked Features");
    removeAttributeButton.setEnabled(false);
    removeAttributeButton.setToolTipText("Remove selected attributes.");
    removeAttributeButton.addActionListener(this);
    removeAttributePanel.add(removeAttributeButton);
    center_left_center.add(removeAttributePanel, BorderLayout.SOUTH);
    center_left.add(instancesSummaryPanel, BorderLayout.NORTH);
    center_left.add(center_left_center, BorderLayout.CENTER);
    this.saveArffButton = new JButton("Save as Arff (All)");
    this.saveArffButton.addActionListener(this);
    this.saveArffNegOnlyButton = new JButton("Save as Arff (-ve Only)");
    this.saveArffNegOnlyButton.addActionListener(this);
    this.saveArffPosOnlyButton = new JButton("Save as Arff (+ve Only)");
    this.saveArffPosOnlyButton.addActionListener(this);
    JPanel outputPanel = new JPanel(new GridLayout(1, 3));
    outputPanel.setBorder(BorderFactory.createTitledBorder("Output"));
    outputPanel.add(this.saveArffButton);
    outputPanel.add(this.saveArffPosOnlyButton);
    outputPanel.add(this.saveArffNegOnlyButton);
    center_left.add(outputPanel, BorderLayout.SOUTH);
    center.add(center_left);

    JPanel center_right = new JPanel(new GridLayout(2, 1));
    attributeSummaryPanel = new AttributeSummaryPanel();
    attributeSummaryPanel.setBorder(BorderFactory.createTitledBorder("Selected Features"));
    attributeVisualizePanel = new AttributeVisualizationPanel();
    center_right.add(attributeSummaryPanel);
    center_right.add(attributeVisualizePanel);

    center.add(center_right);

    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    JPanel south = new JPanel(gridbag);
    south.setBorder(BorderFactory.createEmptyBorder(10, 5, 0, 5));
    previousStepButton = new JButton("<<< BACK");
    previousStepButton.addActionListener(this);
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1.0;
    c.weighty = 1.0;
    gridbag.setConstraints(previousStepButton, c);

    c.weightx = 3.0;
    c.weighty = 1.0;
    gridbag.setConstraints(this.undoButton, c);
    nextStepButton = new JButton("NEXT >>>");
    nextStepButton.addActionListener(this);
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1.0;
    c.weighty = 1.0;
    gridbag.setConstraints(nextStepButton, c);
    south.add(previousStepButton);
    south.add(this.undoButton);
    south.add(nextStepButton);

    setLayout(new BorderLayout());
    add(center, BorderLayout.CENTER);
    add(north, BorderLayout.NORTH);
    add(south, BorderLayout.SOUTH);

    myAttributeSelectionPanel.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                ListSelectionModel lm = (ListSelectionModel) e.getSource();
                for (int i = e.getFirstIndex(); i <= e.getLastIndex(); i++) {
                    if (lm.isSelectedIndex(i)) {
                        attributeSummaryPanel.setAttribute(i);
                        attributeVisualizePanel.setAttribute(i);
                        break;
                    }
                }
            }
        }
    });
}

From source file:trainableSegmentation.Weka_Segmentation.java

License:GNU General Public License

/**
 * Show advanced settings dialog/*from w  ww.ja  v a2s .c o m*/
 *
 * @return false when canceled
 */
public boolean showSettingsDialog() {
    GenericDialogPlus gd = new GenericDialogPlus("Segmentation settings");

    final boolean[] oldEnableFeatures = wekaSegmentation.getEnabledFeatures();

    gd.addMessage("Training features:");
    final int rows = (int) Math.round(FeatureStack.availableFeatures.length / 2.0);
    gd.addCheckboxGroup(rows, 2, FeatureStack.availableFeatures, oldEnableFeatures);

    if (wekaSegmentation.getLoadedTrainingData() != null) {
        final Vector<Checkbox> v = gd.getCheckboxes();
        for (Checkbox c : v)
            c.setEnabled(false);
        gd.addMessage("WARNING: no features are selectable while using loaded data");
    }

    // Expected membrane thickness
    gd.addNumericField("Membrane thickness:", wekaSegmentation.getMembraneThickness(), 0);
    // Membrane patch size
    gd.addNumericField("Membrane patch size:", wekaSegmentation.getMembranePatchSize(), 0);
    // Field of view
    gd.addNumericField("Minimum sigma:", wekaSegmentation.getMinimumSigma(), 1);
    gd.addNumericField("Maximum sigma:", wekaSegmentation.getMaximumSigma(), 1);

    if (wekaSegmentation.getLoadedTrainingData() != null) {
        for (int i = 0; i < 4; i++)
            ((TextField) gd.getNumericFields().get(i)).setEnabled(false);
    }

    gd.addMessage("Classifier options:");

    // Add Weka panel for selecting the classifier and its options
    GenericObjectEditor m_ClassifierEditor = new GenericObjectEditor();
    PropertyPanel m_CEPanel = new PropertyPanel(m_ClassifierEditor);
    m_ClassifierEditor.setClassType(Classifier.class);
    m_ClassifierEditor.setValue(wekaSegmentation.getClassifier());

    // add classifier editor panel
    gd.addComponent(m_CEPanel, GridBagConstraints.HORIZONTAL, 1);

    Object c = (Object) m_ClassifierEditor.getValue();
    String originalOptions = "";
    String originalClassifierName = c.getClass().getName();
    if (c instanceof OptionHandler) {
        originalOptions = Utils.joinOptions(((OptionHandler) c).getOptions());
    }

    gd.addMessage("Class names:");
    for (int i = 0; i < wekaSegmentation.getNumOfClasses(); i++)
        gd.addStringField("Class " + (i + 1), wekaSegmentation.getClassLabel(i), 15);

    gd.addMessage("Advanced options:");
    gd.addCheckbox("Homogenize classes", wekaSegmentation.doHomogenizeClasses());
    gd.addButton("Save feature stack", new SaveFeatureStackButtonListener(
            "Select location to save feature stack", wekaSegmentation.getFeatureStackArray()));
    gd.addSlider("Result overlay opacity", 0, 100, win.overlayOpacity);
    gd.addHelp("http://fiji.sc/wiki/Trainable_Segmentation_Plugin");

    gd.showDialog();

    if (gd.wasCanceled())
        return false;

    final int numOfFeatures = FeatureStack.availableFeatures.length;

    final boolean[] newEnableFeatures = new boolean[numOfFeatures];

    boolean featuresChanged = false;

    // Read checked features and check if any of them changed
    for (int i = 0; i < numOfFeatures; i++) {
        newEnableFeatures[i] = gd.getNextBoolean();
        if (newEnableFeatures[i] != oldEnableFeatures[i]) {
            featuresChanged = true;
            // Macro recording
            record(SET_FEATURE,
                    new String[] { FeatureStack.availableFeatures[i] + "=" + newEnableFeatures[i] });
        }
    }
    if (featuresChanged) {
        wekaSegmentation.setEnabledFeatures(newEnableFeatures);
    }

    // Membrane thickness
    final int newThickness = (int) gd.getNextNumber();
    if (newThickness != wekaSegmentation.getMembraneThickness()) {
        featuresChanged = true;
        wekaSegmentation.setMembraneThickness(newThickness);
        // Macro recording
        record(SET_MEMBRANE_THICKNESS, new String[] { Integer.toString(newThickness) });
    }
    // Membrane patch size
    final int newPatch = (int) gd.getNextNumber();
    if (newPatch != wekaSegmentation.getMembranePatchSize()) {
        featuresChanged = true;
        // Macro recording
        record(SET_MEMBRANE_PATCH, new String[] { Integer.toString(newPatch) });
        wekaSegmentation.setMembranePatchSize(newPatch);
    }
    // Field of view (minimum and maximum sigma/radius for the filters)
    final float newMinSigma = (float) gd.getNextNumber();
    if (newMinSigma != wekaSegmentation.getMinimumSigma() && newMinSigma > 0) {
        featuresChanged = true;
        // Macro recording
        record(SET_MINIMUM_SIGMA, new String[] { Float.toString(newMinSigma) });
        wekaSegmentation.setMinimumSigma(newMinSigma);
    }

    final float newMaxSigma = (float) gd.getNextNumber();
    if (newMaxSigma != wekaSegmentation.getMaximumSigma()
            && newMaxSigma >= wekaSegmentation.getMinimumSigma()) {
        featuresChanged = true;
        // Macro recording
        record(SET_MAXIMUM_SIGMA, new String[] { Float.toString(newMaxSigma) });
        wekaSegmentation.setMaximumSigma(newMaxSigma);
    }
    if (wekaSegmentation.getMinimumSigma() > wekaSegmentation.getMaximumSigma()) {
        IJ.error("Error in the field of view parameters: they will be reset to default values");
        wekaSegmentation.setMinimumSigma(0f);
        wekaSegmentation.setMaximumSigma(16f);
    }

    // Set classifier and options
    c = (Object) m_ClassifierEditor.getValue();
    String options = "";
    final String[] optionsArray = ((OptionHandler) c).getOptions();
    if (c instanceof OptionHandler) {
        options = Utils.joinOptions(optionsArray);
    }
    //System.out.println("Classifier after choosing: " + c.getClass().getName() + " " + options);
    if (originalClassifierName.equals(c.getClass().getName()) == false
            || originalOptions.equals(options) == false) {
        AbstractClassifier cls;
        try {
            cls = (AbstractClassifier) (c.getClass().newInstance());
            cls.setOptions(optionsArray);
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }

        wekaSegmentation.setClassifier(cls);
        // Macro recording
        record(SET_CLASSIFIER, new String[] { c.getClass().getName(), options });

        IJ.log("Current classifier: " + c.getClass().getName() + " " + options);
    }

    boolean classNameChanged = false;
    for (int i = 0; i < wekaSegmentation.getNumOfClasses(); i++) {
        String s = gd.getNextString();
        if (null == s || 0 == s.length()) {
            IJ.log("Invalid name for class " + (i + 1));
            continue;
        }
        s = s.trim();
        if (!s.equals(wekaSegmentation.getClassLabel(i))) {
            if (0 == s.toLowerCase().indexOf("add to "))
                s = s.substring(7);

            wekaSegmentation.setClassLabel(i, s);
            classNameChanged = true;
            addExampleButton[i].setText("Add to " + s);
            // Macro recording
            record(CHANGE_CLASS_NAME, new String[] { Integer.toString(i), s });
        }
    }

    // Update flag to homogenize number of class instances      
    final boolean homogenizeClasses = gd.getNextBoolean();
    if (wekaSegmentation.doHomogenizeClasses() != homogenizeClasses) {
        wekaSegmentation.setDoHomogenizeClasses(homogenizeClasses);
        // Macro recording
        record(SET_HOMOGENIZATION, new String[] { Boolean.toString(homogenizeClasses) });
    }

    // Update result overlay alpha
    final int newOpacity = (int) gd.getNextNumber();
    if (newOpacity != win.overlayOpacity) {
        win.overlayOpacity = newOpacity;
        win.overlayAlpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, win.overlayOpacity / 100f);
        win.resultOverlay.setComposite(win.overlayAlpha);

        // Macro recording
        record(SET_OPACITY, new String[] { Integer.toString(win.overlayOpacity) });

        if (showColorOverlay)
            displayImage.updateAndDraw();
    }

    // If there is a change in the class names,
    // the data set (instances) must be updated.
    if (classNameChanged) {
        // Pack window to update buttons
        win.pack();
    }

    // Update feature stack if necessary
    if (featuresChanged) {
        // Force features to be updated
        wekaSegmentation.setFeaturesDirty();
    } else // This checks if the feature stacks were updated while using the save feature stack button
    if (wekaSegmentation.getFeatureStackArray().isEmpty() == false
            && wekaSegmentation.getFeatureStackArray().getReferenceSliceIndex() != -1)
        wekaSegmentation.setUpdateFeatures(false);

    return true;
}