public void unloadPlates() throws ChippingManagerException {
   seedChipperGUIController.getSeedChipperController().validateChangePriorToSave();
   //        List<Plate> platesToUnload = getFailedChiplates();
   DefaultListModel destinationsListModel = (DefaultListModel) destinationsList.getModel();
   int[] destinationsLoadCount = new int[destinationsListModel.getSize()];
   // Assign destinations to the seed plates
   int destinationsListIndex = 0;
   updateSeedPlateStatus();
   updateChipPlateStatus();
   // Set the respective locations in the seed plates
   for (int i = 0; i < seedPlates.length; i++) {
     // todo: unload criteria to be refactored to plate object....
     if (SCANNED.equals(seedPlates[i].getStatus()) && seedPlates[i].getPrescanStatus() != null) {
       destinationsListIndex =
           findDestinationListIndex(
               destinationsListModel, destinationsLoadCount, destinationsListIndex, i);
       // Decide the destination
       String seedPlateDestination =
           destinationsListModel.getElementAt(destinationsListIndex).toString();
       logger.info(
           "assigning seed  plates to plate "
               + seedPlates[i].getDeckNest()
               + " ->> "
               + seedPlateDestination);
       seedPlates[i].setStorageLocation(seedPlateDestination);
       destinationsLoadCount[destinationsListIndex]++;
       destinationsListIndex++;
       seedPlates[i].setPrescanStatus(CHIPPED);
     }
   }
   seedChipperGUIController
       .getSeedChipperController()
       .unloadChipperRun(userIDComboBox.getSelectedItem().toString());
   //
   // seedChipperGUIController.getSeedChipperController().syncPrescannedPlatesList(platesToUnload,
   // seedPlates, chipPlates);
   seedChipperGUIController.drawDeck();
   seedChipperGUIController.drawRunsOnDeck();
   logger.info("Plates unloaded to seed store");
   this.dispose();
 }
