Beispiel #1
0
  public boolean executeFilter(@NotNull Editor editor, @NotNull TextRange range, String command)
      throws IOException {
    if (logger.isDebugEnabled()) logger.debug("command=" + command);
    CharSequence chars = editor.getDocument().getCharsSequence();
    StringReader car =
        new StringReader(
            chars.subSequence(range.getStartOffset(), range.getEndOffset()).toString());
    StringWriter sw = new StringWriter();

    logger.debug("about to create filter");
    Process filter = Runtime.getRuntime().exec(command);
    logger.debug("filter created");
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(filter.getOutputStream()));
    logger.debug("sending text");
    copy(car, writer);
    writer.close();
    logger.debug("sent");

    BufferedReader reader = new BufferedReader(new InputStreamReader(filter.getInputStream()));
    logger.debug("getting result");
    copy(reader, sw);
    sw.close();
    logger.debug("received");

    editor.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), sw.toString());

    lastCommand = command;

    return true;
  }
Beispiel #2
0
 public void save(int i) {
   BufferedWriter brw = null;
   TextDocument ta = (TextDocument) td.getComponentAt(i);
   try {
     File file = null;
     if (ta.file == null) { // 判斷是否為新黨案,是的話使用預設路徑儲存
       file = new File(default_auto_save_path + "\\" + ta.fileName);
     } else {
       file = ta.file; // 儲存於原檔案
     }
     brw = new BufferedWriter(new FileWriter(file));
     ta.write(brw);
     ta.save = true;
     td.setTitleAt(i, ta.fileName); // 更新標題名稱
   } catch (FileNotFoundException ffe) { // 若預設路徑不存在,則跳出警告
     JOptionPane.showMessageDialog(
         null,
         ta.fileName + "儲存失敗!\n請檢查Default AutoSave-Path是否存在,或是權限不足.",
         "Save error",
         JOptionPane.ERROR_MESSAGE);
   } catch (Exception exc) {
     exc.printStackTrace();
   } finally {
     try {
       brw.close();
     } catch (Exception exc) {
     }
   }
 }
Beispiel #3
0
 private void saveTab(String toSave, File f) {
   boolean ok = false;
   BufferedWriter out = null;
   try {
     ok = f.createNewFile();
   } catch (IOException e) {
     e.printStackTrace();
   }
   if (ok) {
     try {
       out = new BufferedWriter(new FileWriter(f));
       out.write(toSave);
     } catch (IOException e1) {
       e1.printStackTrace();
     } finally {
       try {
         out.close();
       } catch (IOException e2) {
         e2.printStackTrace();
       }
     }
   } else {
     System.out.println("Couldnt create file...");
   }
   // }
 }
 public void saveWords() {
   // Preconditions: word object array is initialized.
   // Postconditions: TEXT_FILE is updated.
   // Saves all the words in the existing array into the text file using UTF8 encoding.
   try {
     // Writes to the text file of the word list.
     BufferedWriter out =
         new BufferedWriter(new OutputStreamWriter(new FileOutputStream(TEXT_FILE), "UTF8"));
     // Goes through the array of words;
     for (int i = 0; i < wordIndex; i++) {
       String str; // Line that gets saved into the text file.
       // instance variables separated by the ":" character.
       str =
           words[i].getCharacters()
               + ":"
               + words[i].getDefinition()
               + ":"
               + words[i].getPinYin()
               + ":"
               + words[i].getType()
               + ":"
               + words[i].isMemorized().toString()
               + "\n";
       out.write(str);
     }
     out.close();
   } catch (FileNotFoundException e) {
     System.err.println("Not found");
   } catch (java.io.IOException e) {
     System.err.println("IO Exception");
   }
 }
Beispiel #5
0
 private void setFileText(File file, String text) throws Exception {
   BufferedWriter bw =
       new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
   bw.write(text, 0, text.length());
   bw.flush();
   bw.close();
 }
