Re: Applet ( canvas )



Hello All ,

I have been doing dxf parser using Java Applets.
dxf is format file for Auto Cad files.
There is no problem in parsing the file, where the audo cad file(dxf)
is displayed as an applet.

Now I am adding extra functionality to it.
1. I should able to draw figures ( rectangle,circle ,arc.....) on the
applet which i got after parsing the file as output and generate
onclick and onselect events when those figures are drawn.

For this I have taken a class which extends Canvas where the
mouselisteners are implemented .
I am tracking the mousepress , mousedrag , mouse release events and
able to draw

PROBLEM

The problem I am facing is I couldn't able to generate oncreate event
and onselect event.

If I implement this event ,then I could able to select the figures and
able to drag them from one place to another

( A typical analogy to the figures we draw in word and able to select
and drag them)

Below is the code which I wrote , so please go through the code and
help me out in solving my problem.........This task is really
challenging for me and for u tooooooooooooo..............
The real task for Java Applet Programmers.....................
/
**********************************************************************************************
COPYRIGHT (c) 2009.
HONEYWELL INC.,
ALL RIGHTS RESERVED
This software is a copyrighted work and/or information protected
as a trade secret. Legal rights of Honeywell Inc. in this software
is distinct from ownership of any medium in which the software is
embodied. Copyright or trade secret notices included must be
reproduced in any copies authorized by Honeywell Inc.
The information in this software is subject to change without notice
and should not be considered as a commitment by Honeywell Inc.
Project Title :MLS
Development Platform : Windows XP
Development Tool : IBM WebSphere
Author(s) : D.S.GIRISH
***********************************************************************************************/
//
==============================================================================
// YxxfDrwTilemode1View.java
//
// Creates tilemode 1 views
//
==============================================================================

package com.ysystems.ycad.lib.yxxf;


import java.awt.Canvas;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.util.ArrayList;
import java.util.Vector;

import com.ysystems.lib.yutil.YutilProperties;
import com.ysystems.ycad.app.ycadv.Ycadv;


