src/share/classes/sun/swing/JLightweightFrame.java

Print this page

        

*** 27,42 **** --- 27,48 ---- import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Container; + import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; + import java.awt.event.ComponentListener; + import java.awt.event.ContainerEvent; + import java.awt.event.ContainerListener; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; + import java.beans.PropertyChangeEvent; + import java.beans.PropertyChangeListener; import java.security.AccessController; import javax.swing.JLayeredPane; import javax.swing.JPanel; import javax.swing.JRootPane;
*** 78,87 **** --- 84,95 ---- * {@link LightweightContent#paintUnlock()} methods). */ private boolean copyBufferEnabled; private int[] copyBuffer; + private PropertyChangeListener layoutSizeListener; + /** * Constructs a new, initially invisible {@code JLightweightFrame} * instance. */ public JLightweightFrame() {
*** 92,115 **** add(rootPane, BorderLayout.CENTER); setFocusTraversalPolicy(new LayoutFocusTraversalPolicy()); if (getGraphicsConfiguration().isTranslucencyCapable()) { setBackground(new Color(0, 0, 0, 0)); } } /** * Sets the {@link LightweightContent} instance for this frame. * The {@code JComponent} object returned by the * {@link LightweightContent#getComponent()} method is immediately * added to the frame's content pane. * * @param content the {@link LightweightContent} instance */ ! public void setContent(LightweightContent content) { this.content = content; this.component = content.getComponent(); initInterior(); } @Override public Graphics getGraphics() { --- 100,153 ---- add(rootPane, BorderLayout.CENTER); setFocusTraversalPolicy(new LayoutFocusTraversalPolicy()); if (getGraphicsConfiguration().isTranslucencyCapable()) { setBackground(new Color(0, 0, 0, 0)); } + + layoutSizeListener = new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent e) { + Dimension d = (Dimension)e.getNewValue(); + + if ("preferredSize".equals(e.getPropertyName())) { + content.preferredSizeChanged(d.width, d.height); + + } else if ("maximumSize".equals(e.getPropertyName())) { + content.maximumSizeChanged(d.width, d.height); + + } else if ("minimumSize".equals(e.getPropertyName())) { + content.minimumSizeChanged(d.width, d.height); + } + } + }; } /** * Sets the {@link LightweightContent} instance for this frame. * The {@code JComponent} object returned by the * {@link LightweightContent#getComponent()} method is immediately * added to the frame's content pane. * * @param content the {@link LightweightContent} instance */ ! public void setContent(final LightweightContent content) { ! if (content == null) { ! System.err.println("JLightweightFrame.setContent: content may not be null!"); ! return; ! } this.content = content; this.component = content.getComponent(); + Dimension d = this.component.getPreferredSize(); + content.preferredSizeChanged(d.width, d.height); + + d = this.component.getMaximumSize(); + content.maximumSizeChanged(d.width, d.height); + + d = this.component.getMinimumSize(); + content.minimumSizeChanged(d.width, d.height); + initInterior(); } @Override public Graphics getGraphics() {
*** 200,209 **** --- 238,266 ---- } }; contentPane.setLayout(new BorderLayout()); contentPane.add(component); setContentPane(contentPane); + + contentPane.addContainerListener(new ContainerListener() { + @Override + public void componentAdded(ContainerEvent e) { + Component c = JLightweightFrame.this.component; + if (e.getChild() == c) { + c.addPropertyChangeListener("preferredSize", layoutSizeListener); + c.addPropertyChangeListener("maximumSize", layoutSizeListener); + c.addPropertyChangeListener("minimumSize", layoutSizeListener); + } + } + @Override + public void componentRemoved(ContainerEvent e) { + Component c = JLightweightFrame.this.component; + if (e.getChild() == c) { + c.removePropertyChangeListener(layoutSizeListener); + } + } + }); } @SuppressWarnings("deprecation") @Override public void reshape(int x, int y, int width, int height) { super.reshape(x, y, width, height);