Beispiel #6
0
  public void save() {
    BufferedWriter sourceFile = null;

    try {
      String sourceText = sourceArea.getText();

      String cleanText = cleanupSource(sourceText);

      if (cleanText.length() != sourceText.length()) {
        sourceArea.setText(cleanText);

        String message =
            String.format(
                "One or more invalid characters at the end of the source file have been removed.");
        JOptionPane.showMessageDialog(this, message, "ROPE", JOptionPane.INFORMATION_MESSAGE);
      }

      sourceFile = new BufferedWriter(new FileWriter(sourcePath, false));
      sourceFile.write(cleanText);

      setSourceChanged(false);

      setupMenus();
    } catch (IOException ex) {
      ex.printStackTrace();
    } finally {
      if (sourceFile != null) {
        try {
          sourceFile.close();
        } catch (IOException ignore) {
        }
      }
    }
  }
Beispiel #7
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (td.getTabCount() > 0) {
     JFileChooser f = new JFileChooser();
     f.setFileFilter(new MyFileFilter());
     int choose = f.showSaveDialog(getContentPane());
     if (choose == JFileChooser.APPROVE_OPTION) {
       BufferedWriter brw = null;
       try {
         File file = f.getSelectedFile();
         brw = new BufferedWriter(new FileWriter(file));
         int i = td.getSelectedIndex();
         TextDocument ta = (TextDocument) td.getComponentAt(i);
         ta.write(brw);
         ta.fileName = file.getName(); // 將檔案名稱更新為存檔的名稱
         td.setTitleAt(td.getSelectedIndex(), ta.fileName);
         ta.file = file;
         ta.save = true; // 設定已儲存
         System.out.println("Save as pass!");
         td.setTitleAt(i, ta.fileName); // 更新標題名稱
       } catch (Exception exc) {
         exc.printStackTrace();
       } finally {
         try {
           brw.close();
         } catch (Exception ecx) {
           ecx.printStackTrace();
         }
       }
     }
   } else {
     JOptionPane.showMessageDialog(null, "沒有檔案可以儲存!");
   }
 }
  public void write(OutputStream os) throws Exception {
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));

    String str = toString();
    bw.write(str, 0, str.length());
    bw.newLine();
    bw.close();
  }
Beispiel #9
0
    public static Settings init() throws Exception {
      File f = new File("galaxyviewer.ini");
      if (f.getAbsoluteFile().getParentFile().getName().equals("bin"))
        f = new File("..", "galaxyviewer.ini");
      Settings settings;
      if (f.exists()) {
        settings = new Settings();
        BufferedReader in = new BufferedReader(new FileReader(f));
        while (true) {
          String s = in.readLine();
          if (s == null) break;
          if (s.contains("=") == false) continue;
          String[] el = s.split("=", -1);
          if (el[0].equalsIgnoreCase("PlayerNr"))
            settings.playerNr = Integer.parseInt(el[1].trim()) - 1;
          if (el[0].equalsIgnoreCase("GameName")) settings.gameName = el[1].trim();
          if (el[0].equalsIgnoreCase("GameDir")) settings.directory = el[1].trim();
        }
        in.close();
      } else settings = new Settings();

      JTextField pNr = new JTextField("" + (settings.playerNr + 1));
      JTextField gName = new JTextField(settings.gameName);
      JTextField dir = new JTextField("" + settings.directory);

      JPanel p = new JPanel();
      p.setLayout(new GridLayout(3, 2));
      p.add(new JLabel("Player nr"));
      p.add(pNr);
      p.add(new JLabel("Game name"));
      p.add(gName);
      p.add(new JLabel("Game directory"));
      p.add(dir);
      gName.setToolTipText("Do not include file extensions");
      String[] el = {"Ok", "Cancel"};
      int ok =
          JOptionPane.showOptionDialog(
              null,
              p,
              "Choose settings",
              JOptionPane.OK_CANCEL_OPTION,
              JOptionPane.QUESTION_MESSAGE,
              null,
              el,
              el[0]);
      if (ok != 0) System.exit(0);
      settings.playerNr = Integer.parseInt(pNr.getText().trim()) - 1;
      settings.directory = dir.getText().trim();
      settings.gameName = gName.getText().trim();
      BufferedWriter out = new BufferedWriter(new FileWriter(f));
      out.write("PlayerNr=" + (settings.playerNr + 1) + "\n");
      out.write("GameName=" + settings.gameName + "\n");
      out.write("GameDir=" + settings.directory + "\n");
      out.flush();
      out.close();
      return settings;
    }
