|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.core.windows.view.ui; import org.netbeans.core.windows.Constants; import org.netbeans.core.windows.ModeImpl; import org.netbeans.core.windows.WindowManagerImpl; import org.openide.ErrorManager; import org.openide.LifecycleManager; import org.openide.awt.MenuBar; import org.openide.awt.ToolbarPool; import org.openide.cookies.InstanceCookie; import org.openide.filesystems.FileObject; import org.openide.filesystems.Repository; import org.openide.loaders.DataObject; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; import org.openide.util.Utilities; import javax.swing.*; import javax.swing.border.Border; import javax.swing.border.EmptyBorder; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.Arrays; import java.util.Locale; import org.openide.windows.TopComponent; /** The MainWindow of IDE. Holds toolbars, main menu and also entire desktop * if in MDI user interface. Singleton. * This class is final only for performance reasons, can be unfinaled * if desired. * * @author Ian Formanek, Petr Hamernik */ public final class MainWindow extends JFrame { /** generated Serialized Version UID */ static final long serialVersionUID = -1160791973145645501L; /** Desktop. */ private Component desktop; /** Inner panel which contains desktop component */ private JPanel desktopPanel; /** Flag indicating main window is initialized. */ private boolean inited; /** Constructs main window. */ public MainWindow() { // ignore the policy - #46922 // setFocusTraversalPolicy(new WrapperFocusTraversalPolicy(getFocusTraversalPolicy())); } /** Overrides superclass method, adds help context to the new root pane. */ protected void setRootPane(JRootPane root) { super.setRootPane(root); if(root != null) { HelpCtx.setHelpIDString( root, new HelpCtx(MainWindow.class).getHelpID()); } //Optimization related to jdk bug 4939857 - on pre 1.5 jdk's an //extra repaint is caused by the search for an opaque component up //to the component root. Post 1.5, root pane will automatically be //opaque. root.setOpaque(true); if (Utilities.isWindows()) { // use glass pane that will not cause repaint/revalidate of parent when set visible // is called (when setting wait cursor in ModuleActions) #40689 JComponent c = new JPanel() { public void setVisible(boolean flag) { if (flag != isVisible ()) { super.setVisible(flag); } } }; c.setName(root.getName()+".nbGlassPane"); // NOI18N c.setVisible(false); ((JPanel)c).setOpaque(false); root.setGlassPane(c); } } /** Initializes main window. */ public void initializeComponents() { if(inited) { return; } inited = true; // initialize frame setIconImage(createIDEImage()); initListeners(); setDefaultCloseOperation (DO_NOTHING_ON_CLOSE); getAccessibleContext().setAccessibleDescription( NbBundle.getBundle(MainWindow.class).getString("ACSD_MainWindow")); setJMenuBar(createMenuBar()); if (!Constants.NO_TOOLBARS) { JComponent tb = getToolbarComponent(); getContentPane().add(tb, BorderLayout.NORTH); } if(!Constants.SWITCH_STATUSLINE_IN_MENUBAR) { if (Constants.CUSTOM_STATUS_LINE_PATH == null) { JLabel status = new StatusLine(); // XXX #19910 Not to squeeze status line. status.setText(" "); // NOI18N status.setPreferredSize(new Dimension(0, status.getPreferredSize().height)); JPanel panel = new JPanel(new BorderLayout()); panel.add(new JSeparator(), BorderLayout.NORTH); panel.add(status, BorderLayout.CENTER); panel.setName("statusLine"); //NOI18N getContentPane().add(panel, BorderLayout.SOUTH); } else { // custom status line provided JComponent status = getCustomStatusLine(); if (status != null) { getContentPane().add(status, BorderLayout.SOUTH); } } } // initialize desktop panel desktopPanel = new JPanel(); desktopPanel.setBorder(getDesktopBorder()); desktopPanel.setLayout(new BorderLayout()); Color fillC = (Color)UIManager.get("nb_workplace_fill"); //NOI18N if (fillC != null) { desktopPanel.setBackground(fillC); } getContentPane().add(desktopPanel, BorderLayout.CENTER); //#38810 start - focusing the main window in case it's not active and the menu is // selected.. MenuSelectionManager.defaultManager().addChangeListener(new ChangeListener(){ public void stateChanged(ChangeEvent e) { MenuElement[] elems = MenuSelectionManager.defaultManager().getSelectedPath(); if (elems != null && elems.length > 0) { if (elems[0] == getJMenuBar()) { if (!isActive()) { toFront(); } } } } }); //#38810 end } private boolean hackFirst = Boolean.getBoolean("netbeans.winsys.flashhack"); //NOI18N /** Workaround for main window flashing during startup problem on Windows. * Depends on the main window being laid out twice during startup, so may * not be safe enough for producting use, but including for testing. Can't * find any platform it causes a problem on thus far. */ public void doLayout() { if (hackFirst) { hackFirst = false; return; } super.doLayout(); } /** Creates and returns border for desktop which is visually aligned * with currently active LF */ private static Border getDesktopBorder () { Border b = (Border) UIManager.get ("nb.desktop.splitpane.border"); if (b != null) { return b; } else { return new EmptyBorder(1, 1, 1, 1); } } static Image createIDEImage() { return Toolkit.getDefaultToolkit ().getImage ( NbBundle.getLocalizedFile( "org.netbeans.core.resources.frames.ide" // NOI18N + (org.openide.util.Utilities.isLargeFrameIcons() ? "32" : ""), // NOI18N "gif", // NOI18N Locale.getDefault(), MainWindow.class.getClassLoader() ) ); } private void initListeners() { addWindowListener (new WindowAdapter() { public void windowClosing(WindowEvent evt) { LifecycleManager.getDefault().exit(); } public void windowActivated (WindowEvent evt) { // #19685. Cancel foreigner popup when // activated main window. org.netbeans.core.windows.RegistryImpl.cancelMenu(MainWindow.this); } } ); } /** Creates menu bar. */ private static JMenuBar createMenuBar() { JMenuBar menu = getCustomMenuBar(); if (menu == null) { menu = new MenuBar (null); } menu.setBorderPainted(false); if (menu instanceof MenuBar) { ((MenuBar)menu).waitFinished(); } if(Constants.SWITCH_STATUSLINE_IN_MENUBAR) { if (Constants.CUSTOM_STATUS_LINE_PATH == null) { JLabel status = new StatusLine(); JPanel panel = new JPanel(new BorderLayout()); JSeparator sep = new JSeparator(JSeparator.VERTICAL); Dimension d = sep.getPreferredSize(); d.width += 6; // need a bit more padding... sep.setPreferredSize(d); panel.add(sep, BorderLayout.WEST); panel.add(status, BorderLayout.CENTER); panel.setName("statusLine"); //NOI18N menu.add(panel); } else { JComponent status = getCustomStatusLine(); if (status != null) { menu.add(status); } } } return menu; } /** * Tries to find custom menu bar component on system file system. * @return menu bar component or |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.