Exemplo n.º 2
0
 private void handleResquest(String s) {
   Logger.info("@ClientMediator.handleResquest id=" + _id + " :s=" + s);
   if (s.indexOf("sync") > -1) {
     tellClient("sync " + s.split(" ")[1], 0);
   } else if (s.indexOf("get-status") > -1) {
     Integer[] ts = (Integer[]) tankStateProxy().getTanks();
     Logger.debug("ClientMediator.handleResquest: ts.len=" + ts.length);
     for (int i = 0; i < ts.length; i++) {
       ClientMediator cm =
           (ClientMediator) appFacade().retrieveMediator(Const.CLIENT_MEDIATOR + ts[i].intValue());
       TankState t = cm.getState();
       if (t == null || cm.destroyd) continue;
       tellClient(
           "create tank "
               + t.tankID
               + " "
               + t.tankName
               + " 0 0 "
               + t.life
               + " 500 "
               + t.x
               + " "
               + t.y
               + " "
               + cm.getTankAngle()
               + " "
               + cm.getGunAngle(),
           0);
     }
   } else if (s.indexOf("born") > -1) {
     if (_state == null) Arena.addReq(_id, s, null);
   } else if (s.indexOf("move-to") > -1) {
     if (_state != null) {
       Arena.addReq(_id, s, getState());
     }
   } else if (s.indexOf("rotate-to") > -1) { // rotate gun
     if (_state != null) {
       Arena.addReq(_id, s, getState());
     }
   } else if (s.indexOf("shoot") > -1) {
     if (_state != null) {
       Arena.addReq(_id, s, getState());
     }
   } else if (s.indexOf("talk") > -1) {
     if (_state != null) s = "talk " + _state.tankName + " say: " + s.substring(5);
     this.sendNotification(Const.BROAD_CAST, s, null);
   }
 }
  /**
   * Parses the given http response.
   *
   * @param response the http response to parse
   * @return the new account
   */
  private NewAccount parseHttpResponse(String response) {
    NewAccount newAccount = null;
    try {
      JSONObject jsonObject = (JSONObject) JSONValue.parseWithException(response);
      boolean isSuccess = (Boolean) jsonObject.get("success");

      if (isSuccess) {
        newAccount =
            new NewAccount(
                (String) jsonObject.get("sip_address"),
                passField.getPassword(),
                null,
                (String) jsonObject.get("outbound_proxy"));

        String xcapRoot = (String) jsonObject.get("xcap_root");

        // as sip2sip adds @sip2sip.info at the end of the
        // xcap_uri but doesn't report it in resullt after
        // creating account, we add it
        String domain = null;
        int delimIndex = newAccount.getUserName().indexOf("@");
        if (delimIndex != -1) {
          domain = newAccount.getUserName().substring(delimIndex);
        }
        if (domain != null) {
          if (xcapRoot.endsWith("/"))
            xcapRoot = xcapRoot.substring(0, xcapRoot.length() - 1) + domain;
          else xcapRoot += domain;
        }

        newAccount.setXcapRoot(xcapRoot);
      } else {
        showErrorMessage((String) jsonObject.get("error_message"));
      }
    } catch (Throwable e1) {
      if (logger.isInfoEnabled()) logger.info("Failed Json parsing.", e1);
    }

    return newAccount;
  }
  /**
   * Callback method to process modifications in the common ConfigOptions panel. ConfigOptions was
   * developed to be common to many applications (even though we only have three modes), so it does
   * not have any knowledge of how we are using it within this dialog box. So ConfigOptions just
   * sends updates to registered Observers whenever anything changes. We can receive those
   * notifications here, and decide whether we have enough information to enable the "Connect"
   * button of the dialog box.
   */
  public void update(Observable o, Object arg) {
    // we are going to ignore the Observable object, since we are only
    // observing one object. All we are interested in is the argument.

    if (!(arg instanceof OptionUpdate)) {
      log.log(
          Level.WARNING,
          "DatabaseLocationDialog received update type: " + arg,
          new IllegalArgumentException());
      return;
    }

    OptionUpdate optionUpdate = (OptionUpdate) arg;

    // load saved configuration
    SavedConfiguration config = SavedConfiguration.getSavedConfiguration();

    switch (optionUpdate.getUpdateType()) {
      case DB_LOCATION_CHANGED:
        location = (String) optionUpdate.getPayload();
        if (configOptions.getApplicationMode() == ApplicationMode.STANDALONE_CLIENT) {
          File f = new File(location);
          if (f.exists() && f.canRead() && f.canWrite()) {
            validDb = true;
            log.info("File chosen " + location);
            config.setParameter(SavedConfiguration.DATABASE_LOCATION, location);
          } else {
            log.warning("Invalid file " + location);
          }
        } else {
          try {
            if (location.matches("\\d+\\.\\d+\\.\\d+\\.\\d+")) {
              // location given matches 4 '.' separated numbers
              // regex could be improved by limiting each quad to
              // no more than 3 digits.
              String[] quads = location.split("\\.");
              byte[] address = new byte[quads.length];
              for (int i = 0; i < quads.length; i++) {
                address[i] = new Integer(quads[i]).byteValue();
              }
              InetAddress.getByAddress(address);
            } else {
              InetAddress.getAllByName(location);
            }
            log.info("Server specified " + location);
            validDb = true;
            config.setParameter(SavedConfiguration.SERVER_ADDRESS, location);
          } catch (UnknownHostException uhe) {
            log.warning("Unknown host: " + location);
            validDb = false;
          }
        }
        break;
      case PORT_CHANGED:
        port = (String) optionUpdate.getPayload();
        int p = Integer.parseInt(port);

        if (p >= LOWEST_PORT && p < HIGHEST_PORT) {
          if (p < SYSTEM_PORT_BOUNDARY) {
            log.info("User chose System port " + port);
          } else if (p < IANA_PORT_BOUNDARY) {
            log.info("User chose IANA port " + port);
          } else {
            log.info("User chose dynamic port " + port);
          }
          validPort = true;
          config.setParameter(SavedConfiguration.SERVER_PORT, port);
        } else {
          validPort = false;
        }
        break;
      case NETWORK_CHOICE_MADE:
        networkType = (ConnectionType) optionUpdate.getPayload();
        switch (networkType) {
          case SOCKET:
            log.info("Server connection via Sockets");
            break;
          case RMI:
            log.info("Server connection via RMI");
            break;
          default:
            log.info("Unknown connection type: " + networkType);
            break;
        }
        config.setParameter(SavedConfiguration.NETWORK_TYPE, "" + networkType);
        validCnx = true;
        break;
      default:
        log.warning("Unknown update: " + optionUpdate);
        break;
    }

    boolean allValid = validDb && validPort && validCnx;
    connectButton.setEnabled(allValid);
  }
  /**
   * Creates this account on the server.
   *
   * @return the created account
   */
  public NewAccount createAccount() {
    // Check if the two passwords match.
    String pass1 = new String(passField.getPassword());
    String pass2 = new String(retypePassField.getPassword());
    if (!pass1.equals(pass2)) {
      showErrorMessage(
          IppiAccRegWizzActivator.getResources()
              .getI18NString("plugin.sipaccregwizz.NOT_SAME_PASSWORD"));

      return null;
    }

    NewAccount newAccount = null;
    try {
      StringBuilder registerLinkBuilder = new StringBuilder(registerLink);
      registerLinkBuilder
          .append(URLEncoder.encode("email", "UTF-8"))
          .append("=")
          .append(URLEncoder.encode(emailField.getText(), "UTF-8"))
          .append("&")
          .append(URLEncoder.encode("password", "UTF-8"))
          .append("=")
          .append(URLEncoder.encode(new String(passField.getPassword()), "UTF-8"))
          .append("&")
          .append(URLEncoder.encode("display_name", "UTF-8"))
          .append("=")
          .append(URLEncoder.encode(displayNameField.getText(), "UTF-8"))
          .append("&")
          .append(URLEncoder.encode("username", "UTF-8"))
          .append("=")
          .append(URLEncoder.encode(usernameField.getText(), "UTF-8"))
          .append("&")
          .append(URLEncoder.encode("user_agent", "UTF-8"))
          .append("=")
          .append(URLEncoder.encode("sip-communicator.org", "UTF-8"));

      URL url = new URL(registerLinkBuilder.toString());
      URLConnection conn = url.openConnection();

      // If this is not an http connection we have nothing to do here.
      if (!(conn instanceof HttpURLConnection)) {
        return null;
      }

      HttpURLConnection httpConn = (HttpURLConnection) conn;

      int responseCode = httpConn.getResponseCode();

      if (responseCode == HttpURLConnection.HTTP_OK) {
        // Read all the text returned by the server
        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String str;

        StringBuffer stringBuffer = new StringBuffer();
        while ((str = in.readLine()) != null) {
          stringBuffer.append(str);
        }

        if (logger.isInfoEnabled())
          logger.info("JSON response to create account request: " + stringBuffer.toString());

        newAccount = parseHttpResponse(stringBuffer.toString());
      }
    } catch (MalformedURLException e1) {
      if (logger.isInfoEnabled())
        logger.info("Failed to create URL with string: " + registerLink, e1);
    } catch (IOException e1) {
      if (logger.isInfoEnabled()) logger.info("Failed to open connection.", e1);
    }
    return newAccount;
  }
Exemplo n.º 6
0
 /** Logs the interaction, Type can be S - Server Sent C - Client Sent */
 public void logComand(String command, char type) {
   logger.info("For[" + type + "] " + command);
 }
Exemplo n.º 7
0
  public QSAdminGUI(QSAdminMain qsadminMain, JFrame parentFrame) {
    this.parentFrame = parentFrame;
    Container cp = this;
    qsadminMain.setGUI(this);
    cp.setLayout(new BorderLayout(5, 5));
    headerPanel = new HeaderPanel(qsadminMain, parentFrame);
    mainCommandPanel = new MainCommandPanel(qsadminMain);
    cmdConsole = new CmdConsole(qsadminMain);
    propertiePanel = new PropertiePanel(qsadminMain);

    if (headerPanel == null
        || mainCommandPanel == null
        || cmdConsole == null
        || propertiePanel == null) {
      throw new RuntimeException("Loading of one of gui component failed.");
    }

    headerPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    cp.add(headerPanel, BorderLayout.NORTH);
    JScrollPane propertieScrollPane = new JScrollPane(propertiePanel);
    // JScrollPane commandScrollPane = new JScrollPane(mainCommandPanel);
    JSplitPane splitPane =
        new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, mainCommandPanel, cmdConsole);
    splitPane.setOneTouchExpandable(false);
    splitPane.setDividerLocation(250);
    // splitPane.setDividerLocation(0.70);

    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    tabbedPane.addTab("Main", ball, splitPane, "Main Commands");
    tabbedPane.addTab("Get/Set", ball, propertieScrollPane, "Properties Panel");

    QSAdminPluginConfig qsAdminPluginConfig = null;
    PluginPanel pluginPanel = null;
    // -- start of loadPlugins
    try {
      File xmlFile = null;
      ClassLoader classLoader = null;
      Class mainClass = null;

      File file = new File(pluginDir);
      File dirs[] = null;

      if (file.canRead()) dirs = file.listFiles(new DirFileList());

      for (int i = 0; dirs != null && i < dirs.length; i++) {
        xmlFile = new File(dirs[i].getAbsolutePath() + File.separator + "plugin.xml");
        if (xmlFile.canRead()) {
          qsAdminPluginConfig = PluginConfigReader.read(xmlFile);
          if (qsAdminPluginConfig.getActive().equals("yes")
              && qsAdminPluginConfig.getType().equals("javax.swing.JPanel")) {
            classLoader = ClassUtil.getClassLoaderFromJars(dirs[i].getAbsolutePath());
            mainClass = classLoader.loadClass(qsAdminPluginConfig.getMainClass());
            logger.fine("Got PluginMainClass " + mainClass);
            pluginPanel = (PluginPanel) mainClass.newInstance();
            if (JPanel.class.isInstance(pluginPanel) == true) {
              logger.info("Loading plugin : " + qsAdminPluginConfig.getName());
              pluginPanelMap.put("" + (2 + i), pluginPanel);
              plugins.add(pluginPanel);
              tabbedPane.addTab(
                  qsAdminPluginConfig.getName(),
                  ball,
                  (JPanel) pluginPanel,
                  qsAdminPluginConfig.getDesc());
              pluginPanel.setQSAdminMain(qsadminMain);
              pluginPanel.init();
            }
          } else {
            logger.info(
                "Plugin "
                    + dirs[i]
                    + " is disabled so skipping "
                    + qsAdminPluginConfig.getActive()
                    + ":"
                    + qsAdminPluginConfig.getType());
          }
        } else {
          logger.info("No plugin configuration found in " + xmlFile + " so skipping");
        }
      }
    } catch (Exception e) {
      logger.warning("Error loading plugin : " + e);
      logger.fine("StackTrace:\n" + MyString.getStackTrace(e));
    }
    // -- end of loadPlugins

    tabbedPane.addChangeListener(
        new ChangeListener() {
          int selected = -1;
          int oldSelected = -1;

          public void stateChanged(ChangeEvent e) {
            // if plugin
            selected = tabbedPane.getSelectedIndex();
            if (selected >= 2) {
              ((PluginPanel) pluginPanelMap.get("" + selected)).activated();
            }
            if (oldSelected >= 2) {
              ((PluginPanel) pluginPanelMap.get("" + oldSelected)).deactivated();
            }
            oldSelected = selected;
          }
        });

    // tabbedPane.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
    cp.add(tabbedPane, BorderLayout.CENTER);

    buildMenu();
  }