Search in sources :

Example 1 with OpenFile

use of com.tagtraum.perf.gcviewer.ctrl.action.OpenFile in project GCViewer by chewiebug.

the class GCViewerGuiController method copyPreferencesFromGui.

/**
     * Copies values that are stored in menu items into <code>GCPreferences</code> instance.
     * 
     * @param gui source to copy values from
     * @return <code>GCPreferences</code> with current values
     */
private GCPreferences copyPreferencesFromGui(GCViewerGui gui) {
    GCPreferences preferences = gui.getPreferences();
    for (Entry<String, JCheckBoxMenuItem> menuEntry : ((GCViewerGuiMenuBar) gui.getJMenuBar()).getViewMenuItems().entrySet()) {
        JCheckBoxMenuItem item = menuEntry.getValue();
        preferences.setGcLineProperty(item.getActionCommand(), item.getState());
    }
    preferences.setWindowWidth(gui.getWidth());
    preferences.setWindowHeight(gui.getHeight());
    preferences.setWindowX(gui.getX());
    preferences.setWindowY(gui.getY());
    OpenFile openFileAction = (OpenFile) gui.getActionMap().get(ActionCommands.OPEN_FILE.toString());
    if (openFileAction.getLastSelectedFiles().length != 0) {
        preferences.setLastFile(openFileAction.getLastSelectedFiles()[0].getAbsolutePath());
    }
    // recent files
    List<String> recentFileList = new LinkedList<String>();
    for (GCResourceGroup urlSet : ((GCViewerGuiMenuBar) gui.getJMenuBar()).getRecentGCResourcesModel().getResourceNameGroups()) {
        recentFileList.add(urlSet.getUrlGroupString());
    }
    preferences.setRecentFiles(recentFileList);
    return preferences;
}
Also used : GCResourceGroup(com.tagtraum.perf.gcviewer.view.model.GCResourceGroup) GCPreferences(com.tagtraum.perf.gcviewer.view.model.GCPreferences) OpenFile(com.tagtraum.perf.gcviewer.ctrl.action.OpenFile) LinkedList(java.util.LinkedList)

Example 2 with OpenFile

use of com.tagtraum.perf.gcviewer.ctrl.action.OpenFile in project GCViewer by chewiebug.

the class GCViewerGuiController method applyPreferences.

void applyPreferences(GCViewerGui gui, GCPreferences preferences) {
    // default visibility to be able to access it from unittests
    gui.setPreferences(preferences);
    if (preferences.isPropertiesLoaded()) {
        for (Entry<String, JCheckBoxMenuItem> menuEntry : ((GCViewerGuiMenuBar) gui.getJMenuBar()).getViewMenuItems().entrySet()) {
            JCheckBoxMenuItem item = menuEntry.getValue();
            item.setState(preferences.getGcLineProperty(menuEntry.getKey()));
        // TODO necessary? state is set above; no GCDocument open at this moment
        //viewMenuActionListener.actionPerformed(new ActionEvent(item, 0, item.getActionCommand()));
        }
        gui.setBounds(preferences.getWindowX(), preferences.getWindowY(), preferences.getWindowWidth(), preferences.getWindowHeight());
        String lastfile = preferences.getLastFile();
        if (lastfile != null) {
            ((OpenFile) gui.getActionMap().get(ActionCommands.OPEN_FILE.toString())).setSelectedFile(new File(lastfile));
        }
        // recent files (add in reverse order, so that the order in recentMenu is correct
        List<String> recentFiles = preferences.getRecentFiles();
        for (int i = recentFiles.size() - 1; i >= 0; --i) {
            String filename = recentFiles.get(i);
            if (filename.length() > 0) {
                ((GCViewerGuiMenuBar) gui.getJMenuBar()).getRecentGCResourcesModel().add(filename);
            }
        }
    } else {
        gui.setBounds(0, 0, 800, 600);
    }
}
Also used : OpenFile(com.tagtraum.perf.gcviewer.ctrl.action.OpenFile) OpenFile(com.tagtraum.perf.gcviewer.ctrl.action.OpenFile) File(java.io.File)

Aggregations

OpenFile (com.tagtraum.perf.gcviewer.ctrl.action.OpenFile)2 GCPreferences (com.tagtraum.perf.gcviewer.view.model.GCPreferences)1 GCResourceGroup (com.tagtraum.perf.gcviewer.view.model.GCResourceGroup)1 File (java.io.File)1 LinkedList (java.util.LinkedList)1