提交 a5ce3333 编写于 作者: A alexp

6982661: Complete JLayer component

Reviewed-by: malenkov
上级 e203fb92
...@@ -4787,6 +4787,17 @@ public abstract class JComponent extends Container implements Serializable, ...@@ -4787,6 +4787,17 @@ public abstract class JComponent extends Container implements Serializable,
* @see RepaintManager#addDirtyRegion * @see RepaintManager#addDirtyRegion
*/ */
public void repaint(long tm, int x, int y, int width, int height) { public void repaint(long tm, int x, int y, int width, int height) {
Container p = this;
while ((p = p.getParent()) instanceof JComponent) {
JComponent jp = (JComponent) p;
if (jp.isPaintingOrigin()) {
Rectangle rectangle = SwingUtilities.convertRectangle(
this, new Rectangle(x, y, width, height), jp);
jp.repaint(tm,
rectangle.x, rectangle.y, rectangle.width, rectangle.height);
return;
}
}
RepaintManager.currentManager(this).addDirtyRegion(this, x, y, width, height); RepaintManager.currentManager(this).addDirtyRegion(this, x, y, width, height);
} }
......
...@@ -25,17 +25,17 @@ ...@@ -25,17 +25,17 @@
package javax.swing; package javax.swing;
import sun.awt.AWTAccessor;
import javax.swing.plaf.LayerUI; import javax.swing.plaf.LayerUI;
import javax.swing.border.Border;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.Serializable;
import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
...@@ -156,8 +156,6 @@ public final class JLayer<V extends Component> ...@@ -156,8 +156,6 @@ public final class JLayer<V extends Component>
private LayerUI<? super V> layerUI; private LayerUI<? super V> layerUI;
private JPanel glassPane; private JPanel glassPane;
private boolean isPainting; private boolean isPainting;
private static final DefaultLayerLayout sharedLayoutInstance =
new DefaultLayerLayout();
private long eventMask; private long eventMask;
private static final LayerEventController eventController = private static final LayerEventController eventController =
...@@ -165,7 +163,7 @@ public final class JLayer<V extends Component> ...@@ -165,7 +163,7 @@ public final class JLayer<V extends Component>
/** /**
* Creates a new {@code JLayer} object with a {@code null} view component * Creates a new {@code JLayer} object with a {@code null} view component
* and {@code null} {@link javax.swing.plaf.LayerUI}. * and default {@link javax.swing.plaf.LayerUI}.
* *
* @see #setView * @see #setView
* @see #setUI * @see #setUI
...@@ -176,14 +174,14 @@ public final class JLayer<V extends Component> ...@@ -176,14 +174,14 @@ public final class JLayer<V extends Component>
/** /**
* Creates a new {@code JLayer} object * Creates a new {@code JLayer} object
* with {@code null} {@link javax.swing.plaf.LayerUI}. * with default {@link javax.swing.plaf.LayerUI}.
* *
* @param view the component to be decorated by this {@code JLayer} * @param view the component to be decorated by this {@code JLayer}
* *
* @see #setUI * @see #setUI
*/ */
public JLayer(V view) { public JLayer(V view) {
this(view, null); this(view, new LayerUI<V>());
} }
/** /**
...@@ -195,7 +193,6 @@ public final class JLayer<V extends Component> ...@@ -195,7 +193,6 @@ public final class JLayer<V extends Component>
* to be used by this {@code JLayer} * to be used by this {@code JLayer}
*/ */
public JLayer(V view, LayerUI<V> ui) { public JLayer(V view, LayerUI<V> ui) {
setLayout(sharedLayoutInstance);
setGlassPane(createGlassPane()); setGlassPane(createGlassPane());
setView(view); setView(view);
setUI(ui); setUI(ui);
...@@ -279,10 +276,15 @@ public final class JLayer<V extends Component> ...@@ -279,10 +276,15 @@ public final class JLayer<V extends Component>
*/ */
public void setGlassPane(JPanel glassPane) { public void setGlassPane(JPanel glassPane) {
Component oldGlassPane = getGlassPane(); Component oldGlassPane = getGlassPane();
boolean isGlassPaneVisible = false;
if (oldGlassPane != null) { if (oldGlassPane != null) {
isGlassPaneVisible = oldGlassPane.isVisible();
super.remove(oldGlassPane); super.remove(oldGlassPane);
} }
if (glassPane != null) { if (glassPane != null) {
AWTAccessor.getComponentAccessor().setMixingCutoutShape(glassPane,
new Rectangle());
glassPane.setVisible(isGlassPaneVisible);
super.addImpl(glassPane, null, 0); super.addImpl(glassPane, null, 0);
} }
this.glassPane = glassPane; this.glassPane = glassPane;
...@@ -302,6 +304,40 @@ public final class JLayer<V extends Component> ...@@ -302,6 +304,40 @@ public final class JLayer<V extends Component>
return new DefaultLayerGlassPane(); return new DefaultLayerGlassPane();
} }
/**
* Sets the layout manager for this container. This method is
* overridden to prevent the layout manager from being set.
* <p/>Note: If {@code mgr} is non-{@code null}, this
* method will throw an exception as layout managers are not supported on
* a {@code JLayer}.
*
* @param mgr the specified layout manager
* @exception IllegalArgumentException this method is not supported
*/
public void setLayout(LayoutManager mgr) {
if (mgr != null) {
throw new IllegalArgumentException("JLayer.setLayout() not supported");
}
}
/**
* A non-{@code null] border, or non-zero insets, isn't supported, to prevent the geometry
* of this component from becoming complex enough to inhibit
* subclassing of {@code LayerUI} class. To create a {@code JLayer} with a border,
* add it to a {@code JPanel} that has a border.
* <p/>Note: If {@code border} is non-{@code null}, this
* method will throw an exception as borders are not supported on
* a {@code JLayer}.
*
* @param border the {@code Border} to set
* @exception IllegalArgumentException this method is not supported
*/
public void setBorder(Border border) {
if (border != null) {
throw new IllegalArgumentException("JLayer.setBorder() not supported");
}
}
/** /**
* This method is not supported by {@code JLayer} * This method is not supported by {@code JLayer}
* and always throws {@code UnsupportedOperationException} * and always throws {@code UnsupportedOperationException}
...@@ -340,6 +376,32 @@ public final class JLayer<V extends Component> ...@@ -340,6 +376,32 @@ public final class JLayer<V extends Component>
setGlassPane(null); setGlassPane(null);
} }
/**
* Always returns {@code true} to cause painting to originate from {@code JLayer},
* or one of its ancestors.
*
* @return true
* @see JComponent#isPaintingOrigin()
*/
boolean isPaintingOrigin() {
return true;
}
/**
* Delegates repainting to {@link javax.swing.plaf.LayerUI#repaint} method.
*
* @param tm this parameter is not used
* @param x the x value of the dirty region
* @param y the y value of the dirty region
* @param width the width of the dirty region
* @param height the height of the dirty region
*/
public void repaint(long tm, int x, int y, int width, int height) {
if (getUI() != null) {
getUI().repaint(tm, x, y, width, height, this);
}
}
/** /**
* Delegates all painting to the {@link javax.swing.plaf.LayerUI} object. * Delegates all painting to the {@link javax.swing.plaf.LayerUI} object.
* *
...@@ -364,14 +426,18 @@ public final class JLayer<V extends Component> ...@@ -364,14 +426,18 @@ public final class JLayer<V extends Component>
} }
/** /**
* To enable the correct painting of the {@code glassPane} and view component, * The {@code JLayer} overrides the default implementation of
* the {@code JLayer} overrides the default implementation of * this method (in {@code JComponent}) to return {@code false}.
* this method to return {@code false} when the {@code glassPane} is visible. * This ensures
* * that the drawing machinery will call the {@code JLayer}'s
* @return false if {@code JLayer}'s {@code glassPane} is visible * {@code paint}
* implementation rather than messaging the {@code JLayer}'s
* children directly.
*
* @return false
*/ */
public boolean isOptimizedDrawingEnabled() { public boolean isOptimizedDrawingEnabled() {
return glassPane == null || !glassPane.isVisible(); return false;
} }
/** /**
...@@ -461,17 +527,16 @@ public final class JLayer<V extends Component> ...@@ -461,17 +527,16 @@ public final class JLayer<V extends Component>
/** /**
* Returns the preferred size of the viewport for a view component. * Returns the preferred size of the viewport for a view component.
* <p/> * <p/>
* If the ui delegate of this layer is not {@code null}, this method delegates its * If the view component of this layer implements {@link Scrollable}, this method delegates its
* implementation to the {@code LayerUI.getPreferredScrollableViewportSize(JLayer)} * implementation to the view component.
* *
* @return the preferred size of the viewport for a view component * @return the preferred size of the viewport for a view component
* *
* @see Scrollable * @see Scrollable
* @see LayerUI#getPreferredScrollableViewportSize(JLayer)
*/ */
public Dimension getPreferredScrollableViewportSize() { public Dimension getPreferredScrollableViewportSize() {
if (getUI() != null) { if (getView() instanceof Scrollable) {
return getUI().getPreferredScrollableViewportSize(this); return ((Scrollable)getView()).getPreferredScrollableViewportSize();
} }
return getPreferredSize(); return getPreferredSize();
} }
...@@ -481,18 +546,17 @@ public final class JLayer<V extends Component> ...@@ -481,18 +546,17 @@ public final class JLayer<V extends Component>
* that display logical rows or columns in order to completely expose * that display logical rows or columns in order to completely expose
* one block of rows or columns, depending on the value of orientation. * one block of rows or columns, depending on the value of orientation.
* <p/> * <p/>
* If the ui delegate of this layer is not {@code null}, this method delegates its * If the view component of this layer implements {@link Scrollable}, this method delegates its
* implementation to the {@code LayerUI.getScrollableBlockIncrement(JLayer,Rectangle,int,int)} * implementation to the view component.
* *
* @return the "block" increment for scrolling in the specified direction * @return the "block" increment for scrolling in the specified direction
* *
* @see Scrollable * @see Scrollable
* @see LayerUI#getScrollableBlockIncrement(JLayer, Rectangle, int, int)
*/ */
public int getScrollableBlockIncrement(Rectangle visibleRect, public int getScrollableBlockIncrement(Rectangle visibleRect,
int orientation, int direction) { int orientation, int direction) {
if (getUI() != null) { if (getView() instanceof Scrollable) {
return getUI().getScrollableBlockIncrement(this, visibleRect, return ((Scrollable)getView()).getScrollableBlockIncrement(visibleRect,
orientation, direction); orientation, direction);
} }
return (orientation == SwingConstants.VERTICAL) ? visibleRect.height : return (orientation == SwingConstants.VERTICAL) ? visibleRect.height :
...@@ -504,17 +568,16 @@ public final class JLayer<V extends Component> ...@@ -504,17 +568,16 @@ public final class JLayer<V extends Component>
* determine the height of the layer, unless the preferred height * determine the height of the layer, unless the preferred height
* of the layer is smaller than the height of the viewport. * of the layer is smaller than the height of the viewport.
* <p/> * <p/>
* If the ui delegate of this layer is not null, this method delegates its * If the view component of this layer implements {@link Scrollable}, this method delegates its
* implementation to the {@code LayerUI.getScrollableTracksViewportHeight(JLayer)} * implementation to the view component.
* *
* @return whether the layer should track the height of the viewport * @return whether the layer should track the height of the viewport
* *
* @see Scrollable * @see Scrollable
* @see LayerUI#getScrollableTracksViewportHeight(JLayer)
*/ */
public boolean getScrollableTracksViewportHeight() { public boolean getScrollableTracksViewportHeight() {
if (getUI() != null) { if (getView() instanceof Scrollable) {
return getUI().getScrollableTracksViewportHeight(this); return ((Scrollable)getView()).getScrollableTracksViewportHeight();
} }
return false; return false;
} }
...@@ -524,17 +587,16 @@ public final class JLayer<V extends Component> ...@@ -524,17 +587,16 @@ public final class JLayer<V extends Component>
* determine the width of the layer, unless the preferred width * determine the width of the layer, unless the preferred width
* of the layer is smaller than the width of the viewport. * of the layer is smaller than the width of the viewport.
* <p/> * <p/>
* If the ui delegate of this layer is not null, this method delegates its * If the view component of this layer implements {@link Scrollable}, this method delegates its
* implementation to the {@code LayerUI.getScrollableTracksViewportWidth(JLayer)} * implementation to the view component.
* *
* @return whether the layer should track the width of the viewport * @return whether the layer should track the width of the viewport
* *
* @see Scrollable * @see Scrollable
* @see LayerUI#getScrollableTracksViewportWidth(JLayer)
*/ */
public boolean getScrollableTracksViewportWidth() { public boolean getScrollableTracksViewportWidth() {
if (getUI() != null) { if (getView() instanceof Scrollable) {
return getUI().getScrollableTracksViewportWidth(this); return ((Scrollable)getView()).getScrollableTracksViewportWidth();
} }
return false; return false;
} }
...@@ -549,20 +611,19 @@ public final class JLayer<V extends Component> ...@@ -549,20 +611,19 @@ public final class JLayer<V extends Component>
* Scrolling containers, like {@code JScrollPane}, will use this method * Scrolling containers, like {@code JScrollPane}, will use this method
* each time the user requests a unit scroll. * each time the user requests a unit scroll.
* <p/> * <p/>
* If the ui delegate of this layer is not {@code null}, this method delegates its * If the view component of this layer implements {@link Scrollable}, this method delegates its
* implementation to the {@code LayerUI.getScrollableUnitIncrement(JLayer,Rectangle,int,int)} * implementation to the view component.
* *
* @return The "unit" increment for scrolling in the specified direction. * @return The "unit" increment for scrolling in the specified direction.
* This value should always be positive. * This value should always be positive.
* *
* @see Scrollable * @see Scrollable
* @see LayerUI#getScrollableUnitIncrement(JLayer, Rectangle, int, int)
*/ */
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation,
int direction) { int direction) {
if (getUI() != null) { if (getView() instanceof Scrollable) {
return getUI().getScrollableUnitIncrement( return ((Scrollable) getView()).getScrollableUnitIncrement(
this, visibleRect, orientation, direction); visibleRect, orientation, direction);
} }
return 1; return 1;
} }
...@@ -594,6 +655,16 @@ public final class JLayer<V extends Component> ...@@ -594,6 +655,16 @@ public final class JLayer<V extends Component>
eventController.updateAWTEventListener(eventMask, 0); eventController.updateAWTEventListener(eventMask, 0);
} }
/**
* Delegates its functionality to the {@link javax.swing.plaf.LayerUI#doLayout(JLayer)} method,
* if {@code LayerUI} is set.
*/
public void doLayout() {
if (getUI() != null) {
getUI().doLayout(this);
}
}
/** /**
* static AWTEventListener to be shared with all AbstractLayerUIs * static AWTEventListener to be shared with all AbstractLayerUIs
*/ */
...@@ -625,8 +696,8 @@ public final class JLayer<V extends Component> ...@@ -625,8 +696,8 @@ public final class JLayer<V extends Component>
JLayer l = (JLayer) component; JLayer l = (JLayer) component;
LayerUI ui = l.getUI(); LayerUI ui = l.getUI();
if (ui != null && if (ui != null &&
isEventEnabled(l.getLayerEventMask(), isEventEnabled(l.getLayerEventMask(), event.getID()) &&
event.getID())) { (!(event instanceof InputEvent) || !((InputEvent)event).isConsumed())) {
ui.eventDispatched(event, l); ui.eventDispatched(event, l);
} }
} }
...@@ -758,82 +829,4 @@ public final class JLayer<V extends Component> ...@@ -758,82 +829,4 @@ public final class JLayer<V extends Component>
return super.contains(x, y); return super.contains(x, y);
} }
} }
/**
* The default layout manager for the {@link javax.swing.JLayer}.<br/>
* It places the glassPane on top of the view component
* and makes it the same size as {@code JLayer},
* it also makes the view component the same size but minus layer's insets<br/>
*/
private static class DefaultLayerLayout implements LayoutManager, Serializable {
/**
* {@inheritDoc}
*/
public void layoutContainer(Container parent) {
JLayer layer = (JLayer) parent;
Component view = layer.getView();
Component glassPane = layer.getGlassPane();
if (view != null) {
Insets insets = layer.getInsets();
view.setLocation(insets.left, insets.top);
view.setSize(layer.getWidth() - insets.left - insets.right,
layer.getHeight() - insets.top - insets.bottom);
}
if (glassPane != null) {
glassPane.setLocation(0, 0);
glassPane.setSize(layer.getWidth(), layer.getHeight());
}
}
/**
* {@inheritDoc}
*/
public Dimension minimumLayoutSize(Container parent) {
JLayer layer = (JLayer) parent;
Insets insets = layer.getInsets();
Dimension ret = new Dimension(insets.left + insets.right,
insets.top + insets.bottom);
Component view = layer.getView();
if (view != null) {
Dimension size = view.getMinimumSize();
ret.width += size.width;
ret.height += size.height;
}
if (ret.width == 0 || ret.height == 0) {
ret.width = ret.height = 4;
}
return ret;
}
/**
* {@inheritDoc}
*/
public Dimension preferredLayoutSize(Container parent) {
JLayer layer = (JLayer) parent;
Insets insets = layer.getInsets();
Dimension ret = new Dimension(insets.left + insets.right,
insets.top + insets.bottom);
Component view = layer.getView();
if (view != null) {
Dimension size = view.getPreferredSize();
if (size.width > 0 && size.height > 0) {
ret.width += size.width;
ret.height += size.height;
}
}
return ret;
}
/**
* {@inheritDoc}
*/
public void addLayoutComponent(String name, Component comp) {
}
/**
* {@inheritDoc}
*/
public void removeLayoutComponent(Component comp) {
}
}
} }
...@@ -600,136 +600,124 @@ public class LayerUI<V extends Component> ...@@ -600,136 +600,124 @@ public class LayerUI<V extends Component>
} }
/** /**
* Returns the preferred size of the viewport for a view component. * If the {@code JLayer}'s view component is not {@code null},
* this calls the view's {@code getBaseline()} method.
* Otherwise, the default implementation is called.
* *
* @param l the {@code JLayer} component where this UI delegate is being installed * @param c {@code JLayer} to return baseline resize behavior for
* @return the preferred size of the viewport for a view component * @param width the width to get the baseline for
* @see Scrollable#getPreferredScrollableViewportSize() * @param height the height to get the baseline for
* @return baseline or a value &lt; 0 indicating there is no reasonable
* baseline
*/ */
public Dimension getPreferredScrollableViewportSize(JLayer<? extends V> l) { public int getBaseline(JComponent c, int width, int height) {
if (l.getView() instanceof Scrollable) { JLayer l = (JLayer) c;
return ((Scrollable)l.getView()).getPreferredScrollableViewportSize(); if (l.getView() != null) {
return l.getView().getBaseline(width, height);
} }
return l.getPreferredSize(); return super.getBaseline(c, width, height);
} }
/** /**
* Returns a scroll increment, which is required for components * If the {@code JLayer}'s view component is not {@code null},
* that display logical rows or columns in order to completely expose * this returns the result of the view's {@code getBaselineResizeBehavior()} method.
* one block of rows or columns, depending on the value of orientation. * Otherwise, the default implementation is called.
* *
* @param l the {@code JLayer} component where this UI delegate is being installed * @param c {@code JLayer} to return baseline resize behavior for
* @param visibleRect The view area visible within the viewport * @return an enum indicating how the baseline changes as the component
* @param orientation Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL. * size changes
* @param direction Less than zero to scroll up/left, greater than zero for down/right.
* @return the "block" increment for scrolling in the specified direction
* @see Scrollable#getScrollableBlockIncrement(Rectangle, int, int)
*/ */
public int getScrollableBlockIncrement(JLayer<? extends V> l, public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c) {
Rectangle visibleRect, JLayer l = (JLayer) c;
int orientation, int direction) { if (l.getView() != null) {
if (l.getView() instanceof Scrollable) { return l.getView().getBaselineResizeBehavior();
return ((Scrollable)l.getView()).getScrollableBlockIncrement(
visibleRect,orientation, direction);
} }
return (orientation == SwingConstants.VERTICAL) ? visibleRect.height : return super.getBaselineResizeBehavior(c);
visibleRect.width;
} }
/** /**
* Returns {@code false} to indicate that the height of the viewport does not * Causes the passed instance of {@code JLayer} to lay out its components.
* determine the height of the layer, unless the preferred height
* of the layer is smaller than the height of the viewport.
* *
* @param l the {@code JLayer} component where this UI delegate is being installed * @param l the {@code JLayer} component where this UI delegate is being installed
* @return whether the layer should track the height of the viewport
* @see Scrollable#getScrollableTracksViewportHeight()
*/ */
public boolean getScrollableTracksViewportHeight(JLayer<? extends V> l) { public void doLayout(JLayer<? extends V> l) {
if (l.getView() instanceof Scrollable) { Component view = l.getView();
return ((Scrollable)l.getView()).getScrollableTracksViewportHeight(); if (view != null) {
view.setBounds(0, 0, l.getWidth(), l.getHeight());
}
Component glassPane = l.getGlassPane();
if (glassPane != null) {
glassPane.setBounds(0, 0, l.getWidth(), l.getHeight());
} }
return false;
} }
/** /**
* Returns {@code false} to indicate that the width of the viewport does not * If the {@code JLayer}'s view component is not {@code null},
* determine the width of the layer, unless the preferred width * this returns the result of the view's {@code getPreferredSize()} method.
* of the layer is smaller than the width of the viewport. * Otherwise, the default implementation is used.
* *
* @param l the {@code JLayer} component where this UI delegate is being installed * @param c {@code JLayer} to return preferred size for
* @return whether the layer should track the width of the viewport * @return preferred size for the passed {@code JLayer}
* @see Scrollable
* @see LayerUI#getScrollableTracksViewportWidth(JLayer)
*/ */
public boolean getScrollableTracksViewportWidth(JLayer<? extends V> l) { public Dimension getPreferredSize(JComponent c) {
if (l.getView() instanceof Scrollable) { JLayer l = (JLayer) c;
return ((Scrollable)l.getView()).getScrollableTracksViewportWidth(); Component view = l.getView();
if (view != null) {
return view.getPreferredSize();
} }
return false; return super.getPreferredSize(c);
} }
/** /**
* Returns a scroll increment, which is required for components * If the {@code JLayer}'s view component is not {@code null},
* that display logical rows or columns in order to completely expose * this returns the result of the view's {@code getMinimalSize()} method.
* one new row or column, depending on the value of orientation. * Otherwise, the default implementation is used.
* Ideally, components should handle a partially exposed row or column
* by returning the distance required to completely expose the item.
* <p>
* Scrolling containers, like JScrollPane, will use this method
* each time the user requests a unit scroll.
* *
* @param l the {@code JLayer} component where this UI delegate is being installed * @param c {@code JLayer} to return preferred size for
* @param visibleRect The view area visible within the viewport * @return minimal size for the passed {@code JLayer}
* @param orientation Either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL.
* @param direction Less than zero to scroll up/left, greater than zero for down/right.
* @return The "unit" increment for scrolling in the specified direction.
* This value should always be positive.
* @see Scrollable#getScrollableUnitIncrement(Rectangle, int, int)
*/ */
public int getScrollableUnitIncrement(JLayer<? extends V> l, public Dimension getMinimumSize(JComponent c) {
Rectangle visibleRect, JLayer l = (JLayer) c;
int orientation, int direction) { Component view = l.getView();
if (l.getView() instanceof Scrollable) { if (view != null) {
return ((Scrollable)l.getView()).getScrollableUnitIncrement( return view.getMinimumSize();
visibleRect, orientation, direction);
} }
return 1; return super.getMinimumSize(c);
} }
/** /**
* If the {@code JLayer}'s view component is not {@code null}, * If the {@code JLayer}'s view component is not {@code null},
* this calls the view's {@code getBaseline()} method. * this returns the result of the view's {@code getMaximumSize()} method.
* Otherwise, the default implementation is called. * Otherwise, the default implementation is used.
* *
* @param c {@code JLayer} to return baseline resize behavior for * @param c {@code JLayer} to return preferred size for
* @param width the width to get the baseline for * @return maximun size for the passed {@code JLayer}
* @param height the height to get the baseline for
* @return baseline or a value &lt; 0 indicating there is no reasonable
* baseline
*/ */
public int getBaseline(JComponent c, int width, int height) { public Dimension getMaximumSize(JComponent c) {
JLayer l = (JLayer) c; JLayer l = (JLayer) c;
if (l.getView() != null) { Component view = l.getView();
return l.getView().getBaseline(width, height); if (view != null) {
return view.getMaximumSize();
} }
return super.getBaseline(c, width, height); return super.getMaximumSize(c);
} }
/** /**
* If the {@code JLayer}'s view component is not {@code null}, * Adds the specified region to the dirty region list if the component
* this calls the view's {@code getBaselineResizeBehavior()} method. * is showing. The component will be repainted after all of the
* Otherwise, the default implementation is called. * currently pending events have been dispatched.
* * <p/>
* @param c {@code JLayer} to return baseline resize behavior for * This method is to be overridden when the dirty region needs to be changed.
* @return an enum indicating how the baseline changes as the component *
* size changes * @param tm this parameter is not used
* @param x the x value of the dirty region
* @param y the y value of the dirty region
* @param width the width of the dirty region
* @param height the height of the dirty region
* @see java.awt.Component#isShowing
* @see RepaintManager#addDirtyRegion
*/ */
public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c) { public void repaint(long tm, int x, int y, int width, int height, JLayer<? extends V> l) {
JLayer l = (JLayer) c; RepaintManager.currentManager(l).addDirtyRegion(l, x, y, width, height);
if (l.getView() != null) {
return l.getView().getBaselineResizeBehavior();
}
return super.getBaselineResizeBehavior(c);
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册