/*
* Copyright (C) 2010 Markus Echterhoff <tam@edu.uni-klu.ac.at>
*
* This file is part of EvoPaint.
*
* EvoPaint 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 3 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 EvoPaint. If not, see <http://www.gnu.org/licenses/>.
*/
package evopaint.gui;
import evopaint.Configuration;
import evopaint.gui.util.AutoSelectOnFocusSpinner;
import java.awt.Checkbox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
/**
*
* @author Markus Echterhoff <tam@edu.uni-klu.ac.at>
*/
public class BrushOptionsPanel extends JPanel {
private Configuration configuration;
Checkbox checkboxRandom;
public BrushOptionsPanel(Configuration configuration) {
this.configuration = configuration;
// here we go, this is going to be one butt-ugly long constructor
//setBorder(new TitledBorder("Paint Options"));
setLayout(new GridBagLayout());
setBackground(new Color(0xF2F2F5));
GridBagConstraints constraints = new GridBagConstraints();
constraints.anchor = GridBagConstraints.WEST;
JLabel headingLabel = new JLabel("<html><b>Brush Options</b></html>");
constraints.insets = new Insets(5, 5, 0, 0);
add(headingLabel, constraints);
constraints.insets = new Insets(0, 5, 5, 5);
// and here comes the spinner
constraints.gridy = 2;
JPanel panelBrushSize = new JPanel();
panelBrushSize.setBackground(new Color(0xF2F2F5));
add(panelBrushSize, constraints);
// labeled
JLabel labelForSpinner = new JLabel("Size");
panelBrushSize.add(labelForSpinner);
SpinnerNumberModel spinnerModel = new SpinnerNumberModel(configuration.brush.size, 1, Math.min(configuration.dimension.width, configuration.dimension.height), 1);
JSpinner spinnerBrushSize = new AutoSelectOnFocusSpinner(spinnerModel);
spinnerBrushSize.addChangeListener(new SpinnerBrushSizeListener(spinnerBrushSize));
labelForSpinner.setLabelFor(spinnerBrushSize);
panelBrushSize.add(spinnerBrushSize);
}
private class SpinnerBrushSizeListener implements ChangeListener {
JSpinner spinnerBrushSize;
public SpinnerBrushSizeListener(JSpinner spinnerBrushSize) {
this.spinnerBrushSize = spinnerBrushSize;
}
public void stateChanged(ChangeEvent e) {
configuration.brush.size = (Integer)spinnerBrushSize.getValue();
}
}
}