/**
* A collection of one or more nonoverlapping views in Model Space.
* <br>Tilemode 1 views.
* <br>Model Space (tiled viewports).
* <br>One to N nonoverlapping views.
* <br>Each view has its own draw thread rendering one model view.
* <br>
*/
public class YxxfDrwTilemode1View extends Canvas
{
int positionX1 = 0;
int positionY1 = 0;
int positionX2 = 0;
int positionY2 = 0;
int maxLines = 1000;
int currentLines = 0;
int[][] drawLines = new int[maxLines][4];
ArrayList al = new ArrayList();


public Point sPoint = new Point(-1, -1);
public Point ePoint = new Point(-1, -1);
public Vector points = new Vector();

public static Vector rectPoints = new Vector();

public final static Point fsPoint = new Point(-1,-1);
public final static Point fePoint = new Point(-1,-1);
public int numofrects;

public static int entity;
public final static int line = 1 ;
public final static int rectangle = 2;
/**
* Java Graphics Context for this Graphics Context.
*/
private
Graphics jgc;


/*private
YxxfDrwToolbarView entfile = new YxxfDrwToolbarView();*/

public
Ycadv entfile = new Ycadv();

//
==========================================================================
/**
* Properties.
*/
private
YutilProperties props_DrwTilemode1View
= new YutilProperties
();
//
==========================================================================


//
==========================================================================
// Display items.

/**
* Graphics context for this view.
*/
private
YxxfGfxContext gc = new YxxfGfxContext
();

/**
* Draw thread for this view.
*/
private
YxxfDrwTilemode1DrawT Tdraw;
//
==========================================================================


//
==========================================================================
/**
* View Handler.
*/
private
YxxfDrwViewHandler vhandler = null;

/**
* View Monitor.
*/
private
YxxfDrwViewMonitor vhandlermon = new
YxxfDrwViewMonitor();

/**
* View Event - Mouse Down.
*/
private
YxxfDrwViewHandlerEvent vhandlerevt_command_mousedown
= new
YxxfDrwViewHandlerEvent(

YxxfDrwViewHandlerEvent.COMMAND_MOUSEDOWN);

/**
* View Event - Mouse Drag.
*/
private
YxxfDrwViewHandlerEvent vhandlerevt_command_mousedrag
= new
YxxfDrwViewHandlerEvent(

YxxfDrwViewHandlerEvent.COMMAND_MOUSEDRAG);

/**
* View Event - Mouse Up.
*/
private
YxxfDrwViewHandlerEvent vhandlerevt_command_mouseup
= new
YxxfDrwViewHandlerEvent(

YxxfDrwViewHandlerEvent.COMMAND_MOUSEUP);


//
==========================================================================


//
==========================================================================
// Constructors

/**
* Constructor (empty)
*/
public
YxxfDrwTilemode1View()
{

}

/**
* Constructor
* @param D The Drawing.
* @param vport The Vport.
* @param vhandler The View Handler.
*/
public
YxxfDrwTilemode1View(Yxxf D, YxxfDrwViewHandler vhandler,
YxxfTblVport vport)
{
setDrawing(D);
setViewHandler(vhandler);
setVport(vport);
}

//g
/*public
void collectrectinfo(int sx,int sy,int ex,int ey)
{
System.out.println("In rectangle information"+sx+sy+ex+ey);
fsPoint.x=sx;fsPoint.y=sy;
fePoint.x=ex;fePoint.y=ey;
System.out.println("In rectangle information after
assigning"+fsPoint.x+fsPoint.y+fePoint.x+fePoint.y);
//jgc.drawRect(sx, sy, ex, ey);
//repaint();
System.out.println("IN Collecting information");
}*/

public
void collectrectinfo(ArrayList eList)
{
System.out.println("eList size is"+eList.size());
for(int i=0 ; i < eList.size() ; i++)
{
System.out.println("eList index 0 value"+eList.get(i));
Object c = eList.get(i);
if( c instanceof YxxfMarkupRect)
{
YxxfMarkupRect mRect=(YxxfMarkupRect)c;
System.out.println("Markuprect values"+mRect.sx+mRect.sy
+mRect.ex+mRect.ey);

rectPoints.addElement(new Rectangle
(mRect.sx,mRect.sy,mRect.ex, mRect.ey));
System.out.println("initial rectPoints size
is"+rectPoints.size());

//repaint();
}
}

}

//g

/**
* Set the Drawing.
* @param D The Drawing.
*/
public
void setDrawing(Yxxf D)
{
gc.setDrawing(D);
}

/**
* Get the Drawing.
* @return The Drawing.
*/
public
Yxxf getDrawing()
{
return gc.getDrawing();
}


/**
* Set the value of the controlling Viewhandler and connect the
monitor observer object.
* @param vhandler The Viewhandler.
*/
public
void setViewHandler(YxxfDrwViewHandler vhandler)
{
vhandlermon.deleteObservers();

this.vhandler = vhandler;

if (vhandler != null)
vhandlermon.addObserver(vhandler);
}

/**
* Get the Viewhandler.
* @return The Viewhandler.
*/
public
YxxfDrwViewHandler getViewHandler()
{
return vhandler;
}


/**
* Get the Graphics context.
*/
public
YxxfGfxContext getGC()
{
return gc;
}


/**
* Set the value of the Vport.
* @param vport The Vport.
*/
public
void setVport(YxxfTblVport vport)
{
gc.setVport(vport);
gc.setVportOrig((YxxfTblVport)vport.clone());
}

/**
* Get the Vport.
* @return The Vport.
*/
public
YxxfTblVport getVport()
{
return gc.getVport();
}


/**
* Set the value of the unmodified Vport.
* @param vportorig The unmodified Vport.
*/
public
void setVportOrig(YxxfTblVport vportorig)
{
gc.setVportOrig(vportorig);
}

/**
* Get the unmodified Vport (for undo).
* @return The unmodified Vport.
*/
public
YxxfTblVport getVportOrig()
{
return gc.getVportOrig();
}
//
==========================================================================


//
==========================================================================
// Set properties

/**
* Set properties from args string.
* @param args The Properties.
* @param scanout Parse the arguments flag.
*/
public
void setProperties(String args, boolean scanout)
{
props_DrwTilemode1View.setProperties(args, scanout);
}


/**
* Set properties from argv array.
* @param args The Properties.
*/
public
void setProperties(String argv[])
{
props_DrwTilemode1View.setProperties(argv);
}


/**
* Set properties from argprops YutilProperties.
* @param argprops The Properties.
*/
public
void setProperties(YutilProperties argprops)
{
props_DrwTilemode1View.setProperties(argprops);
}
//
==========================================================================


//
==========================================================================
/**
* Initialize the Tilemode1 View.
*/
public
void commandTilemode1View_init()
{
// Display local params
//d System.out.println("+++++++++++
+YxxfDrwTilemode1View:props_DrwTilemode1View.e BEG");
//d for (Enumeration e = props_DrwTilemode1View.propertyNames();
e.hasMoreElements(); )
//d {
//d String key = (String)e.nextElement();
//d String val = props_DrwTilemode1View.getProperty(key);
//d System.out.println("++++++++++++YxxfDrwTilemode1View:key=
[" + key + "],val=[" + val + "]");
//d }
//d System.out.println("+++++++++++
+YxxfDrwTilemode1View:props_DrwTilemode1View.e END");

//
// Create draw thread
//
Tdraw = new YxxfDrwTilemode1DrawT(this, gc);
Tdraw.setProperties(props_DrwTilemode1View); // Set properties
}
//
==========================================================================


//
==========================================================================
/**
* Start the Tilemode1 View draw thread.
*/
public
void commandTilemode1View_start()
{
//
// Start draw thread
//
Tdraw.start();
}
//
==========================================================================


//
==========================================================================
/**
* Redraw the Tilemode1 View.
*/
public
void commandTilemode1View_redraw()
{
repaint();
}
//
==========================================================================


//
==========================================================================
/**
* Wait for the Tilemode1 View draw to complete.
*/
public
void commandTilemode1View_wait_for_complete()
{
gc.commandGC_wait_for_complete();
}
//
==========================================================================


//
==========================================================================
/**
* Set rendering flag.
*/
public
void commandTilemode1View_set_rendering(boolean arg_val)
{
gc.setRenderingJGCFlag(arg_val);
}
//
==========================================================================


//
==========================================================================
/**
* Undo any changes to the Tilemode1 View and redraw it.
*/
public
void commandTilemode1View_restore()
{
getVportOrig().copyInto(getVport()); // Restore original vport

gc.commandGC_user_view_reset(); // Reset user view

if (gc.getRenderingJGCFlag())
commandTilemode1View_redraw();
}
//
==========================================================================


//
==========================================================================
/**
* Draw the Tilemode 1 View scaled to the size of the object.
*/
public
void commandTilemode1View_calc_extents()
{
gc.gc_doing_flag_calc_extents = true;

commandTilemode1View_redraw();
}
//
==========================================================================


//
==========================================================================
/**
* Zoom in to the Tilemode1 View object and redraw it.
*/
public
void commandTilemode1View_zoom_in(double zoompct)
{
getVport().vheight *= (1.0 - (zoompct / 100.0));

if (gc.getRenderingJGCFlag())
commandTilemode1View_redraw();
}
//
==========================================================================


//
==========================================================================
/**
* Zoom out from the Tilemode1 View object and redraw it.
*/
public
void commandTilemode1View_zoom_out(double zoompct)
{
getVport().vheight *= (1.0 + (zoompct / 100.0));

if (gc.getRenderingJGCFlag())
commandTilemode1View_redraw();
}
//
==========================================================================


//
==========================================================================
/**
* Zoom in to the head extents of Tilemode1 View object and redraw
it.
*/
public
void commandTilemode1View_zoom_to_head_extents()
{
// M_view
getVport().vtgt.set(YxxfGfxPointW.W0);
getVport().vdir.set(YxxfGfxPointW.Wz);
getVport().viewtwistang = 0.0; // Degrees

// M_user
gc.commandGC_user_view_reset(); // Reset user view

// M_display
getVport().vheight = getDrawing().secHeader.extmax.y -
getDrawing().secHeader.extmin.y;
getVport().vaspect = Math.abs(getDrawing().secHeader.extmax.x
- getDrawing().secHeader.extmin.x) / // vaspect = vwidth / vheight
Math.abs(getDrawing().secHeader.extmax.y
- getDrawing().secHeader.extmin.y);
getVport().vcpx = (getDrawing().secHeader.extmin.x + getDrawing
().secHeader.extmax.x) / 2.0;
getVport().vcpy = (getDrawing().secHeader.extmin.y + getDrawing
().secHeader.extmax.y) / 2.0;

if (gc.getRenderingJGCFlag())
commandTilemode1View_redraw();
}
//
==========================================================================


//
==========================================================================
/**
* Zoom to the calc extents of Tilemode1 View and redraw it.
*/
public
void commandTilemode1View_zoom_to_calc_extents()
{
if (gc.gc_doing_flag_calc_extents_valid)
{
setVportToCalcExtents();
}
else
{
gc.gc_doing_flag_calc_extents = true; // need to calculate
the extents
gc.gc_doing_flag_zoom_to_calc_extents = true; // and zoom
to them
}

// System.out.println("+++++++++++
+YxxfDrwTilemode1View:gc_doing_flag_calc_extents=" +
gc.gc_doing_flag_calc_extents);
// System.out.println("+++++++++++
+YxxfDrwTilemode1View:gc_doing_flag_calc_extents_valid=" +
gc.gc_doing_flag_calc_extents_valid);
// System.out.println("+++++++++++
+YxxfDrwTilemode1View:gc_doing_flag_zoom_to_calc_extents=" +
gc.gc_doing_flag_zoom_to_calc_extents);
// System.out.println("+++++++++++
+YxxfDrwTilemode1View:extmin=" + gc.calc_extmin);
// System.out.println("+++++++++++
+YxxfDrwTilemode1View:extmax=" + gc.calc_extmax);

