Java Code Examples for javax.swing.JComponent#getComponentCount()

The following examples show how to use javax.swing.JComponent#getComponentCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwingTasks.java    From LoboBrowser with MIT License 6 votes vote down vote up
private static void setEnabledRecursive(final JComponent component, final boolean enabled) {
  component.setEnabled(enabled);
  final int count = component.getComponentCount();
  for (int i = 0; i < count; i++) {
    final Component child = component.getComponent(i);
    if (child instanceof JComponent) {
      final JComponent jchild = (JComponent) child;
      if (enabled) {
        final Boolean nestedEnabling = (Boolean) jchild.getClientProperty(NESTED_ENABLING);
        if ((nestedEnabling == null) || nestedEnabling.booleanValue()) {
          setEnabledRecursive(jchild, true);
        }
      } else {
        setEnabledRecursive(jchild, false);
      }
    }
  }
}
 
Example 2
Source File: SeaGlassButtonUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * @see javax.swing.plaf.basic.BasicButtonUI#getMaximumSize(javax.swing.JComponent)
 */
public Dimension getMaximumSize(JComponent c) {
    if (c.getComponentCount() > 0 && c.getLayout() != null) {
        return null;
    }

    AbstractButton   b      = (AbstractButton) c;
    SeaGlassContext  ss     = getContext(c);
    final SynthStyle style2 = ss.getStyle();
    Dimension        size   = style2.getGraphicsUtils(ss).getMaximumSize(ss, style2.getFont(ss), b.getText(), getSizingIcon(b),
                                                                         b.getHorizontalAlignment(), b.getVerticalAlignment(),
                                                                         b.getHorizontalTextPosition(), b.getVerticalTextPosition(),
                                                                         b.getIconTextGap(), b.getDisplayedMnemonicIndex());

    ss.dispose();
    return size;
}
 
Example 3
Source File: SeaGlassButtonUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * @see javax.swing.plaf.basic.BasicButtonUI#getPreferredSize(javax.swing.JComponent)
 */
public Dimension getPreferredSize(JComponent c) {
    if (c.getComponentCount() > 0 && c.getLayout() != null) {
        return null;
    }

    AbstractButton     b             = (AbstractButton) c;
    SeaGlassContext    ss            = getContext(c);
    SynthStyle         style2        = ss.getStyle();
    SynthGraphicsUtils graphicsUtils = style2.getGraphicsUtils(ss);
    Dimension          size          = graphicsUtils.getPreferredSize(ss, style2.getFont(ss), b.getText(), getSizingIcon(b),
                                                                      b.getHorizontalAlignment(),
                                                                      b.getVerticalAlignment(), b.getHorizontalTextPosition(),
                                                                      b.getVerticalTextPosition(), b.getIconTextGap(),
                                                                      b.getDisplayedMnemonicIndex());

    ss.dispose();
    // Make height odd.
    size.height &= ~1;
    return size;
}
 
Example 4
Source File: SeaGlassButtonUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * @see javax.swing.plaf.basic.BasicButtonUI#getMinimumSize(javax.swing.JComponent)
 */
public Dimension getMinimumSize(JComponent c) {
    if (c.getComponentCount() > 0 && c.getLayout() != null) {
        return null;
    }

    AbstractButton   b      = (AbstractButton) c;
    SeaGlassContext  ss     = getContext(c);
    final SynthStyle style2 = ss.getStyle();
    Dimension        size   = style2.getGraphicsUtils(ss).getMinimumSize(ss, style2.getFont(ss), b.getText(), getSizingIcon(b),
                                                                         b.getHorizontalAlignment(), b.getVerticalAlignment(),
                                                                         b.getHorizontalTextPosition(), b.getVerticalTextPosition(),
                                                                         b.getIconTextGap(), b.getDisplayedMnemonicIndex());

    ss.dispose();
    return size;
}
 
Example 5
Source File: FileCheckList.java    From pumpernickel with MIT License 5 votes vote down vote up
private static void getCheckBoxes(JComponent jc, List<JCheckBox> list) {
	if (jc instanceof JCheckBox) {
		list.add((JCheckBox) jc);
	}
	for (int a = 0; a < jc.getComponentCount(); a++) {
		if (jc.getComponent(a) instanceof JComponent) {
			getCheckBoxes((JComponent) jc.getComponent(a), list);
		}
	}
}
 
Example 6
Source File: MagicStyle.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
public static void refreshComponentStyle(final JComponent container) {
    for (Component component : container.getComponents()) {
        if (component instanceof JComponent) {
            final JComponent widget = (JComponent)component;
            if (widget.getComponentCount() > 0) {
                refreshComponentStyle(widget);
            }
            if (widget instanceof IThemeStyle) {
                ((IThemeStyle)widget).refreshStyle();
            }
        }
    }
}
 
