Java Code Examples for java.awt.Container

The following are top voted examples for showing how to use java.awt.Container. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: jdk8u-jdk   File: SortingFocusTraversalPolicy.java   Source Code and License 6 votes vote down vote up
private void enumerateCycle(Container container, List<Component> cycle) {
    if (!(container.isVisible() && container.isDisplayable())) {
        return;
    }

    cycle.add(container);

    Component[] components = container.getComponents();
    for (Component comp : components) {
        if (comp instanceof Container) {
            Container cont = (Container)comp;

            if (!cont.isFocusCycleRoot() &&
                !cont.isFocusTraversalPolicyProvider() &&
                !((cont instanceof JComponent) && ((JComponent)cont).isManagingFocus()))
            {
                enumerateCycle(cont, cycle);
                continue;
            }
        }
        cycle.add(comp);
    }
}
 
Example 2
Project: openjdk-jdk10   File: XComponentPeer.java   Source Code and License 6 votes vote down vote up
private void addTree(Collection<Long> order, Set<Long> set, Container cont) {
    for (int i = 0; i < cont.getComponentCount(); i++) {
        Component comp = cont.getComponent(i);
        Object peer = AWTAccessor.getComponentAccessor().getPeer(comp);
        if (peer instanceof XComponentPeer) {
            Long window = Long.valueOf(((XComponentPeer)peer).getWindow());
            if (!set.contains(window)) {
                set.add(window);
                order.add(window);
            }
        } else if (comp instanceof Container) {
            // It is lightweight container, it might contain heavyweight components attached to this
            // peer
            addTree(order, set, (Container)comp);
        }
    }
}
 
Example 3
Project: AgentWorkbench   File: ProjectWindow.java   Source Code and License 6 votes vote down vote up
@Override
public void removeProjectTab(ProjectWindowTab projectWindowTab) {

	DefaultMutableTreeNode node = this.getTreeNode(projectWindowTab.getTitle());
	if (node != null) {
		DefaultMutableTreeNode pareNode = (DefaultMutableTreeNode) node.getParent();
		pareNode.remove(node);
	}

	JComponent component = projectWindowTab.getJComponentForVisualization();
	Container container = component.getParent();
	if (container != null) {
		container.remove(component);
	}
	this.tabVector.remove(projectWindowTab);

	this.getTreeModel().reload();
	this.projectTreeExpand2Level(3, true);
}
 
Example 4
Project: alevin-svn2   File: SatelliteViewerCorner.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void setViewer(LayerViewer vv) {
	if (this.vv == vv)
		return;
	this.vv = vv;
	Container contentPane = satellite.getContentPane();

	if (satelliteViewer != null)
		contentPane.remove(satelliteViewer);
	if (vv != null) {
		satelliteViewer = new MySatelliteVisualizationViewer(vv,
				new Dimension(100, 100));

		satelliteViewer.getRenderContext().setVertexFillPaintTransformer(
				vv.getRenderContext().getVertexFillPaintTransformer());

		vv.addChangeListener(satelliteViewer);

		contentPane.add(satelliteViewer);
	} else {
		satelliteViewer = null;
	}
	satellite.pack();
	autoZoomSatellite();
}
 
Example 5
Project: openjdk-jdk10   File: Test8039464.java   Source Code and License 6 votes vote down vote up
private static void init(Container container) {
    container.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridx = 0;
    gbc.gridy = 1;
    JLabel label = new JLabel();
    Dimension size = new Dimension(111, 0);
    label.setPreferredSize(size);
    label.setMinimumSize(size);
    container.add(label, gbc);
    gbc.gridx = 1;
    gbc.weightx = 1;
    container.add(new JScrollBar(JScrollBar.HORIZONTAL, 1, 111, 1, 1111), gbc);
    gbc.gridx = 2;
    gbc.gridy = 0;
    gbc.weightx = 0;
    gbc.weighty = 1;
    container.add(new JScrollBar(JScrollBar.VERTICAL, 1, 111, 1, 1111), gbc);
}
 
