diff options
author | Camil Staps | 2015-06-05 15:57:28 +0200 |
---|---|---|
committer | Camil Staps | 2015-06-05 15:57:28 +0200 |
commit | 614c03cc1b8eb508d6ed3c698dfa3bc3a6936ca9 (patch) | |
tree | 81e34734c883868426f90a8f110d51b2c9b7bee6 /Week15 Mandelbrot/src/com/camilstaps/mandelbrot/Textfields.java | |
parent | Option for multiple (4) or single swingworker(s) (diff) |
Cleanup; javadoc
Diffstat (limited to 'Week15 Mandelbrot/src/com/camilstaps/mandelbrot/Textfields.java')
-rw-r--r-- | Week15 Mandelbrot/src/com/camilstaps/mandelbrot/Textfields.java | 61 |
1 files changed, 58 insertions, 3 deletions
diff --git a/Week15 Mandelbrot/src/com/camilstaps/mandelbrot/Textfields.java b/Week15 Mandelbrot/src/com/camilstaps/mandelbrot/Textfields.java index d719c4a..5cd20f3 100644 --- a/Week15 Mandelbrot/src/com/camilstaps/mandelbrot/Textfields.java +++ b/Week15 Mandelbrot/src/com/camilstaps/mandelbrot/Textfields.java @@ -36,18 +36,32 @@ import javax.swing.JPanel; import javax.swing.JTextField; /** - * - * @author camilstaps + * The Textfields form a view and a controller for the FractalModel class, and + * a controller for the Grid class + * @author Camil Staps */ public class Textfields extends JPanel implements Observer { + /** + * The FractalModel to view and control + */ private final FractalModel fractalModel; + + /** + * The Grid to control + */ private final Grid grid; + /** + * Initial values of the text fields + */ private final String INITIAL_CENTER_X = "-0.46", INITIAL_CENTER_Y = "0", INITIAL_SCALE = "0.5"; + /** + * The components + */ private final JTextField field_centerX = new JTextField(INITIAL_CENTER_X, 6); private final JTextField field_centerY = new JTextField(INITIAL_CENTER_Y, 6); private final JTextField field_scale = new JTextField(INITIAL_SCALE, 6); @@ -55,6 +69,11 @@ public class Textfields extends JPanel implements Observer { private final JButton button_reset = new JButton("Reset"); private final JCheckBox checkbox_multiple_swingworkers = new JCheckBox("Multiple SwingWorkers"); + /** + * Create a new instance + * @param fractalModel + * @param grid + */ public Textfields(FractalModel fractalModel, Grid grid) { super(new BorderLayout()); @@ -68,6 +87,9 @@ public class Textfields extends JPanel implements Observer { button_redraw.doClick(); } + /** + * Setup the swing components with their listeners + */ private void setupControls() { JPanel panel = new JPanel(new GridLayout(9,1)); @@ -81,16 +103,24 @@ public class Textfields extends JPanel implements Observer { panel.add(field_scale); button_redraw.addActionListener(new ActionListener() { + /** + * Update the FractalModel's bounds + * @param ae + */ @Override public void actionPerformed(ActionEvent ae) { if (ae.getActionCommand().equals("Redraw")) { - fractalModel.setBorders(getStartX(), getEndX(), getStartY(), getEndY()); + fractalModel.setBounds(getStartX(), getEndX(), getStartY(), getEndY()); } } }); panel.add(button_redraw); button_reset.addActionListener(new ActionListener() { + /** + * Reset the textfields to their default values + * @param ae + */ @Override public void actionPerformed(ActionEvent ae) { field_centerX.setText(INITIAL_CENTER_X); @@ -103,6 +133,10 @@ public class Textfields extends JPanel implements Observer { panel.add(button_reset); checkbox_multiple_swingworkers.addActionListener(new ActionListener() { + /** + * Tell the Grid to use single or multiple SwingWorkers + * @param ae + */ @Override public void actionPerformed(ActionEvent ae) { grid.setUseMultipleSwingWorkers(checkbox_multiple_swingworkers.isSelected()); @@ -119,30 +153,51 @@ public class Textfields extends JPanel implements Observer { return 200; } + /** + * Get the desired low bound on x of the model + * @return + */ protected double getStartX() { double width = 1 / Double.parseDouble(field_scale.getText()); double center = Double.parseDouble(field_centerX.getText()); return center - width / 2; } + /** + * Get the desired high bound on x of the model + * @return + */ protected double getEndX() { double width = 1 / Double.parseDouble(field_scale.getText()); double center = Double.parseDouble(field_centerX.getText()); return center + width / 2; } + /** + * Get the desired low bound on y of the model + * @return + */ protected double getStartY() { double height = 1 / Double.parseDouble(field_scale.getText()); double center = Double.parseDouble(field_centerY.getText()); return center - height / 2; } + /** + * Get the desired high bound on y of the model + * @return + */ protected double getEndY() { double height = 1 / Double.parseDouble(field_scale.getText()); double center = Double.parseDouble(field_centerY.getText()); return center + height / 2; } + /** + * Update the text fields based on the FractalModel's bounds + * @param o + * @param o1 + */ @Override public final void update(Observable o, Object o1) { field_centerX.setText(Float.toString((float) |