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

pauker::program::gui::swing::PaukerFrame::PaukerFrame (  )  [inline]

Creates new form JPauker

Definition at line 252 of file PaukerFrame.java.

References initComponents(), pauker::program::SearchEngine::setSearchLimit(), and STRINGS.

Referenced by main().

                         {

        KeyboardFocusManager currentKeyboardFocusManager =
                KeyboardFocusManager.getCurrentKeyboardFocusManager();
        currentKeyboardFocusManager.addPropertyChangeListener(this);

        currentLesson = new Lesson();

        // init our search engine for similar cards
        searchEngine = new SearchEngine();

        // load preferences
        recentFiles = new ArrayList<String>();
        Preferences preferences =
                Preferences.userRoot().node(preferencesPathName);
        for (int i = 0; i < MAX_RECENT_FILES; i++) {
            String recentFile = preferences.get("RECENT_FILE_" + i, null);
            if (recentFile == null) {
                break;
            } else {
                recentFiles.add(recentFile);
                recentFilesHaveChanged = true;
            }
        }
        lastAccessedDirectory = preferences.get("LAST_DIRECTORY", "");
        showTimer = preferences.getBoolean("SHOW_TIMER", true);
        repeatingStrategy = Pauker.RepeatingStrategy.values()[preferences.getInt("REPEATING_STRATEGY",
                Pauker.RepeatingStrategy.OLDEST_FIRST.ordinal())];
        putBackStrategy = Pauker.PutbackStrategy.values()[preferences.getInt("PUTBACK_STRATEGY",
                Pauker.PutbackStrategy.ON_TOP.ordinal())];
        ustmTime = preferences.getInt("USTM_TIME", Pauker.USTM_TIME);
        stmTime = preferences.getInt("STM_TIME", Pauker.STM_TIME);
        matchCase = preferences.getBoolean("MATCH_CASE", true);
        lineWrapping = preferences.getBoolean("LINE_WRAPPING", false);
        splitOrientation = preferences.getInt("SPLIT_ORIENTATION",
                JSplitPane.HORIZONTAL_SPLIT);
        searchLimit = preferences.getInt("SEARCH_LIMIT", 1);
        searchEngine.setSearchLimit(searchLimit);
        playRingTone = preferences.getBoolean("PLAY_RINGTONE", true);
        int dividerLocation = preferences.getInt("MAIN_DIVIDER_LOCATION", -1);

        String frontSideFontFamily =
                preferences.get("FRONTSIDE_FONT_FAMILY", "Default");
        int frontSideFontStyle =
                preferences.getInt("FRONTSIDE_FONT_STYLE", Font.PLAIN);
        int frontSizeFontSize = preferences.getInt("FRONTSIDE_FONT_SIZE", 12);
        frontSideFont = new Font(
                frontSideFontFamily, frontSideFontStyle, frontSizeFontSize);
        int frontSideForegroundRGB = preferences.getInt(
                "FRONTSIDE_FOREGROUND", Color.BLACK.getRGB());
        frontSideForeground = new Color(frontSideForegroundRGB);
        int frontSideBackgroundRGB = preferences.getInt(
                "FRONTSIDE_BACKGROUND", Color.WHITE.getRGB());
        frontSideBackground = new Color(frontSideBackgroundRGB);

        String reverseSideFontFamily =
                preferences.get("REVERSESIDE_FONT_FAMILY", "Default");
        int reverseSideFontStyle =
                preferences.getInt("REVERSESIDE_FONT_STYLE", Font.PLAIN);
        int reverseSizeFontSize =
                preferences.getInt("REVERSESIDE_FONT_SIZE", 12);
        reverseSideFont = new Font(reverseSideFontFamily,
                reverseSideFontStyle, reverseSizeFontSize);
        int reverseSideForegroundRGB = preferences.getInt(
                "REVERSESIDE_FOREGROUND", Color.BLACK.getRGB());
        reverseSideForeground = new Color(reverseSideForegroundRGB);
        int reverseSideBackgroundRGB = preferences.getInt(
                "REVERSESIDE_BACKGROUND", Color.WHITE.getRGB());
        reverseSideBackground = new Color(reverseSideBackgroundRGB);
        repeatByTyping = preferences.getBoolean("REPEAT_BY_TYPING", false);
        keepNewCardDialogOpen =
                preferences.getBoolean("KEEP_NEW_CARD_WINDOW_OPEN", false);
        String toolbarConstraints =
                preferences.get("TOOLBAR_CONSTRAINTS", "North");
        boolean toolbarVisible =
                preferences.getBoolean("TOOLBAR_VISIBLE", true);
        int sideInt = preferences.getInt("FONT_DIALOG_SIDE", 0);
        fontDialogSide = Card.Element.values()[sideInt];

        // init some vars
        String versionString = STRINGS.getString("Pauker_Version");
        titleString = MessageFormat.format(
                STRINGS.getString("ProgramTitle"), versionString);
        ringTone = Applet.newAudioClip(
                getClass().getResource("/pauker/sounds/phone.wav"));
        defautToolkit = Toolkit.getDefaultToolkit();

        initComponents();

        // place toolbar at saved position
        if (toolbarConstraints.equals(BorderLayout.NORTH)) {
            getContentPane().add(toolBar, BorderLayout.NORTH);
        } else if (toolbarConstraints.equals(BorderLayout.WEST)) {
            toolBar.setOrientation(JToolBar.VERTICAL);
            getContentPane().add(toolBar, BorderLayout.WEST);
        } else if (toolbarConstraints.equals(BorderLayout.SOUTH)) {
            getContentPane().add(toolBar, BorderLayout.SOUTH);
        } else if (toolbarConstraints.equals(BorderLayout.EAST)) {
            toolBar.setOrientation(JToolBar.VERTICAL);
            getContentPane().add(toolBar, BorderLayout.EAST);
        }
        // toolbar visibility
        showToolBarMenuItem.setSelected(toolbarVisible);

        // our own version of JList
        batchListCellRenderer = new BatchListCellRenderer(
                this, batchList.getSelectionBackground());
        batchListModel = new BatchListModel();
        batchList.setCellRenderer(batchListCellRenderer);
        batchList.setModel(batchListModel);

        setIconImage(new ImageIcon(
                getClass().getResource("/pauker/icons/icon.png")).getImage());
        currentTitle = titleString;

        // set Mnemonics
        fileMenu.setMnemonic(STRINGS.getString("File_Mnemonic").charAt(0));
        extraMenu.setMnemonic(STRINGS.getString("Extra_Mnemonic").charAt(0));
        helpMenu.setMnemonic(STRINGS.getString("Help_Mnemonic").charAt(0));

        // we have our own FocusTraversalPolicy
        setFocusTraversalPolicy(new MyFocusTraversalPolicy());

        statisticPanel.setPaukerFrame(this);
        showTimerCheckBox.setSelected(showTimer);

        // init card layouts
        showPanel(cardPanel, "overviewPanel");
        showPanel(lessonPanel, "aboutPanel");

        batchPanelBorder = (TitledBorder) batchPanel.getBorder();

        // !!! IMPORTANT !!!
        // call setLineWrap() only after creating batchListCellRenderer
        // otherwise we get NPE's
        setLineWrap(lineWrapping);

        Dimension smallDimension = new Dimension(10, 10);
        aboutPanel.setPreferredSize(smallDimension);
        batchListPanel.setPreferredSize(smallDimension);

        // set minimun height
        Dimension statisticPanelSize = statisticPanel.getSize();
        statisticPanelSize.width = 10;
        statisticPanel.setMinimumSize(statisticPanelSize);

        aboutDocument = aboutTextArea.getDocument();
        aboutDocument.addDocumentListener(this);

        xmlFileFilter = new FileFilter() {

            public boolean accept(File file) {
                if (file.isDirectory()) {
                    return true;
                }
                String path = file.getPath().toLowerCase();
                return (path.endsWith(".xml.gz") ||
                        path.endsWith(".pau.gz") ||
                        path.endsWith(".pau"));
            }

            public String getDescription() {
                return STRINGS.getString("PaukerFileFilter_Description");
            }
        };
        csvFileFilter = new FileFilter() {

            public boolean accept(File file) {
                if (file.isDirectory()) {
                    return true;
                }
                return file.getPath().toLowerCase().endsWith(".csv");
            }

            public String getDescription() {
                return STRINGS.getString("CSVFileFilter_Description");
            }
        };

        openFileDialog = new OpenFileDialog(this, xmlFileFilter, csvFileFilter);
        int openFileDialogWidth =
                preferences.getInt("OPEN_FILE_DIALOG_WIDTH", -1);
        int openFileDialogHeigth =
                preferences.getInt("OPEN_FILE_DIALOG_HEIGTH", -1);
        if ((openFileDialogWidth != -1) && (openFileDialogHeigth != -1)) {
            openFileDialog.setSize(openFileDialogWidth, openFileDialogHeigth);
        }

        saveFileChooser = new JFileChooser();
        saveFileChooser.addChoosableFileFilter(xmlFileFilter);
        saveFileChooser.addChoosableFileFilter(csvFileFilter);
        saveFileChooser.setFileFilter(xmlFileFilter);
        FileChooserAccessory fileChooserAccessory = new FileChooserAccessory();
        saveFileChooser.setAccessory(fileChooserAccessory);
        saveFileChooser.addPropertyChangeListener(fileChooserAccessory);
        saveFileChooser.setFileView(new PaukerFileView());

        // activate help
        try {
            ClassLoader classLoader =
                    Thread.currentThread().getContextClassLoader();
            URL helpSetURL =
                    HelpSet.findHelpSet(classLoader, "pauker/help/HelpSet.hs");
            HelpSet helpSet = new HelpSet(classLoader, helpSetURL);
            helpbroker = helpSet.createHelpBroker();
        } catch (Exception exception) {
            logger.log(Level.SEVERE, "could not init Java help", exception);
        }

        Action focusTypingOKButtonAction = new AbstractAction() {

            public void actionPerformed(ActionEvent event) {
                typingOKButton.requestFocusInWindow();
            }
        };

        KeyStroke tabKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);

        InputMap inputMap = repeatingInsertTextArea.getInputMap();
        inputMap.put(tabKeyStroke, "tabAction");
        ActionMap actionMap = repeatingInsertTextArea.getActionMap();
        actionMap.put("tabAction", focusTypingOKButtonAction);

        // assemble reasonable sizes of statistics panel
        Dimension preferredStatisticSize = statisticPanel.getPreferredSize();
        statisticPanel.setMinimumSize(preferredStatisticSize);
        Dimension newSize = new Dimension(preferredStatisticSize);
        newSize.height = 220;
        statisticPanel.setPreferredSize(newSize);

        expirationTimer.start();

        pack();

        if (dividerLocation != -1) {
            int minimumDividerLocation = splitPane.getMinimumDividerLocation();
            int maximumDividerLocation = splitPane.getMaximumDividerLocation();
            if ((0 < dividerLocation) &&
                    (dividerLocation < minimumDividerLocation)) {
                splitPane.setDividerLocation(minimumDividerLocation);
            } else if ((maximumDividerLocation < dividerLocation)) {
                splitPane.setDividerLocation(maximumDividerLocation);
            } else {
                splitPane.setDividerLocation(dividerLocation);
            }
        }
    }


Generated by  Doxygen 1.6.0   Back to index