feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,927 @@
/*
* Copyright (c) 2002, 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 sun.swing.plaf.synth;
import javax.swing.plaf.synth.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.plaf.*;
/**
* Default implementation of SynthStyle. Has setters for the various
* SynthStyle methods. Many of the properties can be specified for all states,
* using SynthStyle directly, or a specific state using one of the StateInfo
* methods.
* <p>
* Beyond the constructor a subclass should override the <code>addTo</code>
* and <code>clone</code> methods, these are used when the Styles are being
* merged into a resulting style.
*
* @author Scott Violet
*/
public class DefaultSynthStyle extends SynthStyle implements Cloneable {
private static final Object PENDING = new Object();
/**
* Should the component be opaque?
*/
private boolean opaque;
/**
* Insets.
*/
private Insets insets;
/**
* Information specific to ComponentState.
*/
private StateInfo[] states;
/**
* User specific data.
*/
private Map data;
/**
* Font to use if there is no matching StateInfo, or the StateInfo doesn't
* define one.
*/
private Font font;
/**
* SynthGraphics, may be null.
*/
private SynthGraphicsUtils synthGraphics;
/**
* Painter to use if the StateInfo doesn't have one.
*/
private SynthPainter painter;
/**
* Nullary constructor, intended for subclassers.
*/
public DefaultSynthStyle() {
}
/**
* Creates a new DefaultSynthStyle that is a copy of the passed in
* style. Any StateInfo's of the passed in style are clonsed as well.
*
* @param style Style to duplicate
*/
public DefaultSynthStyle(DefaultSynthStyle style) {
opaque = style.opaque;
if (style.insets != null) {
insets = new Insets(style.insets.top, style.insets.left,
style.insets.bottom, style.insets.right);
}
if (style.states != null) {
states = new StateInfo[style.states.length];
for (int counter = style.states.length - 1; counter >= 0;
counter--) {
states[counter] = (StateInfo)style.states[counter].clone();
}
}
if (style.data != null) {
data = new HashMap();
data.putAll(style.data);
}
font = style.font;
synthGraphics = style.synthGraphics;
painter = style.painter;
}
/**
* Creates a new DefaultSynthStyle.
*
* @param insets Insets for the Style
* @param opaque Whether or not the background is completely painted in
* an opaque color
* @param states StateInfos describing properties per state
* @param data Style specific data.
*/
public DefaultSynthStyle(Insets insets, boolean opaque,
StateInfo[] states, Map data) {
this.insets = insets;
this.opaque = opaque;
this.states = states;
this.data = data;
}
public Color getColor(SynthContext context, ColorType type) {
return getColor(context.getComponent(), context.getRegion(),
context.getComponentState(), type);
}
public Color getColor(JComponent c, Region id, int state,
ColorType type) {
// For the enabled state, prefer the widget's colors
if (!id.isSubregion() && state == SynthConstants.ENABLED) {
if (type == ColorType.BACKGROUND) {
return c.getBackground();
}
else if (type == ColorType.FOREGROUND) {
return c.getForeground();
}
else if (type == ColorType.TEXT_FOREGROUND) {
// If getForeground returns a non-UIResource it means the
// developer has explicitly set the foreground, use it over
// that of TEXT_FOREGROUND as that is typically the expected
// behavior.
Color color = c.getForeground();
if (!(color instanceof UIResource)) {
return color;
}
}
}
// Then use what we've locally defined
Color color = getColorForState(c, id, state, type);
if (color == null) {
// No color, fallback to that of the widget.
if (type == ColorType.BACKGROUND ||
type == ColorType.TEXT_BACKGROUND) {
return c.getBackground();
}
else if (type == ColorType.FOREGROUND ||
type == ColorType.TEXT_FOREGROUND) {
return c.getForeground();
}
}
return color;
}
protected Color getColorForState(SynthContext context, ColorType type) {
return getColorForState(context.getComponent(), context.getRegion(),
context.getComponentState(), type);
}
/**
* Returns the color for the specified state.
*
* @param c JComponent the style is associated with
* @param id Region identifier
* @param state State of the region.
* @param type Type of color being requested.
* @return Color to render with
*/
protected Color getColorForState(JComponent c, Region id, int state,
ColorType type) {
// Use the best state.
StateInfo si = getStateInfo(state);
Color color;
if (si != null && (color = si.getColor(type)) != null) {
return color;
}
if (si == null || si.getComponentState() != 0) {
si = getStateInfo(0);
if (si != null) {
return si.getColor(type);
}
}
return null;
}
/**
* Sets the font that is used if there is no matching StateInfo, or
* it does not define a font.
*
* @param font Font to use for rendering
*/
public void setFont(Font font) {
this.font = font;
}
public Font getFont(SynthContext state) {
return getFont(state.getComponent(), state.getRegion(),
state.getComponentState());
}
public Font getFont(JComponent c, Region id, int state) {
if (!id.isSubregion() && state == SynthConstants.ENABLED) {
return c.getFont();
}
Font cFont = c.getFont();
if (cFont != null && !(cFont instanceof UIResource)) {
return cFont;
}
return getFontForState(c, id, state);
}
/**
* Returns the font for the specified state. This should NOT callback
* to the JComponent.
*
* @param c JComponent the style is associated with
* @param id Region identifier
* @param state State of the region.
* @return Font to render with
*/
protected Font getFontForState(JComponent c, Region id, int state) {
if (c == null) {
return this.font;
}
// First pass, look for the best match
StateInfo si = getStateInfo(state);
Font font;
if (si != null && (font = si.getFont()) != null) {
return font;
}
if (si == null || si.getComponentState() != 0) {
si = getStateInfo(0);
if (si != null && (font = si.getFont()) != null) {
return font;
}
}
// Fallback font.
return this.font;
}
protected Font getFontForState(SynthContext context) {
return getFontForState(context.getComponent(), context.getRegion(),
context.getComponentState());
}
/**
* Sets the SynthGraphicsUtils that will be used for rendering.
*
* @param graphics SynthGraphics
*/
public void setGraphicsUtils(SynthGraphicsUtils graphics) {
this.synthGraphics = graphics;
}
/**
* Returns a SynthGraphicsUtils.
*
* @param context SynthContext identifying requestor
* @return SynthGraphicsUtils
*/
public SynthGraphicsUtils getGraphicsUtils(SynthContext context) {
if (synthGraphics == null) {
return super.getGraphicsUtils(context);
}
return synthGraphics;
}
/**
* Sets the insets.
*
* @param Insets.
*/
public void setInsets(Insets insets) {
this.insets = insets;
}
/**
* Returns the Insets. If <code>to</code> is non-null the resulting
* insets will be placed in it, otherwise a new Insets object will be
* created and returned.
*
* @param context SynthContext identifying requestor
* @param to Where to place Insets
* @return Insets.
*/
public Insets getInsets(SynthContext state, Insets to) {
if (to == null) {
to = new Insets(0, 0, 0, 0);
}
if (insets != null) {
to.left = insets.left;
to.right = insets.right;
to.top = insets.top;
to.bottom = insets.bottom;
}
else {
to.left = to.right = to.top = to.bottom = 0;
}
return to;
}
/**
* Sets the Painter to use for the border.
*
* @param painter Painter for the Border.
*/
public void setPainter(SynthPainter painter) {
this.painter = painter;
}
/**
* Returns the Painter for the passed in Component. This may return null.
*
* @param ss SynthContext identifying requestor
* @return Painter for the border
*/
public SynthPainter getPainter(SynthContext ss) {
return painter;
}
/**
* Sets whether or not the JComponent should be opaque.
*
* @param opaque Whether or not the JComponent should be opaque.
*/
public void setOpaque(boolean opaque) {
this.opaque = opaque;
}
/**
* Returns the value to initialize the opacity property of the Component
* to. A Style should NOT assume the opacity will remain this value, the
* developer may reset it or override it.
*
* @param ss SynthContext identifying requestor
* @return opaque Whether or not the JComponent is opaque.
*/
public boolean isOpaque(SynthContext ss) {
return opaque;
}
/**
* Sets style specific values. This does NOT copy the data, it
* assigns it directly to this Style.
*
* @param data Style specific values
*/
public void setData(Map data) {
this.data = data;
}
/**
* Returns the style specific data.
*
* @return Style specific data.
*/
public Map getData() {
return data;
}
/**
* Getter for a region specific style property.
*
* @param state SynthContext identifying requestor
* @param key Property being requested.
* @return Value of the named property
*/
public Object get(SynthContext state, Object key) {
// Look for the best match
StateInfo si = getStateInfo(state.getComponentState());
if (si != null && si.getData() != null && getKeyFromData(si.getData(), key) != null) {
return getKeyFromData(si.getData(), key);
}
si = getStateInfo(0);
if (si != null && si.getData() != null && getKeyFromData(si.getData(), key) != null) {
return getKeyFromData(si.getData(), key);
}
if(getKeyFromData(data, key) != null)
return getKeyFromData(data, key);
return getDefaultValue(state, key);
}
private Object getKeyFromData(Map stateData, Object key) {
Object value = null;
if (stateData != null) {
synchronized(stateData) {
value = stateData.get(key);
}
while (value == PENDING) {
synchronized(stateData) {
try {
stateData.wait();
} catch (InterruptedException ie) {}
value = stateData.get(key);
}
}
if (value instanceof UIDefaults.LazyValue) {
synchronized(stateData) {
stateData.put(key, PENDING);
}
value = ((UIDefaults.LazyValue)value).createValue(null);
synchronized(stateData) {
stateData.put(key, value);
stateData.notifyAll();
}
}
}
return value;
}
/**
* Returns the default value for a particular property. This is only
* invoked if this style doesn't define a property for <code>key</code>.
*
* @param state SynthContext identifying requestor
* @param key Property being requested.
* @return Value of the named property
*/
public Object getDefaultValue(SynthContext context, Object key) {
return super.get(context, key);
}
/**
* Creates a clone of this style.
*
* @return Clone of this style
*/
public Object clone() {
DefaultSynthStyle style;
try {
style = (DefaultSynthStyle)super.clone();
} catch (CloneNotSupportedException cnse) {
return null;
}
if (states != null) {
style.states = new StateInfo[states.length];
for (int counter = states.length - 1; counter >= 0; counter--) {
style.states[counter] = (StateInfo)states[counter].clone();
}
}
if (data != null) {
style.data = new HashMap();
style.data.putAll(data);
}
return style;
}
/**
* Merges the contents of this Style with that of the passed in Style,
* returning the resulting merged syle. Properties of this
* <code>DefaultSynthStyle</code> will take precedence over those of the
* passed in <code>DefaultSynthStyle</code>. For example, if this
* style specifics a non-null font, the returned style will have its
* font so to that regardless of the <code>style</code>'s font.
*
* @param style Style to add our styles to
* @return Merged style.
*/
public DefaultSynthStyle addTo(DefaultSynthStyle style) {
if (insets != null) {
style.insets = this.insets;
}
if (font != null) {
style.font = this.font;
}
if (painter != null) {
style.painter = this.painter;
}
if (synthGraphics != null) {
style.synthGraphics = this.synthGraphics;
}
style.opaque = opaque;
if (states != null) {
if (style.states == null) {
style.states = new StateInfo[states.length];
for (int counter = states.length - 1; counter >= 0; counter--){
if (states[counter] != null) {
style.states[counter] = (StateInfo)states[counter].
clone();
}
}
}
else {
// Find the number of new states in unique, merging any
// matching states as we go. Also, move any merge styles
// to the end to give them precedence.
int unique = 0;
// Number of StateInfos that match.
int matchCount = 0;
int maxOStyles = style.states.length;
for (int thisCounter = states.length - 1; thisCounter >= 0;
thisCounter--) {
int state = states[thisCounter].getComponentState();
boolean found = false;
for (int oCounter = maxOStyles - 1 - matchCount;
oCounter >= 0; oCounter--) {
if (state == style.states[oCounter].
getComponentState()) {
style.states[oCounter] = states[thisCounter].
addTo(style.states[oCounter]);
// Move StateInfo to end, giving it precedence.
StateInfo tmp = style.states[maxOStyles - 1 -
matchCount];
style.states[maxOStyles - 1 - matchCount] =
style.states[oCounter];
style.states[oCounter] = tmp;
matchCount++;
found = true;
break;
}
}
if (!found) {
unique++;
}
}
if (unique != 0) {
// There are states that exist in this Style that
// don't exist in the other style, recreate the array
// and add them.
StateInfo[] newStates = new StateInfo[
unique + maxOStyles];
int newIndex = maxOStyles;
System.arraycopy(style.states, 0, newStates, 0,maxOStyles);
for (int thisCounter = states.length - 1; thisCounter >= 0;
thisCounter--) {
int state = states[thisCounter].getComponentState();
boolean found = false;
for (int oCounter = maxOStyles - 1; oCounter >= 0;
oCounter--) {
if (state == style.states[oCounter].
getComponentState()) {
found = true;
break;
}
}
if (!found) {
newStates[newIndex++] = (StateInfo)states[
thisCounter].clone();
}
}
style.states = newStates;
}
}
}
if (data != null) {
if (style.data == null) {
style.data = new HashMap();
}
style.data.putAll(data);
}
return style;
}
/**
* Sets the array of StateInfo's which are used to specify properties
* specific to a particular style.
*
* @param states StateInfos
*/
public void setStateInfo(StateInfo[] states) {
this.states = states;
}
/**
* Returns the array of StateInfo's that that are used to specify
* properties specific to a particular style.
*
* @return Array of StateInfos.
*/
public StateInfo[] getStateInfo() {
return states;
}
/**
* Returns the best matching StateInfo for a particular state.
*
* @param state Component state.
* @return Best matching StateInfo, or null
*/
public StateInfo getStateInfo(int state) {
// Use the StateInfo with the most bits that matches that of state.
// If there is none, than fallback to
// the StateInfo with a state of 0, indicating it'll match anything.
// Consider if we have 3 StateInfos a, b and c with states:
// SELECTED, SELECTED | ENABLED, 0
//
// Input Return Value
// ----- ------------
// SELECTED a
// SELECTED | ENABLED b
// MOUSE_OVER c
// SELECTED | ENABLED | FOCUSED b
// ENABLED c
if (states != null) {
int bestCount = 0;
int bestIndex = -1;
int wildIndex = -1;
if (state == 0) {
for (int counter = states.length - 1; counter >= 0;counter--) {
if (states[counter].getComponentState() == 0) {
return states[counter];
}
}
return null;
}
for (int counter = states.length - 1; counter >= 0; counter--) {
int oState = states[counter].getComponentState();
if (oState == 0) {
if (wildIndex == -1) {
wildIndex = counter;
}
}
else if ((state & oState) == oState) {
// This is key, we need to make sure all bits of the
// StateInfo match, otherwise a StateInfo with
// SELECTED | ENABLED would match ENABLED, which we
// don't want.
// This comes from BigInteger.bitCnt
int bitCount = oState;
bitCount -= (0xaaaaaaaa & bitCount) >>> 1;
bitCount = (bitCount & 0x33333333) + ((bitCount >>> 2) &
0x33333333);
bitCount = bitCount + (bitCount >>> 4) & 0x0f0f0f0f;
bitCount += bitCount >>> 8;
bitCount += bitCount >>> 16;
bitCount = bitCount & 0xff;
if (bitCount > bestCount) {
bestIndex = counter;
bestCount = bitCount;
}
}
}
if (bestIndex != -1) {
return states[bestIndex];
}
if (wildIndex != -1) {
return states[wildIndex];
}
}
return null;
}
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append(super.toString()).append(',');
buf.append("data=").append(data).append(',');
buf.append("font=").append(font).append(',');
buf.append("insets=").append(insets).append(',');
buf.append("synthGraphics=").append(synthGraphics).append(',');
buf.append("painter=").append(painter).append(',');
StateInfo[] states = getStateInfo();
if (states != null) {
buf.append("states[");
for (StateInfo state : states) {
buf.append(state.toString()).append(',');
}
buf.append(']').append(',');
}
// remove last newline
buf.deleteCharAt(buf.length() - 1);
return buf.toString();
}
/**
* StateInfo represents Style information specific to the state of
* a component.
*/
public static class StateInfo {
private Map data;
private Font font;
private Color[] colors;
private int state;
/**
* Creates a new StateInfo.
*/
public StateInfo() {
}
/**
* Creates a new StateInfo with the specified properties
*
* @param state Component state(s) that this StateInfo should be used
* for
* @param painter Painter responsible for rendering
* @param bgPainter Painter responsible for rendering the background
* @param font Font for this state
* @param colors Colors for this state
*/
public StateInfo(int state, Font font, Color[] colors) {
this.state = state;
this.font = font;
this.colors = colors;
}
/**
* Creates a new StateInfo that is a copy of the passed in
* StateInfo.
*
* @param info StateInfo to copy.
*/
public StateInfo(StateInfo info) {
this.state = info.state;
this.font = info.font;
if(info.data != null) {
if(data == null) {
data = new HashMap();
}
data.putAll(info.data);
}
if (info.colors != null) {
this.colors = new Color[info.colors.length];
System.arraycopy(info.colors, 0, colors, 0,info.colors.length);
}
}
public Map getData() {
return data;
}
public void setData(Map data) {
this.data = data;
}
/**
* Sets the font for this state.
*
* @param font Font to use for rendering
*/
public void setFont(Font font) {
this.font = font;
}
/**
* Returns the font for this state.
*
* @return Returns the font to use for rendering this state
*/
public Font getFont() {
return font;
}
/**
* Sets the array of colors to use for rendering this state. This
* is indexed by <code>ColorType.getID()</code>.
*
* @param colors Array of colors
*/
public void setColors(Color[] colors) {
this.colors = colors;
}
/**
* Returns the array of colors to use for rendering this state. This
* is indexed by <code>ColorType.getID()</code>.
*
* @return Array of colors
*/
public Color[] getColors() {
return colors;
}
/**
* Returns the Color to used for the specified ColorType.
*
* @return Color.
*/
public Color getColor(ColorType type) {
if (colors != null) {
int id = type.getID();
if (id < colors.length) {
return colors[id];
}
}
return null;
}
/**
* Merges the contents of this StateInfo with that of the passed in
* StateInfo, returning the resulting merged StateInfo. Properties of
* this <code>StateInfo</code> will take precedence over those of the
* passed in <code>StateInfo</code>. For example, if this
* StateInfo specifics a non-null font, the returned StateInfo will
* have its font so to that regardless of the <code>StateInfo</code>'s
* font.
*
* @param info StateInfo to add our styles to
* @return Merged StateInfo.
*/
public StateInfo addTo(StateInfo info) {
if (font != null) {
info.font = font;
}
if(data != null) {
if(info.data == null) {
info.data = new HashMap();
}
info.data.putAll(data);
}
if (colors != null) {
if (info.colors == null) {
info.colors = new Color[colors.length];
System.arraycopy(colors, 0, info.colors, 0,
colors.length);
}
else {
if (info.colors.length < colors.length) {
Color[] old = info.colors;
info.colors = new Color[colors.length];
System.arraycopy(old, 0, info.colors, 0, old.length);
}
for (int counter = colors.length - 1; counter >= 0;
counter--) {
if (colors[counter] != null) {
info.colors[counter] = colors[counter];
}
}
}
}
return info;
}
/**
* Sets the state this StateInfo corresponds to.
*
* @see SynthConstants
* @param state info.
*/
public void setComponentState(int state) {
this.state = state;
}
/**
* Returns the state this StateInfo corresponds to.
*
* @see SynthConstants
* @return state info.
*/
public int getComponentState() {
return state;
}
/**
* Returns the number of states that are similar between the
* ComponentState this StateInfo represents and val.
*/
private int getMatchCount(int val) {
// This comes from BigInteger.bitCnt
val &= state;
val -= (0xaaaaaaaa & val) >>> 1;
val = (val & 0x33333333) + ((val >>> 2) & 0x33333333);
val = val + (val >>> 4) & 0x0f0f0f0f;
val += val >>> 8;
val += val >>> 16;
return val & 0xff;
}
/**
* Creates and returns a copy of this StateInfo.
*
* @return Copy of this StateInfo.
*/
public Object clone() {
return new StateInfo(this);
}
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append(super.toString()).append(',');
buf.append("state=").append(Integer.toString(state)).append(',');
buf.append("font=").append(font).append(',');
if (colors != null) {
buf.append("colors=").append(Arrays.asList(colors)).
append(',');
}
return buf.toString();
}
}
}

