use of java.awt.event.ContainerListener in project JMRI by JMRI.
the class ThrottleFrame method ynstrument.
// #JYNSTRUMENT# here instantiate the Jynstrument, put it in a component, initialize the context and start it
public JInternalFrame ynstrument(String path) {
if (path == null) {
return null;
}
// everything is there
Jynstrument it = JynstrumentFactory.createInstrument(path, this);
if (it == null) {
log.error("Error while creating Jynstrument " + path);
return null;
}
setTransparentBackground(it);
JInternalFrame newiFrame = new JInternalFrame(it.getClassName());
newiFrame.add(it);
newiFrame.addInternalFrameListener(frameListener);
newiFrame.setDoubleBuffered(true);
newiFrame.setResizable(true);
newiFrame.setClosable(true);
newiFrame.setIconifiable(true);
newiFrame.getContentPane().addContainerListener(new ContainerListener() {
@Override
public void componentAdded(ContainerEvent e) {
}
@Override
public void componentRemoved(ContainerEvent e) {
Container c = e.getContainer();
while ((!(c instanceof JInternalFrame)) && (!(c instanceof TranslucentJPanel))) {
c = c.getParent();
}
c.setVisible(false);
remove(c);
repaint();
}
});
newiFrame.pack();
add(newiFrame, PANEL_LAYER_FRAME);
newiFrame.setVisible(true);
return newiFrame;
}
use of java.awt.event.ContainerListener in project jdk8u_jdk by JetBrains.
the class JLightweightFrame method initInterior.
private void initInterior() {
contentPane = new JPanel() {
@Override
public void paint(Graphics g) {
if (!copyBufferEnabled) {
content.paintLock();
}
try {
super.paint(g);
final Rectangle clip = g.getClipBounds() != null ? g.getClipBounds() : new Rectangle(0, 0, contentPane.getWidth(), contentPane.getHeight());
clip.x = Math.max(0, clip.x);
clip.y = Math.max(0, clip.y);
clip.width = Math.min(contentPane.getWidth(), clip.width);
clip.height = Math.min(contentPane.getHeight(), clip.height);
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
Rectangle c = contentPane.getBounds().intersection(clip);
notifyImageUpdated(c.x, c.y, c.width, c.height);
}
});
} finally {
if (!copyBufferEnabled) {
content.paintUnlock();
}
}
}
@Override
protected boolean isPaintingOrigin() {
return true;
}
};
contentPane.setLayout(new BorderLayout());
contentPane.add(component);
if ("true".equals(AccessController.doPrivileged(new GetPropertyAction("swing.jlf.contentPaneTransparent", "false")))) {
contentPane.setOpaque(false);
}
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);
}
}
});
}
Aggregations