Example 6
Project: openjdk-jdk10   File: bug6219960.java   Source Code and License 6 votes vote down vote up
private static JButton findButton(Component comp) {

        if (comp instanceof JButton) {
            return (JButton) comp;
        }

        if (comp instanceof Container) {
            Container cont = (Container) comp;
            for (int i = 0; i < cont.getComponentCount(); i++) {
                JButton result = findButton(cont.getComponent(i));
                if (result != null) {
                    return result;
                }
            }
        }
        return null;
    }
 
Example 7
Project: OpenJSharp   File: XComponentPeer.java   Source Code and License 6 votes vote down vote up
private void addTree(Collection order, Set set, Container cont) {
    for (int i = 0; i < cont.getComponentCount(); i++) {
        Component comp = cont.getComponent(i);
        ComponentPeer peer = comp.getPeer();
        if (peer instanceof XComponentPeer) {
            Long window = Long.valueOf(((XComponentPeer)peer).getWindow());
            if (!set.contains(window)) {
                set.add(window);
                order.add(window);
            }
        } else if (comp instanceof Container) {
            // It is lightweight container, it might contain heavyweight components attached to this
            // peer
            addTree(order, set, (Container)comp);
        }
    }
}
 
Example 8
Project: OpenJSharp   File: MotifOptionPaneUI.java   Source Code and License 6 votes vote down vote up
protected Container createSeparator() {
    return new JPanel() {

        public Dimension getPreferredSize() {
            return new Dimension(10, 2);
        }

        public void paint(Graphics g) {
            int width = getWidth();
            g.setColor(Color.darkGray);
            g.drawLine(0, 0, width, 0);
            g.setColor(Color.white);
            g.drawLine(0, 1, width, 1);
        }
    };
}
 
Example 9
Project: marathonv5   File: GeneralSiblingSelector.java   Source Code and License 6 votes vote down vote up
protected List<IJavaElement> found(List<IJavaElement> pElements, IJavaAgent driver) {
    List<IJavaElement> r = new ArrayList<IJavaElement>();
    for (IJavaElement je : pElements) {
        Component component = je.getComponent();
        if (!(component instanceof Container)) {
            continue;
        }
        int index = getIndexOfComponentInParent(component);
        if (index < 0) {
            continue;
        }
        Container parent = component.getParent();
        JWindow topContainer = driver.switchTo().getTopContainer();
        for (int i = index + 1; i < parent.getComponentCount(); i++) {
            Component c = parent.getComponent(i);
            IJavaElement je2 = JavaElementFactory.createElement(c, driver, driver.switchTo().getTopContainer());
            if (sibling.matchesSelector(je2).size() > 0) {
                IJavaElement e = topContainer.addElement(JavaElementFactory.createElement(c, driver, topContainer));
                if (!r.contains(e)) {
                    r.add(e);
                }
            }
        }
    }
    return r;
}
 
Example 10
Project: jdk8u-jdk   File: JDesktopPane.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a new <code>JDesktopPane</code>.
 */
public JDesktopPane() {
    setUIProperty("opaque", Boolean.TRUE);
    setFocusCycleRoot(true);

    setFocusTraversalPolicy(new LayoutFocusTraversalPolicy() {
        public Component getDefaultComponent(Container c) {
            JInternalFrame jifArray[] = getAllFrames();
            Component comp = null;
            for (JInternalFrame jif : jifArray) {
                comp = jif.getFocusTraversalPolicy().getDefaultComponent(jif);
                if (comp != null) {
                    break;
                }
            }
            return comp;
        }
    });
    updateUI();
}
 
Example 11
Project: nativehtml   File: SwingLayoutAdapter.java   Source Code and License 6 votes vote down vote up
@Override
public void layoutContainer(Container container) {
  ComponentElement parent = (ComponentElement) container;
  CssStyleDeclaration style = ((ComponentElement) parent).getComputedStyle();

  float scale = parent.getOwnerDocument().getSettings().getScale();
  float containingBoxWidth = container.getWidth() / scale;

  float left = style.getPx(CssProperty.BORDER_LEFT_WIDTH, containingBoxWidth) + 
      style.getPx(CssProperty.PADDING_LEFT, containingBoxWidth);
  float top = style.getPx(CssProperty.BORDER_TOP_WIDTH, containingBoxWidth) + 
      style.getPx(CssProperty.PADDING_TOP, containingBoxWidth);
  float right = style.getPx(CssProperty.BORDER_RIGHT_WIDTH, containingBoxWidth) + 
      style.getPx(CssProperty.PADDING_RIGHT, containingBoxWidth);
  
  layout.layout(parent, left, top, container.getWidth() - left - right, false);
}
 
