diff --git a/jdk/src/share/classes/java/awt/Component.java b/jdk/src/share/classes/java/awt/Component.java
index ff7aed6403f..e9c274fcb42 100644
--- a/jdk/src/share/classes/java/awt/Component.java
+++ b/jdk/src/share/classes/java/awt/Component.java
@@ -94,7 +94,17 @@ import sun.util.logging.PlatformLogger;
* the nonmenu-related Abstract Window Toolkit components. Class
* Component can also be extended directly to create a
* lightweight component. A lightweight component is a component that is
- * not associated with a native opaque window.
+ * not associated with a native window. On the contrary, a heavyweight
+ * component is associated with a native window. The {@link #isLightweight()}
+ * method may be used to distinguish between the two kinds of the components.
+ *
+ * Lightweight and heavyweight components may be mixed in a single component + * hierarchy. However, for correct operating of such a mixed hierarchy of + * components, the whole hierarchy must be valid. When the hierarchy gets + * invalidated, like after changing the bounds of components, or + * adding/removing components to/from containers, the whole hierarchy must be + * validated afterwards by means of the {@link Container#validate()} method + * invoked on the top-most invalid container of the hierarchy. *
*
b.
+ *
+ * This method changes layout-related information, and therefore,
+ * invalidates the component hierarchy.
+ *
* @param b if true, shows this component;
* otherwise, hides this component
* @see #isVisible
+ * @see #invalidate
* @since JDK1.1
*/
public void setVisible(boolean b) {
@@ -1753,10 +1768,15 @@ public abstract class Component implements ImageObserver, MenuContainer,
/**
* Sets the font of this component.
+ *
+ * This method changes layout-related information, and therefore,
+ * invalidates the component hierarchy.
+ *
* @param f the font to become this component's font;
* if this parameter is null then this
* component will inherit the font of its parent
* @see #getFont
+ * @see #invalidate
* @since JDK1.0
* @beaninfo
* bound: true
@@ -1830,8 +1850,13 @@ public abstract class Component implements ImageObserver, MenuContainer,
/**
* Sets the locale of this component. This is a bound property.
+ *
+ * This method changes layout-related information, and therefore,
+ * invalidates the component hierarchy.
+ *
* @param l the locale to become this component's locale
* @see #getLocale
+ * @see #invalidate
* @since JDK1.1
*/
public void setLocale(Locale l) {
@@ -1951,12 +1976,17 @@ public abstract class Component implements ImageObserver, MenuContainer,
* Moves this component to a new location. The top-left corner of
* the new location is specified by the x and y
* parameters in the coordinate space of this component's parent.
+ *
+ * This method changes layout-related information, and therefore,
+ * invalidates the component hierarchy.
+ *
* @param x the x-coordinate of the new location's
* top-left corner in the parent's coordinate space
* @param y the y-coordinate of the new location's
* top-left corner in the parent's coordinate space
* @see #getLocation
* @see #setBounds
+ * @see #invalidate
* @since JDK1.1
*/
public void setLocation(int x, int y) {
@@ -1979,11 +2009,16 @@ public abstract class Component implements ImageObserver, MenuContainer,
* Moves this component to a new location. The top-left corner of
* the new location is specified by point p. Point
* p is given in the parent's coordinate space.
+ *
+ * This method changes layout-related information, and therefore,
+ * invalidates the component hierarchy.
+ *
* @param p the point defining the top-left corner
* of the new location, given in the coordinate space of this
* component's parent
* @see #getLocation
* @see #setBounds
+ * @see #invalidate
* @since JDK1.1
*/
public void setLocation(Point p) {
@@ -2018,10 +2053,15 @@ public abstract class Component implements ImageObserver, MenuContainer,
/**
* Resizes this component so that it has width width
* and height height.
+ *
+ * This method changes layout-related information, and therefore,
+ * invalidates the component hierarchy.
+ *
* @param width the new width of this component in pixels
* @param height the new height of this component in pixels
* @see #getSize
* @see #setBounds
+ * @see #invalidate
* @since JDK1.1
*/
public void setSize(int width, int height) {
@@ -2043,10 +2083,15 @@ public abstract class Component implements ImageObserver, MenuContainer,
/**
* Resizes this component so that it has width d.width
* and height d.height.
+ *
+ * This method changes layout-related information, and therefore,
+ * invalidates the component hierarchy.
+ *
* @param d the dimension specifying the new size
* of this component
* @see #setSize
* @see #setBounds
+ * @see #invalidate
* @since JDK1.1
*/
public void setSize(Dimension d) {
@@ -2089,6 +2134,10 @@ public abstract class Component implements ImageObserver, MenuContainer,
* Moves and resizes this component. The new location of the top-left
* corner is specified by x and y, and the
* new size is specified by width and height.
+ *
+ * This method changes layout-related information, and therefore,
+ * invalidates the component hierarchy.
+ *
* @param x the new x-coordinate of this component
* @param y the new y-coordinate of this component
* @param width the new width of this component
@@ -2099,6 +2148,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
* @see #setLocation(Point)
* @see #setSize(int, int)
* @see #setSize(Dimension)
+ * @see #invalidate
* @since JDK1.1
*/
public void setBounds(int x, int y, int width, int height) {
@@ -2231,12 +2281,17 @@ public abstract class Component implements ImageObserver, MenuContainer,
* position is specified by r.x and r.y,
* and its new size is specified by r.width and
* r.height
+ *
+ * This method changes layout-related information, and therefore, + * invalidates the component hierarchy. + * * @param r the new bounding rectangle for this component * @see #getBounds * @see #setLocation(int, int) * @see #setLocation(Point) * @see #setSize(int, int) * @see #setSize(Dimension) + * @see #invalidate * @since JDK1.1 */ public void setBounds(Rectangle r) { @@ -6625,8 +6680,13 @@ public abstract class Component implements ImageObserver, MenuContainer, * native screen resource. * This method is called internally by the toolkit and should * not be called directly by programs. + *
+ * This method changes layout-related information, and therefore, + * invalidates the component hierarchy. + * * @see #isDisplayable * @see #removeNotify + * @see #invalidate * @since JDK1.0 */ public void addNotify() { @@ -8593,8 +8653,13 @@ public abstract class Component implements ImageObserver, MenuContainer, * To set the orientation of an entire component * hierarchy, use * {@link #applyComponentOrientation applyComponentOrientation}. + *
+ * This method changes layout-related information, and therefore,
+ * invalidates the component hierarchy.
+ *
*
* @see ComponentOrientation
+ * @see #invalidate
*
* @author Laura Werner, IBM
* @beaninfo
@@ -8630,12 +8695,17 @@ public abstract class Component implements ImageObserver, MenuContainer,
/**
* Sets the ComponentOrientation property of this component
* and all components contained within it.
+ *
+ * This method changes layout-related information, and therefore,
+ * invalidates the component hierarchy.
+ *
*
* @param orientation the new component orientation of this component and
* the components contained within it.
* @exception NullPointerException if orientation is null.
* @see #setComponentOrientation
* @see #getComponentOrientation
+ * @see #invalidate
* @since 1.4
*/
public void applyComponentOrientation(ComponentOrientation orientation) {
diff --git a/jdk/src/share/classes/java/awt/Container.java b/jdk/src/share/classes/java/awt/Container.java
index 58ee70e22d1..010d8b08ac3 100644
--- a/jdk/src/share/classes/java/awt/Container.java
+++ b/jdk/src/share/classes/java/awt/Container.java
@@ -381,16 +381,15 @@ public class Container extends Component {
* Appends the specified component to the end of this container.
* This is a convenience method for {@link #addImpl}.
*
- * Note: If a component has been added to a container that
- * has been displayed, validate must be
- * called on that container to display the new component.
- * If multiple components are being added, you can improve
- * efficiency by calling validate only once,
- * after all the components have been added.
+ * This method changes layout-related information, and therefore,
+ * invalidates the component hierarchy. If the container has already been
+ * displayed, the hierarchy must be validated thereafter in order to
+ * display the added component.
*
* @param comp the component to be added
* @exception NullPointerException if {@code comp} is {@code null}
* @see #addImpl
+ * @see #invalidate
* @see #validate
* @see javax.swing.JComponent#revalidate()
* @return the component argument
@@ -406,8 +405,15 @@ public class Container extends Component {
*
* This method is obsolete as of 1.1. Please use the
* method add(Component, Object) instead.
+ *
+ * This method changes layout-related information, and therefore, + * invalidates the component hierarchy. If the container has already been + * displayed, the hierarchy must be validated thereafter in order to + * display the added component. + * * @exception NullPointerException if {@code comp} is {@code null} * @see #add(Component, Object) + * @see #invalidate */ public Component add(String name, Component comp) { addImpl(comp, name, -1); @@ -419,12 +425,11 @@ public class Container extends Component { * position. * This is a convenience method for {@link #addImpl}. *
- * Note: If a component has been added to a container that
- * has been displayed, validate must be
- * called on that container to display the new component.
- * If multiple components are being added, you can improve
- * efficiency by calling validate only once,
- * after all the components have been added.
+ * This method changes layout-related information, and therefore,
+ * invalidates the component hierarchy. If the container has already been
+ * displayed, the hierarchy must be validated thereafter in order to
+ * display the added component.
+ *
*
* @param comp the component to be added
* @param index the position at which to insert the component,
@@ -435,6 +440,7 @@ public class Container extends Component {
* @return the component comp
* @see #addImpl
* @see #remove
+ * @see #invalidate
* @see #validate
* @see javax.swing.JComponent#revalidate()
*/
@@ -700,6 +706,9 @@ public class Container extends Component {
* This property is guaranteed to apply only to lightweight
* non-Container components.
*
+ * This method changes layout-related information, and therefore, + * invalidates the component hierarchy. + *
* Note: Not all platforms support changing the z-order of
* heavyweight components from one container into another without
* the call to removeNotify. There is no way to detect
@@ -723,6 +732,7 @@ public class Container extends Component {
* @exception IllegalArgumentException if adding a Window
* to a container
* @see #getComponentZOrder(java.awt.Component)
+ * @see #invalidate
* @since 1.5
*/
public void setComponentZOrder(Component comp, int index) {
@@ -923,18 +933,18 @@ public class Container extends Component {
* this container's layout using the specified constraints object.
* This is a convenience method for {@link #addImpl}.
*
- * Note: If a component has been added to a container that
- * has been displayed, validate must be
- * called on that container to display the new component.
- * If multiple components are being added, you can improve
- * efficiency by calling validate only once,
- * after all the components have been added.
+ * This method changes layout-related information, and therefore,
+ * invalidates the component hierarchy. If the container has already been
+ * displayed, the hierarchy must be validated thereafter in order to
+ * display the added component.
+ *
*
* @param comp the component to be added
* @param constraints an object expressing
* layout contraints for this component
* @exception NullPointerException if {@code comp} is {@code null}
* @see #addImpl
+ * @see #invalidate
* @see #validate
* @see javax.swing.JComponent#revalidate()
* @see LayoutManager
@@ -951,12 +961,11 @@ public class Container extends Component {
* the specified constraints object.
* This is a convenience method for {@link #addImpl}.
*
- * Note: If a component has been added to a container that
- * has been displayed, validate must be
- * called on that container to display the new component.
- * If multiple components are being added, you can improve
- * efficiency by calling validate only once,
- * after all the components have been added.
+ * This method changes layout-related information, and therefore,
+ * invalidates the component hierarchy. If the container has already been
+ * displayed, the hierarchy must be validated thereafter in order to
+ * display the added component.
+ *
*
* @param comp the component to be added
* @param constraints an object expressing layout contraints for this
@@ -967,6 +976,7 @@ public class Container extends Component {
* @exception IllegalArgumentException if {@code index} is invalid (see
* {@link #addImpl} for details)
* @see #addImpl
+ * @see #invalidate
* @see #validate
* @see javax.swing.JComponent#revalidate()
* @see #remove
@@ -1014,6 +1024,11 @@ public class Container extends Component {
* super.addImpl(comp, constraints, index)
*
*
+ * This method changes layout-related information, and therefore,
+ * invalidates the component hierarchy. If the container has already been
+ * displayed, the hierarchy must be validated thereafter in order to
+ * display the added component.
+ *
* @param comp the component to be added
* @param constraints an object expressing layout constraints
* for this component
@@ -1033,6 +1048,7 @@ public class Container extends Component {
* @see #add(Component)
* @see #add(Component, int)
* @see #add(Component, java.lang.Object)
+ * @see #invalidate
* @see LayoutManager
* @see LayoutManager2
* @since JDK1.1
@@ -1145,19 +1161,18 @@ public class Container extends Component {
* This method also notifies the layout manager to remove the
* component from this container's layout via the
* removeLayoutComponent method.
- *
*
- * Note: If a component has been removed from a container that
- * had been displayed, {@link #validate} must be
- * called on that container to reflect changes.
- * If multiple components are being removed, you can improve
- * efficiency by calling {@link #validate} only once,
- * after all the components have been removed.
+ * This method changes layout-related information, and therefore,
+ * invalidates the component hierarchy. If the container has already been
+ * displayed, the hierarchy must be validated thereafter in order to
+ * reflect the changes.
+ *
*
* @param index the index of the component to be removed
* @throws ArrayIndexOutOfBoundsException if {@code index} is not in
* range {@code [0, getComponentCount()-1]}
* @see #add
+ * @see #invalidate
* @see #validate
* @see #getComponentCount
* @since JDK1.1
@@ -1209,17 +1224,15 @@ public class Container extends Component {
* This method also notifies the layout manager to remove the
* component from this container's layout via the
* removeLayoutComponent method.
- *
*
- * Note: If a component has been removed from a container that
- * had been displayed, {@link #validate} must be
- * called on that container to reflect changes.
- * If multiple components are being removed, you can improve
- * efficiency by calling {@link #validate} only once,
- * after all the components have been removed.
+ * This method changes layout-related information, and therefore,
+ * invalidates the component hierarchy. If the container has already been
+ * displayed, the hierarchy must be validated thereafter in order to
+ * reflect the changes.
*
* @param comp the component to be removed
* @see #add
+ * @see #invalidate
* @see #validate
* @see #remove(int)
*/
@@ -1239,8 +1252,15 @@ public class Container extends Component {
* This method also notifies the layout manager to remove the
* components from this container's layout via the
* removeLayoutComponent method.
+ *
+ * This method changes layout-related information, and therefore, + * invalidates the component hierarchy. If the container has already been + * displayed, the hierarchy must be validated thereafter in order to + * reflect the changes. + * * @see #add * @see #remove + * @see #invalidate */ public void removeAll() { synchronized (getTreeLock()) { @@ -1432,9 +1452,14 @@ public class Container extends Component { /** * Sets the layout manager for this container. + *
+ * This method changes layout-related information, and therefore, + * invalidates the component hierarchy. + * * @param mgr the specified layout manager * @see #doLayout * @see #getLayout + * @see #invalidate */ public void setLayout(LayoutManager mgr) { layoutMgr = mgr; @@ -1502,9 +1527,17 @@ public class Container extends Component { *
If this {@code Container} is not valid, this method invokes * the {@code validateTree} method and marks this {@code Container} * as valid. Otherwise, no action is performed. + *
+ * Note that the {@code invalidate()} method may invalidate not only the + * component it is called upon, but also the parents of the component. + * Therefore, to restore the validity of the hierarchy, the {@code + * validate()} method must be invoked on the top-most invalid container of + * the hierarchy. For performance reasons a developer may postpone the + * validation of the hierarchy till a bunch of layout-related operations + * completes, e.g. after adding all the children to the container. * * @see #add(java.awt.Component) - * @see Component#invalidate + * @see #invalidate * @see javax.swing.JComponent#revalidate() * @see #validateTree */ @@ -1588,8 +1621,13 @@ public class Container extends Component { /** * Sets the font of this container. + *
+ * This method changes layout-related information, and therefore,
+ * invalidates the component hierarchy.
+ *
* @param f The font to become this container's font.
* @see Component#getFont
+ * @see #invalidate
* @since JDK1.0
*/
public void setFont(Font f) {
@@ -3386,12 +3424,16 @@ public class Container extends Component {
/**
* Sets the ComponentOrientation property of this container
* and all components contained within it.
+ *
+ * This method changes layout-related information, and therefore,
+ * invalidates the component hierarchy.
*
* @param o the new component orientation of this container and
* the components contained within it.
* @exception NullPointerException if orientation is null.
* @see Component#setComponentOrientation
* @see Component#getComponentOrientation
+ * @see #invalidate
* @since 1.4
*/
public void applyComponentOrientation(ComponentOrientation o) {
@@ -4069,16 +4111,16 @@ public class Container extends Component {
mixingLog.fine("this = " + this);
}
- if (!isMixingNeeded()) {
- return;
- }
-
boolean isLightweight = isLightweight();
if (isLightweight && isRecursivelyVisibleUpToHeavyweightContainer()) {
recursiveShowHeavyweightChildren();
}
+ if (!isMixingNeeded()) {
+ return;
+ }
+
if (!isLightweight || (isLightweight && hasHeavyweightDescendants())) {
recursiveApplyCurrentShape();
}
diff --git a/jdk/src/share/classes/java/awt/EventQueue.java b/jdk/src/share/classes/java/awt/EventQueue.java
index fedf3fb6fac..3e9febf79b7 100644
--- a/jdk/src/share/classes/java/awt/EventQueue.java
+++ b/jdk/src/share/classes/java/awt/EventQueue.java
@@ -843,7 +843,8 @@ public class EventQueue {
final void initDispatchThread() {
synchronized (this) {
- if (dispatchThread == null && !threadGroup.isDestroyed()) {
+ AppContext appContext = AppContext.getAppContext();
+ if (dispatchThread == null && !threadGroup.isDestroyed() && !appContext.isDisposed()) {
dispatchThread = (EventDispatchThread)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
diff --git a/jdk/src/share/classes/javax/swing/JFileChooser.java b/jdk/src/share/classes/javax/swing/JFileChooser.java
index 8ba9c7c42af..dae4a1ce599 100644
--- a/jdk/src/share/classes/javax/swing/JFileChooser.java
+++ b/jdk/src/share/classes/javax/swing/JFileChooser.java
@@ -715,7 +715,7 @@ public class JFileChooser extends JComponent implements Accessible {
*
+ * import javax.swing.*;
+ * import javax.swing.plaf.LayerUI;
+ * import java.awt.*;
+ *
+ * public class JLayerSample {
+ *
+ * private static JLayer<JComponent> createLayer() {
+ * // This custom layerUI will fill the layer with translucent green
+ * // and print out all mouseMotion events generated within its borders
+ * LayerUI<JComponent> layerUI = new LayerUI<JComponent>() {
+ *
+ * public void paint(Graphics g, JComponent c) {
+ * // paint the layer as is
+ * super.paint(g, c);
+ * // fill it with the translucent green
+ * g.setColor(new Color(0, 128, 0, 128));
+ * g.fillRect(0, 0, c.getWidth(), c.getHeight());
+ * }
+ *
+ * public void installUI(JComponent c) {
+ * super.installUI(c);
+ * // enable mouse motion events for the layer's subcomponents
+ * ((JLayer) c).setLayerEventMask(AWTEvent.MOUSE_MOTION_EVENT_MASK);
+ * }
+ *
+ * public void uninstallUI(JComponent c) {
+ * super.uninstallUI(c);
+ * // reset the layer event mask
+ * ((JLayer) c).setLayerEventMask(0);
+ * }
+ *
+ * // overridden method which catches MouseMotion events
+ * public void eventDispatched(AWTEvent e, JLayer<? extends JComponent> l) {
+ * System.out.println("AWTEvent detected: " + e);
+ * }
+ * };
* // create a component to be decorated with the layer
- * JPanel panel = new JPanel();
- * panel.add(new JButton("JButton"));
- * // This custom layerUI will fill the layer with translucent green
- * // and print out all mouseMotion events generated within its borders
- * LayerUI<JPanel> layerUI = new LayerUI<JPanel>() {
- * public void paint(Graphics g, JCompo nent c) {
- * // paint the layer as is
- * super.paint(g, c);
- * // fill it with the translucent green
- * g.setColor(new Color(0, 128, 0, 128));
- * g.fillRect(0, 0, c.getWidth(), c.getHeight());
- * }
- * // overridden method which catches MouseMotion events
- * public void eventDispatched(AWTEvent e, JLayer<JPanel> l) {
- * System.out.println("AWTEvent detected: " + e);
- * }
- * };
- * // create the layer for the panel using our custom layerUI
- * JLayer<JPanel> layer = new JLayer<JPanel>(panel, layerUI);
- * // work with the layer as with any other Swing component
- * frame.add(layer);
+ * JPanel panel = new JPanel();
+ * panel.add(new JButton("JButton"));
+ *
+ * // create the layer for the panel using our custom layerUI
+ * return new JLayer<JComponent>(panel, layerUI);
+ * }
+ *
+ * private static void createAndShowGUI() {
+ * final JFrame frame = new JFrame();
+ * frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ *
+ * // work with the layer as with any other Swing component
+ * frame.add(createLayer());
+ *
+ * frame.setSize(200, 200);
+ * frame.setLocationRelativeTo(null);
+ * frame.setVisible(true);
+ * }
+ *
+ * public static void main(String[] args) throws Exception {
+ * SwingUtilities.invokeAndWait(new Runnable() {
+ * public void run() {
+ * createAndShowGUI();
+ * }
+ * });
+ * }
+ * }
*
*
* Note: {@code JLayer} doesn't support the following methods:
@@ -291,7 +333,9 @@ public final class JLayerImage - icon nn from resource 124 in comctl32.dll (Windows only).
+ * "fileChooserIcon Image - icon can be ListView, DetailsView, UpFolder, NewFolder or
+ * ViewMenu (Windows only).
*
* @return An Object matching the key string.
*/
diff --git a/jdk/src/share/classes/sun/swing/SwingUtilities2.java b/jdk/src/share/classes/sun/swing/SwingUtilities2.java
index 201cb43e3e4..60681d56fbc 100644
--- a/jdk/src/share/classes/sun/swing/SwingUtilities2.java
+++ b/jdk/src/share/classes/sun/swing/SwingUtilities2.java
@@ -192,6 +192,19 @@ public class SwingUtilities2 {
fontCache = new LSBCacheEntry[CACHE_SIZE];
}
+ /**
+ * Fill the character buffer cache. Return the buffer length.
+ */
+ private static int syncCharsBuffer(String s) {
+ int length = s.length();
+ if ((charsBuffer == null) || (charsBuffer.length < length)) {
+ charsBuffer = s.toCharArray();
+ } else {
+ s.getChars(0, length, charsBuffer, 0);
+ }
+ return length;
+ }
+
/**
* checks whether TextLayout is required to handle characters.
*
@@ -237,15 +250,23 @@ public class SwingUtilities2 {
* Returns the left side bearing of the first character of string. The
* left side bearing is calculated from the passed in
* FontMetrics. If the passed in String is less than one
- * character, this will throw a StringIndexOutOfBoundsException exception.
+ * character {@code 0} is returned.
*
* @param c JComponent that will display the string
* @param fm FontMetrics used to measure the String width
* @param string String to get the left side bearing for.
+ * @throws NullPointerException if {@code string} is {@code null}
+ *
+ * @return the left side bearing of the first character of string
+ * or {@code 0} if the string is empty
*/
public static int getLeftSideBearing(JComponent c, FontMetrics fm,
String string) {
- return getLeftSideBearing(c, fm, string.charAt(0));
+ int res = 0;
+ if (!string.isEmpty()) {
+ res = getLeftSideBearing(c, fm, string.charAt(0));
+ }
+ return res;
}
/**
@@ -353,7 +374,21 @@ public class SwingUtilities2 {
if (string == null || string.equals("")) {
return 0;
}
- return fm.stringWidth(string);
+ boolean needsTextLayout = ((c != null) &&
+ (c.getClientProperty(TextAttribute.NUMERIC_SHAPING) != null));
+ if (needsTextLayout) {
+ synchronized(charsBufferLock) {
+ int length = syncCharsBuffer(string);
+ needsTextLayout = isComplexLayout(charsBuffer, 0, length);
+ }
+ }
+ if (needsTextLayout) {
+ TextLayout layout = createTextLayout(c, string,
+ fm.getFont(), fm.getFontRenderContext());
+ return (int) layout.getAdvance();
+ } else {
+ return fm.stringWidth(string);
+ }
}
@@ -394,21 +429,11 @@ public class SwingUtilities2 {
String string, int availTextWidth) {
// c may be null here.
String clipString = "...";
- int stringLength = string.length();
availTextWidth -= SwingUtilities2.stringWidth(c, fm, clipString);
- if (availTextWidth <= 0) {
- //can not fit any characters
- return clipString;
- }
-
boolean needsTextLayout;
synchronized (charsBufferLock) {
- if (charsBuffer == null || charsBuffer.length < stringLength) {
- charsBuffer = string.toCharArray();
- } else {
- string.getChars(0, stringLength, charsBuffer, 0);
- }
+ int stringLength = syncCharsBuffer(string);
needsTextLayout =
isComplexLayout(charsBuffer, 0, stringLength);
if (!needsTextLayout) {
@@ -425,6 +450,10 @@ public class SwingUtilities2 {
if (needsTextLayout) {
FontRenderContext frc = getFontRenderContext(c, fm);
AttributedString aString = new AttributedString(string);
+ if (c != null) {
+ aString.addAttribute(TextAttribute.NUMERIC_SHAPING,
+ c.getClientProperty(TextAttribute.NUMERIC_SHAPING));
+ }
LineBreakMeasurer measurer =
new LineBreakMeasurer(aString.getIterator(), frc);
int nChars = measurer.nextOffset(availTextWidth);
@@ -465,7 +494,7 @@ public class SwingUtilities2 {
*/
float screenWidth = (float)
g2d.getFont().getStringBounds(text, DEFAULT_FRC).getWidth();
- TextLayout layout = new TextLayout(text, g2d.getFont(),
+ TextLayout layout = createTextLayout(c, text, g2d.getFont(),
g2d.getFontRenderContext());
layout = layout.getJustifiedLayout(screenWidth);
@@ -505,7 +534,21 @@ public class SwingUtilities2 {
}
}
- g.drawString(text, x, y);
+ boolean needsTextLayout = ((c != null) &&
+ (c.getClientProperty(TextAttribute.NUMERIC_SHAPING) != null));
+ if (needsTextLayout) {
+ synchronized(charsBufferLock) {
+ int length = syncCharsBuffer(text);
+ needsTextLayout = isComplexLayout(charsBuffer, 0, length);
+ }
+ }
+ if (needsTextLayout) {
+ TextLayout layout = createTextLayout(c, text, g2.getFont(),
+ g2.getFontRenderContext());
+ layout.draw(g2, x, y);
+ } else {
+ g.drawString(text, x, y);
+ }
if (oldAAValue != null) {
g2.setRenderingHint(KEY_TEXT_ANTIALIASING, oldAAValue);
@@ -547,11 +590,7 @@ public class SwingUtilities2 {
boolean needsTextLayout = isPrinting;
if (!needsTextLayout) {
synchronized (charsBufferLock) {
- if (charsBuffer == null || charsBuffer.length < textLength) {
- charsBuffer = text.toCharArray();
- } else {
- text.getChars(0, textLength, charsBuffer, 0);
- }
+ syncCharsBuffer(text);
needsTextLayout =
isComplexLayout(charsBuffer, 0, textLength);
}
@@ -567,7 +606,7 @@ public class SwingUtilities2 {
Graphics2D g2d = getGraphics2D(g);
if (g2d != null) {
TextLayout layout =
- new TextLayout(text, g2d.getFont(),
+ createTextLayout(c, text, g2d.getFont(),
g2d.getFontRenderContext());
if (isPrinting) {
float screenWidth = (float)g2d.getFont().
@@ -728,7 +767,7 @@ public class SwingUtilities2 {
!isFontRenderContextPrintCompatible
(deviceFontRenderContext, frc)) {
TextLayout layout =
- new TextLayout(new String(data,offset,length),
+ createTextLayout(c, new String(data, offset, length),
g2d.getFont(),
deviceFontRenderContext);
float screenWidth = (float)g2d.getFont().
@@ -846,6 +885,20 @@ public class SwingUtilities2 {
return retVal;
}
+ private static TextLayout createTextLayout(JComponent c, String s,
+ Font f, FontRenderContext frc) {
+ Object shaper = (c == null ?
+ null : c.getClientProperty(TextAttribute.NUMERIC_SHAPING));
+ if (shaper == null) {
+ return new TextLayout(s, f, frc);
+ } else {
+ MapImage - icon nn from resource 216 in shell32.dll,
- * or if not found there from resource 124 in comctl32.dll (Windows only).
+ * "fileChooserIcon Image - icon can be ListView, DetailsView, UpFolder, NewFolder or
+ * ViewMenu (Windows only).
* "optionPaneIcon iconName":
* Returns an Image - icon from the system icon list
*
@@ -303,26 +322,23 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
}
return folders.toArray(new File[folders.size()]);
} else if (key.startsWith("fileChooserIcon ")) {
- int i = -1;
- String name = key.substring(key.indexOf(" ")+1);
- try {
- i = Integer.parseInt(name);
- } catch (NumberFormatException ex) {
- if (name.equals("ListView")) {
- i = (USE_SHELL32_ICONS) ? 21 : 2;
- } else if (name.equals("DetailsView")) {
- i = (USE_SHELL32_ICONS) ? 23 : 3;
- } else if (name.equals("UpFolder")) {
- i = (USE_SHELL32_ICONS) ? 28 : 8;
- } else if (name.equals("NewFolder")) {
- i = (USE_SHELL32_ICONS) ? 31 : 11;
- } else if (name.equals("ViewMenu")) {
- i = (USE_SHELL32_ICONS) ? 21 : 2;
- }
- }
- if (i >= 0) {
- return Win32ShellFolder2.getFileChooserIcon(i);
+ String name = key.substring(key.indexOf(" ") + 1);
+
+ int iconIndex;
+
+ if (name.equals("ListView") || name.equals("ViewMenu")) {
+ iconIndex = VIEW_LIST;
+ } else if (name.equals("DetailsView")) {
+ iconIndex = VIEW_DETAILS;
+ } else if (name.equals("UpFolder")) {
+ iconIndex = VIEW_PARENTFOLDER;
+ } else if (name.equals("NewFolder")) {
+ iconIndex = VIEW_NEWFOLDER;
+ } else {
+ return null;
}
+
+ return getStandardViewButton(iconIndex);
} else if (key.startsWith("optionPaneIcon ")) {
Win32ShellFolder2.SystemIcon iconType;
if (key == "optionPaneIcon Error") {
diff --git a/jdk/src/windows/native/sun/windows/ShellFolder2.cpp b/jdk/src/windows/native/sun/windows/ShellFolder2.cpp
index 64eea69bced..353e47cffb3 100644
--- a/jdk/src/windows/native/sun/windows/ShellFolder2.cpp
+++ b/jdk/src/windows/native/sun/windows/ShellFolder2.cpp
@@ -256,7 +256,6 @@ JNIEXPORT void JNICALL Java_sun_awt_shell_Win32ShellFolderManager2_uninitializeC
static IShellIcon* getIShellIcon(IShellFolder* pIShellFolder) {
// http://msdn.microsoft.com/library/en-us/shellcc/platform/Shell/programmersguide/shell_int/shell_int_programming/std_ifaces.asp
HRESULT hres;
- HICON hIcon = NULL;
IShellIcon* pIShellIcon;
if (pIShellFolder != NULL) {
hres = pIShellFolder->QueryInterface(IID_IShellIcon, (void**)&pIShellIcon);
@@ -965,89 +964,40 @@ JNIEXPORT jintArray JNICALL Java_sun_awt_shell_Win32ShellFolder2_getIconBits
/*
* Class: sun_awt_shell_Win32ShellFolder2
- * Method: getFileChooserBitmapBits
- * Signature: ()[I
+ * Method: getStandardViewButton0
+ * Signature: (I)[I
*/
-JNIEXPORT jintArray JNICALL Java_sun_awt_shell_Win32ShellFolder2_getFileChooserBitmapBits
- (JNIEnv* env, jclass cls)
+JNIEXPORT jintArray JNICALL Java_sun_awt_shell_Win32ShellFolder2_getStandardViewButton0
+ (JNIEnv* env, jclass cls, jint iconIndex)
{
- HBITMAP hBitmap = NULL;
- BITMAP bm;
- HINSTANCE libComCtl32;
- HINSTANCE libShell32;
+ jintArray result = NULL;
- libShell32 = LoadLibrary(TEXT("shell32.dll"));
- if (libShell32 != NULL) {
- hBitmap = (HBITMAP)LoadImage(libShell32,
- IS_WINVISTA ? TEXT("IDB_TB_SH_DEF_16") : MAKEINTRESOURCE(216),
- IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
+ // Create a toolbar
+ HWND hWndToolbar = ::CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
+ 0, 0, 0, 0, 0,
+ NULL, NULL, NULL, NULL);
- if (hBitmap == NULL) {
- // version of shell32.dll doesn't match OS version.
- // So we either are in a Vista Compatibility Mode
- // or shell32.dll was copied from OS of another version
- hBitmap = (HBITMAP)LoadImage(libShell32,
- IS_WINVISTA ? MAKEINTRESOURCE(216) : TEXT("IDB_TB_SH_DEF_16"),
- IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
+ if (hWndToolbar != NULL) {
+ SendMessage(hWndToolbar, TB_LOADIMAGES, (WPARAM)IDB_VIEW_SMALL_COLOR, (LPARAM)HINST_COMMCTRL);
+
+ HIMAGELIST hImageList = (HIMAGELIST) SendMessage(hWndToolbar, TB_GETIMAGELIST, 0, 0);
+
+ if (hImageList != NULL) {
+ HICON hIcon = ImageList_GetIcon(hImageList, iconIndex, ILD_TRANSPARENT);
+
+ if (hIcon != NULL) {
+ result = Java_sun_awt_shell_Win32ShellFolder2_getIconBits(env, cls, ptr_to_jlong(hIcon), 16);
+
+ DestroyIcon(hIcon);
+ }
+
+ ImageList_Destroy(hImageList);
}
- }
- if (hBitmap == NULL) {
- libComCtl32 = LoadLibrary(TEXT("comctl32.dll"));
- if (libComCtl32 != NULL) {
- hBitmap = (HBITMAP)LoadImage(libComCtl32, MAKEINTRESOURCE(124),
- IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
- }
- }
- if (hBitmap == NULL) {
- return NULL;
+
+ DestroyWindow(hWndToolbar);
}
- GetObject(hBitmap, sizeof(bm), (LPSTR)&bm);
-
- // Get the screen DC
- HDC dc = GetDC(NULL);
- if (dc == NULL) {
- return NULL;
- }
-
- // Set up BITMAPINFO
- BITMAPINFO bmi;
- memset(&bmi, 0, sizeof(BITMAPINFO));
- bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- bmi.bmiHeader.biWidth = bm.bmWidth;
- bmi.bmiHeader.biHeight = -bm.bmHeight;
- bmi.bmiHeader.biPlanes = 1;
- bmi.bmiHeader.biBitCount = 32;
- bmi.bmiHeader.biCompression = BI_RGB;
- // Extract the color bitmap
- int numPixels = bm.bmWidth * bm.bmHeight;
- //long colorBits[192 * 16];
- long *colorBits = (long*)safe_Malloc(numPixels * sizeof(long));
- if (GetDIBits(dc, hBitmap, 0, bm.bmHeight, colorBits, &bmi, DIB_RGB_COLORS) == 0) {
- return NULL;
- }
-
- // Release DC
- ReleaseDC(NULL, dc);
-
- // The color of the first pixel defines the transparency, according
- // to the documentation for LR_LOADTRANSPARENT at
- // http://msdn.microsoft.com/library/psdk/winui/resource_9fhi.htm
- long transparent = colorBits[0];
- for (int i=0; i < numPixels; i++) {
- if (colorBits[i] != transparent) {
- colorBits[i] |= 0xff000000;
- }
- }
-
- // Create java array
- jintArray bits = env->NewIntArray(numPixels);
- // Copy values to java array
- env->SetIntArrayRegion(bits, 0, numPixels, colorBits);
- // Fix 4745575 GDI Resource Leak
- ::DeleteObject(hBitmap);
- ::FreeLibrary(libComCtl32);
- return bits;
+ return result;
}
/*
diff --git a/jdk/test/javax/swing/JComponent/4337267/bug4337267.java b/jdk/test/javax/swing/JComponent/4337267/bug4337267.java
new file mode 100644
index 00000000000..a3e3f24b0ad
--- /dev/null
+++ b/jdk/test/javax/swing/JComponent/4337267/bug4337267.java
@@ -0,0 +1,254 @@
+/*
+ * @test
+ * @bug 4337267
+ * @summary test that numeric shaping works in Swing components
+ * @author Sergey Groznyh
+ * @run main bug4337267
+ */
+
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.font.NumericShaper;
+import java.awt.font.TextAttribute;
+import java.awt.image.BufferedImage;
+import javax.swing.BoxLayout;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextArea;
+import javax.swing.SwingUtilities;
+
+public class bug4337267 {
+ TestJPanel p1, p2;
+ TestBufferedImage i1, i2;
+ JComponent[] printq;
+ JFrame window;
+ static boolean testFailed = false;
+ static boolean done = false;
+
+ String shaped =
+ "000 (E) 111 (A) \u0641\u0642\u0643 \u0662\u0662\u0662 (E) 333";
+ String text = "000 (E) 111 (A) \u0641\u0642\u0643 222 (E) 333";
+
+ void run() {
+ initUI();
+ testTextComponent();
+ testNonTextComponentHTML();
+ testNonTextComponentPlain();
+
+ doneTask();
+ }
+
+ void initUI() {
+ window = new JFrame("bug4337267");
+ window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ window.setSize(800, 600);
+ Component content = createContentPane();
+ window.add(content);
+ window.setVisible(true);
+ }
+
+ Runnable printComponents = new Runnable() {
+ public void run() {
+ printComponent(printq[0], i1);
+ printComponent(printq[1], i2);
+ }
+ };
+
+ Runnable compareRasters = new Runnable() {
+ public void run() {
+ assertEquals(p1.image, p2.image);
+ assertEquals(i1, i2);
+ }
+ };
+
+ void doneTask() {
+ final Object monitor = this;
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ done = true;
+ synchronized(monitor) {
+ monitor.notify();
+ }
+ }
+ });
+ }
+
+
+ void fail(String message) {
+ testFailed = true;
+ throw new RuntimeException(message);
+ }
+
+ void assertEquals(Object o1, Object o2) {
+ if ((o1 == null) && (o2 != null)) {
+ fail("Expected null, got " + o2);
+ } else if ((o1 != null) && (o2 == null)) {
+ fail("Expected " + o1 + ", got null");
+ } else if (!o1.equals(o2)) {
+ fail("Expected " + o1 + ", got " + o2);
+ }
+ }
+
+ void testTextComponent() {
+ System.out.println("testTextComponent:");
+ JTextArea area1 = new JTextArea();
+ injectComponent(p1, area1, false);
+ area1.setText(shaped);
+ JTextArea area2 = new JTextArea();
+ injectComponent(p2, area2, true);
+ area2.setText(text);
+ window.repaint();
+ printq = new JComponent[] { area1, area2 };
+ SwingUtilities.invokeLater(printComponents);
+ SwingUtilities.invokeLater(compareRasters);
+ }
+
+ void testNonTextComponentHTML() {
+ System.out.println("testNonTextComponentHTML:");
+ JLabel label1 = new JLabel();
+ injectComponent(p1, label1, false);
+ label1.setText("" + shaped);
+ JLabel label2 = new JLabel();
+ injectComponent(p2, label2, true);
+ label2.setText("" + text);
+ window.repaint();
+ printq = new JComponent[] { label1, label2 };
+ SwingUtilities.invokeLater(printComponents);
+ SwingUtilities.invokeLater(compareRasters);
+ }
+
+ void testNonTextComponentPlain() {
+ System.out.println("testNonTextComponentHTML:");
+ JLabel label1 = new JLabel();
+ injectComponent(p1, label1, false);
+ label1.setText(shaped);
+ JLabel label2 = new JLabel();
+ injectComponent(p2, label2, true);
+ label2.setText(text);
+ window.repaint();
+ printq = new JComponent[] { label1, label2 };
+ SwingUtilities.invokeLater(printComponents);
+ SwingUtilities.invokeLater(compareRasters);
+ }
+
+ void setShaping(JComponent c) {
+ c.putClientProperty(TextAttribute.NUMERIC_SHAPING,
+ NumericShaper.getContextualShaper(NumericShaper.ARABIC));
+ }
+
+ void injectComponent(JComponent p, JComponent c, boolean shape) {
+ if (shape) {
+ setShaping(c);
+ }
+ p.removeAll();
+ p.add(c);
+ }
+
+ void printComponent(JComponent c, TestBufferedImage i) {
+ Graphics g = i.getGraphics();
+ g.setColor(c.getBackground());
+ g.fillRect(0, 0, i.getWidth(), i.getHeight());
+ c.print(g);
+ }
+
+ Component createContentPane() {
+ Dimension size = new Dimension(500, 100);
+ i1 = new TestBufferedImage(size.width, size.height,
+ BufferedImage.TYPE_INT_ARGB);
+ i2 = new TestBufferedImage(size.width, size.height,
+ BufferedImage.TYPE_INT_ARGB);
+ p1 = new TestJPanel();
+ p1.setPreferredSize(size);
+ p2 = new TestJPanel();
+ p2.setPreferredSize(size);
+ JPanel panel = new JPanel();
+ panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
+ panel.add(p1);
+ panel.add(p2);
+
+ return panel;
+ }
+
+ static class TestBufferedImage extends BufferedImage {
+ int MAX_GLITCHES = 0;
+
+ TestBufferedImage(int width, int height, int imageType) {
+ super(width, height, imageType);
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (! (other instanceof TestBufferedImage)) {
+ return false;
+ }
+ TestBufferedImage image2 = (TestBufferedImage) other;
+ int width = getWidth();
+ int height = getHeight();
+ if ((image2.getWidth() != width) || (image2.getHeight() != height)) {
+ return false;
+ }
+ int glitches = 0;
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ int rgb1 = getRGB(x, y);
+ int rgb2 = image2.getRGB(x, y);
+ if (rgb1 != rgb2) {
+ //System.out.println(x+" "+y+" "+rgb1+" "+rgb2);
+ glitches++;
+ }
+ }
+ }
+ return glitches <= MAX_GLITCHES;
+ }
+ }
+
+ static class TestJPanel extends JPanel {
+ TestBufferedImage image = createImage(new Dimension(1, 1));
+
+ TestBufferedImage createImage(Dimension d) {
+ return new TestBufferedImage(d.width, d.height,
+ BufferedImage.TYPE_INT_ARGB);
+ }
+
+ public void setPreferredSize(Dimension size) {
+ super.setPreferredSize(size);
+ image = createImage(size);
+ }
+
+ public void paint(Graphics g) {
+ Graphics g0 = image.getGraphics();
+ super.paint(g0);
+ g.drawImage(image, 0, 0, this);
+ }
+ }
+
+
+
+ public static void main(String[] args) throws Throwable {
+ final bug4337267 test = new bug4337267();
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ test.run();
+ }
+ });
+
+ synchronized(test) {
+ while (!done) {
+ try {
+ test.wait();
+ } catch (InterruptedException ex) {
+ // do nothing
+ }
+ }
+ }
+
+ if (testFailed) {
+ throw new RuntimeException("FAIL");
+ }
+
+ System.out.println("OK");
+ }
+}
diff --git a/jdk/test/javax/swing/JFileChooser/6489130/bug6489130.java b/jdk/test/javax/swing/JFileChooser/6489130/bug6489130.java
new file mode 100644
index 00000000000..684d691fedc
--- /dev/null
+++ b/jdk/test/javax/swing/JFileChooser/6489130/bug6489130.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. 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.
+ *
+ * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 6489130
+ * @summary FileChooserDemo hung by keeping pressing Enter key
+ * @author Pavel Porvatov
+ @run main bug6489130
+ */
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+public class bug6489130 {
+ private final JFileChooser chooser = new JFileChooser();
+
+ private static final CountDownLatch MUX = new CountDownLatch(1);
+
+ private final Timer timer = new Timer(1000, new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ switch (state) {
+ case 0:
+ case 1: {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ chooser.showOpenDialog(null);
+ }
+ });
+
+ break;
+ }
+
+ case 2:
+ case 3: {
+ Window[] windows = Frame.getWindows();
+
+ if (windows.length > 0) {
+ windows[0].dispose();
+ }
+
+ break;
+ }
+
+ case 4: {
+ MUX.countDown();
+
+ break;
+ }
+ }
+
+ state++;
+ }
+ });
+
+ private int state = 0;
+
+ public static void main(String[] args) throws InterruptedException {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ new bug6489130().run();
+ }
+ });
+
+ if (!MUX.await(10, TimeUnit.SECONDS)) {
+ throw new RuntimeException("Timeout");
+ }
+ }
+
+ private void run() {
+ timer.start();
+ }
+}
diff --git a/jdk/test/javax/swing/JFileChooser/6840086/bug6840086.java b/jdk/test/javax/swing/JFileChooser/6840086/bug6840086.java
new file mode 100644
index 00000000000..bdd012f4cf3
--- /dev/null
+++ b/jdk/test/javax/swing/JFileChooser/6840086/bug6840086.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. 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.
+ *
+ * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ @bug 6840086
+ @summary JFileChooser lacks icons on top right when running on Windows 7
+ @author Pavel Porvatov
+ @run main bug6840086
+*/
+
+import sun.awt.OSInfo;
+import sun.awt.shell.ShellFolder;
+
+import java.awt.*;
+
+public class bug6840086 {
+ private static final String[] KEYS = {
+ "fileChooserIcon ListView",
+ "fileChooserIcon ViewMenu",
+ "fileChooserIcon DetailsView",
+ "fileChooserIcon UpFolder",
+ "fileChooserIcon NewFolder",
+ };
+
+ public static void main(String[] args) {
+ if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
+ System.out.println("The test was skipped because it is sensible only for Windows.");
+
+ return;
+ }
+
+ for (String key : KEYS) {
+ Image image = (Image) ShellFolder.get(key);
+
+ if (image == null) {
+ throw new RuntimeException("The image '" + key + "' not found.");
+ }
+
+ if (image != ShellFolder.get(key)) {
+ throw new RuntimeException("The image '" + key + "' is not cached.");
+ }
+ }
+
+ System.out.println("The test passed.");
+ }
+}
diff --git a/jdk/test/javax/swing/JLayer/6875716/bug6875716.java b/jdk/test/javax/swing/JLayer/6875716/bug6875716.java
new file mode 100644
index 00000000000..c59c4544a6e
--- /dev/null
+++ b/jdk/test/javax/swing/JLayer/6875716/bug6875716.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc. 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.
+ *
+ * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+ * @bug 6875716
+ * @summary JLayer.remove((Component)null) should behave consistently in (not) throwing NPE
+ * @author Alexander Potochkin
+ */
+
+import javax.swing.*;
+import java.awt.*;
+
+public class bug6875716 {
+
+ public static void main(String[] args) throws Exception {
+ JLayer