コード例 #1
1
ファイル: WPart11Dialog.java プロジェクト: timburrow/ovj3
  /**
   * Returns the value of the component
   *
   * @param nLineInd index of the line in the file.
   */
  protected String getValue(int nLineInd) {
    JComponent comp = null;
    String strValue = null;

    // Get the component corresponding to the line of the file from the list.
    if (nLineInd < m_aListComp.size()) {
      comp = (JComponent) m_aListComp.get(nLineInd);
    }

    if (comp == null) return strValue;

    // Get the value of the component
    if (comp instanceof JTextField) strValue = ((JTextField) comp).getText();
    else if (comp instanceof JCheckBox) strValue = ((JCheckBox) comp).isSelected() ? "yes" : "no";
    else if (comp instanceof JComboBox) strValue = (String) ((JComboBox) comp).getSelectedItem();

    // if the value is of the form: $home, then parse the value
    /*if (strValue.indexOf('$') >= 0)
    {
        String strNewValue = WFileUtil.parseValue(strValue, new HashMap());
        if (strNewValue != null && strNewValue.trim().length() > 0)
            strValue = strNewValue;
    }*/

    return strValue;
  }
コード例 #2
0
    protected void writeAuditTrail(String strPath, String strUser, StringBuffer sbValues) {
      BufferedReader reader = WFileUtil.openReadFile(strPath);
      String strLine;
      ArrayList aListData = WUtil.strToAList(sbValues.toString(), false, "\n");
      StringBuffer sbData = sbValues;
      String strPnl = (this instanceof DisplayTemplate) ? "Data Template " : "Data Dir ";
      if (reader == null) {
        Messages.postDebug("Error opening file " + strPath);
        return;
      }

      try {
        while ((strLine = reader.readLine()) != null) {
          // if the line in the file is not in the arraylist,
          // then that line has been deleted
          if (!aListData.contains(strLine))
            WUserUtil.writeAuditTrail(new Date(), strUser, "Deleted " + strPnl + strLine);

          // remove the lines that are also in the file or those which
          // have been deleted.
          aListData.remove(strLine);
        }

        // Traverse through the remaining new lines in the arraylist,
        // and write it to the audit trail
        for (int i = 0; i < aListData.size(); i++) {
          strLine = (String) aListData.get(i);
          WUserUtil.writeAuditTrail(new Date(), strUser, "Added " + strPnl + strLine);
        }
        reader.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
コード例 #3
0
    /** Returns the value in the proper format: "value". */
    protected String getValue(String strUser, String strValue) {

      ArrayList aListValues = WUtil.strToAList(strValue);
      String strNewValue = "";

      if (strValue == null || strValue.trim().length() <= 0) return "";

      String strPath =
          FileUtil.openPath("SYSPROF" + File.separator + strUser)
              + File.pathSeparator
              + FileUtil.openPath("USRPROF" + File.separator + strUser);
      HashMap hmUser = WFileUtil.getHashMap(strPath);

      for (int i = 0; i < aListValues.size(); i++) {
        strNewValue = (String) aListValues.get(i);
        if (strNewValue == null) strNewValue = "";

        // if the value is of the form: $home, then parse the value
        if (hmUser != null && strNewValue.indexOf('$') >= 0) {
          strValue = WFileUtil.parseValue(strNewValue, hmUser);
          if (strValue != null && strValue.trim().length() > 0) strNewValue = strValue;
        }
      }

      return strNewValue;
    }
コード例 #4
0
ファイル: WPart11Dialog.java プロジェクト: timburrow/ovj3
    protected void buildPanel(String strPath) {
      strPath = FileUtil.openPath(strPath);
      ArrayList aListPath = new ArrayList();
      BufferedReader reader = WFileUtil.openReadFile(strPath);
      if (reader == null) return;

      String strLine;
      try {
        while ((strLine = reader.readLine()) != null) {
          StringTokenizer strTok = new StringTokenizer(strLine, ":");
          if (strTok.countTokens() < 4) continue;

          boolean bChecksum = false;
          boolean bShow = false;

          String strDir = strTok.nextToken();
          String strChecksum = strTok.nextToken();

          if (strChecksum.equalsIgnoreCase("checksum")) bChecksum = true;

          if (bChecksum && (strDir.equals("file") || strDir.equals("dir"))) {
            String strValue = strTok.nextToken();
            String strShow = strTok.nextToken();
            if (strShow.equalsIgnoreCase("yes")) bShow = true;

            if (bShow) aListPath.add(strValue);
          }
        }

        m_cmbPath = new JComboBox(aListPath.toArray());

        JPanel pnlDisplay = new JPanel(new GridBagLayout());
        GridBagConstraints gbc =
            new GridBagConstraints(
                0,
                0,
                1,
                1,
                0.2,
                0.2,
                GridBagConstraints.NORTHWEST,
                GridBagConstraints.HORIZONTAL,
                new Insets(0, 0, 0, 0),
                0,
                0);
        pnlDisplay.add(m_cmbPath, gbc);
        gbc.gridx = 1;
        pnlDisplay.add(m_cmbChecksum, gbc);
        add(pnlDisplay, BorderLayout.NORTH);
        add(m_txaChecksum, BorderLayout.CENTER);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
コード例 #5
0
    protected void clear(JComponent comp) {
      int nCompCount = comp.getComponentCount();
      ArrayList aListComps = new ArrayList();

      for (int i = 0; i < comp.getComponentCount(); i++) {
        Component compChild = comp.getComponent(i);
        if (compChild instanceof JComponent) {
          JComponent jcomp = (JComponent) compChild;
          if (jcomp instanceof JCheckBox || jcomp instanceof JTextField) aListComps.add(comp);
          else clear(jcomp);
        }
      }
      clear(aListComps);
    }
コード例 #6
0
  /** When a new set of saved statements come in, refresh the menu of saved statements. */
  private void refreshSaveMenu() {
    ArrayList list;
    // first, delete what's already there
    for (; ; ) {
      Component comp = popup.getComponent(1);
      if (!(comp instanceof JMenuItem)) break;

      JMenuItem item = (JMenuItem) comp;
      if (item.getActionCommand().startsWith("save:")) popup.remove(1);
      else break;
    }
    StatementHistory history;
    history = sshare.statementHistory();
    // now insert the new list of saved statements
    list = history.getNamedStatementList();
    Color bgColor = Util.getBgColor();
    for (int i = 0; i < list.size(); i++) {
      ArrayList nameNlabel = (ArrayList) list.get(i);
      JMenuItem item = new JMenuItem("  " + (String) nameNlabel.get(1));
      item.setActionCommand("save:" + (String) nameNlabel.get(0));
      popup.add(item, 1);
      //	    item.setBackground(bgColor);
      item.addActionListener(popActionListener);
    }
  } // refreshSaveMenu()
コード例 #7
0
ファイル: WPart11Dialog.java プロジェクト: timburrow/ovj3
  /**
   * Creates the components based on the information in each line.
   *
   * @param sTokLine the tokens in a line.
   *     <p>The file is of the following format: auditDir:/vnmr/part11/auditTrails:system
   *     part11Dir:/vnmr/part11/data:system part11Dir:/vnmr/part11/data:system
   *     file:standard:cmdHistory:yes file:standard:fid:yes file:standard:procpar:yes
   *     file:standard:conpar:yes
   *     <p>Based on this format, the line is parsed as follows: 1) if the line starts with the
   *     keyword 'file', then it skips over the first two tokens in the line which are 'file' and
   *     'standard', and the third token in the line is the label of the item, and the fourth token
   *     in the line corresponds to the value of the checkbox. 2) if the line doesnot start with the
   *     keyword 'file', then the second and the fourth tokens are skipped, first token in the line
   *     is the label of the item, and the third token is the value of the textfield.
   */
  protected void createJComps(StringTokenizer sTokLine) {
    boolean bFile = false;
    boolean bMode = false;
    JComponent compValue = null;
    boolean bDir = false;

    for (int i = 0; sTokLine.hasMoreTokens(); i++) {
      String strTok = sTokLine.nextToken();
      if (i == 0) {
        bFile = strTok.equalsIgnoreCase("file") ? true : false;
        bMode = strTok.equalsIgnoreCase("dataType") ? true : false;
        bDir = false;
        if (strTok.equalsIgnoreCase("dir")) bDir = true;

        // Case 2, create a label for the first token.
        if (!bFile && !bDir) createLabel(strTok, m_pnlDisplay);
      } else {
        // Case 1 => file:standard:conpar:yes
        if (bFile) {
          // skip over the first tokenwhich is the keyword 'file'
          if (i == 1) continue;
          // else check for checkbox value.
          else if (strTok.equalsIgnoreCase("yes") || strTok.equalsIgnoreCase("no"))
            compValue = createChkBox(strTok, m_pnlDisplay);
          // else create a label.
          else createLabel(strTok, m_pnlDisplay);
        }
        // Case 2 => part11Dir:/vnmr/part11/data:system Or dataType:Non-FDA
        else if (!bDir) {
          if (i == 1) {
            // create a combobox
            if (bMode) compValue = createCombo(strTok, m_pnlDisplay);
            // create a textfield and sets it's value.
            else compValue = createTxf(strTok, m_pnlDisplay);
          }
        }
      }
    }
    m_aListComp.add(compValue);
  }
コード例 #8
0
ファイル: WPart11Dialog.java プロジェクト: timburrow/ovj3
  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);
    }
  }
コード例 #9
0
ファイル: ModelessDialog.java プロジェクト: timburrow/ovj3
  private void initUi() {
    String history;
    String undo;
    String close;
    String abandon;
    String help;
    String string;
    char helpMnemonic;
    char historyMnemonic;
    char undoMnemonic;
    char closeMnemonic;
    char abandonMnemonic;

    DisplayOptions.addChangeListener(this);

    // setAlwaysOnTop(true);

    // Get text for buttons from properties/resource file
    history = Util.getLabel("blHistory", "Edit...");
    undo = Util.getLabel("blUndo", "Undo");
    close = Util.getLabel("blClose", "Close");
    abandon = Util.getLabel("blAbandon", "Abandon");
    help = Util.getLabel("blHelp", "Help");

    // buttons
    undoButton = new JButton(undo);
    closeButton = new JButton(close);
    abandonButton = new JButton(abandon);
    helpButton = new JButton(help);

    // Create an ArrayList of menu items from properties file

    ArrayList<String> historyList = new ArrayList<String>();
    historyList.add(Util.getLabel("mlHistReturnInitState", "Return to initial state"));
    historyList.add(Util.getLabel("mlHistMakeSnapshot", "Make a snapshot"));
    historyList.add(Util.getLabel("mlHistReturnToSnapshot", "Return to snapshot"));
    historyList.add(Util.getLabel("mlHistReturnToDefault", "Return to system defaults"));

    // Pop Button for history menu
    historyButton = new MPopButton(historyList);
    historyButton.setText(history);

    // Only set mnemonics if found.

    if (Util.labelExists("blmHelp")) {
      string = Util.getLabel("blmHelp");
      helpMnemonic = string.charAt(0);
      helpButton.setMnemonic(helpMnemonic);
    }

    if (Util.labelExists("blmUndo")) {
      string = Util.getLabel("blmUndo");
      undoMnemonic = string.charAt(0);
      undoButton.setMnemonic(undoMnemonic);
    }

    if (Util.labelExists("blmAbandon")) {
      string = Util.getLabel("blmAbandon");
      abandonMnemonic = string.charAt(0);
      abandonButton.setMnemonic(abandonMnemonic);
    }

    if (Util.labelExists("blmClose")) {
      string = Util.getLabel("blmClose");
      closeMnemonic = string.charAt(0);
      closeButton.setMnemonic(closeMnemonic);
    }

    if (Util.labelExists("blmHistory")) {
      string = Util.getLabel("blmHistory");
      historyMnemonic = string.charAt(0);
      historyButton.setMnemonic(historyMnemonic);
    }

    helpButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            // Display Help if help file exists
            CSH_Util.displayCSHelp(dialogTitle);
          }
        });

    // Make a panel to hold the buttons
    buttonPane = new JPanel();

    // Put an empty border around the inside of the panel.
    buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 5, 10, 5));
    buttonPane.setLayout(new SimpleH2Layout(SimpleH2Layout.CENTER));

    // Add the buttons to the panel with space between buttons.
    buttonPane.add(historyButton);
    // buttonPane.add(Box.createRigidArea(new Dimension(5, 0)));
    buttonPane.add(undoButton);
    // buttonPane.add(Box.createRigidArea(new Dimension(5, 0)));
    buttonPane.add(closeButton);
    // buttonPane.add(Box.createRigidArea(new Dimension(5, 0)));
    buttonPane.add(abandonButton);
    // buttonPane.add(Box.createRigidArea(new Dimension(5, 0)));
    buttonPane.add(helpButton);

    // Put everything together, using the content pane's BorderLayout.
    Container contentPane = getContentPane();
    contentPane.add(buttonPane, BorderLayout.SOUTH);

    setHistoryEnabled(false);
    // setCloseEnabled(false);
    setAbandonEnabled(false);
    setUndoEnabled(false);

    if (!CSH_Util.haveTopic(dialogTitle)) setHelpEnabled(false);

    // buttonPane.setVisible(false);
    // Add key listener to the whole dialog
    addKeyListener(this);
    // Make the frame fit its contents.
    // pack(); // nothing to pack.
  }