Example 12
Project: incubator-netbeans   File: MethodChooser.java   Source Code and License 6 votes vote down vote up
private static void requestFocus(final JEditorPane editorPane) {
    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                requestFocus(editorPane);
            }
        });
        return ;
    }
    Container p = editorPane;
    while ((p = p.getParent()) != null) {
        if (p instanceof TopComponent) {
            ((TopComponent) p).requestActive();
            break;
        }
    }
    editorPane.requestFocusInWindow();
}
 
Example 13
Project: openjdk-jdk10   File: Test4619792.java   Source Code and License 6 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    Class[] types = {
            Component.class,
            Container.class,
            JComponent.class,
            AbstractButton.class,
            JButton.class,
            JToggleButton.class,
    };
    // Control set. "enabled" and "name" has the same pattern and can be found
    String[] names = {
            "enabled",
            "name",
            "focusable",
    };
    for (String name : names) {
        for (Class type : types) {
            BeanUtils.getPropertyDescriptor(type, name);
        }
    }
}
 
Example 14
Project: Bachelor-Thesis   File: RoutingInfoWindow.java   Source Code and License 6 votes vote down vote up
public RoutingInfoWindow(DTNHost host) {
	this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	this.host = host;
	Container cp = this.getContentPane();
	this.setLayout(new BorderLayout());
	
	this.treePane = new JScrollPane();
	updateTree();
	
	cp.add(treePane, BorderLayout.NORTH);
	
	this.refreshButton = new JButton("refresh");
	this.refreshButton.addActionListener(this);
	cp.add(refreshButton, BorderLayout.SOUTH);
	
	this.pack();		
	this.setVisible(true);
}
 
Example 15
Project: jaer   File: SingleOrStereoCameraCalibration.java   Source Code and License 6 votes vote down vote up
static void setButtonState(Container c, String buttonString, boolean flag) {
	int len = c.getComponentCount();
	for (int i = 0; i < len; i++) {
		Component comp = c.getComponent(i);

		if (comp instanceof JButton) {
			JButton b = (JButton) comp;

			if (buttonString.equals(b.getText())) {
				b.setEnabled(flag);
			}

		} else if (comp instanceof Container) {
			setButtonState((Container) comp, buttonString, flag);
		}
	}
}
 
Example 16
Project: ats-framework   File: SwingElementFinder.java   Source Code and License 6 votes vote down vote up
public static <T extends Component> T find(
                                            Robot robot,
                                            Container root,
                                            GenericTypeMatcher<T> m ) {

    ComponentHierarchy hierarchy = robot.hierarchy();
    List<Component> found = null;
    if (root == null) {
        found = find(hierarchy, m);
    } else {
        found = find(new SingleComponentHierarchy(root, hierarchy), m);
    }
    if (found.isEmpty()) {
        throw componentNotFound(robot, hierarchy, m);
    }
    if (found.size() > 1) {
        throw multipleComponentsFound(found, m);
    }
    Component component = found.iterator().next();
    return m.supportedType().cast(component);
}
 
Example 17
Project: jdk8u-jdk   File: MetalworksDocumentFrame.java   Source Code and License 6 votes vote down vote up
public Dimension minimumLayoutSize(Container c) {
    Insets insets = c.getInsets();

    int labelWidth = 0;
    for (Component comp : labels) {
        labelWidth = Math.max(labelWidth, comp.getPreferredSize().width);
    }

    int yPos = insets.top;

    Iterator<Component> labelIter = labels.listIterator();
    Iterator<Component> fieldIter = fields.listIterator();
    while (labelIter.hasNext() && fieldIter.hasNext()) {
        Component label = labelIter.next();
        Component field = fieldIter.next();
        int height = Math.max(label.getPreferredSize().height, field.
                getPreferredSize().height);
        yPos += (height + yGap);
    }
    return new Dimension(labelWidth * 3, yPos);
}
 
