/** * The ActionListener implementation * * @param event the event. */ public void actionPerformed(ActionEvent event) { String searchText = textField.getText().trim(); if (searchText.equals("") && !saveAs.isSelected() && (fileLength > 10000000)) { textPane.setText("Blank search text is not allowed for large IdTables."); } else { File outputFile = null; if (saveAs.isSelected()) { outputFile = chooser.getSelectedFile(); if (outputFile != null) { String name = outputFile.getName(); int k = name.lastIndexOf("."); if (k != -1) name = name.substring(0, k); name += ".txt"; File parent = outputFile.getAbsoluteFile().getParentFile(); outputFile = new File(parent, name); chooser.setSelectedFile(outputFile); } if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) System.exit(0); outputFile = chooser.getSelectedFile(); } textPane.setText(""); Searcher searcher = new Searcher(searchText, event.getSource().equals(searchPHI), outputFile); searcher.start(); } }
private static int getBuildNumber(File installDirectory) { installDirectory = installDirectory.getAbsoluteFile(); File buildTxt = new File(installDirectory, BUILD_NUMBER_FILE); if ((!buildTxt.exists()) || (buildTxt.isDirectory())) { buildTxt = new File(new File(installDirectory, BIN_FOLDER), BUILD_NUMBER_FILE); } if (buildTxt.exists() && !buildTxt.isDirectory()) { int buildNumber = -1; String buildNumberText = getContent(buildTxt); if (buildNumberText != null) { try { if (buildNumberText.length() > 1) { buildNumberText = buildNumberText.trim(); buildNumber = Integer.parseInt(buildNumberText); } } catch (Exception e) { // OK } } return buildNumber; } return -1; }
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; }
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(); } }