feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
34
jdkSrc/jdk8/com/sun/java/swing/Painter.java
Normal file
34
jdkSrc/jdk8/com/sun/java/swing/Painter.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 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 com.sun.java.swing;
|
||||
|
||||
/**
|
||||
* This class is preserved for backward compatibility with JDK 6.
|
||||
*
|
||||
* @deprecated Use {@link javax.swing.Painter} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface Painter<T> extends javax.swing.Painter<T> {
|
||||
}
|
||||
222
jdkSrc/jdk8/com/sun/java/swing/SwingUtilities3.java
Normal file
222
jdkSrc/jdk8/com/sun/java/swing/SwingUtilities3.java
Normal file
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2010, 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 com.sun.java.swing;
|
||||
|
||||
import sun.awt.EventQueueDelegate;
|
||||
import sun.awt.AppContext;
|
||||
import sun.awt.SunToolkit;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.applet.Applet;
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Window;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.RepaintManager;
|
||||
|
||||
/**
|
||||
* A collection of utility methods for Swing.
|
||||
* <p>
|
||||
* <b>WARNING:</b> While this class is public, it should not be treated as
|
||||
* public API and its API may change in incompatable ways between dot dot
|
||||
* releases and even patch releases. You should not rely on this class even
|
||||
* existing.
|
||||
*
|
||||
* This is a second part of sun.swing.SwingUtilities2. It is required
|
||||
* to provide services for JavaFX applets.
|
||||
*
|
||||
*/
|
||||
public class SwingUtilities3 {
|
||||
/**
|
||||
* The {@code clientProperty} key for delegate {@code RepaintManager}
|
||||
*/
|
||||
private static final Object DELEGATE_REPAINT_MANAGER_KEY =
|
||||
new StringBuilder("DelegateRepaintManagerKey");
|
||||
|
||||
/**
|
||||
* Registers delegate RepaintManager for {@code JComponent}.
|
||||
*/
|
||||
public static void setDelegateRepaintManager(JComponent component,
|
||||
RepaintManager repaintManager) {
|
||||
/* setting up flag in AppContext to speed up lookups in case
|
||||
* there are no delegate RepaintManagers used.
|
||||
*/
|
||||
AppContext.getAppContext().put(DELEGATE_REPAINT_MANAGER_KEY,
|
||||
Boolean.TRUE);
|
||||
|
||||
component.putClientProperty(DELEGATE_REPAINT_MANAGER_KEY,
|
||||
repaintManager);
|
||||
}
|
||||
|
||||
private static final Map<Container, Boolean> vsyncedMap =
|
||||
Collections.synchronizedMap(new WeakHashMap<Container, Boolean>());
|
||||
|
||||
/**
|
||||
* Sets vsyncRequested state for the {@code rootContainer}. If
|
||||
* {@code isRequested} is {@code true} then vsynced
|
||||
* {@code BufferStrategy} is enabled for this {@code rootContainer}.
|
||||
*
|
||||
* Note: requesting vsynced painting does not guarantee one. The outcome
|
||||
* depends on current RepaintManager's RepaintManager.PaintManager
|
||||
* and on the capabilities of the graphics hardware/software and what not.
|
||||
*
|
||||
* @param rootContainer topmost container. Should be either {@code Window}
|
||||
* or {@code Applet}
|
||||
* @param isRequested the value to set vsyncRequested state to
|
||||
*/
|
||||
public static void setVsyncRequested(Container rootContainer,
|
||||
boolean isRequested) {
|
||||
assert (rootContainer instanceof Applet) || (rootContainer instanceof Window);
|
||||
if (isRequested) {
|
||||
vsyncedMap.put(rootContainer, Boolean.TRUE);
|
||||
} else {
|
||||
vsyncedMap.remove(rootContainer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if vsync painting is requested for {@code rootContainer}
|
||||
*
|
||||
* @param rootContainer topmost container. Should be either Window or Applet
|
||||
* @return {@code true} if vsync painting is requested for {@code rootContainer}
|
||||
*/
|
||||
public static boolean isVsyncRequested(Container rootContainer) {
|
||||
assert (rootContainer instanceof Applet) || (rootContainer instanceof Window);
|
||||
return Boolean.TRUE == vsyncedMap.get(rootContainer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns delegate {@code RepaintManager} for {@code component} hierarchy.
|
||||
*/
|
||||
public static RepaintManager getDelegateRepaintManager(Component
|
||||
component) {
|
||||
RepaintManager delegate = null;
|
||||
if (Boolean.TRUE == SunToolkit.targetToAppContext(component)
|
||||
.get(DELEGATE_REPAINT_MANAGER_KEY)) {
|
||||
while (delegate == null && component != null) {
|
||||
while (component != null
|
||||
&& ! (component instanceof JComponent)) {
|
||||
component = component.getParent();
|
||||
}
|
||||
if (component != null) {
|
||||
delegate = (RepaintManager)
|
||||
((JComponent) component)
|
||||
.getClientProperty(DELEGATE_REPAINT_MANAGER_KEY);
|
||||
component = component.getParent();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return delegate;
|
||||
}
|
||||
|
||||
/*
|
||||
* We use maps to avoid reflection. Hopefully it should perform better
|
||||
* this way.
|
||||
*/
|
||||
public static void setEventQueueDelegate(
|
||||
Map<String, Map<String, Object>> map) {
|
||||
EventQueueDelegate.setDelegate(new EventQueueDelegateFromMap(map));
|
||||
}
|
||||
|
||||
private static class EventQueueDelegateFromMap
|
||||
implements EventQueueDelegate.Delegate {
|
||||
private final AWTEvent[] afterDispatchEventArgument;
|
||||
private final Object[] afterDispatchHandleArgument;
|
||||
private final Callable<Void> afterDispatchCallable;
|
||||
|
||||
private final AWTEvent[] beforeDispatchEventArgument;
|
||||
private final Callable<Object> beforeDispatchCallable;
|
||||
|
||||
private final EventQueue[] getNextEventEventQueueArgument;
|
||||
private final Callable<AWTEvent> getNextEventCallable;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public EventQueueDelegateFromMap(Map<String, Map<String, Object>> objectMap) {
|
||||
Map<String, Object> methodMap = objectMap.get("afterDispatch");
|
||||
afterDispatchEventArgument = (AWTEvent[]) methodMap.get("event");
|
||||
afterDispatchHandleArgument = (Object[]) methodMap.get("handle");
|
||||
afterDispatchCallable = (Callable<Void>) methodMap.get("method");
|
||||
|
||||
methodMap = objectMap.get("beforeDispatch");
|
||||
beforeDispatchEventArgument = (AWTEvent[]) methodMap.get("event");
|
||||
beforeDispatchCallable = (Callable<Object>) methodMap.get("method");
|
||||
|
||||
methodMap = objectMap.get("getNextEvent");
|
||||
getNextEventEventQueueArgument =
|
||||
(EventQueue[]) methodMap.get("eventQueue");
|
||||
getNextEventCallable = (Callable<AWTEvent>) methodMap.get("method");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterDispatch(AWTEvent event, Object handle) throws InterruptedException {
|
||||
afterDispatchEventArgument[0] = event;
|
||||
afterDispatchHandleArgument[0] = handle;
|
||||
try {
|
||||
afterDispatchCallable.call();
|
||||
} catch (InterruptedException e) {
|
||||
throw e;
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object beforeDispatch(AWTEvent event) throws InterruptedException {
|
||||
beforeDispatchEventArgument[0] = event;
|
||||
try {
|
||||
return beforeDispatchCallable.call();
|
||||
} catch (InterruptedException e) {
|
||||
throw e;
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AWTEvent getNextEvent(EventQueue eventQueue) throws InterruptedException {
|
||||
getNextEventEventQueueArgument[0] = eventQueue;
|
||||
try {
|
||||
return getNextEventCallable.call();
|
||||
} catch (InterruptedException e) {
|
||||
throw e;
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1303
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKColorChooserPanel.java
Normal file
1303
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKColorChooserPanel.java
Normal file
File diff suppressed because it is too large
Load Diff
167
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKColorType.java
Normal file
167
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKColorType.java
Normal file
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 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 com.sun.java.swing.plaf.gtk;
|
||||
|
||||
import javax.swing.plaf.synth.ColorType;
|
||||
import java.awt.Color;
|
||||
import javax.swing.plaf.ColorUIResource;
|
||||
|
||||
/**
|
||||
* @author Scott Violet
|
||||
*/
|
||||
public class GTKColorType extends ColorType {
|
||||
// GTK allows you to specify the foreground and background in a
|
||||
// gtkrc, the rest (dark, mid, light) are calculated from these
|
||||
// values.
|
||||
public static final ColorType LIGHT = new GTKColorType("Light");
|
||||
public static final ColorType DARK = new GTKColorType("Dark");
|
||||
public static final ColorType MID = new GTKColorType("Mid");
|
||||
public static final ColorType BLACK = new GTKColorType("Black");
|
||||
public static final ColorType WHITE = new GTKColorType("White");
|
||||
|
||||
public static final int MAX_COUNT;
|
||||
|
||||
private static final float[] HLS_COLORS = new float[3];
|
||||
private static final Object HLS_COLOR_LOCK = new Object();
|
||||
|
||||
static {
|
||||
MAX_COUNT = WHITE.getID() + 1;
|
||||
}
|
||||
|
||||
private static int hlsToRGB(float h, float l, float s) {
|
||||
float m2 = (l <= .5f) ? (l * (1 + s)) : (l + s - l * s);
|
||||
float m1 = 2.0f * l - m2;
|
||||
float r, g, b;
|
||||
|
||||
if (s == 0.0) {
|
||||
if (h == 0.0) {
|
||||
r = g = b = l;
|
||||
}
|
||||
else {
|
||||
r = g = b = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
r = hlsValue(m1, m2, h + 120);
|
||||
g = hlsValue(m1, m2, h);
|
||||
b = hlsValue(m1, m2, h - 120);
|
||||
}
|
||||
return (((int)(r * 255)) << 16) | (((int)(g * 255.0)) << 8) |
|
||||
((int)(b * 255));
|
||||
}
|
||||
|
||||
private static float hlsValue(float n1, float n2, float h) {
|
||||
if (h > 360) {
|
||||
h -= 360;
|
||||
}
|
||||
else if (h < 0) {
|
||||
h += 360;
|
||||
}
|
||||
if (h < 60) {
|
||||
return n1 + (n2 - n1) * h / 60.0f;
|
||||
}
|
||||
else if (h < 180) {
|
||||
return n2;
|
||||
}
|
||||
else if (h < 240) {
|
||||
return n1 + (n2 - n1) * (240.0f - h) / 60.0f;
|
||||
}
|
||||
return n1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts from RGB color space to HLS colorspace.
|
||||
*/
|
||||
private static float[] rgbToHLS(int rgb, float[] hls) {
|
||||
float r = ((rgb & 0xFF0000) >> 16) / 255.0f;
|
||||
float g = ((rgb & 0xFF00) >> 8) / 255.0f;
|
||||
float b = (rgb & 0xFF) / 255.0f;
|
||||
|
||||
/* calculate lightness */
|
||||
float max = Math.max(Math.max(r, g), b);
|
||||
float min = Math.min(Math.min(r, g), b);
|
||||
float l = (max + min) / 2.0f;
|
||||
float s = 0;
|
||||
float h = 0;
|
||||
|
||||
if (max != min) {
|
||||
float delta = max - min;
|
||||
s = (l <= .5f) ? (delta / (max + min)) : (delta / (2.0f - max -min));
|
||||
if (r == max) {
|
||||
h = (g - b) / delta;
|
||||
}
|
||||
else if (g == max) {
|
||||
h = 2.0f + (b - r) / delta;
|
||||
}
|
||||
else {
|
||||
h = 4.0f + (r - g) / delta;
|
||||
}
|
||||
h *= 60.0f;
|
||||
if (h < 0) {
|
||||
h += 360.0f;
|
||||
}
|
||||
}
|
||||
if (hls == null) {
|
||||
hls = new float[3];
|
||||
}
|
||||
hls[0] = h;
|
||||
hls[1] = l;
|
||||
hls[2] = s;
|
||||
return hls;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a new color derived from the passed in color.
|
||||
* The transformation is done in the HLS color space using the specified
|
||||
* arguments to scale.
|
||||
*
|
||||
* @param color Color to alter
|
||||
* @param hFactory Amount to scale the hue
|
||||
* @param lFactor Amount to scale the lightness
|
||||
* @param sFactory Amount to sacle saturation
|
||||
* @return newly created color
|
||||
*/
|
||||
static Color adjustColor(Color color, float hFactor, float lFactor,
|
||||
float sFactor) {
|
||||
float h;
|
||||
float l;
|
||||
float s;
|
||||
|
||||
synchronized(HLS_COLOR_LOCK) {
|
||||
float[] hls = rgbToHLS(color.getRGB(), HLS_COLORS);
|
||||
h = hls[0];
|
||||
l = hls[1];
|
||||
s = hls[2];
|
||||
}
|
||||
h = Math.min(360, hFactor * h);
|
||||
l = Math.min(1, lFactor * l);
|
||||
s = Math.min(1, sFactor * s);
|
||||
return new ColorUIResource(hlsToRGB(h, l, s));
|
||||
}
|
||||
|
||||
protected GTKColorType(String name) {
|
||||
super(name);
|
||||
}
|
||||
}
|
||||
118
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKConstants.java
Normal file
118
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKConstants.java
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 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 com.sun.java.swing.plaf.gtk;
|
||||
|
||||
/**
|
||||
* @author Scott Violet
|
||||
*/
|
||||
public interface GTKConstants {
|
||||
|
||||
/**
|
||||
* Used to indicate a constant is not defined.
|
||||
*/
|
||||
public static final int UNDEFINED = -100;
|
||||
|
||||
/**
|
||||
* Java representation of native GtkIconSize enum
|
||||
*/
|
||||
public enum IconSize {
|
||||
INVALID,
|
||||
MENU,
|
||||
SMALL_TOOLBAR,
|
||||
LARGE_TOOLBAR,
|
||||
BUTTON,
|
||||
DND,
|
||||
DIALOG
|
||||
}
|
||||
|
||||
/**
|
||||
* Java representation of native GtkTextDirection enum
|
||||
*/
|
||||
public enum TextDirection {
|
||||
NONE,
|
||||
LTR,
|
||||
RTL
|
||||
}
|
||||
|
||||
/**
|
||||
* Java representation of native GtkShadowType enum
|
||||
*/
|
||||
public enum ShadowType {
|
||||
NONE,
|
||||
IN,
|
||||
OUT,
|
||||
ETCHED_IN,
|
||||
ETCHED_OUT
|
||||
}
|
||||
|
||||
/**
|
||||
* Java representation of native GtkStateType enum
|
||||
*/
|
||||
public enum StateType {
|
||||
NORMAL,
|
||||
ACTIVE,
|
||||
PRELIGHT,
|
||||
SELECTED,
|
||||
INSENSITIVE
|
||||
}
|
||||
|
||||
/**
|
||||
* Java representation of native GtkExpanderStyle enum
|
||||
*/
|
||||
public enum ExpanderStyle {
|
||||
COLLAPSED,
|
||||
SEMI_COLLAPSED,
|
||||
SEMI_EXPANDED,
|
||||
EXPANDED,
|
||||
}
|
||||
|
||||
/**
|
||||
* Java representation of native GtkPositionType enum
|
||||
*/
|
||||
public enum PositionType {
|
||||
LEFT,
|
||||
RIGHT,
|
||||
TOP,
|
||||
BOTTOM
|
||||
}
|
||||
|
||||
/**
|
||||
* Java representation of native GtkArrowType enum
|
||||
*/
|
||||
public enum ArrowType {
|
||||
UP,
|
||||
DOWN,
|
||||
LEFT,
|
||||
RIGHT
|
||||
}
|
||||
|
||||
/**
|
||||
* Java representation of native GtkOrientation enum
|
||||
*/
|
||||
public enum Orientation {
|
||||
HORIZONTAL,
|
||||
VERTICAL
|
||||
}
|
||||
}
|
||||
646
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKEngine.java
Normal file
646
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKEngine.java
Normal file
@@ -0,0 +1,646 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 2018, 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 com.sun.java.swing.plaf.gtk;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.util.HashMap;
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.synth.*;
|
||||
|
||||
import com.sun.java.swing.plaf.gtk.GTKConstants.ArrowType;
|
||||
import com.sun.java.swing.plaf.gtk.GTKConstants.ExpanderStyle;
|
||||
import com.sun.java.swing.plaf.gtk.GTKConstants.Orientation;
|
||||
import com.sun.java.swing.plaf.gtk.GTKConstants.PositionType;
|
||||
import com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType;
|
||||
import com.sun.java.swing.plaf.gtk.GTKConstants.TextDirection;
|
||||
|
||||
import sun.awt.image.SunWritableRaster;
|
||||
import sun.swing.ImageCache;
|
||||
|
||||
/**
|
||||
* GTKEngine delegates all painting job to native GTK libraries.
|
||||
*
|
||||
* Painting with GTKEngine looks like this:
|
||||
* First, startPainting() is called. It prepares an offscreen buffer of the
|
||||
* required size.
|
||||
* Then, any number of paintXXX() methods can be called. They effectively ignore
|
||||
* the Graphics parameter and draw to the offscreen buffer.
|
||||
* Finally, finishPainting() should be called. It fills the data buffer passed
|
||||
* in with the image data.
|
||||
*
|
||||
* @author Josh Outwater
|
||||
*/
|
||||
class GTKEngine {
|
||||
|
||||
final static GTKEngine INSTANCE = new GTKEngine();
|
||||
|
||||
/** Size of the image cache */
|
||||
private static final int CACHE_SIZE = 50;
|
||||
|
||||
/** This enum mirrors that in gtk2_interface.h */
|
||||
static enum WidgetType {
|
||||
BUTTON, CHECK_BOX, CHECK_BOX_MENU_ITEM, COLOR_CHOOSER,
|
||||
COMBO_BOX, COMBO_BOX_ARROW_BUTTON, COMBO_BOX_TEXT_FIELD,
|
||||
DESKTOP_ICON, DESKTOP_PANE, EDITOR_PANE, FORMATTED_TEXT_FIELD,
|
||||
HANDLE_BOX, HPROGRESS_BAR,
|
||||
HSCROLL_BAR, HSCROLL_BAR_BUTTON_LEFT, HSCROLL_BAR_BUTTON_RIGHT,
|
||||
HSCROLL_BAR_TRACK, HSCROLL_BAR_THUMB,
|
||||
HSEPARATOR, HSLIDER, HSLIDER_TRACK, HSLIDER_THUMB, HSPLIT_PANE_DIVIDER,
|
||||
INTERNAL_FRAME, INTERNAL_FRAME_TITLE_PANE, IMAGE, LABEL, LIST, MENU,
|
||||
MENU_BAR, MENU_ITEM, MENU_ITEM_ACCELERATOR, OPTION_PANE, PANEL,
|
||||
PASSWORD_FIELD, POPUP_MENU, POPUP_MENU_SEPARATOR,
|
||||
RADIO_BUTTON, RADIO_BUTTON_MENU_ITEM, ROOT_PANE, SCROLL_PANE,
|
||||
SPINNER, SPINNER_ARROW_BUTTON, SPINNER_TEXT_FIELD,
|
||||
SPLIT_PANE, TABBED_PANE, TABBED_PANE_TAB_AREA, TABBED_PANE_CONTENT,
|
||||
TABBED_PANE_TAB, TABLE, TABLE_HEADER, TEXT_AREA, TEXT_FIELD, TEXT_PANE,
|
||||
TITLED_BORDER,
|
||||
TOGGLE_BUTTON, TOOL_BAR, TOOL_BAR_DRAG_WINDOW, TOOL_BAR_SEPARATOR,
|
||||
TOOL_TIP, TREE, TREE_CELL, VIEWPORT, VPROGRESS_BAR,
|
||||
VSCROLL_BAR, VSCROLL_BAR_BUTTON_UP, VSCROLL_BAR_BUTTON_DOWN,
|
||||
VSCROLL_BAR_TRACK, VSCROLL_BAR_THUMB,
|
||||
VSEPARATOR, VSLIDER, VSLIDER_TRACK, VSLIDER_THUMB,
|
||||
VSPLIT_PANE_DIVIDER
|
||||
}
|
||||
|
||||
/**
|
||||
* Representation of GtkSettings properties.
|
||||
* When we need more settings we can add them here and
|
||||
* to all implementations of getGTKSetting().
|
||||
*/
|
||||
static enum Settings {
|
||||
GTK_FONT_NAME,
|
||||
GTK_ICON_SIZES,
|
||||
GTK_CURSOR_BLINK,
|
||||
GTK_CURSOR_BLINK_TIME
|
||||
}
|
||||
|
||||
/* Custom regions are needed for representing regions that don't exist
|
||||
* in the original Region class.
|
||||
*/
|
||||
static class CustomRegion extends Region {
|
||||
/*
|
||||
* TITLED_BORDER Region is mapped to GtkFrame class which can draw
|
||||
* titled borders around components.
|
||||
*/
|
||||
static Region TITLED_BORDER = new CustomRegion("TitledBorder");
|
||||
|
||||
private CustomRegion(String name) {
|
||||
super(name, null, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static HashMap<Region, Object> regionToWidgetTypeMap;
|
||||
private ImageCache cache = new ImageCache(CACHE_SIZE);
|
||||
private int x0, y0, w0, h0;
|
||||
private Graphics graphics;
|
||||
private Object[] cacheArgs;
|
||||
|
||||
private native void native_paint_arrow(
|
||||
int widgetType, int state, int shadowType, String detail,
|
||||
int x, int y, int width, int height, int arrowType);
|
||||
private native void native_paint_box(
|
||||
int widgetType, int state, int shadowType, String detail,
|
||||
int x, int y, int width, int height, int synthState, int dir);
|
||||
private native void native_paint_box_gap(
|
||||
int widgetType, int state, int shadowType, String detail,
|
||||
int x, int y, int width, int height,
|
||||
int gapSide, int gapX, int gapWidth);
|
||||
private native void native_paint_check(
|
||||
int widgetType, int synthState, String detail,
|
||||
int x, int y, int width, int height);
|
||||
private native void native_paint_expander(
|
||||
int widgetType, int state, String detail,
|
||||
int x, int y, int width, int height, int expanderStyle);
|
||||
private native void native_paint_extension(
|
||||
int widgetType, int state, int shadowType, String detail,
|
||||
int x, int y, int width, int height, int placement);
|
||||
private native void native_paint_flat_box(
|
||||
int widgetType, int state, int shadowType, String detail,
|
||||
int x, int y, int width, int height, boolean hasFocus);
|
||||
private native void native_paint_focus(
|
||||
int widgetType, int state, String detail,
|
||||
int x, int y, int width, int height);
|
||||
private native void native_paint_handle(
|
||||
int widgetType, int state, int shadowType, String detail,
|
||||
int x, int y, int width, int height, int orientation);
|
||||
private native void native_paint_hline(
|
||||
int widgetType, int state, String detail,
|
||||
int x, int y, int width, int height);
|
||||
private native void native_paint_option(
|
||||
int widgetType, int synthState, String detail,
|
||||
int x, int y, int width, int height);
|
||||
private native void native_paint_shadow(
|
||||
int widgetType, int state, int shadowType, String detail,
|
||||
int x, int y, int width, int height, int synthState, int dir);
|
||||
private native void native_paint_slider(
|
||||
int widgetType, int state, int shadowType, String detail, int x,
|
||||
int y, int width, int height, int orientation, boolean hasFocus);
|
||||
private native void native_paint_vline(
|
||||
int widgetType, int state, String detail,
|
||||
int x, int y, int width, int height);
|
||||
private native void native_paint_background(
|
||||
int widgetType, int state, int x, int y, int width, int height);
|
||||
private native Object native_get_gtk_setting(int property);
|
||||
private native void nativeSetRangeValue(int widgetType, double value,
|
||||
double min, double max,
|
||||
double visible);
|
||||
|
||||
private native void nativeStartPainting(int w, int h);
|
||||
private native int nativeFinishPainting(int[] buffer, int width, int height);
|
||||
private native void native_switch_theme();
|
||||
|
||||
static {
|
||||
// Make sure the awt toolkit is loaded so we have access to native
|
||||
// methods.
|
||||
Toolkit.getDefaultToolkit();
|
||||
|
||||
// Initialize regionToWidgetTypeMap
|
||||
regionToWidgetTypeMap = new HashMap<Region, Object>(50);
|
||||
regionToWidgetTypeMap.put(Region.ARROW_BUTTON, new WidgetType[] {
|
||||
WidgetType.SPINNER_ARROW_BUTTON,
|
||||
WidgetType.COMBO_BOX_ARROW_BUTTON,
|
||||
WidgetType.HSCROLL_BAR_BUTTON_LEFT,
|
||||
WidgetType.HSCROLL_BAR_BUTTON_RIGHT,
|
||||
WidgetType.VSCROLL_BAR_BUTTON_UP,
|
||||
WidgetType.VSCROLL_BAR_BUTTON_DOWN});
|
||||
regionToWidgetTypeMap.put(Region.BUTTON, WidgetType.BUTTON);
|
||||
regionToWidgetTypeMap.put(Region.CHECK_BOX, WidgetType.CHECK_BOX);
|
||||
regionToWidgetTypeMap.put(Region.CHECK_BOX_MENU_ITEM,
|
||||
WidgetType.CHECK_BOX_MENU_ITEM);
|
||||
regionToWidgetTypeMap.put(Region.COLOR_CHOOSER, WidgetType.COLOR_CHOOSER);
|
||||
regionToWidgetTypeMap.put(Region.FILE_CHOOSER, WidgetType.OPTION_PANE);
|
||||
regionToWidgetTypeMap.put(Region.COMBO_BOX, WidgetType.COMBO_BOX);
|
||||
regionToWidgetTypeMap.put(Region.DESKTOP_ICON, WidgetType.DESKTOP_ICON);
|
||||
regionToWidgetTypeMap.put(Region.DESKTOP_PANE, WidgetType.DESKTOP_PANE);
|
||||
regionToWidgetTypeMap.put(Region.EDITOR_PANE, WidgetType.EDITOR_PANE);
|
||||
regionToWidgetTypeMap.put(Region.FORMATTED_TEXT_FIELD, new WidgetType[] {
|
||||
WidgetType.FORMATTED_TEXT_FIELD, WidgetType.SPINNER_TEXT_FIELD});
|
||||
regionToWidgetTypeMap.put(GTKRegion.HANDLE_BOX, WidgetType.HANDLE_BOX);
|
||||
regionToWidgetTypeMap.put(Region.INTERNAL_FRAME,
|
||||
WidgetType.INTERNAL_FRAME);
|
||||
regionToWidgetTypeMap.put(Region.INTERNAL_FRAME_TITLE_PANE,
|
||||
WidgetType.INTERNAL_FRAME_TITLE_PANE);
|
||||
regionToWidgetTypeMap.put(Region.LABEL, new WidgetType[] {
|
||||
WidgetType.LABEL, WidgetType.COMBO_BOX_TEXT_FIELD});
|
||||
regionToWidgetTypeMap.put(Region.LIST, WidgetType.LIST);
|
||||
regionToWidgetTypeMap.put(Region.MENU, WidgetType.MENU);
|
||||
regionToWidgetTypeMap.put(Region.MENU_BAR, WidgetType.MENU_BAR);
|
||||
regionToWidgetTypeMap.put(Region.MENU_ITEM, WidgetType.MENU_ITEM);
|
||||
regionToWidgetTypeMap.put(Region.MENU_ITEM_ACCELERATOR,
|
||||
WidgetType.MENU_ITEM_ACCELERATOR);
|
||||
regionToWidgetTypeMap.put(Region.OPTION_PANE, WidgetType.OPTION_PANE);
|
||||
regionToWidgetTypeMap.put(Region.PANEL, WidgetType.PANEL);
|
||||
regionToWidgetTypeMap.put(Region.PASSWORD_FIELD,
|
||||
WidgetType.PASSWORD_FIELD);
|
||||
regionToWidgetTypeMap.put(Region.POPUP_MENU, WidgetType.POPUP_MENU);
|
||||
regionToWidgetTypeMap.put(Region.POPUP_MENU_SEPARATOR,
|
||||
WidgetType.POPUP_MENU_SEPARATOR);
|
||||
regionToWidgetTypeMap.put(Region.PROGRESS_BAR, new WidgetType[] {
|
||||
WidgetType.HPROGRESS_BAR, WidgetType.VPROGRESS_BAR});
|
||||
regionToWidgetTypeMap.put(Region.RADIO_BUTTON, WidgetType.RADIO_BUTTON);
|
||||
regionToWidgetTypeMap.put(Region.RADIO_BUTTON_MENU_ITEM,
|
||||
WidgetType.RADIO_BUTTON_MENU_ITEM);
|
||||
regionToWidgetTypeMap.put(Region.ROOT_PANE, WidgetType.ROOT_PANE);
|
||||
regionToWidgetTypeMap.put(Region.SCROLL_BAR, new WidgetType[] {
|
||||
WidgetType.HSCROLL_BAR, WidgetType.VSCROLL_BAR});
|
||||
regionToWidgetTypeMap.put(Region.SCROLL_BAR_THUMB, new WidgetType[] {
|
||||
WidgetType.HSCROLL_BAR_THUMB, WidgetType.VSCROLL_BAR_THUMB});
|
||||
regionToWidgetTypeMap.put(Region.SCROLL_BAR_TRACK, new WidgetType[] {
|
||||
WidgetType.HSCROLL_BAR_TRACK, WidgetType.VSCROLL_BAR_TRACK});
|
||||
regionToWidgetTypeMap.put(Region.SCROLL_PANE, WidgetType.SCROLL_PANE);
|
||||
regionToWidgetTypeMap.put(Region.SEPARATOR, new WidgetType[] {
|
||||
WidgetType.HSEPARATOR, WidgetType.VSEPARATOR});
|
||||
regionToWidgetTypeMap.put(Region.SLIDER, new WidgetType[] {
|
||||
WidgetType.HSLIDER, WidgetType.VSLIDER});
|
||||
regionToWidgetTypeMap.put(Region.SLIDER_THUMB, new WidgetType[] {
|
||||
WidgetType.HSLIDER_THUMB, WidgetType.VSLIDER_THUMB});
|
||||
regionToWidgetTypeMap.put(Region.SLIDER_TRACK, new WidgetType[] {
|
||||
WidgetType.HSLIDER_TRACK, WidgetType.VSLIDER_TRACK});
|
||||
regionToWidgetTypeMap.put(Region.SPINNER, WidgetType.SPINNER);
|
||||
regionToWidgetTypeMap.put(Region.SPLIT_PANE, WidgetType.SPLIT_PANE);
|
||||
regionToWidgetTypeMap.put(Region.SPLIT_PANE_DIVIDER, new WidgetType[] {
|
||||
WidgetType.HSPLIT_PANE_DIVIDER, WidgetType.VSPLIT_PANE_DIVIDER});
|
||||
regionToWidgetTypeMap.put(Region.TABBED_PANE, WidgetType.TABBED_PANE);
|
||||
regionToWidgetTypeMap.put(Region.TABBED_PANE_CONTENT,
|
||||
WidgetType.TABBED_PANE_CONTENT);
|
||||
regionToWidgetTypeMap.put(Region.TABBED_PANE_TAB,
|
||||
WidgetType.TABBED_PANE_TAB);
|
||||
regionToWidgetTypeMap.put(Region.TABBED_PANE_TAB_AREA,
|
||||
WidgetType.TABBED_PANE_TAB_AREA);
|
||||
regionToWidgetTypeMap.put(Region.TABLE, WidgetType.TABLE);
|
||||
regionToWidgetTypeMap.put(Region.TABLE_HEADER, WidgetType.TABLE_HEADER);
|
||||
regionToWidgetTypeMap.put(Region.TEXT_AREA, WidgetType.TEXT_AREA);
|
||||
regionToWidgetTypeMap.put(Region.TEXT_FIELD, new WidgetType[] {
|
||||
WidgetType.TEXT_FIELD, WidgetType.COMBO_BOX_TEXT_FIELD});
|
||||
regionToWidgetTypeMap.put(Region.TEXT_PANE, WidgetType.TEXT_PANE);
|
||||
regionToWidgetTypeMap.put(CustomRegion.TITLED_BORDER, WidgetType.TITLED_BORDER);
|
||||
regionToWidgetTypeMap.put(Region.TOGGLE_BUTTON, WidgetType.TOGGLE_BUTTON);
|
||||
regionToWidgetTypeMap.put(Region.TOOL_BAR, WidgetType.TOOL_BAR);
|
||||
regionToWidgetTypeMap.put(Region.TOOL_BAR_CONTENT, WidgetType.TOOL_BAR);
|
||||
regionToWidgetTypeMap.put(Region.TOOL_BAR_DRAG_WINDOW,
|
||||
WidgetType.TOOL_BAR_DRAG_WINDOW);
|
||||
regionToWidgetTypeMap.put(Region.TOOL_BAR_SEPARATOR,
|
||||
WidgetType.TOOL_BAR_SEPARATOR);
|
||||
regionToWidgetTypeMap.put(Region.TOOL_TIP, WidgetType.TOOL_TIP);
|
||||
regionToWidgetTypeMap.put(Region.TREE, WidgetType.TREE);
|
||||
regionToWidgetTypeMap.put(Region.TREE_CELL, WidgetType.TREE_CELL);
|
||||
regionToWidgetTypeMap.put(Region.VIEWPORT, WidgetType.VIEWPORT);
|
||||
}
|
||||
|
||||
/** Translate Region and JComponent into WidgetType ordinals */
|
||||
static WidgetType getWidgetType(JComponent c, Region id) {
|
||||
Object value = regionToWidgetTypeMap.get(id);
|
||||
|
||||
if (value instanceof WidgetType) {
|
||||
return (WidgetType)value;
|
||||
}
|
||||
|
||||
WidgetType[] widgets = (WidgetType[])value;
|
||||
if (c == null ) {
|
||||
return widgets[0];
|
||||
}
|
||||
|
||||
if (c instanceof JScrollBar) {
|
||||
return (((JScrollBar)c).getOrientation() == JScrollBar.HORIZONTAL) ?
|
||||
widgets[0] : widgets[1];
|
||||
} else if (c instanceof JSeparator) {
|
||||
JSeparator separator = (JSeparator)c;
|
||||
|
||||
/* We should return correrct WidgetType if the seperator is inserted
|
||||
* in Menu/PopupMenu/ToolBar. BugID: 6465603
|
||||
*/
|
||||
if (separator.getParent() instanceof JPopupMenu) {
|
||||
return WidgetType.POPUP_MENU_SEPARATOR;
|
||||
} else if (separator.getParent() instanceof JToolBar) {
|
||||
return WidgetType.TOOL_BAR_SEPARATOR;
|
||||
}
|
||||
|
||||
return (separator.getOrientation() == JSeparator.HORIZONTAL) ?
|
||||
widgets[0] : widgets[1];
|
||||
} else if (c instanceof JSlider) {
|
||||
return (((JSlider)c).getOrientation() == JSlider.HORIZONTAL) ?
|
||||
widgets[0] : widgets[1];
|
||||
} else if (c instanceof JProgressBar) {
|
||||
return (((JProgressBar)c).getOrientation() == JProgressBar.HORIZONTAL) ?
|
||||
widgets[0] : widgets[1];
|
||||
} else if (c instanceof JSplitPane) {
|
||||
return (((JSplitPane)c).getOrientation() == JSplitPane.HORIZONTAL_SPLIT) ?
|
||||
widgets[1] : widgets[0];
|
||||
} else if (id == Region.LABEL) {
|
||||
/*
|
||||
* For all ListCellRenderers we will use COMBO_BOX_TEXT_FIELD widget
|
||||
* type because we can get correct insets. List items however won't be
|
||||
* drawn as a text entry (see GTKPainter.paintLabelBackground).
|
||||
*/
|
||||
if (c instanceof ListCellRenderer) {
|
||||
return widgets[1];
|
||||
} else {
|
||||
return widgets[0];
|
||||
}
|
||||
} else if (id == Region.TEXT_FIELD) {
|
||||
String name = c.getName();
|
||||
if (name != null && name.startsWith("ComboBox")) {
|
||||
return widgets[1];
|
||||
} else {
|
||||
return widgets[0];
|
||||
}
|
||||
} else if (id == Region.FORMATTED_TEXT_FIELD) {
|
||||
String name = c.getName();
|
||||
if (name != null && name.startsWith("Spinner")) {
|
||||
return widgets[1];
|
||||
} else {
|
||||
return widgets[0];
|
||||
}
|
||||
} else if (id == Region.ARROW_BUTTON) {
|
||||
if (c.getParent() instanceof JScrollBar) {
|
||||
Integer prop = (Integer)
|
||||
c.getClientProperty("__arrow_direction__");
|
||||
int dir = (prop != null) ?
|
||||
prop.intValue() : SwingConstants.WEST;
|
||||
switch (dir) {
|
||||
case SwingConstants.WEST:
|
||||
return WidgetType.HSCROLL_BAR_BUTTON_LEFT;
|
||||
case SwingConstants.EAST:
|
||||
return WidgetType.HSCROLL_BAR_BUTTON_RIGHT;
|
||||
case SwingConstants.NORTH:
|
||||
return WidgetType.VSCROLL_BAR_BUTTON_UP;
|
||||
case SwingConstants.SOUTH:
|
||||
return WidgetType.VSCROLL_BAR_BUTTON_DOWN;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
} else if (c.getParent() instanceof JComboBox) {
|
||||
return WidgetType.COMBO_BOX_ARROW_BUTTON;
|
||||
} else {
|
||||
return WidgetType.SPINNER_ARROW_BUTTON;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static int getTextDirection(SynthContext context) {
|
||||
TextDirection dir = TextDirection.NONE;
|
||||
JComponent comp = context.getComponent();
|
||||
if (comp != null) {
|
||||
ComponentOrientation co = comp.getComponentOrientation();
|
||||
if (co != null) {
|
||||
dir = co.isLeftToRight() ?
|
||||
TextDirection.LTR : TextDirection.RTL;
|
||||
}
|
||||
}
|
||||
return dir.ordinal();
|
||||
}
|
||||
|
||||
public void paintArrow(Graphics g, SynthContext context,
|
||||
Region id, int state, ShadowType shadowType, ArrowType direction,
|
||||
String detail, int x, int y, int w, int h) {
|
||||
|
||||
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
|
||||
int widget = getWidgetType(context.getComponent(), id).ordinal();
|
||||
native_paint_arrow(widget, state, shadowType.ordinal(),
|
||||
detail, x - x0, y - y0, w, h, direction.ordinal());
|
||||
}
|
||||
|
||||
public void paintBox(Graphics g, SynthContext context,
|
||||
Region id, int state, ShadowType shadowType,
|
||||
String detail, int x, int y, int w, int h) {
|
||||
|
||||
int gtkState =
|
||||
GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
|
||||
int synthState = context.getComponentState();
|
||||
int dir = getTextDirection(context);
|
||||
int widget = getWidgetType(context.getComponent(), id).ordinal();
|
||||
native_paint_box(widget, gtkState, shadowType.ordinal(),
|
||||
detail, x - x0, y - y0, w, h, synthState, dir);
|
||||
}
|
||||
|
||||
public void paintBoxGap(Graphics g, SynthContext context,
|
||||
Region id, int state, ShadowType shadowType,
|
||||
String detail, int x, int y, int w, int h,
|
||||
PositionType boxGapType, int tabBegin, int size) {
|
||||
|
||||
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
|
||||
int widget = getWidgetType(context.getComponent(), id).ordinal();
|
||||
native_paint_box_gap(widget, state, shadowType.ordinal(), detail,
|
||||
x - x0, y - y0, w, h, boxGapType.ordinal(), tabBegin, size);
|
||||
}
|
||||
|
||||
public void paintCheck(Graphics g, SynthContext context,
|
||||
Region id, String detail, int x, int y, int w, int h) {
|
||||
|
||||
int synthState = context.getComponentState();
|
||||
int widget = getWidgetType(context.getComponent(), id).ordinal();
|
||||
native_paint_check(widget, synthState, detail, x - x0, y - y0, w, h);
|
||||
}
|
||||
|
||||
public void paintExpander(Graphics g, SynthContext context,
|
||||
Region id, int state, ExpanderStyle expanderStyle, String detail,
|
||||
int x, int y, int w, int h) {
|
||||
|
||||
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
|
||||
int widget = getWidgetType(context.getComponent(), id).ordinal();
|
||||
native_paint_expander(widget, state, detail, x - x0, y - y0, w, h,
|
||||
expanderStyle.ordinal());
|
||||
}
|
||||
|
||||
public void paintExtension(Graphics g, SynthContext context,
|
||||
Region id, int state, ShadowType shadowType, String detail,
|
||||
int x, int y, int w, int h, PositionType placement, int tabIndex) {
|
||||
|
||||
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
|
||||
int widget = getWidgetType(context.getComponent(), id).ordinal();
|
||||
native_paint_extension(widget, state, shadowType.ordinal(), detail,
|
||||
x - x0, y - y0, w, h, placement.ordinal());
|
||||
}
|
||||
|
||||
public void paintFlatBox(Graphics g, SynthContext context,
|
||||
Region id, int state, ShadowType shadowType, String detail,
|
||||
int x, int y, int w, int h, ColorType colorType) {
|
||||
|
||||
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
|
||||
int widget = getWidgetType(context.getComponent(), id).ordinal();
|
||||
native_paint_flat_box(widget, state, shadowType.ordinal(), detail,
|
||||
x - x0, y - y0, w, h,
|
||||
context.getComponent().hasFocus());
|
||||
}
|
||||
|
||||
public void paintFocus(Graphics g, SynthContext context,
|
||||
Region id, int state, String detail, int x, int y, int w, int h) {
|
||||
|
||||
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
|
||||
int widget = getWidgetType(context.getComponent(), id).ordinal();
|
||||
native_paint_focus(widget, state, detail, x - x0, y - y0, w, h);
|
||||
}
|
||||
|
||||
public void paintHandle(Graphics g, SynthContext context,
|
||||
Region id, int state, ShadowType shadowType, String detail,
|
||||
int x, int y, int w, int h, Orientation orientation) {
|
||||
|
||||
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
|
||||
int widget = getWidgetType(context.getComponent(), id).ordinal();
|
||||
native_paint_handle(widget, state, shadowType.ordinal(), detail,
|
||||
x - x0, y - y0, w, h, orientation.ordinal());
|
||||
}
|
||||
|
||||
public void paintHline(Graphics g, SynthContext context,
|
||||
Region id, int state, String detail, int x, int y, int w, int h) {
|
||||
|
||||
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
|
||||
int widget = getWidgetType(context.getComponent(), id).ordinal();
|
||||
native_paint_hline(widget, state, detail, x - x0, y - y0, w, h);
|
||||
}
|
||||
|
||||
public void paintOption(Graphics g, SynthContext context,
|
||||
Region id, String detail, int x, int y, int w, int h) {
|
||||
|
||||
int synthState = context.getComponentState();
|
||||
int widget = getWidgetType(context.getComponent(), id).ordinal();
|
||||
native_paint_option(widget, synthState, detail, x - x0, y - y0, w, h);
|
||||
}
|
||||
|
||||
public void paintShadow(Graphics g, SynthContext context,
|
||||
Region id, int state, ShadowType shadowType, String detail,
|
||||
int x, int y, int w, int h) {
|
||||
|
||||
int gtkState =
|
||||
GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
|
||||
int synthState = context.getComponentState();
|
||||
Container parent = context.getComponent().getParent();
|
||||
if(GTKLookAndFeel.is3()) {
|
||||
if (parent != null && parent.getParent() instanceof JComboBox) {
|
||||
if (parent.getParent().hasFocus()) {
|
||||
synthState |= SynthConstants.FOCUSED;
|
||||
}
|
||||
}
|
||||
}
|
||||
int dir = getTextDirection(context);
|
||||
int widget = getWidgetType(context.getComponent(), id).ordinal();
|
||||
native_paint_shadow(widget, gtkState, shadowType.ordinal(), detail,
|
||||
x - x0, y - y0, w, h, synthState, dir);
|
||||
}
|
||||
|
||||
public void paintSlider(Graphics g, SynthContext context,
|
||||
Region id, int state, ShadowType shadowType, String detail, int x,
|
||||
int y, int w, int h, Orientation orientation, boolean hasFocus) {
|
||||
|
||||
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
|
||||
int widget = getWidgetType(context.getComponent(), id).ordinal();
|
||||
native_paint_slider(widget, state, shadowType.ordinal(), detail,
|
||||
x - x0, y - y0, w, h, orientation.ordinal(), hasFocus);
|
||||
}
|
||||
|
||||
public void paintVline(Graphics g, SynthContext context,
|
||||
Region id, int state, String detail, int x, int y, int w, int h) {
|
||||
|
||||
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
|
||||
int widget = getWidgetType(context.getComponent(), id).ordinal();
|
||||
native_paint_vline(widget, state, detail, x - x0, y - y0, w, h);
|
||||
}
|
||||
|
||||
public void paintBackground(Graphics g, SynthContext context,
|
||||
Region id, int state, Color color, int x, int y, int w, int h) {
|
||||
|
||||
state = GTKLookAndFeel.synthStateToGTKStateType(state).ordinal();
|
||||
int widget = getWidgetType(context.getComponent(), id).ordinal();
|
||||
native_paint_background(widget, state, x - x0, y - y0, w, h);
|
||||
}
|
||||
|
||||
private final static ColorModel[] COLOR_MODELS = {
|
||||
// Transparency.OPAQUE
|
||||
new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000),
|
||||
// Transparency.BITMASK
|
||||
new DirectColorModel(25, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x01000000),
|
||||
// Transparency.TRANSLUCENT
|
||||
ColorModel.getRGBdefault(),
|
||||
};
|
||||
|
||||
private final static int[][] BAND_OFFSETS = {
|
||||
{ 0x00ff0000, 0x0000ff00, 0x000000ff }, // OPAQUE
|
||||
{ 0x00ff0000, 0x0000ff00, 0x000000ff, 0x01000000 }, // BITMASK
|
||||
{ 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 } // TRANSLUCENT
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Paint a cached image identified by its size and a set of additional
|
||||
* arguments, if there's one.
|
||||
*
|
||||
* @return true if a cached image has been painted, false otherwise
|
||||
*/
|
||||
public boolean paintCachedImage(Graphics g,
|
||||
int x, int y, int w, int h, Object... args) {
|
||||
if (w <= 0 || h <= 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// look for cached image
|
||||
Image img = cache.getImage(getClass(), null, w, h, args);
|
||||
if (img != null) {
|
||||
g.drawImage(img, x, y, null);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a native offscreen buffer of the specified size.
|
||||
*/
|
||||
public void startPainting(Graphics g,
|
||||
int x, int y, int w, int h, Object... args) {
|
||||
nativeStartPainting(w, h);
|
||||
x0 = x;
|
||||
y0 = y;
|
||||
w0 = w;
|
||||
h0 = h;
|
||||
graphics = g;
|
||||
cacheArgs = args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method that delegates to finishPainting() with
|
||||
* caching enabled.
|
||||
*/
|
||||
public BufferedImage finishPainting() {
|
||||
return finishPainting(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to indicate that painting is finished. We create a new
|
||||
* BufferedImage from the offscreen buffer, (optionally) cache it,
|
||||
* and paint it.
|
||||
*/
|
||||
public BufferedImage finishPainting(boolean useCache) {
|
||||
DataBufferInt dataBuffer = new DataBufferInt(w0 * h0);
|
||||
// Note that stealData() requires a markDirty() afterwards
|
||||
// since we modify the data in it.
|
||||
int transparency =
|
||||
nativeFinishPainting(SunWritableRaster.stealData(dataBuffer, 0),
|
||||
w0, h0);
|
||||
SunWritableRaster.markDirty(dataBuffer);
|
||||
|
||||
int[] bands = BAND_OFFSETS[transparency - 1];
|
||||
WritableRaster raster = Raster.createPackedRaster(
|
||||
dataBuffer, w0, h0, w0, bands, null);
|
||||
|
||||
ColorModel cm = COLOR_MODELS[transparency - 1];
|
||||
BufferedImage img = new BufferedImage(cm, raster, false, null);
|
||||
if (useCache) {
|
||||
cache.setImage(getClass(), null, w0, h0, cacheArgs, img);
|
||||
}
|
||||
graphics.drawImage(img, x0, y0, null);
|
||||
return img;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify native layer of theme change, and flush cache
|
||||
*/
|
||||
public void themeChanged() {
|
||||
synchronized(sun.awt.UNIXToolkit.GTK_LOCK) {
|
||||
native_switch_theme();
|
||||
}
|
||||
cache.flush();
|
||||
}
|
||||
|
||||
/* GtkSettings enum mirrors that in gtk2_interface.h */
|
||||
public Object getSetting(Settings property) {
|
||||
synchronized(sun.awt.UNIXToolkit.GTK_LOCK) {
|
||||
return native_get_gtk_setting(property.ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the GtkAdjustment values for the native GtkRange widget
|
||||
* associated with the given region (e.g. SLIDER, SCROLL_BAR).
|
||||
*/
|
||||
void setRangeValue(SynthContext context, Region id,
|
||||
double value, double min, double max, double visible) {
|
||||
int widget = getWidgetType(context.getComponent(), id).ordinal();
|
||||
nativeSetRangeValue(widget, value, min, max, visible);
|
||||
}
|
||||
}
|
||||
1402
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java
Normal file
1402
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKFileChooserUI.java
Normal file
File diff suppressed because it is too large
Load Diff
127
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKGraphicsUtils.java
Normal file
127
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKGraphicsUtils.java
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2018, 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 com.sun.java.swing.plaf.gtk;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.synth.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
/**
|
||||
* @author Joshua Outwater
|
||||
*/
|
||||
class GTKGraphicsUtils extends SynthGraphicsUtils {
|
||||
public void paintText(SynthContext context, Graphics g, String text,
|
||||
int x, int y, int mnemonicIndex) {
|
||||
if (text == null || text.length() <= 0) {
|
||||
// We don't need to paint empty strings
|
||||
return;
|
||||
}
|
||||
|
||||
if (context.getRegion() == Region.INTERNAL_FRAME_TITLE_PANE) {
|
||||
// Metacity handles painting of text on internal frame title,
|
||||
// ignore this.
|
||||
return;
|
||||
}
|
||||
int componentState = context.getComponentState();
|
||||
String themeName = GTKLookAndFeel.getGtkThemeName();
|
||||
if (themeName != null && themeName.startsWith("blueprint") &&
|
||||
shouldShadowText(context.getRegion(), componentState)) {
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
super.paintText(context, g, text, x+1, y+1, mnemonicIndex);
|
||||
g.setColor(Color.WHITE);
|
||||
}
|
||||
super.paintText(context, g, text, x, y, mnemonicIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints text at the specified location. This will not attempt to
|
||||
* render the text as html nor will it offset by the insets of the
|
||||
* component.
|
||||
*
|
||||
* @param ss SynthContext
|
||||
* @param g Graphics used to render string in.
|
||||
* @param text Text to render
|
||||
* @param bounds Bounds of the text to be drawn.
|
||||
* @param mnemonicIndex Index to draw string at.
|
||||
*/
|
||||
public void paintText(SynthContext context, Graphics g, String text,
|
||||
Rectangle bounds, int mnemonicIndex) {
|
||||
if (text == null || text.length() <= 0) {
|
||||
// We don't need to paint empty strings
|
||||
return;
|
||||
}
|
||||
|
||||
Region id = context.getRegion();
|
||||
if ((id == Region.RADIO_BUTTON ||
|
||||
id == Region.CHECK_BOX ||
|
||||
id == Region.TABBED_PANE_TAB) &&
|
||||
(context.getComponentState() & SynthConstants.FOCUSED) != 0)
|
||||
{
|
||||
JComponent source = context.getComponent();
|
||||
if (!(source instanceof AbstractButton) ||
|
||||
((AbstractButton)source).isFocusPainted()) {
|
||||
|
||||
// The "bounds" parameter encompasses only the actual text;
|
||||
// when drawing the focus, we need to expand that bounding
|
||||
// box by "focus-line-width" plus "focus-padding". Note that
|
||||
// the layout process for these components will have already
|
||||
// taken these values into account, so there should always
|
||||
// be enough space allocated for drawing the focus indicator.
|
||||
int synthState = context.getComponentState();
|
||||
GTKStyle style = (GTKStyle)context.getStyle();
|
||||
int focusSize =
|
||||
style.getClassSpecificIntValue(context,
|
||||
"focus-line-width", 1);
|
||||
int focusPad =
|
||||
style.getClassSpecificIntValue(context,
|
||||
"focus-padding", 1);
|
||||
int totalFocus = focusSize + focusPad;
|
||||
int x = bounds.x - totalFocus;
|
||||
int y = bounds.y - totalFocus;
|
||||
int w = bounds.width + (2 * totalFocus);
|
||||
int h = bounds.height + (2 * totalFocus);
|
||||
|
||||
Color color = g.getColor();
|
||||
GTKPainter.INSTANCE.paintFocus(context, g, id,
|
||||
synthState, "checkbutton",
|
||||
x, y, w, h);
|
||||
g.setColor(color);
|
||||
}
|
||||
}
|
||||
super.paintText(context, g, text, bounds, mnemonicIndex);
|
||||
}
|
||||
|
||||
private static boolean shouldShadowText(Region id, int state) {
|
||||
int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
|
||||
return((gtkState == SynthConstants.MOUSE_OVER) &&
|
||||
(id == Region.MENU ||
|
||||
id == Region.MENU_ITEM ||
|
||||
id == Region.CHECK_BOX_MENU_ITEM ||
|
||||
id == Region.RADIO_BUTTON_MENU_ITEM));
|
||||
}
|
||||
}
|
||||
363
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKIconFactory.java
Normal file
363
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKIconFactory.java
Normal file
@@ -0,0 +1,363 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2018, 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 com.sun.java.swing.plaf.gtk;
|
||||
|
||||
import java.util.*;
|
||||
import javax.swing.plaf.synth.*;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.lang.reflect.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.*;
|
||||
import sun.swing.plaf.synth.*;
|
||||
import com.sun.java.swing.plaf.gtk.GTKConstants.ArrowType;
|
||||
import com.sun.java.swing.plaf.gtk.GTKConstants.ExpanderStyle;
|
||||
import com.sun.java.swing.plaf.gtk.GTKConstants.Orientation;
|
||||
import com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType;
|
||||
|
||||
/**
|
||||
*/
|
||||
class GTKIconFactory {
|
||||
static final int CHECK_ICON_EXTRA_INSET = 1;
|
||||
static final int DEFAULT_ICON_SPACING = 2;
|
||||
static final int DEFAULT_ICON_SIZE = 13;
|
||||
static final int DEFAULT_TOGGLE_MENU_ITEM_SIZE = 12; // For pre-gtk2.4
|
||||
|
||||
private static final String RADIO_BUTTON_ICON = "paintRadioButtonIcon";
|
||||
private static final String CHECK_BOX_ICON = "paintCheckBoxIcon";
|
||||
private static final String MENU_ARROW_ICON = "paintMenuArrowIcon";
|
||||
private static final String CHECK_BOX_MENU_ITEM_CHECK_ICON =
|
||||
"paintCheckBoxMenuItemCheckIcon";
|
||||
private static final String RADIO_BUTTON_MENU_ITEM_CHECK_ICON =
|
||||
"paintRadioButtonMenuItemCheckIcon";
|
||||
private static final String TREE_EXPANDED_ICON = "paintTreeExpandedIcon";
|
||||
private static final String TREE_COLLAPSED_ICON = "paintTreeCollapsedIcon";
|
||||
private static final String ASCENDING_SORT_ICON = "paintAscendingSortIcon";
|
||||
private static final String DESCENDING_SORT_ICON = "paintDescendingSortIcon";
|
||||
private static final String TOOL_BAR_HANDLE_ICON = "paintToolBarHandleIcon";
|
||||
|
||||
private static Map<String, DelegatingIcon> iconsPool =
|
||||
Collections.synchronizedMap(new HashMap<String, DelegatingIcon>());
|
||||
|
||||
private static DelegatingIcon getIcon(String methodName) {
|
||||
DelegatingIcon result = iconsPool.get(methodName);
|
||||
if (result == null) {
|
||||
if (methodName == TREE_COLLAPSED_ICON ||
|
||||
methodName == TREE_EXPANDED_ICON)
|
||||
{
|
||||
result = new SynthExpanderIcon(methodName);
|
||||
|
||||
} else if (methodName == TOOL_BAR_HANDLE_ICON) {
|
||||
result = new ToolBarHandleIcon();
|
||||
|
||||
} else if (methodName == MENU_ARROW_ICON) {
|
||||
result = new MenuArrowIcon();
|
||||
|
||||
} else {
|
||||
result = new DelegatingIcon(methodName);
|
||||
}
|
||||
iconsPool.put(methodName, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Sort arrow
|
||||
//
|
||||
public static Icon getAscendingSortIcon() {
|
||||
return getIcon(ASCENDING_SORT_ICON);
|
||||
}
|
||||
|
||||
public static Icon getDescendingSortIcon() {
|
||||
return getIcon(DESCENDING_SORT_ICON);
|
||||
}
|
||||
|
||||
//
|
||||
// Tree methods
|
||||
//
|
||||
public static SynthIcon getTreeExpandedIcon() {
|
||||
return getIcon(TREE_EXPANDED_ICON);
|
||||
}
|
||||
|
||||
public static SynthIcon getTreeCollapsedIcon() {
|
||||
return getIcon(TREE_COLLAPSED_ICON);
|
||||
}
|
||||
|
||||
//
|
||||
// Radio button
|
||||
//
|
||||
public static SynthIcon getRadioButtonIcon() {
|
||||
return getIcon(RADIO_BUTTON_ICON);
|
||||
}
|
||||
|
||||
//
|
||||
// CheckBox
|
||||
//
|
||||
public static SynthIcon getCheckBoxIcon() {
|
||||
return getIcon(CHECK_BOX_ICON);
|
||||
}
|
||||
|
||||
//
|
||||
// Menus
|
||||
//
|
||||
public static SynthIcon getMenuArrowIcon() {
|
||||
return getIcon(MENU_ARROW_ICON);
|
||||
}
|
||||
|
||||
public static SynthIcon getCheckBoxMenuItemCheckIcon() {
|
||||
return getIcon(CHECK_BOX_MENU_ITEM_CHECK_ICON);
|
||||
}
|
||||
|
||||
public static SynthIcon getRadioButtonMenuItemCheckIcon() {
|
||||
return getIcon(RADIO_BUTTON_MENU_ITEM_CHECK_ICON);
|
||||
}
|
||||
|
||||
//
|
||||
// ToolBar Handle
|
||||
//
|
||||
public static SynthIcon getToolBarHandleIcon() {
|
||||
return getIcon(TOOL_BAR_HANDLE_ICON);
|
||||
}
|
||||
|
||||
static void resetIcons() {
|
||||
synchronized (iconsPool) {
|
||||
for (DelegatingIcon di: iconsPool.values()) {
|
||||
di.resetIconDimensions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class DelegatingIcon extends SynthIcon implements
|
||||
UIResource {
|
||||
private static final Class[] PARAM_TYPES = new Class[] {
|
||||
SynthContext.class, Graphics.class, int.class,
|
||||
int.class, int.class, int.class, int.class
|
||||
};
|
||||
|
||||
private Object method;
|
||||
int iconDimension = -1;
|
||||
|
||||
DelegatingIcon(String methodName ){
|
||||
this.method = methodName;
|
||||
}
|
||||
|
||||
public void paintIcon(SynthContext context, Graphics g,
|
||||
int x, int y, int w, int h) {
|
||||
if (context != null) {
|
||||
GTKPainter.INSTANCE.paintIcon(context, g,
|
||||
getMethod(), x, y, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
public int getIconWidth(SynthContext context) {
|
||||
return getIconDimension(context);
|
||||
}
|
||||
|
||||
public int getIconHeight(SynthContext context) {
|
||||
return getIconDimension(context);
|
||||
}
|
||||
|
||||
void resetIconDimensions() {
|
||||
iconDimension = -1;
|
||||
}
|
||||
|
||||
protected Method getMethod() {
|
||||
if (method instanceof String) {
|
||||
method = resolveMethod((String)method);
|
||||
}
|
||||
return (Method)method;
|
||||
}
|
||||
|
||||
protected Class[] getMethodParamTypes() {
|
||||
return PARAM_TYPES;
|
||||
}
|
||||
|
||||
private Method resolveMethod(String name) {
|
||||
try {
|
||||
return GTKPainter.class.getMethod(name, getMethodParamTypes());
|
||||
} catch (NoSuchMethodException e) {
|
||||
assert false;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
int getIconDimension(SynthContext context) {
|
||||
if (iconDimension >= 0) {
|
||||
return iconDimension;
|
||||
}
|
||||
|
||||
if (context == null) {
|
||||
return DEFAULT_ICON_SIZE;
|
||||
}
|
||||
|
||||
Region region = context.getRegion();
|
||||
GTKStyle style = (GTKStyle) context.getStyle();
|
||||
if (GTKLookAndFeel.is3() && region == Region.MENU) {
|
||||
Object value = style.getClassSpecificValue("arrow-scaling");
|
||||
if (value instanceof Number) {
|
||||
iconDimension = (int)(((Number) value).floatValue() *
|
||||
(style.getFont(context).getSize2D() +
|
||||
2 * style.getClassSpecificIntValue(context,
|
||||
"indicator-spacing", DEFAULT_ICON_SPACING)));
|
||||
if (iconDimension > 0) {
|
||||
return iconDimension;
|
||||
}
|
||||
}
|
||||
}
|
||||
iconDimension = style.getClassSpecificIntValue(context,
|
||||
"indicator-size",
|
||||
(region == Region.CHECK_BOX_MENU_ITEM ||
|
||||
region == Region.RADIO_BUTTON_MENU_ITEM) ?
|
||||
DEFAULT_TOGGLE_MENU_ITEM_SIZE : DEFAULT_ICON_SIZE);
|
||||
|
||||
if (region == Region.CHECK_BOX || region == Region.RADIO_BUTTON) {
|
||||
iconDimension += 2 * style.getClassSpecificIntValue(context,
|
||||
"indicator-spacing", DEFAULT_ICON_SPACING);
|
||||
} else if (region == Region.CHECK_BOX_MENU_ITEM ||
|
||||
region == Region.RADIO_BUTTON_MENU_ITEM) {
|
||||
iconDimension += 2 * CHECK_ICON_EXTRA_INSET;
|
||||
}
|
||||
return iconDimension;
|
||||
}
|
||||
}
|
||||
|
||||
private static class SynthExpanderIcon extends DelegatingIcon {
|
||||
SynthExpanderIcon(String method) {
|
||||
super(method);
|
||||
}
|
||||
|
||||
public void paintIcon(SynthContext context, Graphics g, int x, int y,
|
||||
int w, int h) {
|
||||
if (context != null) {
|
||||
super.paintIcon(context, g, x, y, w, h);
|
||||
updateSizeIfNecessary(context);
|
||||
}
|
||||
}
|
||||
|
||||
int getIconDimension(SynthContext context) {
|
||||
updateSizeIfNecessary(context);
|
||||
return (iconDimension == -1) ? DEFAULT_ICON_SIZE :
|
||||
iconDimension;
|
||||
}
|
||||
|
||||
private void updateSizeIfNecessary(SynthContext context) {
|
||||
if (iconDimension == -1 && context != null) {
|
||||
iconDimension = context.getStyle().getInt(context,
|
||||
"Tree.expanderSize", 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GTK has a separate widget for the handle box, to mirror this
|
||||
// we create a unique icon per ToolBar and lookup the style for the
|
||||
// HandleBox.
|
||||
private static class ToolBarHandleIcon extends DelegatingIcon {
|
||||
private static final Class[] PARAM_TYPES = new Class[] {
|
||||
SynthContext.class, Graphics.class, int.class,
|
||||
int.class, int.class, int.class, int.class, Orientation.class,
|
||||
};
|
||||
|
||||
private SynthStyle style;
|
||||
|
||||
public ToolBarHandleIcon() {
|
||||
super(TOOL_BAR_HANDLE_ICON);
|
||||
}
|
||||
|
||||
protected Class[] getMethodParamTypes() {
|
||||
return PARAM_TYPES;
|
||||
}
|
||||
|
||||
public void paintIcon(SynthContext context, Graphics g, int x, int y,
|
||||
int w, int h) {
|
||||
if (context != null) {
|
||||
JToolBar toolbar = (JToolBar)context.getComponent();
|
||||
Orientation orientation =
|
||||
(toolbar.getOrientation() == JToolBar.HORIZONTAL ?
|
||||
Orientation.HORIZONTAL : Orientation.VERTICAL);
|
||||
|
||||
if (style == null) {
|
||||
style = SynthLookAndFeel.getStyleFactory().getStyle(
|
||||
context.getComponent(), GTKRegion.HANDLE_BOX);
|
||||
}
|
||||
context = new SynthContext(toolbar, GTKRegion.HANDLE_BOX,
|
||||
style, SynthConstants.ENABLED);
|
||||
|
||||
GTKPainter.INSTANCE.paintIcon(context, g,
|
||||
getMethod(), x, y, w, h, orientation);
|
||||
}
|
||||
}
|
||||
|
||||
public int getIconWidth(SynthContext context) {
|
||||
if (context == null) {
|
||||
return 10;
|
||||
}
|
||||
if (((JToolBar)context.getComponent()).getOrientation() ==
|
||||
JToolBar.HORIZONTAL) {
|
||||
return 10;
|
||||
} else {
|
||||
return context.getComponent().getWidth();
|
||||
}
|
||||
}
|
||||
|
||||
public int getIconHeight(SynthContext context) {
|
||||
if (context == null) {
|
||||
return 10;
|
||||
}
|
||||
if (((JToolBar)context.getComponent()).getOrientation() ==
|
||||
JToolBar.HORIZONTAL) {
|
||||
return context.getComponent().getHeight();
|
||||
} else {
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class MenuArrowIcon extends DelegatingIcon {
|
||||
private static final Class[] PARAM_TYPES = new Class[] {
|
||||
SynthContext.class, Graphics.class, int.class,
|
||||
int.class, int.class, int.class, int.class, ArrowType.class,
|
||||
};
|
||||
|
||||
public MenuArrowIcon() {
|
||||
super(MENU_ARROW_ICON);
|
||||
}
|
||||
|
||||
protected Class[] getMethodParamTypes() {
|
||||
return PARAM_TYPES;
|
||||
}
|
||||
|
||||
public void paintIcon(SynthContext context, Graphics g, int x, int y,
|
||||
int w, int h) {
|
||||
if (context != null) {
|
||||
ArrowType arrowDir = ArrowType.RIGHT;
|
||||
if (!context.getComponent().getComponentOrientation().isLeftToRight()) {
|
||||
arrowDir = ArrowType.LEFT;
|
||||
}
|
||||
GTKPainter.INSTANCE.paintIcon(context, g,
|
||||
getMethod(), x, y, w, h, arrowDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1757
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKLookAndFeel.java
Normal file
1757
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKLookAndFeel.java
Normal file
File diff suppressed because it is too large
Load Diff
1602
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKPainter.java
Normal file
1602
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKPainter.java
Normal file
File diff suppressed because it is too large
Load Diff
42
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKRegion.java
Normal file
42
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKRegion.java
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 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 com.sun.java.swing.plaf.gtk;
|
||||
|
||||
import javax.swing.plaf.synth.Region;
|
||||
|
||||
/**
|
||||
* A typesafe enumeration of the distinct rendering portions specific
|
||||
* to GTK.
|
||||
*
|
||||
* @author Scott Violet
|
||||
*/
|
||||
class GTKRegion extends Region {
|
||||
public static final Region HANDLE_BOX = new GTKRegion("HandleBox", null,
|
||||
true);
|
||||
|
||||
protected GTKRegion(String name, String ui, boolean subregion) {
|
||||
super(name, ui, subregion);
|
||||
}
|
||||
}
|
||||
1197
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKStyle.java
Normal file
1197
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKStyle.java
Normal file
File diff suppressed because it is too large
Load Diff
188
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKStyleFactory.java
Normal file
188
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/GTKStyleFactory.java
Normal file
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2012, 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 com.sun.java.swing.plaf.gtk;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.util.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.synth.*;
|
||||
import com.sun.java.swing.plaf.gtk.GTKEngine.WidgetType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Scott Violet
|
||||
*/
|
||||
class GTKStyleFactory extends SynthStyleFactory {
|
||||
|
||||
/**
|
||||
* Saves all styles that have been accessed. In most common cases,
|
||||
* the hash key is simply the WidgetType, but in more complex cases
|
||||
* it will be a ComplexKey object that contains arguments to help
|
||||
* differentiate similar styles.
|
||||
*/
|
||||
private final Map<Object, GTKStyle> stylesCache;
|
||||
|
||||
private Font defaultFont;
|
||||
|
||||
GTKStyleFactory() {
|
||||
stylesCache = new HashMap<Object, GTKStyle>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <code>GTKStyle</code> to use based on the
|
||||
* <code>Region</code> id
|
||||
*
|
||||
* @param c this parameter isn't used, may be null.
|
||||
* @param id of the region to get the style.
|
||||
*/
|
||||
public synchronized SynthStyle getStyle(JComponent c, Region id) {
|
||||
WidgetType wt = GTKEngine.getWidgetType(c, id);
|
||||
|
||||
Object key = null;
|
||||
if (id == Region.SCROLL_BAR) {
|
||||
// The style/insets of a scrollbar can depend on a number of
|
||||
// factors (see GTKStyle.getScrollBarInsets()) so use a
|
||||
// complex key here.
|
||||
if (c != null) {
|
||||
JScrollBar sb = (JScrollBar)c;
|
||||
boolean sp = (sb.getParent() instanceof JScrollPane);
|
||||
boolean horiz = (sb.getOrientation() == JScrollBar.HORIZONTAL);
|
||||
boolean ltr = sb.getComponentOrientation().isLeftToRight();
|
||||
boolean focusable = sb.isFocusable();
|
||||
key = new ComplexKey(wt, sp, horiz, ltr, focusable);
|
||||
}
|
||||
}
|
||||
else if (id == Region.CHECK_BOX || id == Region.RADIO_BUTTON) {
|
||||
// The style/insets of a checkbox or radiobutton can depend
|
||||
// on the component orientation, so use a complex key here.
|
||||
if (c != null) {
|
||||
boolean ltr = c.getComponentOrientation().isLeftToRight();
|
||||
key = new ComplexKey(wt, ltr);
|
||||
}
|
||||
}
|
||||
else if (id == Region.BUTTON) {
|
||||
// The style/insets of a button can depend on whether it is
|
||||
// default capable or in a toolbar, so use a complex key here.
|
||||
if (c != null) {
|
||||
JButton btn = (JButton)c;
|
||||
boolean toolButton = (btn.getParent() instanceof JToolBar);
|
||||
boolean defaultCapable = btn.isDefaultCapable();
|
||||
key = new ComplexKey(wt, toolButton, defaultCapable);
|
||||
}
|
||||
} else if (id == Region.MENU) {
|
||||
if (c instanceof JMenu && ((JMenu) c).isTopLevelMenu() &&
|
||||
UIManager.getBoolean("Menu.useMenuBarForTopLevelMenus")) {
|
||||
wt = WidgetType.MENU_BAR;
|
||||
}
|
||||
}
|
||||
|
||||
if (key == null) {
|
||||
// Otherwise, just use the WidgetType as the key.
|
||||
key = wt;
|
||||
}
|
||||
|
||||
GTKStyle result = stylesCache.get(key);
|
||||
if (result == null) {
|
||||
result = new GTKStyle(defaultFont, wt);
|
||||
stylesCache.put(key, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void initStyles(Font defaultFont) {
|
||||
this.defaultFont = defaultFont;
|
||||
stylesCache.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a hash key used for fetching GTKStyle objects from the
|
||||
* cache. In most cases only the WidgetType is used for lookup, but
|
||||
* in some complex cases, other Object arguments can be specified
|
||||
* via a ComplexKey to differentiate the various styles.
|
||||
*/
|
||||
private static class ComplexKey {
|
||||
private final WidgetType wt;
|
||||
private final Object[] args;
|
||||
|
||||
ComplexKey(WidgetType wt, Object... args) {
|
||||
this.wt = wt;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = wt.hashCode();
|
||||
if (args != null) {
|
||||
for (Object arg : args) {
|
||||
hash = hash*29 + (arg == null ? 0 : arg.hashCode());
|
||||
}
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof ComplexKey)) {
|
||||
return false;
|
||||
}
|
||||
ComplexKey that = (ComplexKey)o;
|
||||
if (this.wt == that.wt) {
|
||||
if (this.args == null && that.args == null) {
|
||||
return true;
|
||||
}
|
||||
if (this.args != null && that.args != null &&
|
||||
this.args.length == that.args.length)
|
||||
{
|
||||
for (int i = 0; i < this.args.length; i++) {
|
||||
Object a1 = this.args[i];
|
||||
Object a2 = that.args[i];
|
||||
if (!(a1==null ? a2==null : a1.equals(a2))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String str = "ComplexKey[wt=" + wt;
|
||||
if (args != null) {
|
||||
str += ",args=[";
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
str += args[i];
|
||||
if (i < args.length-1) str += ",";
|
||||
}
|
||||
str += "]";
|
||||
}
|
||||
str += "]";
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
2159
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/Metacity.java
Normal file
2159
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/Metacity.java
Normal file
File diff suppressed because it is too large
Load Diff
233
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/PangoFonts.java
Normal file
233
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/PangoFonts.java
Normal file
@@ -0,0 +1,233 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2010, 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 com.sun.java.swing.plaf.gtk;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import javax.swing.plaf.FontUIResource;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import sun.font.FontConfigManager;
|
||||
import sun.font.FontUtilities;
|
||||
|
||||
/**
|
||||
* @author Shannon Hickey
|
||||
* @author Leif Samuelsson
|
||||
*/
|
||||
class PangoFonts {
|
||||
|
||||
public static final String CHARS_DIGITS = "0123456789";
|
||||
|
||||
/**
|
||||
* Calculate a default scale factor for fonts in this L&F to match
|
||||
* the reported resolution of the screen.
|
||||
* Java 2D specified a default user-space scale of 72dpi.
|
||||
* This is unlikely to correspond to that of the real screen.
|
||||
* The Xserver reports a value which may be used to adjust for this.
|
||||
* and Java 2D exposes it via a normalizing transform.
|
||||
* However many Xservers report a hard-coded 90dpi whilst others report a
|
||||
* calculated value based on possibly incorrect data.
|
||||
* That is something that must be solved at the X11 level
|
||||
* Note that in an X11 multi-screen environment, the default screen
|
||||
* is the one used by the JRE so it is safe to use it here.
|
||||
*/
|
||||
private static double fontScale;
|
||||
|
||||
static {
|
||||
fontScale = 1.0d;
|
||||
GraphicsEnvironment ge =
|
||||
GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
|
||||
if (!ge.isHeadless()) {
|
||||
GraphicsConfiguration gc =
|
||||
ge.getDefaultScreenDevice().getDefaultConfiguration();
|
||||
AffineTransform at = gc.getNormalizingTransform();
|
||||
fontScale = at.getScaleY();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses a String containing a pango font description and returns
|
||||
* a Font object.
|
||||
*
|
||||
* @param pangoName a String describing a pango font
|
||||
* e.g. "Sans Italic 10"
|
||||
* @return a Font object as a FontUIResource
|
||||
* or null if no suitable font could be created.
|
||||
*/
|
||||
static Font lookupFont(String pangoName) {
|
||||
String family = "";
|
||||
int style = Font.PLAIN;
|
||||
int size = 10;
|
||||
|
||||
StringTokenizer tok = new StringTokenizer(pangoName);
|
||||
|
||||
while (tok.hasMoreTokens()) {
|
||||
String word = tok.nextToken();
|
||||
|
||||
if (word.equalsIgnoreCase("italic")) {
|
||||
style |= Font.ITALIC;
|
||||
} else if (word.equalsIgnoreCase("bold")) {
|
||||
style |= Font.BOLD;
|
||||
} else if (CHARS_DIGITS.indexOf(word.charAt(0)) != -1) {
|
||||
try {
|
||||
size = Integer.parseInt(word);
|
||||
} catch (NumberFormatException ex) {
|
||||
}
|
||||
} else {
|
||||
if (family.length() > 0) {
|
||||
family += " ";
|
||||
}
|
||||
|
||||
family += word;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Java 2D font point sizes are in a user-space scale of 72dpi.
|
||||
* GTK allows a user to configure a "dpi" property used to scale
|
||||
* the fonts used to match a user's preference.
|
||||
* To match the font size of GTK apps we need to obtain this DPI and
|
||||
* adjust as follows:
|
||||
* Some versions of GTK use XSETTINGS if available to dynamically
|
||||
* monitor user-initiated changes in the DPI to be used by GTK
|
||||
* apps. This value is also made available as the Xft.dpi X resource.
|
||||
* This is presumably a function of the font preferences API and/or
|
||||
* the manner in which it requests the toolkit to update the default
|
||||
* for the desktop. This dual approach is probably necessary since
|
||||
* other versions of GTK - or perhaps some apps - determine the size
|
||||
* to use only at start-up from that X resource.
|
||||
* If that resource is not set then GTK scales for the DPI resolution
|
||||
* reported by the Xserver using the formula
|
||||
* DisplayHeight(dpy, screen) / DisplayHeightMM(dpy, screen) * 25.4
|
||||
* (25.4mm == 1 inch).
|
||||
* JDK tracks the Xft.dpi XSETTINGS property directly so it can
|
||||
* dynamically change font size by tracking just that value.
|
||||
* If that resource is not available use the same fall back formula
|
||||
* as GTK (see calculation for fontScale).
|
||||
*
|
||||
* GTK's default setting for Xft.dpi is 96 dpi (and it seems -1
|
||||
* apparently also can mean that "default"). However this default
|
||||
* isn't used if there's no property set. The real default in the
|
||||
* absence of a resource is the Xserver reported dpi.
|
||||
* Finally this DPI is used to calculate the nearest Java 2D font
|
||||
* 72 dpi font size.
|
||||
* There are cases in which JDK behaviour may not exactly mimic
|
||||
* GTK native app behaviour :
|
||||
* 1) When a GTK app is not able to dynamically track the changes
|
||||
* (does not use XSETTINGS), JDK will resize but other apps will
|
||||
* not. This is OK as JDK is exhibiting preferred behaviour and
|
||||
* this is probably how all later GTK apps will behave
|
||||
* 2) When a GTK app does not use XSETTINGS and for some reason
|
||||
* the XRDB property is not present. JDK will pick up XSETTINGS
|
||||
* and the GTK app will use the Xserver default. Since its
|
||||
* impossible for JDK to know that some other GTK app is not
|
||||
* using XSETTINGS its impossible to account for this and in any
|
||||
* case for it to be a problem the values would have to be different.
|
||||
* It also seems unlikely to arise except when a user explicitly
|
||||
* deletes the X resource database entry.
|
||||
* There also some other issues to be aware of for the future:
|
||||
* GTK specifies the Xft.dpi value as server-wide which when used
|
||||
* on systems with 2 distinct X screens with different physical DPI
|
||||
* the font sizes will inevitably appear different. It would have
|
||||
* been a more user-friendly design to further adjust that one
|
||||
* setting depending on the screen resolution to achieve perceived
|
||||
* equivalent sizes. If such a change were ever to be made in GTK
|
||||
* we would need to update for that.
|
||||
*/
|
||||
double dsize = size;
|
||||
int dpi = 96;
|
||||
Object value =
|
||||
Toolkit.getDefaultToolkit().getDesktopProperty("gnome.Xft/DPI");
|
||||
if (value instanceof Integer) {
|
||||
dpi = ((Integer)value).intValue() / 1024;
|
||||
if (dpi == -1) {
|
||||
dpi = 96;
|
||||
}
|
||||
if (dpi < 50) { /* 50 dpi is the minimum value gnome allows */
|
||||
dpi = 50;
|
||||
}
|
||||
/* The Java rasteriser assumes pts are in a user space of
|
||||
* 72 dpi, so we need to adjust for that.
|
||||
*/
|
||||
dsize = ((double)(dpi * size)/ 72.0);
|
||||
} else {
|
||||
/* If there's no property, GTK scales for the resolution
|
||||
* reported by the Xserver using the formula listed above.
|
||||
* fontScale already accounts for the 72 dpi Java 2D space.
|
||||
*/
|
||||
dsize = size * fontScale;
|
||||
}
|
||||
|
||||
/* Round size to nearest integer pt size */
|
||||
size = (int)(dsize + 0.5);
|
||||
if (size < 1) {
|
||||
size = 1;
|
||||
}
|
||||
|
||||
String fcFamilyLC = family.toLowerCase();
|
||||
if (FontUtilities.mapFcName(fcFamilyLC) != null) {
|
||||
/* family is a Fc/Pango logical font which we need to expand. */
|
||||
Font font = FontUtilities.getFontConfigFUIR(fcFamilyLC, style, size);
|
||||
font = font.deriveFont(style, (float)dsize);
|
||||
return new FontUIResource(font);
|
||||
} else {
|
||||
/* It's a physical font which we will create with a fallback */
|
||||
Font font = new Font(family, style, size);
|
||||
/* a roundabout way to set the font size in floating points */
|
||||
font = font.deriveFont(style, (float)dsize);
|
||||
FontUIResource fuir = new FontUIResource(font);
|
||||
return FontUtilities.getCompositeFontUIResource(fuir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a String containing a pango font description and returns
|
||||
* the (unscaled) font size as an integer.
|
||||
*
|
||||
* @param pangoName a String describing a pango font
|
||||
* @return the size of the font described by pangoName (e.g. if
|
||||
* pangoName is "Sans Italic 10", then this method returns 10)
|
||||
*/
|
||||
static int getFontSize(String pangoName) {
|
||||
int size = 10;
|
||||
|
||||
StringTokenizer tok = new StringTokenizer(pangoName);
|
||||
while (tok.hasMoreTokens()) {
|
||||
String word = tok.nextToken();
|
||||
|
||||
if (CHARS_DIGITS.indexOf(word.charAt(0)) != -1) {
|
||||
try {
|
||||
size = Integer.parseInt(word);
|
||||
} catch (NumberFormatException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
}
|
||||
831
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/XColors.java
Normal file
831
jdkSrc/jdk8/com/sun/java/swing/plaf/gtk/XColors.java
Normal file
@@ -0,0 +1,831 @@
|
||||
/*
|
||||
* Copyright (c) 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 com.sun.java.swing.plaf.gtk;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.Arrays;
|
||||
import javax.swing.plaf.ColorUIResource;
|
||||
|
||||
/**
|
||||
* @author Shannon Hickey
|
||||
*/
|
||||
class XColors {
|
||||
|
||||
private static class XColor implements Comparable {
|
||||
String name;
|
||||
|
||||
int red;
|
||||
int green;
|
||||
int blue;
|
||||
|
||||
XColor(String name, int red, int green, int blue) {
|
||||
this.name = name;
|
||||
this.red = red;
|
||||
this.green = green;
|
||||
this.blue = blue;
|
||||
}
|
||||
|
||||
Color toColor() {
|
||||
return new ColorUIResource(red, green, blue);
|
||||
}
|
||||
|
||||
public int compareTo(Object o) {
|
||||
XColor other = (XColor)o;
|
||||
|
||||
return name.compareTo(other.name);
|
||||
}
|
||||
}
|
||||
|
||||
private static XColor key = new XColor("", -1, -1, -1);
|
||||
|
||||
static Color lookupColor(String name) {
|
||||
key.name = name.toLowerCase();
|
||||
|
||||
int pos = Arrays.binarySearch(colors, key);
|
||||
|
||||
if (pos < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return colors[pos].toColor();
|
||||
}
|
||||
|
||||
private static final XColor[] colors = {
|
||||
new XColor("alice blue", 240, 248, 255),
|
||||
new XColor("aliceblue", 240, 248, 255),
|
||||
new XColor("antique white", 250, 235, 215),
|
||||
new XColor("antiquewhite", 250, 235, 215),
|
||||
new XColor("antiquewhite1", 255, 239, 219),
|
||||
new XColor("antiquewhite2", 238, 223, 204),
|
||||
new XColor("antiquewhite3", 205, 192, 176),
|
||||
new XColor("antiquewhite4", 139, 131, 120),
|
||||
new XColor("aquamarine", 127, 255, 212),
|
||||
new XColor("aquamarine1", 127, 255, 212),
|
||||
new XColor("aquamarine2", 118, 238, 198),
|
||||
new XColor("aquamarine3", 102, 205, 170),
|
||||
new XColor("aquamarine4", 69, 139, 116),
|
||||
new XColor("azure", 240, 255, 255),
|
||||
new XColor("azure1", 240, 255, 255),
|
||||
new XColor("azure2", 224, 238, 238),
|
||||
new XColor("azure3", 193, 205, 205),
|
||||
new XColor("azure4", 131, 139, 139),
|
||||
new XColor("beige", 245, 245, 220),
|
||||
new XColor("bisque", 255, 228, 196),
|
||||
new XColor("bisque1", 255, 228, 196),
|
||||
new XColor("bisque2", 238, 213, 183),
|
||||
new XColor("bisque3", 205, 183, 158),
|
||||
new XColor("bisque4", 139, 125, 107),
|
||||
new XColor("black", 0, 0, 0),
|
||||
new XColor("blanched almond", 255, 235, 205),
|
||||
new XColor("blanchedalmond", 255, 235, 205),
|
||||
new XColor("blue", 0, 0, 255),
|
||||
new XColor("blue violet", 138, 43, 226),
|
||||
new XColor("blue1", 0, 0, 255),
|
||||
new XColor("blue2", 0, 0, 238),
|
||||
new XColor("blue3", 0, 0, 205),
|
||||
new XColor("blue4", 0, 0, 139),
|
||||
new XColor("blueviolet", 138, 43, 226),
|
||||
new XColor("brown", 165, 42, 42),
|
||||
new XColor("brown1", 255, 64, 64),
|
||||
new XColor("brown2", 238, 59, 59),
|
||||
new XColor("brown3", 205, 51, 51),
|
||||
new XColor("brown4", 139, 35, 35),
|
||||
new XColor("burlywood", 222, 184, 135),
|
||||
new XColor("burlywood1", 255, 211, 155),
|
||||
new XColor("burlywood2", 238, 197, 145),
|
||||
new XColor("burlywood3", 205, 170, 125),
|
||||
new XColor("burlywood4", 139, 115, 85),
|
||||
new XColor("cadet blue", 95, 158, 160),
|
||||
new XColor("cadetblue", 95, 158, 160),
|
||||
new XColor("cadetblue1", 152, 245, 255),
|
||||
new XColor("cadetblue2", 142, 229, 238),
|
||||
new XColor("cadetblue3", 122, 197, 205),
|
||||
new XColor("cadetblue4", 83, 134, 139),
|
||||
new XColor("chartreuse", 127, 255, 0),
|
||||
new XColor("chartreuse1", 127, 255, 0),
|
||||
new XColor("chartreuse2", 118, 238, 0),
|
||||
new XColor("chartreuse3", 102, 205, 0),
|
||||
new XColor("chartreuse4", 69, 139, 0),
|
||||
new XColor("chocolate", 210, 105, 30),
|
||||
new XColor("chocolate1", 255, 127, 36),
|
||||
new XColor("chocolate2", 238, 118, 33),
|
||||
new XColor("chocolate3", 205, 102, 29),
|
||||
new XColor("chocolate4", 139, 69, 19),
|
||||
new XColor("coral", 255, 127, 80),
|
||||
new XColor("coral1", 255, 114, 86),
|
||||
new XColor("coral2", 238, 106, 80),
|
||||
new XColor("coral3", 205, 91, 69),
|
||||
new XColor("coral4", 139, 62, 47),
|
||||
new XColor("cornflower blue", 100, 149, 237),
|
||||
new XColor("cornflowerblue", 100, 149, 237),
|
||||
new XColor("cornsilk", 255, 248, 220),
|
||||
new XColor("cornsilk1", 255, 248, 220),
|
||||
new XColor("cornsilk2", 238, 232, 205),
|
||||
new XColor("cornsilk3", 205, 200, 177),
|
||||
new XColor("cornsilk4", 139, 136, 120),
|
||||
new XColor("cyan", 0, 255, 255),
|
||||
new XColor("cyan1", 0, 255, 255),
|
||||
new XColor("cyan2", 0, 238, 238),
|
||||
new XColor("cyan3", 0, 205, 205),
|
||||
new XColor("cyan4", 0, 139, 139),
|
||||
new XColor("dark blue", 0, 0, 139),
|
||||
new XColor("dark cyan", 0, 139, 139),
|
||||
new XColor("dark goldenrod", 184, 134, 11),
|
||||
new XColor("dark gray", 169, 169, 169),
|
||||
new XColor("dark green", 0, 100, 0),
|
||||
new XColor("dark grey", 169, 169, 169),
|
||||
new XColor("dark khaki", 189, 183, 107),
|
||||
new XColor("dark magenta", 139, 0, 139),
|
||||
new XColor("dark olive green", 85, 107, 47),
|
||||
new XColor("dark orange", 255, 140, 0),
|
||||
new XColor("dark orchid", 153, 50, 204),
|
||||
new XColor("dark red", 139, 0, 0),
|
||||
new XColor("dark salmon", 233, 150, 122),
|
||||
new XColor("dark sea green", 143, 188, 143),
|
||||
new XColor("dark slate blue", 72, 61, 139),
|
||||
new XColor("dark slate gray", 47, 79, 79),
|
||||
new XColor("dark slate grey", 47, 79, 79),
|
||||
new XColor("dark turquoise", 0, 206, 209),
|
||||
new XColor("dark violet", 148, 0, 211),
|
||||
new XColor("darkblue", 0, 0, 139),
|
||||
new XColor("darkcyan", 0, 139, 139),
|
||||
new XColor("darkgoldenrod", 184, 134, 11),
|
||||
new XColor("darkgoldenrod1", 255, 185, 15),
|
||||
new XColor("darkgoldenrod2", 238, 173, 14),
|
||||
new XColor("darkgoldenrod3", 205, 149, 12),
|
||||
new XColor("darkgoldenrod4", 139, 101, 8),
|
||||
new XColor("darkgray", 169, 169, 169),
|
||||
new XColor("darkgreen", 0, 100, 0),
|
||||
new XColor("darkgrey", 169, 169, 169),
|
||||
new XColor("darkkhaki", 189, 183, 107),
|
||||
new XColor("darkmagenta", 139, 0, 139),
|
||||
new XColor("darkolivegreen", 85, 107, 47),
|
||||
new XColor("darkolivegreen1", 202, 255, 112),
|
||||
new XColor("darkolivegreen2", 188, 238, 104),
|
||||
new XColor("darkolivegreen3", 162, 205, 90),
|
||||
new XColor("darkolivegreen4", 110, 139, 61),
|
||||
new XColor("darkorange", 255, 140, 0),
|
||||
new XColor("darkorange1", 255, 127, 0),
|
||||
new XColor("darkorange2", 238, 118, 0),
|
||||
new XColor("darkorange3", 205, 102, 0),
|
||||
new XColor("darkorange4", 139, 69, 0),
|
||||
new XColor("darkorchid", 153, 50, 204),
|
||||
new XColor("darkorchid1", 191, 62, 255),
|
||||
new XColor("darkorchid2", 178, 58, 238),
|
||||
new XColor("darkorchid3", 154, 50, 205),
|
||||
new XColor("darkorchid4", 104, 34, 139),
|
||||
new XColor("darkred", 139, 0, 0),
|
||||
new XColor("darksalmon", 233, 150, 122),
|
||||
new XColor("darkseagreen", 143, 188, 143),
|
||||
new XColor("darkseagreen1", 193, 255, 193),
|
||||
new XColor("darkseagreen2", 180, 238, 180),
|
||||
new XColor("darkseagreen3", 155, 205, 155),
|
||||
new XColor("darkseagreen4", 105, 139, 105),
|
||||
new XColor("darkslateblue", 72, 61, 139),
|
||||
new XColor("darkslategray", 47, 79, 79),
|
||||
new XColor("darkslategray1", 151, 255, 255),
|
||||
new XColor("darkslategray2", 141, 238, 238),
|
||||
new XColor("darkslategray3", 121, 205, 205),
|
||||
new XColor("darkslategray4", 82, 139, 139),
|
||||
new XColor("darkslategrey", 47, 79, 79),
|
||||
new XColor("darkturquoise", 0, 206, 209),
|
||||
new XColor("darkviolet", 148, 0, 211),
|
||||
new XColor("deep pink", 255, 20, 147),
|
||||
new XColor("deep sky blue", 0, 191, 255),
|
||||
new XColor("deeppink", 255, 20, 147),
|
||||
new XColor("deeppink1", 255, 20, 147),
|
||||
new XColor("deeppink2", 238, 18, 137),
|
||||
new XColor("deeppink3", 205, 16, 118),
|
||||
new XColor("deeppink4", 139, 10, 80),
|
||||
new XColor("deepskyblue", 0, 191, 255),
|
||||
new XColor("deepskyblue1", 0, 191, 255),
|
||||
new XColor("deepskyblue2", 0, 178, 238),
|
||||
new XColor("deepskyblue3", 0, 154, 205),
|
||||
new XColor("deepskyblue4", 0, 104, 139),
|
||||
new XColor("dim gray", 105, 105, 105),
|
||||
new XColor("dim grey", 105, 105, 105),
|
||||
new XColor("dimgray", 105, 105, 105),
|
||||
new XColor("dimgrey", 105, 105, 105),
|
||||
new XColor("dodger blue", 30, 144, 255),
|
||||
new XColor("dodgerblue", 30, 144, 255),
|
||||
new XColor("dodgerblue1", 30, 144, 255),
|
||||
new XColor("dodgerblue2", 28, 134, 238),
|
||||
new XColor("dodgerblue3", 24, 116, 205),
|
||||
new XColor("dodgerblue4", 16, 78, 139),
|
||||
new XColor("firebrick", 178, 34, 34),
|
||||
new XColor("firebrick1", 255, 48, 48),
|
||||
new XColor("firebrick2", 238, 44, 44),
|
||||
new XColor("firebrick3", 205, 38, 38),
|
||||
new XColor("firebrick4", 139, 26, 26),
|
||||
new XColor("floral white", 255, 250, 240),
|
||||
new XColor("floralwhite", 255, 250, 240),
|
||||
new XColor("forest green", 34, 139, 34),
|
||||
new XColor("forestgreen", 34, 139, 34),
|
||||
new XColor("gainsboro", 220, 220, 220),
|
||||
new XColor("ghost white", 248, 248, 255),
|
||||
new XColor("ghostwhite", 248, 248, 255),
|
||||
new XColor("gold", 255, 215, 0),
|
||||
new XColor("gold1", 255, 215, 0),
|
||||
new XColor("gold2", 238, 201, 0),
|
||||
new XColor("gold3", 205, 173, 0),
|
||||
new XColor("gold4", 139, 117, 0),
|
||||
new XColor("goldenrod", 218, 165, 32),
|
||||
new XColor("goldenrod1", 255, 193, 37),
|
||||
new XColor("goldenrod2", 238, 180, 34),
|
||||
new XColor("goldenrod3", 205, 155, 29),
|
||||
new XColor("goldenrod4", 139, 105, 20),
|
||||
new XColor("gray", 190, 190, 190),
|
||||
new XColor("gray0", 0, 0, 0),
|
||||
new XColor("gray1", 3, 3, 3),
|
||||
new XColor("gray10", 26, 26, 26),
|
||||
new XColor("gray100", 255, 255, 255),
|
||||
new XColor("gray11", 28, 28, 28),
|
||||
new XColor("gray12", 31, 31, 31),
|
||||
new XColor("gray13", 33, 33, 33),
|
||||
new XColor("gray14", 36, 36, 36),
|
||||
new XColor("gray15", 38, 38, 38),
|
||||
new XColor("gray16", 41, 41, 41),
|
||||
new XColor("gray17", 43, 43, 43),
|
||||
new XColor("gray18", 46, 46, 46),
|
||||
new XColor("gray19", 48, 48, 48),
|
||||
new XColor("gray2", 5, 5, 5),
|
||||
new XColor("gray20", 51, 51, 51),
|
||||
new XColor("gray21", 54, 54, 54),
|
||||
new XColor("gray22", 56, 56, 56),
|
||||
new XColor("gray23", 59, 59, 59),
|
||||
new XColor("gray24", 61, 61, 61),
|
||||
new XColor("gray25", 64, 64, 64),
|
||||
new XColor("gray26", 66, 66, 66),
|
||||
new XColor("gray27", 69, 69, 69),
|
||||
new XColor("gray28", 71, 71, 71),
|
||||
new XColor("gray29", 74, 74, 74),
|
||||
new XColor("gray3", 8, 8, 8),
|
||||
new XColor("gray30", 77, 77, 77),
|
||||
new XColor("gray31", 79, 79, 79),
|
||||
new XColor("gray32", 82, 82, 82),
|
||||
new XColor("gray33", 84, 84, 84),
|
||||
new XColor("gray34", 87, 87, 87),
|
||||
new XColor("gray35", 89, 89, 89),
|
||||
new XColor("gray36", 92, 92, 92),
|
||||
new XColor("gray37", 94, 94, 94),
|
||||
new XColor("gray38", 97, 97, 97),
|
||||
new XColor("gray39", 99, 99, 99),
|
||||
new XColor("gray4", 10, 10, 10),
|
||||
new XColor("gray40", 102, 102, 102),
|
||||
new XColor("gray41", 105, 105, 105),
|
||||
new XColor("gray42", 107, 107, 107),
|
||||
new XColor("gray43", 110, 110, 110),
|
||||
new XColor("gray44", 112, 112, 112),
|
||||
new XColor("gray45", 115, 115, 115),
|
||||
new XColor("gray46", 117, 117, 117),
|
||||
new XColor("gray47", 120, 120, 120),
|
||||
new XColor("gray48", 122, 122, 122),
|
||||
new XColor("gray49", 125, 125, 125),
|
||||
new XColor("gray5", 13, 13, 13),
|
||||
new XColor("gray50", 127, 127, 127),
|
||||
new XColor("gray51", 130, 130, 130),
|
||||
new XColor("gray52", 133, 133, 133),
|
||||
new XColor("gray53", 135, 135, 135),
|
||||
new XColor("gray54", 138, 138, 138),
|
||||
new XColor("gray55", 140, 140, 140),
|
||||
new XColor("gray56", 143, 143, 143),
|
||||
new XColor("gray57", 145, 145, 145),
|
||||
new XColor("gray58", 148, 148, 148),
|
||||
new XColor("gray59", 150, 150, 150),
|
||||
new XColor("gray6", 15, 15, 15),
|
||||
new XColor("gray60", 153, 153, 153),
|
||||
new XColor("gray61", 156, 156, 156),
|
||||
new XColor("gray62", 158, 158, 158),
|
||||
new XColor("gray63", 161, 161, 161),
|
||||
new XColor("gray64", 163, 163, 163),
|
||||
new XColor("gray65", 166, 166, 166),
|
||||
new XColor("gray66", 168, 168, 168),
|
||||
new XColor("gray67", 171, 171, 171),
|
||||
new XColor("gray68", 173, 173, 173),
|
||||
new XColor("gray69", 176, 176, 176),
|
||||
new XColor("gray7", 18, 18, 18),
|
||||
new XColor("gray70", 179, 179, 179),
|
||||
new XColor("gray71", 181, 181, 181),
|
||||
new XColor("gray72", 184, 184, 184),
|
||||
new XColor("gray73", 186, 186, 186),
|
||||
new XColor("gray74", 189, 189, 189),
|
||||
new XColor("gray75", 191, 191, 191),
|
||||
new XColor("gray76", 194, 194, 194),
|
||||
new XColor("gray77", 196, 196, 196),
|
||||
new XColor("gray78", 199, 199, 199),
|
||||
new XColor("gray79", 201, 201, 201),
|
||||
new XColor("gray8", 20, 20, 20),
|
||||
new XColor("gray80", 204, 204, 204),
|
||||
new XColor("gray81", 207, 207, 207),
|
||||
new XColor("gray82", 209, 209, 209),
|
||||
new XColor("gray83", 212, 212, 212),
|
||||
new XColor("gray84", 214, 214, 214),
|
||||
new XColor("gray85", 217, 217, 217),
|
||||
new XColor("gray86", 219, 219, 219),
|
||||
new XColor("gray87", 222, 222, 222),
|
||||
new XColor("gray88", 224, 224, 224),
|
||||
new XColor("gray89", 227, 227, 227),
|
||||
new XColor("gray9", 23, 23, 23),
|
||||
new XColor("gray90", 229, 229, 229),
|
||||
new XColor("gray91", 232, 232, 232),
|
||||
new XColor("gray92", 235, 235, 235),
|
||||
new XColor("gray93", 237, 237, 237),
|
||||
new XColor("gray94", 240, 240, 240),
|
||||
new XColor("gray95", 242, 242, 242),
|
||||
new XColor("gray96", 245, 245, 245),
|
||||
new XColor("gray97", 247, 247, 247),
|
||||
new XColor("gray98", 250, 250, 250),
|
||||
new XColor("gray99", 252, 252, 252),
|
||||
new XColor("green", 0, 255, 0),
|
||||
new XColor("green yellow", 173, 255, 47),
|
||||
new XColor("green1", 0, 255, 0),
|
||||
new XColor("green2", 0, 238, 0),
|
||||
new XColor("green3", 0, 205, 0),
|
||||
new XColor("green4", 0, 139, 0),
|
||||
new XColor("greenyellow", 173, 255, 47),
|
||||
new XColor("grey", 190, 190, 190),
|
||||
new XColor("grey0", 0, 0, 0),
|
||||
new XColor("grey1", 3, 3, 3),
|
||||
new XColor("grey10", 26, 26, 26),
|
||||
new XColor("grey100", 255, 255, 255),
|
||||
new XColor("grey11", 28, 28, 28),
|
||||
new XColor("grey12", 31, 31, 31),
|
||||
new XColor("grey13", 33, 33, 33),
|
||||
new XColor("grey14", 36, 36, 36),
|
||||
new XColor("grey15", 38, 38, 38),
|
||||
new XColor("grey16", 41, 41, 41),
|
||||
new XColor("grey17", 43, 43, 43),
|
||||
new XColor("grey18", 46, 46, 46),
|
||||
new XColor("grey19", 48, 48, 48),
|
||||
new XColor("grey2", 5, 5, 5),
|
||||
new XColor("grey20", 51, 51, 51),
|
||||
new XColor("grey21", 54, 54, 54),
|
||||
new XColor("grey22", 56, 56, 56),
|
||||
new XColor("grey23", 59, 59, 59),
|
||||
new XColor("grey24", 61, 61, 61),
|
||||
new XColor("grey25", 64, 64, 64),
|
||||
new XColor("grey26", 66, 66, 66),
|
||||
new XColor("grey27", 69, 69, 69),
|
||||
new XColor("grey28", 71, 71, 71),
|
||||
new XColor("grey29", 74, 74, 74),
|
||||
new XColor("grey3", 8, 8, 8),
|
||||
new XColor("grey30", 77, 77, 77),
|
||||
new XColor("grey31", 79, 79, 79),
|
||||
new XColor("grey32", 82, 82, 82),
|
||||
new XColor("grey33", 84, 84, 84),
|
||||
new XColor("grey34", 87, 87, 87),
|
||||
new XColor("grey35", 89, 89, 89),
|
||||
new XColor("grey36", 92, 92, 92),
|
||||
new XColor("grey37", 94, 94, 94),
|
||||
new XColor("grey38", 97, 97, 97),
|
||||
new XColor("grey39", 99, 99, 99),
|
||||
new XColor("grey4", 10, 10, 10),
|
||||
new XColor("grey40", 102, 102, 102),
|
||||
new XColor("grey41", 105, 105, 105),
|
||||
new XColor("grey42", 107, 107, 107),
|
||||
new XColor("grey43", 110, 110, 110),
|
||||
new XColor("grey44", 112, 112, 112),
|
||||
new XColor("grey45", 115, 115, 115),
|
||||
new XColor("grey46", 117, 117, 117),
|
||||
new XColor("grey47", 120, 120, 120),
|
||||
new XColor("grey48", 122, 122, 122),
|
||||
new XColor("grey49", 125, 125, 125),
|
||||
new XColor("grey5", 13, 13, 13),
|
||||
new XColor("grey50", 127, 127, 127),
|
||||
new XColor("grey51", 130, 130, 130),
|
||||
new XColor("grey52", 133, 133, 133),
|
||||
new XColor("grey53", 135, 135, 135),
|
||||
new XColor("grey54", 138, 138, 138),
|
||||
new XColor("grey55", 140, 140, 140),
|
||||
new XColor("grey56", 143, 143, 143),
|
||||
new XColor("grey57", 145, 145, 145),
|
||||
new XColor("grey58", 148, 148, 148),
|
||||
new XColor("grey59", 150, 150, 150),
|
||||
new XColor("grey6", 15, 15, 15),
|
||||
new XColor("grey60", 153, 153, 153),
|
||||
new XColor("grey61", 156, 156, 156),
|
||||
new XColor("grey62", 158, 158, 158),
|
||||
new XColor("grey63", 161, 161, 161),
|
||||
new XColor("grey64", 163, 163, 163),
|
||||
new XColor("grey65", 166, 166, 166),
|
||||
new XColor("grey66", 168, 168, 168),
|
||||
new XColor("grey67", 171, 171, 171),
|
||||
new XColor("grey68", 173, 173, 173),
|
||||
new XColor("grey69", 176, 176, 176),
|
||||
new XColor("grey7", 18, 18, 18),
|
||||
new XColor("grey70", 179, 179, 179),
|
||||
new XColor("grey71", 181, 181, 181),
|
||||
new XColor("grey72", 184, 184, 184),
|
||||
new XColor("grey73", 186, 186, 186),
|
||||
new XColor("grey74", 189, 189, 189),
|
||||
new XColor("grey75", 191, 191, 191),
|
||||
new XColor("grey76", 194, 194, 194),
|
||||
new XColor("grey77", 196, 196, 196),
|
||||
new XColor("grey78", 199, 199, 199),
|
||||
new XColor("grey79", 201, 201, 201),
|
||||
new XColor("grey8", 20, 20, 20),
|
||||
new XColor("grey80", 204, 204, 204),
|
||||
new XColor("grey81", 207, 207, 207),
|
||||
new XColor("grey82", 209, 209, 209),
|
||||
new XColor("grey83", 212, 212, 212),
|
||||
new XColor("grey84", 214, 214, 214),
|
||||
new XColor("grey85", 217, 217, 217),
|
||||
new XColor("grey86", 219, 219, 219),
|
||||
new XColor("grey87", 222, 222, 222),
|
||||
new XColor("grey88", 224, 224, 224),
|
||||
new XColor("grey89", 227, 227, 227),
|
||||
new XColor("grey9", 23, 23, 23),
|
||||
new XColor("grey90", 229, 229, 229),
|
||||
new XColor("grey91", 232, 232, 232),
|
||||
new XColor("grey92", 235, 235, 235),
|
||||
new XColor("grey93", 237, 237, 237),
|
||||
new XColor("grey94", 240, 240, 240),
|
||||
new XColor("grey95", 242, 242, 242),
|
||||
new XColor("grey96", 245, 245, 245),
|
||||
new XColor("grey97", 247, 247, 247),
|
||||
new XColor("grey98", 250, 250, 250),
|
||||
new XColor("grey99", 252, 252, 252),
|
||||
new XColor("honeydew", 240, 255, 240),
|
||||
new XColor("honeydew1", 240, 255, 240),
|
||||
new XColor("honeydew2", 224, 238, 224),
|
||||
new XColor("honeydew3", 193, 205, 193),
|
||||
new XColor("honeydew4", 131, 139, 131),
|
||||
new XColor("hot pink", 255, 105, 180),
|
||||
new XColor("hotpink", 255, 105, 180),
|
||||
new XColor("hotpink1", 255, 110, 180),
|
||||
new XColor("hotpink2", 238, 106, 167),
|
||||
new XColor("hotpink3", 205, 96, 144),
|
||||
new XColor("hotpink4", 139, 58, 98),
|
||||
new XColor("indian red", 205, 92, 92),
|
||||
new XColor("indianred", 205, 92, 92),
|
||||
new XColor("indianred1", 255, 106, 106),
|
||||
new XColor("indianred2", 238, 99, 99),
|
||||
new XColor("indianred3", 205, 85, 85),
|
||||
new XColor("indianred4", 139, 58, 58),
|
||||
new XColor("ivory", 255, 255, 240),
|
||||
new XColor("ivory1", 255, 255, 240),
|
||||
new XColor("ivory2", 238, 238, 224),
|
||||
new XColor("ivory3", 205, 205, 193),
|
||||
new XColor("ivory4", 139, 139, 131),
|
||||
new XColor("khaki", 240, 230, 140),
|
||||
new XColor("khaki1", 255, 246, 143),
|
||||
new XColor("khaki2", 238, 230, 133),
|
||||
new XColor("khaki3", 205, 198, 115),
|
||||
new XColor("khaki4", 139, 134, 78),
|
||||
new XColor("lavender", 230, 230, 250),
|
||||
new XColor("lavender blush", 255, 240, 245),
|
||||
new XColor("lavenderblush", 255, 240, 245),
|
||||
new XColor("lavenderblush1", 255, 240, 245),
|
||||
new XColor("lavenderblush2", 238, 224, 229),
|
||||
new XColor("lavenderblush3", 205, 193, 197),
|
||||
new XColor("lavenderblush4", 139, 131, 134),
|
||||
new XColor("lawn green", 124, 252, 0),
|
||||
new XColor("lawngreen", 124, 252, 0),
|
||||
new XColor("lemon chiffon", 255, 250, 205),
|
||||
new XColor("lemonchiffon", 255, 250, 205),
|
||||
new XColor("lemonchiffon1", 255, 250, 205),
|
||||
new XColor("lemonchiffon2", 238, 233, 191),
|
||||
new XColor("lemonchiffon3", 205, 201, 165),
|
||||
new XColor("lemonchiffon4", 139, 137, 112),
|
||||
new XColor("light blue", 173, 216, 230),
|
||||
new XColor("light coral", 240, 128, 128),
|
||||
new XColor("light cyan", 224, 255, 255),
|
||||
new XColor("light goldenrod", 238, 221, 130),
|
||||
new XColor("light goldenrod yellow", 250, 250, 210),
|
||||
new XColor("light gray", 211, 211, 211),
|
||||
new XColor("light green", 144, 238, 144),
|
||||
new XColor("light grey", 211, 211, 211),
|
||||
new XColor("light pink", 255, 182, 193),
|
||||
new XColor("light salmon", 255, 160, 122),
|
||||
new XColor("light sea green", 32, 178, 170),
|
||||
new XColor("light sky blue", 135, 206, 250),
|
||||
new XColor("light slate blue", 132, 112, 255),
|
||||
new XColor("light slate gray", 119, 136, 153),
|
||||
new XColor("light slate grey", 119, 136, 153),
|
||||
new XColor("light steel blue", 176, 196, 222),
|
||||
new XColor("light yellow", 255, 255, 224),
|
||||
new XColor("lightblue", 173, 216, 230),
|
||||
new XColor("lightblue1", 191, 239, 255),
|
||||
new XColor("lightblue2", 178, 223, 238),
|
||||
new XColor("lightblue3", 154, 192, 205),
|
||||
new XColor("lightblue4", 104, 131, 139),
|
||||
new XColor("lightcoral", 240, 128, 128),
|
||||
new XColor("lightcyan", 224, 255, 255),
|
||||
new XColor("lightcyan1", 224, 255, 255),
|
||||
new XColor("lightcyan2", 209, 238, 238),
|
||||
new XColor("lightcyan3", 180, 205, 205),
|
||||
new XColor("lightcyan4", 122, 139, 139),
|
||||
new XColor("lightgoldenrod", 238, 221, 130),
|
||||
new XColor("lightgoldenrod1", 255, 236, 139),
|
||||
new XColor("lightgoldenrod2", 238, 220, 130),
|
||||
new XColor("lightgoldenrod3", 205, 190, 112),
|
||||
new XColor("lightgoldenrod4", 139, 129, 76),
|
||||
new XColor("lightgoldenrodyellow", 250, 250, 210),
|
||||
new XColor("lightgray", 211, 211, 211),
|
||||
new XColor("lightgreen", 144, 238, 144),
|
||||
new XColor("lightgrey", 211, 211, 211),
|
||||
new XColor("lightpink", 255, 182, 193),
|
||||
new XColor("lightpink1", 255, 174, 185),
|
||||
new XColor("lightpink2", 238, 162, 173),
|
||||
new XColor("lightpink3", 205, 140, 149),
|
||||
new XColor("lightpink4", 139, 95, 101),
|
||||
new XColor("lightsalmon", 255, 160, 122),
|
||||
new XColor("lightsalmon1", 255, 160, 122),
|
||||
new XColor("lightsalmon2", 238, 149, 114),
|
||||
new XColor("lightsalmon3", 205, 129, 98),
|
||||
new XColor("lightsalmon4", 139, 87, 66),
|
||||
new XColor("lightseagreen", 32, 178, 170),
|
||||
new XColor("lightskyblue", 135, 206, 250),
|
||||
new XColor("lightskyblue1", 176, 226, 255),
|
||||
new XColor("lightskyblue2", 164, 211, 238),
|
||||
new XColor("lightskyblue3", 141, 182, 205),
|
||||
new XColor("lightskyblue4", 96, 123, 139),
|
||||
new XColor("lightslateblue", 132, 112, 255),
|
||||
new XColor("lightslategray", 119, 136, 153),
|
||||
new XColor("lightslategrey", 119, 136, 153),
|
||||
new XColor("lightsteelblue", 176, 196, 222),
|
||||
new XColor("lightsteelblue1", 202, 225, 255),
|
||||
new XColor("lightsteelblue2", 188, 210, 238),
|
||||
new XColor("lightsteelblue3", 162, 181, 205),
|
||||
new XColor("lightsteelblue4", 110, 123, 139),
|
||||
new XColor("lightyellow", 255, 255, 224),
|
||||
new XColor("lightyellow1", 255, 255, 224),
|
||||
new XColor("lightyellow2", 238, 238, 209),
|
||||
new XColor("lightyellow3", 205, 205, 180),
|
||||
new XColor("lightyellow4", 139, 139, 122),
|
||||
new XColor("lime green", 50, 205, 50),
|
||||
new XColor("limegreen", 50, 205, 50),
|
||||
new XColor("linen", 250, 240, 230),
|
||||
new XColor("magenta", 255, 0, 255),
|
||||
new XColor("magenta1", 255, 0, 255),
|
||||
new XColor("magenta2", 238, 0, 238),
|
||||
new XColor("magenta3", 205, 0, 205),
|
||||
new XColor("magenta4", 139, 0, 139),
|
||||
new XColor("maroon", 176, 48, 96),
|
||||
new XColor("maroon1", 255, 52, 179),
|
||||
new XColor("maroon2", 238, 48, 167),
|
||||
new XColor("maroon3", 205, 41, 144),
|
||||
new XColor("maroon4", 139, 28, 98),
|
||||
new XColor("medium aquamarine", 102, 205, 170),
|
||||
new XColor("medium blue", 0, 0, 205),
|
||||
new XColor("medium orchid", 186, 85, 211),
|
||||
new XColor("medium purple", 147, 112, 219),
|
||||
new XColor("medium sea green", 60, 179, 113),
|
||||
new XColor("medium slate blue", 123, 104, 238),
|
||||
new XColor("medium spring green", 0, 250, 154),
|
||||
new XColor("medium turquoise", 72, 209, 204),
|
||||
new XColor("medium violet red", 199, 21, 133),
|
||||
new XColor("mediumaquamarine", 102, 205, 170),
|
||||
new XColor("mediumblue", 0, 0, 205),
|
||||
new XColor("mediumorchid", 186, 85, 211),
|
||||
new XColor("mediumorchid1", 224, 102, 255),
|
||||
new XColor("mediumorchid2", 209, 95, 238),
|
||||
new XColor("mediumorchid3", 180, 82, 205),
|
||||
new XColor("mediumorchid4", 122, 55, 139),
|
||||
new XColor("mediumpurple", 147, 112, 219),
|
||||
new XColor("mediumpurple1", 171, 130, 255),
|
||||
new XColor("mediumpurple2", 159, 121, 238),
|
||||
new XColor("mediumpurple3", 137, 104, 205),
|
||||
new XColor("mediumpurple4", 93, 71, 139),
|
||||
new XColor("mediumseagreen", 60, 179, 113),
|
||||
new XColor("mediumslateblue", 123, 104, 238),
|
||||
new XColor("mediumspringgreen", 0, 250, 154),
|
||||
new XColor("mediumturquoise", 72, 209, 204),
|
||||
new XColor("mediumvioletred", 199, 21, 133),
|
||||
new XColor("midnight blue", 25, 25, 112),
|
||||
new XColor("midnightblue", 25, 25, 112),
|
||||
new XColor("mint cream", 245, 255, 250),
|
||||
new XColor("mintcream", 245, 255, 250),
|
||||
new XColor("misty rose", 255, 228, 225),
|
||||
new XColor("mistyrose", 255, 228, 225),
|
||||
new XColor("mistyrose1", 255, 228, 225),
|
||||
new XColor("mistyrose2", 238, 213, 210),
|
||||
new XColor("mistyrose3", 205, 183, 181),
|
||||
new XColor("mistyrose4", 139, 125, 123),
|
||||
new XColor("moccasin", 255, 228, 181),
|
||||
new XColor("navajo white", 255, 222, 173),
|
||||
new XColor("navajowhite", 255, 222, 173),
|
||||
new XColor("navajowhite1", 255, 222, 173),
|
||||
new XColor("navajowhite2", 238, 207, 161),
|
||||
new XColor("navajowhite3", 205, 179, 139),
|
||||
new XColor("navajowhite4", 139, 121, 94),
|
||||
new XColor("navy", 0, 0, 128),
|
||||
new XColor("navy blue", 0, 0, 128),
|
||||
new XColor("navyblue", 0, 0, 128),
|
||||
new XColor("old lace", 253, 245, 230),
|
||||
new XColor("oldlace", 253, 245, 230),
|
||||
new XColor("olive drab", 107, 142, 35),
|
||||
new XColor("olivedrab", 107, 142, 35),
|
||||
new XColor("olivedrab1", 192, 255, 62),
|
||||
new XColor("olivedrab2", 179, 238, 58),
|
||||
new XColor("olivedrab3", 154, 205, 50),
|
||||
new XColor("olivedrab4", 105, 139, 34),
|
||||
new XColor("orange", 255, 165, 0),
|
||||
new XColor("orange red", 255, 69, 0),
|
||||
new XColor("orange1", 255, 165, 0),
|
||||
new XColor("orange2", 238, 154, 0),
|
||||
new XColor("orange3", 205, 133, 0),
|
||||
new XColor("orange4", 139, 90, 0),
|
||||
new XColor("orangered", 255, 69, 0),
|
||||
new XColor("orangered1", 255, 69, 0),
|
||||
new XColor("orangered2", 238, 64, 0),
|
||||
new XColor("orangered3", 205, 55, 0),
|
||||
new XColor("orangered4", 139, 37, 0),
|
||||
new XColor("orchid", 218, 112, 214),
|
||||
new XColor("orchid1", 255, 131, 250),
|
||||
new XColor("orchid2", 238, 122, 233),
|
||||
new XColor("orchid3", 205, 105, 201),
|
||||
new XColor("orchid4", 139, 71, 137),
|
||||
new XColor("pale goldenrod", 238, 232, 170),
|
||||
new XColor("pale green", 152, 251, 152),
|
||||
new XColor("pale turquoise", 175, 238, 238),
|
||||
new XColor("pale violet red", 219, 112, 147),
|
||||
new XColor("palegoldenrod", 238, 232, 170),
|
||||
new XColor("palegreen", 152, 251, 152),
|
||||
new XColor("palegreen1", 154, 255, 154),
|
||||
new XColor("palegreen2", 144, 238, 144),
|
||||
new XColor("palegreen3", 124, 205, 124),
|
||||
new XColor("palegreen4", 84, 139, 84),
|
||||
new XColor("paleturquoise", 175, 238, 238),
|
||||
new XColor("paleturquoise1", 187, 255, 255),
|
||||
new XColor("paleturquoise2", 174, 238, 238),
|
||||
new XColor("paleturquoise3", 150, 205, 205),
|
||||
new XColor("paleturquoise4", 102, 139, 139),
|
||||
new XColor("palevioletred", 219, 112, 147),
|
||||
new XColor("palevioletred1", 255, 130, 171),
|
||||
new XColor("palevioletred2", 238, 121, 159),
|
||||
new XColor("palevioletred3", 205, 104, 137),
|
||||
new XColor("palevioletred4", 139, 71, 93),
|
||||
new XColor("papaya whip", 255, 239, 213),
|
||||
new XColor("papayawhip", 255, 239, 213),
|
||||
new XColor("peach puff", 255, 218, 185),
|
||||
new XColor("peachpuff", 255, 218, 185),
|
||||
new XColor("peachpuff1", 255, 218, 185),
|
||||
new XColor("peachpuff2", 238, 203, 173),
|
||||
new XColor("peachpuff3", 205, 175, 149),
|
||||
new XColor("peachpuff4", 139, 119, 101),
|
||||
new XColor("peru", 205, 133, 63),
|
||||
new XColor("pink", 255, 192, 203),
|
||||
new XColor("pink1", 255, 181, 197),
|
||||
new XColor("pink2", 238, 169, 184),
|
||||
new XColor("pink3", 205, 145, 158),
|
||||
new XColor("pink4", 139, 99, 108),
|
||||
new XColor("plum", 221, 160, 221),
|
||||
new XColor("plum1", 255, 187, 255),
|
||||
new XColor("plum2", 238, 174, 238),
|
||||
new XColor("plum3", 205, 150, 205),
|
||||
new XColor("plum4", 139, 102, 139),
|
||||
new XColor("powder blue", 176, 224, 230),
|
||||
new XColor("powderblue", 176, 224, 230),
|
||||
new XColor("purple", 160, 32, 240),
|
||||
new XColor("purple1", 155, 48, 255),
|
||||
new XColor("purple2", 145, 44, 238),
|
||||
new XColor("purple3", 125, 38, 205),
|
||||
new XColor("purple4", 85, 26, 139),
|
||||
new XColor("red", 255, 0, 0),
|
||||
new XColor("red1", 255, 0, 0),
|
||||
new XColor("red2", 238, 0, 0),
|
||||
new XColor("red3", 205, 0, 0),
|
||||
new XColor("red4", 139, 0, 0),
|
||||
new XColor("rosy brown", 188, 143, 143),
|
||||
new XColor("rosybrown", 188, 143, 143),
|
||||
new XColor("rosybrown1", 255, 193, 193),
|
||||
new XColor("rosybrown2", 238, 180, 180),
|
||||
new XColor("rosybrown3", 205, 155, 155),
|
||||
new XColor("rosybrown4", 139, 105, 105),
|
||||
new XColor("royal blue", 65, 105, 225),
|
||||
new XColor("royalblue", 65, 105, 225),
|
||||
new XColor("royalblue1", 72, 118, 255),
|
||||
new XColor("royalblue2", 67, 110, 238),
|
||||
new XColor("royalblue3", 58, 95, 205),
|
||||
new XColor("royalblue4", 39, 64, 139),
|
||||
new XColor("saddle brown", 139, 69, 19),
|
||||
new XColor("saddlebrown", 139, 69, 19),
|
||||
new XColor("salmon", 250, 128, 114),
|
||||
new XColor("salmon1", 255, 140, 105),
|
||||
new XColor("salmon2", 238, 130, 98),
|
||||
new XColor("salmon3", 205, 112, 84),
|
||||
new XColor("salmon4", 139, 76, 57),
|
||||
new XColor("sandy brown", 244, 164, 96),
|
||||
new XColor("sandybrown", 244, 164, 96),
|
||||
new XColor("sea green", 46, 139, 87),
|
||||
new XColor("seagreen", 46, 139, 87),
|
||||
new XColor("seagreen1", 84, 255, 159),
|
||||
new XColor("seagreen2", 78, 238, 148),
|
||||
new XColor("seagreen3", 67, 205, 128),
|
||||
new XColor("seagreen4", 46, 139, 87),
|
||||
new XColor("seashell", 255, 245, 238),
|
||||
new XColor("seashell1", 255, 245, 238),
|
||||
new XColor("seashell2", 238, 229, 222),
|
||||
new XColor("seashell3", 205, 197, 191),
|
||||
new XColor("seashell4", 139, 134, 130),
|
||||
new XColor("sienna", 160, 82, 45),
|
||||
new XColor("sienna1", 255, 130, 71),
|
||||
new XColor("sienna2", 238, 121, 66),
|
||||
new XColor("sienna3", 205, 104, 57),
|
||||
new XColor("sienna4", 139, 71, 38),
|
||||
new XColor("sky blue", 135, 206, 235),
|
||||
new XColor("skyblue", 135, 206, 235),
|
||||
new XColor("skyblue1", 135, 206, 255),
|
||||
new XColor("skyblue2", 126, 192, 238),
|
||||
new XColor("skyblue3", 108, 166, 205),
|
||||
new XColor("skyblue4", 74, 112, 139),
|
||||
new XColor("slate blue", 106, 90, 205),
|
||||
new XColor("slate gray", 112, 128, 144),
|
||||
new XColor("slate grey", 112, 128, 144),
|
||||
new XColor("slateblue", 106, 90, 205),
|
||||
new XColor("slateblue1", 131, 111, 255),
|
||||
new XColor("slateblue2", 122, 103, 238),
|
||||
new XColor("slateblue3", 105, 89, 205),
|
||||
new XColor("slateblue4", 71, 60, 139),
|
||||
new XColor("slategray", 112, 128, 144),
|
||||
new XColor("slategray1", 198, 226, 255),
|
||||
new XColor("slategray2", 185, 211, 238),
|
||||
new XColor("slategray3", 159, 182, 205),
|
||||
new XColor("slategray4", 108, 123, 139),
|
||||
new XColor("slategrey", 112, 128, 144),
|
||||
new XColor("snow", 255, 250, 250),
|
||||
new XColor("snow1", 255, 250, 250),
|
||||
new XColor("snow2", 238, 233, 233),
|
||||
new XColor("snow3", 205, 201, 201),
|
||||
new XColor("snow4", 139, 137, 137),
|
||||
new XColor("spring green", 0, 255, 127),
|
||||
new XColor("springgreen", 0, 255, 127),
|
||||
new XColor("springgreen1", 0, 255, 127),
|
||||
new XColor("springgreen2", 0, 238, 118),
|
||||
new XColor("springgreen3", 0, 205, 102),
|
||||
new XColor("springgreen4", 0, 139, 69),
|
||||
new XColor("steel blue", 70, 130, 180),
|
||||
new XColor("steelblue", 70, 130, 180),
|
||||
new XColor("steelblue1", 99, 184, 255),
|
||||
new XColor("steelblue2", 92, 172, 238),
|
||||
new XColor("steelblue3", 79, 148, 205),
|
||||
new XColor("steelblue4", 54, 100, 139),
|
||||
new XColor("tan", 210, 180, 140),
|
||||
new XColor("tan1", 255, 165, 79),
|
||||
new XColor("tan2", 238, 154, 73),
|
||||
new XColor("tan3", 205, 133, 63),
|
||||
new XColor("tan4", 139, 90, 43),
|
||||
new XColor("thistle", 216, 191, 216),
|
||||
new XColor("thistle1", 255, 225, 255),
|
||||
new XColor("thistle2", 238, 210, 238),
|
||||
new XColor("thistle3", 205, 181, 205),
|
||||
new XColor("thistle4", 139, 123, 139),
|
||||
new XColor("tomato", 255, 99, 71),
|
||||
new XColor("tomato1", 255, 99, 71),
|
||||
new XColor("tomato2", 238, 92, 66),
|
||||
new XColor("tomato3", 205, 79, 57),
|
||||
new XColor("tomato4", 139, 54, 38),
|
||||
new XColor("turquoise", 64, 224, 208),
|
||||
new XColor("turquoise1", 0, 245, 255),
|
||||
new XColor("turquoise2", 0, 229, 238),
|
||||
new XColor("turquoise3", 0, 197, 205),
|
||||
new XColor("turquoise4", 0, 134, 139),
|
||||
new XColor("violet", 238, 130, 238),
|
||||
new XColor("violet red", 208, 32, 144),
|
||||
new XColor("violetred", 208, 32, 144),
|
||||
new XColor("violetred1", 255, 62, 150),
|
||||
new XColor("violetred2", 238, 58, 140),
|
||||
new XColor("violetred3", 205, 50, 120),
|
||||
new XColor("violetred4", 139, 34, 82),
|
||||
new XColor("wheat", 245, 222, 179),
|
||||
new XColor("wheat1", 255, 231, 186),
|
||||
new XColor("wheat2", 238, 216, 174),
|
||||
new XColor("wheat3", 205, 186, 150),
|
||||
new XColor("wheat4", 139, 126, 102),
|
||||
new XColor("white", 255, 255, 255),
|
||||
new XColor("white smoke", 245, 245, 245),
|
||||
new XColor("whitesmoke", 245, 245, 245),
|
||||
new XColor("yellow", 255, 255, 0),
|
||||
new XColor("yellow green", 154, 205, 50),
|
||||
new XColor("yellow1", 255, 255, 0),
|
||||
new XColor("yellow2", 238, 238, 0),
|
||||
new XColor("yellow3", 205, 205, 0),
|
||||
new XColor("yellow4", 139, 139, 0),
|
||||
new XColor("yellowgreen", 154, 205, 5)
|
||||
};
|
||||
|
||||
}
|
||||
734
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifBorders.java
Normal file
734
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifBorders.java
Normal file
@@ -0,0 +1,734 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2010, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import sun.swing.SwingUtilities2;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.*;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
/**
|
||||
* Factory object that can vend Icons appropriate for the basic L & F.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Amy Fowler
|
||||
*/
|
||||
public class MotifBorders {
|
||||
|
||||
public static class BevelBorder extends AbstractBorder implements UIResource {
|
||||
private Color darkShadow = UIManager.getColor("controlShadow");
|
||||
private Color lightShadow = UIManager.getColor("controlLtHighlight");
|
||||
private boolean isRaised;
|
||||
|
||||
public BevelBorder(boolean isRaised, Color darkShadow, Color lightShadow) {
|
||||
this.isRaised = isRaised;
|
||||
this.darkShadow = darkShadow;
|
||||
this.lightShadow = lightShadow;
|
||||
}
|
||||
|
||||
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
|
||||
g.setColor((isRaised) ? lightShadow : darkShadow);
|
||||
g.drawLine(x, y, x+w-1, y); // top
|
||||
g.drawLine(x, y+h-1, x, y+1); // left
|
||||
|
||||
g.setColor((isRaised) ? darkShadow : lightShadow);
|
||||
g.drawLine(x+1, y+h-1, x+w-1, y+h-1); // bottom
|
||||
g.drawLine(x+w-1, y+h-1, x+w-1, y+1); // right
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets insets) {
|
||||
insets.set(1, 1, 1, 1);
|
||||
return insets;
|
||||
}
|
||||
|
||||
public boolean isOpaque(Component c) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static class FocusBorder extends AbstractBorder implements UIResource {
|
||||
private Color focus;
|
||||
private Color control;
|
||||
|
||||
public FocusBorder(Color control, Color focus) {
|
||||
this.control = control;
|
||||
this.focus = focus;
|
||||
}
|
||||
|
||||
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
|
||||
if (c.hasFocus()) {
|
||||
g.setColor(focus);
|
||||
g.drawRect(x, y, w-1, h-1);
|
||||
} else {
|
||||
g.setColor(control);
|
||||
g.drawRect(x, y, w-1, h-1);
|
||||
}
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets insets) {
|
||||
insets.set(1, 1, 1, 1);
|
||||
return insets;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class ButtonBorder extends AbstractBorder implements UIResource {
|
||||
protected Color focus = UIManager.getColor("activeCaptionBorder");
|
||||
protected Color shadow = UIManager.getColor("Button.shadow");
|
||||
protected Color highlight = UIManager.getColor("Button.light");
|
||||
protected Color darkShadow;
|
||||
|
||||
public ButtonBorder(Color shadow, Color highlight, Color darkShadow, Color focus) {
|
||||
this.shadow = shadow;
|
||||
this.highlight = highlight;
|
||||
this.darkShadow = darkShadow;
|
||||
this.focus = focus;
|
||||
}
|
||||
|
||||
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
|
||||
boolean isPressed = false;
|
||||
boolean hasFocus = false;
|
||||
boolean canBeDefault = false;
|
||||
boolean isDefault = false;
|
||||
|
||||
if (c instanceof AbstractButton) {
|
||||
AbstractButton b = (AbstractButton)c;
|
||||
ButtonModel model = b.getModel();
|
||||
|
||||
isPressed = (model.isArmed() && model.isPressed());
|
||||
hasFocus = (model.isArmed() && isPressed) ||
|
||||
(b.isFocusPainted() && b.hasFocus());
|
||||
if (b instanceof JButton) {
|
||||
canBeDefault = ((JButton)b).isDefaultCapable();
|
||||
isDefault = ((JButton)b).isDefaultButton();
|
||||
}
|
||||
}
|
||||
int bx1 = x+1;
|
||||
int by1 = y+1;
|
||||
int bx2 = x+w-2;
|
||||
int by2 = y+h-2;
|
||||
|
||||
if (canBeDefault) {
|
||||
if (isDefault) {
|
||||
g.setColor(shadow);
|
||||
g.drawLine(x+3, y+3, x+3, y+h-4);
|
||||
g.drawLine(x+3, y+3, x+w-4, y+3);
|
||||
|
||||
g.setColor(highlight);
|
||||
g.drawLine(x+4, y+h-4, x+w-4, y+h-4);
|
||||
g.drawLine(x+w-4, y+3, x+w-4, y+h-4);
|
||||
}
|
||||
bx1 +=6;
|
||||
by1 += 6;
|
||||
bx2 -= 6;
|
||||
by2 -= 6;
|
||||
}
|
||||
|
||||
if (hasFocus) {
|
||||
g.setColor(focus);
|
||||
if (isDefault) {
|
||||
g.drawRect(x, y, w-1, h-1);
|
||||
} else {
|
||||
g.drawRect(bx1-1, by1-1, bx2-bx1+2, by2-by1+2);
|
||||
}
|
||||
}
|
||||
|
||||
g.setColor(isPressed? shadow : highlight);
|
||||
g.drawLine(bx1, by1, bx2, by1);
|
||||
g.drawLine(bx1, by1, bx1, by2);
|
||||
|
||||
g.setColor(isPressed? highlight : shadow);
|
||||
g.drawLine(bx2, by1+1, bx2, by2);
|
||||
g.drawLine(bx1+1, by2, bx2, by2);
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets insets) {
|
||||
int thickness = (c instanceof JButton && ((JButton)c).isDefaultCapable())? 8 : 2;
|
||||
insets.set(thickness, thickness, thickness, thickness);
|
||||
return insets;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class ToggleButtonBorder extends ButtonBorder {
|
||||
|
||||
public ToggleButtonBorder(Color shadow, Color highlight, Color darkShadow, Color focus) {
|
||||
super(shadow, highlight, darkShadow, focus);
|
||||
}
|
||||
|
||||
public void paintBorder(Component c, Graphics g, int x, int y,
|
||||
int width, int height) {
|
||||
if (c instanceof AbstractButton) {
|
||||
AbstractButton b = (AbstractButton)c;
|
||||
ButtonModel model = b.getModel();
|
||||
|
||||
if (model.isArmed() && model.isPressed() || model.isSelected()) {
|
||||
drawBezel(g, x, y, width, height,
|
||||
(model.isPressed() || model.isSelected()),
|
||||
b.isFocusPainted() && b.hasFocus(), shadow, highlight, darkShadow, focus);
|
||||
} else {
|
||||
drawBezel(g, x, y, width, height,
|
||||
false, b.isFocusPainted() && b.hasFocus(),
|
||||
shadow, highlight, darkShadow, focus);
|
||||
}
|
||||
} else {
|
||||
drawBezel(g, x, y, width, height, false, false,
|
||||
shadow, highlight, darkShadow, focus);
|
||||
}
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets insets) {
|
||||
insets.set(2, 2, 3, 3);
|
||||
return insets;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MenuBarBorder extends ButtonBorder {
|
||||
|
||||
public MenuBarBorder(Color shadow, Color highlight, Color darkShadow, Color focus) {
|
||||
super(shadow, highlight, darkShadow, focus);
|
||||
}
|
||||
|
||||
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
|
||||
if (!(c instanceof JMenuBar)) {
|
||||
return;
|
||||
}
|
||||
JMenuBar menuBar = (JMenuBar)c;
|
||||
if (menuBar.isBorderPainted() == true) {
|
||||
// this draws the MenuBar border
|
||||
Dimension size = menuBar.getSize();
|
||||
drawBezel(g,x,y,size.width,size.height,false,false,
|
||||
shadow, highlight, darkShadow, focus);
|
||||
}
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets insets) {
|
||||
insets.set(6, 6, 6, 6);
|
||||
return insets;
|
||||
}
|
||||
}
|
||||
|
||||
public static class FrameBorder extends AbstractBorder implements UIResource {
|
||||
|
||||
JComponent jcomp;
|
||||
Color frameHighlight;
|
||||
Color frameColor;
|
||||
Color frameShadow;
|
||||
|
||||
// The width of the border
|
||||
public final static int BORDER_SIZE = 5;
|
||||
|
||||
/** Constructs an FrameBorder for the JComponent <b>comp</b>.
|
||||
*/
|
||||
public FrameBorder(JComponent comp) {
|
||||
jcomp = comp;
|
||||
}
|
||||
|
||||
/** Sets the FrameBorder's JComponent.
|
||||
*/
|
||||
public void setComponent(JComponent comp) {
|
||||
jcomp = comp;
|
||||
}
|
||||
|
||||
/** Returns the FrameBorder's JComponent.
|
||||
* @see #setComponent
|
||||
*/
|
||||
public JComponent component() {
|
||||
return jcomp;
|
||||
}
|
||||
|
||||
protected Color getFrameHighlight() {
|
||||
return frameHighlight;
|
||||
}
|
||||
|
||||
protected Color getFrameColor() {
|
||||
return frameColor;
|
||||
}
|
||||
|
||||
protected Color getFrameShadow() {
|
||||
return frameShadow;
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets newInsets) {
|
||||
newInsets.set(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE);
|
||||
return newInsets;
|
||||
}
|
||||
|
||||
/** Draws the FrameBorder's top border.
|
||||
*/
|
||||
protected boolean drawTopBorder(Component c, Graphics g,
|
||||
int x, int y, int width, int height) {
|
||||
Rectangle titleBarRect = new Rectangle(x, y, width, BORDER_SIZE);
|
||||
if (!g.getClipBounds().intersects(titleBarRect)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int maxX = width - 1;
|
||||
int maxY = BORDER_SIZE - 1;
|
||||
|
||||
// Draw frame
|
||||
g.setColor(frameColor);
|
||||
g.drawLine(x, y + 2, maxX - 2, y + 2);
|
||||
g.drawLine(x, y + 3, maxX - 2, y + 3);
|
||||
g.drawLine(x, y + 4, maxX - 2, y + 4);
|
||||
|
||||
// Draw highlights
|
||||
g.setColor(frameHighlight);
|
||||
g.drawLine(x, y, maxX, y);
|
||||
g.drawLine(x, y + 1, maxX, y + 1);
|
||||
g.drawLine(x, y + 2, x, y + 4);
|
||||
g.drawLine(x + 1, y + 2, x + 1, y + 4);
|
||||
|
||||
// Draw shadows
|
||||
g.setColor(frameShadow);
|
||||
g.drawLine(x + 4, y + 4, maxX - 4, y + 4);
|
||||
g.drawLine(maxX, y + 1, maxX, maxY);
|
||||
g.drawLine(maxX - 1, y + 2, maxX - 1, maxY);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Draws the FrameBorder's left border.
|
||||
*/
|
||||
protected boolean drawLeftBorder(Component c, Graphics g, int x, int y,
|
||||
int width, int height) {
|
||||
Rectangle borderRect =
|
||||
new Rectangle(0, 0, getBorderInsets(c).left, height);
|
||||
if (!g.getClipBounds().intersects(borderRect)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int startY = BORDER_SIZE;
|
||||
|
||||
g.setColor(frameHighlight);
|
||||
g.drawLine(x, startY, x, height - 1);
|
||||
g.drawLine(x + 1, startY, x + 1, height - 2);
|
||||
|
||||
g.setColor(frameColor);
|
||||
g.fillRect(x + 2, startY, x + 2, height - 3);
|
||||
|
||||
g.setColor(frameShadow);
|
||||
g.drawLine(x + 4, startY, x + 4, height - 5);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Draws the FrameBorder's right border.
|
||||
*/
|
||||
protected boolean drawRightBorder(Component c, Graphics g, int x, int y,
|
||||
int width, int height) {
|
||||
Rectangle borderRect = new Rectangle(
|
||||
width - getBorderInsets(c).right, 0,
|
||||
getBorderInsets(c).right, height);
|
||||
if (!g.getClipBounds().intersects(borderRect)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int startX = width - getBorderInsets(c).right;
|
||||
int startY = BORDER_SIZE;
|
||||
|
||||
g.setColor(frameColor);
|
||||
g.fillRect(startX + 1, startY, 2, height - 1);
|
||||
|
||||
g.setColor(frameShadow);
|
||||
g.fillRect(startX + 3, startY, 2, height - 1);
|
||||
|
||||
g.setColor(frameHighlight);
|
||||
g.drawLine(startX, startY, startX, height - 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Draws the FrameBorder's bottom border.
|
||||
*/
|
||||
protected boolean drawBottomBorder(Component c, Graphics g, int x, int y,
|
||||
int width, int height) {
|
||||
Rectangle borderRect;
|
||||
int marginHeight, startY;
|
||||
|
||||
borderRect = new Rectangle(0, height - getBorderInsets(c).bottom,
|
||||
width, getBorderInsets(c).bottom);
|
||||
if (!g.getClipBounds().intersects(borderRect)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
startY = height - getBorderInsets(c).bottom;
|
||||
|
||||
g.setColor(frameShadow);
|
||||
g.drawLine(x + 1, height - 1, width - 1, height - 1);
|
||||
g.drawLine(x + 2, height - 2, width - 2, height - 2);
|
||||
|
||||
g.setColor(frameColor);
|
||||
g.fillRect(x + 2, startY + 1, width - 4, 2);
|
||||
|
||||
g.setColor(frameHighlight);
|
||||
g.drawLine(x + 5, startY, width - 5, startY);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Returns true if the associated component has focus.
|
||||
protected boolean isActiveFrame() {
|
||||
return jcomp.hasFocus();
|
||||
}
|
||||
|
||||
/** Draws the FrameBorder in the given Rect. Calls
|
||||
* <b>drawTitleBar</b>, <b>drawLeftBorder</b>, <b>drawRightBorder</b> and
|
||||
* <b>drawBottomBorder</b>.
|
||||
*/
|
||||
public void paintBorder(Component c, Graphics g,
|
||||
int x, int y, int width, int height) {
|
||||
if (isActiveFrame()) {
|
||||
frameColor = UIManager.getColor("activeCaptionBorder");
|
||||
} else {
|
||||
frameColor = UIManager.getColor("inactiveCaptionBorder");
|
||||
}
|
||||
frameHighlight = frameColor.brighter();
|
||||
frameShadow = frameColor.darker().darker();
|
||||
|
||||
drawTopBorder(c, g, x, y, width, height);
|
||||
drawLeftBorder(c, g, x, y, width, height);
|
||||
drawRightBorder(c, g, x, y, width, height);
|
||||
drawBottomBorder(c, g, x, y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
public static class InternalFrameBorder extends FrameBorder {
|
||||
|
||||
JInternalFrame frame;
|
||||
|
||||
// The size of the bounding box for Motif frame corners.
|
||||
public final static int CORNER_SIZE = 24;
|
||||
|
||||
/** Constructs an InternalFrameBorder for the InternalFrame
|
||||
* <b>aFrame</b>.
|
||||
*/
|
||||
public InternalFrameBorder(JInternalFrame aFrame) {
|
||||
super(aFrame);
|
||||
frame = aFrame;
|
||||
}
|
||||
|
||||
/** Sets the InternalFrameBorder's InternalFrame.
|
||||
*/
|
||||
public void setFrame(JInternalFrame aFrame) {
|
||||
frame = aFrame;
|
||||
}
|
||||
|
||||
/** Returns the InternalFrameBorder's InternalFrame.
|
||||
* @see #setFrame
|
||||
*/
|
||||
public JInternalFrame frame() {
|
||||
return frame;
|
||||
}
|
||||
|
||||
/** Returns the width of the InternalFrameBorder's resize controls,
|
||||
* appearing along the InternalFrameBorder's bottom border. Clicking
|
||||
* and dragging within these controls lets the user change both the
|
||||
* InternalFrame's width and height, while dragging between the controls
|
||||
* constrains resizing to just the vertical dimension. Override this
|
||||
* method if you implement your own bottom border painting and use a
|
||||
* resize control with a different size.
|
||||
*/
|
||||
public int resizePartWidth() {
|
||||
if (!frame.isResizable()) {
|
||||
return 0;
|
||||
}
|
||||
return FrameBorder.BORDER_SIZE;
|
||||
}
|
||||
|
||||
/** Draws the InternalFrameBorder's top border.
|
||||
*/
|
||||
protected boolean drawTopBorder(Component c, Graphics g,
|
||||
int x, int y, int width, int height) {
|
||||
if (super.drawTopBorder(c, g, x, y, width, height) &&
|
||||
frame.isResizable()) {
|
||||
g.setColor(getFrameShadow());
|
||||
g.drawLine(CORNER_SIZE - 1, y + 1, CORNER_SIZE - 1, y + 4);
|
||||
g.drawLine(width - CORNER_SIZE - 1, y + 1,
|
||||
width - CORNER_SIZE - 1, y + 4);
|
||||
|
||||
g.setColor(getFrameHighlight());
|
||||
g.drawLine(CORNER_SIZE, y, CORNER_SIZE, y + 4);
|
||||
g.drawLine(width - CORNER_SIZE, y, width - CORNER_SIZE, y + 4);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Draws the InternalFrameBorder's left border.
|
||||
*/
|
||||
protected boolean drawLeftBorder(Component c, Graphics g, int x, int y,
|
||||
int width, int height) {
|
||||
if (super.drawLeftBorder(c, g, x, y, width, height) &&
|
||||
frame.isResizable()) {
|
||||
g.setColor(getFrameHighlight());
|
||||
int topY = y + CORNER_SIZE;
|
||||
g.drawLine(x, topY, x + 4, topY);
|
||||
int bottomY = height - CORNER_SIZE;
|
||||
g.drawLine(x + 1, bottomY, x + 5, bottomY);
|
||||
g.setColor(getFrameShadow());
|
||||
g.drawLine(x + 1, topY - 1, x + 5, topY - 1);
|
||||
g.drawLine(x + 1, bottomY - 1, x + 5, bottomY - 1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Draws the InternalFrameBorder's right border.
|
||||
*/
|
||||
protected boolean drawRightBorder(Component c, Graphics g, int x, int y,
|
||||
int width, int height) {
|
||||
if (super.drawRightBorder(c, g, x, y, width, height) &&
|
||||
frame.isResizable()) {
|
||||
int startX = width - getBorderInsets(c).right;
|
||||
g.setColor(getFrameHighlight());
|
||||
int topY = y + CORNER_SIZE;
|
||||
g.drawLine(startX, topY, width - 2, topY);
|
||||
int bottomY = height - CORNER_SIZE;
|
||||
g.drawLine(startX + 1, bottomY, startX + 3, bottomY);
|
||||
g.setColor(getFrameShadow());
|
||||
g.drawLine(startX + 1, topY - 1, width - 2, topY - 1);
|
||||
g.drawLine(startX + 1, bottomY - 1, startX + 3, bottomY - 1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Draws the InternalFrameBorder's bottom border.
|
||||
*/
|
||||
protected boolean drawBottomBorder(Component c, Graphics g, int x, int y,
|
||||
int width, int height) {
|
||||
if (super.drawBottomBorder(c, g, x, y, width, height) &&
|
||||
frame.isResizable()) {
|
||||
int startY = height - getBorderInsets(c).bottom;
|
||||
|
||||
g.setColor(getFrameShadow());
|
||||
g.drawLine(CORNER_SIZE - 1, startY + 1,
|
||||
CORNER_SIZE - 1, height - 1);
|
||||
g.drawLine(width - CORNER_SIZE, startY + 1,
|
||||
width - CORNER_SIZE, height - 1);
|
||||
|
||||
g.setColor(getFrameHighlight());
|
||||
g.drawLine(CORNER_SIZE, startY, CORNER_SIZE, height - 2);
|
||||
g.drawLine(width - CORNER_SIZE + 1, startY,
|
||||
width - CORNER_SIZE + 1, height - 2);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Returns true if the associated internal frame has focus.
|
||||
protected boolean isActiveFrame() {
|
||||
return frame.isSelected();
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawBezel(Graphics g, int x, int y, int w, int h,
|
||||
boolean isPressed, boolean hasFocus,
|
||||
Color shadow, Color highlight,
|
||||
Color darkShadow, Color focus) {
|
||||
|
||||
Color oldColor = g.getColor();
|
||||
g.translate(x, y);
|
||||
|
||||
if (isPressed) {
|
||||
if (hasFocus){
|
||||
g.setColor(focus);
|
||||
g.drawRect(0, 0, w-1, h-1);
|
||||
}
|
||||
g.setColor(shadow); // inner border
|
||||
g.drawRect(1, 1, w-3, h-3);
|
||||
|
||||
g.setColor(highlight); // inner 3D border
|
||||
g.drawLine(2, h-3, w-3, h-3);
|
||||
g.drawLine(w-3, 2, w-3, h-4);
|
||||
|
||||
} else {
|
||||
if (hasFocus) {
|
||||
g.setColor(focus);
|
||||
g.drawRect(0, 0, w-1, h-1);
|
||||
|
||||
g.setColor(highlight); // inner 3D border
|
||||
g.drawLine(1, 1, 1, h-3);
|
||||
g.drawLine(2, 1, w-4, 1);
|
||||
|
||||
g.setColor(shadow);
|
||||
g.drawLine(2, h-3, w-3, h-3);
|
||||
g.drawLine(w-3, 1, w-3, h-4);
|
||||
|
||||
g.setColor(darkShadow); // black drop shadow __|
|
||||
g.drawLine(1, h-2, w-2, h-2);
|
||||
g.drawLine(w-2, h-2, w-2, 1);
|
||||
} else {
|
||||
g.setColor(highlight); // inner 3D border
|
||||
g.drawLine(1,1,1,h-3);
|
||||
g.drawLine(2,1,w-4,1);
|
||||
g.setColor(shadow);
|
||||
g.drawLine(2,h-3,w-3,h-3);
|
||||
g.drawLine(w-3,1,w-3,h-4);
|
||||
|
||||
g.setColor(darkShadow); // black drop shadow __|
|
||||
g.drawLine(1,h-2,w-2,h-2);
|
||||
g.drawLine(w-2,h-2,w-2,0);
|
||||
|
||||
}
|
||||
g.translate(-x, -y);
|
||||
}
|
||||
g.setColor(oldColor);
|
||||
}
|
||||
|
||||
public static class MotifPopupMenuBorder extends AbstractBorder implements UIResource {
|
||||
protected Font font;
|
||||
protected Color background;
|
||||
protected Color foreground;
|
||||
protected Color shadowColor;
|
||||
protected Color highlightColor;
|
||||
|
||||
// Space between the border and text
|
||||
static protected final int TEXT_SPACING = 2;
|
||||
|
||||
// Space for the separator under the title
|
||||
static protected final int GROOVE_HEIGHT = 2;
|
||||
|
||||
/**
|
||||
* Creates a MotifPopupMenuBorder instance
|
||||
*
|
||||
*/
|
||||
public MotifPopupMenuBorder(
|
||||
Font titleFont,
|
||||
Color bgColor,
|
||||
Color fgColor,
|
||||
Color shadow,
|
||||
Color highlight) {
|
||||
this.font = titleFont;
|
||||
this.background = bgColor;
|
||||
this.foreground = fgColor;
|
||||
this.shadowColor = shadow;
|
||||
this.highlightColor = highlight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints the border for the specified component with the
|
||||
* specified position and size.
|
||||
* @param c the component for which this border is being painted
|
||||
* @param g the paint graphics
|
||||
* @param x the x position of the painted border
|
||||
* @param y the y position of the painted border
|
||||
* @param width the width of the painted border
|
||||
* @param height the height of the painted border
|
||||
*/
|
||||
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
|
||||
if (!(c instanceof JPopupMenu)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Font origFont = g.getFont();
|
||||
Color origColor = g.getColor();
|
||||
JPopupMenu popup = (JPopupMenu)c;
|
||||
|
||||
String title = popup.getLabel();
|
||||
if (title == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
g.setFont(font);
|
||||
|
||||
FontMetrics fm = SwingUtilities2.getFontMetrics(popup, g, font);
|
||||
int fontHeight = fm.getHeight();
|
||||
int descent = fm.getDescent();
|
||||
int ascent = fm.getAscent();
|
||||
Point textLoc = new Point();
|
||||
int stringWidth = SwingUtilities2.stringWidth(popup, fm,
|
||||
title);
|
||||
|
||||
textLoc.y = y + ascent + TEXT_SPACING;
|
||||
textLoc.x = x + ((width - stringWidth) / 2);
|
||||
|
||||
g.setColor(background);
|
||||
g.fillRect(textLoc.x - TEXT_SPACING, textLoc.y - (fontHeight-descent),
|
||||
stringWidth + (2 * TEXT_SPACING), fontHeight - descent);
|
||||
g.setColor(foreground);
|
||||
SwingUtilities2.drawString(popup, g, title, textLoc.x, textLoc.y);
|
||||
|
||||
MotifGraphicsUtils.drawGroove(g, x, textLoc.y + TEXT_SPACING,
|
||||
width, GROOVE_HEIGHT,
|
||||
shadowColor, highlightColor);
|
||||
|
||||
g.setFont(origFont);
|
||||
g.setColor(origColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reinitialize the insets parameter with this Border's current Insets.
|
||||
* @param c the component for which this border insets value applies
|
||||
* @param insets the object to be reinitialized
|
||||
*/
|
||||
public Insets getBorderInsets(Component c, Insets insets) {
|
||||
if (!(c instanceof JPopupMenu)) {
|
||||
return insets;
|
||||
}
|
||||
FontMetrics fm;
|
||||
int descent = 0;
|
||||
int ascent = 16;
|
||||
|
||||
String title = ((JPopupMenu)c).getLabel();
|
||||
if (title == null) {
|
||||
insets.left = insets.top = insets.right = insets.bottom = 0;
|
||||
return insets;
|
||||
}
|
||||
|
||||
fm = c.getFontMetrics(font);
|
||||
|
||||
if(fm != null) {
|
||||
descent = fm.getDescent();
|
||||
ascent = fm.getAscent();
|
||||
}
|
||||
|
||||
insets.top += ascent + descent + TEXT_SPACING + GROOVE_HEIGHT;
|
||||
return insets;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2001, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import javax.swing.event.*;
|
||||
|
||||
/**
|
||||
* Button Listener
|
||||
* <p>
|
||||
*
|
||||
* @author Rich Schiavi
|
||||
*/
|
||||
public class MotifButtonListener extends BasicButtonListener {
|
||||
public MotifButtonListener(AbstractButton b ) {
|
||||
super(b);
|
||||
}
|
||||
|
||||
protected void checkOpacity(AbstractButton b) {
|
||||
b.setOpaque( false );
|
||||
}
|
||||
}
|
||||
150
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifButtonUI.java
Normal file
150
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifButtonUI.java
Normal file
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import sun.awt.AppContext;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.plaf.*;
|
||||
|
||||
/**
|
||||
* MotifButton 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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Rich Schiavi
|
||||
*/
|
||||
public class MotifButtonUI extends BasicButtonUI {
|
||||
|
||||
protected Color selectColor;
|
||||
|
||||
private boolean defaults_initialized = false;
|
||||
|
||||
private static final Object MOTIF_BUTTON_UI_KEY = new Object();
|
||||
|
||||
// ********************************
|
||||
// Create PLAF
|
||||
// ********************************
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
AppContext appContext = AppContext.getAppContext();
|
||||
MotifButtonUI motifButtonUI =
|
||||
(MotifButtonUI) appContext.get(MOTIF_BUTTON_UI_KEY);
|
||||
if (motifButtonUI == null) {
|
||||
motifButtonUI = new MotifButtonUI();
|
||||
appContext.put(MOTIF_BUTTON_UI_KEY, motifButtonUI);
|
||||
}
|
||||
return motifButtonUI;
|
||||
}
|
||||
|
||||
// ********************************
|
||||
// Create Listeners
|
||||
// ********************************
|
||||
protected BasicButtonListener createButtonListener(AbstractButton b){
|
||||
return new MotifButtonListener(b);
|
||||
}
|
||||
|
||||
// ********************************
|
||||
// Install Defaults
|
||||
// ********************************
|
||||
public void installDefaults(AbstractButton b) {
|
||||
super.installDefaults(b);
|
||||
if(!defaults_initialized) {
|
||||
selectColor = UIManager.getColor(getPropertyPrefix() + "select");
|
||||
defaults_initialized = true;
|
||||
}
|
||||
LookAndFeel.installProperty(b, "opaque", Boolean.FALSE);
|
||||
}
|
||||
|
||||
protected void uninstallDefaults(AbstractButton b) {
|
||||
super.uninstallDefaults(b);
|
||||
defaults_initialized = false;
|
||||
}
|
||||
|
||||
// ********************************
|
||||
// Default Accessors
|
||||
// ********************************
|
||||
|
||||
protected Color getSelectColor() {
|
||||
return selectColor;
|
||||
}
|
||||
|
||||
// ********************************
|
||||
// Paint Methods
|
||||
// ********************************
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
fillContentArea( g, (AbstractButton)c , c.getBackground() );
|
||||
super.paint(g,c);
|
||||
}
|
||||
|
||||
// Overridden to ensure we don't paint icon over button borders.
|
||||
protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) {
|
||||
Shape oldClip = g.getClip();
|
||||
Rectangle newClip =
|
||||
AbstractBorder.getInteriorRectangle(c, c.getBorder(), 0, 0,
|
||||
c.getWidth(), c.getHeight());
|
||||
|
||||
Rectangle r = oldClip.getBounds();
|
||||
newClip =
|
||||
SwingUtilities.computeIntersection(r.x, r.y, r.width, r.height,
|
||||
newClip);
|
||||
g.setClip(newClip);
|
||||
super.paintIcon(g, c, iconRect);
|
||||
g.setClip(oldClip);
|
||||
}
|
||||
|
||||
protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect){
|
||||
// focus painting is handled by the border
|
||||
}
|
||||
|
||||
protected void paintButtonPressed(Graphics g, AbstractButton b) {
|
||||
|
||||
fillContentArea( g, b , selectColor );
|
||||
|
||||
}
|
||||
|
||||
protected void fillContentArea( Graphics g, AbstractButton b, Color fillColor) {
|
||||
|
||||
if (b.isContentAreaFilled()) {
|
||||
Insets margin = b.getMargin();
|
||||
Insets insets = b.getInsets();
|
||||
Dimension size = b.getSize();
|
||||
g.setColor(fillColor);
|
||||
g.fillRect(insets.left - margin.left,
|
||||
insets.top - margin.top,
|
||||
size.width - (insets.left-margin.left) - (insets.right - margin.right),
|
||||
size.height - (insets.top-margin.top) - (insets.bottom - margin.bottom));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.BasicButtonListener;
|
||||
import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
|
||||
/**
|
||||
* MotifCheckboxMenuItem implementation
|
||||
* <p>
|
||||
*
|
||||
* @author Georges Saab
|
||||
* @author Rich Schiavi
|
||||
*/
|
||||
public class MotifCheckBoxMenuItemUI extends BasicCheckBoxMenuItemUI
|
||||
{
|
||||
protected ChangeListener changeListener;
|
||||
|
||||
public static ComponentUI createUI(JComponent b) {
|
||||
return new MotifCheckBoxMenuItemUI();
|
||||
}
|
||||
|
||||
protected void installListeners() {
|
||||
super.installListeners();
|
||||
changeListener = createChangeListener(menuItem);
|
||||
menuItem.addChangeListener(changeListener);
|
||||
}
|
||||
|
||||
protected void uninstallListeners() {
|
||||
super.uninstallListeners();
|
||||
menuItem.removeChangeListener(changeListener);
|
||||
}
|
||||
|
||||
protected ChangeListener createChangeListener(JComponent c) {
|
||||
return new ChangeHandler();
|
||||
}
|
||||
|
||||
protected class ChangeHandler implements ChangeListener {
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
JMenuItem c = (JMenuItem)e.getSource();
|
||||
LookAndFeel.installProperty(c, "borderPainted", c.isArmed());
|
||||
}
|
||||
}
|
||||
|
||||
protected MouseInputListener createMouseInputListener(JComponent c) {
|
||||
return new MouseInputHandler();
|
||||
}
|
||||
|
||||
|
||||
protected class MouseInputHandler implements MouseInputListener {
|
||||
public void mouseClicked(MouseEvent e) {}
|
||||
public void mousePressed(MouseEvent e) {
|
||||
MenuSelectionManager manager = MenuSelectionManager.defaultManager();
|
||||
manager.setSelectedPath(getPath());
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
MenuSelectionManager manager =
|
||||
MenuSelectionManager.defaultManager();
|
||||
JMenuItem menuItem = (JMenuItem)e.getComponent();
|
||||
Point p = e.getPoint();
|
||||
if(p.x >= 0 && p.x < menuItem.getWidth() &&
|
||||
p.y >= 0 && p.y < menuItem.getHeight()) {
|
||||
manager.clearSelectedPath();
|
||||
menuItem.doClick(0);
|
||||
} else {
|
||||
manager.processMouseEvent(e);
|
||||
}
|
||||
}
|
||||
public void mouseEntered(MouseEvent e) {}
|
||||
public void mouseExited(MouseEvent e) {}
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
MenuSelectionManager.defaultManager().processMouseEvent(e);
|
||||
}
|
||||
public void mouseMoved(MouseEvent e) { }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import sun.awt.AppContext;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import javax.swing.plaf.*;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* MotifCheckBox 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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Rich Schiavi
|
||||
*/
|
||||
public class MotifCheckBoxUI extends MotifRadioButtonUI {
|
||||
|
||||
private static final Object MOTIF_CHECK_BOX_UI_KEY = new Object();
|
||||
|
||||
private final static String propertyPrefix = "CheckBox" + ".";
|
||||
|
||||
private boolean defaults_initialized = false;
|
||||
|
||||
|
||||
// ********************************
|
||||
// Create PLAF
|
||||
// ********************************
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
AppContext appContext = AppContext.getAppContext();
|
||||
MotifCheckBoxUI motifCheckBoxUI =
|
||||
(MotifCheckBoxUI) appContext.get(MOTIF_CHECK_BOX_UI_KEY);
|
||||
if (motifCheckBoxUI == null) {
|
||||
motifCheckBoxUI = new MotifCheckBoxUI();
|
||||
appContext.put(MOTIF_CHECK_BOX_UI_KEY, motifCheckBoxUI);
|
||||
}
|
||||
return motifCheckBoxUI;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
361
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifComboBoxUI.java
Normal file
361
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifComboBoxUI.java
Normal file
@@ -0,0 +1,361 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import java.io.Serializable;
|
||||
import java.awt.event.*;
|
||||
import java.beans.*;
|
||||
|
||||
/**
|
||||
* ComboBox motif look and feel
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Arnaud Weber
|
||||
*/
|
||||
public class MotifComboBoxUI extends BasicComboBoxUI implements Serializable {
|
||||
Icon arrowIcon;
|
||||
static final int HORIZ_MARGIN = 3;
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new MotifComboBoxUI();
|
||||
}
|
||||
|
||||
public void installUI(JComponent c) {
|
||||
super.installUI(c);
|
||||
arrowIcon = new MotifComboBoxArrowIcon(UIManager.getColor("controlHighlight"),
|
||||
UIManager.getColor("controlShadow"),
|
||||
UIManager.getColor("control"));
|
||||
|
||||
Runnable initCode = new Runnable() {
|
||||
public void run(){
|
||||
if ( motifGetEditor() != null ) {
|
||||
motifGetEditor().setBackground( UIManager.getColor( "text" ) );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SwingUtilities.invokeLater( initCode );
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize( JComponent c ) {
|
||||
if ( !isMinimumSizeDirty ) {
|
||||
return new Dimension( cachedMinimumSize );
|
||||
}
|
||||
Dimension size;
|
||||
Insets insets = getInsets();
|
||||
size = getDisplaySize();
|
||||
size.height += insets.top + insets.bottom;
|
||||
int buttonSize = iconAreaWidth();
|
||||
size.width += insets.left + insets.right + buttonSize;
|
||||
|
||||
cachedMinimumSize.setSize( size.width, size.height );
|
||||
isMinimumSizeDirty = false;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
protected ComboPopup createPopup() {
|
||||
return new MotifComboPopup( comboBox );
|
||||
}
|
||||
|
||||
/**
|
||||
* Overriden to empty the MouseMotionListener.
|
||||
*/
|
||||
protected class MotifComboPopup extends BasicComboPopup {
|
||||
|
||||
public MotifComboPopup( JComboBox comboBox ) {
|
||||
super( comboBox );
|
||||
}
|
||||
|
||||
/**
|
||||
* Motif combo popup should not track the mouse in the list.
|
||||
*/
|
||||
public MouseMotionListener createListMouseMotionListener() {
|
||||
return new MouseMotionAdapter() {};
|
||||
}
|
||||
|
||||
public KeyListener createKeyListener() {
|
||||
return super.createKeyListener();
|
||||
}
|
||||
|
||||
protected class InvocationKeyHandler extends BasicComboPopup.InvocationKeyHandler {
|
||||
protected InvocationKeyHandler() {
|
||||
MotifComboPopup.this.super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void installComponents() {
|
||||
if ( comboBox.isEditable() ) {
|
||||
addEditor();
|
||||
}
|
||||
|
||||
comboBox.add( currentValuePane );
|
||||
}
|
||||
|
||||
protected void uninstallComponents() {
|
||||
removeEditor();
|
||||
comboBox.removeAll();
|
||||
}
|
||||
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
boolean hasFocus = comboBox.hasFocus();
|
||||
Rectangle r;
|
||||
|
||||
if (comboBox.isEnabled()) {
|
||||
g.setColor(comboBox.getBackground());
|
||||
} else {
|
||||
g.setColor(UIManager.getColor("ComboBox.disabledBackground"));
|
||||
}
|
||||
g.fillRect(0,0,c.getWidth(),c.getHeight());
|
||||
|
||||
if ( !comboBox.isEditable() ) {
|
||||
r = rectangleForCurrentValue();
|
||||
paintCurrentValue(g,r,hasFocus);
|
||||
}
|
||||
r = rectangleForArrowIcon();
|
||||
arrowIcon.paintIcon(c,g,r.x,r.y);
|
||||
if ( !comboBox.isEditable() ) {
|
||||
Border border = comboBox.getBorder();
|
||||
Insets in;
|
||||
if ( border != null ) {
|
||||
in = border.getBorderInsets(comboBox);
|
||||
}
|
||||
else {
|
||||
in = new Insets( 0, 0, 0, 0 );
|
||||
}
|
||||
// Draw the separation
|
||||
if(MotifGraphicsUtils.isLeftToRight(comboBox)) {
|
||||
r.x -= (HORIZ_MARGIN + 2);
|
||||
}
|
||||
else {
|
||||
r.x += r.width + HORIZ_MARGIN + 1;
|
||||
}
|
||||
r.y = in.top;
|
||||
r.width = 1;
|
||||
r.height = comboBox.getBounds().height - in.bottom - in.top;
|
||||
g.setColor(UIManager.getColor("controlShadow"));
|
||||
g.fillRect(r.x,r.y,r.width,r.height);
|
||||
r.x++;
|
||||
g.setColor(UIManager.getColor("controlHighlight"));
|
||||
g.fillRect(r.x,r.y,r.width,r.height);
|
||||
}
|
||||
}
|
||||
|
||||
public void paintCurrentValue(Graphics g,Rectangle bounds,boolean hasFocus) {
|
||||
ListCellRenderer renderer = comboBox.getRenderer();
|
||||
Component c;
|
||||
Dimension d;
|
||||
c = renderer.getListCellRendererComponent(listBox, comboBox.getSelectedItem(), -1, false, false);
|
||||
c.setFont(comboBox.getFont());
|
||||
if ( comboBox.isEnabled() ) {
|
||||
c.setForeground(comboBox.getForeground());
|
||||
c.setBackground(comboBox.getBackground());
|
||||
}
|
||||
else {
|
||||
c.setForeground(UIManager.getColor("ComboBox.disabledForeground"));
|
||||
c.setBackground(UIManager.getColor("ComboBox.disabledBackground"));
|
||||
}
|
||||
d = c.getPreferredSize();
|
||||
currentValuePane.paintComponent(g,c,comboBox,bounds.x,bounds.y,
|
||||
bounds.width,d.height);
|
||||
}
|
||||
|
||||
protected Rectangle rectangleForArrowIcon() {
|
||||
Rectangle b = comboBox.getBounds();
|
||||
Border border = comboBox.getBorder();
|
||||
Insets in;
|
||||
if ( border != null ) {
|
||||
in = border.getBorderInsets(comboBox);
|
||||
}
|
||||
else {
|
||||
in = new Insets( 0, 0, 0, 0 );
|
||||
}
|
||||
b.x = in.left;
|
||||
b.y = in.top;
|
||||
b.width -= (in.left + in.right);
|
||||
b.height -= (in.top + in.bottom);
|
||||
|
||||
if(MotifGraphicsUtils.isLeftToRight(comboBox)) {
|
||||
b.x = b.x + b.width - HORIZ_MARGIN - arrowIcon.getIconWidth();
|
||||
}
|
||||
else {
|
||||
b.x += HORIZ_MARGIN;
|
||||
}
|
||||
b.y = b.y + (b.height - arrowIcon.getIconHeight()) / 2;
|
||||
b.width = arrowIcon.getIconWidth();
|
||||
b.height = arrowIcon.getIconHeight();
|
||||
return b;
|
||||
}
|
||||
|
||||
protected Rectangle rectangleForCurrentValue() {
|
||||
int width = comboBox.getWidth();
|
||||
int height = comboBox.getHeight();
|
||||
Insets insets = getInsets();
|
||||
if(MotifGraphicsUtils.isLeftToRight(comboBox)) {
|
||||
return new Rectangle(insets.left, insets.top,
|
||||
(width - (insets.left + insets.right)) -
|
||||
iconAreaWidth(),
|
||||
height - (insets.top + insets.bottom));
|
||||
}
|
||||
else {
|
||||
return new Rectangle(insets.left + iconAreaWidth(), insets.top,
|
||||
(width - (insets.left + insets.right)) -
|
||||
iconAreaWidth(),
|
||||
height - (insets.top + insets.bottom));
|
||||
}
|
||||
}
|
||||
|
||||
public int iconAreaWidth() {
|
||||
if ( comboBox.isEditable() )
|
||||
return arrowIcon.getIconWidth() + (2 * HORIZ_MARGIN);
|
||||
else
|
||||
return arrowIcon.getIconWidth() + (3 * HORIZ_MARGIN) + 2;
|
||||
}
|
||||
|
||||
public void configureEditor() {
|
||||
super.configureEditor();
|
||||
editor.setBackground( UIManager.getColor( "text" ) );
|
||||
}
|
||||
|
||||
protected LayoutManager createLayoutManager() {
|
||||
return new ComboBoxLayoutManager();
|
||||
}
|
||||
|
||||
private Component motifGetEditor() {
|
||||
return editor;
|
||||
}
|
||||
|
||||
/**
|
||||
* This inner class is marked "public" due to a compiler bug.
|
||||
* This class should be treated as a "protected" inner class.
|
||||
* Instantiate it only within subclasses of <FooUI>.
|
||||
*/
|
||||
public class ComboBoxLayoutManager extends BasicComboBoxUI.ComboBoxLayoutManager {
|
||||
public ComboBoxLayoutManager() {
|
||||
MotifComboBoxUI.this.super();
|
||||
}
|
||||
public void layoutContainer(Container parent) {
|
||||
if ( motifGetEditor() != null ) {
|
||||
Rectangle cvb = rectangleForCurrentValue();
|
||||
cvb.x += 1;
|
||||
cvb.y += 1;
|
||||
cvb.width -= 1;
|
||||
cvb.height -= 2;
|
||||
motifGetEditor().setBounds(cvb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class MotifComboBoxArrowIcon implements Icon, Serializable {
|
||||
private Color lightShadow;
|
||||
private Color darkShadow;
|
||||
private Color fill;
|
||||
|
||||
public MotifComboBoxArrowIcon(Color lightShadow, Color darkShadow, Color fill) {
|
||||
this.lightShadow = lightShadow;
|
||||
this.darkShadow = darkShadow;
|
||||
this.fill = fill;
|
||||
}
|
||||
|
||||
|
||||
public void paintIcon(Component c, Graphics g, int xo, int yo) {
|
||||
int w = getIconWidth();
|
||||
int h = getIconHeight();
|
||||
|
||||
g.setColor(lightShadow);
|
||||
g.drawLine(xo, yo, xo+w-1, yo);
|
||||
g.drawLine(xo, yo+1, xo+w-3, yo+1);
|
||||
g.setColor(darkShadow);
|
||||
g.drawLine(xo+w-2, yo+1, xo+w-1, yo+1);
|
||||
|
||||
for ( int x = xo+1, y = yo+2, dx = w-6; y+1 < yo+h; y += 2 ) {
|
||||
g.setColor(lightShadow);
|
||||
g.drawLine(x, y, x+1, y);
|
||||
g.drawLine(x, y+1, x+1, y+1);
|
||||
if ( dx > 0 ) {
|
||||
g.setColor(fill);
|
||||
g.drawLine(x+2, y, x+1+dx, y);
|
||||
g.drawLine(x+2, y+1, x+1+dx, y+1);
|
||||
}
|
||||
g.setColor(darkShadow);
|
||||
g.drawLine(x+dx+2, y, x+dx+3, y);
|
||||
g.drawLine(x+dx+2, y+1, x+dx+3, y+1);
|
||||
x += 1;
|
||||
dx -= 2;
|
||||
}
|
||||
|
||||
g.setColor(darkShadow);
|
||||
g.drawLine(xo+(w/2), yo+h-1, xo+(w/2), yo+h-1);
|
||||
|
||||
}
|
||||
|
||||
public int getIconWidth() {
|
||||
return 11;
|
||||
}
|
||||
|
||||
public int getIconHeight() {
|
||||
return 11;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected PropertyChangeListener createPropertyChangeListener() {
|
||||
return new MotifPropertyChangeListener();
|
||||
}
|
||||
|
||||
/**
|
||||
* This class should be made "protected" in future releases.
|
||||
*/
|
||||
private class MotifPropertyChangeListener
|
||||
extends BasicComboBoxUI.PropertyChangeHandler {
|
||||
public void propertyChange(PropertyChangeEvent e) {
|
||||
super.propertyChange(e);
|
||||
String propertyName = e.getPropertyName();
|
||||
if (propertyName == "enabled") {
|
||||
if (comboBox.isEnabled()) {
|
||||
Component editor = motifGetEditor();
|
||||
if (editor != null) {
|
||||
editor.setBackground(UIManager.getColor("text"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,375 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import sun.swing.SwingUtilities2;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import java.beans.*;
|
||||
import java.util.EventListener;
|
||||
import java.io.Serializable;
|
||||
|
||||
import sun.awt.AWTAccessor;
|
||||
import sun.awt.AWTAccessor.MouseEventAccessor;
|
||||
|
||||
/**
|
||||
* Motif rendition of the component.
|
||||
*
|
||||
* @author Thomas Ball
|
||||
* @author Rich Schiavi
|
||||
*/
|
||||
public class MotifDesktopIconUI extends BasicDesktopIconUI
|
||||
{
|
||||
protected DesktopIconActionListener desktopIconActionListener;
|
||||
protected DesktopIconMouseListener desktopIconMouseListener;
|
||||
|
||||
protected Icon defaultIcon;
|
||||
protected IconButton iconButton;
|
||||
protected IconLabel iconLabel;
|
||||
|
||||
// This is only used for its system menu, but we need a reference to it so
|
||||
// we can remove its listeners.
|
||||
private MotifInternalFrameTitlePane sysMenuTitlePane;
|
||||
|
||||
JPopupMenu systemMenu;
|
||||
EventListener mml;
|
||||
|
||||
final static int LABEL_HEIGHT = 18;
|
||||
final static int LABEL_DIVIDER = 4; // padding between icon and label
|
||||
|
||||
final static Font defaultTitleFont =
|
||||
new Font(Font.SANS_SERIF, Font.PLAIN, 12);
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new MotifDesktopIconUI();
|
||||
}
|
||||
|
||||
public MotifDesktopIconUI() {
|
||||
}
|
||||
|
||||
protected void installDefaults(){
|
||||
super.installDefaults();
|
||||
setDefaultIcon(UIManager.getIcon("DesktopIcon.icon"));
|
||||
iconButton = createIconButton(defaultIcon);
|
||||
// An underhanded way of creating a system popup menu.
|
||||
sysMenuTitlePane = new MotifInternalFrameTitlePane(frame);
|
||||
systemMenu = sysMenuTitlePane.getSystemMenu();
|
||||
|
||||
MotifBorders.FrameBorder border = new MotifBorders.FrameBorder(desktopIcon);
|
||||
desktopIcon.setLayout(new BorderLayout());
|
||||
iconButton.setBorder(border);
|
||||
desktopIcon.add(iconButton, BorderLayout.CENTER);
|
||||
iconLabel = createIconLabel(frame);
|
||||
iconLabel.setBorder(border);
|
||||
desktopIcon.add(iconLabel, BorderLayout.SOUTH);
|
||||
desktopIcon.setSize(desktopIcon.getPreferredSize());
|
||||
desktopIcon.validate();
|
||||
JLayeredPane.putLayer(desktopIcon, JLayeredPane.getLayer(frame));
|
||||
}
|
||||
|
||||
protected void installComponents(){
|
||||
}
|
||||
|
||||
protected void uninstallComponents(){
|
||||
}
|
||||
|
||||
protected void installListeners(){
|
||||
super.installListeners();
|
||||
desktopIconActionListener = createDesktopIconActionListener();
|
||||
desktopIconMouseListener = createDesktopIconMouseListener();
|
||||
iconButton.addActionListener(desktopIconActionListener);
|
||||
iconButton.addMouseListener(desktopIconMouseListener);
|
||||
iconLabel.addMouseListener(desktopIconMouseListener);
|
||||
}
|
||||
|
||||
JInternalFrame.JDesktopIcon getDesktopIcon(){
|
||||
return desktopIcon;
|
||||
}
|
||||
|
||||
void setDesktopIcon(JInternalFrame.JDesktopIcon d){
|
||||
desktopIcon = d;
|
||||
}
|
||||
|
||||
JInternalFrame getFrame(){
|
||||
return frame;
|
||||
}
|
||||
|
||||
void setFrame(JInternalFrame f){
|
||||
frame = f ;
|
||||
}
|
||||
|
||||
protected void showSystemMenu(){
|
||||
systemMenu.show(iconButton, 0, getDesktopIcon().getHeight());
|
||||
}
|
||||
|
||||
protected void hideSystemMenu(){
|
||||
systemMenu.setVisible(false);
|
||||
}
|
||||
|
||||
protected IconLabel createIconLabel(JInternalFrame frame){
|
||||
return new IconLabel(frame);
|
||||
}
|
||||
|
||||
protected IconButton createIconButton(Icon i){
|
||||
return new IconButton(i);
|
||||
}
|
||||
|
||||
protected DesktopIconActionListener createDesktopIconActionListener(){
|
||||
return new DesktopIconActionListener();
|
||||
}
|
||||
|
||||
protected DesktopIconMouseListener createDesktopIconMouseListener(){
|
||||
return new DesktopIconMouseListener();
|
||||
}
|
||||
|
||||
protected void uninstallDefaults(){
|
||||
super.uninstallDefaults();
|
||||
desktopIcon.setLayout(null);
|
||||
desktopIcon.remove(iconButton);
|
||||
desktopIcon.remove(iconLabel);
|
||||
}
|
||||
|
||||
protected void uninstallListeners(){
|
||||
super.uninstallListeners();
|
||||
iconButton.removeActionListener(desktopIconActionListener);
|
||||
iconButton.removeMouseListener(desktopIconMouseListener);
|
||||
sysMenuTitlePane.uninstallListeners();
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize(JComponent c) {
|
||||
JInternalFrame iframe = desktopIcon.getInternalFrame();
|
||||
|
||||
int w = defaultIcon.getIconWidth();
|
||||
int h = defaultIcon.getIconHeight() + LABEL_HEIGHT + LABEL_DIVIDER;
|
||||
|
||||
Border border = iframe.getBorder();
|
||||
if(border != null) {
|
||||
w += border.getBorderInsets(iframe).left +
|
||||
border.getBorderInsets(iframe).right;
|
||||
h += border.getBorderInsets(iframe).bottom +
|
||||
border.getBorderInsets(iframe).top;
|
||||
}
|
||||
|
||||
return new Dimension(w, h);
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize(JComponent c) {
|
||||
return getMinimumSize(c);
|
||||
}
|
||||
|
||||
public Dimension getMaximumSize(JComponent c){
|
||||
return getMinimumSize(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default desktop icon.
|
||||
*/
|
||||
public Icon getDefaultIcon() {
|
||||
return defaultIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the icon used as the default desktop icon.
|
||||
*/
|
||||
public void setDefaultIcon(Icon newIcon) {
|
||||
defaultIcon = newIcon;
|
||||
}
|
||||
|
||||
protected class IconLabel extends JPanel {
|
||||
JInternalFrame frame;
|
||||
|
||||
IconLabel(JInternalFrame f) {
|
||||
super();
|
||||
this.frame = f;
|
||||
setFont(defaultTitleFont);
|
||||
|
||||
// Forward mouse events to titlebar for moves.
|
||||
addMouseMotionListener(new MouseMotionListener() {
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
});
|
||||
addMouseListener(new MouseListener() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
public void mousePressed(MouseEvent e) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
public void mouseExited(MouseEvent e) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void forwardEventToParent(MouseEvent e) {
|
||||
MouseEvent newEvent = new MouseEvent(
|
||||
getParent(), e.getID(), e.getWhen(), e.getModifiers(),
|
||||
e.getX(), e.getY(), e.getXOnScreen(),
|
||||
e.getYOnScreen(), e.getClickCount(),
|
||||
e.isPopupTrigger(), MouseEvent.NOBUTTON);
|
||||
MouseEventAccessor meAccessor = AWTAccessor.getMouseEventAccessor();
|
||||
meAccessor.setCausedByTouchEvent(newEvent,
|
||||
meAccessor.isCausedByTouchEvent(e));
|
||||
getParent().dispatchEvent(newEvent);
|
||||
}
|
||||
|
||||
public boolean isFocusTraversable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize() {
|
||||
return new Dimension(defaultIcon.getIconWidth() + 1,
|
||||
LABEL_HEIGHT + LABEL_DIVIDER);
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
String title = frame.getTitle();
|
||||
FontMetrics fm = frame.getFontMetrics(defaultTitleFont);
|
||||
int w = 4;
|
||||
if (title != null) {
|
||||
w += SwingUtilities2.stringWidth(frame, fm, title);
|
||||
}
|
||||
return new Dimension(w, LABEL_HEIGHT + LABEL_DIVIDER);
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
|
||||
// touch-up frame
|
||||
int maxX = getWidth() - 1;
|
||||
Color shadow =
|
||||
UIManager.getColor("inactiveCaptionBorder").darker().darker();
|
||||
g.setColor(shadow);
|
||||
g.setClip(0, 0, getWidth(), getHeight());
|
||||
g.drawLine(maxX - 1, 1, maxX - 1, 1);
|
||||
g.drawLine(maxX, 0, maxX, 0);
|
||||
|
||||
// fill background
|
||||
g.setColor(UIManager.getColor("inactiveCaption"));
|
||||
g.fillRect(2, 1, maxX - 3, LABEL_HEIGHT + 1);
|
||||
|
||||
// draw text -- clipping to truncate text like CDE/Motif
|
||||
g.setClip(2, 1, maxX - 4, LABEL_HEIGHT);
|
||||
int y = LABEL_HEIGHT - SwingUtilities2.getFontMetrics(frame, g).
|
||||
getDescent();
|
||||
g.setColor(UIManager.getColor("inactiveCaptionText"));
|
||||
String title = frame.getTitle();
|
||||
if (title != null) {
|
||||
SwingUtilities2.drawString(frame, g, title, 4, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected class IconButton extends JButton {
|
||||
Icon icon;
|
||||
|
||||
IconButton(Icon icon) {
|
||||
super(icon);
|
||||
this.icon = icon;
|
||||
// Forward mouse events to titlebar for moves.
|
||||
addMouseMotionListener(new MouseMotionListener() {
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
});
|
||||
addMouseListener(new MouseListener() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
public void mousePressed(MouseEvent e) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (!systemMenu.isShowing()) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
}
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
public void mouseExited(MouseEvent e) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void forwardEventToParent(MouseEvent e) {
|
||||
MouseEvent newEvent = new MouseEvent(
|
||||
getParent(), e.getID(), e.getWhen(), e.getModifiers(),
|
||||
e.getX(), e.getY(), e.getXOnScreen(), e.getYOnScreen(),
|
||||
e.getClickCount(), e.isPopupTrigger(), MouseEvent.NOBUTTON );
|
||||
MouseEventAccessor meAccessor = AWTAccessor.getMouseEventAccessor();
|
||||
meAccessor.setCausedByTouchEvent(newEvent,
|
||||
meAccessor.isCausedByTouchEvent(e));
|
||||
getParent().dispatchEvent(newEvent);
|
||||
}
|
||||
|
||||
public boolean isFocusTraversable() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected class DesktopIconActionListener implements ActionListener {
|
||||
public void actionPerformed(ActionEvent e){
|
||||
systemMenu.show(iconButton, 0, getDesktopIcon().getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
protected class DesktopIconMouseListener extends MouseAdapter {
|
||||
// if we drag or move we should deengage the popup
|
||||
public void mousePressed(MouseEvent e){
|
||||
if (e.getClickCount() > 1) {
|
||||
try {
|
||||
getFrame().setIcon(false);
|
||||
} catch (PropertyVetoException e2){ }
|
||||
systemMenu.setVisible(false);
|
||||
/* the mouse release will not get reported correctly,
|
||||
because the icon will no longer be in the hierarchy;
|
||||
maybe that should be fixed, but until it is, we need
|
||||
to do the required cleanup here. */
|
||||
getFrame().getDesktopPane().getDesktopManager().endDraggingFrame((JComponent)e.getSource());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Component;
|
||||
import java.awt.Point;
|
||||
import javax.swing.plaf.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author David Kloba
|
||||
*/
|
||||
public class MotifDesktopPaneUI extends javax.swing.plaf.basic.BasicDesktopPaneUI
|
||||
{
|
||||
|
||||
/// DesktopPaneUI methods
|
||||
public static ComponentUI createUI(JComponent d) {
|
||||
return new MotifDesktopPaneUI();
|
||||
}
|
||||
|
||||
public MotifDesktopPaneUI() {
|
||||
}
|
||||
|
||||
protected void installDesktopManager() {
|
||||
desktopManager = desktop.getDesktopManager();
|
||||
if(desktopManager == null) {
|
||||
desktopManager = new MotifDesktopManager();
|
||||
desktop.setDesktopManager(desktopManager);
|
||||
((MotifDesktopManager)desktopManager).adjustIcons(desktop);
|
||||
}
|
||||
}
|
||||
|
||||
public Insets getInsets(JComponent c) {return new Insets(0,0,0,0);}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
/// DragPane class
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
private class DragPane extends JComponent {
|
||||
public void paint(Graphics g) {
|
||||
g.setColor(Color.darkGray);
|
||||
g.drawRect(0, 0, getWidth()-1, getHeight()-1);
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
/// MotifDesktopManager class
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
private class MotifDesktopManager extends DefaultDesktopManager implements Serializable, UIResource {
|
||||
JComponent dragPane;
|
||||
boolean usingDragPane = false;
|
||||
private transient JLayeredPane layeredPaneForDragPane;
|
||||
int iconWidth, iconHeight;
|
||||
|
||||
// PENDING(klobad) this should be optimized
|
||||
public void setBoundsForFrame(JComponent f, int newX, int newY,
|
||||
int newWidth, int newHeight) {
|
||||
if(!usingDragPane) {
|
||||
boolean didResize;
|
||||
didResize = (f.getWidth() != newWidth || f.getHeight() != newHeight);
|
||||
Rectangle r = f.getBounds();
|
||||
f.setBounds(newX, newY, newWidth, newHeight);
|
||||
SwingUtilities.computeUnion(newX, newY, newWidth, newHeight, r);
|
||||
f.getParent().repaint(r.x, r.y, r.width, r.height);
|
||||
if(didResize) {
|
||||
f.validate();
|
||||
}
|
||||
} else {
|
||||
Rectangle r = dragPane.getBounds();
|
||||
dragPane.setBounds(newX, newY, newWidth, newHeight);
|
||||
SwingUtilities.computeUnion(newX, newY, newWidth, newHeight, r);
|
||||
dragPane.getParent().repaint(r.x, r.y, r.width, r.height);
|
||||
}
|
||||
}
|
||||
|
||||
public void beginDraggingFrame(JComponent f) {
|
||||
usingDragPane = false;
|
||||
if(f.getParent() instanceof JLayeredPane) {
|
||||
if(dragPane == null)
|
||||
dragPane = new DragPane();
|
||||
layeredPaneForDragPane = (JLayeredPane)f.getParent();
|
||||
layeredPaneForDragPane.setLayer(dragPane, Integer.MAX_VALUE);
|
||||
dragPane.setBounds(f.getX(), f.getY(), f.getWidth(), f.getHeight());
|
||||
layeredPaneForDragPane.add(dragPane);
|
||||
usingDragPane = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void dragFrame(JComponent f, int newX, int newY) {
|
||||
setBoundsForFrame(f, newX, newY, f.getWidth(), f.getHeight());
|
||||
}
|
||||
|
||||
public void endDraggingFrame(JComponent f) {
|
||||
if(usingDragPane) {
|
||||
layeredPaneForDragPane.remove(dragPane);
|
||||
usingDragPane = false;
|
||||
if (f instanceof JInternalFrame) {
|
||||
setBoundsForFrame(f, dragPane.getX(), dragPane.getY(),
|
||||
dragPane.getWidth(), dragPane.getHeight());
|
||||
} else if (f instanceof JInternalFrame.JDesktopIcon) {
|
||||
adjustBoundsForIcon((JInternalFrame.JDesktopIcon)f,
|
||||
dragPane.getX(), dragPane.getY());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void beginResizingFrame(JComponent f, int direction) {
|
||||
usingDragPane = false;
|
||||
if(f.getParent() instanceof JLayeredPane) {
|
||||
if(dragPane == null)
|
||||
dragPane = new DragPane();
|
||||
JLayeredPane p = (JLayeredPane)f.getParent();
|
||||
p.setLayer(dragPane, Integer.MAX_VALUE);
|
||||
dragPane.setBounds(f.getX(), f.getY(),
|
||||
f.getWidth(), f.getHeight());
|
||||
p.add(dragPane);
|
||||
usingDragPane = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void resizeFrame(JComponent f, int newX, int newY,
|
||||
int newWidth, int newHeight) {
|
||||
setBoundsForFrame(f, newX, newY, newWidth, newHeight);
|
||||
}
|
||||
|
||||
public void endResizingFrame(JComponent f) {
|
||||
if(usingDragPane) {
|
||||
JLayeredPane p = (JLayeredPane)f.getParent();
|
||||
p.remove(dragPane);
|
||||
usingDragPane = false;
|
||||
setBoundsForFrame(f, dragPane.getX(), dragPane.getY(),
|
||||
dragPane.getWidth(), dragPane.getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
public void iconifyFrame(JInternalFrame f) {
|
||||
JInternalFrame.JDesktopIcon icon = f.getDesktopIcon();
|
||||
Point p = icon.getLocation();
|
||||
adjustBoundsForIcon(icon, p.x, p.y);
|
||||
super.iconifyFrame(f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change positions of icons in the desktop pane so that
|
||||
* they do not overlap
|
||||
*/
|
||||
protected void adjustIcons(JDesktopPane desktop) {
|
||||
// We need to know Motif icon size
|
||||
JInternalFrame.JDesktopIcon icon = new JInternalFrame.JDesktopIcon(
|
||||
new JInternalFrame());
|
||||
Dimension iconSize = icon.getPreferredSize();
|
||||
iconWidth = iconSize.width;
|
||||
iconHeight = iconSize.height;
|
||||
|
||||
JInternalFrame[] frames = desktop.getAllFrames();
|
||||
for (int i=0; i<frames.length; i++) {
|
||||
icon = frames[i].getDesktopIcon();
|
||||
Point ip = icon.getLocation();
|
||||
adjustBoundsForIcon(icon, ip.x, ip.y);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change positions of icon so that it doesn't overlap
|
||||
* other icons.
|
||||
*/
|
||||
protected void adjustBoundsForIcon(JInternalFrame.JDesktopIcon icon,
|
||||
int x, int y) {
|
||||
JDesktopPane c = icon.getDesktopPane();
|
||||
|
||||
int maxy = c.getHeight();
|
||||
int w = iconWidth;
|
||||
int h = iconHeight;
|
||||
c.repaint(x, y, w, h);
|
||||
x = x < 0 ? 0 : x;
|
||||
y = y < 0 ? 0 : y;
|
||||
|
||||
/* Fix for disappearing icons. If the y value is maxy then this
|
||||
* algorithm would place the icon in a non-displayed cell. Never
|
||||
* to be ssen again.*/
|
||||
y = y >= maxy ? (maxy - 1) : y;
|
||||
|
||||
/* Compute the offset for the cell we are trying to go in. */
|
||||
int lx = (x / w) * w;
|
||||
int ygap = maxy % h;
|
||||
int ly = ((y-ygap) / h) * h + ygap;
|
||||
|
||||
/* How far are we into the cell we dropped the icon in. */
|
||||
int dx = x - lx;
|
||||
int dy = y - ly;
|
||||
|
||||
/* Set coordinates for the icon. */
|
||||
x = dx < w/2 ? lx: lx + w;
|
||||
y = dy < h/2 ? ly: ((ly + h) < maxy ? ly + h: ly);
|
||||
|
||||
while (getIconAt(c, icon, x, y) != null) {
|
||||
x += w;
|
||||
}
|
||||
|
||||
/* Cancel the move if the x value was moved off screen. */
|
||||
if (x > c.getWidth()) {
|
||||
return;
|
||||
}
|
||||
if (icon.getParent() != null) {
|
||||
setBoundsForFrame(icon, x, y, w, h);
|
||||
} else {
|
||||
icon.setLocation(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
protected JInternalFrame.JDesktopIcon getIconAt(JDesktopPane desktop,
|
||||
JInternalFrame.JDesktopIcon icon, int x, int y) {
|
||||
|
||||
JInternalFrame.JDesktopIcon currentIcon = null;
|
||||
Component[] components = desktop.getComponents();
|
||||
|
||||
for (int i=0; i<components.length; i++) {
|
||||
Component comp = components[i];
|
||||
if (comp instanceof JInternalFrame.JDesktopIcon &&
|
||||
comp != icon) {
|
||||
|
||||
Point p = comp.getLocation();
|
||||
if (p.x == x && p.y == y) {
|
||||
return (JInternalFrame.JDesktopIcon)comp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}; /// END of MotifDesktopManager
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.BasicEditorPaneUI;
|
||||
|
||||
/**
|
||||
* Provides the look and feel for an pluggable content-type text editor.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Timothy Prinzing
|
||||
*/
|
||||
public class MotifEditorPaneUI extends BasicEditorPaneUI {
|
||||
|
||||
/**
|
||||
* Creates a UI for the JTextPane.
|
||||
*
|
||||
* @param c the JTextPane component
|
||||
* @return the UI
|
||||
*/
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new MotifEditorPaneUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the object to use for a caret. By default an
|
||||
* instance of MotifTextUI.MotifCaret is created. This method
|
||||
* can be redefined to provide something else that implements
|
||||
* the Caret interface.
|
||||
*
|
||||
* @return the caret object
|
||||
*/
|
||||
protected Caret createCaret() {
|
||||
return MotifTextUI.createCaret();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,854 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.beans.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import sun.awt.shell.ShellFolder;
|
||||
import sun.swing.SwingUtilities2;
|
||||
|
||||
/**
|
||||
* Motif FileChooserUI.
|
||||
*
|
||||
* @author Jeff Dinkins
|
||||
*/
|
||||
public class MotifFileChooserUI extends BasicFileChooserUI {
|
||||
|
||||
private FilterComboBoxModel filterComboBoxModel;
|
||||
|
||||
protected JList<File> directoryList = null;
|
||||
protected JList<File> fileList = null;
|
||||
|
||||
protected JTextField pathField = null;
|
||||
protected JComboBox<FileFilter> filterComboBox = null;
|
||||
protected JTextField filenameTextField = null;
|
||||
|
||||
private static final Dimension hstrut10 = new Dimension(10, 1);
|
||||
private static final Dimension vstrut10 = new Dimension(1, 10);
|
||||
|
||||
private static final Insets insets = new Insets(10, 10, 10, 10);
|
||||
|
||||
private static Dimension prefListSize = new Dimension(75, 150);
|
||||
|
||||
private static Dimension WITH_ACCELERATOR_PREF_SIZE = new Dimension(650, 450);
|
||||
private static Dimension PREF_SIZE = new Dimension(350, 450);
|
||||
private static final int MIN_WIDTH = 200;
|
||||
private static final int MIN_HEIGHT = 300;
|
||||
private static Dimension PREF_ACC_SIZE = new Dimension(10, 10);
|
||||
private static Dimension ZERO_ACC_SIZE = new Dimension(1, 1);
|
||||
|
||||
private static Dimension MAX_SIZE = new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
|
||||
|
||||
private static final Insets buttonMargin = new Insets(3, 3, 3, 3);
|
||||
|
||||
private JPanel bottomPanel;
|
||||
|
||||
protected JButton approveButton;
|
||||
|
||||
private String enterFolderNameLabelText = null;
|
||||
private int enterFolderNameLabelMnemonic = 0;
|
||||
private String enterFileNameLabelText = null;
|
||||
private int enterFileNameLabelMnemonic = 0;
|
||||
|
||||
private String filesLabelText = null;
|
||||
private int filesLabelMnemonic = 0;
|
||||
|
||||
private String foldersLabelText = null;
|
||||
private int foldersLabelMnemonic = 0;
|
||||
|
||||
private String pathLabelText = null;
|
||||
private int pathLabelMnemonic = 0;
|
||||
|
||||
private String filterLabelText = null;
|
||||
private int filterLabelMnemonic = 0;
|
||||
|
||||
private JLabel fileNameLabel;
|
||||
|
||||
private void populateFileNameLabel() {
|
||||
if (getFileChooser().getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) {
|
||||
fileNameLabel.setText(enterFolderNameLabelText);
|
||||
fileNameLabel.setDisplayedMnemonic(enterFolderNameLabelMnemonic);
|
||||
} else {
|
||||
fileNameLabel.setText(enterFileNameLabelText);
|
||||
fileNameLabel.setDisplayedMnemonic(enterFileNameLabelMnemonic);
|
||||
}
|
||||
}
|
||||
|
||||
private String fileNameString(File file) {
|
||||
if (file == null) {
|
||||
return null;
|
||||
} else {
|
||||
JFileChooser fc = getFileChooser();
|
||||
if (fc.isDirectorySelectionEnabled() && !fc.isFileSelectionEnabled()) {
|
||||
return file.getPath();
|
||||
} else {
|
||||
return file.getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String fileNameString(File[] files) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (int i = 0; files != null && i < files.length; i++) {
|
||||
if (i > 0) {
|
||||
buf.append(" ");
|
||||
}
|
||||
if (files.length > 1) {
|
||||
buf.append("\"");
|
||||
}
|
||||
buf.append(fileNameString(files[i]));
|
||||
if (files.length > 1) {
|
||||
buf.append("\"");
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public MotifFileChooserUI(JFileChooser filechooser) {
|
||||
super(filechooser);
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
if(filenameTextField != null) {
|
||||
return filenameTextField.getText();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setFileName(String filename) {
|
||||
if(filenameTextField != null) {
|
||||
filenameTextField.setText(filename);
|
||||
}
|
||||
}
|
||||
|
||||
public String getDirectoryName() {
|
||||
return pathField.getText();
|
||||
}
|
||||
|
||||
public void setDirectoryName(String dirname) {
|
||||
pathField.setText(dirname);
|
||||
}
|
||||
|
||||
public void ensureFileIsVisible(JFileChooser fc, File f) {
|
||||
// PENDING(jeff)
|
||||
}
|
||||
|
||||
public void rescanCurrentDirectory(JFileChooser fc) {
|
||||
getModel().validateFileCache();
|
||||
}
|
||||
|
||||
public PropertyChangeListener createPropertyChangeListener(JFileChooser fc) {
|
||||
return new PropertyChangeListener() {
|
||||
public void propertyChange(PropertyChangeEvent e) {
|
||||
String prop = e.getPropertyName();
|
||||
if(prop.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) {
|
||||
File f = (File) e.getNewValue();
|
||||
if(f != null) {
|
||||
setFileName(getFileChooser().getName(f));
|
||||
}
|
||||
} else if (prop.equals(JFileChooser.SELECTED_FILES_CHANGED_PROPERTY)) {
|
||||
File[] files = (File[]) e.getNewValue();
|
||||
JFileChooser fc = getFileChooser();
|
||||
if (files != null && files.length > 0 && (files.length > 1 || fc.isDirectorySelectionEnabled()
|
||||
|| !files[0].isDirectory())) {
|
||||
setFileName(fileNameString(files));
|
||||
}
|
||||
} else if (prop.equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY)) {
|
||||
fileList.clearSelection();
|
||||
} else if(prop.equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)) {
|
||||
directoryList.clearSelection();
|
||||
ListSelectionModel sm = directoryList.getSelectionModel();
|
||||
if (sm instanceof DefaultListSelectionModel) {
|
||||
((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
|
||||
sm.setAnchorSelectionIndex(0);
|
||||
}
|
||||
fileList.clearSelection();
|
||||
sm = fileList.getSelectionModel();
|
||||
if (sm instanceof DefaultListSelectionModel) {
|
||||
((DefaultListSelectionModel)sm).moveLeadSelectionIndex(0);
|
||||
sm.setAnchorSelectionIndex(0);
|
||||
}
|
||||
File currentDirectory = getFileChooser().getCurrentDirectory();
|
||||
if(currentDirectory != null) {
|
||||
try {
|
||||
setDirectoryName(ShellFolder.getNormalizedFile((File)e.getNewValue()).getPath());
|
||||
} catch (IOException ioe) {
|
||||
setDirectoryName(((File)e.getNewValue()).getAbsolutePath());
|
||||
}
|
||||
if ((getFileChooser().getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) && !getFileChooser().isMultiSelectionEnabled()) {
|
||||
setFileName(getDirectoryName());
|
||||
}
|
||||
}
|
||||
} else if(prop.equals(JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY)) {
|
||||
if (fileNameLabel != null) {
|
||||
populateFileNameLabel();
|
||||
}
|
||||
directoryList.clearSelection();
|
||||
} else if (prop.equals(JFileChooser.MULTI_SELECTION_ENABLED_CHANGED_PROPERTY)) {
|
||||
if(getFileChooser().isMultiSelectionEnabled()) {
|
||||
fileList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
||||
} else {
|
||||
fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
fileList.clearSelection();
|
||||
getFileChooser().setSelectedFiles(null);
|
||||
}
|
||||
} else if (prop.equals(JFileChooser.ACCESSORY_CHANGED_PROPERTY)) {
|
||||
if(getAccessoryPanel() != null) {
|
||||
if(e.getOldValue() != null) {
|
||||
getAccessoryPanel().remove((JComponent) e.getOldValue());
|
||||
}
|
||||
JComponent accessory = (JComponent) e.getNewValue();
|
||||
if(accessory != null) {
|
||||
getAccessoryPanel().add(accessory, BorderLayout.CENTER);
|
||||
getAccessoryPanel().setPreferredSize(PREF_ACC_SIZE);
|
||||
getAccessoryPanel().setMaximumSize(MAX_SIZE);
|
||||
} else {
|
||||
getAccessoryPanel().setPreferredSize(ZERO_ACC_SIZE);
|
||||
getAccessoryPanel().setMaximumSize(ZERO_ACC_SIZE);
|
||||
}
|
||||
}
|
||||
} else if (prop.equals(JFileChooser.APPROVE_BUTTON_TEXT_CHANGED_PROPERTY) ||
|
||||
prop.equals(JFileChooser.APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY) ||
|
||||
prop.equals(JFileChooser.DIALOG_TYPE_CHANGED_PROPERTY)) {
|
||||
approveButton.setText(getApproveButtonText(getFileChooser()));
|
||||
approveButton.setToolTipText(getApproveButtonToolTipText(getFileChooser()));
|
||||
} else if (prop.equals(JFileChooser.CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY)) {
|
||||
doControlButtonsChanged(e);
|
||||
} else if (prop.equals("componentOrientation")) {
|
||||
ComponentOrientation o = (ComponentOrientation)e.getNewValue();
|
||||
JFileChooser cc = (JFileChooser)e.getSource();
|
||||
if (o != (ComponentOrientation)e.getOldValue()) {
|
||||
cc.applyComponentOrientation(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
// ComponentUI Interface Implementation methods
|
||||
//
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new MotifFileChooserUI((JFileChooser)c);
|
||||
}
|
||||
|
||||
public void installUI(JComponent c) {
|
||||
super.installUI(c);
|
||||
}
|
||||
|
||||
public void uninstallUI(JComponent c) {
|
||||
c.removePropertyChangeListener(filterComboBoxModel);
|
||||
approveButton.removeActionListener(getApproveSelectionAction());
|
||||
filenameTextField.removeActionListener(getApproveSelectionAction());
|
||||
super.uninstallUI(c);
|
||||
}
|
||||
|
||||
public void installComponents(JFileChooser fc) {
|
||||
fc.setLayout(new BorderLayout(10, 10));
|
||||
fc.setAlignmentX(JComponent.CENTER_ALIGNMENT);
|
||||
|
||||
JPanel interior = new JPanel() {
|
||||
public Insets getInsets() {
|
||||
return insets;
|
||||
}
|
||||
};
|
||||
interior.setInheritsPopupMenu(true);
|
||||
align(interior);
|
||||
interior.setLayout(new BoxLayout(interior, BoxLayout.PAGE_AXIS));
|
||||
|
||||
fc.add(interior, BorderLayout.CENTER);
|
||||
|
||||
// PENDING(jeff) - I18N
|
||||
JLabel l = new JLabel(pathLabelText);
|
||||
l.setDisplayedMnemonic(pathLabelMnemonic);
|
||||
align(l);
|
||||
interior.add(l);
|
||||
|
||||
File currentDirectory = fc.getCurrentDirectory();
|
||||
String curDirName = null;
|
||||
if(currentDirectory != null) {
|
||||
curDirName = currentDirectory.getPath();
|
||||
}
|
||||
pathField = new JTextField(curDirName) {
|
||||
public Dimension getMaximumSize() {
|
||||
Dimension d = super.getMaximumSize();
|
||||
d.height = getPreferredSize().height;
|
||||
return d;
|
||||
}
|
||||
};
|
||||
pathField.setInheritsPopupMenu(true);
|
||||
l.setLabelFor(pathField);
|
||||
align(pathField);
|
||||
|
||||
// Change to folder on return
|
||||
pathField.addActionListener(getUpdateAction());
|
||||
interior.add(pathField);
|
||||
|
||||
interior.add(Box.createRigidArea(vstrut10));
|
||||
|
||||
|
||||
// CENTER: left, right accessory
|
||||
JPanel centerPanel = new JPanel();
|
||||
centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.LINE_AXIS));
|
||||
align(centerPanel);
|
||||
|
||||
// left panel - Filter & folderList
|
||||
JPanel leftPanel = new JPanel();
|
||||
leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS));
|
||||
align(leftPanel);
|
||||
|
||||
// add the filter PENDING(jeff) - I18N
|
||||
l = new JLabel(filterLabelText);
|
||||
l.setDisplayedMnemonic(filterLabelMnemonic);
|
||||
align(l);
|
||||
leftPanel.add(l);
|
||||
|
||||
filterComboBox = new JComboBox<FileFilter>() {
|
||||
public Dimension getMaximumSize() {
|
||||
Dimension d = super.getMaximumSize();
|
||||
d.height = getPreferredSize().height;
|
||||
return d;
|
||||
}
|
||||
};
|
||||
filterComboBox.setInheritsPopupMenu(true);
|
||||
l.setLabelFor(filterComboBox);
|
||||
filterComboBoxModel = createFilterComboBoxModel();
|
||||
filterComboBox.setModel(filterComboBoxModel);
|
||||
filterComboBox.setRenderer(createFilterComboBoxRenderer());
|
||||
fc.addPropertyChangeListener(filterComboBoxModel);
|
||||
align(filterComboBox);
|
||||
leftPanel.add(filterComboBox);
|
||||
|
||||
// leftPanel.add(Box.createRigidArea(vstrut10));
|
||||
|
||||
// Add the Folder List PENDING(jeff) - I18N
|
||||
l = new JLabel(foldersLabelText);
|
||||
l.setDisplayedMnemonic(foldersLabelMnemonic);
|
||||
align(l);
|
||||
leftPanel.add(l);
|
||||
JScrollPane sp = createDirectoryList();
|
||||
sp.getVerticalScrollBar().setFocusable(false);
|
||||
sp.getHorizontalScrollBar().setFocusable(false);
|
||||
sp.setInheritsPopupMenu(true);
|
||||
l.setLabelFor(sp.getViewport().getView());
|
||||
leftPanel.add(sp);
|
||||
leftPanel.setInheritsPopupMenu(true);
|
||||
|
||||
|
||||
// create files list
|
||||
JPanel rightPanel = new JPanel();
|
||||
align(rightPanel);
|
||||
rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.PAGE_AXIS));
|
||||
rightPanel.setInheritsPopupMenu(true);
|
||||
|
||||
l = new JLabel(filesLabelText);
|
||||
l.setDisplayedMnemonic(filesLabelMnemonic);
|
||||
align(l);
|
||||
rightPanel.add(l);
|
||||
sp = createFilesList();
|
||||
l.setLabelFor(sp.getViewport().getView());
|
||||
rightPanel.add(sp);
|
||||
sp.setInheritsPopupMenu(true);
|
||||
|
||||
centerPanel.add(leftPanel);
|
||||
centerPanel.add(Box.createRigidArea(hstrut10));
|
||||
centerPanel.add(rightPanel);
|
||||
centerPanel.setInheritsPopupMenu(true);
|
||||
|
||||
JComponent accessoryPanel = getAccessoryPanel();
|
||||
JComponent accessory = fc.getAccessory();
|
||||
if(accessoryPanel != null) {
|
||||
if(accessory == null) {
|
||||
accessoryPanel.setPreferredSize(ZERO_ACC_SIZE);
|
||||
accessoryPanel.setMaximumSize(ZERO_ACC_SIZE);
|
||||
} else {
|
||||
getAccessoryPanel().add(accessory, BorderLayout.CENTER);
|
||||
accessoryPanel.setPreferredSize(PREF_ACC_SIZE);
|
||||
accessoryPanel.setMaximumSize(MAX_SIZE);
|
||||
}
|
||||
align(accessoryPanel);
|
||||
centerPanel.add(accessoryPanel);
|
||||
accessoryPanel.setInheritsPopupMenu(true);
|
||||
}
|
||||
interior.add(centerPanel);
|
||||
interior.add(Box.createRigidArea(vstrut10));
|
||||
|
||||
// add the filename field PENDING(jeff) - I18N
|
||||
fileNameLabel = new JLabel();
|
||||
populateFileNameLabel();
|
||||
align(fileNameLabel);
|
||||
interior.add(fileNameLabel);
|
||||
|
||||
filenameTextField = new JTextField() {
|
||||
public Dimension getMaximumSize() {
|
||||
Dimension d = super.getMaximumSize();
|
||||
d.height = getPreferredSize().height;
|
||||
return d;
|
||||
}
|
||||
};
|
||||
filenameTextField.setInheritsPopupMenu(true);
|
||||
fileNameLabel.setLabelFor(filenameTextField);
|
||||
filenameTextField.addActionListener(getApproveSelectionAction());
|
||||
align(filenameTextField);
|
||||
filenameTextField.setAlignmentX(JComponent.LEFT_ALIGNMENT);
|
||||
interior.add(filenameTextField);
|
||||
|
||||
bottomPanel = getBottomPanel();
|
||||
bottomPanel.add(new JSeparator(), BorderLayout.NORTH);
|
||||
|
||||
// Add buttons
|
||||
JPanel buttonPanel = new JPanel();
|
||||
align(buttonPanel);
|
||||
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
|
||||
buttonPanel.add(Box.createGlue());
|
||||
|
||||
approveButton = new JButton(getApproveButtonText(fc)) {
|
||||
public Dimension getMaximumSize() {
|
||||
return new Dimension(MAX_SIZE.width, this.getPreferredSize().height);
|
||||
}
|
||||
};
|
||||
approveButton.setMnemonic(getApproveButtonMnemonic(fc));
|
||||
approveButton.setToolTipText(getApproveButtonToolTipText(fc));
|
||||
approveButton.setInheritsPopupMenu(true);
|
||||
align(approveButton);
|
||||
approveButton.setMargin(buttonMargin);
|
||||
approveButton.addActionListener(getApproveSelectionAction());
|
||||
buttonPanel.add(approveButton);
|
||||
buttonPanel.add(Box.createGlue());
|
||||
|
||||
JButton updateButton = new JButton(updateButtonText) {
|
||||
public Dimension getMaximumSize() {
|
||||
return new Dimension(MAX_SIZE.width, this.getPreferredSize().height);
|
||||
}
|
||||
};
|
||||
updateButton.setMnemonic(updateButtonMnemonic);
|
||||
updateButton.setToolTipText(updateButtonToolTipText);
|
||||
updateButton.setInheritsPopupMenu(true);
|
||||
align(updateButton);
|
||||
updateButton.setMargin(buttonMargin);
|
||||
updateButton.addActionListener(getUpdateAction());
|
||||
buttonPanel.add(updateButton);
|
||||
buttonPanel.add(Box.createGlue());
|
||||
|
||||
JButton cancelButton = new JButton(cancelButtonText) {
|
||||
public Dimension getMaximumSize() {
|
||||
return new Dimension(MAX_SIZE.width, this.getPreferredSize().height);
|
||||
}
|
||||
};
|
||||
cancelButton.setMnemonic(cancelButtonMnemonic);
|
||||
cancelButton.setToolTipText(cancelButtonToolTipText);
|
||||
cancelButton.setInheritsPopupMenu(true);
|
||||
align(cancelButton);
|
||||
cancelButton.setMargin(buttonMargin);
|
||||
cancelButton.addActionListener(getCancelSelectionAction());
|
||||
buttonPanel.add(cancelButton);
|
||||
buttonPanel.add(Box.createGlue());
|
||||
|
||||
JButton helpButton = new JButton(helpButtonText) {
|
||||
public Dimension getMaximumSize() {
|
||||
return new Dimension(MAX_SIZE.width, this.getPreferredSize().height);
|
||||
}
|
||||
};
|
||||
helpButton.setMnemonic(helpButtonMnemonic);
|
||||
helpButton.setToolTipText(helpButtonToolTipText);
|
||||
align(helpButton);
|
||||
helpButton.setMargin(buttonMargin);
|
||||
helpButton.setEnabled(false);
|
||||
helpButton.setInheritsPopupMenu(true);
|
||||
buttonPanel.add(helpButton);
|
||||
buttonPanel.add(Box.createGlue());
|
||||
buttonPanel.setInheritsPopupMenu(true);
|
||||
|
||||
bottomPanel.add(buttonPanel, BorderLayout.SOUTH);
|
||||
bottomPanel.setInheritsPopupMenu(true);
|
||||
if (fc.getControlButtonsAreShown()) {
|
||||
fc.add(bottomPanel, BorderLayout.SOUTH);
|
||||
}
|
||||
}
|
||||
|
||||
protected JPanel getBottomPanel() {
|
||||
if (bottomPanel == null) {
|
||||
bottomPanel = new JPanel(new BorderLayout(0, 4));
|
||||
}
|
||||
return bottomPanel;
|
||||
}
|
||||
|
||||
private void doControlButtonsChanged(PropertyChangeEvent e) {
|
||||
if (getFileChooser().getControlButtonsAreShown()) {
|
||||
getFileChooser().add(bottomPanel,BorderLayout.SOUTH);
|
||||
} else {
|
||||
getFileChooser().remove(getBottomPanel());
|
||||
}
|
||||
}
|
||||
|
||||
public void uninstallComponents(JFileChooser fc) {
|
||||
fc.removeAll();
|
||||
bottomPanel = null;
|
||||
if (filterComboBoxModel != null) {
|
||||
fc.removePropertyChangeListener(filterComboBoxModel);
|
||||
}
|
||||
}
|
||||
|
||||
protected void installStrings(JFileChooser fc) {
|
||||
super.installStrings(fc);
|
||||
|
||||
Locale l = fc.getLocale();
|
||||
|
||||
enterFolderNameLabelText = UIManager.getString("FileChooser.enterFolderNameLabelText",l);
|
||||
enterFolderNameLabelMnemonic = getMnemonic("FileChooser.enterFolderNameLabelMnemonic", l);
|
||||
enterFileNameLabelText = UIManager.getString("FileChooser.enterFileNameLabelText",l);
|
||||
enterFileNameLabelMnemonic = getMnemonic("FileChooser.enterFileNameLabelMnemonic", l);
|
||||
|
||||
filesLabelText = UIManager.getString("FileChooser.filesLabelText",l);
|
||||
filesLabelMnemonic = getMnemonic("FileChooser.filesLabelMnemonic", l);
|
||||
|
||||
foldersLabelText = UIManager.getString("FileChooser.foldersLabelText",l);
|
||||
foldersLabelMnemonic = getMnemonic("FileChooser.foldersLabelMnemonic", l);
|
||||
|
||||
pathLabelText = UIManager.getString("FileChooser.pathLabelText",l);
|
||||
pathLabelMnemonic = getMnemonic("FileChooser.pathLabelMnemonic", l);
|
||||
|
||||
filterLabelText = UIManager.getString("FileChooser.filterLabelText",l);
|
||||
filterLabelMnemonic = getMnemonic("FileChooser.filterLabelMnemonic", l);
|
||||
}
|
||||
|
||||
private Integer getMnemonic(String key, Locale l) {
|
||||
return SwingUtilities2.getUIDefaultsInt(key, l);
|
||||
}
|
||||
|
||||
protected void installIcons(JFileChooser fc) {
|
||||
// Since motif doesn't have button icons, leave this empty
|
||||
// which overrides the supertype icon loading
|
||||
}
|
||||
|
||||
protected void uninstallIcons(JFileChooser fc) {
|
||||
// Since motif doesn't have button icons, leave this empty
|
||||
// which overrides the supertype icon loading
|
||||
}
|
||||
|
||||
protected JScrollPane createFilesList() {
|
||||
fileList = new JList<File>();
|
||||
|
||||
if(getFileChooser().isMultiSelectionEnabled()) {
|
||||
fileList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
||||
} else {
|
||||
fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
}
|
||||
|
||||
fileList.setModel(new MotifFileListModel());
|
||||
fileList.getSelectionModel().removeSelectionInterval(0, 0);
|
||||
fileList.setCellRenderer(new FileCellRenderer());
|
||||
fileList.addListSelectionListener(createListSelectionListener(getFileChooser()));
|
||||
fileList.addMouseListener(createDoubleClickListener(getFileChooser(), fileList));
|
||||
fileList.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
JFileChooser chooser = getFileChooser();
|
||||
if (SwingUtilities.isLeftMouseButton(e) && !chooser.isMultiSelectionEnabled()) {
|
||||
int index = SwingUtilities2.loc2IndexFileList(fileList, e.getPoint());
|
||||
if (index >= 0) {
|
||||
File file = fileList.getModel().getElementAt(index);
|
||||
setFileName(chooser.getName(file));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
align(fileList);
|
||||
JScrollPane scrollpane = new JScrollPane(fileList);
|
||||
scrollpane.setPreferredSize(prefListSize);
|
||||
scrollpane.setMaximumSize(MAX_SIZE);
|
||||
align(scrollpane);
|
||||
fileList.setInheritsPopupMenu(true);
|
||||
scrollpane.setInheritsPopupMenu(true);
|
||||
return scrollpane;
|
||||
}
|
||||
|
||||
protected JScrollPane createDirectoryList() {
|
||||
directoryList = new JList<File>();
|
||||
align(directoryList);
|
||||
|
||||
directoryList.setCellRenderer(new DirectoryCellRenderer());
|
||||
directoryList.setModel(new MotifDirectoryListModel());
|
||||
directoryList.getSelectionModel().removeSelectionInterval(0, 0);
|
||||
directoryList.addMouseListener(createDoubleClickListener(getFileChooser(), directoryList));
|
||||
directoryList.addListSelectionListener(createListSelectionListener(getFileChooser()));
|
||||
directoryList.setInheritsPopupMenu(true);
|
||||
|
||||
JScrollPane scrollpane = new JScrollPane(directoryList);
|
||||
scrollpane.setMaximumSize(MAX_SIZE);
|
||||
scrollpane.setPreferredSize(prefListSize);
|
||||
scrollpane.setInheritsPopupMenu(true);
|
||||
align(scrollpane);
|
||||
return scrollpane;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize(JComponent c) {
|
||||
Dimension prefSize =
|
||||
(getFileChooser().getAccessory() != null) ? WITH_ACCELERATOR_PREF_SIZE : PREF_SIZE;
|
||||
Dimension d = c.getLayout().preferredLayoutSize(c);
|
||||
if (d != null) {
|
||||
return new Dimension(d.width < prefSize.width ? prefSize.width : d.width,
|
||||
d.height < prefSize.height ? prefSize.height : d.height);
|
||||
} else {
|
||||
return prefSize;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getMinimumSize(JComponent x) {
|
||||
return new Dimension(MIN_WIDTH, MIN_HEIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getMaximumSize(JComponent x) {
|
||||
return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
protected void align(JComponent c) {
|
||||
c.setAlignmentX(JComponent.LEFT_ALIGNMENT);
|
||||
c.setAlignmentY(JComponent.TOP_ALIGNMENT);
|
||||
}
|
||||
|
||||
protected class FileCellRenderer extends DefaultListCellRenderer {
|
||||
public Component getListCellRendererComponent(JList list, Object value, int index,
|
||||
boolean isSelected, boolean cellHasFocus) {
|
||||
|
||||
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
setText(getFileChooser().getName((File) value));
|
||||
setInheritsPopupMenu(true);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
protected class DirectoryCellRenderer extends DefaultListCellRenderer {
|
||||
public Component getListCellRendererComponent(JList list, Object value, int index,
|
||||
boolean isSelected, boolean cellHasFocus) {
|
||||
|
||||
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
setText(getFileChooser().getName((File) value));
|
||||
setInheritsPopupMenu(true);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
protected class MotifDirectoryListModel extends AbstractListModel<File> implements ListDataListener {
|
||||
public MotifDirectoryListModel() {
|
||||
getModel().addListDataListener(this);
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return getModel().getDirectories().size();
|
||||
}
|
||||
|
||||
public File getElementAt(int index) {
|
||||
return getModel().getDirectories().elementAt(index);
|
||||
}
|
||||
|
||||
public void intervalAdded(ListDataEvent e) {
|
||||
fireIntervalAdded(this, e.getIndex0(), e.getIndex1());
|
||||
}
|
||||
|
||||
public void intervalRemoved(ListDataEvent e) {
|
||||
fireIntervalRemoved(this, e.getIndex0(), e.getIndex1());
|
||||
}
|
||||
|
||||
// PENDING(jeff) - this is inefficient - should sent out
|
||||
// incremental adjustment values instead of saying that the
|
||||
// whole list has changed.
|
||||
public void fireContentsChanged() {
|
||||
fireContentsChanged(this, 0, getModel().getDirectories().size()-1);
|
||||
}
|
||||
|
||||
// PENDING(jeff) - fire the correct interval changed - currently sending
|
||||
// out that everything has changed
|
||||
public void contentsChanged(ListDataEvent e) {
|
||||
fireContentsChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected class MotifFileListModel extends AbstractListModel<File> implements ListDataListener {
|
||||
public MotifFileListModel() {
|
||||
getModel().addListDataListener(this);
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return getModel().getFiles().size();
|
||||
}
|
||||
|
||||
public boolean contains(Object o) {
|
||||
return getModel().getFiles().contains(o);
|
||||
}
|
||||
|
||||
public int indexOf(Object o) {
|
||||
return getModel().getFiles().indexOf(o);
|
||||
}
|
||||
|
||||
public File getElementAt(int index) {
|
||||
return getModel().getFiles().elementAt(index);
|
||||
}
|
||||
|
||||
public void intervalAdded(ListDataEvent e) {
|
||||
fireIntervalAdded(this, e.getIndex0(), e.getIndex1());
|
||||
}
|
||||
|
||||
public void intervalRemoved(ListDataEvent e) {
|
||||
fireIntervalRemoved(this, e.getIndex0(), e.getIndex1());
|
||||
}
|
||||
|
||||
// PENDING(jeff) - this is inefficient - should sent out
|
||||
// incremental adjustment values instead of saying that the
|
||||
// whole list has changed.
|
||||
public void fireContentsChanged() {
|
||||
fireContentsChanged(this, 0, getModel().getFiles().size()-1);
|
||||
}
|
||||
|
||||
// PENDING(jeff) - fire the interval changed
|
||||
public void contentsChanged(ListDataEvent e) {
|
||||
fireContentsChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// DataModel for Types Comboxbox
|
||||
//
|
||||
protected FilterComboBoxModel createFilterComboBoxModel() {
|
||||
return new FilterComboBoxModel();
|
||||
}
|
||||
|
||||
//
|
||||
// Renderer for Types ComboBox
|
||||
//
|
||||
protected FilterComboBoxRenderer createFilterComboBoxRenderer() {
|
||||
return new FilterComboBoxRenderer();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render different type sizes and styles.
|
||||
*/
|
||||
public class FilterComboBoxRenderer extends DefaultListCellRenderer {
|
||||
public Component getListCellRendererComponent(JList list,
|
||||
Object value, int index, boolean isSelected,
|
||||
boolean cellHasFocus) {
|
||||
|
||||
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
|
||||
if (value != null && value instanceof FileFilter) {
|
||||
setText(((FileFilter)value).getDescription());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data model for a type-face selection combo-box.
|
||||
*/
|
||||
protected class FilterComboBoxModel extends AbstractListModel<FileFilter> implements ComboBoxModel<FileFilter>,
|
||||
PropertyChangeListener {
|
||||
protected FileFilter[] filters;
|
||||
protected FilterComboBoxModel() {
|
||||
super();
|
||||
filters = getFileChooser().getChoosableFileFilters();
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent e) {
|
||||
String prop = e.getPropertyName();
|
||||
if(prop.equals(JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY)) {
|
||||
filters = (FileFilter[]) e.getNewValue();
|
||||
fireContentsChanged(this, -1, -1);
|
||||
} else if (prop.equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY)) {
|
||||
fireContentsChanged(this, -1, -1);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSelectedItem(Object filter) {
|
||||
if(filter != null) {
|
||||
getFileChooser().setFileFilter((FileFilter) filter);
|
||||
fireContentsChanged(this, -1, -1);
|
||||
}
|
||||
}
|
||||
|
||||
public Object getSelectedItem() {
|
||||
// Ensure that the current filter is in the list.
|
||||
// NOTE: we shouldnt' have to do this, since JFileChooser adds
|
||||
// the filter to the choosable filters list when the filter
|
||||
// is set. Lets be paranoid just in case someone overrides
|
||||
// setFileFilter in JFileChooser.
|
||||
FileFilter currentFilter = getFileChooser().getFileFilter();
|
||||
boolean found = false;
|
||||
if(currentFilter != null) {
|
||||
for (FileFilter filter : filters) {
|
||||
if (filter == currentFilter) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
getFileChooser().addChoosableFileFilter(currentFilter);
|
||||
}
|
||||
}
|
||||
return getFileChooser().getFileFilter();
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
if(filters != null) {
|
||||
return filters.length;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public FileFilter getElementAt(int index) {
|
||||
if(index > getSize() - 1) {
|
||||
// This shouldn't happen. Try to recover gracefully.
|
||||
return getFileChooser().getFileFilter();
|
||||
}
|
||||
if(filters != null) {
|
||||
return filters[index];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected JButton getApproveButton(JFileChooser fc) {
|
||||
return approveButton;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,476 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import sun.swing.SwingUtilities2;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Component;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.Container;
|
||||
|
||||
import javax.swing.plaf.basic.*;
|
||||
import javax.swing.text.View;
|
||||
|
||||
/*
|
||||
* @author Jeff Dinkins
|
||||
* @author Dave Kloba
|
||||
*/
|
||||
|
||||
public class MotifGraphicsUtils implements SwingConstants
|
||||
{
|
||||
/* Client Property keys for text and accelerator text widths */
|
||||
private static final String MAX_ACC_WIDTH = "maxAccWidth";
|
||||
|
||||
/**
|
||||
* Draws the point (<b>x</b>, <b>y</b>) in the current color.
|
||||
*/
|
||||
static void drawPoint(Graphics g, int x, int y) {
|
||||
g.drawLine(x, y, x, y);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convenience method for drawing a grooved line
|
||||
*
|
||||
*/
|
||||
public static void drawGroove(Graphics g, int x, int y, int w, int h,
|
||||
Color shadow, Color highlight)
|
||||
{
|
||||
Color oldColor = g.getColor(); // Make no net change to g
|
||||
g.translate(x, y);
|
||||
|
||||
g.setColor(shadow);
|
||||
g.drawRect(0, 0, w-2, h-2);
|
||||
|
||||
g.setColor(highlight);
|
||||
g.drawLine(1, h-3, 1, 1);
|
||||
g.drawLine(1, 1, w-3, 1);
|
||||
|
||||
g.drawLine(0, h-1, w-1, h-1);
|
||||
g.drawLine(w-1, h-1, w-1, 0);
|
||||
|
||||
g.translate(-x, -y);
|
||||
g.setColor(oldColor);
|
||||
}
|
||||
|
||||
/** Draws <b>aString</b> in the rectangle defined by
|
||||
* (<b>x</b>, <b>y</b>, <b>width</b>, <b>height</b>).
|
||||
* <b>justification</b> specifies the text's justification, one of
|
||||
* LEFT, CENTER, or RIGHT.
|
||||
* <b>drawStringInRect()</b> does not clip to the rectangle, but instead
|
||||
* uses this rectangle and the desired justification to compute the point
|
||||
* at which to begin drawing the text.
|
||||
* @see #drawString
|
||||
*/
|
||||
public static void drawStringInRect(Graphics g, String aString, int x, int y,
|
||||
int width, int height, int justification) {
|
||||
drawStringInRect(null, g, aString, x, y, width, height, justification);
|
||||
}
|
||||
|
||||
static void drawStringInRect(JComponent c, Graphics g, String aString,
|
||||
int x, int y, int width, int height,
|
||||
int justification) {
|
||||
FontMetrics fontMetrics;
|
||||
int drawWidth, startX, startY, delta;
|
||||
|
||||
if (g.getFont() == null) {
|
||||
// throw new InconsistencyException("No font set");
|
||||
return;
|
||||
}
|
||||
fontMetrics = SwingUtilities2.getFontMetrics(c, g);
|
||||
if (fontMetrics == null) {
|
||||
// throw new InconsistencyException("No metrics for Font " + font());
|
||||
return;
|
||||
}
|
||||
|
||||
if (justification == CENTER) {
|
||||
drawWidth = SwingUtilities2.stringWidth(c, fontMetrics, aString);
|
||||
if (drawWidth > width) {
|
||||
drawWidth = width;
|
||||
}
|
||||
startX = x + (width - drawWidth) / 2;
|
||||
} else if (justification == RIGHT) {
|
||||
drawWidth = SwingUtilities2.stringWidth(c, fontMetrics, aString);
|
||||
if (drawWidth > width) {
|
||||
drawWidth = width;
|
||||
}
|
||||
startX = x + width - drawWidth;
|
||||
} else {
|
||||
startX = x;
|
||||
}
|
||||
|
||||
delta = (height - fontMetrics.getAscent() - fontMetrics.getDescent()) / 2;
|
||||
if (delta < 0) {
|
||||
delta = 0;
|
||||
}
|
||||
|
||||
startY = y + height - delta - fontMetrics.getDescent();
|
||||
|
||||
SwingUtilities2.drawString(c, g, aString, startX, startY);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is not being used to paint menu item since
|
||||
* 6.0 This code left for compatibility only. Do not use or
|
||||
* override it, this will not cause any visible effect.
|
||||
*/
|
||||
public static void paintMenuItem(Graphics g, JComponent c,
|
||||
Icon checkIcon, Icon arrowIcon,
|
||||
Color background, Color foreground,
|
||||
int defaultTextIconGap)
|
||||
{
|
||||
|
||||
JMenuItem b = (JMenuItem) c;
|
||||
ButtonModel model = b.getModel();
|
||||
|
||||
Dimension size = b.getSize();
|
||||
Insets i = c.getInsets();
|
||||
|
||||
Rectangle viewRect = new Rectangle(size);
|
||||
|
||||
viewRect.x += i.left;
|
||||
viewRect.y += i.top;
|
||||
viewRect.width -= (i.right + viewRect.x);
|
||||
viewRect.height -= (i.bottom + viewRect.y);
|
||||
|
||||
Rectangle iconRect = new Rectangle();
|
||||
Rectangle textRect = new Rectangle();
|
||||
Rectangle acceleratorRect = new Rectangle();
|
||||
Rectangle checkRect = new Rectangle();
|
||||
Rectangle arrowRect = new Rectangle();
|
||||
|
||||
Font holdf = g.getFont();
|
||||
Font f = c.getFont();
|
||||
g.setFont(f);
|
||||
FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f);
|
||||
FontMetrics fmAccel = SwingUtilities2.getFontMetrics(
|
||||
c, g, UIManager.getFont("MenuItem.acceleratorFont"));
|
||||
|
||||
if (c.isOpaque()) {
|
||||
if (model.isArmed()|| (c instanceof JMenu && model.isSelected())) {
|
||||
g.setColor(background);
|
||||
} else {
|
||||
g.setColor(c.getBackground());
|
||||
}
|
||||
g.fillRect(0,0, size.width, size.height);
|
||||
}
|
||||
|
||||
// get Accelerator text
|
||||
KeyStroke accelerator = b.getAccelerator();
|
||||
String acceleratorText = "";
|
||||
if (accelerator != null) {
|
||||
int modifiers = accelerator.getModifiers();
|
||||
if (modifiers > 0) {
|
||||
acceleratorText = KeyEvent.getKeyModifiersText(modifiers);
|
||||
acceleratorText += "+";
|
||||
}
|
||||
acceleratorText += KeyEvent.getKeyText(accelerator.getKeyCode());
|
||||
}
|
||||
|
||||
// layout the text and icon
|
||||
String text = layoutMenuItem(c, fm, b.getText(), fmAccel,
|
||||
acceleratorText, b.getIcon(),
|
||||
checkIcon, arrowIcon,
|
||||
b.getVerticalAlignment(),
|
||||
b.getHorizontalAlignment(),
|
||||
b.getVerticalTextPosition(),
|
||||
b.getHorizontalTextPosition(),
|
||||
viewRect, iconRect,
|
||||
textRect, acceleratorRect,
|
||||
checkRect, arrowRect,
|
||||
b.getText() == null
|
||||
? 0 : defaultTextIconGap,
|
||||
defaultTextIconGap
|
||||
);
|
||||
|
||||
// Paint the Check
|
||||
Color holdc = g.getColor();
|
||||
if (checkIcon != null) {
|
||||
if(model.isArmed() || (c instanceof JMenu && model.isSelected()))
|
||||
g.setColor(foreground);
|
||||
checkIcon.paintIcon(c, g, checkRect.x, checkRect.y);
|
||||
g.setColor(holdc);
|
||||
}
|
||||
|
||||
// Paint the Icon
|
||||
if(b.getIcon() != null) {
|
||||
Icon icon;
|
||||
if(!model.isEnabled()) {
|
||||
icon = b.getDisabledIcon();
|
||||
} else if(model.isPressed() && model.isArmed()) {
|
||||
icon = b.getPressedIcon();
|
||||
if(icon == null) {
|
||||
// Use default icon
|
||||
icon = b.getIcon();
|
||||
}
|
||||
} else {
|
||||
icon = b.getIcon();
|
||||
}
|
||||
|
||||
if (icon!=null) {
|
||||
icon.paintIcon(c, g, iconRect.x, iconRect.y);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the Text
|
||||
if(text != null && !text.equals("")) {
|
||||
// Once BasicHTML becomes public, use BasicHTML.propertyKey
|
||||
// instead of the hardcoded string below!
|
||||
View v = (View) c.getClientProperty("html");
|
||||
if (v != null) {
|
||||
v.paint(g, textRect);
|
||||
} else {
|
||||
int mnemIndex = b.getDisplayedMnemonicIndex();
|
||||
|
||||
if(!model.isEnabled()) {
|
||||
// *** paint the text disabled
|
||||
g.setColor(b.getBackground().brighter());
|
||||
SwingUtilities2.drawStringUnderlineCharAt(b, g,text,
|
||||
mnemIndex,
|
||||
textRect.x, textRect.y + fmAccel.getAscent());
|
||||
g.setColor(b.getBackground().darker());
|
||||
SwingUtilities2.drawStringUnderlineCharAt(b, g,text,
|
||||
mnemIndex,
|
||||
textRect.x - 1, textRect.y + fmAccel.getAscent() - 1);
|
||||
|
||||
} else {
|
||||
// *** paint the text normally
|
||||
if (model.isArmed()|| (c instanceof JMenu && model.isSelected())) {
|
||||
g.setColor(foreground);
|
||||
} else {
|
||||
g.setColor(b.getForeground());
|
||||
}
|
||||
SwingUtilities2.drawStringUnderlineCharAt(b, g,text,
|
||||
mnemIndex,
|
||||
textRect.x,
|
||||
textRect.y + fm.getAscent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw the Accelerator Text
|
||||
if(acceleratorText != null && !acceleratorText.equals("")) {
|
||||
|
||||
//Get the maxAccWidth from the parent to calculate the offset.
|
||||
int accOffset = 0;
|
||||
Container parent = b.getParent();
|
||||
if (parent != null && parent instanceof JComponent) {
|
||||
JComponent p = (JComponent) parent;
|
||||
Integer maxValueInt = (Integer) p.getClientProperty(MotifGraphicsUtils.MAX_ACC_WIDTH);
|
||||
int maxValue = maxValueInt != null ?
|
||||
maxValueInt.intValue() : acceleratorRect.width;
|
||||
|
||||
//Calculate the offset, with which the accelerator texts will be drawn with.
|
||||
accOffset = maxValue - acceleratorRect.width;
|
||||
}
|
||||
|
||||
g.setFont( UIManager.getFont("MenuItem.acceleratorFont") );
|
||||
if(!model.isEnabled()) {
|
||||
// *** paint the acceleratorText disabled
|
||||
g.setColor(b.getBackground().brighter());
|
||||
SwingUtilities2.drawString(c, g,acceleratorText,
|
||||
acceleratorRect.x - accOffset, acceleratorRect.y + fm.getAscent());
|
||||
g.setColor(b.getBackground().darker());
|
||||
SwingUtilities2.drawString(c, g,acceleratorText,
|
||||
acceleratorRect.x - accOffset - 1, acceleratorRect.y + fm.getAscent() - 1);
|
||||
} else {
|
||||
// *** paint the acceleratorText normally
|
||||
if (model.isArmed()|| (c instanceof JMenu && model.isSelected()))
|
||||
{
|
||||
g.setColor(foreground);
|
||||
} else {
|
||||
g.setColor(b.getForeground());
|
||||
}
|
||||
SwingUtilities2.drawString(c, g,acceleratorText,
|
||||
acceleratorRect.x - accOffset,
|
||||
acceleratorRect.y + fmAccel.getAscent());
|
||||
}
|
||||
}
|
||||
|
||||
// Paint the Arrow
|
||||
if (arrowIcon != null) {
|
||||
if(model.isArmed() || (c instanceof JMenu && model.isSelected()))
|
||||
g.setColor(foreground);
|
||||
if( !(b.getParent() instanceof JMenuBar) )
|
||||
arrowIcon.paintIcon(c, g, arrowRect.x, arrowRect.y);
|
||||
}
|
||||
|
||||
g.setColor(holdc);
|
||||
g.setFont(holdf);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compute and return the location of the icons origin, the
|
||||
* location of origin of the text baseline, and a possibly clipped
|
||||
* version of the compound labels string. Locations are computed
|
||||
* relative to the viewR rectangle.
|
||||
*/
|
||||
|
||||
private static String layoutMenuItem(
|
||||
JComponent c,
|
||||
FontMetrics fm,
|
||||
String text,
|
||||
FontMetrics fmAccel,
|
||||
String acceleratorText,
|
||||
Icon icon,
|
||||
Icon checkIcon,
|
||||
Icon arrowIcon,
|
||||
int verticalAlignment,
|
||||
int horizontalAlignment,
|
||||
int verticalTextPosition,
|
||||
int horizontalTextPosition,
|
||||
Rectangle viewR,
|
||||
Rectangle iconR,
|
||||
Rectangle textR,
|
||||
Rectangle acceleratorR,
|
||||
Rectangle checkIconR,
|
||||
Rectangle arrowIconR,
|
||||
int textIconGap,
|
||||
int menuItemGap
|
||||
)
|
||||
{
|
||||
|
||||
SwingUtilities.layoutCompoundLabel(c,
|
||||
fm,
|
||||
text,
|
||||
icon,
|
||||
verticalAlignment,
|
||||
horizontalAlignment,
|
||||
verticalTextPosition,
|
||||
horizontalTextPosition,
|
||||
viewR,
|
||||
iconR,
|
||||
textR,
|
||||
textIconGap);
|
||||
|
||||
/* Initialize the acceelratorText bounds rectangle textR. If a null
|
||||
* or and empty String was specified we substitute "" here
|
||||
* and use 0,0,0,0 for acceleratorTextR.
|
||||
*/
|
||||
if( (acceleratorText == null) || acceleratorText.equals("") ) {
|
||||
acceleratorR.width = acceleratorR.height = 0;
|
||||
acceleratorText = "";
|
||||
}
|
||||
else {
|
||||
acceleratorR.width
|
||||
= SwingUtilities2.stringWidth(c, fmAccel, acceleratorText);
|
||||
acceleratorR.height = fmAccel.getHeight();
|
||||
}
|
||||
|
||||
/* Initialize the checkIcon bounds rectangle checkIconR.
|
||||
*/
|
||||
|
||||
if (checkIcon != null) {
|
||||
checkIconR.width = checkIcon.getIconWidth();
|
||||
checkIconR.height = checkIcon.getIconHeight();
|
||||
}
|
||||
else {
|
||||
checkIconR.width = checkIconR.height = 0;
|
||||
}
|
||||
|
||||
/* Initialize the arrowIcon bounds rectangle arrowIconR.
|
||||
*/
|
||||
|
||||
if (arrowIcon != null) {
|
||||
arrowIconR.width = arrowIcon.getIconWidth();
|
||||
arrowIconR.height = arrowIcon.getIconHeight();
|
||||
}
|
||||
else {
|
||||
arrowIconR.width = arrowIconR.height = 0;
|
||||
}
|
||||
|
||||
|
||||
Rectangle labelR = iconR.union(textR);
|
||||
if( MotifGraphicsUtils.isLeftToRight(c) ) {
|
||||
textR.x += checkIconR.width + menuItemGap;
|
||||
iconR.x += checkIconR.width + menuItemGap;
|
||||
|
||||
// Position the Accelerator text rect
|
||||
acceleratorR.x = viewR.x + viewR.width - arrowIconR.width
|
||||
- menuItemGap - acceleratorR.width;
|
||||
|
||||
// Position the Check and Arrow Icons
|
||||
checkIconR.x = viewR.x;
|
||||
arrowIconR.x = viewR.x + viewR.width - menuItemGap
|
||||
- arrowIconR.width;
|
||||
} else {
|
||||
textR.x -= (checkIconR.width + menuItemGap);
|
||||
iconR.x -= (checkIconR.width + menuItemGap);
|
||||
|
||||
// Position the Accelerator text rect
|
||||
acceleratorR.x = viewR.x + arrowIconR.width + menuItemGap;
|
||||
|
||||
// Position the Check and Arrow Icons
|
||||
checkIconR.x = viewR.x + viewR.width - checkIconR.width;
|
||||
arrowIconR.x = viewR.x + menuItemGap;
|
||||
}
|
||||
|
||||
// Align the accelertor text and the check and arrow icons vertically
|
||||
// with the center of the label rect.
|
||||
acceleratorR.y = labelR.y + (labelR.height/2) - (acceleratorR.height/2);
|
||||
arrowIconR.y = labelR.y + (labelR.height/2) - (arrowIconR.height/2);
|
||||
checkIconR.y = labelR.y + (labelR.height/2) - (checkIconR.height/2);
|
||||
|
||||
/*
|
||||
System.out.println("Layout: v=" +viewR+" c="+checkIconR+" i="+
|
||||
iconR+" t="+textR+" acc="+acceleratorR+" a="+arrowIconR);
|
||||
*/
|
||||
return text;
|
||||
}
|
||||
|
||||
private static void drawMenuBezel(Graphics g, Color background,
|
||||
int x, int y,
|
||||
int width, int height)
|
||||
{
|
||||
// shadowed button region
|
||||
g.setColor(background);
|
||||
g.fillRect(x,y,width,height);
|
||||
|
||||
g.setColor(background.brighter().brighter());
|
||||
g.drawLine(x+1, y+height-1, x+width-1, y+height-1);
|
||||
g.drawLine(x+width-1, y+height-2, x+width-1, y+1);
|
||||
|
||||
g.setColor(background.darker().darker());
|
||||
g.drawLine(x, y, x+width-2, y);
|
||||
g.drawLine(x, y+1, x, y+height-2);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Convenience function for determining ComponentOrientation. Helps us
|
||||
* avoid having Munge directives throughout the code.
|
||||
*/
|
||||
static boolean isLeftToRight( Component c ) {
|
||||
return c.getComponentOrientation().isLeftToRight();
|
||||
}
|
||||
}
|
||||
460
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifIconFactory.java
Normal file
460
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifIconFactory.java
Normal file
@@ -0,0 +1,460 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2004, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import javax.swing.plaf.UIResource;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Polygon;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Icon factory for the CDE/Motif Look and Feel
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* 1.20 04/27/99
|
||||
* @author Georges Saab
|
||||
*/
|
||||
public class MotifIconFactory implements Serializable
|
||||
{
|
||||
private static Icon checkBoxIcon;
|
||||
private static Icon radioButtonIcon;
|
||||
private static Icon menuItemCheckIcon;
|
||||
private static Icon menuItemArrowIcon;
|
||||
private static Icon menuArrowIcon;
|
||||
|
||||
public static Icon getMenuItemCheckIcon() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Icon getMenuItemArrowIcon() {
|
||||
if (menuItemArrowIcon == null) {
|
||||
menuItemArrowIcon = new MenuItemArrowIcon();
|
||||
}
|
||||
return menuItemArrowIcon;
|
||||
}
|
||||
|
||||
public static Icon getMenuArrowIcon() {
|
||||
if (menuArrowIcon == null) {
|
||||
menuArrowIcon = new MenuArrowIcon();
|
||||
}
|
||||
return menuArrowIcon;
|
||||
}
|
||||
|
||||
public static Icon getCheckBoxIcon() {
|
||||
if (checkBoxIcon == null) {
|
||||
checkBoxIcon = new CheckBoxIcon();
|
||||
}
|
||||
return checkBoxIcon;
|
||||
}
|
||||
|
||||
public static Icon getRadioButtonIcon() {
|
||||
if (radioButtonIcon == null) {
|
||||
radioButtonIcon = new RadioButtonIcon();
|
||||
}
|
||||
return radioButtonIcon;
|
||||
}
|
||||
|
||||
private static class CheckBoxIcon implements Icon, UIResource, Serializable {
|
||||
final static int csize = 13;
|
||||
|
||||
private Color control = UIManager.getColor("control");
|
||||
private Color foreground = UIManager.getColor("CheckBox.foreground");
|
||||
private Color shadow = UIManager.getColor("controlShadow");
|
||||
private Color highlight = UIManager.getColor("controlHighlight");
|
||||
private Color lightShadow = UIManager.getColor("controlLightShadow");
|
||||
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
AbstractButton b = (AbstractButton) c;
|
||||
ButtonModel model = b.getModel();
|
||||
|
||||
boolean flat = false;
|
||||
|
||||
if(b instanceof JCheckBox) {
|
||||
flat = ((JCheckBox)b).isBorderPaintedFlat();
|
||||
}
|
||||
|
||||
boolean isPressed = model.isPressed();
|
||||
boolean isArmed = model.isArmed();
|
||||
boolean isEnabled = model.isEnabled();
|
||||
boolean isSelected = model.isSelected();
|
||||
|
||||
// There are 4 "looks" to the Motif CheckBox:
|
||||
// drawCheckBezelOut - default unchecked state
|
||||
// drawBezel - when we uncheck in toggled state
|
||||
// drawCheckBezel - when we check in toggle state
|
||||
// drawCheckBezelIn - selected, mouseReleased
|
||||
boolean checkToggleIn = ((isPressed &&
|
||||
!isArmed &&
|
||||
isSelected) ||
|
||||
(isPressed &&
|
||||
isArmed &&
|
||||
!isSelected));
|
||||
boolean uncheckToggleOut = ((isPressed &&
|
||||
!isArmed &&
|
||||
!isSelected) ||
|
||||
(isPressed &&
|
||||
isArmed &&
|
||||
isSelected));
|
||||
|
||||
boolean checkIn = (!isPressed &&
|
||||
isArmed &&
|
||||
isSelected ||
|
||||
(!isPressed &&
|
||||
!isArmed &&
|
||||
isSelected));
|
||||
|
||||
|
||||
if(flat) {
|
||||
g.setColor(shadow);
|
||||
g.drawRect(x+2,y,csize-1,csize-1);
|
||||
if(uncheckToggleOut || checkToggleIn) {
|
||||
g.setColor(control);
|
||||
g.fillRect(x+3,y+1,csize-2,csize-2);
|
||||
}
|
||||
}
|
||||
|
||||
if (checkToggleIn) {
|
||||
// toggled from unchecked to checked
|
||||
drawCheckBezel(g,x,y,csize,true,false,false,flat);
|
||||
} else if (uncheckToggleOut) {
|
||||
// MotifBorderFactory.drawBezel(g,x,y,csize,csize,false,false);
|
||||
drawCheckBezel(g,x,y,csize,true,true,false,flat);
|
||||
} else if (checkIn) {
|
||||
// show checked, unpressed state
|
||||
drawCheckBezel(g,x,y,csize,false,false,true,flat);
|
||||
} else if(!flat) {
|
||||
// show unchecked state
|
||||
drawCheckBezelOut(g,x,y,csize);
|
||||
}
|
||||
}
|
||||
|
||||
public int getIconWidth() {
|
||||
return csize;
|
||||
}
|
||||
|
||||
public int getIconHeight() {
|
||||
return csize;
|
||||
}
|
||||
|
||||
public void drawCheckBezelOut(Graphics g, int x, int y, int csize){
|
||||
Color controlShadow = UIManager.getColor("controlShadow");
|
||||
|
||||
int w = csize;
|
||||
int h = csize;
|
||||
Color oldColor = g.getColor();
|
||||
|
||||
g.translate(x,y);
|
||||
g.setColor(highlight); // inner 3D border
|
||||
g.drawLine(0, 0, 0, h-1);
|
||||
g.drawLine(1, 0, w-1, 0);
|
||||
|
||||
g.setColor(shadow); // black drop shadow __|
|
||||
g.drawLine(1, h-1, w-1, h-1);
|
||||
g.drawLine(w-1, h-1, w-1, 1);
|
||||
g.translate(-x,-y);
|
||||
g.setColor(oldColor);
|
||||
}
|
||||
|
||||
public void drawCheckBezel(Graphics g, int x, int y, int csize,
|
||||
boolean shade, boolean out, boolean check, boolean flat)
|
||||
{
|
||||
|
||||
|
||||
Color oldColor = g.getColor();
|
||||
g.translate(x, y);
|
||||
|
||||
|
||||
//bottom
|
||||
if(!flat) {
|
||||
if (out) {
|
||||
g.setColor(control);
|
||||
g.fillRect(1,1,csize-2,csize-2);
|
||||
g.setColor(shadow);
|
||||
} else {
|
||||
g.setColor(lightShadow);
|
||||
g.fillRect(0,0,csize,csize);
|
||||
g.setColor(highlight);
|
||||
}
|
||||
|
||||
g.drawLine(1,csize-1,csize-2,csize-1);
|
||||
if (shade) {
|
||||
g.drawLine(2,csize-2,csize-3,csize-2);
|
||||
g.drawLine(csize-2,2,csize-2 ,csize-1);
|
||||
if (out) {
|
||||
g.setColor(highlight);
|
||||
} else {
|
||||
g.setColor(shadow);
|
||||
}
|
||||
g.drawLine(1,2,1,csize-2);
|
||||
g.drawLine(1,1,csize-3,1);
|
||||
if (out) {
|
||||
g.setColor(shadow);
|
||||
} else {
|
||||
g.setColor(highlight);
|
||||
}
|
||||
}
|
||||
//right
|
||||
g.drawLine(csize-1,1,csize-1,csize-1);
|
||||
|
||||
//left
|
||||
if (out) {
|
||||
g.setColor(highlight);
|
||||
} else {
|
||||
g.setColor(shadow);
|
||||
}
|
||||
g.drawLine(0,1,0,csize-1);
|
||||
|
||||
//top
|
||||
g.drawLine(0,0,csize-1,0);
|
||||
}
|
||||
|
||||
if (check) {
|
||||
// draw check
|
||||
g.setColor(foreground);
|
||||
g.drawLine(csize-2,1,csize-2,2);
|
||||
g.drawLine(csize-3,2,csize-3,3);
|
||||
g.drawLine(csize-4,3,csize-4,4);
|
||||
g.drawLine(csize-5,4,csize-5,6);
|
||||
g.drawLine(csize-6,5,csize-6,8);
|
||||
g.drawLine(csize-7,6,csize-7,10);
|
||||
g.drawLine(csize-8,7,csize-8,10);
|
||||
g.drawLine(csize-9,6,csize-9,9);
|
||||
g.drawLine(csize-10,5,csize-10,8);
|
||||
g.drawLine(csize-11,5,csize-11,7);
|
||||
g.drawLine(csize-12,6,csize-12,6);
|
||||
}
|
||||
g.translate(-x, -y);
|
||||
g.setColor(oldColor);
|
||||
}
|
||||
} // end class CheckBoxIcon
|
||||
|
||||
private static class RadioButtonIcon implements Icon, UIResource, Serializable {
|
||||
private Color dot = UIManager.getColor("activeCaptionBorder");
|
||||
private Color highlight = UIManager.getColor("controlHighlight");
|
||||
private Color shadow = UIManager.getColor("controlShadow");
|
||||
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
// fill interior
|
||||
AbstractButton b = (AbstractButton) c;
|
||||
ButtonModel model = b.getModel();
|
||||
|
||||
int w = getIconWidth();
|
||||
int h = getIconHeight();
|
||||
|
||||
boolean isPressed = model.isPressed();
|
||||
boolean isArmed = model.isArmed();
|
||||
boolean isEnabled = model.isEnabled();
|
||||
boolean isSelected = model.isSelected();
|
||||
|
||||
boolean checkIn = ((isPressed &&
|
||||
!isArmed &&
|
||||
isSelected) ||
|
||||
(isPressed &&
|
||||
isArmed &&
|
||||
!isSelected)
|
||||
||
|
||||
(!isPressed &&
|
||||
isArmed &&
|
||||
isSelected ||
|
||||
(!isPressed &&
|
||||
!isArmed &&
|
||||
isSelected)));
|
||||
|
||||
if (checkIn){
|
||||
g.setColor(shadow);
|
||||
g.drawLine(x+5,y+0,x+8,y+0);
|
||||
g.drawLine(x+3,y+1,x+4,y+1);
|
||||
g.drawLine(x+9,y+1,x+9,y+1);
|
||||
g.drawLine(x+2,y+2,x+2,y+2);
|
||||
g.drawLine(x+1,y+3,x+1,y+3);
|
||||
g.drawLine(x,y+4,x,y+9);
|
||||
g.drawLine(x+1,y+10,x+1,y+10);
|
||||
g.drawLine(x+2,y+11,x+2,y+11);
|
||||
g.setColor(highlight);
|
||||
g.drawLine(x+3,y+12,x+4,y+12);
|
||||
g.drawLine(x+5,y+13,x+8,y+13);
|
||||
g.drawLine(x+9,y+12,x+10,y+12);
|
||||
g.drawLine(x+11,y+11,x+11,y+11);
|
||||
g.drawLine(x+12,y+10,x+12,y+10);
|
||||
g.drawLine(x+13,y+9,x+13,y+4);
|
||||
g.drawLine(x+12,y+3,x+12,y+3);
|
||||
g.drawLine(x+11,y+2,x+11,y+2);
|
||||
g.drawLine(x+10,y+1,x+10,y+1);
|
||||
g.setColor(dot);
|
||||
g.fillRect(x+4,y+5,6,4);
|
||||
g.drawLine(x+5,y+4,x+8,y+4);
|
||||
g.drawLine(x+5,y+9,x+8,y+9);
|
||||
}
|
||||
else {
|
||||
g.setColor(highlight);
|
||||
g.drawLine(x+5,y+0,x+8,y+0);
|
||||
g.drawLine(x+3,y+1,x+4,y+1);
|
||||
g.drawLine(x+9,y+1,x+9,y+1);
|
||||
g.drawLine(x+2,y+2,x+2,y+2);
|
||||
g.drawLine(x+1,y+3,x+1,y+3);
|
||||
g.drawLine(x,y+4,x,y+9);
|
||||
g.drawLine(x+1,y+10,x+1,y+10);
|
||||
g.drawLine(x+2,y+11,x+2,y+11);
|
||||
|
||||
g.setColor(shadow);
|
||||
g.drawLine(x+3,y+12,x+4,y+12);
|
||||
g.drawLine(x+5,y+13,x+8,y+13);
|
||||
g.drawLine(x+9,y+12,x+10,y+12);
|
||||
g.drawLine(x+11,y+11,x+11,y+11);
|
||||
g.drawLine(x+12,y+10,x+12,y+10);
|
||||
g.drawLine(x+13,y+9,x+13,y+4);
|
||||
g.drawLine(x+12,y+3,x+12,y+3);
|
||||
g.drawLine(x+11,y+2,x+11,y+2);
|
||||
g.drawLine(x+10,y+1,x+10,y+1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public int getIconWidth() {
|
||||
return 14;
|
||||
}
|
||||
|
||||
public int getIconHeight() {
|
||||
return 14;
|
||||
}
|
||||
} // end class RadioButtonIcon
|
||||
|
||||
private static class MenuItemCheckIcon implements Icon, UIResource, Serializable
|
||||
{
|
||||
public void paintIcon(Component c,Graphics g, int x, int y)
|
||||
{
|
||||
}
|
||||
public int getIconWidth() { return 0; }
|
||||
public int getIconHeight() { return 0; }
|
||||
} // end class MenuItemCheckIcon
|
||||
|
||||
|
||||
private static class MenuItemArrowIcon implements Icon, UIResource, Serializable
|
||||
{
|
||||
public void paintIcon(Component c,Graphics g, int x, int y)
|
||||
{
|
||||
}
|
||||
public int getIconWidth() { return 0; }
|
||||
public int getIconHeight() { return 0; }
|
||||
} // end class MenuItemArrowIcon
|
||||
|
||||
private static class MenuArrowIcon implements Icon, UIResource, Serializable
|
||||
{
|
||||
private Color focus = UIManager.getColor("windowBorder");
|
||||
private Color shadow = UIManager.getColor("controlShadow");
|
||||
private Color highlight = UIManager.getColor("controlHighlight");
|
||||
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
AbstractButton b = (AbstractButton) c;
|
||||
ButtonModel model = b.getModel();
|
||||
|
||||
// These variables are kind of pointless as the following code
|
||||
// assumes the icon will be 10 x 10 regardless of their value.
|
||||
int w = getIconWidth();
|
||||
int h = getIconHeight();
|
||||
|
||||
Color oldColor = g.getColor();
|
||||
|
||||
if (model.isSelected()){
|
||||
if( MotifGraphicsUtils.isLeftToRight(c) ){
|
||||
g.setColor(shadow);
|
||||
g.fillRect(x+1,y+1,2,h);
|
||||
g.drawLine(x+4,y+2,x+4,y+2);
|
||||
g.drawLine(x+6,y+3,x+6,y+3);
|
||||
g.drawLine(x+8,y+4,x+8,y+5);
|
||||
g.setColor(focus);
|
||||
g.fillRect(x+2,y+2,2,h-2);
|
||||
g.fillRect(x+4,y+3,2,h-4);
|
||||
g.fillRect(x+6,y+4,2,h-6);
|
||||
g.setColor(highlight);
|
||||
g.drawLine(x+2,y+h,x+2,y+h);
|
||||
g.drawLine(x+4,y+h-1,x+4,y+h-1);
|
||||
g.drawLine(x+6,y+h-2,x+6,y+h-2);
|
||||
g.drawLine(x+8,y+h-4,x+8,y+h-3);
|
||||
} else {
|
||||
g.setColor(highlight);
|
||||
g.fillRect(x+7,y+1,2,10);
|
||||
g.drawLine(x+5,y+9,x+5,y+9);
|
||||
g.drawLine(x+3,y+8,x+3,y+8);
|
||||
g.drawLine(x+1,y+6,x+1,y+7);
|
||||
g.setColor(focus);
|
||||
g.fillRect(x+6,y+2,2,8);
|
||||
g.fillRect(x+4,y+3,2,6);
|
||||
g.fillRect(x+2,y+4,2,4);
|
||||
g.setColor(shadow);
|
||||
g.drawLine(x+1,y+4,x+1,y+5);
|
||||
g.drawLine(x+3,y+3,x+3,y+3);
|
||||
g.drawLine(x+5,y+2,x+5,y+2);
|
||||
g.drawLine(x+7,y+1,x+7,y+1);
|
||||
}
|
||||
} else {
|
||||
if( MotifGraphicsUtils.isLeftToRight(c) ){
|
||||
g.setColor(highlight);
|
||||
g.drawLine(x+1,y+1,x+1,y+h);
|
||||
g.drawLine(x+2,y+1,x+2,y+h-2);
|
||||
g.fillRect(x+3,y+2,2,2);
|
||||
g.fillRect(x+5,y+3,2,2);
|
||||
g.fillRect(x+7,y+4,2,2);
|
||||
g.setColor(shadow);
|
||||
g.drawLine(x+2,y+h-1,x+2,y+h);
|
||||
g.fillRect(x+3,y+h-2,2,2);
|
||||
g.fillRect(x+5,y+h-3,2,2);
|
||||
g.fillRect(x+7,y+h-4,2,2);
|
||||
g.setColor(oldColor);
|
||||
} else {
|
||||
g.setColor(highlight);
|
||||
g.fillRect(x+1,y+4,2,2);
|
||||
g.fillRect(x+3,y+3,2,2);
|
||||
g.fillRect(x+5,y+2,2,2);
|
||||
g.drawLine(x+7,y+1,x+7,y+2);
|
||||
g.setColor(shadow);
|
||||
g.fillRect(x+1,y+h-4,2,2);
|
||||
g.fillRect(x+3,y+h-3,2,2);
|
||||
g.fillRect(x+5,y+h-2,2,2);
|
||||
g.drawLine(x+7,y+3,x+7,y+h);
|
||||
g.drawLine(x+8,y+1,x+8,y+h);
|
||||
g.setColor(oldColor);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public int getIconWidth() { return 10; }
|
||||
public int getIconHeight() { return 10; }
|
||||
} // End class MenuArrowIcon
|
||||
}
|
||||
@@ -0,0 +1,389 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.event.InternalFrameEvent;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import java.util.EventListener;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.VetoableChangeListener;
|
||||
import java.beans.PropertyVetoException;
|
||||
|
||||
import sun.awt.AWTAccessor;
|
||||
import sun.awt.AWTAccessor.MouseEventAccessor;
|
||||
|
||||
/**
|
||||
* Class that manages a Motif title bar
|
||||
*
|
||||
* @since 1.3
|
||||
*/
|
||||
public class MotifInternalFrameTitlePane
|
||||
extends BasicInternalFrameTitlePane implements LayoutManager, ActionListener, PropertyChangeListener
|
||||
{
|
||||
SystemButton systemButton;
|
||||
MinimizeButton minimizeButton;
|
||||
MaximizeButton maximizeButton;
|
||||
JPopupMenu systemMenu;
|
||||
Title title;
|
||||
Color color;
|
||||
Color highlight;
|
||||
Color shadow;
|
||||
|
||||
// The width and height of a title pane button
|
||||
public final static int BUTTON_SIZE = 19; // 17 + 1 pixel border
|
||||
|
||||
|
||||
public MotifInternalFrameTitlePane(JInternalFrame frame) {
|
||||
super(frame);
|
||||
}
|
||||
|
||||
protected void installDefaults() {
|
||||
setFont(UIManager.getFont("InternalFrame.titleFont"));
|
||||
setPreferredSize(new Dimension(100, BUTTON_SIZE));
|
||||
}
|
||||
|
||||
protected void uninstallListeners() {
|
||||
// Get around protected method in superclass
|
||||
super.uninstallListeners();
|
||||
}
|
||||
|
||||
protected PropertyChangeListener createPropertyChangeListener() {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected LayoutManager createLayout() {
|
||||
return this;
|
||||
}
|
||||
|
||||
JPopupMenu getSystemMenu() {
|
||||
return systemMenu;
|
||||
}
|
||||
|
||||
protected void assembleSystemMenu() {
|
||||
systemMenu = new JPopupMenu();
|
||||
JMenuItem mi = systemMenu.add(restoreAction);
|
||||
mi.setMnemonic(getButtonMnemonic("restore"));
|
||||
mi = systemMenu.add(moveAction);
|
||||
mi.setMnemonic(getButtonMnemonic("move"));
|
||||
mi = systemMenu.add(sizeAction);
|
||||
mi.setMnemonic(getButtonMnemonic("size"));
|
||||
mi = systemMenu.add(iconifyAction);
|
||||
mi.setMnemonic(getButtonMnemonic("minimize"));
|
||||
mi = systemMenu.add(maximizeAction);
|
||||
mi.setMnemonic(getButtonMnemonic("maximize"));
|
||||
systemMenu.add(new JSeparator());
|
||||
mi = systemMenu.add(closeAction);
|
||||
mi.setMnemonic(getButtonMnemonic("close"));
|
||||
|
||||
systemButton = new SystemButton();
|
||||
systemButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
systemMenu.show(systemButton, 0, BUTTON_SIZE);
|
||||
}
|
||||
});
|
||||
|
||||
systemButton.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent evt) {
|
||||
try {
|
||||
frame.setSelected(true);
|
||||
} catch (PropertyVetoException pve) {
|
||||
}
|
||||
if ((evt.getClickCount() == 2)) {
|
||||
closeAction.actionPerformed(new
|
||||
ActionEvent(evt.getSource(),
|
||||
ActionEvent.ACTION_PERFORMED,
|
||||
null, evt.getWhen(), 0));
|
||||
systemMenu.setVisible(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static int getButtonMnemonic(String button) {
|
||||
try {
|
||||
return Integer.parseInt(UIManager.getString(
|
||||
"InternalFrameTitlePane." + button + "Button.mnemonic"));
|
||||
} catch (NumberFormatException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
protected void createButtons() {
|
||||
minimizeButton = new MinimizeButton();
|
||||
minimizeButton.addActionListener(iconifyAction);
|
||||
|
||||
maximizeButton = new MaximizeButton();
|
||||
maximizeButton.addActionListener(maximizeAction);
|
||||
}
|
||||
|
||||
|
||||
protected void addSubComponents() {
|
||||
title = new Title(frame.getTitle());
|
||||
title.setFont(getFont());
|
||||
|
||||
add(systemButton);
|
||||
add(title);
|
||||
add(minimizeButton);
|
||||
add(maximizeButton);
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
}
|
||||
|
||||
void setColors(Color c, Color h, Color s) {
|
||||
color = c;
|
||||
highlight = h;
|
||||
shadow = s;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
String prop = evt.getPropertyName();
|
||||
JInternalFrame f = (JInternalFrame)evt.getSource();
|
||||
boolean value = false;
|
||||
if (JInternalFrame.IS_SELECTED_PROPERTY.equals(prop)) {
|
||||
repaint();
|
||||
} else if (prop.equals("maximizable")) {
|
||||
if ((Boolean)evt.getNewValue() == Boolean.TRUE)
|
||||
add(maximizeButton);
|
||||
else
|
||||
remove(maximizeButton);
|
||||
revalidate();
|
||||
repaint();
|
||||
} else if (prop.equals("iconable")) {
|
||||
if ((Boolean)evt.getNewValue() == Boolean.TRUE)
|
||||
add(minimizeButton);
|
||||
else
|
||||
remove(minimizeButton);
|
||||
revalidate();
|
||||
repaint();
|
||||
} else if (prop.equals(JInternalFrame.TITLE_PROPERTY)) {
|
||||
repaint();
|
||||
}
|
||||
enableActions();
|
||||
}
|
||||
|
||||
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) {
|
||||
return new Dimension(100, BUTTON_SIZE);
|
||||
}
|
||||
|
||||
public void layoutContainer(Container c) {
|
||||
int w = getWidth();
|
||||
systemButton.setBounds(0, 0, BUTTON_SIZE, BUTTON_SIZE);
|
||||
int x = w - BUTTON_SIZE;
|
||||
|
||||
if(frame.isMaximizable()) {
|
||||
maximizeButton.setBounds(x, 0, BUTTON_SIZE, BUTTON_SIZE);
|
||||
x -= BUTTON_SIZE;
|
||||
} else if(maximizeButton.getParent() != null) {
|
||||
maximizeButton.getParent().remove(maximizeButton);
|
||||
}
|
||||
|
||||
if(frame.isIconifiable()) {
|
||||
minimizeButton.setBounds(x, 0, BUTTON_SIZE, BUTTON_SIZE);
|
||||
x -= BUTTON_SIZE;
|
||||
} else if(minimizeButton.getParent() != null) {
|
||||
minimizeButton.getParent().remove(minimizeButton);
|
||||
}
|
||||
|
||||
title.setBounds(BUTTON_SIZE, 0, x, BUTTON_SIZE);
|
||||
}
|
||||
|
||||
protected void showSystemMenu(){
|
||||
systemMenu.show(systemButton, 0, BUTTON_SIZE);
|
||||
}
|
||||
|
||||
protected void hideSystemMenu(){
|
||||
systemMenu.setVisible(false);
|
||||
}
|
||||
|
||||
static Dimension buttonDimension = new Dimension(BUTTON_SIZE, BUTTON_SIZE);
|
||||
|
||||
private abstract class FrameButton extends JButton {
|
||||
|
||||
FrameButton() {
|
||||
super();
|
||||
setFocusPainted(false);
|
||||
setBorderPainted(false);
|
||||
}
|
||||
|
||||
public boolean isFocusTraversable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void requestFocus() {
|
||||
// ignore request.
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize() {
|
||||
return buttonDimension;
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return buttonDimension;
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
Dimension d = getSize();
|
||||
int maxX = d.width - 1;
|
||||
int maxY = d.height - 1;
|
||||
|
||||
// draw background
|
||||
g.setColor(color);
|
||||
g.fillRect(1, 1, d.width, d.height);
|
||||
|
||||
// draw border
|
||||
boolean pressed = getModel().isPressed();
|
||||
g.setColor(pressed ? shadow : highlight);
|
||||
g.drawLine(0, 0, maxX, 0);
|
||||
g.drawLine(0, 0, 0, maxY);
|
||||
g.setColor(pressed ? highlight : shadow);
|
||||
g.drawLine(1, maxY, maxX, maxY);
|
||||
g.drawLine(maxX, 1, maxX, maxY);
|
||||
}
|
||||
}
|
||||
|
||||
private class MinimizeButton extends FrameButton {
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(highlight);
|
||||
g.drawLine(7, 8, 7, 11);
|
||||
g.drawLine(7, 8, 10, 8);
|
||||
g.setColor(shadow);
|
||||
g.drawLine(8, 11, 10, 11);
|
||||
g.drawLine(11, 9, 11, 11);
|
||||
}
|
||||
}
|
||||
|
||||
private class MaximizeButton extends FrameButton {
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
int max = BUTTON_SIZE - 5;
|
||||
boolean isMaxed = frame.isMaximum();
|
||||
g.setColor(isMaxed ? shadow : highlight);
|
||||
g.drawLine(4, 4, 4, max);
|
||||
g.drawLine(4, 4, max, 4);
|
||||
g.setColor(isMaxed ? highlight : shadow);
|
||||
g.drawLine(5, max, max, max);
|
||||
g.drawLine(max, 5, max, max);
|
||||
}
|
||||
}
|
||||
|
||||
private class SystemButton extends FrameButton {
|
||||
public boolean isFocusTraversable() { return false; }
|
||||
public void requestFocus() {}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.setColor(highlight);
|
||||
g.drawLine(4, 8, 4, 11);
|
||||
g.drawLine(4, 8, BUTTON_SIZE - 5, 8);
|
||||
g.setColor(shadow);
|
||||
g.drawLine(5, 11, BUTTON_SIZE - 5, 11);
|
||||
g.drawLine(BUTTON_SIZE - 5, 9, BUTTON_SIZE - 5, 11);
|
||||
}
|
||||
}
|
||||
|
||||
private class Title extends FrameButton {
|
||||
Title(String title) {
|
||||
super();
|
||||
setText(title);
|
||||
setHorizontalAlignment(SwingConstants.CENTER);
|
||||
setBorder(BorderFactory.createBevelBorder(
|
||||
BevelBorder.RAISED,
|
||||
UIManager.getColor("activeCaptionBorder"),
|
||||
UIManager.getColor("inactiveCaptionBorder")));
|
||||
|
||||
// Forward mouse events to titlebar for moves.
|
||||
addMouseMotionListener(new MouseMotionListener() {
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
});
|
||||
addMouseListener(new MouseListener() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
public void mousePressed(MouseEvent e) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
public void mouseExited(MouseEvent e) {
|
||||
forwardEventToParent(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void forwardEventToParent(MouseEvent e) {
|
||||
MouseEvent newEvent = new MouseEvent(
|
||||
getParent(), e.getID(), e.getWhen(), e.getModifiers(),
|
||||
e.getX(), e.getY(), e.getXOnScreen(),
|
||||
e.getYOnScreen(), e.getClickCount(),
|
||||
e.isPopupTrigger(), MouseEvent.NOBUTTON);
|
||||
MouseEventAccessor meAccessor = AWTAccessor.getMouseEventAccessor();
|
||||
meAccessor.setCausedByTouchEvent(newEvent,
|
||||
meAccessor.isCausedByTouchEvent(e));
|
||||
getParent().dispatchEvent(newEvent);
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (frame.isSelected()) {
|
||||
g.setColor(UIManager.getColor("activeCaptionText"));
|
||||
} else {
|
||||
g.setColor(UIManager.getColor("inactiveCaptionText"));
|
||||
}
|
||||
Dimension d = getSize();
|
||||
String frameTitle = frame.getTitle();
|
||||
if (frameTitle != null) {
|
||||
MotifGraphicsUtils.drawStringInRect(frame, g, frameTitle,
|
||||
0, 0, d.width, d.height,
|
||||
SwingConstants.CENTER);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2004, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
import javax.swing.plaf.basic.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.*;
|
||||
|
||||
|
||||
/**
|
||||
* A Motif L&F implementation of InternalFrame.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Tom Ball
|
||||
*/
|
||||
public class MotifInternalFrameUI extends BasicInternalFrameUI {
|
||||
|
||||
Color color;
|
||||
Color highlight;
|
||||
Color shadow;
|
||||
MotifInternalFrameTitlePane titlePane;
|
||||
|
||||
/**
|
||||
* As of Java 2 platform v1.3 this previously undocumented field is no
|
||||
* longer used.
|
||||
* Key bindings are now defined by the LookAndFeel, please refer to
|
||||
* the key bindings specification for further details.
|
||||
*
|
||||
* @deprecated As of Java 2 platform v1.3.
|
||||
*/
|
||||
@Deprecated
|
||||
protected KeyStroke closeMenuKey;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// ComponentUI Interface Implementation methods
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
public static ComponentUI createUI(JComponent w) {
|
||||
return new MotifInternalFrameUI((JInternalFrame)w);
|
||||
}
|
||||
|
||||
public MotifInternalFrameUI(JInternalFrame w) {
|
||||
super(w);
|
||||
}
|
||||
|
||||
public void installUI(JComponent c) {
|
||||
super.installUI(c);
|
||||
setColors((JInternalFrame)c);
|
||||
}
|
||||
|
||||
protected void installDefaults() {
|
||||
Border frameBorder = frame.getBorder();
|
||||
frame.setLayout(internalFrameLayout = createLayoutManager());
|
||||
if (frameBorder == null || frameBorder instanceof UIResource) {
|
||||
frame.setBorder(new MotifBorders.InternalFrameBorder(frame));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void installKeyboardActions(){
|
||||
super.installKeyboardActions();
|
||||
// We replace the
|
||||
// we use JPopup in our TitlePane so need escape support
|
||||
closeMenuKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
|
||||
}
|
||||
|
||||
|
||||
protected void uninstallDefaults() {
|
||||
LookAndFeel.uninstallBorder(frame);
|
||||
frame.setLayout(null);
|
||||
internalFrameLayout = null;
|
||||
}
|
||||
|
||||
private JInternalFrame getFrame(){
|
||||
return frame;
|
||||
}
|
||||
|
||||
public JComponent createNorthPane(JInternalFrame w) {
|
||||
titlePane = new MotifInternalFrameTitlePane(w);
|
||||
return titlePane;
|
||||
}
|
||||
|
||||
public Dimension getMaximumSize(JComponent x) {
|
||||
return Toolkit.getDefaultToolkit().getScreenSize();
|
||||
}
|
||||
|
||||
protected void uninstallKeyboardActions(){
|
||||
super.uninstallKeyboardActions();
|
||||
if (isKeyBindingRegistered()){
|
||||
JInternalFrame.JDesktopIcon di = frame.getDesktopIcon();
|
||||
SwingUtilities.replaceUIActionMap(di, null);
|
||||
SwingUtilities.replaceUIInputMap(di, JComponent.WHEN_IN_FOCUSED_WINDOW,
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setupMenuOpenKey(){
|
||||
super.setupMenuOpenKey();
|
||||
ActionMap map = SwingUtilities.getUIActionMap(frame);
|
||||
if (map != null) {
|
||||
// BasicInternalFrameUI creates an action with the same name, we override
|
||||
// it as MotifInternalFrameTitlePane has a titlePane ivar that shadows the
|
||||
// titlePane ivar in BasicInternalFrameUI, making supers action throw
|
||||
// an NPE for us.
|
||||
map.put("showSystemMenu", new AbstractAction(){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
titlePane.showSystemMenu();
|
||||
}
|
||||
public boolean isEnabled(){
|
||||
return isKeyBindingActive();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected void setupMenuCloseKey(){
|
||||
ActionMap map = SwingUtilities.getUIActionMap(frame);
|
||||
if (map != null) {
|
||||
map.put("hideSystemMenu", new AbstractAction(){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
titlePane.hideSystemMenu();
|
||||
}
|
||||
public boolean isEnabled(){
|
||||
return isKeyBindingActive();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Set up the bindings for the DesktopIcon, it is odd that
|
||||
// we install them, and not the desktop icon.
|
||||
JInternalFrame.JDesktopIcon di = frame.getDesktopIcon();
|
||||
InputMap diInputMap = SwingUtilities.getUIInputMap
|
||||
(di, JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||
if (diInputMap == null) {
|
||||
Object[] bindings = (Object[])UIManager.get
|
||||
("DesktopIcon.windowBindings");
|
||||
if (bindings != null) {
|
||||
diInputMap = LookAndFeel.makeComponentInputMap(di, bindings);
|
||||
|
||||
SwingUtilities.replaceUIInputMap(di, JComponent.
|
||||
WHEN_IN_FOCUSED_WINDOW,
|
||||
diInputMap);
|
||||
}
|
||||
}
|
||||
ActionMap diActionMap = SwingUtilities.getUIActionMap(di);
|
||||
if (diActionMap == null) {
|
||||
diActionMap = new ActionMapUIResource();
|
||||
diActionMap.put("hideSystemMenu", new AbstractAction(){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
JInternalFrame.JDesktopIcon icon = getFrame().
|
||||
getDesktopIcon();
|
||||
MotifDesktopIconUI micon = (MotifDesktopIconUI)icon.
|
||||
getUI();
|
||||
micon.hideSystemMenu();
|
||||
}
|
||||
public boolean isEnabled(){
|
||||
return isKeyBindingActive();
|
||||
}
|
||||
});
|
||||
SwingUtilities.replaceUIActionMap(di, diActionMap);
|
||||
}
|
||||
}
|
||||
|
||||
/** This method is called when the frame becomes selected.
|
||||
*/
|
||||
protected void activateFrame(JInternalFrame f) {
|
||||
super.activateFrame(f);
|
||||
setColors(f);
|
||||
}
|
||||
/** This method is called when the frame is no longer selected.
|
||||
*/
|
||||
protected void deactivateFrame(JInternalFrame f) {
|
||||
setColors(f);
|
||||
super.deactivateFrame(f);
|
||||
}
|
||||
|
||||
void setColors(JInternalFrame frame) {
|
||||
if (frame.isSelected()) {
|
||||
color = UIManager.getColor("InternalFrame.activeTitleBackground");
|
||||
} else {
|
||||
color = UIManager.getColor("InternalFrame.inactiveTitleBackground");
|
||||
}
|
||||
highlight = color.brighter();
|
||||
shadow = color.darker().darker();
|
||||
titlePane.setColors(color, highlight, shadow);
|
||||
}
|
||||
}
|
||||
61
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifLabelUI.java
Normal file
61
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifLabelUI.java
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import sun.awt.AppContext;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.basic.BasicLabelUI;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
|
||||
/**
|
||||
* A Motif L&F implementation of LabelUI.
|
||||
* This merely sets up new default values in MotifLookAndFeel.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Amy Fowler
|
||||
*/
|
||||
public class MotifLabelUI extends BasicLabelUI
|
||||
{
|
||||
private static final Object MOTIF_LABEL_UI_KEY = new Object();
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
AppContext appContext = AppContext.getAppContext();
|
||||
MotifLabelUI motifLabelUI =
|
||||
(MotifLabelUI) appContext.get(MOTIF_LABEL_UI_KEY);
|
||||
if (motifLabelUI == null) {
|
||||
motifLabelUI = new MotifLabelUI();
|
||||
appContext.put(MOTIF_LABEL_UI_KEY, motifLabelUI);
|
||||
}
|
||||
return motifLabelUI;
|
||||
}
|
||||
}
|
||||
1281
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifLookAndFeel.java
Normal file
1281
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifLookAndFeel.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Color;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.BasicMenuBarUI;
|
||||
//REMIND
|
||||
import javax.swing.plaf.basic.*;
|
||||
|
||||
/**
|
||||
* A Windows L&F implementation of MenuBarUI. 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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Georges Saab
|
||||
* @author Rich Schiavi
|
||||
*/
|
||||
|
||||
public class MotifMenuBarUI extends BasicMenuBarUI
|
||||
{
|
||||
|
||||
public static ComponentUI createUI(JComponent x) {
|
||||
return new MotifMenuBarUI();
|
||||
}
|
||||
|
||||
} // end class
|
||||
109
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifMenuItemUI.java
Normal file
109
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifMenuItemUI.java
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2004, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.BasicMenuItemUI;
|
||||
|
||||
|
||||
/**
|
||||
* MotifMenuItem implementation
|
||||
* <p>
|
||||
*
|
||||
* @author Rich Schiavi
|
||||
* @author Georges Saab
|
||||
*/
|
||||
public class MotifMenuItemUI extends BasicMenuItemUI
|
||||
{
|
||||
protected ChangeListener changeListener;
|
||||
|
||||
public static ComponentUI createUI(JComponent c)
|
||||
{
|
||||
return new MotifMenuItemUI();
|
||||
}
|
||||
|
||||
protected void installListeners() {
|
||||
super.installListeners();
|
||||
changeListener = createChangeListener(menuItem);
|
||||
menuItem.addChangeListener(changeListener);
|
||||
}
|
||||
|
||||
protected void uninstallListeners() {
|
||||
super.uninstallListeners();
|
||||
menuItem.removeChangeListener(changeListener);
|
||||
}
|
||||
|
||||
protected ChangeListener createChangeListener(JComponent c) {
|
||||
return new ChangeHandler();
|
||||
}
|
||||
|
||||
protected MouseInputListener createMouseInputListener(JComponent c) {
|
||||
return new MouseInputHandler();
|
||||
}
|
||||
|
||||
protected class ChangeHandler implements ChangeListener {
|
||||
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
JMenuItem c = (JMenuItem)e.getSource();
|
||||
LookAndFeel.installProperty(c, "borderPainted",
|
||||
Boolean.valueOf(c.isArmed() || c.isSelected()));
|
||||
}
|
||||
}
|
||||
|
||||
protected class MouseInputHandler implements MouseInputListener {
|
||||
public void mouseClicked(MouseEvent e) {}
|
||||
public void mousePressed(MouseEvent e) {
|
||||
MenuSelectionManager manager = MenuSelectionManager.defaultManager();
|
||||
manager.setSelectedPath(getPath());
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
MenuSelectionManager manager =
|
||||
MenuSelectionManager.defaultManager();
|
||||
JMenuItem menuItem = (JMenuItem)e.getComponent();
|
||||
Point p = e.getPoint();
|
||||
if(p.x >= 0 && p.x < menuItem.getWidth() &&
|
||||
p.y >= 0 && p.y < menuItem.getHeight()) {
|
||||
manager.clearSelectedPath();
|
||||
menuItem.doClick(0);
|
||||
} else {
|
||||
manager.processMouseEvent(e);
|
||||
}
|
||||
}
|
||||
public void mouseEntered(MouseEvent e) {}
|
||||
public void mouseExited(MouseEvent e) {}
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
MenuSelectionManager.defaultManager().processMouseEvent(e);
|
||||
}
|
||||
public void mouseMoved(MouseEvent e) { }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import java.awt.event.*;
|
||||
import javax.swing.MenuSelectionManager;
|
||||
|
||||
/**
|
||||
* A default MouseListener for menu elements
|
||||
*
|
||||
* @author Arnaud Weber
|
||||
*/
|
||||
class MotifMenuMouseListener extends MouseAdapter {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
MenuSelectionManager.defaultManager().processMouseEvent(e);
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
MenuSelectionManager.defaultManager().processMouseEvent(e);
|
||||
}
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
MenuSelectionManager.defaultManager().processMouseEvent(e);
|
||||
}
|
||||
public void mouseExited(MouseEvent e) {
|
||||
MenuSelectionManager.defaultManager().processMouseEvent(e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import java.awt.event.*;
|
||||
import javax.swing.MenuSelectionManager;
|
||||
|
||||
/**
|
||||
* A default MouseListener for menu elements
|
||||
*
|
||||
* @author Arnaud Weber
|
||||
*/
|
||||
class MotifMenuMouseMotionListener implements MouseMotionListener {
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
MenuSelectionManager.defaultManager().processMouseEvent(e);
|
||||
}
|
||||
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
MenuSelectionManager.defaultManager().processMouseEvent(e);
|
||||
}
|
||||
}
|
||||
151
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifMenuUI.java
Normal file
151
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifMenuUI.java
Normal file
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2004, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
|
||||
|
||||
import javax.swing.plaf.basic.BasicMenuUI;
|
||||
|
||||
/**
|
||||
* A Motif L&F implementation of MenuUI.
|
||||
* <p>
|
||||
*
|
||||
* @author Georges Saab
|
||||
* @author Rich Schiavi
|
||||
*/
|
||||
public class MotifMenuUI extends BasicMenuUI
|
||||
{
|
||||
|
||||
public static ComponentUI createUI( JComponent x ) {
|
||||
return new MotifMenuUI();
|
||||
}
|
||||
|
||||
// These should not be necessary because BasicMenuUI does this,
|
||||
// and this class overrides createChangeListener.
|
||||
// protected void installListeners() {
|
||||
// super.installListeners();
|
||||
// changeListener = createChangeListener(menuItem);
|
||||
// menuItem.addChangeListener(changeListener);
|
||||
// }
|
||||
//
|
||||
// protected void uninstallListeners() {
|
||||
// super.uninstallListeners();
|
||||
// menuItem.removeChangeListener(changeListener);
|
||||
// }
|
||||
|
||||
protected ChangeListener createChangeListener(JComponent c) {
|
||||
return new MotifChangeHandler((JMenu)c, this);
|
||||
}
|
||||
|
||||
private boolean popupIsOpen(JMenu m,MenuElement me[]) {
|
||||
int i;
|
||||
JPopupMenu pm = m.getPopupMenu();
|
||||
|
||||
for(i=me.length-1;i>=0;i--) {
|
||||
if(me[i].getComponent() == pm)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected MouseInputListener createMouseInputListener(JComponent c) {
|
||||
return new MouseInputHandler();
|
||||
}
|
||||
|
||||
public class MotifChangeHandler extends ChangeHandler {
|
||||
public MotifChangeHandler(JMenu m, MotifMenuUI ui) {
|
||||
super(m, ui);
|
||||
}
|
||||
|
||||
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
JMenuItem c = (JMenuItem)e.getSource();
|
||||
if (c.isArmed() || c.isSelected()) {
|
||||
c.setBorderPainted(true);
|
||||
// c.repaint();
|
||||
} else {
|
||||
c.setBorderPainted(false);
|
||||
}
|
||||
|
||||
super.stateChanged(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected class MouseInputHandler implements MouseInputListener {
|
||||
public void mouseClicked(MouseEvent e) {}
|
||||
public void mousePressed(MouseEvent e) {
|
||||
MenuSelectionManager manager = MenuSelectionManager.defaultManager();
|
||||
JMenu menu = (JMenu)e.getComponent();
|
||||
if(menu.isEnabled()) {
|
||||
if(menu.isTopLevelMenu()) {
|
||||
if(menu.isSelected()) {
|
||||
manager.clearSelectedPath();
|
||||
} else {
|
||||
Container cnt = menu.getParent();
|
||||
if(cnt != null && cnt instanceof JMenuBar) {
|
||||
MenuElement me[] = new MenuElement[2];
|
||||
me[0]=(MenuElement)cnt;
|
||||
me[1]=menu;
|
||||
manager.setSelectedPath(me);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MenuElement path[] = getPath();
|
||||
if (path.length > 0) {
|
||||
MenuElement newPath[] = new MenuElement[path.length+1];
|
||||
System.arraycopy(path,0,newPath,0,path.length);
|
||||
newPath[path.length] = menu.getPopupMenu();
|
||||
manager.setSelectedPath(newPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
MenuSelectionManager manager =
|
||||
MenuSelectionManager.defaultManager();
|
||||
JMenuItem menuItem = (JMenuItem)e.getComponent();
|
||||
Point p = e.getPoint();
|
||||
if(!(p.x >= 0 && p.x < menuItem.getWidth() &&
|
||||
p.y >= 0 && p.y < menuItem.getHeight())) {
|
||||
manager.processMouseEvent(e);
|
||||
}
|
||||
}
|
||||
public void mouseEntered(MouseEvent e) {}
|
||||
public void mouseExited(MouseEvent e) {}
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
MenuSelectionManager.defaultManager().processMouseEvent(e);
|
||||
}
|
||||
public void mouseMoved(MouseEvent e) { }
|
||||
}
|
||||
|
||||
}
|
||||
114
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifOptionPaneUI.java
Normal file
114
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifOptionPaneUI.java
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.basic.BasicOptionPaneUI;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
/**
|
||||
* Provides the CDE/Motif look and feel for a JOptionPane.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Scott Violet
|
||||
*/
|
||||
public class MotifOptionPaneUI extends BasicOptionPaneUI
|
||||
{
|
||||
/**
|
||||
* Creates a new MotifOptionPaneUI instance.
|
||||
*/
|
||||
public static ComponentUI createUI(JComponent x) {
|
||||
return new MotifOptionPaneUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a Container containin the buttons. The buttons
|
||||
* are created by calling <code>getButtons</code>.
|
||||
*/
|
||||
protected Container createButtonArea() {
|
||||
Container b = super.createButtonArea();
|
||||
|
||||
if(b != null && b.getLayout() instanceof ButtonAreaLayout) {
|
||||
((ButtonAreaLayout)b.getLayout()).setCentersChildren(false);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns null, CDE/Motif does not impose a minimum size.
|
||||
*/
|
||||
public Dimension getMinimumOptionPaneSize() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Container createSeparator() {
|
||||
return new JPanel() {
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(10, 2);
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
int width = getWidth();
|
||||
g.setColor(Color.darkGray);
|
||||
g.drawLine(0, 0, width, 0);
|
||||
g.setColor(Color.white);
|
||||
g.drawLine(0, 1, width, 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and adds a JLabel representing the icon returned from
|
||||
* <code>getIcon</code> to <code>top</code>. This is messaged from
|
||||
* <code>createMessageArea</code>
|
||||
*/
|
||||
protected void addIcon(Container top) {
|
||||
/* Create the icon. */
|
||||
Icon sideIcon = getIcon();
|
||||
|
||||
if (sideIcon != null) {
|
||||
JLabel iconLabel = new JLabel(sideIcon);
|
||||
|
||||
iconLabel.setVerticalAlignment(SwingConstants.CENTER);
|
||||
top.add(iconLabel, "West");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.BasicPasswordFieldUI;
|
||||
|
||||
/**
|
||||
* Provides the Motif look and feel for a password field.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Timothy Prinzing
|
||||
*/
|
||||
public class MotifPasswordFieldUI extends BasicPasswordFieldUI {
|
||||
|
||||
/**
|
||||
* Creates a UI for a JPasswordField.
|
||||
*
|
||||
* @param c the JPasswordField
|
||||
* @return the UI
|
||||
*/
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new MotifPasswordFieldUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the object to use for a caret. By default an
|
||||
* instance of MotifTextUI.MotifCaret is created. This method
|
||||
* can be redefined to provide something else that implements
|
||||
* the Caret interface.
|
||||
*
|
||||
* @return the caret object
|
||||
*/
|
||||
protected Caret createCaret() {
|
||||
return MotifTextUI.createCaret();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
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 Motif L&F implementation of PopupMenuSeparatorUI. This implementation
|
||||
* is a "combined" view/controller.
|
||||
*
|
||||
* @author Jeff Shapiro
|
||||
*/
|
||||
|
||||
public class MotifPopupMenuSeparatorUI extends MotifSeparatorUI
|
||||
{
|
||||
public static ComponentUI createUI( JComponent c )
|
||||
{
|
||||
return new MotifPopupMenuSeparatorUI();
|
||||
}
|
||||
|
||||
public void paint( Graphics g, JComponent c )
|
||||
{
|
||||
Dimension s = c.getSize();
|
||||
|
||||
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 )
|
||||
{
|
||||
return new Dimension( 0, 2 );
|
||||
}
|
||||
|
||||
}
|
||||
114
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifPopupMenuUI.java
Normal file
114
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifPopupMenuUI.java
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import sun.swing.SwingUtilities2;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.border.*;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Insets;
|
||||
import java.awt.LayoutManager;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.BasicPopupMenuUI;
|
||||
|
||||
|
||||
/**
|
||||
* A Motif L&F implementation of PopupMenuUI.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Georges Saab
|
||||
* @author Rich Schiavi
|
||||
*/
|
||||
public class MotifPopupMenuUI extends BasicPopupMenuUI {
|
||||
private static Border border = null;
|
||||
private Font titleFont = null;
|
||||
|
||||
public static ComponentUI createUI(JComponent x) {
|
||||
return new MotifPopupMenuUI();
|
||||
}
|
||||
|
||||
/* This has to deal with the fact that the title may be wider than
|
||||
the widest child component.
|
||||
*/
|
||||
public Dimension getPreferredSize(JComponent c) {
|
||||
LayoutManager layout = c.getLayout();
|
||||
Dimension d = layout.preferredLayoutSize(c);
|
||||
String title = ((JPopupMenu)c).getLabel();
|
||||
if (titleFont == null) {
|
||||
UIDefaults table = UIManager.getLookAndFeelDefaults();
|
||||
titleFont = table.getFont("PopupMenu.font");
|
||||
}
|
||||
FontMetrics fm = c.getFontMetrics(titleFont);
|
||||
int stringWidth = 0;
|
||||
|
||||
if (title!=null) {
|
||||
stringWidth += SwingUtilities2.stringWidth(c, fm, title);
|
||||
}
|
||||
|
||||
if (d.width < stringWidth) {
|
||||
d.width = stringWidth + 8;
|
||||
Insets i = c.getInsets();
|
||||
if (i!=null) {
|
||||
d.width += i.left + i.right;
|
||||
}
|
||||
if (border != null) {
|
||||
i = border.getBorderInsets(c);
|
||||
d.width += i.left + i.right;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected ChangeListener createChangeListener(JPopupMenu m) {
|
||||
return new ChangeListener() {
|
||||
public void stateChanged(ChangeEvent e) {}
|
||||
};
|
||||
}
|
||||
|
||||
public boolean isPopupTrigger(MouseEvent e) {
|
||||
return ((e.getID()==MouseEvent.MOUSE_PRESSED)
|
||||
&& ((e.getModifiers() & MouseEvent.BUTTON3_MASK)!=0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.plaf.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.swing.plaf.basic.BasicProgressBarUI;
|
||||
|
||||
|
||||
/**
|
||||
* A Motif 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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Michael C. Albers
|
||||
*/
|
||||
public class MotifProgressBarUI extends BasicProgressBarUI
|
||||
{
|
||||
/**
|
||||
* Creates the ProgressBar's UI
|
||||
*/
|
||||
public static ComponentUI createUI(JComponent x) {
|
||||
return new MotifProgressBarUI();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.BasicRadioButtonMenuItemUI;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* MotifRadioButtonMenuItem 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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Georges Saab
|
||||
* @author Rich Schiavi
|
||||
*/
|
||||
public class MotifRadioButtonMenuItemUI extends BasicRadioButtonMenuItemUI
|
||||
{
|
||||
protected ChangeListener changeListener;
|
||||
|
||||
public static ComponentUI createUI(JComponent b) {
|
||||
return new MotifRadioButtonMenuItemUI();
|
||||
}
|
||||
|
||||
protected void installListeners() {
|
||||
super.installListeners();
|
||||
changeListener = createChangeListener(menuItem);
|
||||
menuItem.addChangeListener(changeListener);
|
||||
}
|
||||
|
||||
protected void uninstallListeners() {
|
||||
super.uninstallListeners();
|
||||
menuItem.removeChangeListener(changeListener);
|
||||
}
|
||||
|
||||
protected ChangeListener createChangeListener(JComponent c) {
|
||||
return new ChangeHandler();
|
||||
}
|
||||
|
||||
protected class ChangeHandler implements ChangeListener, Serializable {
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
JMenuItem c = (JMenuItem)e.getSource();
|
||||
LookAndFeel.installProperty(c, "borderPainted", c.isArmed());
|
||||
}
|
||||
}
|
||||
|
||||
protected MouseInputListener createMouseInputListener(JComponent c) {
|
||||
return new MouseInputHandler();
|
||||
}
|
||||
|
||||
|
||||
protected class MouseInputHandler implements MouseInputListener {
|
||||
public void mouseClicked(MouseEvent e) {}
|
||||
public void mousePressed(MouseEvent e) {
|
||||
MenuSelectionManager manager = MenuSelectionManager.defaultManager();
|
||||
manager.setSelectedPath(getPath());
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
MenuSelectionManager manager =
|
||||
MenuSelectionManager.defaultManager();
|
||||
JMenuItem menuItem = (JMenuItem)e.getComponent();
|
||||
Point p = e.getPoint();
|
||||
if(p.x >= 0 && p.x < menuItem.getWidth() &&
|
||||
p.y >= 0 && p.y < menuItem.getHeight()) {
|
||||
manager.clearSelectedPath();
|
||||
menuItem.doClick(0);
|
||||
} else {
|
||||
manager.processMouseEvent(e);
|
||||
}
|
||||
}
|
||||
public void mouseEntered(MouseEvent e) {}
|
||||
public void mouseExited(MouseEvent e) {}
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
MenuSelectionManager.defaultManager().processMouseEvent(e);
|
||||
}
|
||||
public void mouseMoved(MouseEvent e) { }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import sun.awt.AppContext;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.basic.BasicRadioButtonUI;
|
||||
|
||||
import javax.swing.plaf.*;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* RadioButtonUI implementation for MotifRadioButtonUI
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Rich Schiavi
|
||||
*/
|
||||
public class MotifRadioButtonUI extends BasicRadioButtonUI {
|
||||
|
||||
private static final Object MOTIF_RADIO_BUTTON_UI_KEY = new Object();
|
||||
|
||||
protected Color focusColor;
|
||||
|
||||
private boolean defaults_initialized = false;
|
||||
|
||||
// ********************************
|
||||
// Create PLAF
|
||||
// ********************************
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
AppContext appContext = AppContext.getAppContext();
|
||||
MotifRadioButtonUI motifRadioButtonUI =
|
||||
(MotifRadioButtonUI) appContext.get(MOTIF_RADIO_BUTTON_UI_KEY);
|
||||
if (motifRadioButtonUI == null) {
|
||||
motifRadioButtonUI = new MotifRadioButtonUI();
|
||||
appContext.put(MOTIF_RADIO_BUTTON_UI_KEY, motifRadioButtonUI);
|
||||
}
|
||||
return motifRadioButtonUI;
|
||||
}
|
||||
|
||||
// ********************************
|
||||
// Install Defaults
|
||||
// ********************************
|
||||
public void installDefaults(AbstractButton b) {
|
||||
super.installDefaults(b);
|
||||
if(!defaults_initialized) {
|
||||
focusColor = UIManager.getColor(getPropertyPrefix() + "focus");
|
||||
defaults_initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected void uninstallDefaults(AbstractButton b) {
|
||||
super.uninstallDefaults(b);
|
||||
defaults_initialized = false;
|
||||
}
|
||||
|
||||
// ********************************
|
||||
// Default Accessors
|
||||
// ********************************
|
||||
|
||||
protected Color getFocusColor() {
|
||||
return focusColor;
|
||||
}
|
||||
|
||||
// ********************************
|
||||
// Paint Methods
|
||||
// ********************************
|
||||
protected void paintFocus(Graphics g, Rectangle t, Dimension d){
|
||||
g.setColor(getFocusColor());
|
||||
g.drawRect(0,0,d.width-1,d.height-1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.BasicArrowButton;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* Motif scroll bar button.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*/
|
||||
public class MotifScrollBarButton extends BasicArrowButton
|
||||
{
|
||||
private Color darkShadow = UIManager.getColor("controlShadow");
|
||||
private Color lightShadow = UIManager.getColor("controlLtHighlight");
|
||||
|
||||
|
||||
public MotifScrollBarButton(int direction)
|
||||
{
|
||||
super(direction);
|
||||
|
||||
switch (direction) {
|
||||
case NORTH:
|
||||
case SOUTH:
|
||||
case EAST:
|
||||
case WEST:
|
||||
this.direction = direction;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("invalid direction");
|
||||
}
|
||||
|
||||
setRequestFocusEnabled(false);
|
||||
setOpaque(true);
|
||||
setBackground(UIManager.getColor("ScrollBar.background"));
|
||||
setForeground(UIManager.getColor("ScrollBar.foreground"));
|
||||
}
|
||||
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
switch (direction) {
|
||||
case NORTH:
|
||||
case SOUTH:
|
||||
return new Dimension(11, 12);
|
||||
case EAST:
|
||||
case WEST:
|
||||
default:
|
||||
return new Dimension(12, 11);
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize() {
|
||||
return getPreferredSize();
|
||||
}
|
||||
|
||||
public Dimension getMaximumSize() {
|
||||
return getPreferredSize();
|
||||
}
|
||||
|
||||
public boolean isFocusTraversable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void paint(Graphics g)
|
||||
{
|
||||
int w = getWidth();
|
||||
int h = getHeight();
|
||||
|
||||
if (isOpaque()) {
|
||||
g.setColor(getBackground());
|
||||
g.fillRect(0, 0, w, h);
|
||||
}
|
||||
|
||||
boolean isPressed = getModel().isPressed();
|
||||
Color lead = (isPressed) ? darkShadow : lightShadow;
|
||||
Color trail = (isPressed) ? lightShadow : darkShadow;
|
||||
Color fill = getBackground();
|
||||
|
||||
int cx = w / 2;
|
||||
int cy = h / 2;
|
||||
int s = Math.min(w, h);
|
||||
|
||||
switch (direction) {
|
||||
case NORTH:
|
||||
g.setColor(lead);
|
||||
g.drawLine(cx, 0, cx, 0);
|
||||
for (int x = cx - 1, y = 1, dx = 1; y <= s - 2; y += 2) {
|
||||
g.setColor(lead);
|
||||
g.drawLine(x, y, x, y);
|
||||
if (y >= (s - 2)) {
|
||||
g.drawLine(x, y + 1, x, y + 1);
|
||||
}
|
||||
g.setColor(fill);
|
||||
g.drawLine(x + 1, y, x + dx, y);
|
||||
if (y < (s - 2)) {
|
||||
g.drawLine(x, y + 1, x + dx + 1, y + 1);
|
||||
}
|
||||
g.setColor(trail);
|
||||
g.drawLine(x + dx + 1, y, x + dx + 1, y);
|
||||
if (y >= (s - 2)) {
|
||||
g.drawLine(x + 1, y + 1, x + dx + 1, y + 1);
|
||||
}
|
||||
dx += 2;
|
||||
x -= 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case SOUTH:
|
||||
g.setColor(trail);
|
||||
g.drawLine(cx, s, cx, s);
|
||||
for (int x = cx - 1, y = s - 1, dx = 1; y >= 1; y -= 2) {
|
||||
g.setColor(lead);
|
||||
g.drawLine(x, y, x, y);
|
||||
if (y <= 2) {
|
||||
g.drawLine(x, y - 1, x + dx + 1, y - 1);
|
||||
}
|
||||
g.setColor(fill);
|
||||
g.drawLine(x + 1, y, x + dx, y);
|
||||
if (y > 2) {
|
||||
g.drawLine(x, y - 1, x + dx + 1, y - 1);
|
||||
}
|
||||
g.setColor(trail);
|
||||
g.drawLine(x + dx + 1, y, x + dx + 1, y);
|
||||
|
||||
dx += 2;
|
||||
x -= 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case EAST:
|
||||
g.setColor(lead);
|
||||
g.drawLine(s, cy, s, cy);
|
||||
for (int y = cy - 1, x = s - 1, dy = 1; x >= 1; x -= 2) {
|
||||
g.setColor(lead);
|
||||
g.drawLine(x, y, x, y);
|
||||
if (x <= 2) {
|
||||
g.drawLine(x - 1, y, x - 1, y + dy + 1);
|
||||
}
|
||||
g.setColor(fill);
|
||||
g.drawLine(x, y + 1, x, y + dy);
|
||||
if (x > 2) {
|
||||
g.drawLine(x - 1, y, x - 1, y + dy + 1);
|
||||
}
|
||||
g.setColor(trail);
|
||||
g.drawLine(x, y + dy + 1, x, y + dy + 1);
|
||||
|
||||
dy += 2;
|
||||
y -= 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case WEST:
|
||||
g.setColor(trail);
|
||||
g.drawLine(0, cy, 0, cy);
|
||||
for (int y = cy - 1, x = 1, dy = 1; x <= s - 2; x += 2) {
|
||||
g.setColor(lead);
|
||||
g.drawLine(x, y, x, y);
|
||||
if (x >= (s - 2)) {
|
||||
g.drawLine(x + 1, y, x + 1, y);
|
||||
}
|
||||
g.setColor(fill);
|
||||
g.drawLine(x, y + 1, x, y + dy);
|
||||
if (x < (s - 2)) {
|
||||
g.drawLine(x + 1, y, x + 1, y + dy + 1);
|
||||
}
|
||||
g.setColor(trail);
|
||||
g.drawLine(x, y + dy + 1, x, y + dy + 1);
|
||||
if (x >= (s - 2)) {
|
||||
g.drawLine(x + 1, y + 1, x + 1, y + dy + 1);
|
||||
}
|
||||
dy += 2;
|
||||
y -= 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
106
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifScrollBarUI.java
Normal file
106
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifScrollBarUI.java
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JScrollBar;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.basic.BasicScrollBarUI;
|
||||
|
||||
import static sun.swing.SwingUtilities2.drawHLine;
|
||||
import static sun.swing.SwingUtilities2.drawVLine;
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of ScrollBarUI for the Motif Look and Feel
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Rich Schiavi
|
||||
* @author Hans Muller
|
||||
*/
|
||||
public class MotifScrollBarUI extends BasicScrollBarUI
|
||||
{
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new MotifScrollBarUI();
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize(JComponent c) {
|
||||
Insets insets = c.getInsets();
|
||||
int dx = insets.left + insets.right;
|
||||
int dy = insets.top + insets.bottom;
|
||||
return (scrollbar.getOrientation() == JScrollBar.VERTICAL)
|
||||
? new Dimension(dx + 11, dy + 33)
|
||||
: new Dimension(dx + 33, dy + 11);
|
||||
}
|
||||
|
||||
protected JButton createDecreaseButton(int orientation) {
|
||||
return new MotifScrollBarButton(orientation);
|
||||
}
|
||||
|
||||
protected JButton createIncreaseButton(int orientation) {
|
||||
return new MotifScrollBarButton(orientation);
|
||||
}
|
||||
|
||||
public void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
|
||||
g.setColor(trackColor);
|
||||
g.fillRect(trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height);
|
||||
}
|
||||
|
||||
public void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
|
||||
if (thumbBounds.isEmpty() || !scrollbar.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int w = thumbBounds.width;
|
||||
int h = thumbBounds.height;
|
||||
|
||||
g.translate(thumbBounds.x, thumbBounds.y);
|
||||
g.setColor(thumbColor);
|
||||
g.fillRect(0, 0, w - 1, h - 1);
|
||||
|
||||
g.setColor(thumbHighlightColor);
|
||||
drawVLine(g, 0, 0, h - 1);
|
||||
drawHLine(g, 1, w - 1, 0);
|
||||
|
||||
g.setColor(thumbLightShadowColor);
|
||||
drawHLine(g, 1, w - 1, h - 1);
|
||||
drawVLine(g, w - 1, 1, h - 2);
|
||||
|
||||
g.translate(-thumbBounds.x, -thumbBounds.y);
|
||||
}
|
||||
}
|
||||
147
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifScrollPaneUI.java
Normal file
147
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifScrollPaneUI.java
Normal file
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.BasicScrollPaneUI;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
|
||||
/**
|
||||
* A CDE/Motif 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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Hans Muller
|
||||
*/
|
||||
public class MotifScrollPaneUI extends BasicScrollPaneUI
|
||||
{
|
||||
private final static Border vsbMarginBorderR = new EmptyBorder(0, 4, 0, 0);
|
||||
private final static Border vsbMarginBorderL = new EmptyBorder(0, 0, 0, 4);
|
||||
private final static Border hsbMarginBorder = new EmptyBorder(4, 0, 0, 0);
|
||||
|
||||
private CompoundBorder vsbBorder;
|
||||
private CompoundBorder hsbBorder;
|
||||
|
||||
private PropertyChangeListener propertyChangeHandler;
|
||||
|
||||
@Override
|
||||
protected void installListeners(JScrollPane scrollPane) {
|
||||
super.installListeners(scrollPane);
|
||||
propertyChangeHandler = createPropertyChangeHandler();
|
||||
scrollPane.addPropertyChangeListener(propertyChangeHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void uninstallListeners(JComponent scrollPane) {
|
||||
super.uninstallListeners(scrollPane);
|
||||
scrollPane.removePropertyChangeListener(propertyChangeHandler);
|
||||
}
|
||||
|
||||
private PropertyChangeListener createPropertyChangeHandler() {
|
||||
return new PropertyChangeListener() {
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent e) {
|
||||
String propertyName = e.getPropertyName();
|
||||
|
||||
if (propertyName.equals("componentOrientation")) {
|
||||
JScrollPane pane = (JScrollPane)e.getSource();
|
||||
JScrollBar vsb = pane.getVerticalScrollBar();
|
||||
if (vsb != null && vsbBorder != null &&
|
||||
vsb.getBorder() == vsbBorder) {
|
||||
// The Border on the verticall scrollbar matches
|
||||
// what we installed, reset it.
|
||||
if (MotifGraphicsUtils.isLeftToRight(pane)) {
|
||||
vsbBorder = new CompoundBorder(vsbMarginBorderR,
|
||||
vsbBorder.getInsideBorder());
|
||||
} else {
|
||||
vsbBorder = new CompoundBorder(vsbMarginBorderL,
|
||||
vsbBorder.getInsideBorder());
|
||||
}
|
||||
vsb.setBorder(vsbBorder);
|
||||
}
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void installDefaults(JScrollPane scrollpane) {
|
||||
super.installDefaults(scrollpane);
|
||||
|
||||
JScrollBar vsb = scrollpane.getVerticalScrollBar();
|
||||
if (vsb != null) {
|
||||
if (MotifGraphicsUtils.isLeftToRight(scrollpane)) {
|
||||
vsbBorder = new CompoundBorder(vsbMarginBorderR,
|
||||
vsb.getBorder());
|
||||
}
|
||||
else {
|
||||
vsbBorder = new CompoundBorder(vsbMarginBorderL,
|
||||
vsb.getBorder());
|
||||
}
|
||||
vsb.setBorder(vsbBorder);
|
||||
}
|
||||
|
||||
JScrollBar hsb = scrollpane.getHorizontalScrollBar();
|
||||
if (hsb != null) {
|
||||
hsbBorder = new CompoundBorder(hsbMarginBorder, hsb.getBorder());
|
||||
hsb.setBorder(hsbBorder);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void uninstallDefaults(JScrollPane c) {
|
||||
super.uninstallDefaults(c);
|
||||
|
||||
JScrollBar vsb = scrollpane.getVerticalScrollBar();
|
||||
if (vsb != null) {
|
||||
if (vsb.getBorder() == vsbBorder) {
|
||||
vsb.setBorder(null);
|
||||
}
|
||||
vsbBorder = null;
|
||||
}
|
||||
|
||||
JScrollBar hsb = scrollpane.getHorizontalScrollBar();
|
||||
if (hsb != null) {
|
||||
if (hsb.getBorder() == hsbBorder) {
|
||||
hsb.setBorder(null);
|
||||
}
|
||||
hsbBorder = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static ComponentUI createUI(JComponent x) {
|
||||
return new MotifScrollPaneUI();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
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 Motif 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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Georges Saab
|
||||
* @author Jeff Shapiro
|
||||
*/
|
||||
|
||||
public class MotifSeparatorUI extends BasicSeparatorUI
|
||||
{
|
||||
public static ComponentUI createUI( JComponent c )
|
||||
{
|
||||
return new MotifSeparatorUI();
|
||||
}
|
||||
|
||||
}
|
||||
162
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifSliderUI.java
Normal file
162
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifSliderUI.java
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.basic.BasicSliderUI;
|
||||
|
||||
import static sun.swing.SwingUtilities2.drawHLine;
|
||||
import static sun.swing.SwingUtilities2.drawVLine;
|
||||
|
||||
/**
|
||||
* Motif Slider
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Jeff Dinkins
|
||||
*/
|
||||
public class MotifSliderUI extends BasicSliderUI {
|
||||
|
||||
static final Dimension PREFERRED_HORIZONTAL_SIZE = new Dimension(164, 15);
|
||||
static final Dimension PREFERRED_VERTICAL_SIZE = new Dimension(15, 164);
|
||||
|
||||
static final Dimension MINIMUM_HORIZONTAL_SIZE = new Dimension(43, 15);
|
||||
static final Dimension MINIMUM_VERTICAL_SIZE = new Dimension(15, 43);
|
||||
|
||||
/**
|
||||
* MotifSliderUI Constructor
|
||||
*/
|
||||
public MotifSliderUI(JSlider b) {
|
||||
super(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* create a MotifSliderUI object
|
||||
*/
|
||||
public static ComponentUI createUI(JComponent b) {
|
||||
return new MotifSliderUI((JSlider)b);
|
||||
}
|
||||
|
||||
public Dimension getPreferredHorizontalSize() {
|
||||
return PREFERRED_HORIZONTAL_SIZE;
|
||||
}
|
||||
|
||||
public Dimension getPreferredVerticalSize() {
|
||||
return PREFERRED_VERTICAL_SIZE;
|
||||
}
|
||||
|
||||
public Dimension getMinimumHorizontalSize() {
|
||||
return MINIMUM_HORIZONTAL_SIZE;
|
||||
}
|
||||
|
||||
public Dimension getMinimumVerticalSize() {
|
||||
return MINIMUM_VERTICAL_SIZE;
|
||||
}
|
||||
|
||||
protected Dimension getThumbSize() {
|
||||
if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
|
||||
return new Dimension( 30, 15 );
|
||||
}
|
||||
else {
|
||||
return new Dimension( 15, 30 );
|
||||
}
|
||||
}
|
||||
|
||||
public void paintFocus(Graphics g) {
|
||||
}
|
||||
|
||||
public void paintTrack(Graphics g) {
|
||||
}
|
||||
|
||||
public void paintThumb(Graphics g) {
|
||||
Rectangle knobBounds = thumbRect;
|
||||
|
||||
int x = knobBounds.x;
|
||||
int y = knobBounds.y;
|
||||
int w = knobBounds.width;
|
||||
int h = knobBounds.height;
|
||||
|
||||
if ( slider.isEnabled() ) {
|
||||
g.setColor(slider.getForeground());
|
||||
}
|
||||
else {
|
||||
// PENDING(jeff) - the thumb should be dithered when disabled
|
||||
g.setColor(slider.getForeground().darker());
|
||||
}
|
||||
|
||||
if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
|
||||
g.translate(x, knobBounds.y-1);
|
||||
|
||||
// fill
|
||||
g.fillRect(0, 1, w, h - 1);
|
||||
|
||||
// highlight
|
||||
g.setColor(getHighlightColor());
|
||||
drawHLine(g, 0, w - 1, 1); // top
|
||||
drawVLine(g, 0, 1, h); // left
|
||||
drawVLine(g, w / 2, 2, h - 1); // center
|
||||
|
||||
// shadow
|
||||
g.setColor(getShadowColor());
|
||||
drawHLine(g, 0, w - 1, h); // bottom
|
||||
drawVLine(g, w - 1, 1, h); // right
|
||||
drawVLine(g, w / 2 - 1, 2, h); // center
|
||||
|
||||
g.translate(-x, -(knobBounds.y-1));
|
||||
}
|
||||
else {
|
||||
g.translate(knobBounds.x-1, 0);
|
||||
|
||||
// fill
|
||||
g.fillRect(1, y, w - 1, h);
|
||||
|
||||
// highlight
|
||||
g.setColor(getHighlightColor());
|
||||
drawHLine(g, 1, w, y); // top
|
||||
drawVLine(g, 1, y + 1, y + h - 1); // left
|
||||
drawHLine(g, 2, w - 1, y + h / 2); // center
|
||||
|
||||
// shadow
|
||||
g.setColor(getShadowColor());
|
||||
drawHLine(g, 2, w, y + h - 1); // bottom
|
||||
drawVLine(g, w, y + h - 1, y); // right
|
||||
drawHLine(g, 2, w - 1, y + h / 2 - 1);// center
|
||||
|
||||
g.translate(-(knobBounds.x-1), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,295 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1999, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.basic.BasicSplitPaneUI;
|
||||
import javax.swing.plaf.basic.BasicSplitPaneDivider;
|
||||
|
||||
|
||||
/**
|
||||
* Divider used for Motif 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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Jeff Dinkins
|
||||
*/
|
||||
public class MotifSplitPaneDivider extends BasicSplitPaneDivider
|
||||
{
|
||||
/**
|
||||
* Default cursor, supers is package private, so we have to have one
|
||||
* too.
|
||||
*/
|
||||
private static final Cursor defaultCursor =
|
||||
Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
|
||||
|
||||
|
||||
public static final int minimumThumbSize = 6;
|
||||
public static final int defaultDividerSize = 18;
|
||||
|
||||
protected static final int pad = 6;
|
||||
|
||||
private int hThumbOffset = 30;
|
||||
private int vThumbOffset = 40;
|
||||
protected int hThumbWidth = 12;
|
||||
protected int hThumbHeight = 18;
|
||||
protected int vThumbWidth = 18;
|
||||
protected int vThumbHeight = 12;
|
||||
|
||||
protected Color highlightColor;
|
||||
protected Color shadowColor;
|
||||
protected Color focusedColor;
|
||||
|
||||
/**
|
||||
* Creates a new Motif SplitPaneDivider
|
||||
*/
|
||||
public MotifSplitPaneDivider(BasicSplitPaneUI ui) {
|
||||
super(ui);
|
||||
highlightColor = UIManager.getColor("SplitPane.highlight");
|
||||
shadowColor = UIManager.getColor("SplitPane.shadow");
|
||||
focusedColor = UIManager.getColor("SplitPane.activeThumb");
|
||||
setDividerSize(hThumbWidth + pad);
|
||||
}
|
||||
|
||||
/**
|
||||
* overrides to hardcode the size of the divider
|
||||
* PENDING(jeff) - rewrite JSplitPane so that this ins't needed
|
||||
*/
|
||||
public void setDividerSize(int newSize) {
|
||||
Insets insets = getInsets();
|
||||
int borderSize = 0;
|
||||
if (getBasicSplitPaneUI().getOrientation() ==
|
||||
JSplitPane.HORIZONTAL_SPLIT) {
|
||||
if (insets != null) {
|
||||
borderSize = insets.left + insets.right;
|
||||
}
|
||||
}
|
||||
else if (insets != null) {
|
||||
borderSize = insets.top + insets.bottom;
|
||||
}
|
||||
if (newSize < pad + minimumThumbSize + borderSize) {
|
||||
setDividerSize(pad + minimumThumbSize + borderSize);
|
||||
} else {
|
||||
vThumbHeight = hThumbWidth = newSize - pad - borderSize;
|
||||
super.setDividerSize(newSize);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints the divider.
|
||||
*/
|
||||
// PENDING(jeff) - the thumb's location and size is currently hard coded.
|
||||
// It should be dynamic.
|
||||
public void paint(Graphics g) {
|
||||
Color bgColor = getBackground();
|
||||
Dimension size = getSize();
|
||||
|
||||
// fill
|
||||
g.setColor(getBackground());
|
||||
g.fillRect(0, 0, size.width, size.height);
|
||||
|
||||
if(getBasicSplitPaneUI().getOrientation() ==
|
||||
JSplitPane.HORIZONTAL_SPLIT) {
|
||||
int center = size.width/2;
|
||||
int x = center - hThumbWidth/2;
|
||||
int y = hThumbOffset;
|
||||
|
||||
// split line
|
||||
g.setColor(shadowColor);
|
||||
g.drawLine(center-1, 0, center-1, size.height);
|
||||
|
||||
g.setColor(highlightColor);
|
||||
g.drawLine(center, 0, center, size.height);
|
||||
|
||||
// draw thumb
|
||||
g.setColor((splitPane.hasFocus()) ? focusedColor :
|
||||
getBackground());
|
||||
g.fillRect(x+1, y+1, hThumbWidth-2, hThumbHeight-1);
|
||||
|
||||
g.setColor(highlightColor);
|
||||
g.drawLine(x, y, x+hThumbWidth-1, y); // top
|
||||
g.drawLine(x, y+1, x, y+hThumbHeight-1); // left
|
||||
|
||||
g.setColor(shadowColor);
|
||||
g.drawLine(x+1, y+hThumbHeight-1,
|
||||
x+hThumbWidth-1, y+hThumbHeight-1); // bottom
|
||||
g.drawLine(x+hThumbWidth-1, y+1,
|
||||
x+hThumbWidth-1, y+hThumbHeight-2); // right
|
||||
|
||||
} else {
|
||||
int center = size.height/2;
|
||||
int x = size.width - vThumbOffset;
|
||||
int y = size.height/2 - vThumbHeight/2;
|
||||
|
||||
// split line
|
||||
g.setColor(shadowColor);
|
||||
g.drawLine(0, center-1, size.width, center-1);
|
||||
|
||||
g.setColor(highlightColor);
|
||||
g.drawLine(0, center, size.width, center);
|
||||
|
||||
// draw thumb
|
||||
g.setColor((splitPane.hasFocus()) ? focusedColor :
|
||||
getBackground());
|
||||
g.fillRect(x+1, y+1, vThumbWidth-1, vThumbHeight-1);
|
||||
|
||||
g.setColor(highlightColor);
|
||||
g.drawLine(x, y, x+vThumbWidth, y); // top
|
||||
g.drawLine(x, y+1, x, y+vThumbHeight); // left
|
||||
|
||||
g.setColor(shadowColor);
|
||||
g.drawLine(x+1, y+vThumbHeight,
|
||||
x+vThumbWidth, y+vThumbHeight); // bottom
|
||||
g.drawLine(x+vThumbWidth, y+1,
|
||||
x+vThumbWidth, y+vThumbHeight-1); // right
|
||||
}
|
||||
super.paint(g);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The minimums size is the same as the preferredSize
|
||||
*/
|
||||
public Dimension getMinimumSize() {
|
||||
return getPreferredSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the SplitPaneUI that is using the receiver. This is completely
|
||||
* overriden from super to create a different MouseHandler.
|
||||
*/
|
||||
public void setBasicSplitPaneUI(BasicSplitPaneUI newUI) {
|
||||
if (splitPane != null) {
|
||||
splitPane.removePropertyChangeListener(this);
|
||||
if (mouseHandler != null) {
|
||||
splitPane.removeMouseListener(mouseHandler);
|
||||
splitPane.removeMouseMotionListener(mouseHandler);
|
||||
removeMouseListener(mouseHandler);
|
||||
removeMouseMotionListener(mouseHandler);
|
||||
mouseHandler = null;
|
||||
}
|
||||
}
|
||||
splitPaneUI = newUI;
|
||||
if (newUI != null) {
|
||||
splitPane = newUI.getSplitPane();
|
||||
if (splitPane != null) {
|
||||
if (mouseHandler == null) mouseHandler=new MotifMouseHandler();
|
||||
splitPane.addMouseListener(mouseHandler);
|
||||
splitPane.addMouseMotionListener(mouseHandler);
|
||||
addMouseListener(mouseHandler);
|
||||
addMouseMotionListener(mouseHandler);
|
||||
splitPane.addPropertyChangeListener(this);
|
||||
if (splitPane.isOneTouchExpandable()) {
|
||||
oneTouchExpandableChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
splitPane = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the point at <code>x</code>, <code>y</code>
|
||||
* is inside the thumb.
|
||||
*/
|
||||
private boolean isInThumb(int x, int y) {
|
||||
Dimension size = getSize();
|
||||
int thumbX;
|
||||
int thumbY;
|
||||
int thumbWidth;
|
||||
int thumbHeight;
|
||||
|
||||
if (getBasicSplitPaneUI().getOrientation() ==
|
||||
JSplitPane.HORIZONTAL_SPLIT) {
|
||||
int center = size.width/2;
|
||||
thumbX = center - hThumbWidth/2;
|
||||
thumbY = hThumbOffset;
|
||||
thumbWidth = hThumbWidth;
|
||||
thumbHeight = hThumbHeight;
|
||||
}
|
||||
else {
|
||||
int center = size.height/2;
|
||||
thumbX = size.width - vThumbOffset;
|
||||
thumbY = size.height/2 - vThumbHeight/2;
|
||||
thumbWidth = vThumbWidth;
|
||||
thumbHeight = vThumbHeight;
|
||||
}
|
||||
return (x >= thumbX && x < (thumbX + thumbWidth) &&
|
||||
y >= thumbY && y < (thumbY + thumbHeight));
|
||||
}
|
||||
|
||||
//
|
||||
// Two methods are exposed so that MotifMouseHandler can see the
|
||||
// superclass protected ivars
|
||||
//
|
||||
|
||||
private DragController getDragger() {
|
||||
return dragger;
|
||||
}
|
||||
|
||||
private JSplitPane getSplitPane() {
|
||||
return splitPane;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* MouseHandler is subclassed to only pass off to super if the mouse
|
||||
* is in the thumb. Motif only allows dragging when the thumb is clicked
|
||||
* in.
|
||||
*/
|
||||
private class MotifMouseHandler extends MouseHandler {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
// Constrain the mouse pressed to the thumb.
|
||||
if (e.getSource() == MotifSplitPaneDivider.this &&
|
||||
getDragger() == null && getSplitPane().isEnabled() &&
|
||||
isInThumb(e.getX(), e.getY())) {
|
||||
super.mousePressed(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
if (getDragger() != null) {
|
||||
return;
|
||||
}
|
||||
if (!isInThumb(e.getX(), e.getY())) {
|
||||
if (getCursor() != defaultCursor) {
|
||||
setCursor(defaultCursor);
|
||||
}
|
||||
return;
|
||||
}
|
||||
super.mouseMoved(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import javax.swing.plaf.basic.BasicSplitPaneUI;
|
||||
import javax.swing.plaf.basic.BasicSplitPaneDivider;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Motif rendition of a 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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Jeff Dinkins
|
||||
*/
|
||||
public class MotifSplitPaneUI extends BasicSplitPaneUI
|
||||
{
|
||||
public MotifSplitPaneUI() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new MotifSplitPaneUI instance
|
||||
*/
|
||||
public static ComponentUI createUI(JComponent x) {
|
||||
return new MotifSplitPaneUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the default divider.
|
||||
*/
|
||||
public BasicSplitPaneDivider createDefaultDivider() {
|
||||
return new MotifSplitPaneDivider(this);
|
||||
}
|
||||
|
||||
}
|
||||
306
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifTabbedPaneUI.java
Normal file
306
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifTabbedPaneUI.java
Normal file
@@ -0,0 +1,306 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.BasicTabbedPaneUI;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* A Motif L&F implementation of TabbedPaneUI.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Amy Fowler
|
||||
* @author Philip Milne
|
||||
*/
|
||||
public class MotifTabbedPaneUI extends BasicTabbedPaneUI
|
||||
{
|
||||
|
||||
// Instance variables initialized at installation
|
||||
|
||||
protected Color unselectedTabBackground;
|
||||
protected Color unselectedTabForeground;
|
||||
protected Color unselectedTabShadow;
|
||||
protected Color unselectedTabHighlight;
|
||||
|
||||
|
||||
// UI creation
|
||||
|
||||
public static ComponentUI createUI(JComponent tabbedPane) {
|
||||
return new MotifTabbedPaneUI();
|
||||
}
|
||||
|
||||
|
||||
// UI Installation/De-installation
|
||||
|
||||
|
||||
protected void installDefaults() {
|
||||
super.installDefaults();
|
||||
|
||||
unselectedTabBackground = UIManager.getColor("TabbedPane.unselectedTabBackground");
|
||||
unselectedTabForeground = UIManager.getColor("TabbedPane.unselectedTabForeground");
|
||||
unselectedTabShadow = UIManager.getColor("TabbedPane.unselectedTabShadow");
|
||||
unselectedTabHighlight = UIManager.getColor("TabbedPane.unselectedTabHighlight");
|
||||
}
|
||||
|
||||
protected void uninstallDefaults() {
|
||||
super.uninstallDefaults();
|
||||
|
||||
unselectedTabBackground = null;
|
||||
unselectedTabForeground = null;
|
||||
unselectedTabShadow = null;
|
||||
unselectedTabHighlight = null;
|
||||
}
|
||||
|
||||
// UI Rendering
|
||||
|
||||
protected void paintContentBorderTopEdge(Graphics g, int tabPlacement,
|
||||
int selectedIndex,
|
||||
int x, int y, int w, int h) {
|
||||
Rectangle selRect = selectedIndex < 0? null :
|
||||
getTabBounds(selectedIndex, calcRect);
|
||||
g.setColor(lightHighlight);
|
||||
|
||||
// Draw unbroken line if tabs are not on TOP, OR
|
||||
// selected tab is not visible (SCROLL_TAB_LAYOUT)
|
||||
//
|
||||
if (tabPlacement != TOP || selectedIndex < 0 ||
|
||||
(selRect.x < x || selRect.x > x + w)) {
|
||||
g.drawLine(x, y, x+w-2, y);
|
||||
} else {
|
||||
// Break line to show visual connection to selected tab
|
||||
g.drawLine(x, y, selRect.x - 1, y);
|
||||
if (selRect.x + selRect.width < x + w - 2) {
|
||||
g.drawLine(selRect.x + selRect.width, y,
|
||||
x+w-2, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement,
|
||||
int selectedIndex,
|
||||
int x, int y, int w, int h) {
|
||||
Rectangle selRect = selectedIndex < 0? null :
|
||||
getTabBounds(selectedIndex, calcRect);
|
||||
g.setColor(shadow);
|
||||
|
||||
// Draw unbroken line if tabs are not on BOTTOM, OR
|
||||
// selected tab is not visible (SCROLL_TAB_LAYOUT)
|
||||
//
|
||||
if (tabPlacement != BOTTOM || selectedIndex < 0 ||
|
||||
(selRect.x < x || selRect.x > x + w)) {
|
||||
g.drawLine(x+1, y+h-1, x+w-1, y+h-1);
|
||||
} else {
|
||||
// Break line to show visual connection to selected tab
|
||||
g.drawLine(x+1, y+h-1, selRect.x - 1, y+h-1);
|
||||
if (selRect.x + selRect.width < x + w - 2) {
|
||||
g.drawLine(selRect.x + selRect.width, y+h-1, x+w-2, y+h-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void paintContentBorderRightEdge(Graphics g, int tabPlacement,
|
||||
int selectedIndex,
|
||||
int x, int y, int w, int h) {
|
||||
Rectangle selRect = selectedIndex < 0? null :
|
||||
getTabBounds(selectedIndex, calcRect);
|
||||
g.setColor(shadow);
|
||||
// Draw unbroken line if tabs are not on RIGHT, OR
|
||||
// selected tab is not visible (SCROLL_TAB_LAYOUT)
|
||||
//
|
||||
if (tabPlacement != RIGHT || selectedIndex < 0 ||
|
||||
(selRect.y < y || selRect.y > y + h)) {
|
||||
g.drawLine(x+w-1, y+1, x+w-1, y+h-1);
|
||||
} else {
|
||||
// Break line to show visual connection to selected tab
|
||||
g.drawLine(x+w-1, y+1, x+w-1, selRect.y - 1);
|
||||
if (selRect.y + selRect.height < y + h - 2 ) {
|
||||
g.drawLine(x+w-1, selRect.y + selRect.height,
|
||||
x+w-1, y+h-2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void paintTabBackground(Graphics g,
|
||||
int tabPlacement, int tabIndex,
|
||||
int x, int y, int w, int h,
|
||||
boolean isSelected ) {
|
||||
g.setColor(isSelected? tabPane.getBackgroundAt(tabIndex) : unselectedTabBackground);
|
||||
switch(tabPlacement) {
|
||||
case LEFT:
|
||||
g.fillRect(x+1, y+1, w-1, h-2);
|
||||
break;
|
||||
case RIGHT:
|
||||
g.fillRect(x, y+1, w-1, h-2);
|
||||
break;
|
||||
case BOTTOM:
|
||||
g.fillRect(x+1, y, w-2, h-3);
|
||||
g.drawLine(x+2, y+h-3, x+w-3, y+h-3);
|
||||
g.drawLine(x+3, y+h-2, x+w-4, y+h-2);
|
||||
break;
|
||||
case TOP:
|
||||
default:
|
||||
g.fillRect(x+1, y+3, w-2, h-3);
|
||||
g.drawLine(x+2, y+2, x+w-3, y+2);
|
||||
g.drawLine(x+3, y+1, x+w-4, y+1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void paintTabBorder(Graphics g,
|
||||
int tabPlacement, int tabIndex,
|
||||
int x, int y, int w, int h,
|
||||
boolean isSelected) {
|
||||
g.setColor(isSelected? lightHighlight : unselectedTabHighlight);
|
||||
|
||||
switch(tabPlacement) {
|
||||
case LEFT:
|
||||
g.drawLine(x, y+2, x, y+h-3);
|
||||
g.drawLine(x+1, y+1, x+1, y+2);
|
||||
g.drawLine(x+2, y, x+2, y+1);
|
||||
g.drawLine(x+3, y, x+w-1, y);
|
||||
g.setColor(isSelected? shadow : unselectedTabShadow);
|
||||
g.drawLine(x+1, y+h-3, x+1, y+h-2);
|
||||
g.drawLine(x+2, y+h-2, x+2, y+h-1);
|
||||
g.drawLine(x+3, y+h-1, x+w-1, y+h-1);
|
||||
break;
|
||||
case RIGHT:
|
||||
g.drawLine(x, y, x+w-3, y);
|
||||
g.setColor(isSelected? shadow : unselectedTabShadow);
|
||||
g.drawLine(x+w-3, y, x+w-3, y+1);
|
||||
g.drawLine(x+w-2, y+1, x+w-2, y+2);
|
||||
g.drawLine(x+w-1, y+2, x+w-1, y+h-3);
|
||||
g.drawLine(x+w-2, y+h-3, x+w-2, y+h-2);
|
||||
g.drawLine(x+w-3, y+h-2, x+w-3, y+h-1);
|
||||
g.drawLine(x, y+h-1, x+w-3, y+h-1);
|
||||
break;
|
||||
case BOTTOM:
|
||||
g.drawLine(x, y, x, y+h-3);
|
||||
g.drawLine(x+1, y+h-3, x+1, y+h-2);
|
||||
g.drawLine(x+2, y+h-2, x+2, y+h-1);
|
||||
g.setColor(isSelected? shadow : unselectedTabShadow);
|
||||
g.drawLine(x+3, y+h-1, x+w-4, y+h-1);
|
||||
g.drawLine(x+w-3, y+h-2, x+w-3, y+h-1);
|
||||
g.drawLine(x+w-2, y+h-3, x+w-2, y+h-2);
|
||||
g.drawLine(x+w-1, y, x+w-1, y+h-3);
|
||||
break;
|
||||
case TOP:
|
||||
default:
|
||||
g.drawLine(x, y+2, x, y+h-1);
|
||||
g.drawLine(x+1, y+1, x+1, y+2);
|
||||
g.drawLine(x+2, y, x+2, y+1);
|
||||
g.drawLine(x+3, y, x+w-4, y);
|
||||
g.setColor(isSelected? shadow : unselectedTabShadow);
|
||||
g.drawLine(x+w-3, y, x+w-3, y+1);
|
||||
g.drawLine(x+w-2, y+1, x+w-2, y+2);
|
||||
g.drawLine(x+w-1, y+2, x+w-1, y+h-1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void paintFocusIndicator(Graphics g, int tabPlacement,
|
||||
Rectangle[] rects, int tabIndex,
|
||||
Rectangle iconRect, Rectangle textRect,
|
||||
boolean isSelected) {
|
||||
Rectangle tabRect = rects[tabIndex];
|
||||
if (tabPane.hasFocus() && isSelected) {
|
||||
int x, y, w, h;
|
||||
g.setColor(focus);
|
||||
switch(tabPlacement) {
|
||||
case LEFT:
|
||||
x = tabRect.x + 3;
|
||||
y = tabRect.y + 3;
|
||||
w = tabRect.width - 6;
|
||||
h = tabRect.height - 7;
|
||||
break;
|
||||
case RIGHT:
|
||||
x = tabRect.x + 2;
|
||||
y = tabRect.y + 3;
|
||||
w = tabRect.width - 6;
|
||||
h = tabRect.height - 7;
|
||||
break;
|
||||
case BOTTOM:
|
||||
x = tabRect.x + 3;
|
||||
y = tabRect.y + 2;
|
||||
w = tabRect.width - 7;
|
||||
h = tabRect.height - 6;
|
||||
break;
|
||||
case TOP:
|
||||
default:
|
||||
x = tabRect.x + 3;
|
||||
y = tabRect.y + 3;
|
||||
w = tabRect.width - 7;
|
||||
h = tabRect.height - 6;
|
||||
}
|
||||
g.drawRect(x, y, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
protected int getTabRunIndent(int tabPlacement, int run) {
|
||||
return run*3;
|
||||
}
|
||||
|
||||
protected int getTabRunOverlay(int tabPlacement) {
|
||||
tabRunOverlay = (tabPlacement == LEFT || tabPlacement == RIGHT)?
|
||||
(int)Math.round((float)maxTabWidth * .10) :
|
||||
(int)Math.round((float)maxTabHeight * .22);
|
||||
|
||||
// Ensure that runover lay is not more than insets
|
||||
// 2 pixel offset is set from insets to each run
|
||||
switch(tabPlacement) {
|
||||
case LEFT:
|
||||
if( tabRunOverlay > tabInsets.right - 2 )
|
||||
tabRunOverlay = tabInsets.right - 2 ;
|
||||
break;
|
||||
case RIGHT:
|
||||
if( tabRunOverlay > tabInsets.left - 2 )
|
||||
tabRunOverlay = tabInsets.left - 2 ;
|
||||
break;
|
||||
case TOP:
|
||||
if( tabRunOverlay > tabInsets.bottom - 2 )
|
||||
tabRunOverlay = tabInsets.bottom - 2 ;
|
||||
break;
|
||||
case BOTTOM:
|
||||
if( tabRunOverlay > tabInsets.top - 2 )
|
||||
tabRunOverlay = tabInsets.top - 2 ;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return tabRunOverlay;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.BasicTextAreaUI;
|
||||
|
||||
/**
|
||||
* Provides the look and feel for a plain text editor. In this
|
||||
* implementation the default UI is extended to act as a simple
|
||||
* view factory.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Timothy Prinzing
|
||||
*/
|
||||
public class MotifTextAreaUI extends BasicTextAreaUI {
|
||||
|
||||
/**
|
||||
* Creates a UI for a JTextArea.
|
||||
*
|
||||
* @param ta a text area
|
||||
* @return the UI
|
||||
*/
|
||||
public static ComponentUI createUI(JComponent ta) {
|
||||
return new MotifTextAreaUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the object to use for a caret. By default an
|
||||
* instance of MotifTextUI.MotifCaret is created. This method
|
||||
* can be redefined to provide something else that implements
|
||||
* the Caret interface.
|
||||
*
|
||||
* @return the caret object
|
||||
*/
|
||||
protected Caret createCaret() {
|
||||
return MotifTextUI.createCaret();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.basic.BasicTextFieldUI;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.text.Caret;
|
||||
|
||||
/**
|
||||
* Provides the Motif look and feel for a text field.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Timothy Prinzing
|
||||
*/
|
||||
public class MotifTextFieldUI extends BasicTextFieldUI {
|
||||
|
||||
/**
|
||||
* Creates a UI for a JTextField.
|
||||
*
|
||||
* @param c the text field
|
||||
* @return the UI
|
||||
*/
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new MotifTextFieldUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the object to use for a caret. By default an
|
||||
* instance of MotifTextUI.MotifCaret is created. This method
|
||||
* can be redefined to provide something else that implements
|
||||
* the Caret interface.
|
||||
*
|
||||
* @return the caret object
|
||||
*/
|
||||
protected Caret createCaret() {
|
||||
return MotifTextUI.createCaret();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.BasicTextPaneUI;
|
||||
|
||||
/**
|
||||
* Provides the look and feel for a styled text editor.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Timothy Prinzing
|
||||
*/
|
||||
public class MotifTextPaneUI extends BasicTextPaneUI {
|
||||
|
||||
/**
|
||||
* Creates a UI for the JTextPane.
|
||||
*
|
||||
* @param c the JTextPane object
|
||||
* @return the UI
|
||||
*/
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new MotifTextPaneUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the object to use for a caret. By default an
|
||||
* instance of MotifTextUI.MotifCaret is created. This method
|
||||
* can be redefined to provide something else that implements
|
||||
* the Caret interface.
|
||||
*
|
||||
* @return the caret object
|
||||
*/
|
||||
protected Caret createCaret() {
|
||||
return MotifTextUI.createCaret();
|
||||
}
|
||||
|
||||
}
|
||||
175
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifTextUI.java
Normal file
175
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifTextUI.java
Normal file
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.*;
|
||||
import javax.swing.plaf.*;
|
||||
|
||||
/**
|
||||
* Provides the look and feel features that are common across
|
||||
* the Motif/CDE text LAF implementations.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Timothy Prinzing
|
||||
*/
|
||||
public class MotifTextUI {
|
||||
|
||||
/**
|
||||
* Creates the object to use for a caret for all of the Motif
|
||||
* text components. The caret is rendered as an I-beam on Motif.
|
||||
*
|
||||
* @return the caret object
|
||||
*/
|
||||
public static Caret createCaret() {
|
||||
return new MotifCaret();
|
||||
}
|
||||
|
||||
/**
|
||||
* The motif caret is rendered as an I beam.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*/
|
||||
public static class MotifCaret extends DefaultCaret implements UIResource {
|
||||
|
||||
/**
|
||||
* Called when the component containing the caret gains
|
||||
* focus. This is implemented to repaint the component
|
||||
* so the focus rectangle will be re-rendered, as well
|
||||
* as providing the superclass behavior.
|
||||
*
|
||||
* @param e the focus event
|
||||
* @see FocusListener#focusGained
|
||||
*/
|
||||
public void focusGained(FocusEvent e) {
|
||||
super.focusGained(e);
|
||||
getComponent().repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the component containing the caret loses
|
||||
* focus. This is implemented to set the caret to visibility
|
||||
* to false.
|
||||
*
|
||||
* @param e the focus event
|
||||
* @see FocusListener#focusLost
|
||||
*/
|
||||
public void focusLost(FocusEvent e) {
|
||||
super.focusLost(e);
|
||||
getComponent().repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Damages the area surrounding the caret to cause
|
||||
* it to be repainted. If paint() is reimplemented,
|
||||
* this method should also be reimplemented.
|
||||
*
|
||||
* @param r the current location of the caret, does nothing if null
|
||||
* @see #paint
|
||||
*/
|
||||
protected void damage(Rectangle r) {
|
||||
if (r != null) {
|
||||
x = r.x - IBeamOverhang - 1;
|
||||
y = r.y;
|
||||
width = r.width + (2 * IBeamOverhang) + 3;
|
||||
height = r.height;
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the caret as a vertical line. If this is reimplemented
|
||||
* the damage method should also be reimplemented as it assumes the
|
||||
* shape of the caret is a vertical line. Does nothing if isVisible()
|
||||
* is false. The caret color is derived from getCaretColor() if
|
||||
* the component has focus, else from getDisabledTextColor().
|
||||
*
|
||||
* @param g the graphics context
|
||||
* @see #damage
|
||||
*/
|
||||
public void paint(Graphics g) {
|
||||
if(isVisible()) {
|
||||
try {
|
||||
JTextComponent c = getComponent();
|
||||
Color fg = c.hasFocus() ? c.getCaretColor() :
|
||||
c.getDisabledTextColor();
|
||||
TextUI mapper = c.getUI();
|
||||
int dot = getDot();
|
||||
Rectangle r = mapper.modelToView(c, dot);
|
||||
int x0 = r.x - IBeamOverhang;
|
||||
int x1 = r.x + IBeamOverhang;
|
||||
int y0 = r.y + 1;
|
||||
int y1 = r.y + r.height - 2;
|
||||
g.setColor(fg);
|
||||
g.drawLine(r.x, y0, r.x, y1);
|
||||
g.drawLine(x0, y0, x1, y0);
|
||||
g.drawLine(x0, y1, x1, y1);
|
||||
} catch (BadLocationException e) {
|
||||
// can't render I guess
|
||||
//System.err.println("Can't render caret");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static final int IBeamOverhang = 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default bindings all keymaps implementing the Motif feel.
|
||||
*/
|
||||
static final JTextComponent.KeyBinding[] defaultBindings = {
|
||||
new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT,
|
||||
InputEvent.CTRL_MASK),
|
||||
DefaultEditorKit.copyAction),
|
||||
new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT,
|
||||
InputEvent.SHIFT_MASK),
|
||||
DefaultEditorKit.pasteAction),
|
||||
new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,
|
||||
InputEvent.SHIFT_MASK),
|
||||
DefaultEditorKit.cutAction),
|
||||
new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT,
|
||||
InputEvent.SHIFT_MASK),
|
||||
DefaultEditorKit.selectionBackwardAction),
|
||||
new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,
|
||||
InputEvent.SHIFT_MASK),
|
||||
DefaultEditorKit.selectionForwardAction),
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import sun.awt.AppContext;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
|
||||
|
||||
/**
|
||||
* BasicToggleButton 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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Rich Schiavi
|
||||
*/
|
||||
public class MotifToggleButtonUI extends BasicToggleButtonUI
|
||||
{
|
||||
private static final Object MOTIF_TOGGLE_BUTTON_UI_KEY = new Object();
|
||||
|
||||
protected Color selectColor;
|
||||
|
||||
private boolean defaults_initialized = false;
|
||||
|
||||
// ********************************
|
||||
// Create PLAF
|
||||
// ********************************
|
||||
public static ComponentUI createUI(JComponent b) {
|
||||
AppContext appContext = AppContext.getAppContext();
|
||||
MotifToggleButtonUI motifToggleButtonUI =
|
||||
(MotifToggleButtonUI) appContext.get(MOTIF_TOGGLE_BUTTON_UI_KEY);
|
||||
if (motifToggleButtonUI == null) {
|
||||
motifToggleButtonUI = new MotifToggleButtonUI();
|
||||
appContext.put(MOTIF_TOGGLE_BUTTON_UI_KEY, motifToggleButtonUI);
|
||||
}
|
||||
return motifToggleButtonUI;
|
||||
}
|
||||
|
||||
// ********************************
|
||||
// Install Defaults
|
||||
// ********************************
|
||||
public void installDefaults(AbstractButton b) {
|
||||
super.installDefaults(b);
|
||||
if(!defaults_initialized) {
|
||||
selectColor = UIManager.getColor(getPropertyPrefix() + "select");
|
||||
defaults_initialized = true;
|
||||
}
|
||||
LookAndFeel.installProperty(b, "opaque", Boolean.FALSE);
|
||||
}
|
||||
|
||||
protected void uninstallDefaults(AbstractButton b) {
|
||||
super.uninstallDefaults(b);
|
||||
defaults_initialized = false;
|
||||
}
|
||||
|
||||
// ********************************
|
||||
// Default Accessors
|
||||
// ********************************
|
||||
|
||||
protected Color getSelectColor() {
|
||||
return selectColor;
|
||||
}
|
||||
|
||||
// ********************************
|
||||
// Paint Methods
|
||||
// ********************************
|
||||
protected void paintButtonPressed(Graphics g, AbstractButton b) {
|
||||
if (b.isContentAreaFilled()) {
|
||||
Color oldColor = g.getColor();
|
||||
Dimension size = b.getSize();
|
||||
Insets insets = b.getInsets();
|
||||
Insets margin = b.getMargin();
|
||||
|
||||
if(b.getBackground() instanceof UIResource) {
|
||||
g.setColor(getSelectColor());
|
||||
}
|
||||
g.fillRect(insets.left - margin.left,
|
||||
insets.top - margin.top,
|
||||
size.width - (insets.left-margin.left) - (insets.right - margin.right),
|
||||
size.height - (insets.top-margin.top) - (insets.bottom - margin.bottom));
|
||||
g.setColor(oldColor);
|
||||
}
|
||||
}
|
||||
|
||||
public Insets getInsets(JComponent c) {
|
||||
Border border = c.getBorder();
|
||||
Insets i = border != null? border.getBorderInsets(c) : new Insets(0,0,0,0);
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1999, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.tree.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.beans.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Motif rendered to display a tree cell.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Jeff Dinkins
|
||||
*/
|
||||
public class MotifTreeCellRenderer extends DefaultTreeCellRenderer
|
||||
{
|
||||
static final int LEAF_SIZE = 13;
|
||||
static final Icon LEAF_ICON = new IconUIResource(new TreeLeafIcon());
|
||||
|
||||
public MotifTreeCellRenderer() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static Icon loadLeafIcon() {
|
||||
return LEAF_ICON;
|
||||
}
|
||||
|
||||
/**
|
||||
* Icon for a node with no children.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*/
|
||||
public static class TreeLeafIcon implements Icon, Serializable {
|
||||
|
||||
Color bg;
|
||||
Color shadow;
|
||||
Color highlight;
|
||||
|
||||
public TreeLeafIcon() {
|
||||
bg = UIManager.getColor("Tree.iconBackground");
|
||||
shadow = UIManager.getColor("Tree.iconShadow");
|
||||
highlight = UIManager.getColor("Tree.iconHighlight");
|
||||
}
|
||||
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
g.setColor(bg);
|
||||
|
||||
y -= 3;
|
||||
g.fillRect(x + 4, y + 7, 5, 5);
|
||||
|
||||
g.drawLine(x + 6, y + 6, x + 6, y + 6);
|
||||
g.drawLine(x + 3, y + 9, x + 3, y + 9);
|
||||
g.drawLine(x + 6, y + 12, x + 6, y + 12);
|
||||
g.drawLine(x + 9, y + 9, x + 9, y + 9);
|
||||
|
||||
g.setColor(highlight);
|
||||
g.drawLine(x + 2, y + 9, x + 5, y + 6);
|
||||
g.drawLine(x + 3, y + 10, x + 5, y + 12);
|
||||
|
||||
g.setColor(shadow);
|
||||
g.drawLine(x + 6, y + 13, x + 10, y + 9);
|
||||
g.drawLine(x + 9, y + 8, x + 7, y + 6);
|
||||
}
|
||||
|
||||
public int getIconWidth() {
|
||||
return LEAF_SIZE;
|
||||
}
|
||||
|
||||
public int getIconHeight() {
|
||||
return LEAF_SIZE;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
166
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifTreeUI.java
Normal file
166
jdkSrc/jdk8/com/sun/java/swing/plaf/motif/MotifTreeUI.java
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.motif;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.tree.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
|
||||
/**
|
||||
* Motif rendition of the tree component.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Jeff Dinkins
|
||||
*/
|
||||
public class MotifTreeUI extends BasicTreeUI
|
||||
{
|
||||
static final int HALF_SIZE = 7;
|
||||
static final int SIZE = 14;
|
||||
|
||||
/**
|
||||
* creates a UI object to represent a Motif Tree widget
|
||||
*/
|
||||
public MotifTreeUI() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void installUI(JComponent c) {
|
||||
super.installUI(c);
|
||||
}
|
||||
|
||||
// BasicTreeUI overrides
|
||||
|
||||
protected void paintVerticalLine( Graphics g, JComponent c, int x, int top, int bottom )
|
||||
{
|
||||
if (tree.getComponentOrientation().isLeftToRight()) {
|
||||
g.fillRect( x, top, 2, bottom - top + 2 );
|
||||
} else {
|
||||
g.fillRect( x - 1, top, 2, bottom - top + 2 );
|
||||
}
|
||||
}
|
||||
|
||||
protected void paintHorizontalLine( Graphics g, JComponent c, int y, int left, int right )
|
||||
{
|
||||
g.fillRect( left, y, right - left + 1, 2 );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The minus sign button icon.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*/
|
||||
public static class MotifExpandedIcon implements Icon, Serializable {
|
||||
static Color bg;
|
||||
static Color fg;
|
||||
static Color highlight;
|
||||
static Color shadow;
|
||||
|
||||
public MotifExpandedIcon() {
|
||||
bg = UIManager.getColor("Tree.iconBackground");
|
||||
fg = UIManager.getColor("Tree.iconForeground");
|
||||
highlight = UIManager.getColor("Tree.iconHighlight");
|
||||
shadow = UIManager.getColor("Tree.iconShadow");
|
||||
}
|
||||
|
||||
public static Icon createExpandedIcon() {
|
||||
return new MotifExpandedIcon();
|
||||
}
|
||||
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
g.setColor(highlight);
|
||||
g.drawLine(x, y, x+SIZE-1, y);
|
||||
g.drawLine(x, y+1, x, y+SIZE-1);
|
||||
|
||||
g.setColor(shadow);
|
||||
g.drawLine(x+SIZE-1, y+1, x+SIZE-1, y+SIZE-1);
|
||||
g.drawLine(x+1, y+SIZE-1, x+SIZE-1, y+SIZE-1);
|
||||
|
||||
g.setColor(bg);
|
||||
g.fillRect(x+1, y+1, SIZE-2, SIZE-2);
|
||||
|
||||
g.setColor(fg);
|
||||
g.drawLine(x+3, y+HALF_SIZE-1, x+SIZE-4, y+HALF_SIZE-1);
|
||||
g.drawLine(x+3, y+HALF_SIZE, x+SIZE-4, y+HALF_SIZE);
|
||||
}
|
||||
|
||||
public int getIconWidth() { return SIZE; }
|
||||
public int getIconHeight() { return SIZE; }
|
||||
}
|
||||
|
||||
/**
|
||||
* The plus sign button icon.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*/
|
||||
public static class MotifCollapsedIcon extends MotifExpandedIcon {
|
||||
public static Icon createCollapsedIcon() {
|
||||
return new MotifCollapsedIcon();
|
||||
}
|
||||
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
super.paintIcon(c, g, x, y);
|
||||
g.drawLine(x + HALF_SIZE-1, y + 3, x + HALF_SIZE-1, y + (SIZE - 4));
|
||||
g.drawLine(x + HALF_SIZE, y + 3, x + HALF_SIZE, y + (SIZE - 4));
|
||||
}
|
||||
}
|
||||
|
||||
public static ComponentUI createUI(JComponent x) {
|
||||
return new MotifTreeUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default cell renderer that is used to do the
|
||||
* stamping of each node.
|
||||
*/
|
||||
public TreeCellRenderer createDefaultCellRenderer() {
|
||||
return new MotifTreeCellRenderer();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.sun.java.swing.plaf.motif.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public final class motif extends ListResourceBundle {
|
||||
protected final Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "FileChooser.acceptAllFileFilter.textAndMnemonic", "*" },
|
||||
{ "FileChooser.cancelButton.textAndMnemonic", "Cancel" },
|
||||
{ "FileChooser.cancelButtonToolTip.textAndMnemonic", "Abort file chooser dialog." },
|
||||
{ "FileChooser.enterFileNameLabel.textAndMnemonic", "E&nter file name:" },
|
||||
{ "FileChooser.enterFolderNameLabel.textAndMnemonic", "Enter folder name:" },
|
||||
{ "FileChooser.filesLabel.textAndMnemonic", "F&iles" },
|
||||
{ "FileChooser.filterLabel.textAndMnemonic", "Filte&r" },
|
||||
{ "FileChooser.foldersLabel.textAndMnemonic", "Fo&lders" },
|
||||
{ "FileChooser.helpButton.textAndMnemonic", "Help" },
|
||||
{ "FileChooser.helpButtonToolTip.textAndMnemonic", "FileChooser help." },
|
||||
{ "FileChooser.openButton.textAndMnemonic", "OK" },
|
||||
{ "FileChooser.openButtonToolTip.textAndMnemonic", "Open selected file." },
|
||||
{ "FileChooser.openDialogTitle.textAndMnemonic", "Open" },
|
||||
{ "FileChooser.pathLabel.textAndMnemonic", "Enter &path or folder name:" },
|
||||
{ "FileChooser.saveButton.textAndMnemonic", "Save" },
|
||||
{ "FileChooser.saveButtonToolTip.textAndMnemonic", "Save selected file." },
|
||||
{ "FileChooser.saveDialogTitle.textAndMnemonic", "Save" },
|
||||
{ "FileChooser.updateButton.textAndMnemonic", "Update" },
|
||||
{ "FileChooser.updateButtonToolTip.textAndMnemonic", "Update directory listing." },
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.sun.java.swing.plaf.motif.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public final class motif_de extends ListResourceBundle {
|
||||
protected final Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "FileChooser.acceptAllFileFilter.textAndMnemonic", "*" },
|
||||
{ "FileChooser.cancelButton.textAndMnemonic", "Abbrechen" },
|
||||
{ "FileChooser.cancelButtonToolTip.textAndMnemonic", "Dialogfeld f\u00FCr Dateiauswahl schlie\u00DFen." },
|
||||
{ "FileChooser.enterFileNameLabel.textAndMnemonic", "Dateina&me eingeben:" },
|
||||
{ "FileChooser.enterFolderNameLabel.textAndMnemonic", "Ordnernamen eingeben:" },
|
||||
{ "FileChooser.filesLabel.textAndMnemonic", "Date&ien" },
|
||||
{ "FileChooser.filterLabel.textAndMnemonic", "Filte&r" },
|
||||
{ "FileChooser.foldersLabel.textAndMnemonic", "Ord&ner" },
|
||||
{ "FileChooser.helpButton.textAndMnemonic", "Hilfe" },
|
||||
{ "FileChooser.helpButtonToolTip.textAndMnemonic", "FileChooser-Hilfe." },
|
||||
{ "FileChooser.openButton.textAndMnemonic", "OK" },
|
||||
{ "FileChooser.openButtonToolTip.textAndMnemonic", "Ausgew\u00E4hlte Datei \u00F6ffnen." },
|
||||
{ "FileChooser.openDialogTitle.textAndMnemonic", "\u00D6ffnen" },
|
||||
{ "FileChooser.pathLabel.textAndMnemonic", "&Pfad- oder Ordnername eingeben:" },
|
||||
{ "FileChooser.saveButton.textAndMnemonic", "Speichern" },
|
||||
{ "FileChooser.saveButtonToolTip.textAndMnemonic", "Ausgew\u00E4hlte Datei speichern." },
|
||||
{ "FileChooser.saveDialogTitle.textAndMnemonic", "Speichern" },
|
||||
{ "FileChooser.updateButton.textAndMnemonic", "Aktualisieren" },
|
||||
{ "FileChooser.updateButtonToolTip.textAndMnemonic", "Verzeichnisliste aktualisieren." },
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.sun.java.swing.plaf.motif.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public final class motif_es extends ListResourceBundle {
|
||||
protected final Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "FileChooser.acceptAllFileFilter.textAndMnemonic", "*" },
|
||||
{ "FileChooser.cancelButton.textAndMnemonic", "Cancelar" },
|
||||
{ "FileChooser.cancelButtonToolTip.textAndMnemonic", "Abortar cuadro de di\u00E1logo del selector de archivos." },
|
||||
{ "FileChooser.enterFileNameLabel.textAndMnemonic", "I&ntroducir nombre de archivo:" },
|
||||
{ "FileChooser.enterFolderNameLabel.textAndMnemonic", "Introducir nombre de carpeta:" },
|
||||
{ "FileChooser.filesLabel.textAndMnemonic", "Arch&ivos" },
|
||||
{ "FileChooser.filterLabel.textAndMnemonic", "Filt&ro" },
|
||||
{ "FileChooser.foldersLabel.textAndMnemonic", "Carpe&tas" },
|
||||
{ "FileChooser.helpButton.textAndMnemonic", "Ayuda" },
|
||||
{ "FileChooser.helpButtonToolTip.textAndMnemonic", "Ayuda del selector de archivos." },
|
||||
{ "FileChooser.openButton.textAndMnemonic", "Aceptar" },
|
||||
{ "FileChooser.openButtonToolTip.textAndMnemonic", "Abrir archivo seleccionado." },
|
||||
{ "FileChooser.openDialogTitle.textAndMnemonic", "Abrir" },
|
||||
{ "FileChooser.pathLabel.textAndMnemonic", "Introducir nombre de ruta de acceso o car&peta:" },
|
||||
{ "FileChooser.saveButton.textAndMnemonic", "Guardar" },
|
||||
{ "FileChooser.saveButtonToolTip.textAndMnemonic", "Guardar archivo seleccionado." },
|
||||
{ "FileChooser.saveDialogTitle.textAndMnemonic", "Guardar" },
|
||||
{ "FileChooser.updateButton.textAndMnemonic", "Actualizar" },
|
||||
{ "FileChooser.updateButtonToolTip.textAndMnemonic", "Actualizar lista de directorios." },
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.sun.java.swing.plaf.motif.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public final class motif_fr extends ListResourceBundle {
|
||||
protected final Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "FileChooser.acceptAllFileFilter.textAndMnemonic", "*" },
|
||||
{ "FileChooser.cancelButton.textAndMnemonic", "Annuler" },
|
||||
{ "FileChooser.cancelButtonToolTip.textAndMnemonic", "Ferme la bo\u00EEte de dialogue du s\u00E9lecteur de fichiers." },
|
||||
{ "FileChooser.enterFileNameLabel.textAndMnemonic", "E&ntrez le nom du fichier :" },
|
||||
{ "FileChooser.enterFolderNameLabel.textAndMnemonic", "Entrez le nom du dossier :" },
|
||||
{ "FileChooser.filesLabel.textAndMnemonic", "F&ichiers" },
|
||||
{ "FileChooser.filterLabel.textAndMnemonic", "Filt&re" },
|
||||
{ "FileChooser.foldersLabel.textAndMnemonic", "&Dossiers" },
|
||||
{ "FileChooser.helpButton.textAndMnemonic", "Aide" },
|
||||
{ "FileChooser.helpButtonToolTip.textAndMnemonic", "Aide du s\u00E9lecteur de fichiers" },
|
||||
{ "FileChooser.openButton.textAndMnemonic", "OK" },
|
||||
{ "FileChooser.openButtonToolTip.textAndMnemonic", "Ouvre le fichier s\u00E9lectionn\u00E9." },
|
||||
{ "FileChooser.openDialogTitle.textAndMnemonic", "Ouvrir" },
|
||||
{ "FileChooser.pathLabel.textAndMnemonic", "Entrez le c&hemin ou le nom du dossier :" },
|
||||
{ "FileChooser.saveButton.textAndMnemonic", "Enregistrer" },
|
||||
{ "FileChooser.saveButtonToolTip.textAndMnemonic", "Enregistre le fichier s\u00E9lectionn\u00E9." },
|
||||
{ "FileChooser.saveDialogTitle.textAndMnemonic", "Enregistrer" },
|
||||
{ "FileChooser.updateButton.textAndMnemonic", "Mettre \u00E0 jour" },
|
||||
{ "FileChooser.updateButtonToolTip.textAndMnemonic", "Met \u00E0 jour la liste des r\u00E9pertoires." },
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.sun.java.swing.plaf.motif.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public final class motif_it extends ListResourceBundle {
|
||||
protected final Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "FileChooser.acceptAllFileFilter.textAndMnemonic", "*" },
|
||||
{ "FileChooser.cancelButton.textAndMnemonic", "Annulla" },
|
||||
{ "FileChooser.cancelButtonToolTip.textAndMnemonic", "Chiude la finestra di dialogo di selezione file." },
|
||||
{ "FileChooser.enterFileNameLabel.textAndMnemonic", "Immettere il &nome file: " },
|
||||
{ "FileChooser.enterFolderNameLabel.textAndMnemonic", "Nome cartella:" },
|
||||
{ "FileChooser.filesLabel.textAndMnemonic", "F&ile" },
|
||||
{ "FileChooser.filterLabel.textAndMnemonic", "Filt&ro" },
|
||||
{ "FileChooser.foldersLabel.textAndMnemonic", "Car&telle" },
|
||||
{ "FileChooser.helpButton.textAndMnemonic", "?" },
|
||||
{ "FileChooser.helpButtonToolTip.textAndMnemonic", "Guida FileChooser." },
|
||||
{ "FileChooser.openButton.textAndMnemonic", "OK" },
|
||||
{ "FileChooser.openButtonToolTip.textAndMnemonic", "Apre il file selezionato." },
|
||||
{ "FileChooser.openDialogTitle.textAndMnemonic", "Apri" },
|
||||
{ "FileChooser.pathLabel.textAndMnemonic", "&Percorso o nome cartella:" },
|
||||
{ "FileChooser.saveButton.textAndMnemonic", "Salva" },
|
||||
{ "FileChooser.saveButtonToolTip.textAndMnemonic", "Salva il file selezionato." },
|
||||
{ "FileChooser.saveDialogTitle.textAndMnemonic", "Salva" },
|
||||
{ "FileChooser.updateButton.textAndMnemonic", "Aggiorna" },
|
||||
{ "FileChooser.updateButtonToolTip.textAndMnemonic", "Aggiorna lista directory." },
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.sun.java.swing.plaf.motif.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public final class motif_ja extends ListResourceBundle {
|
||||
protected final Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "FileChooser.acceptAllFileFilter.textAndMnemonic", "*" },
|
||||
{ "FileChooser.cancelButton.textAndMnemonic", "\u53D6\u6D88" },
|
||||
{ "FileChooser.cancelButtonToolTip.textAndMnemonic", "\u30D5\u30A1\u30A4\u30EB\u30FB\u30C1\u30E5\u30FC\u30B6\u30FB\u30C0\u30A4\u30A2\u30ED\u30B0\u3092\u7D42\u4E86\u3057\u307E\u3059\u3002" },
|
||||
{ "FileChooser.enterFileNameLabel.textAndMnemonic", "\u30D5\u30A1\u30A4\u30EB\u540D\u3092\u5165\u529B(&N):" },
|
||||
{ "FileChooser.enterFolderNameLabel.textAndMnemonic", "\u30D5\u30A9\u30EB\u30C0\u540D\u3092\u5165\u529B:" },
|
||||
{ "FileChooser.filesLabel.textAndMnemonic", "\u30D5\u30A1\u30A4\u30EB(&I)" },
|
||||
{ "FileChooser.filterLabel.textAndMnemonic", "\u30D5\u30A3\u30EB\u30BF(&R)" },
|
||||
{ "FileChooser.foldersLabel.textAndMnemonic", "\u30D5\u30A9\u30EB\u30C0(&L)" },
|
||||
{ "FileChooser.helpButton.textAndMnemonic", "\u30D8\u30EB\u30D7" },
|
||||
{ "FileChooser.helpButtonToolTip.textAndMnemonic", "FileChooser\u306E\u30D8\u30EB\u30D7\u3067\u3059\u3002" },
|
||||
{ "FileChooser.openButton.textAndMnemonic", "OK" },
|
||||
{ "FileChooser.openButtonToolTip.textAndMnemonic", "\u9078\u629E\u3057\u305F\u30D5\u30A1\u30A4\u30EB\u3092\u958B\u304D\u307E\u3059\u3002" },
|
||||
{ "FileChooser.openDialogTitle.textAndMnemonic", "\u958B\u304F" },
|
||||
{ "FileChooser.pathLabel.textAndMnemonic", "\u30D1\u30B9\u307E\u305F\u306F\u30D5\u30A9\u30EB\u30C0\u540D\u3092\u5165\u529B(&P):" },
|
||||
{ "FileChooser.saveButton.textAndMnemonic", "\u4FDD\u5B58" },
|
||||
{ "FileChooser.saveButtonToolTip.textAndMnemonic", "\u9078\u629E\u3057\u305F\u30D5\u30A1\u30A4\u30EB\u3092\u4FDD\u5B58\u3057\u307E\u3059\u3002" },
|
||||
{ "FileChooser.saveDialogTitle.textAndMnemonic", "\u4FDD\u5B58" },
|
||||
{ "FileChooser.updateButton.textAndMnemonic", "\u66F4\u65B0" },
|
||||
{ "FileChooser.updateButtonToolTip.textAndMnemonic", "\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u306E\u30EA\u30B9\u30C8\u3092\u66F4\u65B0\u3057\u307E\u3059\u3002" },
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.sun.java.swing.plaf.motif.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public final class motif_ko extends ListResourceBundle {
|
||||
protected final Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "FileChooser.acceptAllFileFilter.textAndMnemonic", "*" },
|
||||
{ "FileChooser.cancelButton.textAndMnemonic", "\uCDE8\uC18C" },
|
||||
{ "FileChooser.cancelButtonToolTip.textAndMnemonic", "\uD30C\uC77C \uC120\uD0DD\uAE30 \uB300\uD654\uC0C1\uC790\uB97C \uC911\uB2E8\uD569\uB2C8\uB2E4." },
|
||||
{ "FileChooser.enterFileNameLabel.textAndMnemonic", "\uD30C\uC77C \uC774\uB984 \uC785\uB825(&N):" },
|
||||
{ "FileChooser.enterFolderNameLabel.textAndMnemonic", "\uD3F4\uB354 \uC774\uB984 \uC785\uB825:" },
|
||||
{ "FileChooser.filesLabel.textAndMnemonic", "\uD30C\uC77C(&I)" },
|
||||
{ "FileChooser.filterLabel.textAndMnemonic", "\uD544\uD130(&R)" },
|
||||
{ "FileChooser.foldersLabel.textAndMnemonic", "\uD3F4\uB354(&L)" },
|
||||
{ "FileChooser.helpButton.textAndMnemonic", "\uB3C4\uC6C0\uB9D0" },
|
||||
{ "FileChooser.helpButtonToolTip.textAndMnemonic", "FileChooser \uB3C4\uC6C0\uB9D0\uC785\uB2C8\uB2E4." },
|
||||
{ "FileChooser.openButton.textAndMnemonic", "\uD655\uC778" },
|
||||
{ "FileChooser.openButtonToolTip.textAndMnemonic", "\uC120\uD0DD\uB41C \uD30C\uC77C\uC744 \uC5FD\uB2C8\uB2E4." },
|
||||
{ "FileChooser.openDialogTitle.textAndMnemonic", "\uC5F4\uAE30" },
|
||||
{ "FileChooser.pathLabel.textAndMnemonic", "\uACBD\uB85C \uB610\uB294 \uD3F4\uB354 \uC774\uB984 \uC785\uB825(&P):" },
|
||||
{ "FileChooser.saveButton.textAndMnemonic", "\uC800\uC7A5" },
|
||||
{ "FileChooser.saveButtonToolTip.textAndMnemonic", "\uC120\uD0DD\uB41C \uD30C\uC77C\uC744 \uC800\uC7A5\uD569\uB2C8\uB2E4." },
|
||||
{ "FileChooser.saveDialogTitle.textAndMnemonic", "\uC800\uC7A5" },
|
||||
{ "FileChooser.updateButton.textAndMnemonic", "\uC5C5\uB370\uC774\uD2B8" },
|
||||
{ "FileChooser.updateButtonToolTip.textAndMnemonic", "\uB514\uB809\uD1A0\uB9AC \uBAA9\uB85D\uC744 \uC5C5\uB370\uC774\uD2B8\uD569\uB2C8\uB2E4." },
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.sun.java.swing.plaf.motif.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public final class motif_pt_BR extends ListResourceBundle {
|
||||
protected final Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "FileChooser.acceptAllFileFilter.textAndMnemonic", "*" },
|
||||
{ "FileChooser.cancelButton.textAndMnemonic", "Cancelar" },
|
||||
{ "FileChooser.cancelButtonToolTip.textAndMnemonic", "Abortar caixa de di\u00E1logo do seletor de arquivos." },
|
||||
{ "FileChooser.enterFileNameLabel.textAndMnemonic", "I&nforme o nome do arquivo:" },
|
||||
{ "FileChooser.enterFolderNameLabel.textAndMnemonic", "Informar nome da pasta:" },
|
||||
{ "FileChooser.filesLabel.textAndMnemonic", "Arqu&ivos" },
|
||||
{ "FileChooser.filterLabel.textAndMnemonic", "Filt&ro" },
|
||||
{ "FileChooser.foldersLabel.textAndMnemonic", "Pa&stas" },
|
||||
{ "FileChooser.helpButton.textAndMnemonic", "Ajuda" },
|
||||
{ "FileChooser.helpButtonToolTip.textAndMnemonic", "Ajuda do FileChooser." },
|
||||
{ "FileChooser.openButton.textAndMnemonic", "OK" },
|
||||
{ "FileChooser.openButtonToolTip.textAndMnemonic", "Abrir arquivo selecionado." },
|
||||
{ "FileChooser.openDialogTitle.textAndMnemonic", "Abrir" },
|
||||
{ "FileChooser.pathLabel.textAndMnemonic", "Informar &caminho ou nome da pasta:" },
|
||||
{ "FileChooser.saveButton.textAndMnemonic", "Salvar" },
|
||||
{ "FileChooser.saveButtonToolTip.textAndMnemonic", "Salvar arquivo selecionado." },
|
||||
{ "FileChooser.saveDialogTitle.textAndMnemonic", "Salvar" },
|
||||
{ "FileChooser.updateButton.textAndMnemonic", "Atualizar" },
|
||||
{ "FileChooser.updateButtonToolTip.textAndMnemonic", "Atualizar lista de diret\u00F3rios." },
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.sun.java.swing.plaf.motif.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public final class motif_sv extends ListResourceBundle {
|
||||
protected final Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "FileChooser.acceptAllFileFilter.textAndMnemonic", "*" },
|
||||
{ "FileChooser.cancelButton.textAndMnemonic", "Avbryt" },
|
||||
{ "FileChooser.cancelButtonToolTip.textAndMnemonic", "Avbryt dialogrutan f\u00F6r filval." },
|
||||
{ "FileChooser.enterFileNameLabel.textAndMnemonic", "A&nge filnamn:" },
|
||||
{ "FileChooser.enterFolderNameLabel.textAndMnemonic", "Ange ett mappnamn:" },
|
||||
{ "FileChooser.filesLabel.textAndMnemonic", "F&iler" },
|
||||
{ "FileChooser.filterLabel.textAndMnemonic", "Filte&r" },
|
||||
{ "FileChooser.foldersLabel.textAndMnemonic", "Ma&ppar" },
|
||||
{ "FileChooser.helpButton.textAndMnemonic", "Hj\u00E4lp" },
|
||||
{ "FileChooser.helpButtonToolTip.textAndMnemonic", "Hj\u00E4lp f\u00F6r val av fil." },
|
||||
{ "FileChooser.openButton.textAndMnemonic", "OK" },
|
||||
{ "FileChooser.openButtonToolTip.textAndMnemonic", "\u00D6ppna vald fil." },
|
||||
{ "FileChooser.openDialogTitle.textAndMnemonic", "\u00D6ppna" },
|
||||
{ "FileChooser.pathLabel.textAndMnemonic", "Ange &s\u00F6kv\u00E4g eller mappnamn:" },
|
||||
{ "FileChooser.saveButton.textAndMnemonic", "Spara" },
|
||||
{ "FileChooser.saveButtonToolTip.textAndMnemonic", "Spara vald fil." },
|
||||
{ "FileChooser.saveDialogTitle.textAndMnemonic", "Spara" },
|
||||
{ "FileChooser.updateButton.textAndMnemonic", "Uppdatera" },
|
||||
{ "FileChooser.updateButtonToolTip.textAndMnemonic", "Uppdatera kataloglistan." },
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.sun.java.swing.plaf.motif.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public final class motif_zh_CN extends ListResourceBundle {
|
||||
protected final Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "FileChooser.acceptAllFileFilter.textAndMnemonic", "*" },
|
||||
{ "FileChooser.cancelButton.textAndMnemonic", "\u53D6\u6D88" },
|
||||
{ "FileChooser.cancelButtonToolTip.textAndMnemonic", "\u4E2D\u6B62\u6587\u4EF6\u9009\u62E9\u5668\u5BF9\u8BDD\u6846\u3002" },
|
||||
{ "FileChooser.enterFileNameLabel.textAndMnemonic", "\u8F93\u5165\u6587\u4EF6\u540D(&N):" },
|
||||
{ "FileChooser.enterFolderNameLabel.textAndMnemonic", "\u8F93\u5165\u6587\u4EF6\u5939\u540D:" },
|
||||
{ "FileChooser.filesLabel.textAndMnemonic", "\u6587\u4EF6(&I)" },
|
||||
{ "FileChooser.filterLabel.textAndMnemonic", "\u7B5B\u9009\u5668(&R)" },
|
||||
{ "FileChooser.foldersLabel.textAndMnemonic", "\u6587\u4EF6\u5939(&L)" },
|
||||
{ "FileChooser.helpButton.textAndMnemonic", "\u5E2E\u52A9" },
|
||||
{ "FileChooser.helpButtonToolTip.textAndMnemonic", "FileChooser \u5E2E\u52A9\u3002" },
|
||||
{ "FileChooser.openButton.textAndMnemonic", "\u786E\u5B9A" },
|
||||
{ "FileChooser.openButtonToolTip.textAndMnemonic", "\u6253\u5F00\u6240\u9009\u6587\u4EF6\u3002" },
|
||||
{ "FileChooser.openDialogTitle.textAndMnemonic", "\u6253\u5F00" },
|
||||
{ "FileChooser.pathLabel.textAndMnemonic", "\u8F93\u5165\u8DEF\u5F84\u6216\u6587\u4EF6\u5939\u540D(&P):" },
|
||||
{ "FileChooser.saveButton.textAndMnemonic", "\u4FDD\u5B58" },
|
||||
{ "FileChooser.saveButtonToolTip.textAndMnemonic", "\u4FDD\u5B58\u6240\u9009\u6587\u4EF6\u3002" },
|
||||
{ "FileChooser.saveDialogTitle.textAndMnemonic", "\u4FDD\u5B58" },
|
||||
{ "FileChooser.updateButton.textAndMnemonic", "\u66F4\u65B0" },
|
||||
{ "FileChooser.updateButtonToolTip.textAndMnemonic", "\u66F4\u65B0\u76EE\u5F55\u5217\u8868\u3002" },
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.sun.java.swing.plaf.motif.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public final class motif_zh_HK extends ListResourceBundle {
|
||||
protected final Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "FileChooser.acceptAllFileFilter.textAndMnemonic", "*" },
|
||||
{ "FileChooser.cancelButton.textAndMnemonic", "\u53D6\u6D88" },
|
||||
{ "FileChooser.cancelButtonToolTip.textAndMnemonic", "\u4E2D\u6B62\u6A94\u6848\u9078\u64C7\u5668\u5C0D\u8A71\u65B9\u584A\u3002" },
|
||||
{ "FileChooser.enterFileNameLabel.textAndMnemonic", "\u8F38\u5165\u6A94\u6848\u540D\u7A31(&N):" },
|
||||
{ "FileChooser.enterFolderNameLabel.textAndMnemonic", "\u8F38\u5165\u8CC7\u6599\u593E\u540D\u7A31:" },
|
||||
{ "FileChooser.filesLabel.textAndMnemonic", "\u6A94\u6848(&I)" },
|
||||
{ "FileChooser.filterLabel.textAndMnemonic", "\u7BE9\u9078(&R)" },
|
||||
{ "FileChooser.foldersLabel.textAndMnemonic", "\u8CC7\u6599\u593E(&L)" },
|
||||
{ "FileChooser.helpButton.textAndMnemonic", "\u8AAA\u660E" },
|
||||
{ "FileChooser.helpButtonToolTip.textAndMnemonic", "\u300C\u6A94\u6848\u9078\u64C7\u5668\u300D\u8AAA\u660E\u3002" },
|
||||
{ "FileChooser.openButton.textAndMnemonic", "\u78BA\u5B9A" },
|
||||
{ "FileChooser.openButtonToolTip.textAndMnemonic", "\u958B\u555F\u9078\u53D6\u7684\u6A94\u6848\u3002" },
|
||||
{ "FileChooser.openDialogTitle.textAndMnemonic", "\u958B\u555F" },
|
||||
{ "FileChooser.pathLabel.textAndMnemonic", "\u8F38\u5165\u8DEF\u5F91\u6216\u8CC7\u6599\u593E\u540D\u7A31(&P):" },
|
||||
{ "FileChooser.saveButton.textAndMnemonic", "\u5132\u5B58" },
|
||||
{ "FileChooser.saveButtonToolTip.textAndMnemonic", "\u5132\u5B58\u9078\u53D6\u7684\u6A94\u6848\u3002" },
|
||||
{ "FileChooser.saveDialogTitle.textAndMnemonic", "\u5132\u5B58" },
|
||||
{ "FileChooser.updateButton.textAndMnemonic", "\u66F4\u65B0" },
|
||||
{ "FileChooser.updateButtonToolTip.textAndMnemonic", "\u66F4\u65B0\u76EE\u9304\u6E05\u55AE\u3002" },
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.sun.java.swing.plaf.motif.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public final class motif_zh_TW extends ListResourceBundle {
|
||||
protected final Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "FileChooser.acceptAllFileFilter.textAndMnemonic", "*" },
|
||||
{ "FileChooser.cancelButton.textAndMnemonic", "\u53D6\u6D88" },
|
||||
{ "FileChooser.cancelButtonToolTip.textAndMnemonic", "\u4E2D\u6B62\u6A94\u6848\u9078\u64C7\u5668\u5C0D\u8A71\u65B9\u584A\u3002" },
|
||||
{ "FileChooser.enterFileNameLabel.textAndMnemonic", "\u8F38\u5165\u6A94\u6848\u540D\u7A31(&N):" },
|
||||
{ "FileChooser.enterFolderNameLabel.textAndMnemonic", "\u8F38\u5165\u8CC7\u6599\u593E\u540D\u7A31:" },
|
||||
{ "FileChooser.filesLabel.textAndMnemonic", "\u6A94\u6848(&I)" },
|
||||
{ "FileChooser.filterLabel.textAndMnemonic", "\u7BE9\u9078(&R)" },
|
||||
{ "FileChooser.foldersLabel.textAndMnemonic", "\u8CC7\u6599\u593E(&L)" },
|
||||
{ "FileChooser.helpButton.textAndMnemonic", "\u8AAA\u660E" },
|
||||
{ "FileChooser.helpButtonToolTip.textAndMnemonic", "\u300C\u6A94\u6848\u9078\u64C7\u5668\u300D\u8AAA\u660E\u3002" },
|
||||
{ "FileChooser.openButton.textAndMnemonic", "\u78BA\u5B9A" },
|
||||
{ "FileChooser.openButtonToolTip.textAndMnemonic", "\u958B\u555F\u9078\u53D6\u7684\u6A94\u6848\u3002" },
|
||||
{ "FileChooser.openDialogTitle.textAndMnemonic", "\u958B\u555F" },
|
||||
{ "FileChooser.pathLabel.textAndMnemonic", "\u8F38\u5165\u8DEF\u5F91\u6216\u8CC7\u6599\u593E\u540D\u7A31(&P):" },
|
||||
{ "FileChooser.saveButton.textAndMnemonic", "\u5132\u5B58" },
|
||||
{ "FileChooser.saveButtonToolTip.textAndMnemonic", "\u5132\u5B58\u9078\u53D6\u7684\u6A94\u6848\u3002" },
|
||||
{ "FileChooser.saveDialogTitle.textAndMnemonic", "\u5132\u5B58" },
|
||||
{ "FileChooser.updateButton.textAndMnemonic", "\u66F4\u65B0" },
|
||||
{ "FileChooser.updateButtonToolTip.textAndMnemonic", "\u66F4\u65B0\u76EE\u9304\u6E05\u55AE\u3002" },
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 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 com.sun.java.swing.plaf.nimbus;
|
||||
|
||||
/**
|
||||
* This class is preserved for backward compatibility with JDK 6.
|
||||
*
|
||||
* @deprecated Use {@link javax.swing.plaf.nimbus.AbstractRegionPainter} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractRegionPainter extends javax.swing.plaf.nimbus.AbstractRegionPainter {
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 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 com.sun.java.swing.plaf.nimbus;
|
||||
|
||||
/**
|
||||
* This class is preserved for backward compatibility with JDK 6.
|
||||
*
|
||||
* @deprecated Use {@link javax.swing.plaf.nimbus.NimbusLookAndFeel} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public class NimbusLookAndFeel extends javax.swing.plaf.nimbus.NimbusLookAndFeel {
|
||||
}
|
||||
@@ -0,0 +1,431 @@
|
||||
/*
|
||||
* Copyright (c) 2006, 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import java.security.AccessController;
|
||||
import sun.security.action.GetBooleanAction;
|
||||
|
||||
import java.util.*;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
|
||||
|
||||
import sun.swing.UIClientPropertyKey;
|
||||
import com.sun.java.swing.plaf.windows.TMSchema.State;
|
||||
import static com.sun.java.swing.plaf.windows.TMSchema.State.*;
|
||||
import com.sun.java.swing.plaf.windows.TMSchema.Part;
|
||||
import com.sun.java.swing.plaf.windows.TMSchema.Prop;
|
||||
import com.sun.java.swing.plaf.windows.XPStyle.Skin;
|
||||
|
||||
import sun.awt.AppContext;
|
||||
|
||||
/**
|
||||
* A class to help mimic Vista theme animations. The only kind of
|
||||
* animation it handles for now is 'transition' animation (this seems
|
||||
* to be the only animation which Vista theme can do). This is when
|
||||
* one picture fadein over another one in some period of time.
|
||||
* According to
|
||||
* https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=86852&SiteID=4
|
||||
* The animations are all linear.
|
||||
*
|
||||
* This class has a number of responsibilities.
|
||||
* <ul>
|
||||
* <li> It trigger rapaint for the UI components involved in the animation
|
||||
* <li> It tracks the animation state for every UI component involved in the
|
||||
* animation and paints {@code Skin} in new {@code State} over the
|
||||
* {@code Skin} in last {@code State} using
|
||||
* {@code AlphaComposite.SrcOver.derive(alpha)} where {code alpha}
|
||||
* depends on the state of animation
|
||||
* </ul>
|
||||
*
|
||||
* @author Igor Kushnirskiy
|
||||
*/
|
||||
class AnimationController implements ActionListener, PropertyChangeListener {
|
||||
|
||||
private final static boolean VISTA_ANIMATION_DISABLED =
|
||||
AccessController.doPrivileged(new GetBooleanAction("swing.disablevistaanimation"));
|
||||
|
||||
|
||||
private final static Object ANIMATION_CONTROLLER_KEY =
|
||||
new StringBuilder("ANIMATION_CONTROLLER_KEY");
|
||||
|
||||
private final Map<JComponent, Map<Part, AnimationState>> animationStateMap =
|
||||
new WeakHashMap<JComponent, Map<Part, AnimationState>>();
|
||||
|
||||
//this timer is used to cause repaint on animated components
|
||||
//30 repaints per second should give smooth animation affect
|
||||
private final javax.swing.Timer timer =
|
||||
new javax.swing.Timer(1000/30, this);
|
||||
|
||||
private static synchronized AnimationController getAnimationController() {
|
||||
AppContext appContext = AppContext.getAppContext();
|
||||
Object obj = appContext.get(ANIMATION_CONTROLLER_KEY);
|
||||
if (obj == null) {
|
||||
obj = new AnimationController();
|
||||
appContext.put(ANIMATION_CONTROLLER_KEY, obj);
|
||||
}
|
||||
return (AnimationController) obj;
|
||||
}
|
||||
|
||||
private AnimationController() {
|
||||
timer.setRepeats(true);
|
||||
timer.setCoalesce(true);
|
||||
//we need to dispose the controller on l&f change
|
||||
UIManager.addPropertyChangeListener(this);
|
||||
}
|
||||
|
||||
private static void triggerAnimation(JComponent c,
|
||||
Part part, State newState) {
|
||||
if (c instanceof javax.swing.JTabbedPane
|
||||
|| part == Part.TP_BUTTON) {
|
||||
//idk: we can not handle tabs animation because
|
||||
//the same (component,part) is used to handle all the tabs
|
||||
//and we can not track the states
|
||||
//Vista theme might have transition duration for toolbar buttons
|
||||
//but native application does not seem to animate them
|
||||
return;
|
||||
}
|
||||
AnimationController controller =
|
||||
AnimationController.getAnimationController();
|
||||
State oldState = controller.getState(c, part);
|
||||
if (oldState != newState) {
|
||||
controller.putState(c, part, newState);
|
||||
if (newState == State.DEFAULTED) {
|
||||
// it seems for DEFAULTED button state Vista does animation from
|
||||
// HOT
|
||||
oldState = State.HOT;
|
||||
}
|
||||
if (oldState != null) {
|
||||
long duration;
|
||||
if (newState == State.DEFAULTED) {
|
||||
//Only button might have DEFAULTED state
|
||||
//idk: do not know how to get the value from Vista
|
||||
//one second seems plausible value
|
||||
duration = 1000;
|
||||
} else {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
duration = (xp != null)
|
||||
? xp.getThemeTransitionDuration(
|
||||
c, part,
|
||||
normalizeState(oldState),
|
||||
normalizeState(newState),
|
||||
Prop.TRANSITIONDURATIONS)
|
||||
: 1000;
|
||||
}
|
||||
controller.startAnimation(c, part, oldState, newState, duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for scrollbar up, down, left and right button pictures are
|
||||
// defined by states. It seems that theme has duration defined
|
||||
// only for up button states thus we doing this translation here.
|
||||
private static State normalizeState(State state) {
|
||||
State rv;
|
||||
switch (state) {
|
||||
case DOWNPRESSED:
|
||||
/* falls through */
|
||||
case LEFTPRESSED:
|
||||
/* falls through */
|
||||
case RIGHTPRESSED:
|
||||
rv = UPPRESSED;
|
||||
break;
|
||||
|
||||
case DOWNDISABLED:
|
||||
/* falls through */
|
||||
case LEFTDISABLED:
|
||||
/* falls through */
|
||||
case RIGHTDISABLED:
|
||||
rv = UPDISABLED;
|
||||
break;
|
||||
|
||||
case DOWNHOT:
|
||||
/* falls through */
|
||||
case LEFTHOT:
|
||||
/* falls through */
|
||||
case RIGHTHOT:
|
||||
rv = UPHOT;
|
||||
break;
|
||||
|
||||
case DOWNNORMAL:
|
||||
/* falls through */
|
||||
case LEFTNORMAL:
|
||||
/* falls through */
|
||||
case RIGHTNORMAL:
|
||||
rv = UPNORMAL;
|
||||
break;
|
||||
|
||||
default :
|
||||
rv = state;
|
||||
break;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
private synchronized State getState(JComponent component, Part part) {
|
||||
State rv = null;
|
||||
Object tmpObject =
|
||||
component.getClientProperty(PartUIClientPropertyKey.getKey(part));
|
||||
if (tmpObject instanceof State) {
|
||||
rv = (State) tmpObject;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
private synchronized void putState(JComponent component, Part part,
|
||||
State state) {
|
||||
component.putClientProperty(PartUIClientPropertyKey.getKey(part),
|
||||
state);
|
||||
}
|
||||
|
||||
private synchronized void startAnimation(JComponent component,
|
||||
Part part,
|
||||
State startState,
|
||||
State endState,
|
||||
long millis) {
|
||||
boolean isForwardAndReverse = false;
|
||||
if (endState == State.DEFAULTED) {
|
||||
isForwardAndReverse = true;
|
||||
}
|
||||
Map<Part, AnimationState> map = animationStateMap.get(component);
|
||||
if (millis <= 0) {
|
||||
if (map != null) {
|
||||
map.remove(part);
|
||||
if (map.size() == 0) {
|
||||
animationStateMap.remove(component);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (map == null) {
|
||||
map = new EnumMap<Part, AnimationState>(Part.class);
|
||||
animationStateMap.put(component, map);
|
||||
}
|
||||
map.put(part,
|
||||
new AnimationState(startState, millis, isForwardAndReverse));
|
||||
if (! timer.isRunning()) {
|
||||
timer.start();
|
||||
}
|
||||
}
|
||||
|
||||
static void paintSkin(JComponent component, Skin skin,
|
||||
Graphics g, int dx, int dy, int dw, int dh, State state) {
|
||||
if (VISTA_ANIMATION_DISABLED) {
|
||||
skin.paintSkinRaw(g, dx, dy, dw, dh, state);
|
||||
return;
|
||||
}
|
||||
triggerAnimation(component, skin.part, state);
|
||||
AnimationController controller = getAnimationController();
|
||||
synchronized (controller) {
|
||||
AnimationState animationState = null;
|
||||
Map<Part, AnimationState> map =
|
||||
controller.animationStateMap.get(component);
|
||||
if (map != null) {
|
||||
animationState = map.get(skin.part);
|
||||
}
|
||||
if (animationState != null) {
|
||||
animationState.paintSkin(skin, g, dx, dy, dw, dh, state);
|
||||
} else {
|
||||
skin.paintSkinRaw(g, dx, dy, dw, dh, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void propertyChange(PropertyChangeEvent e) {
|
||||
if ("lookAndFeel" == e.getPropertyName()
|
||||
&& ! (e.getNewValue() instanceof WindowsLookAndFeel) ) {
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void actionPerformed(ActionEvent e) {
|
||||
java.util.List<JComponent> componentsToRemove = null;
|
||||
java.util.List<Part> partsToRemove = null;
|
||||
for (JComponent component : animationStateMap.keySet()) {
|
||||
component.repaint();
|
||||
if (partsToRemove != null) {
|
||||
partsToRemove.clear();
|
||||
}
|
||||
Map<Part, AnimationState> map = animationStateMap.get(component);
|
||||
if (! component.isShowing()
|
||||
|| map == null
|
||||
|| map.size() == 0) {
|
||||
if (componentsToRemove == null) {
|
||||
componentsToRemove = new ArrayList<JComponent>();
|
||||
}
|
||||
componentsToRemove.add(component);
|
||||
continue;
|
||||
}
|
||||
for (Part part : map.keySet()) {
|
||||
if (map.get(part).isDone()) {
|
||||
if (partsToRemove == null) {
|
||||
partsToRemove = new ArrayList<Part>();
|
||||
}
|
||||
partsToRemove.add(part);
|
||||
}
|
||||
}
|
||||
if (partsToRemove != null) {
|
||||
if (partsToRemove.size() == map.size()) {
|
||||
//animation is done for the component
|
||||
if (componentsToRemove == null) {
|
||||
componentsToRemove = new ArrayList<JComponent>();
|
||||
}
|
||||
componentsToRemove.add(component);
|
||||
} else {
|
||||
for (Part part : partsToRemove) {
|
||||
map.remove(part);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (componentsToRemove != null) {
|
||||
for (JComponent component : componentsToRemove) {
|
||||
animationStateMap.remove(component);
|
||||
}
|
||||
}
|
||||
if (animationStateMap.size() == 0) {
|
||||
timer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void dispose() {
|
||||
timer.stop();
|
||||
UIManager.removePropertyChangeListener(this);
|
||||
synchronized (AnimationController.class) {
|
||||
AppContext.getAppContext()
|
||||
.put(ANIMATION_CONTROLLER_KEY, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static class AnimationState {
|
||||
private final State startState;
|
||||
|
||||
//animation duration in nanoseconds
|
||||
private final long duration;
|
||||
|
||||
//animatin start time in nanoseconds
|
||||
private long startTime;
|
||||
|
||||
//direction the alpha value is changing
|
||||
//forward - from 0 to 1
|
||||
//!forward - from 1 to 0
|
||||
private boolean isForward = true;
|
||||
|
||||
//if isForwardAndReverse the animation continually goes
|
||||
//forward and reverse. alpha value is changing from 0 to 1 then
|
||||
//from 1 to 0 and so forth
|
||||
private boolean isForwardAndReverse;
|
||||
|
||||
private float progress;
|
||||
|
||||
AnimationState(final State startState,
|
||||
final long milliseconds,
|
||||
boolean isForwardAndReverse) {
|
||||
assert startState != null && milliseconds > 0;
|
||||
assert SwingUtilities.isEventDispatchThread();
|
||||
|
||||
this.startState = startState;
|
||||
this.duration = milliseconds * 1000000;
|
||||
this.startTime = System.nanoTime();
|
||||
this.isForwardAndReverse = isForwardAndReverse;
|
||||
progress = 0f;
|
||||
}
|
||||
private void updateProgress() {
|
||||
assert SwingUtilities.isEventDispatchThread();
|
||||
|
||||
if (isDone()) {
|
||||
return;
|
||||
}
|
||||
long currentTime = System.nanoTime();
|
||||
|
||||
progress = ((float) (currentTime - startTime))
|
||||
/ duration;
|
||||
progress = Math.max(progress, 0); //in case time was reset
|
||||
if (progress >= 1) {
|
||||
progress = 1;
|
||||
if (isForwardAndReverse) {
|
||||
startTime = currentTime;
|
||||
progress = 0;
|
||||
isForward = ! isForward;
|
||||
}
|
||||
}
|
||||
}
|
||||
void paintSkin(Skin skin, Graphics _g,
|
||||
int dx, int dy, int dw, int dh, State state) {
|
||||
assert SwingUtilities.isEventDispatchThread();
|
||||
|
||||
updateProgress();
|
||||
if (! isDone()) {
|
||||
Graphics2D g = (Graphics2D) _g.create();
|
||||
skin.paintSkinRaw(g, dx, dy, dw, dh, startState);
|
||||
float alpha;
|
||||
if (isForward) {
|
||||
alpha = progress;
|
||||
} else {
|
||||
alpha = 1 - progress;
|
||||
}
|
||||
g.setComposite(AlphaComposite.SrcOver.derive(alpha));
|
||||
skin.paintSkinRaw(g, dx, dy, dw, dh, state);
|
||||
g.dispose();
|
||||
} else {
|
||||
skin.paintSkinRaw(_g, dx, dy, dw, dh, state);
|
||||
}
|
||||
}
|
||||
boolean isDone() {
|
||||
assert SwingUtilities.isEventDispatchThread();
|
||||
|
||||
return progress >= 1;
|
||||
}
|
||||
}
|
||||
|
||||
private static class PartUIClientPropertyKey
|
||||
implements UIClientPropertyKey {
|
||||
|
||||
private static final Map<Part, PartUIClientPropertyKey> map =
|
||||
new EnumMap<Part, PartUIClientPropertyKey>(Part.class);
|
||||
|
||||
static synchronized PartUIClientPropertyKey getKey(Part part) {
|
||||
PartUIClientPropertyKey rv = map.get(part);
|
||||
if (rv == null) {
|
||||
rv = new PartUIClientPropertyKey(part);
|
||||
map.put(part, rv);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
private final Part part;
|
||||
private PartUIClientPropertyKey(Part part) {
|
||||
this.part = part;
|
||||
}
|
||||
public String toString() {
|
||||
return part.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
285
jdkSrc/jdk8/com/sun/java/swing/plaf/windows/DesktopProperty.java
Normal file
285
jdkSrc/jdk8/com/sun/java/swing/plaf/windows/DesktopProperty.java
Normal file
@@ -0,0 +1,285 @@
|
||||
/*
|
||||
* 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import java.awt.*;
|
||||
import java.beans.*;
|
||||
import java.lang.ref.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.*;
|
||||
|
||||
/**
|
||||
* Wrapper for a value from the desktop. The value is lazily looked up, and
|
||||
* can be accessed using the <code>UIManager.ActiveValue</code> method
|
||||
* <code>createValue</code>. If the underlying desktop property changes this
|
||||
* will force the UIs to update all known Frames. You can invoke
|
||||
* <code>invalidate</code> to force the value to be fetched again.
|
||||
*
|
||||
*/
|
||||
// NOTE: Don't rely on this class staying in this location. It is likely
|
||||
// to move to a different package in the future.
|
||||
public class DesktopProperty implements UIDefaults.ActiveValue {
|
||||
/**
|
||||
* Indicates if an updateUI call is pending.
|
||||
*/
|
||||
private static boolean updatePending;
|
||||
|
||||
/**
|
||||
* ReferenceQueue of unreferenced WeakPCLs.
|
||||
*/
|
||||
private static final ReferenceQueue<DesktopProperty> queue = new ReferenceQueue<DesktopProperty>();
|
||||
|
||||
/**
|
||||
* PropertyChangeListener attached to the Toolkit.
|
||||
*/
|
||||
private WeakPCL pcl;
|
||||
/**
|
||||
* Key used to lookup value from desktop.
|
||||
*/
|
||||
private final String key;
|
||||
/**
|
||||
* Value to return.
|
||||
*/
|
||||
private Object value;
|
||||
/**
|
||||
* Fallback value in case we get null from desktop.
|
||||
*/
|
||||
private final Object fallback;
|
||||
|
||||
|
||||
/**
|
||||
* Cleans up any lingering state held by unrefeernced
|
||||
* DesktopProperties.
|
||||
*/
|
||||
static void flushUnreferencedProperties() {
|
||||
WeakPCL pcl;
|
||||
|
||||
while ((pcl = (WeakPCL)queue.poll()) != null) {
|
||||
pcl.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets whether or not an updateUI call is pending.
|
||||
*/
|
||||
private static synchronized void setUpdatePending(boolean update) {
|
||||
updatePending = update;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a UI update is pending.
|
||||
*/
|
||||
private static synchronized boolean isUpdatePending() {
|
||||
return updatePending;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the UIs of all the known Frames.
|
||||
*/
|
||||
private static void updateAllUIs() {
|
||||
// Check if the current UI is WindowsLookAndfeel and flush the XP style map.
|
||||
// Note: Change the package test if this class is moved to a different package.
|
||||
Class uiClass = UIManager.getLookAndFeel().getClass();
|
||||
if (uiClass.getPackage().equals(DesktopProperty.class.getPackage())) {
|
||||
XPStyle.invalidateStyle();
|
||||
}
|
||||
Frame appFrames[] = Frame.getFrames();
|
||||
for (Frame appFrame : appFrames) {
|
||||
updateWindowUI(appFrame);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the UI of the passed in window and all its children.
|
||||
*/
|
||||
private static void updateWindowUI(Window window) {
|
||||
SwingUtilities.updateComponentTreeUI(window);
|
||||
Window ownedWins[] = window.getOwnedWindows();
|
||||
for (Window ownedWin : ownedWins) {
|
||||
updateWindowUI(ownedWin);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a DesktopProperty.
|
||||
*
|
||||
* @param key Key used in looking up desktop value.
|
||||
* @param fallback Value used if desktop property is null.
|
||||
*/
|
||||
public DesktopProperty(String key, Object fallback) {
|
||||
this.key = key;
|
||||
this.fallback = fallback;
|
||||
// The only sure fire way to clear our references is to create a
|
||||
// Thread and wait for a reference to be added to the queue.
|
||||
// Because it is so rare that you will actually change the look
|
||||
// and feel, this stepped is forgoed and a middle ground of
|
||||
// flushing references from the constructor is instead done.
|
||||
// The implication is that once one DesktopProperty is created
|
||||
// there will most likely be n (number of DesktopProperties created
|
||||
// by the LookAndFeel) WeakPCLs around, but this number will not
|
||||
// grow past n.
|
||||
flushUnreferencedProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* UIManager.LazyValue method, returns the value from the desktop
|
||||
* or the fallback value if the desktop value is null.
|
||||
*/
|
||||
public Object createValue(UIDefaults table) {
|
||||
if (value == null) {
|
||||
value = configureValue(getValueFromDesktop());
|
||||
if (value == null) {
|
||||
value = configureValue(getDefaultValue());
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value from the desktop.
|
||||
*/
|
||||
protected Object getValueFromDesktop() {
|
||||
Toolkit toolkit = Toolkit.getDefaultToolkit();
|
||||
|
||||
if (pcl == null) {
|
||||
pcl = new WeakPCL(this, getKey(), UIManager.getLookAndFeel());
|
||||
toolkit.addPropertyChangeListener(getKey(), pcl);
|
||||
}
|
||||
|
||||
return toolkit.getDesktopProperty(getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value to use if the desktop property is null.
|
||||
*/
|
||||
protected Object getDefaultValue() {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidates the current value.
|
||||
*
|
||||
* @param laf the LookAndFeel this DesktopProperty was created with
|
||||
*/
|
||||
public void invalidate(LookAndFeel laf) {
|
||||
invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalides the current value so that the next invocation of
|
||||
* <code>createValue</code> will ask for the property again.
|
||||
*/
|
||||
public void invalidate() {
|
||||
value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that all components in the GUI hierarchy be updated
|
||||
* to reflect dynamic changes in this look&feel. This update occurs
|
||||
* by uninstalling and re-installing the UI objects. Requests are
|
||||
* batched and collapsed into a single update pass because often
|
||||
* many desktop properties will change at once.
|
||||
*/
|
||||
protected void updateUI() {
|
||||
if (!isUpdatePending()) {
|
||||
setUpdatePending(true);
|
||||
Runnable uiUpdater = new Runnable() {
|
||||
public void run() {
|
||||
updateAllUIs();
|
||||
setUpdatePending(false);
|
||||
}
|
||||
};
|
||||
SwingUtilities.invokeLater(uiUpdater);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the value as appropriate for a defaults property in
|
||||
* the UIDefaults table.
|
||||
*/
|
||||
protected Object configureValue(Object value) {
|
||||
if (value != null) {
|
||||
if (value instanceof Color) {
|
||||
return new ColorUIResource((Color)value);
|
||||
}
|
||||
else if (value instanceof Font) {
|
||||
return new FontUIResource((Font)value);
|
||||
}
|
||||
else if (value instanceof UIDefaults.LazyValue) {
|
||||
value = ((UIDefaults.LazyValue)value).createValue(null);
|
||||
}
|
||||
else if (value instanceof UIDefaults.ActiveValue) {
|
||||
value = ((UIDefaults.ActiveValue)value).createValue(null);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key used to lookup the desktop properties value.
|
||||
*/
|
||||
protected String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* As there is typically only one Toolkit, the PropertyChangeListener
|
||||
* is handled via a WeakReference so as not to pin down the
|
||||
* DesktopProperty.
|
||||
*/
|
||||
private static class WeakPCL extends WeakReference<DesktopProperty>
|
||||
implements PropertyChangeListener {
|
||||
private String key;
|
||||
private LookAndFeel laf;
|
||||
|
||||
WeakPCL(DesktopProperty target, String key, LookAndFeel laf) {
|
||||
super(target, queue);
|
||||
this.key = key;
|
||||
this.laf = laf;
|
||||
}
|
||||
|
||||
public void propertyChange(PropertyChangeEvent pce) {
|
||||
DesktopProperty property = get();
|
||||
|
||||
if (property == null || laf != UIManager.getLookAndFeel()) {
|
||||
// The property was GC'ed, we're no longer interested in
|
||||
// PropertyChanges, remove the listener.
|
||||
dispose();
|
||||
}
|
||||
else {
|
||||
property.invalidate(laf);
|
||||
property.updateUI();
|
||||
}
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
Toolkit.getDefaultToolkit().removePropertyChangeListener(key, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
565
jdkSrc/jdk8/com/sun/java/swing/plaf/windows/TMSchema.java
Normal file
565
jdkSrc/jdk8/com/sun/java/swing/plaf/windows/TMSchema.java
Normal file
@@ -0,0 +1,565 @@
|
||||
/*
|
||||
* Copyright (c) 2005, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* <p>These classes are designed to be used while the
|
||||
* corresponding <code>LookAndFeel</code> class has been installed
|
||||
* (<code>UIManager.setLookAndFeel(new <i>XXX</i>LookAndFeel())</code>).
|
||||
* Using them while a different <code>LookAndFeel</code> is installed
|
||||
* may produce unexpected results, including exceptions.
|
||||
* Additionally, changing the <code>LookAndFeel</code>
|
||||
* maintained by the <code>UIManager</code> without updating the
|
||||
* corresponding <code>ComponentUI</code> of any
|
||||
* <code>JComponent</code>s may also produce unexpected results,
|
||||
* such as the wrong colors showing up, and is generally not
|
||||
* encouraged.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.sun.java.swing.plaf.windows;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import sun.awt.windows.ThemeReader;
|
||||
|
||||
/**
|
||||
* Implements Windows Parts and their States and Properties for the Windows Look and Feel.
|
||||
*
|
||||
* See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/userex/topics/partsandstates.asp
|
||||
* See tmschema.h (or vssym32.h & vsstyle.h for MS Vista)
|
||||
*
|
||||
* @author Leif Samuelsson
|
||||
*/
|
||||
class TMSchema {
|
||||
|
||||
/**
|
||||
* An enumeration of the various Windows controls (also known as
|
||||
* components, or top-level parts)
|
||||
*/
|
||||
public static enum Control {
|
||||
BUTTON,
|
||||
COMBOBOX,
|
||||
EDIT,
|
||||
HEADER,
|
||||
LISTBOX,
|
||||
LISTVIEW,
|
||||
MENU,
|
||||
PROGRESS,
|
||||
REBAR,
|
||||
SCROLLBAR,
|
||||
SPIN,
|
||||
TAB,
|
||||
TOOLBAR,
|
||||
TRACKBAR,
|
||||
TREEVIEW,
|
||||
WINDOW
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An enumeration of the Windows compoent parts
|
||||
*/
|
||||
public static enum Part {
|
||||
MENU (Control.MENU, 0), // Special case, not in native
|
||||
MP_BARBACKGROUND (Control.MENU, 7),
|
||||
MP_BARITEM (Control.MENU, 8),
|
||||
MP_POPUPBACKGROUND (Control.MENU, 9),
|
||||
MP_POPUPBORDERS (Control.MENU, 10),
|
||||
MP_POPUPCHECK (Control.MENU, 11),
|
||||
MP_POPUPCHECKBACKGROUND (Control.MENU, 12),
|
||||
MP_POPUPGUTTER (Control.MENU, 13),
|
||||
MP_POPUPITEM (Control.MENU, 14),
|
||||
MP_POPUPSEPARATOR (Control.MENU, 15),
|
||||
MP_POPUPSUBMENU (Control.MENU, 16),
|
||||
|
||||
BP_PUSHBUTTON (Control.BUTTON, 1),
|
||||
BP_RADIOBUTTON(Control.BUTTON, 2),
|
||||
BP_CHECKBOX (Control.BUTTON, 3),
|
||||
BP_GROUPBOX (Control.BUTTON, 4),
|
||||
|
||||
CP_COMBOBOX (Control.COMBOBOX, 0),
|
||||
CP_DROPDOWNBUTTON(Control.COMBOBOX, 1),
|
||||
CP_BACKGROUND (Control.COMBOBOX, 2),
|
||||
CP_TRANSPARENTBACKGROUND (Control.COMBOBOX, 3),
|
||||
CP_BORDER (Control.COMBOBOX, 4),
|
||||
CP_READONLY (Control.COMBOBOX, 5),
|
||||
CP_DROPDOWNBUTTONRIGHT (Control.COMBOBOX, 6),
|
||||
CP_DROPDOWNBUTTONLEFT (Control.COMBOBOX, 7),
|
||||
CP_CUEBANNER (Control.COMBOBOX, 8),
|
||||
|
||||
|
||||
EP_EDIT (Control.EDIT, 0),
|
||||
EP_EDITTEXT(Control.EDIT, 1),
|
||||
|
||||
HP_HEADERITEM(Control.HEADER, 1),
|
||||
HP_HEADERSORTARROW(Control.HEADER, 4),
|
||||
|
||||
LBP_LISTBOX(Control.LISTBOX, 0),
|
||||
|
||||
LVP_LISTVIEW(Control.LISTVIEW, 0),
|
||||
|
||||
PP_PROGRESS (Control.PROGRESS, 0),
|
||||
PP_BAR (Control.PROGRESS, 1),
|
||||
PP_BARVERT (Control.PROGRESS, 2),
|
||||
PP_CHUNK (Control.PROGRESS, 3),
|
||||
PP_CHUNKVERT(Control.PROGRESS, 4),
|
||||
|
||||
RP_GRIPPER (Control.REBAR, 1),
|
||||
RP_GRIPPERVERT(Control.REBAR, 2),
|
||||
|
||||
SBP_SCROLLBAR (Control.SCROLLBAR, 0),
|
||||
SBP_ARROWBTN (Control.SCROLLBAR, 1),
|
||||
SBP_THUMBBTNHORZ (Control.SCROLLBAR, 2),
|
||||
SBP_THUMBBTNVERT (Control.SCROLLBAR, 3),
|
||||
SBP_LOWERTRACKHORZ(Control.SCROLLBAR, 4),
|
||||
SBP_UPPERTRACKHORZ(Control.SCROLLBAR, 5),
|
||||
SBP_LOWERTRACKVERT(Control.SCROLLBAR, 6),
|
||||
SBP_UPPERTRACKVERT(Control.SCROLLBAR, 7),
|
||||
SBP_GRIPPERHORZ (Control.SCROLLBAR, 8),
|
||||
SBP_GRIPPERVERT (Control.SCROLLBAR, 9),
|
||||
SBP_SIZEBOX (Control.SCROLLBAR, 10),
|
||||
|
||||
SPNP_UP (Control.SPIN, 1),
|
||||
SPNP_DOWN(Control.SPIN, 2),
|
||||
|
||||
TABP_TABITEM (Control.TAB, 1),
|
||||
TABP_TABITEMLEFTEDGE (Control.TAB, 2),
|
||||
TABP_TABITEMRIGHTEDGE(Control.TAB, 3),
|
||||
TABP_PANE (Control.TAB, 9),
|
||||
|
||||
TP_TOOLBAR (Control.TOOLBAR, 0),
|
||||
TP_BUTTON (Control.TOOLBAR, 1),
|
||||
TP_SEPARATOR (Control.TOOLBAR, 5),
|
||||
TP_SEPARATORVERT (Control.TOOLBAR, 6),
|
||||
|
||||
TKP_TRACK (Control.TRACKBAR, 1),
|
||||
TKP_TRACKVERT (Control.TRACKBAR, 2),
|
||||
TKP_THUMB (Control.TRACKBAR, 3),
|
||||
TKP_THUMBBOTTOM(Control.TRACKBAR, 4),
|
||||
TKP_THUMBTOP (Control.TRACKBAR, 5),
|
||||
TKP_THUMBVERT (Control.TRACKBAR, 6),
|
||||
TKP_THUMBLEFT (Control.TRACKBAR, 7),
|
||||
TKP_THUMBRIGHT (Control.TRACKBAR, 8),
|
||||
TKP_TICS (Control.TRACKBAR, 9),
|
||||
TKP_TICSVERT (Control.TRACKBAR, 10),
|
||||
|
||||
TVP_TREEVIEW(Control.TREEVIEW, 0),
|
||||
TVP_GLYPH (Control.TREEVIEW, 2),
|
||||
|
||||
WP_WINDOW (Control.WINDOW, 0),
|
||||
WP_CAPTION (Control.WINDOW, 1),
|
||||
WP_MINCAPTION (Control.WINDOW, 3),
|
||||
WP_MAXCAPTION (Control.WINDOW, 5),
|
||||
WP_FRAMELEFT (Control.WINDOW, 7),
|
||||
WP_FRAMERIGHT (Control.WINDOW, 8),
|
||||
WP_FRAMEBOTTOM (Control.WINDOW, 9),
|
||||
WP_SYSBUTTON (Control.WINDOW, 13),
|
||||
WP_MDISYSBUTTON (Control.WINDOW, 14),
|
||||
WP_MINBUTTON (Control.WINDOW, 15),
|
||||
WP_MDIMINBUTTON (Control.WINDOW, 16),
|
||||
WP_MAXBUTTON (Control.WINDOW, 17),
|
||||
WP_CLOSEBUTTON (Control.WINDOW, 18),
|
||||
WP_MDICLOSEBUTTON (Control.WINDOW, 20),
|
||||
WP_RESTOREBUTTON (Control.WINDOW, 21),
|
||||
WP_MDIRESTOREBUTTON(Control.WINDOW, 22);
|
||||
|
||||
private final Control control;
|
||||
private final int value;
|
||||
|
||||
private Part(Control control, int value) {
|
||||
this.control = control;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getControlName(Component component) {
|
||||
String str = "";
|
||||
if (component instanceof JComponent) {
|
||||
JComponent c = (JComponent)component;
|
||||
String subAppName = (String)c.getClientProperty("XPStyle.subAppName");
|
||||
if (subAppName != null) {
|
||||
str = subAppName + "::";
|
||||
}
|
||||
}
|
||||
return str + control.toString();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return control.toString()+"."+name();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An enumeration of the possible component states
|
||||
*/
|
||||
public static enum State {
|
||||
ACTIVE,
|
||||
ASSIST,
|
||||
BITMAP,
|
||||
CHECKED,
|
||||
CHECKEDDISABLED,
|
||||
CHECKEDHOT,
|
||||
CHECKEDNORMAL,
|
||||
CHECKEDPRESSED,
|
||||
CHECKMARKNORMAL,
|
||||
CHECKMARKDISABLED,
|
||||
BULLETNORMAL,
|
||||
BULLETDISABLED,
|
||||
CLOSED,
|
||||
DEFAULTED,
|
||||
DISABLED,
|
||||
DISABLEDHOT,
|
||||
DISABLEDPUSHED,
|
||||
DOWNDISABLED,
|
||||
DOWNHOT,
|
||||
DOWNNORMAL,
|
||||
DOWNPRESSED,
|
||||
FOCUSED,
|
||||
HOT,
|
||||
HOTCHECKED,
|
||||
ICONHOT,
|
||||
ICONNORMAL,
|
||||
ICONPRESSED,
|
||||
ICONSORTEDHOT,
|
||||
ICONSORTEDNORMAL,
|
||||
ICONSORTEDPRESSED,
|
||||
INACTIVE,
|
||||
INACTIVENORMAL, // See note 1
|
||||
INACTIVEHOT, // See note 1
|
||||
INACTIVEPUSHED, // See note 1
|
||||
INACTIVEDISABLED, // See note 1
|
||||
LEFTDISABLED,
|
||||
LEFTHOT,
|
||||
LEFTNORMAL,
|
||||
LEFTPRESSED,
|
||||
MIXEDDISABLED,
|
||||
MIXEDHOT,
|
||||
MIXEDNORMAL,
|
||||
MIXEDPRESSED,
|
||||
NORMAL,
|
||||
PRESSED,
|
||||
OPENED,
|
||||
PUSHED,
|
||||
READONLY,
|
||||
RIGHTDISABLED,
|
||||
RIGHTHOT,
|
||||
RIGHTNORMAL,
|
||||
RIGHTPRESSED,
|
||||
SELECTED,
|
||||
UNCHECKEDDISABLED,
|
||||
UNCHECKEDHOT,
|
||||
UNCHECKEDNORMAL,
|
||||
UNCHECKEDPRESSED,
|
||||
UPDISABLED,
|
||||
UPHOT,
|
||||
UPNORMAL,
|
||||
UPPRESSED,
|
||||
HOVER,
|
||||
UPHOVER,
|
||||
DOWNHOVER,
|
||||
LEFTHOVER,
|
||||
RIGHTHOVER,
|
||||
SORTEDDOWN,
|
||||
SORTEDHOT,
|
||||
SORTEDNORMAL,
|
||||
SORTEDPRESSED,
|
||||
SORTEDUP;
|
||||
|
||||
|
||||
/**
|
||||
* A map of allowed states for each Part
|
||||
*/
|
||||
private static EnumMap<Part, State[]> stateMap;
|
||||
|
||||
private static synchronized void initStates() {
|
||||
stateMap = new EnumMap<Part, State[]>(Part.class);
|
||||
|
||||
stateMap.put(Part.EP_EDITTEXT,
|
||||
new State[] {
|
||||
NORMAL, HOT, SELECTED, DISABLED, FOCUSED, READONLY, ASSIST
|
||||
});
|
||||
|
||||
stateMap.put(Part.BP_PUSHBUTTON,
|
||||
new State[] { NORMAL, HOT, PRESSED, DISABLED, DEFAULTED });
|
||||
|
||||
stateMap.put(Part.BP_RADIOBUTTON,
|
||||
new State[] {
|
||||
UNCHECKEDNORMAL, UNCHECKEDHOT, UNCHECKEDPRESSED, UNCHECKEDDISABLED,
|
||||
CHECKEDNORMAL, CHECKEDHOT, CHECKEDPRESSED, CHECKEDDISABLED
|
||||
});
|
||||
|
||||
stateMap.put(Part.BP_CHECKBOX,
|
||||
new State[] {
|
||||
UNCHECKEDNORMAL, UNCHECKEDHOT, UNCHECKEDPRESSED, UNCHECKEDDISABLED,
|
||||
CHECKEDNORMAL, CHECKEDHOT, CHECKEDPRESSED, CHECKEDDISABLED,
|
||||
MIXEDNORMAL, MIXEDHOT, MIXEDPRESSED, MIXEDDISABLED
|
||||
});
|
||||
|
||||
State[] comboBoxStates = new State[] { NORMAL, HOT, PRESSED, DISABLED };
|
||||
stateMap.put(Part.CP_COMBOBOX, comboBoxStates);
|
||||
stateMap.put(Part.CP_DROPDOWNBUTTON, comboBoxStates);
|
||||
stateMap.put(Part.CP_BACKGROUND, comboBoxStates);
|
||||
stateMap.put(Part.CP_TRANSPARENTBACKGROUND, comboBoxStates);
|
||||
stateMap.put(Part.CP_BORDER, comboBoxStates);
|
||||
stateMap.put(Part.CP_READONLY, comboBoxStates);
|
||||
stateMap.put(Part.CP_DROPDOWNBUTTONRIGHT, comboBoxStates);
|
||||
stateMap.put(Part.CP_DROPDOWNBUTTONLEFT, comboBoxStates);
|
||||
stateMap.put(Part.CP_CUEBANNER, comboBoxStates);
|
||||
|
||||
stateMap.put(Part.HP_HEADERITEM, new State[] { NORMAL, HOT, PRESSED,
|
||||
SORTEDNORMAL, SORTEDHOT, SORTEDPRESSED,
|
||||
ICONNORMAL, ICONHOT, ICONPRESSED,
|
||||
ICONSORTEDNORMAL, ICONSORTEDHOT, ICONSORTEDPRESSED });
|
||||
|
||||
stateMap.put(Part.HP_HEADERSORTARROW,
|
||||
new State[] {SORTEDDOWN, SORTEDUP});
|
||||
|
||||
State[] scrollBarStates = new State[] { NORMAL, HOT, PRESSED, DISABLED, HOVER };
|
||||
stateMap.put(Part.SBP_SCROLLBAR, scrollBarStates);
|
||||
stateMap.put(Part.SBP_THUMBBTNVERT, scrollBarStates);
|
||||
stateMap.put(Part.SBP_THUMBBTNHORZ, scrollBarStates);
|
||||
stateMap.put(Part.SBP_GRIPPERVERT, scrollBarStates);
|
||||
stateMap.put(Part.SBP_GRIPPERHORZ, scrollBarStates);
|
||||
|
||||
stateMap.put(Part.SBP_ARROWBTN,
|
||||
new State[] {
|
||||
UPNORMAL, UPHOT, UPPRESSED, UPDISABLED,
|
||||
DOWNNORMAL, DOWNHOT, DOWNPRESSED, DOWNDISABLED,
|
||||
LEFTNORMAL, LEFTHOT, LEFTPRESSED, LEFTDISABLED,
|
||||
RIGHTNORMAL, RIGHTHOT, RIGHTPRESSED, RIGHTDISABLED,
|
||||
UPHOVER, DOWNHOVER, LEFTHOVER, RIGHTHOVER
|
||||
});
|
||||
|
||||
|
||||
State[] spinnerStates = new State[] { NORMAL, HOT, PRESSED, DISABLED };
|
||||
stateMap.put(Part.SPNP_UP, spinnerStates);
|
||||
stateMap.put(Part.SPNP_DOWN, spinnerStates);
|
||||
|
||||
stateMap.put(Part.TVP_GLYPH, new State[] { CLOSED, OPENED });
|
||||
|
||||
State[] frameButtonStates = new State[] {
|
||||
NORMAL, HOT, PUSHED, DISABLED, // See note 1
|
||||
INACTIVENORMAL, INACTIVEHOT, INACTIVEPUSHED, INACTIVEDISABLED,
|
||||
};
|
||||
// Note 1: The INACTIVE frame button states apply when the frame
|
||||
// is inactive. They are not defined in tmschema.h
|
||||
|
||||
// Fix for 6316538: Vista has five frame button states
|
||||
if (ThemeReader.getInt(Control.WINDOW.toString(),
|
||||
Part.WP_CLOSEBUTTON.getValue(), 1,
|
||||
Prop.IMAGECOUNT.getValue()) == 10) {
|
||||
frameButtonStates = new State[] {
|
||||
NORMAL, HOT, PUSHED, DISABLED, null,
|
||||
INACTIVENORMAL, INACTIVEHOT, INACTIVEPUSHED, INACTIVEDISABLED, null
|
||||
};
|
||||
}
|
||||
|
||||
stateMap.put(Part.WP_MINBUTTON, frameButtonStates);
|
||||
stateMap.put(Part.WP_MAXBUTTON, frameButtonStates);
|
||||
stateMap.put(Part.WP_RESTOREBUTTON, frameButtonStates);
|
||||
stateMap.put(Part.WP_CLOSEBUTTON, frameButtonStates);
|
||||
|
||||
// States for Slider (trackbar)
|
||||
stateMap.put(Part.TKP_TRACK, new State[] { NORMAL });
|
||||
stateMap.put(Part.TKP_TRACKVERT, new State[] { NORMAL });
|
||||
|
||||
State[] sliderThumbStates =
|
||||
new State[] { NORMAL, HOT, PRESSED, FOCUSED, DISABLED };
|
||||
stateMap.put(Part.TKP_THUMB, sliderThumbStates);
|
||||
stateMap.put(Part.TKP_THUMBBOTTOM, sliderThumbStates);
|
||||
stateMap.put(Part.TKP_THUMBTOP, sliderThumbStates);
|
||||
stateMap.put(Part.TKP_THUMBVERT, sliderThumbStates);
|
||||
stateMap.put(Part.TKP_THUMBRIGHT, sliderThumbStates);
|
||||
|
||||
// States for Tabs
|
||||
State[] tabStates = new State[] { NORMAL, HOT, SELECTED, DISABLED, FOCUSED };
|
||||
stateMap.put(Part.TABP_TABITEM, tabStates);
|
||||
stateMap.put(Part.TABP_TABITEMLEFTEDGE, tabStates);
|
||||
stateMap.put(Part.TABP_TABITEMRIGHTEDGE, tabStates);
|
||||
|
||||
|
||||
stateMap.put(Part.TP_BUTTON,
|
||||
new State[] {
|
||||
NORMAL, HOT, PRESSED, DISABLED, CHECKED, HOTCHECKED
|
||||
});
|
||||
|
||||
State[] frameStates = new State[] { ACTIVE, INACTIVE };
|
||||
stateMap.put(Part.WP_WINDOW, frameStates);
|
||||
stateMap.put(Part.WP_FRAMELEFT, frameStates);
|
||||
stateMap.put(Part.WP_FRAMERIGHT, frameStates);
|
||||
stateMap.put(Part.WP_FRAMEBOTTOM, frameStates);
|
||||
|
||||
State[] captionStates = new State[] { ACTIVE, INACTIVE, DISABLED };
|
||||
stateMap.put(Part.WP_CAPTION, captionStates);
|
||||
stateMap.put(Part.WP_MINCAPTION, captionStates);
|
||||
stateMap.put(Part.WP_MAXCAPTION, captionStates);
|
||||
|
||||
stateMap.put(Part.MP_BARBACKGROUND,
|
||||
new State[] { ACTIVE, INACTIVE });
|
||||
stateMap.put(Part.MP_BARITEM,
|
||||
new State[] { NORMAL, HOT, PUSHED,
|
||||
DISABLED, DISABLEDHOT, DISABLEDPUSHED });
|
||||
stateMap.put(Part.MP_POPUPCHECK,
|
||||
new State[] { CHECKMARKNORMAL, CHECKMARKDISABLED,
|
||||
BULLETNORMAL, BULLETDISABLED });
|
||||
stateMap.put(Part.MP_POPUPCHECKBACKGROUND,
|
||||
new State[] { DISABLEDPUSHED, NORMAL, BITMAP });
|
||||
stateMap.put(Part.MP_POPUPITEM,
|
||||
new State[] { NORMAL, HOT, DISABLED, DISABLEDHOT });
|
||||
stateMap.put(Part.MP_POPUPSUBMENU,
|
||||
new State[] { NORMAL, DISABLED });
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static synchronized int getValue(Part part, State state) {
|
||||
if (stateMap == null) {
|
||||
initStates();
|
||||
}
|
||||
|
||||
Enum[] states = stateMap.get(part);
|
||||
if (states != null) {
|
||||
for (int i = 0; i < states.length; i++) {
|
||||
if (state == states[i]) {
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (state == null || state == State.NORMAL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An enumeration of the possible component attributes and the
|
||||
* corresponding value type
|
||||
*/
|
||||
public static enum Prop {
|
||||
COLOR(Color.class, 204),
|
||||
SIZE(Dimension.class, 207),
|
||||
|
||||
FLATMENUS(Boolean.class, 1001),
|
||||
|
||||
BORDERONLY(Boolean.class, 2203), // only draw the border area of the image
|
||||
|
||||
IMAGECOUNT(Integer.class, 2401), // the number of state images in an imagefile
|
||||
BORDERSIZE(Integer.class, 2403), // the size of the border line for bgtype=BorderFill
|
||||
|
||||
PROGRESSCHUNKSIZE(Integer.class, 2411), // size of progress control chunks
|
||||
PROGRESSSPACESIZE(Integer.class, 2412), // size of progress control spaces
|
||||
|
||||
TEXTSHADOWOFFSET(Point.class, 3402), // where char shadows are drawn, relative to orig. chars
|
||||
|
||||
NORMALSIZE(Dimension.class, 3409), // size of dest rect that exactly source
|
||||
|
||||
|
||||
SIZINGMARGINS ( Insets.class, 3601), // margins used for 9-grid sizing
|
||||
CONTENTMARGINS(Insets.class, 3602), // margins that define where content can be placed
|
||||
CAPTIONMARGINS(Insets.class, 3603), // margins that define where caption text can be placed
|
||||
|
||||
BORDERCOLOR(Color.class, 3801), // color of borders for BorderFill
|
||||
FILLCOLOR ( Color.class, 3802), // color of bg fill
|
||||
TEXTCOLOR ( Color.class, 3803), // color text is drawn in
|
||||
|
||||
TEXTSHADOWCOLOR(Color.class, 3818), // color of text shadow
|
||||
|
||||
BGTYPE(Integer.class, 4001), // basic drawing type for each part
|
||||
|
||||
TEXTSHADOWTYPE(Integer.class, 4010), // type of shadow to draw with text
|
||||
|
||||
TRANSITIONDURATIONS(Integer.class, 6000);
|
||||
|
||||
private final Class type;
|
||||
private final int value;
|
||||
|
||||
private Prop(Class type, int value) {
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name()+"["+type.getName()+"] = "+value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An enumeration of attribute values for some Props
|
||||
*/
|
||||
public static enum TypeEnum {
|
||||
BT_IMAGEFILE (Prop.BGTYPE, "imagefile", 0),
|
||||
BT_BORDERFILL(Prop.BGTYPE, "borderfill", 1),
|
||||
|
||||
TST_NONE(Prop.TEXTSHADOWTYPE, "none", 0),
|
||||
TST_SINGLE(Prop.TEXTSHADOWTYPE, "single", 1),
|
||||
TST_CONTINUOUS(Prop.TEXTSHADOWTYPE, "continuous", 2);
|
||||
|
||||
|
||||
private TypeEnum(Prop prop, String enumName, int value) {
|
||||
this.prop = prop;
|
||||
this.enumName = enumName;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
private final Prop prop;
|
||||
private final String enumName;
|
||||
private final int value;
|
||||
|
||||
public String toString() {
|
||||
return prop+"="+enumName+"="+value;
|
||||
}
|
||||
|
||||
String getName() {
|
||||
return enumName;
|
||||
}
|
||||
|
||||
|
||||
static TypeEnum getTypeEnum(Prop prop, int enumval) {
|
||||
for (TypeEnum e : TypeEnum.values()) {
|
||||
if (e.prop == prop && e.value == enumval) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
336
jdkSrc/jdk8/com/sun/java/swing/plaf/windows/WindowsBorders.java
Normal file
336
jdkSrc/jdk8/com/sun/java/swing/plaf/windows/WindowsBorders.java
Normal file
@@ -0,0 +1,336 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2010, 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import static com.sun.java.swing.plaf.windows.TMSchema.*;
|
||||
import static com.sun.java.swing.plaf.windows.XPStyle.Skin;
|
||||
|
||||
/**
|
||||
* Factory object that can vend Borders appropriate for the Windows 95 L & F.
|
||||
* @author Rich Schiavi
|
||||
*/
|
||||
|
||||
public class WindowsBorders {
|
||||
|
||||
/**
|
||||
* Returns a border instance for a Windows Progress Bar
|
||||
* @since 1.4
|
||||
*/
|
||||
public static Border getProgressBarBorder() {
|
||||
UIDefaults table = UIManager.getLookAndFeelDefaults();
|
||||
Border progressBarBorder = new BorderUIResource.CompoundBorderUIResource(
|
||||
new WindowsBorders.ProgressBarBorder(
|
||||
table.getColor("ProgressBar.shadow"),
|
||||
table.getColor("ProgressBar.highlight")),
|
||||
new EmptyBorder(1,1,1,1)
|
||||
);
|
||||
return progressBarBorder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a border instance for a Windows ToolBar
|
||||
*
|
||||
* @return a border used for the toolbar
|
||||
* @since 1.4
|
||||
*/
|
||||
public static Border getToolBarBorder() {
|
||||
UIDefaults table = UIManager.getLookAndFeelDefaults();
|
||||
Border toolBarBorder = new WindowsBorders.ToolBarBorder(
|
||||
table.getColor("ToolBar.shadow"),
|
||||
table.getColor("ToolBar.highlight"));
|
||||
return toolBarBorder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an new instance of a border used to indicate which cell item
|
||||
* has focus.
|
||||
*
|
||||
* @return a border to indicate which cell item has focus
|
||||
* @since 1.4
|
||||
*/
|
||||
public static Border getFocusCellHighlightBorder() {
|
||||
return new ComplementDashedBorder();
|
||||
}
|
||||
|
||||
public static Border getTableHeaderBorder() {
|
||||
UIDefaults table = UIManager.getLookAndFeelDefaults();
|
||||
Border tableHeaderBorder = new BorderUIResource.CompoundBorderUIResource(
|
||||
new BasicBorders.ButtonBorder(
|
||||
table.getColor("Table.shadow"),
|
||||
table.getColor("Table.darkShadow"),
|
||||
table.getColor("Table.light"),
|
||||
table.getColor("Table.highlight")),
|
||||
new BasicBorders.MarginBorder());
|
||||
return tableHeaderBorder;
|
||||
}
|
||||
|
||||
public static Border getInternalFrameBorder() {
|
||||
UIDefaults table = UIManager.getLookAndFeelDefaults();
|
||||
Border internalFrameBorder = new
|
||||
BorderUIResource.CompoundBorderUIResource(
|
||||
BorderFactory.createBevelBorder(BevelBorder.RAISED,
|
||||
table.getColor("InternalFrame.borderColor"),
|
||||
table.getColor("InternalFrame.borderHighlight"),
|
||||
table.getColor("InternalFrame.borderDarkShadow"),
|
||||
table.getColor("InternalFrame.borderShadow")),
|
||||
new WindowsBorders.InternalFrameLineBorder(
|
||||
table.getColor("InternalFrame.activeBorderColor"),
|
||||
table.getColor("InternalFrame.inactiveBorderColor"),
|
||||
table.getInt("InternalFrame.borderWidth")));
|
||||
|
||||
return internalFrameBorder;
|
||||
}
|
||||
|
||||
public static class ProgressBarBorder extends AbstractBorder implements UIResource {
|
||||
protected Color shadow;
|
||||
protected Color highlight;
|
||||
|
||||
public ProgressBarBorder(Color shadow, Color highlight) {
|
||||
this.highlight = highlight;
|
||||
this.shadow = shadow;
|
||||
}
|
||||
|
||||
public void paintBorder(Component c, Graphics g, int x, int y,
|
||||
int width, int height) {
|
||||
g.setColor(shadow);
|
||||
g.drawLine(x,y, width-1,y); // draw top
|
||||
g.drawLine(x,y, x,height-1); // draw left
|
||||
g.setColor(highlight);
|
||||
g.drawLine(x,height-1, width-1,height-1); // draw bottom
|
||||
g.drawLine(width-1,y, width-1,height-1); // draw right
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets insets) {
|
||||
insets.set(1,1,1,1);
|
||||
return insets;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A border for the ToolBar. If the ToolBar is floatable then the handle grip is drawn
|
||||
* <p>
|
||||
* @since 1.4
|
||||
*/
|
||||
public static class ToolBarBorder extends AbstractBorder implements UIResource, SwingConstants {
|
||||
protected Color shadow;
|
||||
protected Color highlight;
|
||||
|
||||
public ToolBarBorder(Color shadow, Color highlight) {
|
||||
this.highlight = highlight;
|
||||
this.shadow = shadow;
|
||||
}
|
||||
|
||||
public void paintBorder(Component c, Graphics g, int x, int y,
|
||||
int width, int height) {
|
||||
if (!(c instanceof JToolBar)) {
|
||||
return;
|
||||
}
|
||||
g.translate(x, y);
|
||||
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp != null) {
|
||||
Border xpBorder = xp.getBorder(c, Part.TP_TOOLBAR);
|
||||
if (xpBorder != null) {
|
||||
xpBorder.paintBorder(c, g, 0, 0, width, height);
|
||||
}
|
||||
}
|
||||
if (((JToolBar)c).isFloatable()) {
|
||||
boolean vertical = ((JToolBar)c).getOrientation() == VERTICAL;
|
||||
|
||||
if (xp != null) {
|
||||
Part part = vertical ? Part.RP_GRIPPERVERT : Part.RP_GRIPPER;
|
||||
Skin skin = xp.getSkin(c, part);
|
||||
int dx, dy, dw, dh;
|
||||
if (vertical) {
|
||||
dx = 0;
|
||||
dy = 2;
|
||||
dw = width - 1;
|
||||
dh = skin.getHeight();
|
||||
} else {
|
||||
dw = skin.getWidth();
|
||||
dh = height - 1;
|
||||
dx = c.getComponentOrientation().isLeftToRight() ? 2 : (width-dw-2);
|
||||
dy = 0;
|
||||
}
|
||||
skin.paintSkin(g, dx, dy, dw, dh, State.NORMAL);
|
||||
|
||||
} else {
|
||||
|
||||
if (!vertical) {
|
||||
if (c.getComponentOrientation().isLeftToRight()) {
|
||||
g.setColor(shadow);
|
||||
g.drawLine(4, 3, 4, height - 4);
|
||||
g.drawLine(4, height - 4, 2, height - 4);
|
||||
|
||||
g.setColor(highlight);
|
||||
g.drawLine(2, 3, 3, 3);
|
||||
g.drawLine(2, 3, 2, height - 5);
|
||||
} else {
|
||||
g.setColor(shadow);
|
||||
g.drawLine(width - 3, 3, width - 3, height - 4);
|
||||
g.drawLine(width - 4, height - 4, width - 4, height - 4);
|
||||
|
||||
g.setColor(highlight);
|
||||
g.drawLine(width - 5, 3, width - 4, 3);
|
||||
g.drawLine(width - 5, 3, width - 5, height - 5);
|
||||
}
|
||||
} else { // Vertical
|
||||
g.setColor(shadow);
|
||||
g.drawLine(3, 4, width - 4, 4);
|
||||
g.drawLine(width - 4, 2, width - 4, 4);
|
||||
|
||||
g.setColor(highlight);
|
||||
g.drawLine(3, 2, width - 4, 2);
|
||||
g.drawLine(3, 2, 3, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g.translate(-x, -y);
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets insets) {
|
||||
insets.set(1,1,1,1);
|
||||
if (!(c instanceof JToolBar)) {
|
||||
return insets;
|
||||
}
|
||||
if (((JToolBar)c).isFloatable()) {
|
||||
int gripInset = (XPStyle.getXP() != null) ? 12 : 9;
|
||||
if (((JToolBar)c).getOrientation() == HORIZONTAL) {
|
||||
if (c.getComponentOrientation().isLeftToRight()) {
|
||||
insets.left = gripInset;
|
||||
} else {
|
||||
insets.right = gripInset;
|
||||
}
|
||||
} else {
|
||||
insets.top = gripInset;
|
||||
}
|
||||
}
|
||||
return insets;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class is an implementation of a dashed border.
|
||||
* @since 1.4
|
||||
*/
|
||||
public static class DashedBorder extends LineBorder implements UIResource {
|
||||
public DashedBorder(Color color) {
|
||||
super(color);
|
||||
}
|
||||
|
||||
public DashedBorder(Color color, int thickness) {
|
||||
super(color, thickness);
|
||||
}
|
||||
|
||||
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
|
||||
Color oldColor = g.getColor();
|
||||
int i;
|
||||
|
||||
g.setColor(lineColor);
|
||||
for(i = 0; i < thickness; i++) {
|
||||
BasicGraphicsUtils.drawDashedRect(g, x+i, y+i, width-i-i, height-i-i);
|
||||
}
|
||||
g.setColor(oldColor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A dashed border that paints itself in the complementary color
|
||||
* of the component's background color.
|
||||
*/
|
||||
static class ComplementDashedBorder extends LineBorder implements UIResource {
|
||||
private Color origColor;
|
||||
private Color paintColor;
|
||||
|
||||
public ComplementDashedBorder() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
|
||||
Color color = c.getBackground();
|
||||
|
||||
if (origColor != color) {
|
||||
origColor = color;
|
||||
paintColor = new Color(~origColor.getRGB());
|
||||
}
|
||||
|
||||
g.setColor(paintColor);
|
||||
BasicGraphicsUtils.drawDashedRect(g, x, y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class is an implementation of the InternalFrameLine border.
|
||||
* @since 1.4
|
||||
*/
|
||||
public static class InternalFrameLineBorder extends LineBorder implements
|
||||
UIResource {
|
||||
protected Color activeColor;
|
||||
protected Color inactiveColor;
|
||||
|
||||
public InternalFrameLineBorder(Color activeBorderColor,
|
||||
Color inactiveBorderColor,
|
||||
int thickness) {
|
||||
super(activeBorderColor, thickness);
|
||||
activeColor = activeBorderColor;
|
||||
inactiveColor = inactiveBorderColor;
|
||||
}
|
||||
|
||||
public void paintBorder(Component c, Graphics g, int x, int y,
|
||||
int width, int height) {
|
||||
|
||||
JInternalFrame jif = null;
|
||||
if (c instanceof JInternalFrame) {
|
||||
jif = (JInternalFrame)c;
|
||||
} else if (c instanceof JInternalFrame.JDesktopIcon) {
|
||||
jif = ((JInternalFrame.JDesktopIcon)c).getInternalFrame();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (jif.isSelected()) {
|
||||
// Set the line color so the line border gets the correct
|
||||
// color.
|
||||
lineColor = activeColor;
|
||||
super.paintBorder(c, g, x, y, width, height);
|
||||
} else {
|
||||
lineColor = inactiveColor;
|
||||
super.paintBorder(c, g, x, y, width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
|
||||
/**
|
||||
* Button Listener
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Rich Schiavi
|
||||
*/
|
||||
public class WindowsButtonListener extends BasicButtonListener {
|
||||
public WindowsButtonListener(AbstractButton b) {
|
||||
super(b);
|
||||
}
|
||||
/*
|
||||
This class is currently not used, but exists in case customers
|
||||
were subclassing it.
|
||||
*/
|
||||
}
|
||||
320
jdkSrc/jdk8/com/sun/java/swing/plaf/windows/WindowsButtonUI.java
Normal file
320
jdkSrc/jdk8/com/sun/java/swing/plaf/windows/WindowsButtonUI.java
Normal file
@@ -0,0 +1,320 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import javax.swing.plaf.basic.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.*;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import static com.sun.java.swing.plaf.windows.TMSchema.*;
|
||||
import static com.sun.java.swing.plaf.windows.TMSchema.Part.*;
|
||||
import static com.sun.java.swing.plaf.windows.XPStyle.Skin;
|
||||
import sun.awt.AppContext;
|
||||
|
||||
|
||||
/**
|
||||
* Windows button.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Jeff Dinkins
|
||||
*
|
||||
*/
|
||||
public class WindowsButtonUI extends BasicButtonUI
|
||||
{
|
||||
protected int dashedRectGapX;
|
||||
protected int dashedRectGapY;
|
||||
protected int dashedRectGapWidth;
|
||||
protected int dashedRectGapHeight;
|
||||
|
||||
protected Color focusColor;
|
||||
|
||||
private boolean defaults_initialized = false;
|
||||
|
||||
private static final Object WINDOWS_BUTTON_UI_KEY = new Object();
|
||||
|
||||
// ********************************
|
||||
// Create PLAF
|
||||
// ********************************
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
AppContext appContext = AppContext.getAppContext();
|
||||
WindowsButtonUI windowsButtonUI =
|
||||
(WindowsButtonUI) appContext.get(WINDOWS_BUTTON_UI_KEY);
|
||||
if (windowsButtonUI == null) {
|
||||
windowsButtonUI = new WindowsButtonUI();
|
||||
appContext.put(WINDOWS_BUTTON_UI_KEY, windowsButtonUI);
|
||||
}
|
||||
return windowsButtonUI;
|
||||
}
|
||||
|
||||
|
||||
// ********************************
|
||||
// Defaults
|
||||
// ********************************
|
||||
protected void installDefaults(AbstractButton b) {
|
||||
super.installDefaults(b);
|
||||
if(!defaults_initialized) {
|
||||
String pp = getPropertyPrefix();
|
||||
dashedRectGapX = UIManager.getInt(pp + "dashedRectGapX");
|
||||
dashedRectGapY = UIManager.getInt(pp + "dashedRectGapY");
|
||||
dashedRectGapWidth = UIManager.getInt(pp + "dashedRectGapWidth");
|
||||
dashedRectGapHeight = UIManager.getInt(pp + "dashedRectGapHeight");
|
||||
focusColor = UIManager.getColor(pp + "focus");
|
||||
defaults_initialized = true;
|
||||
}
|
||||
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp != null) {
|
||||
b.setBorder(xp.getBorder(b, getXPButtonType(b)));
|
||||
LookAndFeel.installProperty(b, "rolloverEnabled", Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
protected void uninstallDefaults(AbstractButton b) {
|
||||
super.uninstallDefaults(b);
|
||||
defaults_initialized = false;
|
||||
}
|
||||
|
||||
protected Color getFocusColor() {
|
||||
return focusColor;
|
||||
}
|
||||
|
||||
// ********************************
|
||||
// Paint Methods
|
||||
// ********************************
|
||||
|
||||
/**
|
||||
* Overridden method to render the text without the mnemonic
|
||||
*/
|
||||
protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) {
|
||||
WindowsGraphicsUtils.paintText(g, b, textRect, text, getTextShiftOffset());
|
||||
}
|
||||
|
||||
protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect){
|
||||
|
||||
// focus painted same color as text on Basic??
|
||||
int width = b.getWidth();
|
||||
int height = b.getHeight();
|
||||
g.setColor(getFocusColor());
|
||||
BasicGraphicsUtils.drawDashedRect(g, dashedRectGapX, dashedRectGapY,
|
||||
width - dashedRectGapWidth, height - dashedRectGapHeight);
|
||||
}
|
||||
|
||||
protected void paintButtonPressed(Graphics g, AbstractButton b){
|
||||
setTextShiftOffset();
|
||||
}
|
||||
|
||||
// ********************************
|
||||
// Layout Methods
|
||||
// ********************************
|
||||
public Dimension getPreferredSize(JComponent c) {
|
||||
Dimension d = super.getPreferredSize(c);
|
||||
|
||||
/* Ensure that the width and height of the button is odd,
|
||||
* to allow for the focus line if focus is painted
|
||||
*/
|
||||
AbstractButton b = (AbstractButton)c;
|
||||
if (d != null && b.isFocusPainted()) {
|
||||
if(d.width % 2 == 0) { d.width += 1; }
|
||||
if(d.height % 2 == 0) { d.height += 1; }
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
/* These rectangles/insets are allocated once for all
|
||||
* ButtonUI.paint() calls. Re-using rectangles rather than
|
||||
* allocating them in each paint call substantially reduced the time
|
||||
* it took paint to run. Obviously, this method can't be re-entered.
|
||||
*/
|
||||
private Rectangle viewRect = new Rectangle();
|
||||
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
if (XPStyle.getXP() != null) {
|
||||
WindowsButtonUI.paintXPButtonBackground(g, c);
|
||||
}
|
||||
super.paint(g, c);
|
||||
}
|
||||
|
||||
static Part getXPButtonType(AbstractButton b) {
|
||||
if(b instanceof JCheckBox) {
|
||||
return Part.BP_CHECKBOX;
|
||||
}
|
||||
if(b instanceof JRadioButton) {
|
||||
return Part.BP_RADIOBUTTON;
|
||||
}
|
||||
boolean toolbar = (b.getParent() instanceof JToolBar);
|
||||
return toolbar ? Part.TP_BUTTON : Part.BP_PUSHBUTTON;
|
||||
}
|
||||
|
||||
static State getXPButtonState(AbstractButton b) {
|
||||
Part part = getXPButtonType(b);
|
||||
ButtonModel model = b.getModel();
|
||||
State state = State.NORMAL;
|
||||
switch (part) {
|
||||
case BP_RADIOBUTTON:
|
||||
/* falls through */
|
||||
case BP_CHECKBOX:
|
||||
if (! model.isEnabled()) {
|
||||
state = (model.isSelected()) ? State.CHECKEDDISABLED
|
||||
: State.UNCHECKEDDISABLED;
|
||||
} else if (model.isPressed() && model.isArmed()) {
|
||||
state = (model.isSelected()) ? State.CHECKEDPRESSED
|
||||
: State.UNCHECKEDPRESSED;
|
||||
} else if (model.isRollover()) {
|
||||
state = (model.isSelected()) ? State.CHECKEDHOT
|
||||
: State.UNCHECKEDHOT;
|
||||
} else {
|
||||
state = (model.isSelected()) ? State.CHECKEDNORMAL
|
||||
: State.UNCHECKEDNORMAL;
|
||||
}
|
||||
break;
|
||||
case BP_PUSHBUTTON:
|
||||
/* falls through */
|
||||
case TP_BUTTON:
|
||||
boolean toolbar = (b.getParent() instanceof JToolBar);
|
||||
if (toolbar) {
|
||||
if (model.isArmed() && model.isPressed()) {
|
||||
state = State.PRESSED;
|
||||
} else if (!model.isEnabled()) {
|
||||
state = State.DISABLED;
|
||||
} else if (model.isSelected() && model.isRollover()) {
|
||||
state = State.HOTCHECKED;
|
||||
} else if (model.isSelected()) {
|
||||
state = State.CHECKED;
|
||||
} else if (model.isRollover()) {
|
||||
state = State.HOT;
|
||||
} else if (b.hasFocus()) {
|
||||
state = State.HOT;
|
||||
}
|
||||
} else {
|
||||
if ((model.isArmed() && model.isPressed())
|
||||
|| model.isSelected()) {
|
||||
state = State.PRESSED;
|
||||
} else if (!model.isEnabled()) {
|
||||
state = State.DISABLED;
|
||||
} else if (model.isRollover() || model.isPressed()) {
|
||||
state = State.HOT;
|
||||
} else if (b instanceof JButton
|
||||
&& ((JButton)b).isDefaultButton()) {
|
||||
state = State.DEFAULTED;
|
||||
} else if (b.hasFocus()) {
|
||||
state = State.HOT;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default :
|
||||
state = State.NORMAL;
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
static void paintXPButtonBackground(Graphics g, JComponent c) {
|
||||
AbstractButton b = (AbstractButton)c;
|
||||
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
|
||||
Part part = getXPButtonType(b);
|
||||
|
||||
if (b.isContentAreaFilled() && xp != null) {
|
||||
|
||||
Skin skin = xp.getSkin(b, part);
|
||||
|
||||
State state = getXPButtonState(b);
|
||||
Dimension d = c.getSize();
|
||||
int dx = 0;
|
||||
int dy = 0;
|
||||
int dw = d.width;
|
||||
int dh = d.height;
|
||||
|
||||
Border border = c.getBorder();
|
||||
Insets insets;
|
||||
if (border != null) {
|
||||
// Note: The border may be compound, containing an outer
|
||||
// opaque border (supplied by the application), plus an
|
||||
// inner transparent margin border. We want to size the
|
||||
// background to fill the transparent part, but stay
|
||||
// inside the opaque part.
|
||||
insets = WindowsButtonUI.getOpaqueInsets(border, c);
|
||||
} else {
|
||||
insets = c.getInsets();
|
||||
}
|
||||
if (insets != null) {
|
||||
dx += insets.left;
|
||||
dy += insets.top;
|
||||
dw -= (insets.left + insets.right);
|
||||
dh -= (insets.top + insets.bottom);
|
||||
}
|
||||
skin.paintSkin(g, dx, dy, dw, dh, state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns - b.getBorderInsets(c) if border is opaque
|
||||
* - null if border is completely non-opaque
|
||||
* - somewhere inbetween if border is compound and
|
||||
* outside border is opaque and inside isn't
|
||||
*/
|
||||
private static Insets getOpaqueInsets(Border b, Component c) {
|
||||
if (b == null) {
|
||||
return null;
|
||||
}
|
||||
if (b.isBorderOpaque()) {
|
||||
return b.getBorderInsets(c);
|
||||
} else if (b instanceof CompoundBorder) {
|
||||
CompoundBorder cb = (CompoundBorder)b;
|
||||
Insets iOut = getOpaqueInsets(cb.getOutsideBorder(), c);
|
||||
if (iOut != null && iOut.equals(cb.getOutsideBorder().getBorderInsets(c))) {
|
||||
// Outside border is opaque, keep looking
|
||||
Insets iIn = getOpaqueInsets(cb.getInsideBorder(), c);
|
||||
if (iIn == null) {
|
||||
// Inside is non-opaque, use outside insets
|
||||
return iOut;
|
||||
} else {
|
||||
// Found non-opaque somewhere in the inside (which is
|
||||
// also compound).
|
||||
return new Insets(iOut.top + iIn.top, iOut.left + iIn.left,
|
||||
iOut.bottom + iIn.bottom, iOut.right + iIn.right);
|
||||
}
|
||||
} else {
|
||||
// Outside is either all non-opaque or has non-opaque
|
||||
// border inside another compound border
|
||||
return iOut;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
|
||||
import com.sun.java.swing.plaf.windows.TMSchema.Part;
|
||||
import com.sun.java.swing.plaf.windows.TMSchema.State;
|
||||
|
||||
|
||||
/**
|
||||
* Windows check box menu item.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*/
|
||||
public class WindowsCheckBoxMenuItemUI extends BasicCheckBoxMenuItemUI {
|
||||
|
||||
final WindowsMenuItemUIAccessor accessor =
|
||||
new WindowsMenuItemUIAccessor() {
|
||||
|
||||
public JMenuItem getMenuItem() {
|
||||
return menuItem;
|
||||
}
|
||||
|
||||
public State getState(JMenuItem menuItem) {
|
||||
return WindowsMenuItemUI.getState(this, menuItem);
|
||||
}
|
||||
|
||||
public Part getPart(JMenuItem menuItem) {
|
||||
return WindowsMenuItemUI.getPart(this, menuItem);
|
||||
}
|
||||
};
|
||||
public static ComponentUI createUI(JComponent b) {
|
||||
return new WindowsCheckBoxMenuItemUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintBackground(Graphics g, JMenuItem menuItem,
|
||||
Color bgColor) {
|
||||
if (WindowsMenuItemUI.isVistaPainting()) {
|
||||
WindowsMenuItemUI.paintBackground(accessor, g, menuItem, bgColor);
|
||||
return;
|
||||
}
|
||||
super.paintBackground(g, menuItem, bgColor);
|
||||
}
|
||||
/**
|
||||
* Method which renders the text of the current menu item.
|
||||
* <p>
|
||||
* @param g Graphics context
|
||||
* @param menuItem Current menu item to render
|
||||
* @param textRect Bounding rectangle to render the text.
|
||||
* @param text String to render
|
||||
* @since 1.4
|
||||
*/
|
||||
protected void paintText(Graphics g, JMenuItem menuItem,
|
||||
Rectangle textRect, String text) {
|
||||
if (WindowsMenuItemUI.isVistaPainting()) {
|
||||
WindowsMenuItemUI.paintText(accessor, g, menuItem,
|
||||
textRect, text);
|
||||
return;
|
||||
}
|
||||
ButtonModel model = menuItem.getModel();
|
||||
Color oldColor = g.getColor();
|
||||
|
||||
if(model.isEnabled() && model.isArmed()) {
|
||||
g.setColor(selectionForeground); // Uses protected field.
|
||||
}
|
||||
|
||||
WindowsGraphicsUtils.paintText(g, menuItem, textRect, text, 0);
|
||||
|
||||
g.setColor(oldColor);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import sun.awt.AppContext;
|
||||
|
||||
import javax.swing.plaf.basic.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.*;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Windows check box.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Jeff Dinkins
|
||||
*/
|
||||
public class WindowsCheckBoxUI extends WindowsRadioButtonUI
|
||||
{
|
||||
// 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 WINDOWS_CHECK_BOX_UI_KEY = new Object();
|
||||
|
||||
private final static String propertyPrefix = "CheckBox" + ".";
|
||||
|
||||
private boolean defaults_initialized = false;
|
||||
|
||||
// ********************************
|
||||
// Create PLAF
|
||||
// ********************************
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
AppContext appContext = AppContext.getAppContext();
|
||||
WindowsCheckBoxUI windowsCheckBoxUI =
|
||||
(WindowsCheckBoxUI) appContext.get(WINDOWS_CHECK_BOX_UI_KEY);
|
||||
if (windowsCheckBoxUI == null) {
|
||||
windowsCheckBoxUI = new WindowsCheckBoxUI();
|
||||
appContext.put(WINDOWS_CHECK_BOX_UI_KEY, windowsCheckBoxUI);
|
||||
}
|
||||
return windowsCheckBoxUI;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public void uninstallDefaults(AbstractButton b) {
|
||||
super.uninstallDefaults(b);
|
||||
defaults_initialized = false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
/**
|
||||
* Implements the Windows95/98/ME/NT/2000 Look and Feel.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public class WindowsClassicLookAndFeel extends WindowsLookAndFeel {
|
||||
public String getName() {
|
||||
return "Windows Classic";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,572 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.*;
|
||||
|
||||
import static com.sun.java.swing.plaf.windows.TMSchema.Part;
|
||||
import static com.sun.java.swing.plaf.windows.TMSchema.State;
|
||||
import static com.sun.java.swing.plaf.windows.XPStyle.Skin;
|
||||
|
||||
import sun.swing.DefaultLookup;
|
||||
import sun.swing.StringUIClientPropertyKey;
|
||||
|
||||
|
||||
/**
|
||||
* Windows combo box.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Tom Santos
|
||||
* @author Igor Kushnirskiy
|
||||
*/
|
||||
|
||||
public class WindowsComboBoxUI extends BasicComboBoxUI {
|
||||
|
||||
private static final MouseListener rolloverListener =
|
||||
new MouseAdapter() {
|
||||
private void handleRollover(MouseEvent e, boolean isRollover) {
|
||||
JComboBox comboBox = getComboBox(e);
|
||||
WindowsComboBoxUI comboBoxUI = getWindowsComboBoxUI(e);
|
||||
if (comboBox == null || comboBoxUI == null) {
|
||||
return;
|
||||
}
|
||||
if (! comboBox.isEditable()) {
|
||||
//mouse over editable ComboBox does not switch rollover
|
||||
//for the arrow button
|
||||
ButtonModel m = null;
|
||||
if (comboBoxUI.arrowButton != null) {
|
||||
m = comboBoxUI.arrowButton.getModel();
|
||||
}
|
||||
if (m != null ) {
|
||||
m.setRollover(isRollover);
|
||||
}
|
||||
}
|
||||
comboBoxUI.isRollover = isRollover;
|
||||
comboBox.repaint();
|
||||
}
|
||||
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
handleRollover(e, true);
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent e) {
|
||||
handleRollover(e, false);
|
||||
}
|
||||
|
||||
private JComboBox getComboBox(MouseEvent event) {
|
||||
Object source = event.getSource();
|
||||
JComboBox rv = null;
|
||||
if (source instanceof JComboBox) {
|
||||
rv = (JComboBox) source;
|
||||
} else if (source instanceof XPComboBoxButton) {
|
||||
rv = ((XPComboBoxButton) source)
|
||||
.getWindowsComboBoxUI().comboBox;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
private WindowsComboBoxUI getWindowsComboBoxUI(MouseEvent event) {
|
||||
JComboBox comboBox = getComboBox(event);
|
||||
WindowsComboBoxUI rv = null;
|
||||
if (comboBox != null
|
||||
&& comboBox.getUI() instanceof WindowsComboBoxUI) {
|
||||
rv = (WindowsComboBoxUI) comboBox.getUI();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
};
|
||||
private boolean isRollover = false;
|
||||
|
||||
private static final PropertyChangeListener componentOrientationListener =
|
||||
new PropertyChangeListener() {
|
||||
public void propertyChange(PropertyChangeEvent e) {
|
||||
String propertyName = e.getPropertyName();
|
||||
Object source = null;
|
||||
if ("componentOrientation" == propertyName
|
||||
&& (source = e.getSource()) instanceof JComboBox
|
||||
&& ((JComboBox) source).getUI() instanceof
|
||||
WindowsComboBoxUI) {
|
||||
JComboBox comboBox = (JComboBox) source;
|
||||
WindowsComboBoxUI comboBoxUI = (WindowsComboBoxUI) comboBox.getUI();
|
||||
if (comboBoxUI.arrowButton instanceof XPComboBoxButton) {
|
||||
((XPComboBoxButton) comboBoxUI.arrowButton).setPart(
|
||||
(comboBox.getComponentOrientation() ==
|
||||
ComponentOrientation.RIGHT_TO_LEFT)
|
||||
? Part.CP_DROPDOWNBUTTONLEFT
|
||||
: Part.CP_DROPDOWNBUTTONRIGHT);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new WindowsComboBoxUI();
|
||||
}
|
||||
|
||||
public void installUI( JComponent c ) {
|
||||
super.installUI( c );
|
||||
isRollover = false;
|
||||
comboBox.setRequestFocusEnabled( true );
|
||||
if (XPStyle.getXP() != null && arrowButton != null) {
|
||||
//we can not do it in installListeners because arrowButton
|
||||
//is initialized after installListeners is invoked
|
||||
comboBox.addMouseListener(rolloverListener);
|
||||
arrowButton.addMouseListener(rolloverListener);
|
||||
}
|
||||
}
|
||||
|
||||
public void uninstallUI(JComponent c ) {
|
||||
comboBox.removeMouseListener(rolloverListener);
|
||||
if(arrowButton != null) {
|
||||
arrowButton.removeMouseListener(rolloverListener);
|
||||
}
|
||||
super.uninstallUI( c );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 1.6
|
||||
*/
|
||||
@Override
|
||||
protected void installListeners() {
|
||||
super.installListeners();
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
//button glyph for LTR and RTL combobox might differ
|
||||
if (xp != null
|
||||
&& xp.isSkinDefined(comboBox, Part.CP_DROPDOWNBUTTONRIGHT)) {
|
||||
comboBox.addPropertyChangeListener("componentOrientation",
|
||||
componentOrientationListener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 1.6
|
||||
*/
|
||||
@Override
|
||||
protected void uninstallListeners() {
|
||||
super.uninstallListeners();
|
||||
comboBox.removePropertyChangeListener("componentOrientation",
|
||||
componentOrientationListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 1.6
|
||||
*/
|
||||
protected void configureEditor() {
|
||||
super.configureEditor();
|
||||
if (XPStyle.getXP() != null) {
|
||||
editor.addMouseListener(rolloverListener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 1.6
|
||||
*/
|
||||
protected void unconfigureEditor() {
|
||||
super.unconfigureEditor();
|
||||
editor.removeMouseListener(rolloverListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 1.6
|
||||
*/
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
if (XPStyle.getXP() != null) {
|
||||
paintXPComboBoxBackground(g, c);
|
||||
}
|
||||
super.paint(g, c);
|
||||
}
|
||||
|
||||
State getXPComboBoxState(JComponent c) {
|
||||
State state = State.NORMAL;
|
||||
if (!c.isEnabled()) {
|
||||
state = State.DISABLED;
|
||||
} else if (isPopupVisible(comboBox)) {
|
||||
state = State.PRESSED;
|
||||
} else if (isRollover) {
|
||||
state = State.HOT;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
private void paintXPComboBoxBackground(Graphics g, JComponent c) {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp == null) {
|
||||
return;
|
||||
}
|
||||
State state = getXPComboBoxState(c);
|
||||
Skin skin = null;
|
||||
if (! comboBox.isEditable()
|
||||
&& xp.isSkinDefined(c, Part.CP_READONLY)) {
|
||||
skin = xp.getSkin(c, Part.CP_READONLY);
|
||||
}
|
||||
if (skin == null) {
|
||||
skin = xp.getSkin(c, Part.CP_COMBOBOX);
|
||||
}
|
||||
skin.paintSkin(g, 0, 0, c.getWidth(), c.getHeight(), state);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if ( xp != null) {
|
||||
bounds.x += 2;
|
||||
bounds.y += 2;
|
||||
bounds.width -= 4;
|
||||
bounds.height -= 4;
|
||||
} else {
|
||||
bounds.x += 1;
|
||||
bounds.y += 1;
|
||||
bounds.width -= 2;
|
||||
bounds.height -= 2;
|
||||
}
|
||||
if (! comboBox.isEditable()
|
||||
&& xp != null
|
||||
&& xp.isSkinDefined(comboBox, Part.CP_READONLY)) {
|
||||
// On vista for READNLY ComboBox
|
||||
// color for currentValue is the same as for any other item
|
||||
|
||||
// mostly copied from javax.swing.plaf.basic.BasicComboBoxUI.paintCurrentValue
|
||||
ListCellRenderer renderer = comboBox.getRenderer();
|
||||
Component c;
|
||||
if ( hasFocus && !isPopupVisible(comboBox) ) {
|
||||
c = renderer.getListCellRendererComponent(
|
||||
listBox,
|
||||
comboBox.getSelectedItem(),
|
||||
-1,
|
||||
true,
|
||||
false );
|
||||
} else {
|
||||
c = renderer.getListCellRendererComponent(
|
||||
listBox,
|
||||
comboBox.getSelectedItem(),
|
||||
-1,
|
||||
false,
|
||||
false );
|
||||
}
|
||||
c.setFont(comboBox.getFont());
|
||||
if ( comboBox.isEnabled() ) {
|
||||
c.setForeground(comboBox.getForeground());
|
||||
c.setBackground(comboBox.getBackground());
|
||||
} else {
|
||||
c.setForeground(DefaultLookup.getColor(
|
||||
comboBox, this, "ComboBox.disabledForeground", null));
|
||||
c.setBackground(DefaultLookup.getColor(
|
||||
comboBox, this, "ComboBox.disabledBackground", null));
|
||||
}
|
||||
boolean shouldValidate = false;
|
||||
if (c instanceof JPanel) {
|
||||
shouldValidate = true;
|
||||
}
|
||||
currentValuePane.paintComponent(g, c, comboBox, bounds.x, bounds.y,
|
||||
bounds.width, bounds.height, shouldValidate);
|
||||
|
||||
} else {
|
||||
super.paintCurrentValue(g, bounds, hasFocus);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 1.6
|
||||
*/
|
||||
public void paintCurrentValueBackground(Graphics g, Rectangle bounds,
|
||||
boolean hasFocus) {
|
||||
if (XPStyle.getXP() == null) {
|
||||
super.paintCurrentValueBackground(g, bounds, hasFocus);
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize( JComponent c ) {
|
||||
Dimension d = super.getMinimumSize(c);
|
||||
if (XPStyle.getXP() != null) {
|
||||
d.width += 5;
|
||||
} else {
|
||||
d.width += 4;
|
||||
}
|
||||
d.height += 2;
|
||||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a layout manager for managing the components which make up the
|
||||
* combo box.
|
||||
*
|
||||
* @return an instance of a layout manager
|
||||
*/
|
||||
protected LayoutManager createLayoutManager() {
|
||||
return new BasicComboBoxUI.ComboBoxLayoutManager() {
|
||||
public void layoutContainer(Container parent) {
|
||||
super.layoutContainer(parent);
|
||||
|
||||
if (XPStyle.getXP() != null && arrowButton != null) {
|
||||
Dimension d = parent.getSize();
|
||||
Insets insets = getInsets();
|
||||
int buttonWidth = arrowButton.getPreferredSize().width;
|
||||
arrowButton.setBounds(WindowsGraphicsUtils.isLeftToRight((JComboBox)parent)
|
||||
? (d.width - insets.right - buttonWidth)
|
||||
: insets.left,
|
||||
insets.top,
|
||||
buttonWidth, d.height - insets.top - insets.bottom);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected void installKeyboardActions() {
|
||||
super.installKeyboardActions();
|
||||
}
|
||||
|
||||
protected ComboPopup createPopup() {
|
||||
return super.createPopup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the default editor that will be used in editable combo boxes.
|
||||
* A default editor will be used only if an editor has not been
|
||||
* explicitly set with <code>setEditor</code>.
|
||||
*
|
||||
* @return a <code>ComboBoxEditor</code> used for the combo box
|
||||
* @see javax.swing.JComboBox#setEditor
|
||||
*/
|
||||
protected ComboBoxEditor createEditor() {
|
||||
return new WindowsComboBoxEditor();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 1.6
|
||||
*/
|
||||
@Override
|
||||
protected ListCellRenderer createRenderer() {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp != null && xp.isSkinDefined(comboBox, Part.CP_READONLY)) {
|
||||
return new WindowsComboBoxRenderer();
|
||||
} else {
|
||||
return super.createRenderer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an button which will be used as the control to show or hide
|
||||
* the popup portion of the combo box.
|
||||
*
|
||||
* @return a button which represents the popup control
|
||||
*/
|
||||
protected JButton createArrowButton() {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp != null) {
|
||||
return new XPComboBoxButton(xp);
|
||||
} else {
|
||||
return super.createArrowButton();
|
||||
}
|
||||
}
|
||||
|
||||
private class XPComboBoxButton extends XPStyle.GlyphButton {
|
||||
public XPComboBoxButton(XPStyle xp) {
|
||||
super(null,
|
||||
(! xp.isSkinDefined(comboBox, Part.CP_DROPDOWNBUTTONRIGHT))
|
||||
? Part.CP_DROPDOWNBUTTON
|
||||
: (comboBox.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT)
|
||||
? Part.CP_DROPDOWNBUTTONLEFT
|
||||
: Part.CP_DROPDOWNBUTTONRIGHT
|
||||
);
|
||||
setRequestFocusEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected State getState() {
|
||||
State rv;
|
||||
rv = super.getState();
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (rv != State.DISABLED
|
||||
&& comboBox != null && ! comboBox.isEditable()
|
||||
&& xp != null && xp.isSkinDefined(comboBox,
|
||||
Part.CP_DROPDOWNBUTTONRIGHT)) {
|
||||
/*
|
||||
* for non editable ComboBoxes Vista seems to have the
|
||||
* same glyph for all non DISABLED states
|
||||
*/
|
||||
rv = State.NORMAL;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(17, 21);
|
||||
}
|
||||
|
||||
void setPart(Part part) {
|
||||
setPart(comboBox, part);
|
||||
}
|
||||
|
||||
WindowsComboBoxUI getWindowsComboBoxUI() {
|
||||
return WindowsComboBoxUI.this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Subclassed to add Windows specific Key Bindings.
|
||||
* This class is now obsolete and doesn't do anything.
|
||||
* Only included for backwards API compatibility.
|
||||
* Do not call or override.
|
||||
*
|
||||
* @deprecated As of Java 2 platform v1.4.
|
||||
*/
|
||||
@Deprecated
|
||||
protected class WindowsComboPopup extends BasicComboPopup {
|
||||
|
||||
public WindowsComboPopup( JComboBox cBox ) {
|
||||
super( cBox );
|
||||
}
|
||||
|
||||
protected KeyListener createKeyListener() {
|
||||
return new InvocationKeyHandler();
|
||||
}
|
||||
|
||||
protected class InvocationKeyHandler extends BasicComboPopup.InvocationKeyHandler {
|
||||
protected InvocationKeyHandler() {
|
||||
WindowsComboPopup.this.super();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Subclassed to highlight selected item in an editable combo box.
|
||||
*/
|
||||
public static class WindowsComboBoxEditor
|
||||
extends BasicComboBoxEditor.UIResource {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @since 1.6
|
||||
*/
|
||||
protected JTextField createEditorComponent() {
|
||||
JTextField editor = super.createEditorComponent();
|
||||
Border border = (Border)UIManager.get("ComboBox.editorBorder");
|
||||
if (border != null) {
|
||||
editor.setBorder(border);
|
||||
}
|
||||
editor.setOpaque(false);
|
||||
return editor;
|
||||
}
|
||||
|
||||
public void setItem(Object item) {
|
||||
super.setItem(item);
|
||||
Object focus = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
|
||||
if ((focus == editor) || (focus == editor.getParent())) {
|
||||
editor.selectAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclassed to set opacity {@code false} on the renderer
|
||||
* and to show border for focused cells.
|
||||
*/
|
||||
private static class WindowsComboBoxRenderer
|
||||
extends BasicComboBoxRenderer.UIResource {
|
||||
private static final Object BORDER_KEY
|
||||
= new StringUIClientPropertyKey("BORDER_KEY");
|
||||
private static final Border NULL_BORDER = new EmptyBorder(0, 0, 0, 0);
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Component getListCellRendererComponent(
|
||||
JList list,
|
||||
Object value,
|
||||
int index,
|
||||
boolean isSelected,
|
||||
boolean cellHasFocus) {
|
||||
Component rv =
|
||||
super.getListCellRendererComponent(list, value, index,
|
||||
isSelected, cellHasFocus);
|
||||
if (rv instanceof JComponent) {
|
||||
JComponent component = (JComponent) rv;
|
||||
if (index == -1 && isSelected) {
|
||||
Border border = component.getBorder();
|
||||
Border dashedBorder =
|
||||
new WindowsBorders.DashedBorder(list.getForeground());
|
||||
component.setBorder(dashedBorder);
|
||||
//store current border in client property if needed
|
||||
if (component.getClientProperty(BORDER_KEY) == null) {
|
||||
component.putClientProperty(BORDER_KEY,
|
||||
(border == null) ? NULL_BORDER : border);
|
||||
}
|
||||
} else {
|
||||
if (component.getBorder() instanceof
|
||||
WindowsBorders.DashedBorder) {
|
||||
Object storedBorder = component.getClientProperty(BORDER_KEY);
|
||||
if (storedBorder instanceof Border) {
|
||||
component.setBorder(
|
||||
(storedBorder == NULL_BORDER) ? null
|
||||
: (Border) storedBorder);
|
||||
}
|
||||
component.putClientProperty(BORDER_KEY, null);
|
||||
}
|
||||
}
|
||||
if (index == -1) {
|
||||
component.setOpaque(false);
|
||||
component.setForeground(list.getForeground());
|
||||
} else {
|
||||
component.setOpaque(true);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2004, 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Windows icon for a minimized window on the desktop.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*/
|
||||
public class WindowsDesktopIconUI extends BasicDesktopIconUI {
|
||||
private int width;
|
||||
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new WindowsDesktopIconUI();
|
||||
}
|
||||
|
||||
public void installDefaults() {
|
||||
super.installDefaults();
|
||||
width = UIManager.getInt("DesktopIcon.width");
|
||||
}
|
||||
|
||||
public void installUI(JComponent c) {
|
||||
super.installUI(c);
|
||||
|
||||
c.setOpaque(XPStyle.getXP() == null);
|
||||
}
|
||||
|
||||
// Uninstall the listeners added by the WindowsInternalFrameTitlePane
|
||||
public void uninstallUI(JComponent c) {
|
||||
WindowsInternalFrameTitlePane thePane =
|
||||
(WindowsInternalFrameTitlePane)iconPane;
|
||||
super.uninstallUI(c);
|
||||
thePane.uninstallListeners();
|
||||
}
|
||||
|
||||
protected void installComponents() {
|
||||
iconPane = new WindowsInternalFrameTitlePane(frame);
|
||||
desktopIcon.setLayout(new BorderLayout());
|
||||
desktopIcon.add(iconPane, BorderLayout.CENTER);
|
||||
|
||||
if (XPStyle.getXP() != null) {
|
||||
desktopIcon.setBorder(null);
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize(JComponent c) {
|
||||
// Windows desktop icons can not be resized. Therefore, we should
|
||||
// always return the minimum size of the desktop icon. See
|
||||
// getMinimumSize(JComponent c).
|
||||
return getMinimumSize(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Windows desktop icons are restricted to a width of 160 pixels by
|
||||
* default. This value is retrieved by the DesktopIcon.width property.
|
||||
*/
|
||||
public Dimension getMinimumSize(JComponent c) {
|
||||
Dimension dim = super.getMinimumSize(c);
|
||||
dim.width = width;
|
||||
return dim;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import javax.swing.DefaultDesktopManager;
|
||||
import javax.swing.JInternalFrame;
|
||||
import javax.swing.JLayeredPane;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.beans.PropertyVetoException;
|
||||
import java.util.Vector;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
* This class implements a DesktopManager which more closely follows
|
||||
* the MDI model than the DefaultDesktopManager. Unlike the
|
||||
* DefaultDesktopManager policy, MDI requires that the selected
|
||||
* and activated child frames are the same, and that that frame
|
||||
* always be the top-most window.
|
||||
* <p>
|
||||
* The maximized state is managed by the DesktopManager with MDI,
|
||||
* instead of just being a property of the individual child frame.
|
||||
* This means that if the currently selected window is maximized
|
||||
* and another window is selected, that new window will be maximized.
|
||||
*
|
||||
* @see javax.swing.DefaultDesktopManager
|
||||
* @author Thomas Ball
|
||||
*/
|
||||
public class WindowsDesktopManager extends DefaultDesktopManager
|
||||
implements java.io.Serializable, javax.swing.plaf.UIResource {
|
||||
|
||||
/* The frame which is currently selected/activated.
|
||||
* We store this value to enforce MDI's single-selection model.
|
||||
*/
|
||||
private WeakReference<JInternalFrame> currentFrameRef;
|
||||
|
||||
public void activateFrame(JInternalFrame f) {
|
||||
JInternalFrame currentFrame = currentFrameRef != null ?
|
||||
currentFrameRef.get() : null;
|
||||
try {
|
||||
super.activateFrame(f);
|
||||
if (currentFrame != null && f != currentFrame) {
|
||||
// If the current frame is maximized, transfer that
|
||||
// attribute to the frame being activated.
|
||||
if (currentFrame.isMaximum() &&
|
||||
(f.getClientProperty("JInternalFrame.frameType") !=
|
||||
"optionDialog") ) {
|
||||
//Special case. If key binding was used to select next
|
||||
//frame instead of minimizing the icon via the minimize
|
||||
//icon.
|
||||
if (!currentFrame.isIcon()) {
|
||||
currentFrame.setMaximum(false);
|
||||
if (f.isMaximizable()) {
|
||||
if (!f.isMaximum()) {
|
||||
f.setMaximum(true);
|
||||
} else if (f.isMaximum() && f.isIcon()) {
|
||||
f.setIcon(false);
|
||||
} else {
|
||||
f.setMaximum(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (currentFrame.isSelected()) {
|
||||
currentFrame.setSelected(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!f.isSelected()) {
|
||||
f.setSelected(true);
|
||||
}
|
||||
} catch (PropertyVetoException e) {}
|
||||
if (f != currentFrame) {
|
||||
currentFrameRef = new WeakReference<JInternalFrame>(f);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* Windows desktop 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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author David Kloba
|
||||
*/
|
||||
public class WindowsDesktopPaneUI extends BasicDesktopPaneUI
|
||||
{
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new WindowsDesktopPaneUI();
|
||||
}
|
||||
|
||||
protected void installDesktopManager() {
|
||||
desktopManager = desktop.getDesktopManager();
|
||||
if(desktopManager == null) {
|
||||
desktopManager = new WindowsDesktopManager();
|
||||
desktop.setDesktopManager(desktopManager);
|
||||
}
|
||||
}
|
||||
|
||||
protected void installDefaults() {
|
||||
super.installDefaults();
|
||||
}
|
||||
|
||||
protected void installKeyboardActions() {
|
||||
super.installKeyboardActions();
|
||||
|
||||
// Request focus if it isn't set.
|
||||
if(!desktop.requestDefaultFocus()) {
|
||||
desktop.requestFocus();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.Caret;
|
||||
|
||||
|
||||
/**
|
||||
* Windows rendition of the component.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*/
|
||||
public class WindowsEditorPaneUI extends BasicEditorPaneUI
|
||||
{
|
||||
|
||||
/**
|
||||
* Creates a UI for a JEditorPane.
|
||||
*
|
||||
* @param c the configurable text component
|
||||
* @return the UI
|
||||
*/
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new WindowsEditorPaneUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the object to use for a caret. By default an
|
||||
* instance of WindowsCaret is created. This method
|
||||
* can be redefined to provide something else that implements
|
||||
* the InputPosition interface or a subclass of DefaultCaret.
|
||||
*
|
||||
* @return the caret object
|
||||
*/
|
||||
protected Caret createCaret() {
|
||||
return new WindowsTextUI.WindowsCaret();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import sun.swing.SwingUtilities2;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.UIResource;
|
||||
|
||||
import static com.sun.java.swing.plaf.windows.TMSchema.*;
|
||||
|
||||
/**
|
||||
* A collection of static utility methods used for rendering the Windows look
|
||||
* and feel.
|
||||
*
|
||||
* @author Mark Davidson
|
||||
* @since 1.4
|
||||
*/
|
||||
public class WindowsGraphicsUtils {
|
||||
|
||||
/**
|
||||
* Renders a text String in Windows without the mnemonic.
|
||||
* This is here because the WindowsUI hierarchy doesn't match the Component hierarchy. All
|
||||
* the overriden paintText methods of the ButtonUI delegates will call this static method.
|
||||
* <p>
|
||||
* @param g Graphics context
|
||||
* @param b Current button to render
|
||||
* @param textRect Bounding rectangle to render the text.
|
||||
* @param text String to render
|
||||
*/
|
||||
public static void paintText(Graphics g, AbstractButton b,
|
||||
Rectangle textRect, String text,
|
||||
int textShiftOffset) {
|
||||
FontMetrics fm = SwingUtilities2.getFontMetrics(b, g);
|
||||
|
||||
int mnemIndex = b.getDisplayedMnemonicIndex();
|
||||
// W2K Feature: Check to see if the Underscore should be rendered.
|
||||
if (WindowsLookAndFeel.isMnemonicHidden() == true) {
|
||||
mnemIndex = -1;
|
||||
}
|
||||
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp != null && !(b instanceof JMenuItem)) {
|
||||
paintXPText(b, g, textRect.x + textShiftOffset,
|
||||
textRect.y + fm.getAscent() + textShiftOffset,
|
||||
text, mnemIndex);
|
||||
} else {
|
||||
paintClassicText(b, g, textRect.x + textShiftOffset,
|
||||
textRect.y + fm.getAscent() + textShiftOffset,
|
||||
text, mnemIndex);
|
||||
}
|
||||
}
|
||||
|
||||
static void paintClassicText(AbstractButton b, Graphics g, int x, int y,
|
||||
String text, int mnemIndex) {
|
||||
ButtonModel model = b.getModel();
|
||||
|
||||
/* Draw the Text */
|
||||
Color color = b.getForeground();
|
||||
if(model.isEnabled()) {
|
||||
/*** paint the text normally */
|
||||
if(!(b instanceof JMenuItem && model.isArmed())
|
||||
&& !(b instanceof JMenu && (model.isSelected() || model.isRollover()))) {
|
||||
/* We shall not set foreground color for selected menu or
|
||||
* armed menuitem. Foreground must be set in appropriate
|
||||
* Windows* class because these colors passes from
|
||||
* BasicMenuItemUI as protected fields and we can't
|
||||
* reach them from this class */
|
||||
g.setColor(b.getForeground());
|
||||
}
|
||||
SwingUtilities2.drawStringUnderlineCharAt(b, g,text, mnemIndex, x, y);
|
||||
} else { /*** paint the text disabled ***/
|
||||
color = UIManager.getColor("Button.shadow");
|
||||
Color shadow = UIManager.getColor("Button.disabledShadow");
|
||||
if(model.isArmed()) {
|
||||
color = UIManager.getColor("Button.disabledForeground");
|
||||
} else {
|
||||
if (shadow == null) {
|
||||
shadow = b.getBackground().darker();
|
||||
}
|
||||
g.setColor(shadow);
|
||||
SwingUtilities2.drawStringUnderlineCharAt(b, g, text, mnemIndex,
|
||||
x + 1, y + 1);
|
||||
}
|
||||
if (color == null) {
|
||||
color = b.getBackground().brighter();
|
||||
}
|
||||
g.setColor(color);
|
||||
SwingUtilities2.drawStringUnderlineCharAt(b, g, text, mnemIndex, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
static void paintXPText(AbstractButton b, Graphics g, int x, int y,
|
||||
String text, int mnemIndex) {
|
||||
Part part = WindowsButtonUI.getXPButtonType(b);
|
||||
State state = WindowsButtonUI.getXPButtonState(b);
|
||||
paintXPText(b, part, state, g, x, y, text, mnemIndex);
|
||||
}
|
||||
|
||||
static void paintXPText(AbstractButton b, Part part, State state,
|
||||
Graphics g, int x, int y, String text, int mnemIndex) {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp == null) {
|
||||
return;
|
||||
}
|
||||
Color textColor = b.getForeground();
|
||||
|
||||
if (textColor instanceof UIResource) {
|
||||
textColor = xp.getColor(b, part, state, Prop.TEXTCOLOR, b.getForeground());
|
||||
// to work around an apparent bug in Windows, use the pushbutton
|
||||
// color for disabled toolbar buttons if the disabled color is the
|
||||
// same as the enabled color
|
||||
if (part == Part.TP_BUTTON && state == State.DISABLED) {
|
||||
Color enabledColor = xp.getColor(b, part, State.NORMAL,
|
||||
Prop.TEXTCOLOR, b.getForeground());
|
||||
if(textColor.equals(enabledColor)) {
|
||||
textColor = xp.getColor(b, Part.BP_PUSHBUTTON, state,
|
||||
Prop.TEXTCOLOR, textColor);
|
||||
}
|
||||
}
|
||||
// only draw shadow if developer hasn't changed the foreground color
|
||||
// and if the current style has text shadows.
|
||||
TypeEnum shadowType = xp.getTypeEnum(b, part,
|
||||
state, Prop.TEXTSHADOWTYPE);
|
||||
if (shadowType == TypeEnum.TST_SINGLE ||
|
||||
shadowType == TypeEnum.TST_CONTINUOUS) {
|
||||
Color shadowColor = xp.getColor(b, part, state,
|
||||
Prop.TEXTSHADOWCOLOR, Color.black);
|
||||
Point offset = xp.getPoint(b, part, state, Prop.TEXTSHADOWOFFSET);
|
||||
if (offset != null) {
|
||||
g.setColor(shadowColor);
|
||||
SwingUtilities2.drawStringUnderlineCharAt(b, g, text, mnemIndex,
|
||||
x + offset.x,
|
||||
y + offset.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g.setColor(textColor);
|
||||
SwingUtilities2.drawStringUnderlineCharAt(b, g, text, mnemIndex, x, y);
|
||||
}
|
||||
|
||||
static boolean isLeftToRight(Component c) {
|
||||
return c.getComponentOrientation().isLeftToRight();
|
||||
}
|
||||
|
||||
/*
|
||||
* Repaints all the components with the mnemonics in the given window and
|
||||
* all its owned windows.
|
||||
*/
|
||||
static void repaintMnemonicsInWindow(Window w) {
|
||||
if(w == null || !w.isShowing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Window[] ownedWindows = w.getOwnedWindows();
|
||||
for(int i=0;i<ownedWindows.length;i++) {
|
||||
repaintMnemonicsInWindow(ownedWindows[i]);
|
||||
}
|
||||
|
||||
repaintMnemonicsInContainer(w);
|
||||
}
|
||||
|
||||
/*
|
||||
* Repaints all the components with the mnemonics in container.
|
||||
* Recursively searches for all the subcomponents.
|
||||
*/
|
||||
static void repaintMnemonicsInContainer(Container cont) {
|
||||
Component c;
|
||||
for(int i=0; i<cont.getComponentCount(); i++) {
|
||||
c = cont.getComponent(i);
|
||||
if(c == null || !c.isVisible()) {
|
||||
continue;
|
||||
}
|
||||
if(c instanceof AbstractButton
|
||||
&& ((AbstractButton)c).getMnemonic() != '\0') {
|
||||
c.repaint();
|
||||
continue;
|
||||
} else if(c instanceof JLabel
|
||||
&& ((JLabel)c).getDisplayedMnemonic() != '\0') {
|
||||
c.repaint();
|
||||
continue;
|
||||
}
|
||||
if(c instanceof Container) {
|
||||
repaintMnemonicsInContainer((Container)c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,913 @@
|
||||
/*
|
||||
* 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.ButtonUI;
|
||||
import javax.swing.plaf.UIResource;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
import static com.sun.java.swing.plaf.windows.TMSchema.*;
|
||||
import static com.sun.java.swing.plaf.windows.XPStyle.Skin;
|
||||
|
||||
import sun.swing.MenuItemCheckIconFactory;
|
||||
|
||||
/**
|
||||
* Factory object that can vend Icons appropriate for the Windows L & F.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author David Kloba
|
||||
* @author Georges Saab
|
||||
* @author Rich Schiavi
|
||||
*/
|
||||
public class WindowsIconFactory implements Serializable
|
||||
{
|
||||
private static Icon frame_closeIcon;
|
||||
private static Icon frame_iconifyIcon;
|
||||
private static Icon frame_maxIcon;
|
||||
private static Icon frame_minIcon;
|
||||
private static Icon frame_resizeIcon;
|
||||
private static Icon checkBoxIcon;
|
||||
private static Icon radioButtonIcon;
|
||||
private static Icon checkBoxMenuItemIcon;
|
||||
private static Icon radioButtonMenuItemIcon;
|
||||
private static Icon menuItemCheckIcon;
|
||||
private static Icon menuItemArrowIcon;
|
||||
private static Icon menuArrowIcon;
|
||||
private static VistaMenuItemCheckIconFactory menuItemCheckIconFactory;
|
||||
|
||||
public static Icon getMenuItemCheckIcon() {
|
||||
if (menuItemCheckIcon == null) {
|
||||
menuItemCheckIcon = new MenuItemCheckIcon();
|
||||
}
|
||||
return menuItemCheckIcon;
|
||||
}
|
||||
|
||||
public static Icon getMenuItemArrowIcon() {
|
||||
if (menuItemArrowIcon == null) {
|
||||
menuItemArrowIcon = new MenuItemArrowIcon();
|
||||
}
|
||||
return menuItemArrowIcon;
|
||||
}
|
||||
|
||||
public static Icon getMenuArrowIcon() {
|
||||
if (menuArrowIcon == null) {
|
||||
menuArrowIcon = new MenuArrowIcon();
|
||||
}
|
||||
return menuArrowIcon;
|
||||
}
|
||||
|
||||
public static Icon getCheckBoxIcon() {
|
||||
if (checkBoxIcon == null) {
|
||||
checkBoxIcon = new CheckBoxIcon();
|
||||
}
|
||||
return checkBoxIcon;
|
||||
}
|
||||
|
||||
public static Icon getRadioButtonIcon() {
|
||||
if (radioButtonIcon == null) {
|
||||
radioButtonIcon = new RadioButtonIcon();
|
||||
}
|
||||
return radioButtonIcon;
|
||||
}
|
||||
|
||||
public static Icon getCheckBoxMenuItemIcon() {
|
||||
if (checkBoxMenuItemIcon == null) {
|
||||
checkBoxMenuItemIcon = new CheckBoxMenuItemIcon();
|
||||
}
|
||||
return checkBoxMenuItemIcon;
|
||||
}
|
||||
|
||||
public static Icon getRadioButtonMenuItemIcon() {
|
||||
if (radioButtonMenuItemIcon == null) {
|
||||
radioButtonMenuItemIcon = new RadioButtonMenuItemIcon();
|
||||
}
|
||||
return radioButtonMenuItemIcon;
|
||||
}
|
||||
|
||||
static
|
||||
synchronized VistaMenuItemCheckIconFactory getMenuItemCheckIconFactory() {
|
||||
if (menuItemCheckIconFactory == null) {
|
||||
menuItemCheckIconFactory =
|
||||
new VistaMenuItemCheckIconFactory();
|
||||
}
|
||||
return menuItemCheckIconFactory;
|
||||
}
|
||||
|
||||
public static Icon createFrameCloseIcon() {
|
||||
if (frame_closeIcon == null) {
|
||||
frame_closeIcon = new FrameButtonIcon(Part.WP_CLOSEBUTTON);
|
||||
}
|
||||
return frame_closeIcon;
|
||||
}
|
||||
|
||||
public static Icon createFrameIconifyIcon() {
|
||||
if (frame_iconifyIcon == null) {
|
||||
frame_iconifyIcon = new FrameButtonIcon(Part.WP_MINBUTTON);
|
||||
}
|
||||
return frame_iconifyIcon;
|
||||
}
|
||||
|
||||
public static Icon createFrameMaximizeIcon() {
|
||||
if (frame_maxIcon == null) {
|
||||
frame_maxIcon = new FrameButtonIcon(Part.WP_MAXBUTTON);
|
||||
}
|
||||
return frame_maxIcon;
|
||||
}
|
||||
|
||||
public static Icon createFrameMinimizeIcon() {
|
||||
if (frame_minIcon == null) {
|
||||
frame_minIcon = new FrameButtonIcon(Part.WP_RESTOREBUTTON);
|
||||
}
|
||||
return frame_minIcon;
|
||||
}
|
||||
|
||||
public static Icon createFrameResizeIcon() {
|
||||
if(frame_resizeIcon == null)
|
||||
frame_resizeIcon = new ResizeIcon();
|
||||
return frame_resizeIcon;
|
||||
}
|
||||
|
||||
|
||||
private static class FrameButtonIcon implements Icon, Serializable {
|
||||
private Part part;
|
||||
|
||||
private FrameButtonIcon(Part part) {
|
||||
this.part = part;
|
||||
}
|
||||
|
||||
public void paintIcon(Component c, Graphics g, int x0, int y0) {
|
||||
int width = getIconWidth();
|
||||
int height = getIconHeight();
|
||||
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp != null) {
|
||||
Skin skin = xp.getSkin(c, part);
|
||||
AbstractButton b = (AbstractButton)c;
|
||||
ButtonModel model = b.getModel();
|
||||
|
||||
// Find out if frame is inactive
|
||||
JInternalFrame jif = (JInternalFrame)SwingUtilities.
|
||||
getAncestorOfClass(JInternalFrame.class, b);
|
||||
boolean jifSelected = (jif != null && jif.isSelected());
|
||||
|
||||
State state;
|
||||
if (jifSelected) {
|
||||
if (!model.isEnabled()) {
|
||||
state = State.DISABLED;
|
||||
} else if (model.isArmed() && model.isPressed()) {
|
||||
state = State.PUSHED;
|
||||
} else if (model.isRollover()) {
|
||||
state = State.HOT;
|
||||
} else {
|
||||
state = State.NORMAL;
|
||||
}
|
||||
} else {
|
||||
if (!model.isEnabled()) {
|
||||
state = State.INACTIVEDISABLED;
|
||||
} else if (model.isArmed() && model.isPressed()) {
|
||||
state = State.INACTIVEPUSHED;
|
||||
} else if (model.isRollover()) {
|
||||
state = State.INACTIVEHOT;
|
||||
} else {
|
||||
state = State.INACTIVENORMAL;
|
||||
}
|
||||
}
|
||||
skin.paintSkin(g, 0, 0, width, height, state);
|
||||
} else {
|
||||
g.setColor(Color.black);
|
||||
int x = width / 12 + 2;
|
||||
int y = height / 5;
|
||||
int h = height - y * 2 - 1;
|
||||
int w = width * 3/4 -3;
|
||||
int thickness2 = Math.max(height / 8, 2);
|
||||
int thickness = Math.max(width / 15, 1);
|
||||
if (part == Part.WP_CLOSEBUTTON) {
|
||||
int lineWidth;
|
||||
if (width > 47) lineWidth = 6;
|
||||
else if (width > 37) lineWidth = 5;
|
||||
else if (width > 26) lineWidth = 4;
|
||||
else if (width > 16) lineWidth = 3;
|
||||
else if (width > 12) lineWidth = 2;
|
||||
else lineWidth = 1;
|
||||
y = height / 12 + 2;
|
||||
if (lineWidth == 1) {
|
||||
if (w % 2 == 1) { x++; w++; }
|
||||
g.drawLine(x, y, x+w-2, y+w-2);
|
||||
g.drawLine(x+w-2, y, x, y+w-2);
|
||||
} else if (lineWidth == 2) {
|
||||
if (w > 6) { x++; w--; }
|
||||
g.drawLine(x, y, x+w-2, y+w-2);
|
||||
g.drawLine(x+w-2, y, x, y+w-2);
|
||||
g.drawLine(x+1, y, x+w-1, y+w-2);
|
||||
g.drawLine(x+w-1, y, x+1, y+w-2);
|
||||
} else {
|
||||
x += 2; y++; w -= 2;
|
||||
g.drawLine(x, y, x+w-1, y+w-1);
|
||||
g.drawLine(x+w-1, y, x, y+w-1);
|
||||
g.drawLine(x+1, y, x+w-1, y+w-2);
|
||||
g.drawLine(x+w-2, y, x, y+w-2);
|
||||
g.drawLine(x, y+1, x+w-2, y+w-1);
|
||||
g.drawLine(x+w-1, y+1, x+1, y+w-1);
|
||||
for (int i = 4; i <= lineWidth; i++) {
|
||||
g.drawLine(x+i-2, y, x+w-1, y+w-i+1);
|
||||
g.drawLine(x, y+i-2, x+w-i+1, y+w-1);
|
||||
g.drawLine(x+w-i+1, y, x, y+w-i+1);
|
||||
g.drawLine(x+w-1, y+i-2, x+i-2, y+w-1);
|
||||
}
|
||||
}
|
||||
} else if (part == Part.WP_MINBUTTON) {
|
||||
g.fillRect(x, y+h-thickness2, w-w/3, thickness2);
|
||||
} else if (part == Part.WP_MAXBUTTON) {
|
||||
g.fillRect(x, y, w, thickness2);
|
||||
g.fillRect(x, y, thickness, h);
|
||||
g.fillRect(x+w-thickness, y, thickness, h);
|
||||
g.fillRect(x, y+h-thickness, w, thickness);
|
||||
} else if (part == Part.WP_RESTOREBUTTON) {
|
||||
g.fillRect(x+w/3, y, w-w/3, thickness2);
|
||||
g.fillRect(x+w/3, y, thickness, h/3);
|
||||
g.fillRect(x+w-thickness, y, thickness, h-h/3);
|
||||
g.fillRect(x+w-w/3, y+h-h/3-thickness, w/3, thickness);
|
||||
|
||||
g.fillRect(x, y+h/3, w-w/3, thickness2);
|
||||
g.fillRect(x, y+h/3, thickness, h-h/3);
|
||||
g.fillRect(x+w-w/3-thickness, y+h/3, thickness, h-h/3);
|
||||
g.fillRect(x, y+h-thickness, w-w/3, thickness);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getIconWidth() {
|
||||
int width;
|
||||
if (XPStyle.getXP() != null) {
|
||||
// Fix for XP bug where sometimes these sizes aren't updated properly
|
||||
// Assume for now that height is correct and derive width using the
|
||||
// ratio from the uxtheme part
|
||||
width = UIManager.getInt("InternalFrame.titleButtonHeight") -2;
|
||||
Dimension d = XPStyle.getPartSize(Part.WP_CLOSEBUTTON, State.NORMAL);
|
||||
if (d != null && d.width != 0 && d.height != 0) {
|
||||
width = (int) ((float) width * d.width / d.height);
|
||||
}
|
||||
} else {
|
||||
width = UIManager.getInt("InternalFrame.titleButtonWidth") -2;
|
||||
}
|
||||
if (XPStyle.getXP() != null) {
|
||||
width -= 2;
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getIconHeight() {
|
||||
int height = UIManager.getInt("InternalFrame.titleButtonHeight")-4;
|
||||
return height;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static class ResizeIcon implements Icon, Serializable {
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
g.setColor(UIManager.getColor("InternalFrame.resizeIconHighlight"));
|
||||
g.drawLine(0, 11, 11, 0);
|
||||
g.drawLine(4, 11, 11, 4);
|
||||
g.drawLine(8, 11, 11, 8);
|
||||
|
||||
g.setColor(UIManager.getColor("InternalFrame.resizeIconShadow"));
|
||||
g.drawLine(1, 11, 11, 1);
|
||||
g.drawLine(2, 11, 11, 2);
|
||||
g.drawLine(5, 11, 11, 5);
|
||||
g.drawLine(6, 11, 11, 6);
|
||||
g.drawLine(9, 11, 11, 9);
|
||||
g.drawLine(10, 11, 11, 10);
|
||||
}
|
||||
public int getIconWidth() { return 13; }
|
||||
public int getIconHeight() { return 13; }
|
||||
};
|
||||
|
||||
private static class CheckBoxIcon implements Icon, Serializable
|
||||
{
|
||||
final static int csize = 13;
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
JCheckBox cb = (JCheckBox) c;
|
||||
ButtonModel model = cb.getModel();
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
|
||||
if (xp != null) {
|
||||
State state;
|
||||
if (model.isSelected()) {
|
||||
state = State.CHECKEDNORMAL;
|
||||
if (!model.isEnabled()) {
|
||||
state = State.CHECKEDDISABLED;
|
||||
} else if (model.isPressed() && model.isArmed()) {
|
||||
state = State.CHECKEDPRESSED;
|
||||
} else if (model.isRollover()) {
|
||||
state = State.CHECKEDHOT;
|
||||
}
|
||||
} else {
|
||||
state = State.UNCHECKEDNORMAL;
|
||||
if (!model.isEnabled()) {
|
||||
state = State.UNCHECKEDDISABLED;
|
||||
} else if (model.isPressed() && model.isArmed()) {
|
||||
state = State.UNCHECKEDPRESSED;
|
||||
} else if (model.isRollover()) {
|
||||
state = State.UNCHECKEDHOT;
|
||||
}
|
||||
}
|
||||
Part part = Part.BP_CHECKBOX;
|
||||
xp.getSkin(c, part).paintSkin(g, x, y, state);
|
||||
} else {
|
||||
// outer bevel
|
||||
if(!cb.isBorderPaintedFlat()) {
|
||||
// Outer top/left
|
||||
g.setColor(UIManager.getColor("CheckBox.shadow"));
|
||||
g.drawLine(x, y, x+11, y);
|
||||
g.drawLine(x, y+1, x, y+11);
|
||||
|
||||
// Outer bottom/right
|
||||
g.setColor(UIManager.getColor("CheckBox.highlight"));
|
||||
g.drawLine(x+12, y, x+12, y+12);
|
||||
g.drawLine(x, y+12, x+11, y+12);
|
||||
|
||||
// Inner top.left
|
||||
g.setColor(UIManager.getColor("CheckBox.darkShadow"));
|
||||
g.drawLine(x+1, y+1, x+10, y+1);
|
||||
g.drawLine(x+1, y+2, x+1, y+10);
|
||||
|
||||
// Inner bottom/right
|
||||
g.setColor(UIManager.getColor("CheckBox.light"));
|
||||
g.drawLine(x+1, y+11, x+11, y+11);
|
||||
g.drawLine(x+11, y+1, x+11, y+10);
|
||||
|
||||
// inside box
|
||||
if((model.isPressed() && model.isArmed()) || !model.isEnabled()) {
|
||||
g.setColor(UIManager.getColor("CheckBox.background"));
|
||||
} else {
|
||||
g.setColor(UIManager.getColor("CheckBox.interiorBackground"));
|
||||
}
|
||||
g.fillRect(x+2, y+2, csize-4, csize-4);
|
||||
} else {
|
||||
g.setColor(UIManager.getColor("CheckBox.shadow"));
|
||||
g.drawRect(x+1, y+1, csize-3, csize-3);
|
||||
|
||||
if((model.isPressed() && model.isArmed()) || !model.isEnabled()) {
|
||||
g.setColor(UIManager.getColor("CheckBox.background"));
|
||||
} else {
|
||||
g.setColor(UIManager.getColor("CheckBox.interiorBackground"));
|
||||
}
|
||||
g.fillRect(x+2, y+2, csize-4, csize-4);
|
||||
}
|
||||
|
||||
if(model.isEnabled()) {
|
||||
g.setColor(UIManager.getColor("CheckBox.foreground"));
|
||||
} else {
|
||||
g.setColor(UIManager.getColor("CheckBox.shadow"));
|
||||
}
|
||||
|
||||
// paint check
|
||||
if (model.isSelected()) {
|
||||
g.drawLine(x+9, y+3, x+9, y+3);
|
||||
g.drawLine(x+8, y+4, x+9, y+4);
|
||||
g.drawLine(x+7, y+5, x+9, y+5);
|
||||
g.drawLine(x+6, y+6, x+8, y+6);
|
||||
g.drawLine(x+3, y+7, x+7, y+7);
|
||||
g.drawLine(x+4, y+8, x+6, y+8);
|
||||
g.drawLine(x+5, y+9, x+5, y+9);
|
||||
g.drawLine(x+3, y+5, x+3, y+5);
|
||||
g.drawLine(x+3, y+6, x+4, y+6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getIconWidth() {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp != null) {
|
||||
return xp.getSkin(null, Part.BP_CHECKBOX).getWidth();
|
||||
} else {
|
||||
return csize;
|
||||
}
|
||||
}
|
||||
|
||||
public int getIconHeight() {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp != null) {
|
||||
return xp.getSkin(null, Part.BP_CHECKBOX).getHeight();
|
||||
} else {
|
||||
return csize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class RadioButtonIcon implements Icon, UIResource, Serializable
|
||||
{
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
AbstractButton b = (AbstractButton) c;
|
||||
ButtonModel model = b.getModel();
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
|
||||
if (xp != null) {
|
||||
Part part = Part.BP_RADIOBUTTON;
|
||||
Skin skin = xp.getSkin(b, part);
|
||||
State state;
|
||||
int index = 0;
|
||||
if (model.isSelected()) {
|
||||
state = State.CHECKEDNORMAL;
|
||||
if (!model.isEnabled()) {
|
||||
state = State.CHECKEDDISABLED;
|
||||
} else if (model.isPressed() && model.isArmed()) {
|
||||
state = State.CHECKEDPRESSED;
|
||||
} else if (model.isRollover()) {
|
||||
state = State.CHECKEDHOT;
|
||||
}
|
||||
} else {
|
||||
state = State.UNCHECKEDNORMAL;
|
||||
if (!model.isEnabled()) {
|
||||
state = State.UNCHECKEDDISABLED;
|
||||
} else if (model.isPressed() && model.isArmed()) {
|
||||
state = State.UNCHECKEDPRESSED;
|
||||
} else if (model.isRollover()) {
|
||||
state = State.UNCHECKEDHOT;
|
||||
}
|
||||
}
|
||||
skin.paintSkin(g, x, y, state);
|
||||
} else {
|
||||
// fill interior
|
||||
if((model.isPressed() && model.isArmed()) || !model.isEnabled()) {
|
||||
g.setColor(UIManager.getColor("RadioButton.background"));
|
||||
} else {
|
||||
g.setColor(UIManager.getColor("RadioButton.interiorBackground"));
|
||||
}
|
||||
g.fillRect(x+2, y+2, 8, 8);
|
||||
|
||||
|
||||
// outter left arc
|
||||
g.setColor(UIManager.getColor("RadioButton.shadow"));
|
||||
g.drawLine(x+4, y+0, x+7, y+0);
|
||||
g.drawLine(x+2, y+1, x+3, y+1);
|
||||
g.drawLine(x+8, y+1, x+9, y+1);
|
||||
g.drawLine(x+1, y+2, x+1, y+3);
|
||||
g.drawLine(x+0, y+4, x+0, y+7);
|
||||
g.drawLine(x+1, y+8, x+1, y+9);
|
||||
|
||||
// outter right arc
|
||||
g.setColor(UIManager.getColor("RadioButton.highlight"));
|
||||
g.drawLine(x+2, y+10, x+3, y+10);
|
||||
g.drawLine(x+4, y+11, x+7, y+11);
|
||||
g.drawLine(x+8, y+10, x+9, y+10);
|
||||
g.drawLine(x+10, y+9, x+10, y+8);
|
||||
g.drawLine(x+11, y+7, x+11, y+4);
|
||||
g.drawLine(x+10, y+3, x+10, y+2);
|
||||
|
||||
|
||||
// inner left arc
|
||||
g.setColor(UIManager.getColor("RadioButton.darkShadow"));
|
||||
g.drawLine(x+4, y+1, x+7, y+1);
|
||||
g.drawLine(x+2, y+2, x+3, y+2);
|
||||
g.drawLine(x+8, y+2, x+9, y+2);
|
||||
g.drawLine(x+2, y+3, x+2, y+3);
|
||||
g.drawLine(x+1, y+4, x+1, y+7);
|
||||
g.drawLine(x+2, y+8, x+2, y+8);
|
||||
|
||||
|
||||
// inner right arc
|
||||
g.setColor(UIManager.getColor("RadioButton.light"));
|
||||
g.drawLine(x+2, y+9, x+3, y+9);
|
||||
g.drawLine(x+4, y+10, x+7, y+10);
|
||||
g.drawLine(x+8, y+9, x+9, y+9);
|
||||
g.drawLine(x+9, y+8, x+9, y+8);
|
||||
g.drawLine(x+10, y+7, x+10, y+4);
|
||||
g.drawLine(x+9, y+3, x+9, y+3);
|
||||
|
||||
|
||||
// indicate whether selected or not
|
||||
if (model.isSelected()) {
|
||||
if (model.isEnabled()) {
|
||||
g.setColor(UIManager.getColor("RadioButton.foreground"));
|
||||
} else {
|
||||
g.setColor(UIManager.getColor("RadioButton.shadow"));
|
||||
}
|
||||
g.fillRect(x+4, y+5, 4, 2);
|
||||
g.fillRect(x+5, y+4, 2, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getIconWidth() {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp != null) {
|
||||
return xp.getSkin(null, Part.BP_RADIOBUTTON).getWidth();
|
||||
} else {
|
||||
return 13;
|
||||
}
|
||||
}
|
||||
|
||||
public int getIconHeight() {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp != null) {
|
||||
return xp.getSkin(null, Part.BP_RADIOBUTTON).getHeight();
|
||||
} else {
|
||||
return 13;
|
||||
}
|
||||
}
|
||||
} // end class RadioButtonIcon
|
||||
|
||||
|
||||
private static class CheckBoxMenuItemIcon implements Icon, UIResource, Serializable
|
||||
{
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
AbstractButton b = (AbstractButton) c;
|
||||
ButtonModel model = b.getModel();
|
||||
boolean isSelected = model.isSelected();
|
||||
if (isSelected) {
|
||||
y = y - getIconHeight() / 2;
|
||||
g.drawLine(x+9, y+3, x+9, y+3);
|
||||
g.drawLine(x+8, y+4, x+9, y+4);
|
||||
g.drawLine(x+7, y+5, x+9, y+5);
|
||||
g.drawLine(x+6, y+6, x+8, y+6);
|
||||
g.drawLine(x+3, y+7, x+7, y+7);
|
||||
g.drawLine(x+4, y+8, x+6, y+8);
|
||||
g.drawLine(x+5, y+9, x+5, y+9);
|
||||
g.drawLine(x+3, y+5, x+3, y+5);
|
||||
g.drawLine(x+3, y+6, x+4, y+6);
|
||||
}
|
||||
}
|
||||
public int getIconWidth() { return 9; }
|
||||
public int getIconHeight() { return 9; }
|
||||
|
||||
} // End class CheckBoxMenuItemIcon
|
||||
|
||||
|
||||
private static class RadioButtonMenuItemIcon implements Icon, UIResource, Serializable
|
||||
{
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
AbstractButton b = (AbstractButton) c;
|
||||
ButtonModel model = b.getModel();
|
||||
if (b.isSelected() == true) {
|
||||
g.fillRoundRect(x+3,y+3, getIconWidth()-6, getIconHeight()-6,
|
||||
4, 4);
|
||||
}
|
||||
}
|
||||
public int getIconWidth() { return 12; }
|
||||
public int getIconHeight() { return 12; }
|
||||
|
||||
} // End class RadioButtonMenuItemIcon
|
||||
|
||||
|
||||
private static class MenuItemCheckIcon implements Icon, UIResource, Serializable{
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
/* For debugging:
|
||||
Color oldColor = g.getColor();
|
||||
g.setColor(Color.orange);
|
||||
g.fill3DRect(x,y,getIconWidth(), getIconHeight(), true);
|
||||
g.setColor(oldColor);
|
||||
*/
|
||||
}
|
||||
public int getIconWidth() { return 9; }
|
||||
public int getIconHeight() { return 9; }
|
||||
|
||||
} // End class MenuItemCheckIcon
|
||||
|
||||
private static class MenuItemArrowIcon implements Icon, UIResource, Serializable {
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
/* For debugging:
|
||||
Color oldColor = g.getColor();
|
||||
g.setColor(Color.green);
|
||||
g.fill3DRect(x,y,getIconWidth(), getIconHeight(), true);
|
||||
g.setColor(oldColor);
|
||||
*/
|
||||
}
|
||||
public int getIconWidth() { return 4; }
|
||||
public int getIconHeight() { return 8; }
|
||||
|
||||
} // End class MenuItemArrowIcon
|
||||
|
||||
private static class MenuArrowIcon implements Icon, UIResource, Serializable {
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (WindowsMenuItemUI.isVistaPainting(xp)) {
|
||||
State state = State.NORMAL;
|
||||
if (c instanceof JMenuItem) {
|
||||
state = ((JMenuItem) c).getModel().isEnabled()
|
||||
? State.NORMAL : State.DISABLED;
|
||||
}
|
||||
Skin skin = xp.getSkin(c, Part.MP_POPUPSUBMENU);
|
||||
if (WindowsGraphicsUtils.isLeftToRight(c)) {
|
||||
skin.paintSkin(g, x, y, state);
|
||||
} else {
|
||||
Graphics2D g2d = (Graphics2D)g.create();
|
||||
g2d.translate(x + skin.getWidth(), y);
|
||||
g2d.scale(-1, 1);
|
||||
skin.paintSkin(g2d, 0, 0, state);
|
||||
g2d.dispose();
|
||||
}
|
||||
} else {
|
||||
g.translate(x,y);
|
||||
if( WindowsGraphicsUtils.isLeftToRight(c) ) {
|
||||
g.drawLine( 0, 0, 0, 7 );
|
||||
g.drawLine( 1, 1, 1, 6 );
|
||||
g.drawLine( 2, 2, 2, 5 );
|
||||
g.drawLine( 3, 3, 3, 4 );
|
||||
} else {
|
||||
g.drawLine( 4, 0, 4, 7 );
|
||||
g.drawLine( 3, 1, 3, 6 );
|
||||
g.drawLine( 2, 2, 2, 5 );
|
||||
g.drawLine( 1, 3, 1, 4 );
|
||||
}
|
||||
g.translate(-x,-y);
|
||||
}
|
||||
}
|
||||
public int getIconWidth() {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (WindowsMenuItemUI.isVistaPainting(xp)) {
|
||||
Skin skin = xp.getSkin(null, Part.MP_POPUPSUBMENU);
|
||||
return skin.getWidth();
|
||||
} else {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
public int getIconHeight() {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (WindowsMenuItemUI.isVistaPainting(xp)) {
|
||||
Skin skin = xp.getSkin(null, Part.MP_POPUPSUBMENU);
|
||||
return skin.getHeight();
|
||||
} else {
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
} // End class MenuArrowIcon
|
||||
|
||||
static class VistaMenuItemCheckIconFactory
|
||||
implements MenuItemCheckIconFactory {
|
||||
private static final int OFFSET = 3;
|
||||
|
||||
public Icon getIcon(JMenuItem component) {
|
||||
return new VistaMenuItemCheckIcon(component);
|
||||
}
|
||||
|
||||
public boolean isCompatible(Object icon, String prefix) {
|
||||
return icon instanceof VistaMenuItemCheckIcon
|
||||
&& ((VistaMenuItemCheckIcon) icon).type == getType(prefix);
|
||||
}
|
||||
|
||||
public Icon getIcon(String type) {
|
||||
return new VistaMenuItemCheckIcon(type);
|
||||
}
|
||||
|
||||
static int getIconWidth() {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
return ((xp != null) ? xp.getSkin(null, Part.MP_POPUPCHECK).getWidth() : 16)
|
||||
+ 2 * OFFSET;
|
||||
}
|
||||
|
||||
private static Class<? extends JMenuItem> getType(Component c) {
|
||||
Class<? extends JMenuItem> rv = null;
|
||||
if (c instanceof JCheckBoxMenuItem) {
|
||||
rv = JCheckBoxMenuItem.class;
|
||||
} else if (c instanceof JRadioButtonMenuItem) {
|
||||
rv = JRadioButtonMenuItem.class;
|
||||
} else if (c instanceof JMenu) {
|
||||
rv = JMenu.class;
|
||||
} else if (c instanceof JMenuItem) {
|
||||
rv = JMenuItem.class;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
private static Class<? extends JMenuItem> getType(String type) {
|
||||
Class<? extends JMenuItem> rv = null;
|
||||
if (type == "CheckBoxMenuItem") {
|
||||
rv = JCheckBoxMenuItem.class;
|
||||
} else if (type == "RadioButtonMenuItem") {
|
||||
rv = JRadioButtonMenuItem.class;
|
||||
} else if (type == "Menu") {
|
||||
rv = JMenu.class;
|
||||
} else if (type == "MenuItem") {
|
||||
rv = JMenuItem.class;
|
||||
} else {
|
||||
// this should never happen
|
||||
rv = JMenuItem.class;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* CheckIcon for JMenuItem, JMenu, JCheckBoxMenuItem and
|
||||
* JRadioButtonMenuItem.
|
||||
* Note: to be used on Vista only.
|
||||
*/
|
||||
private static class VistaMenuItemCheckIcon
|
||||
implements Icon, UIResource, Serializable {
|
||||
|
||||
private final JMenuItem menuItem;
|
||||
private final Class<? extends JMenuItem> type;
|
||||
|
||||
VistaMenuItemCheckIcon(JMenuItem menuItem) {
|
||||
this.type = getType(menuItem);
|
||||
this.menuItem = menuItem;
|
||||
}
|
||||
VistaMenuItemCheckIcon(String type) {
|
||||
this.type = getType(type);
|
||||
this.menuItem = null;
|
||||
}
|
||||
|
||||
public int getIconHeight() {
|
||||
Icon lafIcon = getLaFIcon();
|
||||
if (lafIcon != null) {
|
||||
return lafIcon.getIconHeight();
|
||||
}
|
||||
Icon icon = getIcon();
|
||||
int height = 0;
|
||||
if (icon != null) {
|
||||
height = icon.getIconHeight();
|
||||
} else {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp != null) {
|
||||
Skin skin = xp.getSkin(null, Part.MP_POPUPCHECK);
|
||||
height = skin.getHeight();
|
||||
} else {
|
||||
height = 16;
|
||||
}
|
||||
}
|
||||
height += 2 * OFFSET;
|
||||
return height;
|
||||
}
|
||||
|
||||
public int getIconWidth() {
|
||||
Icon lafIcon = getLaFIcon();
|
||||
if (lafIcon != null) {
|
||||
return lafIcon.getIconWidth();
|
||||
}
|
||||
Icon icon = getIcon();
|
||||
int width = 0;
|
||||
if (icon != null) {
|
||||
width = icon.getIconWidth() + 2 * OFFSET;
|
||||
} else {
|
||||
width = VistaMenuItemCheckIconFactory.getIconWidth();
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
Icon lafIcon = getLaFIcon();
|
||||
if (lafIcon != null) {
|
||||
lafIcon.paintIcon(c, g, x, y);
|
||||
return;
|
||||
}
|
||||
assert menuItem == null || c == menuItem;
|
||||
Icon icon = getIcon();
|
||||
if (type == JCheckBoxMenuItem.class
|
||||
|| type == JRadioButtonMenuItem.class) {
|
||||
AbstractButton b = (AbstractButton) c;
|
||||
if (b.isSelected()) {
|
||||
Part backgroundPart = Part.MP_POPUPCHECKBACKGROUND;
|
||||
Part part = Part.MP_POPUPCHECK;
|
||||
State backgroundState;
|
||||
State state;
|
||||
if (isEnabled(c, null)) {
|
||||
backgroundState =
|
||||
(icon != null) ? State.BITMAP : State.NORMAL;
|
||||
state = (type == JRadioButtonMenuItem.class)
|
||||
? State.BULLETNORMAL
|
||||
: State.CHECKMARKNORMAL;
|
||||
} else {
|
||||
backgroundState = State.DISABLEDPUSHED;
|
||||
state =
|
||||
(type == JRadioButtonMenuItem.class)
|
||||
? State.BULLETDISABLED
|
||||
: State.CHECKMARKDISABLED;
|
||||
}
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp != null) {
|
||||
Skin skin;
|
||||
skin = xp.getSkin(c, backgroundPart);
|
||||
skin.paintSkin(g, x, y,
|
||||
getIconWidth(), getIconHeight(), backgroundState);
|
||||
if (icon == null) {
|
||||
skin = xp.getSkin(c, part);
|
||||
skin.paintSkin(g, x + OFFSET, y + OFFSET, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (icon != null) {
|
||||
icon.paintIcon(c, g, x + OFFSET, y + OFFSET);
|
||||
}
|
||||
}
|
||||
private static WindowsMenuItemUIAccessor getAccessor(
|
||||
JMenuItem menuItem) {
|
||||
WindowsMenuItemUIAccessor rv = null;
|
||||
ButtonUI uiObject = (menuItem != null) ? menuItem.getUI()
|
||||
: null;
|
||||
if (uiObject instanceof WindowsMenuItemUI) {
|
||||
rv = ((WindowsMenuItemUI) uiObject).accessor;
|
||||
} else if (uiObject instanceof WindowsMenuUI) {
|
||||
rv = ((WindowsMenuUI) uiObject).accessor;
|
||||
} else if (uiObject instanceof WindowsCheckBoxMenuItemUI) {
|
||||
rv = ((WindowsCheckBoxMenuItemUI) uiObject).accessor;
|
||||
} else if (uiObject instanceof WindowsRadioButtonMenuItemUI) {
|
||||
rv = ((WindowsRadioButtonMenuItemUI) uiObject).accessor;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
private static boolean isEnabled(Component c, State state) {
|
||||
if (state == null && c instanceof JMenuItem) {
|
||||
WindowsMenuItemUIAccessor accessor =
|
||||
getAccessor((JMenuItem) c);
|
||||
if (accessor != null) {
|
||||
state = accessor.getState((JMenuItem) c);
|
||||
}
|
||||
}
|
||||
if (state == null) {
|
||||
if (c != null) {
|
||||
return c.isEnabled();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return (state != State.DISABLED)
|
||||
&& (state != State.DISABLEDHOT)
|
||||
&& (state != State.DISABLEDPUSHED);
|
||||
}
|
||||
}
|
||||
private Icon getIcon() {
|
||||
Icon rv = null;
|
||||
if (menuItem == null) {
|
||||
return rv;
|
||||
}
|
||||
WindowsMenuItemUIAccessor accessor =
|
||||
getAccessor(menuItem);
|
||||
State state = (accessor != null) ? accessor.getState(menuItem)
|
||||
: null;
|
||||
if (isEnabled(menuItem, null)) {
|
||||
if (state == State.PUSHED) {
|
||||
rv = menuItem.getPressedIcon();
|
||||
} else {
|
||||
rv = menuItem.getIcon();
|
||||
}
|
||||
} else {
|
||||
rv = menuItem.getDisabledIcon();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
/**
|
||||
* Check if developer changed icon in the UI table.
|
||||
*
|
||||
* @return the icon to use or {@code null} if the current one is to
|
||||
* be used
|
||||
*/
|
||||
private Icon getLaFIcon() {
|
||||
// use icon from the UI table if it does not match this one.
|
||||
Icon rv = (Icon) UIManager.getDefaults().get(typeToString(type));
|
||||
if (rv instanceof VistaMenuItemCheckIcon
|
||||
&& ((VistaMenuItemCheckIcon) rv).type == type) {
|
||||
rv = null;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
private static String typeToString(
|
||||
Class<? extends JMenuItem> type) {
|
||||
assert type == JMenuItem.class
|
||||
|| type == JMenu.class
|
||||
|| type == JCheckBoxMenuItem.class
|
||||
|| type == JRadioButtonMenuItem.class;
|
||||
StringBuilder sb = new StringBuilder(type.getName());
|
||||
// remove package name, dot and the first character
|
||||
sb.delete(0, sb.lastIndexOf("J") + 1);
|
||||
sb.append(".checkIcon");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
} // End class VistaMenuItemCheckIconFactory
|
||||
}
|
||||
@@ -0,0 +1,569 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import sun.swing.SwingUtilities2;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyVetoException;
|
||||
|
||||
import static com.sun.java.swing.plaf.windows.TMSchema.*;
|
||||
import static com.sun.java.swing.plaf.windows.XPStyle.Skin;
|
||||
|
||||
public class WindowsInternalFrameTitlePane extends BasicInternalFrameTitlePane {
|
||||
private Color selectedTitleGradientColor;
|
||||
private Color notSelectedTitleGradientColor;
|
||||
private JPopupMenu systemPopupMenu;
|
||||
private JLabel systemLabel;
|
||||
|
||||
private Font titleFont;
|
||||
private int titlePaneHeight;
|
||||
private int buttonWidth, buttonHeight;
|
||||
private boolean hotTrackingOn;
|
||||
|
||||
public WindowsInternalFrameTitlePane(JInternalFrame f) {
|
||||
super(f);
|
||||
}
|
||||
|
||||
protected void addSubComponents() {
|
||||
add(systemLabel);
|
||||
add(iconButton);
|
||||
add(maxButton);
|
||||
add(closeButton);
|
||||
}
|
||||
|
||||
protected void installDefaults() {
|
||||
super.installDefaults();
|
||||
|
||||
titlePaneHeight = UIManager.getInt("InternalFrame.titlePaneHeight");
|
||||
buttonWidth = UIManager.getInt("InternalFrame.titleButtonWidth") - 4;
|
||||
buttonHeight = UIManager.getInt("InternalFrame.titleButtonHeight") - 4;
|
||||
|
||||
Object obj = UIManager.get("InternalFrame.titleButtonToolTipsOn");
|
||||
hotTrackingOn = (obj instanceof Boolean) ? (Boolean)obj : true;
|
||||
|
||||
|
||||
if (XPStyle.getXP() != null) {
|
||||
// Fix for XP bug where sometimes these sizes aren't updated properly
|
||||
// Assume for now that height is correct and derive width using the
|
||||
// ratio from the uxtheme part
|
||||
buttonWidth = buttonHeight;
|
||||
Dimension d = XPStyle.getPartSize(Part.WP_CLOSEBUTTON, State.NORMAL);
|
||||
if (d != null && d.width != 0 && d.height != 0) {
|
||||
buttonWidth = (int) ((float) buttonWidth * d.width / d.height);
|
||||
}
|
||||
} else {
|
||||
buttonWidth += 2;
|
||||
Color activeBorderColor =
|
||||
UIManager.getColor("InternalFrame.activeBorderColor");
|
||||
setBorder(BorderFactory.createLineBorder(activeBorderColor, 1));
|
||||
}
|
||||
// JDK-8039383: initialize these colors because getXP() may return null when theme is changed
|
||||
selectedTitleGradientColor =
|
||||
UIManager.getColor("InternalFrame.activeTitleGradient");
|
||||
notSelectedTitleGradientColor =
|
||||
UIManager.getColor("InternalFrame.inactiveTitleGradient");
|
||||
}
|
||||
|
||||
protected void uninstallListeners() {
|
||||
// Get around protected method in superclass
|
||||
super.uninstallListeners();
|
||||
}
|
||||
|
||||
protected void createButtons() {
|
||||
super.createButtons();
|
||||
if (XPStyle.getXP() != null) {
|
||||
iconButton.setContentAreaFilled(false);
|
||||
maxButton.setContentAreaFilled(false);
|
||||
closeButton.setContentAreaFilled(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setButtonIcons() {
|
||||
super.setButtonIcons();
|
||||
|
||||
if (!hotTrackingOn) {
|
||||
iconButton.setToolTipText(null);
|
||||
maxButton.setToolTipText(null);
|
||||
closeButton.setToolTipText(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
|
||||
paintTitleBackground(g);
|
||||
|
||||
String title = frame.getTitle();
|
||||
if (title != null) {
|
||||
boolean isSelected = frame.isSelected();
|
||||
Font oldFont = g.getFont();
|
||||
Font newFont = (titleFont != null) ? titleFont : getFont();
|
||||
g.setFont(newFont);
|
||||
|
||||
// Center text vertically.
|
||||
FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g, newFont);
|
||||
int baseline = (getHeight() + fm.getAscent() - fm.getLeading() -
|
||||
fm.getDescent()) / 2;
|
||||
|
||||
Rectangle lastIconBounds = new Rectangle(0, 0, 0, 0);
|
||||
if (frame.isIconifiable()) {
|
||||
lastIconBounds = iconButton.getBounds();
|
||||
} else if (frame.isMaximizable()) {
|
||||
lastIconBounds = maxButton.getBounds();
|
||||
} else if (frame.isClosable()) {
|
||||
lastIconBounds = closeButton.getBounds();
|
||||
}
|
||||
|
||||
int titleX;
|
||||
int titleW;
|
||||
int gap = 2;
|
||||
if (WindowsGraphicsUtils.isLeftToRight(frame)) {
|
||||
if (lastIconBounds.x == 0) { // There are no icons
|
||||
lastIconBounds.x = frame.getWidth() - frame.getInsets().right;
|
||||
}
|
||||
titleX = systemLabel.getX() + systemLabel.getWidth() + gap;
|
||||
if (xp != null) {
|
||||
titleX += 2;
|
||||
}
|
||||
titleW = lastIconBounds.x - titleX - gap;
|
||||
} else {
|
||||
if (lastIconBounds.x == 0) { // There are no icons
|
||||
lastIconBounds.x = frame.getInsets().left;
|
||||
}
|
||||
titleW = SwingUtilities2.stringWidth(frame, fm, title);
|
||||
int minTitleX = lastIconBounds.x + lastIconBounds.width + gap;
|
||||
if (xp != null) {
|
||||
minTitleX += 2;
|
||||
}
|
||||
int availableWidth = systemLabel.getX() - gap - minTitleX;
|
||||
if (availableWidth > titleW) {
|
||||
titleX = systemLabel.getX() - gap - titleW;
|
||||
} else {
|
||||
titleX = minTitleX;
|
||||
titleW = availableWidth;
|
||||
}
|
||||
}
|
||||
title = getTitle(frame.getTitle(), fm, titleW);
|
||||
|
||||
if (xp != null) {
|
||||
String shadowType = null;
|
||||
if (isSelected) {
|
||||
shadowType = xp.getString(this, Part.WP_CAPTION,
|
||||
State.ACTIVE, Prop.TEXTSHADOWTYPE);
|
||||
}
|
||||
if ("single".equalsIgnoreCase(shadowType)) {
|
||||
Point shadowOffset = xp.getPoint(this, Part.WP_WINDOW, State.ACTIVE,
|
||||
Prop.TEXTSHADOWOFFSET);
|
||||
Color shadowColor = xp.getColor(this, Part.WP_WINDOW, State.ACTIVE,
|
||||
Prop.TEXTSHADOWCOLOR, null);
|
||||
if (shadowOffset != null && shadowColor != null) {
|
||||
g.setColor(shadowColor);
|
||||
SwingUtilities2.drawString(frame, g, title,
|
||||
titleX + shadowOffset.x,
|
||||
baseline + shadowOffset.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
g.setColor(isSelected ? selectedTextColor : notSelectedTextColor);
|
||||
SwingUtilities2.drawString(frame, g, title, titleX, baseline);
|
||||
g.setFont(oldFont);
|
||||
}
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return getMinimumSize();
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize() {
|
||||
Dimension d = new Dimension(super.getMinimumSize());
|
||||
d.height = titlePaneHeight + 2;
|
||||
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp != null) {
|
||||
// Note: Don't know how to calculate height on XP,
|
||||
// the captionbarheight is 25 but native caption is 30 (maximized 26)
|
||||
if (frame.isMaximum()) {
|
||||
d.height -= 1;
|
||||
} else {
|
||||
d.height += 3;
|
||||
}
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
protected void paintTitleBackground(Graphics g) {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (xp != null) {
|
||||
Part part = frame.isIcon() ? Part.WP_MINCAPTION
|
||||
: (frame.isMaximum() ? Part.WP_MAXCAPTION
|
||||
: Part.WP_CAPTION);
|
||||
State state = frame.isSelected() ? State.ACTIVE : State.INACTIVE;
|
||||
Skin skin = xp.getSkin(this, part);
|
||||
skin.paintSkin(g, 0, 0, getWidth(), getHeight(), state);
|
||||
} else {
|
||||
Boolean gradientsOn = (Boolean)LookAndFeel.getDesktopPropertyValue(
|
||||
"win.frame.captionGradientsOn", Boolean.valueOf(false));
|
||||
if (gradientsOn.booleanValue() && g instanceof Graphics2D) {
|
||||
Graphics2D g2 = (Graphics2D)g;
|
||||
Paint savePaint = g2.getPaint();
|
||||
|
||||
boolean isSelected = frame.isSelected();
|
||||
int w = getWidth();
|
||||
|
||||
if (isSelected) {
|
||||
GradientPaint titleGradient = new GradientPaint(0,0,
|
||||
selectedTitleColor,
|
||||
(int)(w*.75),0,
|
||||
selectedTitleGradientColor);
|
||||
g2.setPaint(titleGradient);
|
||||
} else {
|
||||
GradientPaint titleGradient = new GradientPaint(0,0,
|
||||
notSelectedTitleColor,
|
||||
(int)(w*.75),0,
|
||||
notSelectedTitleGradientColor);
|
||||
g2.setPaint(titleGradient);
|
||||
}
|
||||
g2.fillRect(0, 0, getWidth(), getHeight());
|
||||
g2.setPaint(savePaint);
|
||||
} else {
|
||||
super.paintTitleBackground(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void assembleSystemMenu() {
|
||||
systemPopupMenu = new JPopupMenu();
|
||||
addSystemMenuItems(systemPopupMenu);
|
||||
enableActions();
|
||||
systemLabel = new JLabel(frame.getFrameIcon()) {
|
||||
protected void paintComponent(Graphics g) {
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int w = getWidth();
|
||||
int h = getHeight();
|
||||
g = g.create(); // Create scratch graphics
|
||||
if (isOpaque()) {
|
||||
g.setColor(getBackground());
|
||||
g.fillRect(0, 0, w, h);
|
||||
}
|
||||
Icon icon = getIcon();
|
||||
int iconWidth;
|
||||
int iconHeight;
|
||||
if (icon != null &&
|
||||
(iconWidth = icon.getIconWidth()) > 0 &&
|
||||
(iconHeight = icon.getIconHeight()) > 0) {
|
||||
|
||||
// Set drawing scale to make icon scale to our desired size
|
||||
double drawScale;
|
||||
if (iconWidth > iconHeight) {
|
||||
// Center icon vertically
|
||||
y = (h - w*iconHeight/iconWidth) / 2;
|
||||
drawScale = w / (double)iconWidth;
|
||||
} else {
|
||||
// Center icon horizontally
|
||||
x = (w - h*iconWidth/iconHeight) / 2;
|
||||
drawScale = h / (double)iconHeight;
|
||||
}
|
||||
((Graphics2D)g).translate(x, y);
|
||||
((Graphics2D)g).scale(drawScale, drawScale);
|
||||
icon.paintIcon(this, g, 0, 0);
|
||||
}
|
||||
g.dispose();
|
||||
}
|
||||
};
|
||||
systemLabel.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getClickCount() == 2 && frame.isClosable() &&
|
||||
!frame.isIcon()) {
|
||||
systemPopupMenu.setVisible(false);
|
||||
frame.doDefaultCloseAction();
|
||||
}
|
||||
else {
|
||||
super.mouseClicked(e);
|
||||
}
|
||||
}
|
||||
public void mousePressed(MouseEvent e) {
|
||||
try {
|
||||
frame.setSelected(true);
|
||||
} catch(PropertyVetoException pve) {
|
||||
}
|
||||
showSystemPopupMenu(e.getComponent());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void addSystemMenuItems(JPopupMenu menu) {
|
||||
JMenuItem mi = menu.add(restoreAction);
|
||||
mi.setMnemonic(getButtonMnemonic("restore"));
|
||||
mi = menu.add(moveAction);
|
||||
mi.setMnemonic(getButtonMnemonic("move"));
|
||||
mi = menu.add(sizeAction);
|
||||
mi.setMnemonic(getButtonMnemonic("size"));
|
||||
mi = menu.add(iconifyAction);
|
||||
mi.setMnemonic(getButtonMnemonic("minimize"));
|
||||
mi = menu.add(maximizeAction);
|
||||
mi.setMnemonic(getButtonMnemonic("maximize"));
|
||||
menu.add(new JSeparator());
|
||||
mi = menu.add(closeAction);
|
||||
mi.setMnemonic(getButtonMnemonic("close"));
|
||||
}
|
||||
|
||||
private static int getButtonMnemonic(String button) {
|
||||
try {
|
||||
return Integer.parseInt(UIManager.getString(
|
||||
"InternalFrameTitlePane." + button + "Button.mnemonic"));
|
||||
} catch (NumberFormatException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
protected void showSystemMenu(){
|
||||
showSystemPopupMenu(systemLabel);
|
||||
}
|
||||
|
||||
private void showSystemPopupMenu(Component invoker){
|
||||
Dimension dim = new Dimension();
|
||||
Border border = frame.getBorder();
|
||||
if (border != null) {
|
||||
dim.width += border.getBorderInsets(frame).left +
|
||||
border.getBorderInsets(frame).right;
|
||||
dim.height += border.getBorderInsets(frame).bottom +
|
||||
border.getBorderInsets(frame).top;
|
||||
}
|
||||
if (!frame.isIcon()) {
|
||||
systemPopupMenu.show(invoker,
|
||||
getX() - dim.width,
|
||||
getY() + getHeight() - dim.height);
|
||||
} else {
|
||||
systemPopupMenu.show(invoker,
|
||||
getX() - dim.width,
|
||||
getY() - systemPopupMenu.getPreferredSize().height -
|
||||
dim.height);
|
||||
}
|
||||
}
|
||||
|
||||
protected PropertyChangeListener createPropertyChangeListener() {
|
||||
return new WindowsPropertyChangeHandler();
|
||||
}
|
||||
|
||||
protected LayoutManager createLayout() {
|
||||
return new WindowsTitlePaneLayout();
|
||||
}
|
||||
|
||||
public class WindowsTitlePaneLayout extends BasicInternalFrameTitlePane.TitlePaneLayout {
|
||||
private Insets captionMargin = null;
|
||||
private Insets contentMargin = null;
|
||||
private XPStyle xp = XPStyle.getXP();
|
||||
|
||||
WindowsTitlePaneLayout() {
|
||||
if (xp != null) {
|
||||
Component c = WindowsInternalFrameTitlePane.this;
|
||||
captionMargin = xp.getMargin(c, Part.WP_CAPTION, null, Prop.CAPTIONMARGINS);
|
||||
contentMargin = xp.getMargin(c, Part.WP_CAPTION, null, Prop.CONTENTMARGINS);
|
||||
}
|
||||
if (captionMargin == null) {
|
||||
captionMargin = new Insets(0, 2, 0, 2);
|
||||
}
|
||||
if (contentMargin == null) {
|
||||
contentMargin = new Insets(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private int layoutButton(JComponent button, Part part,
|
||||
int x, int y, int w, int h, int gap,
|
||||
boolean leftToRight) {
|
||||
if (!leftToRight) {
|
||||
x -= w;
|
||||
}
|
||||
button.setBounds(x, y, w, h);
|
||||
if (leftToRight) {
|
||||
x += w + 2;
|
||||
} else {
|
||||
x -= 2;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
public void layoutContainer(Container c) {
|
||||
boolean leftToRight = WindowsGraphicsUtils.isLeftToRight(frame);
|
||||
int x, y;
|
||||
int w = getWidth();
|
||||
int h = getHeight();
|
||||
|
||||
// System button
|
||||
// Note: this icon is square, but the buttons aren't always.
|
||||
int iconSize = (xp != null) ? (h-2)*6/10 : h-4;
|
||||
if (xp != null) {
|
||||
x = (leftToRight) ? captionMargin.left + 2 : w - captionMargin.right - 2;
|
||||
} else {
|
||||
x = (leftToRight) ? captionMargin.left : w - captionMargin.right;
|
||||
}
|
||||
y = (h - iconSize) / 2;
|
||||
layoutButton(systemLabel, Part.WP_SYSBUTTON,
|
||||
x, y, iconSize, iconSize, 0,
|
||||
leftToRight);
|
||||
|
||||
// Right hand buttons
|
||||
if (xp != null) {
|
||||
x = (leftToRight) ? w - captionMargin.right - 2 : captionMargin.left + 2;
|
||||
y = 1; // XP seems to ignore margins and offset here
|
||||
if (frame.isMaximum()) {
|
||||
y += 1;
|
||||
} else {
|
||||
y += 5;
|
||||
}
|
||||
} else {
|
||||
x = (leftToRight) ? w - captionMargin.right : captionMargin.left;
|
||||
y = (h - buttonHeight) / 2;
|
||||
}
|
||||
|
||||
if(frame.isClosable()) {
|
||||
x = layoutButton(closeButton, Part.WP_CLOSEBUTTON,
|
||||
x, y, buttonWidth, buttonHeight, 2,
|
||||
!leftToRight);
|
||||
}
|
||||
|
||||
if(frame.isMaximizable()) {
|
||||
x = layoutButton(maxButton, Part.WP_MAXBUTTON,
|
||||
x, y, buttonWidth, buttonHeight, (xp != null) ? 2 : 0,
|
||||
!leftToRight);
|
||||
}
|
||||
|
||||
if(frame.isIconifiable()) {
|
||||
layoutButton(iconButton, Part.WP_MINBUTTON,
|
||||
x, y, buttonWidth, buttonHeight, 0,
|
||||
!leftToRight);
|
||||
}
|
||||
}
|
||||
} // end WindowsTitlePaneLayout
|
||||
|
||||
public class WindowsPropertyChangeHandler extends PropertyChangeHandler {
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
String prop = evt.getPropertyName();
|
||||
|
||||
// Update the internal frame icon for the system menu.
|
||||
if (JInternalFrame.FRAME_ICON_PROPERTY.equals(prop) &&
|
||||
systemLabel != null) {
|
||||
systemLabel.setIcon(frame.getFrameIcon());
|
||||
}
|
||||
|
||||
super.propertyChange(evt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A versatile Icon implementation which can take an array of Icon
|
||||
* instances (typically <code>ImageIcon</code>s) and choose one that gives the best
|
||||
* quality for a given Graphics2D scale factor when painting.
|
||||
* <p>
|
||||
* The class is public so it can be instantiated by UIDefaults.ProxyLazyValue.
|
||||
* <p>
|
||||
* Note: We assume here that icons are square.
|
||||
*/
|
||||
public static class ScalableIconUIResource implements Icon, UIResource {
|
||||
// We can use an arbitrary size here because we scale to it in paintIcon()
|
||||
private static final int SIZE = 16;
|
||||
|
||||
private Icon[] icons;
|
||||
|
||||
/**
|
||||
* @params objects an array of Icon or UIDefaults.LazyValue
|
||||
* <p>
|
||||
* The constructor is public so it can be called by UIDefaults.ProxyLazyValue.
|
||||
*/
|
||||
public ScalableIconUIResource(Object[] objects) {
|
||||
this.icons = new Icon[objects.length];
|
||||
|
||||
for (int i = 0; i < objects.length; i++) {
|
||||
if (objects[i] instanceof UIDefaults.LazyValue) {
|
||||
icons[i] = (Icon)((UIDefaults.LazyValue)objects[i]).createValue(null);
|
||||
} else {
|
||||
icons[i] = (Icon)objects[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the <code>Icon</code> closest to the requested size
|
||||
*/
|
||||
protected Icon getBestIcon(int size) {
|
||||
if (icons != null && icons.length > 0) {
|
||||
int bestIndex = 0;
|
||||
int minDiff = Integer.MAX_VALUE;
|
||||
for (int i=0; i < icons.length; i++) {
|
||||
Icon icon = icons[i];
|
||||
int iconSize;
|
||||
if (icon != null && (iconSize = icon.getIconWidth()) > 0) {
|
||||
int diff = Math.abs(iconSize - size);
|
||||
if (diff < minDiff) {
|
||||
minDiff = diff;
|
||||
bestIndex = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return icons[bestIndex];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
Graphics2D g2d = (Graphics2D)g.create();
|
||||
// Calculate how big our drawing area is in pixels
|
||||
// Assume we are square
|
||||
int size = getIconWidth();
|
||||
double scale = g2d.getTransform().getScaleX();
|
||||
Icon icon = getBestIcon((int)(size * scale));
|
||||
int iconSize;
|
||||
if (icon != null && (iconSize = icon.getIconWidth()) > 0) {
|
||||
// Set drawing scale to make icon act true to our reported size
|
||||
double drawScale = size / (double)iconSize;
|
||||
g2d.translate(x, y);
|
||||
g2d.scale(drawScale, drawScale);
|
||||
icon.paintIcon(c, g2d, 0, 0);
|
||||
}
|
||||
g2d.dispose();
|
||||
}
|
||||
|
||||
public int getIconWidth() {
|
||||
return SIZE;
|
||||
}
|
||||
|
||||
public int getIconHeight() {
|
||||
return SIZE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import java.awt.*;
|
||||
import java.beans.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
|
||||
import static com.sun.java.swing.plaf.windows.TMSchema.*;
|
||||
import static com.sun.java.swing.plaf.windows.XPStyle.Skin;
|
||||
|
||||
/**
|
||||
* Windows rendition of the component.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*/
|
||||
public class WindowsInternalFrameUI extends BasicInternalFrameUI
|
||||
{
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
|
||||
public void installDefaults() {
|
||||
super.installDefaults();
|
||||
|
||||
if (xp != null) {
|
||||
frame.setBorder(new XPBorder());
|
||||
} else {
|
||||
frame.setBorder(UIManager.getBorder("InternalFrame.border"));
|
||||
}
|
||||
}
|
||||
|
||||
public void installUI(JComponent c) {
|
||||
super.installUI(c);
|
||||
|
||||
LookAndFeel.installProperty(c, "opaque",
|
||||
xp == null? Boolean.TRUE : Boolean.FALSE);
|
||||
}
|
||||
|
||||
public void uninstallDefaults() {
|
||||
frame.setBorder(null);
|
||||
super.uninstallDefaults();
|
||||
}
|
||||
|
||||
public static ComponentUI createUI(JComponent b) {
|
||||
return new WindowsInternalFrameUI((JInternalFrame)b);
|
||||
}
|
||||
|
||||
public WindowsInternalFrameUI(JInternalFrame w){
|
||||
super(w);
|
||||
}
|
||||
|
||||
protected DesktopManager createDesktopManager(){
|
||||
return new WindowsDesktopManager();
|
||||
}
|
||||
|
||||
protected JComponent createNorthPane(JInternalFrame w) {
|
||||
titlePane = new WindowsInternalFrameTitlePane(w);
|
||||
return titlePane;
|
||||
}
|
||||
|
||||
private class XPBorder extends AbstractBorder {
|
||||
private Skin leftSkin = xp.getSkin(frame, Part.WP_FRAMELEFT);
|
||||
private Skin rightSkin = xp.getSkin(frame, Part.WP_FRAMERIGHT);
|
||||
private Skin bottomSkin = xp.getSkin(frame, Part.WP_FRAMEBOTTOM);
|
||||
|
||||
/**
|
||||
* @param x the x position of the painted border
|
||||
* @param y the y position of the painted border
|
||||
* @param width the width of the painted border
|
||||
* @param height the height of the painted border
|
||||
*/
|
||||
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
|
||||
State state = ((JInternalFrame)c).isSelected() ? State.ACTIVE : State.INACTIVE;
|
||||
int topBorderHeight = (titlePane != null) ? titlePane.getSize().height : 0;
|
||||
|
||||
bottomSkin.paintSkin(g, 0, height-bottomSkin.getHeight(),
|
||||
width, bottomSkin.getHeight(),
|
||||
state);
|
||||
|
||||
leftSkin.paintSkin(g, 0, topBorderHeight-1,
|
||||
leftSkin.getWidth(), height-topBorderHeight-bottomSkin.getHeight()+2,
|
||||
state);
|
||||
|
||||
rightSkin.paintSkin(g, width-rightSkin.getWidth(), topBorderHeight-1,
|
||||
rightSkin.getWidth(), height-topBorderHeight-bottomSkin.getHeight()+2,
|
||||
state);
|
||||
|
||||
}
|
||||
|
||||
public Insets getBorderInsets(Component c, Insets insets) {
|
||||
insets.top = 4;
|
||||
insets.left = leftSkin.getWidth();
|
||||
insets.right = rightSkin.getWidth();
|
||||
insets.bottom = bottomSkin.getHeight();
|
||||
|
||||
return insets;
|
||||
}
|
||||
|
||||
public boolean isBorderOpaque() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
112
jdkSrc/jdk8/com/sun/java/swing/plaf/windows/WindowsLabelUI.java
Normal file
112
jdkSrc/jdk8/com/sun/java/swing/plaf/windows/WindowsLabelUI.java
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import sun.swing.SwingUtilities2;
|
||||
import sun.awt.AppContext;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
|
||||
import javax.swing.plaf.basic.BasicLabelUI;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Windows rendition of the component.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*/
|
||||
public class WindowsLabelUI extends BasicLabelUI {
|
||||
|
||||
private static final Object WINDOWS_LABEL_UI_KEY = new Object();
|
||||
|
||||
// ********************************
|
||||
// Create PLAF
|
||||
// ********************************
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
AppContext appContext = AppContext.getAppContext();
|
||||
WindowsLabelUI windowsLabelUI =
|
||||
(WindowsLabelUI) appContext.get(WINDOWS_LABEL_UI_KEY);
|
||||
if (windowsLabelUI == null) {
|
||||
windowsLabelUI = new WindowsLabelUI();
|
||||
appContext.put(WINDOWS_LABEL_UI_KEY, windowsLabelUI);
|
||||
}
|
||||
return windowsLabelUI;
|
||||
}
|
||||
|
||||
protected void paintEnabledText(JLabel l, Graphics g, String s,
|
||||
int textX, int textY) {
|
||||
int mnemonicIndex = l.getDisplayedMnemonicIndex();
|
||||
// W2K Feature: Check to see if the Underscore should be rendered.
|
||||
if (WindowsLookAndFeel.isMnemonicHidden() == true) {
|
||||
mnemonicIndex = -1;
|
||||
}
|
||||
|
||||
g.setColor(l.getForeground());
|
||||
SwingUtilities2.drawStringUnderlineCharAt(l, g, s, mnemonicIndex,
|
||||
textX, textY);
|
||||
}
|
||||
|
||||
protected void paintDisabledText(JLabel l, Graphics g, String s,
|
||||
int textX, int textY) {
|
||||
int mnemonicIndex = l.getDisplayedMnemonicIndex();
|
||||
// W2K Feature: Check to see if the Underscore should be rendered.
|
||||
if (WindowsLookAndFeel.isMnemonicHidden() == true) {
|
||||
mnemonicIndex = -1;
|
||||
}
|
||||
if ( UIManager.getColor("Label.disabledForeground") instanceof Color &&
|
||||
UIManager.getColor("Label.disabledShadow") instanceof Color) {
|
||||
g.setColor( UIManager.getColor("Label.disabledShadow") );
|
||||
SwingUtilities2.drawStringUnderlineCharAt(l, g, s,
|
||||
mnemonicIndex,
|
||||
textX + 1, textY + 1);
|
||||
g.setColor( UIManager.getColor("Label.disabledForeground") );
|
||||
SwingUtilities2.drawStringUnderlineCharAt(l, g, s,
|
||||
mnemonicIndex,
|
||||
textX, textY);
|
||||
} else {
|
||||
Color background = l.getBackground();
|
||||
g.setColor(background.brighter());
|
||||
SwingUtilities2.drawStringUnderlineCharAt(l,g, s, mnemonicIndex,
|
||||
textX + 1, textY + 1);
|
||||
g.setColor(background.darker());
|
||||
SwingUtilities2.drawStringUnderlineCharAt(l,g, s, mnemonicIndex,
|
||||
textX, textY);
|
||||
}
|
||||
}
|
||||
}
|
||||
2639
jdkSrc/jdk8/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java
Normal file
2639
jdkSrc/jdk8/com/sun/java/swing/plaf/windows/WindowsLookAndFeel.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import javax.swing.plaf.basic.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.ActionMapUIResource;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.HierarchyEvent;
|
||||
import java.awt.event.HierarchyListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
import java.awt.event.WindowStateListener;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
import com.sun.java.swing.plaf.windows.TMSchema.*;
|
||||
import com.sun.java.swing.plaf.windows.XPStyle.*;
|
||||
|
||||
/**
|
||||
* Windows rendition of the component.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*/
|
||||
public class WindowsMenuBarUI extends BasicMenuBarUI
|
||||
{
|
||||
/* to be accessed on the EDT only */
|
||||
private WindowListener windowListener = null;
|
||||
private HierarchyListener hierarchyListener = null;
|
||||
private Window window = null;
|
||||
|
||||
public static ComponentUI createUI(JComponent x) {
|
||||
return new WindowsMenuBarUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void uninstallListeners() {
|
||||
uninstallWindowListener();
|
||||
if (hierarchyListener != null) {
|
||||
menuBar.removeHierarchyListener(hierarchyListener);
|
||||
hierarchyListener = null;
|
||||
}
|
||||
super.uninstallListeners();
|
||||
}
|
||||
private void installWindowListener() {
|
||||
if (windowListener == null) {
|
||||
Component component = menuBar.getTopLevelAncestor();
|
||||
if (component instanceof Window) {
|
||||
window = (Window) component;
|
||||
windowListener = new WindowAdapter() {
|
||||
@Override
|
||||
public void windowActivated(WindowEvent e) {
|
||||
menuBar.repaint();
|
||||
}
|
||||
@Override
|
||||
public void windowDeactivated(WindowEvent e) {
|
||||
menuBar.repaint();
|
||||
}
|
||||
};
|
||||
((Window) component).addWindowListener(windowListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void uninstallWindowListener() {
|
||||
if (windowListener != null && window != null) {
|
||||
window.removeWindowListener(windowListener);
|
||||
}
|
||||
window = null;
|
||||
windowListener = null;
|
||||
}
|
||||
@Override
|
||||
protected void installListeners() {
|
||||
if (WindowsLookAndFeel.isOnVista()) {
|
||||
installWindowListener();
|
||||
hierarchyListener =
|
||||
new HierarchyListener() {
|
||||
public void hierarchyChanged(HierarchyEvent e) {
|
||||
if ((e.getChangeFlags()
|
||||
& HierarchyEvent.DISPLAYABILITY_CHANGED) != 0) {
|
||||
if (menuBar.isDisplayable()) {
|
||||
installWindowListener();
|
||||
} else {
|
||||
uninstallWindowListener();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
menuBar.addHierarchyListener(hierarchyListener);
|
||||
}
|
||||
super.installListeners();
|
||||
}
|
||||
|
||||
protected void installKeyboardActions() {
|
||||
super.installKeyboardActions();
|
||||
ActionMap map = SwingUtilities.getUIActionMap(menuBar);
|
||||
if (map == null) {
|
||||
map = new ActionMapUIResource();
|
||||
SwingUtilities.replaceUIActionMap(menuBar, map);
|
||||
}
|
||||
map.put("takeFocus", new TakeFocus());
|
||||
}
|
||||
|
||||
/**
|
||||
* Action that activates the menu (e.g. when F10 is pressed).
|
||||
* Unlike BasicMenuBarUI.TakeFocus, this Action will not show menu popup.
|
||||
*/
|
||||
private static class TakeFocus extends AbstractAction {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JMenuBar menuBar = (JMenuBar)e.getSource();
|
||||
JMenu menu = menuBar.getMenu(0);
|
||||
if (menu != null) {
|
||||
MenuSelectionManager msm =
|
||||
MenuSelectionManager.defaultManager();
|
||||
MenuElement path[] = new MenuElement[2];
|
||||
path[0] = (MenuElement)menuBar;
|
||||
path[1] = (MenuElement)menu;
|
||||
msm.setSelectedPath(path);
|
||||
|
||||
// show mnemonics
|
||||
WindowsLookAndFeel.setMnemonicHidden(false);
|
||||
WindowsLookAndFeel.repaintRootPane(menuBar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g, JComponent c) {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
if (WindowsMenuItemUI.isVistaPainting(xp)) {
|
||||
Skin skin;
|
||||
skin = xp.getSkin(c, Part.MP_BARBACKGROUND);
|
||||
int width = c.getWidth();
|
||||
int height = c.getHeight();
|
||||
State state = isActive(c) ? State.ACTIVE : State.INACTIVE;
|
||||
skin.paintSkin(g, 0, 0, width, height, state);
|
||||
} else {
|
||||
super.paint(g, c);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if component belongs to an active window.
|
||||
* @param c component to check
|
||||
* @return true if component belongs to an active window
|
||||
*/
|
||||
static boolean isActive(JComponent c) {
|
||||
JRootPane rootPane = c.getRootPane();
|
||||
if (rootPane != null) {
|
||||
Component component = rootPane.getParent();
|
||||
if (component instanceof Window) {
|
||||
return ((Window) component).isActive();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
|
||||
import sun.swing.SwingUtilities2;
|
||||
|
||||
import com.sun.java.swing.plaf.windows.TMSchema.*;
|
||||
import com.sun.java.swing.plaf.windows.XPStyle.*;
|
||||
|
||||
/**
|
||||
* Windows rendition of the component.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*
|
||||
* @author Igor Kushnirskiy
|
||||
*/
|
||||
|
||||
public class WindowsMenuItemUI extends BasicMenuItemUI {
|
||||
final WindowsMenuItemUIAccessor accessor =
|
||||
new WindowsMenuItemUIAccessor() {
|
||||
|
||||
public JMenuItem getMenuItem() {
|
||||
return menuItem;
|
||||
}
|
||||
|
||||
public State getState(JMenuItem menuItem) {
|
||||
return WindowsMenuItemUI.getState(this, menuItem);
|
||||
}
|
||||
|
||||
public Part getPart(JMenuItem menuItem) {
|
||||
return WindowsMenuItemUI.getPart(this, menuItem);
|
||||
}
|
||||
};
|
||||
public static ComponentUI createUI(JComponent c) {
|
||||
return new WindowsMenuItemUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method which renders the text of the current menu item.
|
||||
* <p>
|
||||
* @param g Graphics context
|
||||
* @param menuItem Current menu item to render
|
||||
* @param textRect Bounding rectangle to render the text.
|
||||
* @param text String to render
|
||||
*/
|
||||
protected void paintText(Graphics g, JMenuItem menuItem,
|
||||
Rectangle textRect, String text) {
|
||||
if (WindowsMenuItemUI.isVistaPainting()) {
|
||||
WindowsMenuItemUI.paintText(accessor, g, menuItem, textRect, text);
|
||||
return;
|
||||
}
|
||||
ButtonModel model = menuItem.getModel();
|
||||
Color oldColor = g.getColor();
|
||||
|
||||
if(model.isEnabled() &&
|
||||
(model.isArmed() || (menuItem instanceof JMenu &&
|
||||
model.isSelected()))) {
|
||||
g.setColor(selectionForeground); // Uses protected field.
|
||||
}
|
||||
|
||||
WindowsGraphicsUtils.paintText(g, menuItem, textRect, text, 0);
|
||||
|
||||
g.setColor(oldColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintBackground(Graphics g, JMenuItem menuItem,
|
||||
Color bgColor) {
|
||||
if (WindowsMenuItemUI.isVistaPainting()) {
|
||||
WindowsMenuItemUI.paintBackground(accessor, g, menuItem, bgColor);
|
||||
return;
|
||||
}
|
||||
super.paintBackground(g, menuItem, bgColor);
|
||||
}
|
||||
|
||||
static void paintBackground(WindowsMenuItemUIAccessor menuItemUI,
|
||||
Graphics g, JMenuItem menuItem, Color bgColor) {
|
||||
XPStyle xp = XPStyle.getXP();
|
||||
assert isVistaPainting(xp);
|
||||
if (isVistaPainting(xp)) {
|
||||
int menuWidth = menuItem.getWidth();
|
||||
int menuHeight = menuItem.getHeight();
|
||||
if (menuItem.isOpaque()) {
|
||||
Color oldColor = g.getColor();
|
||||
g.setColor(menuItem.getBackground());
|
||||
g.fillRect(0,0, menuWidth, menuHeight);
|
||||
g.setColor(oldColor);
|
||||
}
|
||||
Part part = menuItemUI.getPart(menuItem);
|
||||
Skin skin = xp.getSkin(menuItem, part);
|
||||
skin.paintSkin(g, 0 , 0,
|
||||
menuWidth,
|
||||
menuHeight,
|
||||
menuItemUI.getState(menuItem));
|
||||
}
|
||||
}
|
||||
|
||||
static void paintText(WindowsMenuItemUIAccessor menuItemUI, Graphics g,
|
||||
JMenuItem menuItem, Rectangle textRect,
|
||||
String text) {
|
||||
assert isVistaPainting();
|
||||
if (isVistaPainting()) {
|
||||
State state = menuItemUI.getState(menuItem);
|
||||
|
||||
/* part of it copied from WindowsGraphicsUtils.java */
|
||||
FontMetrics fm = SwingUtilities2.getFontMetrics(menuItem, g);
|
||||
int mnemIndex = menuItem.getDisplayedMnemonicIndex();
|
||||
// W2K Feature: Check to see if the Underscore should be rendered.
|
||||
if (WindowsLookAndFeel.isMnemonicHidden() == true) {
|
||||
mnemIndex = -1;
|
||||
}
|
||||
WindowsGraphicsUtils.paintXPText(menuItem,
|
||||
menuItemUI.getPart(menuItem), state,
|
||||
g, textRect.x,
|
||||
textRect.y + fm.getAscent(),
|
||||
text, mnemIndex);
|
||||
}
|
||||
}
|
||||
|
||||
static State getState(WindowsMenuItemUIAccessor menuItemUI, JMenuItem menuItem) {
|
||||
State state;
|
||||
ButtonModel model = menuItem.getModel();
|
||||
if (model.isArmed()) {
|
||||
state = (model.isEnabled()) ? State.HOT : State.DISABLEDHOT;
|
||||
} else {
|
||||
state = (model.isEnabled()) ? State.NORMAL : State.DISABLED;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
static Part getPart(WindowsMenuItemUIAccessor menuItemUI, JMenuItem menuItem) {
|
||||
return Part.MP_POPUPITEM;
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO idk can we use XPStyle.isVista?
|
||||
* is it possible that in some theme some Vista parts are not defined while
|
||||
* others are?
|
||||
*/
|
||||
static boolean isVistaPainting(final XPStyle xp) {
|
||||
return xp != null && xp.isSkinDefined(null, Part.MP_POPUPITEM);
|
||||
}
|
||||
|
||||
static boolean isVistaPainting() {
|
||||
return isVistaPainting(XPStyle.getXP());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JMenuItem;
|
||||
|
||||
import com.sun.java.swing.plaf.windows.TMSchema.Part;
|
||||
import com.sun.java.swing.plaf.windows.TMSchema.State;
|
||||
|
||||
/**
|
||||
* Accessor interface for WindowsMenuItemUI to allow for "multiple implementation
|
||||
* inheritance".
|
||||
*
|
||||
* @author Igor Kushnirskiy
|
||||
*/
|
||||
interface WindowsMenuItemUIAccessor {
|
||||
JMenuItem getMenuItem();
|
||||
State getState(JMenuItem menuItem);
|
||||
Part getPart(JMenuItem menuItem);
|
||||
}
|
||||
295
jdkSrc/jdk8/com/sun/java/swing/plaf/windows/WindowsMenuUI.java
Normal file
295
jdkSrc/jdk8/com/sun/java/swing/plaf/windows/WindowsMenuUI.java
Normal file
@@ -0,0 +1,295 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2007, 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.basic.BasicMenuUI;
|
||||
import javax.swing.event.MouseInputListener;
|
||||
import javax.swing.*;
|
||||
|
||||
import com.sun.java.swing.plaf.windows.TMSchema.Part;
|
||||
import com.sun.java.swing.plaf.windows.TMSchema.State;
|
||||
|
||||
/**
|
||||
* Windows rendition of the component.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*/
|
||||
public class WindowsMenuUI extends BasicMenuUI {
|
||||
protected Integer menuBarHeight;
|
||||
protected boolean hotTrackingOn;
|
||||
|
||||
final WindowsMenuItemUIAccessor accessor =
|
||||
new WindowsMenuItemUIAccessor() {
|
||||
|
||||
public JMenuItem getMenuItem() {
|
||||
return menuItem;
|
||||
}
|
||||
|
||||
public State getState(JMenuItem menu) {
|
||||
State state = menu.isEnabled() ? State.NORMAL
|
||||
: State.DISABLED;
|
||||
ButtonModel model = menu.getModel();
|
||||
if (model.isArmed() || model.isSelected()) {
|
||||
state = (menu.isEnabled()) ? State.PUSHED
|
||||
: State.DISABLEDPUSHED;
|
||||
} else if (model.isRollover()
|
||||
&& ((JMenu) menu).isTopLevelMenu()) {
|
||||
/*
|
||||
* Only paint rollover if no other menu on menubar is
|
||||
* selected
|
||||
*/
|
||||
State stateTmp = state;
|
||||
state = (menu.isEnabled()) ? State.HOT
|
||||
: State.DISABLEDHOT;
|
||||
for (MenuElement menuElement :
|
||||
((JMenuBar) menu.getParent()).getSubElements()) {
|
||||
if (((JMenuItem) menuElement).isSelected()) {
|
||||
state = stateTmp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//non top level menus have HOT state instead of PUSHED
|
||||
if (!((JMenu) menu).isTopLevelMenu()) {
|
||||
if (state == State.PUSHED) {
|
||||
state = State.HOT;
|
||||
} else if (state == State.DISABLEDPUSHED) {
|
||||
state = State.DISABLEDHOT;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* on Vista top level menu for non active frame looks disabled
|
||||
*/
|
||||
if (((JMenu) menu).isTopLevelMenu() && WindowsMenuItemUI.isVistaPainting()) {
|
||||
if (! WindowsMenuBarUI.isActive(menu)) {
|
||||
state = State.DISABLED;
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
public Part getPart(JMenuItem menuItem) {
|
||||
return ((JMenu) menuItem).isTopLevelMenu() ? Part.MP_BARITEM
|
||||
: Part.MP_POPUPITEM;
|
||||
}
|
||||
};
|
||||
public static ComponentUI createUI(JComponent x) {
|
||||
return new WindowsMenuUI();
|
||||
}
|
||||
|
||||
protected void installDefaults() {
|
||||
super.installDefaults();
|
||||
if (!WindowsLookAndFeel.isClassicWindows()) {
|
||||
menuItem.setRolloverEnabled(true);
|
||||
}
|
||||
|
||||
menuBarHeight = (Integer)UIManager.getInt("MenuBar.height");
|
||||
|
||||
Object obj = UIManager.get("MenuBar.rolloverEnabled");
|
||||
hotTrackingOn = (obj instanceof Boolean) ? (Boolean)obj : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the background of the menu.
|
||||
* @since 1.4
|
||||
*/
|
||||
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
|
||||
if (WindowsMenuItemUI.isVistaPainting()) {
|
||||
WindowsMenuItemUI.paintBackground(accessor, g, menuItem, bgColor);
|
||||
return;
|
||||
}
|
||||
|
||||
JMenu menu = (JMenu)menuItem;
|
||||
ButtonModel model = menu.getModel();
|
||||
|
||||
// Use superclass method for the old Windows LAF,
|
||||
// for submenus, and for XP toplevel if selected or pressed
|
||||
if (WindowsLookAndFeel.isClassicWindows() ||
|
||||
!menu.isTopLevelMenu() ||
|
||||
(XPStyle.getXP() != null && (model.isArmed() || model.isSelected()))) {
|
||||
|
||||
super.paintBackground(g, menu, bgColor);
|
||||
return;
|
||||
}
|
||||
|
||||
Color oldColor = g.getColor();
|
||||
int menuWidth = menu.getWidth();
|
||||
int menuHeight = menu.getHeight();
|
||||
|
||||
UIDefaults table = UIManager.getLookAndFeelDefaults();
|
||||
Color highlight = table.getColor("controlLtHighlight");
|
||||
Color shadow = table.getColor("controlShadow");
|
||||
|
||||
g.setColor(menu.getBackground());
|
||||
g.fillRect(0,0, menuWidth, menuHeight);
|
||||
|
||||
if (menu.isOpaque()) {
|
||||
if (model.isArmed() || model.isSelected()) {
|
||||
// Draw a lowered bevel border
|
||||
g.setColor(shadow);
|
||||
g.drawLine(0,0, menuWidth - 1,0);
|
||||
g.drawLine(0,0, 0,menuHeight - 2);
|
||||
|
||||
g.setColor(highlight);
|
||||
g.drawLine(menuWidth - 1,0, menuWidth - 1,menuHeight - 2);
|
||||
g.drawLine(0,menuHeight - 2, menuWidth - 1,menuHeight - 2);
|
||||
} else if (model.isRollover() && model.isEnabled()) {
|
||||
// Only paint rollover if no other menu on menubar is selected
|
||||
boolean otherMenuSelected = false;
|
||||
MenuElement[] menus = ((JMenuBar)menu.getParent()).getSubElements();
|
||||
for (int i = 0; i < menus.length; i++) {
|
||||
if (((JMenuItem)menus[i]).isSelected()) {
|
||||
otherMenuSelected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!otherMenuSelected) {
|
||||
if (XPStyle.getXP() != null) {
|
||||
g.setColor(selectionBackground); // Uses protected field.
|
||||
g.fillRect(0, 0, menuWidth, menuHeight);
|
||||
} else {
|
||||
// Draw a raised bevel border
|
||||
g.setColor(highlight);
|
||||
g.drawLine(0,0, menuWidth - 1,0);
|
||||
g.drawLine(0,0, 0,menuHeight - 2);
|
||||
|
||||
g.setColor(shadow);
|
||||
g.drawLine(menuWidth - 1,0, menuWidth - 1,menuHeight - 2);
|
||||
g.drawLine(0,menuHeight - 2, menuWidth - 1,menuHeight - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
g.setColor(oldColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method which renders the text of the current menu item.
|
||||
* <p>
|
||||
* @param g Graphics context
|
||||
* @param menuItem Current menu item to render
|
||||
* @param textRect Bounding rectangle to render the text.
|
||||
* @param text String to render
|
||||
* @since 1.4
|
||||
*/
|
||||
protected void paintText(Graphics g, JMenuItem menuItem,
|
||||
Rectangle textRect, String text) {
|
||||
if (WindowsMenuItemUI.isVistaPainting()) {
|
||||
WindowsMenuItemUI.paintText(accessor, g, menuItem, textRect, text);
|
||||
return;
|
||||
}
|
||||
JMenu menu = (JMenu)menuItem;
|
||||
ButtonModel model = menuItem.getModel();
|
||||
Color oldColor = g.getColor();
|
||||
|
||||
// Only paint rollover if no other menu on menubar is selected
|
||||
boolean paintRollover = model.isRollover();
|
||||
if (paintRollover && menu.isTopLevelMenu()) {
|
||||
MenuElement[] menus = ((JMenuBar)menu.getParent()).getSubElements();
|
||||
for (int i = 0; i < menus.length; i++) {
|
||||
if (((JMenuItem)menus[i]).isSelected()) {
|
||||
paintRollover = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((model.isSelected() && (WindowsLookAndFeel.isClassicWindows() ||
|
||||
!menu.isTopLevelMenu())) ||
|
||||
(XPStyle.getXP() != null && (paintRollover ||
|
||||
model.isArmed() ||
|
||||
model.isSelected()))) {
|
||||
g.setColor(selectionForeground); // Uses protected field.
|
||||
}
|
||||
|
||||
WindowsGraphicsUtils.paintText(g, menuItem, textRect, text, 0);
|
||||
|
||||
g.setColor(oldColor);
|
||||
}
|
||||
|
||||
protected MouseInputListener createMouseInputListener(JComponent c) {
|
||||
return new WindowsMouseInputHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* This class implements a mouse handler that sets the rollover flag to
|
||||
* true when the mouse enters the menu and false when it exits.
|
||||
* @since 1.4
|
||||
*/
|
||||
protected class WindowsMouseInputHandler extends BasicMenuUI.MouseInputHandler {
|
||||
public void mouseEntered(MouseEvent evt) {
|
||||
super.mouseEntered(evt);
|
||||
|
||||
JMenu menu = (JMenu)evt.getSource();
|
||||
if (hotTrackingOn && menu.isTopLevelMenu() && menu.isRolloverEnabled()) {
|
||||
menu.getModel().setRollover(true);
|
||||
menuItem.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent evt) {
|
||||
super.mouseExited(evt);
|
||||
|
||||
JMenu menu = (JMenu)evt.getSource();
|
||||
ButtonModel model = menu.getModel();
|
||||
if (menu.isRolloverEnabled()) {
|
||||
model.setRollover(false);
|
||||
menuItem.repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Dimension getPreferredMenuItemSize(JComponent c,
|
||||
Icon checkIcon,
|
||||
Icon arrowIcon,
|
||||
int defaultTextIconGap) {
|
||||
|
||||
Dimension d = super.getPreferredMenuItemSize(c, checkIcon, arrowIcon,
|
||||
defaultTextIconGap);
|
||||
|
||||
// Note: When toolbar containers (rebars) are implemented, only do
|
||||
// this if the JMenuBar is not in a rebar (i.e. ignore the desktop
|
||||
// property win.menu.height if in a rebar.)
|
||||
if (c instanceof JMenu && ((JMenu)c).isTopLevelMenu() &&
|
||||
menuBarHeight != null && d.height < menuBarHeight) {
|
||||
|
||||
d.height = menuBarHeight;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 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 com.sun.java.swing.plaf.windows;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Windows rendition of the component.
|
||||
* <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. A future release of Swing will provide support for
|
||||
* long term persistence.
|
||||
*/
|
||||
public class WindowsOptionPaneUI extends BasicOptionPaneUI {
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user