Java 类java.awt.Container 实例源码

项目:jdk8u-jdk    文件:SortingFocusTraversalPolicy.java   
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);
    }
}
项目:openjdk-jdk10    文件:XComponentPeer.java   
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);
        }
    }
}
项目:AgentWorkbench    文件:ProjectWindow.java   
@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);
}
项目:alevin-svn2    文件:SatelliteViewerCorner.java   
@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();
}
项目:openjdk-jdk10    文件:Test8039464.java   
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);
}
项目:openjdk-jdk10    文件:bug6219960.java   
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;
    }
项目:OpenJSharp    文件:XComponentPeer.java   
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);
        }
    }
}
项目:OpenJSharp    文件:MotifOptionPaneUI.java   
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);
        }
    };
}
项目:marathonv5    文件:GeneralSiblingSelector.java   
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;
}
项目:jdk8u-jdk    文件:JDesktopPane.java   
/**
 * 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();
}
项目:nativehtml    文件:SwingLayoutAdapter.java   
@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);
}
项目:incubator-netbeans    文件:MethodChooser.java   
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();
}
项目:openjdk-jdk10    文件:Test4619792.java   
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);
        }
    }
}
项目:Bachelor-Thesis    文件:RoutingInfoWindow.java   
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);
}
项目:jaer    文件:SingleOrStereoCameraCalibration.java   
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);
        }
    }
}
项目:ats-framework    文件:SwingElementFinder.java   
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);
}
项目:jdk8u-jdk    文件:MetalworksDocumentFrame.java   
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);
}
项目:openjdk-jdk10    文件:D3DScreenUpdateManager.java   
/**
 * 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;
}
项目:jdk8u-jdk    文件:AncestorNotifier.java   
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());
        }
    }
}
项目:VASSAL-src    文件:WizardDisplayerImpl.java   
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;
}
项目:incubator-netbeans    文件:PalettePanel.java   
@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);
    }
}
项目:OpenGL-Bullet-engine    文件:VerticalFlowLayout.java   
/**
 * 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;
    }
}
项目:OpenJSharp    文件:SynthMenuLayout.java   
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);
}
项目:incubator-netbeans    文件:FileEditor.java   
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);
        }
    }
}
项目:openjdk-jdk10    文件:SwingContainerIsForContainerOnly.java   
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;
        };
    });
}
项目:openjdk-jdk10    文件:AncestorNotifier.java   
/**
 * 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);
        }
    }
}
项目:jdk8u-jdk    文件:LegacyGlueFocusTraversalPolicy.java   
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;
}
项目:VASSAL-src    文件:HexGrid.java   
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;
  }
项目:incubator-netbeans    文件:ToolbarRow.java   
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;
}
项目:Method_Trace_Tool    文件:VerticalFlowLayout.java   
/**
 * 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);
}
项目:JuggleMasterPro    文件:Tools.java   
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);
            }
        }
    }
项目:openjdk-jdk10    文件:ContainerOperator.java   
/**
 * Maps {@code Container.getComponentCount()} through queue
 */
public int getComponentCount() {
    return (runMapping(new MapIntegerAction("getComponentCount") {
        @Override
        public int map() {
            return ((Container) getSource()).getComponentCount();
        }
    }));
}
项目:incubator-netbeans    文件:NbURLMapper.java   
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;
}
项目:incubator-netbeans    文件:OutputOperator.java   
/** 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;
}
项目:cuttlefish    文件:VertexImageShaperDemo.java   
/**
* 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);
  }
项目:POPBL_V    文件:RecordDialog.java   
private Container dialogPanel() {
    JPanel panel = new JPanel(new BorderLayout());

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

    return panel;
}
项目:incubator-netbeans    文件:TerminalAction.java   
@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();
}
项目:jaer    文件:DynamicFontSizeJLabel.java   
@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);
            }
        }
    }
项目:JDigitalSimulator    文件:Simulation.java   
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;
}
项目:incubator-netbeans    文件:NbPresenter.java   
/** 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();
        }
    }
}