123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- package urgrip.toolbar;
- import com.ur.urcap.api.contribution.toolbar.ToolbarAPIProvider;
- import com.ur.urcap.api.contribution.toolbar.ToolbarContext;
- import com.ur.urcap.api.contribution.toolbar.swing.SwingToolbarContribution;
- import com.ur.urcap.api.domain.io.DigitalIO;
- import urgrip.installation.URGripInstallationNodeContribution;
- import urgrip.installation.URGripInstallationNodeService;
- import javax.swing.*;
- import java.awt.*;
- import java.util.*;
- class MyToolbarContribution implements SwingToolbarContribution {
- private static final int VERTICAL_SPACE = 10;
- private static final int HEADER_FONT_SIZE = 24;
- private final ToolbarContext context;
- private final ToolbarAPIProvider apiProvider;
- private final IOHandler ioHandler;
- private final URGripInstallationNodeContribution installationNode;
- private JLabel demoToolStatus;
- private HashMap<String, JCheckBox> boxes=new HashMap<>();
- private DigitalIO ioGripClose, ioGripOpen, ioCoupleClose, ioCoupleOpen, blowout, waitfor;
- private JButton bGrip;
- private JButton bRelease;
- private JButton bBlow;
- private JButton bCouple;
- private JButton bDecouple;
- MyToolbarContribution(ToolbarContext context) {
- this.context = context;
- this.apiProvider = context.getAPIProvider();
- this.ioHandler = new IOHandler(this.apiProvider.getApplicationAPI().getIOModel());
- this.installationNode = apiProvider.getApplicationAPI().getInstallationNode(URGripInstallationNodeContribution.class);
- }
- @Override
- public void openView() {
- initializeIO();
- }
- @Override
- public void closeView() {
- }
- private void initializeIO() {
- ioGripClose = ioHandler.getDigitalIO(installationNode.getGripCloseIO());
- ioGripOpen = ioHandler.getDigitalIO(installationNode.getGripOpenIO());
- ioCoupleClose = ioHandler.getDigitalIO(installationNode.getCoupleCloseIO());
- ioCoupleOpen = ioHandler.getDigitalIO(installationNode.getCoupleOpenIO());
- blowout = ioHandler.getDigitalIO(installationNode.getBlowoutIO());
- waitfor = ioHandler.getDigitalIO(installationNode.getWaitforIO());
- }
- public void buildUI(JPanel jPanel) {
- jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS));
- jPanel.add(createHeader());
- jPanel.add(createVerticalSpace());
- jPanel.add(createButtons());
- jPanel.add(createInfo());
- }
- private Box createHeader() {
- Box headerBox = Box.createHorizontalBox();
- headerBox.setAlignmentX(Component.CENTER_ALIGNMENT);
- JLabel header = new JLabel("Gripper");
- header.setFont(header.getFont().deriveFont(Font.BOLD, HEADER_FONT_SIZE));
- headerBox.add(header);
- return headerBox;
- }
- private Box createButtons() {
- Box box = Box.createHorizontalBox();
- bGrip = new JButton("grip");
- box.add(bGrip);
- new MyButton(bGrip, new HandleButton() {
- @Override public void action() {
- ioGripOpen.setValue(true);
- ioGripClose.setValue(false);
- }
- });
- bRelease = new JButton("release");
- box.add(bRelease);
- new MyButton(bRelease, new HandleButton() {
- @Override public void action() {
- ioGripOpen.setValue(false);
- ioGripClose.setValue(true);
- }
- });
- bBlow = new JButton("blow out");
- box.add(bBlow);
- new MyButton(bBlow, new HandleButton() {
- @Override
- public void down() {
- blowout.setValue(true);
- }
- @Override
- public void up() {
- blowout.setValue(false);
- }
- });
- bCouple = new JButton("couple");
- box.add(bCouple);
- new MyButton(bCouple, new HandleButton() {
- @Override public void action() {
- ioCoupleClose.setValue(false);
- ioCoupleOpen.setValue(true);
- }
- });
- bDecouple = new JButton("decouple");
- box.add(bDecouple);
- new MyButton(bDecouple, new HandleButton() {
- @Override public void action() {
- ioCoupleClose.setValue(true);
- ioCoupleOpen.setValue(false);
- }
- });
- return box;
- }
- private Box createInfo() {
- Box infoBox = Box.createVerticalBox();
- infoBox.setAlignmentX(Component.CENTER_ALIGNMENT);
- demoToolStatus = new JLabel();
- demoToolStatus.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
- infoBox.add(demoToolStatus);
- return infoBox;
- }
- private Component createVerticalSpace() {
- return Box.createRigidArea(new Dimension(0, VERTICAL_SPACE));
- }
- private void updateText(String text) {
- SwingUtilities.invokeLater(() -> demoToolStatus.setText("<HTML>" + text +"</HTML>"));
- }
- }
|