commandTilemode1View_redraw();
}

/**
* Utility method - sets the Vport to the previously calculated
and valid extents.
*/
protected
void setVportToCalcExtents()
{
// M_view
getVport().vtgt.set(YxxfGfxPointW.W0);
getVport().vdir.set(YxxfGfxPointW.Wz);
getVport().viewtwistang = 0.0; // Degrees

// M_user
gc.commandGC_user_view_reset();

// M_display
getVport().vheight = gc.calc_extmax.y - gc.calc_extmin.y;
getVport().vaspect = Math.abs(gc.calc_extmax.x -
gc.calc_extmin.x) / // vaspect = vwidth / vheight
Math.abs(gc.calc_extmax.y -
gc.calc_extmin.y);
getVport().vcpx = (gc.calc_extmin.x + gc.calc_extmax.x) / 2.0;
getVport().vcpy = (gc.calc_extmin.y + gc.calc_extmax.y) / 2.0;
}
//
==========================================================================


//
==========================================================================
/**
* Pan left over the Tilemode1 View and redraw it.
*/
public
void commandTilemode1View_pan_l(double panpct)
{
getVport().vcpx -= (getVport().vheight * getVport().vaspect) *
(panpct / 100.0);

if (gc.getRenderingJGCFlag())
commandTilemode1View_redraw();
}
//
==========================================================================