Example 7
Source File: BreadCrumbUI.java    From pumpernickel with MIT License 5 votes vote down vote up
@Override
protected Collection<JComponent> getEmphasizedComponents(
		JComponent container) {
	Collection<JComponent> returnValue = super
			.getEmphasizedComponents(container);
	if (returnValue.isEmpty()) {
		// when the super has nothing to emphasize, try to emphasize
		// the last thing the user touched. For ex: if they rolled
		// the mouse over a label and then left the container, keep
		// the last thing they rolled over emphasized, just for
		// continuity.
		List<JComponent> lastEmphasized = (List<JComponent>) container
				.getClientProperty(PROPERTY_LAST_EMPHASIZED);
		if (lastEmphasized != null) {
			returnValue = new ArrayList<>();
			List children = Arrays.asList(container.getComponents());
			for (JComponent jc : lastEmphasized) {
				if (children.contains(jc)) {
					returnValue.add(jc);
				}
			}
		}

		// if that failed, grab the last node in the path.
		if (returnValue.isEmpty() && container.getComponentCount() > 0) {
			JComponent last = (JComponent) container
					.getComponent(container.getComponentCount() - 1);
			returnValue = Arrays.asList(last);
		}
	}
	container.putClientProperty(PROPERTY_LAST_EMPHASIZED,
			new ArrayList<>(returnValue));
	return returnValue;
}
 
Example 8
Source File: JColorPicker.java    From pumpernickel with MIT License 5 votes vote down vote up
private static void setOpaque(JComponent jc, boolean opaque) {
	if (jc instanceof JTextField)
		return;

	jc.setOpaque(false);
	if (jc instanceof JSpinner)
		return;

	for (int a = 0; a < jc.getComponentCount(); a++) {
		JComponent child = (JComponent) jc.getComponent(a);
		setOpaque(child, opaque);
	}
}
 
Example 9
Source File: ColorPicker.java    From PyramidShader with GNU General Public License v3.0 5 votes vote down vote up
private static void setOpaque(JComponent jc,boolean opaque) {
	if(jc instanceof JTextField)
		return;
	
	jc.setOpaque(false);
	if(jc instanceof JSpinner)
		return;
	
	for(int a = 0; a<jc.getComponentCount(); a++) {
		JComponent child = (JComponent)jc.getComponent(a);
		setOpaque(child,opaque);
	}
}
 
Example 10
Source File: AbstractModalDialog.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
protected void setEnabledComponentsWhileLoading(boolean enabled) {
    JDialog dialog = getJDialog();
    JPanel dialogContentPanel = (JPanel)dialog.getContentPane();

    Stack<JComponent> stack = new Stack<JComponent>();
    stack.push(dialogContentPanel);
    while (!stack.isEmpty()) {
        JComponent component = stack.pop();
        component.setEnabled(enabled);
        int childrenCount = component.getComponentCount();
        for (int i=0; i<childrenCount; i++) {
            Component child = component.getComponent(i);
            if (child instanceof JComponent) {
                JComponent childComponent = (JComponent) child;
                boolean found = false;
                for (int k=0; k<this.componentsAllwaysEnabled.size(); k++) {
                    if (childComponent == this.componentsAllwaysEnabled.get(k)) {
                        found = true;
                    }
                }
                if (!found) {
                    // add the component in the stack to be enabled/disabled
                    stack.push(childComponent);
                }
            }
        }
    }
}
 
Example 11
Source File: BatchPatternDialog.java    From xdm with GNU General Public License v2.0 5 votes vote down vote up
private void transparentSpinner(JSpinner spTo2) {
	JComponent c = spTo2.getEditor();
	for (int i = 0; i < c.getComponentCount(); i++) {
		Component ct = c.getComponent(i);
		if (ct instanceof JTextField) {
			ct.setForeground(Color.WHITE);
			ct.setBackground(ColorResource.getDarkBtnColor());
		}
	}
	spTo2.setForeground(Color.WHITE);
	spTo2.setBackground(ColorResource.getDarkBgColor());
	spTo2.setBorder(null);

}
 