View File

@@ -0,0 +1,340 @@
/*
* Copyright (c) 2004, 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 sun.swing.plaf.synth;
import java.awt.*;
import java.awt.image.BufferedImage;
import sun.swing.CachedPainter;
/**
* Paint9Painter is used for painting images for both Synth and GTK's
* pixmap/blueprint engines.
*
*/
public class Paint9Painter extends CachedPainter {
/**
* Enumeration for the types of painting this class can handle.
*/
public enum PaintType {
/**
* Painting type indicating the image should be centered in
* the space provided. When used the <code>mask</code> is ignored.
*/
CENTER,
/**
* Painting type indicating the image should be tiled across the
* specified width and height. When used the <code>mask</code> is
* ignored.
*/
TILE,
/**
* Painting type indicating the image should be split into nine
* regions with the top, left, bottom and right areas stretched.
*/
PAINT9_STRETCH,
/**
* Painting type indicating the image should be split into nine
* regions with the top, left, bottom and right areas tiled.
*/
PAINT9_TILE
};
private static final Insets EMPTY_INSETS = new Insets(0, 0, 0, 0);
public static final int PAINT_TOP_LEFT = 1;
public static final int PAINT_TOP = 2;
public static final int PAINT_TOP_RIGHT = 4;
public static final int PAINT_LEFT = 8;
public static final int PAINT_CENTER = 16;
public static final int PAINT_RIGHT = 32;
public static final int PAINT_BOTTOM_RIGHT = 64;
public static final int PAINT_BOTTOM = 128;
public static final int PAINT_BOTTOM_LEFT = 256;
/**
* Specifies that all regions should be painted. If this is set any
* other regions specified will not be painted. For example
* PAINT_ALL | PAINT_CENTER will paint all but the center.
*/
public static final int PAINT_ALL = 512;
/**
* Convenience method for testing the validity of an image.
*
* @param image Image to check.
* @return true if <code>image</code> is non-null and has a positive
* size.
*/
public static boolean validImage(Image image) {
return (image != null && image.getWidth(null) > 0 &&
image.getHeight(null) > 0);
}
public Paint9Painter(int cacheCount) {
super(cacheCount);
}
/**
* Paints using the algorightm specified by <code>paintType</code>.
* NOTE that this just invokes super.paint(...) with the same
* argument ordering as this method.
*
* @param c Component rendering to
* @param g Graphics to render to
* @param x X-coordinate
* @param y Y-coordinate
* @param w Width to render to
* @param h Height to render to
* @param source Image to render from, if <code>null</code> this method
* will do nothing
* @param sInsets Insets specifying the portion of the image that
* will be stretched or tiled, if <code>null</code> empty
* <code>Insets</code> will be used.
* @param dInsets Destination insets specifying the portion of the image
* will be stretched or tiled, if <code>null</code> empty
* <code>Insets</code> will be used.
* @param paintType Specifies what type of algorithm to use in painting
* @param mask Specifies portion of image to render, if
* <code>PAINT_ALL</code> is specified, any other regions
* specified will not be painted, for example
* PAINT_ALL | PAINT_CENTER paints everything but the center.
*/
public void paint(Component c, Graphics g, int x,
int y, int w, int h, Image source, Insets sInsets,
Insets dInsets,
PaintType type, int mask) {
if (source == null) {
return;
}
super.paint(c, g, x, y, w, h, source, sInsets, dInsets, type, mask);
}
protected void paintToImage(Component c, Image destImage, Graphics g,
int w, int h, Object[] args) {
int argIndex = 0;
while (argIndex < args.length) {
Image image = (Image)args[argIndex++];
Insets sInsets = (Insets)args[argIndex++];
Insets dInsets = (Insets)args[argIndex++];
PaintType type = (PaintType)args[argIndex++];
int mask = (Integer)args[argIndex++];
paint9(g, 0, 0, w, h, image, sInsets, dInsets, type, mask);
}
}
protected void paint9(Graphics g, int x, int y, int w, int h,
Image image, Insets sInsets,
Insets dInsets, PaintType type, int componentMask) {
if (!validImage(image)) {
return;
}
if (sInsets == null) {
sInsets = EMPTY_INSETS;
}
if (dInsets == null) {
dInsets = EMPTY_INSETS;
}
int iw = image.getWidth(null);
int ih = image.getHeight(null);
if (type == PaintType.CENTER) {
// Center the image
g.drawImage(image, x + (w - iw) / 2,
y + (h - ih) / 2, null);
}
else if (type == PaintType.TILE) {
// Tile the image
int lastIY = 0;
for (int yCounter = y, maxY = y + h; yCounter < maxY;
yCounter += (ih - lastIY), lastIY = 0) {
int lastIX = 0;
for (int xCounter = x, maxX = x + w; xCounter < maxX;
xCounter += (iw - lastIX), lastIX = 0) {
int dx2 = Math.min(maxX, xCounter + iw - lastIX);
int dy2 = Math.min(maxY, yCounter + ih - lastIY);
g.drawImage(image, xCounter, yCounter, dx2, dy2,
lastIX, lastIY, lastIX + dx2 - xCounter,
lastIY + dy2 - yCounter, null);
}
}
}
else {
int st = sInsets.top;
int sl = sInsets.left;
int sb = sInsets.bottom;
int sr = sInsets.right;
int dt = dInsets.top;
int dl = dInsets.left;
int db = dInsets.bottom;
int dr = dInsets.right;
// Constrain the insets to the size of the image
if (st + sb > ih) {
db = dt = sb = st = Math.max(0, ih / 2);
}
if (sl + sr > iw) {
dl = dr = sl = sr = Math.max(0, iw / 2);
}
// Constrain the insets to the size of the region we're painting
// in.
if (dt + db > h) {
dt = db = Math.max(0, h / 2 - 1);
}
if (dl + dr > w) {
dl = dr = Math.max(0, w / 2 - 1);
}
boolean stretch = (type == PaintType.PAINT9_STRETCH);
if ((componentMask & PAINT_ALL) != 0) {
componentMask = (PAINT_ALL - 1) & ~componentMask;
}
if ((componentMask & PAINT_LEFT) != 0) {
drawChunk(image, g, stretch, x, y + dt, x + dl, y + h - db,
0, st, sl, ih - sb, false);
}
if ((componentMask & PAINT_TOP_LEFT) != 0) {
drawImage(image, g, x, y, x + dl, y + dt,
0, 0, sl, st);
}
if ((componentMask & PAINT_TOP) != 0) {
drawChunk(image, g, stretch, x + dl, y, x + w - dr, y + dt,
sl, 0, iw - sr, st, true);
}
if ((componentMask & PAINT_TOP_RIGHT) != 0) {
drawImage(image, g, x + w - dr, y, x + w, y + dt,
iw - sr, 0, iw, st);
}
if ((componentMask & PAINT_RIGHT) != 0) {
drawChunk(image, g, stretch,
x + w - dr, y + dt, x + w, y + h - db,
iw - sr, st, iw, ih - sb, false);
}
if ((componentMask & PAINT_BOTTOM_RIGHT) != 0) {
drawImage(image, g, x + w - dr, y + h - db, x + w, y + h,
iw - sr, ih - sb, iw, ih);
}
if ((componentMask & PAINT_BOTTOM) != 0) {
drawChunk(image, g, stretch,
x + dl, y + h - db, x + w - dr, y + h,
sl, ih - sb, iw - sr, ih, true);
}
if ((componentMask & PAINT_BOTTOM_LEFT) != 0) {
drawImage(image, g, x, y + h - db, x + dl, y + h,
0, ih - sb, sl, ih);
}
if ((componentMask & PAINT_CENTER) != 0) {
drawImage(image, g, x + dl, y + dt, x + w - dr, y + h - db,
sl, st, iw - sr, ih - sb);
}
}
}
private void drawImage(Image image, Graphics g,
int dx1, int dy1, int dx2, int dy2, int sx1,
int sy1, int sx2, int sy2) {
// PENDING: is this necessary, will G2D do it for me?
if (dx2 - dx1 <= 0 || dy2 - dy1 <= 0 || sx2 - sx1 <= 0 ||
sy2 - sy1 <= 0) {
// Bogus location, nothing to paint
return;
}
g.drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null);
}
/**
* Draws a portion of an image, stretched or tiled.
*
* @param image Image to render.
* @param g Graphics to render to
* @param stretch Whether the image should be stretched or timed in the
* provided space.
* @param dx1 X origin to draw to
* @param dy1 Y origin to draw to
* @param dx2 End x location to draw to
* @param dy2 End y location to draw to
* @param sx1 X origin to draw from
* @param sy1 Y origin to draw from
* @param sx2 Max x location to draw from
* @param sy2 Max y location to draw from
* @param xDirection Used if the image is not stretched. If true it
* indicates the image should be tiled along the x axis.
*/
private void drawChunk(Image image, Graphics g, boolean stretch,
int dx1, int dy1, int dx2, int dy2, int sx1,
int sy1, int sx2, int sy2,
boolean xDirection) {
if (dx2 - dx1 <= 0 || dy2 - dy1 <= 0 || sx2 - sx1 <= 0 ||
sy2 - sy1 <= 0) {
// Bogus location, nothing to paint
return;
}
if (stretch) {
g.drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null);
}
else {
int xSize = sx2 - sx1;
int ySize = sy2 - sy1;
int deltaX;
int deltaY;
if (xDirection) {
deltaX = xSize;
deltaY = 0;
}
else {
deltaX = 0;
deltaY = ySize;
}
while (dx1 < dx2 && dy1 < dy2) {
int newDX2 = Math.min(dx2, dx1 + xSize);
int newDY2 = Math.min(dy2, dy1 + ySize);
g.drawImage(image, dx1, dy1, newDX2, newDY2,
sx1, sy1, sx1 + newDX2 - dx1,
sy1 + newDY2 - dy1, null);
dx1 += deltaX;
dy1 += deltaY;
}
}
}
/**
* Subclassed to always create a translucent image.
*/
protected Image createImage(Component c, int w, int h,
GraphicsConfiguration config,
Object[] args) {
if (config == null) {
return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
}
return config.createCompatibleImage(w, h, Transparency.TRANSLUCENT);
}
}

