Java Code Examples for javax.swing.JToolBar#getComponents()

The following examples show how to use javax.swing.JToolBar#getComponents() . 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: AbstractToolbarFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void update (String containerCtx) {
//        System.err.println("ToolbarFactory update " + containerCtx);
        JToolBar tb = (JToolBar) mappings.get(munge(containerCtx));
        synchronized (tb.getTreeLock()) {
    //        System.err.println("Toolbar to update: " + tb);
            ActionProvider provider = getEngine().getActionProvider();
            if (tb != null) {
                Component[] c = tb.getComponents();
                for (int i=0; i < c.length; i++) {
                    if (c[i] instanceof AbstractButton) {
                        AbstractButton b = (AbstractButton) c[i];
                        String action = (String) b.getClientProperty (KEY_ACTION);
                        configureToolbarButton (b, containerCtx, action, provider,
                            getEngine().getContextProvider().getContext());
                    }
                }

            } else {
                System.err.println("Asked to update non existent toolbar " + containerCtx);
            }
        }
    }
 
Example 2
Source File: OpenTCSView.java    From openAGV with Apache License 2.0 5 votes vote down vote up
private void configureToolBarButtons(JToolBar bar) {
  final Dimension dimButton = new Dimension(32, 34);
  for (Component comp : bar.getComponents()) {
    if (comp instanceof JButton || comp instanceof JToggleButton) {
      JComponent tbButton = (JComponent) comp;
      tbButton.setMaximumSize(dimButton);
      tbButton.setPreferredSize(dimButton);
      tbButton.setBorder(new EtchedBorder());
    }
  }
}
 
Example 3
Source File: PaletteToolBarBorder.java    From openAGV with Apache License 2.0 5 votes vote down vote up
@Override
public void paintBorder(Component component, Graphics gr, int x, int y, int w, int h) {
  Graphics2D g = (Graphics2D) gr;

  g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
  g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

  if ((component instanceof JToolBar) /* && ((((JToolBar) component).getUI()) instanceof PaletteToolBarUI) */) {
    JToolBar c = (JToolBar) component;

    if (c.isFloatable()) {
      int borderColor = 0x80ff0000;
      float[] stops = ENABLED_STOPS;
      Color[] stopColors = ENABLED_STOP_COLORS;

      g.setColor(new Color(borderColor, true));
      LinearGradientPaint lgp = new LinearGradientPaint(
          new Point2D.Float(1, 1), new Point2D.Float(19, 1),
          stops, stopColors,
          MultipleGradientPaint.CycleMethod.REPEAT);
      g.setPaint(lgp);
      g.fillRect(1, 1, 7 - 2, h - 2);
      ImageIcon icon = new ImageIcon(getClass().getResource("/org/opentcs/guing/res/symbols/toolbar/border.jpg"));

      if (c.getComponentCount() != 0 && !(c.getComponents()[0] instanceof JLabel)) {
        JLabel label = new JLabel(icon);
        label.setFocusable(false);
        c.add(label, 0);
        label.getParent().setBackground(label.getBackground());
        label.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
      }
    }
  }
}
 
Example 4
Source File: PageInspectorImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Uninitializes the selection mode (removes the page inspection
 * component/s from the toolbar).
 * 
 * @param toolBar toolBar to remove the buttons from.
 */
void uninitSelectionMode(JToolBar toolBar) {
    if (toolBar != null) {
        for (Component component : toolBar.getComponents()) {
            if (SELECTION_MODE_COMPONENT_NAME.equals(component.getName())) {
                toolBar.remove(component);
                break;
            }
        }
    }
}
 
Example 5
Source File: DocumentEditor.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Updates the selected state of the buttons on one of the toolbars.
 * 
 * @param toolbar
 *          toolbar to update
 */
protected void updateBar(JToolBar toolbar) {
  Component btns[] = toolbar.getComponents();
  if(btns != null) {
    for(Component btn : btns) {
      if(btn instanceof ViewButton) ((ViewButton)btn).updateSelected();
    }
  }
}
 
Example 6
Source File: UI2.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 2 votes vote down vote up
/**
 * enable / disable components
 *
 * @param t
 * @param s
 */
private void eComponents(JToolBar t, boolean s) {
    for (Component c : t.getComponents()) {
        c.setEnabled(s);
    }
}
 
Example 7
Source File: AKDockLayout.java    From WorldPainter with GNU General Public License v3.0 2 votes vote down vote up
private void flipSeparators(Component c, int orientn) {

        if (c != null && c instanceof JToolBar
                && UIManager.getLookAndFeel().getName().toLowerCase().indexOf("windows")
                != -1) {

            JToolBar jtb = (JToolBar) c;

            Component comps[] = jtb.getComponents();

            if (comps != null && comps.length > 0) {

                for (int i = 0; i < comps.length; i++) {

                    try {

                        Component component = comps[i];

                        if (component != null) {

                            if (component instanceof JSeparator) {

                                jtb.remove(component);

                                JSeparator separ = new JSeparator();

                                if (orientn == SwingConstants.VERTICAL) {

                                    separ.setOrientation(SwingConstants.VERTICAL);

                                    separ.setMinimumSize(new Dimension(2, 6));

                                    separ.setPreferredSize(new Dimension(2, 6));

                                    separ.setMaximumSize(new Dimension(2, 100));

                                } else {

                                    separ.setOrientation(SwingConstants.HORIZONTAL);

                                    separ.setMinimumSize(new Dimension(6, 2));

                                    separ.setPreferredSize(new Dimension(6, 2));

                                    separ.setMaximumSize(new Dimension(100, 2));

                                }

                                jtb.add(separ, i);

                            }

                        }

                    } catch (Exception e) {

                        e.printStackTrace();

                    }

                }

            }

        }

    }