Beispiel #10
0
 /**
  * When exiting the game, save the best score to the record file.
  *
  * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
  */
 @Override
 public void windowClosing(WindowEvent arg0) {
   try {
     recordWriter = new BufferedWriter(new FileWriter("res/record"));
     recordWriter.write(String.valueOf(bestScore));
     recordWriter.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Beispiel #11
0
 private void write(String msg) {
   SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
   try {
     BufferedWriter bw = new BufferedWriter(new FileWriter(filePath, true));
     bw.write("[" + formatter.format(new java.util.Date()) + "] " + msg);
     bw.newLine();
     bw.close();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
 // ------------------------------------
 // Send RTSP Response
 // ------------------------------------
 private void send_RTSP_response() {
   try {
     RTSPBufferedWriter.write("RTSP/1.0 200 OK" + CRLF);
     RTSPBufferedWriter.write("CSeq: " + RTSPSeqNb + CRLF);
     RTSPBufferedWriter.write("Session: " + RTSP_ID + CRLF);
     RTSPBufferedWriter.flush();
     // System.out.println("RTSP Server - Sent response to Client.");
   } catch (Exception ex) {
     System.out.println("Exception caught: " + ex);
     System.exit(0);
   }
 }
Beispiel #13
0
 /**
  * Writes the error model into the options file so that they can be read by the generator at a
  * later time
  */
 public void storeModelPreference(String model) {
   try {
     FileWriter x = new FileWriter("options", true);
     BufferedWriter optionWriter = new BufferedWriter(x);
     String data = "<IpErrorModel> " + model + " </IpErrorModel>\n";
     optionWriter.write(data, 0, data.length());
     optionWriter.flush();
     optionWriter.close();
   } catch (Exception e) {
     System.out.println("Error while writing to options file in ipModelsMenu.java");
   }
 }
  private void saveFile(File file) {
    try {
      BufferedWriter writer = new BufferedWriter(new FileWriter(file));

      for (QuizCard card : cardList) {
        writer.write(card.getQuestion() + "/");
        writer.write(card.getAnswer() + "/n");
      }
    } catch (IOException ex) {
      System.out.println("Couldn't wirite the cardList out");
      ex.printStackTrace();
    }
  }
Beispiel #15
0
    public void actionPerformed(ActionEvent ae) {

      if (ae.getActionCommand().equals("clear")) {
        scriptArea.setText("");
      } else if (ae.getActionCommand().equals("save")) {
        // fc.setCurrentDirectory(new File("/Users/jc/Documents/LOGO"));
        int bandera = fileChooser.showSaveDialog(myWindow);
        if (bandera == JFileChooser.APPROVE_OPTION) {
          String cadena1 = scriptArea.getText();
          String cadena2 = cadena1.replace("\r", "\n");
          System.out.println(cadena1);
          try {
            BufferedWriter script =
                new BufferedWriter(new FileWriter(fileChooser.getSelectedFile() + ".txt"));
            script.write(cadena2);
            script.close();
          } catch (Exception ex) {
            ex.printStackTrace();
          }
          File file = fileChooser.getSelectedFile();
          JOptionPane.showMessageDialog(myWindow, "File: " + file.getName() + " Saved.\n");
        }
        scriptArea.setCaretPosition(scriptArea.getDocument().getLength());
      } else if (ae.getActionCommand().equals("quit")) {
        myWindow.setVisible(false);
      } else if (ae.getActionCommand().equals("load")) {
        // String arreglo[] = new String[100];
        // int i = 0;
        // fc.setCurrentDirectory(new File("/Users/jc/Documents/LOGO"));
        int bandera = fileChooser.showOpenDialog(myWindow);
        if (bandera == JFileChooser.APPROVE_OPTION) {
          try {
            BufferedReader script =
                new BufferedReader(new FileReader(fileChooser.getSelectedFile()));
            scriptArea.read(script, null);
            script.close();
            scriptArea.requestFocus();
          } catch (Exception ex) {
            ex.printStackTrace();
          }
          File file = fileChooser.getSelectedFile();
          myWindow.setTitle(file.getName());
          JOptionPane.showMessageDialog(myWindow, file.getName() + ": File loaded.\n");
          scriptArea.setCaretPosition(scriptArea.getDocument().getLength());
        }
      } else if (ae.getActionCommand().equals("run")) {
        System.out.println("LEL");
      }
    }
Beispiel #16
0
 // Ende des Dokuments
 public void endDocument() {
   try {
     f.close();
   } catch (IOException e) {
     EfaUtil.foo();
   }
 }
Beispiel #17
0
 // Anfang des Dokuments
 public void startDocument() {
   try {
     f.write("<?xml version=\"1.0\" encoding=\"" + Daten.ENCODING_UTF + "\"?>\n");
   } catch (IOException e) {
     EfaUtil.foo();
   }
 }
Beispiel #18
0
 public void save(String s, File f) {
   try {
     int saveNumber = 1;
     File file = new File(f.getAbsolutePath() + "/save.adv");
     while (file.exists()) {
       file = new File(f.getAbsolutePath() + "/save" + saveNumber + ".adv");
       saveNumber++;
     }
     file.createNewFile();
     FileWriter fWriter = new FileWriter(file.getAbsoluteFile());
     BufferedWriter bWriter = new BufferedWriter(fWriter);
     bWriter.write(s);
     bWriter.close();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Beispiel #19
0
 // Text innerhalb von Elementen
 public void characters(char[] ch, int start, int length) {
   if (skip) return;
   try {
     String s = new String(ch, start, length);
     if (s.indexOf('\n') >= 0 || s.indexOf(10) >= 0 || s.indexOf(13) >= 0) s = s.trim();
     if (s.length() > 0) f.write(s);
   } catch (IOException e) {
   }
 }
Beispiel #20
0
  public void ecrireFichier(String chemin, Vector<Integer> highScore) {
    try {
      FileWriter fw = new FileWriter(chemin, false);

      BufferedWriter output = new BufferedWriter(fw);

      for (int i = 0; i < highScore.size(); i++) {
        output.write(highScore.get(i).toString());
        output.newLine();
      }

      output.flush();

      output.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Beispiel #21
0
  public void saveAs() {
    Vector<RopeFileFilter> filters = new Vector<RopeFileFilter>();

    if (fileExt.equals("m") || fileExt.equals("mac")) {
      filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)"));
      filters.add(
          new RopeFileFilter(
              new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)"));
    } else {
      filters.add(
          new RopeFileFilter(
              new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)"));
      filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)"));
    }
    filters.add(new RopeFileFilter(new String[] {".txt"}, "Text files (*.txt)"));

    RopeFileChooser chooser = new RopeFileChooser(selectedPath, null, filters);
    chooser.setDialogTitle("Save Source File");
    String fileName = String.format("%s.%s", baseName, fileExt);
    chooser.setSelectedFile(new File(selectedPath, fileName));
    JTextField field = chooser.getTextField();
    field.setSelectionStart(0);
    field.setSelectionEnd(baseName.length());
    File file = chooser.save(ROPE.mainFrame);
    if (file != null) {
      selectedPath = file.getParent();

      BufferedWriter writer = null;
      try {
        writer = new BufferedWriter(new FileWriter(file));
        writer.write(sourceArea.getText());
      } catch (IOException ex) {
        ex.printStackTrace();
      } finally {
        try {
          if (writer != null) {
            writer.close();
          }
        } catch (IOException ex) {
          ex.printStackTrace();
        }
      }
    }
  }
Beispiel #22
0
    public void run() {
      try {
        BufferedReader br =
            new BufferedReader(new InputStreamReader(new FileInputStream(file), charset));
        if (outputFile != null) {
          bw =
              new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), charset));
        }
        String line;
        while ((line = br.readLine()) != null) {
          filePosition += line.length() + 2;
          line = line.trim();
          if (!line.startsWith("#")) {
            String[] sides = split(line);
            if ((sides != null) && !sides[0].equals("key")) {

              if (searchPHI) {
                // Search the decrypted PHI for the searchText
                sides[0] = decrypt(sides[0]);
                if (sides[0].indexOf(searchText) != -1) {
                  output(sides[0] + " = " + sides[1] + "\n");
                }
              } else {
                // Search the trial ID for the searchText
                if (sides[1].indexOf(searchText) != -1) {
                  sides[0] = decrypt(sides[0]);
                  output(sides[0] + " = " + sides[1] + "\n");
                }
              }
            }
          }
        }
        br.close();
        if (bw != null) {
          bw.flush();
          bw.close();
        }
      } catch (Exception e) {
        append("\n\n" + e.getClass().getName() + ": " + e.getMessage() + "\n");
      }
      append("\nDone.\n");
      setMessage("Ready...");
    }
Beispiel #23
0
    private void output(String string) throws Exception {
      if (bw != null) bw.write(string);
      else append(string);

      // Set the fraction done.
      long pct = (filePosition * 100) / fileLength;
      if (pct != percentDone) {
        percentDone = pct;
        setMessage("Working... (" + pct + "%)");
      }
    }
Beispiel #24
0
  // Ende eines Elements
  public void endElement(String uri, String localName, String qname) {
    try {
      if (uri.equals("http://www.nmichael.de/elwiz")) { // elwiz-Element
        if (option != null && option.name.equals(localName)) option = null;
        skip = false;
      } else { // Normales Element
        if (skip) return;

        f.write("</" + qname + ">");
      }
    } catch (IOException e) {
    }
  }
Beispiel #25
0
  public synchronized void runSuite() {
    SikuliIDE ide = SikuliIDE.getInstance();
    if (fRunner != null) {
      fTestResult.stop();
      showIDE(true);
    } else {
      try {
        showIDE(false);
        reset();

        // get the current file's python code, write it to a temp file, and run it
        File tmpFile = null;
        String className = null;
        SikuliCodePane codePane = ide.getCurrentCodePane();
        try {
          className = new File(ide.getCurrentFilename()).getName();
          className = className.substring(0, className.lastIndexOf('.')); // remove extension
          tmpFile = File.createTempFile(className, ".py");
          tmpFile.deleteOnExit();
          BufferedWriter bw =
              new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tmpFile), "UTF8"));
          codePane.writePython(bw);
          bw.close();
        } catch (IOException e) {
          e.printStackTrace();
          showIDE(true);
        }
        String filename = tmpFile.getAbsolutePath();

        String path = ide.getCurrentBundlePath();
        Test suite = genTestSuite(className, filename, path);
        doRun(suite);
      } catch (IOException e) {
        e.printStackTrace();
        showIDE(true);
      }
    }
  }
Beispiel #26
0
  // Beginn eines Element-Tags
  public void startElement(String uri, String localName, String qname, Attributes atts) {
    try {
      if (uri.equals("http://www.nmichael.de/elwiz")) {

        // Elemente des elwiz-Namensraums

        if (!localName.equals("option")) { // Hauptelement
          // Namen ermitteln
          String name = null;
          for (int i = 0; i < atts.getLength(); i++)
            if (atts.getLocalName(i).equals("name")) name = atts.getValue(i);

          // Element suchen
          for (int i = 0; i < options.size(); i++)
            if (((ElwizOption) options.get(i)).name.equals(name)) {
              this.option = (ElwizOption) options.get(i);
              break;
            }

        } else { // Unterelement

          // Position des Unterelements für Zugriff auf options-Vektor ermitteln
          int pos = -1;
          for (int i = 0; i < atts.getLength(); i++)
            if (atts.getLocalName(i).equals("pos")) pos = EfaUtil.string2int(atts.getValue(i), -1);

          if (option != null)
            switch (option.type) {
              case ElwizOption.O_OPTIONAL: // optional
                JCheckBox o1 = (JCheckBox) option.components.get(pos);
                if (!o1.isSelected()) skip = true;
                break;
              case ElwizOption.O_SELECT: // select
                JRadioButton o2 = (JRadioButton) option.components.get(pos);
                if (!o2.isSelected()) skip = true;
                ElwizSingleOption eso = (ElwizSingleOption) option.options.get(pos);
                if (!skip && eso.value != null) f.write(eso.value);
                break;
              case ElwizOption.O_VALUE: // value
                JTextField o3 = (JTextField) option.components.get(pos);
                f.write(o3.getText().trim());
                break;
            }
        }

      } else {

        // Elemente des XSLT-Namensraums

        if (skip) return; // Element unterdrücken?

        f.write("<" + qname);
        for (int i = 0; i < atts.getLength(); i++) {
          f.write(
              " "
                  + atts.getLocalName(i)
                  + "=\""
                  + EfaUtil.replace(atts.getValue(i), "<", "&lt;", true)
                  + "\"");
        }
        if (localName.equals("stylesheet"))
          f.write(
              " xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:fo=\"http://www.w3.org/1999/XSL/Format\"");
        f.write(">");
      }
    } catch (IOException e) {
    }
  }
  public static int beginGUIConfigurationTransaction(String sConfigurationFileName, String sUser) {

    String sConfigurationLockFile;
    BufferedWriter bwBufferedWriter;
    File fFile;

    sConfigurationLockFile = new String(sConfigurationFileName + ".lck");

    System.out.println("beginGUIConfigurationTransaction: " + sConfigurationFileName);

    try {
      fFile = new File(URLDecoder.decode(sConfigurationLockFile, "UTF-8"));
    } catch (IOException e) {
      JOptionPane.showMessageDialog(
          null, "URLDecoder.decode failed", "ConfigurationTransaction", JOptionPane.ERROR_MESSAGE);

      return 1;
    }

    if (fFile.exists()) {
      BufferedReader brBufferedReader;
      char cLastConfigurationUser[];

      cLastConfigurationUser = new char[((int) fFile.length())];

      try {
        brBufferedReader =
            new BufferedReader(new FileReader(URLDecoder.decode(sConfigurationLockFile, "UTF-8")));
        brBufferedReader.read(cLastConfigurationUser, 0, (int) (fFile.length()));
        brBufferedReader.close();

        System.out.println(
            "Last configuration user: "******"Operation on BufferedWriter failed (1)",
            "ConfigurationTransaction",
            JOptionPane.ERROR_MESSAGE);

        return 1;
      }

      if (String.copyValueOf(cLastConfigurationUser).compareTo(sUser) == 0) {
        System.out.println("File. delete: " + sConfigurationFileName);

        if (fFile.delete() == false) {
          JOptionPane.showMessageDialog(
              null, "fFile.delete failed", "ConfigurationTransaction", JOptionPane.ERROR_MESSAGE);

          return 2;
        }
      } else {
        JOptionPane.showMessageDialog(
            null,
            "The configuration is locked by "
                + String.copyValueOf(cLastConfigurationUser)
                + ".\nYou cannot change the configuration.",
            "ConfigurationTransaction",
            JOptionPane.PLAIN_MESSAGE);

        return 3;
      }
    }

    try {
      bwBufferedWriter =
          new BufferedWriter(new FileWriter(URLDecoder.decode(sConfigurationLockFile, "UTF-8")));
      bwBufferedWriter.write(sUser, 0, sUser.length());
      bwBufferedWriter.close();

      System.out.println("Configuration user written: " + sUser);
    } catch (IOException e) {
      JOptionPane.showMessageDialog(
          null,
          "Operation on BufferedWriter failed (" + e + ")",
          "ConfigurationTransaction",
          JOptionPane.ERROR_MESSAGE);

      return 4;
    }

    return 0;
  }
Beispiel #28
0
    public void actionPerformed(ActionEvent e) {
      double payRate, hours, basePay, overtimePay, overtimeHours, netPay;
      String payDate, name, hoursErr, outputStr;

      payDate = (dateTF.getText());
      name = (nameTF.getText());
      payRate = Double.parseDouble(payrateTF.getText().is);
      hours = Double.parseDouble(hoursworkedTF.getText());
      overtimeHours = Double.parseDouble(otworkedTF.getText());
      basePay = payRate * hours;
      overtimePay = (1.5 * payRate) * overtimeHours;
      netPay = basePay + overtimePay;

      // throw error if hours entered is more than 40
      if (hours > 40) {
        hoursErr =
            "Hours worked must be 40 or less. Please enter "
                + "the data again. Any additional time over 40 is considered"
                + " overtime.";

        JOptionPane.showMessageDialog(null, hoursErr, "Error", JOptionPane.ERROR_MESSAGE);
      }

      // or continue with output
      else {

        outputStr =
            "Regular Pay: $"
                + basePay
                + "\n"
                + "Overtime Pay: $"
                + overtimePay
                + "\n"
                + "Total Pay: $"
                + netPay
                + "\n\n"
                + "Summary available in the EmployeePayroll.txt file.";

        JOptionPane.showMessageDialog(
            null, outputStr, "Total Pay for " + name + ".", JOptionPane.INFORMATION_MESSAGE);
      }

      try {
        // Create text file, publish information, and close it.
        FileWriter fstream = new FileWriter("EmployeePayroll.txt", true);
        BufferedWriter out = new BufferedWriter(fstream);
        out.write("***Pay Calculation***\n");
        out.write("Pay Date: " + payDate + "\n");
        out.write("Employee Name: " + name + "\n");
        out.write("Pay Rate: " + payRate + "\n");
        out.write("Regular Hours: " + hours + "\n");
        out.write("Overtime Hours: " + overtimeHours + "\n");
        out.write("Regular Pay: $" + basePay + "\n");
        out.write("Overtime Pay: $" + overtimePay + "\n");
        out.write("Total Pay: $" + netPay + "\n");

        // Close the output stream
        out.close();
      } catch (Exception f) { // Catch exception if any
        System.err.println("Error: " + f.getMessage());
      }
    }
  public static int commitGUIConfigurationTransaction(
      XMLTreeForConfiguration xtfcXMLTreeForConfiguration, Vector vFunctionalities) {

    TreeVisit tvConfigurationTreeVisit;
    TreeVisitToGetConfigurationFile tvgcTreeVisitToGetConfigurationFile;
    String sConfigurationFile;
    URL uXML;
    String sConfigurationLockFile;
    BufferedWriter bwBufferedWriter;
    File fFile;

    tvgcTreeVisitToGetConfigurationFile = new TreeVisitToGetConfigurationFile(vFunctionalities);
    tvConfigurationTreeVisit = new TreeVisit(tvgcTreeVisitToGetConfigurationFile);

    if (tvConfigurationTreeVisit.inOrderVisit(xtfcXMLTreeForConfiguration.getXMLTopTreeComponent())
        != 0) {
      JOptionPane.showMessageDialog(
          null, "inOrderVisit failed", "ConfigurationTransaction", JOptionPane.ERROR_MESSAGE);

      return 1;
    }

    sConfigurationFile = tvgcTreeVisitToGetConfigurationFile.getConfigurationFile();

    System.out.println("commitGUIConfigurationTransaction: " + sConfigurationFile);

    uXML = xtfcXMLTreeForConfiguration.getXML();

    try {
      bwBufferedWriter =
          new BufferedWriter(new FileWriter(URLDecoder.decode(uXML.getFile(), "UTF-8")));
      bwBufferedWriter.write(sConfigurationFile, 0, sConfigurationFile.length());
      bwBufferedWriter.close();

      System.out.println(
          "commitGUIConfigurationTransaction: file written ("
              + URLDecoder.decode(uXML.getFile(), "UTF-8")
              + ")");
    } catch (IOException e) {
      JOptionPane.showMessageDialog(
          null,
          "Operation on BufferedWriter failed (3)",
          "ConfigurationTransaction",
          JOptionPane.ERROR_MESSAGE);

      return 2;
    }

    sConfigurationLockFile = new String(uXML.getFile() + ".lck");

    try {
      fFile = new File(URLDecoder.decode(sConfigurationLockFile, "UTF-8"));

      System.out.println("File. delete: " + URLDecoder.decode(sConfigurationLockFile, "UTF-8"));
    } catch (IOException e) {
      JOptionPane.showMessageDialog(
          null, "URLDecoder.decode failed", "ConfigurationTransaction", JOptionPane.ERROR_MESSAGE);

      return 1;
    }

    if (fFile.delete() == false) {
      JOptionPane.showMessageDialog(
          null,
          "fFile.delete on " + sConfigurationLockFile + " failed",
          "ConfigurationTransaction",
          JOptionPane.ERROR_MESSAGE);

      return 3;
    }

    return 0;
  }