Example 18
Project: openjdk-jdk10   File: D3DScreenUpdateManager.java   Source Code and License 5 votes vote down vote up
/**
 * Returns true if the component has heavyweight children.
 *
 * @param comp component to check for hw children
 * @return true if Component has heavyweight children
 */
private static boolean hasHWChildren(Component comp) {
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    if (comp instanceof Container) {
        for (Component c : ((Container)comp).getComponents()) {
            if (acc.getPeer(c) instanceof WComponentPeer || hasHWChildren(c)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 19
Project: jdk8u-jdk   File: AncestorNotifier.java   Source Code and License 5 votes vote down vote up
public void componentShown(ComponentEvent e) {
    Component ancestor = e.getComponent();

    if (ancestor == firstInvisibleAncestor) {
        addListeners(ancestor, false);
        if (firstInvisibleAncestor == null) {
            fireAncestorAdded(root, AncestorEvent.ANCESTOR_ADDED,
                              (Container)ancestor, ancestor.getParent());
        }
    }
}
 
Example 20
Project: VASSAL-src   File: WizardDisplayerImpl.java   Source Code and License 5 votes vote down vote up
public void install (Container c, Object layoutConstraint, Wizard awizard,
        Action helpAction, Map initialProperties, WizardResultReceiver receiver) {        
    JPanel pnl = createOuterPanel (awizard, new Rectangle(), helpAction, initialProperties);
    if (layoutConstraint != null) {
        c.add (pnl, layoutConstraint);
    } else {
        c.add (pnl);
    }
    this.receiver = receiver;
}
 
Example 21
Project: incubator-netbeans   File: PalettePanel.java   Source Code and License 5 votes vote down vote up
@Override
public void layoutContainer( Container parent ) {
    super.layoutContainer(parent);
    if( null != searchpanel && searchpanel.isVisible() ) {
        Insets innerInsets = scrollPane.getInnerInsets();
        Dimension prefSize = searchpanel.getPreferredSize();
        searchpanel.setBounds(innerInsets.left, parent.getHeight()-innerInsets.bottom-prefSize.height,
                parent.getWidth()-innerInsets.left-innerInsets.right, prefSize.height);
    }
}
 
Example 22
Project: OpenGL-Bullet-engine   File: VerticalFlowLayout.java   Source Code and License 5 votes vote down vote up
/**
 * Description of the Method
 *
 * @param target
 *            Description of Parameter
 * @return Description of the Returned Value
 */
@Override
public Dimension minimumLayoutSize(Container target){
	synchronized(target.getTreeLock()){
		Dimension dim=new Dimension(0, 0);
		int nmembers=target.getComponentCount();
		boolean firstVisibleComponent=true;
		
		for(int ii=0;ii<nmembers;ii++){
			Component m=target.getComponent(ii);
			if(m.isVisible()){
				Dimension d=m.getPreferredSize();
				dim.width=Math.max(dim.width, d.width);
				if(firstVisibleComponent){
					firstVisibleComponent=false;
				}else{
					dim.height+=_vgap;
				}
				dim.height+=d.height;
			}
		}
		Insets insets=target.getInsets();
		dim.width+=insets.left+insets.right+_hgap*2;
		dim.height+=insets.top+insets.bottom+_vgap*2;
		return dim;
	}
}
 
Example 23
Project: OpenJSharp   File: SynthMenuLayout.java   Source Code and License 5 votes vote down vote up
public Dimension preferredLayoutSize(Container target) {
    if (target instanceof JPopupMenu) {
        JPopupMenu popupMenu = (JPopupMenu) target;
        popupMenu.putClientProperty(
                SynthMenuItemLayoutHelper.MAX_ACC_OR_ARROW_WIDTH, null);
    }

    return super.preferredLayoutSize(target);
}
 
Example 24
Project: incubator-netbeans   File: FileEditor.java   Source Code and License 5 votes vote down vote up
private void hideShowButtons (Container cont, boolean val) {
    if (cont instanceof JComboBox || cont instanceof JScrollBar) {
        return;
    }
    Component[] c = cont.getComponents();
    for (int i=0; i < c.length; i++) {
        if (c[i] instanceof Container) {
            hideShowButtons ((Container) c[i], val);
        }
        if (c[i] instanceof AbstractButton) {
            c[i].setVisible(val);
        }
    }
}
 
Example 25
Project: openjdk-jdk10   File: SwingContainerIsForContainerOnly.java   Source Code and License 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
    fs.getFileStores();
    Files.walkFileTree(fs.getPath("/modules/java.desktop"), new SimpleFileVisitor<>() {
        @Override
        public FileVisitResult visitFile(Path file,
                                         BasicFileAttributes attrs) {
            file = file.subpath(2, file.getNameCount());
            String name = file.toString();
            if (name.endsWith(".class")) {
                name = name.substring(0, name.indexOf(".")).replace('/', '.');

                final Class<?> type;
                try {
                    type = Class.forName(name, false, null);
                } catch (Throwable e) {
                    return FileVisitResult.CONTINUE;
                }
                if (type.isAnnotationPresent(SwingContainer.class)) {
                    if (!Container.class.isAssignableFrom(type)) {
                        System.err.println("Wrong annotation for: " + type);
                        throw new RuntimeException();
                    }
                }
            }
            return FileVisitResult.CONTINUE;
        };
    });
}
 
Example 26
Project: openjdk-jdk10   File: AncestorNotifier.java   Source Code and License 5 votes vote down vote up
/**
 * Notify all listeners that have registered interest for
 * notification on this event type.  The event instance
 * is lazily created using the parameters passed into
 * the fire method.
 * @see EventListenerList
 */
protected void fireAncestorMoved(JComponent source, int id, Container ancestor, Container ancestorParent) {
    // Guaranteed to return a non-null array
    Object[] listeners = listenerList.getListenerList();
    // Process the listeners last to first, notifying
    // those that are interested in this event
    for (int i = listeners.length-2; i>=0; i-=2) {
        if (listeners[i]==AncestorListener.class) {
            // Lazily create the event:
            AncestorEvent ancestorEvent =
                new AncestorEvent(source, id, ancestor, ancestorParent);
            ((AncestorListener)listeners[i+1]).ancestorMoved(ancestorEvent);
        }
    }
}
 
Example 27
Project: jdk8u-jdk   File: LegacyGlueFocusTraversalPolicy.java   Source Code and License 5 votes vote down vote up
public Component getComponentAfter(Container focusCycleRoot,
                                   Component aComponent) {
    Component hardCoded = aComponent, prevHardCoded;
    HashSet<Component> sanity = new HashSet<Component>();

    do {
        prevHardCoded = hardCoded;
        hardCoded = forwardMap.get(hardCoded);
        if (hardCoded == null) {
            if (delegatePolicy != null &&
                prevHardCoded.isFocusCycleRoot(focusCycleRoot)) {
                return delegatePolicy.getComponentAfter(focusCycleRoot,
                                                        prevHardCoded);
            } else if (delegateManager != null) {
                return delegateManager.
                    getComponentAfter(focusCycleRoot, aComponent);
            } else {
                return null;
            }
        }
        if (sanity.contains(hardCoded)) {
            // cycle detected; bail
            return null;
        }
        sanity.add(hardCoded);
    } while (!accept(hardCoded));

    return hardCoded;
}
 
Example 28
Project: VASSAL-src   File: HexGrid.java   Source Code and License 5 votes vote down vote up
public Configurer getConfigurer() {

    boolean buttonExists = config != null;

    AutoConfigurer c = (AutoConfigurer) super.getConfigurer();
    final Configurer dxConfig = c.getConfigurer(DX);
    c.getConfigurer(DY).addPropertyChangeListener(new java.beans.PropertyChangeListener() {
      public void propertyChange(java.beans.PropertyChangeEvent evt) {
        if (evt.getNewValue() != null) {
          double hgt = ((Double) evt.getNewValue()).doubleValue();
          dxConfig.setValue(Double.valueOf(sqrt3_2 * hgt).toString());
        }
      }
    });

    if (!buttonExists) {
      JButton b = new JButton(Resources.getString("Editor.Grid.edit_grid")); //$NON-NLS-1$
      b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          editGrid();
        }
      });
      ((Container) c.getControls()).add(b);
    }

    return config;
  }
 