View File

@@ -0,0 +1,133 @@
/*
* Copyright (c) 2003, 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 sun.swing.plaf.synth;
import javax.swing.plaf.synth.*;
import java.util.*;
import java.util.regex.*;
/**
* <b>WARNING:</b> This class is an implementation detail and is only
* public so that it can be used by two packages. You should NOT consider
* this public API.
* <p>
* StyleAssociation is used to lookup a style for a particular
* component (or region).
*
* @author Scott Violet
*/
public class StyleAssociation {
/**
* The style
*/
private SynthStyle _style;
/**
* Pattern used for matching.
*/
private Pattern _pattern;
/**
* Matcher used for testing if path matches that of pattern.
*/
private Matcher _matcher;
/**
* Identifier for this association.
*/
private int _id;
/**
* Returns a StyleAssociation that can be used to determine if
* a particular string matches the returned association.
*/
public static StyleAssociation createStyleAssociation(
String text, SynthStyle style)
throws PatternSyntaxException {
return createStyleAssociation(text, style, 0);
}
/**
* Returns a StyleAssociation that can be used to determine if
* a particular string matches the returned association.
*/
public static StyleAssociation createStyleAssociation(
String text, SynthStyle style, int id)
throws PatternSyntaxException {
return new StyleAssociation(text, style, id);
}
private StyleAssociation(String text, SynthStyle style, int id)
throws PatternSyntaxException {
_style = style;
_pattern = Pattern.compile(text);
_id = id;
}
/**
* Returns the developer specified identifier for this association, will
* be <code>0</code> if an identifier was not specified when this
* <code>StyleAssociation</code> was created.
*/
public int getID() {
return _id;
}
/**
* Returns true if this <code>StyleAssociation</code> matches the
* passed in CharSequence.
*
* @return true if this <code>StyleAssociation</code> matches the
* passed in CharSequence.if this StyleAssociation.
*/
public synchronized boolean matches(CharSequence path) {
if (_matcher == null) {
_matcher = _pattern.matcher(path);
}
else {
_matcher.reset(path);
}
return _matcher.matches();
}
/**
* Returns the text used in matching the string.
*
* @return the text used in matching the string.
*/
public String getText() {
return _pattern.pattern();
}
/**
* Returns the style this association is mapped to.
*
* @return the style this association is mapped to.
*/
public SynthStyle getStyle() {
return _style;
}
}

