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(); } }
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); }
/** * 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); }
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. }
public void addToValue(DataField txf) { m_aListTxfValue.add(txf); }
public void addToLabel(DataField txf) { m_aListTxfLabel.add(txf); }
/** * 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); } }