Example 29
Project: incubator-netbeans   File: ToolbarRow.java   Source Code and License 5 votes vote down vote up
public Dimension preferredLayoutSize(Container parent) {
    Dimension d = new Dimension( 0,0 );
    d.height = getPreferredHeight();
    for( Component c : getComponents() ) {
        if( !c.isVisible() )
            continue;
        d.width += c.getPreferredSize().width;
    }
    Insets borderInsets = parent.getInsets();
    if( null != borderInsets ) {
        d.height += borderInsets.top;
        d.height += borderInsets.bottom;
    }
    return d;
}
 
Example 30
Project: Method_Trace_Tool   File: VerticalFlowLayout.java   Source Code and License 5 votes vote down vote up
/**
 * Lays out the container.
 *
 * @param target
 *            the container to lay out.
 */
public void layoutContainer(Container target) {
	Insets insets = target.getInsets();
	int maxheight = target.getSize().height
			- (insets.top + insets.bottom + vgap * 2);
	int maxwidth = target.getSize().width
			- (insets.left + insets.right + hgap * 2);
	int numcomp = target.getComponentCount();
	int x = insets.left + hgap, y = 0;
	int colw = 0, start = 0;

	for (int i = 0; i < numcomp; i++) {
		Component m = target.getComponent(i);
		if (m.isVisible()) {
			Dimension d = m.getPreferredSize();
			// fit last component to remaining height
			if ((this.vfill) && (i == (numcomp - 1))) {
				d.height = Math.max((maxheight - y),
						m.getPreferredSize().height);
			}

			// fit component size to container width
			if (this.hfill) {
				m.setSize(maxwidth, d.height);
				d.width = maxwidth;
			} else {
				m.setSize(d.width, d.height);
			}

			if (y + d.height > maxheight) {
				placethem(target, x, insets.top + vgap, colw,
						maxheight - y, start, i);
				y = d.height;
				x += hgap + colw;
				colw = d.width;
				start = i;
			} else {
				if (y > 0)
					y += vgap;
				y += d.height;
				colw = Math.max(colw, d.width);
			}
		}
	}
	placethem(target, x, insets.top + vgap, colw, maxheight - y, start,
			numcomp);
}
 
