Commit fb689418 authored by Daniel Vogel's avatar Daniel Vogel

just formatting

parent cef8f1a5
......@@ -5,7 +5,9 @@ import model.TriangleModel;
public class Main1 {
public static void main(String[] args) {
TriangleModel model = new TriangleModel();
view.SimpleTextView view = new view.SimpleTextView(model);
JFrame frame = new JFrame("Triangle Main1");
......
......@@ -6,19 +6,20 @@ import javax.swing.undo.AbstractUndoableEdit;
import javax.swing.undo.UndoableEdit;
public class TriangleModel {
/* A list of the model's views. */
private ArrayList<IView> views = new ArrayList<IView>();
// Limit the size of the triangle.
public static final double MAX_SIDE = 100.0;
public static final double MAX_HYPO = Math.sqrt(MAX_SIDE * MAX_SIDE + MAX_SIDE * MAX_SIDE);
public static final double MAX_HYPO =
Math.sqrt(MAX_SIDE * MAX_SIDE + MAX_SIDE * MAX_SIDE);
private double base = 50.0; // length of the base
private double height = 50.0; // height of the triangle
public TriangleModel() { }
/** Set the base to a new value. Must be between 0 and MAX_BASE. */
public void setBase(double theBase) {
double tmp = Math.max(0, theBase);
......
......@@ -17,9 +17,7 @@ public class GraphicalView extends JComponent {
private double scale = 1.0; // how much should the triangle be scaled?
private int handleSize = 5;
private int handleSize = 5; // size of selectable square for dragging
// To format numbers consistently in the text fields.
private static final NumberFormat formatter = NumberFormat
......@@ -51,7 +49,7 @@ public class GraphicalView extends JComponent {
this.addMouseMotionListener(mil);
}
/** Paint the triangle, and "handles" for resizing if it was selected. */
/** Paint the triangle with "handle" for resizing */
public void paintComponent(Graphics g) {
super.paintComponent(g);
Insets insets = this.getInsets();
......@@ -130,9 +128,9 @@ public class GraphicalView extends JComponent {
selected = onTopCorner(e.getX(), e.getY());
}
public void mouseReleased(MouseEvent e) {
selected = onTopCorner(e.getX(), e.getY());
}
// public void mouseReleased(MouseEvent e) {
// selected = onTopCorner(e.getX(), e.getY());
// }
/** The user is dragging the mouse. Resize appropriately. */
public void mouseDragged(MouseEvent e) {
......
......@@ -17,7 +17,9 @@ import java.text.NumberFormat;
* @author Byron Weber Becker
*/
public class SimpleTextView extends JPanel implements IView {
private TriangleModel model;
private JTextField baseTF = new JTextField(10);
private JTextField heightTF = new JTextField(10);
private JTextField hypoTF = new JTextField(10);
......
......@@ -13,7 +13,9 @@ import java.text.NumberFormat;
* @author Byron Weber Becker
*/
public class TextView extends JPanel {
private TriangleModel model;
private JTextField baseTF = new JTextField(10);
private JTextField heightTF = new JTextField(10);
private JTextField hypoTF = new JTextField(10);
......@@ -37,6 +39,7 @@ public class TextView extends JPanel {
heightTF.setText(formatter.format(model.getHeight()));
}
});
this.model.addView(new IView() {
public void updateView() {
hypoTF.setText(formatter.format(model.getHypotenuse()));
......@@ -54,8 +57,8 @@ public class TextView extends JPanel {
this.add(this.hypoTF);
// Don't allow the user to edit the hypotenuse
this.hypoTF.setEditable(false);
//this.hypoTF.setEnabled(false);
this.hypoTF.setEditable(false); // can still select and copy
//this.hypoTF.setEnabled(false); // greyed out, can't select
}
private void registerControllers() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment