package jas2.util.multibuttontoolbar;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;

/**
 * A MultiToolBar is a subclass of JToolBar which provides support for
 * ButtonGroups of MultiButtons.  Basically, as well as add()ing JButtons, etc
 * to this toolbar you can also add() a ButtonGroup, which has the effect of
 * 
 * 
 * @author Peter Armstrong
 * @author Tony Johnson
 */
public class MultiToolBar extends JToolBar {
	//
	//constructors
	//
	
	/**
	 * Create a new MultiToolBar. Orientration defaults to horizontal.
	 */
	public MultiToolBar() {
	}
	
	/**
	 * Create a new MultiToolBar.
	 * 
	 * @param orientation - The initial orientation (HORIZONTAL/VERTICAL)
	 */
	public MultiToolBar(int orientation) {
		super(orientation);
	}
	
	//
	//public methods
	//
	
	/**
	 * Add the visible button of the mbg to the toolbar, and also somehow
	 * keep track of the mbg and the index of its visible component.
	 */
	public void add(MultiButtonGroup mbg) {
		mbg.setPositionInToolBar(getComponentCount());
			//we need to do this first since the ToolBar is 0 based and
			//getComponentCount() is 1 based
			//!PA - verify
		mbg.setToolBar(this);
		add(mbg.getVisibleButton(true));
	}
	
	/**
	 * Out with the old, in with the new.
	 */
	public void replace(Component oldThing, Component newThing) {
		int theIndex = getComponentIndex(oldThing);
		if (theIndex != -1) {
			remove(theIndex);
			add(newThing, theIndex);
			repaint();
		}
	}
}

 

Ads help maintain this website.