//
==========================================================================
/**
* Pan right over the Tilemode1 View and redraw it.
*/
public
void commandTilemode1View_pan_r(double panpct)
{
getVport().vcpx += (getVport().vheight * getVport().vaspect) *
(panpct / 100.0);

if (gc.getRenderingJGCFlag())
commandTilemode1View_redraw();
}
//
==========================================================================


//
==========================================================================
/**
* Pan up over the Tilemode1 View and redraw it.
*/
public
void commandTilemode1View_pan_u(double panpct)
{
getVport().vcpy += getVport().vheight * (panpct / 100.0);

if (gc.getRenderingJGCFlag())
commandTilemode1View_redraw();
}
//
==========================================================================


//
==========================================================================
/**
* Pan down over the Tilemode1 View and redraw it.
*/
public
void commandTilemode1View_pan_d(double panpct)
{
getVport().vcpy -= getVport().vheight * (panpct / 100.0);

if (gc.getRenderingJGCFlag())
commandTilemode1View_redraw();
}
//
==========================================================================


//
==========================================================================
/**
* Rotate the Tilemode1 View around the x coordinate and redraw
it.
*/
public
void commandTilemode1View_rotate_x_p()
{
gc.commandGC_user_view_rotate_x_p();

if (gc.getRenderingJGCFlag())
commandTilemode1View_redraw();
}
//
==========================================================================


//
==========================================================================
/**
* Rotate the Tilemode1 View around the x coordinate and redraw
it.
*/
public
void commandTilemode1View_rotate_x_m()
{
gc.commandGC_user_view_rotate_x_m();

if (gc.getRenderingJGCFlag())
commandTilemode1View_redraw();
}
//
==========================================================================


//
==========================================================================
/**
* Rotate the Tilemode1 View around the y coordinate and redraw
it.
*/
public
void commandTilemode1View_rotate_y_p()
{
gc.commandGC_user_view_rotate_y_p();

if (gc.getRenderingJGCFlag())
commandTilemode1View_redraw();
}
//
==========================================================================


//
==========================================================================
/**
* Rotate the Tilemode1 View around the y coordinate and redraw
it.
*/
public
void commandTilemode1View_rotate_y_m()
{
gc.commandGC_user_view_rotate_y_m();

if (gc.getRenderingJGCFlag())
commandTilemode1View_redraw();
}
//
==========================================================================


//
==========================================================================
/**
* Rotate the Tilemode1 View around the z coordinate and redraw
it.
*/
public
void commandTilemode1View_rotate_z_p()
{
gc.commandGC_user_view_rotate_z_p();

if (gc.getRenderingJGCFlag())
commandTilemode1View_redraw();
}
//
==========================================================================


//
==========================================================================
/**
* Rotate the Tilemode1 View around the z coordinate and redraw
it.
*/
public
void commandTilemode1View_rotate_z_m()
{
gc.commandGC_user_view_rotate_z_m();

if (gc.getRenderingJGCFlag())
commandTilemode1View_redraw();
}
//
==========================================================================


//
==========================================================================
// Rotate x, y, z using value

/**
* Rotate the Tilemode1 View around the x coordinate and redraw
it.
*/
public
void commandTilemode1View_rotate_x_value(double value)
{
gc.commandGC_user_view_rotate_x_value(value);

if (gc.getRenderingJGCFlag())
commandTilemode1View_redraw();
}

/**
* Rotate the Tilemode1 View around the y coordinate and redraw
it.
*/
public
void commandTilemode1View_rotate_y_value(double value)
{
gc.commandGC_user_view_rotate_y_value(value);

if (gc.getRenderingJGCFlag())
commandTilemode1View_redraw();
}

/**
* Rotate the Tilemode1 View around the z coordinate and redraw
it.
*/
public
void commandTilemode1View_rotate_z_value(double value)
{
gc.commandGC_user_view_rotate_z_value(value);

if (gc.getRenderingJGCFlag())
commandTilemode1View_redraw();
}
//
==========================================================================


//
==========================================================================
/**
* Begin forming the rubber band box on the Tilemode1 View
* @param x The x coordinate.
* @param y The y coordinate.
* @param jgc The Java Graphics object.
*/
public
void commandTilemode1View_rbb_beg(int x, int y, Graphics jgc)
{
gc.commandGC_rbb_beg(x, y, jgc);
}

/**
* Drag the rubber band box on the Tilemode1 View
* @param x The x coordinate.
* @param y The y coordinate.
*/
public
void commandTilemode1View_rbb_drag(int x, int y)
{
gc.commandGC_rbb_drag(x, y);

}

