提交 3ce543e2 编写于 作者: L lana

Merge

......@@ -1828,6 +1828,8 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
* table. While the {@code autoCreateRowSorter} property remains
* {@code true}, every time the model is changed, a new {@code
* TableRowSorter} is created and set as the table's row sorter.
* The default value for the {@code autoCreateRowSorter}
* property is {@code false}.
*
* @param autoCreateRowSorter whether or not a {@code RowSorter}
* should be automatically created
......
......@@ -1838,7 +1838,9 @@ public class JTree extends JComponent implements Scrollable, Accessible
* nodes, or <code>null</code> if nothing is currently selected
*/
public TreePath[] getSelectionPaths() {
return getSelectionModel().getSelectionPaths();
TreePath[] selectionPaths = getSelectionModel().getSelectionPaths();
return (selectionPaths != null && selectionPaths.length > 0) ? selectionPaths : null;
}
/**
......
......@@ -1326,7 +1326,7 @@ public class DefaultCaret extends Rectangle implements Caret, FocusListener, Mou
if ( ! SwingUtilities2.canCurrentEventAccessSystemClipboard() ) {
return;
}
if (this.dot != this.mark && component != null) {
if (this.dot != this.mark && component != null && component.hasFocus()) {
Clipboard clip = getSystemSelection();
if (clip != null) {
String selectedText;
......
......@@ -1181,7 +1181,12 @@ public class HTMLDocument extends DefaultStyledDocument {
public void insertAfterStart(Element elem, String htmlText) throws
BadLocationException, IOException {
verifyParser();
if (elem != null && elem.isLeaf()) {
if (elem == null || htmlText == null) {
return;
}
if (elem.isLeaf()) {
throw new IllegalArgumentException
("Can not insert HTML after start of a leaf");
}
......
/*
* Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2011, 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
......@@ -185,7 +185,7 @@ public class OffScreenImageSource implements ImageProducer {
theConsumer.setDimensions(image.getWidth(), image.getHeight());
theConsumer.setProperties(properties);
sendPixels();
theConsumer.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
theConsumer.imageComplete(ImageConsumer.STATICIMAGEDONE);
} catch (NullPointerException e) {
if (theConsumer != null) {
theConsumer.imageComplete(ImageConsumer.IMAGEERROR);
......
......@@ -524,10 +524,21 @@ public class SwingUtilities2 {
}
// If we get here we're not printing
if (g instanceof Graphics2D) {
AATextInfo info = drawTextAntialiased(c);
if (info != null && (g instanceof Graphics2D)) {
Graphics2D g2 = (Graphics2D)g;
boolean needsTextLayout = ((c != null) &&
(c.getClientProperty(TextAttribute.NUMERIC_SHAPING) != null));
if (needsTextLayout) {
synchronized(charsBufferLock) {
int length = syncCharsBuffer(text);
needsTextLayout = isComplexLayout(charsBuffer, 0, length);
}
}
if (info != null) {
Object oldContrast = null;
Object oldAAValue = g2.getRenderingHint(KEY_TEXT_ANTIALIASING);
if (info.aaHint != oldAAValue) {
......@@ -545,14 +556,6 @@ public class SwingUtilities2 {
}
}
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());
......@@ -567,12 +570,20 @@ public class SwingUtilities2 {
if (oldContrast != null) {
g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST, oldContrast);
}
return;
}
else {
g.drawString(text, x, y);
if (needsTextLayout){
TextLayout layout = createTextLayout(c, text, g2.getFont(),
g2.getFontRenderContext());
layout.draw(g2, x, y);
return;
}
}
g.drawString(text, x, y);
}
/**
* Draws the string at the specified location underlining the specified
......
To run the Ruler demo:
java -jar Ruler.jar
java -jar TransparentRuler.jar
These instructions assume that this installation's version of the java
command is in your path. If it isn't, then you should either
specify the complete path to the java command or update your
PATH environment variable as described in the installation
instructions for the Java(TM) SE Development Kit.
KNOWN ISSUES:
Context menu is clipped with the window shape. The issues are:
CR 7027486 JPopupMenu doesn't take window shape into account
......@@ -466,12 +466,16 @@ public class XComponentPeer extends XWindow implements ComponentPeer, DropTarget
if (true) {
switch(e.getID()) {
case PaintEvent.UPDATE:
if (log.isLoggable(PlatformLogger.FINER)) {
log.finer("XCP coalescePaintEvent : UPDATE : add : x = " +
r.x + ", y = " + r.y + ", width = " + r.width + ",height = " + r.height);
}
return;
case PaintEvent.PAINT:
if (log.isLoggable(PlatformLogger.FINER)) {
log.finer("XCP coalescePaintEvent : PAINT : add : x = " +
r.x + ", y = " + r.y + ", width = " + r.width + ",height = " + r.height);
}
return;
}
}
......@@ -1248,7 +1252,9 @@ public class XComponentPeer extends XWindow implements ComponentPeer, DropTarget
* ButtonPress, ButtonRelease, KeyPress, KeyRelease, EnterNotify, LeaveNotify, MotionNotify
*/
protected boolean isEventDisabled(XEvent e) {
if (enableLog.isLoggable(PlatformLogger.FINEST)) {
enableLog.finest("Component is {1}, checking for disabled event {0}", e, (isEnabled()?"enabled":"disable"));
}
if (!isEnabled()) {
switch (e.get_type()) {
case XConstants.ButtonPress:
......@@ -1258,7 +1264,9 @@ public class XComponentPeer extends XWindow implements ComponentPeer, DropTarget
case XConstants.EnterNotify:
case XConstants.LeaveNotify:
case XConstants.MotionNotify:
if (enableLog.isLoggable(PlatformLogger.FINER)) {
enableLog.finer("Event {0} is disable", e);
}
return true;
}
}
......
......@@ -678,7 +678,7 @@ public class WrapperGenerator {
public void writeToString(StructType stp, PrintWriter pw) {
int type;
pw.println("\n\n\tString getName() {\n\t\treturn \"" + stp.getName()+ "\"; \n\t}");
pw.println("\n\n\tString getFieldsAsString() {\n\t\tString ret=\"\";\n");
pw.println("\n\n\tString getFieldsAsString() {\n\t\tStringBuilder ret = new StringBuilder(" + stp.getNumFields() * 40 + ");\n");
for (Enumeration e = stp.getMembers() ; e.hasMoreElements() ;) {
AtomicType tp = (AtomicType) e.nextElement();
......@@ -688,24 +688,24 @@ public class WrapperGenerator {
if ((name != null) && (name.length() > 0))
{
if (type == AtomicType.TYPE_ATOM) {
pw.println("\t\tret += \"\"+\"" + name + " = \" + XAtom.get(get_" + name + "()) +\", \";");
pw.println("\t\tret.append(\"" + name + " = \" ).append( XAtom.get(get_" + name + "()) ).append(\", \");");
} else if (name.equals("type")) {
pw.println("\t\tret += \"\"+\"type = \" + XlibWrapper.eventToString[get_type()] +\", \";");
pw.println("\t\tret.append(\"type = \").append( XlibWrapper.eventToString[get_type()] ).append(\", \");");
} else if (name.equals("window")){
pw.println("\t\tret += \"\"+\"window = \" + getWindow(get_window()) + \", \";");
pw.println("\t\tret.append(\"window = \" ).append( getWindow(get_window()) ).append(\", \");");
} else if (type == AtomicType.TYPE_ARRAY) {
pw.print("\t\tret += \"{\"");
pw.print("\t\tret.append(\"{\")");
for (int i = 0; i < tp.getArrayLength(); i++) {
pw.print(" + get_" + name + "(" + i + ") + \" \"");
pw.print("\n\t\t.append( get_" + name + "(" + i + ") ).append(\" \")");
}
pw.println(" + \"}\";");
pw.println(".append( \"}\");");
} else {
pw.println("\t\tret += \"\"+\"" + name +" = \" + get_"+ name+"() +\", \";");
pw.println("\t\tret.append(\"" + name +" = \").append( get_"+ name+"() ).append(\", \");");
}
}
}
pw.println("\t\treturn ret;\n\t}\n\n");
pw.println("\t\treturn ret.toString();\n\t}\n\n");
}
public void writeStubs(StructType stp, PrintWriter pw) {
......
......@@ -32,7 +32,7 @@
#include <X11/Xutil.h>
#include <X11/extensions/shape.h>
#include <sys/types.h>
#include <sys/unistd.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>
#include <inttypes.h>
......
/*
* Copyright (c) 2007, 2011, 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 4492274
* @summary Tests if JEditorPane.getPage() correctly returns anchor reference.
* @author Denis Sharypov
*/
import sun.awt.SunToolkit;
import javax.swing.*;
import javax.swing.text.html.HTMLEditorKit;
import java.awt.*;
import java.io.File;
import java.net.URL;
public class bug4492274 {
private static URL page;
private static JEditorPane jep;
public static void main(String args[]) throws Exception {
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
createAndShowGUI();
}
});
toolkit.realSync();
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
try {
page = new URL(page, "#linkname");
jep.setPage(page);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
toolkit.realSync();
if (getPageAnchor() == null) {
throw new RuntimeException("JEditorPane.getPage() returns null anchor reference");
}
}
private static String getPageAnchor() throws Exception {
final String[] result = new String[1];
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
result[0] = jep.getPage().getRef();
}
});
return result[0];
}
private static void createAndShowGUI() {
try {
File file = new File(System.getProperty("test.src", "."), "test.html");
page = file.toURI().toURL();
JFrame f = new JFrame();
jep = new JEditorPane();
jep.setEditorKit(new HTMLEditorKit());
jep.setEditable(false);
jep.setPage(page);
JScrollPane sp = new JScrollPane(jep);
f.getContentPane().add(sp);
f.setSize(500, 500);
f.setVisible(true);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
<html>
<body>
<a name="top">top</a>
<img src=a.jpg width=500 height=1000>
<a name="linkname">bottom</a>
</body>
</html>
/*
* Copyright (c) 2007, 2011, 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 6348946
* @summary Tests that JSlider's thumb moves in the right direction
* when it is used as a JTable cell editor.
* @author Mikhail Lapshin
*/
import sun.awt.SunToolkit;
import java.awt.*;
import java.awt.event.InputEvent;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
public class bug6348946 {
private static JFrame frame;
private static JPanel panel;
private static volatile boolean passed = false;
public static void main(String[] args) throws Exception {
String lf = "javax.swing.plaf.metal.MetalLookAndFeel";
UIManager.setLookAndFeel(lf);
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
setupUI();
}
});
toolkit.realSync();
clickOnSlider();
toolkit.realSync();
checkResult();
} finally {
stopEDT();
}
}
private static void setupUI() {
frame = new JFrame();
panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(new ParameterTable(), BorderLayout.CENTER);
frame.getContentPane().add(panel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private static void clickOnSlider() throws Exception {
Robot robot = new Robot();
robot.setAutoDelay(10);
Rectangle rect = getPanelRectangle();
double clickX = rect.getX() + rect.getWidth() / 4;
double clickY = rect.getY() + rect.getHeight() / 2;
robot.mouseMove((int) clickX, (int) clickY);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
private static void checkResult(){
if (passed) {
System.out.println("Test passed");
} else {
throw new RuntimeException("The thumb moved " +
"to the right instead of the left!");
}
}
private static void stopEDT() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
frame.dispose();
}
});
}
private static class ParameterTable extends JTable {
public ParameterTable() {
super(new Object[][]{{5}}, new String[]{"Value"});
getColumnModel().getColumn(0).setCellRenderer(new Renderer());
getColumnModel().getColumn(0).setCellEditor(new Editor());
}
}
private static class Renderer implements TableCellRenderer {
private JSlider slider = new JSlider(0, 10);
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row, int col) {
int val = (Integer) value;
slider.setValue(val);
return slider;
}
}
private static class Editor extends AbstractCellEditor implements TableCellEditor {
private JSlider slider = new JSlider(0, 10);
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected,
int row, int col) {
int val = (Integer) value;
slider.setValue(val);
return slider;
}
public Editor() {
slider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
if (!slider.getValueIsAdjusting()) {
passed = slider.getValue() <= 5;
}
}
});
}
public Object getCellEditorValue() {
return slider.getValue();
}
}
private static Rectangle getPanelRectangle() throws Exception{
final Rectangle[] result = new Rectangle[1];
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
result[0] = new Rectangle(panel.getLocationOnScreen(), panel.getSize());
}
});
return result[0];
}
}
/*
* Copyright (c) 2011 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.
*/
/*
* Portions Copyright (c) 2011 IBM Corporation
*/
/* @test
* @bug 7049024
* @summary DnD fails with JTextArea and JTextField
* @author Sean Chou
*/
import sun.awt.SunToolkit;
import javax.swing.*;
import javax.swing.text.DefaultCaret;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
public class bug7049024 {
public static Clipboard clipboard = null;
public static JTextField textField = null;
// This button is used to move focus away from textField.
public static JButton button = null;
public static JFrame frame = null;
public static DefaultCaret caret = null;
public static void main(String[] args) throws Exception {
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame = new JFrame("Test");
textField = new JTextField("test selection for textfield");
button = new JButton("To compete the focus");
frame.setLayout(new FlowLayout());
frame.getContentPane().add(textField);
frame.getContentPane().add(button);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
toolkit.realSync();
clipboard = textField.getToolkit().getSystemSelection();
if (null == clipboard) {
return;
}
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
textField.requestFocusInWindow();
}
});
toolkit.realSync();
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
caret = (DefaultCaret) textField.getCaret();
caret.setDot(2);
caret.moveDot(4);
}
});
toolkit.realSync();
String oldSelection = (String) clipboard.getData(DataFlavor.stringFlavor);
System.out.println("oldSelection is " + oldSelection);
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
button.requestFocusInWindow();
}
});
toolkit.realSync(); // So JTextField loses the focus.
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
caret.setDot(4);
caret.moveDot(6);
}
});
toolkit.realSync();
String newSelection = (String) clipboard.getData(DataFlavor.stringFlavor);
System.out.println("newSelection is " + newSelection);
boolean passed = newSelection.equals(oldSelection);
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
frame.dispose();
}
});
if (!passed) {
throw new RuntimeException("The test for bug 7049024 failed");
}
}
}
/*
* Copyright (c) 2007, 2011, 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 6256140
* @summary Esc key doesn't restore old value in JFormattedtextField when ToolTip is set
* @author Alexander Potochkin
* @run main Test6256140
*/
import sun.awt.SunToolkit;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
public class Test6256140 {
private static volatile JFormattedTextField ft;
private final static String initialText = "value";
private final static JLabel toolTipLabel = new JLabel("tip");
public static void main(String[] args) throws Exception {
Robot robot = new Robot();
robot.setAutoDelay(10);
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createAndShowGUI();
}
});
toolkit.realSync();
Point point = ft.getLocationOnScreen();
robot.mouseMove(point.x, point.y);
robot.mouseMove(point.x + 3, point.y + 3);
robot.keyPress(KeyEvent.VK_A);
robot.keyRelease(KeyEvent.VK_A);
toolkit.realSync();
if (!isTooltipShowning()) {
throw new RuntimeException("Tooltip is not shown");
}
robot.keyPress(KeyEvent.VK_ESCAPE);
robot.keyRelease(KeyEvent.VK_ESCAPE);
toolkit.realSync();
if (isTooltipShowning()) {
throw new RuntimeException("Tooltip must be hidden now");
}
if (isTextEqual()) {
throw new RuntimeException("FormattedTextField must *not* cancel the updated value this time");
}
robot.keyPress(KeyEvent.VK_ESCAPE);
robot.keyRelease(KeyEvent.VK_ESCAPE);
toolkit.realSync();
if (!isTextEqual()) {
throw new RuntimeException("FormattedTextField must cancel the updated value");
}
}
private static boolean isTooltipShowning() throws Exception {
final boolean[] result = new boolean[1];
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
result[0] = toolTipLabel.isShowing();
}
});
return result[0];
}
private static boolean isTextEqual() throws Exception {
final boolean[] result = new boolean[1];
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
result[0] = initialText.equals(ft.getText());
}
});
return result[0];
}
private static void createAndShowGUI() {
ToolTipManager.sharedInstance().setDismissDelay(Integer.MAX_VALUE);
ToolTipManager.sharedInstance().setInitialDelay(0);
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new FlowLayout());
ft = new JFormattedTextField() {
public JToolTip createToolTip() {
JToolTip toolTip = super.createToolTip();
toolTip.setLayout(new BorderLayout());
toolTip.add(toolTipLabel);
return toolTip;
}
};
ft.setToolTipText(" ");
ft.setValue(initialText);
frame.add(ft);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
ft.requestFocus();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册