Search in sources :

Example 1 with ContainerEvent

use of java.awt.event.ContainerEvent 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 ContainerEvent

use of java.awt.event.ContainerEvent in project com.revolsys.open by revolsys.

the class ProjectFrame method initUi.

@Override
protected void initUi() {
    setMinimumSize(new Dimension(600, 500));
    final JRootPane rootPane = getRootPane();
    addSaveActions(rootPane, this.project);
    final BoundingBox defaultBoundingBox = getDefaultBoundingBox();
    this.project.setViewBoundingBoxAndGeometryFactory(defaultBoundingBox);
    Project.set(this.project);
    this.project.setPropertyWeak(PROJECT_FRAME, this);
    setConnectionRegistries();
    newMapPanel();
    this.leftTabs.setMinimumSize(new Dimension(100, 300));
    this.leftTabs.setPreferredSize(new Dimension(300, 700));
    this.mapPanel.setMinimumSize(new Dimension(300, 300));
    this.mapPanel.setPreferredSize(new Dimension(700, 700));
    this.leftRightSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, this.leftTabs, this.mapPanel);
    this.leftRightSplit.setBorder(BorderFactory.createEmptyBorder());
    this.bottomTabs.setBorder(BorderFactory.createEmptyBorder());
    this.bottomTabs.setPreferredSize(new Dimension(700, 200));
    final ContainerListener listener = new ContainerAdapter() {

        @Override
        public void componentRemoved(final ContainerEvent e) {
            final Component eventComponent = e.getChild();
            if (eventComponent instanceof ProjectFramePanel) {
                final ProjectFramePanel panel = (ProjectFramePanel) eventComponent;
                panel.setProperty(BOTTOM_TAB, null);
            }
        }
    };
    this.bottomTabs.addContainerListener(listener);
    this.topBottomSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, this.leftRightSplit, this.bottomTabs);
    this.bottomTabs.setMinimumSize(new Dimension(600, 100));
    this.topBottomSplit.setResizeWeight(1);
    add(this.topBottomSplit, BorderLayout.CENTER);
    newTabLeftTableOfContents();
    newTabLeftCatalogPanel();
    addBottomTabs(this.bottomTabs);
    setBounds((Object) null, false);
    super.initUi();
}
Also used : ContainerEvent(java.awt.event.ContainerEvent) BoundingBox(com.revolsys.geometry.model.BoundingBox) ContainerListener(java.awt.event.ContainerListener) JRootPane(javax.swing.JRootPane) Dimension(java.awt.Dimension) JSplitPane(javax.swing.JSplitPane) ContainerAdapter(java.awt.event.ContainerAdapter) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Example 3 with ContainerEvent

use of java.awt.event.ContainerEvent in project adempiere by adempiere.

the class SwingTool method addOpaque.

public static void addOpaque(JComponent c, final boolean opaque) {
    ContainerAdapter ca = new ContainerAdapter() {

        public void componentAdded(ContainerEvent e) {
            setOpaque(e.getChild());
        }

        private void setOpaque(Component c) {
            //ignores all selectable items, like buttons
            if (c instanceof ItemSelectable) {
                return;
            } else // sets transparent
            if (c instanceof JComponent) {
                ((JComponent) c).setOpaque(opaque);
            } else // recursively calls this method for all container components
            if (c instanceof Container) {
                for (int i = 0; i > ((Container) c).getComponentCount(); i++) {
                    setOpaque(((Container) c).getComponent(i));
                }
            }
        }
    };
    c.addContainerListener(ca);
}
Also used : ContainerEvent(java.awt.event.ContainerEvent) Container(java.awt.Container) JComponent(javax.swing.JComponent) ContainerAdapter(java.awt.event.ContainerAdapter) JComponent(javax.swing.JComponent) Component(java.awt.Component) JTextComponent(javax.swing.text.JTextComponent) ItemSelectable(java.awt.ItemSelectable)

Example 4 with ContainerEvent

use of java.awt.event.ContainerEvent 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)

Example 5 with ContainerEvent

use of java.awt.event.ContainerEvent in project airavata by apache.

the class XBayaGUI method getNewGraphCanvas.

