Esempio n. 1
0
 void updateDeviceList(TreeNode parentNode, DeviceList devList) {
   int nDevs = devList.size();
   for (int n = 0; n < nDevs; n++) {
     Device dev = devList.getDevice(n);
     String friendlyName = dev.getFriendlyName();
     TreeNode devNode = new TreeNode(friendlyName);
     devNode.setUserData(dev);
     parentNode.add(devNode);
     updateServiceList(devNode, dev);
     updateIconList(devNode, dev);
     updateDeviceList(devNode, dev.getDeviceList());
   }
 }
Esempio n. 2
0
 void updateIconList(TreeNode parentNode, Device device) {
   IconList iconList = device.getIconList();
   int nIcons = iconList.size();
   for (int n = 0; n < nIcons; n++) {
     Icon icon = iconList.getIcon(n);
     String url = icon.getURL();
     TreeNode iconNode = new TreeNode(url);
     iconNode.setUserData(icon);
     parentNode.add(iconNode);
   }
 }
Esempio n. 3
0
 void updateServiceList(TreeNode parentNode, Device device) {
   ServiceList serviceList = device.getServiceList();
   int nServices = serviceList.size();
   for (int n = 0; n < nServices; n++) {
     Service service = serviceList.getService(n);
     String serviceType = service.getServiceType();
     TreeNode serviceNode = new TreeNode(serviceType);
     serviceNode.setUserData(service);
     parentNode.add(serviceNode);
     updateActionList(serviceNode, service);
     updateStateVariableList(serviceNode, service);
   }
 }
Esempio n. 4
0
 public void GenerateIcons() {
   super.GenerateIcons();
   if (ports == null) {
     ports = new Port[1];
     ports[0] = new Port(15, 49, Port.TYPE_INPUT, 22, Port.ROT_DOWN, this);
   }
   icons = new ImageIcon[1];
   icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR));
   Graphics g;
   try {
     g = icons[0].getImage().getGraphics();
   } catch (NullPointerException e) {
     System.out.println("Could not get Graphics pointer to " + getClass() + " Image");
     return;
   }
   Graphics2D g2 = (Graphics2D) g;
   Color transparent = new Color(0, 0, 0, 0);
   g2.setBackground(transparent);
   g2.clearRect(0, 0, width, height);
   g.setColor(Color.white);
   g.fillRect(16, 0, 4, 2);
   g.fillRect(4, 2, 4, 2);
   g.fillRect(12, 4, 4, 2);
   g.fillRect(20, 4, 4, 2);
   g.fillRect(4, 8, 4, 2);
   g.fillRect(12, 8, 4, 2);
   g.fillRect(24, 8, 4, 2);
   g.fillRect(0, 10, 4, 2);
   g.fillRect(8, 10, 4, 2);
   g.fillRect(16, 10, 4, 2);
   g.fillRect(24, 12, 4, 2);
   g.fillRect(8, 14, 4, 2);
   g.fillRect(16, 14, 4, 2);
   g.fillRect(0, 18, 4, 2);
   g.fillRect(12, 18, 4, 2);
   g.fillRect(24, 18, 4, 2);
   g.fillRect(16, 20, 4, 2);
   g.fillRect(4, 22, 4, 2);
   g.fillRect(20, 22, 4, 2);
   g.fillRect(8, 24, 4, 2);
   g.fillRect(16, 24, 4, 2);
   currentIcon = icons[0].getImage();
 }
    @Override
    public void run() {
      if (androidMode.getSDK() == null) return;

      final Devices devices = Devices.getInstance();
      java.util.List<Device> deviceList = devices.findMultiple(false);
      Device selectedDevice = devices.getSelectedDevice();

      if (deviceList.size() == 0) {
        // if (deviceMenu.getItem(0).isEnabled()) {
        if (0 < deviceMenu.getItemCount()) {
          deviceMenu.removeAll();
          JMenuItem noDevicesItem = new JMenuItem("No connected devices");
          noDevicesItem.setEnabled(false);
          deviceMenu.add(noDevicesItem);
        }
        devices.setSelectedDevice(null);
      } else {
        deviceMenu.removeAll();

        if (selectedDevice == null) {
          selectedDevice = deviceList.get(0);
          devices.setSelectedDevice(selectedDevice);
        } else {
          // check if selected device is still connected
          boolean found = false;
          for (Device device : deviceList) {
            if (device.equals(selectedDevice)) {
              found = true;
              break;
            }
          }

          if (!found) {
            selectedDevice = deviceList.get(0);
            devices.setSelectedDevice(selectedDevice);
          }
        }

        for (final Device device : deviceList) {
          final JCheckBoxMenuItem deviceItem = new JCheckBoxMenuItem(device.getName());
          deviceItem.setEnabled(true);

          if (device.equals(selectedDevice)) deviceItem.setState(true);

          // prevent checkboxmenuitem automatic state changing onclick
          deviceItem.addChangeListener(
              new ChangeListener() {
                @Override
                public void stateChanged(ChangeEvent e) {
                  if (device.equals(devices.getSelectedDevice())) deviceItem.setState(true);
                  else deviceItem.setState(false);
                }
              });

          deviceItem.addActionListener(
              new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                  devices.setSelectedDevice(device);

                  for (int i = 0; i < deviceMenu.getItemCount(); i++) {
                    ((JCheckBoxMenuItem) deviceMenu.getItem(i)).setState(false);
                  }

                  deviceItem.setState(true);
                }
              });

          deviceMenu.add(deviceItem);
        }
      }
    }