提交 096be1c3 编写于 作者: L lana

Merge

......@@ -1163,8 +1163,14 @@ public final class NumericShaper implements java.io.Serializable {
lastkey = newkey;
ctxKey = newkey;
if (((mask & EASTERN_ARABIC) != 0) && (ctxKey == ARABIC_KEY || ctxKey == EASTERN_ARABIC_KEY)) {
if (((mask & EASTERN_ARABIC) != 0) &&
(ctxKey == ARABIC_KEY ||
ctxKey == EASTERN_ARABIC_KEY)) {
ctxKey = EASTERN_ARABIC_KEY;
} else if (((mask & ARABIC) != 0) &&
(ctxKey == ARABIC_KEY ||
ctxKey == EASTERN_ARABIC_KEY)) {
ctxKey = ARABIC_KEY;
} else if ((mask & (1<<ctxKey)) == 0) {
ctxKey = EUROPEAN_KEY;
}
......
......@@ -1330,8 +1330,9 @@ public class JEditorPane extends JTextComponent {
*/
public Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
JViewport port = SwingUtilities.getParentViewport(this);
if (port != null) {
Container parent = SwingUtilities.getUnwrappedParent(this);
if (parent instanceof JViewport) {
JViewport port = (JViewport) parent;
TextUI ui = getUI();
int prefWidth = d.width;
int prefHeight = d.height;
......@@ -1452,8 +1453,9 @@ public class JEditorPane extends JTextComponent {
* match its own, false otherwise
*/
public boolean getScrollableTracksViewportWidth() {
JViewport port = SwingUtilities.getParentViewport(this);
if (port != null) {
Container parent = SwingUtilities.getUnwrappedParent(this);
if (parent instanceof JViewport) {
JViewport port = (JViewport) parent;
TextUI ui = getUI();
int w = port.getWidth();
Dimension min = ui.getMinimumSize(this);
......@@ -1474,8 +1476,9 @@ public class JEditorPane extends JTextComponent {
* false otherwise
*/
public boolean getScrollableTracksViewportHeight() {
JViewport port = SwingUtilities.getParentViewport(this);
if (port != null) {
Container parent = SwingUtilities.getUnwrappedParent(this);
if (parent instanceof JViewport) {
JViewport port = (JViewport) parent;
TextUI ui = getUI();
int h = port.getHeight();
Dimension min = ui.getMinimumSize(this);
......
......@@ -163,18 +163,6 @@ public final class JLayer<V extends Component>
private static final LayerEventController eventController =
new LayerEventController();
private static final long ACCEPTED_EVENTS =
AWTEvent.COMPONENT_EVENT_MASK |
AWTEvent.CONTAINER_EVENT_MASK |
AWTEvent.FOCUS_EVENT_MASK |
AWTEvent.KEY_EVENT_MASK |
AWTEvent.MOUSE_WHEEL_EVENT_MASK |
AWTEvent.MOUSE_MOTION_EVENT_MASK |
AWTEvent.MOUSE_EVENT_MASK |
AWTEvent.INPUT_METHOD_EVENT_MASK |
AWTEvent.HIERARCHY_EVENT_MASK |
AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK;
/**
* Creates a new {@code JLayer} object with a {@code null} view component
* and {@code null} {@link javax.swing.plaf.LayerUI}.
......@@ -396,24 +384,14 @@ public final class JLayer<V extends Component>
}
/**
* Sets the bitmask of event types to receive by this {@code JLayer}.
* Here is the list of the supported event types:
* <ul>
* <li>AWTEvent.COMPONENT_EVENT_MASK</li>
* <li>AWTEvent.CONTAINER_EVENT_MASK</li>
* <li>AWTEvent.FOCUS_EVENT_MASK</li>
* <li>AWTEvent.KEY_EVENT_MASK</li>
* <li>AWTEvent.MOUSE_WHEEL_EVENT_MASK</li>
* <li>AWTEvent.MOUSE_MOTION_EVENT_MASK</li>
* <li>AWTEvent.MOUSE_EVENT_MASK</li>
* <li>AWTEvent.INPUT_METHOD_EVENT_MASK</li>
* <li>AWTEvent.HIERARCHY_EVENT_MASK</li>
* <li>AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK</li>
* </ul>
* Enables the events from JLayer and <b>all its descendants</b>
* defined by the specified event mask parameter
* to be delivered to the
* {@link LayerUI#eventDispatched(AWTEvent, JLayer)} method.
* <p/>
* If {@code LayerUI} is installed,
* {@link javax.swing.plaf.LayerUI#eventDispatched(AWTEvent, JLayer)} method
* will only receive events that match the event mask.
* Events are delivered provided that {@code LayerUI} is set
* for this {@code JLayer} and the {@code JLayer}
* is displayable.
* <p/>
* The following example shows how to correclty use this method
* in the {@code LayerUI} implementations:
......@@ -433,19 +411,15 @@ public final class JLayer<V extends Component>
* }
* </pre>
*
* By default {@code JLayer} receives no events.
* By default {@code JLayer} receives no events and its event mask is {@code 0}.
*
* @param layerEventMask the bitmask of event types to receive
*
* @throws IllegalArgumentException if the {@code layerEventMask} parameter
* contains unsupported event types
* @see #getLayerEventMask()
* @see LayerUI#eventDispatched(AWTEvent, JLayer)
* @see Component#isDisplayable()
*/
public void setLayerEventMask(long layerEventMask) {
if (layerEventMask != (layerEventMask & ACCEPTED_EVENTS)) {
throw new IllegalArgumentException(
"The event bitmask contains unsupported event types");
}
long oldEventMask = getLayerEventMask();
this.eventMask = layerEventMask;
firePropertyChange("layerEventMask", oldEventMask, layerEventMask);
......@@ -629,6 +603,18 @@ public final class JLayer<V extends Component>
private long currentEventMask;
private static final long ACCEPTED_EVENTS =
AWTEvent.COMPONENT_EVENT_MASK |
AWTEvent.CONTAINER_EVENT_MASK |
AWTEvent.FOCUS_EVENT_MASK |
AWTEvent.KEY_EVENT_MASK |
AWTEvent.MOUSE_WHEEL_EVENT_MASK |
AWTEvent.MOUSE_MOTION_EVENT_MASK |
AWTEvent.MOUSE_EVENT_MASK |
AWTEvent.INPUT_METHOD_EVENT_MASK |
AWTEvent.HIERARCHY_EVENT_MASK |
AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK;
@SuppressWarnings("unchecked")
public void eventDispatched(AWTEvent event) {
Object source = event.getSource();
......@@ -660,6 +646,8 @@ public final class JLayer<V extends Component>
for (Long mask : layerMaskList) {
combinedMask |= mask;
}
// filter out all unaccepted events
combinedMask &= ACCEPTED_EVENTS;
if (combinedMask == 0) {
removeAWTEventListener();
} else if (getCurrentEventMask() != combinedMask) {
......
......@@ -25,17 +25,7 @@
package javax.swing;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
......@@ -2779,9 +2769,9 @@ public class JList<E> extends JComponent implements Scrollable, Accessible
getVisibleRowCount() <= 0) {
return true;
}
JViewport port = SwingUtilities.getParentViewport(this);
if (port != null) {
return port.getWidth() > getPreferredSize().width;
Container parent = SwingUtilities.getUnwrappedParent(this);
if (parent instanceof JViewport) {
return parent.getWidth() > getPreferredSize().width;
}
return false;
}
......@@ -2805,9 +2795,9 @@ public class JList<E> extends JComponent implements Scrollable, Accessible
getVisibleRowCount() <= 0) {
return true;
}
JViewport port = SwingUtilities.getParentViewport(this);
if (port != null) {
return port.getHeight() > getPreferredSize().height;
Container parent = SwingUtilities.getUnwrappedParent(this);
if (parent instanceof JViewport) {
return parent.getHeight() > getPreferredSize().height;
}
return false;
}
......
......@@ -719,8 +719,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
* @see #addNotify
*/
protected void configureEnclosingScrollPane() {
JViewport port = SwingUtilities.getParentViewport(this);
if (port != null) {
Container parent = SwingUtilities.getUnwrappedParent(this);
if (parent instanceof JViewport) {
JViewport port = (JViewport) parent;
Container gp = port.getParent();
if (gp instanceof JScrollPane) {
JScrollPane scrollPane = (JScrollPane)gp;
......@@ -752,8 +753,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
* from configureEnclosingScrollPane() and updateUI() in a safe manor.
*/
private void configureEnclosingScrollPaneUI() {
JViewport port = SwingUtilities.getParentViewport(this);
if (port != null) {
Container parent = SwingUtilities.getUnwrappedParent(this);
if (parent instanceof JViewport) {
JViewport port = (JViewport) parent;
Container gp = port.getParent();
if (gp instanceof JScrollPane) {
JScrollPane scrollPane = (JScrollPane)gp;
......@@ -822,8 +824,9 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
* @since 1.3
*/
protected void unconfigureEnclosingScrollPane() {
JViewport port = SwingUtilities.getParentViewport(this);
if (port != null) {
Container parent = SwingUtilities.getUnwrappedParent(this);
if (parent instanceof JViewport) {
JViewport port = (JViewport) parent;
Container gp = port.getParent();
if (gp instanceof JScrollPane) {
JScrollPane scrollPane = (JScrollPane)gp;
......@@ -5217,10 +5220,10 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
* @see #getFillsViewportHeight
*/
public boolean getScrollableTracksViewportHeight() {
JViewport port = SwingUtilities.getParentViewport(this);
Container parent = SwingUtilities.getUnwrappedParent(this);
return getFillsViewportHeight()
&& port != null
&& port.getHeight() > getPreferredSize().height;
&& parent instanceof JViewport
&& parent.getHeight() > getPreferredSize().height;
}
/**
......
......@@ -292,7 +292,7 @@ public class JTextField extends JTextComponent implements SwingConstants {
*/
@Override
public boolean isValidateRoot() {
return SwingUtilities.getParentViewport(this) == null;
return !(SwingUtilities.getUnwrappedParent(this) instanceof JViewport);
}
......
......@@ -3498,9 +3498,9 @@ public class JTree extends JComponent implements Scrollable, Accessible
* @see Scrollable#getScrollableTracksViewportWidth
*/
public boolean getScrollableTracksViewportWidth() {
JViewport port = SwingUtilities.getParentViewport(this);
if (port != null) {
return port.getWidth() > getPreferredSize().width;
Container parent = SwingUtilities.getUnwrappedParent(this);
if (parent instanceof JViewport) {
return parent.getWidth() > getPreferredSize().width;
}
return false;
}
......@@ -3515,9 +3515,9 @@ public class JTree extends JComponent implements Scrollable, Accessible
* @see Scrollable#getScrollableTracksViewportHeight
*/
public boolean getScrollableTracksViewportHeight() {
JViewport port = SwingUtilities.getParentViewport(this);
if (port != null) {
return port.getHeight() > getPreferredSize().height;
Container parent = SwingUtilities.getUnwrappedParent(this);
if (parent instanceof JViewport) {
return parent.getHeight() > getPreferredSize().height;
}
return false;
}
......
......@@ -1969,58 +1969,53 @@ public class SwingUtilities implements SwingConstants
}
/**
* Looks for the first ancestor of the {@code component}
* Returns the first ancestor of the {@code component}
* which is not an instance of {@link JLayer}.
* If this ancestor is an instance of {@code JViewport},
* this {@code JViewport} is returned, otherwise returns {@code null}.
* The following way of obtaining the parent {@code JViewport}
* is not recommended any more:
* <pre>
* JViewport port = null;
* Container parent = component.getParent();
* // not recommended any more
* if(parent instanceof JViewport) {
* port = (JViewport) parent;
* }
* </pre>
* Here is the way to go:
* <pre>
* // the correct way:
* JViewport port = SwingUtilities.getParentViewport(component);
* </pre>
* @param component {@code Component} to get the parent {@code JViewport} of.
* @return the {@code JViewport} instance for the {@code component}
* or {@code null}
*
* @param component {@code Component} to get
* the first ancestor of, which is not a {@link JLayer} instance.
*
* @return the first ancestor of the {@code component}
* which is not an instance of {@link JLayer}.
* If such an ancestor can not be found, {@code null} is returned.
*
* @throws NullPointerException if {@code component} is {@code null}
* @see JLayer
*
* @since 1.7
*/
public static JViewport getParentViewport(Component component) {
do {
component = component.getParent();
if (component instanceof JViewport) {
return (JViewport) component;
}
} while(component instanceof JLayer);
return null;
public static Container getUnwrappedParent(Component component) {
Container parent = component.getParent();
while(parent instanceof JLayer) {
parent = parent.getParent();
}
return parent;
}
/**
* Returns the first {@code JViewport}'s descendant
* which is not an instance of {@code JLayer} or {@code null}.
* which is not an instance of {@code JLayer}.
* If such a descendant can not be found, {@code null} is returned.
*
* If the {@code viewport}'s view component is not a {@code JLayer},
* this method is equal to {@link JViewport#getView()}
* otherwise {@link JLayer#getView()} will be recursively tested
* this method is equivalent to {@link JViewport#getView()}
* otherwise {@link JLayer#getView()} will be recursively
* called on all descending {@code JLayer}s.
*
* @param viewport {@code JViewport} to get the first descendant of,
* which in not a {@code JLayer} instance.
*
* @return the first {@code JViewport}'s descendant
* which is not an instance of {@code JLayer} or {@code null}.
* which is not an instance of {@code JLayer}.
* If such a descendant can not be found, {@code null} is returned.
*
* @throws NullPointerException if {@code viewport} is {@code null}
* @see JViewport#getView()
* @see JLayer
*
* @since 1.7
*/
static Component getUnwrappedView(JViewport viewport) {
public static Component getUnwrappedView(JViewport viewport) {
Component view = viewport.getView();
while (view instanceof JLayer) {
view = ((JLayer)view).getView();
......
......@@ -72,58 +72,18 @@ public class LayerUI<V extends Component>
* the specified {@code Graphics} object to
* render the content of the component.
* <p/>
* If {@code g} is not an instance of {@code Graphics2D},
* this method is no-op.
* The default implementation paints the passed component as is.
*
* @param g the {@code Graphics} context in which to paint;
* @param c the component being painted;
* it can be safely cast to {@code JLayer<? extends V>}
*
* @see #configureGraphics(Graphics2D, JLayer)
* @see #paintLayer(Graphics2D, JLayer)
* @param g the {@code Graphics} context in which to paint
* @param c the component being painted
*/
public void paint(Graphics g, JComponent c) {
if (g instanceof Graphics2D) {
Graphics2D g2 = (Graphics2D) g.create();
JLayer<? extends V> l = (JLayer<? extends V>) c;
configureGraphics(g2, l);
paintLayer(g2, l);
g2.dispose();
}
}
/**
* This method is called by the {@link #paint} method prior to
* {@link #paintLayer} to configure the {@code Graphics2D} object.
* The default implementation is empty.
*
* @param g2 the {@code Graphics2D} object to configure
* @param l the {@code JLayer} being painted
*
* @see #paintLayer(Graphics2D, JLayer)
*/
protected void configureGraphics(Graphics2D g2, JLayer<? extends V> l) {
}
/**
* Called by the {@link #paint} method,
* subclasses should override this method
* to perform any custom painting operations.
* <p/>
* The default implementation paints the passed {@code JLayer} as is.
*
* @param g2 the {@code Graphics2D} context in which to paint
* @param l the {@code JLayer} being painted
*
* @see #configureGraphics(Graphics2D, JLayer)
*/
protected void paintLayer(Graphics2D g2, JLayer<? extends V> l) {
l.paint(g2);
c.paint(g);
}
/**
* Dispatches {@code AWTEvent}s for {@code JLayer}
* and <b>all its subcomponents</b> to this {@code LayerUI} instance.
* Processes {@code AWTEvent}s for {@code JLayer}
* and <b>all its descendants</b> to this {@code LayerUI} instance.
* <p/>
* To enable the {@code AWTEvent}s of a particular type,
* you call {@link JLayer#setLayerEventMask}
......@@ -133,13 +93,14 @@ public class LayerUI<V extends Component>
* By default this method calls the appropriate
* {@code process&lt;event&nbsp;type&gt;Event}
* method for the given class of event.
* <p/>
* <b>Note:</b> Events are processed only for displayable {@code JLayer}s.
*
* @param e the event to be dispatched
* @param l the layer this LayerUI is set to
*
* @see JLayer#setLayerEventMask(long)
* @see #installUI(javax.swing.JComponent)
* @see #uninstallUI(javax.swing.JComponent)
* @see Component#isDisplayable()
* @see #processComponentEvent
* @see #processFocusEvent
* @see #processKeyEvent
......@@ -627,17 +588,6 @@ public class LayerUI<V extends Component>
propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
}
/**
* Repaints all {@code JLayer} instances this {@code LayerUI} is set to.
* Call this method when the state of this {@code LayerUI} is changed
* and the visual appearance of its {@code JLayer} objects needs to be updated.
*
* @see Component#repaint()
*/
protected void repaintLayer() {
firePropertyChange("dirty", null, null);
}
/**
* Notifies the {@code LayerUI} when any of its property are changed
* and enables updating every {@code JLayer}
......@@ -647,9 +597,6 @@ public class LayerUI<V extends Component>
* @param l the {@code JLayer} this LayerUI is set to
*/
public void applyPropertyChange(PropertyChangeEvent evt, JLayer<? extends V> l) {
if ("dirty".equals(evt.getPropertyName())) {
l.repaint();
}
}
/**
......
......@@ -38,6 +38,7 @@ import javax.swing.plaf.synth.SynthStyle;
import java.awt.Color;
import java.awt.Font;
import java.awt.Insets;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
......@@ -193,7 +194,7 @@ public final class NimbusStyle extends SynthStyle {
* UIDefaults which overrides (or supplements) those defaults found in
* UIManager.
*/
private JComponent component;
private WeakReference<JComponent> component;
/**
* Create a new NimbusStyle. Only the prefix must be supplied. At the
......@@ -209,7 +210,9 @@ public final class NimbusStyle extends SynthStyle {
* should be null otherwise.
*/
NimbusStyle(String prefix, JComponent c) {
this.component = c;
if (c != null) {
this.component = new WeakReference<JComponent>(c);
}
this.prefix = prefix;
this.painter = new SynthPainterImpl(this);
}
......@@ -251,9 +254,11 @@ public final class NimbusStyle extends SynthStyle {
// value is an instance of UIDefaults, then these defaults are used
// in place of, or in addition to, the defaults in UIManager.
if (component != null) {
Object o = component.getClientProperty("Nimbus.Overrides");
// We know component.get() is non-null here, as if the component
// were GC'ed, we wouldn't be processing its style.
Object o = component.get().getClientProperty("Nimbus.Overrides");
if (o instanceof UIDefaults) {
Object i = component.getClientProperty(
Object i = component.get().getClientProperty(
"Nimbus.Overrides.InheritDefaults");
boolean inherit = i instanceof Boolean ? (Boolean)i : true;
UIDefaults d = (UIDefaults)o;
......
......@@ -2069,9 +2069,9 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A
* width to match its own
*/
public boolean getScrollableTracksViewportWidth() {
JViewport port = SwingUtilities.getParentViewport(this);
if (port != null) {
return port.getWidth() > getPreferredSize().width;
Container parent = SwingUtilities.getUnwrappedParent(this);
if (parent instanceof JViewport) {
return parent.getWidth() > getPreferredSize().width;
}
return false;
}
......@@ -2090,9 +2090,9 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A
* to match its own
*/
public boolean getScrollableTracksViewportHeight() {
JViewport port = SwingUtilities.getParentViewport(this);
if (port != null) {
return (port.getHeight() > getPreferredSize().height);
Container parent = SwingUtilities.getUnwrappedParent(this);
if (parent instanceof JViewport) {
return parent.getHeight() > getPreferredSize().height;
}
return false;
}
......
......@@ -403,9 +403,14 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
}
}
String path = dir.getPath();
return (path.length() == 3
&& path.charAt(1) == ':'
&& Arrays.asList(drives.listFiles()).contains(dir));
if (path.length() != 3 || path.charAt(1) != ':') {
return false;
}
File[] files = drives.listFiles();
return files != null && Arrays.asList(files).contains(dir);
}
return false;
}
......
/*
* Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved.
* Copyright (c) 2010 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
......@@ -23,7 +23,7 @@
/*
* @test
* @bug 6843181
* @bug 6843181 6943963
* @summary Confirm that NumericShaper is thread-safe.
* @run main/timeout=300/othervm MTTest
*/
......@@ -37,33 +37,34 @@ public class MTTest {
static volatile boolean runrun = true;
static volatile boolean err = false;
final static String text = "-123 (English) 456.00 (Arabic) \u0641\u0642\u0643 -789 (Thai) \u0e01\u0e33 01.23";
static char[] t1, t2;
final static String text = "-123 (English) 456.00 (Arabic) \u0641\u0642\u0643 -456 (Thai) \u0e01\u0e33 01.23";
final static char[] expected1 = "-123 (English) 456.00 (Arabic) \u0641\u0642\u0643 -\u06f4\u06f5\u06f6 (Thai) \u0e01\u0e33 \u0e50\u0e51.\u0e52\u0e53".toCharArray(); // for EASTERN_ARABIC
final static char[] expected2 = "-123 (English) 456.00 (Arabic) \u0641\u0642\u0643 -\u0664\u0665\u0666 (Thai) \u0e01\u0e33 \u0e50\u0e51.\u0e52\u0e53".toCharArray(); // for ARABIC
static NumericShaper ns1, ns2, ns3, ns4;
public static void main(String[] args) {
System.out.println(" original: " + text);
ns1 = getContextualShaper(EnumSet.of(Range.ARABIC), Range.ARABIC);
t1 = text.toCharArray();
ns1.shape(t1, 0, t1.length);
System.out.println("expected t1: " + String.valueOf(t1));
ns2 = getContextualShaper(EnumSet.of(Range.THAI), Range.THAI);
t2 = text.toCharArray();
ns2.shape(t2, 0, t2.length);
System.out.println("expected t2: " + String.valueOf(t2));
System.out.println("original: " + text);
ns1 = getContextualShaper(EnumSet.of(Range.EASTERN_ARABIC, Range.THAI),
Range.EUROPEAN);
ns2 = getContextualShaper(EnumSet.of(Range.ARABIC, Range.THAI),
Range.EUROPEAN);
System.out.println("expected for Eastern-Arabic & Thai: " +
String.valueOf(expected1));
System.out.println("expected for Arabic & Thai: " +
String.valueOf(expected2));
ns3 = getContextualShaper(ARABIC, ARABIC);
ns4 = getContextualShaper(THAI, THAI);
ns3 = getContextualShaper(EASTERN_ARABIC|THAI, EUROPEAN);
ns4 = getContextualShaper(ARABIC|THAI, EUROPEAN);
Thread th1 = new Thread(new Work(ns1, t1));
Thread th2 = new Thread(new Work(ns2, t2));
Thread th3 = new Thread(new Work(ns1, t1));
Thread th4 = new Thread(new Work(ns2, t2));
Thread th5 = new Thread(new Work(ns3, t1));
Thread th6 = new Thread(new Work(ns4, t2));
Thread th7 = new Thread(new Work(ns3, t1));
Thread th8 = new Thread(new Work(ns4, t2));
Thread th1 = new Thread(new Work(ns1, expected1));
Thread th2 = new Thread(new Work(ns2, expected2));
Thread th3 = new Thread(new Work(ns1, expected1));
Thread th4 = new Thread(new Work(ns2, expected2));
Thread th5 = new Thread(new Work(ns3, expected1));
Thread th6 = new Thread(new Work(ns4, expected2));
Thread th7 = new Thread(new Work(ns3, expected1));
Thread th8 = new Thread(new Work(ns4, expected2));
th1.start();
th2.start();
......@@ -110,8 +111,8 @@ public class MTTest {
int count = 0;
while (runrun) {
char[] t = text.toCharArray();
count++;
try {
count++;
ns.shape(t, 0, t.length);
} catch (Exception e) {
System.err.println("Error: Unexpected exception: " + e);
......
/*
* Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved.
* Copyright (c) 2010 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
......@@ -23,7 +23,7 @@
/*
* @test
* @bug 6842557
* @bug 6842557 6943963
* @summary confirm that shaping works as expected. (Mainly for new characters which were added in Unicode 5)
* used where appropriate.
*/
......@@ -33,15 +33,25 @@ import java.util.EnumSet;
import static java.awt.font.NumericShaper.*;
public class ShapingTest {
private static boolean err = false;
public static void main(String[] args) {
test6842557();
test6943963();
if (err) {
throw new RuntimeException("shape() returned unexpected value.");
}
}
private static void test6842557() {
NumericShaper ns_old = getContextualShaper(ARABIC | TAMIL | ETHIOPIC,
EUROPEAN);
NumericShaper ns_new = getContextualShaper(EnumSet.of(
Range.ARABIC, Range.TAMIL, Range.ETHIOPIC),
Range.EUROPEAN);
boolean err = false;
String[][] data = {
// Arabic "October 10"
{"\u0623\u0643\u062a\u0648\u0628\u0631 10",
......@@ -60,45 +70,62 @@ public class ShapingTest {
};
for (int i = 0; i < data.length; i++) {
String expected = data[i][1];
char[] text = data[i][0].toCharArray();
ns_old.shape(text, 0, text.length);
String got = new String(text);
if (!expected.equals(got)) {
err = true;
System.err.println("Error with traditional range.");
System.err.println(" text = " + data[i][0]);
System.err.println(" got = " + got);
System.err.println(" expected = " + expected);
} else {
System.err.println("OK with traditional range.");
System.err.println(" text = " + data[i][0]);
System.err.println(" got = " + got);
System.err.println(" expected = " + expected);
}
text = data[i][0].toCharArray();
ns_new.shape(text, 0, text.length);
got = new String(text);
if (!expected.equals(got)) {
err = true;
System.err.println("Error with new Enum range.");
System.err.println(" text = " + data[i][0]);
System.err.println(" got = " + got);
System.err.println(" expected = " + expected);
} else {
System.err.println("OK with new Enum range.");
System.err.println(" text = " + data[i][0]);
System.err.println(" got = " + got);
System.err.println(" expected = " + expected);
}
checkResult("ARABIC | TAMIL | ETHIOPIC",
ns_old, data[i][0], data[i][1]);
checkResult("Range.ARABIC, Range.TAMIL, Range.ETHIOPIC",
ns_new, data[i][0], data[i][1]);
}
}
if (err) {
throw new RuntimeException("shape() returned unexpected value.");
private static void test6943963() {
// Needed to reproduce this bug.
NumericShaper ns_dummy = getContextualShaper(ARABIC | TAMIL | ETHIOPIC,
EUROPEAN);
char[] c = "\u1200 1".toCharArray();
ns_dummy.shape(c, 0, c.length);
String given = "\u0627\u0628 456";
String expected_ARABIC = "\u0627\u0628 \u0664\u0665\u0666";
String expected_EASTERN_ARABIC = "\u0627\u0628 \u06f4\u06f5\u06f6";
NumericShaper ns = getContextualShaper(ARABIC);
checkResult("ARABIC", ns, given, expected_ARABIC);
ns = getContextualShaper(EnumSet.of(Range.ARABIC));
checkResult("Range.ARABIC", ns, given, expected_ARABIC);
ns = getContextualShaper(EASTERN_ARABIC);
checkResult("EASTERN_ARABIC", ns, given, expected_EASTERN_ARABIC);
ns = getContextualShaper(EnumSet.of(Range.EASTERN_ARABIC));
checkResult("Range.EASTERN_ARABIC", ns, given, expected_EASTERN_ARABIC);
ns = getContextualShaper(ARABIC | EASTERN_ARABIC);
checkResult("ARABIC | EASTERN_ARABIC", ns, given, expected_EASTERN_ARABIC);
ns = getContextualShaper(EnumSet.of(Range.ARABIC, Range.EASTERN_ARABIC));
checkResult("Range.ARABIC, Range.EASTERN_ARABIC", ns, given, expected_EASTERN_ARABIC);
}
private static void checkResult(String ranges, NumericShaper ns,
String given, String expected) {
char[] text = given.toCharArray();
ns.shape(text, 0, text.length);
String got = new String(text);
if (!expected.equals(got)) {
err = true;
System.err.println("Error with range(s) <" + ranges + ">.");
System.err.println(" text = " + given);
System.err.println(" got = " + got);
System.err.println(" expected = " + expected);
} else {
System.out.println("OK with range(s) <" + ranges + ">.");
System.out.println(" text = " + given);
System.out.println(" got = " + got);
System.out.println(" expected = " + expected);
}
}
......
/*
* Copyright 2010 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 6945316
@summary The Win32ShellFolderManager2.isFileSystemRoot can throw NPE
@author Pavel Porvatov
@run main bug6945316
*/
import sun.awt.OSInfo;
import sun.awt.shell.ShellFolder;
import java.awt.*;
import java.io.File;
import java.util.concurrent.CountDownLatch;
public class bug6945316 {
public static void main(String[] args) throws Exception {
if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
System.out.println("The test is suitable only for Windows OS. Skipped.");
return;
}
// Init toolkit because it shouldn't be interrupted while initialization
Toolkit.getDefaultToolkit();
// Init the sun.awt.shell.Win32ShellFolderManager2.drives field
ShellFolder.get("fileChooserComboBoxFolders");
// To get NPE the path must obey the following rules:
// path.length() == 3 && path.charAt(1) == ':'
final File tempFile = new File("c:\\");
for (int i = 0; i < 10000; i++) {
final CountDownLatch countDownLatch = new CountDownLatch(1);
final Thread thread = new Thread() {
public void run() {
countDownLatch.countDown();
ShellFolder.isFileSystemRoot(tempFile);
}
};
thread.start();
countDownLatch.await();
thread.interrupt();
}
}
}
/*
* 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 6919629
@summary Tests that components with Nimbus.Overrides are GC'ed properly
@author Peter Zhelezniakov
@run main Test6919629
*/
import java.awt.Color;
import java.lang.ref.WeakReference;
import javax.swing.*;
import javax.swing.plaf.nimbus.NimbusLookAndFeel;
public class Test6919629
{
JFrame f;
WeakReference<JLabel> ref;
public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(new NimbusLookAndFeel());
Test6919629 t = new Test6919629();
t.test();
System.gc();
t.check();
}
void test() throws Exception {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
UIDefaults d = new UIDefaults();
d.put("Label.textForeground", Color.MAGENTA);
JLabel l = new JLabel();
ref = new WeakReference<JLabel>(l);
l.putClientProperty("Nimbus.Overrides", d);
f = new JFrame();
f.getContentPane().add(l);
f.pack();
f.setVisible(true);
}
});
Thread.sleep(2000);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
f.getContentPane().removeAll();
f.setVisible(false);
f.dispose();
}
});
Thread.sleep(2000);
}
void check() {
if (ref.get() != null) {
throw new RuntimeException("Failed: an unused component wasn't collected");
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部