EliteExperts

| November 17, 2015

The objectives of this assignment are to:

 

1)    Gain further understanding and experience with inheritance.

2)    Gain understanding and experience with polymorphism.

3)    Gain further understanding and experience with interfaces.

4)    Gain understanding and experience with low level graphics.

5)    Modify an existing program to meet new requirements applying concepts of objectives 1 through 4.

6)    Gain experience with medium-size Java program.

7)    Continue to practice good programming techniques.

COSC 210 – Object Oriented Programming

Assignment 7

 

 

Due: Nov 18th

 

The objectives of this assignment are to:

 

  • Gain further understanding and experience with inheritance.
  • Gain understanding and experience with polymorphism.
  • Gain further understanding and experience with interfaces.
  • Gain understanding and experience with low level graphics.
  • Modify an existing program to meet new requirements applying concepts of objectives 1 through 4.
  • Gain experience with medium-size Java program.
  • Continue to practice good programming techniques.

 

AFTER YOU HAVE COMPLETED, create a zip file named [your name]Assignment7.zip containing your entire project.  Upload the .zip file to Moodle.  Printout all source files you created or modified.  Include a screen shot of the editor with boxes, ellipses, lines and images shown in the editor.  Turn-in all printouts.

 

 

COSC 210 – Fundamentals of Computer Science

Assignment 7 Problem Statement

Updated

 

On the tomcat drive in folder cosc210 you will find file named PainterStartup.zip.  This file contains the source code for the start of a Painter program.  In its current state, Painter can create boxes and text objects at given locations.  Both boxes and text objects can be repositioned and resized using a mouse.  The task is to add to the program the implementation for an ellipse, line, image, and group objects.

 

Instructions:

 

  • Add an ellipse object. An ellipse is very similar in implementation as the box, except it renders an oval instead of a rectangle.  The ellipse can be repositioned by dragging the object to a new location.  The ellipse can be resized by first clicking over the ellipse to display grab handles and then dragging a grab handle to a new position.  The grab handles are to be rendered at the same positions as the box.  Likewise, clicking anywhere in the smallest rectangle that encloses the ellipse performs selection.

 

  • Add a Line object. A Line is to be created by selecting a Line tool and then click and drag over the canvas.  The line is rendered from the point of the initial click to the mouse pointer.  On releasing the mouse the construction of the line object is completed.  Have the Line object inherit from PtrDrawAbstractAreaObject.  Thus it will have only two grab handles.

 

A Line is selected by clicking anywhere over the line.  Right now if you click anywhere in the rectangular region hold the line, then the line is selected.   To accomplish this task, override the isOver method in PtrDrawAbstractAreaObject.

 

Given below is a partial solution to determine if a mouse click position (the x and y parameters to the isOver method) is over a line:

 

double ratio = (double) getWidth() / (double) getHeight();

 

if (Math.abs((x – getX()) * ratio) – (y – getY()) <= 1) {

return true;

}

 

You need to modify this code when the y to x ratio is less than -1 or greater than 1.  (Hint: Inverse the roles of width and height, and the roles of x and y)

 

  • Add an Image object. An Image object is created by selecting an Image tool and then clicking anywhere on the canvas.  On clicking the canvas, a File Selection Dialog should be displayed.  The dialog prompts for selection of .gif and .jpg files.  On selecting a .gif or .jpg file and clicking “Open”, an Image object that renders the image of the selected file is created at the click position.  Image selection and drag behaviors are the same as a Box object. The image object additionally renders lines at the edges of the image (as done in Box).

 

The code for displaying a File Selection Dialog is:

 

JFileChooser fileChooser = new JFileChooser();

fileChooser.setFileFilter(new FileFilter() {

public boolean accept(File f) {

return f.isDirectory() || f.getName().toLowerCase().endsWith(“.jpg”)

|| f.getName().toLowerCase().endsWith(“.gif”);

}

 

public String getDescription() {

return “JPG & GIF Images”;

}

});

 

