feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
433
jdkSrc/jdk8/javax/swing/plaf/metal/DefaultMetalTheme.java
Normal file
433
jdkSrc/jdk8/javax/swing/plaf/metal/DefaultMetalTheme.java
Normal file
@@ -0,0 +1,433 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
import sun.awt.AppContext;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
import sun.swing.SwingUtilities2;
|
||||
|
||||
/**
|
||||
* A concrete implementation of {@code MetalTheme} providing
|
||||
* the original look of the Java Look and Feel, code-named "Steel". Refer
|
||||
* to {@link MetalLookAndFeel#setCurrentTheme} for details on changing
|
||||
* the default theme.
|
||||
* <p>
|
||||
* All colors returned by {@code DefaultMetalTheme} are completely
|
||||
* opaque.
|
||||
*
|
||||
* <h3><a name="fontStyle"></a>Font Style</h3>
|
||||
*
|
||||
* {@code DefaultMetalTheme} uses bold fonts for many controls. To make all
|
||||
* controls (with the exception of the internal frame title bars and
|
||||
* client decorated frame title bars) use plain fonts you can do either of
|
||||
* the following:
|
||||
* <ul>
|
||||
* <li>Set the system property <code>swing.boldMetal</code> to
|
||||
* <code>false</code>. For example,
|
||||
* <code>java -Dswing.boldMetal=false MyApp</code>.
|
||||
* <li>Set the defaults property <code>swing.boldMetal</code> to
|
||||
* <code>Boolean.FALSE</code>. For example:
|
||||
* <code>UIManager.put("swing.boldMetal", Boolean.FALSE);</code>
|
||||
* </ul>
|
||||
* The defaults property <code>swing.boldMetal</code>, if set,
|
||||
* takes precedence over the system property of the same name. After
|
||||
* setting this defaults property you need to re-install
|
||||
* <code>MetalLookAndFeel</code>, as well as update the UI
|
||||
* of any previously created widgets. Otherwise the results are undefined.
|
||||
* The following illustrates how to do this:
|
||||
* <pre>
|
||||
* // turn off bold fonts
|
||||
* UIManager.put("swing.boldMetal", Boolean.FALSE);
|
||||
*
|
||||
* // re-install the Metal Look and Feel
|
||||
* UIManager.setLookAndFeel(new MetalLookAndFeel());
|
||||
*
|
||||
* // Update the ComponentUIs for all Components. This
|
||||
* // needs to be invoked for all windows.
|
||||
* SwingUtilities.updateComponentTreeUI(rootComponent);
|
||||
* </pre>
|
||||
* <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™
|
||||
* has been added to the <code>java.beans</code> package.
|
||||
* Please see {@link java.beans.XMLEncoder}.
|
||||
*
|
||||
* @see MetalLookAndFeel
|
||||
* @see MetalLookAndFeel#setCurrentTheme
|
||||
*
|
||||
* @author Steve Wilson
|
||||
*/
|
||||
public class DefaultMetalTheme extends MetalTheme {
|
||||
/**
|
||||
* Whether or not fonts should be plain. This is only used if
|
||||
* the defaults property 'swing.boldMetal' == "false".
|
||||
*/
|
||||
private static final boolean PLAIN_FONTS;
|
||||
|
||||
/**
|
||||
* Names of the fonts to use.
|
||||
*/
|
||||
private static final String[] fontNames = {
|
||||
Font.DIALOG,Font.DIALOG,Font.DIALOG,Font.DIALOG,Font.DIALOG,Font.DIALOG
|
||||
};
|
||||
/**
|
||||
* Styles for the fonts. This is ignored if the defaults property
|
||||
* <code>swing.boldMetal</code> is false, or PLAIN_FONTS is true.
|
||||
*/
|
||||
private static final int[] fontStyles = {
|
||||
Font.BOLD, Font.PLAIN, Font.PLAIN, Font.BOLD, Font.BOLD, Font.PLAIN
|
||||
};
|
||||
/**
|
||||
* Sizes for the fonts.
|
||||
*/
|
||||
private static final int[] fontSizes = {
|
||||
12, 12, 12, 12, 12, 10
|
||||
};
|
||||
|
||||
// note the properties listed here can currently be used by people
|
||||
// providing runtimes to hint what fonts are good. For example the bold
|
||||
// dialog font looks bad on a Mac, so Apple could use this property to
|
||||
// hint at a good font.
|
||||
//
|
||||
// However, we don't promise to support these forever. We may move
|
||||
// to getting these from the swing.properties file, or elsewhere.
|
||||
/**
|
||||
* System property names used to look up fonts.
|
||||
*/
|
||||
private static final String[] defaultNames = {
|
||||
"swing.plaf.metal.controlFont",
|
||||
"swing.plaf.metal.systemFont",
|
||||
"swing.plaf.metal.userFont",
|
||||
"swing.plaf.metal.controlFont",
|
||||
"swing.plaf.metal.controlFont",
|
||||
"swing.plaf.metal.smallFont"
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the ideal font name for the font identified by key.
|
||||
*/
|
||||
static String getDefaultFontName(int key) {
|
||||
return fontNames[key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ideal font size for the font identified by key.
|
||||
*/
|
||||
static int getDefaultFontSize(int key) {
|
||||
return fontSizes[key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ideal font style for the font identified by key.
|
||||
*/
|
||||
static int getDefaultFontStyle(int key) {
|
||||
if (key != WINDOW_TITLE_FONT) {
|
||||
Object boldMetal = null;
|
||||
if (AppContext.getAppContext().get(
|
||||
SwingUtilities2.LAF_STATE_KEY) != null) {
|
||||
// Only access the boldMetal key if a look and feel has
|
||||
// been loaded, otherwise we'll trigger loading the look
|
||||
// and feel.
|
||||
boldMetal = UIManager.get("swing.boldMetal");
|
||||
}
|
||||
if (boldMetal != null) {
|
||||
if (Boolean.FALSE.equals(boldMetal)) {
|
||||
return Font.PLAIN;
|
||||
}
|
||||
}
|
||||
else if (PLAIN_FONTS) {
|
||||
return Font.PLAIN;
|
||||
}
|
||||
}
|
||||
return fontStyles[key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default used to look up the specified font.
|
||||
*/
|
||||
static String getDefaultPropertyName(int key) {
|
||||
return defaultNames[key];
|
||||
}
|
||||
|
||||
static {
|
||||
Object boldProperty = java.security.AccessController.doPrivileged(
|
||||
new GetPropertyAction("swing.boldMetal"));
|
||||
if (boldProperty == null || !"false".equals(boldProperty)) {
|
||||
PLAIN_FONTS = false;
|
||||
}
|
||||
else {
|
||||
PLAIN_FONTS = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static final ColorUIResource primary1 = new ColorUIResource(
|
||||
102, 102, 153);
|
||||
private static final ColorUIResource primary2 = new ColorUIResource(153,
|
||||
153, 204);
|
||||
private static final ColorUIResource primary3 = new ColorUIResource(
|
||||
204, 204, 255);
|
||||
private static final ColorUIResource secondary1 = new ColorUIResource(
|
||||
102, 102, 102);
|
||||
private static final ColorUIResource secondary2 = new ColorUIResource(
|
||||
153, 153, 153);
|
||||
private static final ColorUIResource secondary3 = new ColorUIResource(
|
||||
204, 204, 204);
|
||||
|
||||
private FontDelegate fontDelegate;
|
||||
|
||||
/**
|
||||
* Returns the name of this theme. This returns {@code "Steel"}.
|
||||
*
|
||||
* @return the name of this theme.
|
||||
*/
|
||||
public String getName() { return "Steel"; }
|
||||
|
||||
/**
|
||||
* Creates and returns an instance of {@code DefaultMetalTheme}.
|
||||
*/
|
||||
public DefaultMetalTheme() {
|
||||
install();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primary 1 color. This returns a color with rgb values
|
||||
* of 102, 102, and 153, respectively.
|
||||
*
|
||||
* @return the primary 1 color
|
||||
*/
|
||||
protected ColorUIResource getPrimary1() { return primary1; }
|
||||
|
||||
/**
|
||||
* Returns the primary 2 color. This returns a color with rgb values
|
||||
* of 153, 153, 204, respectively.
|
||||
*
|
||||
* @return the primary 2 color
|
||||
*/
|
||||
protected ColorUIResource getPrimary2() { return primary2; }
|
||||
|
||||
/**
|
||||
* Returns the primary 3 color. This returns a color with rgb values
|
||||
* 204, 204, 255, respectively.
|
||||
*
|
||||
* @return the primary 3 color
|
||||
*/
|
||||
protected ColorUIResource getPrimary3() { return primary3; }
|
||||
|
||||
/**
|
||||
* Returns the secondary 1 color. This returns a color with rgb values
|
||||
* 102, 102, and 102, respectively.
|
||||
*
|
||||
* @return the secondary 1 color
|
||||
*/
|
||||
protected ColorUIResource getSecondary1() { return secondary1; }
|
||||
|
||||
/**
|
||||
* Returns the secondary 2 color. This returns a color with rgb values
|
||||
* 153, 153, and 153, respectively.
|
||||
*
|
||||
* @return the secondary 2 color
|
||||
*/
|
||||
protected ColorUIResource getSecondary2() { return secondary2; }
|
||||
|
||||
/**
|
||||
* Returns the secondary 3 color. This returns a color with rgb values
|
||||
* 204, 204, and 204, respectively.
|
||||
*
|
||||
* @return the secondary 3 color
|
||||
*/
|
||||
protected ColorUIResource getSecondary3() { return secondary3; }
|
||||
|
||||
|
||||
/**
|
||||
* Returns the control text font. This returns Dialog, 12pt. If
|
||||
* plain fonts have been enabled as described in <a href="#fontStyle">
|
||||
* font style</a>, the font style is plain. Otherwise the font style is
|
||||
* bold.
|
||||
*
|
||||
* @return the control text font
|
||||
*/
|
||||
public FontUIResource getControlTextFont() {
|
||||
return getFont(CONTROL_TEXT_FONT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the system text font. This returns Dialog, 12pt, plain.
|
||||
*
|
||||
* @return the system text font
|
||||
*/
|
||||
public FontUIResource getSystemTextFont() {
|
||||
return getFont(SYSTEM_TEXT_FONT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user text font. This returns Dialog, 12pt, plain.
|
||||
*
|
||||
* @return the user text font
|
||||
*/
|
||||
public FontUIResource getUserTextFont() {
|
||||
return getFont(USER_TEXT_FONT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the menu text font. This returns Dialog, 12pt. If
|
||||
* plain fonts have been enabled as described in <a href="#fontStyle">
|
||||
* font style</a>, the font style is plain. Otherwise the font style is
|
||||
* bold.
|
||||
*
|
||||
* @return the menu text font
|
||||
*/
|
||||
public FontUIResource getMenuTextFont() {
|
||||
return getFont(MENU_TEXT_FONT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the window title font. This returns Dialog, 12pt, bold.
|
||||
*
|
||||
* @return the window title font
|
||||
*/
|
||||
public FontUIResource getWindowTitleFont() {
|
||||
return getFont(WINDOW_TITLE_FONT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sub-text font. This returns Dialog, 10pt, plain.
|
||||
*
|
||||
* @return the sub-text font
|
||||
*/
|
||||
public FontUIResource getSubTextFont() {
|
||||
return getFont(SUB_TEXT_FONT);
|
||||
}
|
||||
|
||||
private FontUIResource getFont(int key) {
|
||||
return fontDelegate.getFont(key);
|
||||
}
|
||||
|
||||
void install() {
|
||||
if (MetalLookAndFeel.isWindows() &&
|
||||
MetalLookAndFeel.useSystemFonts()) {
|
||||
fontDelegate = new WindowsFontDelegate();
|
||||
}
|
||||
else {
|
||||
fontDelegate = new FontDelegate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this is a theme provided by the core platform.
|
||||
*/
|
||||
boolean isSystemTheme() {
|
||||
return (getClass() == DefaultMetalTheme.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* FontDelegates add an extra level of indirection to obtaining fonts.
|
||||
*/
|
||||
private static class FontDelegate {
|
||||
private static int[] defaultMapping = {
|
||||
CONTROL_TEXT_FONT, SYSTEM_TEXT_FONT,
|
||||
USER_TEXT_FONT, CONTROL_TEXT_FONT,
|
||||
CONTROL_TEXT_FONT, SUB_TEXT_FONT
|
||||
};
|
||||
FontUIResource fonts[];
|
||||
|
||||
// menu and window are mapped to controlFont
|
||||
public FontDelegate() {
|
||||
fonts = new FontUIResource[6];
|
||||
}
|
||||
|
||||
public FontUIResource getFont(int type) {
|
||||
int mappedType = defaultMapping[type];
|
||||
if (fonts[type] == null) {
|
||||
Font f = getPrivilegedFont(mappedType);
|
||||
|
||||
if (f == null) {
|
||||
f = new Font(getDefaultFontName(type),
|
||||
getDefaultFontStyle(type),
|
||||
getDefaultFontSize(type));
|
||||
}
|
||||
fonts[type] = new FontUIResource(f);
|
||||
}
|
||||
return fonts[type];
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the same as invoking
|
||||
* <code>Font.getFont(key)</code>, with the exception
|
||||
* that it is wrapped inside a <code>doPrivileged</code> call.
|
||||
*/
|
||||
protected Font getPrivilegedFont(final int key) {
|
||||
return java.security.AccessController.doPrivileged(
|
||||
new java.security.PrivilegedAction<Font>() {
|
||||
public Font run() {
|
||||
return Font.getFont(getDefaultPropertyName(key));
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The WindowsFontDelegate uses DesktopProperties to obtain fonts.
|
||||
*/
|
||||
private static class WindowsFontDelegate extends FontDelegate {
|
||||
private MetalFontDesktopProperty[] props;
|
||||
private boolean[] checkedPriviledged;
|
||||
|
||||
public WindowsFontDelegate() {
|
||||
props = new MetalFontDesktopProperty[6];
|
||||
checkedPriviledged = new boolean[6];
|
||||
}
|
||||
|
||||
public FontUIResource getFont(int type) {
|
||||
if (fonts[type] != null) {
|
||||
return fonts[type];
|
||||
}
|
||||
if (!checkedPriviledged[type]) {
|
||||
Font f = getPrivilegedFont(type);
|
||||
|
||||
checkedPriviledged[type] = true;
|
||||
if (f != null) {
|
||||
fonts[type] = new FontUIResource(f);
|
||||
return fonts[type];
|
||||
}
|
||||
}
|
||||
if (props[type] == null) {
|
||||
props[type] = new MetalFontDesktopProperty(type);
|
||||
}
|
||||
// While passing null may seem bad, we don't actually use
|
||||
// the table and looking it up is rather expensive.
|
||||
return (FontUIResource)props[type].createValue(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
976
jdkSrc/jdk8/javax/swing/plaf/metal/MetalBorders.java
Normal file
976
jdkSrc/jdk8/javax/swing/plaf/metal/MetalBorders.java
Normal file
@@ -0,0 +1,976 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.BasicBorders;
|
||||
import javax.swing.text.JTextComponent;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Window;
|
||||
|
||||
import sun.swing.StringUIClientPropertyKey;
|
||||
import sun.swing.SwingUtilities2;
|
||||
|
||||
|
||||
/**
|
||||
* Factory object that can vend Borders appropriate for the metal L & F.
|
||||
* @author Steve Wilson
|
||||
*/
|
||||
|
||||
public class MetalBorders {
|
||||
|
||||
/**
|
||||
* Client property indicating the button shouldn't provide a rollover
|
||||
* indicator. Only used with the Ocean theme.
|
||||
*/
|
||||
static Object NO_BUTTON_ROLLOVER =
|
||||
new StringUIClientPropertyKey("NoButtonRollover");
|
||||
|
||||
|
||||
public static class Flush3DBorder extends AbstractBorder implements UIResource{
|
||||
public void paintBorder(Component c, Graphics g, int x, int y,
|
||||
int w, int h) {
|
||||
if (c.isEnabled()) {
|
||||
MetalUtils.drawFlush3DBorder(g, x, y, w, h);
|
||||
} else {
|
||||
MetalUtils.drawDisabledBorder(g, x, y, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets newInsets) {
|
||||
newInsets.set(2, 2, 2, 2);
|
||||
return newInsets;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ButtonBorder extends AbstractBorder implements UIResource {
|
||||
|
||||
protected static Insets borderInsets = new Insets( 3, 3, 3, 3 );
|
||||
|
||||
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
|
||||
if (!(c instanceof AbstractButton)) {
|
||||
return;
|
||||
}
|
||||
if (MetalLookAndFeel.usingOcean()) {
|
||||
paintOceanBorder(c, g, x, y, w, h);
|
||||
return;
|
||||
}
|
||||
AbstractButton button = (AbstractButton)c;
|
||||
ButtonModel model = button.getModel();
|
||||
|
||||
if ( model.isEnabled() ) {
|
||||
boolean isPressed = model.isPressed() && model.isArmed();
|
||||
boolean isDefault = (button instanceof JButton && ((JButton)button).isDefaultButton());
|
||||
|
||||
if (isPressed && isDefault) {
|
||||
MetalUtils.drawDefaultButtonPressedBorder(g, x, y, w, h);
|
||||
} else if (isPressed) {
|
||||
MetalUtils.drawPressed3DBorder( g, x, y, w, h );
|
||||
} else if (isDefault) {
|
||||
MetalUtils.drawDefaultButtonBorder( g, x, y, w, h, false);
|
||||
} else {
|
||||
MetalUtils.drawButtonBorder( g, x, y, w, h, false);
|
||||
}
|
||||
} else { // disabled state
|
||||
MetalUtils.drawDisabledBorder( g, x, y, w-1, h-1 );
|
||||
}
|
||||
}
|
||||
|
||||
private void paintOceanBorder(Component c, Graphics g, int x, int y,
|
||||
int w, int h) {
|
||||
AbstractButton button = (AbstractButton)c;
|
||||
ButtonModel model = ((AbstractButton)c).getModel();
|
||||
|
||||
g.translate(x, y);
|
||||
if (MetalUtils.isToolBarButton(button)) {
|
||||
if (model.isEnabled()) {
|
||||
if (model.isPressed()) {
|
||||
g.setColor(MetalLookAndFeel.getWhite());
|
||||
g.fillRect(1, h - 1, w - 1, 1);
|
||||
g.fillRect(w - 1, 1, 1, h - 1);
|
||||
g.setColor(MetalLookAndFeel.getControlDarkShadow());
|
||||
g.drawRect(0, 0, w - 2, h - 2);
|
||||
g.fillRect(1, 1, w - 3, 1);
|
||||
}
|
||||
else if (model.isSelected() || model.isRollover()) {
|
||||
g.setColor(MetalLookAndFeel.getWhite());
|
||||
g.fillRect(1, h - 1, w - 1, 1);
|
||||
g.fillRect(w - 1, 1, 1, h - 1);
|
||||
g.setColor(MetalLookAndFeel.getControlDarkShadow());
|
||||
g.drawRect(0, 0, w - 2, h - 2);
|
||||
}
|
||||
else {
|
||||
g.setColor(MetalLookAndFeel.getWhite());
|
||||
g.drawRect(1, 1, w - 2, h - 2);
|
||||
g.setColor(UIManager.getColor(
|
||||
"Button.toolBarBorderBackground"));
|
||||
g.drawRect(0, 0, w - 2, h - 2);
|
||||
}
|
||||
}
|
||||
else {
|
||||
g.setColor(UIManager.getColor(
|
||||
"Button.disabledToolBarBorderBackground"));
|
||||
g.drawRect(0, 0, w - 2, h - 2);
|
||||
}
|
||||
}
|
||||
else if (model.isEnabled()) {
|
||||
boolean pressed = model.isPressed();
|
||||
boolean armed = model.isArmed();
|
||||
|
||||
if ((c instanceof JButton) && ((JButton)c).isDefaultButton()) {
|
||||
g.setColor(MetalLookAndFeel.getControlDarkShadow());
|
||||
g.drawRect(0, 0, w - 1, h - 1);
|
||||
g.drawRect(1, 1, w - 3, h - 3);
|
||||
}
|
||||
else if (pressed) {
|
||||
g.setColor(MetalLookAndFeel.getControlDarkShadow());
|
||||
g.fillRect(0, 0, w, 2);
|
||||
g.fillRect(0, 2, 2, h - 2);
|
||||
g.fillRect(w - 1, 1, 1, h - 1);
|
||||
g.fillRect(1, h - 1, w - 2, 1);
|
||||
}
|
||||
else if (model.isRollover() && button.getClientProperty(
|
||||
NO_BUTTON_ROLLOVER) == null) {
|
||||
g.setColor(MetalLookAndFeel.getPrimaryControl());
|
||||
g.drawRect(0, 0, w - 1, h - 1);
|
||||
g.drawRect(2, 2, w - 5, h - 5);
|
||||
g.setColor(MetalLookAndFeel.getControlDarkShadow());
|
||||
g.drawRect(1, 1, w - 3, h - 3);
|
||||
}
|
||||
else {
|
||||
g.setColor(MetalLookAndFeel.getControlDarkShadow());
|
||||
g.drawRect(0, 0, w - 1, h - 1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
g.setColor(MetalLookAndFeel.getInactiveControlTextColor());
|
||||
g.drawRect(0, 0, w - 1, h - 1);
|
||||
if ((c instanceof JButton) && ((JButton)c).isDefaultButton()) {
|
||||
g.drawRect(1, 1, w - 3, h - 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets newInsets) {
|
||||
newInsets.set(3, 3, 3, 3);
|
||||
return newInsets;
|
||||
}
|
||||
}
|
||||
|
||||
public static class InternalFrameBorder extends AbstractBorder implements UIResource {
|
||||
private static final int corner = 14;
|
||||
|
||||
public void paintBorder(Component c, Graphics g, int x, int y,
|
||||
int w, int h) {
|
||||
|
||||
Color background;
|
||||
Color highlight;
|
||||
Color shadow;
|
||||
|
||||
if (c instanceof JInternalFrame && ((JInternalFrame)c).isSelected()) {
|
||||
background = MetalLookAndFeel.getPrimaryControlDarkShadow();
|
||||
highlight = MetalLookAndFeel.getPrimaryControlShadow();
|
||||
shadow = MetalLookAndFeel.getPrimaryControlInfo();
|
||||
} else {
|
||||
background = MetalLookAndFeel.getControlDarkShadow();
|
||||
highlight = MetalLookAndFeel.getControlShadow();
|
||||
shadow = MetalLookAndFeel.getControlInfo();
|
||||
}
|
||||
|
||||
g.setColor(background);
|
||||
// Draw outermost lines
|
||||
g.drawLine( 1, 0, w-2, 0);
|
||||
g.drawLine( 0, 1, 0, h-2);
|
||||
g.drawLine( w-1, 1, w-1, h-2);
|
||||
g.drawLine( 1, h-1, w-2, h-1);
|
||||
|
||||
// Draw the bulk of the border
|
||||
for (int i = 1; i < 5; i++) {
|
||||
g.drawRect(x+i,y+i,w-(i*2)-1, h-(i*2)-1);
|
||||
}
|
||||
|
||||
if (c instanceof JInternalFrame &&
|
||||
((JInternalFrame)c).isResizable()) {
|
||||
g.setColor(highlight);
|
||||
// Draw the Long highlight lines
|
||||
g.drawLine( corner+1, 3, w-corner, 3);
|
||||
g.drawLine( 3, corner+1, 3, h-corner);
|
||||
g.drawLine( w-2, corner+1, w-2, h-corner);
|
||||
g.drawLine( corner+1, h-2, w-corner, h-2);
|
||||
|
||||
g.setColor(shadow);
|
||||
// Draw the Long shadow lines
|
||||
g.drawLine( corner, 2, w-corner-1, 2);
|
||||
g.drawLine( 2, corner, 2, h-corner-1);
|
||||
g.drawLine( w-3, corner, w-3, h-corner-1);
|
||||
g.drawLine( corner, h-3, w-corner-1, h-3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets newInsets) {
|
||||
newInsets.set(5, 5, 5, 5);
|
||||
return newInsets;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Border for a Frame.
|
||||
* @since 1.4
|
||||
*/
|
||||
static class FrameBorder extends AbstractBorder implements UIResource {
|
||||
private static final int corner = 14;
|
||||
|
||||
public void paintBorder(Component c, Graphics g, int x, int y,
|
||||
int w, int h) {
|
||||
|
||||
Color background;
|
||||
Color highlight;
|
||||
Color shadow;
|
||||
|
||||
Window window = SwingUtilities.getWindowAncestor(c);
|
||||
if (window != null && window.isActive()) {
|
||||
background = MetalLookAndFeel.getPrimaryControlDarkShadow();
|
||||
highlight = MetalLookAndFeel.getPrimaryControlShadow();
|
||||
shadow = MetalLookAndFeel.getPrimaryControlInfo();
|
||||
} else {
|
||||
background = MetalLookAndFeel.getControlDarkShadow();
|
||||
highlight = MetalLookAndFeel.getControlShadow();
|
||||
shadow = MetalLookAndFeel.getControlInfo();
|
||||
}
|
||||
|
||||
g.setColor(background);
|
||||
// Draw outermost lines
|
||||
g.drawLine( x+1, y+0, x+w-2, y+0);
|
||||
g.drawLine( x+0, y+1, x+0, y +h-2);
|
||||
g.drawLine( x+w-1, y+1, x+w-1, y+h-2);
|
||||
g.drawLine( x+1, y+h-1, x+w-2, y+h-1);
|
||||
|
||||
// Draw the bulk of the border
|
||||
for (int i = 1; i < 5; i++) {
|
||||
g.drawRect(x+i,y+i,w-(i*2)-1, h-(i*2)-1);
|
||||
}
|
||||
|
||||
if ((window instanceof Frame) && ((Frame) window).isResizable()) {
|
||||
g.setColor(highlight);
|
||||
// Draw the Long highlight lines
|
||||
g.drawLine( corner+1, 3, w-corner, 3);
|
||||
g.drawLine( 3, corner+1, 3, h-corner);
|
||||
g.drawLine( w-2, corner+1, w-2, h-corner);
|
||||
g.drawLine( corner+1, h-2, w-corner, h-2);
|
||||
|
||||
g.setColor(shadow);
|
||||
// Draw the Long shadow lines
|
||||
g.drawLine( corner, 2, w-corner-1, 2);
|
||||
g.drawLine( 2, corner, 2, h-corner-1);
|
||||
g.drawLine( w-3, corner, w-3, h-corner-1);
|
||||
g.drawLine( corner, h-3, w-corner-1, h-3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets newInsets)
|
||||
{
|
||||
newInsets.set(5, 5, 5, 5);
|
||||
return newInsets;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Border for a Frame.
|
||||
* @since 1.4
|
||||
*/
|
||||
static class DialogBorder extends AbstractBorder implements UIResource
|
||||
{
|
||||
private static final int corner = 14;
|
||||
|
||||
protected Color getActiveBackground()
|
||||
{
|
||||
return MetalLookAndFeel.getPrimaryControlDarkShadow();
|
||||
}
|
||||
|
||||
protected Color getActiveHighlight()
|
||||
{
|
||||
return MetalLookAndFeel.getPrimaryControlShadow();
|
||||
}
|
||||
|
||||
protected Color getActiveShadow()
|
||||
{
|
||||
return MetalLookAndFeel.getPrimaryControlInfo();
|
||||
}
|
||||
|
||||
protected Color getInactiveBackground()
|
||||
{
|
||||
return MetalLookAndFeel.getControlDarkShadow();
|
||||
}
|
||||
|
||||
protected Color getInactiveHighlight()
|
||||
{
|
||||
return MetalLookAndFeel.getControlShadow();
|
||||
}
|
||||
|
||||
protected Color getInactiveShadow()
|
||||
{
|
||||
return MetalLookAndFeel.getControlInfo();
|
||||
}
|
||||
|
||||
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h)
|
||||
{
|
||||
Color background;
|
||||
Color highlight;
|
||||
Color shadow;
|
||||
|
||||
Window window = SwingUtilities.getWindowAncestor(c);
|
||||
if (window != null && window.isActive()) {
|
||||
background = getActiveBackground();
|
||||
highlight = getActiveHighlight();
|
||||
shadow = getActiveShadow();
|
||||
} else {
|
||||
background = getInactiveBackground();
|
||||
highlight = getInactiveHighlight();
|
||||
shadow = getInactiveShadow();
|
||||
}
|
||||
|
||||
g.setColor(background);
|
||||
// Draw outermost lines
|
||||
g.drawLine( x + 1, y + 0, x + w-2, y + 0);
|
||||
g.drawLine( x + 0, y + 1, x + 0, y + h - 2);
|
||||
g.drawLine( x + w - 1, y + 1, x + w - 1, y + h - 2);
|
||||
g.drawLine( x + 1, y + h - 1, x + w - 2, y + h - 1);
|
||||
|
||||
// Draw the bulk of the border
|
||||
for (int i = 1; i < 5; i++) {
|
||||
g.drawRect(x+i,y+i,w-(i*2)-1, h-(i*2)-1);
|
||||
}
|
||||
|
||||
|
||||
if ((window instanceof Dialog) && ((Dialog) window).isResizable()) {
|
||||
g.setColor(highlight);
|
||||
// Draw the Long highlight lines
|
||||
g.drawLine( corner+1, 3, w-corner, 3);
|
||||
g.drawLine( 3, corner+1, 3, h-corner);
|
||||
g.drawLine( w-2, corner+1, w-2, h-corner);
|
||||
g.drawLine( corner+1, h-2, w-corner, h-2);
|
||||
|
||||
g.setColor(shadow);
|
||||
// Draw the Long shadow lines
|
||||
g.drawLine( corner, 2, w-corner-1, 2);
|
||||
g.drawLine( 2, corner, 2, h-corner-1);
|
||||
g.drawLine( w-3, corner, w-3, h-corner-1);
|
||||
g.drawLine( corner, h-3, w-corner-1, h-3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets newInsets)
|
||||
{
|
||||
newInsets.set(5, 5, 5, 5);
|
||||
return newInsets;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Border for an Error Dialog.
|
||||
* @since 1.4
|
||||
*/
|
||||
static class ErrorDialogBorder extends DialogBorder implements UIResource
|
||||
{
|
||||
protected Color getActiveBackground() {
|
||||
return UIManager.getColor("OptionPane.errorDialog.border.background");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Border for a QuestionDialog. Also used for a JFileChooser and a
|
||||
* JColorChooser..
|
||||
* @since 1.4
|
||||
*/
|
||||
static class QuestionDialogBorder extends DialogBorder implements UIResource
|
||||
{
|
||||
protected Color getActiveBackground() {
|
||||
return UIManager.getColor("OptionPane.questionDialog.border.background");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Border for a Warning Dialog.
|
||||
* @since 1.4
|
||||
*/
|
||||
static class WarningDialogBorder extends DialogBorder implements UIResource
|
||||
{
|
||||
protected Color getActiveBackground() {
|
||||
return UIManager.getColor("OptionPane.warningDialog.border.background");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Border for a Palette.
|
||||
* @since 1.3
|
||||
*/
|
||||
public static class PaletteBorder extends AbstractBorder implements UIResource {
|
||||
int titleHeight = 0;
|
||||
|
||||
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
|
||||
|
||||
g.translate(x,y);
|
||||
g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
|
||||
g.drawLine(0, 1, 0, h-2);
|
||||
g.drawLine(1, h-1, w-2, h-1);
|
||||
g.drawLine(w-1, 1, w-1, h-2);
|
||||
g.drawLine( 1, 0, w-2, 0);
|
||||
g.drawRect(1,1, w-3, h-3);
|
||||
g.translate(-x,-y);
|
||||
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets newInsets) {
|
||||
newInsets.set(1, 1, 1, 1);
|
||||
return newInsets;
|
||||
}
|
||||
}
|
||||
|
||||
public static class OptionDialogBorder extends AbstractBorder implements UIResource {
|
||||
int titleHeight = 0;
|
||||
|
||||
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
|
||||
|
||||
g.translate(x,y);
|
||||
|
||||
int messageType = JOptionPane.PLAIN_MESSAGE;
|
||||
if (c instanceof JInternalFrame) {
|
||||
Object obj = ((JInternalFrame) c).getClientProperty(
|
||||
"JInternalFrame.messageType");
|
||||
if (obj instanceof Integer) {
|
||||
messageType = (Integer) obj;
|
||||
}
|
||||
}
|
||||
|
||||
Color borderColor;
|
||||
|
||||
switch (messageType) {
|
||||
case(JOptionPane.ERROR_MESSAGE):
|
||||
borderColor = UIManager.getColor(
|
||||
"OptionPane.errorDialog.border.background");
|
||||
break;
|
||||
case(JOptionPane.QUESTION_MESSAGE):
|
||||
borderColor = UIManager.getColor(
|
||||
"OptionPane.questionDialog.border.background");
|
||||
break;
|
||||
case(JOptionPane.WARNING_MESSAGE):
|
||||
borderColor = UIManager.getColor(
|
||||
"OptionPane.warningDialog.border.background");
|
||||
break;
|
||||
case(JOptionPane.INFORMATION_MESSAGE):
|
||||
case(JOptionPane.PLAIN_MESSAGE):
|
||||
default:
|
||||
borderColor = MetalLookAndFeel.getPrimaryControlDarkShadow();
|
||||
break;
|
||||
}
|
||||
|
||||
g.setColor(borderColor);
|
||||
|
||||
// Draw outermost lines
|
||||
g.drawLine( 1, 0, w-2, 0);
|
||||
g.drawLine( 0, 1, 0, h-2);
|
||||
g.drawLine( w-1, 1, w-1, h-2);
|
||||
g.drawLine( 1, h-1, w-2, h-1);
|
||||
|
||||
// Draw the bulk of the border
|
||||
for (int i = 1; i < 3; i++) {
|
||||
g.drawRect(i, i, w-(i*2)-1, h-(i*2)-1);
|
||||
}
|
||||
|
||||
g.translate(-x,-y);
|
||||
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets newInsets) {
|
||||
newInsets.set(3, 3, 3, 3);
|
||||
return newInsets;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class MenuBarBorder extends AbstractBorder implements UIResource {
|
||||
protected static Insets borderInsets = new Insets( 1, 0, 1, 0 );
|
||||
|
||||
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
|
||||
g.translate(x, y);
|
||||
|
||||
if (MetalLookAndFeel.usingOcean()) {
|
||||
// Only paint a border if we're not next to a horizontal toolbar
|
||||
if (c instanceof JMenuBar
|
||||
&& !MetalToolBarUI.doesMenuBarBorderToolBar((JMenuBar)c)) {
|
||||
g.setColor(MetalLookAndFeel.getControl());
|
||||
SwingUtilities2.drawHLine(g, 0, w - 1, h - 2);
|
||||
g.setColor(UIManager.getColor("MenuBar.borderColor"));
|
||||
SwingUtilities2.drawHLine(g, 0, w - 1, h - 1);
|
||||
}
|
||||
} else {
|
||||
g.setColor(MetalLookAndFeel.getControlShadow());
|
||||
SwingUtilities2.drawHLine(g, 0, w - 1, h - 1);
|
||||
}
|
||||
g.translate(-x, -y);
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets newInsets) {
|
||||
if (MetalLookAndFeel.usingOcean()) {
|
||||
newInsets.set(0, 0, 2, 0);
|
||||
}
|
||||
else {
|
||||
newInsets.set(1, 0, 1, 0);
|
||||
}
|
||||
return newInsets;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MenuItemBorder extends AbstractBorder implements UIResource {
|
||||
protected static Insets borderInsets = new Insets( 2, 2, 2, 2 );
|
||||
|
||||
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
|
||||
if (!(c instanceof JMenuItem)) {
|
||||
return;
|
||||
}
|
||||
JMenuItem b = (JMenuItem) c;
|
||||
ButtonModel model = b.getModel();
|
||||
|
||||
g.translate( x, y );
|
||||
|
||||
if ( c.getParent() instanceof JMenuBar ) {
|
||||
if ( model.isArmed() || model.isSelected() ) {
|
||||
g.setColor( MetalLookAndFeel.getControlDarkShadow() );
|
||||
g.drawLine( 0, 0, w - 2, 0 );
|
||||
g.drawLine( 0, 0, 0, h - 1 );
|
||||
g.drawLine( w - 2, 2, w - 2, h - 1 );
|
||||
|
||||
g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
|
||||
g.drawLine( w - 1, 1, w - 1, h - 1 );
|
||||
|
||||
g.setColor( MetalLookAndFeel.getMenuBackground() );
|
||||
g.drawLine( w - 1, 0, w - 1, 0 );
|
||||
}
|
||||
} else {
|
||||
if ( model.isArmed() || ( c instanceof JMenu && model.isSelected() ) ) {
|
||||
g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
|
||||
g.drawLine( 0, 0, w - 1, 0 );
|
||||
|
||||
g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
|
||||
g.drawLine( 0, h - 1, w - 1, h - 1 );
|
||||
} else {
|
||||
g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
|
||||
g.drawLine( 0, 0, 0, h - 1 );
|
||||
}
|
||||
}
|
||||
|
||||
g.translate( -x, -y );
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets newInsets) {
|
||||
newInsets.set(2, 2, 2, 2);
|
||||
return newInsets;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PopupMenuBorder extends AbstractBorder implements UIResource {
|
||||
protected static Insets borderInsets = new Insets( 3, 1, 2, 1 );
|
||||
|
||||
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
|
||||
g.translate( x, y );
|
||||
|
||||
g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
|
||||
g.drawRect( 0, 0, w - 1, h - 1 );
|
||||
|
||||
g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
|
||||
g.drawLine( 1, 1, w - 2, 1 );
|
||||
g.drawLine( 1, 2, 1, 2 );
|
||||
g.drawLine( 1, h - 2, 1, h - 2 );
|
||||
|
||||
g.translate( -x, -y );
|
||||
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets newInsets) {
|
||||
newInsets.set(3, 1, 2, 1);
|
||||
return newInsets;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class RolloverButtonBorder extends ButtonBorder {
|
||||
|
||||
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
|
||||
AbstractButton b = (AbstractButton) c;
|
||||
ButtonModel model = b.getModel();
|
||||
|
||||
if ( model.isRollover() && !( model.isPressed() && !model.isArmed() ) ) {
|
||||
super.paintBorder( c, g, x, y, w, h );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A border which is like a Margin border but it will only honor the margin
|
||||
* if the margin has been explicitly set by the developer.
|
||||
*
|
||||
* Note: This is identical to the package private class
|
||||
* BasicBorders.RolloverMarginBorder and should probably be consolidated.
|
||||
*/
|
||||
static class RolloverMarginBorder extends EmptyBorder {
|
||||
|
||||
public RolloverMarginBorder() {
|
||||
super(3,3,3,3); // hardcoded margin for JLF requirements.
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets insets) {
|
||||
Insets margin = null;
|
||||
|
||||
if (c instanceof AbstractButton) {
|
||||
margin = ((AbstractButton)c).getMargin();
|
||||
}
|
||||
if (margin == null || margin instanceof UIResource) {
|
||||
// default margin so replace
|
||||
insets.left = left;
|
||||
insets.top = top;
|
||||
insets.right = right;
|
||||
insets.bottom = bottom;
|
||||
} else {
|
||||
// Margin which has been explicitly set by the user.
|
||||
insets.left = margin.left;
|
||||
insets.top = margin.top;
|
||||
insets.right = margin.right;
|
||||
insets.bottom = margin.bottom;
|
||||
}
|
||||
return insets;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ToolBarBorder extends AbstractBorder implements UIResource, SwingConstants
|
||||
{
|
||||
protected MetalBumps bumps = new MetalBumps( 10, 10,
|
||||
MetalLookAndFeel.getControlHighlight(),
|
||||
MetalLookAndFeel.getControlDarkShadow(),
|
||||
UIManager.getColor("ToolBar.background"));
|
||||
|
||||
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h )
|
||||
{
|
||||
if (!(c instanceof JToolBar)) {
|
||||
return;
|
||||
}
|
||||
g.translate( x, y );
|
||||
|
||||
if ( ((JToolBar) c).isFloatable() )
|
||||
{
|
||||
if ( ((JToolBar) c).getOrientation() == HORIZONTAL )
|
||||
{
|
||||
int shift = MetalLookAndFeel.usingOcean() ? -1 : 0;
|
||||
bumps.setBumpArea( 10, h - 4 );
|
||||
if( MetalUtils.isLeftToRight(c) ) {
|
||||
bumps.paintIcon( c, g, 2, 2 + shift );
|
||||
} else {
|
||||
bumps.paintIcon( c, g, w-12,
|
||||
2 + shift );
|
||||
}
|
||||
}
|
||||
else // vertical
|
||||
{
|
||||
bumps.setBumpArea( w - 4, 10 );
|
||||
bumps.paintIcon( c, g, 2, 2 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (((JToolBar) c).getOrientation() == HORIZONTAL &&
|
||||
MetalLookAndFeel.usingOcean()) {
|
||||
g.setColor(MetalLookAndFeel.getControl());
|
||||
g.drawLine(0, h - 2, w, h - 2);
|
||||
g.setColor(UIManager.getColor("ToolBar.borderColor"));
|
||||
g.drawLine(0, h - 1, w, h - 1);
|
||||
}
|
||||
|
||||
g.translate( -x, -y );
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets newInsets) {
|
||||
if (MetalLookAndFeel.usingOcean()) {
|
||||
newInsets.set(1, 2, 3, 2);
|
||||
}
|
||||
else {
|
||||
newInsets.top = newInsets.left = newInsets.bottom = newInsets.right = 2;
|
||||
}
|
||||
|
||||
if (!(c instanceof JToolBar)) {
|
||||
return newInsets;
|
||||
}
|
||||
if ( ((JToolBar) c).isFloatable() ) {
|
||||
if ( ((JToolBar) c).getOrientation() == HORIZONTAL ) {
|
||||
if (c.getComponentOrientation().isLeftToRight()) {
|
||||
newInsets.left = 16;
|
||||
} else {
|
||||
newInsets.right = 16;
|
||||
}
|
||||
} else {// vertical
|
||||
newInsets.top = 16;
|
||||
}
|
||||
}
|
||||
|
||||
Insets margin = ((JToolBar) c).getMargin();
|
||||
|
||||
if ( margin != null ) {
|
||||
newInsets.left += margin.left;
|
||||
newInsets.top += margin.top;
|
||||
newInsets.right += margin.right;
|
||||
newInsets.bottom += margin.bottom;
|
||||
}
|
||||
|
||||
return newInsets;
|
||||
}
|
||||
}
|
||||
|
||||
private static Border buttonBorder;
|
||||
|
||||
/**
|
||||
* Returns a border instance for a JButton
|
||||
* @since 1.3
|
||||
*/
|
||||
public static Border getButtonBorder() {
|
||||
if (buttonBorder == null) {
|
||||
buttonBorder = new BorderUIResource.CompoundBorderUIResource(
|
||||
new MetalBorders.ButtonBorder(),
|
||||
new BasicBorders.MarginBorder());
|
||||
}
|
||||
return buttonBorder;
|
||||
}
|
||||
|
||||
private static Border textBorder;
|
||||
|
||||
/**
|
||||
* Returns a border instance for a text component
|
||||
* @since 1.3
|
||||
*/
|
||||
public static Border getTextBorder() {
|
||||
if (textBorder == null) {
|
||||
textBorder = new BorderUIResource.CompoundBorderUIResource(
|
||||
new MetalBorders.Flush3DBorder(),
|
||||
new BasicBorders.MarginBorder());
|
||||
}
|
||||
return textBorder;
|
||||
}
|
||||
|
||||
private static Border textFieldBorder;
|
||||
|
||||
/**
|
||||
* Returns a border instance for a JTextField
|
||||
* @since 1.3
|
||||
*/
|
||||
public static Border getTextFieldBorder() {
|
||||
if (textFieldBorder == null) {
|
||||
textFieldBorder = new BorderUIResource.CompoundBorderUIResource(
|
||||
new MetalBorders.TextFieldBorder(),
|
||||
new BasicBorders.MarginBorder());
|
||||
}
|
||||
return textFieldBorder;
|
||||
}
|
||||
|
||||
public static class TextFieldBorder extends Flush3DBorder {
|
||||
|
||||
public void paintBorder(Component c, Graphics g, int x, int y,
|
||||
int w, int h) {
|
||||
|
||||
if (!(c instanceof JTextComponent)) {
|
||||
// special case for non-text components (bug ID 4144840)
|
||||
if (c.isEnabled()) {
|
||||
MetalUtils.drawFlush3DBorder(g, x, y, w, h);
|
||||
} else {
|
||||
MetalUtils.drawDisabledBorder(g, x, y, w, h);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (c.isEnabled() && ((JTextComponent)c).isEditable()) {
|
||||
MetalUtils.drawFlush3DBorder(g, x, y, w, h);
|
||||
} else {
|
||||
MetalUtils.drawDisabledBorder(g, x, y, w, h);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static class ScrollPaneBorder extends AbstractBorder implements UIResource {
|
||||
public void paintBorder(Component c, Graphics g, int x, int y,
|
||||
int w, int h) {
|
||||
|
||||
if (!(c instanceof JScrollPane)) {
|
||||
return;
|
||||
}
|
||||
JScrollPane scroll = (JScrollPane)c;
|
||||
JComponent colHeader = scroll.getColumnHeader();
|
||||
int colHeaderHeight = 0;
|
||||
if (colHeader != null)
|
||||
colHeaderHeight = colHeader.getHeight();
|
||||
|
||||
JComponent rowHeader = scroll.getRowHeader();
|
||||
int rowHeaderWidth = 0;
|
||||
if (rowHeader != null)
|
||||
rowHeaderWidth = rowHeader.getWidth();
|
||||
|
||||
|
||||
g.translate( x, y);
|
||||
|
||||
g.setColor( MetalLookAndFeel.getControlDarkShadow() );
|
||||
g.drawRect( 0, 0, w-2, h-2 );
|
||||
g.setColor( MetalLookAndFeel.getControlHighlight() );
|
||||
|
||||
g.drawLine( w-1, 1, w-1, h-1);
|
||||
g.drawLine( 1, h-1, w-1, h-1);
|
||||
|
||||
g.setColor( MetalLookAndFeel.getControl() );
|
||||
g.drawLine( w-2, 2+colHeaderHeight, w-2, 2+colHeaderHeight );
|
||||
g.drawLine( 1+rowHeaderWidth, h-2, 1+rowHeaderWidth, h-2 );
|
||||
|
||||
g.translate( -x, -y);
|
||||
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets insets) {
|
||||
insets.set(1, 1, 2, 2);
|
||||
return insets;
|
||||
}
|
||||
}
|
||||
|
||||
private static Border toggleButtonBorder;
|
||||
|
||||
/**
|
||||
* Returns a border instance for a JToggleButton
|
||||
* @since 1.3
|
||||
*/
|
||||
public static Border getToggleButtonBorder() {
|
||||
if (toggleButtonBorder == null) {
|
||||
toggleButtonBorder = new BorderUIResource.CompoundBorderUIResource(
|
||||
new MetalBorders.ToggleButtonBorder(),
|
||||
new BasicBorders.MarginBorder());
|
||||
}
|
||||
return toggleButtonBorder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.3
|
||||
*/
|
||||
public static class ToggleButtonBorder extends ButtonBorder {
|
||||
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
|
||||
AbstractButton button = (AbstractButton)c;
|
||||
ButtonModel model = button.getModel();
|
||||
if (MetalLookAndFeel.usingOcean()) {
|
||||
if(model.isArmed() || !button.isEnabled()) {
|
||||
super.paintBorder(c, g, x, y, w, h);
|
||||
}
|
||||
else {
|
||||
g.setColor(MetalLookAndFeel.getControlDarkShadow());
|
||||
g.drawRect(0, 0, w - 1, h - 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (! c.isEnabled() ) {
|
||||
MetalUtils.drawDisabledBorder( g, x, y, w-1, h-1 );
|
||||
} else {
|
||||
if ( model.isPressed() && model.isArmed() ) {
|
||||
MetalUtils.drawPressed3DBorder( g, x, y, w, h );
|
||||
} else if ( model.isSelected() ) {
|
||||
MetalUtils.drawDark3DBorder( g, x, y, w, h );
|
||||
} else {
|
||||
MetalUtils.drawFlush3DBorder( g, x, y, w, h );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Border for a Table Header
|
||||
* @since 1.3
|
||||
*/
|
||||
public static class TableHeaderBorder extends javax.swing.border.AbstractBorder {
|
||||
protected Insets editorBorderInsets = new Insets( 2, 2, 2, 0 );
|
||||
|
||||
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
|
||||
g.translate( x, y );
|
||||
|
||||
g.setColor( MetalLookAndFeel.getControlDarkShadow() );
|
||||
g.drawLine( w-1, 0, w-1, h-1 );
|
||||
g.drawLine( 1, h-1, w-1, h-1 );
|
||||
g.setColor( MetalLookAndFeel.getControlHighlight() );
|
||||
g.drawLine( 0, 0, w-2, 0 );
|
||||
g.drawLine( 0, 0, 0, h-2 );
|
||||
|
||||
g.translate( -x, -y );
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets insets) {
|
||||
insets.set(2, 2, 2, 0);
|
||||
return insets;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a border instance for a Desktop Icon
|
||||
* @since 1.3
|
||||
*/
|
||||
public static Border getDesktopIconBorder() {
|
||||
return new BorderUIResource.CompoundBorderUIResource(
|
||||
new LineBorder(MetalLookAndFeel.getControlDarkShadow(), 1),
|
||||
new MatteBorder (2,2,1,2, MetalLookAndFeel.getControl()));
|
||||
}
|
||||
|
||||
static Border getToolBarRolloverBorder() {
|
||||
if (MetalLookAndFeel.usingOcean()) {
|
||||
return new CompoundBorder(
|
||||
new MetalBorders.ButtonBorder(),
|
||||
new MetalBorders.RolloverMarginBorder());
|
||||
}
|
||||
return new CompoundBorder(new MetalBorders.RolloverButtonBorder(),
|
||||
new MetalBorders.RolloverMarginBorder());
|
||||
}
|
||||
|
||||
static Border getToolBarNonrolloverBorder() {
|
||||
if (MetalLookAndFeel.usingOcean()) {
|
||||
new CompoundBorder(
|
||||
new MetalBorders.ButtonBorder(),
|
||||
new MetalBorders.RolloverMarginBorder());
|
||||
}
|
||||
return new CompoundBorder(new MetalBorders.ButtonBorder(),
|
||||
new MetalBorders.RolloverMarginBorder());
|
||||
}
|
||||
}
|
||||
235
jdkSrc/jdk8/javax/swing/plaf/metal/MetalBumps.java
Normal file
235
jdkSrc/jdk8/javax/swing/plaf/metal/MetalBumps.java
Normal file
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import sun.awt.AppContext;
|
||||
|
||||
/**
|
||||
* Implements the bumps used throughout the Metal Look and Feel.
|
||||
*
|
||||
* @author Tom Santos
|
||||
* @author Steve Wilson
|
||||
*/
|
||||
|
||||
|
||||
class MetalBumps implements Icon {
|
||||
|
||||
static final Color ALPHA = new Color(0, 0, 0, 0);
|
||||
|
||||
protected int xBumps;
|
||||
protected int yBumps;
|
||||
protected Color topColor;
|
||||
protected Color shadowColor;
|
||||
protected Color backColor;
|
||||
|
||||
private static final Object METAL_BUMPS = new Object();
|
||||
protected BumpBuffer buffer;
|
||||
|
||||
/**
|
||||
* Creates MetalBumps of the specified size with the specified colors.
|
||||
* If <code>newBackColor</code> is null, the background will be
|
||||
* transparent.
|
||||
*/
|
||||
public MetalBumps( int width, int height,
|
||||
Color newTopColor, Color newShadowColor, Color newBackColor ) {
|
||||
setBumpArea( width, height );
|
||||
setBumpColors( newTopColor, newShadowColor, newBackColor );
|
||||
}
|
||||
|
||||
private static BumpBuffer createBuffer(GraphicsConfiguration gc,
|
||||
Color topColor, Color shadowColor, Color backColor) {
|
||||
AppContext context = AppContext.getAppContext();
|
||||
List<BumpBuffer> buffers = (List<BumpBuffer>) context.get(METAL_BUMPS);
|
||||
if (buffers == null) {
|
||||
buffers = new ArrayList<BumpBuffer>();
|
||||
context.put(METAL_BUMPS, buffers);
|
||||
}
|
||||
for (BumpBuffer buffer : buffers) {
|
||||
if (buffer.hasSameConfiguration(gc, topColor, shadowColor, backColor)) {
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
BumpBuffer buffer = new BumpBuffer(gc, topColor, shadowColor, backColor);
|
||||
buffers.add(buffer);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public void setBumpArea( Dimension bumpArea ) {
|
||||
setBumpArea( bumpArea.width, bumpArea.height );
|
||||
}
|
||||
|
||||
public void setBumpArea( int width, int height ) {
|
||||
xBumps = width / 2;
|
||||
yBumps = height / 2;
|
||||
}
|
||||
|
||||
public void setBumpColors( Color newTopColor, Color newShadowColor, Color newBackColor ) {
|
||||
topColor = newTopColor;
|
||||
shadowColor = newShadowColor;
|
||||
if (newBackColor == null) {
|
||||
backColor = ALPHA;
|
||||
}
|
||||
else {
|
||||
backColor = newBackColor;
|
||||
}
|
||||
}
|
||||
|
||||
public void paintIcon( Component c, Graphics g, int x, int y ) {
|
||||
GraphicsConfiguration gc = (g instanceof Graphics2D) ?
|
||||
((Graphics2D) g).getDeviceConfiguration() : null;
|
||||
|
||||
if ((buffer == null) || !buffer.hasSameConfiguration(gc, topColor, shadowColor, backColor)) {
|
||||
buffer = createBuffer(gc, topColor, shadowColor, backColor);
|
||||
}
|
||||
|
||||
int bufferWidth = BumpBuffer.IMAGE_SIZE;
|
||||
int bufferHeight = BumpBuffer.IMAGE_SIZE;
|
||||
int iconWidth = getIconWidth();
|
||||
int iconHeight = getIconHeight();
|
||||
int x2 = x + iconWidth;
|
||||
int y2 = y + iconHeight;
|
||||
int savex = x;
|
||||
|
||||
while (y < y2) {
|
||||
int h = Math.min(y2 - y, bufferHeight);
|
||||
for (x = savex; x < x2; x += bufferWidth) {
|
||||
int w = Math.min(x2 - x, bufferWidth);
|
||||
g.drawImage(buffer.getImage(),
|
||||
x, y, x+w, y+h,
|
||||
0, 0, w, h,
|
||||
null);
|
||||
}
|
||||
y += bufferHeight;
|
||||
}
|
||||
}
|
||||
|
||||
public int getIconWidth() {
|
||||
return xBumps * 2;
|
||||
}
|
||||
|
||||
public int getIconHeight() {
|
||||
return yBumps * 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class BumpBuffer {
|
||||
|
||||
static final int IMAGE_SIZE = 64;
|
||||
|
||||
transient Image image;
|
||||
Color topColor;
|
||||
Color shadowColor;
|
||||
Color backColor;
|
||||
private GraphicsConfiguration gc;
|
||||
|
||||
public BumpBuffer(GraphicsConfiguration gc, Color aTopColor,
|
||||
Color aShadowColor, Color aBackColor) {
|
||||
this.gc = gc;
|
||||
topColor = aTopColor;
|
||||
shadowColor = aShadowColor;
|
||||
backColor = aBackColor;
|
||||
createImage();
|
||||
fillBumpBuffer();
|
||||
}
|
||||
|
||||
public boolean hasSameConfiguration(GraphicsConfiguration gc,
|
||||
Color aTopColor, Color aShadowColor,
|
||||
Color aBackColor) {
|
||||
if (this.gc != null) {
|
||||
if (!this.gc.equals(gc)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (gc != null) {
|
||||
return false;
|
||||
}
|
||||
return topColor.equals( aTopColor ) &&
|
||||
shadowColor.equals( aShadowColor ) &&
|
||||
backColor.equals( aBackColor );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Image containing the bumps appropriate for the passed in
|
||||
* <code>GraphicsConfiguration</code>.
|
||||
*/
|
||||
public Image getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints the bumps into the current image.
|
||||
*/
|
||||
private void fillBumpBuffer() {
|
||||
Graphics g = image.getGraphics();
|
||||
|
||||
g.setColor( backColor );
|
||||
g.fillRect( 0, 0, IMAGE_SIZE, IMAGE_SIZE );
|
||||
|
||||
g.setColor(topColor);
|
||||
for (int x = 0; x < IMAGE_SIZE; x+=4) {
|
||||
for (int y = 0; y < IMAGE_SIZE; y+=4) {
|
||||
g.drawLine( x, y, x, y );
|
||||
g.drawLine( x+2, y+2, x+2, y+2);
|
||||
}
|
||||
}
|
||||
|
||||
g.setColor(shadowColor);
|
||||
for (int x = 0; x < IMAGE_SIZE; x+=4) {
|
||||
for (int y = 0; y < IMAGE_SIZE; y+=4) {
|
||||
g.drawLine( x+1, y+1, x+1, y+1 );
|
||||
g.drawLine( x+3, y+3, x+3, y+3);
|
||||
}
|
||||
}
|
||||
g.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the image appropriate for the passed in
|
||||
* <code>GraphicsConfiguration</code>, which may be null.
|
||||
*/
|
||||
private void createImage() {
|
||||
if (gc != null) {
|
||||
image = gc.createCompatibleImage(IMAGE_SIZE, IMAGE_SIZE,
|
||||
(backColor != MetalBumps.ALPHA) ? Transparency.OPAQUE :
|
||||
Transparency.BITMASK);
|
||||
}
|
||||
else {
|
||||
int cmap[] = { backColor.getRGB(), topColor.getRGB(),
|
||||
shadowColor.getRGB() };
|
||||
IndexColorModel icm = new IndexColorModel(8, 3, cmap, 0, false,
|
||||
(backColor == MetalBumps.ALPHA) ? 0 : -1,
|
||||
DataBuffer.TYPE_BYTE);
|
||||
image = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE,
|
||||
BufferedImage.TYPE_BYTE_INDEXED, icm);
|
||||
}
|
||||
}
|
||||
}
|
||||
207
jdkSrc/jdk8/javax/swing/plaf/metal/MetalButtonUI.java
Normal file
207
jdkSrc/jdk8/javax/swing/plaf/metal/MetalButtonUI.java
Normal file
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import sun.swing.SwingUtilities2;
|
||||
import sun.awt.AppContext;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.beans.*;
|
||||
import javax.swing.plaf.*;
|
||||
|
||||
/**
|
||||
* MetalButtonUI implementation
|
||||
* <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™
|
||||
* has been added to the <code>java.beans</code> package.
|
||||
* Please see {@link java.beans.XMLEncoder}.
|
||||
*
|
||||
* @author Tom Santos
|
||||
*/
|
||||
public class MetalButtonUI extends BasicButtonUI {
|
||||
// NOTE: These are not really needed, but at this point we can't pull
|
||||
// them. Their values are updated purely for historical reasons.
|
||||
protected Color focusColor;
|
||||
protected Color selectColor;
|
||||
protected Color disabledTextColor;
|
||||
|
||||
private static final Object METAL_BUTTON_UI_KEY = new Object();
|
||||
|
||||
// ********************************
|
||||
// Create PLAF
|
||||
// ********************************
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
AppContext appContext = AppContext.getAppContext();
|
||||
MetalButtonUI metalButtonUI =
|
||||
(MetalButtonUI) appContext.get(METAL_BUTTON_UI_KEY);
|
||||
if (metalButtonUI == null) {
|
||||
metalButtonUI = new MetalButtonUI();
|
||||
appContext.put(METAL_BUTTON_UI_KEY, metalButtonUI);
|
||||
}
|
||||
return metalButtonUI;
|
||||
}
|
||||
|
||||
// ********************************
|
||||
// Install
|
||||
// ********************************
|
||||
public void installDefaults(AbstractButton b) {
|
||||
super.installDefaults(b);
|
||||
}
|
||||
|
||||
public void uninstallDefaults(AbstractButton b) {
|
||||
super.uninstallDefaults(b);
|
||||
}
|
||||
|
||||
// ********************************
|
||||
// Create Listeners
|
||||
// ********************************
|
||||
protected BasicButtonListener createButtonListener(AbstractButton b) {
|
||||
return super.createButtonListener(b);
|
||||
}
|
||||
|
||||
|
||||
// ********************************
|
||||
// Default Accessors
|
||||
// ********************************
|
||||
protected Color getSelectColor() {
|
||||
selectColor = UIManager.getColor(getPropertyPrefix() + "select");
|
||||
return selectColor;
|
||||
}
|
||||
|
||||
protected Color getDisabledTextColor() {
|
||||
disabledTextColor = UIManager.getColor(getPropertyPrefix() +
|
||||
"disabledText");
|
||||
return disabledTextColor;
|
||||
}
|
||||
|
||||
protected Color getFocusColor() {
|
||||
focusColor = UIManager.getColor(getPropertyPrefix() + "focus");
|
||||
return focusColor;
|
||||
}
|
||||
|
||||
// ********************************
|
||||
// Paint
|
||||
// ********************************
|
||||
/**
|
||||
* If necessary paints the background of the component, then
|
||||
* invokes <code>paint</code>.
|
||||
*
|
||||
* @param g Graphics to paint to
|
||||
* @param c JComponent painting on
|
||||
* @throws NullPointerException if <code>g</code> or <code>c</code> is
|
||||
* null
|
||||
* @see javax.swing.plaf.ComponentUI#update
|
||||
* @see javax.swing.plaf.ComponentUI#paint
|
||||
* @since 1.5
|
||||
*/
|
||||
public void update(Graphics g, JComponent c) {
|
||||
AbstractButton button = (AbstractButton)c;
|
||||
if ((c.getBackground() instanceof UIResource) &&
|
||||
button.isContentAreaFilled() && c.isEnabled()) {
|
||||
ButtonModel model = button.getModel();
|
||||
if (!MetalUtils.isToolBarButton(c)) {
|
||||
if (!model.isArmed() && !model.isPressed() &&
|
||||
MetalUtils.drawGradient(
|
||||
c, g, "Button.gradient", 0, 0, c.getWidth(),
|
||||
c.getHeight(), true)) {
|
||||
paint(g, c);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (model.isRollover() && MetalUtils.drawGradient(
|
||||
c, g, "Button.gradient", 0, 0, c.getWidth(),
|
||||
c.getHeight(), true)) {
|
||||
paint(g, c);
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.update(g, c);
|
||||
}
|
||||
|
||||
protected void paintButtonPressed(Graphics g, AbstractButton b) {
|
||||
if ( b.isContentAreaFilled() ) {
|
||||
Dimension size = b.getSize();
|
||||
g.setColor(getSelectColor());
|
||||
g.fillRect(0, 0, size.width, size.height);
|
||||
}
|
||||
}
|
||||
|
||||
protected void paintFocus(Graphics g, AbstractButton b,
|
||||
Rectangle viewRect, Rectangle textRect, Rectangle iconRect){
|
||||
|
||||
Rectangle focusRect = new Rectangle();
|
||||
String text = b.getText();
|
||||
boolean isIcon = b.getIcon() != null;
|
||||
|
||||
// If there is text
|
||||
if ( text != null && !text.equals( "" ) ) {
|
||||
if ( !isIcon ) {
|
||||
focusRect.setBounds( textRect );
|
||||
}
|
||||
else {
|
||||
focusRect.setBounds( iconRect.union( textRect ) );
|
||||
}
|
||||
}
|
||||
// If there is an icon and no text
|
||||
else if ( isIcon ) {
|
||||
focusRect.setBounds( iconRect );
|
||||
}
|
||||
|
||||
g.setColor(getFocusColor());
|
||||
g.drawRect((focusRect.x-1), (focusRect.y-1),
|
||||
focusRect.width+1, focusRect.height+1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
|
||||
AbstractButton b = (AbstractButton) c;
|
||||
ButtonModel model = b.getModel();
|
||||
FontMetrics fm = SwingUtilities2.getFontMetrics(c, g);
|
||||
int mnemIndex = b.getDisplayedMnemonicIndex();
|
||||
|
||||
/* Draw the Text */
|
||||
if(model.isEnabled()) {
|
||||
/*** paint the text normally */
|
||||
g.setColor(b.getForeground());
|
||||
}
|
||||
else {
|
||||
/*** paint the text disabled ***/
|
||||
g.setColor(getDisabledTextColor());
|
||||
}
|
||||
SwingUtilities2.drawStringUnderlineCharAt(c, g,text,mnemIndex,
|
||||
textRect.x, textRect.y + fm.getAscent());
|
||||
}
|
||||
}
|
||||
107
jdkSrc/jdk8/javax/swing/plaf/metal/MetalCheckBoxIcon.java
Normal file
107
jdkSrc/jdk8/javax/swing/plaf/metal/MetalCheckBoxIcon.java
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import javax.swing.plaf.*;
|
||||
|
||||
/**
|
||||
* CheckboxIcon implementation for OrganicCheckBoxUI
|
||||
* <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™
|
||||
* has been added to the <code>java.beans</code> package.
|
||||
* Please see {@link java.beans.XMLEncoder}.
|
||||
*
|
||||
* @author Steve Wilson
|
||||
*/
|
||||
public class MetalCheckBoxIcon implements Icon, UIResource, Serializable {
|
||||
|
||||
protected int getControlSize() { return 13; }
|
||||
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
|
||||
JCheckBox cb = (JCheckBox)c;
|
||||
ButtonModel model = cb.getModel();
|
||||
int controlSize = getControlSize();
|
||||
|
||||
boolean drawCheck = model.isSelected();
|
||||
|
||||
if (model.isEnabled()) {
|
||||
if(cb.isBorderPaintedFlat()) {
|
||||
g.setColor(MetalLookAndFeel.getControlDarkShadow());
|
||||
g.drawRect(x+1, y, controlSize-1, controlSize-1);
|
||||
}
|
||||
if (model.isPressed() && model.isArmed()) {
|
||||
if(cb.isBorderPaintedFlat()) {
|
||||
g.setColor(MetalLookAndFeel.getControlShadow());
|
||||
g.fillRect(x+2, y+1, controlSize-2, controlSize-2);
|
||||
} else {
|
||||
g.setColor(MetalLookAndFeel.getControlShadow());
|
||||
g.fillRect(x, y, controlSize-1, controlSize-1);
|
||||
MetalUtils.drawPressed3DBorder(g, x, y, controlSize, controlSize);
|
||||
}
|
||||
} else if(!cb.isBorderPaintedFlat()) {
|
||||
MetalUtils.drawFlush3DBorder(g, x, y, controlSize, controlSize);
|
||||
}
|
||||
g.setColor( MetalLookAndFeel.getControlInfo() );
|
||||
} else {
|
||||
g.setColor( MetalLookAndFeel.getControlShadow() );
|
||||
g.drawRect( x, y, controlSize-1, controlSize-1);
|
||||
}
|
||||
|
||||
|
||||
if(drawCheck) {
|
||||
if (cb.isBorderPaintedFlat()) {
|
||||
x++;
|
||||
}
|
||||
drawCheck(c,g,x,y);
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawCheck(Component c, Graphics g, int x, int y) {
|
||||
int controlSize = getControlSize();
|
||||
g.fillRect( x+3, y+5, 2, controlSize-8 );
|
||||
g.drawLine( x+(controlSize-4), y+3, x+5, y+(controlSize-6) );
|
||||
g.drawLine( x+(controlSize-4), y+4, x+5, y+(controlSize-5) );
|
||||
}
|
||||
|
||||
public int getIconWidth() {
|
||||
return getControlSize();
|
||||
}
|
||||
|
||||
public int getIconHeight() {
|
||||
return getControlSize();
|
||||
}
|
||||
}
|
||||
100
jdkSrc/jdk8/javax/swing/plaf/metal/MetalCheckBoxUI.java
Normal file
100
jdkSrc/jdk8/javax/swing/plaf/metal/MetalCheckBoxUI.java
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import sun.awt.AppContext;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.basic.BasicCheckBoxUI;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.plaf.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* CheckboxUI implementation for MetalCheckboxUI
|
||||
* <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™
|
||||
* has been added to the <code>java.beans</code> package.
|
||||
* Please see {@link java.beans.XMLEncoder}.
|
||||
*
|
||||
* @author Michael C. Albers
|
||||
*
|
||||
*/
|
||||
public class MetalCheckBoxUI extends MetalRadioButtonUI {
|
||||
|
||||
// NOTE: MetalCheckBoxUI inherts from MetalRadioButtonUI instead
|
||||
// of BasicCheckBoxUI because we want to pick up all the
|
||||
// painting changes made in MetalRadioButtonUI.
|
||||
|
||||
private static final Object METAL_CHECK_BOX_UI_KEY = new Object();
|
||||
|
||||
private final static String propertyPrefix = "CheckBox" + ".";
|
||||
|
||||
private boolean defaults_initialized = false;
|
||||
|
||||
// ********************************
|
||||
// Create PlAF
|
||||
// ********************************
|
||||
public static ComponentUI createUI(JComponent b) {
|
||||
AppContext appContext = AppContext.getAppContext();
|
||||
MetalCheckBoxUI checkboxUI =
|
||||
(MetalCheckBoxUI) appContext.get(METAL_CHECK_BOX_UI_KEY);
|
||||
if (checkboxUI == null) {
|
||||
checkboxUI = new MetalCheckBoxUI();
|
||||
appContext.put(METAL_CHECK_BOX_UI_KEY, checkboxUI);
|
||||
}
|
||||
return checkboxUI;
|
||||
}
|
||||
|
||||
public String getPropertyPrefix() {
|
||||
return propertyPrefix;
|
||||
}
|
||||
|
||||
// ********************************
|
||||
// Defaults
|
||||
// ********************************
|
||||
public void installDefaults(AbstractButton b) {
|
||||
super.installDefaults(b);
|
||||
if(!defaults_initialized) {
|
||||
icon = UIManager.getIcon(getPropertyPrefix() + "icon");
|
||||
defaults_initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected void uninstallDefaults(AbstractButton b) {
|
||||
super.uninstallDefaults(b);
|
||||
defaults_initialized = false;
|
||||
}
|
||||
|
||||
}
|
||||
224
jdkSrc/jdk8/javax/swing/plaf/metal/MetalComboBoxButton.java
Normal file
224
jdkSrc/jdk8/javax/swing/plaf/metal/MetalComboBoxButton.java
Normal file
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.border.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* JButton subclass to help out MetalComboBoxUI
|
||||
* <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™
|
||||
* has been added to the <code>java.beans</code> package.
|
||||
* Please see {@link java.beans.XMLEncoder}.
|
||||
*
|
||||
* @see MetalComboBoxButton
|
||||
* @author Tom Santos
|
||||
*/
|
||||
public class MetalComboBoxButton extends JButton {
|
||||
protected JComboBox comboBox;
|
||||
protected JList listBox;
|
||||
protected CellRendererPane rendererPane;
|
||||
protected Icon comboIcon;
|
||||
protected boolean iconOnly = false;
|
||||
|
||||
public final JComboBox getComboBox() { return comboBox;}
|
||||
public final void setComboBox( JComboBox cb ) { comboBox = cb;}
|
||||
|
||||
public final Icon getComboIcon() { return comboIcon;}
|
||||
public final void setComboIcon( Icon i ) { comboIcon = i;}
|
||||
|
||||
public final boolean isIconOnly() { return iconOnly;}
|
||||
public final void setIconOnly( boolean isIconOnly ) { iconOnly = isIconOnly;}
|
||||
|
||||
MetalComboBoxButton() {
|
||||
super( "" );
|
||||
DefaultButtonModel model = new DefaultButtonModel() {
|
||||
public void setArmed( boolean armed ) {
|
||||
super.setArmed( isPressed() ? true : armed );
|
||||
}
|
||||
};
|
||||
setModel( model );
|
||||
}
|
||||
|
||||
public MetalComboBoxButton( JComboBox cb, Icon i,
|
||||
CellRendererPane pane, JList list ) {
|
||||
this();
|
||||
comboBox = cb;
|
||||
comboIcon = i;
|
||||
rendererPane = pane;
|
||||
listBox = list;
|
||||
setEnabled( comboBox.isEnabled() );
|
||||
}
|
||||
|
||||
public MetalComboBoxButton( JComboBox cb, Icon i, boolean onlyIcon,
|
||||
CellRendererPane pane, JList list ) {
|
||||
this( cb, i, pane, list );
|
||||
iconOnly = onlyIcon;
|
||||
}
|
||||
|
||||
public boolean isFocusTraversable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
super.setEnabled(enabled);
|
||||
|
||||
// Set the background and foreground to the combobox colors.
|
||||
if (enabled) {
|
||||
setBackground(comboBox.getBackground());
|
||||
setForeground(comboBox.getForeground());
|
||||
} else {
|
||||
setBackground(UIManager.getColor("ComboBox.disabledBackground"));
|
||||
setForeground(UIManager.getColor("ComboBox.disabledForeground"));
|
||||
}
|
||||
}
|
||||
|
||||
public void paintComponent( Graphics g ) {
|
||||
boolean leftToRight = MetalUtils.isLeftToRight(comboBox);
|
||||
|
||||
// Paint the button as usual
|
||||
super.paintComponent( g );
|
||||
|
||||
Insets insets = getInsets();
|
||||
|
||||
int width = getWidth() - (insets.left + insets.right);
|
||||
int height = getHeight() - (insets.top + insets.bottom);
|
||||
|
||||
if ( height <= 0 || width <= 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
int left = insets.left;
|
||||
int top = insets.top;
|
||||
int right = left + (width - 1);
|
||||
int bottom = top + (height - 1);
|
||||
|
||||
int iconWidth = 0;
|
||||
int iconLeft = (leftToRight) ? right : left;
|
||||
|
||||
// Paint the icon
|
||||
if ( comboIcon != null ) {
|
||||
iconWidth = comboIcon.getIconWidth();
|
||||
int iconHeight = comboIcon.getIconHeight();
|
||||
int iconTop = 0;
|
||||
|
||||
if ( iconOnly ) {
|
||||
iconLeft = (getWidth() / 2) - (iconWidth / 2);
|
||||
iconTop = (getHeight() / 2) - (iconHeight / 2);
|
||||
}
|
||||
else {
|
||||
if (leftToRight) {
|
||||
iconLeft = (left + (width - 1)) - iconWidth;
|
||||
}
|
||||
else {
|
||||
iconLeft = left;
|
||||
}
|
||||
iconTop = (top + ((bottom - top) / 2)) - (iconHeight / 2);
|
||||
}
|
||||
|
||||
comboIcon.paintIcon( this, g, iconLeft, iconTop );
|
||||
|
||||
// Paint the focus
|
||||
if ( comboBox.hasFocus() && (!MetalLookAndFeel.usingOcean() ||
|
||||
comboBox.isEditable())) {
|
||||
g.setColor( MetalLookAndFeel.getFocusColor() );
|
||||
g.drawRect( left - 1, top - 1, width + 3, height + 1 );
|
||||
}
|
||||
}
|
||||
|
||||
if (MetalLookAndFeel.usingOcean()) {
|
||||
// With Ocean the button only paints the arrow, bail.
|
||||
return;
|
||||
}
|
||||
|
||||
// Let the renderer paint
|
||||
if ( ! iconOnly && comboBox != null ) {
|
||||
ListCellRenderer renderer = comboBox.getRenderer();
|
||||
Component c;
|
||||
boolean renderPressed = getModel().isPressed();
|
||||
c = renderer.getListCellRendererComponent(listBox,
|
||||
comboBox.getSelectedItem(),
|
||||
-1,
|
||||
renderPressed,
|
||||
false);
|
||||
c.setFont(rendererPane.getFont());
|
||||
|
||||
if ( model.isArmed() && model.isPressed() ) {
|
||||
if ( isOpaque() ) {
|
||||
c.setBackground(UIManager.getColor("Button.select"));
|
||||
}
|
||||
c.setForeground(comboBox.getForeground());
|
||||
}
|
||||
else if ( !comboBox.isEnabled() ) {
|
||||
if ( isOpaque() ) {
|
||||
c.setBackground(UIManager.getColor("ComboBox.disabledBackground"));
|
||||
}
|
||||
c.setForeground(UIManager.getColor("ComboBox.disabledForeground"));
|
||||
}
|
||||
else {
|
||||
c.setForeground(comboBox.getForeground());
|
||||
c.setBackground(comboBox.getBackground());
|
||||
}
|
||||
|
||||
|
||||
int cWidth = width - (insets.right + iconWidth);
|
||||
|
||||
// Fix for 4238829: should lay out the JPanel.
|
||||
boolean shouldValidate = false;
|
||||
if (c instanceof JPanel) {
|
||||
shouldValidate = true;
|
||||
}
|
||||
|
||||
if (leftToRight) {
|
||||
rendererPane.paintComponent( g, c, this,
|
||||
left, top, cWidth, height, shouldValidate );
|
||||
}
|
||||
else {
|
||||
rendererPane.paintComponent( g, c, this,
|
||||
left + iconWidth, top, cWidth, height, shouldValidate );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize() {
|
||||
Dimension ret = new Dimension();
|
||||
Insets insets = getInsets();
|
||||
ret.width = insets.left + getComboIcon().getIconWidth() + insets.right;
|
||||
ret.height = insets.bottom + getComboIcon().getIconHeight() + insets.top;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
139
jdkSrc/jdk8/javax/swing/plaf/metal/MetalComboBoxEditor.java
Normal file
139
jdkSrc/jdk8/javax/swing/plaf/metal/MetalComboBoxEditor.java
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import java.io.Serializable;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.plaf.basic.BasicComboBoxEditor;
|
||||
|
||||
/**
|
||||
* The default editor for Metal editable combo boxes
|
||||
* <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™
|
||||
* has been added to the <code>java.beans</code> package.
|
||||
* Please see {@link java.beans.XMLEncoder}.
|
||||
*
|
||||
* @author Steve Wilson
|
||||
*/
|
||||
public class MetalComboBoxEditor extends BasicComboBoxEditor {
|
||||
|
||||
public MetalComboBoxEditor() {
|
||||
super();
|
||||
//editor.removeFocusListener(this);
|
||||
editor = new JTextField("",9) {
|
||||
// workaround for 4530952
|
||||
public void setText(String s) {
|
||||
if (getText().equals(s)) {
|
||||
return;
|
||||
}
|
||||
super.setText(s);
|
||||
}
|
||||
// The preferred and minimum sizes are overriden and padded by
|
||||
// 4 to keep the size as it previously was. Refer to bugs
|
||||
// 4775789 and 4517214 for details.
|
||||
public Dimension getPreferredSize() {
|
||||
Dimension pref = super.getPreferredSize();
|
||||
pref.height += 4;
|
||||
return pref;
|
||||
}
|
||||
public Dimension getMinimumSize() {
|
||||
Dimension min = super.getMinimumSize();
|
||||
min.height += 4;
|
||||
return min;
|
||||
}
|
||||
};
|
||||
|
||||
editor.setBorder( new EditorBorder() );
|
||||
//editor.addFocusListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* The default editor border <code>Insets</code>. This field
|
||||
* might not be used.
|
||||
*/
|
||||
protected static Insets editorBorderInsets = new Insets( 2, 2, 2, 0 );
|
||||
|
||||
class EditorBorder extends AbstractBorder {
|
||||
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
|
||||
g.translate( x, y );
|
||||
|
||||
if (MetalLookAndFeel.usingOcean()) {
|
||||
g.setColor(MetalLookAndFeel.getControlDarkShadow());
|
||||
g.drawRect(0, 0, w, h - 1);
|
||||
g.setColor(MetalLookAndFeel.getControlShadow());
|
||||
g.drawRect(1, 1, w - 2, h - 3);
|
||||
}
|
||||
else {
|
||||
g.setColor( MetalLookAndFeel.getControlDarkShadow() );
|
||||
g.drawLine( 0, 0, w-1, 0 );
|
||||
g.drawLine( 0, 0, 0, h-2 );
|
||||
g.drawLine( 0, h-2, w-1, h-2 );
|
||||
g.setColor( MetalLookAndFeel.getControlHighlight() );
|
||||
g.drawLine( 1, 1, w-1, 1 );
|
||||
g.drawLine( 1, 1, 1, h-1 );
|
||||
g.drawLine( 1, h-1, w-1, h-1 );
|
||||
g.setColor( MetalLookAndFeel.getControl() );
|
||||
g.drawLine( 1, h-2, 1, h-2 );
|
||||
}
|
||||
|
||||
g.translate( -x, -y );
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets insets) {
|
||||
insets.set(2, 2, 2, 0);
|
||||
return insets;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A subclass of BasicComboBoxEditor that implements UIResource.
|
||||
* BasicComboBoxEditor doesn't implement UIResource
|
||||
* directly so that applications can safely override the
|
||||
* cellRenderer property with BasicListCellRenderer subclasses.
|
||||
* <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™
|
||||
* has been added to the <code>java.beans</code> package.
|
||||
* Please see {@link java.beans.XMLEncoder}.
|
||||
*/
|
||||
public static class UIResource extends MetalComboBoxEditor
|
||||
implements javax.swing.plaf.UIResource {
|
||||
}
|
||||
}
|
||||
74
jdkSrc/jdk8/javax/swing/plaf/metal/MetalComboBoxIcon.java
Normal file
74
jdkSrc/jdk8/javax/swing/plaf/metal/MetalComboBoxIcon.java
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2000, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.border.*;
|
||||
import java.io.Serializable;
|
||||
import javax.swing.plaf.basic.BasicComboBoxUI;
|
||||
|
||||
|
||||
/**
|
||||
* This utility class draws the horizontal bars which indicate a MetalComboBox
|
||||
*
|
||||
* @see MetalComboBoxUI
|
||||
* @author Tom Santos
|
||||
*/
|
||||
public class MetalComboBoxIcon implements Icon, Serializable {
|
||||
|
||||
/**
|
||||
* Paints the horizontal bars for the
|
||||
*/
|
||||
public void paintIcon(Component c, Graphics g, int x, int y){
|
||||
JComponent component = (JComponent)c;
|
||||
int iconWidth = getIconWidth();
|
||||
|
||||
g.translate( x, y );
|
||||
|
||||
g.setColor( component.isEnabled() ? MetalLookAndFeel.getControlInfo() : MetalLookAndFeel.getControlShadow() );
|
||||
g.drawLine( 0, 0, iconWidth - 1, 0 );
|
||||
g.drawLine( 1, 1, 1 + (iconWidth - 3), 1 );
|
||||
g.drawLine( 2, 2, 2 + (iconWidth - 5), 2 );
|
||||
g.drawLine( 3, 3, 3 + (iconWidth - 7), 3 );
|
||||
g.drawLine( 4, 4, 4 + (iconWidth - 9), 4 );
|
||||
|
||||
g.translate( -x, -y );
|
||||
}
|
||||
|
||||
/**
|
||||
* Created a stub to satisfy the interface.
|
||||
*/
|
||||
public int getIconWidth() { return 10; }
|
||||
|
||||
/**
|
||||
* Created a stub to satisfy the interface.
|
||||
*/
|
||||
public int getIconHeight() { return 5; }
|
||||
|
||||
}
|
||||
382
jdkSrc/jdk8/javax/swing/plaf/metal/MetalComboBoxUI.java
Normal file
382
jdkSrc/jdk8/javax/swing/plaf/metal/MetalComboBoxUI.java
Normal file
@@ -0,0 +1,382 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import java.io.Serializable;
|
||||
import java.beans.*;
|
||||
|
||||
|
||||
/**
|
||||
* Metal UI for JComboBox
|
||||
* <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™
|
||||
* has been added to the <code>java.beans</code> package.
|
||||
* Please see {@link java.beans.XMLEncoder}.
|
||||
*
|
||||
* @see MetalComboBoxEditor
|
||||
* @see MetalComboBoxButton
|
||||
* @author Tom Santos
|
||||
*/
|
||||
public class MetalComboBoxUI extends BasicComboBoxUI {
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new MetalComboBoxUI();
|
||||
}
|
||||
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
if (MetalLookAndFeel.usingOcean()) {
|
||||
super.paint(g, c);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If necessary paints the currently selected item.
|
||||
*
|
||||
* @param g Graphics to paint to
|
||||
* @param bounds Region to paint current value to
|
||||
* @param hasFocus whether or not the JComboBox has focus
|
||||
* @throws NullPointerException if any of the arguments are null.
|
||||
* @since 1.5
|
||||
*/
|
||||
public void paintCurrentValue(Graphics g, Rectangle bounds,
|
||||
boolean hasFocus) {
|
||||
// This is really only called if we're using ocean.
|
||||
if (MetalLookAndFeel.usingOcean()) {
|
||||
bounds.x += 2;
|
||||
bounds.width -= 3;
|
||||
if (arrowButton != null) {
|
||||
Insets buttonInsets = arrowButton.getInsets();
|
||||
bounds.y += buttonInsets.top;
|
||||
bounds.height -= (buttonInsets.top + buttonInsets.bottom);
|
||||
}
|
||||
else {
|
||||
bounds.y += 2;
|
||||
bounds.height -= 4;
|
||||
}
|
||||
super.paintCurrentValue(g, bounds, hasFocus);
|
||||
}
|
||||
else if (g == null || bounds == null) {
|
||||
throw new NullPointerException(
|
||||
"Must supply a non-null Graphics and Rectangle");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If necessary paints the background of the currently selected item.
|
||||
*
|
||||
* @param g Graphics to paint to
|
||||
* @param bounds Region to paint background to
|
||||
* @param hasFocus whether or not the JComboBox has focus
|
||||
* @throws NullPointerException if any of the arguments are null.
|
||||
* @since 1.5
|
||||
*/
|
||||
public void paintCurrentValueBackground(Graphics g, Rectangle bounds,
|
||||
boolean hasFocus) {
|
||||
// This is really only called if we're using ocean.
|
||||
if (MetalLookAndFeel.usingOcean()) {
|
||||
g.setColor(MetalLookAndFeel.getControlDarkShadow());
|
||||
g.drawRect(bounds.x, bounds.y, bounds.width, bounds.height - 1);
|
||||
g.setColor(MetalLookAndFeel.getControlShadow());
|
||||
g.drawRect(bounds.x + 1, bounds.y + 1, bounds.width - 2,
|
||||
bounds.height - 3);
|
||||
if (hasFocus && !isPopupVisible(comboBox) &&
|
||||
arrowButton != null) {
|
||||
g.setColor(listBox.getSelectionBackground());
|
||||
Insets buttonInsets = arrowButton.getInsets();
|
||||
if (buttonInsets.top > 2) {
|
||||
g.fillRect(bounds.x + 2, bounds.y + 2, bounds.width - 3,
|
||||
buttonInsets.top - 2);
|
||||
}
|
||||
if (buttonInsets.bottom > 2) {
|
||||
g.fillRect(bounds.x + 2, bounds.y + bounds.height -
|
||||
buttonInsets.bottom, bounds.width - 3,
|
||||
buttonInsets.bottom - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (g == null || bounds == null) {
|
||||
throw new NullPointerException(
|
||||
"Must supply a non-null Graphics and Rectangle");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the baseline.
|
||||
*
|
||||
* @throws NullPointerException {@inheritDoc}
|
||||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
* @see javax.swing.JComponent#getBaseline(int, int)
|
||||
* @since 1.6
|
||||
*/
|
||||
public int getBaseline(JComponent c, int width, int height) {
|
||||
int baseline;
|
||||
if (MetalLookAndFeel.usingOcean() && height >= 4) {
|
||||
height -= 4;
|
||||
baseline = super.getBaseline(c, width, height);
|
||||
if (baseline >= 0) {
|
||||
baseline += 2;
|
||||
}
|
||||
}
|
||||
else {
|
||||
baseline = super.getBaseline(c, width, height);
|
||||
}
|
||||
return baseline;
|
||||
}
|
||||
|
||||
protected ComboBoxEditor createEditor() {
|
||||
return new MetalComboBoxEditor.UIResource();
|
||||
}
|
||||
|
||||
protected ComboPopup createPopup() {
|
||||
return super.createPopup();
|
||||
}
|
||||
|
||||
protected JButton createArrowButton() {
|
||||
boolean iconOnly = (comboBox.isEditable() ||
|
||||
MetalLookAndFeel.usingOcean());
|
||||
JButton button = new MetalComboBoxButton( comboBox,
|
||||
new MetalComboBoxIcon(),
|
||||
iconOnly,
|
||||
currentValuePane,
|
||||
listBox );
|
||||
button.setMargin( new Insets( 0, 1, 1, 3 ) );
|
||||
if (MetalLookAndFeel.usingOcean()) {
|
||||
// Disabled rollover effect.
|
||||
button.putClientProperty(MetalBorders.NO_BUTTON_ROLLOVER,
|
||||
Boolean.TRUE);
|
||||
}
|
||||
updateButtonForOcean(button);
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the necessary state on the ComboBoxButton for ocean.
|
||||
*/
|
||||
private void updateButtonForOcean(JButton button) {
|
||||
if (MetalLookAndFeel.usingOcean()) {
|
||||
// Ocean renders the focus in a different way, this
|
||||
// would be redundant.
|
||||
button.setFocusPainted(comboBox.isEditable());
|
||||
}
|
||||
}
|
||||
|
||||
public PropertyChangeListener createPropertyChangeListener() {
|
||||
return new MetalPropertyChangeListener();
|
||||
}
|
||||
|
||||
/**
|
||||
* This class should be treated as a "protected" inner class.
|
||||
* Instantiate it only within subclasses of {@code MetalComboBoxUI}.
|
||||
*/
|
||||
public class MetalPropertyChangeListener extends BasicComboBoxUI.PropertyChangeHandler {
|
||||
public void propertyChange(PropertyChangeEvent e) {
|
||||
super.propertyChange( e );
|
||||
String propertyName = e.getPropertyName();
|
||||
|
||||
if ( propertyName == "editable" ) {
|
||||
if(arrowButton instanceof MetalComboBoxButton) {
|
||||
MetalComboBoxButton button = (MetalComboBoxButton)arrowButton;
|
||||
button.setIconOnly( comboBox.isEditable() ||
|
||||
MetalLookAndFeel.usingOcean() );
|
||||
}
|
||||
comboBox.repaint();
|
||||
updateButtonForOcean(arrowButton);
|
||||
} else if ( propertyName == "background" ) {
|
||||
Color color = (Color)e.getNewValue();
|
||||
arrowButton.setBackground(color);
|
||||
listBox.setBackground(color);
|
||||
|
||||
} else if ( propertyName == "foreground" ) {
|
||||
Color color = (Color)e.getNewValue();
|
||||
arrowButton.setForeground(color);
|
||||
listBox.setForeground(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* As of Java 2 platform v1.4 this method is no longer used. Do not call or
|
||||
* override. All the functionality of this method is in the
|
||||
* MetalPropertyChangeListener.
|
||||
*
|
||||
* @deprecated As of Java 2 platform v1.4.
|
||||
*/
|
||||
@Deprecated
|
||||
protected void editablePropertyChanged( PropertyChangeEvent e ) { }
|
||||
|
||||
protected LayoutManager createLayoutManager() {
|
||||
return new MetalComboBoxLayoutManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* This class should be treated as a "protected" inner class.
|
||||
* Instantiate it only within subclasses of {@code MetalComboBoxUI}.
|
||||
*/
|
||||
public class MetalComboBoxLayoutManager extends BasicComboBoxUI.ComboBoxLayoutManager {
|
||||
public void layoutContainer( Container parent ) {
|
||||
layoutComboBox( parent, this );
|
||||
}
|
||||
public void superLayout( Container parent ) {
|
||||
super.layoutContainer( parent );
|
||||
}
|
||||
}
|
||||
|
||||
// This is here because of a bug in the compiler.
|
||||
// When a protected-inner-class-savvy compiler comes out we
|
||||
// should move this into MetalComboBoxLayoutManager.
|
||||
public void layoutComboBox( Container parent, MetalComboBoxLayoutManager manager ) {
|
||||
if (comboBox.isEditable() && !MetalLookAndFeel.usingOcean()) {
|
||||
manager.superLayout( parent );
|
||||
return;
|
||||
}
|
||||
|
||||
if (arrowButton != null) {
|
||||
if (MetalLookAndFeel.usingOcean() ) {
|
||||
Insets insets = comboBox.getInsets();
|
||||
int buttonWidth = arrowButton.getMinimumSize().width;
|
||||
arrowButton.setBounds(MetalUtils.isLeftToRight(comboBox)
|
||||
? (comboBox.getWidth() - insets.right - buttonWidth)
|
||||
: insets.left,
|
||||
insets.top, buttonWidth,
|
||||
comboBox.getHeight() - insets.top - insets.bottom);
|
||||
}
|
||||
else {
|
||||
Insets insets = comboBox.getInsets();
|
||||
int width = comboBox.getWidth();
|
||||
int height = comboBox.getHeight();
|
||||
arrowButton.setBounds( insets.left, insets.top,
|
||||
width - (insets.left + insets.right),
|
||||
height - (insets.top + insets.bottom) );
|
||||
}
|
||||
}
|
||||
|
||||
if (editor != null && MetalLookAndFeel.usingOcean()) {
|
||||
Rectangle cvb = rectangleForCurrentValue();
|
||||
editor.setBounds(cvb);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* As of Java 2 platform v1.4 this method is no
|
||||
* longer used.
|
||||
*
|
||||
* @deprecated As of Java 2 platform v1.4.
|
||||
*/
|
||||
@Deprecated
|
||||
protected void removeListeners() {
|
||||
if ( propertyChangeListener != null ) {
|
||||
comboBox.removePropertyChangeListener( propertyChangeListener );
|
||||
}
|
||||
}
|
||||
|
||||
// These two methods were overloaded and made public. This was probably a
|
||||
// mistake in the implementation. The functionality that they used to
|
||||
// provide is no longer necessary and should be removed. However,
|
||||
// removing them will create an uncompatible API change.
|
||||
|
||||
public void configureEditor() {
|
||||
super.configureEditor();
|
||||
}
|
||||
|
||||
public void unconfigureEditor() {
|
||||
super.unconfigureEditor();
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize( JComponent c ) {
|
||||
if ( !isMinimumSizeDirty ) {
|
||||
return new Dimension( cachedMinimumSize );
|
||||
}
|
||||
|
||||
Dimension size = null;
|
||||
|
||||
if ( !comboBox.isEditable() &&
|
||||
arrowButton != null) {
|
||||
Insets buttonInsets = arrowButton.getInsets();
|
||||
Insets insets = comboBox.getInsets();
|
||||
|
||||
size = getDisplaySize();
|
||||
size.width += insets.left + insets.right;
|
||||
size.width += buttonInsets.right;
|
||||
size.width += arrowButton.getMinimumSize().width;
|
||||
size.height += insets.top + insets.bottom;
|
||||
size.height += buttonInsets.top + buttonInsets.bottom;
|
||||
}
|
||||
else if ( comboBox.isEditable() &&
|
||||
arrowButton != null &&
|
||||
editor != null ) {
|
||||
size = super.getMinimumSize( c );
|
||||
Insets margin = arrowButton.getMargin();
|
||||
size.height += margin.top + margin.bottom;
|
||||
size.width += margin.left + margin.right;
|
||||
}
|
||||
else {
|
||||
size = super.getMinimumSize( c );
|
||||
}
|
||||
|
||||
cachedMinimumSize.setSize( size.width, size.height );
|
||||
isMinimumSizeDirty = false;
|
||||
|
||||
return new Dimension( cachedMinimumSize );
|
||||
}
|
||||
|
||||
/**
|
||||
* This class should be treated as a "protected" inner class.
|
||||
* Instantiate it only within subclasses of {@code MetalComboBoxUI}.
|
||||
*
|
||||
* This class is now obsolete and doesn't do anything and
|
||||
* is only included for backwards API compatibility. Do not call or
|
||||
* override.
|
||||
*
|
||||
* @deprecated As of Java 2 platform v1.4.
|
||||
*/
|
||||
@Deprecated
|
||||
public class MetalComboPopup extends BasicComboPopup {
|
||||
|
||||
public MetalComboPopup( JComboBox cBox) {
|
||||
super( cBox );
|
||||
}
|
||||
|
||||
// This method was overloaded and made public. This was probably
|
||||
// mistake in the implementation. The functionality that they used to
|
||||
// provide is no longer necessary and should be removed. However,
|
||||
// removing them will create an uncompatible API change.
|
||||
|
||||
public void delegateFocus(MouseEvent e) {
|
||||
super.delegateFocus(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
144
jdkSrc/jdk8/javax/swing/plaf/metal/MetalDesktopIconUI.java
Normal file
144
jdkSrc/jdk8/javax/swing/plaf/metal/MetalDesktopIconUI.java
Normal file
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.*;
|
||||
import java.beans.*;
|
||||
import java.util.EventListener;
|
||||
import java.io.Serializable;
|
||||
import javax.swing.plaf.basic.BasicDesktopIconUI;
|
||||
|
||||
/**
|
||||
* Metal desktop icon.
|
||||
*
|
||||
* @author Steve Wilson
|
||||
*/
|
||||
public class MetalDesktopIconUI extends BasicDesktopIconUI
|
||||
{
|
||||
|
||||
JButton button;
|
||||
JLabel label;
|
||||
TitleListener titleListener;
|
||||
private int width;
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new MetalDesktopIconUI();
|
||||
}
|
||||
|
||||
public MetalDesktopIconUI() {
|
||||
}
|
||||
|
||||
protected void installDefaults() {
|
||||
super.installDefaults();
|
||||
LookAndFeel.installColorsAndFont(desktopIcon, "DesktopIcon.background", "DesktopIcon.foreground", "DesktopIcon.font");
|
||||
width = UIManager.getInt("DesktopIcon.width");
|
||||
}
|
||||
|
||||
protected void installComponents() {
|
||||
frame = desktopIcon.getInternalFrame();
|
||||
Icon icon = frame.getFrameIcon();
|
||||
String title = frame.getTitle();
|
||||
|
||||
button = new JButton (title, icon);
|
||||
button.addActionListener( new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
deiconize(); }} );
|
||||
button.setFont(desktopIcon.getFont());
|
||||
button.setBackground(desktopIcon.getBackground());
|
||||
button.setForeground(desktopIcon.getForeground());
|
||||
|
||||
int buttonH = button.getPreferredSize().height;
|
||||
|
||||
Icon drag = new MetalBumps((buttonH/3), buttonH,
|
||||
MetalLookAndFeel.getControlHighlight(),
|
||||
MetalLookAndFeel.getControlDarkShadow(),
|
||||
MetalLookAndFeel.getControl());
|
||||
label = new JLabel(drag);
|
||||
|
||||
label.setBorder( new MatteBorder( 0, 2, 0, 1, desktopIcon.getBackground()) );
|
||||
desktopIcon.setLayout(new BorderLayout(2, 0));
|
||||
desktopIcon.add(button, BorderLayout.CENTER);
|
||||
desktopIcon.add(label, BorderLayout.WEST);
|
||||
}
|
||||
|
||||
protected void uninstallComponents() {
|
||||
desktopIcon.setLayout(null);
|
||||
desktopIcon.remove(label);
|
||||
desktopIcon.remove(button);
|
||||
button = null;
|
||||
frame = null;
|
||||
}
|
||||
|
||||
protected void installListeners() {
|
||||
super.installListeners();
|
||||
desktopIcon.getInternalFrame().addPropertyChangeListener(
|
||||
titleListener = new TitleListener());
|
||||
}
|
||||
|
||||
protected void uninstallListeners() {
|
||||
desktopIcon.getInternalFrame().removePropertyChangeListener(
|
||||
titleListener);
|
||||
titleListener = null;
|
||||
super.uninstallListeners();
|
||||
}
|
||||
|
||||
|
||||
public Dimension getPreferredSize(JComponent c) {
|
||||
// Metal desktop icons can not be resized. Their dimensions should
|
||||
// always be the minimum size. See getMinimumSize(JComponent c).
|
||||
return getMinimumSize(c);
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize(JComponent c) {
|
||||
// For the metal desktop icon we will use the layout maanger to
|
||||
// determine the correct height of the component, but we want to keep
|
||||
// the width consistent according to the jlf spec.
|
||||
return new Dimension(width,
|
||||
desktopIcon.getLayout().minimumLayoutSize(desktopIcon).height);
|
||||
}
|
||||
|
||||
public Dimension getMaximumSize(JComponent c) {
|
||||
// Metal desktop icons can not be resized. Their dimensions should
|
||||
// always be the minimum size. See getMinimumSize(JComponent c).
|
||||
return getMinimumSize(c);
|
||||
}
|
||||
|
||||
class TitleListener implements PropertyChangeListener {
|
||||
public void propertyChange (PropertyChangeEvent e) {
|
||||
if (e.getPropertyName().equals("title")) {
|
||||
button.setText((String)e.getNewValue());
|
||||
}
|
||||
|
||||
if (e.getPropertyName().equals("frameIcon")) {
|
||||
button.setIcon((Icon)e.getNewValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1275
jdkSrc/jdk8/javax/swing/plaf/metal/MetalFileChooserUI.java
Normal file
1275
jdkSrc/jdk8/javax/swing/plaf/metal/MetalFileChooserUI.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* DesktopProperty that only uses font height in configuring font. This
|
||||
* is only used on Windows.
|
||||
*
|
||||
*/
|
||||
class MetalFontDesktopProperty extends com.sun.java.swing.plaf.windows.DesktopProperty {
|
||||
/**
|
||||
* Maps from metal font theme type as defined in MetalTheme
|
||||
* to the corresponding desktop property name.
|
||||
*/
|
||||
private static final String[] propertyMapping = {
|
||||
"win.ansiVar.font.height",
|
||||
"win.tooltip.font.height",
|
||||
"win.ansiVar.font.height",
|
||||
"win.menu.font.height",
|
||||
"win.frame.captionFont.height",
|
||||
"win.menu.font.height"
|
||||
};
|
||||
|
||||
/**
|
||||
* Corresponds to a MetalTheme font type.
|
||||
*/
|
||||
private int type;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a MetalFontDesktopProperty. The key used to lookup the
|
||||
* desktop property is determined from the type of font.
|
||||
*
|
||||
* @param type MetalTheme font type.
|
||||
*/
|
||||
MetalFontDesktopProperty(int type) {
|
||||
this(propertyMapping[type], type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a MetalFontDesktopProperty.
|
||||
*
|
||||
* @param key Key used in looking up desktop value.
|
||||
* @param toolkit Toolkit used to fetch property from, can be null
|
||||
* in which default will be used.
|
||||
* @param type Type of font being used, corresponds to MetalTheme font
|
||||
* type.
|
||||
*/
|
||||
MetalFontDesktopProperty(String key, int type) {
|
||||
super(key, null);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overriden to create a Font with the size coming from the desktop
|
||||
* and the style and name coming from DefaultMetalTheme.
|
||||
*/
|
||||
protected Object configureValue(Object value) {
|
||||
if (value instanceof Integer) {
|
||||
value = new Font(DefaultMetalTheme.getDefaultFontName(type),
|
||||
DefaultMetalTheme.getDefaultFontStyle(type),
|
||||
((Integer)value).intValue());
|
||||
}
|
||||
return super.configureValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default font.
|
||||
*/
|
||||
protected Object getDefaultValue() {
|
||||
return new Font(DefaultMetalTheme.getDefaultFontName(type),
|
||||
DefaultMetalTheme.getDefaultFontStyle(type),
|
||||
DefaultMetalTheme.getDefaultFontSize(type));
|
||||
}
|
||||
}
|
||||
189
jdkSrc/jdk8/javax/swing/plaf/metal/MetalHighContrastTheme.java
Normal file
189
jdkSrc/jdk8/javax/swing/plaf/metal/MetalHighContrastTheme.java
Normal file
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2002, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import javax.swing.plaf.metal.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* A high contrast theme. This is used on Windows if the system property
|
||||
* awt.highContrast.on is true.
|
||||
*
|
||||
* @author Michael C. Albers
|
||||
*/
|
||||
class MetalHighContrastTheme extends DefaultMetalTheme {
|
||||
private static final ColorUIResource primary1 = new
|
||||
ColorUIResource(0, 0, 0);
|
||||
private static final ColorUIResource primary2 = new ColorUIResource(
|
||||
204, 204, 204);
|
||||
private static final ColorUIResource primary3 = new ColorUIResource(255,
|
||||
255, 255);
|
||||
private static final ColorUIResource primaryHighlight = new
|
||||
ColorUIResource(102, 102, 102);
|
||||
private static final ColorUIResource secondary2 = new ColorUIResource(
|
||||
204, 204, 204);
|
||||
private static final ColorUIResource secondary3 = new ColorUIResource(
|
||||
255, 255, 255);
|
||||
private static final ColorUIResource controlHighlight = new
|
||||
ColorUIResource(102, 102, 102);
|
||||
|
||||
|
||||
// This does not override getSecondary1 (102,102,102)
|
||||
|
||||
public String getName() {
|
||||
return "Contrast";
|
||||
}
|
||||
|
||||
protected ColorUIResource getPrimary1() {
|
||||
return primary1;
|
||||
}
|
||||
|
||||
protected ColorUIResource getPrimary2() {
|
||||
return primary2;
|
||||
}
|
||||
|
||||
protected ColorUIResource getPrimary3() {
|
||||
return primary3;
|
||||
}
|
||||
|
||||
public ColorUIResource getPrimaryControlHighlight() {
|
||||
return primaryHighlight;
|
||||
}
|
||||
|
||||
protected ColorUIResource getSecondary2() {
|
||||
return secondary2;
|
||||
}
|
||||
|
||||
protected ColorUIResource getSecondary3() {
|
||||
return secondary3;
|
||||
}
|
||||
|
||||
public ColorUIResource getControlHighlight() {
|
||||
// This was super.getSecondary3();
|
||||
return secondary2;
|
||||
}
|
||||
|
||||
public ColorUIResource getFocusColor() {
|
||||
return getBlack();
|
||||
}
|
||||
|
||||
public ColorUIResource getTextHighlightColor() {
|
||||
return getBlack();
|
||||
}
|
||||
|
||||
public ColorUIResource getHighlightedTextColor() {
|
||||
return getWhite();
|
||||
}
|
||||
|
||||
public ColorUIResource getMenuSelectedBackground() {
|
||||
return getBlack();
|
||||
}
|
||||
|
||||
public ColorUIResource getMenuSelectedForeground() {
|
||||
return getWhite();
|
||||
}
|
||||
|
||||
public ColorUIResource getAcceleratorForeground() {
|
||||
return getBlack();
|
||||
}
|
||||
|
||||
public ColorUIResource getAcceleratorSelectedForeground() {
|
||||
return getWhite();
|
||||
}
|
||||
|
||||
public void addCustomEntriesToTable(UIDefaults table) {
|
||||
Border blackLineBorder = new BorderUIResource(new LineBorder(
|
||||
getBlack()));
|
||||
Border whiteLineBorder = new BorderUIResource(new LineBorder(
|
||||
getWhite()));
|
||||
Object textBorder = new BorderUIResource(new CompoundBorder(
|
||||
blackLineBorder, new BasicBorders.MarginBorder()));
|
||||
|
||||
Object[] defaults = new Object[] {
|
||||
"ToolTip.border", blackLineBorder,
|
||||
|
||||
"TitledBorder.border", blackLineBorder,
|
||||
|
||||
"TextField.border", textBorder,
|
||||
|
||||
"PasswordField.border", textBorder,
|
||||
|
||||
"TextArea.border", textBorder,
|
||||
|
||||
"TextPane.border", textBorder,
|
||||
|
||||
"EditorPane.border", textBorder,
|
||||
|
||||
"ComboBox.background", getWindowBackground(),
|
||||
"ComboBox.foreground", getUserTextColor(),
|
||||
"ComboBox.selectionBackground", getTextHighlightColor(),
|
||||
"ComboBox.selectionForeground", getHighlightedTextColor(),
|
||||
|
||||
"ProgressBar.foreground", getUserTextColor(),
|
||||
"ProgressBar.background", getWindowBackground(),
|
||||
"ProgressBar.selectionForeground", getWindowBackground(),
|
||||
"ProgressBar.selectionBackground", getUserTextColor(),
|
||||
|
||||
"OptionPane.errorDialog.border.background",
|
||||
getPrimary1(),
|
||||
"OptionPane.errorDialog.titlePane.foreground",
|
||||
getPrimary3(),
|
||||
"OptionPane.errorDialog.titlePane.background",
|
||||
getPrimary1(),
|
||||
"OptionPane.errorDialog.titlePane.shadow",
|
||||
getPrimary2(),
|
||||
"OptionPane.questionDialog.border.background",
|
||||
getPrimary1(),
|
||||
"OptionPane.questionDialog.titlePane.foreground",
|
||||
getPrimary3(),
|
||||
"OptionPane.questionDialog.titlePane.background",
|
||||
getPrimary1(),
|
||||
"OptionPane.questionDialog.titlePane.shadow",
|
||||
getPrimary2(),
|
||||
"OptionPane.warningDialog.border.background",
|
||||
getPrimary1(),
|
||||
"OptionPane.warningDialog.titlePane.foreground",
|
||||
getPrimary3(),
|
||||
"OptionPane.warningDialog.titlePane.background",
|
||||
getPrimary1(),
|
||||
"OptionPane.warningDialog.titlePane.shadow",
|
||||
getPrimary2(),
|
||||
};
|
||||
|
||||
table.putDefaults(defaults);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this is a theme provided by the core platform.
|
||||
*/
|
||||
boolean isSystemTheme() {
|
||||
return (getClass() == MetalHighContrastTheme.class);
|
||||
}
|
||||
}
|
||||
2659
jdkSrc/jdk8/javax/swing/plaf/metal/MetalIconFactory.java
Normal file
2659
jdkSrc/jdk8/javax/swing/plaf/metal/MetalIconFactory.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,551 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import sun.swing.SwingUtilities2;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.event.InternalFrameEvent;
|
||||
import java.util.EventListener;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
|
||||
|
||||
|
||||
/**
|
||||
* Class that manages a JLF title bar
|
||||
* @author Steve Wilson
|
||||
* @author Brian Beck
|
||||
* @since 1.3
|
||||
*/
|
||||
|
||||
public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane {
|
||||
|
||||
protected boolean isPalette = false;
|
||||
protected Icon paletteCloseIcon;
|
||||
protected int paletteTitleHeight;
|
||||
|
||||
private static final Border handyEmptyBorder = new EmptyBorder(0,0,0,0);
|
||||
|
||||
/**
|
||||
* Key used to lookup Color from UIManager. If this is null,
|
||||
* <code>getWindowTitleBackground</code> is used.
|
||||
*/
|
||||
private String selectedBackgroundKey;
|
||||
/**
|
||||
* Key used to lookup Color from UIManager. If this is null,
|
||||
* <code>getWindowTitleForeground</code> is used.
|
||||
*/
|
||||
private String selectedForegroundKey;
|
||||
/**
|
||||
* Key used to lookup shadow color from UIManager. If this is null,
|
||||
* <code>getPrimaryControlDarkShadow</code> is used.
|
||||
*/
|
||||
private String selectedShadowKey;
|
||||
/**
|
||||
* Boolean indicating the state of the <code>JInternalFrame</code>s
|
||||
* closable property at <code>updateUI</code> time.
|
||||
*/
|
||||
private boolean wasClosable;
|
||||
|
||||
int buttonsWidth = 0;
|
||||
|
||||
MetalBumps activeBumps
|
||||
= new MetalBumps( 0, 0,
|
||||
MetalLookAndFeel.getPrimaryControlHighlight(),
|
||||
MetalLookAndFeel.getPrimaryControlDarkShadow(),
|
||||
(UIManager.get("InternalFrame.activeTitleGradient") != null) ? null :
|
||||
MetalLookAndFeel.getPrimaryControl() );
|
||||
MetalBumps inactiveBumps
|
||||
= new MetalBumps( 0, 0,
|
||||
MetalLookAndFeel.getControlHighlight(),
|
||||
MetalLookAndFeel.getControlDarkShadow(),
|
||||
(UIManager.get("InternalFrame.inactiveTitleGradient") != null) ? null :
|
||||
MetalLookAndFeel.getControl() );
|
||||
MetalBumps paletteBumps;
|
||||
|
||||
private Color activeBumpsHighlight = MetalLookAndFeel.
|
||||
getPrimaryControlHighlight();
|
||||
private Color activeBumpsShadow = MetalLookAndFeel.
|
||||
getPrimaryControlDarkShadow();
|
||||
|
||||
public MetalInternalFrameTitlePane(JInternalFrame f) {
|
||||
super( f );
|
||||
}
|
||||
|
||||
public void addNotify() {
|
||||
super.addNotify();
|
||||
// This is done here instead of in installDefaults as I was worried
|
||||
// that the BasicInternalFrameUI might not be fully initialized, and
|
||||
// that if this resets the closable state the BasicInternalFrameUI
|
||||
// Listeners that get notified might be in an odd/uninitialized state.
|
||||
updateOptionPaneState();
|
||||
}
|
||||
|
||||
protected void installDefaults() {
|
||||
super.installDefaults();
|
||||
setFont( UIManager.getFont("InternalFrame.titleFont") );
|
||||
paletteTitleHeight
|
||||
= UIManager.getInt("InternalFrame.paletteTitleHeight");
|
||||
paletteCloseIcon = UIManager.getIcon("InternalFrame.paletteCloseIcon");
|
||||
wasClosable = frame.isClosable();
|
||||
selectedForegroundKey = selectedBackgroundKey = null;
|
||||
if (MetalLookAndFeel.usingOcean()) {
|
||||
setOpaque(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected void uninstallDefaults() {
|
||||
super.uninstallDefaults();
|
||||
if (wasClosable != frame.isClosable()) {
|
||||
frame.setClosable(wasClosable);
|
||||
}
|
||||
}
|
||||
|
||||
protected void createButtons() {
|
||||
super.createButtons();
|
||||
|
||||
Boolean paintActive = frame.isSelected() ? Boolean.TRUE:Boolean.FALSE;
|
||||
iconButton.putClientProperty("paintActive", paintActive);
|
||||
iconButton.setBorder(handyEmptyBorder);
|
||||
|
||||
maxButton.putClientProperty("paintActive", paintActive);
|
||||
maxButton.setBorder(handyEmptyBorder);
|
||||
|
||||
closeButton.putClientProperty("paintActive", paintActive);
|
||||
closeButton.setBorder(handyEmptyBorder);
|
||||
|
||||
// The palette close icon isn't opaque while the regular close icon is.
|
||||
// This makes sure palette close buttons have the right background.
|
||||
closeButton.setBackground(MetalLookAndFeel.getPrimaryControlShadow());
|
||||
|
||||
if (MetalLookAndFeel.usingOcean()) {
|
||||
iconButton.setContentAreaFilled(false);
|
||||
maxButton.setContentAreaFilled(false);
|
||||
closeButton.setContentAreaFilled(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the parent's method to do nothing. Metal frames do not
|
||||
* have system menus.
|
||||
*/
|
||||
protected void assembleSystemMenu() {}
|
||||
|
||||
/**
|
||||
* Override the parent's method to do nothing. Metal frames do not
|
||||
* have system menus.
|
||||
*/
|
||||
protected void addSystemMenuItems(JMenu systemMenu) {}
|
||||
|
||||
/**
|
||||
* Override the parent's method to do nothing. Metal frames do not
|
||||
* have system menus.
|
||||
*/
|
||||
protected void showSystemMenu() {}
|
||||
|
||||
/**
|
||||
* Override the parent's method avoid creating a menu bar. Metal frames
|
||||
* do not have system menus.
|
||||
*/
|
||||
protected void addSubComponents() {
|
||||
add(iconButton);
|
||||
add(maxButton);
|
||||
add(closeButton);
|
||||
}
|
||||
|
||||
protected PropertyChangeListener createPropertyChangeListener() {
|
||||
return new MetalPropertyChangeHandler();
|
||||
}
|
||||
|
||||
protected LayoutManager createLayout() {
|
||||
return new MetalTitlePaneLayout();
|
||||
}
|
||||
|
||||
class MetalPropertyChangeHandler
|
||||
extends BasicInternalFrameTitlePane.PropertyChangeHandler
|
||||
{
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
String prop = evt.getPropertyName();
|
||||
if( prop.equals(JInternalFrame.IS_SELECTED_PROPERTY) ) {
|
||||
Boolean b = (Boolean)evt.getNewValue();
|
||||
iconButton.putClientProperty("paintActive", b);
|
||||
closeButton.putClientProperty("paintActive", b);
|
||||
maxButton.putClientProperty("paintActive", b);
|
||||
}
|
||||
else if ("JInternalFrame.messageType".equals(prop)) {
|
||||
updateOptionPaneState();
|
||||
frame.repaint();
|
||||
}
|
||||
super.propertyChange(evt);
|
||||
}
|
||||
}
|
||||
|
||||
class MetalTitlePaneLayout extends TitlePaneLayout {
|
||||
public void addLayoutComponent(String name, Component c) {}
|
||||
public void removeLayoutComponent(Component c) {}
|
||||
public Dimension preferredLayoutSize(Container c) {
|
||||
return minimumLayoutSize(c);
|
||||
}
|
||||
|
||||
public Dimension minimumLayoutSize(Container c) {
|
||||
// Compute width.
|
||||
int width = 30;
|
||||
if (frame.isClosable()) {
|
||||
width += 21;
|
||||
}
|
||||
if (frame.isMaximizable()) {
|
||||
width += 16 + (frame.isClosable() ? 10 : 4);
|
||||
}
|
||||
if (frame.isIconifiable()) {
|
||||
width += 16 + (frame.isMaximizable() ? 2 :
|
||||
(frame.isClosable() ? 10 : 4));
|
||||
}
|
||||
FontMetrics fm = frame.getFontMetrics(getFont());
|
||||
String frameTitle = frame.getTitle();
|
||||
int title_w = frameTitle != null ? SwingUtilities2.stringWidth(
|
||||
frame, fm, frameTitle) : 0;
|
||||
int title_length = frameTitle != null ? frameTitle.length() : 0;
|
||||
|
||||
if (title_length > 2) {
|
||||
int subtitle_w = SwingUtilities2.stringWidth(frame, fm,
|
||||
frame.getTitle().substring(0, 2) + "...");
|
||||
width += (title_w < subtitle_w) ? title_w : subtitle_w;
|
||||
}
|
||||
else {
|
||||
width += title_w;
|
||||
}
|
||||
|
||||
// Compute height.
|
||||
int height;
|
||||
if (isPalette) {
|
||||
height = paletteTitleHeight;
|
||||
} else {
|
||||
int fontHeight = fm.getHeight();
|
||||
fontHeight += 7;
|
||||
Icon icon = frame.getFrameIcon();
|
||||
int iconHeight = 0;
|
||||
if (icon != null) {
|
||||
// SystemMenuBar forces the icon to be 16x16 or less.
|
||||
iconHeight = Math.min(icon.getIconHeight(), 16);
|
||||
}
|
||||
iconHeight += 5;
|
||||
height = Math.max(fontHeight, iconHeight);
|
||||
}
|
||||
|
||||
return new Dimension(width, height);
|
||||
}
|
||||
|
||||
public void layoutContainer(Container c) {
|
||||
boolean leftToRight = MetalUtils.isLeftToRight(frame);
|
||||
|
||||
int w = getWidth();
|
||||
int x = leftToRight ? w : 0;
|
||||
int y = 2;
|
||||
int spacing;
|
||||
|
||||
// assumes all buttons have the same dimensions
|
||||
// these dimensions include the borders
|
||||
int buttonHeight = closeButton.getIcon().getIconHeight();
|
||||
int buttonWidth = closeButton.getIcon().getIconWidth();
|
||||
|
||||
if(frame.isClosable()) {
|
||||
if (isPalette) {
|
||||
spacing = 3;
|
||||
x += leftToRight ? -spacing -(buttonWidth+2) : spacing;
|
||||
closeButton.setBounds(x, y, buttonWidth+2, getHeight()-4);
|
||||
if( !leftToRight ) x += (buttonWidth+2);
|
||||
} else {
|
||||
spacing = 4;
|
||||
x += leftToRight ? -spacing -buttonWidth : spacing;
|
||||
closeButton.setBounds(x, y, buttonWidth, buttonHeight);
|
||||
if( !leftToRight ) x += buttonWidth;
|
||||
}
|
||||
}
|
||||
|
||||
if(frame.isMaximizable() && !isPalette ) {
|
||||
spacing = frame.isClosable() ? 10 : 4;
|
||||
x += leftToRight ? -spacing -buttonWidth : spacing;
|
||||
maxButton.setBounds(x, y, buttonWidth, buttonHeight);
|
||||
if( !leftToRight ) x += buttonWidth;
|
||||
}
|
||||
|
||||
if(frame.isIconifiable() && !isPalette ) {
|
||||
spacing = frame.isMaximizable() ? 2
|
||||
: (frame.isClosable() ? 10 : 4);
|
||||
x += leftToRight ? -spacing -buttonWidth : spacing;
|
||||
iconButton.setBounds(x, y, buttonWidth, buttonHeight);
|
||||
if( !leftToRight ) x += buttonWidth;
|
||||
}
|
||||
|
||||
buttonsWidth = leftToRight ? w - x : x;
|
||||
}
|
||||
}
|
||||
|
||||
public void paintPalette(Graphics g) {
|
||||
boolean leftToRight = MetalUtils.isLeftToRight(frame);
|
||||
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
|
||||
if (paletteBumps == null) {
|
||||
paletteBumps
|
||||
= new MetalBumps(0, 0,
|
||||
MetalLookAndFeel.getPrimaryControlHighlight(),
|
||||
MetalLookAndFeel.getPrimaryControlInfo(),
|
||||
MetalLookAndFeel.getPrimaryControlShadow() );
|
||||
}
|
||||
|
||||
Color background = MetalLookAndFeel.getPrimaryControlShadow();
|
||||
Color darkShadow = MetalLookAndFeel.getPrimaryControlDarkShadow();
|
||||
|
||||
g.setColor(background);
|
||||
g.fillRect(0, 0, width, height);
|
||||
|
||||
g.setColor( darkShadow );
|
||||
g.drawLine ( 0, height - 1, width, height -1);
|
||||
|
||||
int xOffset = leftToRight ? 4 : buttonsWidth + 4;
|
||||
int bumpLength = width - buttonsWidth -2*4;
|
||||
int bumpHeight = getHeight() - 4;
|
||||
paletteBumps.setBumpArea( bumpLength, bumpHeight );
|
||||
paletteBumps.paintIcon( this, g, xOffset, 2);
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
if(isPalette) {
|
||||
paintPalette(g);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean leftToRight = MetalUtils.isLeftToRight(frame);
|
||||
boolean isSelected = frame.isSelected();
|
||||
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
|
||||
Color background = null;
|
||||
Color foreground = null;
|
||||
Color shadow = null;
|
||||
|
||||
MetalBumps bumps;
|
||||
String gradientKey;
|
||||
|
||||
if (isSelected) {
|
||||
if (!MetalLookAndFeel.usingOcean()) {
|
||||
closeButton.setContentAreaFilled(true);
|
||||
maxButton.setContentAreaFilled(true);
|
||||
iconButton.setContentAreaFilled(true);
|
||||
}
|
||||
if (selectedBackgroundKey != null) {
|
||||
background = UIManager.getColor(selectedBackgroundKey);
|
||||
}
|
||||
if (background == null) {
|
||||
background = MetalLookAndFeel.getWindowTitleBackground();
|
||||
}
|
||||
if (selectedForegroundKey != null) {
|
||||
foreground = UIManager.getColor(selectedForegroundKey);
|
||||
}
|
||||
if (selectedShadowKey != null) {
|
||||
shadow = UIManager.getColor(selectedShadowKey);
|
||||
}
|
||||
if (shadow == null) {
|
||||
shadow = MetalLookAndFeel.getPrimaryControlDarkShadow();
|
||||
}
|
||||
if (foreground == null) {
|
||||
foreground = MetalLookAndFeel.getWindowTitleForeground();
|
||||
}
|
||||
activeBumps.setBumpColors(activeBumpsHighlight, activeBumpsShadow,
|
||||
UIManager.get("InternalFrame.activeTitleGradient") !=
|
||||
null ? null : background);
|
||||
bumps = activeBumps;
|
||||
gradientKey = "InternalFrame.activeTitleGradient";
|
||||
} else {
|
||||
if (!MetalLookAndFeel.usingOcean()) {
|
||||
closeButton.setContentAreaFilled(false);
|
||||
maxButton.setContentAreaFilled(false);
|
||||
iconButton.setContentAreaFilled(false);
|
||||
}
|
||||
background = MetalLookAndFeel.getWindowTitleInactiveBackground();
|
||||
foreground = MetalLookAndFeel.getWindowTitleInactiveForeground();
|
||||
shadow = MetalLookAndFeel.getControlDarkShadow();
|
||||
bumps = inactiveBumps;
|
||||
gradientKey = "InternalFrame.inactiveTitleGradient";
|
||||
}
|
||||
|
||||
if (!MetalUtils.drawGradient(this, g, gradientKey, 0, 0, width,
|
||||
height, true)) {
|
||||
g.setColor(background);
|
||||
g.fillRect(0, 0, width, height);
|
||||
}
|
||||
|
||||
g.setColor( shadow );
|
||||
g.drawLine ( 0, height - 1, width, height -1);
|
||||
g.drawLine ( 0, 0, 0 ,0);
|
||||
g.drawLine ( width - 1, 0 , width -1, 0);
|
||||
|
||||
|
||||
int titleLength;
|
||||
int xOffset = leftToRight ? 5 : width - 5;
|
||||
String frameTitle = frame.getTitle();
|
||||
|
||||
Icon icon = frame.getFrameIcon();
|
||||
if ( icon != null ) {
|
||||
if( !leftToRight )
|
||||
xOffset -= icon.getIconWidth();
|
||||
int iconY = ((height / 2) - (icon.getIconHeight() /2));
|
||||
icon.paintIcon(frame, g, xOffset, iconY);
|
||||
xOffset += leftToRight ? icon.getIconWidth() + 5 : -5;
|
||||
}
|
||||
|
||||
if(frameTitle != null) {
|
||||
Font f = getFont();
|
||||
g.setFont(f);
|
||||
FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g, f);
|
||||
int fHeight = fm.getHeight();
|
||||
|
||||
g.setColor(foreground);
|
||||
|
||||
int yOffset = ( (height - fm.getHeight() ) / 2 ) + fm.getAscent();
|
||||
|
||||
Rectangle rect = new Rectangle(0, 0, 0, 0);
|
||||
if (frame.isIconifiable()) { rect = iconButton.getBounds(); }
|
||||
else if (frame.isMaximizable()) { rect = maxButton.getBounds(); }
|
||||
else if (frame.isClosable()) { rect = closeButton.getBounds(); }
|
||||
int titleW;
|
||||
|
||||
if( leftToRight ) {
|
||||
if (rect.x == 0) {
|
||||
rect.x = frame.getWidth()-frame.getInsets().right-2;
|
||||
}
|
||||
titleW = rect.x - xOffset - 4;
|
||||
frameTitle = getTitle(frameTitle, fm, titleW);
|
||||
} else {
|
||||
titleW = xOffset - rect.x - rect.width - 4;
|
||||
frameTitle = getTitle(frameTitle, fm, titleW);
|
||||
xOffset -= SwingUtilities2.stringWidth(frame, fm, frameTitle);
|
||||
}
|
||||
|
||||
titleLength = SwingUtilities2.stringWidth(frame, fm, frameTitle);
|
||||
SwingUtilities2.drawString(frame, g, frameTitle, xOffset, yOffset);
|
||||
xOffset += leftToRight ? titleLength + 5 : -5;
|
||||
}
|
||||
|
||||
int bumpXOffset;
|
||||
int bumpLength;
|
||||
if( leftToRight ) {
|
||||
bumpLength = width - buttonsWidth - xOffset - 5;
|
||||
bumpXOffset = xOffset;
|
||||
} else {
|
||||
bumpLength = xOffset - buttonsWidth - 5;
|
||||
bumpXOffset = buttonsWidth + 5;
|
||||
}
|
||||
int bumpYOffset = 3;
|
||||
int bumpHeight = getHeight() - (2 * bumpYOffset);
|
||||
bumps.setBumpArea( bumpLength, bumpHeight );
|
||||
bumps.paintIcon(this, g, bumpXOffset, bumpYOffset);
|
||||
}
|
||||
|
||||
public void setPalette(boolean b) {
|
||||
isPalette = b;
|
||||
|
||||
if (isPalette) {
|
||||
closeButton.setIcon(paletteCloseIcon);
|
||||
if( frame.isMaximizable() )
|
||||
remove(maxButton);
|
||||
if( frame.isIconifiable() )
|
||||
remove(iconButton);
|
||||
} else {
|
||||
closeButton.setIcon(closeIcon);
|
||||
if( frame.isMaximizable() )
|
||||
add(maxButton);
|
||||
if( frame.isIconifiable() )
|
||||
add(iconButton);
|
||||
}
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates any state dependant upon the JInternalFrame being shown in
|
||||
* a <code>JOptionPane</code>.
|
||||
*/
|
||||
private void updateOptionPaneState() {
|
||||
int type = -2;
|
||||
boolean closable = wasClosable;
|
||||
Object obj = frame.getClientProperty("JInternalFrame.messageType");
|
||||
|
||||
if (obj == null) {
|
||||
// Don't change the closable state unless in an JOptionPane.
|
||||
return;
|
||||
}
|
||||
if (obj instanceof Integer) {
|
||||
type = ((Integer) obj).intValue();
|
||||
}
|
||||
switch (type) {
|
||||
case JOptionPane.ERROR_MESSAGE:
|
||||
selectedBackgroundKey =
|
||||
"OptionPane.errorDialog.titlePane.background";
|
||||
selectedForegroundKey =
|
||||
"OptionPane.errorDialog.titlePane.foreground";
|
||||
selectedShadowKey = "OptionPane.errorDialog.titlePane.shadow";
|
||||
closable = false;
|
||||
break;
|
||||
case JOptionPane.QUESTION_MESSAGE:
|
||||
selectedBackgroundKey =
|
||||
"OptionPane.questionDialog.titlePane.background";
|
||||
selectedForegroundKey =
|
||||
"OptionPane.questionDialog.titlePane.foreground";
|
||||
selectedShadowKey =
|
||||
"OptionPane.questionDialog.titlePane.shadow";
|
||||
closable = false;
|
||||
break;
|
||||
case JOptionPane.WARNING_MESSAGE:
|
||||
selectedBackgroundKey =
|
||||
"OptionPane.warningDialog.titlePane.background";
|
||||
selectedForegroundKey =
|
||||
"OptionPane.warningDialog.titlePane.foreground";
|
||||
selectedShadowKey = "OptionPane.warningDialog.titlePane.shadow";
|
||||
closable = false;
|
||||
break;
|
||||
case JOptionPane.INFORMATION_MESSAGE:
|
||||
case JOptionPane.PLAIN_MESSAGE:
|
||||
selectedBackgroundKey = selectedForegroundKey = selectedShadowKey =
|
||||
null;
|
||||
closable = false;
|
||||
break;
|
||||
default:
|
||||
selectedBackgroundKey = selectedForegroundKey = selectedShadowKey =
|
||||
null;
|
||||
break;
|
||||
}
|
||||
if (closable != frame.isClosable()) {
|
||||
frame.setClosable(closable);
|
||||
}
|
||||
}
|
||||
}
|
||||
255
jdkSrc/jdk8/javax/swing/plaf/metal/MetalInternalFrameUI.java
Normal file
255
jdkSrc/jdk8/javax/swing/plaf/metal/MetalInternalFrameUI.java
Normal file
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import javax.swing.plaf.*;
|
||||
|
||||
/**
|
||||
* Metal implementation of JInternalFrame.
|
||||
* <p>
|
||||
*
|
||||
* @author Steve Wilson
|
||||
*/
|
||||
public class MetalInternalFrameUI extends BasicInternalFrameUI {
|
||||
|
||||
private static final PropertyChangeListener metalPropertyChangeListener =
|
||||
new MetalPropertyChangeHandler();
|
||||
|
||||
private static final Border handyEmptyBorder = new EmptyBorder(0,0,0,0);
|
||||
|
||||
protected static String IS_PALETTE = "JInternalFrame.isPalette";
|
||||
private static String IS_PALETTE_KEY = "JInternalFrame.isPalette";
|
||||
private static String FRAME_TYPE = "JInternalFrame.frameType";
|
||||
private static String NORMAL_FRAME = "normal";
|
||||
private static String PALETTE_FRAME = "palette";
|
||||
private static String OPTION_DIALOG = "optionDialog";
|
||||
|
||||
public MetalInternalFrameUI(JInternalFrame b) {
|
||||
super(b);
|
||||
}
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new MetalInternalFrameUI( (JInternalFrame) c);
|
||||
}
|
||||
|
||||
public void installUI(JComponent c) {
|
||||
super.installUI(c);
|
||||
|
||||
Object paletteProp = c.getClientProperty(IS_PALETTE_KEY);
|
||||
if ( paletteProp != null ) {
|
||||
setPalette( ((Boolean)paletteProp).booleanValue() );
|
||||
}
|
||||
|
||||
Container content = frame.getContentPane();
|
||||
stripContentBorder(content);
|
||||
//c.setOpaque(false);
|
||||
}
|
||||
|
||||
public void uninstallUI(JComponent c) {
|
||||
frame = (JInternalFrame)c;
|
||||
|
||||
Container cont = ((JInternalFrame)(c)).getContentPane();
|
||||
if (cont instanceof JComponent) {
|
||||
JComponent content = (JComponent)cont;
|
||||
if ( content.getBorder() == handyEmptyBorder) {
|
||||
content.setBorder(null);
|
||||
}
|
||||
}
|
||||
super.uninstallUI(c);
|
||||
}
|
||||
|
||||
protected void installListeners() {
|
||||
super.installListeners();
|
||||
frame.addPropertyChangeListener(metalPropertyChangeListener);
|
||||
}
|
||||
|
||||
protected void uninstallListeners() {
|
||||
frame.removePropertyChangeListener(metalPropertyChangeListener);
|
||||
super.uninstallListeners();
|
||||
}
|
||||
|
||||
protected void installKeyboardActions(){
|
||||
super.installKeyboardActions();
|
||||
ActionMap map = SwingUtilities.getUIActionMap(frame);
|
||||
if (map != null) {
|
||||
// BasicInternalFrameUI creates an action with the same name, we override
|
||||
// it as Metal frames do not have system menus.
|
||||
map.remove("showSystemMenu");
|
||||
}
|
||||
}
|
||||
|
||||
protected void uninstallKeyboardActions(){
|
||||
super.uninstallKeyboardActions();
|
||||
}
|
||||
|
||||
protected void uninstallComponents() {
|
||||
titlePane = null;
|
||||
super.uninstallComponents();
|
||||
}
|
||||
|
||||
private void stripContentBorder(Object c) {
|
||||
if ( c instanceof JComponent ) {
|
||||
JComponent contentComp = (JComponent)c;
|
||||
Border contentBorder = contentComp.getBorder();
|
||||
if (contentBorder == null || contentBorder instanceof UIResource) {
|
||||
contentComp.setBorder( handyEmptyBorder );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected JComponent createNorthPane(JInternalFrame w) {
|
||||
return new MetalInternalFrameTitlePane(w);
|
||||
}
|
||||
|
||||
|
||||
private void setFrameType( String frameType )
|
||||
{
|
||||
if ( frameType.equals( OPTION_DIALOG ) )
|
||||
{
|
||||
LookAndFeel.installBorder(frame, "InternalFrame.optionDialogBorder");
|
||||
((MetalInternalFrameTitlePane)titlePane).setPalette( false );
|
||||
}
|
||||
else if ( frameType.equals( PALETTE_FRAME ) )
|
||||
{
|
||||
LookAndFeel.installBorder(frame, "InternalFrame.paletteBorder");
|
||||
((MetalInternalFrameTitlePane)titlePane).setPalette( true );
|
||||
}
|
||||
else
|
||||
{
|
||||
LookAndFeel.installBorder(frame, "InternalFrame.border");
|
||||
((MetalInternalFrameTitlePane)titlePane).setPalette( false );
|
||||
}
|
||||
}
|
||||
|
||||
// this should be deprecated - jcs
|
||||
public void setPalette(boolean isPalette) {
|
||||
if (isPalette) {
|
||||
LookAndFeel.installBorder(frame, "InternalFrame.paletteBorder");
|
||||
} else {
|
||||
LookAndFeel.installBorder(frame, "InternalFrame.border");
|
||||
}
|
||||
((MetalInternalFrameTitlePane)titlePane).setPalette(isPalette);
|
||||
|
||||
}
|
||||
|
||||
private static class MetalPropertyChangeHandler implements
|
||||
PropertyChangeListener
|
||||
{
|
||||
public void propertyChange(PropertyChangeEvent e)
|
||||
{
|
||||
String name = e.getPropertyName();
|
||||
JInternalFrame jif = (JInternalFrame)e.getSource();
|
||||
|
||||
if (!(jif.getUI() instanceof MetalInternalFrameUI)) {
|
||||
return;
|
||||
}
|
||||
|
||||
MetalInternalFrameUI ui = (MetalInternalFrameUI)jif.getUI();
|
||||
|
||||
if ( name.equals( FRAME_TYPE ) )
|
||||
{
|
||||
if ( e.getNewValue() instanceof String )
|
||||
{
|
||||
ui.setFrameType( (String) e.getNewValue() );
|
||||
}
|
||||
}
|
||||
else if ( name.equals(IS_PALETTE_KEY) )
|
||||
{
|
||||
if ( e.getNewValue() != null )
|
||||
{
|
||||
ui.setPalette( ((Boolean)e.getNewValue()).booleanValue() );
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.setPalette( false );
|
||||
}
|
||||
} else if ( name.equals( JInternalFrame.CONTENT_PANE_PROPERTY ) ) {
|
||||
ui.stripContentBorder(e.getNewValue());
|
||||
}
|
||||
}
|
||||
} // end class MetalPropertyChangeHandler
|
||||
|
||||
|
||||
private class BorderListener1 extends BorderListener implements SwingConstants
|
||||
{
|
||||
|
||||
Rectangle getIconBounds() {
|
||||
boolean leftToRight = MetalUtils.isLeftToRight(frame);
|
||||
int xOffset = leftToRight ? 5 : titlePane.getWidth() - 5;
|
||||
Rectangle rect = null;
|
||||
|
||||
Icon icon = frame.getFrameIcon();
|
||||
if ( icon != null ) {
|
||||
if ( !leftToRight ) {
|
||||
xOffset -= icon.getIconWidth();
|
||||
}
|
||||
int iconY = ((titlePane.getHeight() / 2) - (icon.getIconHeight() /2));
|
||||
rect = new Rectangle(xOffset, iconY,
|
||||
icon.getIconWidth(), icon.getIconHeight());
|
||||
}
|
||||
return rect;
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getClickCount() == 2 && e.getSource() == getNorthPane() &&
|
||||
frame.isClosable() && !frame.isIcon()) {
|
||||
Rectangle rect = getIconBounds();
|
||||
if ((rect != null) && rect.contains(e.getX(), e.getY())) {
|
||||
frame.doDefaultCloseAction();
|
||||
}
|
||||
else {
|
||||
super.mouseClicked(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
super.mouseClicked(e);
|
||||
}
|
||||
}
|
||||
}; /// End BorderListener Class
|
||||
|
||||
|
||||
/**
|
||||
* Returns the <code>MouseInputAdapter</code> that will be installed
|
||||
* on the TitlePane.
|
||||
*
|
||||
* @param w the <code>JInternalFrame</code>
|
||||
* @return the <code>MouseInputAdapter</code> that will be installed
|
||||
* on the TitlePane.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected MouseInputAdapter createBorderListener(JInternalFrame w) {
|
||||
return new BorderListener1();
|
||||
}
|
||||
}
|
||||
87
jdkSrc/jdk8/javax/swing/plaf/metal/MetalLabelUI.java
Normal file
87
jdkSrc/jdk8/javax/swing/plaf/metal/MetalLabelUI.java
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import sun.swing.SwingUtilities2;
|
||||
import sun.awt.AppContext;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
|
||||
/**
|
||||
* A Windows L&F implementation of LabelUI. This implementation
|
||||
* is completely static, i.e. there's only one UIView implementation
|
||||
* that's shared by all JLabel objects.
|
||||
*
|
||||
* @author Hans Muller
|
||||
*/
|
||||
|
||||
public class MetalLabelUI extends BasicLabelUI
|
||||
{
|
||||
/**
|
||||
* The default <code>MetalLabelUI</code> instance. This field might
|
||||
* not be used. To change the default instance use a subclass which
|
||||
* overrides the <code>createUI</code> method, and place that class
|
||||
* name in defaults table under the key "LabelUI".
|
||||
*/
|
||||
protected static MetalLabelUI metalLabelUI = new MetalLabelUI();
|
||||
|
||||
private static final Object METAL_LABEL_UI_KEY = new Object();
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
if (System.getSecurityManager() != null) {
|
||||
AppContext appContext = AppContext.getAppContext();
|
||||
MetalLabelUI safeMetalLabelUI =
|
||||
(MetalLabelUI) appContext.get(METAL_LABEL_UI_KEY);
|
||||
if (safeMetalLabelUI == null) {
|
||||
safeMetalLabelUI = new MetalLabelUI();
|
||||
appContext.put(METAL_LABEL_UI_KEY, safeMetalLabelUI);
|
||||
}
|
||||
return safeMetalLabelUI;
|
||||
}
|
||||
return metalLabelUI;
|
||||
}
|
||||
|
||||
/**
|
||||
* Just paint the text gray (Label.disabledForeground) rather than
|
||||
* in the labels foreground color.
|
||||
*
|
||||
* @see #paint
|
||||
* @see #paintEnabledText
|
||||
*/
|
||||
protected void paintDisabledText(JLabel l, Graphics g, String s, int textX, int textY)
|
||||
{
|
||||
int mnemIndex = l.getDisplayedMnemonicIndex();
|
||||
g.setColor(UIManager.getColor("Label.disabledForeground"));
|
||||
SwingUtilities2.drawStringUnderlineCharAt(l, g, s, mnemIndex,
|
||||
textX, textY);
|
||||
}
|
||||
}
|
||||
2435
jdkSrc/jdk8/javax/swing/plaf/metal/MetalLookAndFeel.java
Normal file
2435
jdkSrc/jdk8/javax/swing/plaf/metal/MetalLookAndFeel.java
Normal file
File diff suppressed because it is too large
Load Diff
119
jdkSrc/jdk8/javax/swing/plaf/metal/MetalMenuBarUI.java
Normal file
119
jdkSrc/jdk8/javax/swing/plaf/metal/MetalMenuBarUI.java
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.UIResource;
|
||||
import javax.swing.plaf.basic.*;
|
||||
|
||||
/**
|
||||
* Metal implementation of <code>MenuBarUI</code>. This class is responsible
|
||||
* for providing the metal look and feel for <code>JMenuBar</code>s.
|
||||
*
|
||||
* @see javax.swing.plaf.MenuBarUI
|
||||
* @since 1.5
|
||||
*/
|
||||
public class MetalMenuBarUI extends BasicMenuBarUI {
|
||||
/**
|
||||
* Creates the <code>ComponentUI</code> implementation for the passed
|
||||
* in component.
|
||||
*
|
||||
* @param x JComponent to create the ComponentUI implementation for
|
||||
* @return ComponentUI implementation for <code>x</code>
|
||||
* @throws NullPointerException if <code>x</code> is null
|
||||
*/
|
||||
public static ComponentUI createUI(JComponent x) {
|
||||
if (x == null) {
|
||||
throw new NullPointerException("Must pass in a non-null component");
|
||||
}
|
||||
return new MetalMenuBarUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the specified component appropriate for the metal look and
|
||||
* feel.
|
||||
*
|
||||
* @param c the component where this UI delegate is being installed
|
||||
* @throws NullPointerException if <code>c</code> is null.
|
||||
*/
|
||||
public void installUI(JComponent c) {
|
||||
super.installUI(c);
|
||||
MetalToolBarUI.register(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverses configuration which was done on the specified component during
|
||||
* <code>installUI</code>.
|
||||
*
|
||||
* @param c the component where this UI delegate is being installed
|
||||
* @throws NullPointerException if <code>c</code> is null.
|
||||
*/
|
||||
public void uninstallUI(JComponent c) {
|
||||
super.uninstallUI(c);
|
||||
MetalToolBarUI.unregister(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* If necessary paints the background of the component, then
|
||||
* invokes <code>paint</code>.
|
||||
*
|
||||
* @param g Graphics to paint to
|
||||
* @param c JComponent painting on
|
||||
* @throws NullPointerException if <code>g</code> or <code>c</code> is
|
||||
* null
|
||||
* @see javax.swing.plaf.ComponentUI#update
|
||||
* @see javax.swing.plaf.ComponentUI#paint
|
||||
* @since 1.5
|
||||
*/
|
||||
public void update(Graphics g, JComponent c) {
|
||||
boolean isOpaque = c.isOpaque();
|
||||
if (g == null) {
|
||||
throw new NullPointerException("Graphics must be non-null");
|
||||
}
|
||||
if (isOpaque && (c.getBackground() instanceof UIResource) &&
|
||||
UIManager.get("MenuBar.gradient") != null) {
|
||||
if (MetalToolBarUI.doesMenuBarBorderToolBar((JMenuBar)c)) {
|
||||
JToolBar tb = (JToolBar)MetalToolBarUI.
|
||||
findRegisteredComponentOfType(c, JToolBar.class);
|
||||
if (tb.isOpaque() &&tb.getBackground() instanceof UIResource) {
|
||||
MetalUtils.drawGradient(c, g, "MenuBar.gradient", 0, 0,
|
||||
c.getWidth(), c.getHeight() +
|
||||
tb.getHeight(), true);
|
||||
paint(g, c);
|
||||
return;
|
||||
}
|
||||
}
|
||||
MetalUtils.drawGradient(c, g, "MenuBar.gradient", 0, 0,
|
||||
c.getWidth(), c.getHeight(),true);
|
||||
paint(g, c);
|
||||
}
|
||||
else {
|
||||
super.update(g, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Rectangle;
|
||||
import javax.swing.plaf.*;
|
||||
|
||||
|
||||
/**
|
||||
* A Metal L&F implementation of PopupMenuSeparatorUI. This implementation
|
||||
* is a "combined" view/controller.
|
||||
*
|
||||
* @author Jeff Shapiro
|
||||
*/
|
||||
|
||||
public class MetalPopupMenuSeparatorUI extends MetalSeparatorUI
|
||||
{
|
||||
public static ComponentUI createUI( JComponent c )
|
||||
{
|
||||
return new MetalPopupMenuSeparatorUI();
|
||||
}
|
||||
|
||||
public void paint( Graphics g, JComponent c )
|
||||
{
|
||||
Dimension s = c.getSize();
|
||||
|
||||
g.setColor( c.getForeground() );
|
||||
g.drawLine( 0, 1, s.width, 1 );
|
||||
|
||||
g.setColor( c.getBackground() );
|
||||
g.drawLine( 0, 2, s.width, 2 );
|
||||
g.drawLine( 0, 0, 0, 0 );
|
||||
g.drawLine( 0, 3, 0, 3 );
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize( JComponent c )
|
||||
{
|
||||
return new Dimension( 0, 4 );
|
||||
}
|
||||
}
|
||||
190
jdkSrc/jdk8/javax/swing/plaf/metal/MetalProgressBarUI.java
Normal file
190
jdkSrc/jdk8/javax/swing/plaf/metal/MetalProgressBarUI.java
Normal file
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* The Metal implementation of ProgressBarUI.
|
||||
* <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™
|
||||
* has been added to the <code>java.beans</code> package.
|
||||
* Please see {@link java.beans.XMLEncoder}.
|
||||
*
|
||||
* @author Michael C. Albers
|
||||
*/
|
||||
public class MetalProgressBarUI extends BasicProgressBarUI {
|
||||
|
||||
private Rectangle innards;
|
||||
private Rectangle box;
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new MetalProgressBarUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a bit of special highlighting on the progress bar.
|
||||
* The core painting is deferred to the BasicProgressBar's
|
||||
* <code>paintDeterminate</code> method.
|
||||
* @since 1.4
|
||||
*/
|
||||
public void paintDeterminate(Graphics g, JComponent c) {
|
||||
super.paintDeterminate(g,c);
|
||||
|
||||
if (!(g instanceof Graphics2D)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (progressBar.isBorderPainted()) {
|
||||
Insets b = progressBar.getInsets(); // area for border
|
||||
int barRectWidth = progressBar.getWidth() - (b.left + b.right);
|
||||
int barRectHeight = progressBar.getHeight() - (b.top + b.bottom);
|
||||
int amountFull = getAmountFull(b, barRectWidth, barRectHeight);
|
||||
boolean isLeftToRight = MetalUtils.isLeftToRight(c);
|
||||
int startX, startY, endX, endY;
|
||||
|
||||
// The progress bar border is painted according to a light source.
|
||||
// This light source is stationary and does not change when the
|
||||
// component orientation changes.
|
||||
startX = b.left;
|
||||
startY = b.top;
|
||||
endX = b.left + barRectWidth - 1;
|
||||
endY = b.top + barRectHeight - 1;
|
||||
|
||||
Graphics2D g2 = (Graphics2D)g;
|
||||
g2.setStroke(new BasicStroke(1.f));
|
||||
|
||||
if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
|
||||
// Draw light line lengthwise across the progress bar.
|
||||
g2.setColor(MetalLookAndFeel.getControlShadow());
|
||||
g2.drawLine(startX, startY, endX, startY);
|
||||
|
||||
if (amountFull > 0) {
|
||||
// Draw darker lengthwise line over filled area.
|
||||
g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
|
||||
|
||||
if (isLeftToRight) {
|
||||
g2.drawLine(startX, startY,
|
||||
startX + amountFull - 1, startY);
|
||||
} else {
|
||||
g2.drawLine(endX, startY,
|
||||
endX - amountFull + 1, startY);
|
||||
if (progressBar.getPercentComplete() != 1.f) {
|
||||
g2.setColor(MetalLookAndFeel.getControlShadow());
|
||||
}
|
||||
}
|
||||
}
|
||||
// Draw a line across the width. The color is determined by
|
||||
// the code above.
|
||||
g2.drawLine(startX, startY, startX, endY);
|
||||
|
||||
} else { // VERTICAL
|
||||
// Draw light line lengthwise across the progress bar.
|
||||
g2.setColor(MetalLookAndFeel.getControlShadow());
|
||||
g2.drawLine(startX, startY, startX, endY);
|
||||
|
||||
if (amountFull > 0) {
|
||||
// Draw darker lengthwise line over filled area.
|
||||
g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
|
||||
g2.drawLine(startX, endY,
|
||||
startX, endY - amountFull + 1);
|
||||
}
|
||||
// Draw a line across the width. The color is determined by
|
||||
// the code above.
|
||||
g2.setColor(MetalLookAndFeel.getControlShadow());
|
||||
|
||||
if (progressBar.getPercentComplete() == 1.f) {
|
||||
g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
|
||||
}
|
||||
g2.drawLine(startX, startY, endX, startY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a bit of special highlighting on the progress bar
|
||||
* and bouncing box.
|
||||
* The core painting is deferred to the BasicProgressBar's
|
||||
* <code>paintIndeterminate</code> method.
|
||||
* @since 1.4
|
||||
*/
|
||||
public void paintIndeterminate(Graphics g, JComponent c) {
|
||||
super.paintIndeterminate(g, c);
|
||||
|
||||
if (!progressBar.isBorderPainted() || (!(g instanceof Graphics2D))) {
|
||||
return;
|
||||
}
|
||||
|
||||
Insets b = progressBar.getInsets(); // area for border
|
||||
int barRectWidth = progressBar.getWidth() - (b.left + b.right);
|
||||
int barRectHeight = progressBar.getHeight() - (b.top + b.bottom);
|
||||
int amountFull = getAmountFull(b, barRectWidth, barRectHeight);
|
||||
boolean isLeftToRight = MetalUtils.isLeftToRight(c);
|
||||
int startX, startY, endX, endY;
|
||||
Rectangle box = null;
|
||||
box = getBox(box);
|
||||
|
||||
// The progress bar border is painted according to a light source.
|
||||
// This light source is stationary and does not change when the
|
||||
// component orientation changes.
|
||||
startX = b.left;
|
||||
startY = b.top;
|
||||
endX = b.left + barRectWidth - 1;
|
||||
endY = b.top + barRectHeight - 1;
|
||||
|
||||
Graphics2D g2 = (Graphics2D)g;
|
||||
g2.setStroke(new BasicStroke(1.f));
|
||||
|
||||
if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
|
||||
// Draw light line lengthwise across the progress bar.
|
||||
g2.setColor(MetalLookAndFeel.getControlShadow());
|
||||
g2.drawLine(startX, startY, endX, startY);
|
||||
g2.drawLine(startX, startY, startX, endY);
|
||||
|
||||
// Draw darker lengthwise line over filled area.
|
||||
g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
|
||||
g2.drawLine(box.x, startY, box.x + box.width - 1, startY);
|
||||
|
||||
} else { // VERTICAL
|
||||
// Draw light line lengthwise across the progress bar.
|
||||
g2.setColor(MetalLookAndFeel.getControlShadow());
|
||||
g2.drawLine(startX, startY, startX, endY);
|
||||
g2.drawLine(startX, startY, endX, startY);
|
||||
|
||||
// Draw darker lengthwise line over filled area.
|
||||
g2.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
|
||||
g2.drawLine(startX, box.y, startX, box.y + box.height - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
226
jdkSrc/jdk8/javax/swing/plaf/metal/MetalRadioButtonUI.java
Normal file
226
jdkSrc/jdk8/javax/swing/plaf/metal/MetalRadioButtonUI.java
Normal file
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import sun.swing.SwingUtilities2;
|
||||
import sun.awt.AppContext;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.*;
|
||||
import java.io.Serializable;
|
||||
import javax.swing.text.View;
|
||||
|
||||
|
||||
/**
|
||||
* RadioButtonUI implementation for MetalRadioButtonUI
|
||||
* <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™
|
||||
* has been added to the <code>java.beans</code> package.
|
||||
* Please see {@link java.beans.XMLEncoder}.
|
||||
*
|
||||
* @author Michael C. Albers (Metal modifications)
|
||||
* @author Jeff Dinkins (original BasicRadioButtonCode)
|
||||
*/
|
||||
public class MetalRadioButtonUI extends BasicRadioButtonUI {
|
||||
|
||||
private static final Object METAL_RADIO_BUTTON_UI_KEY = new Object();
|
||||
|
||||
protected Color focusColor;
|
||||
protected Color selectColor;
|
||||
protected Color disabledTextColor;
|
||||
|
||||
private boolean defaults_initialized = false;
|
||||
|
||||
// ********************************
|
||||
// Create PlAF
|
||||
// ********************************
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
AppContext appContext = AppContext.getAppContext();
|
||||
MetalRadioButtonUI metalRadioButtonUI =
|
||||
(MetalRadioButtonUI) appContext.get(METAL_RADIO_BUTTON_UI_KEY);
|
||||
if (metalRadioButtonUI == null) {
|
||||
metalRadioButtonUI = new MetalRadioButtonUI();
|
||||
appContext.put(METAL_RADIO_BUTTON_UI_KEY, metalRadioButtonUI);
|
||||
}
|
||||
return metalRadioButtonUI;
|
||||
}
|
||||
|
||||
// ********************************
|
||||
// Install Defaults
|
||||
// ********************************
|
||||
public void installDefaults(AbstractButton b) {
|
||||
super.installDefaults(b);
|
||||
if(!defaults_initialized) {
|
||||
focusColor = UIManager.getColor(getPropertyPrefix() + "focus");
|
||||
selectColor = UIManager.getColor(getPropertyPrefix() + "select");
|
||||
disabledTextColor = UIManager.getColor(getPropertyPrefix() + "disabledText");
|
||||
defaults_initialized = true;
|
||||
}
|
||||
LookAndFeel.installProperty(b, "opaque", Boolean.TRUE);
|
||||
}
|
||||
|
||||
protected void uninstallDefaults(AbstractButton b) {
|
||||
super.uninstallDefaults(b);
|
||||
defaults_initialized = false;
|
||||
}
|
||||
|
||||
// ********************************
|
||||
// Default Accessors
|
||||
// ********************************
|
||||
protected Color getSelectColor() {
|
||||
return selectColor;
|
||||
}
|
||||
|
||||
protected Color getDisabledTextColor() {
|
||||
return disabledTextColor;
|
||||
}
|
||||
|
||||
protected Color getFocusColor() {
|
||||
return focusColor;
|
||||
}
|
||||
|
||||
|
||||
// ********************************
|
||||
// Paint Methods
|
||||
// ********************************
|
||||
public synchronized void paint(Graphics g, JComponent c) {
|
||||
|
||||
AbstractButton b = (AbstractButton) c;
|
||||
ButtonModel model = b.getModel();
|
||||
|
||||
Dimension size = c.getSize();
|
||||
|
||||
int w = size.width;
|
||||
int h = size.height;
|
||||
|
||||
Font f = c.getFont();
|
||||
g.setFont(f);
|
||||
FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f);
|
||||
|
||||
Rectangle viewRect = new Rectangle(size);
|
||||
Rectangle iconRect = new Rectangle();
|
||||
Rectangle textRect = new Rectangle();
|
||||
|
||||
Insets i = c.getInsets();
|
||||
viewRect.x += i.left;
|
||||
viewRect.y += i.top;
|
||||
viewRect.width -= (i.right + viewRect.x);
|
||||
viewRect.height -= (i.bottom + viewRect.y);
|
||||
|
||||
Icon altIcon = b.getIcon();
|
||||
Icon selectedIcon = null;
|
||||
Icon disabledIcon = null;
|
||||
|
||||
String text = SwingUtilities.layoutCompoundLabel(
|
||||
c, fm, b.getText(), altIcon != null ? altIcon : getDefaultIcon(),
|
||||
b.getVerticalAlignment(), b.getHorizontalAlignment(),
|
||||
b.getVerticalTextPosition(), b.getHorizontalTextPosition(),
|
||||
viewRect, iconRect, textRect, b.getIconTextGap());
|
||||
|
||||
// fill background
|
||||
if(c.isOpaque()) {
|
||||
g.setColor(b.getBackground());
|
||||
g.fillRect(0,0, size.width, size.height);
|
||||
}
|
||||
|
||||
|
||||
// Paint the radio button
|
||||
if(altIcon != null) {
|
||||
|
||||
if(!model.isEnabled()) {
|
||||
if(model.isSelected()) {
|
||||
altIcon = b.getDisabledSelectedIcon();
|
||||
} else {
|
||||
altIcon = b.getDisabledIcon();
|
||||
}
|
||||
} else if(model.isPressed() && model.isArmed()) {
|
||||
altIcon = b.getPressedIcon();
|
||||
if(altIcon == null) {
|
||||
// Use selected icon
|
||||
altIcon = b.getSelectedIcon();
|
||||
}
|
||||
} else if(model.isSelected()) {
|
||||
if(b.isRolloverEnabled() && model.isRollover()) {
|
||||
altIcon = b.getRolloverSelectedIcon();
|
||||
if (altIcon == null) {
|
||||
altIcon = b.getSelectedIcon();
|
||||
}
|
||||
} else {
|
||||
altIcon = b.getSelectedIcon();
|
||||
}
|
||||
} else if(b.isRolloverEnabled() && model.isRollover()) {
|
||||
altIcon = b.getRolloverIcon();
|
||||
}
|
||||
|
||||
if(altIcon == null) {
|
||||
altIcon = b.getIcon();
|
||||
}
|
||||
|
||||
altIcon.paintIcon(c, g, iconRect.x, iconRect.y);
|
||||
|
||||
} else {
|
||||
getDefaultIcon().paintIcon(c, g, iconRect.x, iconRect.y);
|
||||
}
|
||||
|
||||
|
||||
// Draw the Text
|
||||
if(text != null) {
|
||||
View v = (View) c.getClientProperty(BasicHTML.propertyKey);
|
||||
if (v != null) {
|
||||
v.paint(g, textRect);
|
||||
} else {
|
||||
int mnemIndex = b.getDisplayedMnemonicIndex();
|
||||
if(model.isEnabled()) {
|
||||
// *** paint the text normally
|
||||
g.setColor(b.getForeground());
|
||||
} else {
|
||||
// *** paint the text disabled
|
||||
g.setColor(getDisabledTextColor());
|
||||
}
|
||||
SwingUtilities2.drawStringUnderlineCharAt(c,g,text,
|
||||
mnemIndex, textRect.x, textRect.y + fm.getAscent());
|
||||
}
|
||||
if(b.hasFocus() && b.isFocusPainted() &&
|
||||
textRect.width > 0 && textRect.height > 0 ) {
|
||||
paintFocus(g,textRect,size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void paintFocus(Graphics g, Rectangle t, Dimension d){
|
||||
g.setColor(getFocusColor());
|
||||
g.drawRect(t.x-1, t.y-1, t.width+1, t.height+1);
|
||||
}
|
||||
}
|
||||
989
jdkSrc/jdk8/javax/swing/plaf/metal/MetalRootPaneUI.java
Normal file
989
jdkSrc/jdk8/javax/swing/plaf/metal/MetalRootPaneUI.java
Normal file
@@ -0,0 +1,989 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import java.awt.event.*;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.security.*;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* <code>Border</code> and <code>Component</code> are only installed/added if
|
||||
* 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™
|
||||
* has been added to the <code>java.beans</code> package.
|
||||
* Please see {@link java.beans.XMLEncoder}.
|
||||
*
|
||||
* @author Terry Kellerman
|
||||
* @since 1.4
|
||||
*/
|
||||
public class MetalRootPaneUI extends BasicRootPaneUI
|
||||
{
|
||||
/**
|
||||
* Keys to lookup borders in defaults table.
|
||||
*/
|
||||
private static final String[] borderKeys = new String[] {
|
||||
null, "RootPane.frameBorder", "RootPane.plainDialogBorder",
|
||||
"RootPane.informationDialogBorder",
|
||||
"RootPane.errorDialogBorder", "RootPane.colorChooserDialogBorder",
|
||||
"RootPane.fileChooserDialogBorder", "RootPane.questionDialogBorder",
|
||||
"RootPane.warningDialogBorder"
|
||||
};
|
||||
/**
|
||||
* The amount of space (in pixels) that the cursor is changed on.
|
||||
*/
|
||||
private static final int CORNER_DRAG_WIDTH = 16;
|
||||
|
||||
/**
|
||||
* Region from edges that dragging is active from.
|
||||
*/
|
||||
private static final int BORDER_DRAG_THICKNESS = 5;
|
||||
|
||||
/**
|
||||
* Window the <code>JRootPane</code> is in.
|
||||
*/
|
||||
private Window window;
|
||||
|
||||
/**
|
||||
* <code>JComponent</code> providing window decorations. This will be
|
||||
* null if not providing window decorations.
|
||||
*/
|
||||
private JComponent titlePane;
|
||||
|
||||
/**
|
||||
* <code>MouseInputListener</code> that is added to the parent
|
||||
* <code>Window</code> the <code>JRootPane</code> is contained in.
|
||||
*/
|
||||
private MouseInputListener mouseInputListener;
|
||||
|
||||
/**
|
||||
* The <code>LayoutManager</code> that is set on the
|
||||
* <code>JRootPane</code>.
|
||||
*/
|
||||
private LayoutManager layoutManager;
|
||||
|
||||
/**
|
||||
* <code>LayoutManager</code> of the <code>JRootPane</code> before we
|
||||
* replaced it.
|
||||
*/
|
||||
private LayoutManager savedOldLayout;
|
||||
|
||||
/**
|
||||
* <code>JRootPane</code> providing the look and feel for.
|
||||
*/
|
||||
private JRootPane root;
|
||||
|
||||
/**
|
||||
* <code>Cursor</code> used to track the cursor set by the user.
|
||||
* This is initially <code>Cursor.DEFAULT_CURSOR</code>.
|
||||
*/
|
||||
private Cursor lastCursor =
|
||||
Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
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
|
||||
*/
|
||||
public void installUI(JComponent c) {
|
||||
super.installUI(c);
|
||||
root = (JRootPane)c;
|
||||
int style = root.getWindowDecorationStyle();
|
||||
if (style != JRootPane.NONE) {
|
||||
installClientDecorations(root);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public void uninstallUI(JComponent c) {
|
||||
super.uninstallUI(c);
|
||||
uninstallClientDecorations(root);
|
||||
|
||||
layoutManager = null;
|
||||
mouseInputListener = null;
|
||||
root = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs the appropriate <code>Border</code> onto the
|
||||
* <code>JRootPane</code>.
|
||||
*/
|
||||
void installBorder(JRootPane root) {
|
||||
int style = root.getWindowDecorationStyle();
|
||||
|
||||
if (style == JRootPane.NONE) {
|
||||
LookAndFeel.uninstallBorder(root);
|
||||
}
|
||||
else {
|
||||
LookAndFeel.installBorder(root, borderKeys[style]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes any border that may have been installed.
|
||||
*/
|
||||
private void uninstallBorder(JRootPane root) {
|
||||
LookAndFeel.uninstallBorder(root);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
private void installWindowListeners(JRootPane root, Component parent) {
|
||||
if (parent instanceof Window) {
|
||||
window = (Window)parent;
|
||||
}
|
||||
else {
|
||||
window = SwingUtilities.getWindowAncestor(parent);
|
||||
}
|
||||
if (window != null) {
|
||||
if (mouseInputListener == null) {
|
||||
mouseInputListener = createWindowMouseInputListener(root);
|
||||
}
|
||||
window.addMouseListener(mouseInputListener);
|
||||
window.addMouseMotionListener(mouseInputListener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstalls the necessary Listeners on the <code>Window</code> the
|
||||
* Listeners were last installed on.
|
||||
*/
|
||||
private void uninstallWindowListeners(JRootPane root) {
|
||||
if (window != null) {
|
||||
window.removeMouseListener(mouseInputListener);
|
||||
window.removeMouseMotionListener(mouseInputListener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs the appropriate LayoutManager on the <code>JRootPane</code>
|
||||
* to render the window decorations.
|
||||
*/
|
||||
private void installLayout(JRootPane root) {
|
||||
if (layoutManager == null) {
|
||||
layoutManager = createLayoutManager();
|
||||
}
|
||||
savedOldLayout = root.getLayout();
|
||||
root.setLayout(layoutManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstalls the previously installed <code>LayoutManager</code>.
|
||||
*/
|
||||
private void uninstallLayout(JRootPane root) {
|
||||
if (savedOldLayout != null) {
|
||||
root.setLayout(savedOldLayout);
|
||||
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>.
|
||||
*/
|
||||
private void installClientDecorations(JRootPane root) {
|
||||
installBorder(root);
|
||||
|
||||
JComponent titlePane = createTitlePane(root);
|
||||
|
||||
setTitlePane(root, titlePane);
|
||||
installWindowListeners(root, root.getParent());
|
||||
installLayout(root);
|
||||
if (window != null) {
|
||||
root.revalidate();
|
||||
root.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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).
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <code>JComponent</code> to render the window decoration
|
||||
* style.
|
||||
*/
|
||||
private JComponent createTitlePane(JRootPane root) {
|
||||
return new MetalTitlePane(root, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 = 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 = 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 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.getMenuBar() != null) {
|
||||
mbd = root.getMenuBar().getPreferredSize();
|
||||
if (mbd != null) {
|
||||
mbWidth = mbd.width;
|
||||
mbHeight = mbd.height;
|
||||
}
|
||||
}
|
||||
|
||||
if (root.getWindowDecorationStyle() != JRootPane.NONE &&
|
||||
(root.getUI() instanceof MetalRootPaneUI)) {
|
||||
JComponent titlePane = ((MetalRootPaneUI)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 + tpWidth + i.top + i.bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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;
|
||||
|
||||
if(root.getContentPane() != null) {
|
||||
cpd = root.getContentPane().getMinimumSize();
|
||||
} else {
|
||||
cpd = root.getSize();
|
||||
}
|
||||
if (cpd != null) {
|
||||
cpWidth = cpd.width;
|
||||
cpHeight = cpd.height;
|
||||
}
|
||||
|
||||
if(root.getMenuBar() != null) {
|
||||
mbd = root.getMenuBar().getMinimumSize();
|
||||
if (mbd != null) {
|
||||
mbWidth = mbd.width;
|
||||
mbHeight = mbd.height;
|
||||
}
|
||||
}
|
||||
if (root.getWindowDecorationStyle() != JRootPane.NONE &&
|
||||
(root.getUI() instanceof MetalRootPaneUI)) {
|
||||
JComponent titlePane = ((MetalRootPaneUI)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 + tpWidth + i.top + i.bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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 MetalRootPaneUI)) {
|
||||
JComponent titlePane = ((MetalRootPaneUI)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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instructs the layout manager to perform the layout for the specified
|
||||
* container.
|
||||
*
|
||||
* @param 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 MetalRootPaneUI)) {
|
||||
JComponent titlePane = ((MetalRootPaneUI)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) {
|
||||
Dimension mbd = root.getMenuBar().getPreferredSize();
|
||||
root.getMenuBar().setBounds(0, nextY, w, mbd.height);
|
||||
nextY += mbd.height;
|
||||
}
|
||||
if(root.getContentPane() != null) {
|
||||
Dimension cpd = root.getContentPane().getPreferredSize();
|
||||
root.getContentPane().setBounds(0, nextY, w,
|
||||
h < nextY ? 0 : h - nextY);
|
||||
}
|
||||
}
|
||||
|
||||
public void addLayoutComponent(String name, Component comp) {}
|
||||
public void removeLayoutComponent(Component comp) {}
|
||||
public void addLayoutComponent(Component comp, Object constraints) {}
|
||||
public float getLayoutAlignmentX(Container target) { return 0.0f; }
|
||||
public float getLayoutAlignmentY(Container target) { return 0.0f; }
|
||||
public void invalidateLayout(Container target) {}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Maps from positions to cursor type. Refer to calculateCorner and
|
||||
* calculatePosition for details of this.
|
||||
*/
|
||||
private static final int[] cursorMapping = new int[]
|
||||
{ Cursor.NW_RESIZE_CURSOR, Cursor.NW_RESIZE_CURSOR, Cursor.N_RESIZE_CURSOR,
|
||||
Cursor.NE_RESIZE_CURSOR, Cursor.NE_RESIZE_CURSOR,
|
||||
Cursor.NW_RESIZE_CURSOR, 0, 0, 0, Cursor.NE_RESIZE_CURSOR,
|
||||
Cursor.W_RESIZE_CURSOR, 0, 0, 0, Cursor.E_RESIZE_CURSOR,
|
||||
Cursor.SW_RESIZE_CURSOR, 0, 0, 0, Cursor.SE_RESIZE_CURSOR,
|
||||
Cursor.SW_RESIZE_CURSOR, Cursor.SW_RESIZE_CURSOR, Cursor.S_RESIZE_CURSOR,
|
||||
Cursor.SE_RESIZE_CURSOR, Cursor.SE_RESIZE_CURSOR
|
||||
};
|
||||
|
||||
/**
|
||||
* MouseInputHandler is responsible for handling resize/moving of
|
||||
* the Window. It sets the cursor directly on the Window when then
|
||||
* mouse moves over a hot spot.
|
||||
*/
|
||||
private class MouseInputHandler implements MouseInputListener {
|
||||
/**
|
||||
* Set to true if the drag operation is moving the window.
|
||||
*/
|
||||
private boolean isMovingWindow;
|
||||
|
||||
/**
|
||||
* Used to determine the corner the resize is occurring 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;
|
||||
|
||||
public void mousePressed(MouseEvent ev) {
|
||||
JRootPane rootPane = getRootPane();
|
||||
|
||||
if (rootPane.getWindowDecorationStyle() == JRootPane.NONE) {
|
||||
return;
|
||||
}
|
||||
Point dragWindowOffset = ev.getPoint();
|
||||
Window w = (Window)ev.getSource();
|
||||
if (w != null) {
|
||||
w.toFront();
|
||||
}
|
||||
Point convertedDragWindowOffset = SwingUtilities.convertPoint(
|
||||
w, dragWindowOffset, getTitlePane());
|
||||
|
||||
Frame f = null;
|
||||
Dialog d = null;
|
||||
|
||||
if (w instanceof Frame) {
|
||||
f = (Frame)w;
|
||||
} else if (w instanceof Dialog) {
|
||||
d = (Dialog)w;
|
||||
}
|
||||
|
||||
int frameState = (f != null) ? f.getExtendedState() : 0;
|
||||
|
||||
if (getTitlePane() != null &&
|
||||
getTitlePane().contains(convertedDragWindowOffset)) {
|
||||
if ((f != null && ((frameState & Frame.MAXIMIZED_BOTH) == 0)
|
||||
|| (d != null))
|
||||
&& dragWindowOffset.y >= BORDER_DRAG_THICKNESS
|
||||
&& dragWindowOffset.x >= BORDER_DRAG_THICKNESS
|
||||
&& dragWindowOffset.x < w.getWidth()
|
||||
- BORDER_DRAG_THICKNESS) {
|
||||
isMovingWindow = true;
|
||||
dragOffsetX = dragWindowOffset.x;
|
||||
dragOffsetY = dragWindowOffset.y;
|
||||
}
|
||||
}
|
||||
else if (f != null && f.isResizable()
|
||||
&& ((frameState & Frame.MAXIMIZED_BOTH) == 0)
|
||||
|| (d != null && d.isResizable())) {
|
||||
dragOffsetX = dragWindowOffset.x;
|
||||
dragOffsetY = dragWindowOffset.y;
|
||||
dragWidth = w.getWidth();
|
||||
dragHeight = w.getHeight();
|
||||
dragCursor = getCursor(calculateCorner(
|
||||
w, dragWindowOffset.x, dragWindowOffset.y));
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent ev) {
|
||||
if (dragCursor != 0 && window != null && !window.isValid()) {
|
||||
// Some Window systems validate as you resize, others won't,
|
||||
// thus the check for validity before repainting.
|
||||
window.validate();
|
||||
getRootPane().repaint();
|
||||
}
|
||||
isMovingWindow = false;
|
||||
dragCursor = 0;
|
||||
}
|
||||
|
||||
public void mouseMoved(MouseEvent ev) {
|
||||
JRootPane root = getRootPane();
|
||||
|
||||
if (root.getWindowDecorationStyle() == JRootPane.NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
Window w = (Window)ev.getSource();
|
||||
|
||||
Frame f = null;
|
||||
Dialog d = null;
|
||||
|
||||
if (w instanceof Frame) {
|
||||
f = (Frame)w;
|
||||
} else if (w instanceof Dialog) {
|
||||
d = (Dialog)w;
|
||||
}
|
||||
|
||||
// Update the cursor
|
||||
int cursor = getCursor(calculateCorner(w, ev.getX(), ev.getY()));
|
||||
|
||||
if (cursor != 0 && ((f != null && (f.isResizable() &&
|
||||
(f.getExtendedState() & Frame.MAXIMIZED_BOTH) == 0))
|
||||
|| (d != null && d.isResizable()))) {
|
||||
w.setCursor(Cursor.getPredefinedCursor(cursor));
|
||||
}
|
||||
else {
|
||||
w.setCursor(lastCursor);
|
||||
}
|
||||
}
|
||||
|
||||
private 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseDragged(MouseEvent ev) {
|
||||
Window w = (Window)ev.getSource();
|
||||
Point pt = ev.getPoint();
|
||||
|
||||
if (isMovingWindow) {
|
||||
Point eventLocationOnScreen = ev.getLocationOnScreen();
|
||||
w.setLocation(eventLocationOnScreen.x - dragOffsetX,
|
||||
eventLocationOnScreen.y - dragOffsetY);
|
||||
}
|
||||
else if (dragCursor != 0) {
|
||||
Rectangle r = w.getBounds();
|
||||
Rectangle startBounds = new Rectangle(r);
|
||||
Dimension min = w.getMinimumSize();
|
||||
|
||||
switch (dragCursor) {
|
||||
case Cursor.E_RESIZE_CURSOR:
|
||||
adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) -
|
||||
r.width, 0);
|
||||
break;
|
||||
case Cursor.S_RESIZE_CURSOR:
|
||||
adjust(r, min, 0, 0, 0, pt.y + (dragHeight - dragOffsetY) -
|
||||
r.height);
|
||||
break;
|
||||
case Cursor.N_RESIZE_CURSOR:
|
||||
adjust(r, min, 0, pt.y -dragOffsetY, 0,
|
||||
-(pt.y - dragOffsetY));
|
||||
break;
|
||||
case Cursor.W_RESIZE_CURSOR:
|
||||
adjust(r, min, pt.x - dragOffsetX, 0,
|
||||
-(pt.x - dragOffsetX), 0);
|
||||
break;
|
||||
case Cursor.NE_RESIZE_CURSOR:
|
||||
adjust(r, min, 0, pt.y - dragOffsetY,
|
||||
pt.x + (dragWidth - dragOffsetX) - r.width,
|
||||
-(pt.y - dragOffsetY));
|
||||
break;
|
||||
case Cursor.SE_RESIZE_CURSOR:
|
||||
adjust(r, min, 0, 0,
|
||||
pt.x + (dragWidth - dragOffsetX) - r.width,
|
||||
pt.y + (dragHeight - dragOffsetY) -
|
||||
r.height);
|
||||
break;
|
||||
case Cursor.NW_RESIZE_CURSOR:
|
||||
adjust(r, min, pt.x - dragOffsetX,
|
||||
pt.y - dragOffsetY,
|
||||
-(pt.x - dragOffsetX),
|
||||
-(pt.y - dragOffsetY));
|
||||
break;
|
||||
case Cursor.SW_RESIZE_CURSOR:
|
||||
adjust(r, min, pt.x - dragOffsetX, 0,
|
||||
-(pt.x - dragOffsetX),
|
||||
pt.y + (dragHeight - dragOffsetY) - r.height);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (!r.equals(startBounds)) {
|
||||
w.setBounds(r);
|
||||
// Defer repaint/validate on mouseReleased unless dynamic
|
||||
// layout is active.
|
||||
if (Toolkit.getDefaultToolkit().isDynamicLayoutActive()) {
|
||||
w.validate();
|
||||
getRootPane().repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseEntered(MouseEvent ev) {
|
||||
Window w = (Window)ev.getSource();
|
||||
lastCursor = w.getCursor();
|
||||
mouseMoved(ev);
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent ev) {
|
||||
Window w = (Window)ev.getSource();
|
||||
w.setCursor(lastCursor);
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent ev) {
|
||||
Window w = (Window)ev.getSource();
|
||||
Frame f = null;
|
||||
|
||||
if (w instanceof Frame) {
|
||||
f = (Frame)w;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
Point convertedPoint = SwingUtilities.convertPoint(
|
||||
w, ev.getPoint(), getTitlePane());
|
||||
|
||||
int state = f.getExtendedState();
|
||||
if (getTitlePane() != null &&
|
||||
getTitlePane().contains(convertedPoint)) {
|
||||
if ((ev.getClickCount() % 2) == 0 &&
|
||||
((ev.getModifiers() & InputEvent.BUTTON1_MASK) != 0)) {
|
||||
if (f.isResizable()) {
|
||||
if ((state & Frame.MAXIMIZED_BOTH) != 0) {
|
||||
f.setExtendedState(state & ~Frame.MAXIMIZED_BOTH);
|
||||
}
|
||||
else {
|
||||
f.setExtendedState(state | Frame.MAXIMIZED_BOTH);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the corner that contains the point <code>x</code>,
|
||||
* <code>y</code>, or -1 if the position doesn't match a corner.
|
||||
*/
|
||||
private int calculateCorner(Window w, int x, int y) {
|
||||
Insets insets = w.getInsets();
|
||||
int xPosition = calculatePosition(x - insets.left,
|
||||
w.getWidth() - insets.left - insets.right);
|
||||
int yPosition = calculatePosition(y - insets.top,
|
||||
w.getHeight() - insets.top - insets.bottom);
|
||||
|
||||
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
|
||||
*/
|
||||
private int getCursor(int corner) {
|
||||
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
|
||||
*/
|
||||
private int calculatePosition(int spot, int width) {
|
||||
if (spot < BORDER_DRAG_THICKNESS) {
|
||||
return 0;
|
||||
}
|
||||
if (spot < CORNER_DRAG_WIDTH) {
|
||||
return 1;
|
||||
}
|
||||
if (spot >= (width - BORDER_DRAG_THICKNESS)) {
|
||||
return 4;
|
||||
}
|
||||
if (spot >= (width - CORNER_DRAG_WIDTH)) {
|
||||
return 3;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
478
jdkSrc/jdk8/javax/swing/plaf/metal/MetalScrollBarUI.java
Normal file
478
jdkSrc/jdk8/javax/swing/plaf/metal/MetalScrollBarUI.java
Normal file
@@ -0,0 +1,478 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JScrollBar;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.basic.BasicScrollBarUI;
|
||||
|
||||
import static sun.swing.SwingUtilities2.drawHLine;
|
||||
import static sun.swing.SwingUtilities2.drawRect;
|
||||
import static sun.swing.SwingUtilities2.drawVLine;
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of ScrollBarUI for the Metal Look and Feel
|
||||
* <p>
|
||||
*
|
||||
* @author Tom Santos
|
||||
* @author Steve Wilson
|
||||
*/
|
||||
public class MetalScrollBarUI extends BasicScrollBarUI
|
||||
{
|
||||
private static Color shadowColor;
|
||||
private static Color highlightColor;
|
||||
private static Color darkShadowColor;
|
||||
private static Color thumbColor;
|
||||
private static Color thumbShadow;
|
||||
private static Color thumbHighlightColor;
|
||||
|
||||
|
||||
protected MetalBumps bumps;
|
||||
|
||||
protected MetalScrollButton increaseButton;
|
||||
protected MetalScrollButton decreaseButton;
|
||||
|
||||
protected int scrollBarWidth;
|
||||
|
||||
public static final String FREE_STANDING_PROP = "JScrollBar.isFreeStanding";
|
||||
protected boolean isFreeStanding = true;
|
||||
|
||||
public static ComponentUI createUI( JComponent c )
|
||||
{
|
||||
return new MetalScrollBarUI();
|
||||
}
|
||||
|
||||
protected void installDefaults() {
|
||||
scrollBarWidth = ((Integer)(UIManager.get( "ScrollBar.width" ))).intValue();
|
||||
super.installDefaults();
|
||||
bumps = new MetalBumps( 10, 10, thumbHighlightColor, thumbShadow, thumbColor );
|
||||
}
|
||||
|
||||
protected void installListeners(){
|
||||
super.installListeners();
|
||||
((ScrollBarListener)propertyChangeListener).handlePropertyChange( scrollbar.getClientProperty( FREE_STANDING_PROP ) );
|
||||
}
|
||||
|
||||
protected PropertyChangeListener createPropertyChangeListener(){
|
||||
return new ScrollBarListener();
|
||||
}
|
||||
|
||||
protected void configureScrollBarColors()
|
||||
{
|
||||
super.configureScrollBarColors();
|
||||
shadowColor = UIManager.getColor("ScrollBar.shadow");
|
||||
highlightColor = UIManager.getColor("ScrollBar.highlight");
|
||||
darkShadowColor = UIManager.getColor("ScrollBar.darkShadow");
|
||||
thumbColor = UIManager.getColor("ScrollBar.thumb");
|
||||
thumbShadow = UIManager.getColor("ScrollBar.thumbShadow");
|
||||
thumbHighlightColor = UIManager.getColor("ScrollBar.thumbHighlight");
|
||||
|
||||
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize( JComponent c )
|
||||
{
|
||||
if ( scrollbar.getOrientation() == JScrollBar.VERTICAL )
|
||||
{
|
||||
return new Dimension( scrollBarWidth, scrollBarWidth * 3 + 10 );
|
||||
}
|
||||
else // Horizontal
|
||||
{
|
||||
return new Dimension( scrollBarWidth * 3 + 10, scrollBarWidth );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Returns the view that represents the decrease view.
|
||||
*/
|
||||
protected JButton createDecreaseButton( int orientation )
|
||||
{
|
||||
decreaseButton = new MetalScrollButton( orientation, scrollBarWidth, isFreeStanding );
|
||||
return decreaseButton;
|
||||
}
|
||||
|
||||
/** Returns the view that represents the increase view. */
|
||||
protected JButton createIncreaseButton( int orientation )
|
||||
{
|
||||
increaseButton = new MetalScrollButton( orientation, scrollBarWidth, isFreeStanding );
|
||||
return increaseButton;
|
||||
}
|
||||
|
||||
protected void paintTrack( Graphics g, JComponent c, Rectangle trackBounds )
|
||||
{
|
||||
g.translate( trackBounds.x, trackBounds.y );
|
||||
|
||||
boolean leftToRight = MetalUtils.isLeftToRight(c);
|
||||
|
||||
if ( scrollbar.getOrientation() == JScrollBar.VERTICAL )
|
||||
{
|
||||
if ( !isFreeStanding ) {
|
||||
trackBounds.width += 2;
|
||||
if ( !leftToRight ) {
|
||||
g.translate( -1, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( c.isEnabled() ) {
|
||||
g.setColor( darkShadowColor );
|
||||
drawVLine(g, 0, 0, trackBounds.height - 1);
|
||||
drawVLine(g, trackBounds.width - 2, 0, trackBounds.height - 1);
|
||||
drawHLine(g, 2, trackBounds.width - 1, trackBounds.height - 1);
|
||||
drawHLine(g, 2, trackBounds.width - 2, 0);
|
||||
|
||||
g.setColor( shadowColor );
|
||||
// g.setColor( Color.red);
|
||||
drawVLine(g, 1, 1, trackBounds.height - 2);
|
||||
drawHLine(g, 1, trackBounds.width - 3, 1);
|
||||
if (scrollbar.getValue() != scrollbar.getMaximum()) { // thumb shadow
|
||||
int y = thumbRect.y + thumbRect.height - trackBounds.y;
|
||||
drawHLine(g, 1, trackBounds.width - 1, y);
|
||||
}
|
||||
g.setColor(highlightColor);
|
||||
drawVLine(g, trackBounds.width - 1, 0, trackBounds.height - 1);
|
||||
} else {
|
||||
MetalUtils.drawDisabledBorder(g, 0, 0, trackBounds.width, trackBounds.height );
|
||||
}
|
||||
|
||||
if ( !isFreeStanding ) {
|
||||
trackBounds.width -= 2;
|
||||
if ( !leftToRight ) {
|
||||
g.translate( 1, 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
else // HORIZONTAL
|
||||
{
|
||||
if ( !isFreeStanding ) {
|
||||
trackBounds.height += 2;
|
||||
}
|
||||
|
||||
if ( c.isEnabled() ) {
|
||||
g.setColor( darkShadowColor );
|
||||
drawHLine(g, 0, trackBounds.width - 1, 0); // top
|
||||
drawVLine(g, 0, 2, trackBounds.height - 2); // left
|
||||
drawHLine(g, 0, trackBounds.width - 1, trackBounds.height - 2 ); // bottom
|
||||
drawVLine(g, trackBounds.width - 1, 2, trackBounds.height - 1 ); // right
|
||||
|
||||
g.setColor( shadowColor );
|
||||
// g.setColor( Color.red);
|
||||
drawHLine(g, 1, trackBounds.width - 2, 1 ); // top
|
||||
drawVLine(g, 1, 1, trackBounds.height - 3 ); // left
|
||||
drawHLine(g, 0, trackBounds.width - 1, trackBounds.height - 1 ); // bottom
|
||||
if (scrollbar.getValue() != scrollbar.getMaximum()) { // thumb shadow
|
||||
int x = thumbRect.x + thumbRect.width - trackBounds.x;
|
||||
drawVLine(g, x, 1, trackBounds.height-1);
|
||||
}
|
||||
} else {
|
||||
MetalUtils.drawDisabledBorder(g, 0, 0, trackBounds.width, trackBounds.height );
|
||||
}
|
||||
|
||||
if ( !isFreeStanding ) {
|
||||
trackBounds.height -= 2;
|
||||
}
|
||||
}
|
||||
|
||||
g.translate( -trackBounds.x, -trackBounds.y );
|
||||
}
|
||||
|
||||
protected void paintThumb( Graphics g, JComponent c, Rectangle thumbBounds )
|
||||
{
|
||||
if (!c.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (MetalLookAndFeel.usingOcean()) {
|
||||
oceanPaintThumb(g, c, thumbBounds);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean leftToRight = MetalUtils.isLeftToRight(c);
|
||||
|
||||
g.translate( thumbBounds.x, thumbBounds.y );
|
||||
|
||||
if ( scrollbar.getOrientation() == JScrollBar.VERTICAL )
|
||||
{
|
||||
if ( !isFreeStanding ) {
|
||||
thumbBounds.width += 2;
|
||||
if ( !leftToRight ) {
|
||||
g.translate( -1, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
g.setColor( thumbColor );
|
||||
g.fillRect( 0, 0, thumbBounds.width - 2, thumbBounds.height - 1 );
|
||||
|
||||
g.setColor( thumbShadow );
|
||||
drawRect(g, 0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
|
||||
|
||||
g.setColor( thumbHighlightColor );
|
||||
drawHLine(g, 1, thumbBounds.width - 3, 1);
|
||||
drawVLine(g, 1, 1, thumbBounds.height - 2);
|
||||
|
||||
bumps.setBumpArea( thumbBounds.width - 6, thumbBounds.height - 7 );
|
||||
bumps.paintIcon( c, g, 3, 4 );
|
||||
|
||||
if ( !isFreeStanding ) {
|
||||
thumbBounds.width -= 2;
|
||||
if ( !leftToRight ) {
|
||||
g.translate( 1, 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
else // HORIZONTAL
|
||||
{
|
||||
if ( !isFreeStanding ) {
|
||||
thumbBounds.height += 2;
|
||||
}
|
||||
|
||||
g.setColor( thumbColor );
|
||||
g.fillRect( 0, 0, thumbBounds.width - 1, thumbBounds.height - 2 );
|
||||
|
||||
g.setColor( thumbShadow );
|
||||
drawRect(g, 0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
|
||||
|
||||
g.setColor( thumbHighlightColor );
|
||||
drawHLine(g, 1, thumbBounds.width - 3, 1);
|
||||
drawVLine(g, 1, 1, thumbBounds.height - 3);
|
||||
|
||||
bumps.setBumpArea( thumbBounds.width - 7, thumbBounds.height - 6 );
|
||||
bumps.paintIcon( c, g, 4, 3 );
|
||||
|
||||
if ( !isFreeStanding ) {
|
||||
thumbBounds.height -= 2;
|
||||
}
|
||||
}
|
||||
|
||||
g.translate( -thumbBounds.x, -thumbBounds.y );
|
||||
}
|
||||
|
||||
private void oceanPaintThumb(Graphics g, JComponent c,
|
||||
Rectangle thumbBounds) {
|
||||
boolean leftToRight = MetalUtils.isLeftToRight(c);
|
||||
|
||||
g.translate(thumbBounds.x, thumbBounds.y);
|
||||
|
||||
if (scrollbar.getOrientation() == JScrollBar.VERTICAL) {
|
||||
if (!isFreeStanding) {
|
||||
thumbBounds.width += 2;
|
||||
if (!leftToRight) {
|
||||
g.translate(-1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (thumbColor != null) {
|
||||
g.setColor(thumbColor);
|
||||
g.fillRect(0, 0, thumbBounds.width - 2,thumbBounds.height - 1);
|
||||
}
|
||||
|
||||
g.setColor(thumbShadow);
|
||||
drawRect(g, 0, 0, thumbBounds.width - 2, thumbBounds.height - 1);
|
||||
|
||||
g.setColor(thumbHighlightColor);
|
||||
drawHLine(g, 1, thumbBounds.width - 3, 1);
|
||||
drawVLine(g, 1, 1, thumbBounds.height - 2);
|
||||
|
||||
MetalUtils.drawGradient(c, g, "ScrollBar.gradient", 2, 2,
|
||||
thumbBounds.width - 4,
|
||||
thumbBounds.height - 3, false);
|
||||
|
||||
int gripSize = thumbBounds.width - 8;
|
||||
if (gripSize > 2 && thumbBounds.height >= 10) {
|
||||
g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
|
||||
int gripY = thumbBounds.height / 2 - 2;
|
||||
for (int counter = 0; counter < 6; counter += 2) {
|
||||
g.fillRect(4, counter + gripY, gripSize, 1);
|
||||
}
|
||||
|
||||
g.setColor(MetalLookAndFeel.getWhite());
|
||||
gripY++;
|
||||
for (int counter = 0; counter < 6; counter += 2) {
|
||||
g.fillRect(5, counter + gripY, gripSize, 1);
|
||||
}
|
||||
}
|
||||
if (!isFreeStanding) {
|
||||
thumbBounds.width -= 2;
|
||||
if (!leftToRight) {
|
||||
g.translate(1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else { // HORIZONTAL
|
||||
if (!isFreeStanding) {
|
||||
thumbBounds.height += 2;
|
||||
}
|
||||
|
||||
if (thumbColor != null) {
|
||||
g.setColor(thumbColor);
|
||||
g.fillRect(0, 0, thumbBounds.width - 1,thumbBounds.height - 2);
|
||||
}
|
||||
|
||||
g.setColor(thumbShadow);
|
||||
drawRect(g, 0, 0, thumbBounds.width - 1, thumbBounds.height - 2);
|
||||
|
||||
g.setColor(thumbHighlightColor);
|
||||
drawHLine(g, 1, thumbBounds.width - 2, 1);
|
||||
drawVLine(g, 1, 1, thumbBounds.height - 3);
|
||||
|
||||
MetalUtils.drawGradient(c, g, "ScrollBar.gradient", 2, 2,
|
||||
thumbBounds.width - 3,
|
||||
thumbBounds.height - 4, true);
|
||||
|
||||
int gripSize = thumbBounds.height - 8;
|
||||
if (gripSize > 2 && thumbBounds.width >= 10) {
|
||||
g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
|
||||
int gripX = thumbBounds.width / 2 - 2;
|
||||
for (int counter = 0; counter < 6; counter += 2) {
|
||||
g.fillRect(gripX + counter, 4, 1, gripSize);
|
||||
}
|
||||
|
||||
g.setColor(MetalLookAndFeel.getWhite());
|
||||
gripX++;
|
||||
for (int counter = 0; counter < 6; counter += 2) {
|
||||
g.fillRect(gripX + counter, 5, 1, gripSize);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isFreeStanding) {
|
||||
thumbBounds.height -= 2;
|
||||
}
|
||||
}
|
||||
|
||||
g.translate( -thumbBounds.x, -thumbBounds.y );
|
||||
}
|
||||
|
||||
protected Dimension getMinimumThumbSize()
|
||||
{
|
||||
return new Dimension( scrollBarWidth, scrollBarWidth );
|
||||
}
|
||||
|
||||
/**
|
||||
* This is overridden only to increase the invalid area. This
|
||||
* ensures that the "Shadow" below the thumb is invalidated
|
||||
*/
|
||||
protected void setThumbBounds(int x, int y, int width, int height)
|
||||
{
|
||||
/* If the thumbs bounds haven't changed, we're done.
|
||||
*/
|
||||
if ((thumbRect.x == x) &&
|
||||
(thumbRect.y == y) &&
|
||||
(thumbRect.width == width) &&
|
||||
(thumbRect.height == height)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Update thumbRect, and repaint the union of x,y,w,h and
|
||||
* the old thumbRect.
|
||||
*/
|
||||
int minX = Math.min(x, thumbRect.x);
|
||||
int minY = Math.min(y, thumbRect.y);
|
||||
int maxX = Math.max(x + width, thumbRect.x + thumbRect.width);
|
||||
int maxY = Math.max(y + height, thumbRect.y + thumbRect.height);
|
||||
|
||||
thumbRect.setBounds(x, y, width, height);
|
||||
scrollbar.repaint(minX, minY, (maxX - minX)+1, (maxY - minY)+1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
class ScrollBarListener extends BasicScrollBarUI.PropertyChangeHandler
|
||||
{
|
||||
public void propertyChange(PropertyChangeEvent e)
|
||||
{
|
||||
String name = e.getPropertyName();
|
||||
if ( name.equals( FREE_STANDING_PROP ) )
|
||||
{
|
||||
handlePropertyChange( e.getNewValue() );
|
||||
}
|
||||
else {
|
||||
super.propertyChange( e );
|
||||
}
|
||||
}
|
||||
|
||||
public void handlePropertyChange( Object newValue )
|
||||
{
|
||||
if ( newValue != null )
|
||||
{
|
||||
boolean temp = ((Boolean)newValue).booleanValue();
|
||||
boolean becameFlush = temp == false && isFreeStanding == true;
|
||||
boolean becameNormal = temp == true && isFreeStanding == false;
|
||||
|
||||
isFreeStanding = temp;
|
||||
|
||||
if ( becameFlush ) {
|
||||
toFlush();
|
||||
}
|
||||
else if ( becameNormal ) {
|
||||
toFreeStanding();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if ( !isFreeStanding ) {
|
||||
isFreeStanding = true;
|
||||
toFreeStanding();
|
||||
}
|
||||
|
||||
// This commented-out block is used for testing flush scrollbars.
|
||||
/*
|
||||
if ( isFreeStanding ) {
|
||||
isFreeStanding = false;
|
||||
toFlush();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
if ( increaseButton != null )
|
||||
{
|
||||
increaseButton.setFreeStanding( isFreeStanding );
|
||||
}
|
||||
if ( decreaseButton != null )
|
||||
{
|
||||
decreaseButton.setFreeStanding( isFreeStanding );
|
||||
}
|
||||
}
|
||||
|
||||
protected void toFlush() {
|
||||
scrollBarWidth -= 2;
|
||||
}
|
||||
|
||||
protected void toFreeStanding() {
|
||||
scrollBarWidth += 2;
|
||||
}
|
||||
} // end class ScrollBarListener
|
||||
}
|
||||
346
jdkSrc/jdk8/javax/swing/plaf/metal/MetalScrollButton.java
Normal file
346
jdkSrc/jdk8/javax/swing/plaf/metal/MetalScrollButton.java
Normal file
@@ -0,0 +1,346 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Color;
|
||||
import java.awt.Polygon;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import javax.swing.plaf.basic.BasicArrowButton;
|
||||
|
||||
|
||||
/**
|
||||
* JButton object for Metal scrollbar arrows.
|
||||
* <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™
|
||||
* has been added to the <code>java.beans</code> package.
|
||||
* Please see {@link java.beans.XMLEncoder}.
|
||||
*
|
||||
* @author Tom Santos
|
||||
* @author Steve Wilson
|
||||
*/
|
||||
public class MetalScrollButton extends BasicArrowButton
|
||||
{
|
||||
private static Color shadowColor;
|
||||
private static Color highlightColor;
|
||||
private boolean isFreeStanding = false;
|
||||
|
||||
private int buttonWidth;
|
||||
|
||||
public MetalScrollButton( int direction, int width, boolean freeStanding )
|
||||
{
|
||||
super( direction );
|
||||
|
||||
shadowColor = UIManager.getColor("ScrollBar.darkShadow");
|
||||
highlightColor = UIManager.getColor("ScrollBar.highlight");
|
||||
|
||||
buttonWidth = width;
|
||||
isFreeStanding = freeStanding;
|
||||
}
|
||||
|
||||
public void setFreeStanding( boolean freeStanding )
|
||||
{
|
||||
isFreeStanding = freeStanding;
|
||||
}
|
||||
|
||||
public void paint( Graphics g )
|
||||
{
|
||||
boolean leftToRight = MetalUtils.isLeftToRight(this);
|
||||
boolean isEnabled = getParent().isEnabled();
|
||||
|
||||
Color arrowColor = isEnabled ? MetalLookAndFeel.getControlInfo() : MetalLookAndFeel.getControlDisabled();
|
||||
boolean isPressed = getModel().isPressed();
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
int w = width;
|
||||
int h = height;
|
||||
int arrowHeight = (height+1) / 4;
|
||||
int arrowWidth = (height+1) / 2;
|
||||
|
||||
if ( isPressed )
|
||||
{
|
||||
g.setColor( MetalLookAndFeel.getControlShadow() );
|
||||
}
|
||||
else
|
||||
{
|
||||
g.setColor( getBackground() );
|
||||
}
|
||||
|
||||
g.fillRect( 0, 0, width, height );
|
||||
|
||||
if ( getDirection() == NORTH )
|
||||
{
|
||||
if ( !isFreeStanding ) {
|
||||
height +=1;
|
||||
g.translate( 0, -1 );
|
||||
width += 2;
|
||||
if ( !leftToRight ) {
|
||||
g.translate( -1, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the arrow
|
||||
g.setColor( arrowColor );
|
||||
int startY = ((h+1) - arrowHeight) / 2;
|
||||
int startX = (w / 2);
|
||||
// System.out.println( "startX :" + startX + " startY :"+startY);
|
||||
for (int line = 0; line < arrowHeight; line++) {
|
||||
g.drawLine( startX-line, startY+line, startX +line+1, startY+line);
|
||||
}
|
||||
/* g.drawLine( 7, 6, 8, 6 );
|
||||
g.drawLine( 6, 7, 9, 7 );
|
||||
g.drawLine( 5, 8, 10, 8 );
|
||||
g.drawLine( 4, 9, 11, 9 );*/
|
||||
|
||||
if (isEnabled) {
|
||||
g.setColor( highlightColor );
|
||||
|
||||
if ( !isPressed )
|
||||
{
|
||||
g.drawLine( 1, 1, width - 3, 1 );
|
||||
g.drawLine( 1, 1, 1, height - 1 );
|
||||
}
|
||||
|
||||
g.drawLine( width - 1, 1, width - 1, height - 1 );
|
||||
|
||||
g.setColor( shadowColor );
|
||||
g.drawLine( 0, 0, width - 2, 0 );
|
||||
g.drawLine( 0, 0, 0, height - 1 );
|
||||
g.drawLine( width - 2, 2, width - 2, height - 1 );
|
||||
} else {
|
||||
MetalUtils.drawDisabledBorder(g, 0, 0, width, height+1);
|
||||
}
|
||||
if ( !isFreeStanding ) {
|
||||
height -= 1;
|
||||
g.translate( 0, 1 );
|
||||
width -= 2;
|
||||
if ( !leftToRight ) {
|
||||
g.translate( 1, 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( getDirection() == SOUTH )
|
||||
{
|
||||
if ( !isFreeStanding ) {
|
||||
height += 1;
|
||||
width += 2;
|
||||
if ( !leftToRight ) {
|
||||
g.translate( -1, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the arrow
|
||||
g.setColor( arrowColor );
|
||||
|
||||
int startY = (((h+1) - arrowHeight) / 2)+ arrowHeight-1;
|
||||
int startX = (w / 2);
|
||||
|
||||
// System.out.println( "startX2 :" + startX + " startY2 :"+startY);
|
||||
|
||||
for (int line = 0; line < arrowHeight; line++) {
|
||||
g.drawLine( startX-line, startY-line, startX +line+1, startY-line);
|
||||
}
|
||||
|
||||
/* g.drawLine( 4, 5, 11, 5 );
|
||||
g.drawLine( 5, 6, 10, 6 );
|
||||
g.drawLine( 6, 7, 9, 7 );
|
||||
g.drawLine( 7, 8, 8, 8 ); */
|
||||
|
||||
if (isEnabled) {
|
||||
g.setColor( highlightColor );
|
||||
|
||||
if ( !isPressed )
|
||||
{
|
||||
g.drawLine( 1, 0, width - 3, 0 );
|
||||
g.drawLine( 1, 0, 1, height - 3 );
|
||||
}
|
||||
|
||||
g.drawLine( 1, height - 1, width - 1, height - 1 );
|
||||
g.drawLine( width - 1, 0, width - 1, height - 1 );
|
||||
|
||||
g.setColor( shadowColor );
|
||||
g.drawLine( 0, 0, 0, height - 2 );
|
||||
g.drawLine( width - 2, 0, width - 2, height - 2 );
|
||||
g.drawLine( 2, height - 2, width - 2, height - 2 );
|
||||
} else {
|
||||
MetalUtils.drawDisabledBorder(g, 0,-1, width, height+1);
|
||||
}
|
||||
|
||||
if ( !isFreeStanding ) {
|
||||
height -= 1;
|
||||
width -= 2;
|
||||
if ( !leftToRight ) {
|
||||
g.translate( 1, 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( getDirection() == EAST )
|
||||
{
|
||||
if ( !isFreeStanding ) {
|
||||
height += 2;
|
||||
width += 1;
|
||||
}
|
||||
|
||||
// Draw the arrow
|
||||
g.setColor( arrowColor );
|
||||
|
||||
int startX = (((w+1) - arrowHeight) / 2) + arrowHeight-1;
|
||||
int startY = (h / 2);
|
||||
|
||||
//System.out.println( "startX2 :" + startX + " startY2 :"+startY);
|
||||
|
||||
for (int line = 0; line < arrowHeight; line++) {
|
||||
g.drawLine( startX-line, startY-line, startX -line, startY+line+1);
|
||||
}
|
||||
|
||||
|
||||
/* g.drawLine( 5, 4, 5, 11 );
|
||||
g.drawLine( 6, 5, 6, 10 );
|
||||
g.drawLine( 7, 6, 7, 9 );
|
||||
g.drawLine( 8, 7, 8, 8 );*/
|
||||
|
||||
if (isEnabled) {
|
||||
g.setColor( highlightColor );
|
||||
|
||||
if ( !isPressed )
|
||||
{
|
||||
g.drawLine( 0, 1, width - 3, 1 );
|
||||
g.drawLine( 0, 1, 0, height - 3 );
|
||||
}
|
||||
|
||||
g.drawLine( width - 1, 1, width - 1, height - 1 );
|
||||
g.drawLine( 0, height - 1, width - 1, height - 1 );
|
||||
|
||||
g.setColor( shadowColor );
|
||||
g.drawLine( 0, 0,width - 2, 0 );
|
||||
g.drawLine( width - 2, 2, width - 2, height - 2 );
|
||||
g.drawLine( 0, height - 2, width - 2, height - 2 );
|
||||
} else {
|
||||
MetalUtils.drawDisabledBorder(g,-1,0, width+1, height);
|
||||
}
|
||||
if ( !isFreeStanding ) {
|
||||
height -= 2;
|
||||
width -= 1;
|
||||
}
|
||||
}
|
||||
else if ( getDirection() == WEST )
|
||||
{
|
||||
if ( !isFreeStanding ) {
|
||||
height += 2;
|
||||
width += 1;
|
||||
g.translate( -1, 0 );
|
||||
}
|
||||
|
||||
// Draw the arrow
|
||||
g.setColor( arrowColor );
|
||||
|
||||
int startX = (((w+1) - arrowHeight) / 2);
|
||||
int startY = (h / 2);
|
||||
|
||||
|
||||
for (int line = 0; line < arrowHeight; line++) {
|
||||
g.drawLine( startX+line, startY-line, startX +line, startY+line+1);
|
||||
}
|
||||
|
||||
/* g.drawLine( 6, 7, 6, 8 );
|
||||
g.drawLine( 7, 6, 7, 9 );
|
||||
g.drawLine( 8, 5, 8, 10 );
|
||||
g.drawLine( 9, 4, 9, 11 );*/
|
||||
|
||||
if (isEnabled) {
|
||||
g.setColor( highlightColor );
|
||||
|
||||
|
||||
if ( !isPressed )
|
||||
{
|
||||
g.drawLine( 1, 1, width - 1, 1 );
|
||||
g.drawLine( 1, 1, 1, height - 3 );
|
||||
}
|
||||
|
||||
g.drawLine( 1, height - 1, width - 1, height - 1 );
|
||||
|
||||
g.setColor( shadowColor );
|
||||
g.drawLine( 0, 0, width - 1, 0 );
|
||||
g.drawLine( 0, 0, 0, height - 2 );
|
||||
g.drawLine( 2, height - 2, width - 1, height - 2 );
|
||||
} else {
|
||||
MetalUtils.drawDisabledBorder(g,0,0, width+1, height);
|
||||
}
|
||||
|
||||
if ( !isFreeStanding ) {
|
||||
height -= 2;
|
||||
width -= 1;
|
||||
g.translate( 1, 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize()
|
||||
{
|
||||
if ( getDirection() == NORTH )
|
||||
{
|
||||
return new Dimension( buttonWidth, buttonWidth - 2 );
|
||||
}
|
||||
else if ( getDirection() == SOUTH )
|
||||
{
|
||||
return new Dimension( buttonWidth, buttonWidth - (isFreeStanding ? 1 : 2) );
|
||||
}
|
||||
else if ( getDirection() == EAST )
|
||||
{
|
||||
return new Dimension( buttonWidth - (isFreeStanding ? 1 : 2), buttonWidth );
|
||||
}
|
||||
else if ( getDirection() == WEST )
|
||||
{
|
||||
return new Dimension( buttonWidth - 2, buttonWidth );
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Dimension( 0, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize()
|
||||
{
|
||||
return getPreferredSize();
|
||||
}
|
||||
|
||||
public Dimension getMaximumSize()
|
||||
{
|
||||
return new Dimension( Integer.MAX_VALUE, Integer.MAX_VALUE );
|
||||
}
|
||||
|
||||
public int getButtonWidth() {
|
||||
return buttonWidth;
|
||||
}
|
||||
}
|
||||
162
jdkSrc/jdk8/javax/swing/plaf/metal/MetalScrollPaneUI.java
Normal file
162
jdkSrc/jdk8/javax/swing/plaf/metal/MetalScrollPaneUI.java
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.beans.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
|
||||
/**
|
||||
* A Metal L&F implementation of ScrollPaneUI.
|
||||
* <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™
|
||||
* has been added to the <code>java.beans</code> package.
|
||||
* Please see {@link java.beans.XMLEncoder}.
|
||||
*
|
||||
* @author Steve Wilson
|
||||
*/
|
||||
public class MetalScrollPaneUI extends BasicScrollPaneUI
|
||||
{
|
||||
|
||||
private PropertyChangeListener scrollBarSwapListener;
|
||||
|
||||
public static ComponentUI createUI(JComponent x) {
|
||||
return new MetalScrollPaneUI();
|
||||
}
|
||||
|
||||
public void installUI(JComponent c) {
|
||||
|
||||
super.installUI(c);
|
||||
|
||||
JScrollPane sp = (JScrollPane)c;
|
||||
updateScrollbarsFreeStanding();
|
||||
}
|
||||
|
||||
public void uninstallUI(JComponent c) {
|
||||
super.uninstallUI(c);
|
||||
|
||||
JScrollPane sp = (JScrollPane)c;
|
||||
JScrollBar hsb = sp.getHorizontalScrollBar();
|
||||
JScrollBar vsb = sp.getVerticalScrollBar();
|
||||
if (hsb != null) {
|
||||
hsb.putClientProperty( MetalScrollBarUI.FREE_STANDING_PROP, null);
|
||||
}
|
||||
if (vsb != null) {
|
||||
vsb.putClientProperty( MetalScrollBarUI.FREE_STANDING_PROP, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void installListeners(JScrollPane scrollPane) {
|
||||
super.installListeners(scrollPane);
|
||||
scrollBarSwapListener = createScrollBarSwapListener();
|
||||
scrollPane.addPropertyChangeListener(scrollBarSwapListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected void uninstallListeners(JComponent c) {
|
||||
super.uninstallListeners(c);
|
||||
c.removePropertyChangeListener(scrollBarSwapListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated - Replaced by {@link #uninstallListeners(JComponent)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void uninstallListeners(JScrollPane scrollPane) {
|
||||
super.uninstallListeners(scrollPane);
|
||||
scrollPane.removePropertyChangeListener(scrollBarSwapListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the border of the scrollpane is an instance of
|
||||
* <code>MetalBorders.ScrollPaneBorder</code>, the client property
|
||||
* <code>FREE_STANDING_PROP</code> of the scrollbars
|
||||
* is set to false, otherwise it is set to true.
|
||||
*/
|
||||
private void updateScrollbarsFreeStanding() {
|
||||
if (scrollpane == null) {
|
||||
return;
|
||||
}
|
||||
Border border = scrollpane.getBorder();
|
||||
Object value;
|
||||
|
||||
if (border instanceof MetalBorders.ScrollPaneBorder) {
|
||||
value = Boolean.FALSE;
|
||||
}
|
||||
else {
|
||||
value = Boolean.TRUE;
|
||||
}
|
||||
JScrollBar sb = scrollpane.getHorizontalScrollBar();
|
||||
if (sb != null) {
|
||||
sb.putClientProperty
|
||||
(MetalScrollBarUI.FREE_STANDING_PROP, value);
|
||||
}
|
||||
sb = scrollpane.getVerticalScrollBar();
|
||||
if (sb != null) {
|
||||
sb.putClientProperty
|
||||
(MetalScrollBarUI.FREE_STANDING_PROP, value);
|
||||
}
|
||||
}
|
||||
|
||||
protected PropertyChangeListener createScrollBarSwapListener() {
|
||||
return new PropertyChangeListener() {
|
||||
public void propertyChange(PropertyChangeEvent e) {
|
||||
String propertyName = e.getPropertyName();
|
||||
if (propertyName.equals("verticalScrollBar") ||
|
||||
propertyName.equals("horizontalScrollBar")) {
|
||||
JScrollBar oldSB = (JScrollBar)e.getOldValue();
|
||||
if (oldSB != null) {
|
||||
oldSB.putClientProperty(
|
||||
MetalScrollBarUI.FREE_STANDING_PROP, null);
|
||||
}
|
||||
JScrollBar newSB = (JScrollBar)e.getNewValue();
|
||||
if (newSB != null) {
|
||||
newSB.putClientProperty(
|
||||
MetalScrollBarUI.FREE_STANDING_PROP,
|
||||
Boolean.FALSE);
|
||||
}
|
||||
}
|
||||
else if ("border".equals(propertyName)) {
|
||||
updateScrollbarsFreeStanding();
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
}
|
||||
95
jdkSrc/jdk8/javax/swing/plaf/metal/MetalSeparatorUI.java
Normal file
95
jdkSrc/jdk8/javax/swing/plaf/metal/MetalSeparatorUI.java
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Rectangle;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.BasicSeparatorUI;
|
||||
|
||||
|
||||
/**
|
||||
* A Metal L&F implementation of SeparatorUI. This implementation
|
||||
* is a "combined" view/controller.
|
||||
* <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™
|
||||
* has been added to the <code>java.beans</code> package.
|
||||
* Please see {@link java.beans.XMLEncoder}.
|
||||
*
|
||||
* @author Jeff Shapiro
|
||||
*/
|
||||
|
||||
public class MetalSeparatorUI extends BasicSeparatorUI
|
||||
{
|
||||
public static ComponentUI createUI( JComponent c )
|
||||
{
|
||||
return new MetalSeparatorUI();
|
||||
}
|
||||
|
||||
protected void installDefaults( JSeparator s )
|
||||
{
|
||||
LookAndFeel.installColors( s, "Separator.background", "Separator.foreground" );
|
||||
}
|
||||
|
||||
public void paint( Graphics g, JComponent c )
|
||||
{
|
||||
Dimension s = c.getSize();
|
||||
|
||||
if ( ((JSeparator)c).getOrientation() == JSeparator.VERTICAL )
|
||||
{
|
||||
g.setColor( c.getForeground() );
|
||||
g.drawLine( 0, 0, 0, s.height );
|
||||
|
||||
g.setColor( c.getBackground() );
|
||||
g.drawLine( 1, 0, 1, s.height );
|
||||
}
|
||||
else // HORIZONTAL
|
||||
{
|
||||
g.setColor( c.getForeground() );
|
||||
g.drawLine( 0, 0, s.width, 0 );
|
||||
|
||||
g.setColor( c.getBackground() );
|
||||
g.drawLine( 0, 1, s.width, 1 );
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize( JComponent c )
|
||||
{
|
||||
if ( ((JSeparator)c).getOrientation() == JSeparator.VERTICAL )
|
||||
return new Dimension( 2, 0 );
|
||||
else
|
||||
return new Dimension( 0, 2 );
|
||||
}
|
||||
}
|
||||
556
jdkSrc/jdk8/javax/swing/plaf/metal/MetalSliderUI.java
Normal file
556
jdkSrc/jdk8/javax/swing/plaf/metal/MetalSliderUI.java
Normal file
@@ -0,0 +1,556 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import javax.swing.plaf.basic.BasicSliderUI;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Color;
|
||||
import java.beans.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.*;
|
||||
|
||||
/**
|
||||
* A Java L&F implementation of SliderUI.
|
||||
* <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™
|
||||
* has been added to the <code>java.beans</code> package.
|
||||
* Please see {@link java.beans.XMLEncoder}.
|
||||
*
|
||||
* @author Tom Santos
|
||||
*/
|
||||
public class MetalSliderUI extends BasicSliderUI {
|
||||
|
||||
protected final int TICK_BUFFER = 4;
|
||||
protected boolean filledSlider = false;
|
||||
// NOTE: these next five variables are currently unused.
|
||||
protected static Color thumbColor;
|
||||
protected static Color highlightColor;
|
||||
protected static Color darkShadowColor;
|
||||
protected static int trackWidth;
|
||||
protected static int tickLength;
|
||||
private int safeLength;
|
||||
|
||||
/**
|
||||
* A default horizontal thumb <code>Icon</code>. This field might not be
|
||||
* used. To change the <code>Icon</code> used by this delegate directly set it
|
||||
* using the <code>Slider.horizontalThumbIcon</code> UIManager property.
|
||||
*/
|
||||
protected static Icon horizThumbIcon;
|
||||
|
||||
/**
|
||||
* A default vertical thumb <code>Icon</code>. This field might not be
|
||||
* used. To change the <code>Icon</code> used by this delegate directly set it
|
||||
* using the <code>Slider.verticalThumbIcon</code> UIManager property.
|
||||
*/
|
||||
protected static Icon vertThumbIcon;
|
||||
|
||||
private static Icon SAFE_HORIZ_THUMB_ICON;
|
||||
private static Icon SAFE_VERT_THUMB_ICON;
|
||||
|
||||
|
||||
protected final String SLIDER_FILL = "JSlider.isFilled";
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new MetalSliderUI();
|
||||
}
|
||||
|
||||
public MetalSliderUI() {
|
||||
super( null );
|
||||
}
|
||||
|
||||
private static Icon getHorizThumbIcon() {
|
||||
if (System.getSecurityManager() != null) {
|
||||
return SAFE_HORIZ_THUMB_ICON;
|
||||
} else {
|
||||
return horizThumbIcon;
|
||||
}
|
||||
}
|
||||
|
||||
private static Icon getVertThumbIcon() {
|
||||
if (System.getSecurityManager() != null) {
|
||||
return SAFE_VERT_THUMB_ICON;
|
||||
} else {
|
||||
return vertThumbIcon;
|
||||
}
|
||||
}
|
||||
|
||||
public void installUI( JComponent c ) {
|
||||
trackWidth = ((Integer)UIManager.get( "Slider.trackWidth" )).intValue();
|
||||
tickLength = safeLength = ((Integer)UIManager.get( "Slider.majorTickLength" )).intValue();
|
||||
horizThumbIcon = SAFE_HORIZ_THUMB_ICON =
|
||||
UIManager.getIcon( "Slider.horizontalThumbIcon" );
|
||||
vertThumbIcon = SAFE_VERT_THUMB_ICON =
|
||||
UIManager.getIcon( "Slider.verticalThumbIcon" );
|
||||
|
||||
super.installUI( c );
|
||||
|
||||
thumbColor = UIManager.getColor("Slider.thumb");
|
||||
highlightColor = UIManager.getColor("Slider.highlight");
|
||||
darkShadowColor = UIManager.getColor("Slider.darkShadow");
|
||||
|
||||
scrollListener.setScrollByBlock( false );
|
||||
|
||||
prepareFilledSliderField();
|
||||
}
|
||||
|
||||
protected PropertyChangeListener createPropertyChangeListener( JSlider slider ) {
|
||||
return new MetalPropertyListener();
|
||||
}
|
||||
|
||||
protected class MetalPropertyListener extends BasicSliderUI.PropertyChangeHandler {
|
||||
public void propertyChange( PropertyChangeEvent e ) { // listen for slider fill
|
||||
super.propertyChange( e );
|
||||
|
||||
if (e.getPropertyName().equals(SLIDER_FILL)) {
|
||||
prepareFilledSliderField();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void prepareFilledSliderField() {
|
||||
// Use true for Ocean theme
|
||||
filledSlider = MetalLookAndFeel.usingOcean();
|
||||
|
||||
Object sliderFillProp = slider.getClientProperty(SLIDER_FILL);
|
||||
|
||||
if (sliderFillProp != null) {
|
||||
filledSlider = ((Boolean) sliderFillProp).booleanValue();
|
||||
}
|
||||
}
|
||||
|
||||
public void paintThumb(Graphics g) {
|
||||
Rectangle knobBounds = thumbRect;
|
||||
|
||||
g.translate( knobBounds.x, knobBounds.y );
|
||||
|
||||
if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
|
||||
getHorizThumbIcon().paintIcon( slider, g, 0, 0 );
|
||||
}
|
||||
else {
|
||||
getVertThumbIcon().paintIcon( slider, g, 0, 0 );
|
||||
}
|
||||
|
||||
g.translate( -knobBounds.x, -knobBounds.y );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a rectangle enclosing the track that will be painted.
|
||||
*/
|
||||
private Rectangle getPaintTrackRect() {
|
||||
int trackLeft = 0, trackRight, trackTop = 0, trackBottom;
|
||||
if (slider.getOrientation() == JSlider.HORIZONTAL) {
|
||||
trackBottom = (trackRect.height - 1) - getThumbOverhang();
|
||||
trackTop = trackBottom - (getTrackWidth() - 1);
|
||||
trackRight = trackRect.width - 1;
|
||||
}
|
||||
else {
|
||||
if (MetalUtils.isLeftToRight(slider)) {
|
||||
trackLeft = (trackRect.width - getThumbOverhang()) -
|
||||
getTrackWidth();
|
||||
trackRight = (trackRect.width - getThumbOverhang()) - 1;
|
||||
}
|
||||
else {
|
||||
trackLeft = getThumbOverhang();
|
||||
trackRight = getThumbOverhang() + getTrackWidth() - 1;
|
||||
}
|
||||
trackBottom = trackRect.height - 1;
|
||||
}
|
||||
return new Rectangle(trackRect.x + trackLeft, trackRect.y + trackTop,
|
||||
trackRight - trackLeft, trackBottom - trackTop);
|
||||
}
|
||||
|
||||
public void paintTrack(Graphics g) {
|
||||
if (MetalLookAndFeel.usingOcean()) {
|
||||
oceanPaintTrack(g);
|
||||
return;
|
||||
}
|
||||
Color trackColor = !slider.isEnabled() ? MetalLookAndFeel.getControlShadow() :
|
||||
slider.getForeground();
|
||||
|
||||
boolean leftToRight = MetalUtils.isLeftToRight(slider);
|
||||
|
||||
g.translate( trackRect.x, trackRect.y );
|
||||
|
||||
int trackLeft = 0;
|
||||
int trackTop = 0;
|
||||
int trackRight;
|
||||
int trackBottom;
|
||||
|
||||
// Draw the track
|
||||
if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
|
||||
trackBottom = (trackRect.height - 1) - getThumbOverhang();
|
||||
trackTop = trackBottom - (getTrackWidth() - 1);
|
||||
trackRight = trackRect.width - 1;
|
||||
}
|
||||
else {
|
||||
if (leftToRight) {
|
||||
trackLeft = (trackRect.width - getThumbOverhang()) -
|
||||
getTrackWidth();
|
||||
trackRight = (trackRect.width - getThumbOverhang()) - 1;
|
||||
}
|
||||
else {
|
||||
trackLeft = getThumbOverhang();
|
||||
trackRight = getThumbOverhang() + getTrackWidth() - 1;
|
||||
}
|
||||
trackBottom = trackRect.height - 1;
|
||||
}
|
||||
|
||||
if ( slider.isEnabled() ) {
|
||||
g.setColor( MetalLookAndFeel.getControlDarkShadow() );
|
||||
g.drawRect( trackLeft, trackTop,
|
||||
(trackRight - trackLeft) - 1, (trackBottom - trackTop) - 1 );
|
||||
|
||||
g.setColor( MetalLookAndFeel.getControlHighlight() );
|
||||
g.drawLine( trackLeft + 1, trackBottom, trackRight, trackBottom );
|
||||
g.drawLine( trackRight, trackTop + 1, trackRight, trackBottom );
|
||||
|
||||
g.setColor( MetalLookAndFeel.getControlShadow() );
|
||||
g.drawLine( trackLeft + 1, trackTop + 1, trackRight - 2, trackTop + 1 );
|
||||
g.drawLine( trackLeft + 1, trackTop + 1, trackLeft + 1, trackBottom - 2 );
|
||||
}
|
||||
else {
|
||||
g.setColor( MetalLookAndFeel.getControlShadow() );
|
||||
g.drawRect( trackLeft, trackTop,
|
||||
(trackRight - trackLeft) - 1, (trackBottom - trackTop) - 1 );
|
||||
}
|
||||
|
||||
// Draw the fill
|
||||
if ( filledSlider ) {
|
||||
int middleOfThumb;
|
||||
int fillTop;
|
||||
int fillLeft;
|
||||
int fillBottom;
|
||||
int fillRight;
|
||||
|
||||
if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
|
||||
middleOfThumb = thumbRect.x + (thumbRect.width / 2);
|
||||
middleOfThumb -= trackRect.x; // To compensate for the g.translate()
|
||||
fillTop = !slider.isEnabled() ? trackTop : trackTop + 1;
|
||||
fillBottom = !slider.isEnabled() ? trackBottom - 1 : trackBottom - 2;
|
||||
|
||||
if ( !drawInverted() ) {
|
||||
fillLeft = !slider.isEnabled() ? trackLeft : trackLeft + 1;
|
||||
fillRight = middleOfThumb;
|
||||
}
|
||||
else {
|
||||
fillLeft = middleOfThumb;
|
||||
fillRight = !slider.isEnabled() ? trackRight - 1 : trackRight - 2;
|
||||
}
|
||||
}
|
||||
else {
|
||||
middleOfThumb = thumbRect.y + (thumbRect.height / 2);
|
||||
middleOfThumb -= trackRect.y; // To compensate for the g.translate()
|
||||
fillLeft = !slider.isEnabled() ? trackLeft : trackLeft + 1;
|
||||
fillRight = !slider.isEnabled() ? trackRight - 1 : trackRight - 2;
|
||||
|
||||
if ( !drawInverted() ) {
|
||||
fillTop = middleOfThumb;
|
||||
fillBottom = !slider.isEnabled() ? trackBottom - 1 : trackBottom - 2;
|
||||
}
|
||||
else {
|
||||
fillTop = !slider.isEnabled() ? trackTop : trackTop + 1;
|
||||
fillBottom = middleOfThumb;
|
||||
}
|
||||
}
|
||||
|
||||
if ( slider.isEnabled() ) {
|
||||
g.setColor( slider.getBackground() );
|
||||
g.drawLine( fillLeft, fillTop, fillRight, fillTop );
|
||||
g.drawLine( fillLeft, fillTop, fillLeft, fillBottom );
|
||||
|
||||
g.setColor( MetalLookAndFeel.getControlShadow() );
|
||||
g.fillRect( fillLeft + 1, fillTop + 1,
|
||||
fillRight - fillLeft, fillBottom - fillTop );
|
||||
}
|
||||
else {
|
||||
g.setColor( MetalLookAndFeel.getControlShadow() );
|
||||
g.fillRect(fillLeft, fillTop, fillRight - fillLeft, fillBottom - fillTop);
|
||||
}
|
||||
}
|
||||
|
||||
g.translate( -trackRect.x, -trackRect.y );
|
||||
}
|
||||
|
||||
private void oceanPaintTrack(Graphics g) {
|
||||
boolean leftToRight = MetalUtils.isLeftToRight(slider);
|
||||
boolean drawInverted = drawInverted();
|
||||
Color sliderAltTrackColor = (Color)UIManager.get(
|
||||
"Slider.altTrackColor");
|
||||
|
||||
// Translate to the origin of the painting rectangle
|
||||
Rectangle paintRect = getPaintTrackRect();
|
||||
g.translate(paintRect.x, paintRect.y);
|
||||
|
||||
// Width and height of the painting rectangle.
|
||||
int w = paintRect.width;
|
||||
int h = paintRect.height;
|
||||
|
||||
if (slider.getOrientation() == JSlider.HORIZONTAL) {
|
||||
int middleOfThumb = thumbRect.x + thumbRect.width / 2 - paintRect.x;
|
||||
|
||||
if (slider.isEnabled()) {
|
||||
int fillMinX;
|
||||
int fillMaxX;
|
||||
|
||||
if (middleOfThumb > 0) {
|
||||
g.setColor(drawInverted ? MetalLookAndFeel.getControlDarkShadow() :
|
||||
MetalLookAndFeel.getPrimaryControlDarkShadow());
|
||||
|
||||
g.drawRect(0, 0, middleOfThumb - 1, h - 1);
|
||||
}
|
||||
|
||||
if (middleOfThumb < w) {
|
||||
g.setColor(drawInverted ? MetalLookAndFeel.getPrimaryControlDarkShadow() :
|
||||
MetalLookAndFeel.getControlDarkShadow());
|
||||
|
||||
g.drawRect(middleOfThumb, 0, w - middleOfThumb - 1, h - 1);
|
||||
}
|
||||
|
||||
if (filledSlider) {
|
||||
g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
|
||||
if (drawInverted) {
|
||||
fillMinX = middleOfThumb;
|
||||
fillMaxX = w - 2;
|
||||
g.drawLine(1, 1, middleOfThumb, 1);
|
||||
} else {
|
||||
fillMinX = 1;
|
||||
fillMaxX = middleOfThumb;
|
||||
g.drawLine(middleOfThumb, 1, w - 1, 1);
|
||||
}
|
||||
if (h == 6) {
|
||||
g.setColor(MetalLookAndFeel.getWhite());
|
||||
g.drawLine(fillMinX, 1, fillMaxX, 1);
|
||||
g.setColor(sliderAltTrackColor);
|
||||
g.drawLine(fillMinX, 2, fillMaxX, 2);
|
||||
g.setColor(MetalLookAndFeel.getControlShadow());
|
||||
g.drawLine(fillMinX, 3, fillMaxX, 3);
|
||||
g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
|
||||
g.drawLine(fillMinX, 4, fillMaxX, 4);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
g.setColor(MetalLookAndFeel.getControlShadow());
|
||||
|
||||
if (middleOfThumb > 0) {
|
||||
if (!drawInverted && filledSlider) {
|
||||
g.fillRect(0, 0, middleOfThumb - 1, h - 1);
|
||||
} else {
|
||||
g.drawRect(0, 0, middleOfThumb - 1, h - 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (middleOfThumb < w) {
|
||||
if (drawInverted && filledSlider) {
|
||||
g.fillRect(middleOfThumb, 0, w - middleOfThumb - 1, h - 1);
|
||||
} else {
|
||||
g.drawRect(middleOfThumb, 0, w - middleOfThumb - 1, h - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int middleOfThumb = thumbRect.y + (thumbRect.height / 2) - paintRect.y;
|
||||
|
||||
if (slider.isEnabled()) {
|
||||
int fillMinY;
|
||||
int fillMaxY;
|
||||
|
||||
if (middleOfThumb > 0) {
|
||||
g.setColor(drawInverted ? MetalLookAndFeel.getPrimaryControlDarkShadow() :
|
||||
MetalLookAndFeel.getControlDarkShadow());
|
||||
|
||||
g.drawRect(0, 0, w - 1, middleOfThumb - 1);
|
||||
}
|
||||
|
||||
if (middleOfThumb < h) {
|
||||
g.setColor(drawInverted ? MetalLookAndFeel.getControlDarkShadow() :
|
||||
MetalLookAndFeel.getPrimaryControlDarkShadow());
|
||||
|
||||
g.drawRect(0, middleOfThumb, w - 1, h - middleOfThumb - 1);
|
||||
}
|
||||
|
||||
if (filledSlider) {
|
||||
g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
|
||||
if (drawInverted()) {
|
||||
fillMinY = 1;
|
||||
fillMaxY = middleOfThumb;
|
||||
if (leftToRight) {
|
||||
g.drawLine(1, middleOfThumb, 1, h - 1);
|
||||
} else {
|
||||
g.drawLine(w - 2, middleOfThumb, w - 2, h - 1);
|
||||
}
|
||||
} else {
|
||||
fillMinY = middleOfThumb;
|
||||
fillMaxY = h - 2;
|
||||
if (leftToRight) {
|
||||
g.drawLine(1, 1, 1, middleOfThumb);
|
||||
} else {
|
||||
g.drawLine(w - 2, 1, w - 2, middleOfThumb);
|
||||
}
|
||||
}
|
||||
if (w == 6) {
|
||||
g.setColor(leftToRight ? MetalLookAndFeel.getWhite() : MetalLookAndFeel.getPrimaryControlShadow());
|
||||
g.drawLine(1, fillMinY, 1, fillMaxY);
|
||||
g.setColor(leftToRight ? sliderAltTrackColor : MetalLookAndFeel.getControlShadow());
|
||||
g.drawLine(2, fillMinY, 2, fillMaxY);
|
||||
g.setColor(leftToRight ? MetalLookAndFeel.getControlShadow() : sliderAltTrackColor);
|
||||
g.drawLine(3, fillMinY, 3, fillMaxY);
|
||||
g.setColor(leftToRight ? MetalLookAndFeel.getPrimaryControlShadow() : MetalLookAndFeel.getWhite());
|
||||
g.drawLine(4, fillMinY, 4, fillMaxY);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
g.setColor(MetalLookAndFeel.getControlShadow());
|
||||
|
||||
if (middleOfThumb > 0) {
|
||||
if (drawInverted && filledSlider) {
|
||||
g.fillRect(0, 0, w - 1, middleOfThumb - 1);
|
||||
} else {
|
||||
g.drawRect(0, 0, w - 1, middleOfThumb - 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (middleOfThumb < h) {
|
||||
if (!drawInverted && filledSlider) {
|
||||
g.fillRect(0, middleOfThumb, w - 1, h - middleOfThumb - 1);
|
||||
} else {
|
||||
g.drawRect(0, middleOfThumb, w - 1, h - middleOfThumb - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g.translate(-paintRect.x, -paintRect.y);
|
||||
}
|
||||
|
||||
public void paintFocus(Graphics g) {
|
||||
}
|
||||
|
||||
protected Dimension getThumbSize() {
|
||||
Dimension size = new Dimension();
|
||||
|
||||
if ( slider.getOrientation() == JSlider.VERTICAL ) {
|
||||
size.width = getVertThumbIcon().getIconWidth();
|
||||
size.height = getVertThumbIcon().getIconHeight();
|
||||
}
|
||||
else {
|
||||
size.width = getHorizThumbIcon().getIconWidth();
|
||||
size.height = getHorizThumbIcon().getIconHeight();
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the height of the tick area for horizontal sliders and the width of the
|
||||
* tick area for vertical sliders. BasicSliderUI uses the returned value to
|
||||
* determine the tick area rectangle.
|
||||
*/
|
||||
public int getTickLength() {
|
||||
return slider.getOrientation() == JSlider.HORIZONTAL ? safeLength + TICK_BUFFER + 1 :
|
||||
safeLength + TICK_BUFFER + 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shorter dimension of the track.
|
||||
*/
|
||||
protected int getTrackWidth() {
|
||||
// This strange calculation is here to keep the
|
||||
// track in proportion to the thumb.
|
||||
final double kIdealTrackWidth = 7.0;
|
||||
final double kIdealThumbHeight = 16.0;
|
||||
final double kWidthScalar = kIdealTrackWidth / kIdealThumbHeight;
|
||||
|
||||
if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
|
||||
return (int)(kWidthScalar * thumbRect.height);
|
||||
}
|
||||
else {
|
||||
return (int)(kWidthScalar * thumbRect.width);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the longer dimension of the slide bar. (The slide bar is only the
|
||||
* part that runs directly under the thumb)
|
||||
*/
|
||||
protected int getTrackLength() {
|
||||
if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
|
||||
return trackRect.width;
|
||||
}
|
||||
return trackRect.height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount that the thumb goes past the slide bar.
|
||||
*/
|
||||
protected int getThumbOverhang() {
|
||||
return (int)(getThumbSize().getHeight()-getTrackWidth())/2;
|
||||
}
|
||||
|
||||
protected void scrollDueToClickInTrack( int dir ) {
|
||||
scrollByUnit( dir );
|
||||
}
|
||||
|
||||
protected void paintMinorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) {
|
||||
g.setColor( slider.isEnabled() ? slider.getForeground() : MetalLookAndFeel.getControlShadow() );
|
||||
g.drawLine( x, TICK_BUFFER, x, TICK_BUFFER + (safeLength / 2) );
|
||||
}
|
||||
|
||||
protected void paintMajorTickForHorizSlider( Graphics g, Rectangle tickBounds, int x ) {
|
||||
g.setColor( slider.isEnabled() ? slider.getForeground() : MetalLookAndFeel.getControlShadow() );
|
||||
g.drawLine( x, TICK_BUFFER , x, TICK_BUFFER + (safeLength - 1) );
|
||||
}
|
||||
|
||||
protected void paintMinorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) {
|
||||
g.setColor( slider.isEnabled() ? slider.getForeground() : MetalLookAndFeel.getControlShadow() );
|
||||
|
||||
if (MetalUtils.isLeftToRight(slider)) {
|
||||
g.drawLine( TICK_BUFFER, y, TICK_BUFFER + (safeLength / 2), y );
|
||||
}
|
||||
else {
|
||||
g.drawLine( 0, y, safeLength/2, y );
|
||||
}
|
||||
}
|
||||
|
||||
protected void paintMajorTickForVertSlider( Graphics g, Rectangle tickBounds, int y ) {
|
||||
g.setColor( slider.isEnabled() ? slider.getForeground() : MetalLookAndFeel.getControlShadow() );
|
||||
|
||||
if (MetalUtils.isLeftToRight(slider)) {
|
||||
g.drawLine( TICK_BUFFER, y, TICK_BUFFER + safeLength, y );
|
||||
}
|
||||
else {
|
||||
g.drawLine( 0, y, safeLength, y );
|
||||
}
|
||||
}
|
||||
}
|
||||
416
jdkSrc/jdk8/javax/swing/plaf/metal/MetalSplitPaneDivider.java
Normal file
416
jdkSrc/jdk8/javax/swing/plaf/metal/MetalSplitPaneDivider.java
Normal file
@@ -0,0 +1,416 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
|
||||
|
||||
/**
|
||||
* Metal's split pane divider
|
||||
* <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™
|
||||
* has been added to the <code>java.beans</code> package.
|
||||
* Please see {@link java.beans.XMLEncoder}.
|
||||
*
|
||||
* @author Steve Wilson
|
||||
* @author Ralph kar
|
||||
*/
|
||||
class MetalSplitPaneDivider extends BasicSplitPaneDivider
|
||||
{
|
||||
private MetalBumps bumps = new MetalBumps(10, 10,
|
||||
MetalLookAndFeel.getControlHighlight(),
|
||||
MetalLookAndFeel.getControlDarkShadow(),
|
||||
MetalLookAndFeel.getControl() );
|
||||
|
||||
private MetalBumps focusBumps = new MetalBumps(10, 10,
|
||||
MetalLookAndFeel.getPrimaryControlHighlight(),
|
||||
MetalLookAndFeel.getPrimaryControlDarkShadow(),
|
||||
UIManager.getColor("SplitPane.dividerFocusColor"));
|
||||
|
||||
private int inset = 2;
|
||||
|
||||
private Color controlColor = MetalLookAndFeel.getControl();
|
||||
private Color primaryControlColor = UIManager.getColor(
|
||||
"SplitPane.dividerFocusColor");
|
||||
|
||||
public MetalSplitPaneDivider(BasicSplitPaneUI ui) {
|
||||
super(ui);
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
MetalBumps usedBumps;
|
||||
if (splitPane.hasFocus()) {
|
||||
usedBumps = focusBumps;
|
||||
g.setColor(primaryControlColor);
|
||||
}
|
||||
else {
|
||||
usedBumps = bumps;
|
||||
g.setColor(controlColor);
|
||||
}
|
||||
Rectangle clip = g.getClipBounds();
|
||||
Insets insets = getInsets();
|
||||
g.fillRect(clip.x, clip.y, clip.width, clip.height);
|
||||
Dimension size = getSize();
|
||||
size.width -= inset * 2;
|
||||
size.height -= inset * 2;
|
||||
int drawX = inset;
|
||||
int drawY = inset;
|
||||
if (insets != null) {
|
||||
size.width -= (insets.left + insets.right);
|
||||
size.height -= (insets.top + insets.bottom);
|
||||
drawX += insets.left;
|
||||
drawY += insets.top;
|
||||
}
|
||||
usedBumps.setBumpArea(size);
|
||||
usedBumps.paintIcon(this, g, drawX, drawY);
|
||||
super.paint(g);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and return an instance of JButton that can be used to
|
||||
* collapse the left component in the metal split pane.
|
||||
*/
|
||||
protected JButton createLeftOneTouchButton() {
|
||||
JButton b = new JButton() {
|
||||
// Sprite buffer for the arrow image of the left button
|
||||
int[][] buffer = {{0, 0, 0, 2, 2, 0, 0, 0, 0},
|
||||
{0, 0, 2, 1, 1, 1, 0, 0, 0},
|
||||
{0, 2, 1, 1, 1, 1, 1, 0, 0},
|
||||
{2, 1, 1, 1, 1, 1, 1, 1, 0},
|
||||
{0, 3, 3, 3, 3, 3, 3, 3, 3}};
|
||||
|
||||
public void setBorder(Border b) {
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
JSplitPane splitPane = getSplitPaneFromSuper();
|
||||
if(splitPane != null) {
|
||||
int oneTouchSize = getOneTouchSizeFromSuper();
|
||||
int orientation = getOrientationFromSuper();
|
||||
int blockSize = Math.min(getDividerSize(),
|
||||
oneTouchSize);
|
||||
|
||||
// Initialize the color array
|
||||
Color[] colors = {
|
||||
this.getBackground(),
|
||||
MetalLookAndFeel.getPrimaryControlDarkShadow(),
|
||||
MetalLookAndFeel.getPrimaryControlInfo(),
|
||||
MetalLookAndFeel.getPrimaryControlHighlight()};
|
||||
|
||||
// Fill the background first ...
|
||||
g.setColor(this.getBackground());
|
||||
if (isOpaque()) {
|
||||
g.fillRect(0, 0, this.getWidth(),
|
||||
this.getHeight());
|
||||
}
|
||||
|
||||
// ... then draw the arrow.
|
||||
if (getModel().isPressed()) {
|
||||
// Adjust color mapping for pressed button state
|
||||
colors[1] = colors[2];
|
||||
}
|
||||
if(orientation == JSplitPane.VERTICAL_SPLIT) {
|
||||
// Draw the image for a vertical split
|
||||
for (int i=1; i<=buffer[0].length; i++) {
|
||||
for (int j=1; j<blockSize; j++) {
|
||||
if (buffer[j-1][i-1] == 0) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
g.setColor(
|
||||
colors[buffer[j-1][i-1]]);
|
||||
}
|
||||
g.drawLine(i, j, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Draw the image for a horizontal split
|
||||
// by simply swaping the i and j axis.
|
||||
// Except the drawLine() call this code is
|
||||
// identical to the code block above. This was done
|
||||
// in order to remove the additional orientation
|
||||
// check for each pixel.
|
||||
for (int i=1; i<=buffer[0].length; i++) {
|
||||
for (int j=1; j<blockSize; j++) {
|
||||
if (buffer[j-1][i-1] == 0) {
|
||||
// Nothing needs
|
||||
// to be drawn
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
// Set the color from the
|
||||
// color map
|
||||
g.setColor(
|
||||
colors[buffer[j-1][i-1]]);
|
||||
}
|
||||
// Draw a pixel
|
||||
g.drawLine(j, i, j, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Don't want the button to participate in focus traversable.
|
||||
public boolean isFocusTraversable() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
b.setRequestFocusEnabled(false);
|
||||
b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||
b.setFocusPainted(false);
|
||||
b.setBorderPainted(false);
|
||||
maybeMakeButtonOpaque(b);
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* If necessary <code>c</code> is made opaque.
|
||||
*/
|
||||
private void maybeMakeButtonOpaque(JComponent c) {
|
||||
Object opaque = UIManager.get("SplitPane.oneTouchButtonsOpaque");
|
||||
if (opaque != null) {
|
||||
c.setOpaque(((Boolean)opaque).booleanValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and return an instance of JButton that can be used to
|
||||
* collapse the right component in the metal split pane.
|
||||
*/
|
||||
protected JButton createRightOneTouchButton() {
|
||||
JButton b = new JButton() {
|
||||
// Sprite buffer for the arrow image of the right button
|
||||
int[][] buffer = {{2, 2, 2, 2, 2, 2, 2, 2},
|
||||
{0, 1, 1, 1, 1, 1, 1, 3},
|
||||
{0, 0, 1, 1, 1, 1, 3, 0},
|
||||
{0, 0, 0, 1, 1, 3, 0, 0},
|
||||
{0, 0, 0, 0, 3, 0, 0, 0}};
|
||||
|
||||
public void setBorder(Border border) {
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
JSplitPane splitPane = getSplitPaneFromSuper();
|
||||
if(splitPane != null) {
|
||||
int oneTouchSize = getOneTouchSizeFromSuper();
|
||||
int orientation = getOrientationFromSuper();
|
||||
int blockSize = Math.min(getDividerSize(),
|
||||
oneTouchSize);
|
||||
|
||||
// Initialize the color array
|
||||
Color[] colors = {
|
||||
this.getBackground(),
|
||||
MetalLookAndFeel.getPrimaryControlDarkShadow(),
|
||||
MetalLookAndFeel.getPrimaryControlInfo(),
|
||||
MetalLookAndFeel.getPrimaryControlHighlight()};
|
||||
|
||||
// Fill the background first ...
|
||||
g.setColor(this.getBackground());
|
||||
if (isOpaque()) {
|
||||
g.fillRect(0, 0, this.getWidth(),
|
||||
this.getHeight());
|
||||
}
|
||||
|
||||
// ... then draw the arrow.
|
||||
if (getModel().isPressed()) {
|
||||
// Adjust color mapping for pressed button state
|
||||
colors[1] = colors[2];
|
||||
}
|
||||
if(orientation == JSplitPane.VERTICAL_SPLIT) {
|
||||
// Draw the image for a vertical split
|
||||
for (int i=1; i<=buffer[0].length; i++) {
|
||||
for (int j=1; j<blockSize; j++) {
|
||||
if (buffer[j-1][i-1] == 0) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
g.setColor(
|
||||
colors[buffer[j-1][i-1]]);
|
||||
}
|
||||
g.drawLine(i, j, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Draw the image for a horizontal split
|
||||
// by simply swaping the i and j axis.
|
||||
// Except the drawLine() call this code is
|
||||
// identical to the code block above. This was done
|
||||
// in order to remove the additional orientation
|
||||
// check for each pixel.
|
||||
for (int i=1; i<=buffer[0].length; i++) {
|
||||
for (int j=1; j<blockSize; j++) {
|
||||
if (buffer[j-1][i-1] == 0) {
|
||||
// Nothing needs
|
||||
// to be drawn
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
// Set the color from the
|
||||
// color map
|
||||
g.setColor(
|
||||
colors[buffer[j-1][i-1]]);
|
||||
}
|
||||
// Draw a pixel
|
||||
g.drawLine(j, i, j, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Don't want the button to participate in focus traversable.
|
||||
public boolean isFocusTraversable() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||
b.setFocusPainted(false);
|
||||
b.setBorderPainted(false);
|
||||
b.setRequestFocusEnabled(false);
|
||||
maybeMakeButtonOpaque(b);
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to layout a MetalSplitPaneDivider. Layout for the divider
|
||||
* involves appropriately moving the left/right buttons around.
|
||||
* <p>
|
||||
* This class should be treated as a "protected" inner class.
|
||||
* Instantiate it only within subclasses of MetalSplitPaneDivider.
|
||||
*/
|
||||
public class MetalDividerLayout implements LayoutManager {
|
||||
|
||||
// NOTE NOTE NOTE NOTE NOTE
|
||||
// This class is no longer used, the functionality has
|
||||
// been rolled into BasicSplitPaneDivider.DividerLayout as a
|
||||
// defaults property
|
||||
|
||||
public void layoutContainer(Container c) {
|
||||
JButton leftButton = getLeftButtonFromSuper();
|
||||
JButton rightButton = getRightButtonFromSuper();
|
||||
JSplitPane splitPane = getSplitPaneFromSuper();
|
||||
int orientation = getOrientationFromSuper();
|
||||
int oneTouchSize = getOneTouchSizeFromSuper();
|
||||
int oneTouchOffset = getOneTouchOffsetFromSuper();
|
||||
Insets insets = getInsets();
|
||||
|
||||
// This layout differs from the one used in BasicSplitPaneDivider.
|
||||
// It does not center justify the oneTouchExpadable buttons.
|
||||
// This was necessary in order to meet the spec of the Metal
|
||||
// splitpane divider.
|
||||
if (leftButton != null && rightButton != null &&
|
||||
c == MetalSplitPaneDivider.this) {
|
||||
if (splitPane.isOneTouchExpandable()) {
|
||||
if (orientation == JSplitPane.VERTICAL_SPLIT) {
|
||||
int extraY = (insets != null) ? insets.top : 0;
|
||||
int blockSize = getDividerSize();
|
||||
|
||||
if (insets != null) {
|
||||
blockSize -= (insets.top + insets.bottom);
|
||||
}
|
||||
blockSize = Math.min(blockSize, oneTouchSize);
|
||||
leftButton.setBounds(oneTouchOffset, extraY,
|
||||
blockSize * 2, blockSize);
|
||||
rightButton.setBounds(oneTouchOffset +
|
||||
oneTouchSize * 2, extraY,
|
||||
blockSize * 2, blockSize);
|
||||
}
|
||||
else {
|
||||
int blockSize = getDividerSize();
|
||||
int extraX = (insets != null) ? insets.left : 0;
|
||||
|
||||
if (insets != null) {
|
||||
blockSize -= (insets.left + insets.right);
|
||||
}
|
||||
blockSize = Math.min(blockSize, oneTouchSize);
|
||||
leftButton.setBounds(extraX, oneTouchOffset,
|
||||
blockSize, blockSize * 2);
|
||||
rightButton.setBounds(extraX, oneTouchOffset +
|
||||
oneTouchSize * 2, blockSize,
|
||||
blockSize * 2);
|
||||
}
|
||||
}
|
||||
else {
|
||||
leftButton.setBounds(-5, -5, 1, 1);
|
||||
rightButton.setBounds(-5, -5, 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension minimumLayoutSize(Container c) {
|
||||
return new Dimension(0,0);
|
||||
}
|
||||
|
||||
public Dimension preferredLayoutSize(Container c) {
|
||||
return new Dimension(0, 0);
|
||||
}
|
||||
|
||||
public void removeLayoutComponent(Component c) {}
|
||||
|
||||
public void addLayoutComponent(String string, Component c) {}
|
||||
}
|
||||
|
||||
/*
|
||||
* The following methods only exist in order to be able to access protected
|
||||
* members in the superclass, because these are otherwise not available
|
||||
* in any inner class.
|
||||
*/
|
||||
|
||||
int getOneTouchSizeFromSuper() {
|
||||
return super.ONE_TOUCH_SIZE;
|
||||
}
|
||||
|
||||
int getOneTouchOffsetFromSuper() {
|
||||
return super.ONE_TOUCH_OFFSET;
|
||||
}
|
||||
|
||||
int getOrientationFromSuper() {
|
||||
return super.orientation;
|
||||
}
|
||||
|
||||
JSplitPane getSplitPaneFromSuper() {
|
||||
return super.splitPane;
|
||||
}
|
||||
|
||||
JButton getLeftButtonFromSuper() {
|
||||
return super.leftButton;
|
||||
}
|
||||
|
||||
JButton getRightButtonFromSuper() {
|
||||
return super.rightButton;
|
||||
}
|
||||
}
|
||||
63
jdkSrc/jdk8/javax/swing/plaf/metal/MetalSplitPaneUI.java
Normal file
63
jdkSrc/jdk8/javax/swing/plaf/metal/MetalSplitPaneUI.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
|
||||
/**
|
||||
* Metal split pane.
|
||||
* <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™
|
||||
* has been added to the <code>java.beans</code> package.
|
||||
* Please see {@link java.beans.XMLEncoder}.
|
||||
*
|
||||
* @author Steve Wilson
|
||||
*/
|
||||
public class MetalSplitPaneUI extends BasicSplitPaneUI
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new MetalSplitPaneUI instance
|
||||
*/
|
||||
public static ComponentUI createUI(JComponent x) {
|
||||
return new MetalSplitPaneUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the default divider.
|
||||
*/
|
||||
public BasicSplitPaneDivider createDefaultDivider() {
|
||||
return new MetalSplitPaneDivider(this);
|
||||
}
|
||||
}
|
||||
1229
jdkSrc/jdk8/javax/swing/plaf/metal/MetalTabbedPaneUI.java
Normal file
1229
jdkSrc/jdk8/javax/swing/plaf/metal/MetalTabbedPaneUI.java
Normal file
File diff suppressed because it is too large
Load Diff
68
jdkSrc/jdk8/javax/swing/plaf/metal/MetalTextFieldUI.java
Normal file
68
jdkSrc/jdk8/javax/swing/plaf/metal/MetalTextFieldUI.java
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import java.awt.*;
|
||||
import java.beans.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import javax.swing.text.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
|
||||
/**
|
||||
* Basis of a look and feel for a JTextField.
|
||||
* <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™
|
||||
* has been added to the <code>java.beans</code> package.
|
||||
* Please see {@link java.beans.XMLEncoder}.
|
||||
*
|
||||
* @author Steve Wilson
|
||||
*/
|
||||
public class MetalTextFieldUI extends BasicTextFieldUI {
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new MetalTextFieldUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a bound property is changed
|
||||
* on the associated JTextComponent. This is a hook
|
||||
* which UI implementations may change to reflect how the
|
||||
* UI displays bound properties of JTextComponent subclasses.
|
||||
*
|
||||
* @param evt the property change event
|
||||
*/
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
super.propertyChange(evt);
|
||||
}
|
||||
|
||||
}
|
||||
485
jdkSrc/jdk8/javax/swing/plaf/metal/MetalTheme.java
Normal file
485
jdkSrc/jdk8/javax/swing/plaf/metal/MetalTheme.java
Normal file
@@ -0,0 +1,485 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* {@code MetalTheme} provides the color palette and fonts used by
|
||||
* the Java Look and Feel.
|
||||
* <p>
|
||||
* {@code MetalTheme} is abstract, see {@code DefaultMetalTheme} and
|
||||
* {@code OceanTheme} for concrete implementations.
|
||||
* <p>
|
||||
* {@code MetalLookAndFeel} maintains the current theme that the
|
||||
* the {@code ComponentUI} implementations for metal use. Refer to
|
||||
* {@link MetalLookAndFeel#setCurrentTheme
|
||||
* MetalLookAndFeel.setCurrentTheme(MetalTheme)} for details on changing
|
||||
* the current theme.
|
||||
* <p>
|
||||
* {@code MetalTheme} provides a number of public methods for getting
|
||||
* colors. These methods are implemented in terms of a
|
||||
* handful of protected abstract methods. A subclass need only override
|
||||
* the protected abstract methods ({@code getPrimary1},
|
||||
* {@code getPrimary2}, {@code getPrimary3}, {@code getSecondary1},
|
||||
* {@code getSecondary2}, and {@code getSecondary3}); although a subclass
|
||||
* may override the other public methods for more control over the set of
|
||||
* colors that are used.
|
||||
* <p>
|
||||
* Concrete implementations of {@code MetalTheme} must return {@code non-null}
|
||||
* values from all methods. While the behavior of returning {@code null} is
|
||||
* not specified, returning {@code null} will result in incorrect behavior.
|
||||
* <p>
|
||||
* It is strongly recommended that subclasses return completely opaque colors.
|
||||
* To do otherwise may result in rendering problems, such as visual garbage.
|
||||
*
|
||||
* @see DefaultMetalTheme
|
||||
* @see OceanTheme
|
||||
* @see MetalLookAndFeel#setCurrentTheme
|
||||
*
|
||||
* @author Steve Wilson
|
||||
*/
|
||||
public abstract class MetalTheme {
|
||||
|
||||
// Contants identifying the various Fonts that are Theme can support
|
||||
static final int CONTROL_TEXT_FONT = 0;
|
||||
static final int SYSTEM_TEXT_FONT = 1;
|
||||
static final int USER_TEXT_FONT = 2;
|
||||
static final int MENU_TEXT_FONT = 3;
|
||||
static final int WINDOW_TITLE_FONT = 4;
|
||||
static final int SUB_TEXT_FONT = 5;
|
||||
|
||||
static ColorUIResource white = new ColorUIResource( 255, 255, 255 );
|
||||
private static ColorUIResource black = new ColorUIResource( 0, 0, 0 );
|
||||
|
||||
/**
|
||||
* Returns the name of this theme.
|
||||
*
|
||||
* @return the name of this theme
|
||||
*/
|
||||
public abstract String getName();
|
||||
|
||||
/**
|
||||
* Returns the primary 1 color.
|
||||
*
|
||||
* @return the primary 1 color
|
||||
*/
|
||||
protected abstract ColorUIResource getPrimary1(); // these are blue in Metal Default Theme
|
||||
|
||||
/**
|
||||
* Returns the primary 2 color.
|
||||
*
|
||||
* @return the primary 2 color
|
||||
*/
|
||||
protected abstract ColorUIResource getPrimary2();
|
||||
|
||||
/**
|
||||
* Returns the primary 3 color.
|
||||
*
|
||||
* @return the primary 3 color
|
||||
*/
|
||||
protected abstract ColorUIResource getPrimary3();
|
||||
|
||||
/**
|
||||
* Returns the secondary 1 color.
|
||||
*
|
||||
* @return the secondary 1 color
|
||||
*/
|
||||
protected abstract ColorUIResource getSecondary1(); // these are gray in Metal Default Theme
|
||||
|
||||
/**
|
||||
* Returns the secondary 2 color.
|
||||
*
|
||||
* @return the secondary 2 color
|
||||
*/
|
||||
protected abstract ColorUIResource getSecondary2();
|
||||
|
||||
/**
|
||||
* Returns the secondary 3 color.
|
||||
*
|
||||
* @return the secondary 3 color
|
||||
*/
|
||||
protected abstract ColorUIResource getSecondary3();
|
||||
|
||||
/**
|
||||
* Returns the control text font.
|
||||
*
|
||||
* @return the control text font
|
||||
*/
|
||||
public abstract FontUIResource getControlTextFont();
|
||||
|
||||
/**
|
||||
* Returns the system text font.
|
||||
*
|
||||
* @return the system text font
|
||||
*/
|
||||
public abstract FontUIResource getSystemTextFont();
|
||||
|
||||
/**
|
||||
* Returns the user text font.
|
||||
*
|
||||
* @return the user text font
|
||||
*/
|
||||
public abstract FontUIResource getUserTextFont();
|
||||
|
||||
/**
|
||||
* Returns the menu text font.
|
||||
*
|
||||
* @return the menu text font
|
||||
*/
|
||||
public abstract FontUIResource getMenuTextFont();
|
||||
|
||||
/**
|
||||
* Returns the window title font.
|
||||
*
|
||||
* @return the window title font
|
||||
*/
|
||||
public abstract FontUIResource getWindowTitleFont();
|
||||
|
||||
/**
|
||||
* Returns the sub-text font.
|
||||
*
|
||||
* @return the sub-text font
|
||||
*/
|
||||
public abstract FontUIResource getSubTextFont();
|
||||
|
||||
/**
|
||||
* Returns the white color. This returns opaque white
|
||||
* ({@code 0xFFFFFFFF}).
|
||||
*
|
||||
* @return the white color
|
||||
*/
|
||||
protected ColorUIResource getWhite() { return white; }
|
||||
|
||||
/**
|
||||
* Returns the black color. This returns opaque black
|
||||
* ({@code 0xFF000000}).
|
||||
*
|
||||
* @return the black color
|
||||
*/
|
||||
protected ColorUIResource getBlack() { return black; }
|
||||
|
||||
/**
|
||||
* Returns the focus color. This returns the value of
|
||||
* {@code getPrimary2()}.
|
||||
*
|
||||
* @return the focus color
|
||||
*/
|
||||
public ColorUIResource getFocusColor() { return getPrimary2(); }
|
||||
|
||||
/**
|
||||
* Returns the desktop color. This returns the value of
|
||||
* {@code getPrimary2()}.
|
||||
*
|
||||
* @return the desktop color
|
||||
*/
|
||||
public ColorUIResource getDesktopColor() { return getPrimary2(); }
|
||||
|
||||
/**
|
||||
* Returns the control color. This returns the value of
|
||||
* {@code getSecondary3()}.
|
||||
*
|
||||
* @return the control color
|
||||
*/
|
||||
public ColorUIResource getControl() { return getSecondary3(); }
|
||||
|
||||
/**
|
||||
* Returns the control shadow color. This returns
|
||||
* the value of {@code getSecondary2()}.
|
||||
*
|
||||
* @return the control shadow color
|
||||
*/
|
||||
public ColorUIResource getControlShadow() { return getSecondary2(); }
|
||||
|
||||
/**
|
||||
* Returns the control dark shadow color. This returns
|
||||
* the value of {@code getSecondary1()}.
|
||||
*
|
||||
* @return the control dark shadow color
|
||||
*/
|
||||
public ColorUIResource getControlDarkShadow() { return getSecondary1(); }
|
||||
|
||||
/**
|
||||
* Returns the control info color. This returns
|
||||
* the value of {@code getBlack()}.
|
||||
*
|
||||
* @return the control info color
|
||||
*/
|
||||
public ColorUIResource getControlInfo() { return getBlack(); }
|
||||
|
||||
/**
|
||||
* Returns the control highlight color. This returns
|
||||
* the value of {@code getWhite()}.
|
||||
*
|
||||
* @return the control highlight color
|
||||
*/
|
||||
public ColorUIResource getControlHighlight() { return getWhite(); }
|
||||
|
||||
/**
|
||||
* Returns the control disabled color. This returns
|
||||
* the value of {@code getSecondary2()}.
|
||||
*
|
||||
* @return the control disabled color
|
||||
*/
|
||||
public ColorUIResource getControlDisabled() { return getSecondary2(); }
|
||||
|
||||
/**
|
||||
* Returns the primary control color. This returns
|
||||
* the value of {@code getPrimary3()}.
|
||||
*
|
||||
* @return the primary control color
|
||||
*/
|
||||
public ColorUIResource getPrimaryControl() { return getPrimary3(); }
|
||||
|
||||
/**
|
||||
* Returns the primary control shadow color. This returns
|
||||
* the value of {@code getPrimary2()}.
|
||||
*
|
||||
* @return the primary control shadow color
|
||||
*/
|
||||
public ColorUIResource getPrimaryControlShadow() { return getPrimary2(); }
|
||||
/**
|
||||
* Returns the primary control dark shadow color. This
|
||||
* returns the value of {@code getPrimary1()}.
|
||||
*
|
||||
* @return the primary control dark shadow color
|
||||
*/
|
||||
public ColorUIResource getPrimaryControlDarkShadow() { return getPrimary1(); }
|
||||
|
||||
/**
|
||||
* Returns the primary control info color. This
|
||||
* returns the value of {@code getBlack()}.
|
||||
*
|
||||
* @return the primary control info color
|
||||
*/
|
||||
public ColorUIResource getPrimaryControlInfo() { return getBlack(); }
|
||||
|
||||
/**
|
||||
* Returns the primary control highlight color. This
|
||||
* returns the value of {@code getWhite()}.
|
||||
*
|
||||
* @return the primary control highlight color
|
||||
*/
|
||||
public ColorUIResource getPrimaryControlHighlight() { return getWhite(); }
|
||||
|
||||
/**
|
||||
* Returns the system text color. This returns the value of
|
||||
* {@code getBlack()}.
|
||||
*
|
||||
* @return the system text color
|
||||
*/
|
||||
public ColorUIResource getSystemTextColor() { return getBlack(); }
|
||||
|
||||
/**
|
||||
* Returns the control text color. This returns the value of
|
||||
* {@code getControlInfo()}.
|
||||
*
|
||||
* @return the control text color
|
||||
*/
|
||||
public ColorUIResource getControlTextColor() { return getControlInfo(); }
|
||||
|
||||
/**
|
||||
* Returns the inactive control text color. This returns the value of
|
||||
* {@code getControlDisabled()}.
|
||||
*
|
||||
* @return the inactive control text color
|
||||
*/
|
||||
public ColorUIResource getInactiveControlTextColor() { return getControlDisabled(); }
|
||||
|
||||
/**
|
||||
* Returns the inactive system text color. This returns the value of
|
||||
* {@code getSecondary2()}.
|
||||
*
|
||||
* @return the inactive system text color
|
||||
*/
|
||||
public ColorUIResource getInactiveSystemTextColor() { return getSecondary2(); }
|
||||
|
||||
/**
|
||||
* Returns the user text color. This returns the value of
|
||||
* {@code getBlack()}.
|
||||
*
|
||||
* @return the user text color
|
||||
*/
|
||||
public ColorUIResource getUserTextColor() { return getBlack(); }
|
||||
|
||||
/**
|
||||
* Returns the text highlight color. This returns the value of
|
||||
* {@code getPrimary3()}.
|
||||
*
|
||||
* @return the text highlight color
|
||||
*/
|
||||
public ColorUIResource getTextHighlightColor() { return getPrimary3(); }
|
||||
|
||||
/**
|
||||
* Returns the highlighted text color. This returns the value of
|
||||
* {@code getControlTextColor()}.
|
||||
*
|
||||
* @return the highlighted text color
|
||||
*/
|
||||
public ColorUIResource getHighlightedTextColor() { return getControlTextColor(); }
|
||||
|
||||
/**
|
||||
* Returns the window background color. This returns the value of
|
||||
* {@code getWhite()}.
|
||||
*
|
||||
* @return the window background color
|
||||
*/
|
||||
public ColorUIResource getWindowBackground() { return getWhite(); }
|
||||
|
||||
/**
|
||||
* Returns the window title background color. This returns the value of
|
||||
* {@code getPrimary3()}.
|
||||
*
|
||||
* @return the window title background color
|
||||
*/
|
||||
public ColorUIResource getWindowTitleBackground() { return getPrimary3(); }
|
||||
|
||||
/**
|
||||
* Returns the window title foreground color. This returns the value of
|
||||
* {@code getBlack()}.
|
||||
*
|
||||
* @return the window title foreground color
|
||||
*/
|
||||
public ColorUIResource getWindowTitleForeground() { return getBlack(); }
|
||||
|
||||
/**
|
||||
* Returns the window title inactive background color. This
|
||||
* returns the value of {@code getSecondary3()}.
|
||||
*
|
||||
* @return the window title inactive background color
|
||||
*/
|
||||
public ColorUIResource getWindowTitleInactiveBackground() { return getSecondary3(); }
|
||||
|
||||
/**
|
||||
* Returns the window title inactive foreground color. This
|
||||
* returns the value of {@code getBlack()}.
|
||||
*
|
||||
* @return the window title inactive foreground color
|
||||
*/
|
||||
public ColorUIResource getWindowTitleInactiveForeground() { return getBlack(); }
|
||||
|
||||
/**
|
||||
* Returns the menu background color. This
|
||||
* returns the value of {@code getSecondary3()}.
|
||||
*
|
||||
* @return the menu background color
|
||||
*/
|
||||
public ColorUIResource getMenuBackground() { return getSecondary3(); }
|
||||
|
||||
/**
|
||||
* Returns the menu foreground color. This
|
||||
* returns the value of {@code getBlack()}.
|
||||
*
|
||||
* @return the menu foreground color
|
||||
*/
|
||||
public ColorUIResource getMenuForeground() { return getBlack(); }
|
||||
|
||||
/**
|
||||
* Returns the menu selected background color. This
|
||||
* returns the value of {@code getPrimary2()}.
|
||||
*
|
||||
* @return the menu selected background color
|
||||
*/
|
||||
public ColorUIResource getMenuSelectedBackground() { return getPrimary2(); }
|
||||
|
||||
/**
|
||||
* Returns the menu selected foreground color. This
|
||||
* returns the value of {@code getBlack()}.
|
||||
*
|
||||
* @return the menu selected foreground color
|
||||
*/
|
||||
public ColorUIResource getMenuSelectedForeground() { return getBlack(); }
|
||||
|
||||
/**
|
||||
* Returns the menu disabled foreground color. This
|
||||
* returns the value of {@code getSecondary2()}.
|
||||
*
|
||||
* @return the menu disabled foreground color
|
||||
*/
|
||||
public ColorUIResource getMenuDisabledForeground() { return getSecondary2(); }
|
||||
|
||||
/**
|
||||
* Returns the separator background color. This
|
||||
* returns the value of {@code getWhite()}.
|
||||
*
|
||||
* @return the separator background color
|
||||
*/
|
||||
public ColorUIResource getSeparatorBackground() { return getWhite(); }
|
||||
|
||||
/**
|
||||
* Returns the separator foreground color. This
|
||||
* returns the value of {@code getPrimary1()}.
|
||||
*
|
||||
* @return the separator foreground color
|
||||
*/
|
||||
public ColorUIResource getSeparatorForeground() { return getPrimary1(); }
|
||||
|
||||
/**
|
||||
* Returns the accelerator foreground color. This
|
||||
* returns the value of {@code getPrimary1()}.
|
||||
*
|
||||
* @return the accelerator foreground color
|
||||
*/
|
||||
public ColorUIResource getAcceleratorForeground() { return getPrimary1(); }
|
||||
|
||||
/**
|
||||
* Returns the accelerator selected foreground color. This
|
||||
* returns the value of {@code getBlack()}.
|
||||
*
|
||||
* @return the accelerator selected foreground color
|
||||
*/
|
||||
public ColorUIResource getAcceleratorSelectedForeground() { return getBlack(); }
|
||||
|
||||
/**
|
||||
* Adds values specific to this theme to the defaults table. This method
|
||||
* is invoked when the look and feel defaults are obtained from
|
||||
* {@code MetalLookAndFeel}.
|
||||
* <p>
|
||||
* This implementation does nothing; it is provided for subclasses
|
||||
* that wish to customize the defaults table.
|
||||
*
|
||||
* @param table the {@code UIDefaults} to add the values to
|
||||
*
|
||||
* @see MetalLookAndFeel#getDefaults
|
||||
*/
|
||||
public void addCustomEntriesToTable(UIDefaults table) {}
|
||||
|
||||
/**
|
||||
* This is invoked when a MetalLookAndFeel is installed and about to
|
||||
* start using this theme. When we can add API this should be nuked
|
||||
* in favor of DefaultMetalTheme overriding addCustomEntriesToTable.
|
||||
*/
|
||||
void install() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this is a theme provided by the core platform.
|
||||
*/
|
||||
boolean isSystemTheme() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
1040
jdkSrc/jdk8/javax/swing/plaf/metal/MetalTitlePane.java
Normal file
1040
jdkSrc/jdk8/javax/swing/plaf/metal/MetalTitlePane.java
Normal file
File diff suppressed because it is too large
Load Diff
225
jdkSrc/jdk8/javax/swing/plaf/metal/MetalToggleButtonUI.java
Normal file
225
jdkSrc/jdk8/javax/swing/plaf/metal/MetalToggleButtonUI.java
Normal file
@@ -0,0 +1,225 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import sun.swing.SwingUtilities2;
|
||||
import sun.awt.AppContext;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.lang.ref.*;
|
||||
import java.util.*;
|
||||
import javax.swing.plaf.basic.BasicToggleButtonUI;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* MetalToggleButton implementation
|
||||
* <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™
|
||||
* has been added to the <code>java.beans</code> package.
|
||||
* Please see {@link java.beans.XMLEncoder}.
|
||||
*
|
||||
* @author Tom Santos
|
||||
*/
|
||||
public class MetalToggleButtonUI extends BasicToggleButtonUI {
|
||||
|
||||
private static final Object METAL_TOGGLE_BUTTON_UI_KEY = new Object();
|
||||
|
||||
protected Color focusColor;
|
||||
protected Color selectColor;
|
||||
protected Color disabledTextColor;
|
||||
|
||||
private boolean defaults_initialized = false;
|
||||
|
||||
// ********************************
|
||||
// Create PLAF
|
||||
// ********************************
|
||||
public static ComponentUI createUI(JComponent b) {
|
||||
AppContext appContext = AppContext.getAppContext();
|
||||
MetalToggleButtonUI metalToggleButtonUI =
|
||||
(MetalToggleButtonUI) appContext.get(METAL_TOGGLE_BUTTON_UI_KEY);
|
||||
if (metalToggleButtonUI == null) {
|
||||
metalToggleButtonUI = new MetalToggleButtonUI();
|
||||
appContext.put(METAL_TOGGLE_BUTTON_UI_KEY, metalToggleButtonUI);
|
||||
}
|
||||
return metalToggleButtonUI;
|
||||
}
|
||||
|
||||
// ********************************
|
||||
// Install Defaults
|
||||
// ********************************
|
||||
public void installDefaults(AbstractButton b) {
|
||||
super.installDefaults(b);
|
||||
if(!defaults_initialized) {
|
||||
focusColor = UIManager.getColor(getPropertyPrefix() + "focus");
|
||||
selectColor = UIManager.getColor(getPropertyPrefix() + "select");
|
||||
disabledTextColor = UIManager.getColor(getPropertyPrefix() + "disabledText");
|
||||
defaults_initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected void uninstallDefaults(AbstractButton b) {
|
||||
super.uninstallDefaults(b);
|
||||
defaults_initialized = false;
|
||||
}
|
||||
|
||||
// ********************************
|
||||
// Default Accessors
|
||||
// ********************************
|
||||
protected Color getSelectColor() {
|
||||
return selectColor;
|
||||
}
|
||||
|
||||
protected Color getDisabledTextColor() {
|
||||
return disabledTextColor;
|
||||
}
|
||||
|
||||
protected Color getFocusColor() {
|
||||
return focusColor;
|
||||
}
|
||||
|
||||
|
||||
// ********************************
|
||||
// Paint Methods
|
||||
// ********************************
|
||||
/**
|
||||
* If necessary paints the background of the component, then invokes
|
||||
* <code>paint</code>.
|
||||
*
|
||||
* @param g Graphics to paint to
|
||||
* @param c JComponent painting on
|
||||
* @throws NullPointerException if <code>g</code> or <code>c</code> is
|
||||
* null
|
||||
* @see javax.swing.plaf.ComponentUI#update
|
||||
* @see javax.swing.plaf.ComponentUI#paint
|
||||
* @since 1.5
|
||||
*/
|
||||
public void update(Graphics g, JComponent c) {
|
||||
AbstractButton button = (AbstractButton)c;
|
||||
if ((c.getBackground() instanceof UIResource) &&
|
||||
button.isContentAreaFilled() && c.isEnabled()) {
|
||||
ButtonModel model = button.getModel();
|
||||
if (!MetalUtils.isToolBarButton(c)) {
|
||||
if (!model.isArmed() && !model.isPressed() &&
|
||||
MetalUtils.drawGradient(
|
||||
c, g, "ToggleButton.gradient", 0, 0, c.getWidth(),
|
||||
c.getHeight(), true)) {
|
||||
paint(g, c);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if ((model.isRollover() || model.isSelected()) &&
|
||||
MetalUtils.drawGradient(c, g, "ToggleButton.gradient",
|
||||
0, 0, c.getWidth(), c.getHeight(), true)) {
|
||||
paint(g, c);
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.update(g, c);
|
||||
}
|
||||
|
||||
protected void paintButtonPressed(Graphics g, AbstractButton b) {
|
||||
if ( b.isContentAreaFilled() ) {
|
||||
g.setColor(getSelectColor());
|
||||
g.fillRect(0, 0, b.getWidth(), b.getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
|
||||
AbstractButton b = (AbstractButton) c;
|
||||
ButtonModel model = b.getModel();
|
||||
FontMetrics fm = SwingUtilities2.getFontMetrics(b, g);
|
||||
int mnemIndex = b.getDisplayedMnemonicIndex();
|
||||
|
||||
/* Draw the Text */
|
||||
if(model.isEnabled()) {
|
||||
/*** paint the text normally */
|
||||
g.setColor(b.getForeground());
|
||||
}
|
||||
else {
|
||||
/*** paint the text disabled ***/
|
||||
if (model.isSelected()) {
|
||||
g.setColor(c.getBackground());
|
||||
} else {
|
||||
g.setColor(getDisabledTextColor());
|
||||
}
|
||||
}
|
||||
SwingUtilities2.drawStringUnderlineCharAt(c, g, text, mnemIndex,
|
||||
textRect.x, textRect.y + fm.getAscent());
|
||||
}
|
||||
|
||||
protected void paintFocus(Graphics g, AbstractButton b,
|
||||
Rectangle viewRect, Rectangle textRect, Rectangle iconRect){
|
||||
|
||||
Rectangle focusRect = new Rectangle();
|
||||
String text = b.getText();
|
||||
boolean isIcon = b.getIcon() != null;
|
||||
|
||||
// If there is text
|
||||
if ( text != null && !text.equals( "" ) ) {
|
||||
if ( !isIcon ) {
|
||||
focusRect.setBounds( textRect );
|
||||
}
|
||||
else {
|
||||
focusRect.setBounds( iconRect.union( textRect ) );
|
||||
}
|
||||
}
|
||||
// If there is an icon and no text
|
||||
else if ( isIcon ) {
|
||||
focusRect.setBounds( iconRect );
|
||||
}
|
||||
|
||||
g.setColor(getFocusColor());
|
||||
g.drawRect((focusRect.x-1), (focusRect.y-1),
|
||||
focusRect.width+1, focusRect.height+1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints the appropriate icon of the button <code>b</code> in the
|
||||
* space <code>iconRect</code>.
|
||||
*
|
||||
* @param g Graphics to paint to
|
||||
* @param b Button to render for
|
||||
* @param iconRect space to render in
|
||||
* @throws NullPointerException if any of the arguments are null.
|
||||
* @since 1.5
|
||||
*/
|
||||
protected void paintIcon(Graphics g, AbstractButton b, Rectangle iconRect) {
|
||||
super.paintIcon(g, b, iconRect);
|
||||
}
|
||||
}
|
||||
396
jdkSrc/jdk8/javax/swing/plaf/metal/MetalToolBarUI.java
Normal file
396
jdkSrc/jdk8/javax/swing/plaf/metal/MetalToolBarUI.java
Normal file
@@ -0,0 +1,396 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.*;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.*;
|
||||
|
||||
import java.beans.PropertyChangeListener;
|
||||
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
|
||||
/**
|
||||
* A Metal Look and Feel implementation of ToolBarUI. This implementation
|
||||
* is a "combined" view/controller.
|
||||
* <p>
|
||||
*
|
||||
* @author Jeff Shapiro
|
||||
*/
|
||||
public class MetalToolBarUI extends BasicToolBarUI
|
||||
{
|
||||
/**
|
||||
* An array of WeakReferences that point to JComponents. This will contain
|
||||
* instances of JToolBars and JMenuBars and is used to find
|
||||
* JToolBars/JMenuBars that border each other.
|
||||
*/
|
||||
private static List<WeakReference<JComponent>> components = new ArrayList<WeakReference<JComponent>>();
|
||||
|
||||
/**
|
||||
* This protected field is implementation specific. Do not access directly
|
||||
* or override. Use the create method instead.
|
||||
*
|
||||
* @see #createContainerListener
|
||||
*/
|
||||
protected ContainerListener contListener;
|
||||
|
||||
/**
|
||||
* This protected field is implementation specific. Do not access directly
|
||||
* or override. Use the create method instead.
|
||||
*
|
||||
* @see #createRolloverListener
|
||||
*/
|
||||
protected PropertyChangeListener rolloverListener;
|
||||
|
||||
private static Border nonRolloverBorder;
|
||||
|
||||
/**
|
||||
* Last menubar the toolbar touched. This is only useful for ocean.
|
||||
*/
|
||||
private JMenuBar lastMenuBar;
|
||||
|
||||
/**
|
||||
* Registers the specified component.
|
||||
*/
|
||||
synchronized static void register(JComponent c) {
|
||||
if (c == null) {
|
||||
// Exception is thrown as convenience for callers that are
|
||||
// typed to throw an NPE.
|
||||
throw new NullPointerException("JComponent must be non-null");
|
||||
}
|
||||
components.add(new WeakReference<JComponent>(c));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters the specified component.
|
||||
*/
|
||||
synchronized static void unregister(JComponent c) {
|
||||
for (int counter = components.size() - 1; counter >= 0; counter--) {
|
||||
// Search for the component, removing any flushed references
|
||||
// along the way.
|
||||
JComponent target = components.get(counter).get();
|
||||
|
||||
if (target == c || target == null) {
|
||||
components.remove(counter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a previously registered component of class <code>target</code>
|
||||
* that shares the JRootPane ancestor of <code>from</code>.
|
||||
*/
|
||||
synchronized static Object findRegisteredComponentOfType(JComponent from,
|
||||
Class target) {
|
||||
JRootPane rp = SwingUtilities.getRootPane(from);
|
||||
if (rp != null) {
|
||||
for (int counter = components.size() - 1; counter >= 0; counter--){
|
||||
Object component = ((WeakReference)components.get(counter)).
|
||||
get();
|
||||
|
||||
if (component == null) {
|
||||
// WeakReference has gone away, remove the WeakReference
|
||||
components.remove(counter);
|
||||
}
|
||||
else if (target.isInstance(component) && SwingUtilities.
|
||||
getRootPane((Component)component) == rp) {
|
||||
return component;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the passed in JMenuBar is above a horizontal
|
||||
* JToolBar.
|
||||
*/
|
||||
static boolean doesMenuBarBorderToolBar(JMenuBar c) {
|
||||
JToolBar tb = (JToolBar)MetalToolBarUI.
|
||||
findRegisteredComponentOfType(c, JToolBar.class);
|
||||
if (tb != null && tb.getOrientation() == JToolBar.HORIZONTAL) {
|
||||
JRootPane rp = SwingUtilities.getRootPane(c);
|
||||
Point point = new Point(0, 0);
|
||||
point = SwingUtilities.convertPoint(c, point, rp);
|
||||
int menuX = point.x;
|
||||
int menuY = point.y;
|
||||
point.x = point.y = 0;
|
||||
point = SwingUtilities.convertPoint(tb, point, rp);
|
||||
return (point.x == menuX && menuY + c.getHeight() == point.y &&
|
||||
c.getWidth() == tb.getWidth());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ComponentUI createUI( JComponent c )
|
||||
{
|
||||
return new MetalToolBarUI();
|
||||
}
|
||||
|
||||
public void installUI( JComponent c )
|
||||
{
|
||||
super.installUI( c );
|
||||
register(c);
|
||||
}
|
||||
|
||||
public void uninstallUI( JComponent c )
|
||||
{
|
||||
super.uninstallUI( c );
|
||||
nonRolloverBorder = null;
|
||||
unregister(c);
|
||||
}
|
||||
|
||||
protected void installListeners() {
|
||||
super.installListeners();
|
||||
|
||||
contListener = createContainerListener();
|
||||
if (contListener != null) {
|
||||
toolBar.addContainerListener(contListener);
|
||||
}
|
||||
rolloverListener = createRolloverListener();
|
||||
if (rolloverListener != null) {
|
||||
toolBar.addPropertyChangeListener(rolloverListener);
|
||||
}
|
||||
}
|
||||
|
||||
protected void uninstallListeners() {
|
||||
super.uninstallListeners();
|
||||
|
||||
if (contListener != null) {
|
||||
toolBar.removeContainerListener(contListener);
|
||||
}
|
||||
rolloverListener = createRolloverListener();
|
||||
if (rolloverListener != null) {
|
||||
toolBar.removePropertyChangeListener(rolloverListener);
|
||||
}
|
||||
}
|
||||
|
||||
protected Border createRolloverBorder() {
|
||||
return super.createRolloverBorder();
|
||||
}
|
||||
|
||||
protected Border createNonRolloverBorder() {
|
||||
return super.createNonRolloverBorder();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a non rollover border for Toggle buttons in the toolbar.
|
||||
*/
|
||||
private Border createNonRolloverToggleBorder() {
|
||||
return createNonRolloverBorder();
|
||||
}
|
||||
|
||||
protected void setBorderToNonRollover(Component c) {
|
||||
if (c instanceof JToggleButton && !(c instanceof JCheckBox)) {
|
||||
// 4735514, 4886944: The method createNonRolloverToggleBorder() is
|
||||
// private in BasicToolBarUI so we can't override it. We still need
|
||||
// to call super from this method so that it can save away the
|
||||
// original border and then we install ours.
|
||||
|
||||
// Before calling super we get a handle to the old border, because
|
||||
// super will install a non-UIResource border that we can't
|
||||
// distinguish from one provided by an application.
|
||||
JToggleButton b = (JToggleButton)c;
|
||||
Border border = b.getBorder();
|
||||
super.setBorderToNonRollover(c);
|
||||
if (border instanceof UIResource) {
|
||||
if (nonRolloverBorder == null) {
|
||||
nonRolloverBorder = createNonRolloverToggleBorder();
|
||||
}
|
||||
b.setBorder(nonRolloverBorder);
|
||||
}
|
||||
} else {
|
||||
super.setBorderToNonRollover(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a container listener that will be added to the JToolBar.
|
||||
* If this method returns null then it will not be added to the
|
||||
* toolbar.
|
||||
*
|
||||
* @return an instance of a <code>ContainerListener</code> or null
|
||||
*/
|
||||
protected ContainerListener createContainerListener() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a property change listener that will be added to the JToolBar.
|
||||
* If this method returns null then it will not be added to the
|
||||
* toolbar.
|
||||
*
|
||||
* @return an instance of a <code>PropertyChangeListener</code> or null
|
||||
*/
|
||||
protected PropertyChangeListener createRolloverListener() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected MouseInputListener createDockingListener( )
|
||||
{
|
||||
return new MetalDockingListener( toolBar );
|
||||
}
|
||||
|
||||
protected void setDragOffset(Point p) {
|
||||
if (!GraphicsEnvironment.isHeadless()) {
|
||||
if (dragWindow == null) {
|
||||
dragWindow = createDragWindow(toolBar);
|
||||
}
|
||||
dragWindow.setOffset(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If necessary paints the background of the component, then invokes
|
||||
* <code>paint</code>.
|
||||
*
|
||||
* @param g Graphics to paint to
|
||||
* @param c JComponent painting on
|
||||
* @throws NullPointerException if <code>g</code> or <code>c</code> is
|
||||
* null
|
||||
* @see javax.swing.plaf.ComponentUI#update
|
||||
* @see javax.swing.plaf.ComponentUI#paint
|
||||
* @since 1.5
|
||||
*/
|
||||
public void update(Graphics g, JComponent c) {
|
||||
if (g == null) {
|
||||
throw new NullPointerException("graphics must be non-null");
|
||||
}
|
||||
if (c.isOpaque() && (c.getBackground() instanceof UIResource) &&
|
||||
((JToolBar)c).getOrientation() ==
|
||||
JToolBar.HORIZONTAL && UIManager.get(
|
||||
"MenuBar.gradient") != null) {
|
||||
JRootPane rp = SwingUtilities.getRootPane(c);
|
||||
JMenuBar mb = (JMenuBar)findRegisteredComponentOfType(
|
||||
c, JMenuBar.class);
|
||||
if (mb != null && mb.isOpaque() &&
|
||||
(mb.getBackground() instanceof UIResource)) {
|
||||
Point point = new Point(0, 0);
|
||||
point = SwingUtilities.convertPoint(c, point, rp);
|
||||
int x = point.x;
|
||||
int y = point.y;
|
||||
point.x = point.y = 0;
|
||||
point = SwingUtilities.convertPoint(mb, point, rp);
|
||||
if (point.x == x && y == point.y + mb.getHeight() &&
|
||||
mb.getWidth() == c.getWidth() &&
|
||||
MetalUtils.drawGradient(c, g, "MenuBar.gradient",
|
||||
0, -mb.getHeight(), c.getWidth(), c.getHeight() +
|
||||
mb.getHeight(), true)) {
|
||||
setLastMenuBar(mb);
|
||||
paint(g, c);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (MetalUtils.drawGradient(c, g, "MenuBar.gradient",
|
||||
0, 0, c.getWidth(), c.getHeight(), true)) {
|
||||
setLastMenuBar(null);
|
||||
paint(g, c);
|
||||
return;
|
||||
}
|
||||
}
|
||||
setLastMenuBar(null);
|
||||
super.update(g, c);
|
||||
}
|
||||
|
||||
private void setLastMenuBar(JMenuBar lastMenuBar) {
|
||||
if (MetalLookAndFeel.usingOcean()) {
|
||||
if (this.lastMenuBar != lastMenuBar) {
|
||||
// The menubar we previously touched has changed, force it
|
||||
// to repaint.
|
||||
if (this.lastMenuBar != null) {
|
||||
this.lastMenuBar.repaint();
|
||||
}
|
||||
if (lastMenuBar != null) {
|
||||
lastMenuBar.repaint();
|
||||
}
|
||||
this.lastMenuBar = lastMenuBar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No longer used. Cannot remove for compatibility reasons
|
||||
protected class MetalContainerListener
|
||||
extends BasicToolBarUI.ToolBarContListener {}
|
||||
|
||||
// No longer used. Cannot remove for compatibility reasons
|
||||
protected class MetalRolloverListener
|
||||
extends BasicToolBarUI.PropertyListener {}
|
||||
|
||||
protected class MetalDockingListener extends DockingListener {
|
||||
private boolean pressedInBumps = false;
|
||||
|
||||
public MetalDockingListener(JToolBar t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent e) {
|
||||
super.mousePressed(e);
|
||||
if (!toolBar.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
pressedInBumps = false;
|
||||
Rectangle bumpRect = new Rectangle();
|
||||
|
||||
if (toolBar.getOrientation() == JToolBar.HORIZONTAL) {
|
||||
int x = MetalUtils.isLeftToRight(toolBar) ? 0 : toolBar.getSize().width-14;
|
||||
bumpRect.setBounds(x, 0, 14, toolBar.getSize().height);
|
||||
} else { // vertical
|
||||
bumpRect.setBounds(0, 0, toolBar.getSize().width, 14);
|
||||
}
|
||||
if (bumpRect.contains(e.getPoint())) {
|
||||
pressedInBumps = true;
|
||||
Point dragOffset = e.getPoint();
|
||||
if (!MetalUtils.isLeftToRight(toolBar)) {
|
||||
dragOffset.x -= (toolBar.getSize().width
|
||||
- toolBar.getPreferredSize().width);
|
||||
}
|
||||
setDragOffset(dragOffset);
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
if (pressedInBumps) {
|
||||
super.mouseDragged(e);
|
||||
}
|
||||
}
|
||||
} // end class MetalDockingListener
|
||||
}
|
||||
197
jdkSrc/jdk8/javax/swing/plaf/metal/MetalToolTipUI.java
Normal file
197
jdkSrc/jdk8/javax/swing/plaf/metal/MetalToolTipUI.java
Normal file
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import sun.swing.SwingUtilities2;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.BasicToolTipUI;
|
||||
import javax.swing.plaf.basic.BasicHTML;
|
||||
import javax.swing.text.View;
|
||||
|
||||
|
||||
/**
|
||||
* A Metal L&F extension of BasicToolTipUI.
|
||||
* <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™
|
||||
* has been added to the <code>java.beans</code> package.
|
||||
* Please see {@link java.beans.XMLEncoder}.
|
||||
*
|
||||
* @author Steve Wilson
|
||||
*/
|
||||
public class MetalToolTipUI extends BasicToolTipUI {
|
||||
|
||||
static MetalToolTipUI sharedInstance = new MetalToolTipUI();
|
||||
private Font smallFont;
|
||||
// Refer to note in getAcceleratorString about this field.
|
||||
private JToolTip tip;
|
||||
public static final int padSpaceBetweenStrings = 12;
|
||||
private String acceleratorDelimiter;
|
||||
|
||||
public MetalToolTipUI() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
public void installUI(JComponent c) {
|
||||
super.installUI(c);
|
||||
tip = (JToolTip)c;
|
||||
Font f = c.getFont();
|
||||
smallFont = new Font( f.getName(), f.getStyle(), f.getSize() - 2 );
|
||||
acceleratorDelimiter = UIManager.getString( "MenuItem.acceleratorDelimiter" );
|
||||
if ( acceleratorDelimiter == null ) { acceleratorDelimiter = "-"; }
|
||||
}
|
||||
|
||||
public void uninstallUI(JComponent c) {
|
||||
super.uninstallUI(c);
|
||||
tip = null;
|
||||
}
|
||||
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
JToolTip tip = (JToolTip)c;
|
||||
Font font = c.getFont();
|
||||
FontMetrics metrics = SwingUtilities2.getFontMetrics(c, g, font);
|
||||
Dimension size = c.getSize();
|
||||
int accelBL;
|
||||
|
||||
g.setColor(c.getForeground());
|
||||
// fix for bug 4153892
|
||||
String tipText = tip.getTipText();
|
||||
if (tipText == null) {
|
||||
tipText = "";
|
||||
}
|
||||
|
||||
String accelString = getAcceleratorString(tip);
|
||||
FontMetrics accelMetrics = SwingUtilities2.getFontMetrics(c, g, smallFont);
|
||||
int accelSpacing = calcAccelSpacing(c, accelMetrics, accelString);
|
||||
|
||||
Insets insets = tip.getInsets();
|
||||
Rectangle paintTextR = new Rectangle(
|
||||
insets.left + 3,
|
||||
insets.top,
|
||||
size.width - (insets.left + insets.right) - 6 - accelSpacing,
|
||||
size.height - (insets.top + insets.bottom));
|
||||
View v = (View) c.getClientProperty(BasicHTML.propertyKey);
|
||||
if (v != null) {
|
||||
v.paint(g, paintTextR);
|
||||
accelBL = BasicHTML.getHTMLBaseline(v, paintTextR.width,
|
||||
paintTextR.height);
|
||||
} else {
|
||||
g.setFont(font);
|
||||
SwingUtilities2.drawString(tip, g, tipText, paintTextR.x,
|
||||
paintTextR.y + metrics.getAscent());
|
||||
accelBL = metrics.getAscent();
|
||||
}
|
||||
|
||||
if (!accelString.equals("")) {
|
||||
g.setFont(smallFont);
|
||||
g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
|
||||
SwingUtilities2.drawString(tip, g, accelString,
|
||||
tip.getWidth() - 1 - insets.right
|
||||
- accelSpacing
|
||||
+ padSpaceBetweenStrings
|
||||
- 3,
|
||||
paintTextR.y + accelBL);
|
||||
}
|
||||
}
|
||||
|
||||
private int calcAccelSpacing(JComponent c, FontMetrics fm, String accel) {
|
||||
return accel.equals("")
|
||||
? 0
|
||||
: padSpaceBetweenStrings +
|
||||
SwingUtilities2.stringWidth(c, fm, accel);
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize(JComponent c) {
|
||||
Dimension d = super.getPreferredSize(c);
|
||||
|
||||
String key = getAcceleratorString((JToolTip)c);
|
||||
if (!(key.equals(""))) {
|
||||
d.width += calcAccelSpacing(c, c.getFontMetrics(smallFont), key);
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
protected boolean isAcceleratorHidden() {
|
||||
Boolean b = (Boolean)UIManager.get("ToolTip.hideAccelerator");
|
||||
return b != null && b.booleanValue();
|
||||
}
|
||||
|
||||
private String getAcceleratorString(JToolTip tip) {
|
||||
this.tip = tip;
|
||||
|
||||
String retValue = getAcceleratorString();
|
||||
|
||||
this.tip = null;
|
||||
return retValue;
|
||||
}
|
||||
|
||||
// NOTE: This requires the tip field to be set before this is invoked.
|
||||
// As MetalToolTipUI is shared between all JToolTips the tip field is
|
||||
// set appropriately before this is invoked. Unfortunately this means
|
||||
// that subclasses that randomly invoke this method will see varying
|
||||
// results. If this becomes an issue, MetalToolTipUI should no longer be
|
||||
// shared.
|
||||
public String getAcceleratorString() {
|
||||
if (tip == null || isAcceleratorHidden()) {
|
||||
return "";
|
||||
}
|
||||
JComponent comp = tip.getComponent();
|
||||
if (!(comp instanceof AbstractButton)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
KeyStroke[] keys = comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).keys();
|
||||
if (keys == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String controlKeyStr = "";
|
||||
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
int mod = keys[i].getModifiers();
|
||||
controlKeyStr = KeyEvent.getKeyModifiersText(mod) +
|
||||
acceleratorDelimiter +
|
||||
KeyEvent.getKeyText(keys[i].getKeyCode());
|
||||
break;
|
||||
}
|
||||
|
||||
return controlKeyStr;
|
||||
}
|
||||
|
||||
}
|
||||
238
jdkSrc/jdk8/javax/swing/plaf/metal/MetalTreeUI.java
Normal file
238
jdkSrc/jdk8/javax/swing/plaf/metal/MetalTreeUI.java
Normal file
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.beans.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.tree.*;
|
||||
|
||||
import javax.swing.plaf.basic.*;
|
||||
|
||||
/**
|
||||
* The metal look and feel implementation of <code>TreeUI</code>.
|
||||
* <p>
|
||||
* <code>MetalTreeUI</code> allows for configuring how to
|
||||
* visually render the spacing and delineation between nodes. The following
|
||||
* hints are supported:
|
||||
*
|
||||
* <table summary="Descriptions of supported hints: Angled, Horizontal, and None">
|
||||
* <tr>
|
||||
* <th><p style="text-align:left">Angled</p></th>
|
||||
* <td>A line is drawn connecting the child to the parent. For handling
|
||||
* of the root node refer to
|
||||
* {@link javax.swing.JTree#setRootVisible} and
|
||||
* {@link javax.swing.JTree#setShowsRootHandles}.
|
||||
* </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <th><p style="text-align:left">Horizontal</p></th>
|
||||
* <td>A horizontal line is drawn dividing the children of the root node.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <th><p style="text-align:left">None</p></th>
|
||||
* <td>Do not draw any visual indication between nodes.</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* <p>
|
||||
* As it is typically impractical to obtain the <code>TreeUI</code> from
|
||||
* the <code>JTree</code> and cast to an instance of <code>MetalTreeUI</code>
|
||||
* you enable this property via the client property
|
||||
* <code>JTree.lineStyle</code>. For example, to switch to
|
||||
* <code>Horizontal</code> style you would do:
|
||||
* <code>tree.putClientProperty("JTree.lineStyle", "Horizontal");</code>
|
||||
* <p>
|
||||
* The default is <code>Angled</code>.
|
||||
*
|
||||
* @author Tom Santos
|
||||
* @author Steve Wilson (value add stuff)
|
||||
*/
|
||||
public class MetalTreeUI extends BasicTreeUI {
|
||||
|
||||
private static Color lineColor;
|
||||
|
||||
private static final String LINE_STYLE = "JTree.lineStyle";
|
||||
|
||||
private static final String LEG_LINE_STYLE_STRING = "Angled";
|
||||
private static final String HORIZ_STYLE_STRING = "Horizontal";
|
||||
private static final String NO_STYLE_STRING = "None";
|
||||
|
||||
private static final int LEG_LINE_STYLE = 2;
|
||||
private static final int HORIZ_LINE_STYLE = 1;
|
||||
private static final int NO_LINE_STYLE = 0;
|
||||
|
||||
private int lineStyle = LEG_LINE_STYLE;
|
||||
private PropertyChangeListener lineStyleListener = new LineListener();
|
||||
|
||||
// Boilerplate
|
||||
public static ComponentUI createUI(JComponent x) {
|
||||
return new MetalTreeUI();
|
||||
}
|
||||
|
||||
public MetalTreeUI()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
protected int getHorizontalLegBuffer()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public void installUI( JComponent c ) {
|
||||
super.installUI( c );
|
||||
lineColor = UIManager.getColor( "Tree.line" );
|
||||
|
||||
Object lineStyleFlag = c.getClientProperty( LINE_STYLE );
|
||||
decodeLineStyle(lineStyleFlag);
|
||||
c.addPropertyChangeListener(lineStyleListener);
|
||||
|
||||
}
|
||||
|
||||
public void uninstallUI( JComponent c) {
|
||||
c.removePropertyChangeListener(lineStyleListener);
|
||||
super.uninstallUI(c);
|
||||
}
|
||||
|
||||
/** this function converts between the string passed into the client property
|
||||
* and the internal representation (currently and int)
|
||||
*
|
||||
*/
|
||||
protected void decodeLineStyle(Object lineStyleFlag) {
|
||||
if ( lineStyleFlag == null ||
|
||||
lineStyleFlag.equals(LEG_LINE_STYLE_STRING)){
|
||||
lineStyle = LEG_LINE_STYLE; // default case
|
||||
} else {
|
||||
if ( lineStyleFlag.equals(NO_STYLE_STRING) ) {
|
||||
lineStyle = NO_LINE_STYLE;
|
||||
} else if ( lineStyleFlag.equals(HORIZ_STYLE_STRING) ) {
|
||||
lineStyle = HORIZ_LINE_STYLE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected boolean isLocationInExpandControl(int row, int rowLevel,
|
||||
int mouseX, int mouseY) {
|
||||
if(tree != null && !isLeaf(row)) {
|
||||
int boxWidth;
|
||||
|
||||
if(getExpandedIcon() != null)
|
||||
boxWidth = getExpandedIcon().getIconWidth() + 6;
|
||||
else
|
||||
boxWidth = 8;
|
||||
|
||||
Insets i = tree.getInsets();
|
||||
int boxLeftX = (i != null) ? i.left : 0;
|
||||
|
||||
|
||||
boxLeftX += (((rowLevel + depthOffset - 1) * totalChildIndent) +
|
||||
getLeftChildIndent()) - boxWidth/2;
|
||||
|
||||
int boxRightX = boxLeftX + boxWidth;
|
||||
|
||||
return mouseX >= boxLeftX && mouseX <= boxRightX;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
super.paint( g, c );
|
||||
|
||||
|
||||
// Paint the lines
|
||||
if (lineStyle == HORIZ_LINE_STYLE && !largeModel) {
|
||||
paintHorizontalSeparators(g,c);
|
||||
}
|
||||
}
|
||||
|
||||
protected void paintHorizontalSeparators(Graphics g, JComponent c) {
|
||||
g.setColor( lineColor );
|
||||
|
||||
Rectangle clipBounds = g.getClipBounds();
|
||||
|
||||
int beginRow = getRowForPath(tree, getClosestPathForLocation
|
||||
(tree, 0, clipBounds.y));
|
||||
int endRow = getRowForPath(tree, getClosestPathForLocation
|
||||
(tree, 0, clipBounds.y + clipBounds.height - 1));
|
||||
|
||||
if ( beginRow <= -1 || endRow <= -1 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
for ( int i = beginRow; i <= endRow; ++i ) {
|
||||
TreePath path = getPathForRow(tree, i);
|
||||
|
||||
if(path != null && path.getPathCount() == 2) {
|
||||
Rectangle rowBounds = getPathBounds(tree,getPathForRow
|
||||
(tree, i));
|
||||
|
||||
// Draw a line at the top
|
||||
if(rowBounds != null)
|
||||
g.drawLine(clipBounds.x, rowBounds.y,
|
||||
clipBounds.x + clipBounds.width, rowBounds.y);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds,
|
||||
Insets insets, TreePath path) {
|
||||
if (lineStyle == LEG_LINE_STYLE) {
|
||||
super.paintVerticalPartOfLeg(g, clipBounds, insets, path);
|
||||
}
|
||||
}
|
||||
|
||||
protected void paintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds,
|
||||
Insets insets, Rectangle bounds,
|
||||
TreePath path, int row,
|
||||
boolean isExpanded,
|
||||
boolean hasBeenExpanded, boolean
|
||||
isLeaf) {
|
||||
if (lineStyle == LEG_LINE_STYLE) {
|
||||
super.paintHorizontalPartOfLeg(g, clipBounds, insets, bounds,
|
||||
path, row, isExpanded,
|
||||
hasBeenExpanded, isLeaf);
|
||||
}
|
||||
}
|
||||
|
||||
/** This class listens for changes in line style */
|
||||
class LineListener implements PropertyChangeListener {
|
||||
public void propertyChange(PropertyChangeEvent e) {
|
||||
String name = e.getPropertyName();
|
||||
if ( name.equals( LINE_STYLE ) ) {
|
||||
decodeLineStyle(e.getNewValue());
|
||||
}
|
||||
}
|
||||
} // end class PaletteListener
|
||||
|
||||
}
|
||||
452
jdkSrc/jdk8/javax/swing/plaf/metal/MetalUtils.java
Normal file
452
jdkSrc/jdk8/javax/swing/plaf/metal/MetalUtils.java
Normal file
@@ -0,0 +1,452 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.lang.ref.*;
|
||||
import java.util.*;
|
||||
import sun.swing.CachedPainter;
|
||||
import sun.swing.ImageIconUIResource;
|
||||
|
||||
/**
|
||||
* This is a dumping ground for random stuff we want to use in several places.
|
||||
*
|
||||
* @author Steve Wilson
|
||||
*/
|
||||
|
||||
class MetalUtils {
|
||||
|
||||
static void drawFlush3DBorder(Graphics g, Rectangle r) {
|
||||
drawFlush3DBorder(g, r.x, r.y, r.width, r.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* This draws the "Flush 3D Border" which is used throughout the Metal L&F
|
||||
*/
|
||||
static void drawFlush3DBorder(Graphics g, int x, int y, int w, int h) {
|
||||
g.translate( x, y);
|
||||
g.setColor( MetalLookAndFeel.getControlDarkShadow() );
|
||||
g.drawRect( 0, 0, w-2, h-2 );
|
||||
g.setColor( MetalLookAndFeel.getControlHighlight() );
|
||||
g.drawRect( 1, 1, w-2, h-2 );
|
||||
g.setColor( MetalLookAndFeel.getControl() );
|
||||
g.drawLine( 0, h-1, 1, h-2 );
|
||||
g.drawLine( w-1, 0, w-2, 1 );
|
||||
g.translate( -x, -y);
|
||||
}
|
||||
|
||||
/**
|
||||
* This draws a variant "Flush 3D Border"
|
||||
* It is used for things like pressed buttons.
|
||||
*/
|
||||
static void drawPressed3DBorder(Graphics g, Rectangle r) {
|
||||
drawPressed3DBorder( g, r.x, r.y, r.width, r.height );
|
||||
}
|
||||
|
||||
static void drawDisabledBorder(Graphics g, int x, int y, int w, int h) {
|
||||
g.translate( x, y);
|
||||
g.setColor( MetalLookAndFeel.getControlShadow() );
|
||||
g.drawRect( 0, 0, w-1, h-1 );
|
||||
g.translate(-x, -y);
|
||||
}
|
||||
|
||||
/**
|
||||
* This draws a variant "Flush 3D Border"
|
||||
* It is used for things like pressed buttons.
|
||||
*/
|
||||
static void drawPressed3DBorder(Graphics g, int x, int y, int w, int h) {
|
||||
g.translate( x, y);
|
||||
|
||||
drawFlush3DBorder(g, 0, 0, w, h);
|
||||
|
||||
g.setColor( MetalLookAndFeel.getControlShadow() );
|
||||
g.drawLine( 1, 1, 1, h-2 );
|
||||
g.drawLine( 1, 1, w-2, 1 );
|
||||
g.translate( -x, -y);
|
||||
}
|
||||
|
||||
/**
|
||||
* This draws a variant "Flush 3D Border"
|
||||
* It is used for things like active toggle buttons.
|
||||
* This is used rarely.
|
||||
*/
|
||||
static void drawDark3DBorder(Graphics g, Rectangle r) {
|
||||
drawDark3DBorder(g, r.x, r.y, r.width, r.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* This draws a variant "Flush 3D Border"
|
||||
* It is used for things like active toggle buttons.
|
||||
* This is used rarely.
|
||||
*/
|
||||
static void drawDark3DBorder(Graphics g, int x, int y, int w, int h) {
|
||||
g.translate( x, y);
|
||||
|
||||
drawFlush3DBorder(g, 0, 0, w, h);
|
||||
|
||||
g.setColor( MetalLookAndFeel.getControl() );
|
||||
g.drawLine( 1, 1, 1, h-2 );
|
||||
g.drawLine( 1, 1, w-2, 1 );
|
||||
g.setColor( MetalLookAndFeel.getControlShadow() );
|
||||
g.drawLine( 1, h-2, 1, h-2 );
|
||||
g.drawLine( w-2, 1, w-2, 1 );
|
||||
g.translate( -x, -y);
|
||||
}
|
||||
|
||||
static void drawButtonBorder(Graphics g, int x, int y, int w, int h, boolean active) {
|
||||
if (active) {
|
||||
drawActiveButtonBorder(g, x, y, w, h);
|
||||
} else {
|
||||
drawFlush3DBorder(g, x, y, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
static void drawActiveButtonBorder(Graphics g, int x, int y, int w, int h) {
|
||||
drawFlush3DBorder(g, x, y, w, h);
|
||||
g.setColor( MetalLookAndFeel.getPrimaryControl() );
|
||||
g.drawLine( x+1, y+1, x+1, h-3 );
|
||||
g.drawLine( x+1, y+1, w-3, x+1 );
|
||||
g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
|
||||
g.drawLine( x+2, h-2, w-2, h-2 );
|
||||
g.drawLine( w-2, y+2, w-2, h-2 );
|
||||
}
|
||||
|
||||
static void drawDefaultButtonBorder(Graphics g, int x, int y, int w, int h, boolean active) {
|
||||
drawButtonBorder(g, x+1, y+1, w-1, h-1, active);
|
||||
g.translate(x, y);
|
||||
g.setColor( MetalLookAndFeel.getControlDarkShadow() );
|
||||
g.drawRect( 0, 0, w-3, h-3 );
|
||||
g.drawLine( w-2, 0, w-2, 0);
|
||||
g.drawLine( 0, h-2, 0, h-2);
|
||||
g.translate(-x, -y);
|
||||
}
|
||||
|
||||
static void drawDefaultButtonPressedBorder(Graphics g, int x, int y, int w, int h) {
|
||||
drawPressed3DBorder(g, x + 1, y + 1, w - 1, h - 1);
|
||||
g.translate(x, y);
|
||||
g.setColor(MetalLookAndFeel.getControlDarkShadow());
|
||||
g.drawRect(0, 0, w - 3, h - 3);
|
||||
g.drawLine(w - 2, 0, w - 2, 0);
|
||||
g.drawLine(0, h - 2, 0, h - 2);
|
||||
g.setColor(MetalLookAndFeel.getControl());
|
||||
g.drawLine(w - 1, 0, w - 1, 0);
|
||||
g.drawLine(0, h - 1, 0, h - 1);
|
||||
g.translate(-x, -y);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convenience function for determining ComponentOrientation. Helps us
|
||||
* avoid having Munge directives throughout the code.
|
||||
*/
|
||||
static boolean isLeftToRight( Component c ) {
|
||||
return c.getComponentOrientation().isLeftToRight();
|
||||
}
|
||||
|
||||
static int getInt(Object key, int defaultValue) {
|
||||
Object value = UIManager.get(key);
|
||||
|
||||
if (value instanceof Integer) {
|
||||
return ((Integer)value).intValue();
|
||||
}
|
||||
if (value instanceof String) {
|
||||
try {
|
||||
return Integer.parseInt((String)value);
|
||||
} catch (NumberFormatException nfe) {}
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
//
|
||||
// Ocean specific stuff.
|
||||
//
|
||||
/**
|
||||
* Draws a radial type gradient. The gradient will be drawn vertically if
|
||||
* <code>vertical</code> is true, otherwise horizontally.
|
||||
* The UIManager key consists of five values:
|
||||
* r1 r2 c1 c2 c3. The gradient is broken down into four chunks drawn
|
||||
* in order from the origin.
|
||||
* <ol>
|
||||
* <li>Gradient r1 % of the size from c1 to c2
|
||||
* <li>Rectangle r2 % of the size in c2.
|
||||
* <li>Gradient r1 % of the size from c2 to c1
|
||||
* <li>The remaining size will be filled with a gradient from c1 to c3.
|
||||
* </ol>
|
||||
*
|
||||
* @param c Component rendering to
|
||||
* @param g Graphics to draw to.
|
||||
* @param key UIManager key used to look up gradient values.
|
||||
* @param x X coordinate to draw from
|
||||
* @param y Y coordinate to draw from
|
||||
* @param w Width to draw to
|
||||
* @param h Height to draw to
|
||||
* @param vertical Direction of the gradient
|
||||
* @return true if <code>key</code> exists, otherwise false.
|
||||
*/
|
||||
static boolean drawGradient(Component c, Graphics g, String key,
|
||||
int x, int y, int w, int h, boolean vertical) {
|
||||
java.util.List gradient = (java.util.List)UIManager.get(key);
|
||||
if (gradient == null || !(g instanceof Graphics2D)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (w <= 0 || h <= 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
GradientPainter.INSTANCE.paint(
|
||||
c, (Graphics2D)g, gradient, x, y, w, h, vertical);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private static class GradientPainter extends CachedPainter {
|
||||
/**
|
||||
* Instance used for painting. This is the only instance that is
|
||||
* ever created.
|
||||
*/
|
||||
public static final GradientPainter INSTANCE = new GradientPainter(8);
|
||||
|
||||
// Size of images to create. For vertical gradients this is the width,
|
||||
// otherwise it's the height.
|
||||
private static final int IMAGE_SIZE = 64;
|
||||
|
||||
/**
|
||||
* This is the actual width we're painting in, or last painted to.
|
||||
*/
|
||||
private int w;
|
||||
/**
|
||||
* This is the actual height we're painting in, or last painted to
|
||||
*/
|
||||
private int h;
|
||||
|
||||
|
||||
GradientPainter(int count) {
|
||||
super(count);
|
||||
}
|
||||
|
||||
public void paint(Component c, Graphics2D g,
|
||||
java.util.List gradient, int x, int y, int w,
|
||||
int h, boolean isVertical) {
|
||||
int imageWidth;
|
||||
int imageHeight;
|
||||
if (isVertical) {
|
||||
imageWidth = IMAGE_SIZE;
|
||||
imageHeight = h;
|
||||
}
|
||||
else {
|
||||
imageWidth = w;
|
||||
imageHeight = IMAGE_SIZE;
|
||||
}
|
||||
synchronized(c.getTreeLock()) {
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
paint(c, g, x, y, imageWidth, imageHeight,
|
||||
gradient, isVertical);
|
||||
}
|
||||
}
|
||||
|
||||
protected void paintToImage(Component c, Image image, Graphics g,
|
||||
int w, int h, Object[] args) {
|
||||
Graphics2D g2 = (Graphics2D)g;
|
||||
java.util.List gradient = (java.util.List)args[0];
|
||||
boolean isVertical = ((Boolean)args[1]).booleanValue();
|
||||
// Render to the VolatileImage
|
||||
if (isVertical) {
|
||||
drawVerticalGradient(g2,
|
||||
((Number)gradient.get(0)).floatValue(),
|
||||
((Number)gradient.get(1)).floatValue(),
|
||||
(Color)gradient.get(2),
|
||||
(Color)gradient.get(3),
|
||||
(Color)gradient.get(4), w, h);
|
||||
}
|
||||
else {
|
||||
drawHorizontalGradient(g2,
|
||||
((Number)gradient.get(0)).floatValue(),
|
||||
((Number)gradient.get(1)).floatValue(),
|
||||
(Color)gradient.get(2),
|
||||
(Color)gradient.get(3),
|
||||
(Color)gradient.get(4), w, h);
|
||||
}
|
||||
}
|
||||
|
||||
protected void paintImage(Component c, Graphics g,
|
||||
int x, int y, int imageW, int imageH,
|
||||
Image image, Object[] args) {
|
||||
boolean isVertical = ((Boolean)args[1]).booleanValue();
|
||||
// Render to the screen
|
||||
g.translate(x, y);
|
||||
if (isVertical) {
|
||||
for (int counter = 0; counter < w; counter += IMAGE_SIZE) {
|
||||
int tileSize = Math.min(IMAGE_SIZE, w - counter);
|
||||
g.drawImage(image, counter, 0, counter + tileSize, h,
|
||||
0, 0, tileSize, h, null);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int counter = 0; counter < h; counter += IMAGE_SIZE) {
|
||||
int tileSize = Math.min(IMAGE_SIZE, h - counter);
|
||||
g.drawImage(image, 0, counter, w, counter + tileSize,
|
||||
0, 0, w, tileSize, null);
|
||||
}
|
||||
}
|
||||
g.translate(-x, -y);
|
||||
}
|
||||
|
||||
private void drawVerticalGradient(Graphics2D g, float ratio1,
|
||||
float ratio2, Color c1,Color c2,
|
||||
Color c3, int w, int h) {
|
||||
int mid = (int)(ratio1 * h);
|
||||
int mid2 = (int)(ratio2 * h);
|
||||
if (mid > 0) {
|
||||
g.setPaint(getGradient((float)0, (float)0, c1, (float)0,
|
||||
(float)mid, c2));
|
||||
g.fillRect(0, 0, w, mid);
|
||||
}
|
||||
if (mid2 > 0) {
|
||||
g.setColor(c2);
|
||||
g.fillRect(0, mid, w, mid2);
|
||||
}
|
||||
if (mid > 0) {
|
||||
g.setPaint(getGradient((float)0, (float)mid + mid2, c2,
|
||||
(float)0, (float)mid * 2 + mid2, c1));
|
||||
g.fillRect(0, mid + mid2, w, mid);
|
||||
}
|
||||
if (h - mid * 2 - mid2 > 0) {
|
||||
g.setPaint(getGradient((float)0, (float)mid * 2 + mid2, c1,
|
||||
(float)0, (float)h, c3));
|
||||
g.fillRect(0, mid * 2 + mid2, w, h - mid * 2 - mid2);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawHorizontalGradient(Graphics2D g, float ratio1,
|
||||
float ratio2, Color c1,Color c2,
|
||||
Color c3, int w, int h) {
|
||||
int mid = (int)(ratio1 * w);
|
||||
int mid2 = (int)(ratio2 * w);
|
||||
if (mid > 0) {
|
||||
g.setPaint(getGradient((float)0, (float)0, c1,
|
||||
(float)mid, (float)0, c2));
|
||||
g.fillRect(0, 0, mid, h);
|
||||
}
|
||||
if (mid2 > 0) {
|
||||
g.setColor(c2);
|
||||
g.fillRect(mid, 0, mid2, h);
|
||||
}
|
||||
if (mid > 0) {
|
||||
g.setPaint(getGradient((float)mid + mid2, (float)0, c2,
|
||||
(float)mid * 2 + mid2, (float)0, c1));
|
||||
g.fillRect(mid + mid2, 0, mid, h);
|
||||
}
|
||||
if (w - mid * 2 - mid2 > 0) {
|
||||
g.setPaint(getGradient((float)mid * 2 + mid2, (float)0, c1,
|
||||
w, (float)0, c3));
|
||||
g.fillRect(mid * 2 + mid2, 0, w - mid * 2 - mid2, h);
|
||||
}
|
||||
}
|
||||
|
||||
private GradientPaint getGradient(float x1, float y1,
|
||||
Color c1, float x2, float y2,
|
||||
Color c2) {
|
||||
return new GradientPaint(x1, y1, c1, x2, y2, c2, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the specified widget is in a toolbar.
|
||||
*/
|
||||
static boolean isToolBarButton(JComponent c) {
|
||||
return (c.getParent() instanceof JToolBar);
|
||||
}
|
||||
|
||||
static Icon getOceanToolBarIcon(Image i) {
|
||||
ImageProducer prod = new FilteredImageSource(i.getSource(),
|
||||
new OceanToolBarImageFilter());
|
||||
return new ImageIconUIResource(Toolkit.getDefaultToolkit().createImage(prod));
|
||||
}
|
||||
|
||||
static Icon getOceanDisabledButtonIcon(Image image) {
|
||||
Object[] range = (Object[])UIManager.get("Button.disabledGrayRange");
|
||||
int min = 180;
|
||||
int max = 215;
|
||||
if (range != null) {
|
||||
min = ((Integer)range[0]).intValue();
|
||||
max = ((Integer)range[1]).intValue();
|
||||
}
|
||||
ImageProducer prod = new FilteredImageSource(image.getSource(),
|
||||
new OceanDisabledButtonImageFilter(min , max));
|
||||
return new ImageIconUIResource(Toolkit.getDefaultToolkit().createImage(prod));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Used to create a disabled Icon with the ocean look.
|
||||
*/
|
||||
private static class OceanDisabledButtonImageFilter extends RGBImageFilter{
|
||||
private float min;
|
||||
private float factor;
|
||||
|
||||
OceanDisabledButtonImageFilter(int min, int max) {
|
||||
canFilterIndexColorModel = true;
|
||||
this.min = (float)min;
|
||||
this.factor = (max - min) / 255f;
|
||||
}
|
||||
|
||||
public int filterRGB(int x, int y, int rgb) {
|
||||
// Coefficients are from the sRGB color space:
|
||||
int gray = Math.min(255, (int)(((0.2125f * ((rgb >> 16) & 0xFF)) +
|
||||
(0.7154f * ((rgb >> 8) & 0xFF)) +
|
||||
(0.0721f * (rgb & 0xFF)) + .5f) * factor + min));
|
||||
|
||||
return (rgb & 0xff000000) | (gray << 16) | (gray << 8) |
|
||||
(gray << 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Used to create the rollover icons with the ocean look.
|
||||
*/
|
||||
private static class OceanToolBarImageFilter extends RGBImageFilter {
|
||||
OceanToolBarImageFilter() {
|
||||
canFilterIndexColorModel = true;
|
||||
}
|
||||
|
||||
public int filterRGB(int x, int y, int rgb) {
|
||||
int r = ((rgb >> 16) & 0xff);
|
||||
int g = ((rgb >> 8) & 0xff);
|
||||
int b = (rgb & 0xff);
|
||||
int gray = Math.max(Math.max(r, g), b);
|
||||
return (rgb & 0xff000000) | (gray << 16) | (gray << 8) |
|
||||
(gray << 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
460
jdkSrc/jdk8/javax/swing/plaf/metal/OceanTheme.java
Normal file
460
jdkSrc/jdk8/javax/swing/plaf/metal/OceanTheme.java
Normal file
@@ -0,0 +1,460 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package javax.swing.plaf.metal;
|
||||
|
||||
import java.awt.*;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.*;
|
||||
import sun.swing.SwingUtilities2;
|
||||
import sun.swing.PrintColorUIResource;
|
||||
import sun.swing.SwingLazyValue;
|
||||
|
||||
/**
|
||||
* The default theme for the {@code MetalLookAndFeel}.
|
||||
* <p>
|
||||
* The designers
|
||||
* of the Metal Look and Feel strive to keep the default look up to
|
||||
* date, possibly through the use of new themes in the future.
|
||||
* Therefore, developers should only use this class directly when they
|
||||
* wish to customize the "Ocean" look, or force it to be the current
|
||||
* theme, regardless of future updates.
|
||||
|
||||
* <p>
|
||||
* All colors returned by {@code OceanTheme} are completely
|
||||
* opaque.
|
||||
*
|
||||
* @since 1.5
|
||||
* @see MetalLookAndFeel#setCurrentTheme
|
||||
*/
|
||||
public class OceanTheme extends DefaultMetalTheme {
|
||||
private static final ColorUIResource PRIMARY1 =
|
||||
new ColorUIResource(0x6382BF);
|
||||
private static final ColorUIResource PRIMARY2 =
|
||||
new ColorUIResource(0xA3B8CC);
|
||||
private static final ColorUIResource PRIMARY3 =
|
||||
new ColorUIResource(0xB8CFE5);
|
||||
private static final ColorUIResource SECONDARY1 =
|
||||
new ColorUIResource(0x7A8A99);
|
||||
private static final ColorUIResource SECONDARY2 =
|
||||
new ColorUIResource(0xB8CFE5);
|
||||
private static final ColorUIResource SECONDARY3 =
|
||||
new ColorUIResource(0xEEEEEE);
|
||||
|
||||
private static final ColorUIResource CONTROL_TEXT_COLOR =
|
||||
new PrintColorUIResource(0x333333, Color.BLACK);
|
||||
private static final ColorUIResource INACTIVE_CONTROL_TEXT_COLOR =
|
||||
new ColorUIResource(0x999999);
|
||||
private static final ColorUIResource MENU_DISABLED_FOREGROUND =
|
||||
new ColorUIResource(0x999999);
|
||||
private static final ColorUIResource OCEAN_BLACK =
|
||||
new PrintColorUIResource(0x333333, Color.BLACK);
|
||||
|
||||
private static final ColorUIResource OCEAN_DROP =
|
||||
new ColorUIResource(0xD2E9FF);
|
||||
|
||||
// ComponentOrientation Icon
|
||||
// Delegates to different icons based on component orientation
|
||||
private static class COIcon extends IconUIResource {
|
||||
private Icon rtl;
|
||||
|
||||
public COIcon(Icon ltr, Icon rtl) {
|
||||
super(ltr);
|
||||
this.rtl = rtl;
|
||||
}
|
||||
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
if (MetalUtils.isLeftToRight(c)) {
|
||||
super.paintIcon(c, g, x, y);
|
||||
} else {
|
||||
rtl.paintIcon(c, g, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// InternalFrame Icon
|
||||
// Delegates to different icons based on button state
|
||||
private static class IFIcon extends IconUIResource {
|
||||
private Icon pressed;
|
||||
|
||||
public IFIcon(Icon normal, Icon pressed) {
|
||||
super(normal);
|
||||
this.pressed = pressed;
|
||||
}
|
||||
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
ButtonModel model = ((AbstractButton)c).getModel();
|
||||
if (model.isPressed() && model.isArmed()) {
|
||||
pressed.paintIcon(c, g, x, y);
|
||||
} else {
|
||||
super.paintIcon(c, g, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of <code>OceanTheme</code>
|
||||
*/
|
||||
public OceanTheme() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add this theme's custom entries to the defaults table.
|
||||
*
|
||||
* @param table the defaults table, non-null
|
||||
* @throws NullPointerException if {@code table} is {@code null}
|
||||
*/
|
||||
public void addCustomEntriesToTable(UIDefaults table) {
|
||||
Object focusBorder = new SwingLazyValue(
|
||||
"javax.swing.plaf.BorderUIResource$LineBorderUIResource",
|
||||
new Object[] {getPrimary1()});
|
||||
// .30 0 DDE8F3 white secondary2
|
||||
java.util.List buttonGradient = Arrays.asList(
|
||||
new Object[] {new Float(.3f), new Float(0f),
|
||||
new ColorUIResource(0xDDE8F3), getWhite(), getSecondary2() });
|
||||
|
||||
// Other possible properties that aren't defined:
|
||||
//
|
||||
// Used when generating the disabled Icons, provides the region to
|
||||
// constrain grays to.
|
||||
// Button.disabledGrayRange -> Object[] of Integers giving min/max
|
||||
// InternalFrame.inactiveTitleGradient -> Gradient when the
|
||||
// internal frame is inactive.
|
||||
Color cccccc = new ColorUIResource(0xCCCCCC);
|
||||
Color dadada = new ColorUIResource(0xDADADA);
|
||||
Color c8ddf2 = new ColorUIResource(0xC8DDF2);
|
||||
Object directoryIcon = getIconResource("icons/ocean/directory.gif");
|
||||
Object fileIcon = getIconResource("icons/ocean/file.gif");
|
||||
java.util.List sliderGradient = Arrays.asList(new Object[] {
|
||||
new Float(.3f), new Float(.2f),
|
||||
c8ddf2, getWhite(), new ColorUIResource(SECONDARY2) });
|
||||
|
||||
Object[] defaults = new Object[] {
|
||||
"Button.gradient", buttonGradient,
|
||||
"Button.rollover", Boolean.TRUE,
|
||||
"Button.toolBarBorderBackground", INACTIVE_CONTROL_TEXT_COLOR,
|
||||
"Button.disabledToolBarBorderBackground", cccccc,
|
||||
"Button.rolloverIconType", "ocean",
|
||||
|
||||
"CheckBox.rollover", Boolean.TRUE,
|
||||
"CheckBox.gradient", buttonGradient,
|
||||
|
||||
"CheckBoxMenuItem.gradient", buttonGradient,
|
||||
|
||||
// home2
|
||||
"FileChooser.homeFolderIcon",
|
||||
getIconResource("icons/ocean/homeFolder.gif"),
|
||||
// directory2
|
||||
"FileChooser.newFolderIcon",
|
||||
getIconResource("icons/ocean/newFolder.gif"),
|
||||
// updir2
|
||||
"FileChooser.upFolderIcon",
|
||||
getIconResource("icons/ocean/upFolder.gif"),
|
||||
|
||||
// computer2
|
||||
"FileView.computerIcon",
|
||||
getIconResource("icons/ocean/computer.gif"),
|
||||
"FileView.directoryIcon", directoryIcon,
|
||||
// disk2
|
||||
"FileView.hardDriveIcon",
|
||||
getIconResource("icons/ocean/hardDrive.gif"),
|
||||
"FileView.fileIcon", fileIcon,
|
||||
// floppy2
|
||||
"FileView.floppyDriveIcon",
|
||||
getIconResource("icons/ocean/floppy.gif"),
|
||||
|
||||
"Label.disabledForeground", getInactiveControlTextColor(),
|
||||
|
||||
"Menu.opaque", Boolean.FALSE,
|
||||
|
||||
"MenuBar.gradient", Arrays.asList(new Object[] {
|
||||
new Float(1f), new Float(0f),
|
||||
getWhite(), dadada,
|
||||
new ColorUIResource(dadada) }),
|
||||
"MenuBar.borderColor", cccccc,
|
||||
|
||||
"InternalFrame.activeTitleGradient", buttonGradient,
|
||||
// close2
|
||||
"InternalFrame.closeIcon",
|
||||
new UIDefaults.LazyValue() {
|
||||
public Object createValue(UIDefaults table) {
|
||||
return new IFIcon(getHastenedIcon("icons/ocean/close.gif", table),
|
||||
getHastenedIcon("icons/ocean/close-pressed.gif", table));
|
||||
}
|
||||
},
|
||||
// minimize
|
||||
"InternalFrame.iconifyIcon",
|
||||
new UIDefaults.LazyValue() {
|
||||
public Object createValue(UIDefaults table) {
|
||||
return new IFIcon(getHastenedIcon("icons/ocean/iconify.gif", table),
|
||||
getHastenedIcon("icons/ocean/iconify-pressed.gif", table));
|
||||
}
|
||||
},
|
||||
// restore
|
||||
"InternalFrame.minimizeIcon",
|
||||
new UIDefaults.LazyValue() {
|
||||
public Object createValue(UIDefaults table) {
|
||||
return new IFIcon(getHastenedIcon("icons/ocean/minimize.gif", table),
|
||||
getHastenedIcon("icons/ocean/minimize-pressed.gif", table));
|
||||
}
|
||||
},
|
||||
// menubutton3
|
||||
"InternalFrame.icon",
|
||||
getIconResource("icons/ocean/menu.gif"),
|
||||
// maximize2
|
||||
"InternalFrame.maximizeIcon",
|
||||
new UIDefaults.LazyValue() {
|
||||
public Object createValue(UIDefaults table) {
|
||||
return new IFIcon(getHastenedIcon("icons/ocean/maximize.gif", table),
|
||||
getHastenedIcon("icons/ocean/maximize-pressed.gif", table));
|
||||
}
|
||||
},
|
||||
// paletteclose
|
||||
"InternalFrame.paletteCloseIcon",
|
||||
new UIDefaults.LazyValue() {
|
||||
public Object createValue(UIDefaults table) {
|
||||
return new IFIcon(getHastenedIcon("icons/ocean/paletteClose.gif", table),
|
||||
getHastenedIcon("icons/ocean/paletteClose-pressed.gif", table));
|
||||
}
|
||||
},
|
||||
|
||||
"List.focusCellHighlightBorder", focusBorder,
|
||||
|
||||
"MenuBarUI", "javax.swing.plaf.metal.MetalMenuBarUI",
|
||||
|
||||
"OptionPane.errorIcon",
|
||||
getIconResource("icons/ocean/error.png"),
|
||||
"OptionPane.informationIcon",
|
||||
getIconResource("icons/ocean/info.png"),
|
||||
"OptionPane.questionIcon",
|
||||
getIconResource("icons/ocean/question.png"),
|
||||
"OptionPane.warningIcon",
|
||||
getIconResource("icons/ocean/warning.png"),
|
||||
|
||||
"RadioButton.gradient", buttonGradient,
|
||||
"RadioButton.rollover", Boolean.TRUE,
|
||||
|
||||
"RadioButtonMenuItem.gradient", buttonGradient,
|
||||
|
||||
"ScrollBar.gradient", buttonGradient,
|
||||
|
||||
"Slider.altTrackColor", new ColorUIResource(0xD2E2EF),
|
||||
"Slider.gradient", sliderGradient,
|
||||
"Slider.focusGradient", sliderGradient,
|
||||
|
||||
"SplitPane.oneTouchButtonsOpaque", Boolean.FALSE,
|
||||
"SplitPane.dividerFocusColor", c8ddf2,
|
||||
|
||||
"TabbedPane.borderHightlightColor", getPrimary1(),
|
||||
"TabbedPane.contentAreaColor", c8ddf2,
|
||||
"TabbedPane.contentBorderInsets", new Insets(4, 2, 3, 3),
|
||||
"TabbedPane.selected", c8ddf2,
|
||||
"TabbedPane.tabAreaBackground", dadada,
|
||||
"TabbedPane.tabAreaInsets", new Insets(2, 2, 0, 6),
|
||||
"TabbedPane.unselectedBackground", SECONDARY3,
|
||||
|
||||
"Table.focusCellHighlightBorder", focusBorder,
|
||||
"Table.gridColor", SECONDARY1,
|
||||
"TableHeader.focusCellBackground", c8ddf2,
|
||||
|
||||
"ToggleButton.gradient", buttonGradient,
|
||||
|
||||
"ToolBar.borderColor", cccccc,
|
||||
"ToolBar.isRollover", Boolean.TRUE,
|
||||
|
||||
"Tree.closedIcon", directoryIcon,
|
||||
|
||||
"Tree.collapsedIcon",
|
||||
new UIDefaults.LazyValue() {
|
||||
public Object createValue(UIDefaults table) {
|
||||
return new COIcon(getHastenedIcon("icons/ocean/collapsed.gif", table),
|
||||
getHastenedIcon("icons/ocean/collapsed-rtl.gif", table));
|
||||
}
|
||||
},
|
||||
|
||||
"Tree.expandedIcon",
|
||||
getIconResource("icons/ocean/expanded.gif"),
|
||||
"Tree.leafIcon", fileIcon,
|
||||
"Tree.openIcon", directoryIcon,
|
||||
"Tree.selectionBorderColor", getPrimary1(),
|
||||
"Tree.dropLineColor", getPrimary1(),
|
||||
"Table.dropLineColor", getPrimary1(),
|
||||
"Table.dropLineShortColor", OCEAN_BLACK,
|
||||
|
||||
"Table.dropCellBackground", OCEAN_DROP,
|
||||
"Tree.dropCellBackground", OCEAN_DROP,
|
||||
"List.dropCellBackground", OCEAN_DROP,
|
||||
"List.dropLineColor", getPrimary1()
|
||||
};
|
||||
table.putDefaults(defaults);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overriden to enable picking up the system fonts, if applicable.
|
||||
*/
|
||||
boolean isSystemTheme() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of this theme, "Ocean".
|
||||
*
|
||||
* @return "Ocean"
|
||||
*/
|
||||
public String getName() {
|
||||
return "Ocean";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primary 1 color. This returns a color with an rgb hex value
|
||||
* of {@code 0x6382BF}.
|
||||
*
|
||||
* @return the primary 1 color
|
||||
* @see java.awt.Color#decode
|
||||
*/
|
||||
protected ColorUIResource getPrimary1() {
|
||||
return PRIMARY1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primary 2 color. This returns a color with an rgb hex value
|
||||
* of {@code 0xA3B8CC}.
|
||||
*
|
||||
* @return the primary 2 color
|
||||
* @see java.awt.Color#decode
|
||||
*/
|
||||
protected ColorUIResource getPrimary2() {
|
||||
return PRIMARY2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primary 3 color. This returns a color with an rgb hex value
|
||||
* of {@code 0xB8CFE5}.
|
||||
*
|
||||
* @return the primary 3 color
|
||||
* @see java.awt.Color#decode
|
||||
*/
|
||||
protected ColorUIResource getPrimary3() {
|
||||
return PRIMARY3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the secondary 1 color. This returns a color with an rgb hex
|
||||
* value of {@code 0x7A8A99}.
|
||||
*
|
||||
* @return the secondary 1 color
|
||||
* @see java.awt.Color#decode
|
||||
*/
|
||||
protected ColorUIResource getSecondary1() {
|
||||
return SECONDARY1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the secondary 2 color. This returns a color with an rgb hex
|
||||
* value of {@code 0xB8CFE5}.
|
||||
*
|
||||
* @return the secondary 2 color
|
||||
* @see java.awt.Color#decode
|
||||
*/
|
||||
protected ColorUIResource getSecondary2() {
|
||||
return SECONDARY2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the secondary 3 color. This returns a color with an rgb hex
|
||||
* value of {@code 0xEEEEEE}.
|
||||
*
|
||||
* @return the secondary 3 color
|
||||
* @see java.awt.Color#decode
|
||||
*/
|
||||
protected ColorUIResource getSecondary3() {
|
||||
return SECONDARY3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the black color. This returns a color with an rgb hex
|
||||
* value of {@code 0x333333}.
|
||||
*
|
||||
* @return the black color
|
||||
* @see java.awt.Color#decode
|
||||
*/
|
||||
protected ColorUIResource getBlack() {
|
||||
return OCEAN_BLACK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the desktop color. This returns a color with an rgb hex
|
||||
* value of {@code 0xFFFFFF}.
|
||||
*
|
||||
* @return the desktop color
|
||||
* @see java.awt.Color#decode
|
||||
*/
|
||||
public ColorUIResource getDesktopColor() {
|
||||
return MetalTheme.white;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the inactive control text color. This returns a color with an
|
||||
* rgb hex value of {@code 0x999999}.
|
||||
*
|
||||
* @return the inactive control text color
|
||||
*/
|
||||
public ColorUIResource getInactiveControlTextColor() {
|
||||
return INACTIVE_CONTROL_TEXT_COLOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the control text color. This returns a color with an
|
||||
* rgb hex value of {@code 0x333333}.
|
||||
*
|
||||
* @return the control text color
|
||||
*/
|
||||
public ColorUIResource getControlTextColor() {
|
||||
return CONTROL_TEXT_COLOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the menu disabled foreground color. This returns a color with an
|
||||
* rgb hex value of {@code 0x999999}.
|
||||
*
|
||||
* @return the menu disabled foreground color
|
||||
*/
|
||||
public ColorUIResource getMenuDisabledForeground() {
|
||||
return MENU_DISABLED_FOREGROUND;
|
||||
}
|
||||
|
||||
private Object getIconResource(String iconID) {
|
||||
return SwingUtilities2.makeIcon(getClass(), OceanTheme.class, iconID);
|
||||
}
|
||||
|
||||
// makes use of getIconResource() to fetch an icon and then hastens it
|
||||
// - calls createValue() on it and returns the actual icon
|
||||
private Icon getHastenedIcon(String iconID, UIDefaults table) {
|
||||
Object res = getIconResource(iconID);
|
||||
return (Icon)((UIDefaults.LazyValue)res).createValue(table);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user