Example #1
0
  public void buildPanel() {
    String path = FileUtil.getLayoutPath(layoutDir, fname);
    if (path == null) {
      Messages.postError("Could not open xml file:" + fname);
      return;
    }
    removeAll();
    try {
      LayoutBuilder.build(pane, vnmrIf, path);
    } catch (Exception e) {
      String strError = "Error building file: " + path;
      Messages.postError(strError);
      Messages.writeStackTrace(e);
      return;
    }

    if (bScrollBar) {
      spane =
          new JScrollPane(
              pane,
              JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
              JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
      add(spane);
    } else {
      spane = null;
      add(pane);
    }
    paramsLayout.preferredLayoutSize(pane);
  }
Example #2
0
  /** Write file with position and size of the login box */
  public static void writePersistence() {

    Messages.postDebug("LoginBox", "LoginBox.writePersistence");
    // If the panel has not been created, don't try to write a file
    if (position == null) return;

    String filepath = FileUtil.savePath("USER/PERSISTENCE/LoginPanel");

    FileWriter fw;
    PrintWriter os;
    try {
      File file = new File(filepath);
      fw = new FileWriter(file);
      os = new PrintWriter(fw);
      os.println("Login Panel");

      os.println(height);
      os.println(width);
      double xd = position.getX();
      int xi = (int) xd;
      os.println(xi);
      double yd = position.getY();
      int yi = (int) yd;
      os.println(yi);

      os.close();
    } catch (Exception er) {
      Messages.postError("Problem creating  " + filepath);
      Messages.writeStackTrace(er);
    }
  }
Example #3
0
 private boolean readPersistence(boolean sysFlag) {
   String path = getPersistenceFilePath(sysFlag);
   boolean ok = readPersistence(path);
   if (!ok && sysFlag) {
     Messages.postError("Cannot read persistence file: " + path);
   }
   return ok;
 }
Example #4
0
  private void addTool(String key, Class tool) {
    Class[] constructArgs = null;
    if (key.equals("XMLToolPanel")) {
      constructArgs = new Class[3];
      constructArgs[0] = vnmr.ui.SessionShare.class;
      constructArgs[1] = String.class;
      constructArgs[2] = String.class;
    } else {
      constructArgs = new Class[1];
      constructArgs[0] = vnmr.ui.SessionShare.class;
    }

    try {
      Constructor c = tool.getConstructor(constructArgs);
      vobjs.put(key, c);
    } catch (NoSuchMethodException nse) {
      Messages.postError("Problem initiating " + key + " area.");
      Messages.writeStackTrace(nse, tool + " not found.");
    } catch (SecurityException se) {
      Messages.postError("Problem initiating " + key + " area.");
      Messages.writeStackTrace(se);
    }
  }
Example #5
0
  public void buildConfig() {
    BufferedReader in = WFileUtil.openReadFile(m_strPath);
    String strLine = null;

    if (in == null) {
      Messages.postError("Error opening file " + m_strPath);
      return;
    }

    try {
      m_pnlDisplay.removeAll();
      m_pnlDisplay.setLayout(new WGridLayout(0, 2));
      m_aListComp.clear();
      while ((strLine = in.readLine()) != null) {
        if (strLine.startsWith("#") || strLine.startsWith("%") || strLine.startsWith("@")) continue;
        StringTokenizer sTokLine = new StringTokenizer(strLine, File.pathSeparator);
        createJComps(sTokLine);
      }
      setVisible(true);
    } catch (Exception e) {
      // e.printStackTrace();
      Messages.writeStackTrace(e);
    }
  }
Example #6
0
  public boolean readPersistence(String path) {
    BufferedReader input = TuneUtilities.getReader(path);

    String line = null;
    boolean rtn = true;
    try {
      while ((line = input.readLine()) != null) {
        StringTokenizer toker = new StringTokenizer(line);
        if (toker.hasMoreTokens()) {
          String key = toker.nextToken().toLowerCase();
          if (key.equals("backlash")) {
            double backlash = Double.parseDouble(toker.nextToken());
            // backlash = Math.max(MIN_BACKLASH, backlash);/*CMP*/
            // backlash = Math.min(MAX_BACKLASH, backlash);/*CMP*/
            setBacklash(backlash);
            m_backlashGroup.clear();
            while (toker.hasMoreTokens()) {
              m_backlashGroup.add(new Integer(toker.nextToken()));
            }
          } else if (key.equals("backlashlimits")) {
            m_maxBacklash = Double.parseDouble(toker.nextToken());
            if (toker.hasMoreTokens()) {
              m_minBacklash = Double.parseDouble(toker.nextToken());
            }
          } else if (key.equals("steps/rev")) {
            m_stepsPerRev = Integer.parseInt(toker.nextToken());
          } else if (key.equals("limit")) {
            m_minLimit = Integer.parseInt(toker.nextToken());
            if (toker.hasMoreTokens()) {
              m_maxLimit = Integer.parseInt(toker.nextToken());
            }

          } else if (key.equals("odom")) {
            m_odometerCW = Long.parseLong(toker.nextToken());
            m_odometerCCW = Long.parseLong(toker.nextToken());

          } else if (key.equals("mincalstep")) {
            m_minCalStep = Integer.valueOf(toker.nextToken());
          } else if (key.equals("indexdirection")) {
            int dir = Integer.parseInt(toker.nextToken());
            m_indexDirection = dir > 0 ? 1 : -1;
          } else if (key.equals("indexdistance")) {
            m_indexDistance = Integer.parseInt(toker.nextToken());
          } else if (key.equals("reqswversion")) {
            // Verify version of software and persistence file
            m_minSWVersion = toker.nextToken();
            if (!ProbeTune.isSwVersionAtLeast(m_minSWVersion)) {
              String msg =
                  "Require software version "
                      + m_minSWVersion
                      + "<br>"
                      + " to operate on the file "
                      + path;
              Messages.postError(msg);
              String title = "Incompatible_Motor_File";
              m_master.sendToGui("popup error title " + title + " msg " + msg);
            }
          }
        }
      }
    } catch (NumberFormatException nfe) {
      Messages.postError("Bad number in persistence file: " + path + ", line: \"" + line + "\"");
      rtn = false;
    } catch (NoSuchElementException nsee) {
      Messages.postError("Bad line in persistence file: " + path + ", line: \"" + line + "\"");
      rtn = false;
    } catch (Exception e) {
      rtn = false;
    } finally {
      try {
        input.close();
      } catch (Exception e) {
      }
    }
    return rtn;
  }
    /**
     * Write the file by writing the values from the labels, and the values list.
     *
     * @param strFile the file to be written.
     * @param aListLabels arraylist of texfields of labels.
     * @param aListValues arraylist of texfields of values.
     */
    protected void writeFile(
        String strUser, String strFile, ArrayList aListLabels, ArrayList aListValues) {
      String strPath = FileUtil.openPath(strFile);
      String strLabel = "";
      String strValue = "";
      StringBuffer sbValues = new StringBuffer();
      JTextField txfLabel = null;
      JTextField txfValue = null;
      boolean bNewFile = false;
      int nFDAMode = Util.getPart11Mode();

      // if it's the part11 pnl and the mode is nonFDA,
      // then don't write the file for this panel
      // the other way is not true.
      if (this instanceof DisplayParentDirectory) {
        if ((isPart11Pnl() && nFDAMode == Util.NONFDA)) {
          return;
        }
      }

      if (strPath == null) {
        strPath = FileUtil.savePath(strFile);
        bNewFile = true;
      }

      if (strPath == null || aListLabels == null) return;

      if (aListValues == null) aListValues = new ArrayList();

      // Get the list of the textfields for values and labels.
      int nLblSize = aListLabels.size();
      int nValueSize = aListValues.size();
      ArrayList<String> labelList = new ArrayList<String>();

      // Get the value from each textfield, and add it to the buffer.
      for (int i = 0; i < nLblSize; i++) {
        txfLabel = (JTextField) aListLabels.get(i);
        txfValue = (i < nValueSize) ? (JTextField) aListValues.get(i) : null;

        strLabel = (txfLabel != null) ? txfLabel.getText() : null;
        strValue = (txfValue != null) ? txfValue.getText() : "";

        // We need to be sure they don't have two data directories with
        // the same labels.  Save the label list if we are writing to
        // the "data" file.
        if (strFile.indexOf("data") != -1) {
          if (labelList.contains(strLabel)) {
            Messages.postError(
                "The Data Directory specifications "
                    + "must not have duplicate Label names. "
                    + "The Label \""
                    + strLabel
                    + "\" is duplicated.  "
                    + "Skipping the second instance.  Please "
                    + "specify a new Label.");
            continue;
          } else labelList.add(strLabel);
        }

        if (strLabel == null || strLabel.trim().length() <= 0 || strValue.equals(INFOSTR)) continue;

        // for user template tab, don't need to parse the value
        if (!(this instanceof DisplayTemplate)) strValue = getValue(strUser, strValue);
        strLabel = strLabel.trim();
        if (strValue != null) strValue = strValue.trim();

        // sbValues.append("\"");
        sbValues.append(strLabel);
        // sbValues.append("\"  ");

        sbValues.append(File.pathSeparator);
        sbValues.append(strValue);
        sbValues.append("\n");
      }

      if (Util.isPart11Sys()) writeAuditTrail(strPath, strUser, sbValues);

      // write the data to the file.
      BufferedWriter writer = WFileUtil.openWriteFile(strPath);
      WFileUtil.writeAndClose(writer, sbValues);

      // if it's a template file, then make it writable for everyone.
      if (bNewFile) {
        String strCmd = "chmod 755 ";
        if (this instanceof DisplayTemplate) strCmd = "chmod 777 ";
        if (Util.iswindows()) strPath = UtilB.windowsPathToUnix(strPath);
        String[] cmd = {WGlobal.SHTOOLCMD, WGlobal.SHTOOLOPTION, strCmd + strPath};
        WUtil.runScriptInThread(cmd);
      }
    }