📄 skinrootpaneui.java
字号:
}
/**
* Returns the <code>JComponent</code> to render the window decoration
* style.
*/
private JComponent createTitlePane(JRootPane root) {
JComponent titlePane =
new SkinTitlePane(title = new Window.FrameWindow()) {
// overriden to set the popup to not be lightweight. it
// resulted in the popupmenu being hidden, not correctly
// z-ordered. Using a JWindow does the trick
protected JMenu createSystemMenu() {
JMenu menu = new JMenu(" ");
menu.getPopupMenu().setLightWeightPopupEnabled(false);
return menu;
}
};
titlePane.setOpaque(false);
return titlePane;
}
/**
* Returns a <code>MouseListener</code> that will be added to the <code>Window</code>
* containing the <code>JRootPane</code>.
*/
private MouseInputListener createWindowMouseInputListener(JRootPane root) {
return new MouseInputHandler();
}
/**
* Returns a <code>LayoutManager</code> that will be set on the <code>JRootPane</code>.
*/
private LayoutManager createLayoutManager() {
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.
*/
private void setTitlePane(JRootPane root, JComponent titlePane) {
JLayeredPane layeredPane = root.getLayeredPane();
JComponent oldTitlePane = getTitlePane();
if (oldTitlePane != null) {
oldTitlePane.setVisible(false);
layeredPane.remove(oldTitlePane);
}
if (titlePane != null) {
layeredPane.add(titlePane, JLayeredPane.FRAME_CONTENT_LAYER);
titlePane.setVisible(true);
}
this.titlePane = (SkinTitlePane)titlePane;
}
/**
* 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
*/
private JComponent getTitlePane() {
return titlePane;
}
private Window.FrameWindow getFrameWindow() {
return title;
}
private java.awt.Window getMainWindow() {
return window;
}
/**
* Returns the <code>JRootPane</code> we're providing the look and feel
* for.
*/
private JRootPane getRootPane() {
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.
*/
public void propertyChange(PropertyChangeEvent e) {
super.propertyChange(e);
String propertyName = e.getPropertyName();
if (propertyName == null) {
return;
}
if (propertyName.equals("windowDecorationStyle")) {
JRootPane root = (JRootPane)e.getSource();
int style = getWindowDecorationStyle(root);
// This is potentially more than needs to be done,
// but it rarely happens and makes the install/uninstall process
// simpler. MetalTitlePane also assumes it will be recreated if
// the decoration style changes.
uninstallClientDecorations(root);
if (style != JRootPane_NONE) {
installClientDecorations(root);
}
} else if (propertyName.equals("ancestor")) {
uninstallWindowListeners(root);
if (getWindowDecorationStyle((JRootPane)e.getSource())
!= JRootPane_NONE) {
installWindowListeners(root, root.getParent());
}
}
return;
}
public static void adjust(
Rectangle bounds,
Dimension min,
int deltaX,
int deltaY,
int deltaWidth,
int deltaHeight) {
bounds.x += deltaX;
bounds.y += deltaY;
bounds.width += deltaWidth;
bounds.height += deltaHeight;
if (min != null) {
if (bounds.width < min.width) {
int correction = min.width - bounds.width;
if (deltaX != 0) {
bounds.x -= correction;
}
bounds.width = min.width;
}
if (bounds.height < min.height) {
int correction = min.height - bounds.height;
if (deltaY != 0) {
bounds.y -= correction;
}
bounds.height = min.height;
}
}
}
/**
* Returns the corner that contains the point <code>x</code>,<code>y</code>,
* or -1 if the position doesn't match a corner.
*/
public static int calculateCorner(Component c, int x, int y) {
int xPosition = calculatePosition(x, c.getWidth());
int yPosition = calculatePosition(y, c.getHeight());
if (xPosition == -1 || yPosition == -1) {
return -1;
}
return yPosition * 5 + xPosition;
}
/**
* Returns the Cursor to render for the specified corner. This returns 0 if
* the corner doesn't map to a valid Cursor
*/
public static int getCursor(int corner) {
if (corner == -1) {
return 0;
}
return SkinRootPaneUI.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
*/
public static int calculatePosition(int spot, int width) {
if (spot < SkinRootPaneUI.BORDER_DRAG_THICKNESS) {
return 0;
}
if (spot < SkinRootPaneUI.CORNER_DRAG_WIDTH) {
return 1;
}
if (spot >= (width - SkinRootPaneUI.BORDER_DRAG_THICKNESS)) {
return 4;
}
if (spot >= (width - SkinRootPaneUI.CORNER_DRAG_WIDTH)) {
return 3;
}
return 2;
}
/**
* 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.
private static class MetalRootLayout implements LayoutManager2 {
/**
* Returns the amount of space the layout would like to have.
*
* @param parent the Container for which this layout manager is being used
* @return a Dimension object containing the layout's preferred size
*/
public Dimension preferredLayoutSize(Container parent) {
Dimension cpd, mbd, tpd;
int cpWidth = 0;
int cpHeight = 0;
int mbWidth = 0;
int mbHeight = 0;
int tpWidth = 0;
int tpHeight = 0;
Insets i = parent.getInsets();
JRootPane root = (JRootPane)parent;
if (root.getContentPane() != null) {
cpd = root.getContentPane().getPreferredSize();
} else {
cpd = root.getSize();
}
if (cpd != null) {
cpWidth = cpd.width;
cpHeight = cpd.height;
}
if (root.getJMenuBar() != null) {
mbd = root.getJMenuBar().getPreferredSize();
if (mbd != null) {
mbWidth = mbd.width;
mbHeight = mbd.height;
}
}
if (getWindowDecorationStyle(root) != JRootPane_NONE
&& (root.getUI() instanceof SkinRootPaneUI)) {
JComponent titlePane = ((SkinRootPaneUI)root.getUI()).getTitlePane();
if (titlePane != null) {
tpd = titlePane.getPreferredSize();
if (tpd != null) {
tpWidth = tpd.width;
tpHeight = tpd.height;
}
}
}
return new Dimension(
Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right,
cpHeight + mbHeight + tpHeight + i.top + i.bottom);
}
/**
* Returns the minimum amount of space the layout needs.
*
* @param parent the Container for which this layout manager is being used
* @return a Dimension object containing the layout's minimum size
*/
public Dimension minimumLayoutSize(Container parent) {
Dimension cpd, mbd, tpd;
int cpWidth = 0;
int cpHeight = 0;
int mbWidth = 0;
int mbHeight = 0;
int tpWidth = 0;
int tpHeight = 0;
Insets i = parent.getInsets();
JRootPane root = (JRootPane)parent;
// This code is enabled only if the parent is not a window with
// look and feel decorations. Otherwise the look and feel honors
// the minimum size and the window can not be resized to a small
// size in the case where a component in the component hierarchy
// returns a wrong/big minimum size. In such case, the minimum
// size will be the one of the title pane.
if (!(root.getParent() instanceof java.awt.Window
&& getWindowDecorationStyle(root) != JRootPane_NONE)) {
if (root.getContentPane() != null) {
cpd = root.getContentPane().getMinimumSize();
} else {
cpd = root.getSize();
}
if (cpd != null) {
cpWidth = cpd.width;
cpHeight = cpd.height;
}
}
if (root.getJMenuBar() != null) {
mbd = root.getJMenuBar().getMinimumSize();
if (mbd != null) {
mbWidth = mbd.width;
mbHeight = mbd.height;
}
}
if (getWindowDecorationStyle(root) != JRootPane_NONE
&& (root.getUI() instanceof SkinRootPaneUI)) {
JComponent titlePane = ((SkinRootPaneUI)root.getUI()).getTitlePane();
if (titlePane != null) {
tpd = titlePane.getMinimumSize();
if (tpd != null) {
tpWidth = tpd.width;
tpHeight = tpd.height;
}
}
}
// FYI, MetalRootLayout has a bug in the dimension as it uses
// tpWidth in the height calculation
// Now logged as
// http://developer.java.sun.com/developer/bugParade/bugs/4916923.html
return new Dimension(
Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right,
cpHeight + mbHeight + tpHeight + i.top + i.bottom);
}
/**
* Returns the maximum amount of space the layout can use.
*
* @param target the Container for which this layout manager is being used
* @return a Dimension object containing the layout's maximum size
*/
public Dimension maximumLayoutSize(Container target) {
Dimension cpd, mbd, tpd;
int cpWidth = Integer.MAX_VALUE;
int cpHeight = Integer.MAX_VALUE;
int mbWidth = Integer.MAX_VALUE;
int mbHeight = Integer.MAX_VALUE;
int tpWidth = Integer.MAX_VALUE;
int tpHeight = Integer.MAX_VALUE;
Insets i = target.getInsets();
JRootPane root = (JRootPane)target;
if (root.getContentPane() != null) {
cpd = root.getContentPane().getMaximumSize();
if (cpd != null) {
cpWidth = cpd.width;
cpHeight = cpd.height;
}
}
if (root.getJMenuBar() != null) {
mbd = root.getJMenuBar().getMaximumSize();
if (mbd != null) {
mbWidth = mbd.width;
mbHeight = mbd.height;
}
}
if (getWindowDecorationStyle(root) != JRootPane_NONE
&& (root.getUI() instanceof SkinRootPaneUI)) {
JComponent titlePane = ((SkinRootPaneUI)root.getUI()).getTitlePane();
if (titlePane != null) {
tpd = titlePane.getMaximumSize();
if (tpd != null) {
tpWidth = tpd.width;
tpHeight = tpd.height;
}
}
}
int maxHeight = Math.max(Math.max(cpHeight, mbHeight), tpHeight);
// 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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -