package torus;
import javax.swing.*;
import java.awt.*;
import com.borland.jbcl.layout.*;
import javax.swing.event.*;
import java.beans.*;
/**
* Control panel for torus demo, in its own frame.
* Four sliders (each with label to show value) plus label for number of triangles.
* G. Hart 2003, CSE391 demo
*/
public class controls extends JFrame {
JPanel jPanel1 = new JPanel();
JLabel r1Label = new JLabel();
JSlider n2 = new JSlider(3,100,20); // min,max,initial values
JSlider n1 = new JSlider(3,100,32);
JSlider r1 = new JSlider();
JSlider r2 = new JSlider();
JLabel r2Label = new JLabel();
JLabel n1Label = new JLabel();
JLabel n2Label = new JLabel();
JLabel status = new JLabel();
JLabel jLabel5 = new JLabel();
J3Dviewer theViewer;
GridBagLayout gridBagLayout1 = new GridBagLayout(); // the frame that created us
public controls(J3Dviewer viewer) {
theViewer=viewer; // remember frame so we can send it messages
try {
jbInit();
this.setVisible(true);
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
jPanel1.setLayout(gridBagLayout1);
r1Label.setAlignmentY((float) 0.5);
r1Label.setHorizontalAlignment(SwingConstants.CENTER);
r1Label.setText("Mid Radius");
n2.setMinimum(3);
n2.addChangeListener(new controls_n2_changeAdapter(this));
n1.setMinimum(3);
n1.addChangeListener(new controls_n1_changeAdapter(this));
r2Label.setHorizontalAlignment(SwingConstants.CENTER);
r2Label.setText("Small Radius");
n1Label.setHorizontalAlignment(SwingConstants.CENTER);
n1Label.setText("N around");
n2Label.setHorizontalAlignment(SwingConstants.CENTER);
n2Label.setText("N through hole");
status.setHorizontalAlignment(SwingConstants.CENTER);
status.setText("-");
jLabel5.setFont(new java.awt.Font("Dialog", 0, 18));
jLabel5.setHorizontalAlignment(SwingConstants.CENTER);
jLabel5.setText("Torus Viewer Demo");
r2.addChangeListener(new controls_r2_changeAdapter(this));
r1.addChangeListener(new controls_r1_changeAdapter(this));
this.getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jLabel5, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(16, 92, 0, 74), 79, 7));
jPanel1.add(r2, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(71, 14, 0, 0), -29, 1));
jPanel1.add(r1, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(25, 14, 0, 0), -29, 0));
jPanel1.add(r1Label, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 31, 0, 17), 76, 0));
jPanel1.add(r2Label, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 34, 0, 18), 58, 0));
jPanel1.add(n1, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(25, 23, 0, 34), -39, 0));
jPanel1.add(n1Label, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 41, 0, 59), 67, 0));
jPanel1.add(n2, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(72, 22, 0, 34), -38, 0));
jPanel1.add(n2Label, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 41, 0, 57), 39, 0));
jPanel1.add(status, new GridBagConstraints(0, 5, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(41, 71, 29, 73), 255, 0));
}
//if any of the sliders are changed, recalculate object and update viewer
void r1_stateChanged(ChangeEvent e) {
theViewer.updateThing();
}
void r2_stateChanged(ChangeEvent e) {
theViewer.updateThing();
}
void n1_stateChanged(ChangeEvent e) {
theViewer.updateThing();
}
void n2_stateChanged(ChangeEvent e) {
theViewer.updateThing();
}
}
class controls_r2_changeAdapter implements javax.swing.event.ChangeListener {
controls adaptee;
controls_r2_changeAdapter(controls adaptee) {
this.adaptee = adaptee;
}
public void stateChanged(ChangeEvent e) {
adaptee.r2_stateChanged(e);
}
}
class controls_r1_changeAdapter implements javax.swing.event.ChangeListener {
controls adaptee;
controls_r1_changeAdapter(controls adaptee) {
this.adaptee = adaptee;
}
public void stateChanged(ChangeEvent e) {
adaptee.r1_stateChanged(e);
}
}
class controls_n1_changeAdapter implements javax.swing.event.ChangeListener {
controls adaptee;
controls_n1_changeAdapter(controls adaptee) {
this.adaptee = adaptee;
}
public void stateChanged(ChangeEvent e) {
adaptee.n1_stateChanged(e);
}
}
class controls_n2_changeAdapter implements javax.swing.event.ChangeListener {
controls adaptee;
controls_n2_changeAdapter(controls adaptee) {
this.adaptee = adaptee;
}
public void stateChanged(ChangeEvent e) {
adaptee.n2_stateChanged(e);
}
}