Search in sources :

Example 1 with GCResourceGroup

use of com.tagtraum.perf.gcviewer.view.model.GCResourceGroup in project GCViewer by chewiebug.

the class GCDocument method relayout.

/**
     * Relayouts all chartPanelViews contained in this document. Should always be called, when
     * a change with the chartPanelViews happened (add / remove / minimize / maximize 
     * chartPanelView).
     */
public void relayout() {
    getContentPane().removeAll();
    String newTitle = "";
    if (chartPanelViews.size() > 0) {
        GCResourceGroup group = new GCResourceGroup(getGCResources());
        newTitle = group.getGroupStringShort();
    }
    setTitle(newTitle);
    int row = 0;
    boolean noMaximizedChartPanelView = true;
    ChartPanelView lastMaximizedChartPanelView = getLastMaximizedChartPanelView();
    MasterViewPortChangeListener masterViewPortChangeListener = new MasterViewPortChangeListener();
    for (int i = 0; i < chartPanelViews.size(); i++) {
        final ChartPanelView chartPanelView = chartPanelViews.get(i);
        final ModelChartImpl modelChart = (ModelChartImpl) chartPanelView.getModelChart();
        final ModelMetricsPanel modelMetricsPanel = chartPanelView.getModelMetricsPanel();
        final JTabbedPane modelChartAndDetails = chartPanelView.getModelChartAndDetails();
        modelChart.resetPolygonCache();
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.anchor = GridBagConstraints.NORTH;
        constraints.gridy = row;
        if (chartPanelViews.size() > 1 || (chartPanelView.isMinimized() && chartPanelViews.size() == 1)) {
            constraints.gridwidth = 2;
            constraints.weightx = 2;
            //constraints.weighty = 1;
            getContentPane().add(chartPanelView.getViewBar(), constraints);
            row++;
        }
        constraints.fill = GridBagConstraints.BOTH;
        constraints.gridy = row;
        constraints.gridwidth = 1;
        //2
        constraints.gridheight = 1;
        constraints.gridx = 0;
        constraints.weightx = 2;
        constraints.weighty = 2;
        modelChart.setPreferredSize(new Dimension(800, 600));
        modelChartAndDetails.setVisible(!chartPanelView.isMinimized());
        getContentPane().add(modelChartAndDetails, constraints);
        constraints.gridy = row;
        constraints.gridheight = 1;
        constraints.gridx = 1;
        constraints.weightx = 0;
        constraints.weighty = 0;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.anchor = GridBagConstraints.SOUTH;
        getContentPane().add(modelMetricsPanel, constraints);
        modelMetricsPanel.setVisible(showModelMetricsPanel && (!chartPanelView.isMinimized()));
        if (!chartPanelView.isMinimized()) {
            noMaximizedChartPanelView = false;
            final boolean isLastMaximizedChartPanelView = lastMaximizedChartPanelView == chartPanelView;
            // lock viewports with each other...
            // remove old master listeners
            final JViewport viewport = modelChart.getViewport();
            lockChartsToOneScrollbar(viewport, isLastMaximizedChartPanelView, modelChart, masterViewPortChangeListener);
            final JScrollBar horizontalScrollBar = modelChart.getHorizontalScrollBar();
            // clean old change listeners
            ChangeListener[] changeListeners = ((DefaultBoundedRangeModel) horizontalScrollBar.getModel()).getChangeListeners();
            for (int j = 0; j < changeListeners.length; j++) {
                if (changeListeners[j] instanceof ScrollBarMaximumChangeListener) {
                    horizontalScrollBar.getModel().removeChangeListener(changeListeners[j]);
                }
            }
            if (isLastMaximizedChartPanelView && isWatched()) {
                horizontalScrollBar.getModel().addChangeListener(new ScrollBarMaximumChangeListener());
            }
            if (isLastMaximizedChartPanelView) {
                horizontalScrollBar.setEnabled(!isWatched());
            }
        }
        row++;
    }
    if (noMaximizedChartPanelView) {
        // add dummy panel
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.fill = GridBagConstraints.BOTH;
        constraints.gridy = row;
        constraints.weightx = 3;
        constraints.weighty = 3;
        getContentPane().add(new JPanel(), constraints);
    }
    scaleModelChart();
    invalidate();
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) GCResourceGroup(com.tagtraum.perf.gcviewer.view.model.GCResourceGroup) JViewport(javax.swing.JViewport) JTabbedPane(javax.swing.JTabbedPane) Dimension(java.awt.Dimension) Point(java.awt.Point) DefaultBoundedRangeModel(javax.swing.DefaultBoundedRangeModel) JScrollBar(javax.swing.JScrollBar) PropertyChangeListener(java.beans.PropertyChangeListener) ChangeListener(javax.swing.event.ChangeListener)

Example 2 with GCResourceGroup

use of com.tagtraum.perf.gcviewer.view.model.GCResourceGroup 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)

Aggregations

GCResourceGroup (com.tagtraum.perf.gcviewer.view.model.GCResourceGroup)2 OpenFile (com.tagtraum.perf.gcviewer.ctrl.action.OpenFile)1 GCPreferences (com.tagtraum.perf.gcviewer.view.model.GCPreferences)1 Dimension (java.awt.Dimension)1 GridBagConstraints (java.awt.GridBagConstraints)1 Point (java.awt.Point)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 LinkedList (java.util.LinkedList)1 DefaultBoundedRangeModel (javax.swing.DefaultBoundedRangeModel)1 JPanel (javax.swing.JPanel)1 JScrollBar (javax.swing.JScrollBar)1 JTabbedPane (javax.swing.JTabbedPane)1 JViewport (javax.swing.JViewport)1 ChangeListener (javax.swing.event.ChangeListener)1