Logo Search packages:      
Sourcecode: pauker version File versions  Download package

boolean pauker::program::gui::swing::PaukerFrame::openFiles ( File[]  files,
String  encoding,
boolean  merging 
) [inline]

Opens the selected files.

Parameters:
files the selected files
encoding the encoding of the files
merging if the files should be merged
Returns:
true, if the files could be opened

Definition at line 4284 of file PaukerFrame.java.

References pauker::program::Lesson::getDescription(), pauker::program::Lesson::getNumberOfCards(), pauker::program::Lesson::getNumberOfExpiredCards(), pauker::program::Lesson::getUnlearnedBatch(), pauker::program::SearchEngine::index(), pauker::program::SearchEngine::init(), pauker::program::Lesson::merge(), pauker::program::Lesson::refreshExpiration(), somethingHasChanged(), and STRINGS.

Referenced by main().

                                                                             {

        String path = null;
        try {
            if (merging) {
                // try opening all lessons before actually merging them
                Lesson[] newLessons = new Lesson[files.length];
                for (int i = 0; i < files.length; i++) {
                    path = files[i].getPath();
                    newLessons[i] = Pauker.openLesson(path, encoding);
                }
                System.out.println("all lessons opened");

                // merge all lessons into the current one
                for (int i = 0; i < newLessons.length; i++) {
                    Lesson newLesson = newLessons[i];
                    if (newLesson.getNumberOfCards() == 0) {
                        System.out.println(files[i] + " contains no cards!");
                    } else {
                        somethingHasChanged();
                        currentLesson.merge(newLesson);
                    }
                }
                System.out.println("all lessons merged");

            } else {
                // open single file
                path = files[0].getPath();
                Lesson newLesson = Pauker.openLesson(path, encoding);

                int lastSeparatorIndex = path.lastIndexOf(File.separatorChar);
                /* Only remember complete directory names.
                 * (We can have relative path names when coming from the command line.
                 *  Then we must not remember anything here...)
                 */
                if (lastSeparatorIndex != -1) {
                    lastAccessedDirectory = path.substring(0, lastSeparatorIndex);
                }
                currentLesson = newLesson;
                currentFileName = path;
                addToRecentFiles(currentFileName);
                somethingChanged = false;
                currentTitle = path.substring(lastSeparatorIndex + 1) + " (" + titleString + ")";
                setTitle(currentTitle);
                saveButton.setEnabled(false);
                saveMenuItem.setEnabled(false);
            }

        } catch (Exception ex) {

            logger.log(Level.SEVERE, "could not open files", ex);

            String errorMessage = MessageFormat.format(
                    STRINGS.getString("Error_Opening_File"), path);
            JOptionPane.showMessageDialog(this, errorMessage,
                    STRINGS.getString("Error"), JOptionPane.ERROR_MESSAGE);

            recentFiles.remove(path);
            recentFilesHaveChanged = true;

            return false;
        }

        // refresh expiration
        currentLesson.refreshExpiration();

        // reset gui
        statisticPanel.setLesson(currentLesson);

        learnNewCardsButton.setEnabled((currentLesson.getUnlearnedBatch()).getNumberOfCards() > 0);
        repeatCardsButton.setEnabled(currentLesson.getNumberOfExpiredCards() > 0);

        settingAboutText = true;
        aboutTextArea.setText(currentLesson.getDescription());
        aboutTextArea.setCaretPosition(0);
        settingAboutText = false;
        showPanel(lessonPanel, "aboutPanel");

        /*
        // limit preferred height of batch list (it is much too high)
        batchListPanel.setPreferredSize(null);
        batchListPanel.doLayout();
        Dimension preferredSize = batchListPanel.getPreferredSize();
        preferredSize.width += 20; // prevent initial horizontal scrollbar
        preferredSize.height = 50;
        batchListPanel.setPreferredSize(preferredSize);
         */

        // TODO: some people like it, some not...
        statisticPanel.setPreferredSize(null);
        Dimension preferredStatisticSize = statisticPanel.getPreferredSize();
        Dimension newSize = new Dimension(preferredStatisticSize);
        newSize.height = 220;
        statisticPanel.setPreferredSize(newSize);

        // the following lines of code are a version of pack() that never
        // shrinks the window
        Dimension currentSize = getSize();
        Dimension preferredSize = getPreferredSize();
        setSize(Math.max(currentSize.width, preferredSize.width),
                Math.max(currentSize.height, preferredSize.height));

        // TODO: background thread?
        searchEngine.init();
        searchEngine.index(currentLesson);

        return true;
    }


Generated by  Doxygen 1.6.0   Back to index