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;
}
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();
}
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);
}
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);
}
}
});
}
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;
}
Aggregations