void onOpenFileClicked() { if (!maybeSave()) { return; } try { JFileChooser fc = new JFileChooser(); FileNameExtensionFilter filter1 = new FileNameExtensionFilter(strings.getString("filetype." + EXTENSION), EXTENSION); fc.setFileFilter(filter1); int rv = fc.showOpenDialog(this); if (rv == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); Tournament t = new Tournament(); t.loadFile(file); setTournament(file, t); } } catch (Exception e) { JOptionPane.showMessageDialog( this, e, strings.getString("main.error_caption"), JOptionPane.ERROR_MESSAGE); } }
/** * Constructs a new TranslatorComponent with the given filters of the source and destination * files. */ public TranslatorComponent(FileFilter sourceFilter, FileFilter destFilter) { this.sourceFilter = sourceFilter; this.destFilter = destFilter; init(); jbInit(); source.setName("Source"); destination.setName("Destination"); sourceFileChooser = new JFileChooser(); sourceFileChooser.setFileFilter(sourceFilter); destFileChooser = new JFileChooser(); destFileChooser.setFileFilter(destFilter); source.enableUserInput(); destination.disableUserInput(); }
private void resetGlobFilter() { if (actualFileFilter != null) { JFileChooser chooser = getFileChooser(); FileFilter currentFilter = chooser.getFileFilter(); if (currentFilter != null && currentFilter.equals(globFilter)) { chooser.setFileFilter(actualFileFilter); chooser.removeChoosableFileFilter(globFilter); } actualFileFilter = null; } }
/** * Use a JFileChooser in Save mode to select files to open. Use a filter for FileFilter subclass * to select for "*.java" files. If a file is selected, then this file will be used as final * output */ boolean saveFile() { File file = null; JFileChooser fc = new JFileChooser(); // Start in current directory fc.setCurrentDirectory(new File(".")); // Set filter for Java source files. fc.setFileFilter(fJavaFilter); // Set to a default name for save. fc.setSelectedFile(fFile); // Open chooser dialog int result = fc.showSaveDialog(this); if (result == JFileChooser.CANCEL_OPTION) { return true; } else if (result == JFileChooser.APPROVE_OPTION) { fFile = fc.getSelectedFile(); String textFile = fFile.toString(); if (fileNo.equalsIgnoreCase("SAVE")) { UpLoadFile.outputfile.setText(textFile); } else if (fileNo.equalsIgnoreCase("SAVE2")) { UpLoadMAGEMLFile.outputfile1.setText(textFile); } else if (fileNo.equalsIgnoreCase("SAVE3")) { UpLoadMAGEMLFile.outputfile2.setText(textFile); } else if (fileNo.equalsIgnoreCase("SAVEJPAG")) { JPEGFileName = textFile; // System.out.println ("JPG filename OpenFileDir= " +JPEGFileName); File fFile = new File(JPEGFileName); if (fFile.exists()) { int response = JOptionPane.showConfirmDialog( null, "Overwrite existing file " + JPEGFileName + " ??", "Confirm Overwrite", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.CANCEL_OPTION) { /* go back to reload the file*/ return false; } } SetUpPlotWindow.saveComponentAsJPEG(SetUpPlotWindow.content, JPEGFileName); } return true; } else { return false; } } // saveFile
/* * This function just finds and loads the file */ private boolean loadFile() { JFileChooser fc = new JFileChooser(); fc.setDialogTitle("Load File"); // Choose only files, not directories fc.setFileSelectionMode(JFileChooser.FILES_ONLY); // Start in current directory fc.setCurrentDirectory(new File(".")); // Set filter for Java source files. fc.setFileFilter(fJavaFilter); // Now open chooser int result = fc.showOpenDialog(this); if (result == JFileChooser.CANCEL_OPTION) { // return true; } else if (result == JFileChooser.APPROVE_OPTION) { fFile = fc.getSelectedFile(); String textFile = fFile.toString(); if (fileNo.equalsIgnoreCase("LOAD1")) { UpLoadFile.filePath1.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD2")) { UpLoadFile.filePath2.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD3")) { VisualizationInput.originalFilePath.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD4")) { VisualizationInput.DWDVecFilePath.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD5")) { VisualizationInput.DWDOutputFilePath.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD6")) { UpLoadMAGEMLFile.filePath1.setText(textFile); } else if (fileNo.equalsIgnoreCase("LOAD7")) { UpLoadMAGEMLFile.filePath2.setText(textFile); } // Get the absolute path for the file being opened filePath = fFile.getAbsolutePath(); if (filePath == null) { // fTextField.setText (filePath); return false; } } else { return false; } return true; } /*End of loadFile*/
private void setXMLChooserFileFilter(JFileChooser chooser) { chooser.setFileFilter( new FileFilter() { @Override public boolean accept(File f) { return f.isDirectory() || f.getName().endsWith("xml"); } @Override public String getDescription() { return "Herolabs xml output file"; } }); }
public ScaleMainFrame() { super(new BorderLayout()); nameTF = new JTextField(); JPanel top = new JPanel(new BorderLayout()); top.add(new JLabel("Scale Name:"), BorderLayout.WEST); top.add(nameTF, BorderLayout.CENTER); PlayButton pb = new PlayButton("PLAY"); tempoP = new IntSetPanel(1, 10000, "Tempo"); tempoP.setValue(120); JPanel botL = new JPanel(new BorderLayout()); botL.add(pb, BorderLayout.EAST); botL.add(tempoP, BorderLayout.CENTER); PianoKeyB kb = new PianoKeyB(); kb.setPreferredSize(new Dimension(150, 40)); // JPanel botTop = new JPanel(new GridLayout(1, 2)); JPanel botTop = new JPanel(new FlowLayout()); botTop.add(botL); botTop.add(kb); JButton newB = new JButton("New"); saveB = new JButton("Save"); JButton loadB = new JButton("Load"); newB.addActionListener(this); saveB.addActionListener(this); loadB.addActionListener(this); pb.addActionListener(this); JPanel botBot = new JPanel(new GridLayout(1, 3)); botBot.add(newB); botBot.add(saveB); botBot.add(loadB); JPanel bottom = new JPanel(new BorderLayout()); bottom.add(botTop, BorderLayout.CENTER); bottom.add(botBot, BorderLayout.SOUTH); sp = new ScalePanel(this, kb); add(top, BorderLayout.NORTH); add(sp, BorderLayout.CENTER); add(bottom, BorderLayout.SOUTH); setPreferredSize(new Dimension(500, 300)); fileChooser = new JFileChooser(new File("Features/Scales")); filter = new ScaleFilter(); fileChooser.addChoosableFileFilter(filter); fileChooser.setFileFilter(filter); }
// Saves the open project to a new file selected by the user public boolean saveFileAs() { // Filter the file chooser by Cue Masher files JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileFilter(new CueFileFilter()); // Display the existing file location by default if it exists String filePath = soundManager.getProjectFilePath(); if (filePath != null) { File openProjectFile = new File(filePath); fileChooser.setSelectedFile(openProjectFile); } int choice = fileChooser.showSaveDialog(CueMasherPanel.this); if (choice == JFileChooser.APPROVE_OPTION) { // Get the name of the file the user selected File file = fileChooser.getSelectedFile(); filePath = file.getAbsolutePath().trim(); // Make sure that it has a Cue Masher file extension String cueMasherExt = CueFileFilter.CUE_MASHER_FILE_EXT; boolean addExt = false; if (filePath.length() < cueMasherExt.length()) addExt = true; else { String ext = filePath.substring(filePath.length() - cueMasherExt.length(), filePath.length()); if (!ext.equalsIgnoreCase(cueMasherExt)) addExt = true; } // Add the cue masher file extension if it doesn't exist if (addExt) filePath = filePath + cueMasherExt; // Save the project to the selected file soundManager.setProjectFilePath(filePath); return soundManager.saveFile(); } return false; }
/** @return true if file was saved, false if user canceled */ boolean onSaveAsFileClicked() { try { JFileChooser fc = new JFileChooser(); FileNameExtensionFilter filter1 = new FileNameExtensionFilter(strings.getString("filetype." + EXTENSION), EXTENSION); fc.setFileFilter(filter1); int rv = fc.showSaveDialog(this); if (rv == JFileChooser.APPROVE_OPTION) { currentFile = fc.getSelectedFile(); if (!currentFile.getName().endsWith("." + EXTENSION)) { currentFile = new File(currentFile.getPath() + "." + EXTENSION); } doSave(currentFile); refresh(); return true; } } catch (Exception e) { JOptionPane.showMessageDialog( this, e, strings.getString("main.error_caption"), JOptionPane.ERROR_MESSAGE); } return false; }
// Initializes this component. private void jbInit() { fileChooser.setFileFilter(new ScriptFileFilter()); this.getContentPane().setLayout(null); Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>(); JLabel slowLabel = new JLabel("Slow"); slowLabel.setFont(Utilities.thinLabelsFont); JLabel fastLabel = new JLabel("Fast"); fastLabel.setFont(Utilities.thinLabelsFont); labelTable.put(1, slowLabel); labelTable.put(5, fastLabel); speedSlider.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { SpeedSlider_stateChanged(e); } }); speedSlider.setLabelTable(labelTable); speedSlider.setMajorTickSpacing(1); speedSlider.setPaintTicks(true); speedSlider.setPaintLabels(true); speedSlider.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0)); speedSlider.setPreferredSize(new Dimension(95, 50)); speedSlider.setMinimumSize(new Dimension(95, 50)); speedSlider.setToolTipText("Speed"); speedSlider.setMaximumSize(new Dimension(95, 50)); final Dimension buttonSize = new Dimension(39, 39); loadProgramButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { loadProgramButton_actionPerformed(); } }); loadProgramButton.setMaximumSize(buttonSize); loadProgramButton.setMinimumSize(buttonSize); loadProgramButton.setPreferredSize(buttonSize); loadProgramButton.setSize(buttonSize); loadProgramButton.setToolTipText("Load Program"); loadProgramButton.setIcon(loadProgramIcon); ffwdButton.setMaximumSize(buttonSize); ffwdButton.setMinimumSize(buttonSize); ffwdButton.setPreferredSize(buttonSize); ffwdButton.setToolTipText("Run"); ffwdButton.setIcon(ffwdIcon); ffwdButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { ffwdButton_actionPerformed(); } }); stopButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { stopButton_actionPerformed(); } }); stopButton.setMaximumSize(buttonSize); stopButton.setMinimumSize(buttonSize); stopButton.setPreferredSize(buttonSize); stopButton.setToolTipText("Stop"); stopButton.setIcon(stopIcon); rewindButton.setMaximumSize(buttonSize); rewindButton.setMinimumSize(buttonSize); rewindButton.setPreferredSize(buttonSize); rewindButton.setToolTipText("Reset"); rewindButton.setIcon(rewindIcon); rewindButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { rewindButton_actionPerformed(); } }); scriptButton.setMaximumSize(buttonSize); scriptButton.setMinimumSize(buttonSize); scriptButton.setPreferredSize(buttonSize); scriptButton.setToolTipText("Load Script"); scriptButton.setIcon(scriptIcon); scriptButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { scriptButton_actionPerformed(); } }); breakButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { breakButton_actionPerformed(); } }); breakButton.setMaximumSize(buttonSize); breakButton.setMinimumSize(buttonSize); breakButton.setPreferredSize(buttonSize); breakButton.setToolTipText("Open breakpoint panel"); breakButton.setIcon(breakIcon); breakpointWindow.addBreakpointListener(this); singleStepButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { singleStepButton_actionPerformed(); } }); singleStepButton.setMaximumSize(buttonSize); singleStepButton.setMinimumSize(buttonSize); singleStepButton.setPreferredSize(buttonSize); singleStepButton.setSize(buttonSize); singleStepButton.setToolTipText("Single Step"); singleStepButton.setIcon(singleStepIcon); stepOverButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { stepOverButton_actionPerformed(); } }); stepOverButton.setMaximumSize(buttonSize); stepOverButton.setMinimumSize(buttonSize); stepOverButton.setPreferredSize(buttonSize); stepOverButton.setSize(buttonSize); stepOverButton.setToolTipText("Step Over"); stepOverButton.setIcon(stepOverIcon); animationCombo.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { animationCombo_actionPerformed(); } }); formatCombo.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { formatCombo_actionPerformed(); } }); additionalDisplayCombo.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { additionalDisplayCombo_actionPerformed(); } }); messageLbl.setFont(Utilities.statusLineFont); messageLbl.setBorder(BorderFactory.createLoweredBevelBorder()); messageLbl.setBounds(new Rectangle(0, 667, CONTROLLER_WIDTH - 8, 25)); toolBar = new JToolBar(); toolBar.setSize(new Dimension(TOOLBAR_WIDTH, TOOLBAR_HEIGHT)); toolBar.setLayout(new FlowLayout(FlowLayout.LEFT, 3, 0)); toolBar.setFloatable(false); toolBar.setLocation(0, 0); toolBar.setBorder(BorderFactory.createEtchedBorder()); arrangeToolBar(); this.getContentPane().add(toolBar, null); toolBar.revalidate(); toolBar.repaint(); repaint(); // Creating the menu bar menuBar = new JMenuBar(); arrangeMenu(); setJMenuBar(menuBar); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); this.getContentPane().add(messageLbl, null); setControllerSize(); // sets the frame to be visible. setVisible(true); }
public void actionPerformed(ActionEvent e) { if (isDirectorySelected()) { File dir = getDirectory(); if (dir != null) { try { // Strip trailing ".." dir = ShellFolder.getNormalizedFile(dir); } catch (IOException ex) { // Ok, use f as is } changeDirectory(dir); return; } } JFileChooser chooser = getFileChooser(); String filename = getFileName(); FileSystemView fs = chooser.getFileSystemView(); File dir = chooser.getCurrentDirectory(); if (filename != null) { // Remove whitespaces from end of filename int i = filename.length() - 1; while (i >= 0 && filename.charAt(i) <= ' ') { i--; } filename = filename.substring(0, i + 1); } if (filename == null || filename.length() == 0) { // no file selected, multiple selection off, therefore cancel the approve action resetGlobFilter(); return; } File selectedFile = null; File[] selectedFiles = null; // Unix: Resolve '~' to user's home directory if (File.separatorChar == '/') { if (filename.startsWith("~/")) { filename = System.getProperty("user.home") + filename.substring(1); } else if (filename.equals("~")) { filename = System.getProperty("user.home"); } } if (chooser.isMultiSelectionEnabled() && filename.length() > 1 && filename.charAt(0) == '"' && filename.charAt(filename.length() - 1) == '"') { List<File> fList = new ArrayList<File>(); String[] files = filename.substring(1, filename.length() - 1).split("\" \""); // Optimize searching files by names in "children" array Arrays.sort(files); File[] children = null; int childIndex = 0; for (String str : files) { File file = fs.createFileObject(str); if (!file.isAbsolute()) { if (children == null) { children = fs.getFiles(dir, false); Arrays.sort(children); } for (int k = 0; k < children.length; k++) { int l = (childIndex + k) % children.length; if (children[l].getName().equals(str)) { file = children[l]; childIndex = l + 1; break; } } } fList.add(file); } if (!fList.isEmpty()) { selectedFiles = fList.toArray(new File[fList.size()]); } resetGlobFilter(); } else { selectedFile = fs.createFileObject(filename); if (!selectedFile.isAbsolute()) { selectedFile = fs.getChild(dir, filename); } // check for wildcard pattern FileFilter currentFilter = chooser.getFileFilter(); if (!selectedFile.exists() && isGlobPattern(filename)) { changeDirectory(selectedFile.getParentFile()); if (globFilter == null) { globFilter = new GlobFilter(); } try { globFilter.setPattern(selectedFile.getName()); if (!(currentFilter instanceof GlobFilter)) { actualFileFilter = currentFilter; } chooser.setFileFilter(null); chooser.setFileFilter(globFilter); return; } catch (PatternSyntaxException pse) { // Not a valid glob pattern. Abandon filter. } } resetGlobFilter(); // Check for directory change action boolean isDir = (selectedFile != null && selectedFile.isDirectory()); boolean isTrav = (selectedFile != null && chooser.isTraversable(selectedFile)); boolean isDirSelEnabled = chooser.isDirectorySelectionEnabled(); boolean isFileSelEnabled = chooser.isFileSelectionEnabled(); boolean isCtrl = (e != null && (e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0); if (isDir && isTrav && (isCtrl || !isDirSelEnabled)) { changeDirectory(selectedFile); return; } else if ((isDir || !isFileSelEnabled) && (!isDir || !isDirSelEnabled) && (!isDirSelEnabled || selectedFile.exists())) { selectedFile = null; } } if (selectedFiles != null || selectedFile != null) { if (selectedFiles != null || chooser.isMultiSelectionEnabled()) { if (selectedFiles == null) { selectedFiles = new File[] {selectedFile}; } chooser.setSelectedFiles(selectedFiles); // Do it again. This is a fix for bug 4949273 to force the // selected value in case the ListSelectionModel clears it // for non-existing file names. chooser.setSelectedFiles(selectedFiles); } else { chooser.setSelectedFile(selectedFile); } chooser.approveSelection(); } else { if (chooser.isMultiSelectionEnabled()) { chooser.setSelectedFiles(null); } else { chooser.setSelectedFile(null); } chooser.cancelSelection(); } }
public void saveUnsaved() throws SaveAbortedException { if (!saved) { int option = 0; if (loadedFile == null) option = JOptionPane.showConfirmDialog( this, new JLabel("Save changes to UNTITLED?"), "Warning", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); else option = JOptionPane.showConfirmDialog( this, new JLabel("Save changes to " + loadedFile.getName() + "?"), "Warning", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if (option == JOptionPane.YES_OPTION) { if (loadedFile == null) // SAVE NEW FILE { if (nameTF.getText().equals("")) { JOptionPane.showMessageDialog( this, new JLabel("Please type in the Scale Name"), "Warning", JOptionPane.WARNING_MESSAGE); throw new SaveAbortedException(); } fileChooser.setFileFilter(filter); int option2 = fileChooser.showSaveDialog(this); if (option2 == JFileChooser.APPROVE_OPTION) { File target = fileChooser.getSelectedFile(); try { PrintStream stream = new PrintStream(new FileOutputStream(target), true); save(stream); stream.close(); } catch (Exception ex) { JOptionPane.showMessageDialog( this, new JLabel("Error: " + ex.getMessage()), "Error", JOptionPane.ERROR_MESSAGE); } } else throw new SaveAbortedException(); ; } else // save LOADED FILE { try { PrintStream stream = new PrintStream(new FileOutputStream(loadedFile), true); save(stream); stream.close(); } catch (Exception ex) { JOptionPane.showMessageDialog( this, new JLabel("Error: " + ex.getMessage()), "Error", JOptionPane.ERROR_MESSAGE); } } } else if (option == JOptionPane.CANCEL_OPTION) throw new SaveAbortedException(); ; } }
public void actionPerformed(ActionEvent e) { JButton b = (JButton) e.getSource(); if (b.getText() == "PLAY") { if (scoreP != null) scoreP.playScale(sp.getScale(), tempoP.getValue()); } else if (b.getText() == "New") { try { saveUnsaved(); } catch (SaveAbortedException ex) { return; } sp.notes.removeAllElements(); sp.repaint(); nameTF.setText(""); loadedFile = null; } else if (b.getText() == "Save") { if (nameTF.getText().equals("")) { JOptionPane.showMessageDialog( this, new JLabel("Please type in the Scale Name"), "Warning", JOptionPane.WARNING_MESSAGE); return; } fileChooser.setFileFilter(filter); int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { File target = fileChooser.getSelectedFile(); if (target.getName().indexOf(".scl") == -1) target = new File(target.getPath() + ".scl"); try { PrintStream stream = new PrintStream(new FileOutputStream(target), true); save(stream); stream.close(); } catch (Exception ex) { JOptionPane.showMessageDialog( this, new JLabel("Error: " + ex.getMessage()), "Error", JOptionPane.ERROR_MESSAGE); } } } else if (b.getText() == "Load") { try { saveUnsaved(); } catch (SaveAbortedException ex) { return; } fileChooser.setFileFilter(filter); int option = fileChooser.showOpenDialog(this); if (option == JFileChooser.APPROVE_OPTION) { loadedFile = fileChooser.getSelectedFile(); SAXParserFactory factory = SAXParserFactory.newInstance(); ScaleParser handler = new ScaleParser(false); try { SAXParser parser = factory.newSAXParser(); parser.parse(loadedFile, handler); // System.out.println("success"); } catch (Exception ex) { // System.out.println("no!!!!!! exception: "+e); // System.out.println(ex.getMessage()); ex.printStackTrace(); } // -----now :P:P--------------- System.out.println("name: " + handler.getName()); nameTF.setText(handler.getName()); sp.notes.removeAllElements(); int[] scale = handler.getScale(); for (int i = 0; i < scale.length; i++) { sp.addNote(scale[i]); } sp.repaint(); } else loadedFile = null; } }
private boolean autoDetectPaths() { if (Globals.ON_WIN) { List<File> progFiles = AutoDetectPaths.findProgramFilesDir(); File sOffice = null; if (fileSearchCancelled) { return false; } for (File dir : progFiles) { sOffice = findFileDir(dir, "soffice.exe"); if (sOffice != null) { break; } } if (sOffice == null) { JOptionPane.showMessageDialog( parent, Globals.lang( "Unable to autodetect OpenOffice installation. Please choose the installation directory manually."), Globals.lang("Could not find OpenOffice installation"), JOptionPane.INFORMATION_MESSAGE); JFileChooser jfc = new JFileChooser(new File("C:\\")); jfc.setDialogType(JFileChooser.OPEN_DIALOG); jfc.setFileFilter( new javax.swing.filechooser.FileFilter() { @Override public boolean accept(File file) { return file.isDirectory(); } @Override public String getDescription() { return Globals.lang("Directories"); } }); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); jfc.showOpenDialog(parent); if (jfc.getSelectedFile() != null) { sOffice = jfc.getSelectedFile(); } } if (sOffice == null) { return false; } Globals.prefs.put("ooExecutablePath", new File(sOffice, "soffice.exe").getPath()); File unoil = findFileDir(sOffice.getParentFile(), "unoil.jar"); if (fileSearchCancelled) { return false; } File jurt = findFileDir(sOffice.getParentFile(), "jurt.jar"); if (fileSearchCancelled) { return false; } if ((unoil != null) && (jurt != null)) { Globals.prefs.put("ooUnoilPath", unoil.getPath()); Globals.prefs.put("ooJurtPath", jurt.getPath()); return true; } else { return false; } } else if (Globals.ON_MAC) { File rootDir = new File("/Applications"); File[] files = rootDir.listFiles(); for (File file : files) { if (file.isDirectory() && file.getName().equals("OpenOffice.org.app")) { rootDir = file; // System.out.println("Setting starting dir to: "+file.getPath()); break; } } // System.out.println("Searching for soffice.bin"); File sOffice = findFileDir(rootDir, "soffice.bin"); // System.out.println("Found: "+(sOffice != null ? sOffice.getPath() : "-")); if (fileSearchCancelled) { return false; } if (sOffice != null) { Globals.prefs.put("ooExecutablePath", new File(sOffice, "soffice.bin").getPath()); // System.out.println("Searching for unoil.jar"); File unoil = findFileDir(rootDir, "unoil.jar"); // System.out.println("Found: "+(unoil != null ? unoil.getPath(): "-")); if (fileSearchCancelled) { return false; } // System.out.println("Searching for jurt.jar"); File jurt = findFileDir(rootDir, "jurt.jar"); // System.out.println("Found: "+(jurt != null ? jurt.getPath(): "-")); if (fileSearchCancelled) { return false; } if ((unoil != null) && (jurt != null)) { Globals.prefs.put("ooUnoilPath", unoil.getPath()); Globals.prefs.put("ooJurtPath", jurt.getPath()); return true; } else { return false; } } else { return false; } } else { // Linux: String usrRoot = "/usr/lib"; File inUsr = findFileDir(new File("/usr/lib"), "soffice"); if (fileSearchCancelled) { return false; } if (inUsr == null) { inUsr = findFileDir(new File("/usr/lib64"), "soffice"); if (inUsr != null) { usrRoot = "/usr/lib64"; } } if (fileSearchCancelled) { return false; } File inOpt = findFileDir(new File("/opt"), "soffice"); if (fileSearchCancelled) { return false; } if ((inUsr != null) && (inOpt == null)) { return setupPreferencesForOO(usrRoot, inUsr); } else if ((inOpt != null) && (inUsr == null)) { Globals.prefs.put("ooExecutablePath", new File(inOpt, "soffice.bin").getPath()); File unoil = findFileDir(new File("/opt"), "unoil.jar"); File jurt = findFileDir(new File("/opt"), "jurt.jar"); if ((unoil != null) && (jurt != null)) { Globals.prefs.put("ooUnoilPath", unoil.getPath()); Globals.prefs.put("ooJurtPath", jurt.getPath()); return true; } else { return false; } } else if (inOpt != null) { // Found both JRadioButton optRB = new JRadioButton(inOpt.getPath(), true); JRadioButton usrRB = new JRadioButton(inUsr.getPath(), false); ButtonGroup bg = new ButtonGroup(); bg.add(optRB); bg.add(usrRB); DefaultFormBuilder b = new DefaultFormBuilder(new FormLayout("left:pref", "")); b.append( Globals.lang( "Found more than one OpenOffice executable. Please choose which one to connect to:")); b.append(optRB); b.append(usrRB); int answer = JOptionPane.showConfirmDialog( null, b.getPanel(), Globals.lang("Choose OpenOffice executable"), JOptionPane.OK_CANCEL_OPTION); if (answer == JOptionPane.CANCEL_OPTION) { return false; } else { if (optRB.isSelected()) { return setupPreferencesForOO("/opt", inOpt); } else { return setupPreferencesForOO(usrRoot, inUsr); } } } else { return false; } } }