View File

@@ -0,0 +1,586 @@
/*
* 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 sun.swing.plaf.synth;
import javax.swing.plaf.synth.*;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.io.File;
import java.util.regex.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.filechooser.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.BasicFileChooserUI;
/**
* Synth FileChooserUI.
*
* Note: This class is abstract. It does not actually create the file chooser GUI.
* <p>
* Note that the classes in the com.sun.java.swing.plaf.synth
* package are not
* part of the core Java APIs. They are a part of Sun's JDK and JRE
* distributions. Although other licensees may choose to distribute
* these classes, developers cannot depend on their availability in
* non-Sun implementations. Additionally this API may change in
* incompatible ways between releases. While this class is public, it
* shoud be considered an implementation detail, and subject to change.
*
* @author Leif Samuelsson
* @author Jeff Dinkins
*/
public abstract class SynthFileChooserUI extends BasicFileChooserUI implements
SynthUI {
private JButton approveButton, cancelButton;
private SynthStyle style;
// Some generic FileChooser functions
private Action fileNameCompletionAction = new FileNameCompletionAction();
private FileFilter actualFileFilter = null;
private GlobFilter globFilter = null;
public static ComponentUI createUI(JComponent c) {
return new SynthFileChooserUIImpl((JFileChooser)c);
}
public SynthFileChooserUI(JFileChooser b) {
super(b);
}
public SynthContext getContext(JComponent c) {
return new SynthContext(c, Region.FILE_CHOOSER, style,
getComponentState(c));
}
protected SynthContext getContext(JComponent c, int state) {
Region region = SynthLookAndFeel.getRegion(c);
return new SynthContext(c, Region.FILE_CHOOSER, style, state);
}
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) {
if (c.isEnabled()) {
if (c.isFocusOwner()) {
return ENABLED | FOCUSED;
}
return ENABLED;
}
return DISABLED;
}
private void updateStyle(JComponent c) {
SynthStyle newStyle = SynthLookAndFeel.getStyleFactory().getStyle(c,
Region.FILE_CHOOSER);
if (newStyle != style) {
if (style != null) {
style.uninstallDefaults(getContext(c, ENABLED));
}
style = newStyle;
SynthContext context = getContext(c, ENABLED);
style.installDefaults(context);
Border border = c.getBorder();
if (border == null || border instanceof UIResource) {
c.setBorder(new UIBorder(style.getInsets(context, null)));
}
directoryIcon = style.getIcon(context, "FileView.directoryIcon");
fileIcon = style.getIcon(context, "FileView.fileIcon");
computerIcon = style.getIcon(context, "FileView.computerIcon");
hardDriveIcon = style.getIcon(context, "FileView.hardDriveIcon");
floppyDriveIcon = style.getIcon(context, "FileView.floppyDriveIcon");
newFolderIcon = style.getIcon(context, "FileChooser.newFolderIcon");
upFolderIcon = style.getIcon(context, "FileChooser.upFolderIcon");
homeFolderIcon = style.getIcon(context, "FileChooser.homeFolderIcon");
detailsViewIcon = style.getIcon(context, "FileChooser.detailsViewIcon");
listViewIcon = style.getIcon(context, "FileChooser.listViewIcon");
}
}
public void installUI(JComponent c) {
super.installUI(c);
SwingUtilities.replaceUIActionMap(c, createActionMap());
}
public void installComponents(JFileChooser fc) {
SynthContext context = getContext(fc, ENABLED);
cancelButton = new JButton(cancelButtonText);
cancelButton.setName("SynthFileChooser.cancelButton");
cancelButton.setIcon(context.getStyle().getIcon(context, "FileChooser.cancelIcon"));
cancelButton.setMnemonic(cancelButtonMnemonic);
cancelButton.setToolTipText(cancelButtonToolTipText);
cancelButton.addActionListener(getCancelSelectionAction());
approveButton = new JButton(getApproveButtonText(fc));
approveButton.setName("SynthFileChooser.approveButton");
approveButton.setIcon(context.getStyle().getIcon(context, "FileChooser.okIcon"));
approveButton.setMnemonic(getApproveButtonMnemonic(fc));
approveButton.setToolTipText(getApproveButtonToolTipText(fc));
approveButton.addActionListener(getApproveSelectionAction());
}
public void uninstallComponents(JFileChooser fc) {
fc.removeAll();
}
protected void installListeners(JFileChooser fc) {
super.installListeners(fc);
getModel().addListDataListener(new ListDataListener() {
public void contentsChanged(ListDataEvent e) {
// Update the selection after JList has been updated
new DelayedSelectionUpdater();
}
public void intervalAdded(ListDataEvent e) {
new DelayedSelectionUpdater();
}
public void intervalRemoved(ListDataEvent e) {
}
});
}
private class DelayedSelectionUpdater implements Runnable {
DelayedSelectionUpdater() {
SwingUtilities.invokeLater(this);
}
public void run() {
updateFileNameCompletion();
}
}
protected abstract ActionMap createActionMap();
protected void installDefaults(JFileChooser fc) {
super.installDefaults(fc);
updateStyle(fc);
}
protected void uninstallDefaults(JFileChooser fc) {
super.uninstallDefaults(fc);
SynthContext context = getContext(getFileChooser(), ENABLED);
style.uninstallDefaults(context);
style = null;
}
protected void installIcons(JFileChooser fc) {
// The icons are installed in updateStyle, not here
}
public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c);
if (c.isOpaque()) {
g.setColor(style.getColor(context, ColorType.BACKGROUND));
g.fillRect(0, 0, c.getWidth(), c.getHeight());
}
style.getPainter(context).paintFileChooserBackground(context,
g, 0, 0, c.getWidth(), c.getHeight());
paint(context, g);
}
public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) {
}
public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c);
paint(context, g);
}
protected void paint(SynthContext context, Graphics g) {
}
abstract public void setFileName(String fileName);
abstract public String getFileName();
protected void doSelectedFileChanged(PropertyChangeEvent e) {
}
protected void doSelectedFilesChanged(PropertyChangeEvent e) {
}
protected void doDirectoryChanged(PropertyChangeEvent e) {
}
protected void doAccessoryChanged(PropertyChangeEvent e) {
}
protected void doFileSelectionModeChanged(PropertyChangeEvent e) {
}
protected void doMultiSelectionChanged(PropertyChangeEvent e) {
if (!getFileChooser().isMultiSelectionEnabled()) {
getFileChooser().setSelectedFiles(null);
}
}
protected void doControlButtonsChanged(PropertyChangeEvent e) {
if (getFileChooser().getControlButtonsAreShown()) {
approveButton.setText(getApproveButtonText(getFileChooser()));
approveButton.setToolTipText(getApproveButtonToolTipText(getFileChooser()));
approveButton.setMnemonic(getApproveButtonMnemonic(getFileChooser()));
}
}
protected void doAncestorChanged(PropertyChangeEvent e) {
}
public PropertyChangeListener createPropertyChangeListener(JFileChooser fc) {
return new SynthFCPropertyChangeListener();
}
private class SynthFCPropertyChangeListener implements PropertyChangeListener {
public void propertyChange(PropertyChangeEvent e) {
String prop = e.getPropertyName();
if (prop.equals(JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY)) {
doFileSelectionModeChanged(e);
} else if (prop.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) {
doSelectedFileChanged(e);
} else if (prop.equals(JFileChooser.SELECTED_FILES_CHANGED_PROPERTY)) {
doSelectedFilesChanged(e);
} else if (prop.equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)) {
doDirectoryChanged(e);
} else if (prop == JFileChooser.MULTI_SELECTION_ENABLED_CHANGED_PROPERTY) {
doMultiSelectionChanged(e);
} else if (prop == JFileChooser.ACCESSORY_CHANGED_PROPERTY) {
doAccessoryChanged(e);
} else if (prop == JFileChooser.APPROVE_BUTTON_TEXT_CHANGED_PROPERTY ||
prop == JFileChooser.APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY ||
prop == JFileChooser.DIALOG_TYPE_CHANGED_PROPERTY ||
prop == 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);
}
} else if (prop.equals("ancestor")) {
doAncestorChanged(e);
}
}
}
/**
* Responds to a File Name completion request (e.g. Tab)
*/
private class FileNameCompletionAction extends AbstractAction {
protected FileNameCompletionAction() {
super("fileNameCompletion");
}
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = getFileChooser();
String fileName = getFileName();
if (fileName != null) {
// Remove whitespace from beginning and end of filename
fileName = fileName.trim();
}
resetGlobFilter();
if (fileName == null || fileName.equals("") ||
(chooser.isMultiSelectionEnabled() && fileName.startsWith("\""))) {
return;
}
FileFilter currentFilter = chooser.getFileFilter();
if (globFilter == null) {
globFilter = new GlobFilter();
}
try {
globFilter.setPattern(!isGlobPattern(fileName) ? fileName + "*" : fileName);
if (!(currentFilter instanceof GlobFilter)) {
actualFileFilter = currentFilter;
}
chooser.setFileFilter(null);
chooser.setFileFilter(globFilter);
fileNameCompletionString = fileName;
} catch (PatternSyntaxException pse) {
// Not a valid glob pattern. Abandon filter.
}
}
}
private String fileNameCompletionString;
private void updateFileNameCompletion() {
if (fileNameCompletionString != null) {
if (fileNameCompletionString.equals(getFileName())) {
File[] files = getModel().getFiles().toArray(new File[0]);
String str = getCommonStartString(files);
if (str != null && str.startsWith(fileNameCompletionString)) {
setFileName(str);
}
fileNameCompletionString = null;
}
}
}
private String getCommonStartString(File[] files) {
String str = null;
String str2 = null;
int i = 0;
if (files.length == 0) {
return null;
}
while (true) {
for (int f = 0; f < files.length; f++) {
String name = files[f].getName();
if (f == 0) {
if (name.length() == i) {
return str;
}
str2 = name.substring(0, i+1);
}
if (!name.startsWith(str2)) {
return str;
}
}
str = str2;
i++;
}
}
private void resetGlobFilter() {
if (actualFileFilter != null) {
JFileChooser chooser = getFileChooser();
FileFilter currentFilter = chooser.getFileFilter();
if (currentFilter != null && currentFilter.equals(globFilter)) {
chooser.setFileFilter(actualFileFilter);
chooser.removeChoosableFileFilter(globFilter);
}
actualFileFilter = null;
}
}
private static boolean isGlobPattern(String fileName) {
return ((File.separatorChar == '\\' && fileName.indexOf('*') >= 0)
|| (File.separatorChar == '/' && (fileName.indexOf('*') >= 0
|| fileName.indexOf('?') >= 0
|| fileName.indexOf('[') >= 0)));
}
/* A file filter which accepts file patterns containing
* the special wildcard '*' on windows, plus '?', and '[ ]' on Unix.
*/
class GlobFilter extends FileFilter {
Pattern pattern;
String globPattern;
public void setPattern(String globPattern) {
char[] gPat = globPattern.toCharArray();
char[] rPat = new char[gPat.length * 2];
boolean isWin32 = (File.separatorChar == '\\');
boolean inBrackets = false;
int j = 0;
this.globPattern = globPattern;
if (isWin32) {
// On windows, a pattern ending with *.* is equal to ending with *
int len = gPat.length;
if (globPattern.endsWith("*.*")) {
len -= 2;
}
for (int i = 0; i < len; i++) {
if (gPat[i] == '*') {
rPat[j++] = '.';
}
rPat[j++] = gPat[i];
}
} else {
for (int i = 0; i < gPat.length; i++) {
switch(gPat[i]) {
case '*':
if (!inBrackets) {
rPat[j++] = '.';
}
rPat[j++] = '*';
break;
case '?':
rPat[j++] = inBrackets ? '?' : '.';
break;
case '[':
inBrackets = true;
rPat[j++] = gPat[i];
if (i < gPat.length - 1) {
switch (gPat[i+1]) {
case '!':
case '^':
rPat[j++] = '^';
i++;
break;
case ']':
rPat[j++] = gPat[++i];
break;
}
}
break;
case ']':
rPat[j++] = gPat[i];
inBrackets = false;
break;
case '\\':
if (i == 0 && gPat.length > 1 && gPat[1] == '~') {
rPat[j++] = gPat[++i];
} else {
rPat[j++] = '\\';
if (i < gPat.length - 1 && "*?[]".indexOf(gPat[i+1]) >= 0) {
rPat[j++] = gPat[++i];
} else {
rPat[j++] = '\\';
}
}
break;
default:
//if ("+()|^$.{}<>".indexOf(gPat[i]) >= 0) {
if (!Character.isLetterOrDigit(gPat[i])) {
rPat[j++] = '\\';
}
rPat[j++] = gPat[i];
break;
}
}
}
this.pattern = Pattern.compile(new String(rPat, 0, j), Pattern.CASE_INSENSITIVE);
}
public boolean accept(File f) {
if (f == null) {
return false;
}
if (f.isDirectory()) {
return true;
}
return pattern.matcher(f.getName()).matches();
}
public String getDescription() {
return globPattern;
}
}
// *******************************************************
// ************ FileChooser UI PLAF methods **************
// *******************************************************
// *****************************
// ***** Directory Actions *****
// *****************************
public Action getFileNameCompletionAction() {
return fileNameCompletionAction;
}
protected JButton getApproveButton(JFileChooser fc) {
return approveButton;
}
protected JButton getCancelButton(JFileChooser fc) {
return cancelButton;
}
// Overload to do nothing. We don't have and icon cache.
public void clearIconCache() { }
// Copied as SynthBorder is package private in synth
private class UIBorder extends AbstractBorder implements UIResource {
private Insets _insets;
UIBorder(Insets insets) {
if (insets != null) {
_insets = new Insets(insets.top, insets.left, insets.bottom,
insets.right);
}
else {
_insets = null;
}
}
public void paintBorder(Component c, Graphics g, int x, int y,
int width, int height) {
if (!(c instanceof JComponent)) {
return;
}
JComponent jc = (JComponent)c;
SynthContext context = getContext(jc);
SynthStyle style = context.getStyle();
if (style != null) {
style.getPainter(context).paintFileChooserBorder(
context, g, x, y, width, height);
}
}
public Insets getBorderInsets(Component c, Insets insets) {
if (insets == null) {
insets = new Insets(0, 0, 0, 0);
}
if (_insets != null) {
insets.top = _insets.top;
insets.bottom = _insets.bottom;
insets.left = _insets.left;
insets.right = _insets.right;
}
else {
insets.top = insets.bottom = insets.right = insets.left = 0;
}
return insets;
}
public boolean isBorderOpaque() {
return false;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,126 @@
/*
* 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 sun.swing.plaf.synth;
import javax.swing.plaf.synth.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.UIResource;
/**
* An icon that is passed a SynthContext. Subclasses need only implement
* the variants that take a SynthContext, but must be prepared for the
* SynthContext to be null.
*
* @author Scott Violet
*/
public abstract class SynthIcon implements Icon {
public static int getIconWidth(Icon icon, SynthContext context) {
if (icon == null) {
return 0;
}
if (icon instanceof SynthIcon) {
return ((SynthIcon)icon).getIconWidth(context);
}
return icon.getIconWidth();
}
public static int getIconHeight(Icon icon, SynthContext context) {
if (icon == null) {
return 0;
}
if (icon instanceof SynthIcon) {
return ((SynthIcon)icon).getIconHeight(context);
}
return icon.getIconHeight();
}
public static void paintIcon(Icon icon, SynthContext context, Graphics g,
int x, int y, int w, int h) {
if (icon instanceof SynthIcon) {
((SynthIcon)icon).paintIcon(context, g, x, y, w, h);
}
else if (icon != null) {
icon.paintIcon(context.getComponent(), g, x, y);
}
}
/**
* Paints the icon at the specified location.
*
* @param context Identifies hosting region, may be null.
* @param x x location to paint to
* @param y y location to paint to
* @param w Width of the region to paint to, may be 0
* @param h Height of the region to paint to, may be 0
*/
public abstract void paintIcon(SynthContext context, Graphics g, int x,
int y, int w, int h);
/**
* Returns the desired width of the Icon.
*
* @param context SynthContext requesting the Icon, may be null.
* @return Desired width of the icon.
*/
public abstract int getIconWidth(SynthContext context);
/**
* Returns the desired height of the Icon.
*
* @param context SynthContext requesting the Icon, may be null.
* @return Desired height of the icon.
*/
public abstract int getIconHeight(SynthContext context);
/**
* Paints the icon. This is a cover method for
* <code>paintIcon(null, g, x, y, 0, 0)</code>
*/
public void paintIcon(Component c, Graphics g, int x, int y) {
paintIcon(null, g, x, y, 0, 0);
}
/**
* Returns the icon's width. This is a cover methods for
* <code>getIconWidth(null)</code>.
*
* @return an int specifying the fixed width of the icon.
*/
public int getIconWidth() {
return getIconWidth(null);
}
/**
* Returns the icon's height. This is a cover method for
* <code>getIconHeight(null)</code>.
*
* @return an int specifying the fixed height of the icon.
*/
public int getIconHeight() {
return getIconHeight(null);
}
}