Example 12
Source File: PumpernickelShowcaseApp.java    From pumpernickel with MIT License 5 votes vote down vote up
private List<String> getKeywords(JComponent jc) {
	List<String> returnValue = new ArrayList<>();
	if (jc instanceof LazyDemoPanel) {
		LazyDemoPanel ldp = (LazyDemoPanel) jc;
		ShowcaseDemo d = ldp.getShowcaseDemo();
		if (d.getKeywords() == null)
			throw new NullPointerException(ldp.demoClassName);
		for (String keyword : d.getKeywords()) {
			returnValue.add(keyword.toLowerCase());
		}
		Class[] classes = d.getClasses();
		if (classes == null)
			throw new NullPointerException(
					d.getClass().getSimpleName());
		for (Class z : classes) {
			int layer = 0;
			/*
			 * Include at least 4 layers: CircularProgressBarUI ->
			 * BasicProgressBarUI -> ProgressBarUI -> ComponentUI
			 */
			while (z != null && !z.equals(Object.class) && layer < 4) {
				returnValue.add(z.getSimpleName().toLowerCase());
				returnValue.add(z.getName().toLowerCase());
				z = z.getSuperclass();
				layer++;
			}
		}
	}
	for (int a = 0; a < jc.getComponentCount(); a++) {
		if (jc.getComponent(a) instanceof JComponent)
			returnValue.addAll(
					getKeywords((JComponent) jc.getComponent(a)));
	}
	return returnValue;
}
 
Example 13
Source File: AnimatedLayout.java    From pumpernickel with MIT License 5 votes vote down vote up
private void registerChildren(JComponent c) {
	String key = "animatedLayout.propertyListener";
	for (int a = 0; a < c.getComponentCount(); a++) {
		JComponent child = (JComponent) c.getComponent(a);
		if (child.getClientProperty(key) == null) {
			child.putClientProperty(key, destinationListener);
			child.addPropertyChangeListener(PROPERTY_DESTINATION,
					destinationListener);
		}
	}
}
 
Example 14
Source File: LSettingsGui.java    From scelight with Apache License 2.0 5 votes vote down vote up
/**
 * Removes previously bounded {@link ISettingChangeListener}s from the specified component, and also from all of its child components recursively.
 * 
 * <p>
 * Implementation simply clears the client property to which the bounded setting change listener was stored for to trigger the previously registered
 * property change listener to take care of the rest.
 * </p>
 * 
 * @param container container of components whose bounded setting change listener to remove
 * 
 * @see #addBindExecuteScl(ISettingChangeListener, ISettingsBean, Set, JComponent)
 */
public static void removeAllBoundedScl( final JComponent container ) {
	// Just for the short name...
	final JComponent c = container;
	
	if ( c.getClientProperty( PROP_BOUNDED_SCL_LIST ) != null )
		c.putClientProperty( PROP_BOUNDED_SCL_LIST, null );
	
	for ( int i = c.getComponentCount() - 1; i >= 0; i-- ) {
		final Component comp = c.getComponent( i );
		if ( comp instanceof JComponent )
			removeAllBoundedScl( (JComponent) comp );
	}
}
 
Example 15
Source File: SkillDefaultEditor.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private void removeDefault() {
    JComponent parent = (JComponent) getParent();
    parent.remove(this);
    if (parent.getComponentCount() == 0) {
        parent.add(new SkillDefaultEditor());
    }
    parent.revalidate();
    parent.repaint();
    notifyActionListeners();
}
 
Example 16
Source File: MScreenHelper.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
static void refreshComponentStyle(final JComponent container) {
    for (Component component : container.getComponents()) {
        if (component instanceof JComponent) {
            final JComponent widget = (JComponent)component;
            if (widget.getComponentCount() > 0) {
                refreshComponentStyle(widget);
            }
            if (widget instanceof IThemeStyle) {
                ((IThemeStyle)widget).refreshStyle();
            }
        }
    }
}
 
Example 17
Source File: ModelPropertiesDialog.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
private void clearPopupMenu(JComponent component) {
    component.setComponentPopupMenu(null);
    for (int i = 0; i < component.getComponentCount(); i++) {
        Component c = component.getComponent(i);
        if (c instanceof JComponent)
            clearPopupMenu((JComponent) c);
    }
}
 
Example 18
Source File: QualifierPreferencesPanel.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
private void clearPopupMenu(JComponent component) {
    component.setComponentPopupMenu(null);
    for (int i = 0; i < component.getComponentCount(); i++) {
        Component c = component.getComponent(i);
        if (c instanceof JComponent)
            clearPopupMenu((JComponent) c);
    }
}
 
Example 19
Source File: DropTargetLayer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private  void drawOpenSpotAtEndOfMenuBar(Graphics2D g2, JComponent mb) {
    Point mblocation = SwingUtilities.convertPoint(mb, new Point(0,0), this);
    if(mb.getComponentCount() > 0) {
        Component lastComp = mb.getComponent(mb.getComponentCount()-1);
        mblocation.x += lastComp.getX() + lastComp.getWidth();
    }
    g2.drawRect(mblocation.x+2, mblocation.y+2, mb.getHeight()-4, mb.getHeight()-4);
}
 
Example 20
Source File: DropTargetLayer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private boolean isLastChild(JComponent child, JComponent parent) {
    if(parent == null) return false;
    if(parent.getComponentCount() < 1) return false;
    return (child == parent.getComponent(parent.getComponentCount()-1));
}