提交 f1f03a8c 编写于 作者: S serb

8005255: [macosx] Cleanup warnings in sun.lwawt

Reviewed-by: alexsch, anthony
上级 a460ab1d
...@@ -110,7 +110,6 @@ FILES_export = \ ...@@ -110,7 +110,6 @@ FILES_export = \
sun/lwawt/LWWindowPeer.java \ sun/lwawt/LWWindowPeer.java \
sun/lwawt/PlatformWindow.java \ sun/lwawt/PlatformWindow.java \
sun/lwawt/SecurityWarningWindow.java \ sun/lwawt/SecurityWarningWindow.java \
sun/lwawt/SelectionClearListener.java \
sun/lwawt/macosx/CPrinterDevice.java \ sun/lwawt/macosx/CPrinterDevice.java \
sun/lwawt/macosx/CPrinterDialog.java \ sun/lwawt/macosx/CPrinterDialog.java \
sun/lwawt/macosx/CPrinterDialogPeer.java \ sun/lwawt/macosx/CPrinterDialogPeer.java \
......
/* /*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -33,6 +33,10 @@ import java.awt.peer.ButtonPeer; ...@@ -33,6 +33,10 @@ import java.awt.peer.ButtonPeer;
import javax.swing.JButton; import javax.swing.JButton;
/**
* Lightweight implementation of {@link ButtonPeer}. Delegates most of the work
* to the {@link JButton}.
*/
final class LWButtonPeer extends LWComponentPeer<Button, JButton> final class LWButtonPeer extends LWComponentPeer<Button, JButton>
implements ButtonPeer, ActionListener { implements ButtonPeer, ActionListener {
...@@ -42,7 +46,7 @@ final class LWButtonPeer extends LWComponentPeer<Button, JButton> ...@@ -42,7 +46,7 @@ final class LWButtonPeer extends LWComponentPeer<Button, JButton>
} }
@Override @Override
protected JButton createDelegate() { JButton createDelegate() {
return new JButtonDelegate(); return new JButtonDelegate();
} }
...@@ -74,6 +78,7 @@ final class LWButtonPeer extends LWComponentPeer<Button, JButton> ...@@ -74,6 +78,7 @@ final class LWButtonPeer extends LWComponentPeer<Button, JButton>
return true; return true;
} }
@SuppressWarnings("serial")// Safe: outer class is non-serializable.
private final class JButtonDelegate extends JButton { private final class JButtonDelegate extends JButton {
// Empty non private constructor was added because access to this // Empty non private constructor was added because access to this
......
/* /*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -33,6 +33,10 @@ import java.awt.peer.CanvasPeer; ...@@ -33,6 +33,10 @@ import java.awt.peer.CanvasPeer;
import javax.swing.JComponent; import javax.swing.JComponent;
/**
* Lightweight implementation of {@link CanvasPeer}. This peer is empty, because
* all the components in lwawt use graphic object from the top level window.
*/
class LWCanvasPeer<T extends Component, D extends JComponent> class LWCanvasPeer<T extends Component, D extends JComponent>
extends LWComponentPeer<T, D> implements CanvasPeer { extends LWComponentPeer<T, D> implements CanvasPeer {
......
/* /*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -41,6 +41,11 @@ import javax.swing.JRadioButton; ...@@ -41,6 +41,11 @@ import javax.swing.JRadioButton;
import javax.swing.JToggleButton; import javax.swing.JToggleButton;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
/**
* Lightweight implementation of {@link CheckboxPeer}. Delegates most of the
* work to the {@link JCheckBox} and {@link JRadioButton}, which are placed
* inside an empty {@link JComponent}.
*/
final class LWCheckboxPeer final class LWCheckboxPeer
extends LWComponentPeer<Checkbox, LWCheckboxPeer.CheckboxDelegate> extends LWComponentPeer<Checkbox, LWCheckboxPeer.CheckboxDelegate>
implements CheckboxPeer, ItemListener { implements CheckboxPeer, ItemListener {
...@@ -51,12 +56,12 @@ final class LWCheckboxPeer ...@@ -51,12 +56,12 @@ final class LWCheckboxPeer
} }
@Override @Override
protected CheckboxDelegate createDelegate() { CheckboxDelegate createDelegate() {
return new CheckboxDelegate(); return new CheckboxDelegate();
} }
@Override @Override
protected Component getDelegateFocusOwner() { Component getDelegateFocusOwner() {
return getDelegate().getCurrentButton(); return getDelegate().getCurrentButton();
} }
...@@ -137,6 +142,7 @@ final class LWCheckboxPeer ...@@ -137,6 +142,7 @@ final class LWCheckboxPeer
return true; return true;
} }
@SuppressWarnings("serial")// Safe: outer class is non-serializable.
final class CheckboxDelegate extends JComponent { final class CheckboxDelegate extends JComponent {
private final JCheckBox cb; private final JCheckBox cb;
......
...@@ -34,6 +34,10 @@ import java.awt.peer.ChoicePeer; ...@@ -34,6 +34,10 @@ import java.awt.peer.ChoicePeer;
import javax.accessibility.Accessible; import javax.accessibility.Accessible;
import javax.swing.*; import javax.swing.*;
/**
* Lightweight implementation of {@link ChoicePeer}. Delegates most of the work
* to the {@link JComboBox}.
*/
final class LWChoicePeer extends LWComponentPeer<Choice, JComboBox<String>> final class LWChoicePeer extends LWComponentPeer<Choice, JComboBox<String>>
implements ChoicePeer, ItemListener { implements ChoicePeer, ItemListener {
...@@ -50,7 +54,7 @@ final class LWChoicePeer extends LWComponentPeer<Choice, JComboBox<String>> ...@@ -50,7 +54,7 @@ final class LWChoicePeer extends LWComponentPeer<Choice, JComboBox<String>>
} }
@Override @Override
protected JComboBox<String> createDelegate() { JComboBox<String> createDelegate() {
return new JComboBoxDelegate(); return new JComboBoxDelegate();
} }
...@@ -128,6 +132,7 @@ final class LWChoicePeer extends LWComponentPeer<Choice, JComboBox<String>> ...@@ -128,6 +132,7 @@ final class LWChoicePeer extends LWComponentPeer<Choice, JComboBox<String>>
return true; return true;
} }
@SuppressWarnings("serial")// Safe: outer class is non-serializable.
private final class JComboBoxDelegate extends JComboBox<String> { private final class JComboBoxDelegate extends JComboBox<String> {
// Empty non private constructor was added because access to this // Empty non private constructor was added because access to this
......
/* /*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -72,19 +72,23 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -72,19 +72,23 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
{ {
private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWComponentPeer"); private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWComponentPeer");
// State lock is to be used for modifications to this /**
// peer's fields (e.g. bounds, background, font, etc.) * State lock is to be used for modifications to this peer's fields (e.g.
// It should be the last lock in the lock chain * bounds, background, font, etc.) It should be the last lock in the lock
private final Object stateLock = * chain
new StringBuilder("LWComponentPeer.stateLock"); */
private final Object stateLock = new Object();
// The lock to operate with the peers hierarchy. AWT tree /**
// lock is not used as there are many peers related ops * The lock to operate with the peers hierarchy. AWT tree lock is not used
// to be done on the toolkit thread, and we don't want to * as there are many peers related ops to be done on the toolkit thread, and
// depend on a public lock on this thread * we don't want to depend on a public lock on this thread
private static final Object peerTreeLock = */
new StringBuilder("LWComponentPeer.peerTreeLock"); private static final Object peerTreeLock = new Object();
/**
* The associated AWT object.
*/
private final T target; private final T target;
/** /**
...@@ -95,7 +99,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -95,7 +99,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
* the hierarchy. The exception is LWWindowPeers: their containers are * the hierarchy. The exception is LWWindowPeers: their containers are
* always null * always null
*/ */
private final LWContainerPeer containerPeer; private final LWContainerPeer<?, ?> containerPeer;
/** /**
* Handy reference to the top-level window peer. Window peer is borrowed * Handy reference to the top-level window peer. Window peer is borrowed
...@@ -147,11 +151,18 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -147,11 +151,18 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
*/ */
private Image backBuffer; private Image backBuffer;
/**
* All Swing delegates use delegateContainer as a parent. This container
* intentionally do not use parent of the peer.
*/
@SuppressWarnings("serial")// Safe: outer class is non-serializable.
private final class DelegateContainer extends Container { private final class DelegateContainer extends Container {
{ {
enableEvents(0xFFFFFFFF); enableEvents(0xFFFFFFFF);
} }
// Empty non private constructor was added because access to this
// class shouldn't be emulated by a synthetic accessor method.
DelegateContainer() { DelegateContainer() {
super(); super();
} }
...@@ -182,7 +193,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -182,7 +193,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
} }
} }
public LWComponentPeer(T target, PlatformComponent platformComponent) { LWComponentPeer(final T target, final PlatformComponent platformComponent) {
targetPaintArea = new LWRepaintArea(); targetPaintArea = new LWRepaintArea();
this.target = target; this.target = target;
this.platformComponent = platformComponent; this.platformComponent = platformComponent;
...@@ -276,15 +287,18 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -276,15 +287,18 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
* This method is called under getDelegateLock(). * This method is called under getDelegateLock().
* Overridden in subclasses. * Overridden in subclasses.
*/ */
protected D createDelegate() { D createDelegate() {
return null; return null;
} }
protected final D getDelegate() { final D getDelegate() {
return delegate; return delegate;
} }
protected Component getDelegateFocusOwner() { /**
* This method should be called under getDelegateLock().
*/
Component getDelegateFocusOwner() {
return getDelegate(); return getDelegate();
} }
...@@ -356,7 +370,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -356,7 +370,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
} }
// Just a helper method // Just a helper method
protected final LWContainerPeer getContainerPeer() { protected final LWContainerPeer<?, ?> getContainerPeer() {
return containerPeer; return containerPeer;
} }
...@@ -390,7 +404,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -390,7 +404,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
protected void disposeImpl() { protected void disposeImpl() {
destroyBuffers(); destroyBuffers();
LWContainerPeer cp = getContainerPeer(); LWContainerPeer<?, ?> cp = getContainerPeer();
if (cp != null) { if (cp != null) {
cp.removeChildPeer(this); cp.removeChildPeer(this);
} }
...@@ -462,12 +476,13 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -462,12 +476,13 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
sg2d.constrain(size.x, size.y, size.width, size.height, getVisibleRegion()); sg2d.constrain(size.x, size.y, size.width, size.height, getVisibleRegion());
} }
public Region getVisibleRegion() { Region getVisibleRegion() {
return computeVisibleRect(this, getRegion()); return computeVisibleRect(this, getRegion());
} }
static final Region computeVisibleRect(LWComponentPeer c, Region region) { static final Region computeVisibleRect(final LWComponentPeer<?, ?> c,
final LWContainerPeer p = c.getContainerPeer(); Region region) {
final LWContainerPeer<?, ?> p = c.getContainerPeer();
if (p != null) { if (p != null) {
final Rectangle r = c.getBounds(); final Rectangle r = c.getBounds();
region = region.getTranslatedRegion(r.x, r.y); region = region.getTranslatedRegion(r.x, r.y);
...@@ -612,7 +627,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -612,7 +627,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
* @param p Point relative to the peer. * @param p Point relative to the peer.
* @return Cursor of the peer or null if default cursor should be used. * @return Cursor of the peer or null if default cursor should be used.
*/ */
protected Cursor getCursor(final Point p) { Cursor getCursor(final Point p) {
return getTarget().getCursor(); return getTarget().getCursor();
} }
...@@ -717,7 +732,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -717,7 +732,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
@Override @Override
public void setEnabled(final boolean e) { public void setEnabled(final boolean e) {
boolean status = e; boolean status = e;
final LWComponentPeer cp = getContainerPeer(); final LWComponentPeer<?, ?> cp = getContainerPeer();
if (cp != null) { if (cp != null) {
status &= cp.isEnabled(); status &= cp.isEnabled();
} }
...@@ -802,12 +817,12 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -802,12 +817,12 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
} }
@Override @Override
public void setZOrder(ComponentPeer above) { public void setZOrder(final ComponentPeer above) {
LWContainerPeer cp = getContainerPeer(); LWContainerPeer<?, ?> cp = getContainerPeer();
// Don't check containerPeer for null as it can only happen // Don't check containerPeer for null as it can only happen
// for windows, but this method is overridden in // for windows, but this method is overridden in
// LWWindowPeer and doesn't call super() // LWWindowPeer and doesn't call super()
cp.setChildPeerZOrder(this, (LWComponentPeer) above); cp.setChildPeerZOrder(this, (LWComponentPeer<?, ?>) above);
} }
@Override @Override
...@@ -923,7 +938,9 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -923,7 +938,9 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
LWKeyboardFocusManagerPeer.removeLastFocusRequest(getTarget()); LWKeyboardFocusManagerPeer.removeLastFocusRequest(getTarget());
return false; return false;
} }
LWWindowPeer parentPeer = (LWWindowPeer) parentWindow.getPeer(); final LWWindowPeer parentPeer =
(LWWindowPeer) AWTAccessor.getComponentAccessor()
.getPeer(parentWindow);
if (parentPeer == null) { if (parentPeer == null) {
focusLog.fine("request rejected, parentPeer is null"); focusLog.fine("request rejected, parentPeer is null");
LWKeyboardFocusManagerPeer.removeLastFocusRequest(getTarget()); LWKeyboardFocusManagerPeer.removeLastFocusRequest(getTarget());
...@@ -1138,7 +1155,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -1138,7 +1155,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
} }
protected final void repaintParent(final Rectangle oldB) { protected final void repaintParent(final Rectangle oldB) {
final LWContainerPeer cp = getContainerPeer(); final LWContainerPeer<?, ?> cp = getContainerPeer();
if (cp != null) { if (cp != null) {
// Repaint unobscured part of the parent // Repaint unobscured part of the parent
cp.repaintPeer(cp.getContentSize().intersection(oldB)); cp.repaintPeer(cp.getContentSize().intersection(oldB));
...@@ -1275,7 +1292,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -1275,7 +1292,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
/** /**
* Handler for FocusEvents. * Handler for FocusEvents.
*/ */
protected void handleJavaFocusEvent(FocusEvent e) { void handleJavaFocusEvent(final FocusEvent e) {
// Note that the peer receives all the FocusEvents from // Note that the peer receives all the FocusEvents from
// its lightweight children as well // its lightweight children as well
KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance(); KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
...@@ -1311,7 +1328,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -1311,7 +1328,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
* Finds a top-most visible component for the given point. The location is * Finds a top-most visible component for the given point. The location is
* specified relative to the peer's parent. * specified relative to the peer's parent.
*/ */
public LWComponentPeer findPeerAt(final int x, final int y) { LWComponentPeer<?, ?> findPeerAt(final int x, final int y) {
final Rectangle r = getBounds(); final Rectangle r = getBounds();
final Region sh = getRegion(); final Region sh = getRegion();
final boolean found = isVisible() && sh.contains(x - r.x, y - r.y); final boolean found = isVisible() && sh.contains(x - r.x, y - r.y);
...@@ -1328,7 +1345,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -1328,7 +1345,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
} }
public Point windowToLocal(Point p, LWWindowPeer wp) { public Point windowToLocal(Point p, LWWindowPeer wp) {
LWComponentPeer cp = this; LWComponentPeer<?, ?> cp = this;
while (cp != wp) { while (cp != wp) {
Rectangle cpb = cp.getBounds(); Rectangle cpb = cp.getBounds();
p.x -= cpb.x; p.x -= cpb.x;
...@@ -1349,7 +1366,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -1349,7 +1366,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
} }
public Point localToWindow(Point p) { public Point localToWindow(Point p) {
LWComponentPeer cp = getContainerPeer(); LWComponentPeer<?, ?> cp = getContainerPeer();
Rectangle r = getBounds(); Rectangle r = getBounds();
while (cp != null) { while (cp != null) {
p.x += r.x; p.x += r.x;
...@@ -1370,7 +1387,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -1370,7 +1387,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
repaintPeer(getSize()); repaintPeer(getSize());
} }
public void repaintPeer(final Rectangle r) { void repaintPeer(final Rectangle r) {
final Rectangle toPaint = getSize().intersection(r); final Rectangle toPaint = getSize().intersection(r);
if (!isShowing() || toPaint.isEmpty()) { if (!isShowing() || toPaint.isEmpty()) {
return; return;
...@@ -1389,7 +1406,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -1389,7 +1406,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
protected final boolean isShowing() { protected final boolean isShowing() {
synchronized (getPeerTreeLock()) { synchronized (getPeerTreeLock()) {
if (isVisible()) { if (isVisible()) {
final LWContainerPeer container = getContainerPeer(); final LWContainerPeer<?, ?> container = getContainerPeer();
return (container == null) || container.isShowing(); return (container == null) || container.isShowing();
} }
} }
...@@ -1397,8 +1414,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent> ...@@ -1397,8 +1414,7 @@ public abstract class LWComponentPeer<T extends Component, D extends JComponent>
} }
/** /**
* Paints the peer. Overridden in subclasses to delegate the actual painting * Paints the peer. Delegate the actual painting to Swing components.
* to Swing components.
*/ */
protected final void paintPeer(final Graphics g) { protected final void paintPeer(final Graphics g) {
final D delegate = getDelegate(); final D delegate = getDelegate();
......
/* /*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -41,32 +41,25 @@ import java.util.List; ...@@ -41,32 +41,25 @@ import java.util.List;
import javax.swing.JComponent; import javax.swing.JComponent;
abstract class LWContainerPeer<T extends Container, D extends JComponent> abstract class LWContainerPeer<T extends Container, D extends JComponent>
extends LWCanvasPeer<T, D> extends LWCanvasPeer<T, D> implements ContainerPeer {
implements ContainerPeer
{
// List of child peers sorted by z-order from bottom-most
// to top-most
private List<LWComponentPeer> childPeers =
new LinkedList<LWComponentPeer>();
LWContainerPeer(T target, PlatformComponent platformComponent) {
super(target, platformComponent);
}
void addChildPeer(LWComponentPeer child) { /**
synchronized (getPeerTreeLock()) { * List of child peers sorted by z-order from bottom-most to top-most.
addChildPeer(child, childPeers.size()); */
} private final List<LWComponentPeer<?, ?>> childPeers = new LinkedList<>();
LWContainerPeer(final T target, final PlatformComponent platformComponent) {
super(target, platformComponent);
} }
void addChildPeer(LWComponentPeer child, int index) { final void addChildPeer(final LWComponentPeer<?, ?> child) {
synchronized (getPeerTreeLock()) { synchronized (getPeerTreeLock()) {
childPeers.add(index, child); childPeers.add(childPeers.size(), child);
// TODO: repaint
} }
// TODO: repaint
} }
void removeChildPeer(LWComponentPeer child) { final void removeChildPeer(final LWComponentPeer<?, ?> child) {
synchronized (getPeerTreeLock()) { synchronized (getPeerTreeLock()) {
childPeers.remove(child); childPeers.remove(child);
} }
...@@ -74,7 +67,8 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent> ...@@ -74,7 +67,8 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent>
} }
// Used by LWComponentPeer.setZOrder() // Used by LWComponentPeer.setZOrder()
void setChildPeerZOrder(LWComponentPeer peer, LWComponentPeer above) { final void setChildPeerZOrder(final LWComponentPeer<?, ?> peer,
final LWComponentPeer<?, ?> above) {
synchronized (getPeerTreeLock()) { synchronized (getPeerTreeLock()) {
childPeers.remove(peer); childPeers.remove(peer);
int index = (above != null) ? childPeers.indexOf(above) : childPeers.size(); int index = (above != null) ? childPeers.indexOf(above) : childPeers.size();
...@@ -98,25 +92,27 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent> ...@@ -98,25 +92,27 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent>
} }
@Override @Override
public void beginValidate() { public final void beginValidate() {
// TODO: it seems that begin/endValidate() is only useful // TODO: it seems that begin/endValidate() is only useful
// for heavyweight windows, when a batch movement for // for heavyweight windows, when a batch movement for
// child windows occurs. That's why no-op // child windows occurs. That's why no-op
} }
@Override @Override
public void endValidate() { public final void endValidate() {
// TODO: it seems that begin/endValidate() is only useful // TODO: it seems that begin/endValidate() is only useful
// for heavyweight windows, when a batch movement for // for heavyweight windows, when a batch movement for
// child windows occurs. That's why no-op // child windows occurs. That's why no-op
} }
@Override @Override
public void beginLayout() { public final void beginLayout() {
// Skip all painting till endLayout() // Skip all painting till endLayout()
setLayouting(true); setLayouting(true);
} }
@Override @Override
public void endLayout() { public final void endLayout() {
setLayouting(false); setLayouting(false);
// Post an empty event to flush all the pending target paints // Post an empty event to flush all the pending target paints
...@@ -125,18 +121,19 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent> ...@@ -125,18 +121,19 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent>
// ---- PEER NOTIFICATIONS ---- // // ---- PEER NOTIFICATIONS ---- //
/* /**
* Returns a copy of the childPeer collection. * Returns a copy of the childPeer collection.
*/ */
protected List<LWComponentPeer> getChildren() { @SuppressWarnings("unchecked")
final List<LWComponentPeer<?, ?>> getChildren() {
synchronized (getPeerTreeLock()) { synchronized (getPeerTreeLock()) {
Object copy = ((LinkedList)childPeers).clone(); Object copy = ((LinkedList<?>) childPeers).clone();
return (List<LWComponentPeer>)copy; return (List<LWComponentPeer<?, ?>>) copy;
} }
} }
@Override @Override
public final Region getVisibleRegion() { final Region getVisibleRegion() {
return cutChildren(super.getVisibleRegion(), null); return cutChildren(super.getVisibleRegion(), null);
} }
...@@ -144,9 +141,9 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent> ...@@ -144,9 +141,9 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent>
* Removes bounds of children above specific child from the region. If above * Removes bounds of children above specific child from the region. If above
* is null removes all bounds of children. * is null removes all bounds of children.
*/ */
protected final Region cutChildren(Region r, final LWComponentPeer above) { final Region cutChildren(Region r, final LWComponentPeer<?, ?> above) {
boolean aboveFound = above == null; boolean aboveFound = above == null;
for (final LWComponentPeer child : getChildren()) { for (final LWComponentPeer<?, ?> child : getChildren()) {
if (!aboveFound && child == above) { if (!aboveFound && child == above) {
aboveFound = true; aboveFound = true;
continue; continue;
...@@ -170,8 +167,8 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent> ...@@ -170,8 +167,8 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent>
* specified relative to the peer's parent. * specified relative to the peer's parent.
*/ */
@Override @Override
public final LWComponentPeer findPeerAt(int x, int y) { final LWComponentPeer<?, ?> findPeerAt(int x, int y) {
LWComponentPeer peer = super.findPeerAt(x, y); LWComponentPeer<?, ?> peer = super.findPeerAt(x, y);
final Rectangle r = getBounds(); final Rectangle r = getBounds();
// Translate to this container's coordinates to pass to children // Translate to this container's coordinates to pass to children
x -= r.x; x -= r.x;
...@@ -179,7 +176,7 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent> ...@@ -179,7 +176,7 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent>
if (peer != null && getContentSize().contains(x, y)) { if (peer != null && getContentSize().contains(x, y)) {
synchronized (getPeerTreeLock()) { synchronized (getPeerTreeLock()) {
for (int i = childPeers.size() - 1; i >= 0; --i) { for (int i = childPeers.size() - 1; i >= 0; --i) {
LWComponentPeer p = childPeers.get(i).findPeerAt(x, y); LWComponentPeer<?, ?> p = childPeers.get(i).findPeerAt(x, y);
if (p != null) { if (p != null) {
peer = p; peer = p;
break; break;
...@@ -195,7 +192,7 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent> ...@@ -195,7 +192,7 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent>
* peers should be repainted * peers should be repainted
*/ */
@Override @Override
public final void repaintPeer(final Rectangle r) { final void repaintPeer(final Rectangle r) {
final Rectangle toPaint = getSize().intersection(r); final Rectangle toPaint = getSize().intersection(r);
if (!isShowing() || toPaint.isEmpty()) { if (!isShowing() || toPaint.isEmpty()) {
return; return;
...@@ -208,13 +205,13 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent> ...@@ -208,13 +205,13 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent>
repaintChildren(toPaint); repaintChildren(toPaint);
} }
/* /**
* Paints all the child peers in the straight z-order, so the * Paints all the child peers in the straight z-order, so the
* bottom-most ones are painted first. * bottom-most ones are painted first.
*/ */
private void repaintChildren(final Rectangle r) { private void repaintChildren(final Rectangle r) {
final Rectangle content = getContentSize(); final Rectangle content = getContentSize();
for (final LWComponentPeer child : getChildren()) { for (final LWComponentPeer<?, ?> child : getChildren()) {
final Rectangle childBounds = child.getBounds(); final Rectangle childBounds = child.getBounds();
Rectangle toPaint = r.intersection(childBounds); Rectangle toPaint = r.intersection(childBounds);
toPaint = toPaint.intersection(content); toPaint = toPaint.intersection(content);
...@@ -223,21 +220,21 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent> ...@@ -223,21 +220,21 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent>
} }
} }
protected Rectangle getContentSize() { Rectangle getContentSize() {
return getSize(); return getSize();
} }
@Override @Override
public void setEnabled(final boolean e) { public void setEnabled(final boolean e) {
super.setEnabled(e); super.setEnabled(e);
for (final LWComponentPeer child : getChildren()) { for (final LWComponentPeer<?, ?> child : getChildren()) {
child.setEnabled(e && child.getTarget().isEnabled()); child.setEnabled(e && child.getTarget().isEnabled());
} }
} }
@Override @Override
public void setBackground(final Color c) { public void setBackground(final Color c) {
for (final LWComponentPeer child : getChildren()) { for (final LWComponentPeer<?, ?> child : getChildren()) {
if (!child.getTarget().isBackgroundSet()) { if (!child.getTarget().isBackgroundSet()) {
child.setBackground(c); child.setBackground(c);
} }
...@@ -247,7 +244,7 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent> ...@@ -247,7 +244,7 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent>
@Override @Override
public void setForeground(final Color c) { public void setForeground(final Color c) {
for (final LWComponentPeer child : getChildren()) { for (final LWComponentPeer<?, ?> child : getChildren()) {
if (!child.getTarget().isForegroundSet()) { if (!child.getTarget().isForegroundSet()) {
child.setForeground(c); child.setForeground(c);
} }
...@@ -257,7 +254,7 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent> ...@@ -257,7 +254,7 @@ abstract class LWContainerPeer<T extends Container, D extends JComponent>
@Override @Override
public void setFont(final Font f) { public void setFont(final Font f) {
for (final LWComponentPeer child : getChildren()) { for (final LWComponentPeer<?, ?> child : getChildren()) {
if (!child.getTarget().isFontSet()) { if (!child.getTarget().isFontSet()) {
child.setFont(f); child.setFont(f);
} }
......
/* /*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -32,6 +32,7 @@ import java.awt.Point; ...@@ -32,6 +32,7 @@ import java.awt.Point;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import sun.awt.AWTAccessor;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
public abstract class LWCursorManager { public abstract class LWCursorManager {
...@@ -109,7 +110,8 @@ public abstract class LWCursorManager { ...@@ -109,7 +110,8 @@ public abstract class LWCursorManager {
cursorPos.y - p.y); cursorPos.y - p.y);
} }
while (c != null) { while (c != null) {
if (c.isVisible() && c.isEnabled() && (c.getPeer() != null)) { final Object p = AWTAccessor.getComponentAccessor().getPeer(c);
if (c.isVisible() && c.isEnabled() && p != null) {
break; break;
} }
c = c.getParent(); c = c.getParent();
......
/* /*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -44,7 +44,7 @@ final class LWLabelPeer extends LWComponentPeer<Label, JLabel> ...@@ -44,7 +44,7 @@ final class LWLabelPeer extends LWComponentPeer<Label, JLabel>
} }
@Override @Override
protected JLabel createDelegate() { JLabel createDelegate() {
return new JLabel(); return new JLabel();
} }
......
/* /*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -33,7 +33,8 @@ import java.awt.peer.ListPeer; ...@@ -33,7 +33,8 @@ import java.awt.peer.ListPeer;
import java.util.Arrays; import java.util.Arrays;
/** /**
* Lightweight implementation of {@link ListPeer}. * Lightweight implementation of {@link ListPeer}. Delegates most of the work to
* the {@link JList}, which is placed inside {@link JScrollPane}.
*/ */
final class LWListPeer extends LWComponentPeer<List, LWListPeer.ScrollableJList> final class LWListPeer extends LWComponentPeer<List, LWListPeer.ScrollableJList>
implements ListPeer { implements ListPeer {
...@@ -56,7 +57,7 @@ final class LWListPeer extends LWComponentPeer<List, LWListPeer.ScrollableJList> ...@@ -56,7 +57,7 @@ final class LWListPeer extends LWComponentPeer<List, LWListPeer.ScrollableJList>
} }
@Override @Override
protected ScrollableJList createDelegate() { ScrollableJList createDelegate() {
return new ScrollableJList(); return new ScrollableJList();
} }
...@@ -78,7 +79,7 @@ final class LWListPeer extends LWComponentPeer<List, LWListPeer.ScrollableJList> ...@@ -78,7 +79,7 @@ final class LWListPeer extends LWComponentPeer<List, LWListPeer.ScrollableJList>
} }
@Override @Override
protected Component getDelegateFocusOwner() { Component getDelegateFocusOwner() {
return getDelegate().getView(); return getDelegate().getView();
} }
...@@ -193,6 +194,7 @@ final class LWListPeer extends LWComponentPeer<List, LWListPeer.ScrollableJList> ...@@ -193,6 +194,7 @@ final class LWListPeer extends LWComponentPeer<List, LWListPeer.ScrollableJList>
} }
} }
@SuppressWarnings("serial")// Safe: outer class is non-serializable.
final class ScrollableJList extends JScrollPane implements ListSelectionListener { final class ScrollableJList extends JScrollPane implements ListSelectionListener {
private boolean skipStateChangedEvent; private boolean skipStateChangedEvent;
...@@ -234,9 +236,10 @@ final class LWListPeer extends LWComponentPeer<List, LWListPeer.ScrollableJList> ...@@ -234,9 +236,10 @@ final class LWListPeer extends LWComponentPeer<List, LWListPeer.ScrollableJList>
} }
@Override @Override
@SuppressWarnings("unchecked")
public void valueChanged(final ListSelectionEvent e) { public void valueChanged(final ListSelectionEvent e) {
if (!e.getValueIsAdjusting() && !isSkipStateChangedEvent()) { if (!e.getValueIsAdjusting() && !isSkipStateChangedEvent()) {
final JList source = (JList) e.getSource(); final JList<?> source = (JList<?>) e.getSource();
for(int i = 0 ; i < source.getModel().getSize(); i++) { for(int i = 0 ; i < source.getModel().getSize(); i++) {
final boolean wasSelected = Arrays.binarySearch(oldSelectedIndices, i) >= 0; final boolean wasSelected = Arrays.binarySearch(oldSelectedIndices, i) >= 0;
...@@ -255,6 +258,7 @@ final class LWListPeer extends LWComponentPeer<List, LWListPeer.ScrollableJList> ...@@ -255,6 +258,7 @@ final class LWListPeer extends LWComponentPeer<List, LWListPeer.ScrollableJList>
} }
} }
@SuppressWarnings("unchecked")
public JList<String> getView() { public JList<String> getView() {
return (JList<String>) getViewport().getView(); return (JList<String>) getViewport().getView();
} }
...@@ -289,7 +293,7 @@ final class LWListPeer extends LWComponentPeer<List, LWListPeer.ScrollableJList> ...@@ -289,7 +293,7 @@ final class LWListPeer extends LWComponentPeer<List, LWListPeer.ScrollableJList>
private final class JListDelegate extends JList<String> { private final class JListDelegate extends JList<String> {
JListDelegate() { JListDelegate() {
super(ScrollableJList.this.model); super(model);
} }
@Override @Override
......
/* /*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -30,10 +30,9 @@ import java.awt.Window; ...@@ -30,10 +30,9 @@ import java.awt.Window;
import java.awt.peer.MouseInfoPeer; import java.awt.peer.MouseInfoPeer;
public class LWMouseInfoPeer implements MouseInfoPeer { import sun.awt.AWTAccessor;
public LWMouseInfoPeer() { public class LWMouseInfoPeer implements MouseInfoPeer {
}
@Override @Override
public int fillPointWithCoords(Point point) { public int fillPointWithCoords(Point point) {
...@@ -52,7 +51,7 @@ public class LWMouseInfoPeer implements MouseInfoPeer { ...@@ -52,7 +51,7 @@ public class LWMouseInfoPeer implements MouseInfoPeer {
return false; return false;
} }
LWWindowPeer windowPeer = (LWWindowPeer)w.getPeer(); final Object windowPeer = AWTAccessor.getComponentAccessor().getPeer(w);
return LWWindowPeer.getWindowUnderCursor() == windowPeer; return LWWindowPeer.getWindowUnderCursor() == windowPeer;
} }
......
/* /*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -31,6 +31,10 @@ import java.awt.peer.PanelPeer; ...@@ -31,6 +31,10 @@ import java.awt.peer.PanelPeer;
import javax.swing.JPanel; import javax.swing.JPanel;
/**
* Lightweight implementation of {@link PanelPeer}. Delegates most of the work
* to the {@link JPanel}.
*/
final class LWPanelPeer extends LWContainerPeer<Panel, JPanel> final class LWPanelPeer extends LWContainerPeer<Panel, JPanel>
implements PanelPeer { implements PanelPeer {
...@@ -39,7 +43,7 @@ final class LWPanelPeer extends LWContainerPeer<Panel, JPanel> ...@@ -39,7 +43,7 @@ final class LWPanelPeer extends LWContainerPeer<Panel, JPanel>
} }
@Override @Override
public JPanel createDelegate() { JPanel createDelegate() {
return new JPanel(); return new JPanel();
} }
} }
/* /*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,39 +26,38 @@ ...@@ -26,39 +26,38 @@
package sun.lwawt; package sun.lwawt;
import sun.awt.RepaintArea;
import java.awt.Component; import java.awt.Component;
import java.awt.Graphics; import java.awt.Graphics;
import sun.awt.AWTAccessor;
import sun.awt.RepaintArea;
/** /**
* Emulates appearance of heavyweight components before call of the user code.
*
* @author Sergey Bylokhov * @author Sergey Bylokhov
*/ */
final class LWRepaintArea extends RepaintArea { final class LWRepaintArea extends RepaintArea {
@Override @Override
protected void updateComponent(final Component comp, final Graphics g) { protected void updateComponent(final Component comp, final Graphics g) {
// We shouldn't paint native component as a result of UPDATE events,
// just flush onscreen back-buffer.
if (comp != null) { if (comp != null) {
super.updateComponent(comp, g); super.updateComponent(comp, g);
flushBuffers((LWComponentPeer) comp.getPeer()); LWComponentPeer.flushOnscreenGraphics();
} }
} }
@Override @Override
protected void paintComponent(final Component comp, final Graphics g) { protected void paintComponent(final Component comp, final Graphics g) {
if (comp != null) { if (comp != null) {
final LWComponentPeer peer = (LWComponentPeer) comp.getPeer(); Object peer = AWTAccessor.getComponentAccessor().getPeer(comp);
if (peer != null) { if (peer != null) {
peer.paintPeer(g); ((LWComponentPeer<?, ?>) peer).paintPeer(g);
} }
super.paintComponent(comp, g); super.paintComponent(comp, g);
flushBuffers(peer); LWComponentPeer.flushOnscreenGraphics();
}
}
private static void flushBuffers(final LWComponentPeer peer) {
if (peer != null) {
peer.flushOnscreenGraphics();
} }
} }
} }
...@@ -34,10 +34,14 @@ import java.awt.peer.ScrollbarPeer; ...@@ -34,10 +34,14 @@ import java.awt.peer.ScrollbarPeer;
import javax.swing.JScrollBar; import javax.swing.JScrollBar;
/**
* Lightweight implementation of {@link ScrollbarPeer}. Delegates most of the
* work to the {@link JScrollBar}.
*/
final class LWScrollBarPeer extends LWComponentPeer<Scrollbar, JScrollBar> final class LWScrollBarPeer extends LWComponentPeer<Scrollbar, JScrollBar>
implements ScrollbarPeer, AdjustmentListener { implements ScrollbarPeer, AdjustmentListener {
//JScrollBar fires two changes with firePropertyChange (one for old value // JScrollBar fires two changes with firePropertyChange (one for old value
// and one for new one. // and one for new one.
// We save the last value and don't fire event if not changed. // We save the last value and don't fire event if not changed.
private int currentValue; private int currentValue;
...@@ -48,7 +52,7 @@ final class LWScrollBarPeer extends LWComponentPeer<Scrollbar, JScrollBar> ...@@ -48,7 +52,7 @@ final class LWScrollBarPeer extends LWComponentPeer<Scrollbar, JScrollBar>
} }
@Override @Override
protected JScrollBar createDelegate() { JScrollBar createDelegate() {
return new JScrollBar(); return new JScrollBar();
} }
......
/* /*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -33,6 +33,10 @@ import java.awt.event.MouseWheelEvent; ...@@ -33,6 +33,10 @@ import java.awt.event.MouseWheelEvent;
import java.awt.peer.ScrollPanePeer; import java.awt.peer.ScrollPanePeer;
import java.util.List; import java.util.List;
/**
* Lightweight implementation of {@link ScrollPanePeer}. Delegates most of the
* work to the {@link JScrollPane}.
*/
final class LWScrollPanePeer extends LWContainerPeer<ScrollPane, JScrollPane> final class LWScrollPanePeer extends LWContainerPeer<ScrollPane, JScrollPane>
implements ScrollPanePeer, ChangeListener { implements ScrollPanePeer, ChangeListener {
...@@ -41,7 +45,8 @@ final class LWScrollPanePeer extends LWContainerPeer<ScrollPane, JScrollPane> ...@@ -41,7 +45,8 @@ final class LWScrollPanePeer extends LWContainerPeer<ScrollPane, JScrollPane>
super(target, platformComponent); super(target, platformComponent);
} }
protected JScrollPane createDelegate() { @Override
JScrollPane createDelegate() {
final JScrollPane sp = new JScrollPane(); final JScrollPane sp = new JScrollPane();
final JPanel panel = new JPanel(); final JPanel panel = new JPanel();
panel.setOpaque(false); panel.setOpaque(false);
...@@ -72,7 +77,7 @@ final class LWScrollPanePeer extends LWContainerPeer<ScrollPane, JScrollPane> ...@@ -72,7 +77,7 @@ final class LWScrollPanePeer extends LWContainerPeer<ScrollPane, JScrollPane>
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override
public void run() { public void run() {
final LWComponentPeer viewPeer = getViewPeer(); final LWComponentPeer<?, ?> viewPeer = getViewPeer();
if (viewPeer != null) { if (viewPeer != null) {
final Rectangle r; final Rectangle r;
synchronized (getDelegateLock()) { synchronized (getDelegateLock()) {
...@@ -96,14 +101,13 @@ final class LWScrollPanePeer extends LWContainerPeer<ScrollPane, JScrollPane> ...@@ -96,14 +101,13 @@ final class LWScrollPanePeer extends LWContainerPeer<ScrollPane, JScrollPane>
} }
} }
LWComponentPeer getViewPeer() { LWComponentPeer<?, ?> getViewPeer() {
List<LWComponentPeer> peerList = getChildren(); final List<LWComponentPeer<?, ?>> peerList = getChildren();
return peerList.isEmpty() ? null : peerList.get(0); return peerList.isEmpty() ? null : peerList.get(0);
} }
@Override @Override
protected Rectangle getContentSize() { Rectangle getContentSize() {
Rectangle viewRect = getDelegate().getViewport().getViewRect(); Rectangle viewRect = getDelegate().getViewport().getViewRect();
return new Rectangle(viewRect.width, viewRect.height); return new Rectangle(viewRect.width, viewRect.height);
} }
...@@ -112,7 +116,7 @@ final class LWScrollPanePeer extends LWContainerPeer<ScrollPane, JScrollPane> ...@@ -112,7 +116,7 @@ final class LWScrollPanePeer extends LWContainerPeer<ScrollPane, JScrollPane>
public void layout() { public void layout() {
super.layout(); super.layout();
synchronized (getDelegateLock()) { synchronized (getDelegateLock()) {
LWComponentPeer viewPeer = getViewPeer(); final LWComponentPeer<?, ?> viewPeer = getViewPeer();
if (viewPeer != null) { if (viewPeer != null) {
Component view = getDelegate().getViewport().getView(); Component view = getDelegate().getViewport().getView();
view.setBounds(viewPeer.getBounds()); view.setBounds(viewPeer.getBounds());
......
/* /*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -44,7 +44,7 @@ import javax.swing.text.JTextComponent; ...@@ -44,7 +44,7 @@ import javax.swing.text.JTextComponent;
/** /**
* Lightweight implementation of {@link TextAreaPeer}. Delegates most of the * Lightweight implementation of {@link TextAreaPeer}. Delegates most of the
* work to the {@link JTextArea} inside JScrollPane. * work to the {@link JTextArea} inside {@link JScrollPane}.
*/ */
final class LWTextAreaPeer final class LWTextAreaPeer
extends LWTextComponentPeer<TextArea, LWTextAreaPeer.ScrollableJTextArea> extends LWTextComponentPeer<TextArea, LWTextAreaPeer.ScrollableJTextArea>
...@@ -66,7 +66,7 @@ final class LWTextAreaPeer ...@@ -66,7 +66,7 @@ final class LWTextAreaPeer
} }
@Override @Override
protected ScrollableJTextArea createDelegate() { ScrollableJTextArea createDelegate() {
return new ScrollableJTextArea(); return new ScrollableJTextArea();
} }
...@@ -85,7 +85,7 @@ final class LWTextAreaPeer ...@@ -85,7 +85,7 @@ final class LWTextAreaPeer
} }
@Override @Override
protected Cursor getCursor(final Point p) { Cursor getCursor(final Point p) {
final boolean isContains; final boolean isContains;
synchronized (getDelegateLock()) { synchronized (getDelegateLock()) {
isContains = getDelegate().getViewport().getBounds().contains(p); isContains = getDelegate().getViewport().getBounds().contains(p);
...@@ -94,7 +94,7 @@ final class LWTextAreaPeer ...@@ -94,7 +94,7 @@ final class LWTextAreaPeer
} }
@Override @Override
protected Component getDelegateFocusOwner() { Component getDelegateFocusOwner() {
return getTextComponent(); return getTextComponent();
} }
...@@ -200,7 +200,7 @@ final class LWTextAreaPeer ...@@ -200,7 +200,7 @@ final class LWTextAreaPeer
} }
} }
@SuppressWarnings("serial") @SuppressWarnings("serial")// Safe: outer class is non-serializable.
final class ScrollableJTextArea extends JScrollPane { final class ScrollableJTextArea extends JScrollPane {
ScrollableJTextArea() { ScrollableJTextArea() {
...@@ -218,7 +218,6 @@ final class LWTextAreaPeer ...@@ -218,7 +218,6 @@ final class LWTextAreaPeer
super.setEnabled(enabled); super.setEnabled(enabled);
} }
@SuppressWarnings("serial")
private final class JTextAreaDelegate extends JTextArea { private final class JTextAreaDelegate extends JTextArea {
// Empty non private constructor was added because access to this // Empty non private constructor was added because access to this
......
/* /*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -44,11 +44,14 @@ import javax.swing.event.DocumentListener; ...@@ -44,11 +44,14 @@ import javax.swing.event.DocumentListener;
import javax.swing.text.Document; import javax.swing.text.Document;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
/**
* Lightweight implementation of {@link TextComponentPeer}. Provides useful
* methods for {@link LWTextAreaPeer} and {@link LWTextFieldPeer}
*/
abstract class LWTextComponentPeer<T extends TextComponent, D extends JComponent> abstract class LWTextComponentPeer<T extends TextComponent, D extends JComponent>
extends LWComponentPeer<T, D> extends LWComponentPeer<T, D>
implements DocumentListener, TextComponentPeer, InputMethodListener { implements DocumentListener, TextComponentPeer, InputMethodListener {
private volatile boolean firstChangeSkipped; private volatile boolean firstChangeSkipped;
LWTextComponentPeer(final T target, LWTextComponentPeer(final T target,
...@@ -218,14 +221,14 @@ abstract class LWTextComponentPeer<T extends TextComponent, D extends JComponent ...@@ -218,14 +221,14 @@ abstract class LWTextComponentPeer<T extends TextComponent, D extends JComponent
} }
@Override @Override
public void inputMethodTextChanged(InputMethodEvent event) { public void inputMethodTextChanged(final InputMethodEvent event) {
synchronized (getDelegateLock()) { synchronized (getDelegateLock()) {
AWTAccessor.getComponentAccessor().processEvent(getTextComponent(), event); AWTAccessor.getComponentAccessor().processEvent(getTextComponent(), event);
} }
} }
@Override @Override
public void caretPositionChanged(InputMethodEvent event) { public void caretPositionChanged(final InputMethodEvent event) {
synchronized (getDelegateLock()) { synchronized (getDelegateLock()) {
AWTAccessor.getComponentAccessor().processEvent(getTextComponent(), event); AWTAccessor.getComponentAccessor().processEvent(getTextComponent(), event);
} }
......
/* /*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -37,6 +37,10 @@ import java.awt.peer.TextFieldPeer; ...@@ -37,6 +37,10 @@ import java.awt.peer.TextFieldPeer;
import javax.swing.*; import javax.swing.*;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
/**
* Lightweight implementation of {@link TextFieldPeer}. Delegates most of the
* work to the {@link JPasswordField}.
*/
final class LWTextFieldPeer final class LWTextFieldPeer
extends LWTextComponentPeer<TextField, JPasswordField> extends LWTextComponentPeer<TextField, JPasswordField>
implements TextFieldPeer, ActionListener { implements TextFieldPeer, ActionListener {
...@@ -47,7 +51,7 @@ final class LWTextFieldPeer ...@@ -47,7 +51,7 @@ final class LWTextFieldPeer
} }
@Override @Override
protected JPasswordField createDelegate() { JPasswordField createDelegate() {
return new JPasswordFieldDelegate(); return new JPasswordFieldDelegate();
} }
...@@ -107,7 +111,7 @@ final class LWTextFieldPeer ...@@ -107,7 +111,7 @@ final class LWTextFieldPeer
* @param e the focus event * @param e the focus event
*/ */
@Override @Override
protected void handleJavaFocusEvent(final FocusEvent e) { void handleJavaFocusEvent(final FocusEvent e) {
if (e.getID() == FocusEvent.FOCUS_LOST) { if (e.getID() == FocusEvent.FOCUS_LOST) {
// In order to de-select the selection // In order to de-select the selection
setCaretPosition(0); setCaretPosition(0);
...@@ -115,6 +119,7 @@ final class LWTextFieldPeer ...@@ -115,6 +119,7 @@ final class LWTextFieldPeer
super.handleJavaFocusEvent(e); super.handleJavaFocusEvent(e);
} }
@SuppressWarnings("serial")// Safe: outer class is non-serializable.
private final class JPasswordFieldDelegate extends JPasswordField { private final class JPasswordFieldDelegate extends JPasswordField {
// Empty non private constructor was added because access to this // Empty non private constructor was added because access to this
......
...@@ -557,16 +557,18 @@ public abstract class LWToolkit extends SunToolkit implements Runnable { ...@@ -557,16 +557,18 @@ public abstract class LWToolkit extends SunToolkit implements Runnable {
} }
@Override @Override
public void grab(Window w) { public void grab(final Window w) {
if (w.getPeer() != null) { final Object peer = AWTAccessor.getComponentAccessor().getPeer(w);
((LWWindowPeer)w.getPeer()).grab(); if (peer != null) {
((LWWindowPeer) peer).grab();
} }
} }
@Override @Override
public void ungrab(Window w) { public void ungrab(final Window w) {
if (w.getPeer() != null) { final Object peer = AWTAccessor.getComponentAccessor().getPeer(w);
((LWWindowPeer)w.getPeer()).ungrab(false); if (peer != null) {
((LWWindowPeer) peer).ungrab(false);
} }
} }
......
...@@ -43,7 +43,7 @@ public class LWWindowPeer ...@@ -43,7 +43,7 @@ public class LWWindowPeer
extends LWContainerPeer<Window, JComponent> extends LWContainerPeer<Window, JComponent>
implements FramePeer, DialogPeer, FullScreenCapable, DisplayChangedListener, PlatformEventNotifier implements FramePeer, DialogPeer, FullScreenCapable, DisplayChangedListener, PlatformEventNotifier
{ {
public static enum PeerType { public enum PeerType {
SIMPLEWINDOW, SIMPLEWINDOW,
FRAME, FRAME,
DIALOG, DIALOG,
...@@ -83,15 +83,15 @@ public class LWWindowPeer ...@@ -83,15 +83,15 @@ public class LWWindowPeer
// A peer where the last mouse event came to. Used by cursor manager to // A peer where the last mouse event came to. Used by cursor manager to
// find the component under cursor // find the component under cursor
private static volatile LWComponentPeer lastCommonMouseEventPeer = null; private static volatile LWComponentPeer<?, ?> lastCommonMouseEventPeer;
// A peer where the last mouse event came to. Used to generate // A peer where the last mouse event came to. Used to generate
// MOUSE_ENTERED/EXITED notifications // MOUSE_ENTERED/EXITED notifications
private volatile LWComponentPeer lastMouseEventPeer; private volatile LWComponentPeer<?, ?> lastMouseEventPeer;
// Peers where all dragged/released events should come to, // Peers where all dragged/released events should come to,
// depending on what mouse button is being dragged according to Cocoa // depending on what mouse button is being dragged according to Cocoa
private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3]; private static final LWComponentPeer<?, ?>[] mouseDownTarget = new LWComponentPeer<?, ?>[3];
// A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
// on MOUSE_RELEASE. Click events are only generated if there were no drag // on MOUSE_RELEASE. Click events are only generated if there were no drag
...@@ -129,7 +129,8 @@ public class LWWindowPeer ...@@ -129,7 +129,8 @@ public class LWWindowPeer
this.peerType = peerType; this.peerType = peerType;
Window owner = target.getOwner(); Window owner = target.getOwner();
LWWindowPeer ownerPeer = (owner != null) ? (LWWindowPeer)owner.getPeer() : null; LWWindowPeer ownerPeer = owner == null ? null :
(LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(owner);
PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null; PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null;
// The delegate.initialize() needs a non-null GC on X11. // The delegate.initialize() needs a non-null GC on X11.
...@@ -163,10 +164,10 @@ public class LWWindowPeer ...@@ -163,10 +164,10 @@ public class LWWindowPeer
// Init warning window(for applets) // Init warning window(for applets)
SecurityWarningWindow warn = null; SecurityWarningWindow warn = null;
if (((Window)target).getWarningString() != null) { if (target.getWarningString() != null) {
// accessSystemTray permission allows to display TrayIcon, TrayIcon tooltip // accessSystemTray permission allows to display TrayIcon, TrayIcon tooltip
// and TrayIcon balloon windows without a warning window. // and TrayIcon balloon windows without a warning window.
if (!AWTAccessor.getWindowAccessor().isTrayIconWindow((Window)target)) { if (!AWTAccessor.getWindowAccessor().isTrayIconWindow(target)) {
LWToolkit toolkit = (LWToolkit)Toolkit.getDefaultToolkit(); LWToolkit toolkit = (LWToolkit)Toolkit.getDefaultToolkit();
warn = toolkit.createSecurityWarning(target, this); warn = toolkit.createSecurityWarning(target, this);
} }
...@@ -210,6 +211,7 @@ public class LWWindowPeer ...@@ -210,6 +211,7 @@ public class LWWindowPeer
} }
// Just a helper method // Just a helper method
@Override
public PlatformWindow getPlatformWindow() { public PlatformWindow getPlatformWindow() {
return platformWindow; return platformWindow;
} }
...@@ -391,7 +393,8 @@ public class LWWindowPeer ...@@ -391,7 +393,8 @@ public class LWWindowPeer
@Override @Override
public void setModalBlocked(Dialog blocker, boolean blocked) { public void setModalBlocked(Dialog blocker, boolean blocked) {
synchronized (getPeerTreeLock()) { synchronized (getPeerTreeLock()) {
this.blocker = blocked ? (LWWindowPeer)blocker.getPeer() : null; this.blocker = !blocked ? null :
(LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(blocker);
} }
platformWindow.setModalBlocked(blocked); platformWindow.setModalBlocked(blocked);
...@@ -458,6 +461,7 @@ public class LWWindowPeer ...@@ -458,6 +461,7 @@ public class LWWindowPeer
textured = isTextured; textured = isTextured;
} }
@Override
public final boolean isTranslucent() { public final boolean isTranslucent() {
synchronized (getStateLock()) { synchronized (getStateLock()) {
/* /*
...@@ -537,7 +541,8 @@ public class LWWindowPeer ...@@ -537,7 +541,8 @@ public class LWWindowPeer
public void blockWindows(List<Window> windows) { public void blockWindows(List<Window> windows) {
//TODO: LWX will probably need some collectJavaToplevels to speed this up //TODO: LWX will probably need some collectJavaToplevels to speed this up
for (Window w : windows) { for (Window w : windows) {
WindowPeer wp = (WindowPeer)w.getPeer(); WindowPeer wp =
(WindowPeer) AWTAccessor.getComponentAccessor().getPeer(w);
if (wp != null) { if (wp != null) {
wp.setModalBlocked((Dialog)getTarget(), true); wp.setModalBlocked((Dialog)getTarget(), true);
} }
...@@ -694,7 +699,7 @@ public class LWWindowPeer ...@@ -694,7 +699,7 @@ public class LWWindowPeer
// TODO: fill "bdata" member of AWTEvent // TODO: fill "bdata" member of AWTEvent
Rectangle r = getBounds(); Rectangle r = getBounds();
// findPeerAt() expects parent coordinates // findPeerAt() expects parent coordinates
LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y); LWComponentPeer<?, ?> targetPeer = findPeerAt(r.x + x, r.y + y);
if (id == MouseEvent.MOUSE_EXITED) { if (id == MouseEvent.MOUSE_EXITED) {
isMouseOver = false; isMouseOver = false;
...@@ -743,7 +748,7 @@ public class LWWindowPeer ...@@ -743,7 +748,7 @@ public class LWWindowPeer
screenX, screenY, modifiers, clickCount, popupTrigger, screenX, screenY, modifiers, clickCount, popupTrigger,
targetPeer); targetPeer);
} else { } else {
LWComponentPeer topmostTargetPeer = LWComponentPeer<?, ?> topmostTargetPeer =
topmostWindowPeer != null ? topmostWindowPeer.findPeerAt(r.x + x, r.y + y) : null; topmostWindowPeer != null ? topmostWindowPeer.findPeerAt(r.x + x, r.y + y) : null;
topmostWindowPeer.generateMouseEnterExitEventsForComponents(when, button, x, y, topmostWindowPeer.generateMouseEnterExitEventsForComponents(when, button, x, y,
screenX, screenY, modifiers, clickCount, popupTrigger, screenX, screenY, modifiers, clickCount, popupTrigger,
...@@ -840,7 +845,7 @@ public class LWWindowPeer ...@@ -840,7 +845,7 @@ public class LWWindowPeer
private void generateMouseEnterExitEventsForComponents(long when, private void generateMouseEnterExitEventsForComponents(long when,
int button, int x, int y, int screenX, int screenY, int button, int x, int y, int screenX, int screenY,
int modifiers, int clickCount, boolean popupTrigger, int modifiers, int clickCount, boolean popupTrigger,
LWComponentPeer targetPeer) { final LWComponentPeer<?, ?> targetPeer) {
if (!isMouseOver || targetPeer == lastMouseEventPeer) { if (!isMouseOver || targetPeer == lastMouseEventPeer) {
return; return;
...@@ -899,7 +904,7 @@ public class LWWindowPeer ...@@ -899,7 +904,7 @@ public class LWWindowPeer
// TODO: could we just use the last mouse event target here? // TODO: could we just use the last mouse event target here?
Rectangle r = getBounds(); Rectangle r = getBounds();
// findPeerAt() expects parent coordinates // findPeerAt() expects parent coordinates
final LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y); final LWComponentPeer<?, ?> targetPeer = findPeerAt(r.x + x, r.y + y);
if (targetPeer == null || !targetPeer.isEnabled()) { if (targetPeer == null || !targetPeer.isEnabled()) {
return; return;
} }
...@@ -1157,8 +1162,9 @@ public class LWWindowPeer ...@@ -1157,8 +1162,9 @@ public class LWWindowPeer
if (focusLog.isLoggable(PlatformLogger.Level.FINE)) { if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
focusLog.fine("requesting native focus to the owner " + owner); focusLog.fine("requesting native focus to the owner " + owner);
} }
LWWindowPeer currentActivePeer = (currentActive != null ? LWWindowPeer currentActivePeer = currentActive == null ? null :
(LWWindowPeer)currentActive.getPeer() : null); (LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(
currentActive);
// Ensure the opposite is natively active and suppress sending events. // Ensure the opposite is natively active and suppress sending events.
if (currentActivePeer != null && currentActivePeer.platformWindow.isActive()) { if (currentActivePeer != null && currentActivePeer.platformWindow.isActive()) {
...@@ -1270,7 +1276,8 @@ public class LWWindowPeer ...@@ -1270,7 +1276,8 @@ public class LWWindowPeer
while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) { while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) {
owner = owner.getOwner(); owner = owner.getOwner();
} }
return owner != null ? (LWWindowPeer)owner.getPeer() : null; return owner == null ? null :
(LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(owner);
} }
/** /**
...@@ -1289,11 +1296,13 @@ public class LWWindowPeer ...@@ -1289,11 +1296,13 @@ public class LWWindowPeer
} }
} }
@Override
public void enterFullScreenMode() { public void enterFullScreenMode() {
platformWindow.enterFullScreenMode(); platformWindow.enterFullScreenMode();
updateSecurityWarningVisibility(); updateSecurityWarningVisibility();
} }
@Override
public void exitFullScreenMode() { public void exitFullScreenMode() {
platformWindow.exitFullScreenMode(); platformWindow.exitFullScreenMode();
updateSecurityWarningVisibility(); updateSecurityWarningVisibility();
......
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. 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.lwawt;
/*
* Every time the TextField (or TextArea) change selection, every other text components
* must immediately clear their selections.
*/
interface SelectionClearListener {
void clearSelection();
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册