예제 #1
0
  /**
   * Create a toolbar containing the given tools (if any).
   *
   * @param template Conta
   */
  protected void changeToolBar(JComponent[] template, IControlCenterPlugin selplugin) {
    // Setup the tool bar.
    if (toolbar == null) {
      toolbar = new JToolBar("Main Toolbar");
      getContentPane().add(BorderLayout.NORTH, toolbar);
      // Add standard entries (after gap).
      toolbar.add(Box.createGlue());
      toolcnt++;
      toolbar.addSeparator();
      toolcnt++;

      // ButtonGroup bg = new ButtonGroup();
      IControlCenterPlugin[] plugins = controlcenter.getPlugins();
      for (int i = 0; i < plugins.length; i++) {
        final IControlCenterPlugin plugin = plugins[i];
        // final JToggleButton button = new JToggleButton(new PluginAction(plugins[i]));
        final JButton button = new JButton(new PluginAction(plugins[i]));
        Icon ic = plugin.getToolIcon(selplugin.getName().equals(plugins[i].getName()));
        if (ic != null) button.setIcon(ic);
        else button.setText(plugins[i].getName());
        button.setText("A");
        button.putClientProperty("plugin", plugins[i]);
        button.setBorder(null);
        button.setText(null);
        button.setMinimumSize(BUTTON_DIM);
        button.setHorizontalAlignment(SwingConstants.CENTER);
        button.setVerticalAlignment(SwingConstants.CENTER);
        button.setToolTipText(plugins[i].getName());
        button
            .getModel()
            .addItemListener(
                new ItemListener() {
                  public void itemStateChanged(ItemEvent e) {
                    // System.out.println(plugin.getName()+" :"+button.isSelected());
                    button.setIcon(plugin.getToolIcon(button.isSelected()));
                  }
                });
        //	            if(plugins[i].getHelpID()!=null)
        //	            	SHelp.setupHelp(button, plugins[i].getHelpID());

        // bg.add(button);
        toolbar.add(button);
        toolcnt++;
      }
      toolbar.addSeparator();
      toolcnt++;
      toolbar.add(new JadexLogoButton(toolbar));
      toolcnt++;
    } else {
      while (toolbar.getComponentCount() > toolcnt) {
        //				Component	comp	= toolbar.getComponent(0);
        toolbar.remove(0);
        // if(lasttoolbar!=null)
        //	lasttoolbar.add(comp);
      }
    }

    for (int i = 0; template != null && i < template.length; i++) toolbar.add(template[i], i);
    // lasttoolbar	= template;

    // Select plugins
    for (int i = 0; i < toolbar.getComponentCount(); i++) {
      JComponent comp = (JComponent) toolbar.getComponent(i);
      if (comp.getClientProperty("plugin") != null) {
        IControlCenterPlugin pl = (IControlCenterPlugin) comp.getClientProperty("plugin");
        ((JButton) comp).setIcon(pl.getToolIcon(pl.equals(selplugin)));
        // ((JToggleButton)comp).setSelected(pluginname.equals(comp.getClientProperty("pluginname")));
      }
    }

    toolbar.validate();
    toolbar.repaint();

    // If toolbar has been dropped out -> pack the window (hack???).
    Container root = toolbar;
    while (root.getParent() != null && !(root instanceof Window)) root = root.getParent();
    if (root != null && !(root instanceof JFrame)) {
      ((Window) root).pack();
    }
  }