📄 uiutilities.java
字号:
/*
* 09/08/2005
*
* UIUtilities.java - Utility methods for org.fife.ui classes.
* Copyright (C) 2005 Robert Futrell
* email@address.com
* www.website.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.fife.ui;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.border.Border;
/**
* Utility methods for <code>org.fife.ui</code> GUI components.
*
* @author Robert Futrell
* @version 1.0
*/
public class UIUtilities {
/*
* -1 => Not yet determined, 0 => no, 1 => yes.
*/
private static int nonOpaqueTabbedPaneComponents = -1;
/*
* A very common border that can be shared across many components.
*/
private static final Border EMPTY_5_BORDER =
BorderFactory.createEmptyBorder(5,5,5,5);
/*****************************************************************************/
/**
* Private constructor so we cannot instantiate this class.
*/
private UIUtilities() {
}
/*****************************************************************************/
/**
* Collapses all nodes in the specified tree.
*
* @param tree The tree.
* @see #expandAllNodes
*/
public static void collapseAllNodes(final JTree tree) {
for (int i=tree.getRowCount(); i>=0; i--)
tree.collapseRow(i);
}
/*****************************************************************************/
/**
* Returns a button to add to a panel in a tabbed pane. This method
* checks system properties to determine the operating system this JVM is
* running in; if it is determined that this OS paints its tabbed panes
* in a special way (such as the gradient tabbed panes in Windows XP),
* then the button returned is not opaque. Otherwise, a regular (opaque)
* button is returned.
*
* @return A button to add to a <code>JTabbedPane</code>.
* @see #createTabbedPanePanel
*/
public static RButton createTabbedPaneButton(String text) {
RButton button = new RButton(text);
if (getUseNonOpaqueTabbedPaneComponents())
button.setOpaque(false);
return button;
}
/*****************************************************************************/
/**
* Returns an opaque panel so we get the cool gradient effect on Windows
* XP.
*
* @return A panel to add to a <code>JTabbedPane</code>.
* @see #createTabbedPaneButton
*/
public static JPanel createTabbedPanePanel() {
JPanel panel = new JPanel();
if (getUseNonOpaqueTabbedPaneComponents())
panel.setOpaque(false);
return panel;
}
/*****************************************************************************/
/**
* Expands all nodes in the specified tree.
*
* @param tree The tree.
* @see #collapseAllNodes
*/
public static void expandAllNodes(final JTree tree) {
// Do separately for nested panels.
int j=0;
while (j<tree.getRowCount()) {
tree.expandRow(j++);
}
}
/*****************************************************************************/
/**
* Returns an empty border of width 5 on all sides. Since this is a
* very common border in GUI's, the border returned is a singleton.
*
* @return The border.
*/
public static Border getEmpty5Border() {
return EMPTY_5_BORDER;
}
/*****************************************************************************/
/**
* Returns whether or not this operating system should use non-opaque
* components in tabbed panes to show off, for example, a gradient effect.
*
* @return Whether or not non-opaque components should be used in tabbed
* panes.
*/
static synchronized boolean getUseNonOpaqueTabbedPaneComponents() {
if (nonOpaqueTabbedPaneComponents==-1) {
String osname = System.getProperty("os.name");
if (osname!=null) {
// Check for Windows XP.
if (osname.toLowerCase().indexOf("windows")>-1) {
String osver = System.getProperty("os.version");
boolean isXP = osver!=null && osver.startsWith("5.1");
nonOpaqueTabbedPaneComponents = isXP ? 1 : 0;
}
}
else {
nonOpaqueTabbedPaneComponents = 0;
}
}
return nonOpaqueTabbedPaneComponents==1 ? true : false;
}
/*****************************************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -