package devASD.templateProject;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import jv.object.PsDebug;
import jv.object.PsUpdateIf;
import jv.project.PjProject_IP;
import javafx.scene.control.CheckBox;
import javafx.scene.control.RadioButton;
/**
* Here is a template you may use to create your own project with JavaView.
* You just have to change a few lines according to your project name and goal.
* These lines are highlighted with this comment : //TODO To modify : [Explanation of what to modify]
*
* See PaTemplateProject for more information on the architecture of a JVproject.
*
* You are of course supposed to modify all the comments according to the JavaDoc rules to explain
* what each elements of this file is for.
*
*
*
* Info Panel (IP) of your project. Each project, as well as each geometry, may have
* an info panel for inspecting and steering the instance. Modifications in the panel
* should result in a call to project.update(Object)
.
*
* Panel adds a slider Panel with slider for the integers given in the parent project.
* The sliders are children of the project and send update(Object)
whenever
* they change by user interaction.
*
* Furthermore the Panel contains buttons to run or reset the simulation.
*
* This info panel is optional and can be removed without any changes in the project.
* Each info panel must follow special naming conventions such that JavaView is able to
* show it automatically, or on request. The class name must be identical to the class
* name of the corresponding class with the suffix '_IP' attached.
*
* @see jv.project.PjProject
* @author you
* @version now, 1.00 created (ms)
*/
public class PjTemplateProject_IP extends PjProject_IP implements ActionListener, ItemListener {
protected PjTemplateProject m_myProject;
protected Panel m_sliderPanel;
protected Panel m_buttonPanel;
protected Panel m_checkBoxPanel;
protected Panel m_radioButtonPanel;
protected Button m_bStep;
protected Button m_bReset;
protected Checkbox m_checkBox;
//Radio button
protected CheckboxGroup m_radioButton;
protected Checkbox m_checkBox1;
protected Checkbox m_checkBox2;
//TODO To modify : Name
public PjTemplateProject_IP() {
super();
//TODO To modify : Name
// Add title label which will later display the title of the project.
addTitle("Template Project to help you start");
// Panel to contain slider for number of points
m_sliderPanel = new Panel();
m_sliderPanel.setLayout(new GridLayout(1, 1));
add(m_sliderPanel);
// Add buttons
m_buttonPanel = new Panel();
m_buttonPanel.setLayout(new GridLayout(2,1));
m_bStep = new Button("Step");
m_bStep.addActionListener(this);
m_buttonPanel.add(m_bStep);
m_bReset = new Button("Reset");
m_bReset.addActionListener(this);
m_buttonPanel.add(m_bReset);
add(m_buttonPanel);
//Add m_checkBox
m_checkBoxPanel = new Panel();
m_checkBoxPanel.setLayout(new GridLayout(1,1));
m_checkBox = new Checkbox("Checkbox");
m_checkBox.addItemListener(this);
m_checkBoxPanel.add(m_checkBox);
add(m_checkBox);
//Add radio Button
m_radioButtonPanel = new Panel();
m_radioButtonPanel.setLayout(new GridLayout(1, 1));
m_radioButton = new CheckboxGroup();
m_checkBox1 = new Checkbox("1st Choice", m_radioButton, true);
m_checkBox1.addItemListener(this);
m_checkBox2 = new Checkbox("2nd Choice", m_radioButton, false);
m_checkBox2.addItemListener(this);
m_radioButtonPanel.add(m_checkBox1);
m_radioButtonPanel.add(m_checkBox2);
add(m_radioButtonPanel);
// Call to init() is mandatory
if (getClass() == PjTemplateProject_IP.class) {
init();
}
}
public void init() {
super.init();
}
public void setParent(PsUpdateIf parent) {
super.setParent(parent);
//TODO To modify : Name
m_myProject = (PjTemplateProject) parent;
setTitle(m_myProject.getName());
// Add info panel of integer to panel of sliders.
m_sliderPanel.add(m_myProject.m_stepSize.getInfoPanel());
}
/**
* Here we arrive from outside world of this panel, e.g. if
* project has changed somewhere else and must update its panel. Such an update
* is automatically by superclasses of PjProject.
*/
public boolean update(Object event) {
if (m_myProject==null) {
if (PsDebug.WARNING) PsDebug.warning("missing parent, setParent not called");
return false;
}
return super.update(event);
}
/**
* Handle action events invoked from buttons, menu items, text fields.
*/
public void actionPerformed(ActionEvent event) {
if (m_myProject==null)
return;
Object source = event.getSource();
if (source == m_bReset) {
m_myProject.init();
m_myProject.update(this);
}
if (source == m_bStep) {
m_myProject.step();
m_myProject.update(this);
}
}
/**
* Handle events from the checkboxes
*
*/
public void itemStateChanged(ItemEvent event) {
if(m_myProject == null)
return;
Object source = event.getSource();
if(source == m_checkBox)
m_myProject.m_checkBoxState = m_checkBox.getState();
if(source == m_checkBox1)
m_myProject.m_choice = 1;
else
m_myProject.m_choice = 2;
update(this);
}
}