下面列出了javax.swing.JRootPane#NONE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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).
* </p>
*
* @param root the JRootPane.
*/
private void uninstallClientDecorations(JRootPane root) {
uninstallBorder(root);
uninstallWindowListeners(root);
setTitlePane(root, null);
uninstallLayout(root);
// 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.
int style = root.getWindowDecorationStyle();
if (style == JRootPane.NONE) {
root.repaint();
root.revalidate();
}
// Reset the cursor, as we may have changed it to a resize cursor
if (window != null) {
window.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
window = null;
}
protected void uninstallClientDecorations() {
LookAndFeel.uninstallBorder( rootPane );
setTitlePane( null );
if( windowResizer != null ) {
windowResizer.uninstall();
windowResizer = null;
}
if( oldLayout != null ) {
rootPane.setLayout( oldLayout );
oldLayout = null;
}
if( rootPane.getWindowDecorationStyle() == JRootPane.NONE ) {
rootPane.revalidate();
rootPane.repaint();
}
}
@Override
public void propertyChange( PropertyChangeEvent e ) {
super.propertyChange( e );
switch( e.getPropertyName() ) {
case "windowDecorationStyle":
uninstallClientDecorations();
if( rootPane.getWindowDecorationStyle() != JRootPane.NONE )
installClientDecorations();
break;
case FlatClientProperties.MENU_BAR_EMBEDDED:
if( titlePane != null ) {
titlePane.menuBarChanged();
rootPane.revalidate();
rootPane.repaint();
}
break;
}
}
/**
* {@inheritDoc}
*/
public boolean isInState(JComponent c) {
Component parent = c.getParent();
if (true)
return ((JRootPane) c).getWindowDecorationStyle() == JRootPane.NONE;
if (parent instanceof JFrame)
return true;
if (parent instanceof JInternalFrame)
return true;
if (parent instanceof JDialog)
return true;
return false;
}
/**
* 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).
*
* @param root the root
*/
private void uninstallClientDecorations(JRootPane root)
{
uninstallBorder(root);
uninstallWindowListeners(root);
setTitlePane(root, null);
uninstallLayout(root);
// 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.
int style = root.getWindowDecorationStyle();
if (style == JRootPane.NONE)
{
root.repaint();
root.revalidate();
}
// Reset the cursor, as we may have changed it to a resize cursor
if (window != null)
{
window.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
window = null;
}
public Dimension preferredLayoutSize(Container parent)
{
Insets insets = parent.getInsets();
JRootPane root = (JRootPane) parent;
int h = 0;
Dimension cpd = null;
if (root.getContentPane() != null)
{
cpd = root.getContentPane().getPreferredSize();
if (!(root.getContentPane() instanceof LuckBackgroundPanel)
&& root.getWindowDecorationStyle() != JRootPane.NONE)
{
h += UIManager.getInt(LuckRootPaneUIBundle.TITLEPANEL_HEIGHT);
}
}
else
{
cpd = root.getSize();
}
h += cpd.height;
return getDimension(insets, cpd.width, h);
}
/**
* @see javax.swing.plaf.ComponentUI#update(java.awt.Graphics, javax.swing.JComponent)
*/
public void update(Graphics g, JComponent c) {
SeaGlassContext context = getContext(c);
SeaGlassLookAndFeel.update(context, g);
if (((JRootPane) c).getWindowDecorationStyle() != JRootPane.NONE) {
context.getPainter().paintRootPaneBackground(context, g, 0, 0, c.getWidth(), c.getHeight());
} else if (PlatformUtils.isMac()) {
// We may need to paint the rootpane on a Mac if the window is
// decorated.
boolean shouldPaint = false;
Container toplevelContainer = c.getParent();
if (toplevelContainer instanceof JFrame) {
shouldPaint = !((JFrame) toplevelContainer).isUndecorated();
}
if (shouldPaint) {
if (!paintTextured) {
g.setColor(c.getBackground());
g.fillRect(0, 0, c.getWidth(), c.getHeight());
} else if (isWindowFocused.isInState(c)) {
contentActive.paint((Graphics2D) g, c, c.getWidth(), c.getHeight());
} else {
contentInactive.paint((Graphics2D) g, c, c.getWidth(), c.getHeight());
}
}
}
paint(context, g);
context.dispose();
}
public Dimension preferredLayoutSize(Container parent)
{
Insets insets = parent.getInsets();
LuckBackgroundPanel baPanel = (LuckBackgroundPanel) parent;
int h = 0;
if (baPanel.getRootPane() != null && JRootPane.NONE != baPanel
.getRootPane().getWindowDecorationStyle())
{
Dimension titleDm = baPanel.getTitlePanel().getPreferredSize();
h += titleDm.height;
}
if (baPanel.getJMenuBar() != null && baPanel.getJMenuBar().isVisible())
{
Dimension menuBarDm = baPanel.getRootPane().getJMenuBar().getPreferredSize();
h += menuBarDm.height;
}
Dimension contentDm = baPanel.getContentPane().getPreferredSize();
h += contentDm.height;
return getDimension(insets, contentDm.width, h);
}
public Dimension maximumLayoutSize(Container parent)
{
Insets insets = parent.getInsets();
LuckBackgroundPanel baPanel = (LuckBackgroundPanel) parent;
int h = 0;
if (JRootPane.NONE != baPanel.getRootPane().getWindowDecorationStyle())
{
Dimension titleDm = baPanel.getTitlePanel().getMaximumSize();
h += titleDm.height;
}
if (baPanel.getRootPane().getJMenuBar() != null
&& baPanel.getRootPane().getJMenuBar().isVisible())
{
Dimension menuBarDm = baPanel.getRootPane().getJMenuBar().getMaximumSize();
h += menuBarDm.height;
}
Dimension contentDm = baPanel.getContentPane().getMaximumSize();
h += contentDm.height;
return getDimension(insets, contentDm.width, h);
}
/**
* Installs the appropriate <code>Border</code> onto the <code>
* JRootPane</code>.
*
* @param root the root pane.
*/
public void installBorder(JRootPane root) {
int style = root.getWindowDecorationStyle();
if (style == JRootPane.NONE) {
LookAndFeel.uninstallBorder(root);
} else {
root.setBorder(new SeaGlassBorder(this, new Insets(0, 1, 1, 1)));
}
}
/**
* 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 = root.getWindowDecorationStyle();
// 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 (((JRootPane)e.getSource()).getWindowDecorationStyle() !=
JRootPane.NONE)
{
installWindowListeners(root, root.getParent());
}
}
return;
}
/**
* Instructs the layout manager to perform the layout for the specified
* container.
*
* @param parent the Container for which this layout manager is being
* used
*/
public void layoutContainer(Container parent) {
JRootPane root = (JRootPane) parent;
Rectangle b = root.getBounds();
Insets i = root.getInsets();
int nextY = 0;
int w = b.width - i.right - i.left;
int h = b.height - i.top - i.bottom;
if (root.getLayeredPane() != null) {
root.getLayeredPane().setBounds(i.left, i.top, w, h);
}
if (root.getGlassPane() != null) {
root.getGlassPane().setBounds(i.left, i.top, w, h);
}
// Note: This is laying out the children in the layeredPane,
// technically, these are not our children.
if (root.getWindowDecorationStyle() != JRootPane.NONE && (root.getUI() instanceof SeaGlassRootPaneUI)) {
JComponent titlePane = ((SeaGlassRootPaneUI) root.getUI()).getTitlePane();
if (titlePane != null) {
Dimension tpd = titlePane.getPreferredSize();
if (tpd != null) {
int tpHeight = tpd.height;
titlePane.setBounds(0, 0, w, tpHeight);
nextY += tpHeight;
}
}
}
if (root.getJMenuBar() != null) {
boolean menuInTitle = (root.getClientProperty("JRootPane.MenuInTitle") == Boolean.TRUE);
Dimension mbd = root.getJMenuBar().getPreferredSize();
int x = menuInTitle? 20 : 0;
root.getJMenuBar().setBounds(x, menuInTitle ? 0 : nextY, w, mbd.height);
root.getJMenuBar().setOpaque(false);
root.getJMenuBar().setBackground(transparentColor);
if (!menuInTitle) {
nextY += mbd.height;
}
}
if (root.getContentPane() != null) {
/* Dimension cpd = */ root.getContentPane().getPreferredSize();
root.getContentPane().setBounds(0, nextY, w, h < nextY ? 0 : h - nextY);
}
}
/**
* 处理JFrame的双击标题面板缩放事件
*/
public void mouseClicked(MouseEvent e)
{
Window window = (Window) e.getSource();
if(window instanceof JFrame)
{
JFrame frame = (JFrame) window;
JRootPane root = frame.getRootPane();
// 不包含窗体装饰直接返回
if (root.getWindowDecorationStyle() == JRootPane.NONE)
{
return;
}
// 不在标题栏覆盖区域直接返回
if(!titleArea.contains(e.getPoint()))
{
return;
}
if ((e.getClickCount() % 2) == 0 && ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0))
{
int state = frame.getExtendedState();
if (frame.isResizable())
{
if ((state & JFrame.MAXIMIZED_BOTH) != 0)
{
frame.setExtendedState(state & ~JFrame.MAXIMIZED_BOTH);
}
else
{
frame.setExtendedState(state | JFrame.MAXIMIZED_BOTH);
}
}
}
}
}
/**
* v1.0.1:修复自定义拖拽区域BUG, 增加边界判断
*/
public void mousePressed(MouseEvent e)
{
Window window = (Window) e.getSource();
JRootPane root = LuckWindowUtil.getRootPane(window);
// 不包含窗体装饰直接返回
if (root == null || root.getWindowDecorationStyle() == JRootPane.NONE)
{
return;
}
if (window != null)
{
window.toFront();
}
// 如果是单击标题栏, 则标记接下来的拖动事件为移动窗口, 判断当前鼠标是否超出边界
if (dragArea.contains(e.getPoint())
&& dragCursor == Cursor.DEFAULT_CURSOR)
{
if(window instanceof JFrame)
{
JFrame frame = (JFrame)window;
// 如果当前窗体是全屏状态则直接返回
if(frame.getExtendedState() == JFrame.MAXIMIZED_BOTH)
{
return;
}
}
// 设置为可以移动并记录当前坐标
isMovingWindow = true;
dragOffsetX = e.getPoint().x;
dragOffsetY = e.getPoint().y;
}
else if(LuckWindowUtil.isResizable(window))
{
dragOffsetX = e.getPoint().x;
dragOffsetY = e.getPoint().y;
dragWidth = window.getWidth();
dragHeight = window.getHeight();
JRootPane rootPane = LuckWindowUtil.getRootPane(window);
if(rootPane != null && LuckWindowUtil.isResizable(window))
{
dragCursor = getCursor(dragWidth, dragHeight, e.getPoint(), rootPane.getInsets());
}
}
}
public void layoutContainer(Container parent)
{
JRootPane root = (JRootPane) parent;
Rectangle bound = root.getBounds();
Insets inset = root.getInsets();
// 获取内容面板实际宽度, 减去左右边框面积
// Calculate the actual width
int w = bound.width - inset.right - inset.left;
// 获取内容面板实际高度, 减去上下边框面积
int h = bound.height - inset.top - inset.bottom;
// 设置层级面板在根窗格中的位置
// Calculate the actual height
if(root.getLayeredPane() != null)
{
root.getLayeredPane().setBounds(inset.left, inset.top, w, h);
}
// 布局玻璃窗格
// layout LayeredPane
if(root.getGlassPane() != null)
{
root.getGlassPane().setBounds(inset.left, inset.top, w, h);
}
// 获取当前内容面板
// get current ContentPane
Container content = root.getContentPane();
LuckRootPaneUI rootPaneUI = (LuckRootPaneUI) root.getUI();
// 使用 <code>LuckBackgroundPanel</code>替换当前的内容面板
// Use <code>LuckBackgroundPanel</code> replace the current contents of the panel
if(!(content instanceof LuckBackgroundPanel))
{
Window window = SwingUtilities.getWindowAncestor(root);
boolean isResizeableOnInit = LuckWindowUtil.isResizable(window);
int initStyle = root.getWindowDecorationStyle();
if(initStyle != JRootPane.NONE)
{
//
LuckTitlePanel titlePanel = rootPaneUI.createTitlePanel(initStyle, isResizeableOnInit);
LuckBackgroundPanel background = rootPaneUI.createContentPane(titlePanel, content);
root.setContentPane(background);
}
}
root.getContentPane().setBounds(0, 0, w, h);
}
/**
* 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;
Dimension mbd;
Dimension 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().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 (root.getWindowDecorationStyle() != JRootPane.NONE && (root.getUI() instanceof SeaGlassRootPaneUI)) {
JComponent titlePane = ((SeaGlassRootPaneUI) root.getUI()).getTitlePane();
if (titlePane != null) {
tpd = titlePane.getMinimumSize();
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);
}
/**
* Instructs the layout manager to perform the layout for the specified
* container.
*
* @param parent the parent
*/
@SuppressWarnings("deprecation")
public void layoutContainer(Container parent)
{
JRootPane root = (JRootPane) parent;
Rectangle b = root.getBounds();
Insets i = root.getInsets();
int nextY = 0;
int w = b.width - i.right - i.left;
int h = b.height - i.top - i.bottom;
if(root.getLayeredPane() != null)
{
root.getLayeredPane().setBounds(i.left, i.top, w, h);
}
if(root.getGlassPane() != null)
{
root.getGlassPane().setBounds(i.left, i.top, w, h);
}
// Note: This is laying out the children in the layeredPane,
// technically, these are not our children.
if (root.getWindowDecorationStyle() != JRootPane.NONE &&
(root.getUI() instanceof BERootPaneUI))
{
JComponent titlePane = ((BERootPaneUI)root.getUI()).
getTitlePane();
if (titlePane != null)
{
Dimension tpd = titlePane.getPreferredSize();
if (tpd != null)
{
int tpHeight = tpd.height;
titlePane.setBounds(0, 0, w, tpHeight);
nextY += tpHeight;
}
}
}
if(root.getMenuBar() != null
//* 该 行代码由Jack Jiang于2012-10-20增加:目的是为解决当
//* MebuBar被设置不可见时任然被错误地当作可视组件占据布局空间,这
//* 在BE LNF中的表现就是当menuBar不可见,它占据的那块空间将会是全透明
//* 的空白区。这个问题在Metal主题中仍然存在(就是设置JFrame.setDefaultLookAndFeelDecorated(true);
//* JDialog.setDefaultLookAndFeelDecorated(true);后的Metal主题状态),
//* 可能官方不认为这是个bug吧。
//* 为什么无论什么外观当在使用系统窗口边框类型时不会出现这样的情况呢?它
//* 可能是由于窗口外观的实现原理决定的吧(按理说是同一原理),有待深究!!!
&& root.getMenuBar().isVisible()
)
{
Dimension mbd = root.getMenuBar().getPreferredSize();
root.getMenuBar().setBounds(0, nextY, w, mbd.height);
nextY += mbd.height;
}
if(root.getContentPane() != null
//* 该 行代码由Jack Jiang于2012-10-20增加:目的是为解决与menubar在设置可见性时遇难到的一样的问题
&& root.getContentPane().isVisible()
)
{
Dimension cpd = root.getContentPane().getPreferredSize();
root.getContentPane().setBounds(0, nextY, w,
h < nextY ? 0 : h - nextY);
}
}
/**
* Returns the maximum amount of space the layout can use.
*
* @param target the target
* @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.getMenuBar() != null)
{
mbd = root.getMenuBar().getMaximumSize();
if (mbd != null)
{
mbWidth = mbd.width;
mbHeight = mbd.height;
}
}
if (root.getWindowDecorationStyle() != JRootPane.NONE &&
(root.getUI() instanceof BERootPaneUI))
{
JComponent titlePane = ((BERootPaneUI)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.
if (maxHeight != Integer.MAX_VALUE)
{
maxHeight = cpHeight + mbHeight + tpHeight + i.top + i.bottom;
}
int maxWidth = Math.max(Math.max(cpWidth, mbWidth), tpWidth);
// Similar overflow comment as above
if (maxWidth != Integer.MAX_VALUE)
{
maxWidth += i.left + i.right;
}
return new Dimension(maxWidth, maxHeight);
}
/**
* 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;
Dimension mbd;
Dimension 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 (root.getWindowDecorationStyle() != JRootPane.NONE && (root.getUI() instanceof SeaGlassRootPaneUI)) {
JComponent titlePane = ((SeaGlassRootPaneUI) 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.
if (maxHeight != Integer.MAX_VALUE) {
maxHeight = cpHeight + mbHeight + tpHeight + i.top + i.bottom;
}
int maxWidth = Math.max(Math.max(cpWidth, mbWidth), tpWidth);
// Similar overflow comment as above
if (maxWidth != Integer.MAX_VALUE) {
maxWidth += i.left + i.right;
}
return new Dimension(maxWidth, maxHeight);
}
/**
* 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
*/
public void installUI(JComponent c)
{
super.installUI(c);
root = (JRootPane)c;
int style = root.getWindowDecorationStyle();
if (style != JRootPane.NONE)
{
installClientDecorations(root);
}
}