asmt7/~$sc_210_-_assignment_7_fall_15.doc
asmt7/cosc_210_-_assignment_7_fall_15.doc
COSC 210 - Object Oriented Programming
Assignment 7
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.
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:
1) 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.
2) 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 r ...
1. asmt7/~$sc_210_-_assignment_7_fall_15.doc
asmt7/cosc_210_-_assignment_7_fall_15.doc
COSC 210 - Object Oriented Programming
Assignment 7
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.
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
2. 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:
1) 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.
2) 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();
3. 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)
3) 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");
4. }
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
4) 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:
5. 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.
5) 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);
6. 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());
6) 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:
1) 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
7. above the starting point. Fix this to work in all cases for 3
bonus points.
2) 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.
3) 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
4) The south east grab handle processing is broken. Fix this to
behave as the other grab handles for 3 bonus points
5) 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.
asmt7/image_0.jpeg
asmt7/image_2.jpeg
asmt7/image_4.jpeg
15. PainterStartup/com/javera/ui/actions/Closeable.javaPainterStart
up/com/javera/ui/actions/Closeable.javapackage com.javera.ui.a
ctions;
import java.awt.event.ActionEvent;
import java.util.EventObject;
/**
* This interface should be implemented by UI classes that want
to allow some data they handle to be saved.
* @author David T. Smith
*/
publicinterfaceCloseable{
publicvoid close(ActionEvent evt);
publicboolean isCloseable(EventObject evt);
}
PainterStartup/com/javera/ui/actions/CloseAction.classpackage
com.javera.ui.actions;
publicsynchronizedclass CloseAction extends
ManagedStateAction {
privatestatic CloseAction saveAction;
static void <clinit>();
private void CloseAction();
publicstatic CloseAction getAction();
public void actionPerformed(java.awt.event.ActionEvent);
public boolean isTargetEnabled(java.util.EventObject);
}
PainterStartup/com/javera/ui/actions/CloseAction.javaPainterSt
artup/com/javera/ui/actions/CloseAction.java//Copyright 2004, (
c) Javera Software, LLC. as an unpublished work. All rights res
17. if(target !=null){
return target.isCloseable(evt);
}else{
returnfalse;
}
}
}
PainterStartup/com/javera/ui/actions/CloseAllable.classpackage
com.javera.ui.actions;
publicabstractinterface CloseAllable {
publicabstract boolean closeAll(java.awt.event.ActionEvent);
publicabstract boolean isCloseAllable(java.util.EventObject);
}
PainterStartup/com/javera/ui/actions/CloseAllable.javaPainterSt
artup/com/javera/ui/actions/CloseAllable.javapackage com.javer
a.ui.actions;
import java.awt.event.ActionEvent;
import java.util.EventObject;
/**
* This interface should be implemented by UI classes that want
to allow some data they handle to be saved.
* @author David T. Smith
*/
publicinterfaceCloseAllable{
publicboolean closeAll(ActionEvent evt);
publicboolean isCloseAllable(EventObject evt);
}
31. import java.awt.event.ActionEvent;
import java.util.EventObject;
/**
* This interface should be implemented by components that wis
h to work
* with Export actions.
*/
publicinterfaceExportable{
/**
* Performs the Export action.
*/
publicvoid export(ActionEvent evt );
/**
* Implementing object should use this method to specify wh
ether an Export
* is currently performable.
*/
publicboolean isExportable(EventObject evt );
}
PainterStartup/com/javera/ui/actions/ExportAction.classpackage
com.javera.ui.actions;
publicsynchronizedclass ExportAction extends
ManagedStateAction {
privatestatic ExportAction exportAction;
static void <clinit>();
private void ExportAction();
publicstatic ExportAction getAction();
public void actionPerformed(java.awt.event.ActionEvent);
public boolean isTargetEnabled(java.util.EventObject);
}
49. PainterStartup/com/javera/ui/actions/PageSetupable.classpackag
e com.javera.ui.actions;
publicabstractinterface PageSetupable {
publicabstract void pageSetup(java.awt.event.ActionEvent);
publicabstract boolean
isPageSetupable(java.util.EventObject);
}
PainterStartup/com/javera/ui/actions/PageSetupable.javaPainter
Startup/com/javera/ui/actions/PageSetupable.javapackage com.j
avera.ui.actions;
import java.awt.event.ActionEvent;
import java.util.EventObject;
/**
* This interface should be implemented by components that wis
h to work
* with Print actions.
*/
publicinterfacePageSetupable{
/** Performs the Print action. */
publicvoid pageSetup(ActionEvent evt );
/**
* Implementing object should use this method to specify wh
ether a Print
* is currently performable.
*/
publicboolean isPageSetupable(EventObject evt );
}
62. }
PainterStartup/com/javera/ui/actions/Saveable.javaPainterStartu
p/com/javera/ui/actions/Saveable.javapackage com.javera.ui.acti
ons;
import java.awt.event.ActionEvent;
import java.util.EventObject;
/**
* This interface should be implemented by UI classes that want
to allow some data they handle to be saved.
* @author David T. Smith
*/
publicinterfaceSaveable{
publicvoid save(ActionEvent evt);
publicboolean isSaveable(EventObject evt);
}
PainterStartup/com/javera/ui/actions/SaveAction.classpackage
com.javera.ui.actions;
publicsynchronizedclass SaveAction extends
ManagedStateAction {
privatestatic SaveAction saveAction;
static void <clinit>();
private void SaveAction();
publicstatic SaveAction getAction();
public void actionPerformed(java.awt.event.ActionEvent);
public boolean isTargetEnabled(java.util.EventObject);
}
PainterStartup/com/javera/ui/actions/SaveAction.javaPainterSta
64. }else{
returnfalse;
}
}
}
PainterStartup/com/javera/ui/actions/SaveAllable.classpackage
com.javera.ui.actions;
publicabstractinterface SaveAllable {
publicabstract void saveAll(java.awt.event.ActionEvent);
publicabstract boolean isSaveAllable(java.util.EventObject);
}
PainterStartup/com/javera/ui/actions/SaveAllable.javaPainterSta
rtup/com/javera/ui/actions/SaveAllable.javapackage com.javera.
ui.actions;
import java.awt.event.ActionEvent;
import java.util.EventObject;
/**
* This interface should be implemented by UI classes that want
to allow some data they handle to be saved.
* @author David T. Smith
*/
publicinterfaceSaveAllable{
publicvoid saveAll(ActionEvent evt);
publicboolean isSaveAllable(EventObject evt);
}
PainterStartup/com/javera/ui/actions/SaveAllAction.classpackag
e com.javera.ui.actions;
66. (SaveAllable)ActionUtilities.getCommandTarget(e,SaveAllable.
class);
if(target !=null&& target.isSaveAllable(e)){
target.saveAll(e);
}
}
publicboolean isTargetEnabled(EventObject evt){
SaveAllable target =
(SaveAllable)ActionUtilities.getCommandTarget(evt,SaveAllabl
e.class);
if(target !=null){
return target.isSaveAllable(evt);
}else{
returnfalse;
}
}
}
PainterStartup/com/javera/ui/actions/SaveAsable.classpackage
com.javera.ui.actions;
publicabstractinterface SaveAsable {
publicabstract void saveAs(java.awt.event.ActionEvent);
publicabstract boolean isSaveAsable(java.util.EventObject);
}
PainterStartup/com/javera/ui/actions/SaveAsable.javaPainterSta
rtup/com/javera/ui/actions/SaveAsable.java//Copyright 2004, (c)
Javera Software, LLC. as an unpublished work. All rights reser
ved world-wide.
//This is a proprietary trade secret of Javera Software LLC. Use
restricted to licensing terms.
67. package com.javera.ui.actions;
import java.awt.event.ActionEvent;
import java.util.EventObject;
/**
* This interface should be implemented by UI classes that want
to allow some data they handle to be saved
* as another entity.
* @author David T. Smith
*/
publicinterfaceSaveAsable{
publicvoid saveAs(ActionEvent evt);
publicboolean isSaveAsable(EventObject evt);
}
PainterStartup/com/javera/ui/actions/SaveAsAction.classpackag
e com.javera.ui.actions;
publicsynchronizedclass SaveAsAction extends
javax.swing.AbstractAction {
privatestatic SaveAsAction saveAsAction;
static void <clinit>();
private void SaveAsAction();
publicstatic SaveAsAction getAction();
public void actionPerformed(java.awt.event.ActionEvent);
public boolean isTargetEnabled(java.util.EventObject);
}
PainterStartup/com/javera/ui/actions/SaveAsAction.javaPainter
Startup/com/javera/ui/actions/SaveAsAction.java//Copyright 20
04, (c) Javera Software, LLC. as an unpublished work. All right
s reserved world-wide.
//This is a proprietary trade secret of Javera Software LLC. Use
77. PainterStartup/com/javera/ui/CompleteEntry.javaPainterStartup/
com/javera/ui/CompleteEntry.javapackage com.javera.ui;
/**
* @author dtsmith
*/
publicinterfaceCompleteEntry{
publicvoid completeEntry();
}
PainterStartup/com/javera/ui/GetIcon.classpackage
com.javera.ui;
publicabstractinterface GetIcon {
publicabstract javax.swing.Icon getIcon();
}
PainterStartup/com/javera/ui/GetIcon.javaPainterStartup/com/ja
vera/ui/GetIcon.java//Copyright 2004, (c) Javera Software, LLC
. as an unpublished work. All rights reserved world-wide.
//This is a proprietary trade secret of Javera Software LLC. Use
restricted to licensing terms.
package com.javera.ui;
import javax.swing.Icon;
/**
* GetIcon interface provides access to the getIcon() method use
d by
* the various renderers to obtain an Icon for a given object
*
* @author David T. Smith
*/
publicinterfaceGetIcon{
78. /**
* Get the icon to be displayed by the renderer
* @ return the icon to be displayed
*/
publicIcon getIcon();
}
PainterStartup/com/javera/ui/GetObject.classpackage
com.javera.ui;
publicabstractinterface GetObject {
publicabstract Object getObject();
}
PainterStartup/com/javera/ui/GetObject.javaPainterStartup/com/
javera/ui/GetObject.java//Copyright 2004, (c) Javera Software,
LLC. as an unpublished work. All rights reserved world-wide.
//This is a proprietary trade secret of Javera Software LLC. Use
restricted to licensing terms.
package com.javera.ui;
/**
* GetObject interface provides access to the getObject() metho
d used by
* the various renderers to obtain a contained object
*
* @author David T. Smith
*/
publicinterfaceGetObject{
/**
* Get the contained object
* @return the contained object
*/
publicObject getObject();
79. }
PainterStartup/com/javera/ui/GetPopupMenu.classpackage
com.javera.ui;
publicabstractinterface GetPopupMenu {
publicabstract javax.swing.JPopupMenu
getPopupMenu(java.awt.event.MouseEvent);
}
PainterStartup/com/javera/ui/GetPopupMenu.javaPainterStartup
/com/javera/ui/GetPopupMenu.java//Copyright 2004, (c) Javera
Software, LLC. as an unpublished work. All rights reserved wo
rld-wide.
//This is a proprietary trade secret of Javera Software LLC. Use
restricted to licensing terms.
package com.javera.ui;
import java.awt.event.MouseEvent;
import javax.swing.JPopupMenu;
publicinterfaceGetPopupMenu{
publicJPopupMenu getPopupMenu(MouseEvent e);
}
PainterStartup/com/javera/ui/GetText.classpackage
com.javera.ui;
publicabstractinterface GetText {
publicabstract String getText();
}
PainterStartup/com/javera/ui/GetText.javaPainterStartup/com/ja
80. vera/ui/GetText.java//Copyright 2004, (c) Javera Software, LLC
. as an unpublished work. All rights reserved world-wide.
//This is a proprietary trade secret of Javera Software LLC. Use
restricted to licensing terms.
package com.javera.ui;
/**
* GetText interface provides access to the getText() method us
ed by
* the default renderers for JvList and JvComboBox to get the te
xt to be
* displayed as an entry
*
* @author David T. Smith
*/
publicinterfaceGetText{
/**
* Get the text to be displayed by the renderer
* @ return the text to be displayed
*/
publicString getText();
}
PainterStartup/com/javera/ui/GetTransferable.classpackage
com.javera.ui;
publicabstractinterface GetTransferable {
publicabstract java.awt.datatransfer.Transferable
getTransferable();
}
PainterStartup/com/javera/ui/GetTransferable.javaPainterStartu
p/com/javera/ui/GetTransferable.java// Copyright 2004, (c) Jave
ra Software, LLC. as an unpublished work. All rights reserved
81. world-wide.
// This is a proprietary trade secret of Javera Software LLC. Us
e restricted to licensing terms.
package com.javera.ui;
import java.awt.datatransfer.Transferable;
/**
* @author dtsmith
*/
publicinterfaceGetTransferable{
/**
* @return
*/
Transferable getTransferable();
}
PainterStartup/com/javera/ui/GetValue.classpackage
com.javera.ui;
publicabstractinterface GetValue {
publicabstract Object getValue();
}
PainterStartup/com/javera/ui/GetValue.javaPainterStartup/com/j
avera/ui/GetValue.java//Copyright 2004, (c) Javera Software, L
LC. as an unpublished work. All rights reserved world-wide.
//This is a proprietary trade secret of Javera Software LLC. Use
restricted to licensing terms.
package com.javera.ui;
82. /**
* GetValue interface provides access to the getValue() method
used
* to obtain a value associated with an object
*
* @author David T. Smith
*/
publicinterfaceGetValue{
/**
* Get the contained object
* @return the contained object
*/
publicObject getValue();
}
PainterStartup/com/javera/ui/GuiListDataListener.classpackage
com.javera.ui;
publicabstractinterface GuiListDataListener extends
javax.swing.event.ListDataListener {
}
PainterStartup/com/javera/ui/GuiListDataListener.javaPainterSt
artup/com/javera/ui/GuiListDataListener.java// Copyright 2004,
(c) Javera Software, LLC. as an unpublished work. All rights re
served world-wide.
// This is a proprietary trade secret of Javera Software LLC. Us
e restricted to licensing terms.
package com.javera.ui;
import javax.swing.event.ListDataListener;
/**
* @author dtsmith
83. */
publicinterfaceGuiListDataListenerextendsListDataListener{
}
PainterStartup/com/javera/ui/IconManager.classpackage
com.javera.ui;
publicsynchronizedclass IconManager {
static ClassLoader classLoader;
static java.util.Hashtable iconTable;
static void <clinit>();
public void IconManager();
publicstatic javax.swing.ImageIcon getIcon(String);
publicstatic javax.swing.ImageIcon getImageIcon(String);
}
PainterStartup/com/javera/ui/IconManager.javaPainterStartup/c
om/javera/ui/IconManager.java//Copyright 2004, (c) Javera Soft
ware, LLC. as an unpublished work. All rights reserved world-
wide.
//This is a proprietary trade secret of Javera Software LLC. Use
restricted to licensing terms.
package com.javera.ui;
import java.net.*;
import java.util.Hashtable;
import javax.swing.ImageIcon;
/**
* IconManager provides a convenience class to load icons.
*
* @author David T. Smith
*/
85. private java.util.ArrayList dataFlavors;
public void JavaObjectTransferable(Object);
public java.awt.datatransfer.DataFlavor[]
getTransferDataFlavors();
public boolean
isDataFlavorSupported(java.awt.datatransfer.DataFlavor);
public boolean
addDataFlavor(java.awt.datatransfer.DataFlavor);
public Object
getTransferData(java.awt.datatransfer.DataFlavor) throws
java.awt.datatransfer.UnsupportedFlavorException,
java.io.IOException;
}
PainterStartup/com/javera/ui/JavaObjectTransferable.javaPainte
rStartup/com/javera/ui/JavaObjectTransferable.java// Copyright
2004, (c) Javera Software, LLC. as an unpublished work. All ri
ghts reserved world-wide.
// This is a proprietary trade secret of Javera Software LLC. Us
e restricted to licensing terms.
package com.javera.ui;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
/**
* @author dtsmith
*/
publicclassJavaObjectTransferableimplementsTransferable,Seria
lizable{
87. private java.awt.Dimension dim;
public void JvBoxLayout$Filler(int, int);
public java.awt.Dimension getMinimumSize();
public java.awt.Dimension getPreferredSize();
public java.awt.Dimension getMaximumSize();
}
PainterStartup/com/javera/ui/layout/JvBoxLayout.classpackage
com.javera.ui.layout;
publicsynchronizedclass JvBoxLayout implements
java.awt.LayoutManager2, com.javera.ui.LayoutPrintLayout,
java.io.Serializable {
publicstaticfinal int X_AXIS = 0;
publicstaticfinal int Y_AXIS = 1;
private int axis;
private int gap;
private int topMargin;
private int bottomMargin;
private int leftMargin;
private int rightMargin;
private java.util.Map weightMap;
public void JvBoxLayout(int);
public void JvBoxLayout(int, int, int, int, int, int);
public int getGap();
public void setGap(int);
public int getTopMargin();
public void setTopMargin(int);
public int getLeftMargin();
public void setLeftMargin(int);
public int getBottomMargin();
public void setBottomMargin(int);
public int getRightMargin();
public void setRightMargin(int);
public void addLayoutComponent(java.awt.Component,
Object);
88. public java.awt.Dimension
maximumLayoutSize(java.awt.Container);
public float getLayoutAlignmentX(java.awt.Container);
public float getLayoutAlignmentY(java.awt.Container);
public void invalidateLayout(java.awt.Container);
public void addLayoutComponent(String,
java.awt.Component);
public void removeLayoutComponent(java.awt.Component);
public java.awt.Dimension
minimumLayoutSize(java.awt.Container);
public java.awt.Dimension
preferredLayoutSize(java.awt.Container);
public void layoutContainer(java.awt.Container);
publicstatic java.awt.Component createFiller(int, int);
public int layoutPrint(java.awt.Container, int);
}
PainterStartup/com/javera/ui/layout/JvBoxLayout.javaPainterSt
artup/com/javera/ui/layout/JvBoxLayout.java//Copyright 2004, (
c) Javera Software, LLC. as an unpublished work. All rights res
erved world-wide.
//This is a proprietary trade secret of Javera Software LLC. Use
restricted to licensing terms.
package com.javera.ui.layout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.LayoutManager2;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
89. import javax.accessibility.Accessible;
import com.javera.ui.LayoutPrintLayout;
import com.javera.ui.LayoutPrint;
//import com.javera.ui.panel.JvPanel;
/**
* A Javera box layout arranges components in a vertical or hori
zontal format.
* For vertical format all components are resized to have the sa
me width of
* the container, but have a height that is in proportion to their a
ssigned
* weights and such that the total height of all compoenents fills
the height
* of the container. Likewise a horizontal format will resize co
mponents to
* have the same width as the container and a height that is in pr
oportion to
* the assigned weights. If a component has an assigned weight
of 0 then that
* components is sized according to its preferred size.
*
* Weights are assigned using a Double as the second argument
to the
* containers add method. A null second argument will be inter
preted as a
* zero weight assignement.
*
* A Javera box layout is similar in function to a Box layout exc
ept that the
* assigned weights, not glue or preferred sizes are used to distr
ibute space
* over the row or column. Javera box layout also provides gap
* separation and margins.
90. *
* @author David T. Smith
*/
publicclassJvBoxLayoutimplementsLayoutManager2,LayoutPrin
tLayout,Serializable{
/**
* Horizontal axis orientation
*/
publicfinalstaticint X_AXIS =0;
/**
* Vertical axis orientation
*/
publicfinalstaticint Y_AXIS =1;
/**
* The axis orientation of the weighted layout.
*/
privateint axis;
/**
* The weighted layout manager allows a seperation of compo
nents with
* gaps. The gap will specify the space between components.
*
* @serial
* @see getGap
* @see setGap
*/
privateint gap;
/**
* The weighted layout manager allows specification of a top
margin to be
* reserved above laidout components.
91. *
* @serial
* @see getTopMargin
* @see setTopMargin
*/
privateint topMargin;
/**
* The command button layout manager allows specification
of a bottom
* margin to be reserved below laidout components.
*
* @serial
* @see getBottomMargin
* @see setBottomMargin
*/
privateint bottomMargin;
/**
* The weighted layout manager allows specification of a left
margin to be
* reserved to the left of the leftmost component.
*
* @serial
* @see getLeftMargin
* @see setLeftMargin
*/
privateint leftMargin;
/**
* The weighted layout manager allows specification of a rig
ht margin to
* be reserved to the right of the rightmost component.
*
* @serial
* @see getRightMargin
92. * @see setRightMargin
*/
privateint rightMargin;
/**
* A Map of each component's weight, keyed on the compone
nt
* objects themselves.
*/
privateMap weightMap =newHashMap();
/**
* Constructs a new Weighted Layout with specified axis, a d
efault 5 pixel
* gap, and a 5 pixel margins.
*
* @param axis X_AXIS or Y_AXIS
*/
publicJvBoxLayout(int axis){
this(axis,5,5,5,5,5);
}
/**
* Constructs a new Weighted Layout with specified axis, gap
, and margins.
*
* @param axis X_AXIS or Y_AXIS
* @param gap the gap between components.
* @param topMargin the top margin.
* @param leftMargin the left margin.
* @param bottomMargin the bottom margin.
* @param rightMargin the right margin.
*/
publicJvBoxLayout(
int axis,
int gap,
93. int topMargin,
int leftMargin,
int bottomMargin,
int rightMargin){
this.axis = axis;
this.gap = gap;
this.topMargin = topMargin;
this.leftMargin = leftMargin;
this.bottomMargin = bottomMargin;
this.rightMargin = rightMargin;
}
/**
* Gets the gap between components.
*
* @return the gap between components.
*/
publicint getGap(){
return gap;
}
/**
* Sets the gap between components.
*
* @param gap the gap between components
*/
publicvoid setGap(int gap){
this.gap = gap;
}
/**
* Gets the top margin to be reserved above all components.
*
* @return the top margin.
*/
publicint getTopMargin(){
94. return topMargin;
}
/**
* Sets the top margin to be reserve above components.
*
* @param topMargin the top margin.
*/
publicvoid setTopMargin(int topMargin){
this.topMargin = topMargin;
}
/**
* Gets the left margin to be reserved to the left of the
* leftmost component.
*
* @return the left margin.
*/
publicint getLeftMargin(){
return leftMargin;
}
/**
* Sets the left margin to be reserved to the left of the
* leftmost component.
*
* @param leftMargin the left margin.
*/
publicvoid setLeftMargin(int leftMargin){
this.leftMargin = leftMargin;
}
/**
* Gets the bottom margin to be reserved below all componen
ts.
*
95. * @return the bottom margin.
*/
publicint getBottomMargin(){
return bottomMargin;
18.2 problemTrue Flight Golf manufacturers a popular shaft for
golf clubs. Its trade secret is a unique process for weaving
high-tension wire into the center of the shaft such that energy is
accumulated during the swing and released at impact. A
specialized machine costing $3,000,000 is utilized in the
manufacturing process. The machine has a 3-year life and no
salvage value. True Flight uses straight-line depreciation.
During the year, 25,000 shafts were produced, and the company
was operating at full capacity. $700,000 of wire was used
during the year.(a)Is machinery depreciation fixed or variable?
Is wire fixed or variable?(b)For the two noted cost items, how
much was total variable cost and total fixed cost?(c)For the two
noted cost items, how much was variable cost per unit and how
much was fixed cost per unit?(d)Repeat requirements (b) and
(c), assuming production was only 20,000 units (and wire usage
was reduced proportionately).(e)For the following year, if the
company acquired an additional machine to enable production
of 40,000 total units, what would happen to the expected total
and per unit variable and fixed cost?(f)If the company
experiences significant growth, and finds it necessary to
continue to add additional machines, how would the machine
cost be characterized (hint: fixed, variable, or something else)?
In theory, at what production level(s) would per unit cost be
minimized?
&L&"Arial,Bold"&20 &R&"Myriad Web Pro,Bold"&20B-18.02
B-18.02
Worksheet(a)(b)(c)(d)(e)(f)
&L&"Myriad Web Pro,Bold"&12Name:
Date: Section: &R&"Myriad Web
96. Pro,Bold"&20B-18.02
B-18.02
19.2 ProblemMary Ann Clark is an artist and is employed by
Fenway Racing. Fenway Racing manufactures custom race cars
to exact specifications of drivers. Mary Ann's job is to hand
paint logos and other custom artwork on each car. Below is her
daily time sheet for March 7, 20X6:FENWAY
RACINGEmployee:Mary Ann ClarkDaily Time
SheetDate:03/07/X6Start
TimeStop
TimeJob NumberTaskClientAdmin HoursDirect Labor
Hours8:008:30set upPrepare paints and
airbrushn/a0.500.008:3010:45#11245Paint race numbersMario
A.0.002.2510:4511:00repairsRepair broken
compressorn/a0.250.0011:0012:00#11302Paint advertising sign
on
doorAJF0.000.7512:001:00lunchn/an/a0.000.001:004:30#11305
Paint hood logoJeff G.0.003.504:305:00clean upClean up
equipmentn/a0.500.00Total hours1.256.50(a)Examine the time
sheet and find the error. What is the importance of correctly
accumulating time by job? How does the time sheet data track
to the cost assignment process?(b)How much of Mary Ann's
time (after making the correction) is attributable to direct labor
and how much to overhead? How is the direct labor cost
assigned to individual jobs, and how is the overhead cost
allocated?
&R&"Myriad Web Pro,Bold"&20B-19.02
B-19.02
Worksheet (2)(a)(b)
&L&"Myriad Web Pro,Bold"&12Name:
Date: Section: &R&"Myriad Web
Pro,Bold"&20B-19.02
B-19.02
20.2 ProblemZeus Corporation produces cultured diamonds via
a secretive process that grows the diamonds in a vacuum
97. chamber filled with a carbon gas cloud. The diamonds are
produced in a single continuous process, and Zeus uses the
weighted-average process costing method of accounting for
production.
The production process requires constant utilization of facilities
and equipment, as well as direct labor by skilled technicians.
As a result, direct labor and factory overhead are both deemed
to be introduced uniformly throughout production.At the
beginning of June, 20X9, 4,000 diamonds were in process.
During June, an additional 8,000 diamonds were started, and
7,000 diamonds were completed and transferred to finished
goods.As of the beginning of the month, work in process was
80% complete with respect to materials and 60% complete with
respect to conversion costs.As of the end of the month, work in
process was 70% complete with respect to materials and 40%
complete with respect to conversion costs.Prepare a "unit
reconciliation" schedule that includes calculations showing the
equivalent units of materials, direct labor, and factory overhead
for June.
&L&"Arial,Bold"&20 &R&"Myriad Web Pro,Bold"&20B-20.02
B-20.02
Worksheet (3)Unit Reconciliation:Quantity
ScheduleBeginning Work in ProcessStarted into
ProductionTotal Units into ProductionEquivalent Units
Calculations:ConversionDirect
MaterialsDirect
LaborFactory OverheadTo Finished GoodsEnding Work in
ProcessTotal Units ReconciledEnding WIP Completion Status:
Materials = %
Conversion = %
&L&"Myriad Web Pro,Bold"&12Name:
Date: Section: &R&"Myriad Web
Pro,Bold"&20B-20.02
B-20.02
98. 21.2 ProblemLogan Township acquired its water system from a
private company on June 1. No receivables were acquired with
the purchase. Therefore, total accounts receivable on June 1
had a zero balance.
Logan plans to bill customers in the month following the month
of sale, and 70% of the resulting billings will be collected
during the billing month. In the next following month, 90% of
the remaining balance should be collectable. The remaining
uncollectible amounts will relate to citizens who have moved
away. Such amounts are never expected to be collected and will
be written off.
Water sales during June are estimated at $3,000,000, and
expected to increase 30% in July. August sales will be 10% less
than July sales.(a)For each dollar of sales, how much is
expected to be collected?(b)Estimate the monthly cash
collections for June, July, August, and September.(c)As of the
end of August, how much will be the estimated amount of
receivables from which future cash flows are anticipated?
&L&"Arial,Bold"&12 &R&"Myriad Web Pro,Bold"&20B-21.02
B-21.02
Worksheet
(4)(a)(b)JuneJulyAugustSeptember(c)JuneJulyAugustTotal
Receivables
&L&"Myriad Web Pro,Bold"&12Name:
Date: Section: &R&"Myriad Web
Pro,Bold"&20B-21.02
B-21.02