123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- package uraxis.toolbar;
- import com.ur.urcap.api.contribution.toolbar.ToolbarContext;
- import com.ur.urcap.api.contribution.toolbar.swing.SwingToolbarContribution;
- import uraxis.Activator;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.util.*;
- import java.util.Timer;
- class MyToolbarContribution implements SwingToolbarContribution {
- private static final int VERTICAL_SPACE = 10;
- private static final int HEADER_FONT_SIZE = 24;
- private final ToolbarContext context;
- private JLabel demoToolStatus;
- private Timer uiTimer;
- MyToolbarContribution(ToolbarContext context) {
- this.context = context;
- }
- @Override
- public void openView() {
- //UI updates from non-GUI threads must use EventQueue.invokeLater (or SwingUtilities.invokeLater)
- uiTimer = new Timer(true);
- uiTimer.schedule(new TimerTask() {
- @Override
- public void run() {
- EventQueue.invokeLater(new Runnable() {
- @Override
- public void run() {
- demoToolStatus.setText("<HTML>" + get3rdPartyStatus() + "</HTML>");
- }
- });
- }
- }, 0, 1000);
- }
- @Override
- public void closeView() {
- uiTimer.cancel();
- }
- 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("Festo Axis Control");
- header.setFont(header.getFont().deriveFont(Font.BOLD, HEADER_FONT_SIZE));
- headerBox.add(header);
- return headerBox;
- }
- private Box createButtons() {
- Box box = Box.createHorizontalBox();
- JButton left100 = new JButton("<<<1000");
- left100.addActionListener(new AbstractAction() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Activator.daemonInterface.rel(-1000, 20);
- }
- });
- box.add(left100);
- JButton left10 = new JButton("<<100");
- left10.addActionListener(new AbstractAction() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Activator.daemonInterface.rel(-100, 20);
- }
- });
- box.add(left10);
- JButton left1 = new JButton("<10");
- left1.addActionListener(new AbstractAction() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Activator.daemonInterface.rel(-10, 20);
- }
- });
- box.add(left1);
- JButton right1 = new JButton("10>");
- right1.addActionListener(new AbstractAction() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Activator.daemonInterface.rel(10, 20);
- }
- });
- box.add(right1);
- JButton right10 = new JButton("100>>");
- right10.addActionListener(new AbstractAction() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Activator.daemonInterface.rel(100, 20);
- }
- });
- box.add(right10);
- JButton right100 = new JButton("1000>>>");
- right100.addActionListener(new AbstractAction() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Activator.daemonInterface.rel(1000, 20);
- }
- });
- box.add(right100);
- return box;
- }
- private Box createInfo() {
- Box infoBox = Box.createVerticalBox();
- infoBox.setAlignmentX(Component.CENTER_ALIGNMENT);
- // JLabel pane1 = new JLabel();
- // pane1.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
- // pane1.setText("<HTML>This is a sample URCap Toolbar contribution. Feel free to use this as an example for creating new contributions.</HTML>");
- // pane1.setBackground(infoBox.getBackground());
- // infoBox.add(pane1);
- //
- // JLabel pane2 = new JLabel();
- // Locale locale = context.getAPIProvider().getSystemAPI().getSystemSettings().getLocalization().getLocale();
- // pane2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
- // pane2.setText("<HTML>Currently, the robot is configured to use the Locale: " + locale.getDisplayName() + "</HTML>");
- // infoBox.add(pane2);
- demoToolStatus = new JLabel();
- demoToolStatus.setText("<HTML>" + get3rdPartyStatus() +"</HTML>");
- 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 String get3rdPartyStatus() {
- Date now = new Date();
- int curPos=Activator.daemonInterface.getpos();
- String curStatus=Activator.daemonInterface.getstatus();
- return String.format("Position: %d, read at %tF %tT.<br/>%s", curPos, now, now, curStatus);
- }
- }
|