/**
* End the forming of the rubber band box on the Tilemode1 View
* @param x The x coordinate.
* @param y The y coordinate.
*/
public
void commandTilemode1View_rbb_end(int x, int y)
{
gc.commandGC_rbb_end(x, y);



}
//
==========================================================================


//
==========================================================================
/**
* Begin rubber band line draw.
* @param x The x coordinate.
* @param y The y coordinate.
* @param jgc The Java Graphics object.
*/
public
void commandTilemode1View_rbl_beg(int x, int y, Graphics jgc)
{
gc.commandGC_rbl_beg(x, y, jgc);
}

/**
* Draw rubber band line as cursor is dragged.
* @param x The x coordinate.
* @param y The y coordinate.
*/
public
void commandTilemode1View_rbl_drag(int x, int y)
{
gc.commandGC_rbl_drag(x, y);
//commandTilemode1View_redraw();
}

/**
* End rubber band line draw.
* @param x The x coordinate.
* @param y The y coordinate.
*/
public
void commandTilemode1View_rbl_end(int x, int y)
{
gc.commandGC_rbl_end(x, y);
// commandTilemode1View_redraw();
}
//
==========================================================================


//
==========================================================================
/**
* Calculate the position of the Viewport based on the parent
Viewport.
* @return The origination point.
*/
public
Point location()
{
//d System.out.println("+++++++++++
+YxxfDrwTilemode1View:location");
Container parent = getParent();

if (parent == null)
return super.location();

Dimension parentsize = parent.size();

int bw = props_DrwTilemode1View.getProperty_int
("borderwidth"); // border width

int x = (int)Math.floor(getVport().llx * (double)
(parentsize.width - bw));
int y = (int)Math.floor(getVport().ury * (double)
(parentsize.height - bw));

// System.out.println("+++++++++++
+YxxfDrwTilemode1View:location ,parentsize=" + parentsize + ",x="
+ x + ",y=" + y);
return new Point (x + bw, (parentsize.height - bw) - y + bw);
}


/**
* Calculate the preferred dimensions of the Viewport based
* on the parent Viewport dimensions.
* @return The Viewport dimensions.
*/
public
Dimension preferredSize()
{
//d System.out.println("+++++++++++
+YxxfDrwTilemode1View:preferredSize");
Container parent = getParent();

if (parent == null)
return super.preferredSize();

Dimension parentsize = parent.size();

int bw = props_DrwTilemode1View.getProperty_int
("borderwidth"); // border width

int x1 = (int)Math.floor(getVport().llx * (double)
(parentsize.width - bw));
int x2 = (int)Math.floor(getVport().urx * (double)
(parentsize.width - bw));

int h1 = (int)Math.floor(getVport().lly * (double)
(parentsize.height - bw));
int h2 = (int)Math.floor(getVport().ury * (double)
(parentsize.height - bw));

// System.out.println("+++++++++++
+YxxfDrwTilemode1View:preferredSize,parentsize=" + parentsize + ",x1="
+ x1 + ",x2=" + x2 + ",h1=" + h1 + ",h2=" + h2);
return new Dimension(x2 - (x1 - 1) - 1 - bw, h2 - (h1 - 1) - 1
- bw);
}


/**
* Calculate the minimum size of the Viewport based on the parent
Viewport.
* @return The minimum Viewport dimensions.
*/
public
Dimension minimumSize()
{
//d System.out.println("+++++++++++
+YxxfDrwTilemode1View:minimumSize");
return preferredSize();
}


// public
// void resize(int w, int h)
// {
//d System.out.println("++++++++++++YxxfDrwTilemode1View:resize("
+ w + "," + h + ")");
// super.resize(w, h);
// }


// public
// void reshape(int x, int y, int w, int h)
// {
//d System.out.println("++++++++++++YxxfDrwTilemode1View:reshape("
+ x + "," + y + "," + w + "," + h + ")");
// super.reshape(x, y, w, h);
// }


//d public
//d void layout()
//d {
//d System.out.println("++++++++++++YxxfDrwTilemode1View:layout("
+ ")");
//d System.out.println(" :layout|
isEn=" + isEnabled() +
//d
",isSh=" + isShowing() +
//d
",isVa=" + isValid() +
//d
",isVi=" + isVisible() );
//d super.layout();
//d }
//
==========================================================================


//
==========================================================================
// public
// boolean action(Event evt, Object arg)
// {
// System.out.println("++++++++++++YxxfDrwTilemode1View:IN
action ,evt=[" + evt + "]");
//
// return false;
// }


/* public
boolean gotFocus(Event evt, Object arg)
{
evt.g
System.out.println("++++++++++++YxxfDrwTilemode1View:IN
gotFocus ,evt=[" + evt + "]");

return false;
}*/


// public
// boolean lostFocus(Event evt, Object arg)
// {
// System.out.println("++++++++++++YxxfDrwTilemode1View:IN
lostFocus ,evt=[" + evt + "]");
//
// return false;
// }


