Package nodebox.node

Examples of nodebox.node.Port


    private Port getPort() {
        return nodeAttributesDialog.getNode().getInput(portName);
    }

    public void updateValues() {
        Port port = getPort();
        nameField.setText(port.getName());
        labelField.setText(port.getDisplayLabel());
        typeField.setText(port.getType());
        descriptionField.setText(port.getDescription());
        rangeBox.setSelectedItem(getHumanizedRange(port.getRange()));
        if (port.isStandardType()) {
            widgetBox.setSelectedItem(getHumanizedWidget(port.getWidget()));
            valueField.setText(port.getValue().toString());
        } else
            valueField.setEnabled(false);
        Object minimumValue = port.getMinimumValue();
        String minimumValueString = minimumValue == null ? "" : minimumValue.toString();
        minimumValueCheck.setSelected(minimumValue != null);
        minimumValueField.setText(minimumValueString);
        minimumValueField.setEnabled(minimumValue != null);
        Object maximumValue = port.getMaximumValue();
        String maximumValueString = maximumValue == null ? "" : maximumValue.toString();
        maximumValueCheck.setSelected(maximumValue != null);
        maximumValueField.setText(maximumValueString);
        maximumValueField.setEnabled(maximumValue != null);
        menuItemsTable.tableChanged(new TableModelEvent(menuItemsTable.getModel()));
View Full Code Here


        menuItemsTable.tableChanged(new TableModelEvent(menuItemsTable.getModel()));
        revalidate();
    }

    public void actionPerformed(ActionEvent e) {
        Port port = getPort();
        if (e.getSource() == labelField) {
            if (labelField.getText().equals(port.getDisplayLabel())) return;
            nodeAttributesDialog.setPortLabel(portName, labelField.getText());
        } else if (e.getSource() == descriptionField) {
            nodeAttributesDialog.setPortDescription(portName, descriptionField.getText());
        } else if (e.getSource() == widgetBox) {
            HumanizedObject newWidget = (HumanizedObject) widgetBox.getSelectedItem();
            if (port.getWidget() == newWidget.getObject()) return;
            nodeAttributesDialog.setPortWidget(portName, (Port.Widget) newWidget.getObject());
        } else if (e.getSource() == rangeBox) {
            HumanizedObject newRange = (HumanizedObject) rangeBox.getSelectedItem();
            if (port.getRange() == newRange.getObject()) return;
            nodeAttributesDialog.setPortRange(portName, (Port.Range) newRange.getObject());
        } else if (e.getSource() == valueField) {
            String newValue = valueField.getText();
            if (port.getValue() != null && port.getValue().toString().equals(newValue)) return;
            try {
                nodeAttributesDialog.setPortValue(portName, Port.parseValue(port.getType(), valueField.getText()));
            } catch (IllegalArgumentException e1) {
                showError("Value " + valueField.getText() + " is invalid: " + e1.getMessage());
            }
        } else if (e.getSource() == minimumValueCheck) {
            if (minimumValueCheck.isSelected() && port.getMinimumValue() != null) return;
            nodeAttributesDialog.setPortMinimumValue(portName, minimumValueCheck.isSelected() ? (double) 0f : null);
        } else if (e.getSource() == minimumValueField) {
            try {
                float v = Float.parseFloat(minimumValueField.getText());
                if (v == port.getMinimumValue()) return;
                nodeAttributesDialog.setPortMinimumValue(portName, (double) v);
            } catch (Exception e1) {
                showError("Value " + minimumValueField.getText() + " is invalid: " + e1.getMessage());
            }
        } else if (e.getSource() == maximumValueCheck) {
            if (maximumValueCheck.isSelected() && port.getMaximumValue() != null) return;
            nodeAttributesDialog.setPortMaximumValue(portName, maximumValueCheck.isSelected() ? (double) 0f : null);
        } else if (e.getSource() == maximumValueField) {
            try {
                float v = Float.parseFloat(maximumValueField.getText());
                if (v == port.getMaximumValue()) return;
                nodeAttributesDialog.setPortMaximumValue(portName, (double) v);
            } catch (Exception e1) {
                showError("Value " + maximumValueField.getText() + " is invalid: " + e1.getMessage());
            }
        } else if (e.getSource() == addButton) {
            MenuItemDialog dialog = new MenuItemDialog((Dialog) SwingUtilities.getRoot(this));
            dialog.setVisible(true);
            if (dialog.isSuccessful()) {
                nodeAttributesDialog.addPortMenuItem(portName, dialog.getKey(), dialog.getLabel());
                menuItemsTable.tableChanged(new TableModelEvent(menuItemsTable.getModel()));
            }
        } else if (e.getSource() == removeButton) {
            MenuItem item = port.getMenuItems().get(menuItemsTable.getSelectedRow());
            nodeAttributesDialog.removePortMenuItem(portName, item);
        } else if (e.getSource() == upButton) {
            moveMenuItemUp();
        } else if (e.getSource() == downButton) {
            moveMenuItemDown();
View Full Code Here

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

        Dimension labelSize = new Dimension(PortView.LABEL_WIDTH, 16);

        Port port = getPort();
        label = new ShadowLabel(port.getDisplayLabel());
        if (! port.getDescription().isEmpty())
            label.setToolTipText(port.getName() + ": " + port.getDescription());
        else
            label.setToolTipText(port.getName());
        label.setBorder(null);
        label.setPreferredSize(labelSize);
        label.setMinimumSize(labelSize);

        this.control = control;
View Full Code Here

        for (Port p : node.getInputs())
            portNames.add(p.getName());

        for (String portName : portNames) {
            Port p = node.getInput(portName);
            // Hide ports with names that start with an underscore.
            if (portName.startsWith("_") || p.getName().startsWith("_")) continue;
            // Hide ports whose values can't be persisted.
            if (p.isCustomType()) continue;
            // Hide ports that accept lists.
            if (p.hasListRange()) continue;
            Class widgetClass = CONTROL_MAP.get(p.getWidget());
            JComponent control;
            if (getDocument().isConnected(portName)) {
                control = new JLabel("<connected>");
                control.setMinimumSize(new Dimension(10, 35));
                control.setFont(Theme.SMALL_FONT);
                control.setForeground(Theme.TEXT_DISABLED_COLOR);
            } else if (widgetClass != null) {
                control = (JComponent) constructControl(widgetClass, activeNodePath, p);
                ((PortControl) control).setValueChangeListener(this);
                ((PortControl) control).setDisplayName(portName);
                controlMap.put(portName, (PortControl) control);
            } else {
                control = new JLabel("  ");
            }

            GridBagConstraints rowConstraints = new GridBagConstraints();
            rowConstraints.gridx = 0;
            rowConstraints.gridy = rowIndex;
            rowConstraints.fill = GridBagConstraints.HORIZONTAL;
            rowConstraints.weightx = 1.0;
            PortRow portRow = new PortRow(getDocument(), portName, control);
            portRow.setEnabled(p.isEnabled());
            controlPanel.add(portRow, rowConstraints);
            rowIndex++;
        }

        if (rowIndex == 0) {
View Full Code Here

TOP

Related Classes of nodebox.node.Port

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.