8201552: Ellipsis in "Classical" label in SwingSet2 demo with Windows L&F at Hidpi
Reviewed-by: prr
--- a/src/java.desktop/macosx/classes/com/apple/laf/AquaTabbedPaneCopyFromBasicUI.java Fri Jun 29 13:44:13 2018 -0700
+++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaTabbedPaneCopyFromBasicUI.java Fri Jun 29 13:58:16 2018 -0700
@@ -3320,7 +3320,7 @@
} else if (name == "indexForNullComponent") {
isRunsDirty = true;
updateHtmlViews((Integer) e.getNewValue(), true);
- } else if (name == "font") {
+ } else if (name == "font" || SwingUtilities2.isScaleChanged(e)) {
calculatedBaseline = false;
}
}
--- a/src/java.desktop/share/classes/java/awt/Component.java Fri Jun 29 13:44:13 2018 -0700
+++ b/src/java.desktop/share/classes/java/awt/Component.java Fri Jun 29 13:58:16 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2018, 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
@@ -22,67 +22,98 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
+
package java.awt;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.util.Objects;
-import java.util.Vector;
-import java.util.Locale;
-import java.util.EventListener;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.Collections;
+import java.applet.Applet;
+import java.awt.dnd.DropTarget;
+import java.awt.event.ActionEvent;
+import java.awt.event.AdjustmentEvent;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.HierarchyBoundsListener;
+import java.awt.event.HierarchyEvent;
+import java.awt.event.HierarchyListener;
+import java.awt.event.InputEvent;
+import java.awt.event.InputMethodEvent;
+import java.awt.event.InputMethodListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.awt.event.MouseWheelEvent;
+import java.awt.event.MouseWheelListener;
+import java.awt.event.PaintEvent;
+import java.awt.event.TextEvent;
+import java.awt.im.InputContext;
+import java.awt.im.InputMethodRequests;
+import java.awt.image.BufferStrategy;
+import java.awt.image.ColorModel;
+import java.awt.image.ImageObserver;
+import java.awt.image.ImageProducer;
+import java.awt.image.VolatileImage;
import java.awt.peer.ComponentPeer;
import java.awt.peer.ContainerPeer;
import java.awt.peer.LightweightPeer;
-import java.awt.image.BufferStrategy;
-import java.awt.image.ImageObserver;
-import java.awt.image.ImageProducer;
-import java.awt.image.ColorModel;
-import java.awt.image.VolatileImage;
-import java.awt.event.*;
-import java.io.Serializable;
-import java.io.ObjectOutputStream;
-import java.io.ObjectInputStream;
-import java.io.IOException;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.beans.Transient;
-import java.awt.im.InputContext;
-import java.awt.im.InputMethodRequests;
-import java.awt.dnd.DropTarget;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.Serializable;
+import java.security.AccessControlContext;
import java.security.AccessController;
-import java.security.AccessControlContext;
-import javax.accessibility.*;
-import java.applet.Applet;
+import java.util.Collections;
+import java.util.EventListener;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.Vector;
+
+import javax.accessibility.Accessible;
+import javax.accessibility.AccessibleComponent;
+import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleRole;
+import javax.accessibility.AccessibleSelection;
+import javax.accessibility.AccessibleState;
+import javax.accessibility.AccessibleStateSet;
import javax.swing.JComponent;
import javax.swing.JRootPane;
-import sun.awt.ComponentFactory;
-import sun.security.action.GetPropertyAction;
+import sun.awt.AWTAccessor;
import sun.awt.AppContext;
-import sun.awt.AWTAccessor;
+import sun.awt.ComponentFactory;
import sun.awt.ConstrainableGraphics;
+import sun.awt.EmbeddedFrame;
+import sun.awt.RequestFocusController;
import sun.awt.SubRegionShowable;
import sun.awt.SunToolkit;
-import sun.awt.EmbeddedFrame;
import sun.awt.dnd.SunDropTargetEvent;
import sun.awt.im.CompositionArea;
+import sun.awt.image.VSyncedBSManager;
import sun.font.FontManager;
import sun.font.FontManagerFactory;
import sun.font.SunFontManager;
import sun.java2d.SunGraphics2D;
+import sun.java2d.SunGraphicsEnvironment;
import sun.java2d.pipe.Region;
-import sun.awt.image.VSyncedBSManager;
import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
-import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
-import sun.awt.RequestFocusController;
-import sun.java2d.SunGraphicsEnvironment;
+import sun.security.action.GetPropertyAction;
import sun.swing.SwingAccessor;
import sun.util.logging.PlatformLogger;
+import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.VSYNC_DEFAULT;
+import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.VSYNC_ON;
+
/**
* A <em>component</em> is an object having a graphical representation
* that can be displayed on the screen and that can interact with the
@@ -1129,24 +1160,31 @@
}
}
- boolean updateGraphicsData(GraphicsConfiguration gc) {
+ final boolean updateGraphicsData(GraphicsConfiguration gc) {
+ GraphicsConfiguration oldConfig = graphicsConfig;
+ // First, update own graphics configuration
+ boolean ret = updateSelfGraphicsData(gc);
+ // Second, update children graphics configurations
+ ret |= updateChildGraphicsData(gc);
+ // Third, fire PropertyChange if needed
+ if (oldConfig != gc) {
+ /*
+ * If component is moved from one screen to another screen or shown
+ * for the first time graphicsConfiguration property is fired to
+ * enable the component to recalculate any rendering data, if needed
+ */
+ firePropertyChange("graphicsConfiguration", oldConfig, gc);
+ }
+ return ret;
+ }
+
+ private boolean updateSelfGraphicsData(GraphicsConfiguration gc) {
checkTreeLock();
-
if (graphicsConfig == gc) {
return false;
}
- GraphicsConfiguration oldConfig = graphicsConfig;
graphicsConfig = gc;
- /*
- * If component is moved from one screen to another sceeen
- * graphicsConfiguration property is fired to enable the component
- * to recalculate any rendering data, if needed
- */
- if (oldConfig != null && gc != null) {
- firePropertyChange("graphicsConfiguration", oldConfig, gc);
- }
-
ComponentPeer peer = this.peer;
if (peer != null) {
return peer.updateGraphicsData(gc);
@@ -1154,6 +1192,10 @@
return false;
}
+ boolean updateChildGraphicsData(GraphicsConfiguration gc) {
+ return false;
+ }
+
/**
* Checks that this component's {@code GraphicsDevice}
* {@code idString} matches the string argument.
--- a/src/java.desktop/share/classes/java/awt/Container.java Fri Jun 29 13:44:13 2018 -0700
+++ b/src/java.desktop/share/classes/java/awt/Container.java Fri Jun 29 13:58:16 2018 -0700
@@ -22,6 +22,7 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
+
package java.awt;
import java.awt.dnd.DropTarget;
@@ -1172,10 +1173,10 @@
}
@Override
- boolean updateGraphicsData(GraphicsConfiguration gc) {
+ final boolean updateChildGraphicsData(GraphicsConfiguration gc) {
checkTreeLock();
- boolean ret = super.updateGraphicsData(gc);
+ boolean ret = false;
for (Component comp : component) {
if (comp != null) {
--- a/src/java.desktop/share/classes/javax/swing/DefaultListCellRenderer.java Fri Jun 29 13:44:13 2018 -0700
+++ b/src/java.desktop/share/classes/javax/swing/DefaultListCellRenderer.java Fri Jun 29 13:58:16 2018 -0700
@@ -35,7 +35,7 @@
import java.io.Serializable;
import sun.swing.DefaultLookup;
-
+import sun.swing.SwingUtilities2;
/**
* Renders an item in a list.
@@ -259,9 +259,10 @@
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
// Strings get interned...
if (propertyName == "text"
- || ((propertyName == "font" || propertyName == "foreground")
- && oldValue != newValue
- && getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey) != null)) {
+ || ((SwingUtilities2.isScaleChanged(propertyName, oldValue, newValue)
+ || propertyName == "font" || propertyName == "foreground")
+ && oldValue != newValue
+ && getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey) != null)) {
super.firePropertyChange(propertyName, oldValue, newValue);
}
--- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicButtonListener.java Fri Jun 29 13:44:13 2018 -0700
+++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicButtonListener.java Fri Jun 29 13:58:16 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -75,9 +75,8 @@
else if(prop == AbstractButton.CONTENT_AREA_FILLED_CHANGED_PROPERTY) {
checkOpacity((AbstractButton) e.getSource() );
}
- else if(prop == AbstractButton.TEXT_CHANGED_PROPERTY ||
- "font" == prop || "foreground" == prop ||
- "ancestor" == prop || "graphicsConfiguration" == prop) {
+ else if(prop == AbstractButton.TEXT_CHANGED_PROPERTY || "font" == prop
+ || "foreground" == prop || SwingUtilities2.isScaleChanged(e)) {
AbstractButton b = (AbstractButton) e.getSource();
BasicHTML.updateRenderer(b, b.getText());
}
--- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java Fri Jun 29 13:44:13 2018 -0700
+++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java Fri Jun 29 13:58:16 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -36,6 +36,7 @@
import java.beans.PropertyChangeEvent;
import sun.awt.AppContext;
import sun.swing.DefaultLookup;
+import sun.swing.SwingUtilities2;
import sun.swing.UIAction;
/**
@@ -1809,6 +1810,10 @@
isMinimumSizeDirty = true;
isDisplaySizeDirty = true;
comboBox.validate();
+ } else if (SwingUtilities2.isScaleChanged(e)) {
+ isMinimumSizeDirty = true;
+ isDisplaySizeDirty = true;
+ comboBox.validate();
}
else if ( propertyName == JComponent.TOOL_TIP_TEXT_KEY ) {
updateToolTipTextForChildren();
--- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicLabelUI.java Fri Jun 29 13:44:13 2018 -0700
+++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicLabelUI.java Fri Jun 29 13:58:16 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -477,8 +477,8 @@
public void propertyChange(PropertyChangeEvent e) {
String name = e.getPropertyName();
- if (name == "text" || "font" == name || "foreground" == name ||
- "ancestor" == name || "graphicsConfiguration" == name) {
+ if (name == "text" || "font" == name || "foreground" == name
+ || SwingUtilities2.isScaleChanged(e)) {
// remove the old html view client property if one
// existed, and install a new one if the text installed
// into the JLabel is html source.
--- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicListUI.java Fri Jun 29 13:44:13 2018 -0700
+++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicListUI.java Fri Jun 29 13:58:16 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -2656,7 +2656,8 @@
updateLayoutStateNeeded |= cellRendererChanged;
redrawList();
}
- else if (propertyName == "font") {
+ else if (propertyName == "font"
+ || SwingUtilities2.isScaleChanged(e)) {
updateLayoutStateNeeded |= fontChanged;
redrawList();
}
--- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuItemUI.java Fri Jun 29 13:44:13 2018 -0700
+++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicMenuItemUI.java Fri Jun 29 13:58:16 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -1145,9 +1145,8 @@
if (name == "labelFor" || name == "displayedMnemonic" ||
name == "accelerator") {
updateAcceleratorBinding();
- } else if (name == "text" || "font" == name ||
- "foreground" == name ||
- "ancestor" == name || "graphicsConfiguration" == name) {
+ } else if (name == "text" || "font" == name || "foreground" == name
+ || SwingUtilities2.isScaleChanged(e)) {
// remove the old html view client property if one
// existed, and install a new one if the text installed
// into the JLabel is html source.
--- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSliderUI.java Fri Jun 29 13:44:13 2018 -0700
+++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSliderUI.java Fri Jun 29 13:58:16 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -35,6 +35,7 @@
import javax.swing.event.*;
import javax.swing.plaf.*;
import sun.swing.DefaultLookup;
+import sun.swing.SwingUtilities2;
import sun.swing.UIAction;
@@ -1829,6 +1830,7 @@
propertyName == "paintTicks" ||
propertyName == "paintTrack" ||
propertyName == "font" ||
+ SwingUtilities2.isScaleChanged(e) ||
propertyName == "paintLabels" ||
propertyName == "Slider.paintThumbArrowShape") {
checkedLabelBaselines = false;
--- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java Fri Jun 29 13:44:13 2018 -0700
+++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java Fri Jun 29 13:58:16 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -4008,7 +4008,7 @@
} else if (name == "indexForNullComponent") {
isRunsDirty = true;
updateHtmlViews((Integer)e.getNewValue(), true);
- } else if (name == "font") {
+ } else if (name == "font" || SwingUtilities2.isScaleChanged(e)) {
calculatedBaseline = false;
}
}
--- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicToolTipUI.java Fri Jun 29 13:44:13 2018 -0700
+++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicToolTipUI.java Fri Jun 29 13:58:16 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -260,9 +260,8 @@
PropertyChangeListener {
public void propertyChange(PropertyChangeEvent e) {
String name = e.getPropertyName();
- if (name.equals("tiptext") || "font".equals(name) ||
- "foreground".equals(name) ||
- "ancestor" == name || "graphicsConfiguration" == name) {
+ if (name.equals("tiptext") || "foreground".equals(name)
+ || "font".equals(name) || SwingUtilities2.isScaleChanged(e)) {
// remove the old html view client property if one
// existed, and install a new one if the text installed
// into the JLabel is html source.
--- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTreeUI.java Fri Jun 29 13:44:13 2018 -0700
+++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTreeUI.java Fri Jun 29 13:58:16 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -3843,7 +3843,8 @@
else if(changeName == JTree.SELECTION_MODEL_PROPERTY) {
setSelectionModel(tree.getSelectionModel());
}
- else if(changeName == "font") {
+ else if(changeName == "font"
+ || SwingUtilities2.isScaleChanged(event)) {
completeEditing();
if(treeState != null)
treeState.invalidateSizes();
--- a/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthToolTipUI.java Fri Jun 29 13:44:13 2018 -0700
+++ b/src/java.desktop/share/classes/javax/swing/plaf/synth/SynthToolTipUI.java Fri Jun 29 13:58:16 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2018, 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
@@ -35,6 +35,7 @@
import javax.swing.plaf.ComponentUI;
import javax.swing.text.View;
+import sun.swing.SwingUtilities2;
/**
* Provides the Synth L&F UI delegate for
@@ -226,9 +227,8 @@
updateStyle((JToolTip)e.getSource());
}
String name = e.getPropertyName();
- if (name.equals("tiptext") || "font".equals(name) ||
- "foreground".equals(name) ||
- "ancestor" == name || "graphicsConfiguration" == name) {
+ if (name.equals("tiptext") || SwingUtilities2.isScaleChanged(e)
+ || "foreground".equals(name) || "font".equals(name)) {
// remove the old html view client property if one
// existed, and install a new one if the text installed
// into the JLabel is html source.
--- a/src/java.desktop/share/classes/javax/swing/table/DefaultTableCellRenderer.java Fri Jun 29 13:44:13 2018 -0700
+++ b/src/java.desktop/share/classes/javax/swing/table/DefaultTableCellRenderer.java Fri Jun 29 13:58:16 2018 -0700
@@ -34,7 +34,7 @@
import java.io.Serializable;
import sun.swing.DefaultLookup;
-
+import sun.swing.SwingUtilities2;
/**
* The standard class for rendering (displaying) individual cells
@@ -345,11 +345,12 @@
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
// Strings get interned...
if (propertyName=="text"
- || propertyName == "labelFor"
- || propertyName == "displayedMnemonic"
- || ((propertyName == "font" || propertyName == "foreground")
- && oldValue != newValue
- && getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey) != null)) {
+ || propertyName == "labelFor"
+ || propertyName == "displayedMnemonic"
+ || ((SwingUtilities2.isScaleChanged(propertyName, oldValue, newValue)
+ || propertyName == "font" || propertyName == "foreground")
+ && oldValue != newValue
+ && getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey) != null)) {
super.firePropertyChange(propertyName, oldValue, newValue);
}
--- a/src/java.desktop/share/classes/javax/swing/tree/DefaultTreeCellRenderer.java Fri Jun 29 13:44:13 2018 -0700
+++ b/src/java.desktop/share/classes/javax/swing/tree/DefaultTreeCellRenderer.java Fri Jun 29 13:58:16 2018 -0700
@@ -43,6 +43,7 @@
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import sun.swing.DefaultLookup;
+import sun.swing.SwingUtilities2;
/**
* Displays an entry in a tree.
@@ -690,9 +691,10 @@
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
// Strings get interned...
if (propertyName == "text"
- || ((propertyName == "font" || propertyName == "foreground")
- && oldValue != newValue
- && getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey) != null)) {
+ || ((SwingUtilities2.isScaleChanged(propertyName, oldValue, newValue)
+ || propertyName == "font" || propertyName == "foreground")
+ && oldValue != newValue
+ && getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey) != null)) {
super.firePropertyChange(propertyName, oldValue, newValue);
}
--- a/src/java.desktop/share/classes/sun/swing/SwingUtilities2.java Fri Jun 29 13:44:13 2018 -0700
+++ b/src/java.desktop/share/classes/sun/swing/SwingUtilities2.java Fri Jun 29 13:58:16 2018 -0700
@@ -25,47 +25,94 @@
package sun.swing;
-import java.lang.reflect.*;
-import java.awt.*;
-import static java.awt.RenderingHints.*;
-import java.awt.event.*;
-import java.awt.font.*;
+import java.awt.AWTEvent;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.FocusTraversalPolicy;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsEnvironment;
+import java.awt.Point;
+import java.awt.PrintGraphics;
+import java.awt.Rectangle;
+import java.awt.RenderingHints;
+import java.awt.Shape;
+import java.awt.Toolkit;
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.font.FontRenderContext;
+import java.awt.font.GlyphVector;
+import java.awt.font.LineBreakMeasurer;
+import java.awt.font.TextAttribute;
+import java.awt.font.TextHitInfo;
+import java.awt.font.TextLayout;
+import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
-import java.awt.geom.AffineTransform;
+import java.awt.print.PrinterGraphics;
+import java.beans.PropertyChangeEvent;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Modifier;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.text.AttributedCharacterIterator;
+import java.text.AttributedString;
+import java.text.BreakIterator;
+import java.text.CharacterIterator;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.Callable;
+import java.util.concurrent.Future;
+import java.util.concurrent.FutureTask;
+
+import javax.swing.JComponent;
+import javax.swing.JList;
+import javax.swing.JTable;
+import javax.swing.ListCellRenderer;
+import javax.swing.ListSelectionModel;
+import javax.swing.SwingUtilities;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
+import javax.swing.event.TreeModelEvent;
+import javax.swing.table.TableCellRenderer;
+import javax.swing.table.TableColumnModel;
+import javax.swing.text.DefaultCaret;
+import javax.swing.text.DefaultHighlighter;
+import javax.swing.text.Highlighter;
+import javax.swing.text.JTextComponent;
+import javax.swing.tree.TreeModel;
+import javax.swing.tree.TreePath;
+
+import sun.awt.AWTAccessor;
+import sun.awt.AWTPermissions;
+import sun.awt.AppContext;
+import sun.awt.SunToolkit;
+import sun.font.FontDesignMetrics;
+import sun.font.FontUtilities;
+import sun.java2d.SunGraphicsEnvironment;
+import sun.print.ProxyPrintGraphics;
+
+import static java.awt.RenderingHints.KEY_TEXT_ANTIALIASING;
+import static java.awt.RenderingHints.KEY_TEXT_LCD_CONTRAST;
+import static java.awt.RenderingHints.VALUE_FRACTIONALMETRICS_DEFAULT;
+import static java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT;
+import static java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HBGR;
+import static java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB;
+import static java.awt.RenderingHints.VALUE_TEXT_ANTIALIAS_OFF;
import static java.awt.geom.AffineTransform.TYPE_FLIP;
import static java.awt.geom.AffineTransform.TYPE_MASK_SCALE;
import static java.awt.geom.AffineTransform.TYPE_TRANSLATION;
-import java.awt.print.PrinterGraphics;
-import java.text.BreakIterator;
-import java.text.CharacterIterator;
-import java.text.AttributedCharacterIterator;
-import java.text.AttributedString;
-
-import javax.swing.*;
-import javax.swing.event.TreeModelEvent;
-import javax.swing.text.Highlighter;
-import javax.swing.text.JTextComponent;
-import javax.swing.text.DefaultHighlighter;
-import javax.swing.text.DefaultCaret;
-import javax.swing.table.TableCellRenderer;
-import javax.swing.table.TableColumnModel;
-import javax.swing.tree.TreeModel;
-import javax.swing.tree.TreePath;
-
-import sun.java2d.pipe.Region;
-import sun.print.ProxyPrintGraphics;
-import sun.awt.*;
-import java.io.*;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.*;
-import sun.font.FontDesignMetrics;
-import sun.font.FontUtilities;
-import sun.java2d.SunGraphicsEnvironment;
-
-import java.util.concurrent.Callable;
-import java.util.concurrent.Future;
-import java.util.concurrent.FutureTask;
/**
* A collection of utility methods for Swing.
@@ -2256,4 +2303,40 @@
public interface RepaintListener {
void repaintPerformed(JComponent c, int x, int y, int w, int h);
}
+
+ /**
+ * Returns whether or not the scale used by {@code GraphicsConfiguration}
+ * was changed.
+ *
+ * @param ev a {@code PropertyChangeEvent}
+ * @return whether or not the scale was changed
+ * @since 11
+ */
+ public static boolean isScaleChanged(final PropertyChangeEvent ev) {
+ return isScaleChanged(ev.getPropertyName(), ev.getOldValue(),
+ ev.getNewValue());
+ }
+
+ /**
+ * Returns whether or not the scale used by {@code GraphicsConfiguration}
+ * was changed.
+ *
+ * @param name the name of the property
+ * @param oldValue the old value of the property
+ * @param newValue the new value of the property
+ * @return whether or not the scale was changed
+ * @since 11
+ */
+ public static boolean isScaleChanged(final String name,
+ final Object oldValue,
+ final Object newValue) {
+ if (oldValue == newValue || !"graphicsConfiguration".equals(name)) {
+ return false;
+ }
+ var newGC = (GraphicsConfiguration) oldValue;
+ var oldGC = (GraphicsConfiguration) newValue;
+ var newTx = newGC != null ? newGC.getDefaultTransform() : null;
+ var oldTx = oldGC != null ? oldGC.getDefaultTransform() : null;
+ return !Objects.equals(newTx, oldTx);
+ }
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/swing/GraphicsConfigNotifier/OrderOfGConfigNotify.java Fri Jun 29 13:58:16 2018 -0700
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+import java.awt.EventQueue;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+
+/**
+ * @test
+ * @key headful
+ * @bug 8201552
+ * @summary Container should get "graphicsConfiguration" notification when all
+ * its children are updated
+ */
+public final class OrderOfGConfigNotify {
+
+ private static String name = "graphicsConfiguration";
+
+ public static void main(final String[] args) throws Exception {
+ EventQueue.invokeAndWait(() -> {
+ AtomicBoolean parentCalled = new AtomicBoolean(false);
+ AtomicBoolean childCalled = new AtomicBoolean(false);
+
+ JFrame frame = new JFrame();
+
+ JPanel parent = new JPanel();
+ parent.addPropertyChangeListener(evt -> {
+ if (!evt.getPropertyName().equals(name)) {
+ return;
+ }
+ if (!childCalled.get()) {
+ throw new RuntimeException("Parent is called/child is not");
+ }
+ parentCalled.set(true);
+ if (parent.getGraphicsConfiguration() == null) {
+ throw new RuntimeException("GraphicsConfiguration is null");
+ }
+ });
+ JPanel child = new JPanel();
+ child.addPropertyChangeListener(evt -> {
+ if (!evt.getPropertyName().equals(name)) {
+ return;
+ }
+ childCalled.set(true);
+ if (child.getGraphicsConfiguration() == null) {
+ throw new RuntimeException("GraphicsConfiguration is null");
+ }
+ });
+ parent.add(child);
+
+ // Frame.add() should update graphicsConfiguration for all hierarchy
+ frame.add(parent);
+ if (!parentCalled.get() || !childCalled.get()) {
+ throw new RuntimeException("Property listener was not called");
+ }
+ });
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/swing/GraphicsConfigNotifier/StalePreferredSize.java Fri Jun 29 13:58:16 2018 -0700
@@ -0,0 +1,212 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.FlowLayout;
+import java.awt.Font;
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.Callable;
+
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JEditorPane;
+import javax.swing.JFormattedTextField;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import javax.swing.JRadioButton;
+import javax.swing.JScrollPane;
+import javax.swing.JSpinner;
+import javax.swing.JTable;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.JToolTip;
+import javax.swing.JTree;
+import javax.swing.SpinnerListModel;
+import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
+import javax.swing.tree.DefaultMutableTreeNode;
+
+import static javax.swing.UIManager.getInstalledLookAndFeels;
+
+/**
+ * @test
+ * @key headful
+ * @bug 8201552
+ * @summary Initial layout of the component should use correct graphics config.
+ * It is checked by SwingUtilities.updateComponentTreeUI(), if layout
+ * was correct the call to updateComponentTreeUI() will be no-op.
+ * @compile -encoding utf-8 StalePreferredSize.java
+ * @run main/othervm/timeout=200 StalePreferredSize
+ * @run main/othervm/timeout=200 -Dsun.java2d.uiScale=1 StalePreferredSize
+ * @run main/othervm/timeout=200 -Dsun.java2d.uiScale=2.25 StalePreferredSize
+ */
+public final class StalePreferredSize {
+
+ // Some text to be tested
+ static final String TEXT[] = new String[]{
+ "<span>A few words to get started before the "
+ + "bug</span><span>overlapping text</span>",
+ "A quick brown fox jumps over the lazy dog",
+ "El veloz murciélago hindú comía feliz cardillo y kiwi. La cigüeña "
+ + "tocaba el saxofón detrás del palenque de paja",
+ "Voix ambiguë d’un cœur qui au zéphyr préfère les jattes de kiwis",
+ "다람쥐 헌 쳇바퀴에 타고파",
+ "Съешь ещё этих мягких французских булок да выпей же чаю"};
+
+ static JFrame frame;
+ static Component component;
+ static int typeFont = 0; // 0 - default, 1 - bold, 2 - italic
+
+ public static void main(final String[] args) throws Exception {
+ for (final UIManager.LookAndFeelInfo laf : getInstalledLookAndFeels()) {
+ EventQueue.invokeAndWait(() -> setLookAndFeel(laf));
+ for (typeFont = 0; typeFont < 3; typeFont++) {
+ System.err.println("typeFont = " + typeFont);
+ for (final boolean html : new boolean[]{true, false}) {
+ for (String text : TEXT) {
+ if (html) {
+ text = "<html>" + text + "</html>";
+ }
+ test(text);
+ }
+ }
+ }
+ }
+ }
+
+ private static void test(String text) throws Exception {
+ System.err.println("text = " + text);
+ // Each Callable create a component to be tested
+ final List<Callable<Component>> comps = List.of(
+ () -> new JLabel(text),
+ () -> new JButton(text),
+ () -> new JMenuItem(text),
+ () -> new JMenu(text),
+ () -> new JList<>(new String[]{text}),
+ () -> new JComboBox<>(new String[]{text}),
+ () -> new JTextField(text),
+ () -> new JTextArea(text),
+ () -> new JCheckBox(text),
+ () -> new JFormattedTextField(text),
+ () -> new JRadioButton(text),
+ () -> new JTree(new DefaultMutableTreeNode(text)),
+ () -> new JSpinner(new SpinnerListModel(new String[]{text})),
+ () -> {
+ JToolTip tip = new JToolTip();
+ tip.setTipText(text);
+ return tip;
+ },
+ () -> {
+ JEditorPane pane = new JEditorPane();
+ pane.setText(text);
+ return pane;
+ },
+ () -> {
+ JTable table = new JTable(1, 1);
+ table.getModel().setValueAt(text, 0, 0);
+ return table;
+ }
+ );
+
+ for (final Callable<Component> creator : comps) {
+ checkComponent(creator);
+ }
+ }
+
+ static void checkComponent(Callable<Component> creator) throws Exception {
+ EventQueue.invokeAndWait(() -> {
+
+ try {
+ component = creator.call();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ Font font = component.getFont();
+ if (typeFont == 1) {
+ component.setFont(new Font(font.deriveFont(Font.BOLD).getAttributes()));
+ }
+ if (typeFont == 2) {
+ component.setFont(new Font(font.deriveFont(Font.ITALIC).getAttributes()));
+ }
+
+ frame = new JFrame();
+ frame.setLayout(new FlowLayout());
+ frame.add(new JScrollPane(component));
+ frame.setSize(300, 100);
+ frame.setLocationRelativeTo(null);
+ frame.setVisible(true);
+ });
+
+ EventQueue.invokeAndWait(() -> {
+
+ // After the frame was shown we change nothing, so current layout
+ // should be optimal and updateComponentTreeUI() should be no-op
+ Dimension before = component.getPreferredSize();
+ SwingUtilities.updateComponentTreeUI(frame);
+ Dimension after = component.getPreferredSize();
+
+ // We change the font size to some big value, as a result the
+ // layout and preferredSize of the component should be changed
+ component.setFont(component.getFont().deriveFont(35f));
+ Dimension last = component.getPreferredSize();
+
+ frame.dispose();
+
+ if (!Objects.equals(before, after)) {
+ System.err.println("Component: " + component);
+ System.err.println("Before: " + before);
+ System.err.println("After: " + after);
+ throw new RuntimeException("Wrong PreferredSize");
+ }
+ // TODO JDK-8206024
+// if (Objects.equals(after, last)) {
+// System.err.println("Component: " + component);
+// System.err.println("After: " + after);
+// System.err.println("Last: " + last);
+// throw new RuntimeException("Wrong PreferredSize");
+// }
+ });
+ }
+
+ private static void setLookAndFeel(final UIManager.LookAndFeelInfo laf) {
+ try {
+ UIManager.setLookAndFeel(laf.getClassName());
+ System.err.println("LookAndFeel: " + laf.getClassName());
+ } catch (final UnsupportedLookAndFeelException ignored) {
+ System.err.println(
+ "Unsupported LookAndFeel: " + laf.getClassName());
+ } catch (ClassNotFoundException | InstantiationException |
+ IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/swing/GraphicsConfigNotifier/TestSingleScreenGConfigNotify.java Fri Jun 29 13:58:16 2018 -0700
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+import java.awt.EventQueue;
+import java.awt.GraphicsConfiguration;
+import java.util.Objects;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+
+/**
+ * @test
+ * @key headful
+ * @bug 8201552
+ * @summary Verifies if graphicsConfiguration property notification is sent
+ * when frame is shown on the screen.
+ * @run main TestSingleScreenGConfigNotify
+ * @run main/othervm -Dsun.java2d.uiScale=2.25 TestSingleScreenGConfigNotify
+ */
+public final class TestSingleScreenGConfigNotify {
+
+ private static String name = "graphicsConfiguration";
+ private static CountDownLatch go = new CountDownLatch(1);
+ private static JFrame frame;
+ private static GraphicsConfiguration after;
+ private static GraphicsConfiguration before;
+ private static JButton button;
+
+ public static void main(final String[] args) throws Exception {
+ EventQueue.invokeAndWait(() -> {
+ frame = new JFrame();
+
+ frame.setSize(300,300);
+ frame.setLocationRelativeTo(null);
+ button = new JButton();
+ button.addPropertyChangeListener(evt -> {
+ if (evt.getPropertyName().equals(name)) {
+ go.countDown();
+ }
+ });
+
+ before = button.getGraphicsConfiguration();
+
+ frame.add(button);
+ frame.setVisible(true);
+ });
+
+ boolean called = go.await(10, TimeUnit.SECONDS);
+
+ EventQueue.invokeAndWait(() -> {
+ after = button.getGraphicsConfiguration();
+ frame.dispose();
+ });
+
+ if (Objects.equals(before, after) && called) {
+ throw new RuntimeException("propertyChange() should not be called");
+ }
+ if (!Objects.equals(before, after) && !called) {
+ throw new RuntimeException("propertyChange() should be called");
+ }
+ }
+}