Mercurial > hg > jdk9-shenandoah > jdk
changeset 12779:38169ef6e325
Merge
author | prr |
---|---|
date | Fri, 18 Sep 2015 09:18:17 -0700 |
parents | 7869179af058 (diff) db2f9bbb40f6 (current diff) |
children | 50292d486635 |
files | src/java.base/share/native/libfdlibm/e_pow.c src/java.base/share/native/libfdlibm/w_pow.c src/java.base/share/native/libjava/Image.c src/java.management/share/classes/com/sun/jmx/remote/internal/IIOPHelper.java src/java.management/share/classes/com/sun/jmx/remote/internal/IIOPProxy.java src/java.management/share/classes/com/sun/jmx/remote/protocol/iiop/ClientProvider.java src/java.management/share/classes/com/sun/jmx/remote/protocol/iiop/IIOPProxyImpl.java src/java.management/share/classes/com/sun/jmx/remote/protocol/iiop/ProxyInputStream.java src/java.management/share/classes/com/sun/jmx/remote/protocol/iiop/ServerProvider.java test/javax/management/remote/mandatory/connection/NoIIOP.java test/sun/security/tools/jarsigner/warnings.sh |
diffstat | 54 files changed, 2961 insertions(+), 986 deletions(-) [+] |
line wrap: on
line diff
--- a/src/java.desktop/macosx/classes/com/apple/laf/AquaCaret.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaCaret.java Fri Sep 18 09:18:17 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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,19 +36,27 @@ import javax.swing.text.*; @SuppressWarnings("serial") // Superclass is not serializable across versions -public class AquaCaret extends DefaultCaret implements UIResource, PropertyChangeListener { - final boolean isMultiLineEditor; - final JTextComponent c; - - boolean mFocused = false; +public class AquaCaret extends DefaultCaret + implements UIResource, PropertyChangeListener { - public AquaCaret(final Window inParentWindow, final JTextComponent inComponent) { - super(); - c = inComponent; - isMultiLineEditor = (c instanceof JTextArea || c instanceof JEditorPane); - inComponent.addPropertyChangeListener(this); + private boolean isMultiLineEditor; + private boolean mFocused = false; + private boolean fPainting = false; + + @Override + public void install(final JTextComponent c) { + super.install(c); + isMultiLineEditor = c instanceof JTextArea || c instanceof JEditorPane; + c.addPropertyChangeListener(this); } + @Override + public void deinstall(final JTextComponent c) { + c.removePropertyChangeListener(this); + super.deinstall(c); + } + + @Override protected Highlighter.HighlightPainter getSelectionPainter() { return AquaHighlighter.getInstance(); } @@ -56,11 +64,13 @@ /** * Only show the flashing caret if the selection range is zero */ + @Override public void setVisible(boolean e) { if (e) e = getDot() == getMark(); super.setVisible(e); } + @Override protected void fireStateChanged() { // If we have focus the caret should only flash if the range length is zero if (mFocused) setVisible(getComponent().isEditable()); @@ -68,6 +78,7 @@ super.fireStateChanged(); } + @Override public void propertyChange(final PropertyChangeEvent evt) { final String propertyName = evt.getPropertyName(); @@ -87,6 +98,7 @@ // --- FocusListener methods -------------------------- private boolean shouldSelectAllOnFocus = true; + @Override public void focusGained(final FocusEvent e) { final JTextComponent component = getComponent(); if (!component.isEnabled() || !component.isEditable()) { @@ -122,12 +134,13 @@ super.focusGained(e); } + @Override public void focusLost(final FocusEvent e) { mFocused = false; shouldSelectAllOnFocus = true; if (isMultiLineEditor) { setVisible(false); - c.repaint(); + getComponent().repaint(); } else { super.focusLost(e); } @@ -136,6 +149,7 @@ // This fixes the problem where when on the mac you have to ctrl left click to // get popup triggers the caret has code that only looks at button number. // see radar # 3125390 + @Override public void mousePressed(final MouseEvent e) { if (!e.isPopupTrigger()) { super.mousePressed(e); @@ -153,6 +167,7 @@ * @param r the current location of the caret * @see #paint */ + @Override protected synchronized void damage(final Rectangle r) { if (r == null || fPainting) return; @@ -182,12 +197,12 @@ repaint(); } - boolean fPainting = false; - - // See <rdar://problem/3833837> 1.4.2_05-141.3: JTextField performance with Aqua L&F - // We are getting into a circular condition with the BasicCaret paint code since it doesn't know about the fact that our - // damage routine above elminates the border. Sadly we can't easily change either one, so we will - // add a painting flag and not damage during a repaint. + // See <rdar://problem/3833837> 1.4.2_05-141.3: JTextField performance with + // Aqua L&F. We are getting into a circular condition with the BasicCaret + // paint code since it doesn't know about the fact that our damage routine + // above elminates the border. Sadly we can't easily change either one, so + // we will add a painting flag and not damage during a repaint. + @Override public void paint(final Graphics g) { if (isVisible()) { fPainting = true;
--- a/src/java.desktop/macosx/classes/com/apple/laf/AquaEditorPaneUI.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaEditorPaneUI.java Fri Sep 18 09:18:17 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -39,6 +39,7 @@ } boolean oldDragState = false; + @Override protected void installDefaults(){ super.installDefaults(); if(!GraphicsEnvironment.isHeadless()){ @@ -47,6 +48,7 @@ } } + @Override protected void uninstallDefaults(){ if(!GraphicsEnvironment.isHeadless()){ getComponent().setDragEnabled(oldDragState); @@ -55,12 +57,14 @@ } FocusListener focusListener; + @Override protected void installListeners(){ super.installListeners(); focusListener = createFocusListener(); getComponent().addFocusListener(focusListener); } + @Override protected void installKeyboardActions() { super.installKeyboardActions(); AquaKeyBindings bindings = AquaKeyBindings.instance(); @@ -69,6 +73,7 @@ bindings.installAquaUpDownActions(c); } + @Override protected void uninstallListeners(){ getComponent().removeFocusListener(focusListener); super.uninstallListeners(); @@ -78,12 +83,12 @@ return new AquaFocusHandler(); } - protected Caret createCaret(){ - final Window owningWindow = SwingUtilities.getWindowAncestor(getComponent()); - final AquaCaret returnValue = new AquaCaret(owningWindow, getComponent()); - return returnValue; + @Override + protected Caret createCaret() { + return new AquaCaret(); } + @Override protected Highlighter createHighlighter(){ return new AquaHighlighter(); }
--- a/src/java.desktop/macosx/classes/com/apple/laf/AquaImageFactory.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaImageFactory.java Fri Sep 18 09:18:17 2015 -0700 @@ -46,7 +46,7 @@ import com.apple.laf.AquaIcon.SystemIcon; import com.apple.laf.AquaUtils.RecyclableObject; import com.apple.laf.AquaUtils.RecyclableSingleton; -import sun.awt.image.MultiResolutionImage; +import java.awt.image.MultiResolutionImage; import sun.awt.image.MultiResolutionCachedImage; public class AquaImageFactory {
--- a/src/java.desktop/macosx/classes/com/apple/laf/AquaInternalFrameUI.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaInternalFrameUI.java Fri Sep 18 09:18:17 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -66,6 +66,7 @@ protected Color fNotSelectedTextColor; AquaInternalFrameBorder fAquaBorder; + private ResizeBox resizeBox; // for button tracking boolean fMouseOverPressedButton; @@ -96,6 +97,7 @@ } /// Inherit (but be careful to check everything they call): + @Override public void installUI(final JComponent c) { // super.installUI(c); // Swing 1.1.1 has a bug in installUI - it doesn't check for null northPane frame = (JInternalFrame)c; @@ -125,12 +127,14 @@ c.setBorder(new CompoundUIBorder(fIsPallet ? paletteWindowShadow.get() : documentWindowShadow.get(), c.getBorder())); } + @Override protected void installDefaults() { super.installDefaults(); fSelectedTextColor = UIManager.getColor("InternalFrame.activeTitleForeground"); fNotSelectedTextColor = UIManager.getColor("InternalFrame.inactiveTitleForeground"); } + @Override public void setSouthPane(final JComponent c) { if (southPane != null) { frame.remove(southPane); @@ -144,6 +148,7 @@ } static final RecyclableSingleton<Icon> closeIcon = new RecyclableSingleton<Icon>() { + @Override protected Icon getInstance() { return new AquaInternalFrameButtonIcon(Widget.TITLE_BAR_CLOSE_BOX); } @@ -153,6 +158,7 @@ } static final RecyclableSingleton<Icon> minimizeIcon = new RecyclableSingleton<Icon>() { + @Override protected Icon getInstance() { return new AquaInternalFrameButtonIcon(Widget.TITLE_BAR_COLLAPSE_BOX); } @@ -162,6 +168,7 @@ } static final RecyclableSingleton<Icon> zoomIcon = new RecyclableSingleton<Icon>() { + @Override protected Icon getInstance() { return new AquaInternalFrameButtonIcon(Widget.TITLE_BAR_ZOOM_BOX); } @@ -175,6 +182,7 @@ painter.state.set(widget); } + @Override public void paintIcon(final Component c, final Graphics g, final int x, final int y) { painter.state.set(getStateFor(c)); super.paintIcon(c, g, x, y); @@ -184,28 +192,24 @@ return State.ROLLOVER; } + @Override public int getIconWidth() { return 19; } + @Override public int getIconHeight() { return 19; } } + @Override protected void installKeyboardActions() { } //$ Not Mac-ish - should we support? - protected ResizeBox resizeBox; + @Override protected void installComponents() { final JLayeredPane layeredPane = frame.getLayeredPane(); - if (resizeBox != null) { - resizeBox.removeListeners(); - layeredPane.removeComponentListener(resizeBox); - layeredPane.remove(resizeBox); - resizeBox = null; - } - resizeBox = new ResizeBox(layeredPane); resizeBox.repositionResizeBox(); @@ -218,6 +222,7 @@ } /// Inherit all the listeners - that's the main reason we subclass Basic! + @Override protected void installListeners() { fPropertyListener = new PropertyListener(); frame.addPropertyChangeListener(fPropertyListener); @@ -225,22 +230,36 @@ } // uninstallDefaults - // uninstallComponents + + @Override + protected void uninstallComponents() { + super.uninstallComponents(); + final JLayeredPane layeredPane = frame.getLayeredPane(); + resizeBox.removeListeners(); + layeredPane.removeComponentListener(resizeBox); + layeredPane.remove(resizeBox); + resizeBox = null; + } + + @Override protected void uninstallListeners() { super.uninstallListeners(); frame.removePropertyChangeListener(fPropertyListener); } + @Override protected void uninstallKeyboardActions() { } // Called when a DesktopIcon replaces an InternalFrame & vice versa //protected void replacePane(JComponent currentPane, JComponent newPane) {} + @Override protected void installMouseHandlers(final JComponent c) { c.addMouseListener(borderListener); c.addMouseMotionListener(borderListener); } + @Override protected void deinstallMouseHandlers(final JComponent c) { c.removeMouseListener(borderListener); c.removeMouseMotionListener(borderListener); @@ -256,6 +275,7 @@ return map; } + @Override public Dimension getPreferredSize(JComponent x) { Dimension preferredSize = super.getPreferredSize(x); Dimension minimumSize = frame.getMinimumSize(); @@ -268,6 +288,7 @@ return preferredSize; } + @Override public void setNorthPane(final JComponent c) { replacePane(northPane, c); northPane = c; @@ -278,6 +299,7 @@ * and adds it to the frame. * Reverse process for the <code>currentPane</code>. */ + @Override protected void replacePane(final JComponent currentPane, final JComponent newPane) { if (currentPane != null) { deinstallMouseHandlers(currentPane); @@ -290,6 +312,7 @@ } // Our "Border" listener is shared by the AquaDesktopIcon + @Override protected MouseInputAdapter createBorderListener(final JInternalFrame w) { return new AquaBorderListener(); } @@ -374,6 +397,7 @@ protected final int RESIZE_NONE = 0; private boolean discardRelease = false; + @Override public void mouseClicked(final MouseEvent e) { if (didForwardEvent(e)) return; @@ -406,6 +430,7 @@ fAquaBorder.repaintButtonArea(frame); } + @Override public void mouseReleased(final MouseEvent e) { if (didForwardEvent(e)) return; @@ -461,6 +486,7 @@ resizeDir = RESIZE_NONE; } + @Override public void mousePressed(final MouseEvent e) { if (didForwardEvent(e)) return; @@ -527,6 +553,7 @@ return true; } + @Override public void mouseDragged(final MouseEvent e) { // do not forward drags // if (didForwardEvent(e)) return; @@ -576,6 +603,7 @@ return; } + @Override public void mouseMoved(final MouseEvent e) { if (didForwardEvent(e)) return; updateRollover(e); @@ -614,7 +642,11 @@ if (hitComponent == null || hitComponent == frame) return false; final Point hitComponentPoint = SwingUtilities.convertPoint(pane, parentPoint, hitComponent); - hitComponent.dispatchEvent(new MouseEvent(hitComponent, e.getID(), e.getWhen(), e.getModifiers(), hitComponentPoint.x, hitComponentPoint.y, e.getClickCount(), e.isPopupTrigger(), e.getButton())); + hitComponent.dispatchEvent( + new MouseEvent(hitComponent, e.getID(), e.getWhen(), + e.getModifiers(), hitComponentPoint.x, + hitComponentPoint.y, e.getClickCount(), + e.isPopupTrigger(), e.getButton())); return true; } @@ -668,6 +700,7 @@ } class PropertyListener implements PropertyChangeListener { + @Override public void propertyChange(final PropertyChangeEvent e) { final String name = e.getPropertyName(); if (FRAME_TYPE.equals(name)) { @@ -704,14 +737,17 @@ } // end class PaletteListener static final InternalFrameShadow documentWindowShadow = new InternalFrameShadow() { + @Override Border getForegroundShadowBorder() { return new AquaUtils.SlicedShadowBorder(new Painter() { + @Override public void paint(final Graphics g, final int x, final int y, final int w, final int h) { g.setColor(new Color(0, 0, 0, 196)); g.fillRoundRect(x, y, w, h, 16, 16); g.fillRect(x, y + h - 16, w, 16); } }, new Painter() { + @Override public void paint(final Graphics g, int x, int y, int w, int h) { g.setColor(new Color(0, 0, 0, 64)); g.drawLine(x + 2, y - 8, x + w - 2, y - 8); @@ -720,14 +756,17 @@ 0, 7, 1.1f, 1.0f, 24, 51, 51, 25, 25, 25, 25); } + @Override Border getBackgroundShadowBorder() { return new AquaUtils.SlicedShadowBorder(new Painter() { + @Override public void paint(final Graphics g, final int x, final int y, final int w, final int h) { g.setColor(new Color(0, 0, 0, 128)); g.fillRoundRect(x - 3, y - 8, w + 6, h, 16, 16); g.fillRect(x - 3, y + h - 20, w + 6, 19); } }, new Painter() { + @Override public void paint(final Graphics g, int x, int y, int w, int h) { g.setColor(new Color(0, 0, 0, 32)); g.drawLine(x, y - 11, x + w - 1, y - 11); @@ -738,8 +777,10 @@ }; static final InternalFrameShadow paletteWindowShadow = new InternalFrameShadow() { + @Override Border getForegroundShadowBorder() { return new AquaUtils.SlicedShadowBorder(new Painter() { + @Override public void paint(final Graphics g, final int x, final int y, final int w, final int h) { g.setColor(new Color(0, 0, 0, 128)); g.fillRect(x, y + 3, w, h - 3); @@ -748,6 +789,7 @@ 0, 3, 1.0f, 1.0f, 10, 25, 25, 12, 12, 12, 12); } + @Override Border getBackgroundShadowBorder() { return getForegroundShadowBorder(); } @@ -762,19 +804,23 @@ abstract Border getForegroundShadowBorder(); abstract Border getBackgroundShadowBorder(); + @Override protected Border getInstance() { final Border fgShadow = getForegroundShadowBorder(); final Border bgShadow = getBackgroundShadowBorder(); return new Border() { + @Override public Insets getBorderInsets(final Component c) { return fgShadow.getBorderInsets(c); } + @Override public boolean isBorderOpaque() { return false; } + @Override public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int w, final int h) { if (((JInternalFrame)c).isSelected()) { fgShadow.paintBorder(c, g, x, y, w, h); @@ -790,6 +836,7 @@ @Override protected Icon getInstance() { return new AquaIcon.ScalingJRSUIIcon(11, 11) { + @Override public void initIconPainter(final AquaPainter<JRSUIState> iconState) { iconState.state.set(Widget.GROW_BOX_TEXTURED); iconState.state.set(WindowType.UTILITY); @@ -799,12 +846,15 @@ }; @SuppressWarnings("serial") // Superclass is not serializable across versions - class ResizeBox extends JLabel implements MouseListener, MouseMotionListener, MouseWheelListener, ComponentListener, PropertyChangeListener, UIResource { - final JLayeredPane layeredPane; - Dimension originalSize; - Point originalLocation; + private final class ResizeBox extends JLabel + implements MouseListener, MouseMotionListener, MouseWheelListener, + ComponentListener, PropertyChangeListener, UIResource { - public ResizeBox(final JLayeredPane layeredPane) { + private final JLayeredPane layeredPane; + private Dimension originalSize; + private Point originalLocation; + + ResizeBox(final JLayeredPane layeredPane) { super(RESIZE_ICON.get()); setSize(11, 11); this.layeredPane = layeredPane; @@ -895,14 +945,18 @@ return c; } + @Override public void mouseClicked(final MouseEvent e) { forwardEventToFrame(e); } + @Override public void mouseEntered(final MouseEvent e) { } + @Override public void mouseExited(final MouseEvent e) { } + @Override public void mousePressed(final MouseEvent e) { if (frame == null) return; @@ -916,6 +970,7 @@ forwardEventToFrame(e); } + @Override public void mouseReleased(final MouseEvent e) { if (originalLocation != null) { resizeInternalFrame(e.getPoint()); @@ -927,13 +982,16 @@ forwardEventToFrame(e); } + @Override public void mouseDragged(final MouseEvent e) { resizeInternalFrame(e.getPoint()); repositionResizeBox(); } + @Override public void mouseMoved(final MouseEvent e) { } + @Override public void mouseWheelMoved(final MouseWheelEvent e) { final Point pt = new Point(); final Component c = getComponentToForwardTo(e, pt); @@ -945,20 +1003,25 @@ e.getPreciseWheelRotation())); } + @Override public void componentResized(final ComponentEvent e) { repositionResizeBox(); } + @Override public void componentShown(final ComponentEvent e) { repositionResizeBox(); } + @Override public void componentMoved(final ComponentEvent e) { repositionResizeBox(); } + @Override public void componentHidden(final ComponentEvent e) { } + @Override public void propertyChange(final PropertyChangeEvent evt) { if (!"resizable".equals(evt.getPropertyName())) return; setVisible(Boolean.TRUE.equals(evt.getNewValue()));
--- a/src/java.desktop/macosx/classes/com/apple/laf/AquaSpinnerUI.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaSpinnerUI.java Fri Sep 18 09:18:17 2015 -0700 @@ -49,12 +49,14 @@ * so we can't subclass! */ public class AquaSpinnerUI extends SpinnerUI { - private static final RecyclableSingleton<? extends PropertyChangeListener> propertyChangeListener = new RecyclableSingletonFromDefaultConstructor<PropertyChangeHandler>(PropertyChangeHandler.class); + private static final RecyclableSingleton<? extends PropertyChangeListener> propertyChangeListener + = new RecyclableSingletonFromDefaultConstructor<>(PropertyChangeHandler.class); static PropertyChangeListener getPropertyChangeListener() { return propertyChangeListener.get(); } - private static final RecyclableSingleton<ArrowButtonHandler> nextButtonHandler = new RecyclableSingleton<ArrowButtonHandler>() { + private static final RecyclableSingleton<ArrowButtonHandler> nextButtonHandler + = new RecyclableSingleton<ArrowButtonHandler>() { @Override protected ArrowButtonHandler getInstance() { return new ArrowButtonHandler("increment", true); @@ -63,7 +65,8 @@ static ArrowButtonHandler getNextButtonHandler() { return nextButtonHandler.get(); } - private static final RecyclableSingleton<ArrowButtonHandler> previousButtonHandler = new RecyclableSingleton<ArrowButtonHandler>() { + private static final RecyclableSingleton<ArrowButtonHandler> previousButtonHandler + = new RecyclableSingleton<ArrowButtonHandler>() { @Override protected ArrowButtonHandler getInstance() { return new ArrowButtonHandler("decrement", false); @@ -73,8 +76,10 @@ return previousButtonHandler.get(); } - JSpinner spinner; - SpinPainter spinPainter; + private JSpinner spinner; + private SpinPainter spinPainter; + private TransparentButton next; + private TransparentButton prev; public static ComponentUI createUI(final JComponent c) { return new AquaSpinnerUI(); @@ -87,12 +92,13 @@ } boolean wasOpaque; + @Override public void installUI(final JComponent c) { this.spinner = (JSpinner)c; installDefaults(); installListeners(); - final TransparentButton next = createNextButton(); - final TransparentButton prev = createPreviousButton(); + next = createNextButton(); + prev = createPreviousButton(); spinPainter = new SpinPainter(next, prev); maybeAdd(next, "Next"); @@ -111,11 +117,21 @@ spinner.setOpaque(false); } + @Override public void uninstallUI(final JComponent c) { uninstallDefaults(); uninstallListeners(); spinner.setOpaque(wasOpaque); + spinPainter = null; spinner = null; + // AquaButtonUI install some listeners to all parents, which means that + // we need to uninstall UI here to remove those listeners, because after + // we remove them from spinner we lost the latest reference to them, + // and our standard uninstallUI machinery will not call them. + next.getUI().uninstallUI(next); + prev.getUI().uninstallUI(prev); + next = null; + prev = null; c.removeAll(); } @@ -164,6 +180,7 @@ /** * {@inheritDoc} */ + @Override public int getBaseline(JComponent c, int width, int height) { super.getBaseline(c, width, height); JComponent editor = spinner.getEditor(); @@ -182,6 +199,7 @@ /** * {@inheritDoc} */ + @Override public Component.BaselineResizeBehavior getBaselineResizeBehavior( JComponent c) { super.getBaselineResizeBehavior(c); @@ -200,8 +218,10 @@ interceptRepaints = true; } + @Override public void paint(final Graphics g) {} + @Override public void repaint() { // only intercept repaints if we are after this has been initialized // otherwise we can't talk to our containing class @@ -315,6 +335,7 @@ return (src instanceof JSpinner) ? (JSpinner)src : null; } + @Override public void actionPerformed(final ActionEvent e) { if (!(e.getSource() instanceof javax.swing.Timer)) { // Most likely resulting from being in ActionMap. @@ -423,6 +444,7 @@ return -1; } + @Override public void mousePressed(final MouseEvent e) { if (!SwingUtilities.isLeftMouseButton(e) || !e.getComponent().isEnabled()) return; spinner = eventToSpinner(e); @@ -431,13 +453,17 @@ focusSpinnerIfNecessary(); } + @Override public void mouseReleased(final MouseEvent e) { autoRepeatTimer.stop(); spinner = null; } + @Override public void mouseClicked(final MouseEvent e) {} + @Override public void mouseEntered(final MouseEvent e) {} + @Override public void mouseExited(final MouseEvent e) {} /** @@ -485,6 +511,7 @@ } } + @Override public void paint(final Graphics g) { if (spinner.isOpaque()) { g.setColor(spinner.getBackground()); @@ -511,6 +538,7 @@ painter.paint(g, spinner, 0, 0, bounds.width, bounds.height); } + @Override public Dimension getPreferredSize() { final Size size = AquaUtilControlSize.getUserSizeFrom(this); @@ -533,6 +561,7 @@ private Component editor = null; private Component painter = null; + @Override public void addLayoutComponent(final String name, final Component c) { if ("Next".equals(name)) { nextButton = c; @@ -545,6 +574,7 @@ } } + @Override public void removeLayoutComponent(Component c) { if (c == nextButton) { c = null; @@ -561,6 +591,7 @@ return (c == null) ? new Dimension(0, 0) : c.getPreferredSize(); } + @Override public Dimension preferredLayoutSize(final Container parent) { // Dimension nextD = preferredSize(nextButton); // Dimension previousD = preferredSize(previousButton); @@ -579,6 +610,7 @@ return size; } + @Override public Dimension minimumLayoutSize(final Container parent) { return preferredLayoutSize(parent); } @@ -589,6 +621,7 @@ } } + @Override public void layoutContainer(final Container parent) { final Insets insets = parent.getInsets(); final int availWidth = parent.getWidth() - (insets.left + insets.right); @@ -629,6 +662,7 @@ * property changes are delegated to protected methods. */ static class PropertyChangeHandler implements PropertyChangeListener { + @Override public void propertyChange(final PropertyChangeEvent e) { final String propertyName = e.getPropertyName(); final JSpinner spinner = (JSpinner)(e.getSource());
--- a/src/java.desktop/macosx/classes/com/apple/laf/AquaTabbedPaneUI.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaTabbedPaneUI.java Fri Sep 18 09:18:17 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -95,6 +95,17 @@ super.assureRectsCreated(tabCount); } + @Override + protected void uninstallListeners() { + // We're not just a mouseListener, we're a mouseMotionListener + if (mouseListener instanceof MouseHandler) { + final MouseHandler mh = (MouseHandler) mouseListener; + mh.dispose(); + tabPane.removeMouseMotionListener(mh); + } + super.uninstallListeners(); + } + protected void uninstallDefaults() { contentDrawingInsets.set(0, 0, 0, 0); } @@ -409,7 +420,15 @@ paintTabNormalFromRect(g, tabPlacement, rects[tabIndex], tabIndex, fIconRect, fTextRect, active, frameActive, isLeftToRight); } - protected void paintTabNormalFromRect(final Graphics g, final int tabPlacement, final Rectangle tabRect, final int nonRectIndex, final Rectangle iconRect, final Rectangle textRect, final boolean active, final boolean frameActive, final boolean isLeftToRight) { + protected void paintTabNormalFromRect(final Graphics g, + final int tabPlacement, + final Rectangle tabRect, + final int nonRectIndex, + final Rectangle iconRect, + final Rectangle textRect, + final boolean active, + final boolean frameActive, + final boolean isLeftToRight) { final int selectedIndex = tabPane.getSelectedIndex(); final boolean isSelected = selectedIndex == nonRectIndex; @@ -420,7 +439,12 @@ paintContents(g, tabPlacement, nonRectIndex, tabRect, iconRect, textRect, isSelected); } - protected void paintCUITab(final Graphics g, final int tabPlacement, final Rectangle tabRect, final boolean isSelected, final boolean frameActive, final boolean isLeftToRight, final int nonRectIndex) { + protected void paintCUITab(final Graphics g, final int tabPlacement, + final Rectangle tabRect, + final boolean isSelected, + final boolean frameActive, + final boolean isLeftToRight, + final int nonRectIndex) { final int tabCount = tabPane.getTabCount(); final boolean needsLeftScrollTab = visibleTabState.needsLeftScrollTab(); @@ -835,14 +859,20 @@ } } - public class MouseHandler extends MouseInputAdapter implements ActionListener { - protected int trackingTab = -3; - protected Timer popupTimer = new Timer(500, this); + class MouseHandler extends MouseInputAdapter implements ActionListener { + + int trackingTab = -3; + private final Timer popupTimer = new Timer(500, this); - public MouseHandler() { + MouseHandler() { popupTimer.setRepeats(false); } + void dispose (){ + popupTimer.removeActionListener(this); + popupTimer.stop(); + } + public void mousePressed(final MouseEvent e) { final JTabbedPane pane = (JTabbedPane)e.getSource(); if (!pane.isEnabled()) {
--- a/src/java.desktop/macosx/classes/com/apple/laf/AquaTextAreaUI.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaTextAreaUI.java Fri Sep 18 09:18:17 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -42,6 +42,7 @@ } AquaFocusHandler handler; + @Override protected void installListeners() { super.installListeners(); @@ -53,6 +54,7 @@ AquaUtilControlSize.addSizePropertyListener(c); } + @Override protected void uninstallListeners() { final JTextComponent c = getComponent(); @@ -66,6 +68,7 @@ } boolean oldDragState = false; + @Override protected void installDefaults() { if (!GraphicsEnvironment.isHeadless()) { oldDragState = getComponent().getDragEnabled(); @@ -74,6 +77,7 @@ super.installDefaults(); } + @Override protected void uninstallDefaults() { if (!GraphicsEnvironment.isHeadless()) { getComponent().setDragEnabled(oldDragState); @@ -81,7 +85,9 @@ super.uninstallDefaults(); } - // Install a default keypress action which handles Cmd and Option keys properly + // Install a default keypress action which handles Cmd and Option keys + // properly + @Override protected void installKeyboardActions() { super.installKeyboardActions(); AquaKeyBindings bindings = AquaKeyBindings.instance(); @@ -90,13 +96,12 @@ bindings.installAquaUpDownActions(c); } + @Override protected Caret createCaret() { - final JTextComponent c = getComponent(); - final Window owningWindow = SwingUtilities.getWindowAncestor(c); - final AquaCaret returnValue = new AquaCaret(owningWindow, c); - return returnValue; + return new AquaCaret(); } + @Override protected Highlighter createHighlighter() { return new AquaHighlighter(); }
--- a/src/java.desktop/macosx/classes/com/apple/laf/AquaTextFieldUI.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaTextFieldUI.java Fri Sep 18 09:18:17 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -42,6 +42,7 @@ protected JComponentPainter delegate; protected AquaFocusHandler handler; + @Override protected void installListeners() { super.installListeners(); @@ -55,6 +56,7 @@ AquaTextFieldSearch.installSearchFieldListener(c); } + @Override protected void uninstallListeners() { final JTextComponent c = getComponent(); AquaTextFieldSearch.uninstallSearchFieldListener(c); @@ -67,6 +69,7 @@ } boolean oldDragState = false; + @Override protected void installDefaults() { if (!GraphicsEnvironment.isHeadless()) { oldDragState = getComponent().getDragEnabled(); @@ -76,6 +79,7 @@ super.installDefaults(); } + @Override protected void uninstallDefaults() { super.uninstallDefaults(); @@ -84,12 +88,15 @@ } } - // Install a default keypress action which handles Cmd and Option keys properly + // Install a default keypress action which handles Cmd and Option keys + // properly + @Override protected void installKeyboardActions() { super.installKeyboardActions(); AquaKeyBindings.instance().setDefaultAction(getKeymapName()); } + @Override protected Rectangle getVisibleEditorRect() { final Rectangle rect = super.getVisibleEditorRect(); if (rect == null) return null; @@ -102,6 +109,7 @@ return rect; } + @Override protected void paintSafely(final Graphics g) { paintBackgroundSafely(g); super.paintSafely(g); @@ -149,20 +157,23 @@ // the common case final int shrinkage = AquaTextFieldBorder.getShrinkageFor(c, height); - g.fillRect(insets.left - 2, insets.top - shrinkage - 1, width - insets.right - insets.left + 4, height - insets.bottom - insets.top + shrinkage * 2 + 2); + g.fillRect(insets.left - 2, insets.top - shrinkage - 1, + width - insets.right - insets.left + 4, + height - insets.bottom - insets.top + shrinkage * 2 + 2); } + @Override protected void paintBackground(final Graphics g) { // we have already ensured that the background is painted to our liking // by paintBackgroundSafely(), called from paintSafely(). } + @Override protected Caret createCaret() { - final JTextComponent c = getComponent(); - final Window owningWindow = SwingUtilities.getWindowAncestor(c); - return new AquaCaret(owningWindow, c); + return new AquaCaret(); } + @Override protected Highlighter createHighlighter() { return new AquaHighlighter(); }
--- a/src/java.desktop/macosx/classes/com/apple/laf/AquaTextPaneUI.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaTextPaneUI.java Fri Sep 18 09:18:17 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, 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 @@ -43,6 +43,7 @@ } AquaFocusHandler handler; + @Override protected void installListeners() { super.installListeners(); final JComponent c = getComponent(); @@ -52,6 +53,7 @@ AquaUtilControlSize.addSizePropertyListener(c); } + @Override protected void uninstallListeners() { final JComponent c = getComponent(); AquaUtilControlSize.removeSizePropertyListener(c); @@ -62,6 +64,7 @@ } boolean oldDragState = false; + @Override protected void installDefaults() { final JTextComponent c = getComponent(); if (!GraphicsEnvironment.isHeadless()) { @@ -71,6 +74,7 @@ super.installDefaults(); } + @Override protected void uninstallDefaults() { if (!GraphicsEnvironment.isHeadless()) { getComponent().setDragEnabled(oldDragState); @@ -78,7 +82,9 @@ super.uninstallDefaults(); } - // Install a default keypress action which handles Cmd and Option keys properly + // Install a default keypress action which handles Cmd and Option keys + // properly + @Override protected void installKeyboardActions() { super.installKeyboardActions(); AquaKeyBindings bindings = AquaKeyBindings.instance(); @@ -88,12 +94,12 @@ bindings.installAquaUpDownActions(c); } + @Override protected Caret createCaret() { - final JTextComponent c = getComponent(); - final Window owningWindow = SwingUtilities.getWindowAncestor(c); - return new AquaCaret(owningWindow, c); + return new AquaCaret(); } + @Override protected Highlighter createHighlighter() { return new AquaHighlighter(); }
--- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CImage.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CImage.java Fri Sep 18 09:18:17 2015 -0700 @@ -31,7 +31,7 @@ import java.util.Arrays; import java.util.List; -import sun.awt.image.MultiResolutionImage; +import java.awt.image.MultiResolutionImage; import sun.awt.image.MultiResolutionCachedImage; import sun.awt.image.SunWritableRaster;
--- a/src/java.desktop/share/classes/com/sun/media/sound/SoftMidiAudioFileReader.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/share/classes/com/sun/media/sound/SoftMidiAudioFileReader.java Fri Sep 18 09:18:17 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2015, 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 @@ -25,10 +25,8 @@ package com.sun.media.sound; -import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.net.URL; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MetaMessage; @@ -44,28 +42,27 @@ import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.UnsupportedAudioFileException; -import javax.sound.sampled.spi.AudioFileReader; /** * MIDI File Audio Renderer/Reader. * * @author Karl Helgason */ -public final class SoftMidiAudioFileReader extends AudioFileReader { +public final class SoftMidiAudioFileReader extends SunFileReader { + + private static final Type MIDI = new Type("MIDI", "mid"); - public static final Type MIDI = new Type("MIDI", "mid"); - private static AudioFormat format = new AudioFormat(44100, 16, 2, true, false); + private static final AudioFormat format = new AudioFormat(44100, 16, 2, + true, false); - public AudioFileFormat getAudioFileFormat(Sequence seq) - throws UnsupportedAudioFileException, IOException { - + private static AudioFileFormat getAudioFileFormat(final Sequence seq) { long totallen = seq.getMicrosecondLength() / 1000000; long len = (long) (format.getFrameRate() * (totallen + 4)); return new AudioFileFormat(MIDI, format, (int) len); } - public AudioInputStream getAudioInputStream(Sequence seq) - throws UnsupportedAudioFileException, IOException { + private AudioInputStream getAudioInputStream(final Sequence seq) + throws InvalidMidiDataException { AudioSynthesizer synth = (AudioSynthesizer) new SoftSynthesizer(); AudioInputStream stream; Receiver recv; @@ -73,7 +70,7 @@ stream = synth.openStream(format, null); recv = synth.getReceiver(); } catch (MidiUnavailableException e) { - throw new IOException(e.toString()); + throw new InvalidMidiDataException(e.toString()); } float divtype = seq.getDivisionType(); Track[] tracks = seq.getTracks(); @@ -111,7 +108,7 @@ if (((MetaMessage) msg).getType() == 0x51) { byte[] data = ((MetaMessage) msg).getData(); if (data.length < 3) { - throw new UnsupportedAudioFileException(); + throw new InvalidMidiDataException(); } mpq = ((data[0] & 0xff) << 16) | ((data[1] & 0xff) << 8) | (data[2] & 0xff); @@ -128,91 +125,25 @@ return stream; } - public AudioInputStream getAudioInputStream(InputStream inputstream) + @Override + public AudioInputStream getAudioInputStream(final InputStream stream) throws UnsupportedAudioFileException, IOException { - - inputstream.mark(200); - Sequence seq; + stream.mark(200); try { - seq = MidiSystem.getSequence(inputstream); - } catch (InvalidMidiDataException e) { - inputstream.reset(); - throw new UnsupportedAudioFileException(); - } catch (IOException e) { - inputstream.reset(); + return getAudioInputStream(MidiSystem.getSequence(stream)); + } catch (final InvalidMidiDataException ignored) { + stream.reset(); throw new UnsupportedAudioFileException(); } - return getAudioInputStream(seq); - } - - public AudioFileFormat getAudioFileFormat(URL url) - throws UnsupportedAudioFileException, IOException { - Sequence seq; - try { - seq = MidiSystem.getSequence(url); - } catch (InvalidMidiDataException e) { - throw new UnsupportedAudioFileException(); - } catch (IOException e) { - throw new UnsupportedAudioFileException(); - } - return getAudioFileFormat(seq); - } - - public AudioFileFormat getAudioFileFormat(File file) - throws UnsupportedAudioFileException, IOException { - Sequence seq; - try { - seq = MidiSystem.getSequence(file); - } catch (InvalidMidiDataException e) { - throw new UnsupportedAudioFileException(); - } catch (IOException e) { - throw new UnsupportedAudioFileException(); - } - return getAudioFileFormat(seq); } - public AudioInputStream getAudioInputStream(URL url) + @Override + AudioFileFormat getAudioFileFormatImpl(final InputStream stream) throws UnsupportedAudioFileException, IOException { - Sequence seq; try { - seq = MidiSystem.getSequence(url); - } catch (InvalidMidiDataException e) { - throw new UnsupportedAudioFileException(); - } catch (IOException e) { + return getAudioFileFormat(MidiSystem.getSequence(stream)); + } catch (final InvalidMidiDataException ignored) { throw new UnsupportedAudioFileException(); } - return getAudioInputStream(seq); - } - - public AudioInputStream getAudioInputStream(File file) - throws UnsupportedAudioFileException, IOException { - if (!file.getName().toLowerCase().endsWith(".mid")) - throw new UnsupportedAudioFileException(); - Sequence seq; - try { - seq = MidiSystem.getSequence(file); - } catch (InvalidMidiDataException e) { - throw new UnsupportedAudioFileException(); - } catch (IOException e) { - throw new UnsupportedAudioFileException(); - } - return getAudioInputStream(seq); - } - - public AudioFileFormat getAudioFileFormat(InputStream inputstream) - throws UnsupportedAudioFileException, IOException { - - inputstream.mark(200); - Sequence seq; - try { - seq = MidiSystem.getSequence(inputstream); - } catch (InvalidMidiDataException e) { - inputstream.reset(); - throw new UnsupportedAudioFileException(); - } catch (IOException e) { - inputstream.reset(); - throw new UnsupportedAudioFileException(); - } - return getAudioFileFormat(seq); } }
--- a/src/java.desktop/share/classes/com/sun/media/sound/SunFileReader.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/share/classes/com/sun/media/sound/SunFileReader.java Fri Sep 18 09:18:17 2015 -0700 @@ -52,10 +52,6 @@ try { return getAudioFileFormatImpl(stream); } finally { - // According to specification the following is not strictly - // necessary, if we got correct format. But it was implemented like - // that in 1.3.0 - 1.8. So I leave it as it was, but it seems - // specification should be updated. stream.reset(); } }
--- a/src/java.desktop/share/classes/java/awt/EventQueue.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/share/classes/java/awt/EventQueue.java Fri Sep 18 09:18:17 2015 -0700 @@ -899,11 +899,13 @@ } } - // Wake up EDT waiting in getNextEvent(), so it can - // pick up a new EventQueue. Post the waking event before - // topQueue.nextQueue is assigned, otherwise the event would - // go newEventQueue - topQueue.postEventPrivate(new InvocationEvent(topQueue, dummyRunnable)); + if (topQueue.dispatchThread != null) { + // Wake up EDT waiting in getNextEvent(), so it can + // pick up a new EventQueue. Post the waking event before + // topQueue.nextQueue is assigned, otherwise the event would + // go newEventQueue + topQueue.postEventPrivate(new InvocationEvent(topQueue, dummyRunnable)); + } newEventQueue.previousQueue = topQueue; topQueue.nextQueue = newEventQueue;
--- a/src/java.desktop/share/classes/java/awt/Font.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/share/classes/java/awt/Font.java Fri Sep 18 09:18:17 2015 -0700 @@ -128,7 +128,9 @@ * <p> * For a discussion of the relative advantages and disadvantages of using * physical or logical fonts, see the - * <a href="http://www.oracle.com/technetwork/java/javase/tech/faq-jsp-138165.html">Internationalization FAQ</a> + * <a href="https://docs.oracle.com/javase/tutorial/2d/text/fonts.html#advantages-and-disadvantages"> + * Physical and Logical Fonts</a> + * in <a href="https://docs.oracle.com/javase/tutorial/index.html">The Java Tutorials</a> * document. * * <h3>Font Faces and Names</h3>
--- a/src/java.desktop/share/classes/java/awt/RenderingHints.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/share/classes/java/awt/RenderingHints.java Fri Sep 18 09:18:17 2015 -0700 @@ -955,6 +955,64 @@ SunHints.VALUE_STROKE_PURE; /** + * Image resolution variant hint key. + * The {@code RESOLUTION_VARIANT} hint controls which image resolution + * variant should be chosen for image drawing. + * + * <ul> + * <li>{@link #VALUE_RESOLUTION_VARIANT_DEFAULT} + * <li>{@link #VALUE_RESOLUTION_VARIANT_BASE} + * <li>{@link #VALUE_RESOLUTION_VARIANT_SIZE_FIT} + * <li>{@link #VALUE_RESOLUTION_VARIANT_DPI_FIT} + * </ul> + * @since 1.9 + */ + public static final Key KEY_RESOLUTION_VARIANT = + SunHints.KEY_RESOLUTION_VARIANT; + + /** + * Image resolution variant hint value -- an image resolution variant is + * chosen based on a default heuristic which may depend on the policies + * of the platform + * + * @see #KEY_RESOLUTION_VARIANT + * @since 1.9 + */ + public static final Object VALUE_RESOLUTION_VARIANT_DEFAULT = + SunHints.VALUE_RESOLUTION_VARIANT_DEFAULT; + + /** + * Image resolution variant hint value -- the standard resolution of an image + * is always used. + * + * @see #KEY_RESOLUTION_VARIANT + * @since 1.9 + */ + public static final Object VALUE_RESOLUTION_VARIANT_BASE = + SunHints.VALUE_RESOLUTION_VARIANT_BASE; + + /** + * Image resolution variant hint value -- an image resolution variant is + * chosen based on the DPI of the screen and the transform in the Graphics2D + * context. + * + * @see #KEY_RESOLUTION_VARIANT + * @since 1.9 + */ + public static final Object VALUE_RESOLUTION_VARIANT_SIZE_FIT = + SunHints.VALUE_RESOLUTION_VARIANT_SIZE_FIT; + + /** + * Image resolution variant hint value -- an image resolution variant is + * chosen based only on the DPI of the screen. + * + * @see #KEY_RESOLUTION_VARIANT + * @since 1.9 + */ + public static final Object VALUE_RESOLUTION_VARIANT_DPI_FIT = + SunHints.VALUE_RESOLUTION_VARIANT_DPI_FIT; + + /** * Constructs a new object with keys and values initialized * from the specified Map object which may be null. * @param init a map of key/value pairs to initialize the hints
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java.desktop/share/classes/java/awt/image/AbstractMultiResolutionImage.java Fri Sep 18 09:18:17 2015 -0700 @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2015, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.awt.image; + +import java.awt.Graphics; +import java.awt.Image; + +/** + * This class provides default implementations of several {@code Image} methods + * for classes that want to implement the {@MultiResolutionImage} interface. + * + * For example, + * <pre> {@code + * public class CustomMultiResolutionImage extends AbstractMultiResolutionImage { + * + * final Image[] resolutionVariants; + * + * public CustomMultiResolutionImage(Image... resolutionVariants) { + * this.resolutionVariants = resolutionVariants; + * } + * + * public Image getResolutionVariant( + * double destImageWidth, double destImageHeight) { + * // return a resolution variant based on the given destination image size + * } + * + * public List<Image> getResolutionVariants() { + * return Collections.unmodifiableList(Arrays.asList(resolutionVariants)); + * } + * + * protected Image getBaseImage() { + * return resolutionVariants[0]; + * } + * } + * } </pre> + * + * @see java.awt.Image + * @see java.awt.image.MultiResolutionImage + * + * @since 1.9 + */ +public abstract class AbstractMultiResolutionImage extends java.awt.Image + implements MultiResolutionImage { + + @Override + public int getWidth(ImageObserver observer) { + return getBaseImage().getWidth(observer); + } + + @Override + public int getHeight(ImageObserver observer) { + return getBaseImage().getHeight(observer); + } + + @Override + public ImageProducer getSource() { + return getBaseImage().getSource(); + } + + @Override + public Graphics getGraphics() { + throw new UnsupportedOperationException("getGraphics() not supported" + + " on Multi-Resolution Images"); + } + + @Override + public Object getProperty(String name, ImageObserver observer) { + return getBaseImage().getProperty(name, observer); + } + + /** + * Return the base image representing the best version of the image for + * rendering at the default width and height. + * + * @return the base image of the set of multi-resolution images + * + * @since 1.9 + */ + protected abstract Image getBaseImage(); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java.desktop/share/classes/java/awt/image/BaseMultiResolutionImage.java Fri Sep 18 09:18:17 2015 -0700 @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2015, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.awt.image; + +import java.awt.Image; +import java.util.List; +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; + +/** + * This class is an array-based implementation of + * the {@code AbstractMultiResolutionImage} class. + * + * This class will implement the + * {@code getResolutionVariant(double destImageWidth, double destImageHeight)} + * method using a simple algorithm which will return the first image variant + * in the array that is large enough to satisfy the rendering request. The + * last image in the array will be returned if no suitable image is found + * that is as large as the rendering request. + * <p> + * For best effect the array of images should be sorted with each image being + * both wider and taller than the previous image. The base image need not be + * the first image in the array. No exception will be thrown if the images + * are not sorted as suggested. + * + * @see java.awt.Image + * @see java.awt.image.MultiResolutionImage + * @see java.awt.image.AbstractMultiResolutionImage + * + * @since 1.9 + */ +public class BaseMultiResolutionImage extends AbstractMultiResolutionImage { + + private final int baseImageIndex; + private final Image[] resolutionVariants; + + /** + * Creates a multi-resolution image with the given resolution variants. + * The first resolution variant is used as the base image. + * + * @param resolutionVariants array of resolution variants sorted by image size + * @throws IllegalArgumentException if null or zero-length array is passed + * @throws NullPointerException if the specified {@code resolutionVariants} + * contains one or more null elements + * + * @since 1.9 + */ + public BaseMultiResolutionImage(Image... resolutionVariants) { + this(0, resolutionVariants); + } + + /** + * Creates a multi-resolution image with the given base image index and + * resolution variants. + * + * @param baseImageIndex the index of base image in the resolution variants + * array + * @param resolutionVariants array of resolution variants sorted by image size + * @throws IllegalArgumentException if null or zero-length array is passed + * @throws NullPointerException if the specified {@code resolutionVariants} + * contains one or more null elements + * @throws IndexOutOfBoundsException if {@code baseImageIndex} is + * negative or greater than or equal to {@code resolutionVariants} + * length. + * + * @since 1.9 + */ + public BaseMultiResolutionImage(int baseImageIndex, + Image... resolutionVariants) { + + if (resolutionVariants == null || resolutionVariants.length == 0) { + throw new IllegalArgumentException( + "Null or zero-length array is passed"); + } + + if (baseImageIndex < 0 || baseImageIndex >= resolutionVariants.length) { + throw new IndexOutOfBoundsException("Invalid base image index: " + + baseImageIndex); + } + + this.baseImageIndex = baseImageIndex; + this.resolutionVariants = Arrays.copyOf(resolutionVariants, + resolutionVariants.length); + + for (Image resolutionVariant : this.resolutionVariants) { + Objects.requireNonNull(resolutionVariant, + "Resolution variant can't be null"); + } + } + + @Override + public Image getResolutionVariant(double destImageWidth, + double destImageHeight) { + + checkSize(destImageWidth, destImageHeight); + + for (Image rvImage : resolutionVariants) { + if (destImageWidth <= rvImage.getWidth(null) + && destImageHeight <= rvImage.getHeight(null)) { + return rvImage; + } + } + return resolutionVariants[resolutionVariants.length - 1]; + } + + private static void checkSize(double width, double height) { + if (width <= 0 || height <= 0) { + throw new IllegalArgumentException(String.format( + "Width (%s) or height (%s) cannot be <= 0", width, height)); + } + + if (!Double.isFinite(width) || !Double.isFinite(height)) { + throw new IllegalArgumentException(String.format( + "Width (%s) or height (%s) is not finite", width, height)); + } + } + + @Override + public List<Image> getResolutionVariants() { + return Collections.unmodifiableList(Arrays.asList(resolutionVariants)); + } + + @Override + protected Image getBaseImage() { + return resolutionVariants[baseImageIndex]; + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java.desktop/share/classes/java/awt/image/MultiResolutionImage.java Fri Sep 18 09:18:17 2015 -0700 @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2015, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ +package java.awt.image; + +import java.awt.Image; +import java.util.List; + +/** + * This interface is designed to be an optional additional API supported by + * some implementations of {@link java.awt.Image} to allow them to provide + * alternate images for various rendering resolutions. The various + * {@code Graphics.drawImage(...)} variant methods will consult the methods + * of this interface if it is implemented on the argument {@code Image} object + * in order to choose the best representation to use for each rendering operation. + * <p> + * The {@code MultiResolutionImage} interface should be implemented by any + * subclass of {@code java.awt.Image} whose instances are intended to provide + * image resolution variants according to the given image width and height. + * For convenience, toolkit images obtained from + * {@code Toolkit.getImage(String name)} and {@code Toolkit.getImage(URL url)} + * will implement this interface on platforms that support naming conventions + * for resolution variants of stored image media and the + * {@code AbstractMultiResolutionImage} and {@code BaseMultiResolutionImage} + * classes are provided to facilitate easy construction of custom multi-resolution + * images from a list of related images. + * + * @see java.awt.Image + * @see java.awt.image.AbstractMultiResolutionImage + * @see java.awt.image.BaseMultiResolutionImage + * @see java.awt.Toolkit#getImage(java.lang.String filename) + * @see java.awt.Toolkit#getImage(java.net.URL url) + * + * @since 1.9 + */ +public interface MultiResolutionImage { + + /** + * Gets a specific image that is the best variant to represent + * this logical image at the indicated size. + * + * @param destImageWidth the width of the destination image, in pixels. + * @param destImageHeight the height of the destination image, in pixels. + * @return image resolution variant. + * @throws IllegalArgumentException if {@code destImageWidth} or + * {@code destImageHeight} is less than or equal to zero, infinity, + * or NaN. + * + * @since 1.9 + */ + Image getResolutionVariant(double destImageWidth, double destImageHeight); + + /** + * Gets a readable list of all resolution variants. + * The list must be nonempty and contain at least one resolution variant. + * <p> + * Note that many implementations might return an unmodifiable list. + * <p> + * @return list of resolution variants. + * @since 1.9 + */ + public List<Image> getResolutionVariants(); +} \ No newline at end of file
--- a/src/java.desktop/share/classes/java/beans/XMLEncoder.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/share/classes/java/beans/XMLEncoder.java Fri Sep 18 09:18:17 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015, 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 @@ -614,10 +614,12 @@ } if (isArgument && target instanceof Field && methodName.equals("get")) { - Field f = (Field)target; - writeln("<object class=" + quote(f.getDeclaringClass().getName()) + - " field=" + quote(f.getName()) + "/>"); - return; + Field f = (Field) target; + if (Modifier.isStatic(f.getModifiers())) { + writeln("<object class=" + quote(f.getDeclaringClass().getName()) + + " field=" + quote(f.getName()) + "/>"); + return; + } } Class<?> primitiveType = primitiveTypeFor(value.getClass());
--- a/src/java.desktop/share/classes/javax/sound/sampled/AudioSystem.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/share/classes/javax/sound/sampled/AudioSystem.java Fri Sep 18 09:18:17 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, 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 @@ -912,9 +912,9 @@ * must point to valid audio file data. The implementation of this method * may require multiple parsers to examine the stream to determine whether * they support it. These parsers must be able to mark the stream, read - * enough data to determine whether they support the stream, and, if not, - * reset the stream's read pointer to its original position. If the input - * stream does not support these operations, this method may fail with an + * enough data to determine whether they support the stream, and reset the + * stream's read pointer to its original position. If the input stream does + * not support these operations, this method may fail with an * {@code IOException}. * * @param stream the input stream from which file format information should @@ -1025,9 +1025,9 @@ * must point to valid audio file data. The implementation of this method * may require multiple parsers to examine the stream to determine whether * they support it. These parsers must be able to mark the stream, read - * enough data to determine whether they support the stream, and, if not, - * reset the stream's read pointer to its original position. If the input - * stream does not support these operation, this method may fail with an + * enough data to determine whether they support the stream, and reset the + * stream's read pointer to its original position. If the input stream does + * not support these operation, this method may fail with an * {@code IOException}. * * @param stream the input stream from which the {@code AudioInputStream}
--- a/src/java.desktop/share/classes/javax/sound/sampled/spi/AudioFileReader.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/share/classes/javax/sound/sampled/spi/AudioFileReader.java Fri Sep 18 09:18:17 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, 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 @@ -49,9 +49,9 @@ * must point to valid audio file data. In general, audio file readers may * need to read some data from the stream before determining whether they * support it. These parsers must be able to mark the stream, read enough - * data to determine whether they support the stream, and, if not, reset the - * stream's read pointer to its original position. If the input stream does - * not support this, this method may fail with an {@code IOException}. + * data to determine whether they support the stream, and reset the stream's + * read pointer to its original position. If the input stream does not + * support this, this method may fail with an {@code IOException}. * * @param stream the input stream from which file format information should * be extracted @@ -101,9 +101,9 @@ * must point to valid audio file data. In general, audio file readers may * need to read some data from the stream before determining whether they * support it. These parsers must be able to mark the stream, read enough - * data to determine whether they support the stream, and, if not, reset the - * stream's read pointer to its original position. If the input stream does - * not support this, this method may fail with an {@code IOException}. + * data to determine whether they support the stream, and reset the stream's + * read pointer to its original position. If the input stream does not + * support this, this method may fail with an {@code IOException}. * * @param stream the input stream from which the {@code AudioInputStream} * should be constructed
--- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java Fri Sep 18 09:18:17 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -403,6 +403,7 @@ protected void uninstallListeners() { header.removeMouseListener(mouseInputListener); header.removeMouseMotionListener(mouseInputListener); + header.removeFocusListener(focusListener); mouseInputListener = null; }
--- a/src/java.desktop/share/classes/javax/swing/text/DefaultCaret.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/share/classes/javax/swing/text/DefaultCaret.java Fri Sep 18 09:18:17 2015 -0700 @@ -860,6 +860,7 @@ Highlighter.HighlightPainter p = getSelectionPainter(); try { selectionTag = h.addHighlight(p0, p1, p); + updateOwnsSelection(); } catch (BadLocationException bl) { selectionTag = null; } @@ -870,6 +871,7 @@ Highlighter h = component.getHighlighter(); h.removeHighlight(selectionTag); selectionTag = null; + updateOwnsSelection(); } } } @@ -1110,6 +1112,7 @@ if (selectionTag != null) { h.removeHighlight(selectionTag); selectionTag = null; + updateOwnsSelection(); } // otherwise, change or add the highlight } else { @@ -1120,6 +1123,7 @@ Highlighter.HighlightPainter p = getSelectionPainter(); selectionTag = h.addHighlight(p0, p1, p); } + updateOwnsSelection(); } catch (BadLocationException e) { throw new StateInvariantError("Bad caret position"); } @@ -1170,6 +1174,7 @@ if (this.dot != dot || this.dotBias != dotBias || selectionTag != null || forceCaretPositionChange) { changeCaretPosition(dot, dotBias); + updateOwnsSelection(); } this.markBias = this.dotBias; this.markLTR = dotLTR; @@ -1177,6 +1182,7 @@ if ((h != null) && (selectionTag != null)) { h.removeHighlight(selectionTag); selectionTag = null; + updateOwnsSelection(); } } @@ -1925,6 +1931,13 @@ } } + /** + * Updates ownsSelection based on text selection in the caret. + */ + private void updateOwnsSelection() { + ownsSelection = (selectionTag != null) + && SwingUtilities2.canAccessSystemClipboard(); + } private class DefaultFilterBypass extends NavigationFilter.FilterBypass { public Caret getCaret() {
--- a/src/java.desktop/share/classes/sun/awt/SunHints.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/share/classes/sun/awt/SunHints.java Fri Sep 18 09:18:17 2015 -0700 @@ -257,8 +257,10 @@ */ @Native public static final int INTKEY_RESOLUTION_VARIANT = 9; @Native public static final int INTVAL_RESOLUTION_VARIANT_DEFAULT = 0; - @Native public static final int INTVAL_RESOLUTION_VARIANT_OFF = 1; - @Native public static final int INTVAL_RESOLUTION_VARIANT_ON = 2; + @Native public static final int INTVAL_RESOLUTION_VARIANT_BASE = 1; + @Native public static final int INTVAL_RESOLUTION_VARIANT_SIZE_FIT = 2; + @Native public static final int INTVAL_RESOLUTION_VARIANT_DPI_FIT = 3; + /** * LCD text contrast control hint key. * Value is "100" to make discontiguous with the others which @@ -466,15 +468,23 @@ public static final Object VALUE_RESOLUTION_VARIANT_DEFAULT = new SunHints.Value(KEY_RESOLUTION_VARIANT, SunHints.INTVAL_RESOLUTION_VARIANT_DEFAULT, - "Choose image resolutions based on a default heuristic"); - public static final Object VALUE_RESOLUTION_VARIANT_OFF = + "Choose image resolutions based on a default" + + "heuristic"); + public static final Object VALUE_RESOLUTION_VARIANT_BASE = new SunHints.Value(KEY_RESOLUTION_VARIANT, - SunHints.INTVAL_RESOLUTION_VARIANT_OFF, + SunHints.INTVAL_RESOLUTION_VARIANT_BASE, "Use only the standard resolution of an image"); - public static final Object VALUE_RESOLUTION_VARIANT_ON = + public static final Object VALUE_RESOLUTION_VARIANT_SIZE_FIT = new SunHints.Value(KEY_RESOLUTION_VARIANT, - SunHints.INTVAL_RESOLUTION_VARIANT_ON, - "Always use resolution-specific variants of images"); + SunHints.INTVAL_RESOLUTION_VARIANT_SIZE_FIT, + "Choose image resolutions based on the DPI" + + "of the screen and transform" + + "in the Graphics2D context"); + public static final Object VALUE_RESOLUTION_VARIANT_DPI_FIT = + new SunHints.Value(KEY_RESOLUTION_VARIANT, + SunHints.INTVAL_RESOLUTION_VARIANT_DPI_FIT, + "Choose image resolutions based only on the DPI" + + " of the screen"); public static class LCDContrastKey extends Key {
--- a/src/java.desktop/share/classes/sun/awt/SunToolkit.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/share/classes/sun/awt/SunToolkit.java Fri Sep 18 09:18:17 2015 -0700 @@ -60,7 +60,7 @@ import sun.awt.image.ByteArrayImageSource; import sun.awt.image.FileImageSource; import sun.awt.image.ImageRepresentation; -import sun.awt.image.MultiResolutionImage; +import java.awt.image.MultiResolutionImage; import sun.awt.image.MultiResolutionToolkitImage; import sun.awt.image.ToolkitImage; import sun.awt.image.URLImageSource;
--- a/src/java.desktop/share/classes/sun/awt/image/AbstractMultiResolutionImage.java Thu Sep 17 22:46:04 2015 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2014, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package sun.awt.image; - -import java.awt.Graphics; -import java.awt.Image; -import java.awt.image.*; - -/** - * This class provides default implementations for the - * <code>MultiResolutionImage</code> interface. The developer needs only - * to subclass this abstract class and define the <code>getResolutionVariant</code>, - * <code>getResolutionVariants</code>, and <code>getBaseImage</code> methods. - * - * - * For example, - * {@code - * public class CustomMultiResolutionImage extends AbstractMultiResolutionImage { - * - * int baseImageIndex; - * Image[] resolutionVariants; - * - * public CustomMultiResolutionImage(int baseImageIndex, - * Image... resolutionVariants) { - * this.baseImageIndex = baseImageIndex; - * this.resolutionVariants = resolutionVariants; - * } - * - * @Override - * public Image getResolutionVariant(float logicalDPIX, float logicalDPIY, - * float baseImageWidth, float baseImageHeight, - * float destImageWidth, float destImageHeight) { - * // return a resolution variant based on the given logical DPI, - * // base image size, or destination image size - * } - * - * @Override - * public List<Image> getResolutionVariants() { - * return Arrays.asList(resolutionVariants); - * } - * - * protected Image getBaseImage() { - * return resolutionVariants[baseImageIndex]; - * } - * } - * } - * - * @see java.awt.Image - * @see java.awt.image.MultiResolutionImage - * - * @since 1.9 - */ -public abstract class AbstractMultiResolutionImage extends java.awt.Image - implements MultiResolutionImage { - - /** - * @inheritDoc - */ - @Override - public int getWidth(ImageObserver observer) { - return getBaseImage().getWidth(null); - } - - /** - * @inheritDoc - */ - @Override - public int getHeight(ImageObserver observer) { - return getBaseImage().getHeight(null); - } - - /** - * @inheritDoc - */ - @Override - public ImageProducer getSource() { - return getBaseImage().getSource(); - } - - /** - * @inheritDoc - */ - @Override - public Graphics getGraphics() { - return getBaseImage().getGraphics(); - - } - - /** - * @inheritDoc - */ - @Override - public Object getProperty(String name, ImageObserver observer) { - return getBaseImage().getProperty(name, observer); - } - - /** - * @return base image - */ - protected abstract Image getBaseImage(); -}
--- a/src/java.desktop/share/classes/sun/awt/image/MultiResolutionCachedImage.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/share/classes/sun/awt/image/MultiResolutionCachedImage.java Fri Sep 18 09:18:17 2015 -0700 @@ -33,6 +33,7 @@ import java.util.function.Function; import java.util.function.BiFunction; import java.util.stream.Collectors; +import java.awt.image.AbstractMultiResolutionImage; public class MultiResolutionCachedImage extends AbstractMultiResolutionImage { @@ -58,7 +59,10 @@ } @Override - public Image getResolutionVariant(int width, int height) { + public Image getResolutionVariant(double destWidth, double destHeight) { + checkSize(destWidth, destHeight); + int width = (int) Math.ceil(destWidth); + int height = (int) Math.ceil(destHeight); ImageCache cache = ImageCache.getInstance(); ImageCacheKey key = new ImageCacheKey(this, width, height); Image resolutionVariant = cache.getImage(key); @@ -70,11 +74,23 @@ return resolutionVariant; } + private static void checkSize(double width, double height) { + if (width <= 0 || height <= 0) { + throw new IllegalArgumentException(String.format( + "Width (%s) or height (%s) cannot be <= 0", width, height)); + } + + if (!Double.isFinite(width) || !Double.isFinite(height)) { + throw new IllegalArgumentException(String.format( + "Width (%s) or height (%s) is not finite", width, height)); + } + } + @Override public List<Image> getResolutionVariants() { return Arrays.stream(sizes).map((Function<Dimension2D, Image>) size - -> getResolutionVariant((int) size.getWidth(), - (int) size.getHeight())).collect(Collectors.toList()); + -> getResolutionVariant(size.getWidth(), size.getHeight())) + .collect(Collectors.toList()); } public MultiResolutionCachedImage map(Function<Image, Image> mapper) {
--- a/src/java.desktop/share/classes/sun/awt/image/MultiResolutionImage.java Thu Sep 17 22:46:04 2015 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2013, 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. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * 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. - */ -package sun.awt.image; - -import java.awt.Image; -import java.util.List; - -/** - * This interface is designed to provide a set of images at various resolutions. - * - * The <code>MultiResolutionImage</code> interface should be implemented by any - * class whose instances are intended to provide image resolution variants - * according to the given image width and height. - * - * For example, - * <pre> - * {@code - * public class ScaledImage extends BufferedImage - * implements MultiResolutionImage { - * - * @Override - * public Image getResolutionVariant(int width, int height) { - * return ((width <= getWidth() && height <= getHeight())) - * ? this : highResolutionImage; - * } - * - * @Override - * public List<Image> getResolutionVariants() { - * return Arrays.asList(this, highResolutionImage); - * } - * } - * }</pre> - * - * It is recommended to cache image variants for performance reasons. - * - * <b>WARNING</b>: This class is an implementation detail. This API may change - * between update release, and it may even be removed or be moved in some other - * package(s)/class(es). - */ -public interface MultiResolutionImage { - - /** - * Provides an image with necessary resolution which best fits to the given - * image width and height. - * - * @param width the desired image resolution width. - * @param height the desired image resolution height. - * @return image resolution variant. - * - * @since 1.8 - */ - public Image getResolutionVariant(int width, int height); - - /** - * Gets list of all resolution variants including the base image - * - * @return list of resolution variants. - * @since 1.8 - */ - public List<Image> getResolutionVariants(); -}
--- a/src/java.desktop/share/classes/sun/awt/image/MultiResolutionToolkitImage.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/share/classes/sun/awt/image/MultiResolutionToolkitImage.java Fri Sep 18 09:18:17 2015 -0700 @@ -26,6 +26,7 @@ import java.awt.Image; import java.awt.image.ImageObserver; +import java.awt.image.MultiResolutionImage; import java.util.Arrays; import java.util.List; import sun.misc.SoftCache; @@ -40,11 +41,24 @@ } @Override - public Image getResolutionVariant(int width, int height) { - return ((width <= getWidth() && height <= getHeight())) + public Image getResolutionVariant(double destWidth, double destHeight) { + checkSize(destWidth, destHeight); + return ((destWidth <= getWidth() && destHeight <= getHeight())) ? this : resolutionVariant; } + private static void checkSize(double width, double height) { + if (width <= 0 || height <= 0) { + throw new IllegalArgumentException(String.format( + "Width (%s) or height (%s) cannot be <= 0", width, height)); + } + + if (!Double.isFinite(width) || !Double.isFinite(height)) { + throw new IllegalArgumentException(String.format( + "Width (%s) or height (%s) is not finite", width, height)); + } + } + public Image getResolutionVariant() { return resolutionVariant; }
--- a/src/java.desktop/share/classes/sun/java2d/SunGraphics2D.java Thu Sep 17 22:46:04 2015 -0400 +++ b/src/java.desktop/share/classes/sun/java2d/SunGraphics2D.java Fri Sep 18 09:18:17 2015 -0700 @@ -94,7 +94,7 @@ import sun.misc.PerformanceLogger; import java.lang.annotation.Native; -import sun.awt.image.MultiResolutionImage; +import java.awt.image.MultiResolutionImage; import static java.awt.geom.AffineTransform.TYPE_FLIP; import static java.awt.geom.AffineTransform.TYPE_MASK_SCALE; @@ -3087,9 +3087,8 @@ // end of text rendering methods private boolean isHiDPIImage(final Image img) { - return (SurfaceManager.getImageScale(img) != 1) || - (resolutionVariantHint != SunHints.INTVAL_RESOLUTION_VARIANT_OFF - && img instanceof MultiResolutionImage); + return (SurfaceManager.getImageScale(img) != 1) + || img instanceof MultiResolutionImage; } private boolean drawHiDPIImage(Image img, int dx1, int dy1, int dx2, @@ -3175,25 +3174,42 @@ int type = transform.getType(); int dw = dx2 - dx1; int dh = dy2 - dy1; - double destRegionWidth; - double destRegionHeight; - - if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP)) == 0) { - destRegionWidth = dw; - destRegionHeight = dh; - } else if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP | TYPE_MASK_SCALE)) == 0) { - destRegionWidth = dw * transform.getScaleX(); - destRegionHeight = dh * transform.getScaleY(); + + double destImageWidth; + double destImageHeight; + + if (resolutionVariantHint == SunHints.INTVAL_RESOLUTION_VARIANT_BASE) { + destImageWidth = srcWidth; + destImageHeight = srcHeight; + } else if (resolutionVariantHint == SunHints.INTVAL_RESOLUTION_VARIANT_DPI_FIT) { + AffineTransform configTransform = getDefaultTransform(); + if (configTransform.isIdentity()) { + destImageWidth = srcWidth; + destImageHeight = srcHeight; + } else { + destImageWidth = srcWidth * configTransform.getScaleX(); + destImageHeight = srcHeight * configTransform.getScaleY(); + } } else { - destRegionWidth = dw * Math.hypot( - transform.getScaleX(), transform.getShearY()); - destRegionHeight = dh * Math.hypot( - transform.getShearX(), transform.getScaleY()); + double destRegionWidth; + double destRegionHeight; + + if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP)) == 0) { + destRegionWidth = dw; + destRegionHeight = dh; + } else if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP | TYPE_MASK_SCALE)) == 0) { + destRegionWidth = dw * transform.getScaleX(); + destRegionHeight = dh * transform.getScaleY(); + } else { + destRegionWidth = dw * Math.hypot( + transform.getScaleX(), transform.getShearY()); + destRegionHeight = dh * Math.hypot( + transform.getShearX(), transform.getScaleY()); + } + destImageWidth = Math.abs(srcWidth * destRegionWidth / sw); + destImageHeight = Math.abs(srcHeight * destRegionHeight / sh); } - int destImageWidth = (int) Math.abs(srcWidth * destRegionWidth / sw); - int destImageHeight = (int) Math.abs(srcHeight * destRegionHeight / sh); - Image resolutionVariant = img.getResolutionVariant(destImageWidth, destImageHeight);
--- a/test/java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java Thu Sep 17 22:46:04 2015 -0400 +++ b/test/java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java Fri Sep 18 09:18:17 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2015 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 @@ -23,7 +23,7 @@ /* @test - @bug 6566434 + @bug 6566434 8039467 @library ../../regtesthelpers @build Util Sysout AbstractTest @summary Choice in unfocusable window responds to keyboard @@ -63,6 +63,18 @@ w.setLayout(new FlowLayout()); w.setSize(200, 200); + // Note that Window w is non focusable. Key press events will not be + // consumed by w, but by any previously focused window & this can + // disturb the environment. So creating tempFrameToHoldFocus frame, + // to consume key press events. + Frame tempFrameToHoldFocus = new Frame(); + tempFrameToHoldFocus.setVisible(true); + Util.waitForIdle(robot); + + tempFrameToHoldFocus.requestFocus(); + Util.clickOnComp(tempFrameToHoldFocus, robot); + Util.waitForIdle(robot); + ch.addKeyListener(new KeyAdapter(){ public void keyTyped(KeyEvent e){ traceEvent("keytyped", e); @@ -94,6 +106,10 @@ testKeys(); Util.waitForIdle(robot); + + tempFrameToHoldFocus.dispose(); + w.dispose(); + f.dispose(); } private static void testKeys(){
--- a/test/java/awt/Cursor/MultiResolutionCursorTest/MultiResolutionCursorTest.java Thu Sep 17 22:46:04 2015 -0400 +++ b/test/java/awt/Cursor/MultiResolutionCursorTest/MultiResolutionCursorTest.java Fri Sep 18 09:18:17 2015 -0700 @@ -25,19 +25,16 @@ import java.awt.Cursor; import java.awt.Dialog; import java.awt.Frame; -import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Label; import java.awt.Point; import java.awt.TextArea; import java.awt.Toolkit; +import java.awt.image.BaseMultiResolutionImage; import java.awt.image.BufferedImage; -import java.util.LinkedList; -import java.util.List; import javax.swing.JApplet; import jdk.testlibrary.OSInfo; -import sun.awt.image.MultiResolutionImage; /** * @test @@ -52,7 +49,7 @@ public class MultiResolutionCursorTest extends JApplet { //Declare things used in the test, like buttons and labels here - static final int sizes[] = {16, 32, 128}; + static final int sizes[] = {8, 16, 32, 128}; static final Color colors[] = {Color.WHITE, Color.RED, Color.GREEN, Color.BLUE}; public void init() { @@ -87,7 +84,12 @@ setVisible(true); validate(); - final Image image = new MultiResolutionCursor(); + final Image image = new BaseMultiResolutionImage( + createResolutionVariant(0), + createResolutionVariant(1), + createResolutionVariant(2), + createResolutionVariant(3) + ); int center = sizes[0] / 2; Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor( @@ -101,53 +103,14 @@ frame.setVisible(true); }// start() - - static class MultiResolutionCursor extends BufferedImage implements MultiResolutionImage { - - List<Image> highResolutionImages; - - public MultiResolutionCursor() { - super(sizes[0], sizes[0], BufferedImage.TYPE_INT_RGB); - - draw(getGraphics(), 0); - highResolutionImages = new LinkedList<>(); - highResolutionImages.add(this); - - for (int i = 1; i < sizes.length; i++) { - BufferedImage highResolutionImage = - new BufferedImage(sizes[i], sizes[i], BufferedImage.TYPE_INT_RGB); - draw(highResolutionImage.getGraphics(), i); - highResolutionImages.add(highResolutionImage); - } - } - - @Override - public Image getResolutionVariant(int width, int height) { - - for (int i = 0; i < sizes.length; i++) { - Image image = highResolutionImages.get(i); - int w = image.getWidth(null); - int h = image.getHeight(null); - - if (width <= w && height <= h) { - return image; - } - } - - return highResolutionImages.get(highResolutionImages.size() - 1); - } - - void draw(Graphics graphics, int index) { - Graphics2D g2 = (Graphics2D) graphics; - Color color = colors[index]; - g2.setColor(color); - g2.fillRect(0, 0, sizes[index], sizes[index]); - } - - @Override - public List<Image> getResolutionVariants() { - return highResolutionImages; - } + static BufferedImage createResolutionVariant(int i) { + BufferedImage resolutionVariant = new BufferedImage(sizes[i], sizes[i], + BufferedImage.TYPE_INT_RGB); + Graphics2D g2 = resolutionVariant.createGraphics(); + g2.setColor(colors[i]); + g2.fillRect(0, 0, sizes[i], sizes[i]); + g2.dispose(); + return resolutionVariant; } }// class BlockedWindowTest
--- a/test/java/awt/Focus/RequestOnCompWithNullParent/RequestOnCompWithNullParent1.java Thu Sep 17 22:46:04 2015 -0400 +++ b/test/java/awt/Focus/RequestOnCompWithNullParent/RequestOnCompWithNullParent1.java Fri Sep 18 09:18:17 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2015, 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 @@ -24,19 +24,14 @@ /* @test @bug 6418028 - @summary java/awt/Focus/RequestOnCompWithNullParent/RequestOnCompWithNullParent_Barrier.java fails @author oleg.sukhodolsky: area=awt.focus @library ../../regtesthelpers + @modules java.desktop/java.awt.peer + java.desktop/sun.awt @build Util @run main RequestOnCompWithNullParent1 */ -/** - * RequestOnCompWithNullParent1.java - * - * summary: java/awt/Focus/RequestOnCompWithNullParent/RequestOnCompWithNullParent_Barrier.java fails - */ - import java.awt.*; import java.awt.event.*; import java.awt.peer.ButtonPeer; @@ -46,26 +41,21 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; -import test.java.awt.regtesthelpers.Util; -//*** global search and replace RequestOnCompWithNullParent1 with name of the test *** +import sun.awt.AWTAccessor; -public class RequestOnCompWithNullParent1 -{ +public class RequestOnCompWithNullParent1 { - private static void init() { - //*** Create instructions for the user here *** - String[] instructions = - { - "This is an AUTOMATIC test, simply wait until it is done.", - "The result (passed or failed) will be shown in the", - "message window below." - }; - Sysout.createDialog( ); - Sysout.printInstructions( instructions ); + public static void main(final String[] args) throws Exception { + Frame frame = new Frame("test for 6418028"); + try { + test(frame); + } finally { + frame.dispose(); + } + } - - Frame frame = new Frame("test for 6418028"); + private static void test(final Frame frame) throws Exception { frame.setLayout(new FlowLayout()); Button btn1 = new Button("Button1"); frame.add(btn1); @@ -80,153 +70,26 @@ }); frame.setVisible(true); - Util.waitForIdle(null); + new Robot().waitForIdle(); btn2.instrumentPeer(); btn2.requestFocusInWindow(); btn2.restorePeer(); - frame.dispose(); - RequestOnCompWithNullParent1.pass(); - }//End init() - - - - /***************************************************** - * Standard Test Machinery Section - * DO NOT modify anything in this section -- it's a - * standard chunk of code which has all of the - * synchronisation necessary for the test harness. - * By keeping it the same in all tests, it is easier - * to read and understand someone else's test, as - * well as insuring that all tests behave correctly - * with the test harness. - * There is a section following this for test- - * classes - ******************************************************/ - private static boolean theTestPassed = false; - private static boolean testGeneratedInterrupt = false; - private static String failureMessage = ""; - - private static Thread mainThread = null; - - private static int sleepTime = 300000; - - // Not sure about what happens if multiple of this test are - // instantiated in the same VM. Being static (and using - // static vars), it aint gonna work. Not worrying about - // it for now. - public static void main( String args[] ) throws InterruptedException - { - mainThread = Thread.currentThread(); - try - { - init(); - } - catch( TestPassedException e ) - { - //The test passed, so just return from main and harness will - // interepret this return as a pass - return; - } - //At this point, neither test pass nor test fail has been - // called -- either would have thrown an exception and ended the - // test, so we know we have multiple threads. - - //Test involves other threads, so sleep and wait for them to - // called pass() or fail() - try - { - Thread.sleep( sleepTime ); - //Timed out, so fail the test - throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" ); - } - catch (InterruptedException e) - { - //The test harness may have interrupted the test. If so, rethrow the exception - // so that the harness gets it and deals with it. - if( ! testGeneratedInterrupt ) throw e; - - //reset flag in case hit this code more than once for some reason (just safety) - testGeneratedInterrupt = false; - - if ( theTestPassed == false ) - { - throw new RuntimeException( failureMessage ); - } - } - - }//main - - public static synchronized void setTimeoutTo( int seconds ) - { - sleepTime = seconds * 1000; } - - public static synchronized void pass() - { - Sysout.println( "The test passed." ); - Sysout.println( "The test is over, hit Ctl-C to stop Java VM" ); - //first check if this is executing in main thread - if ( mainThread == Thread.currentThread() ) - { - //Still in the main thread, so set the flag just for kicks, - // and throw a test passed exception which will be caught - // and end the test. - theTestPassed = true; - throw new TestPassedException(); - } - theTestPassed = true; - testGeneratedInterrupt = true; - mainThread.interrupt(); - }//pass() - - public static synchronized void fail() - { - //test writer didn't specify why test failed, so give generic - fail( "it just plain failed! :-)" ); - } - - public static synchronized void fail( String whyFailed ) - { - Sysout.println( "The test failed: " + whyFailed ); - Sysout.println( "The test is over, hit Ctl-C to stop Java VM" ); - //check if this called from main thread - if ( mainThread == Thread.currentThread() ) - { - //If main thread, fail now 'cause not sleeping - throw new RuntimeException( whyFailed ); - } - theTestPassed = false; - testGeneratedInterrupt = true; - failureMessage = whyFailed; - mainThread.interrupt(); - }//fail() - -}// class RequestOnCompWithNullParent1 - -//This exception is used to exit from any level of call nesting -// when it's determined that the test has passed, and immediately -// end the test. -class TestPassedException extends RuntimeException -{ } -//*********** End Standard Test Machinery Section ********** - - -//************ Begin classes defined for the test **************** - class TestButton extends Button { ButtonPeer origPeer; ButtonPeer proxiedPeer; /** Creates a new instance of TestButton */ - public TestButton(String text) { + TestButton(String text) { super(text); } public void instrumentPeer() { - origPeer = (ButtonPeer) getPeer(); + origPeer = AWTAccessor.getComponentAccessor().getPeer(this); + InvocationHandler handler = new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) { if (method.getName().equals("requestFocus")) { @@ -248,7 +111,9 @@ } }; - proxiedPeer = (ButtonPeer) Proxy.newProxyInstance(ButtonPeer.class.getClassLoader(), new Class[] {ButtonPeer.class}, handler); + proxiedPeer = (ButtonPeer) Proxy.newProxyInstance( + ButtonPeer.class.getClassLoader(), + new Class[] {ButtonPeer.class}, handler); setPeer(proxiedPeer); } @@ -275,145 +140,3 @@ } } } -//************** End classes defined for the test ******************* - - - - -/**************************************************** - Standard Test Machinery - DO NOT modify anything below -- it's a standard - chunk of code whose purpose is to make user - interaction uniform, and thereby make it simpler - to read and understand someone else's test. - ****************************************************/ - -/** - This is part of the standard test machinery. - It creates a dialog (with the instructions), and is the interface - for sending text messages to the user. - To print the instructions, send an array of strings to Sysout.createDialog - WithInstructions method. Put one line of instructions per array entry. - To display a message for the tester to see, simply call Sysout.println - with the string to be displayed. - This mimics System.out.println but works within the test harness as well - as standalone. - */ - -class Sysout -{ - private static TestDialog dialog; - - public static void createDialogWithInstructions( String[] instructions ) - { - dialog = new TestDialog( new Frame(), "Instructions" ); - dialog.printInstructions( instructions ); - dialog.setVisible(true); - println( "Any messages for the tester will display here." ); - } - - public static void createDialog( ) - { - dialog = new TestDialog( new Frame(), "Instructions" ); - String[] defInstr = { "Instructions will appear here. ", "" } ; - dialog.printInstructions( defInstr ); - dialog.setVisible(true); - println( "Any messages for the tester will display here." ); - } - - - public static void printInstructions( String[] instructions ) - { - dialog.printInstructions( instructions ); - } - - - public static void println( String messageIn ) - { - dialog.displayMessage( messageIn ); - System.out.println(messageIn); - } - -}// Sysout class - -/** - This is part of the standard test machinery. It provides a place for the - test instructions to be displayed, and a place for interactive messages - to the user to be displayed. - To have the test instructions displayed, see Sysout. - To have a message to the user be displayed, see Sysout. - Do not call anything in this dialog directly. - */ -class TestDialog extends Dialog -{ - - TextArea instructionsText; - TextArea messageText; - int maxStringLength = 80; - - //DO NOT call this directly, go through Sysout - public TestDialog( Frame frame, String name ) - { - super( frame, name ); - int scrollBoth = TextArea.SCROLLBARS_BOTH; - instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth ); - add( "North", instructionsText ); - - messageText = new TextArea( "", 5, maxStringLength, scrollBoth ); - add("Center", messageText); - - pack(); - - setVisible(true); - }// TestDialog() - - //DO NOT call this directly, go through Sysout - public void printInstructions( String[] instructions ) - { - //Clear out any current instructions - instructionsText.setText( "" ); - - //Go down array of instruction strings - - String printStr, remainingStr; - for( int i=0; i < instructions.length; i++ ) - { - //chop up each into pieces maxSringLength long - remainingStr = instructions[ i ]; - while( remainingStr.length() > 0 ) - { - //if longer than max then chop off first max chars to print - if( remainingStr.length() >= maxStringLength ) - { - //Try to chop on a word boundary - int posOfSpace = remainingStr. - lastIndexOf( ' ', maxStringLength - 1 ); - - if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1; - - printStr = remainingStr.substring( 0, posOfSpace + 1 ); - remainingStr = remainingStr.substring( posOfSpace + 1 ); - } - //else just print - else - { - printStr = remainingStr; - remainingStr = ""; - } - - instructionsText.append( printStr + "\n" ); - - }// while - - }// for - - }//printInstructions() - - //DO NOT call this directly, go through Sysout - public void displayMessage( String messageIn ) - { - messageText.append( messageIn + "\n" ); - System.out.println(messageIn); - } - -}// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/Modal/InvisibleParentTest/InvisibleParentTest.html Fri Sep 18 09:18:17 2015 -0700 @@ -0,0 +1,45 @@ +<!-- + Copyright (c) 2013, 2015, 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. +--> + +<html> +<!-- + @test + @bug 6401700 6412803 + @requires (os.family != "windows") + @summary Tests that modal dialog is shown on the screen and +iconified/restored correctly if its parent window is invisible + @author artem.ananiev: area=awt.modal + @run applet/manual=yesno InvisibleParentTest.html + --> +<head> +<title> InvisibleParentTest </title> +</head> +<body> + +<h1>InvisibleParentTest<br>Bug ID: 6401700, 6412803</h1> + +<p> See the dialog box (usually in upper left corner) for instructions</p> + +<APPLET CODE="InvisibleParentTest.class" WIDTH=200 HEIGHT=200></APPLET> +</body> +</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/Modal/InvisibleParentTest/InvisibleParentTest.java Fri Sep 18 09:18:17 2015 -0700 @@ -0,0 +1,235 @@ +/* + * Copyright (c) 2013, 2015, 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 6401700 6412803 + @summary Tests that modal dialog is shown on the screen and +iconified/restored correctly if some of its blocked windows are invisible + @author artem.ananiev: area=awt.modal + @run applet/manual=yesno InvisibleParentTest.html +*/ + +import java.applet.Applet; +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.Component; +import java.awt.Dialog; +import java.awt.Frame; +import java.awt.TextArea; +import java.awt.Window; + +public class InvisibleParentTest extends Applet +{ + public void init() + { + setLayout(new BorderLayout()); + + String[] instructions = + { + "If your system is Windows, press PASS button.", + "When the test starts two windows should appear: frame G1 and", + " dialog D1. Another one frame F1 should be minimized.", + " If the dialog is not shown (minimizied), press FAIL button.", + "Then minimize frame G1 and restore F1. If the dialog D1 is not", + " restored together with F1, press FAIL, else PASS" + }; + Sysout.createDialogWithInstructions( instructions ); + } + + public void start () + { + Button b; + + setSize (200,200); + setVisible(true); + validate(); + + Component c = this; + while ((c != null) && !(c instanceof Window)) + { + c = c.getParent(); + } + if (c != null) + { + ((Window)c).setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE); + } + + Frame f1 = new Frame("F1"); + f1.setBounds(100, 300, 100, 100); + f1.setVisible(true); + f1.setExtendedState(Frame.ICONIFIED); + + Frame g1 = new Frame("G1"); + g1.setBounds(150, 350, 100, 100); + g1.setVisible(true); + + final Dialog d1 = new Dialog((Frame)null, "D1", Dialog.ModalityType.APPLICATION_MODAL); + d1.setBounds(200, 400, 100, 100); + new Thread(new Runnable() + { + public void run() + { + d1.setVisible(true); + } + }).start(); + } +} + +/**************************************************** + Standard Test Machinery + DO NOT modify anything below -- it's a standard + chunk of code whose purpose is to make user + interaction uniform, and thereby make it simpler + to read and understand someone else's test. + ****************************************************/ + +/** + This is part of the standard test machinery. + It creates a dialog (with the instructions), and is the interface + for sending text messages to the user. + To print the instructions, send an array of strings to Sysout.createDialog + WithInstructions method. Put one line of instructions per array entry. + To display a message for the tester to see, simply call Sysout.println + with the string to be displayed. + This mimics System.out.println but works within the test harness as well + as standalone. + */ + +class Sysout +{ + private static TestDialog dialog; + + public static void createDialogWithInstructions( String[] instructions ) + { + dialog = new TestDialog( new Frame(), "Instructions" ); + dialog.printInstructions( instructions ); + dialog.setVisible(true); + println( "Any messages for the tester will display here." ); + } + + public static void createDialog( ) + { + dialog = new TestDialog( new Frame(), "Instructions" ); + String[] defInstr = { "Instructions will appear here. ", "" } ; + dialog.printInstructions( defInstr ); + dialog.setVisible(true); + println( "Any messages for the tester will display here." ); + } + + + public static void printInstructions( String[] instructions ) + { + dialog.printInstructions( instructions ); + } + + + public static void println( String messageIn ) + { + dialog.displayMessage( messageIn ); + } + +}// Sysout class + +/** + This is part of the standard test machinery. It provides a place for the + test instructions to be displayed, and a place for interactive messages + to the user to be displayed. + To have the test instructions displayed, see Sysout. + To have a message to the user be displayed, see Sysout. + Do not call anything in this dialog directly. + */ +class TestDialog extends Dialog +{ + + TextArea instructionsText; + TextArea messageText; + int maxStringLength = 80; + + //DO NOT call this directly, go through Sysout + public TestDialog( Frame frame, String name ) + { + super( frame, name ); + setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE); + int scrollBoth = TextArea.SCROLLBARS_BOTH; + instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth ); + add( "North", instructionsText ); + + messageText = new TextArea( "", 5, maxStringLength, scrollBoth ); + add("Center", messageText); + + pack(); + + setVisible(true); + }// TestDialog() + + //DO NOT call this directly, go through Sysout + public void printInstructions( String[] instructions ) + { + //Clear out any current instructions + instructionsText.setText( "" ); + + //Go down array of instruction strings + + String printStr, remainingStr; + for( int i=0; i < instructions.length; i++ ) + { + //chop up each into pieces maxSringLength long + remainingStr = instructions[ i ]; + while( remainingStr.length() > 0 ) + { + //if longer than max then chop off first max chars to print + if( remainingStr.length() >= maxStringLength ) + { + //Try to chop on a word boundary + int posOfSpace = remainingStr. + lastIndexOf( ' ', maxStringLength - 1 ); + + if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1; + + printStr = remainingStr.substring( 0, posOfSpace + 1 ); + remainingStr = remainingStr.substring( posOfSpace + 1 ); + } + //else just print + else + { + printStr = remainingStr; + remainingStr = ""; + } + + instructionsText.append( printStr + "\n" ); + + }// while + + }// for + + }//printInstructions() + + //DO NOT call this directly, go through Sysout + public void displayMessage( String messageIn ) + { + messageText.append( messageIn + "\n" ); + System.out.println(messageIn); + } + +}// TestDialog class
--- a/test/java/awt/PrintJob/Text/StringWidth.java Thu Sep 17 22:46:04 2015 -0400 +++ b/test/java/awt/PrintJob/Text/StringWidth.java Fri Sep 18 09:18:17 2015 -0700 @@ -23,7 +23,6 @@ import java.awt.*; import java.util.Properties; -import sun.awt.*; public class StringWidth extends Frame {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/Toolkit/AutoShutdown/EventQueuePush/EventQueuePushAutoshutdown.java Fri Sep 18 09:18:17 2015 -0700 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2015, 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 8081485 + @summary tests that a program terminates automatically after EventQueue.push() + @author Anton Nashatyrev : area=toolkit +*/ + +import java.awt.*; + +public class EventQueuePushAutoshutdown implements Runnable { + private volatile int status = 2; + + public EventQueuePushAutoshutdown() throws Exception { + Runtime.getRuntime().addShutdownHook(new Thread(this)); + Thread thread = new Thread() { + @Override + public void run() { + status = 0; + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + status = 1; + System.exit(status); + } + } + }; + thread.setDaemon(true); + thread.start(); + + System.setProperty("java.awt.headless", "true"); + final EventQueue systemQueue = Toolkit.getDefaultToolkit().getSystemEventQueue(); + systemQueue.push(new EventQueue()); + EventQueue.invokeAndWait(new Runnable() { + @Override + public void run() { + System.out.println("Activated EDT"); + } + }); + System.out.println("After EDT activation"); + } + + public static void main(String[] args) throws Exception { + new EventQueuePushAutoshutdown(); + } + + @Override + public void run() { + Runtime.getRuntime().halt(status); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/Toolkit/AutoShutdown/EventQueuePush/EventQueuePushAutoshutdown.sh Fri Sep 18 09:18:17 2015 -0700 @@ -0,0 +1,159 @@ +#!/bin/ksh -p + +# +# Copyright (c) 20015, 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 EventQueuePushAutoshutdown.sh +# @bug 8081485 +# @summary tests that a program terminates automatically +# after EventQueue.push() +# @author Anton Nashatyrev : area=toolkit +# +# @compile EventQueuePushAutoshutdown.java +# @run shell EventQueuePushAutoshutdown.sh + + +# Beginning of subroutines: +status=1 + +#Call this from anywhere to fail the test with an error message +# usage: fail "reason why the test failed" +fail() + { echo "The test failed :-(" + echo "$*" 1>&2 + echo "exit status was $status" + exit $status + } #end of fail() + +#Call this from anywhere to pass the test with a message +# usage: pass "reason why the test passed if applicable" +pass() + { echo "The test passed!!!" + echo "$*" 1>&2 + exit 0 + } #end of pass() + +# end of subroutines + + +# The beginning of the script proper +OS=`uname -s` +case "$OS" in + SunOS | Linux | Darwin | CYGWIN* ) + FILESEP="/" + ;; + + Windows_95 | Windows_98 | Windows_NT | Windows_ME ) + FILESEP="\\" + ;; + + # catch all other OSs + * ) + echo "Unrecognized system! $OS" + fail "Unrecognized system! $OS" + ;; +esac + + +# Want this test to run standalone as well as in the harness, so do the +# following to copy the test's directory into the harness's scratch directory +# and set all appropriate variables: + +if [ -z "${TESTJAVA}" ] ; then + # TESTJAVA is not set, so the test is running stand-alone. + # TESTJAVA holds the path to the root directory of the build of the JDK + # to be tested. That is, any java files run explicitly in this shell + # should use TESTJAVA in the path to the java interpreter. + # So, we'll set this to the JDK spec'd on the command line. If none + # is given on the command line, tell the user that and use a cheesy + # default. + # THIS IS THE JDK BEING TESTED. + if [ -n "$1" ] ; + then TESTJAVA=$1 + else fail "no JDK specified on command line!" + fi + TESTSRC=. + TESTCLASSES=. + STANDALONE=1; +fi +echo "JDK under test is: $TESTJAVA" + +#Deal with .class files: +if [ -n "${STANDALONE}" ] ; + then + #if standalone, remind user to cd to dir. containing test before running it + echo "Just a reminder: cd to the dir containing this test when running it" + # then compile all .java files (if there are any) into .class files + if [ -a *.java ] ; + then echo "Reminder, this test should be in its own directory with all" + echo "supporting files it needs in the directory with it." + ${TESTJAVA}/bin/javac ./*.java ; + fi + # else in harness so copy all the class files from where jtreg put them + # over to the scratch directory this test is running in. + else cp ${TESTCLASSES}/*.class . ; +fi + +#if in test harness, then copy the entire directory that the test is in over +# to the scratch directory. This catches any support files needed by the test. +if [ -z "${STANDALONE}" ] ; + then cp ${TESTSRC}/* . +fi + +#Just before executing anything, make sure it has executable permission! +chmod 777 ./* + +############### YOUR TEST CODE HERE!!!!!!! ############# + +#All files required for the test should be in the same directory with +# this file. If converting a standalone test to run with the harness, +# as long as all files are in the same directory and it returns 0 for +# pass, you should be able to cut and paste it into here and it will +# run with the test harness. + +${TESTJAVA}/bin/java EventQueuePushAutoshutdown + +############### END YOUR TEST CODE !!!!! ############ +#Be sure the last command executed above this line returns 0 for success, +# something non-zero for failure. +status=$? + +# pass or fail the test based on status of the command +case "$status" in + 0 ) + pass "" + ;; + + 1 ) + fail "The program didn't automatically shut down" + ;; + + * ) + fail "The program terminated unexpectedly!" + ;; +esac + +#For additional examples of how to write platform independent KSH scripts, +# see the jtreg file itself. It is a KSH script for both Solaris and Win32 +
--- a/test/java/awt/image/MultiResolutionImage/NSImageToMultiResolutionImageTest.java Thu Sep 17 22:46:04 2015 -0400 +++ b/test/java/awt/image/MultiResolutionImage/NSImageToMultiResolutionImageTest.java Fri Sep 18 09:18:17 2015 -0700 @@ -23,15 +23,17 @@ import java.awt.Image; import java.awt.Toolkit; -import sun.awt.OSInfo; -import sun.awt.image.MultiResolutionImage; +import java.awt.image.MultiResolutionImage; +import jdk.testlibrary.OSInfo; + /* * @test * @bug 8033534 8035069 * @summary [macosx] Get MultiResolution image from native system * @author Alexander Scherbatiy - * @modules java.desktop/sun.awt - * java.desktop/sun.awt.image + * @modules java.desktop/sun.awt.image + * @library /lib/testlibrary + * @build jdk.testlibrary.OSInfo * @run main NSImageToMultiResolutionImageTest */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/image/MultiResolutionImageCommonTest.java Fri Sep 18 09:18:17 2015 -0700 @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2013, 2015, 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.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.RenderingHints; +import java.awt.image.BufferedImage; +import sun.awt.SunHints; +import java.awt.geom.AffineTransform; +import java.util.Arrays; +import java.util.List; +import java.awt.image.MultiResolutionImage; + +/** + * @test @bug 8011059 + * @author Alexander Scherbatiy + * @summary Test MultiResolution image loading and painting with various scaling + * combinations + * @modules java.desktop/sun.awt + * java.desktop/sun.awt.image + */ +public class MultiResolutionImageCommonTest { + + private static final int IMAGE_WIDTH = 300; + private static final int IMAGE_HEIGHT = 200; + private static final Color COLOR_1X = Color.GREEN; + private static final Color COLOR_2X = Color.BLUE; + + public static void main(String[] args) throws Exception { + testCustomMultiResolutionImage(); + System.out.println("Test passed."); + } + + public static void testCustomMultiResolutionImage() { + testCustomMultiResolutionImage(false); + testCustomMultiResolutionImage(true); + } + + public static void testCustomMultiResolutionImage( + boolean enableImageScaling) { + + Image image = new MultiResolutionBufferedImage(); + + // Same image size + BufferedImage bufferedImage = new BufferedImage( + IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); + Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics(); + setImageScalingHint(g2d, enableImageScaling); + g2d.drawImage(image, 0, 0, null); + checkColor(bufferedImage.getRGB( + 3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false); + + // Twice image size + bufferedImage = new BufferedImage(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, + BufferedImage.TYPE_INT_RGB); + g2d = (Graphics2D) bufferedImage.getGraphics(); + setImageScalingHint(g2d, enableImageScaling); + g2d.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, + 2 * IMAGE_HEIGHT, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null); + checkColor(bufferedImage.getRGB(3 * IMAGE_WIDTH / 2, + 3 * IMAGE_HEIGHT / 2), enableImageScaling); + + // Scale 2x + bufferedImage = new BufferedImage( + 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); + g2d = (Graphics2D) bufferedImage.getGraphics(); + setImageScalingHint(g2d, enableImageScaling); + g2d.scale(2, 2); + g2d.drawImage(image, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null); + checkColor(bufferedImage.getRGB( + 3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); + + // Rotate + bufferedImage = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, + BufferedImage.TYPE_INT_RGB); + g2d = (Graphics2D) bufferedImage.getGraphics(); + setImageScalingHint(g2d, enableImageScaling); + g2d.drawImage(image, 0, 0, null); + g2d.rotate(Math.PI / 4); + checkColor(bufferedImage.getRGB( + 3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false); + + // Scale 2x and Rotate + bufferedImage = new BufferedImage( + 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); + g2d = (Graphics2D) bufferedImage.getGraphics(); + setImageScalingHint(g2d, enableImageScaling); + g2d.scale(-2, 2); + g2d.rotate(-Math.PI / 10); + g2d.drawImage(image, -IMAGE_WIDTH, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null); + checkColor(bufferedImage.getRGB( + 3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); + + // General Transform + bufferedImage = new BufferedImage( + 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); + g2d = (Graphics2D) bufferedImage.getGraphics(); + setImageScalingHint(g2d, enableImageScaling); + float delta = 0.05f; + float cos = 1 - delta * delta / 2; + float sin = 1 + delta; + AffineTransform transform + = new AffineTransform(2 * cos, 0.1, 0.3, -2 * sin, 10, -5); + g2d.setTransform(transform); + g2d.drawImage(image, 0, -IMAGE_HEIGHT, IMAGE_WIDTH, IMAGE_HEIGHT, null); + checkColor(bufferedImage.getRGB( + 3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); + + int D = 10; + // From Source to small Destination region + bufferedImage = new BufferedImage( + IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); + g2d = (Graphics2D) bufferedImage.getGraphics(); + setImageScalingHint(g2d, enableImageScaling); + g2d.drawImage(image, IMAGE_WIDTH / 2, IMAGE_HEIGHT / 2, + IMAGE_WIDTH - D, IMAGE_HEIGHT - D, + D, D, IMAGE_WIDTH - D, IMAGE_HEIGHT - D, null); + checkColor(bufferedImage.getRGB( + 3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false); + + // From Source to large Destination region + bufferedImage = new BufferedImage( + 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); + g2d = (Graphics2D) bufferedImage.getGraphics(); + setImageScalingHint(g2d, enableImageScaling); + g2d.drawImage(image, D, D, 2 * IMAGE_WIDTH - D, 2 * IMAGE_HEIGHT - D, + IMAGE_WIDTH / 2, IMAGE_HEIGHT / 2, + IMAGE_WIDTH - D, IMAGE_HEIGHT - D, null); + checkColor(bufferedImage.getRGB( + 3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); + } + + static class MultiResolutionBufferedImage extends BufferedImage + implements MultiResolutionImage { + + Image highResolutionImage; + + public MultiResolutionBufferedImage() { + super(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); + highResolutionImage = new BufferedImage( + 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, + BufferedImage.TYPE_INT_RGB); + draw(getGraphics(), 1); + draw(highResolutionImage.getGraphics(), 2); + } + + final void draw(Graphics graphics, float resolution) { + Graphics2D g2 = (Graphics2D) graphics; + g2.scale(resolution, resolution); + g2.setColor((resolution == 1) ? COLOR_1X : COLOR_2X); + g2.fillRect(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT); + } + + @Override + public Image getResolutionVariant( + double destImageWidth, double destImageHeight) { + return ((destImageWidth <= getWidth() && destImageHeight <= getHeight())) + ? this : highResolutionImage; + } + + @Override + public List<Image> getResolutionVariants() { + return Arrays.asList(this, highResolutionImage); + } + } + + static void setImageScalingHint( + Graphics2D g2d, boolean enableImageScaling) { + g2d.setRenderingHint(SunHints.KEY_RESOLUTION_VARIANT, enableImageScaling + ? RenderingHints.VALUE_RESOLUTION_VARIANT_DEFAULT + : RenderingHints.VALUE_RESOLUTION_VARIANT_BASE); + } + + static void checkColor(int rgb, boolean isImageScaled) { + + if (!isImageScaled && COLOR_1X.getRGB() != rgb) { + throw new RuntimeException("Wrong 1x color: " + new Color(rgb)); + } + + if (isImageScaled && COLOR_2X.getRGB() != rgb) { + throw new RuntimeException("Wrong 2x color" + new Color(rgb)); + } + } + +}
--- a/test/java/awt/image/MultiResolutionImageTest.java Thu Sep 17 22:46:04 2015 -0400 +++ b/test/java/awt/image/MultiResolutionImageTest.java Fri Sep 18 09:18:17 2015 -0700 @@ -31,25 +31,24 @@ import java.lang.reflect.Method; import java.net.URL; import javax.imageio.ImageIO; -import sun.awt.OSInfo; import sun.awt.SunHints; import java.awt.MediaTracker; -import java.awt.geom.AffineTransform; +import java.awt.RenderingHints; import java.awt.image.ImageObserver; -import java.util.Arrays; -import java.util.List; import javax.swing.JPanel; -import sun.awt.SunToolkit; -import sun.awt.image.MultiResolutionImage; +import jdk.testlibrary.Platform; +import java.awt.image.MultiResolutionImage; /** - * @test - * @bug 8011059 + * @test @bug 8011059 * @author Alexander Scherbatiy * @summary [macosx] Make JDK demos look perfect on retina displays + * @library /lib/testlibrary/ + * @build jdk.testlibrary.Platform + * @requires (os.family == "mac") * @modules java.desktop/sun.awt * java.desktop/sun.awt.image - * @run main MultiResolutionImageTest CUSTOM + * java.desktop/sun.lwawt.macosx * @run main MultiResolutionImageTest TOOLKIT_PREPARE * @run main MultiResolutionImageTest TOOLKIT_LOAD * @run main MultiResolutionImageTest TOOLKIT @@ -70,149 +69,29 @@ if (args.length == 0) { throw new RuntimeException("Not found a test"); } - String test = args[0]; - System.out.println("TEST: " + test); - System.out.println("CHECK OS: " + checkOS()); - - if ("CUSTOM".equals(test)) { - testCustomMultiResolutionImage(); - } else if (checkOS()) { - switch (test) { - case "CUSTOM": - break; - case "TOOLKIT_PREPARE": - testToolkitMultiResolutionImagePrepare(); - break; - case "TOOLKIT_LOAD": - testToolkitMultiResolutionImageLoad(); - break; - case "TOOLKIT": - testToolkitMultiResolutionImage(); - testImageNameTo2xParsing(); - break; - default: - throw new RuntimeException("Unknown test: " + test); - } - } - } - - static boolean checkOS() { - return OSInfo.getOSType() == OSInfo.OSType.MACOSX; - } - - public static void testCustomMultiResolutionImage() { - testCustomMultiResolutionImage(false); - testCustomMultiResolutionImage(true); - } - - public static void testCustomMultiResolutionImage(boolean enableImageScaling) { - - Image image = new MultiResolutionBufferedImage(); - - // Same image size - BufferedImage bufferedImage = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, - BufferedImage.TYPE_INT_RGB); - Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics(); - setImageScalingHint(g2d, enableImageScaling); - g2d.drawImage(image, 0, 0, null); - checkColor(bufferedImage.getRGB(3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false); - - // Twice image size - bufferedImage = new BufferedImage(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, - BufferedImage.TYPE_INT_RGB); - g2d = (Graphics2D) bufferedImage.getGraphics(); - setImageScalingHint(g2d, enableImageScaling); - g2d.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null); - checkColor(bufferedImage.getRGB(3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); - - // Scale 2x - bufferedImage = new BufferedImage(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); - g2d = (Graphics2D) bufferedImage.getGraphics(); - setImageScalingHint(g2d, enableImageScaling); - g2d.scale(2, 2); - g2d.drawImage(image, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null); - checkColor(bufferedImage.getRGB(3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); - // Rotate - bufferedImage = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, - BufferedImage.TYPE_INT_RGB); - g2d = (Graphics2D) bufferedImage.getGraphics(); - setImageScalingHint(g2d, enableImageScaling); - g2d.drawImage(image, 0, 0, null); - g2d.rotate(Math.PI / 4); - checkColor(bufferedImage.getRGB(3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false); - - // Scale 2x and Rotate - bufferedImage = new BufferedImage(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); - g2d = (Graphics2D) bufferedImage.getGraphics(); - setImageScalingHint(g2d, enableImageScaling); - g2d.scale(-2, 2); - g2d.rotate(-Math.PI / 10); - g2d.drawImage(image, -IMAGE_WIDTH, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null); - checkColor(bufferedImage.getRGB(3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); - - // General Transform - bufferedImage = new BufferedImage(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); - g2d = (Graphics2D) bufferedImage.getGraphics(); - setImageScalingHint(g2d, enableImageScaling); - float delta = 0.05f; - float cos = 1 - delta * delta / 2; - float sin = 1 + delta; - AffineTransform transform = new AffineTransform(2 * cos, 0.1, 0.3, -2 * sin, 10, -5); - g2d.setTransform(transform); - g2d.drawImage(image, 0, -IMAGE_HEIGHT, IMAGE_WIDTH, IMAGE_HEIGHT, null); - checkColor(bufferedImage.getRGB(3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); - - int D = 10; - // From Source to small Destination region - bufferedImage = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); - g2d = (Graphics2D) bufferedImage.getGraphics(); - setImageScalingHint(g2d, enableImageScaling); - g2d.drawImage(image, IMAGE_WIDTH / 2, IMAGE_HEIGHT / 2, IMAGE_WIDTH - D, IMAGE_HEIGHT - D, - D, D, IMAGE_WIDTH - D, IMAGE_HEIGHT - D, null); - checkColor(bufferedImage.getRGB(3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false); - - // From Source to large Destination region - bufferedImage = new BufferedImage(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); - g2d = (Graphics2D) bufferedImage.getGraphics(); - setImageScalingHint(g2d, enableImageScaling); - g2d.drawImage(image, D, D, 2 * IMAGE_WIDTH - D, 2 * IMAGE_HEIGHT - D, - IMAGE_WIDTH / 2, IMAGE_HEIGHT / 2, IMAGE_WIDTH - D, IMAGE_HEIGHT - D, null); - checkColor(bufferedImage.getRGB(3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); - } - - static class MultiResolutionBufferedImage extends BufferedImage - implements MultiResolutionImage { - - Image highResolutionImage; - - public MultiResolutionBufferedImage() { - super(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); - highResolutionImage = new BufferedImage( - 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); - draw(getGraphics(), 1); - draw(highResolutionImage.getGraphics(), 2); + // To automatically pass the test if the test is not run using JTReg. + if (!Platform.isOSX()) { + System.out.println("Non-Mac platform detected. Passing the test"); + return; } - - void draw(Graphics graphics, float resolution) { - Graphics2D g2 = (Graphics2D) graphics; - g2.scale(resolution, resolution); - g2.setColor((resolution == 1) ? COLOR_1X : COLOR_2X); - g2.fillRect(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT); + switch (test) { + case "TOOLKIT_PREPARE": + testToolkitMultiResolutionImagePrepare(); + break; + case "TOOLKIT_LOAD": + testToolkitMultiResolutionImageLoad(); + break; + case "TOOLKIT": + testToolkitMultiResolutionImage(); + testImageNameTo2xParsing(); + break; + default: + throw new RuntimeException("Unknown test: " + test); } - - @Override - public Image getResolutionVariant(int width, int height) { - return ((width <= getWidth() && height <= getHeight())) - ? this : highResolutionImage; - } - - @Override - public List<Image> getResolutionVariants() { - return Arrays.asList(this, highResolutionImage); - } + System.out.println("Test passed."); } static void testToolkitMultiResolutionImagePrepare() throws Exception { @@ -224,8 +103,9 @@ Image image = Toolkit.getDefaultToolkit().getImage(fileName); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); - toolkit.prepareImage(image, IMAGE_WIDTH, IMAGE_HEIGHT, new LoadImageObserver(image)); + Toolkit toolkit = Toolkit.getDefaultToolkit(); + toolkit.prepareImage(image, IMAGE_WIDTH, IMAGE_HEIGHT, + new LoadImageObserver(image)); testToolkitMultiResolutionImageLoad(image); } @@ -240,7 +120,8 @@ testToolkitMultiResolutionImageLoad(image); } - static void testToolkitMultiResolutionImageLoad(Image image) throws Exception { + static void testToolkitMultiResolutionImageLoad(Image image) + throws Exception { MediaTracker tracker = new MediaTracker(new JPanel()); tracker.addImage(image, 0); @@ -256,7 +137,7 @@ int h = image.getHeight(null); Image resolutionVariant = ((MultiResolutionImage) image) - .getResolutionVariant(2 * w, 2 * h); + .getResolutionVariant(2 * w, 2 * h); if (image == resolutionVariant) { throw new RuntimeException("Resolution variant is not loaded"); @@ -267,9 +148,10 @@ static void testImageLoaded(Image image) { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Toolkit toolkit = Toolkit.getDefaultToolkit(); - int flags = toolkit.checkImage(image, IMAGE_WIDTH, IMAGE_WIDTH, new SilentImageObserver()); + int flags = toolkit.checkImage(image, IMAGE_WIDTH, IMAGE_WIDTH, + new SilentImageObserver()); if ((flags & (ImageObserver.FRAMEBITS | ImageObserver.ALLBITS)) == 0) { throw new RuntimeException("Image is not loaded!"); } @@ -278,7 +160,8 @@ static class SilentImageObserver implements ImageObserver { @Override - public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { + public boolean imageUpdate(Image img, int infoflags, int x, int y, + int width, int height) { throw new RuntimeException("Observer should not be called!"); } } @@ -292,21 +175,25 @@ } @Override - public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { + public boolean imageUpdate(Image img, int infoflags, int x, int y, + int width, int height) { if (image != img) { - throw new RuntimeException("Original image is not passed to the observer"); + throw new RuntimeException("Original image is not passed " + + "to the observer"); } if ((infoflags & ImageObserver.WIDTH) != 0) { if (width != IMAGE_WIDTH) { - throw new RuntimeException("Original width is not passed to the observer"); + throw new RuntimeException("Original width is not passed " + + "to the observer"); } } if ((infoflags & ImageObserver.HEIGHT) != 0) { if (height != IMAGE_HEIGHT) { - throw new RuntimeException("Original height is not passed to the observer"); + throw new RuntimeException("Original height is not passed " + + "to the observer"); } } @@ -335,7 +222,8 @@ testToolkitMultiResolutionImage(image, true); } - static void testToolkitMultiResolutionImageChache(String fileName, URL url) { + static void testToolkitMultiResolutionImageChache(String fileName, + URL url) { Image img1 = Toolkit.getDefaultToolkit().getImage(fileName); if (!(img1 instanceof MultiResolutionImage)) { @@ -358,8 +246,8 @@ } } - static void testToolkitMultiResolutionImage(Image image, boolean enableImageScaling) - throws Exception { + static void testToolkitMultiResolutionImage(Image image, + boolean enableImageScaling) throws Exception { MediaTracker tracker = new MediaTracker(new JPanel()); tracker.addImage(image, 0); @@ -368,15 +256,16 @@ throw new RuntimeException("Error during image loading"); } - final BufferedImage bufferedImage1x = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, - BufferedImage.TYPE_INT_RGB); + final BufferedImage bufferedImage1x = new BufferedImage(IMAGE_WIDTH, + IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics2D g1x = (Graphics2D) bufferedImage1x.getGraphics(); setImageScalingHint(g1x, false); g1x.drawImage(image, 0, 0, null); - checkColor(bufferedImage1x.getRGB(3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false); + checkColor(bufferedImage1x.getRGB(3 * IMAGE_WIDTH / 4, + 3 * IMAGE_HEIGHT / 4), false); Image resolutionVariant = ((MultiResolutionImage) image). - getResolutionVariant(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT); + getResolutionVariant(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT); if (resolutionVariant == null) { throw new RuntimeException("Resolution variant is null"); @@ -390,23 +279,28 @@ } final BufferedImage bufferedImage2x = new BufferedImage(2 * IMAGE_WIDTH, - 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); + 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics2D g2x = (Graphics2D) bufferedImage2x.getGraphics(); setImageScalingHint(g2x, enableImageScaling); - g2x.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null); - checkColor(bufferedImage2x.getRGB(3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); + g2x.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, + 2 * IMAGE_HEIGHT, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null); + checkColor(bufferedImage2x.getRGB(3 * IMAGE_WIDTH / 2, + 3 * IMAGE_HEIGHT / 2), enableImageScaling); if (!(image instanceof MultiResolutionImage)) { throw new RuntimeException("Not a MultiResolutionImage"); } - MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image; + MultiResolutionImage multiResolutionImage + = (MultiResolutionImage) image; - Image image1x = multiResolutionImage.getResolutionVariant(IMAGE_WIDTH, IMAGE_HEIGHT); - Image image2x = multiResolutionImage.getResolutionVariant(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT); + Image image1x = multiResolutionImage.getResolutionVariant( + IMAGE_WIDTH, IMAGE_HEIGHT); + Image image2x = multiResolutionImage.getResolutionVariant( + 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT); if (image1x.getWidth(null) * 2 != image2x.getWidth(null) - || image1x.getHeight(null) * 2 != image2x.getHeight(null)) { + || image1x.getHeight(null) * 2 != image2x.getHeight(null)) { throw new RuntimeException("Wrong resolution variant size"); } } @@ -416,13 +310,15 @@ ImageObserver observer = new ImageObserver() { @Override - public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { + public boolean imageUpdate(Image img, int infoflags, int x, int y, + int width, int height) { if (img != image) { throw new RuntimeException("Wrong image in observer"); } - if ((infoflags & (ImageObserver.ERROR | ImageObserver.ABORT)) != 0) { + if ((infoflags & (ImageObserver.ERROR | ImageObserver.ABORT)) + != 0) { throw new RuntimeException("Error during image loading"); } @@ -432,18 +328,20 @@ }; final BufferedImage bufferedImage2x = new BufferedImage(2 * IMAGE_WIDTH, - 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); + 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics2D g2x = (Graphics2D) bufferedImage2x.getGraphics(); setImageScalingHint(g2x, true); - g2x.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, observer); + g2x.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, 0, 0, + IMAGE_WIDTH, IMAGE_HEIGHT, observer); } - static void setImageScalingHint(Graphics2D g2d, boolean enableImageScaling) { + static void setImageScalingHint(Graphics2D g2d, + boolean enableImageScaling) { g2d.setRenderingHint(SunHints.KEY_RESOLUTION_VARIANT, enableImageScaling - ? SunHints.VALUE_RESOLUTION_VARIANT_ON - : SunHints.VALUE_RESOLUTION_VARIANT_OFF); + ? RenderingHints.VALUE_RESOLUTION_VARIANT_DEFAULT + : RenderingHints.VALUE_RESOLUTION_VARIANT_BASE); } static void checkColor(int rgb, boolean isImageScaled) { @@ -468,8 +366,9 @@ } static void generateImage(int scale) throws Exception { - BufferedImage image = new BufferedImage(scale * IMAGE_WIDTH, scale * IMAGE_HEIGHT, - BufferedImage.TYPE_INT_RGB); + BufferedImage image = new BufferedImage( + scale * IMAGE_WIDTH, scale * IMAGE_HEIGHT, + BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); g.setColor(scale == 1 ? COLOR_1X : COLOR_2X); g.fillRect(0, 0, scale * IMAGE_WIDTH, scale * IMAGE_HEIGHT); @@ -493,7 +392,7 @@ } throw new RuntimeException("Test name " + testName - + ", result name: " + resultName); + + ", result name: " + resultName); } for (URL[] testURLs : TEST_URLS) { @@ -510,7 +409,7 @@ } throw new RuntimeException("Test url: " + testURL - + ", result url: " + resultURL); + + ", result url: " + resultURL); } } @@ -521,19 +420,22 @@ } static String getTestScaledImageName(String name) throws Exception { - Method method = getScalableImageMethod("getScaledImageName", String.class); + Method method = getScalableImageMethod( + "getScaledImageName", String.class); return (String) method.invoke(null, name); } private static boolean isValidPath(String path) { return !path.isEmpty() && !path.endsWith("/") && !path.endsWith(".") - && !path.contains("@2x"); + && !path.contains("@2x"); } private static Method getScalableImageMethod(String name, - Class... parameterTypes) throws Exception { + Class... parameterTypes) throws Exception { Toolkit toolkit = Toolkit.getDefaultToolkit(); - Method method = toolkit.getClass().getDeclaredMethod(name, parameterTypes); + Method method = toolkit.getClass() + . + getDeclaredMethod(name, parameterTypes); method.setAccessible(true); return method; } @@ -604,9 +506,11 @@ {new URL("jar:file:/dir/Java2D.jar!/images/image.ext"), new URL("jar:file:/dir/Java2D.jar!/images/image@2x.ext")}, {new URL("jar:file:/aaa.bbb/Java2D.jar!/images/image.ext"), - new URL("jar:file:/aaa.bbb/Java2D.jar!/images/image@2x.ext")}, + new URL("jar:file:/aaa.bbb/Java2D.jar!/" + + "images/image@2x.ext")}, {new URL("jar:file:/dir/Java2D.jar!/aaa.bbb/image.ext"), - new URL("jar:file:/dir/Java2D.jar!/aaa.bbb/image@2x.ext")},}; + new URL("jar:file:/dir/Java2D.jar!/" + + "aaa.bbb/image@2x.ext")},}; } catch (Exception e) { throw new RuntimeException(e); } @@ -615,7 +519,8 @@ static class PreloadedImageObserver implements ImageObserver { @Override - public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { + public boolean imageUpdate(Image img, int infoflags, int x, int y, + int width, int height) { throw new RuntimeException("Image should be already preloaded"); } }
--- a/test/java/awt/image/RescaleOp/RescaleAlphaTest.java Thu Sep 17 22:46:04 2015 -0400 +++ b/test/java/awt/image/RescaleOp/RescaleAlphaTest.java Fri Sep 18 09:18:17 2015 -0700 @@ -22,8 +22,8 @@ */ /** * @test - * @bug 8080287 - * @run RescaleAlphaTest + * @bug 8080287 8136354 + * @run main RescaleAlphaTest * @summary RescaleOp with scaleFactor/alpha should copy alpha to destination * channel */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/image/multiresolution/BaseMultiResolutionImageTest.java Fri Sep 18 09:18:17 2015 -0700 @@ -0,0 +1,204 @@ +/* + * Copyright (c) 2015, 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.Dimension; +import java.awt.Image; +import java.awt.image.BufferedImage; +import java.awt.image.BaseMultiResolutionImage; +import java.awt.image.MultiResolutionImage; +import java.util.List; + +/** + * @test + * @bug 8029339 + * @author Alexander Scherbatiy + * @summary Custom MultiResolution image support on HiDPI displays + * @run main BaseMultiResolutionImageTest + */ +public class BaseMultiResolutionImageTest { + + public static void main(String[] args) { + testZeroRVIMages(); + testNullRVIMages(); + testNullRVIMage(); + testIOOBException(); + testRVSizes(); + testBaseMRImage(); + } + + static void testZeroRVIMages() { + try { + new BaseMultiResolutionImage(); + } catch (IllegalArgumentException ignored) { + return; + } + throw new RuntimeException("IllegalArgumentException is not thrown!"); + } + + static void testNullRVIMages() { + try { + new BaseMultiResolutionImage(null); + } catch (IllegalArgumentException ignored) { + return; + } + throw new RuntimeException("IllegalArgumentException is not thrown!"); + } + + static void testNullRVIMage() { + + Image baseImage = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); + + try { + new BaseMultiResolutionImage(baseImage, null); + } catch (NullPointerException ignored) { + return; + } + throw new RuntimeException("NullPointerException is not thrown!"); + } + + static void testIOOBException() { + + for (int baseImageIndex : new int[]{-3, 2, 4}) { + try { + new BaseMultiResolutionImage(baseImageIndex, + createRVImage(0), createRVImage(1)); + } catch (IndexOutOfBoundsException ignored) { + continue; + } + + throw new RuntimeException("IndexOutOfBoundsException is not thrown!"); + } + } + + static void testRVSizes() { + + int imageSize = getSize(1); + + double[][] sizeArray = { + {-imageSize, imageSize}, + {2 * imageSize, -2 * imageSize}, + {Double.POSITIVE_INFINITY, imageSize}, + {Double.POSITIVE_INFINITY, -imageSize}, + {imageSize, Double.NEGATIVE_INFINITY}, + {-imageSize, Double.NEGATIVE_INFINITY}, + {Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY}, + {Double.NaN, imageSize}, + {imageSize, Double.NaN}, + {Double.NaN, Double.NaN}, + {Double.POSITIVE_INFINITY, Double.NaN} + }; + + for (double[] sizes : sizeArray) { + try { + MultiResolutionImage mrImage = new BaseMultiResolutionImage( + 0, createRVImage(0), createRVImage(1)); + mrImage.getResolutionVariant(sizes[0], sizes[1]); + } catch (IllegalArgumentException ignored) { + continue; + } + + throw new RuntimeException("IllegalArgumentException is not thrown!"); + } + } + + static void testBaseMRImage() { + int baseIndex = 1; + int length = 3; + BufferedImage[] resolutionVariants = new BufferedImage[length]; + for (int i = 0; i < length; i++) { + resolutionVariants[i] = createRVImage(i); + } + + BaseMultiResolutionImage mrImage = new BaseMultiResolutionImage(baseIndex, + resolutionVariants); + + List<Image> rvImageList = mrImage.getResolutionVariants(); + if (rvImageList.size() != length) { + throw new RuntimeException("Wrong size of resolution variants list!"); + } + + for (int i = 0; i < length; i++) { + int imageSize = getSize(i); + Image testRVImage = mrImage.getResolutionVariant(imageSize, imageSize); + + if (testRVImage != resolutionVariants[i]) { + throw new RuntimeException("Wrong resolution variant!"); + } + + if (rvImageList.get(i) != resolutionVariants[i]) { + throw new RuntimeException("Wrong resolution variant!"); + } + } + + BufferedImage baseImage = resolutionVariants[baseIndex]; + + if (baseImage.getWidth() != mrImage.getWidth(null) + || baseImage.getHeight() != mrImage.getHeight(null)) { + throw new RuntimeException("Base image is wrong!"); + } + + boolean passed = false; + + try { + rvImageList.set(0, createRVImage(10)); + } catch (Exception e) { + passed = true; + } + + if (!passed) { + throw new RuntimeException("Resolution variants list is modifiable!"); + } + + passed = false; + + try { + rvImageList.remove(0); + } catch (Exception e) { + passed = true; + } + + if (!passed) { + throw new RuntimeException("Resolution variants list is modifiable!"); + } + + passed = false; + + try { + rvImageList.add(0, createRVImage(10)); + } catch (Exception e) { + passed = true; + } + + if (!passed) { + throw new RuntimeException("Resolution variants list is modifiable!"); + } + } + + private static int getSize(int i) { + return 8 * (i + 1); + } + + private static BufferedImage createRVImage(int i) { + return new BufferedImage(getSize(i), getSize(i), + BufferedImage.TYPE_INT_RGB); + } +}
--- a/test/java/awt/image/multiresolution/MultiResolutionCachedImageTest.java Thu Sep 17 22:46:04 2015 -0400 +++ b/test/java/awt/image/multiresolution/MultiResolutionCachedImageTest.java Fri Sep 18 09:18:17 2015 -0700 @@ -98,7 +98,7 @@ } @Override - public Image getResolutionVariant(int width, int height) { + public Image getResolutionVariant(double width, double height) { if (width == size || height == size) { throw new RuntimeException("Base image is requested!"); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/image/multiresolution/MultiResolutionRenderingHintsTest.java Fri Sep 18 09:18:17 2015 -0700 @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2015, 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.Color; +import java.awt.Graphics; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.Image; +import java.awt.Rectangle; +import java.awt.image.BufferedImage; +import java.awt.image.BaseMultiResolutionImage; +import static java.awt.RenderingHints.KEY_RESOLUTION_VARIANT; +import static java.awt.RenderingHints.VALUE_RESOLUTION_VARIANT_BASE; +import static java.awt.RenderingHints.VALUE_RESOLUTION_VARIANT_DPI_FIT; +import static java.awt.RenderingHints.VALUE_RESOLUTION_VARIANT_SIZE_FIT; +import static java.awt.RenderingHints.VALUE_RESOLUTION_VARIANT_DEFAULT; +import java.awt.geom.AffineTransform; +import java.awt.image.ColorModel; +import java.awt.image.Raster; +import sun.java2d.StateTrackable; +import sun.java2d.SunGraphics2D; +import sun.java2d.SurfaceData; +import sun.java2d.loops.SurfaceType; + +/** + * @test + * @bug 8029339 + * @author Alexander Scherbatiy + * @summary Custom MultiResolution image support on HiDPI displays + * @modules java.desktop/sun.java2d + * @run main MultiResolutionRenderingHintsTest + */ +public class MultiResolutionRenderingHintsTest { + + private static final int BASE_SIZE = 200; + private static final Color[] COLORS = { + Color.CYAN, Color.GREEN, Color.BLUE, Color.ORANGE, Color.RED, Color.PINK + }; + + public static void main(String[] args) throws Exception { + + int length = COLORS.length; + BufferedImage[] resolutionVariants = new BufferedImage[length]; + for (int i = 0; i < length; i++) { + resolutionVariants[i] = createRVImage(getSize(i), COLORS[i]); + } + + BaseMultiResolutionImage mrImage = new BaseMultiResolutionImage( + resolutionVariants); + + // base + Color color = getImageColor(VALUE_RESOLUTION_VARIANT_BASE, mrImage, 2, 3); + if (!getColorForScale(1).equals(color)) { + throw new RuntimeException("Wrong base resolution variant!"); + } + + // dpi fit + color = getImageColor(VALUE_RESOLUTION_VARIANT_DPI_FIT, mrImage, 2, 3); + if (!getColorForScale(2).equals(color)) { + throw new RuntimeException("Resolution variant is not based on dpi!"); + } + + // size fit + color = getImageColor(VALUE_RESOLUTION_VARIANT_SIZE_FIT, mrImage, 2, 3); + if (!getColorForScale(6).equals(color)) { + throw new RuntimeException("Resolution variant is not based on" + + " rendered size!"); + } + + // default + // depends on the policies of the platform + // just check that exception is not thrown + getImageColor(VALUE_RESOLUTION_VARIANT_DEFAULT, mrImage, 2, 3); + } + + private static Color getColorForScale(int scale) { + return COLORS[scale - 1]; + } + + private static Color getImageColor(final Object renderingHint, Image image, + double configScale, double graphicsScale) { + + int width = image.getWidth(null); + int height = image.getHeight(null); + + TestSurfaceData surface = new TestSurfaceData(width, height, configScale); + SunGraphics2D g2d = new SunGraphics2D(surface, + Color.BLACK, Color.BLACK, null); + g2d.setRenderingHint(KEY_RESOLUTION_VARIANT, renderingHint); + g2d.scale(graphicsScale, graphicsScale); + g2d.drawImage(image, 0, 0, null); + g2d.dispose(); + return surface.getColor(width / 2, height / 2); + } + + private static int getSize(int i) { + return (i + 1) * BASE_SIZE; + } + + private static BufferedImage createRVImage(int size, Color color) { + BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB); + Graphics g = image.createGraphics(); + g.setColor(Color.BLACK); + g.fillRect(0, 0, size, size); + g.setColor(color); + g.fillOval(0, 0, size, size); + g.dispose(); + return image; + } + + static class TestGraphicsConfig extends GraphicsConfiguration { + + private final double scale; + + TestGraphicsConfig(double scale) { + this.scale = scale; + } + + @Override + public GraphicsDevice getDevice() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public ColorModel getColorModel() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public ColorModel getColorModel(int transparency) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public AffineTransform getDefaultTransform() { + return AffineTransform.getScaleInstance(scale, scale); + } + + @Override + public AffineTransform getNormalizingTransform() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Rectangle getBounds() { + throw new UnsupportedOperationException("Not supported yet."); + } + } + + static class TestSurfaceData extends SurfaceData { + + private final int width; + private final int height; + private final GraphicsConfiguration gc; + private final BufferedImage buffImage; + private final double scale; + + public TestSurfaceData(int width, int height, double scale) { + super(StateTrackable.State.DYNAMIC, SurfaceType.Custom, ColorModel.getRGBdefault()); + this.scale = scale; + gc = new TestGraphicsConfig(scale); + this.width = (int) Math.ceil(scale * width); + this.height = (int) Math.ceil(scale * height); + buffImage = new BufferedImage(this.width, this.height, + BufferedImage.TYPE_INT_RGB); + } + + Color getColor(int x, int y) { + int sx = (int) Math.ceil(x * scale); + int sy = (int) Math.ceil(y * scale); + return new Color(buffImage.getRGB(sx, sy)); + } + + @Override + public SurfaceData getReplacement() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public GraphicsConfiguration getDeviceConfiguration() { + return gc; + } + + @Override + public Raster getRaster(int x, int y, int w, int h) { + return buffImage.getRaster(); + } + + @Override + public Rectangle getBounds() { + return new Rectangle(0, 0, width, height); + } + + @Override + public Object getDestination() { + throw new UnsupportedOperationException("Not supported yet."); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/beans/XMLEncoder/ReferenceToNonStaticField.java Fri Sep 18 09:18:17 2015 -0700 @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2015, 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.font.TextAttribute; + +/** + * @test + * @bug 8060027 + */ +public final class ReferenceToNonStaticField + extends AbstractTest<ReferenceToNonStaticField.TestValue> { + + public static final class TestValue { + + // reference to static field + public TextAttribute font_default = TextAttribute.FONT; + public TextAttribute family_default = TextAttribute.FAMILY; + public TextAttribute family_set1; // will be set to the same as default + public TextAttribute family_set2; // will be set to the same as default + public TextAttribute family_set3; // will be set to the same as default + + // primitive small + public int int_1_default = 1; + public int int_10_default = 10; + public int int_10_set1; // will be set to the same as default + public int int_10_set2; // will be set to the same as default + public int int_10_set3; // will be set to the same as default + + // primitive big + public int int_1000_default = 1000; + public int int_2000_default = 2000; + public int int_2000_set1; // will be set to the same as default + public int int_2000_set2; // will be set to the same as default + public int int_2000_set3; // will be set to the same as default + + // wrappers + public Integer integer_1_default = new Integer(1); + public Integer integer_10_default = new Integer(10); + public Integer integer_10_set1; // will be set to the same as default + public Integer integer_10_set2; // will be set to the same as default + public Integer integer_10_set3; // will be set to the same as default + + public TestValue() { + } + + public TestValue(final Object ignored) { + // set some fields to non-default values, so they will be saved + family_set1 = family_default; + family_set3 = family_default; + family_set2 = family_default; + int_10_set1 = int_10_default; + int_10_set2 = int_10_default; + int_10_set3 = int_10_default; + int_2000_set1 = int_2000_default; + int_2000_set2 = int_2000_default; + int_2000_set3 = int_2000_default; + integer_10_set1 = integer_10_default; + integer_10_set2 = integer_10_default; + integer_10_set3 = integer_10_default; + } + } + + public static void main(final String[] args) { + new ReferenceToNonStaticField().test(true); + } + + protected TestValue getObject() { + return new TestValue(new Object()); + } + + @Override + protected void validate(final TestValue before,final TestValue after) { + super.validate(before, after); + validate(before); + validate(after); + } + + private static void validate(final TestValue object) { + // reference to static field + if (object.font_default != TextAttribute.FONT) { + throw new Error("Wrong font_default: " + object.font_default); + } + if (object.family_default != TextAttribute.FAMILY) { + throw new Error("Wrong family_default: " + object.family_default); + } + if (object.family_set1 != object.family_default) { + throw new Error("Wrong family_set1: " + object.family_set1); + } + if (object.family_set2 != object.family_default) { + throw new Error("Wrong family_set2: " + object.family_set2); + } + if (object.family_set3 != object.family_default) { + throw new Error("Wrong family_set3: " + object.family_set3); + } + // primitive small + if (object.int_1_default != 1) { + throw new Error("Wrong int_1_default: " + object.int_1_default); + } + if (object.int_10_default != 10) { + throw new Error("Wrong int_10_default: " + object.int_10_default); + } + if (object.int_10_set1 != object.int_10_default) { + throw new Error("Wrong int_10_set1: " + object.int_10_set1); + } + if (object.int_10_set2 != object.int_10_default) { + throw new Error("Wrong int_10_set2: " + object.int_10_set2); + } + if (object.int_10_set3 != object.int_10_default) { + throw new Error("Wrong int_10_set3: " + object.int_10_set3); + } + // primitive big + if (object.int_1000_default != 1000) { + throw new Error("Wrong int_1000_default: " + object.int_1000_default); + } + if (object.int_2000_default != 2000) { + throw new Error("Wrong int_2000_default: " + object.int_2000_default); + } + if (object.int_2000_set1 != object.int_2000_default) { + throw new Error("Wrong int_2000_set1: " + object.int_2000_set1); + } + if (object.int_2000_set2 != object.int_2000_default) { + throw new Error("Wrong int_2000_set2: " + object.int_2000_set2); + } + if (object.int_2000_set3 != object.int_2000_default) { + throw new Error("Wrong int_2000_set3: " + object.int_2000_set3); + } + // wrappers + if (!object.integer_1_default.equals(new Integer(1))) { + throw new Error("Wrong integer_1_default: " + object.integer_1_default); + } + if (!object.integer_10_default.equals(new Integer(10))) { + throw new Error("Wrong integer_10_default: " + object.integer_10_default); + } + if (object.integer_10_set1 != object.integer_10_default) { + throw new Error("Wrong integer_10_set1: " + object.integer_10_set1); + } + if (object.integer_10_set2 != object.integer_10_default) { + throw new Error("Wrong integer_10_set2: " + object.integer_10_set2); + } + if (object.integer_10_set3 != object.integer_10_default) { + throw new Error("Wrong integer_10_set3: " + object.integer_10_set3); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/sound/sampled/FileReader/RepeatedFormatReader.java Fri Sep 18 09:18:17 2015 -0700 @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2015, 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.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.UnsupportedAudioFileException; + +/** + * @test + * @bug 8133677 + * @summary Subsequent read from the same stream should work + */ +public final class RepeatedFormatReader { + + // Stubs + + private static byte[] headerMIDI = {0x4d, 0x54, 0x68, 0x64, // MThd + 0, 0, 0, 6, // read header length + 0, 0, // type + 0, 0, // numtracks + 0, 1, // timing + }; + + private static byte[] headerAU = {0x2e, 0x73, 0x6e, 0x64, // AU_SUN_MAGIC + 0, 0, 0, 0, // headerSize + 0, 0, 0, 0, // dataSize + 0, 0, 0, 1, // encoding + 0, 0, 0, 0, // sampleRate + 0, 0, 0, 1 // channels + }; + + private static byte[] headerWAV = {0x52, 0x49, 0x46, 0x46, // RIFF_MAGIC + 1, 1, 1, 1, // fileLength + 0x57, 0x41, 0x56, 0x45, // waveMagic + 0x66, 0x6d, 0x74, 0x20, // FMT_MAGIC + 3, 0, 0, 0, // length + 1, 0, // wav_type WAVE_FORMAT_PCM + 0, 1, // channels + 0, 0, 0, 0, // sampleRate + 0, 0, 0, 0, // avgBytesPerSec + 0, 0, // blockAlign + 1, 0, // sampleSizeInBits + 0x64, 0x61, 0x74, 0x61, // DATA_MAGIC + 0, 0, 0, 0, // dataLength + }; + + private static final byte[][] data = {headerMIDI, headerAU, headerWAV}; + + public static void main(final String[] args) + throws IOException, UnsupportedAudioFileException { + for (final byte[] bytes : data) { + test(bytes); + } + } + + private static void test(final byte[] buffer) + throws IOException, UnsupportedAudioFileException { + final InputStream is = new ByteArrayInputStream(buffer); + for (int i = 0; i < 10; ++i) { + AudioSystem.getAudioFileFormat(is); + } + } +}
--- a/test/javax/swing/JInternalFrame/8020708/bug8020708.java Thu Sep 17 22:46:04 2015 -0400 +++ b/test/javax/swing/JInternalFrame/8020708/bug8020708.java Fri Sep 18 09:18:17 2015 -0700 @@ -35,7 +35,7 @@ /** * @test - * @bug 8020708 + * @bug 8020708 8032568 * @author Alexander Scherbatiy * @summary NLS: mnemonics missing in SwingSet2/JInternalFrame demo * @library ../../regtesthelpers @@ -111,8 +111,14 @@ Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_SPACE); robot.waitForIdle(); - - Util.hitKeys(robot, KeyEvent.VK_C); + int keyCode = KeyEvent.VK_C; + String mnemonic = UIManager + .getString("InternalFrameTitlePane.closeButton.mnemonic"); + try { + keyCode = Integer.parseInt(mnemonic); + } catch (NumberFormatException e) { + } + Util.hitKeys(robot, keyCode); robot.waitForIdle(); robot.delay(500);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/swing/JTableHeader/6442918/bug6442918a.java Fri Sep 18 09:18:17 2015 -0700 @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2015, 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 6442918 8005914 + @summary Ensures that empty table headers do not show "..." + @author Shannon Hickey + @library ../../regtesthelpers + @build Util + @run main/manual bug6442918a + @requires os.family == "windows" +*/ + +import java.awt.BorderLayout; +import java.awt.Dimension; +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.table.DefaultTableCellRenderer; + + +public class bug6442918a { + + public static void main(String[] args) throws Throwable, Exception { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + try { + UIManager.setLookAndFeel("com.sun.java.swing.plaf" + + ".windows.WindowsLookAndFeel"); + } catch (Exception e) { + // test is for Windows look and feel + throw new RuntimeException("Test is only for WLaF." + + e.getMessage()); + } + runTest(); + } + }); + } + + private static void runTest() { + JDialog dialog = Util + .createModalDialogWithPassFailButtons("Empty header showing \"...\""); + String[] columnNames = {"", "", "", "", "Testing"}; + String[][] data = {{"1", "2", "3", "4", "5"}}; + JTable table = new JTable(data, columnNames); + DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); + int tableCellWidth = renderer.getFontMetrics(renderer.getFont()) + .stringWidth("test"); + table.setPreferredScrollableViewportSize(new Dimension( + 5 * tableCellWidth, 50)); + JPanel p = new JPanel(); + p.add(new JScrollPane(table)); + dialog.add(p, BorderLayout.NORTH); + JTextArea area = new JTextArea(); + String txt = "\nInstructions:\n\n"; + txt += "Only the last column header should show \"...\"."; + area.setText(txt); + dialog.add(new JScrollPane(area), BorderLayout.CENTER); + dialog.pack(); + dialog.setVisible(true); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/swing/JTextPane/bug8025082.java Fri Sep 18 09:18:17 2015 -0700 @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2015, 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 8025082 + * @summary The behaviour of the highlight will be lost after clicking the set + * button. + * @run main bug8025082 + */ +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.InputEvent; +import javax.swing.*; + +public class bug8025082 { + + private static JButton button; + private static JFrame frame; + + public static void main(String[] args) throws Exception { + Robot robo = new Robot(); + robo.delay(500); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + createUI(); + } + }); + + robo.waitForIdle(); + Point point = getButtonLocationOnScreen(); + robo.mouseMove(point.x, point.y); + robo.mousePress(InputEvent.BUTTON1_MASK); + robo.mouseRelease(InputEvent.BUTTON1_MASK); + robo.waitForIdle(); + + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + frame.dispose(); + } + }); + } + + private static void createUI() { + frame = new JFrame(); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(500, 500); + JTextPane textpane = new JTextPane(); + textpane.setText("Select Me"); + textpane.selectAll(); + + JPanel panel = new JPanel(new BorderLayout()); + panel.add(textpane, BorderLayout.CENTER); + button = new JButton("Press Me"); + panel.add(button, BorderLayout.SOUTH); + + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (!textpane.getCaret().isSelectionVisible()) { + throw new RuntimeException("Highlight removed after " + + "button click"); + } + } + }); + + frame.getContentPane().add(panel); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + + private static Point getButtonLocationOnScreen() throws Exception { + final Point[] result = new Point[1]; + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + Point point = button.getLocationOnScreen(); + point.x += button.getWidth() / 2; + point.y += button.getHeight() / 2; + result[0] = point; + } + }); + return result[0]; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/swing/UI/UnninstallUIMemoryLeaks/UnninstallUIMemoryLeaks.java Fri Sep 18 09:18:17 2015 -0700 @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2015, 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.FlowLayout; + +import javax.swing.*; +import javax.swing.UIManager.LookAndFeelInfo; + +import static javax.swing.UIManager.getInstalledLookAndFeels; + +/** + * @test + * @bug 8134947 + * @author Sergey Bylokhov + * @run main/timeout=300/othervm -Xmx12m -XX:+HeapDumpOnOutOfMemoryError UnninstallUIMemoryLeaks + */ +public final class UnninstallUIMemoryLeaks { + + private static JFrame frame; + + public static void main(final String[] args) throws Exception { + try { + createGUI(); + for (final LookAndFeelInfo laf : getInstalledLookAndFeels()) { + final String name = laf.getName(); + if (name.contains("OS X") || name.contains("Metal")) { + SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf)); + SwingUtilities.invokeAndWait(() -> { + for (int i = 0; i < 4000; ++i) { + SwingUtilities.updateComponentTreeUI(frame); + } + }); + } + } + } finally { + EventQueue.invokeAndWait(() -> frame.dispose()); + } + } + + private static void createGUI() throws Exception { + EventQueue.invokeAndWait(() -> { + frame = new JFrame(); + frame.setLayout(new FlowLayout()); + + frame.add(new JButton("JButton")); + frame.add(new JCheckBox("JCheckBox")); + frame.add(new JComboBox<>()); + frame.add(new JEditorPane()); + frame.add(new JFormattedTextField("JFormattedTextField")); + frame.add(new JLabel("label")); + frame.add(new JPanel()); + frame.add(new JPasswordField("JPasswordField")); + frame.add(new JProgressBar()); + frame.add(new JRadioButton("JRadioButton")); + frame.add(new JScrollBar()); + frame.add(new JScrollPane()); + frame.add(new JSeparator()); + frame.add(new JSlider()); + frame.add(new JSpinner()); + frame.add(new JSplitPane()); + frame.add(new JTabbedPane()); + frame.add(new JTable()); + frame.add(new JTextArea("JTextArea")); + frame.add(new JTextField("JTextField")); + frame.add(new JTextPane()); + frame.add(new JToggleButton()); + frame.add(new JToolBar()); + frame.add(new JToolTip()); + frame.add(new JTree()); + frame.add(new JViewport()); + + final JMenuBar bar = new JMenuBar(); + final JMenu menu1 = new JMenu("menu1"); + final JMenu menu2 = new JMenu("menu2"); + menu1.add(new JMenuItem("menuitem")); + menu2.add(new JCheckBoxMenuItem("JCheckBoxMenuItem")); + menu2.add(new JRadioButtonMenuItem("JRadioButtonMenuItem")); + bar.add(menu1); + bar.add(menu2); + frame.setJMenuBar(bar); + + final String[] data = {"one", "two", "three", "four"}; + final JList<String> list = new JList<>(data); + frame.add(list); + + final JDesktopPane pane = new JDesktopPane(); + final JInternalFrame internalFrame = new JInternalFrame(); + internalFrame.setBounds(10, 10, 130, 130); + internalFrame.setVisible(true); + pane.add(internalFrame); + pane.setSize(150, 150); + + frame.add(pane); + frame.pack(); + frame.setSize(600, 600); + frame.setLocationRelativeTo(null); + // Commented to prevent a reference from RepaintManager + // frame.setVisible(true); + }); + } + + private static void setLookAndFeel(final LookAndFeelInfo laf) { + try { + UIManager.setLookAndFeel(laf.getClassName()); + System.out.println("LookAndFeel: " + laf.getClassName()); + } catch (ClassNotFoundException | InstantiationException | + UnsupportedLookAndFeelException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/swing/plaf/basic/BasicHTML/4960629/bug4960629.java Fri Sep 18 09:18:17 2015 -0700 @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2015, 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 4960629 7124238 + @summary Tests if font for html text on widgets in correct. + @author Denis Sharypov + @run main bug4960629 +*/ + +import java.awt.Font; +import java.lang.reflect.InvocationTargetException; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.plaf.basic.BasicHTML; +import javax.swing.text.AttributeSet; +import javax.swing.text.View; +import javax.swing.text.html.StyleSheet; +import javax.swing.text.html.HTMLDocument; + +public class bug4960629 { + private boolean passed = false; + private JLabel label = null; + private JFrame f = null; + + public void createAndShowGUI() throws Exception { + try { + UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); + label = new JLabel("<html><P>This is a test of the</P></html>"); + System.out.println("UIManager.getLookAndFeel()" + + UIManager.getLookAndFeel().getClass()); + f = new JFrame(); + f.getContentPane().add(label); + f.pack(); + f.setVisible(true); + test(); + } finally { + f.dispose(); + } + } + + bug4960629() throws InvocationTargetException, InterruptedException { + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + try { + createAndShowGUI(); + } catch (Exception e) { + throw new RuntimeException("Exception " + + e.getMessage()); + } + } + }); + } + + private void test() { + View root = ((View)label.getClientProperty(BasicHTML.propertyKey)) + .getView(0); + int n = root.getViewCount(); + View v = root.getView(n - 1); + AttributeSet attrs = v.getAttributes(); + StyleSheet ss = ((HTMLDocument) v.getDocument()).getStyleSheet(); + Font font = ss.getFont(attrs); + System.out.println(font.getSize()); + passed = (font.getSize() == 12); + if(!passed) { + throw new RuntimeException("Test failed."); + } + } + + public static void main(String args[]) throws Throwable { + new bug4960629(); + } +}
--- a/test/javax/swing/regtesthelpers/Util.java Thu Sep 17 22:46:04 2015 -0400 +++ b/test/javax/swing/regtesthelpers/Util.java Fri Sep 18 09:18:17 2015 -0700 @@ -41,6 +41,7 @@ */ public class Util { + /** * Convert a rectangle from coordinate system of Component c to * screen coordinate system. @@ -266,4 +267,42 @@ result.add(KeyEvent.VK_ALT); return result; } + + /** + * Creates and returns a JDialog with two button, one that says pass, + * another that says fail. The fail button is wired to call + * <code>uiTestFailed</code> with <code>failString</code> and the pass + * button is wired to invoked <code>uiTestPassed</code>. + * <p>The content pane of the JDialog uses a BorderLayout with the + * buttons inside a horizontal box with filler between them and the + * pass button on the left. + * <p>The returned Dialog has not been packed, or made visible, it is + * up to the caller to do that (after putting in some useful components). + */ + public static JDialog createModalDialogWithPassFailButtons(final String failString) { + JDialog retDialog = new JDialog(); + Box buttonBox = Box.createHorizontalBox(); + JButton passButton = new JButton("Pass"); + JButton failButton = new JButton("Fail"); + + passButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + retDialog.dispose(); + } + }); + failButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + retDialog.dispose(); + throw new RuntimeException("Test failed. " + failString); + } + }); + retDialog.setTitle("Test"); + retDialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL); + buttonBox.add(passButton); + buttonBox.add(Box.createGlue()); + buttonBox.add(failButton); + retDialog.getContentPane().add(buttonBox, BorderLayout.SOUTH); + retDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + return retDialog; + } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/sun/java2d/OpenGL/CopyAreaOOB.java Fri Sep 18 09:18:17 2015 -0700 @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2015, 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 6430601 + * @summary Verifies that copyArea() works properly when the + * destination parameters are outside the destination bounds. + * @run main/othervm CopyAreaOOB + * @run main/othervm -Dsun.java2d.opengl=True CopyAreaOOB + * @author campbelc + */ + +import java.awt.*; +import java.awt.image.*; + +public class CopyAreaOOB extends Canvas { + + private static boolean done; + + public void paint(Graphics g) { + synchronized (this) { + if (done) { + return; + } + } + + int w = getWidth(); + int h = getHeight(); + + Graphics2D g2d = (Graphics2D)g; + g2d.setColor(Color.black); + g2d.fillRect(0, 0, w, h); + + g2d.setColor(Color.green); + g2d.fillRect(0, 0, w, 10); + + g2d.setColor(Color.red); + g2d.fillRect(0, 10, 50, h-10); + + // copy the region such that part of it goes below the bottom of the + // destination surface + g2d.copyArea(0, 10, 50, h-10, 60, 10); + + Toolkit.getDefaultToolkit().sync(); + + synchronized (this) { + done = true; + notifyAll(); + } + } + + public Dimension getPreferredSize() { + return new Dimension(400, 400); + } + + private static void testRegion(BufferedImage bi, String name, + int x1, int y1, int x2, int y2, + int expected) + { + for (int y = y1; y < y2; y++) { + for (int x = x1; x < x2; x++) { + int actual = bi.getRGB(x, y); + if (actual != expected) { + throw new RuntimeException("Test failed for " + name + + " region at x="+x+" y="+y+ + " (expected="+ + Integer.toHexString(expected) + + " actual="+ + Integer.toHexString(actual) + + ")"); + } + } + } + } + + public static void main(String[] args) { + boolean show = (args.length == 1) && ("-show".equals(args[0])); + + CopyAreaOOB test = new CopyAreaOOB(); + Frame frame = new Frame(); + frame.setUndecorated(true); + frame.add(test); + frame.pack(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + + // Wait until the component's been painted + synchronized (test) { + while (!done) { + try { + test.wait(); + } catch (InterruptedException e) { + throw new RuntimeException("Failed: Interrupted"); + } + } + } + + try { + Thread.sleep(2000); + } catch (InterruptedException ex) {} + + // Grab the screen region + BufferedImage capture = null; + try { + Robot robot = new Robot(); + Point pt1 = test.getLocationOnScreen(); + Rectangle rect = new Rectangle(pt1.x, pt1.y, 400, 400); + capture = robot.createScreenCapture(rect); + } catch (Exception e) { + throw new RuntimeException("Problems creating Robot"); + } finally { + if (!show) { + frame.dispose(); + } + } + + // Test pixels + testRegion(capture, "green", 0, 0, 400, 10, 0xff00ff00); + testRegion(capture, "original red", 0, 10, 50, 400, 0xffff0000); + testRegion(capture, "background", 50, 10, 60, 400, 0xff000000); + testRegion(capture, "in-between", 60, 10, 110, 20, 0xff000000); + testRegion(capture, "copied red", 60, 20, 110, 400, 0xffff0000); + testRegion(capture, "background", 110, 10, 400, 400, 0xff000000); + } +}