if (fileChooser.showOpenDialog(editor) ==

JFileChooser.APPROVE_OPTION) {

ImageIcon image = new

ImageIcon(fileChooser.getSelectedFile().getAbsolutePath());

 

 

/* you will need to do stuff with your image here         */

/* note the Graphics object has a method drawImage() */

}

 

Make sure to import FileFilter from the javax.swing.filechooser.

 

The above code is added to the PtrDrawImageTool

 

  • Add a group object. A group object represents a set of objects that have been grouped together.  A partial implementation is provided.  Your task is to fix the rendering.   The group object should draw each of the objects in the groupedObjects list.

 

Before drawing any object your will need to create a new graphics object that is transposed to the dimensions if the group object itself.  To do this use:

 

Graphics2D g2 = (Graphics2D) g.create(getX(), getY(), getWidth(),

getHeight());

 

After drawing each of the objects in groupedObjects list, release the resources used by the created graphics object by calling dispose:

 

g2.dispose();

 

One more item, after creating the new graphics context and before drawing each of the objects in the group, use scale as follows:

 

g2.scale(getXScale(), getYScale());

 

This will insure that all objects get rendered as at the right scale when the group object itself is resized.

 

  • Have the box, ellipse, line, and image implement the Lineable and Colorable interface. Create instance variables as needed to hold the values of the parameters.   Before doing any rendering of lines (e.g., any g.drawXXXX method) create a new graphics context as follows:

 

Graphics2D g2 = (Graphics2D) g.create();

 

Then set the line width by:

 

g2.setStroke(new BasicStroke(lineWidth));

 

Also set the color to the lineColor:

 

g2.setColor(lineColor);

 

Use g2 to do the rendering of the lines.  After all line rendering, release the resources of the graphics context by calling dispose();

 

In the corresponding tool object (e.g., PtrDrawBoxTool for PtrDrawBox), after creating the draw object add the following calls in the object:

 

box.setLineColor(editor.getLineColor());

box.setLineWidth(editor.getLineWidth());

 

  • Have the box and ellipse, line implement the Colorable interface. Create instance variables as need to hold the value of the parameter (color).   Before doing any rendering of filled areas (e.g., any g.fillXXXX method)  set the graphics color to the color instance variable:

 

g.setColor(color);  // or use g2 if you have created a new graphics context

 

In the corresponding tool object (e.g., PtrDrawBoxTool for PtrDrawBox), after creating the draw object add the following calls in the object:

 

box.setColor(editor.getColor());

 

Warning:

 

            Your objects may not render correctly whenever they are resized such that either the height or width is negative.

 

Bonus:

 

  • Bonus 5 points -The isInside method provides the implementation for determining if the line is inside a rectangular area as specified by the parameters. This code may not work right if the ending point of the line is to the left or above the starting point.  Fix this to work in all cases for 3 bonus points.

 

  • Currently, if you click in the area where two objects overlap, the object on the bottom is selected. Change this so that the top object is selected.  3 bonus points.

 

  • On the Group object, clicking in anywhere in the bounding rectangle will select the object. Change this so that a group is only selected with clicking over an object in the group. 3 bonus points

 

  • The south east grab handle processing is broken. Fix this to behave as the other grab handles for 3 bonus points

 

  • Currently, if you drag the right hand side smaller than the left (likewise the bottom smaller that the top) the objects may not be displayed correctly (or even at all). Once in the bad display state, clicking over the object no longer works.  Second, if you click in the region of overlapping object, the object on the bottom gets selected.  It should be the top object. Fix these bugs. One possible solution is to add a normalizeRect method to PtrDrawRect.  This will adjust the x, y, width, and height variables so that width and height are never negative.  For example if width is negative then change x to be the value of x plus width and then change width to be the absolute value.  Place a call to this method in the corresponding setter methods after updating the instance variables.  (Note there may be problems with the grab handles).  3 points bonus.

Get a 5 % discount on an order above $ 150
Use the following coupon code :
2018DISC
Flier With Word 2013
Word 2013 Resume

Category: Homework Help

Our Services:
Order a customized paper today!