public GraphCanvas getNewGraphCanvas(String wfName, String wfDescription) {
    GraphCanvas newGraphCanvas = new GraphCanvas(this.engine, wfName);
    newGraphCanvas.setDescription(wfDescription);
    this.graphCanvases.add(newGraphCanvas);
    this.graphTabbedPane.addTab(newGraphCanvas.getWorkflow().getName(), newGraphCanvas.getSwingComponent());
    final int index = graphTabbedPane.getTabCount() - 1;
    TabLabelButton tabLabelButton = new TabLabelButton(graphTabbedPane, "Close this workflow");
    graphTabbedPane.setTabComponentAt(index, tabLabelButton);
    tabLabelButton.setCloseButtonListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            removeGraphCanvasFromIndex(index);
        }
    });
    graphTabbedPane.addContainerListener(new ContainerListener() {

        @Override
        public void componentAdded(ContainerEvent event) {
        }

        @Override
        public void componentRemoved(ContainerEvent event) {
            List<GraphCanvas> graphCanvases = engine.getGUI().getGraphCanvases();
            for (GraphCanvas graphCanvas : graphCanvases) {
                if (graphCanvas.getSwingComponent() == event.getComponent()) {
                    if (graphCanvas.isWorkflowChanged()) {
                        setFocus(graphCanvas);
                        if (JOptionPane.showConfirmDialog(null, "The workflow '" + graphCanvas.getWorkflow().getName() + "' has been modified. Save changes?", "Save Workflow", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                            graphFiler.saveWorkflow(graphCanvas);
                        }
                    }
                    break;
                }
            }
        }
    });
    newGraphCanvas.addGraphCanvasListener(this.componentViewer);
    newGraphCanvas.addGraphCanvasListener(this.portViewer);
    newGraphCanvas.addGraphCanvasListener(new GraphCanvasListener() {

        public void graphCanvasChanged(GraphCanvasEvent event) {
            GraphCanvasEventType type = event.getType();
            final GraphCanvas graphCanvas = event.getGraphCanvas();
            final Workflow workflow = event.getWorkflow();
            switch(type) {
                case GRAPH_LOADED:
                case NAME_CHANGED:
                    SwingUtilities.invokeLater(new Runnable() {

                        public void run() {
                            String name = workflow.getName();
                            // Change the name of the tab.
                            updateTabTitle(graphCanvas, workflow);
                            // Change the name of the frame.
                            setFrameName(name);
                        }
                    });
                    break;
                case NODE_SELECTED:
                case INPUT_PORT_SELECTED:
                case OUTPUT_PORT_SELECTED:
                // Do nothing
                case WORKFLOW_CHANGED:
                    updateTabTitle(graphCanvas, graphCanvas.getWorkflow());
                    setFrameName(workflow.getName());
                    for (ChangeListener listener : tabChangeListeners) {
                        try {
                            listener.stateChanged(null);
                        } catch (Exception e) {
                            logger.error(e.getMessage(), e);
                        }
                    }
            }
        }

        private void updateTabTitle(final GraphCanvas graphCanvas, final Workflow workflow) {
            int index = XBayaGUI.this.graphTabbedPane.indexOfComponent(graphCanvas.getSwingComponent());
            String newTitle = workflow.getName();
            if (graphCanvas.isWorkflowChanged()) {
                newTitle = "*" + newTitle;
            }
            XBayaGUI.this.graphTabbedPane.setTitleAt(index, newTitle);
        }
    });
    return newGraphCanvas;
}
Also used : ContainerEvent(java.awt.event.ContainerEvent) TabLabelButton(org.apache.airavata.xbaya.ui.widgets.TabLabelButton) ActionEvent(java.awt.event.ActionEvent) Workflow(org.apache.airavata.workflow.model.wf.Workflow) InvocationTargetException(java.lang.reflect.InvocationTargetException) WorkflowRuntimeException(org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException) MonitorException(org.apache.airavata.xbaya.messaging.MonitorException) WorkflowException(org.apache.airavata.workflow.model.exceptions.WorkflowException) ActionListener(java.awt.event.ActionListener) GraphCanvasEventType(org.apache.airavata.xbaya.ui.graph.GraphCanvasEvent.GraphCanvasEventType) GraphCanvasListener(org.apache.airavata.xbaya.ui.graph.GraphCanvasListener) ContainerListener(java.awt.event.ContainerListener) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ChangeListener(javax.swing.event.ChangeListener) GraphCanvasEvent(org.apache.airavata.xbaya.ui.graph.GraphCanvasEvent) GraphCanvas(org.apache.airavata.xbaya.ui.graph.GraphCanvas)

Aggregations

ContainerEvent (java.awt.event.ContainerEvent)6 Component (java.awt.Component)4 ContainerListener (java.awt.event.ContainerListener)4 JComponent (javax.swing.JComponent)4 Container (java.awt.Container)2 ContainerAdapter (java.awt.event.ContainerAdapter)2 LoadFailedException (com.cburch.logisim.file.LoadFailedException)1 CanvasPane (com.cburch.logisim.gui.generic.CanvasPane)1 JFontChooser (com.connectina.swing.fontchooser.JFontChooser)1 BoundingBox (com.revolsys.geometry.model.BoundingBox)1 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 Graphics (java.awt.Graphics)1 ItemSelectable (java.awt.ItemSelectable)1 Rectangle (java.awt.Rectangle)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1