/**
* Respond to a mouse button press event.
* @param evt The event.
* @param x The x coordinate of the cursor.
* @param y The y coordinate of the cursor.
* @return true since the event was responded to.
*/
public
boolean mouseDown(Event evt, int x, int y)
{
drawLines[currentLines][0] = positionX1 = x;
drawLines[currentLines][1] = positionY1 = y;

sPoint.x = x;
sPoint.y = y;
//System.out.println("++++++++++++YxxfDrwTilemode1View:IN
mouseDown ,evt=[" + evt + "],x=" + x + ",y=" + y);
System.out.println("++++++++++++YxxfDrwTilemode1View:IN mouseDown
x=" + x + ",y=" + y);

vhandlermon.notifyViewHandler(vhandlerevt_command_mousedown.setArgs
(this, getGraphics(), x, y));

return true;
}


/**
* Respond to a mouse drag while the button is pressed event.
* @param evt The event.
* @param x The x coordinate of the cursor.
* @param y The y coordinate of the cursor.
* @return true since the event was responded to.
*/
public
boolean mouseDrag(Event evt, int x, int y)
{

ePoint.x =x;
ePoint.y = y;

// System.out.println("++++++++++++YxxfDrwTilemode1View:IN
mouseDrag ,evt=[" + evt + "],x=" + x + ",y=" + y);
System.out.println("++++++++++++YxxfDrwTilemode1View:IN
mouseDrag ,x=" + x + ",y=" + y);
// repaint();
vhandlermon.notifyViewHandler
(vhandlerevt_command_mousedrag.setArgs(this, null, x, y));
//repaint();

return true;

}


/**
* Respond to a mouse button release event.
* @param evt The event.
* @param x The x coordinate of the cursor.
* @param y The y coordinate of the cursor.
* @return true since the event was responded to.
*/
public
boolean mouseUp(Event evt, int x, int y)
{
if(entity ==1)
{
drawLines[currentLines][2] = positionX2 = x;
drawLines[currentLines][3] = positionY2 = y;
al.add(drawLines);
currentLines++;
repaint();
}
else if(entity ==2)
{
ePoint.x = x;
ePoint.y = y;
if ((ePoint.x < sPoint.x) & (ePoint.y < sPoint.y))
{
points.addElement(new Rectangle(ePoint.x, ePoint.y, sPoint.x,
sPoint.y));
}
else if (ePoint.x < sPoint.x)
{
points.addElement(new Rectangle(ePoint.x, sPoint.y, sPoint.x,
ePoint.y));
}
else if (ePoint.y < sPoint.y)
{
points.addElement(new Rectangle(sPoint.x, ePoint.y, ePoint.x,
sPoint.y));
}
else
{
points.addElement(new Rectangle(sPoint.x, sPoint.y, ePoint.x,
ePoint.y));
}
repaint();
}
entfile.savingentities(sPoint.x, sPoint.y, ePoint.x, ePoint.y);

// System.out.println("++++++++++++YxxfDrwTilemode1View:IN
mouseUp ,evt=[" + evt + "],x=" + x + ",y=" + y);
System.out.println("++++++++++++YxxfDrwTilemode1View:IN
mouseUp ,x=" + x + ",y=" + y);
repaint();

vhandlermon.notifyViewHandler
(vhandlerevt_command_mouseup.setArgs(this, null, x, y));

numofrects=points.size();
System.out.println("THE NUMBER OF RECTANGLES
ARE:"+numofrects);

return true;
}





// public
// boolean mouseEnter(Event evt, int x, int y)
// {
// System.out.println("++++++++++++YxxfDrwTilemode1View:IN
mouseEnter,evt=[" + evt + "],x=" + x + ",y=" + y);
// System.out.println("++++++++++++YxxfDrwTilemode1View:IN
mouseEnter,x=" + x + ",y=" + y);
//
// return false;
// }


// public
// boolean mouseExit(Event evt, int x, int y)
// {
// System.out.println("++++++++++++YxxfDrwTilemode1View:IN
mouseExit ,evt=[" + evt + "],x=" + x + ",y=" + y);
// System.out.println("++++++++++++YxxfDrwTilemode1View:IN
mouseExit ,x=" + x + ",y=" + y);
//
// return false;
// }


// public
// boolean mouseMove(Event evt, int x, int y)
// {
// System.out.println("++++++++++++YxxfDrwTilemode1View:IN
mouseMove ,evt=[" + evt + "],x=" + x + ",y=" + y);
// System.out.println("++++++++++++YxxfDrwTilemode1View:IN
mouseMove ,x=" + x + ",y=" + y);
//
// return false;
// }
//
==========================================================================


//
==========================================================================
// Painting
//
==========================================================================
/**
* Intercept paint(jgc).
* @param jgc The Java Graphics object.
*/
/*public
void paint(Graphics g)
{
update(g);
}*/

public
void paint(Graphics g)
{
super.paint(g);
gc.commandGC_set_doing_redraw();

Graphics2D g2d= (Graphics2D)g;

g.setColor(Color.red);

// Entities from file
Rectangle entRect;
for(int i=0;i < rectPoints.size(); i++)
{
System.out.println("In rectPoints");
entRect = (Rectangle)rectPoints.elementAt(i);
g.drawRect(entRect.x,entRect.y,entRect.width-
entRect.x,entRect.height-entRect.y);
}

g2d.addRenderingHints( new RenderingHints
( RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON ) );

System.out.println("++++++++YxxfDrwTilemode1View:paint(" + g +
"),isEn=" + isEnabled() + ",isSh=" + isShowing() + ",isVa=" + isValid
() + ",isVi=" + isVisible());

if( entity == 1)
{
for(int i = 0; i < al.size(); i++)
{
g.drawLine(drawLines[i][0],drawLines[i][1],drawLines[i]
[2],drawLines[i][3]);
}
}
else if( entity == 2 )
{
Rectangle p;
// Draw old rectangles.
for(int i=0; i < points.size(); i++)
{
System.out.println("old rectangle size is"+points.size());
p = (Rectangle)points.elementAt(i);
g.drawRect(p.x, p.y, p.width-p.x, p.height-p.y);
//g.drawOval(p.x, p.y, p.width-p.x, p.height-p.y);
}
// Draw current rectangle.
if ((ePoint.x < sPoint.x) & (ePoint.y < sPoint.y))
g.drawRect(ePoint.x, ePoint.y, sPoint.x- ePoint.x, sPoint.y -
ePoint.y);
// g.drawOval(ePoint.x, ePoint.y, sPoint.x- ePoint.x, sPoint.y -
ePoint.y);
else if (ePoint.x < sPoint.x)
g.drawRect(ePoint.x, sPoint.y, sPoint.x-ePoint.x, ePoint.y-
sPoint.y);
//g.drawOval(ePoint.x, sPoint.y, sPoint.x-ePoint.x, ePoint.y-
sPoint.y);
else if (ePoint.y < sPoint.y)
g.drawRect(sPoint.x, ePoint.y, ePoint.x-sPoint.x, sPoint.y-
ePoint.y);
//g.drawOval(sPoint.x, ePoint.y, ePoint.x-sPoint.x, sPoint.y-
ePoint.y);
else
g.drawRect(sPoint.x, sPoint.y, ePoint.x-sPoint.x, ePoint.y-
sPoint.y);
//g.drawOval(sPoint.x, sPoint.y, ePoint.x-sPoint.x, ePoint.y-
sPoint.y);
}
//g.drawRect(fsPoint.x, fsPoint.y, fePoint.x,
fePoint.y);
// gc.commandGC_set_doing_redraw();
}