Example 31
Project: JuggleMasterPro   File: Tools.java   Source Code and License 5 votes vote down vote up
public static void doSetFont(Container objLfatherContainer, Font objLfont) {

		objLfatherContainer.setFont(objLfont);
		for (final Component objLcomponent : objLfatherContainer.getComponents()) {
			if (objLcomponent instanceof Container) {
				Tools.doSetFont((Container) objLcomponent, objLfont);
			} else {
				objLcomponent.setFont(objLfont);
			}
		}
	}
 
Example 32
Project: openjdk-jdk10   File: ContainerOperator.java   Source Code and License 5 votes vote down vote up
/**
 * Maps {@code Container.getComponentCount()} through queue
 */
public int getComponentCount() {
    return (runMapping(new MapIntegerAction("getComponentCount") {
        @Override
        public int map() {
            return ((Container) getSource()).getComponentCount();
        }
    }));
}
 
Example 33
Project: incubator-netbeans   File: NbURLMapper.java   Source Code and License 5 votes vote down vote up
protected URL getUrl(JTextComponent comp) {
    FileObject f = null;
    
    if (comp instanceof Lookup.Provider) {
        f = ((Lookup.Provider) comp).getLookup().lookup(FileObject.class);
    }
    
    if (f == null) {
        Container container = comp.getParent();
        while (container != null) {
            if (container instanceof Lookup.Provider) {
                f = ((Lookup.Provider) container).getLookup().lookup(FileObject.class);
                if (f != null) {
                    break;
                }
            }
            
            container = container.getParent();
        }
    }
    
    if (f != null) {
        try {
            return f.getURL();
        } catch (FileStateInvalidException e) {
            LOG.log(Level.WARNING, "Can't get URL for " + f, e); //NOI18N
        }
    }
    
    return null;
}
 
Example 34
Project: incubator-netbeans   File: OutputOperator.java   Source Code and License 5 votes vote down vote up
/** Returns active OutputTabOperator instance regardless it is the only one in
 * output or it is in tabbed pane.
 * @return active OutputTabOperator instance
 */
