Search in sources :

Example 1 with ContainerListener

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;
}
Also used : ContainerEvent(java.awt.event.ContainerEvent) Jynstrument(jmri.jmrit.jython.Jynstrument) Container(java.awt.Container) ContainerListener(java.awt.event.ContainerListener) JInternalFrame(javax.swing.JInternalFrame)

Example 2 with ContainerListener

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);
            }
        }
    });
}
Also used : Graphics(java.awt.Graphics) ContainerEvent(java.awt.event.ContainerEvent) JPanel(javax.swing.JPanel) GetPropertyAction(sun.security.action.GetPropertyAction) BorderLayout(java.awt.BorderLayout) Rectangle(java.awt.Rectangle) ContainerListener(java.awt.event.ContainerListener) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Aggregations

ContainerEvent (java.awt.event.ContainerEvent)2 ContainerListener (java.awt.event.ContainerListener)2 BorderLayout (java.awt.BorderLayout)1 Component (java.awt.Component)1 Container (java.awt.Container)1 Graphics (java.awt.Graphics)1 Rectangle (java.awt.Rectangle)1 JComponent (javax.swing.JComponent)1 JInternalFrame (javax.swing.JInternalFrame)1 JPanel (javax.swing.JPanel)1 Jynstrument (jmri.jmrit.jython.Jynstrument)1 GetPropertyAction (sun.security.action.GetPropertyAction)1