// /**
// * Passthru paintAll(jgc).
// * @param jgc The Java Graphics object.
// */
/* public
void paintAll(Graphics jgc)
{
System.out.println("++++++++YxxfDrwTilemode1View:paintAll(" +
jgc + "),isEn=" + isEnabled() + ",isSh=" + isShowing() + ",isVa=" +
isValid() + ",isVi=" + isVisible());
super.paintAll(jgc);
}*/


// /**
// * Passthru repaint().
// * @param jgc The Java Graphics object.
// */
// public
// void repaint()
// {
// System.out.println("++++++++YxxfDrwTilemode1View:repaint
(),isEn=" + isEnabled() + ",isSh=" + isShowing() + ",isVa=" + isValid
() + ",isVi=" + isVisible());
// super.repaint();
// }


// /**
// * Passthru repaint(x, y, width, height).
// * @param x X coordinate.
// * @param y Y coordinate.
// * @param width Width.
// * @param height Height.
// */
// public
// void repaint(int x, int y, int width, int height)
// {
// System.out.println("++++++++YxxfDrwTilemode1View:repaint (" +
x + "," + y + "," + width + "," + height + "),isEn=" + isEnabled() +
",isSh=" + isShowing() + ",isVa=" + isValid() + ",isVi=" + isVisible
());
// super.repaint(x, y, width, height);
// }


// /**
// * Passthru repaint(tm).
// * @param tm Time in milliseconds.
// */
// public
// void repaint(long tm)
// {
// System.out.println("++++++++YxxfDrwTilemode1View:repaint (" +
tm + "),isEn=" + isEnabled() + ",isSh=" + isShowing() + ",isVa=" +
isValid() + ",isVi=" + isVisible());
// super.repaint(tm);
// }


// /**
// * Passthru repaint(tm, x, y, width, height).
// * @param tm Time in milliseconds.
// * @param x X coordinate.
// * @param y Y coordinate.
// * @param width Width.
// * @param height Height.
// */
// public
// void repaint(long tm, int x, int y, int width, int height)
// {
// System.out.println("++++++++YxxfDrwTilemode1View:repaint (" +
tm + "," + x + "," + y + "," + width + "," + height + "),isEn=" +
isEnabled() + ",isSh=" + isShowing() + ",isVa=" + isValid() + ",isVi="
+ isVisible());
// super.repaint(tm, x, y, width, height);
// }


