# HG changeset patch
# User lana
# Date 1277183188 25200
# Node ID b8ab8c6db9a618f1a37046220f697bea590c8dbf
# Parent 2a67809d309f95d740a180e9c4ef91502ac581ed# Parent 2a390122edffa1b56cbd75967150748ec3b63041
Merge
diff -r 2a67809d309f -r b8ab8c6db9a6 jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsComboBoxUI.java
--- a/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsComboBoxUI.java Mon Jun 21 22:05:11 2010 -0700
+++ b/jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsComboBoxUI.java Mon Jun 21 22:06:28 2010 -0700
@@ -424,7 +424,7 @@
State rv;
rv = super.getState();
if (rv != State.DISABLED
- && ! comboBox.isEditable()
+ && comboBox != null && ! comboBox.isEditable()
&& XPStyle.getXP().isSkinDefined(comboBox,
Part.CP_DROPDOWNBUTTONRIGHT)) {
/*
diff -r 2a67809d309f -r b8ab8c6db9a6 jdk/src/share/classes/javax/swing/BorderFactory.java
--- a/jdk/src/share/classes/javax/swing/BorderFactory.java Mon Jun 21 22:05:11 2010 -0700
+++ b/jdk/src/share/classes/javax/swing/BorderFactory.java Mon Jun 21 22:06:28 2010 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,7 +26,6 @@
import java.awt.Color;
import java.awt.Font;
-import javax.swing.JComponent;
import javax.swing.border.*;
/**
@@ -74,10 +73,20 @@
return new LineBorder(color, thickness);
}
-// public static Border createLineBorder(Color color, int thickness,
-// boolean drawRounded) {
-// return new JLineBorder(color, thickness, drawRounded);
-// }
+ /**
+ * Creates a line border with the specified color, thickness, and corner shape.
+ *
+ * @param color the color of the border
+ * @param thickness the thickness of the border
+ * @param rounded whether or not border corners should be round
+ * @return the {@code Border} object
+ *
+ * @see LineBorder#LineBorder(Color, int, boolean)
+ * @since 1.7
+ */
+ public static Border createLineBorder(Color color, int thickness, boolean rounded) {
+ return new LineBorder(color, thickness, rounded);
+ }
//// BevelBorder /////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
@@ -180,7 +189,115 @@
}
return null;
}
+
+//// SoftBevelBorder ///////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
+
+ private static Border sharedSoftRaisedBevel;
+ private static Border sharedSoftLoweredBevel;
+
+ /**
+ * Creates a beveled border with a raised edge and softened corners,
+ * using brighter shades of the component's current background color
+ * for highlighting, and darker shading for shadows.
+ * In a raised border, highlights are on top and shadows are underneath.
+ *
+ * @return the {@code Border} object
+ *
+ * @since 1.7
+ */
+ public static Border createRaisedSoftBevelBorder() {
+ if (sharedSoftRaisedBevel == null) {
+ sharedSoftRaisedBevel = new SoftBevelBorder(BevelBorder.RAISED);
+ }
+ return sharedSoftRaisedBevel;
+ }
+
+ /**
+ * Creates a beveled border with a lowered edge and softened corners,
+ * using brighter shades of the component's current background color
+ * for highlighting, and darker shading for shadows.
+ * In a lowered border, shadows are on top and highlights are underneath.
+ *
+ * @return the {@code Border} object
+ *
+ * @since 1.7
+ */
+ public static Border createLoweredSoftBevelBorder() {
+ if (sharedSoftLoweredBevel == null) {
+ sharedSoftLoweredBevel = new SoftBevelBorder(BevelBorder.LOWERED);
+ }
+ return sharedSoftLoweredBevel;
+ }
+
+ /**
+ * Creates a beveled border of the specified type with softened corners,
+ * using brighter shades of the component's current background color
+ * for highlighting, and darker shading for shadows.
+ * The type is either {@link BevelBorder#RAISED} or {@link BevelBorder#LOWERED}.
+ *
+ * @param type a type of a bevel
+ * @return the {@code Border} object or {@code null}
+ * if the specified type is not valid
+ *
+ * @see BevelBorder#BevelBorder(int)
+ * @since 1.7
+ */
+ public static Border createSoftBevelBorder(int type) {
+ if (type == BevelBorder.RAISED) {
+ return createRaisedSoftBevelBorder();
+ }
+ if (type == BevelBorder.LOWERED) {
+ return createLoweredSoftBevelBorder();
+ }
+ return null;
+ }
+
+ /**
+ * Creates a beveled border of the specified type with softened corners,
+ * using the specified highlighting and shadowing.
+ * The type is either {@link BevelBorder#RAISED} or {@link BevelBorder#LOWERED}.
+ * The outer edge of the highlight area uses
+ * a brighter shade of the {@code highlight} color.
+ * The inner edge of the shadow area uses
+ * a brighter shade of the {@code shadow} color.
+ *
+ * @param type a type of a bevel
+ * @param highlight a basic color of the highlight area
+ * @param shadow a basic color of the shadow area
+ * @return the {@code Border} object
+ *
+ * @see BevelBorder#BevelBorder(int, Color, Color)
+ * @since 1.7
+ */
+ public static Border createSoftBevelBorder(int type, Color highlight, Color shadow) {
+ return new BevelBorder(type, highlight, shadow);
+ }
+
+ /**
+ * Creates a beveled border of the specified type with softened corners,
+ * using the specified colors for the inner and outer edges
+ * of the highlight and the shadow areas.
+ * The type is either {@link BevelBorder#RAISED} or {@link BevelBorder#LOWERED}.
+ * Note: The shadow inner and outer colors are switched
+ * for a lowered bevel border.
+ *
+ * @param type a type of a bevel
+ * @param highlightOuter a color of the outer edge of the highlight area
+ * @param highlightInner a color of the inner edge of the highlight area
+ * @param shadowOuter a color of the outer edge of the shadow area
+ * @param shadowInner a color of the inner edge of the shadow area
+ * @return the {@code Border} object
+ *
+ * @see BevelBorder#BevelBorder(int, Color, Color, Color, Color)
+ * @since 1.7
+ */
+ public static Border createSoftBevelBorder(int type, Color highlightOuter, Color highlightInner, Color shadowOuter, Color shadowInner) {
+ return new BevelBorder(type, highlightOuter, highlightInner, shadowOuter, shadowInner);
+ }
+
//// EtchedBorder ///////////////////////////////////////////////////////////
+
static final Border sharedEtchedBorder = new EtchedBorder();
private static Border sharedRaisedEtchedBorder;
diff -r 2a67809d309f -r b8ab8c6db9a6 jdk/src/share/classes/javax/swing/plaf/synth/SynthParser.java
--- a/jdk/src/share/classes/javax/swing/plaf/synth/SynthParser.java Mon Jun 21 22:05:11 2010 -0700
+++ b/jdk/src/share/classes/javax/swing/plaf/synth/SynthParser.java Mon Jun 21 22:06:28 2010 -0700
@@ -658,8 +658,7 @@
}
try {
_colorTypes.add((ColorType)checkCast(typeClass.
- getField(typeName.substring(classIndex,
- typeName.length() - classIndex)).
+ getField(typeName.substring(classIndex)).
get(typeClass), ColorType.class));
} catch (NoSuchFieldException nsfe) {
throw new SAXException("Unable to find color type: " +
diff -r 2a67809d309f -r b8ab8c6db9a6 jdk/src/share/classes/javax/swing/plaf/synth/SynthToolBarUI.java
--- a/jdk/src/share/classes/javax/swing/plaf/synth/SynthToolBarUI.java Mon Jun 21 22:05:11 2010 -0700
+++ b/jdk/src/share/classes/javax/swing/plaf/synth/SynthToolBarUI.java Mon Jun 21 22:06:28 2010 -0700
@@ -363,18 +363,24 @@
SynthIcon.getIconWidth(handleIcon, context) : 0;
Dimension compDim;
for (int i = 0; i < tb.getComponentCount(); i++) {
- compDim = tb.getComponent(i).getMinimumSize();
- dim.width += compDim.width;
- dim.height = Math.max(dim.height, compDim.height);
+ Component component = tb.getComponent(i);
+ if (component.isVisible()) {
+ compDim = component.getMinimumSize();
+ dim.width += compDim.width;
+ dim.height = Math.max(dim.height, compDim.height);
+ }
}
} else {
dim.height = tb.isFloatable() ?
SynthIcon.getIconHeight(handleIcon, context) : 0;
Dimension compDim;
for (int i = 0; i < tb.getComponentCount(); i++) {
- compDim = tb.getComponent(i).getMinimumSize();
- dim.width = Math.max(dim.width, compDim.width);
- dim.height += compDim.height;
+ Component component = tb.getComponent(i);
+ if (component.isVisible()) {
+ compDim = component.getMinimumSize();
+ dim.width = Math.max(dim.width, compDim.width);
+ dim.height += compDim.height;
+ }
}
}
dim.width += insets.left + insets.right;
@@ -395,18 +401,24 @@
SynthIcon.getIconWidth(handleIcon, context) : 0;
Dimension compDim;
for (int i = 0; i < tb.getComponentCount(); i++) {
- compDim = tb.getComponent(i).getPreferredSize();
- dim.width += compDim.width;
- dim.height = Math.max(dim.height, compDim.height);
+ Component component = tb.getComponent(i);
+ if (component.isVisible()) {
+ compDim = component.getPreferredSize();
+ dim.width += compDim.width;
+ dim.height = Math.max(dim.height, compDim.height);
+ }
}
} else {
dim.height = tb.isFloatable() ?
SynthIcon.getIconHeight(handleIcon, context) : 0;
Dimension compDim;
for (int i = 0; i < tb.getComponentCount(); i++) {
- compDim = tb.getComponent(i).getPreferredSize();
- dim.width = Math.max(dim.width, compDim.width);
- dim.height += compDim.height;
+ Component component = tb.getComponent(i);
+ if (component.isVisible()) {
+ compDim = component.getPreferredSize();
+ dim.width = Math.max(dim.width, compDim.width);
+ dim.height += compDim.height;
+ }
}
}
dim.width += insets.left + insets.right;
@@ -469,22 +481,24 @@
for (int i = 0; i < tb.getComponentCount(); i++) {
c = tb.getComponent(i);
- d = c.getPreferredSize();
- int y, h;
- if (d.height >= baseH || c instanceof JSeparator) {
- // Fill available height
- y = baseY;
- h = baseH;
- } else {
- // Center component vertically in the available space
- y = baseY + (baseH / 2) - (d.height / 2);
- h = d.height;
+ if (c.isVisible()) {
+ d = c.getPreferredSize();
+ int y, h;
+ if (d.height >= baseH || c instanceof JSeparator) {
+ // Fill available height
+ y = baseY;
+ h = baseH;
+ } else {
+ // Center component vertically in the available space
+ y = baseY + (baseH / 2) - (d.height / 2);
+ h = d.height;
+ }
+ //if the component is a "glue" component then add to its
+ //width the extraSpacePerGlue it is due
+ if (isGlue(c)) d.width += extraSpacePerGlue;
+ c.setBounds(ltr ? x : x - d.width, y, d.width, h);
+ x = ltr ? x + d.width : x - d.width;
}
- //if the component is a "glue" component then add to its
- //width the extraSpacePerGlue it is due
- if (isGlue(c)) d.width += extraSpacePerGlue;
- c.setBounds(ltr ? x : x - d.width, y, d.width, h);
- x = ltr ? x + d.width : x - d.width;
}
} else {
int handleHeight = tb.isFloatable() ?
@@ -512,29 +526,31 @@
for (int i = 0; i < tb.getComponentCount(); i++) {
c = tb.getComponent(i);
- d = c.getPreferredSize();
- int x, w;
- if (d.width >= baseW || c instanceof JSeparator) {
- // Fill available width
- x = baseX;
- w = baseW;
- } else {
- // Center component horizontally in the available space
- x = baseX + (baseW / 2) - (d.width / 2);
- w = d.width;
+ if (c.isVisible()) {
+ d = c.getPreferredSize();
+ int x, w;
+ if (d.width >= baseW || c instanceof JSeparator) {
+ // Fill available width
+ x = baseX;
+ w = baseW;
+ } else {
+ // Center component horizontally in the available space
+ x = baseX + (baseW / 2) - (d.width / 2);
+ w = d.width;
+ }
+ //if the component is a "glue" component then add to its
+ //height the extraSpacePerGlue it is due
+ if (isGlue(c)) d.height += extraSpacePerGlue;
+ c.setBounds(x, y, w, d.height);
+ y += d.height;
}
- //if the component is a "glue" component then add to its
- //height the extraSpacePerGlue it is due
- if (isGlue(c)) d.height += extraSpacePerGlue;
- c.setBounds(x, y, w, d.height);
- y += d.height;
}
}
context.dispose();
}
private boolean isGlue(Component c) {
- if (c instanceof Box.Filler) {
+ if (c.isVisible() && c instanceof Box.Filler) {
Box.Filler f = (Box.Filler)c;
Dimension min = f.getMinimumSize();
Dimension pref = f.getPreferredSize();
diff -r 2a67809d309f -r b8ab8c6db9a6 jdk/src/share/classes/javax/swing/text/DefaultStyledDocument.java
--- a/jdk/src/share/classes/javax/swing/text/DefaultStyledDocument.java Mon Jun 21 22:05:11 2010 -0700
+++ b/jdk/src/share/classes/javax/swing/text/DefaultStyledDocument.java Mon Jun 21 22:06:28 2010 -0700
@@ -25,15 +25,12 @@
package javax.swing.text;
import java.awt.Color;
-import java.awt.Component;
import java.awt.Font;
-import java.awt.FontMetrics;
import java.awt.font.TextAttribute;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.util.Enumeration;
import java.util.HashMap;
-import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Stack;
@@ -41,15 +38,14 @@
import java.util.ArrayList;
import java.io.IOException;
import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
import java.io.Serializable;
-import javax.swing.Icon;
import javax.swing.event.*;
import javax.swing.undo.AbstractUndoableEdit;
import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;
import javax.swing.undo.UndoableEdit;
import javax.swing.SwingUtilities;
+import static sun.swing.SwingUtilities2.IMPLIED_CR;
/**
* A document that can be marked up with character and paragraph
@@ -782,9 +778,18 @@
// Check for the composed text element. If it is, merge the character attributes
// into this element as well.
if (Utilities.isComposedTextAttributeDefined(attr)) {
- ((MutableAttributeSet)attr).addAttributes(cattr);
- ((MutableAttributeSet)attr).addAttribute(AbstractDocument.ElementNameAttribute,
- AbstractDocument.ContentElementName);
+ MutableAttributeSet mattr = (MutableAttributeSet) attr;
+ mattr.addAttributes(cattr);
+ mattr.addAttribute(AbstractDocument.ElementNameAttribute,
+ AbstractDocument.ContentElementName);
+
+ // Assure that the composed text element is named properly
+ // and doesn't have the CR attribute defined.
+ mattr.addAttribute(StyleConstants.NameAttribute,
+ AbstractDocument.ContentElementName);
+ if (mattr.isDefined(IMPLIED_CR)) {
+ mattr.removeAttribute(IMPLIED_CR);
+ }
}
ElementSpec[] spec = new ElementSpec[parseBuffer.size()];
diff -r 2a67809d309f -r b8ab8c6db9a6 jdk/src/share/classes/javax/swing/text/GlyphView.java
--- a/jdk/src/share/classes/javax/swing/text/GlyphView.java Mon Jun 21 22:05:11 2010 -0700
+++ b/jdk/src/share/classes/javax/swing/text/GlyphView.java Mon Jun 21 22:06:28 2010 -0700
@@ -32,6 +32,7 @@
import javax.swing.UIManager;
import sun.swing.SwingUtilities2;
+import static sun.swing.SwingUtilities2.IMPLIED_CR;
/**
* A GlyphView is a styled chunk of text that represents a view
@@ -1061,7 +1062,6 @@
int length;
// if it is an implied newline character
boolean impliedCR;
- private static final String IMPLIED_CR = "CR";
boolean skipWidth;
/**
diff -r 2a67809d309f -r b8ab8c6db9a6 jdk/src/share/classes/javax/swing/text/Utilities.java
--- a/jdk/src/share/classes/javax/swing/text/Utilities.java Mon Jun 21 22:05:11 2010 -0700
+++ b/jdk/src/share/classes/javax/swing/text/Utilities.java Mon Jun 21 22:06:28 2010 -0700
@@ -404,6 +404,24 @@
}
/**
+ * Adjust text offset so that the length of a resulting string as a whole
+ * fits into the specified width.
+ */
+ static int adjustOffsetForFractionalMetrics(
+ Segment s, FontMetrics fm, int offset, int width) {
+ // Sometimes the offset returned by getTabbedTextOffset is beyond the
+ // available area, when fractional metrics are enabled. We should
+ // guard against this.
+ if (offset < s.count) {
+ while (offset > 0 &&
+ fm.charsWidth(s.array, s.offset, offset + 1) > width) {
+ offset--;
+ }
+ }
+ return offset;
+ }
+
+ /**
* Determine where to break the given text to fit
* within the given span. This tries to find a word boundary.
* @param s the source of the text
@@ -425,7 +443,7 @@
int txtCount = s.count;
int index = Utilities.getTabbedTextOffset(s, metrics, x0, x,
e, startOffset, false);
-
+ index = adjustOffsetForFractionalMetrics(s, metrics, index, x - x0);
if (index >= txtCount - 1) {
return txtCount;
diff -r 2a67809d309f -r b8ab8c6db9a6 jdk/src/share/classes/javax/swing/text/WrappedPlainView.java
--- a/jdk/src/share/classes/javax/swing/text/WrappedPlainView.java Mon Jun 21 22:05:11 2010 -0700
+++ b/jdk/src/share/classes/javax/swing/text/WrappedPlainView.java Mon Jun 21 22:06:28 2010 -0700
@@ -108,7 +108,7 @@
try {
if (line.isLeaf()) {
- drawText(line, p0, p1, g, x, y);
+ drawText(line, p0, p1, g, x, y);
} else {
// this line contains the composed text.
int idx = line.getElementIndex(p0);
@@ -239,9 +239,11 @@
tabBase, tabBase + currentWidth,
this, p0);
} else {
- p = p0 + Utilities.getTabbedTextOffset(segment, metrics,
- tabBase, tabBase + currentWidth,
- this, p0, false);
+ int offset = Utilities.getTabbedTextOffset(segment, metrics,
+ tabBase, tabBase + currentWidth, this, p0, false);
+ offset = Utilities.adjustOffsetForFractionalMetrics(
+ segment, metrics, offset, currentWidth);
+ p = p0 + offset;
}
SegmentCache.releaseSharedSegment(segment);
return p;
diff -r 2a67809d309f -r b8ab8c6db9a6 jdk/src/share/classes/javax/swing/text/html/HTMLDocument.java
--- a/jdk/src/share/classes/javax/swing/text/html/HTMLDocument.java Mon Jun 21 22:05:11 2010 -0700
+++ b/jdk/src/share/classes/javax/swing/text/html/HTMLDocument.java Mon Jun 21 22:06:28 2010 -0700
@@ -24,20 +24,17 @@
*/
package javax.swing.text.html;
-import java.awt.Color;
-import java.awt.Component;
import java.awt.font.TextAttribute;
import java.util.*;
import java.net.URL;
-import java.net.URLEncoder;
import java.net.MalformedURLException;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.undo.*;
-import java.text.Bidi;
import sun.swing.SwingUtilities2;
+import static sun.swing.SwingUtilities2.IMPLIED_CR;
/**
* A document that models HTML. The purpose of this model is to
@@ -1819,7 +1816,6 @@
static String MAP_PROPERTY = "__MAP__";
private static char[] NEWLINE;
- private static final String IMPLIED_CR = "CR";
/**
* I18N property key.
diff -r 2a67809d309f -r b8ab8c6db9a6 jdk/src/share/classes/sun/swing/SwingUtilities2.java
--- a/jdk/src/share/classes/sun/swing/SwingUtilities2.java Mon Jun 21 22:05:11 2010 -0700
+++ b/jdk/src/share/classes/sun/swing/SwingUtilities2.java Mon Jun 21 22:06:28 2010 -0700
@@ -109,6 +109,12 @@
new StringBuffer("AATextInfoPropertyKey");
/**
+ * Attribute key for the content elements. If it is set on an element, the
+ * element is considered to be a line break.
+ */
+ public static final String IMPLIED_CR = "CR";
+
+ /**
* Used to tell a text component, being used as an editor for table
* or tree, how many clicks it took to start editing.
*/
diff -r 2a67809d309f -r b8ab8c6db9a6 jdk/src/share/classes/sun/swing/table/DefaultTableCellHeaderRenderer.java
--- a/jdk/src/share/classes/sun/swing/table/DefaultTableCellHeaderRenderer.java Mon Jun 21 22:05:11 2010 -0700
+++ b/jdk/src/share/classes/sun/swing/table/DefaultTableCellHeaderRenderer.java Mon Jun 21 22:06:28 2010 -0700
@@ -127,7 +127,7 @@
public static SortOrder getColumnSortOrder(JTable table, int column) {
SortOrder rv = null;
- if (table.getRowSorter() == null) {
+ if (table == null || table.getRowSorter() == null) {
return rv;
}
java.util.List extends RowSorter.SortKey> sortKeys =
diff -r 2a67809d309f -r b8ab8c6db9a6 jdk/test/javax/swing/JTable/6788484/bug6788484.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/JTable/6788484/bug6788484.java Mon Jun 21 22:06:28 2010 -0700
@@ -0,0 +1,39 @@
+/*
+ * 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 6788484
+ @summary NPE in DefaultTableCellHeaderRenderer.getColumnSortOrder() with null table
+ @author Alexander Potochkin
+ @run main bug6788484
+*/
+import sun.swing.table.DefaultTableCellHeaderRenderer;
+
+import javax.swing.*;
+
+public class bug6788484 {
+
+ public static void main(String[] args) throws Exception {
+ DefaultTableCellHeaderRenderer.getColumnSortOrder(null, 0);
+ }
+}
diff -r 2a67809d309f -r b8ab8c6db9a6 jdk/test/javax/swing/plaf/synth/6771547/SynthTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/plaf/synth/6771547/SynthTest.java Mon Jun 21 22:06:28 2010 -0700
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * 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.
+ */
+
+/**
+ * @test
+ * @bug 6771547
+ * @author Alexander Potochkin
+ * @summary SynthParser throws StringIndexOutOfBoundsException parsing custom ColorTypes
+ */
+
+import javax.swing.plaf.synth.SynthLookAndFeel;
+import javax.swing.*;
+import java.io.InputStream;
+import java.awt.*;
+
+public class SynthTest {
+
+ public static void main(String[] args) throws Exception {
+ SynthLookAndFeel laf = new SynthLookAndFeel();
+ InputStream in = SynthTest.class.getResourceAsStream(
+ "synthconfig.xml");
+ laf.load(in, SynthTest.class);
+
+ UIManager.setLookAndFeel(laf);
+
+ if (!Color.RED.equals(new JButton().getForeground())) {
+ throw new RuntimeException("The wrong foreground color!");
+ }
+ }
+}
diff -r 2a67809d309f -r b8ab8c6db9a6 jdk/test/javax/swing/plaf/synth/6771547/synthconfig.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/plaf/synth/6771547/synthconfig.xml Mon Jun 21 22:06:28 2010 -0700
@@ -0,0 +1,10 @@
+
B");
+ hitKey(KeyEvent.VK_LEFT);
+ }
+
+ void sendAtParagraphStart() {
+ sendInputMethodEvent();
+ }
+
+ void checkAtParagraphStart() {
+ checkComposedTextRun();
+ }
+
+ void initAfterBRElement() {
+ ep.setText("A
B");
+ hitKey(KeyEvent.VK_LEFT);
+ }
+
+ void sendAtBRElement() {
+ sendInputMethodEvent();
+ }
+
+ void checkAtBrElement() {
+ checkComposedTextRun();
+ }
+
+ private void hitKey(int keycode) {
+ robot.keyPress(keycode);
+ robot.keyRelease(keycode);
+ robot.delay(550); // The magic number equals JRobot.DEFAULT_DELAY
+ }
+
+ private void run() throws Exception {
+ robot = new Robot();
+
+ ep = new JEditorPane();
+ ep.setContentType("text/html");
+ ep.setPreferredSize(new Dimension(100, 100));
+
+ JFrame frame = new JFrame("Test: " + getClass().getName());
+
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.add(ep);
+ frame.setVisible(true);
+ }
+
+ public static void main(String[] args) throws Throwable {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ try {
+ bug6636983 bug6636983 = new bug6636983();
+
+ bug6636983.run();
+ bug6636983.initAtParagraphStart();
+ bug6636983.sendAtParagraphStart();
+ bug6636983.checkAtParagraphStart();
+ bug6636983.initAfterBRElement();
+ bug6636983.sendAtBRElement();
+ bug6636983.checkAtBrElement();
+
+ System.out.println("OK");
+ } catch (Exception e) {
+ throw new RuntimeException("The test failed", e);
+ }
+ }
+ });
+ }
+}
diff -r 2a67809d309f -r b8ab8c6db9a6 jdk/test/javax/swing/text/WrappedPlainView/6857057/StubBranchElement.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/text/WrappedPlainView/6857057/StubBranchElement.java Mon Jun 21 22:06:28 2010 -0700
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ */
+
+import javax.swing.text.*;
+
+class StubBranchElement implements Element {
+ Document document = new DefaultStyledDocument();
+ String context;
+ Element[] children = new StubLeafElement[3];
+
+ public StubBranchElement(String context) {
+ this.context = context;
+ int len = context.length() / 3;
+ for (int i = 0; i < 3; i++) {
+ children[i] = new StubLeafElement(
+ context.substring(len * i, len * (i + 1)), this, len * i);
+ }
+ try {
+ document.insertString(0, context, new SimpleAttributeSet());
+ } catch (BadLocationException e) {
+ }
+ }
+
+ public Document getDocument() {
+ return document;
+ }
+
+ public Element getParentElement() {
+ return null;
+ }
+
+ public String getName() {
+ return "StubBranchElement";
+ }
+
+ public AttributeSet getAttributes() {
+ return new SimpleAttributeSet();
+ }
+
+ public int getStartOffset() {
+ return 0;
+ }
+
+ public int getEndOffset() {
+ return document.getLength();
+ }
+
+ public int getElementIndex(int offset) {
+ return offset / 3;
+ }
+
+ public int getElementCount() {
+ return 3;
+ }
+
+ public Element getElement(int index) {
+ return children[index];
+ }
+
+ public boolean isLeaf() {
+ return false;
+ }
+
+ public Element[] getChildren() {
+ return children;
+ }
+}
diff -r 2a67809d309f -r b8ab8c6db9a6 jdk/test/javax/swing/text/WrappedPlainView/6857057/StubLeafElement.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/text/WrappedPlainView/6857057/StubLeafElement.java Mon Jun 21 22:06:28 2010 -0700
@@ -0,0 +1,81 @@
+/*
+ * 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.
+ */
+
+import javax.swing.text.*;
+
+class StubLeafElement implements Element {
+ Document document = new DefaultStyledDocument();
+ String context;
+ Element parent;
+ int position;
+
+ public StubLeafElement(String context, Element parent, int position) {
+ this.context = context;
+ this.parent = parent;
+ this.position = position;
+ try {
+ document.insertString(0, context, new SimpleAttributeSet());
+ } catch (BadLocationException e) {
+ }
+ }
+
+ public Document getDocument() {
+ return document;
+ }
+
+ public Element getParentElement() {
+ return parent;
+ }
+
+ public String getName() {
+ return "StubLeafElement";
+ }
+
+ public AttributeSet getAttributes() {
+ return new SimpleAttributeSet();
+ }
+
+ public int getStartOffset() {
+ return position;
+ }
+
+ public int getEndOffset() {
+ return position + document.getLength();
+ }
+
+ public int getElementIndex(int offset) {
+ return 0;
+ }
+
+ public int getElementCount() {
+ return 0;
+ }
+
+ public Element getElement(int index) {
+ return this;
+ }
+
+ public boolean isLeaf() {
+ return true;
+ }
+}
diff -r 2a67809d309f -r b8ab8c6db9a6 jdk/test/javax/swing/text/WrappedPlainView/6857057/bug6857057.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/swing/text/WrappedPlainView/6857057/bug6857057.java Mon Jun 21 22:06:28 2010 -0700
@@ -0,0 +1,59 @@
+/*
+ * 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 6857057
+ * @summary test that the JCK GlyphView2021 test doesn't fail
+ * @author Sergey Groznyh
+ * @run main bug6857057
+ */
+
+import javax.swing.*;
+import javax.swing.text.Element;
+import javax.swing.text.GlyphView;
+import javax.swing.text.View;
+
+public class bug6857057 {
+
+ bug6857057() {
+ Element elem = new StubBranchElement(" G L Y P H V");
+ GlyphView view = new GlyphView(elem);
+ float pos = elem.getStartOffset();
+ float len = elem.getEndOffset() - pos;
+ int res = view.getBreakWeight(View.X_AXIS, pos, len);
+ if (res != View.ExcellentBreakWeight) {
+ throw new RuntimeException("breakWeight != ExcellentBreakWeight");
+ }
+ }
+
+ public static void main(String[] args) throws Throwable {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ new bug6857057();
+ }
+ });
+
+ System.out.println("OK");
+ }
+}