MainFrame.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*
* Copyright 1998-2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/**
* A main window container for an application which glues together multiple sets
* of functionality (called Views) into a whole with a single menu bar,
* status bar, and search functionality.
* @see View
*/
public StatusBar() {
super(new BorderLayout());
data.setLabelFor(this);
}
data.setToolTipText(s);
// Force a relayout to avoid truncating text if longer
invalidate();
validate();
}
}
}
/**
* The panel with the Find control
*/
private JTextField text;
public void actionPerformed(ActionEvent e) {
}
public FindPanel() {
button.addActionListener(this);
text.addActionListener(this);
}
}
// Handler for the File->Exit menu item
class ExitAction extends MnemonicAction {
public ExitAction() {
}
public void actionPerformed(ActionEvent e) {
setVisible(false);
dispose();
}
}
// Handler for Edit->Create menu item
class CreateAction extends MnemonicAction {
public CreateAction() {
}
public void actionPerformed(ActionEvent e) {
}
}
// Handler for the Edit->Delete menu item
class DeleteAction extends MnemonicAction {
public DeleteAction() {
}
public void actionPerformed(ActionEvent e) {
}
}
// Handler for the Edit->Duplicate menu item
class DuplicateAction extends MnemonicAction {
public DuplicateAction() {
}
public void actionPerformed(ActionEvent e) {
}
}
// Handler for the Edit->Properties menu item
class PropertiesAction extends MnemonicAction {
public PropertiesAction() {
}
public void actionPerformed(ActionEvent e) {
}
}
// Handler for the View->Update menu item
class UpdateAction extends MnemonicAction {
public UpdateAction() {
}
public void actionPerformed(ActionEvent e) {
}
}
// Listener for selection events from the views
class ViewSelectionListener implements SelectionListener {
public void valueChanged() {
// Set menu item state on edit menu
if (i == 2) {
// Duplicate can only be active for a single selection
&& !activeView.isSelectionMultiple());
} else {
}
}
}
}
public static final int FILE_MENU = 0;
public static final int EDIT_MENU = 1;
public static final int VIEW_MENU = 2;
public static final int ACTIONS_MENU = 3;
public static final int HELP_MENU = 4;
public static final int MENU_COUNT = 5;
// The set of menus for the application
"actions_menu", "help_menu" };
/*
* Table of all the menu actions owned by MainFrame; some end up
* delegating to the View.
*/
private Action [] [] menuActions = {
// File Menu
{ new ExitAction() },
// Edit Menu
new PropertiesAction() },
// View Menu
{ new UpdateAction() },
// Actions Menu
{ },
// Help Menu
{ }
};
private JTabbedPane displayPanel;
private int [] separatorIndex = new int[MENU_COUNT];
private ViewSelectionListener viewSelectionListener =
new ViewSelectionListener();
private boolean initialized = false;
public MainFrame() {
this("");
}
super(title);
// Create basic menu structure
// First the menus
}
// Now the items on each menu
}
}
// separatorIndex will remember where we automatically put separators
for (int i = 0; i < MENU_COUNT; ++i) {
separatorIndex[i] = -1;
}
// Status bar for messages
// Display panel is the area for the view's main display
displayPanel = new JTabbedPane();
public void stateChanged(ChangeEvent e) {
/*
* Prevent premature activation of a view which would otherwise
* happen as a byproduct of adding views to the tabbed pane.
*/
if (initialized) {
try {
} catch (Throwable t) {
t.printStackTrace();
}
}
}
});
activeView = null;
}
public static String getStatusText() {
}
}
// Add a global menu
}
// Add a view to the system
views.addElement(v);
if (isInitial) {
initialView = v;
}
/*
* Listen to selection events from the view, update menu state
* accordingly
*/
}
// Delete a view
public void deleteView(View v) {
views.removeElement(v);
/*
* If we're deleting the currently active view, need to activate
* another one; default to the initial view, unless that is also
* the one we're deleting, in which case just pick the first view.
*/
if (v == activeView) {
if (v != initialView) {
} else {
}
}
}
// Select the view to be shown
public void setActiveView(View v) {
if (activeView != null) {
activeView.setActive(false);
}
// Remove custom menus from existing active view
}
/*
* Remove menu items on standard menus from existing active view,
* add those from new view
*/
if (activeView != null) {
if (e != null) {
if (separatorIndex[i] != -1) {
m.remove(separatorIndex[i]);
separatorIndex[i] = -1;
}
while (e.hasMoreElements()) {
}
}
}
}
Enumeration e = v.menuItems(i);
if (e != null) {
while (e.hasMoreElements()) {
/*
* This test here so separator is only added if we
* actually get a menu item from the view, protecting
* against an empty enumeration causing a stray separator.
*/
if (separatorIndex[i] == -1) {
separatorIndex[i] = m.getItemCount();
m.addSeparator();
}
}
}
}
}
// Add view's menus
Enumeration e = v.menus();
while ((e != null) && e.hasMoreElements()) {
if (m != null) {
}
}
activeView = v;
activeView.setActive(true);
invalidate();
validate();
}
// Call this to get things started
public void initialize() {
if (initialView != null) {
initialized = true;
}
}
}
// Refresh all views, including those not currently active
public void refreshAllViews() {
v.handleUpdate();
}
}
}