/**
* Intercept update(jgc).
* @param jgc The Java Graphics object.
*/
/* public
void update(Graphics jgc)
{
System.out.println("++++++++YxxfDrwTilemode1View:update (" +
jgc + "),isEn=" + isEnabled() + ",isSh=" + isShowing() + ",isVa=" +
isValid() + ",isVi=" + isVisible());
paint(jgc);
}*/
//
==========================================================================


//
==========================================================================
// Printing
//
==========================================================================
/**
* Hook for print().
* Redraw the Viewport into Graphics Object.
* @param jpc The Java Graphics object for printing.
*/
public
void print(Graphics jpc)
{
Rectangle jpc_cliprect = jpc.getClipRect();
System.out.println("++++++++YxxfDrwTilemode1View:print,jpc=" +
jpc + ",jpc.getClipRect()=" + jpc_cliprect);

// Create view
YxxfPrtTilemode1View
prt_tilemode1view = new YxxfPrtTilemode1View(getDrawing(),
jpc,
(int)
jpc_cliprect.x,
(int)
jpc_cliprect.y,
(int)
jpc_cliprect.width,
(int)
jpc_cliprect.height,
getVport());

prt_tilemode1view.setProperties(this.props_DrwTilemode1View);


// Set print background color
String str_printbgcolor = props_DrwTilemode1View.getProperty
("printbgcolor");
if (str_printbgcolor == null)
{ // not set - make it white
prt_tilemode1view.setProperties("bgcolor=#FFFFFF", false);
}
else
if (str_printbgcolor.equals("bgcolor"))
{ // match bgcolor
String str_bgcolor = props_DrwTilemode1View.getProperty
("bgcolor");
if (str_bgcolor == null)
prt_tilemode1view.setProperties("bgcolor=#000000",
false);
else
prt_tilemode1view.setProperties("bgcolor=" +
str_bgcolor, false);
}
else
{ // explicit value
prt_tilemode1view.setProperties("bgcolor=" +
str_printbgcolor, false);
}


// Set print foreground palette
String str_printfgcolor = props_DrwTilemode1View.getProperty
("printfgcolor");
if (str_printfgcolor == null)
{ // depends on value of fgcolor
String str_fgcolor = props_DrwTilemode1View.getProperty
("fgcolor");
if (str_fgcolor == null)
prt_tilemode1view.setProperties
("fgcolor=acihighinverse", false);
else
prt_tilemode1view.setProperties("fgcolor=" +
str_fgcolor, false);
}
else
if (str_printfgcolor.equals("fgcolor"))
{ // match fgcolor
String str_fgcolor = props_DrwTilemode1View.getProperty
("fgcolor");
if (str_fgcolor == null)
prt_tilemode1view.setProperties("fgcolor=aci", false);
else
prt_tilemode1view.setProperties("fgcolor=" +
str_fgcolor, false);
}
else
{ // explicit value
prt_tilemode1view.setProperties("fgcolor=" +
str_printfgcolor, false);
}


// Render and wait
prt_tilemode1view.commandTilemode1View_init();
prt_tilemode1view.commandTilemode1View_start();
prt_tilemode1view.commandTilemode1View_redraw();
prt_tilemode1view.commandTilemode1View_wait_for_complete();

// ToDo: stop prt threads
}

/**
* Hook for printAll().
* @param jpc The Java Graphics object for printing.
*/
public
void printAll(Graphics jpc)
{
System.out.println("+++++++
+YxxfDrwTilemode1View:printAll,jpc=" + jpc);
super.printAll(jpc);
}
//
==========================================================================


//
==========================================================================
/**
* Prepare GC for drawing (pre).
* @return Selected insert.
*/
public
YxxfEntInsert setupGC_predraw()
{
// Set space
YxxfEntInsert ins = gc.getDrawing().secEntities.insMSpace;
gc.setupInsertInit(ins);
gc.initModelStack();

// calc transformation and scale to fit window
gc.setDspwin(this.size());
gc.calcdsp_vport();

// Set the Java Graphics Context
gc.setJGC(this.getGraphics());


// Set background color
String str_bgcolor = props_DrwTilemode1View.getProperty
("bgcolor");
if (str_bgcolor == null)
gc.setBGColor("#000000");
else
gc.setBGColor(str_bgcolor);


// Set foreground palette
String str_fgcolor = props_DrwTilemode1View.getProperty
("fgcolor");
if (str_fgcolor == null)
gc.getPalette().setPalette_aci();
else
if (str_fgcolor.equals("aci"))
gc.getPalette().setPalette_aci();
else
if (str_fgcolor.equals("acihighinverse"))
gc.getPalette().setPalette_acihighinverse();
else
gc.getPalette().setPalette_singlecolor(str_fgcolor);


return ins;
}


/**
* Prepare GC for drawing (post).
*/
public
void setupGC_postdraw()
{
// Shutdown graphics context for screen view
gc.getJGC().dispose();
}
//
==========================================================================
}

This is only the class which i implemented for drawing by extending
the canvas.



.


Quantcast