/* * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.max.ins; import java.awt.*; import javax.swing.*; import com.sun.max.ins.gui.*; import com.sun.max.ins.view.*; import com.sun.max.ins.view.InspectionViews.ViewKind; import com.sun.max.program.*; /** * A singleton view that displays the different aspects of current user focus. * Intended for Inspector testing. */ public final class UserFocusView extends AbstractView<UserFocusView> { private static final ViewKind VIEW_KIND = ViewKind.USER_FOCUS; private static final String SHORT_NAME = "User Focus"; private static final String LONG_NAME = "User Focus View"; private static final String GEOMETRY_SETTINGS_KEY = "userFocusViewGeometry"; public static final class UserFocusViewManager extends AbstractSingletonViewManager<UserFocusView> { protected UserFocusViewManager(Inspection inspection) { super(inspection, VIEW_KIND, SHORT_NAME, LONG_NAME); } @Override protected UserFocusView createView(Inspection inspection) { return new UserFocusView(inspection); } } // Will be non-null before any instances created. private static UserFocusViewManager viewManager = null; public static UserFocusViewManager makeViewManager(Inspection inspection) { if (viewManager == null) { viewManager = new UserFocusViewManager(inspection); } return viewManager; } // This is a singleton viewer, so only use a single level of view preferences. private final FocusTable.FocusViewPreferences viewPreferences; private FocusTable table; private UserFocusView(Inspection inspection) { super(inspection, VIEW_KIND, GEOMETRY_SETTINGS_KEY); Trace.begin(1, tracePrefix() + " initializing"); viewPreferences = FocusTable.FocusViewPreferences.globalPreferences(inspection); createFrame(true); Trace.end(1, tracePrefix() + " initializing"); } @Override public String getTextForTitle() { return viewManager.shortName(); } @Override protected InspectorTable getTable() { return table; } @Override protected void createViewContent() { table = new FocusTable(inspection(), this, viewPreferences); forceRefresh(); JTableColumnResizer.adjustColumnPreferredWidths(table); final JPanel panel = new JPanel(new BorderLayout()); panel.add(table.getTableHeader(), BorderLayout.NORTH); panel.add(table, BorderLayout.CENTER); setContentPane(panel); focus().addListener(table); // Populate menu bar makeMenu(MenuKind.DEFAULT_MENU).add(defaultMenuItems(MenuKind.DEFAULT_MENU)); final InspectorMenu memoryMenu = makeMenu(MenuKind.MEMORY_MENU); memoryMenu.add(defaultMenuItems(MenuKind.MEMORY_MENU)); memoryMenu.add(views().activateSingletonViewAction(ViewKind.ALLOCATIONS)); makeMenu(MenuKind.VIEW_MENU).add(defaultMenuItems(MenuKind.VIEW_MENU)); } @Override protected void refreshState(boolean force) { table.refresh(force); } @Override public InspectorAction getPrintAction() { return getDefaultPrintAction(); } public void tableColumnViewPreferencesChanged() { reconstructView(); } @Override public void viewClosing() { focus().removeListener(table); super.viewClosing(); } }