/*
 * Copyright (C) 2015 Benjamin Peters
 *
 *     This program is free software; you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation; either version 2 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License along
 *     with this program; if not, write to the Free Software Foundation, Inc.,
 *     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

package com.codeversum.monospaced.base;

import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

import com.sun.javafx.css.StyleManager;

/**
 * Provides a alternate Button class with a different look. It is designed for being placed into a ToolBar but can be
 * used everywhere.
 */
public class ToolbarButton extends Button {

	static {
		try {
			StyleManager.getInstance().addUserAgentStylesheet(ToolbarButton.class.getResource("/toolbar-button.css")
					.toExternalForm());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static final int DEFAULT_IMAGE_SIZE = 24;

	/**
	 * @param image The image to display. Can be null.
	 */
	public ToolbarButton(Image image) {
		setFocusTraversable(false);
		getStyleClass().add("toolbar-button");

		ImageView imageView = new ImageView(image);
		imageView.setFitWidth(DEFAULT_IMAGE_SIZE);
		imageView.setFitHeight(DEFAULT_IMAGE_SIZE);

		setGraphic(imageView);
	}

}
