package urgrip.installation; import com.ur.urcap.api.contribution.installation.swing.SwingInstallationNodeView; import com.ur.urcap.api.domain.data.DataModel; import com.ur.urcap.api.domain.io.DigitalIO; import com.ur.urcap.api.domain.io.IO; import com.ur.urcap.api.domain.io.IOModel; import urgrip.programnodes.Style; import urgrip.toolbar.IOHandler; import javax.swing.*; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; import java.awt.Component; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Collection; import java.util.Vector; import static urgrip.installation.URGripInstallationNodeContribution.*; public class URGripInstallationNodeView implements SwingInstallationNodeView { private final Style style; private Box ddGripOpen; private Box ddGripClose; private Box ddBlow; private Box ddCoupleOpen; private Box ddCoupleClose; private Box ddWaitFor; private URGripInstallationNodeContribution installationNode; public URGripInstallationNodeView(Style style) { this.style = style; } @Override public void buildUI(JPanel jPanel, final URGripInstallationNodeContribution installationNode) { this.installationNode=installationNode; Box.createVerticalBox(); jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS)); // jPanel.add(createInfo()); // jPanel.add(createVerticalSpacing()); // jPanel.add(createInput(installationNode)); ddGripOpen = createDropdown(KEY_GRIP_OPEN); jPanel.add(ddGripOpen); ddGripClose = createDropdown(KEY_GRIP_CLOSE); jPanel.add(ddGripClose); ddCoupleOpen = createDropdown(KEY_COUPLE_OPEN); jPanel.add(ddCoupleOpen); ddCoupleClose = createDropdown(KEY_COUPLE_CLOSE); jPanel.add(ddCoupleClose); ddBlow = createDropdown(KEY_BLOWOUT); jPanel.add(ddBlow); ddWaitFor = createDropdown(KEY_WAITFOR); jPanel.add(ddWaitFor); } private Box createDropdown(String key) { Box section = Box.createHorizontalBox(); section.setAlignmentX(Component.LEFT_ALIGNMENT); JComboBox jcb = new JComboBox(); jcb.setPreferredSize(style.getInputfieldSize()); jcb.setMaximumSize(style.getInputfieldSize()); jcb.setMinimumSize(style.getInputfieldSize()); jcb.addActionListener(actionEvent -> { String value=(String) jcb.getSelectedItem(); installationNode.setValue(key, value); installationNode.setValue(key+"_NR", String.valueOf(value)); }); JLabel jl=new JLabel(key); jl.setLabelFor(jcb); section.add(jl); section.add(createHorizontalSpacing()); section.add(jcb); return section; } private Box createInfo() { Box infoBox = Box.createVerticalBox(); infoBox.setAlignmentX(Component.LEFT_ALIGNMENT); JTextPane pane = new JTextPane(); pane.setBorder(BorderFactory.createEmptyBorder()); SimpleAttributeSet attributeSet = new SimpleAttributeSet(); StyleConstants.setLineSpacing(attributeSet, 0.5f); StyleConstants.setLeftIndent(attributeSet, 0f); pane.setParagraphAttributes(attributeSet, false); pane.setText("The popup title below is shared between all Hello World program nodes.\nThe title cannot be empty."); pane.setEditable(false); pane.setMaximumSize(pane.getPreferredSize()); pane.setBackground(infoBox.getBackground()); infoBox.add(pane); return infoBox; } private JComboBox getCBFromBox(Box b) { return (JComboBox) b.getComponent(2); } private Component createHorizontalSpacing() { return Box.createRigidArea(new Dimension(style.getHorizontalSpacing(), 0)); } private Component createVerticalSpacing() { return Box.createRigidArea(new Dimension(0, style.getVerticalSpacing())); } public void setIO(Collection ios, DataModel model) { Vector ioDOUT=new Vector<>(); Vector ioDIN=new Vector<>(); ioDIN.add(IOHandler.NotConnected); ioDOUT.add(IOHandler.NotConnected); for(DigitalIO io: ios) { if(io.isInput()) ioDIN.add(io.getDefaultName()); else ioDOUT.add(io.getDefaultName()); } getCBFromBox(ddGripClose).setModel(new DefaultComboBoxModel(ioDOUT)); getCBFromBox(ddGripClose).setSelectedItem(model.get(KEY_GRIP_CLOSE, KEY_GRIP_CLOSE_DEFAULT)); getCBFromBox(ddGripOpen).setModel(new DefaultComboBoxModel(ioDOUT)); getCBFromBox(ddGripOpen).setSelectedItem(model.get(KEY_GRIP_OPEN, KEY_GRIP_OPEN_DEFAULT)); getCBFromBox(ddCoupleClose).setModel(new DefaultComboBoxModel(ioDOUT)); getCBFromBox(ddCoupleClose).setSelectedItem(model.get(KEY_COUPLE_CLOSE, KEY_COUPLE_CLOSE_DEFAULT)); getCBFromBox(ddCoupleOpen).setModel(new DefaultComboBoxModel(ioDOUT)); getCBFromBox(ddCoupleOpen).setSelectedItem(model.get(KEY_COUPLE_OPEN, KEY_COUPLE_OPEN_DEFAULT)); getCBFromBox(ddBlow).setModel(new DefaultComboBoxModel(ioDOUT)); getCBFromBox(ddBlow).setSelectedItem(model.get(KEY_BLOWOUT, KEY_BLOWOUT_DEFAULT)); getCBFromBox(ddWaitFor).setModel(new DefaultComboBoxModel(ioDIN)); getCBFromBox(ddWaitFor).setSelectedItem(model.get(KEY_WAITFOR, KEY_WAITFOR_DEFAULT)); } }