private OutputTabOperator getActiveOutputTab() {
    OutputTabOperator outputTabOper;
    if(null != JTabbedPaneOperator.findJTabbedPane((Container)getSource(), ComponentSearcher.getTrueChooser(""))) {
        outputTabOper = new OutputTabOperator(((JComponent)new JTabbedPaneOperator(this).getSelectedComponent()));
        outputTabOper.copyEnvironment(this);
    } else {
        outputTabOper = new OutputTabOperator("");
    }
    return outputTabOper;
}
 
Example 35
Project: cuttlefish   File: VertexImageShaperDemo.java   Source Code and License 5 votes vote down vote up
/**
* a driver for this demo
*/
  public static void main(String[] args) {
      JFrame frame = new JFrame();
      Container content = frame.getContentPane();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      content.add(new VertexImageShaperDemo());
      frame.pack();
      frame.setVisible(true);
  }
 
Example 36
Project: POPBL_V   File: RecordDialog.java   Source Code and License 5 votes vote down vote up
private Container dialogPanel() {
	JPanel panel = new JPanel(new BorderLayout());

	panel.add(dataPanel(), BorderLayout.CENTER);
	panel.add(buttonPanel(), BorderLayout.SOUTH);

	return panel;
}
 
Example 37
Project: incubator-netbeans   File: TerminalAction.java   Source Code and License 5 votes vote down vote up
@Override
public final void actionPerformed(ActionEvent e) {
    if (context == null) {
        Object source = e.getSource();
        /*
 Kind of a hack, but I can't think up a better way to get a current
 terminal when Action is performed with the shortcut. Thus it's context
 independent and we need to find an active Terminal. Getting it from TC
 won't work because we can have multiple active Terminals on screen
 (debugger console and terminalemulator, for example).
 Luckily, we can get some useful information from the caller`s source
         */
        if (source instanceof Component) {
            Container container = SwingUtilities.getAncestorOfClass(Terminal.class, (Component) source);
            if (container != null && container instanceof Terminal) {
                this.context = (Terminal) container;
            }
        }
    }

    if (getTerminal() == null) {
        throw new IllegalStateException("No valid terminal component was provided"); // NOI18N
    }

    this.event = e;
    performAction();
}
 
Example 38
Project: jaer   File: DynamicFontSizeJLabel.java   Source Code and License 5 votes vote down vote up
@Override
    public void setText(String str) {
//        System.out.println("setText(\""+str+"\")");
        super.setText(str);
        Container parent=getParent();
        if(parent!=null){
            int w=getWidth();
            int p=parent.getWidth();
            if(w>=p){
                formComponentResized(null);
            }
        }
    }
 
Example 39
Project: JDigitalSimulator   File: Simulation.java   Source Code and License 5 votes vote down vote up
private Application getApplication() {
	Container parent = this.getTopLevelAncestor();
	if(parent instanceof Application)
		return (Application)parent;
	parent = this.getParent();
	while((parent=parent.getParent())!=null)
		if(parent instanceof Application)
			break;
	return parent!=null?(Application)parent:null;
}
 
Example 40
Project: incubator-netbeans   File: NbPresenter.java   Source Code and License 5 votes vote down vote up
/** Requests focus for <code>currentMessage</code> component.
 * If it is of <code>JComponent</code> type it tries default focus
 * request first. */
private void requestFocusForMessage() {
    Component comp = currentMessage;
    
    if(comp == null) {
        return;
    }

    if (/*!Constants.AUTO_FOCUS &&*/ FocusManager.getCurrentManager().getActiveWindow() == null) {
        // Do not steal focus if no Java window have it
        Component defComp = null;
        Container nearestRoot =
            (comp instanceof Container && ((Container) comp).isFocusCycleRoot()) ? (Container) comp : comp.getFocusCycleRootAncestor();
        if (nearestRoot != null) {
            defComp = nearestRoot.getFocusTraversalPolicy().getDefaultComponent(nearestRoot);
        }
        if (defComp != null) {
            defComp.requestFocusInWindow();
        } else {
            comp.requestFocusInWindow();
        }
    } else {
        if (!(comp instanceof JComponent)
            || !((JComponent)comp).requestDefaultFocus()) {

            comp.requestFocus();
        }
    }
}