Package net.sf.arianne.marboard.client.gui.toolbar

Source Code of net.sf.arianne.marboard.client.gui.toolbar.ToolBarBuilder

package net.sf.arianne.marboard.client.gui.toolbar;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JToolBar;

import net.sf.arianne.marboard.client.gui.BoardState;
import net.sf.arianne.marboard.client.gui.DrawingTool;
import net.sf.arianne.marboard.client.gui.MainWindow;
import net.sf.arianne.marboard.client.gui.drawingtool.DotDrawingTool;
import net.sf.arianne.marboard.client.gui.drawingtool.OvalDrawingTool;
import net.sf.arianne.marboard.client.gui.drawingtool.RectangleDrawingTool;
import net.sf.arianne.marboard.client.gui.drawingtool.ShapePickerDrawingTool;
import net.sf.arianne.marboard.client.gui.drawingtool.StraightLineDrawingTool;
import net.sf.arianne.marboard.client.gui.menu.SelectToolActionListener;

/**
* creates the tool bar
*
* @author hendrik, madmetzger
*/
public class ToolBarBuilder {

  /**
   * creates the tool bar
   *
   * @param state state of the board
   * @param mainWindow mainWindow to attach the toolbar too
   * @return JToolBar
   */
  public JToolBar createToolBar(BoardState state, MainWindow mainWindow) {
    JToolBar toolBar = new JToolBar();

    // create buttons for the drawing tools
    toolBar.add(createAction(state, "arrow.gif", new ShapePickerDrawingTool(mainWindow.getDrawingArea())));
    toolBar.add(createAction(state, "dot.png", new DotDrawingTool()));
    toolBar.add(createAction(state, "line.png", new StraightLineDrawingTool(mainWindow.getDrawingArea())));
    toolBar.add(createAction(state, "rectangle.png", new RectangleDrawingTool(mainWindow.getDrawingArea())));
    toolBar.add(createAction(state, "circle.png", new OvalDrawingTool(mainWindow.getDrawingArea())));
    toolBar.add(new JToolBar.Separator());

    // create a color chooser button
    AbstractColorChooserButton colorButton = new ColorChooserButton(state);
    state.register(colorButton);
    toolBar.add(colorButton);
    toolBar.add(new JToolBar.Separator());

    // create a fill color chooser button
    AbstractColorChooserButton fillColorButton = new FillColorChooserButton(state);
    state.register(fillColorButton);
    toolBar.add(fillColorButton);
    return toolBar;
  }

  /**
   * creates a button for a drawing tool
  
   * @param state state of the board
   * @param imageFileName name of image to display on the button
   * @param tool tool to select with this button
   * @return JButton
   */
  private JButton createAction(BoardState state, String imageFileName, DrawingTool tool) {
    String dotPath = getClass().getResource(imageFileName).getFile();
    Icon dotIcon = new ImageIcon(dotPath);
    JButton dotActionButton = new JButton(new SelectToolActionListener(state, tool));
    dotActionButton.setIcon(dotIcon);
    return dotActionButton;
  }

}
TOP

Related Classes of net.sf.arianne.marboard.client.gui.toolbar.ToolBarBuilder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.