/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
/**
* Provides the metal look and feel implementation of <code>RootPaneUI</code>.
* <p>
* <code>MetalRootPaneUI</code> provides support for the
* <code>windowDecorationStyle</code> property of <code>JRootPane</code>.
* <code>MetalRootPaneUI</code> does this by way of installing a custom
* <code>LayoutManager</code>, a private <code>Component</code> to render
* the appropriate widgets, and a private <code>Border</code>. The
* <code>LayoutManager</code> is always installed, regardless of the value of
* the <code>windowDecorationStyle</code> property, but the
* the <code>windowDecorationStyle</code> is other than
* <code>JRootPane.NONE</code>.
* <p>
* <strong>Warning:</strong>
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans<sup><font size="-2">TM</font></sup>
* has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*
* @author Terry Kellerman
* @since 1.4
*/
{
/**
* Keys to lookup borders in defaults table.
*/
"RootPane.informationDialogBorder",
"RootPane.errorDialogBorder", "RootPane.colorChooserDialogBorder",
"RootPane.fileChooserDialogBorder", "RootPane.questionDialogBorder",
"RootPane.warningDialogBorder"
};
/**
* The amount of space (in pixels) that the cursor is changed on.
*/
/**
* Region from edges that dragging is active from.
*/
/**
* Window the <code>JRootPane</code> is in.
*/
/**
* <code>JComponent</code> providing window decorations. This will be
* null if not providing window decorations.
*/
/**
* <code>MouseInputListener</code> that is added to the parent
* <code>Window</code> the <code>JRootPane</code> is contained in.
*/
/**
* The <code>LayoutManager</code> that is set on the
* <code>JRootPane</code>.
*/
/**
* <code>LayoutManager</code> of the <code>JRootPane</code> before we
* replaced it.
*/
/**
* <code>JRootPane</code> providing the look and feel for.
*/
/**
* <code>Cursor</code> used to track the cursor set by the user.
* This is initially <code>Cursor.DEFAULT_CURSOR</code>.
*/
/**
* Creates a UI for a <code>JRootPane</code>.
*
* @param c the JRootPane the RootPaneUI will be created for
* @return the RootPaneUI implementation for the passed in JRootPane
*/
return new MetalRootPaneUI();
}
/**
* Invokes supers implementation of <code>installUI</code> to install
* the necessary state onto the passed in <code>JRootPane</code>
* to render the metal look and feel implementation of
* <code>RootPaneUI</code>. If
* the <code>windowDecorationStyle</code> property of the
* <code>JRootPane</code> is other than <code>JRootPane.NONE</code>,
* this will add a custom <code>Component</code> to render the widgets to
* <code>JRootPane</code>, as well as installing a custom
* <code>Border</code> and <code>LayoutManager</code> on the
* <code>JRootPane</code>.
*
* @param c the JRootPane to install state onto
*/
super.installUI(c);
}
}
/**
* Invokes supers implementation to uninstall any of its state. This will
* also reset the <code>LayoutManager</code> of the <code>JRootPane</code>.
* If a <code>Component</code> has been added to the <code>JRootPane</code>
* to render the window decoration style, this method will remove it.
* Similarly, this will revert the Border and LayoutManager of the
* <code>JRootPane</code> to what it was before <code>installUI</code>
* was invoked.
*
* @param c the JRootPane to uninstall state from
*/
super.uninstallUI(c);
}
/**
* Installs the appropriate <code>Border</code> onto the
* <code>JRootPane</code>.
*/
}
else {
}
}
/**
* Removes any border that may have been installed.
*/
}
/**
* Installs the necessary Listeners on the parent <code>Window</code>,
* if there is one.
* <p>
* This takes the parent so that cleanup can be done from
* <code>removeNotify</code>, at which point the parent hasn't been
* reset yet.
*
* @param parent The parent of the JRootPane
*/
}
else {
}
if (mouseInputListener == null) {
}
}
}
/**
* Uninstalls the necessary Listeners on the <code>Window</code> the
* Listeners were last installed on.
*/
}
}
/**
* Installs the appropriate LayoutManager on the <code>JRootPane</code>
* to render the window decorations.
*/
if (layoutManager == null) {
}
}
/**
* Uninstalls the previously installed <code>LayoutManager</code>.
*/
if (savedOldLayout != null) {
}
}
/**
* Installs the necessary state onto the JRootPane to render client
* decorations. This is ONLY invoked if the <code>JRootPane</code>
* has a decoration style other than <code>JRootPane.NONE</code>.
*/
root.revalidate();
}
}
/**
* Uninstalls any state that <code>installClientDecorations</code> has
* installed.
* <p>
* NOTE: This may be called if you haven't installed client decorations
* yet (ie before <code>installClientDecorations</code> has been invoked).
*/
// We have to revalidate/repaint root if the style is JRootPane.NONE
// only. When we needs to call revalidate/repaint with other styles
// the installClientDecorations is always called after this method
// imediatly and it will cause the revalidate/repaint at the proper
// time.
root.revalidate();
}
// Reset the cursor, as we may have changed it to a resize cursor
(Cursor.DEFAULT_CURSOR));
}
}
/**
* Returns the <code>JComponent</code> to render the window decoration
* style.
*/
return new MetalTitlePane(root, this);
}
/**
* Returns a <code>MouseListener</code> that will be added to the
* <code>Window</code> containing the <code>JRootPane</code>.
*/
return new MouseInputHandler();
}
/**
* Returns a <code>LayoutManager</code> that will be set on the
* <code>JRootPane</code>.
*/
return new MetalRootLayout();
}
/**
* Sets the window title pane -- the JComponent used to provide a plaf a
* way to override the native operating system's window title pane with
* one whose look and feel are controlled by the plaf. The plaf creates
* and sets this value; the default is null, implying a native operating
* system window title pane.
*
* @param content the <code>JComponent</code> to use for the window title pane.
*/
if (oldTitlePane != null) {
oldTitlePane.setVisible(false);
}
titlePane.setVisible(true);
}
}
/**
* Returns the <code>JComponent</code> rendering the title pane. If this
* returns null, it implies there is no need to render window decorations.
*
* @return the current window title pane, or null
* @see #setTitlePane
*/
return titlePane;
}
/**
* Returns the <code>JRootPane</code> we're providing the look and
* feel for.
*/
return root;
}
/**
* Invoked when a property changes. <code>MetalRootPaneUI</code> is
* primarily interested in events originating from the
* <code>JRootPane</code> it has been installed on identifying the
* property <code>windowDecorationStyle</code>. If the
* <code>windowDecorationStyle</code> has changed to a value other
* than <code>JRootPane.NONE</code>, this will add a <code>Component</code>
* to the <code>JRootPane</code> to render the window decorations, as well
* as installing a <code>Border</code> on the <code>JRootPane</code>.
* On the other hand, if the <code>windowDecorationStyle</code> has
* changed to <code>JRootPane.NONE</code>, this will remove the
* <code>Component</code> that has been added to the <code>JRootPane</code>
* as well resetting the Border to what it was before
* <code>installUI</code> was invoked.
*
* @param e A PropertyChangeEvent object describing the event source
* and the property that has changed.
*/
super.propertyChange(e);
if(propertyName == null) {
return;
}
// This is potentially more than needs to be done,
// simpler. MetalTitlePane also assumes it will be recreated if
// the decoration style changes.
}
}
}
}
return;
}
/**
* A custom layout manager that is responsible for the layout of
* layeredPane, glassPane, menuBar and titlePane, if one has been
* installed.
*/
// NOTE: Ideally this would extends JRootPane.RootLayout, but that
// would force this to be non-static.
/**
* Returns the amount of space the layout would like to have.
*
* @param the Container for which this layout manager is being used
* @return a Dimension object containing the layout's preferred size
*/
int cpWidth = 0;
int cpHeight = 0;
int mbWidth = 0;
int mbHeight = 0;
int tpWidth = 0;
int tpHeight = 0;
} else {
}
}
}
}
getTitlePane();
}
}
}
}
/**
* Returns the minimum amount of space the layout needs.
*
* @param the Container for which this layout manager is being used
* @return a Dimension object containing the layout's minimum size
*/
int cpWidth = 0;
int cpHeight = 0;
int mbWidth = 0;
int mbHeight = 0;
int tpWidth = 0;
int tpHeight = 0;
} else {
}
}
}
}
getTitlePane();
}
}
}
}
/**
* Returns the maximum amount of space the layout can use.
*
* @param the Container for which this layout manager is being used
* @return a Dimension object containing the layout's maximum size
*/
}
}
}
}
getTitlePane();
{
}
}
}
// Only overflows if 3 real non-MAX_VALUE heights, sum to > MAX_VALUE
// Only will happen if sums to more than 2 billion units. Not likely.
}
// Similar overflow comment as above
}
}
/**
* Instructs the layout manager to perform the layout for the specified
* container.
*
* @param the Container for which this layout manager is being used
*/
int nextY = 0;
}
}
// Note: This is laying out the children in the layeredPane,
// technically, these are not our children.
getTitlePane();
}
}
}
}
}
}
}
/**
* Maps from positions to cursor type. Refer to calculateCorner and
* calculatePosition for details of this.
*/
private static final int[] cursorMapping = new int[]
};
/**
* the Window. It sets the cursor directly on the Window when then
* mouse moves over a hot spot.
*/
/**
* Set to true if the drag operation is moving the window.
*/
private boolean isMovingWindow;
/**
* Used to determine the corner the resize is occuring from.
*/
private int dragCursor;
/**
* X location the mouse went down on for a drag operation.
*/
private int dragOffsetX;
/**
* Y location the mouse went down on for a drag operation.
*/
private int dragOffsetY;
/**
* Width of the window when the drag started.
*/
private int dragWidth;
/**
* Height of the window when the drag started.
*/
private int dragHeight;
return;
}
if (w != null) {
w.toFront();
}
w, dragWindowOffset, getTitlePane());
if (w instanceof Frame) {
f = (Frame)w;
} else if (w instanceof Dialog) {
d = (Dialog)w;
}
if (getTitlePane() != null &&
|| (d != null))
&& dragWindowOffset.x < w.getWidth()
isMovingWindow = true;
}
}
else if (f != null && f.isResizable()
|| (d != null && d.isResizable())) {
dragHeight = w.getHeight();
w, dragWindowOffset.x, dragWindowOffset.y));
}
}
// Some Window systems validate as you resize, others won't,
// thus the check for validity before repainting.
getRootPane().repaint();
}
isMovingWindow = false;
dragCursor = 0;
}
return;
}
if (w instanceof Frame) {
f = (Frame)w;
} else if (w instanceof Dialog) {
d = (Dialog)w;
}
// Update the cursor
|| (d != null && d.isResizable()))) {
}
else {
w.setCursor(lastCursor);
}
}
if (deltaX != 0) {
bounds.x -= correction;
}
}
if (deltaY != 0) {
bounds.y -= correction;
}
}
}
}
if (isMovingWindow) {
}
else if (dragCursor != 0) {
switch (dragCursor) {
case Cursor.E_RESIZE_CURSOR:
r.width, 0);
break;
case Cursor.S_RESIZE_CURSOR:
r.height);
break;
case Cursor.N_RESIZE_CURSOR:
-(pt.y - dragOffsetY));
break;
case Cursor.W_RESIZE_CURSOR:
break;
case Cursor.NE_RESIZE_CURSOR:
-(pt.y - dragOffsetY));
break;
case Cursor.SE_RESIZE_CURSOR:
r.height);
break;
case Cursor.NW_RESIZE_CURSOR:
pt.y - dragOffsetY,
-(pt.x - dragOffsetX),
-(pt.y - dragOffsetY));
break;
case Cursor.SW_RESIZE_CURSOR:
-(pt.x - dragOffsetX),
break;
default:
break;
}
if (!r.equals(startBounds)) {
w.setBounds(r);
// layout is active.
w.validate();
getRootPane().repaint();
}
}
}
}
lastCursor = w.getCursor();
mouseMoved(ev);
}
w.setCursor(lastCursor);
}
if (w instanceof Frame) {
f = (Frame)w;
} else {
return;
}
int state = f.getExtendedState();
if (getTitlePane() != null &&
if (f.isResizable()) {
}
else {
}
return;
}
}
}
}
/**
* Returns the corner that contains the point <code>x</code>,
* <code>y</code>, or -1 if the position doesn't match a corner.
*/
return -1;
}
}
/**
* Returns the Cursor to render for the specified corner. This returns
* 0 if the corner doesn't map to a valid Cursor
*/
if (corner == -1) {
return 0;
}
return cursorMapping[corner];
}
/**
* Returns an integer indicating the position of <code>spot</code>
* in <code>width</code>. The return value will be:
* 0 if < BORDER_DRAG_THICKNESS
* 1 if < CORNER_DRAG_WIDTH
* 2 if >= CORNER_DRAG_WIDTH && < width - BORDER_DRAG_THICKNESS
* 3 if >= width - CORNER_DRAG_WIDTH
* 4 if >= width - BORDER_DRAG_THICKNESS
* 5 otherwise
*/
if (spot < BORDER_DRAG_THICKNESS) {
return 0;
}
if (spot < CORNER_DRAG_WIDTH) {
return 1;
}
return 4;
}
return 3;
}
return 2;
}
}
}