コード例 #10
0
  public void fillPopupMenu() {
    JMenuItem item;
    TextImageIcon textIcon;
    StatementHistory history;
    int rowCount = 0;
    int numRows = 0;
    Insets margin = new Insets(0, 0, 0, 0);

    // Get the font defined in the displayOptions panel for menus
    Font ft = DisplayOptions.getFont("Menu1");
    // We need a fairly small font, so make it 2 smaller.
    int size = ft.getSize();
    // If larger than 12, subtract 2
    if (size > 12) size -= 2;
    Font font = DisplayOptions.getFont(ft.getName(), ft.getStyle(), size);

    // This flag is used so that we only fill the menu when needed
    if (menuAlreadyFilled) return;

    menuAlreadyFilled = true;

    history = sshare.statementHistory();

    ArrayList list = history.getNamedStatementList();
    Color bgColor = Util.getBgColor();
    // Only show the Saved Statements section if there are some.
    if (list != null && list.size() != 0) {
      item = popup.add("Saved Statements");
      rowCount++;
      //	    item.setForeground(Color.blue);
      //	    item.setBackground(bgColor);
      item.setFont(font);
      item.setMargin(margin);
      popup.add(item);

      for (int i = 0; i < list.size(); i++) {
        ArrayList nameNlabel = (ArrayList) list.get(i);
        // first item in nameNlabel is name and second is label
        item = popup.add("  " + (String) nameNlabel.get(1));
        rowCount++;
        item.setActionCommand("save:" + (String) nameNlabel.get(0));
        //		item.setBackground(bgColor);
        item.addActionListener(popActionListener);
        item.setFont(font);
        item.setMargin(margin);
      }
    }
    // the rest of menu (return object types, statement types, etc.)
    ShufflerService shufflerService = sshare.shufflerService();
    ArrayList objTypes = shufflerService.getAllMenuObjectTypes();

    for (int i = 0; i < objTypes.size(); i++) {
      String objType = (String) objTypes.get(i);

      // Do not display menu for DB_AVAIL_SUB_TYPES
      if (objType.equals(Shuf.DB_AVAIL_SUB_TYPES)) continue;

      // addSeparator looks bad using GridLayout because it creates rows
      // and columns which are all equal in size.  It cannot have a row
      // with a separator which is a different height than the other
      // rectangles it creates. So just use dashes.
      item = popup.add(separator);
      item.setFont(font);
      item.setMargin(margin);
      rowCount++;
      item = popup.add(shufflerService.getCategoryLabel(objType));
      rowCount++;
      //	    item.setForeground(Color.blue);
      item.setActionCommand("title:" + objType);
      //	    item.setBackground(bgColor);
      item.addActionListener(popActionListener);
      item.setFont(font);
      item.setMargin(margin);

      ArrayList menuStrings = shufflerService.getmenuStringsThisObj(objType);

      // If current rowCount plus the next section size is too big,
      // specify the numRows to the current value of rowCount -1.
      // That is, put this next section in a new column.
      // 47 is emperical number of rows to fit 90% full screen.
      if (numRows == 0 && rowCount - 1 + menuStrings.size() > 44) {

        numRows = rowCount - 2;
      }

      for (int j = 0; j < menuStrings.size(); j++) {
        String menuString = (String) menuStrings.get(j);
        item = popup.add("  " + menuString);
        rowCount++;
        item.setActionCommand("command:" + objType + "/" + menuString);
        //		item.setBackground(bgColor);
        item.addActionListener(popActionListener);
        item.setFont(font);
        item.setMargin(margin);
      }
      // The spotter menu changes dynamically when
      // the list of saved statements changes.
      history.addStatementListener(
          new StatementAdapter() {
            public void saveListChanged() {
              refreshSaveMenu();
            }
          });
    }

    if (numRows == 0) numRows = rowCount;

    GridLayoutCol lm = new GridLayoutCol(numRows, 0);
    popup.setLayout(lm);
  }
コード例 #11
0
 public void clearValueArray() {
   m_aListTxfValue.clear();
 }
コード例 #12
0
 public void clearArrays() {
   m_aListTxfLabel.clear();
   m_aListTxfValue.clear();
 }
コード例 #13
0
 public void addToValue(DataField txf) {
   m_aListTxfValue.add(txf);
 }
コード例 #14
0
 public void addToLabel(DataField txf) {
   m_aListTxfLabel.add(txf);
 }
コード例 #15
0
 protected void clear(ArrayList aListComps) {
   for (int i = 0; i < aListComps.size(); i++) {
     JComponent comp = (JComponent) aListComps.get(i);
     comp.removeAll();
   }
 }
コード例 #16
0
 public void clearLabelArray() {
   m_aListTxfLabel.clear();
 }
コード例 #17
0
    /**
     * 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);
      }
    }