//*************************************************************************** // Application: Villanova Cat Cave Conference Center // File: whiteBoard.java // Module: whiteBoard // Version: 1.0 // Written by: Mark Juliano and Sharon Morris and // Graham Mehl and Dharmendra Katkuri and // Thomas Di Sessa // Villanova Master of Science Candidate // Independent Study project // // Rob LaRubbio // Villanova Bachelor of Science Candidate // Independent Study project // // Date: 3/31/96 // // Purpose: This file controls all the actions and communication that // occurs with the white board. All forms of communication // goes through the white board be it in bound or out bound // All Objects that are created are stored by each white board // The white board communicates with the tool kit to ensure // all actions and modes are being interpretted properly. // //*************************************************************************** import java.awt.*; import java.util.*; import java.lang.*; class whiteBoard extends Panel { private Vector items = new Vector(); private toolKit tk; Color Active_Color = Color.black; /* * This is bad design, but we don't know how else to do it */ obj moveMe = null; obj moveSe = null; int skip, firstX, firstY; boolean stat = true; // ********************* Dharma's code (start) ***************** int firstClick = 0; boolean Permit_cont_line = false; private StringBuffer Cont_line_send; int prevX = 0, prevY = 0; int backupX1, backupY1, backupX2, backupY2; String backupMode = " "; Vector backupPoints = new Vector(); obj backupObj = null; int findIndex; int findIndex1; // ********************* Dharma's code (end)******************** zClientDef clientDef; CardWindow card; private StringBuffer SendMe; /* * This method assists in determining at what index of * the string passed the next comma is located */ int NextComma( String message ) { int index = 0; while( message.charAt( index++ ) != ',' ); return( --index ); } /* * This method assists in determining the numeric value * of the string passed, which will be a X or Y * coordinate */ int GetNextCoordinate( String message ) { int index = 0; String coord; index = this.NextComma( message ); coord = message.substring( 0, index ); return( Integer.parseInt( coord, 10 ) ); } // ************** Graham Mehl made changes below this line ****************** /* * This method retrieves the message being * transmitted across the network for drawing on * white boards in the conference room */ String getMessage(String msg) { String tempString = "Temp String Value"; int index; index = this.NextComma( msg ); tempString = msg.substring( 0, index ); return (tempString); } /* * This method retrieves the value of the fontSize being * transmitted across the network for drawing on * white boards in the conference room */ int getFontSize (String stringFontSize) { String font; font = stringFontSize.substring( 0, 2 ); return( Integer.parseInt( font, 10 ) ); } // ************** Graham Mehl made changes above this line ****************** /* * returns the active color of the objects on the * White board */ Color getColor( ) { Active_Color = tk.getColor(); return ( Active_Color ); } /* * This method converts a color in to a literal allowing * it to become part of a string to be transmitted across * the network to another white board */ char GetColor( Color color ) { if( color == Color.blue ) { return( '0' ); } if( color == Color.red ) { return( '1' ); } if( color == Color.black ) { return( '2' ); } if( color == Color.yellow ) { return( '3' ); } if( color == Color.cyan ) { return( '4' ); } if( color == Color.magenta ) { return( '5' ); } if( color == Color.green ) { return( '6' ); } if( color == Color.gray ) { return( '7' ); } if( color == Color.orange ) { return( '8' ); } if( color == Color.pink ) { return( '9' ); } return( '0' ); } /* * This method converts a literal in to a color allowing * it to be pealed off a string that has been transmitted * across the network to another white board */ Color GetColor( String message ) { Color color = Color.black; switch( message.charAt( 0 ) ) { case '0': // blue color = Color.blue; break; case '1': // red color = Color.red; break; case '2': // black color = Color.black; break; case '3': // yellow color = Color.yellow; break; case '4': // cyan color = Color.cyan; break; case '5': // magenta color = Color.magenta; break; case '6': // green color = Color.green; break; case '7': // gray color = Color.gray; break; case '8': // orange color = Color.orange; break; case '9': // pink color = Color.pink; break; } return( color ); } public void DrawObject( String message ) { char firstChar = message.charAt( 0 ); int x1=0, y1=0, x2=0, y2=0, nextComma = 0, nextStart = 0; int x, y, loop=0; Color color= getColor(); if (firstChar != 'Q') { x1 = this.GetNextCoordinate( message.substring( 1 ) ); nextComma = this.NextComma( message.substring( 0 ) ); nextStart = nextComma + 1; y1 = this.GetNextCoordinate( message.substring( nextStart ) ); nextComma = this.NextComma( message.substring( nextStart ) ); nextStart = nextStart + nextComma + 1; x2 = this.GetNextCoordinate( message.substring( nextStart ) ); nextComma = this.NextComma( message.substring( nextStart ) ); nextStart = nextStart + nextComma + 1; y2 = this.GetNextCoordinate( message.substring( nextStart ) ); nextComma = this.NextComma( message.substring( nextStart ) ); nextStart = nextStart + nextComma + 1; color = this.GetColor( message.substring( nextStart ) ); } else { loop = this.GetNextCoordinate( message.substring( 1 ) ); nextComma = this.NextComma( message.substring( 0 ) ); nextStart = nextComma + 1; } switch( firstChar ) { case 'L': // line line l = new line( x1, y1, x2, y2, color ); items.addElement( l ); backupMode = "D"; break; case 'R': // rectangle rect r = new rect( x1, y1, x2, y2, color ); items.addElement( r ); backupMode = "D"; break; case 'C': // circle circle c = new circle( x1, y1, x2, y2, color ); items.addElement( c ); backupMode = "D"; break; case 'O': // oval oval o = new oval( x1, y1, x2, y2, color ); items.addElement( o ); backupMode = "D"; break; case 'Q': contline cl = new contline( x1, y1, 0, 0, color); while (loop > 0) { x = this.GetNextCoordinate( message.substring( nextStart ) ); nextComma = this.NextComma( message.substring( nextStart ) ); nextStart = nextStart + nextComma + 1; y = this.GetNextCoordinate( message.substring( nextStart ) ); nextComma = this.NextComma( message.substring( nextStart ) ); nextStart = nextStart + nextComma + 1; cl.storePoint(x,y); cl.setX2(x); cl.setY2(y); loop--; } color = this.GetColor( message.substring( nextStart ) ); cl.setColor( color ); items.addElement( cl ); backupMode = "D"; break; } this.repaint(); } public void CutObject( String message ) { int x1, y1, x2, y2, nextComma = 0, nextStart = 0; Color color; obj Mv1=null, Mv2=null; Point last_point = new Point(0,0); Graphics g; // get Graphics Context g = getGraphics(); x1 = this.GetNextCoordinate( message.substring( 0 ) ); nextComma = this.NextComma( message.substring( 0 ) ); nextStart = nextComma + 1; y1 = this.GetNextCoordinate( message.substring( nextStart ) ); nextComma = this.NextComma( message.substring( nextStart ) ); Mv1 = findObject(x1,y1); backupX1 = Mv1.getX1(); backupY1 = Mv1.getY1(); backupX2 = Mv1.getX2(); backupY2 = Mv1.getY2(); backupObj = (obj) Mv1.Assign(getColor()); backupMode = "C"; if (Mv1.type.equals("Contline")) { backupPoints.removeAllElements(); int i; for (i=0;i< backupObj.pts.size();i++) { backupPoints.addElement(backupObj.pts.elementAt(i)); } last_point = (Point) Mv1.pts.elementAt((Mv1.pts.size()-1)); backupObj.setX2(last_point.x); backupObj.setY2(last_point.y); } Mv1.erase( g, this ); items.removeElement( Mv1 ); } public void CopyObject( String message ) { int x1, y1, x2, y2, nextComma = 0, nextStart = 0; Color color; obj Mv1=null, Mv2=null; Point last_point = new Point(0,0); Graphics g; // get Graphics Context g = getGraphics(); x1 = this.GetNextCoordinate( message.substring( 0 ) ); nextComma = this.NextComma( message.substring( 0 ) ); nextStart = nextComma + 1; y1 = this.GetNextCoordinate( message.substring( nextStart ) ); nextComma = this.NextComma( message.substring( nextStart ) ); nextStart = nextStart + nextComma + 1; x2 = this.GetNextCoordinate( message.substring( nextStart ) ); nextComma = this.NextComma( message.substring( nextStart ) ); nextStart = nextStart + nextComma + 1; y2 = this.GetNextCoordinate( message.substring( nextStart ) ); nextComma = this.NextComma( message.substring( nextStart ) ); nextStart = nextStart + nextComma + 1; color = this.GetColor( message.substring( nextStart ) ); Mv1 = findObject(x1,y1); backupX1 = Mv1.getX1(); backupY1 = Mv1.getY1(); backupX2 = Mv1.getX2(); backupY2 = Mv1.getY2(); backupObj = (obj) Mv1.Assign(getColor()); Mv2 = (obj) Mv1.Assign(getColor()); backupMode = "D"; int firstX = x1, firstY = y1; if (Mv2.type.equals("Contline")) { backupPoints.removeAllElements(); int i; for (i=0;i< backupObj.pts.size();i++) { backupPoints.addElement(backupObj.pts.elementAt(i)); } Mv2.rePosition(firstX, firstY, x2, y2); last_point = (Point) Mv2.pts.elementAt((Mv2.pts.size()-1)); backupObj.setX2(last_point.x); backupObj.setY2(last_point.y); } else { if( x2 < firstX ) { Mv2.setX1( Mv2.getX1() - ( firstX - x2 ) ); Mv2.setX2( Mv2.getX2() - ( firstX - x2 ) ); } if( x2 > firstX ) { Mv2.setX1( Mv2.getX1() + ( x2 - firstX ) ); Mv2.setX2( Mv2.getX2() + ( x2 - firstX ) ); } if( y2 < firstY ) { Mv2.setY1( Mv2.getY1() - ( firstY - y2 ) ); Mv2.setY2( Mv2.getY2() - ( firstY - y2 ) ); } if( y2 > firstY ) { Mv2.setY1( Mv2.getY1() + ( y2 - firstY ) ); Mv2.setY2( Mv2.getY2() + ( y2 - firstY ) ); } } Mv2.setColor( color ); Mv2.draw(g); items.addElement( Mv2 ); this.repaint(); } public void MoveObject( String message ) { int x1, y1, x2, y2, nextComma = 0, nextStart = 0; Color color; obj Mv1=null, Mv2=null; Point last_point = new Point(0,0); Graphics g; // get Graphics Context g = getGraphics(); x1 = this.GetNextCoordinate( message.substring( 0 ) ); nextComma = this.NextComma( message.substring( 0 ) ); nextStart = nextComma + 1; y1 = this.GetNextCoordinate( message.substring( nextStart ) ); nextComma = this.NextComma( message.substring( nextStart ) ); nextStart = nextStart + nextComma + 1; x2 = this.GetNextCoordinate( message.substring( nextStart ) ); nextComma = this.NextComma( message.substring( nextStart ) ); nextStart = nextStart + nextComma + 1; y2 = this.GetNextCoordinate( message.substring( nextStart ) ); nextComma = this.NextComma( message.substring( nextStart ) ); nextStart = nextStart + nextComma + 1; color = this.GetColor( message.substring( nextStart ) ); Mv1 = findObject(x1,y1); backupX1 = Mv1.getX1(); backupY1 = Mv1.getY1(); backupX2 = Mv1.getX2(); backupY2 = Mv1.getY2(); backupObj = (obj) Mv1.Assign(getColor()); backupMode = "M"; int firstX = x1, firstY = y1; if (Mv1.type.equals("Contline")) { Mv1.erase(g, this); backupPoints.removeAllElements(); int i; for (i=0;i< backupObj.pts.size();i++) { backupPoints.addElement(backupObj.pts.elementAt(i)); } Mv1.rePosition(firstX, firstY, x2, y2); last_point = (Point) Mv1.pts.elementAt((Mv1.pts.size()-1)); backupObj.setX2(last_point.x); backupObj.setY2(last_point.y); } else { if (Mv1 != null) { Mv1.erase(g, this); if( x2 < firstX ) { Mv1.setX1( Mv1.getX1() - ( firstX - x2 ) ); Mv1.setX2( Mv1.getX2() - ( firstX - x2 ) ); } if( x2 > firstX ) { Mv1.setX1( Mv1.getX1() + ( x2 - firstX ) ); Mv1.setX2( Mv1.getX2() + ( x2 - firstX ) ); } if( y2 < firstY ) { Mv1.setY1( Mv1.getY1() - ( firstY - y2 ) ); Mv1.setY2( Mv1.getY2() - ( firstY - y2 ) ); } if( y2 > firstY ) { Mv1.setY1( Mv1.getY1() + ( y2 - firstY ) ); Mv1.setY2( Mv1.getY2() + ( y2 - firstY ) ); } } Mv1.draw(g); } this.repaint(); } // ************** Graham Mehl made changes below this line ****************** /* * This method receives a string as input. This String * is a message that has been determine it contains a * text message that was semt across the network and * must be added to the users white board. */ public void TextObject( String message ) { obj txt=null; Graphics g; // get Graphics Context g = getGraphics(); /* * Prepare the variables of a text object */ int x1, y1, x2, y2; int nextComma = 0, nextStart = 0; char fontSizeChar; int fontSize = 12; Color color; String a_message; char firstChar = message.charAt( 0 ); /* * Peal off the X1 coordinate from the String */ x1 = this.GetNextCoordinate( message.substring( 1 ) ); nextComma = this.NextComma( message.substring( 0 ) ); nextStart = nextComma + 1; /* * Peal off the Y1 coordinate from the String */ y1 = this.GetNextCoordinate( message.substring( nextStart ) ); nextComma = this.NextComma( message.substring( nextStart ) ); nextStart = nextStart + nextComma + 1; /* * Peal off the font size from the String */ fontSize = this.getFontSize( message.substring( nextStart ) ); nextComma = this.NextComma( message.substring( nextStart ) ); nextStart = nextStart + nextComma + 1; /* * Peal off the text message from the String */ a_message = this.getMessage( message.substring( nextStart ) ); nextComma = this.NextComma( message.substring( nextStart ) ); nextStart = nextStart + nextComma + 1; /* * Peal off the X2 coordinate from the String */ x2 = this.GetNextCoordinate( message.substring( nextStart ) ); nextComma = this.NextComma( message.substring( nextStart ) ); nextStart = nextStart + nextComma + 1; /* * Peal off the Y2 coordinate from the String */ y2 = this.GetNextCoordinate( message.substring( nextStart ) ); nextComma = this.NextComma( message.substring( nextStart ) ); nextStart = nextStart + nextComma + 1; /* * Peal off the color of the text from the String */ color = this.GetColor( message.substring( nextStart ) ); switch( firstChar ) { case 'F': // Text textBox text = new textBox( x1, y1, x2, y2, color, fontSize, a_message ); text.setX1(x1); text.setY1(y1); text.setX2(x2); text.setY2(y2); text.setColor(color); items.addElement( text ); break; case 'S': // Update Text message txt = findObject(x1,y1); int firstX = x1, firstY = y1; if (txt != null) { txt.erase(g, this); txt.setX1( x1 ); txt.setX2( x2 ); txt.setY1( y1 ); txt.setY2( y2 ); txt.setFontSize( fontSize ); txt.setMessage( a_message ); txt.setColor( color ); txt.draw(g); } break; default: // error //System.out.println( "Error in text receive\n"); break; } this.repaint(); } // ************** Graham Mehl made changes above this line ****************** public void SendPage( int pageNumber ) { obj item = null; int itemCount = items.size(); itemCount--; while( itemCount >= 0 ) { StringBuffer SendMe = new StringBuffer(); SendMe.append( "IW" ); SendMe.append( pageNumber ); SendMe.append( ":" ); item = ( obj ) items.elementAt( itemCount ); item.getType(); if( item.type.equals( "Text" ) ) { SendMe.append( "T" ); } else { SendMe.append( "D" ); } if( item.type.equals( "Line" ) ) { SendMe.append( "L" ); } if( item.type.equals( "Rect" ) ) { SendMe.append( "R" ); } if( item.type.equals( "Circle" ) ) { SendMe.append( "C" ); } if( item.type.equals( "Oval" ) ) { SendMe.append( "O" ); } if( item.type.equals( "Text" ) ) { SendMe.append( "F" ); } if (item.type.equals("Contline")) { int i; Point send_pt = new Point(0,0); SendMe.append( "Q" ); SendMe.append( item.pts.size() ); SendMe.append( ',' ); for (i=0; i < item.pts.size(); i++) { send_pt = (Point) item.pts.elementAt(i); SendMe.append( send_pt.x ); SendMe.append( ',' ); SendMe.append( send_pt.y ); SendMe.append( ',' ); } } else { SendMe.append( item.getX1() ); SendMe.append( "," ); SendMe.append( item.getY1() ); SendMe.append( "," ); if( item.type.equals( "Text" ) ) { SendMe.append( item.getFontSize() ); SendMe.append( "," ); SendMe.append( item.getMessage() ); SendMe.append( "," ); } SendMe.append( item.getX2() ); SendMe.append( "," ); SendMe.append( item.getY2() ); SendMe.append( "," ); } SendMe.append( this.GetColor( item.getColor() ) ); clientDef.zCommDispatch( "_PM_", SendMe.length(), SendMe.toString() ); itemCount--; } } public void ClearPage() { obj clearMe = null; int itemCount = items.size(); Graphics g; // get Graphics Context g = getGraphics(); itemCount--; while( itemCount >= 0 ) { clearMe = ( obj ) items.elementAt( itemCount ); clearMe.erase( g, this ); items.removeElement( clearMe ); itemCount--; } this.repaint(); g.dispose(); } public void Undo() { // ********************************* Dharma's ************************** obj cc = null; int yy=items.size()-1, index,i; Graphics g; g = getGraphics(); if (backupMode.equals("D")) { cc = ( obj ) items.elementAt( yy ); cc.erase( g, this ); items.removeElement( cc ); } else if (backupMode.equals("C")) { if (backupObj.type.equals("Contline")) { backupObj.pts.removeAllElements(); for (i=0;i < backupPoints.size(); i++) { backupObj.storePoint(backupPoints.elementAt(i)); } Point tp_pt = new Point(0,0); tp_pt = (Point) backupPoints.elementAt(backupPoints.size()-1); backupObj.setX2(tp_pt.x); backupObj.setY2(tp_pt.y); } else { backupObj.setX1(backupX1); backupObj.setY1(backupY1); backupObj.setX2(backupX2); backupObj.setY2(backupY2); } backupObj.draw(g); items.addElement(backupObj); } else if (backupMode.equals("M")) { cc = ( obj ) items.elementAt( findIndex ); cc.erase( g, this ); if (cc.type.equals("Contline")) { Point temp_pt = new Point(0,0); cc.pts.removeAllElements(); for (i=0;i < backupPoints.size(); i++) { temp_pt = (Point) backupPoints.elementAt(i); cc.storePoint(temp_pt.x,temp_pt.y); cc.setX2(temp_pt.x); cc.setY2(temp_pt.y); } } else { cc.setX1(backupX1); cc.setY1(backupY1); cc.setX2(backupX2); cc.setY2(backupY2); } cc.draw(g); } backupMode = "disabled"; } // ************************************* D *****************************8 public void Receive( String message ) { int msgLength = message.length(); switch( message.charAt( 0 ) ) { case 'D': // draw this.DrawObject( message.substring( 1 ) ); break; case 'C': // cut this.CutObject( message.substring( 1 ) ); break; case 'M': // move this.MoveObject( message.substring( 1 ) ); break; case 'P': // copy this.CopyObject( message.substring( 1 ) ); break; case 'T': // text this.TextObject( message.substring( 1 ) ); break; case 'R': // clear this.ClearPage(); break; case 'U': // undo this.Undo(); break; default: // Error break; } } /* * You need to pass the toolKit to the whiteBoard * so that the whiteBoard can call the toolKit's methods */ public whiteBoard( toolKit a_toolKit, CardWindow c, zClientDef commHandler ) { setBackground( Color.white ); Active_Color = Color.black; tk = a_toolKit; clientDef = commHandler; card = c; } private obj findObject( int x, int y ) { int itemCount = 0, itemSize = items.size(); obj temp = null, temp1 = null, temp2 = null; int X1, Y1, X2, Y2 , area; while(itemCount != itemSize) { temp = ( obj ) items.elementAt( itemCount ); findIndex = itemCount; if( temp.isPointIn( x, y ) == true ) { temp1 = temp; for(itemCount++; itemCount != itemSize; itemCount++ ) { X1 = temp.getX1(); Y1 = temp.getY1(); X2 = temp.getX2(); Y2 = temp.getY2(); area = temp.Area(X1,Y1,X2,Y2); temp = ( obj ) items.elementAt( itemCount); if (temp.isPointIn( x,y ) == true) { if (temp.Area(temp.getX1(), temp.getY1(), temp.getX2(),temp.getY2()) <= area) { area = temp.Area(temp.getX1(), temp.getY1(), temp.getX2(),temp.getY2()); temp2 = temp; findIndex = itemCount; } } } if (temp2 != null) return(temp2); else{ return(temp1);} } itemCount++; } return( null ); } /* * this function redraws all the items on the white board */ public void paint( Graphics g ) { int itemCount, itemSize = items.size(); obj temp = null; this.setBackground( Color.white ); for( itemCount = 0; itemCount != itemSize; itemCount++ ) { temp = ( obj ) items.elementAt( itemCount ); temp.draw( g ); } } public boolean handleEvent( Event e ) { obj temp = null; // points to last item in the Vector obj findMe = null; Point last_pt = new Point(0,0); int it; /* * get the position of the last item in the list */ int itemSize = items.size(); /* * since list starts at zero, we need to subtract one */ itemSize--; /* * since you can drag the mouse across the white board * without being in the process of drawing a shape and * this function is called when you drag the mouse, * MOUSE_DRAG, we need to make sure that there are * items in our Vector prior to getting the last item * in the list.... */ if( ( itemSize >= 0 ) && ( ( tk.getMode() != 0 ) || ( tk.getMode() != 10 ) ) ) { /* * create a variable of type object to point * to last item in list */ temp = ( obj ) items.elementAt( itemSize ); } Graphics g; // get Graphics Context g = getGraphics(); switch( e.id ) { case Event.MOUSE_ENTER: show(); switch( tk.getMode() ) { case 0: // lines //setCursor(CROSSHAIR_CURSOR); break; case 1:// rectangle //setCursor(CROSSHAIR_CURSOR); break; case 2:// circle //setCursor(CROSSHAIR_CURSOR); break; case 3:// cut //setCursor(HAND_CURSOR); break; case 4://move //setCursor(MOVE_CURSOR); break; case 5: // text //setCursor(CROSSHAIR_CURSOR); break; default: //setCursor(DEFAULT_CURSOR); break; } break; case Event.WINDOW_EXPOSE: /* * if one window cover our white board and then * is moved, we need to redraw all the items on * the white board */ repaint(); break; // ********************* Dharma's ****************************************** case Event.MOUSE_MOVE: if ((tk.getMode() == 5) && (itemSize >= 0) && (temp.type.equals("Contline")) && (Permit_cont_line == true)) { temp.erase(g, this); temp.setX2( e.x ); temp.setY2( e.y ); temp.draw(g); } break; // ************************ D **************************************** case Event.MOUSE_DOWN: /* * need to add code here to change cursor to across */ // This Dharma's addition **************** START *************** if (itemSize > 0) { for( it = 0; it <= itemSize; it++ ) { temp = ( obj ) items.elementAt(it); if (temp.Select == true) { temp.borderErase(g , this); temp.Select = false; break; } } } findIndex1 = findIndex; findMe = this.findObject( e.x, e.y ); if (findMe != null) { findMe.hilightObject(g); findMe.Select = true; } // This is Dharma's addition *************** END ************************ SendMe = new StringBuffer(); SendMe.append( "W" ); SendMe.append( card.returnpg() ); SendMe.append( ":" ); switch( tk.getMode() ) { case 4: // lines line l = new line( e.x, e.y, e.x, e.y, getColor() ); items.addElement( l ); backupMode = "D"; SendMe.append( "DL" ); SendMe.append( e.x ); SendMe.append( ',' ); SendMe.append( e.y ); SendMe.append( ',' ); break; case 1: // rectangle rect r = new rect( e.x, e.y, e.x, e.y, getColor() ); items.addElement( r ); backupMode = "D"; SendMe.append( "DR" ); SendMe.append( e.x ); SendMe.append( ',' ); SendMe.append( e.y ); SendMe.append( ',' ); break; case 2: // circle circle c = new circle( e.x, e.y, e.x, e.y, getColor() ); items.addElement( c ); backupMode = "D"; SendMe.append( "DC" ); SendMe.append( e.x ); SendMe.append( ',' ); SendMe.append( e.y ); SendMe.append( ',' ); break; case 7: //cut findMe = this.findObject( e.x, e.y ); if( findMe != null ) { backupX1 = findMe.getX1(); backupY1 = findMe.getY1(); backupX2 = findMe.getX2(); backupY2 = findMe.getY2(); backupMode = "C"; backupObj = (obj) findMe.Assign(getColor()); backupObj.setColor( findMe.getColor() ); backupPoints.removeAllElements(); int j; for (j=0;j< backupObj.pts.size();j++) { backupPoints.addElement(backupObj.pts.elementAt(j)); } SendMe.append( "C" ); SendMe.append( e.x ); SendMe.append( ',' ); SendMe.append( e.y ); SendMe.append( ',' ); findMe.erase( g, this ); items.removeElement( findMe ); this.repaint(); } break; case 0: //move findMe = this.findObject( e.x, e.y ); if( findMe != null ) { findMe.Select = true; SendMe.append( "M" ); SendMe.append( e.x ); SendMe.append( ',' ); SendMe.append( e.y ); SendMe.append( ',' ); firstX = e.x; firstY = e.y; moveMe = findMe; backupX1 = findMe.getX1(); backupY1 = findMe.getY1(); backupX2 = findMe.getX2(); backupY2 = findMe.getY2(); backupObj = (obj) findMe.Assign(getColor()); backupPoints.removeAllElements(); int i; for (i=0;i< backupObj.pts.size();i++) { backupPoints.addElement(backupObj.pts.elementAt(i)); } backupMode = "M"; skip = 0; } break; case 9: //text /* * This case sets a default message and adds * it to the list of objects on the white board. */ String tempString; tempString = SendMe.toString(); StringBuffer TextSendMe; TextSendMe = new StringBuffer(tempString); String message; message = " "; textBox text_message = new textBox(e.x, e.y, e.x, e.y, getColor(), 10, message ); text_message.setMessage(); text_message.type = "Text"; TxtWrite messageBoard = new TxtWrite( clientDef, TextSendMe, text_message, this); messageBoard.resize(600,100); messageBoard.setTitle("Message Board"); messageBoard.show(); items.addElement( text_message ); SendMe.append( "TF" ); SendMe.append( e.x ); SendMe.append( ',' ); SendMe.append( e.y ); SendMe.append( ',' ); SendMe.append( "12" ); SendMe.append( ',' ); SendMe.append( message ); SendMe.append( ',' ); break; case 3: // oval oval o = new oval( e.x, e.y, e.x, e.y, getColor() ); items.addElement( o ); SendMe.append( "DO" ); SendMe.append( e.x ); SendMe.append( ',' ); SendMe.append( e.y ); SendMe.append( ',' ); backupMode = "D"; break; case 10: // clear this.ClearPage(); SendMe.append( "R" ); break; case 6: // copy findMe = this.findObject( e.x, e.y ); if( findMe != null ) { firstX = e.x; firstY = e.y; SendMe.append( "P" ); SendMe.append( e.x ); SendMe.append( ',' ); SendMe.append( e.y ); SendMe.append( ',' ); moveMe = findMe.Assign( getColor()); backupMode = "D"; items.addElement(moveMe); skip = 0; stat = true; } break; // ********************* Dharma's addition ******************************** case 5: // contLine firstClick++; if (tk.contVar == 1) { contline ct = new contline( e.x, e.y, e.x, e.y, getColor() ); Cont_line_send = new StringBuffer(); Cont_line_send.append( "W" ); Cont_line_send.append( card.returnpg() ); Cont_line_send.append( ":" ); Cont_line_send.append( "DQ" ); items.addElement(ct); backupPoints.removeAllElements(); tk.contVar = 0; Permit_cont_line = true; } temp = (obj) items.elementAt(items.size() - 1); Permit_cont_line = true; if ( (e.x == prevX) && (e.y == prevY) ) { tk.contVar = 1; Permit_cont_line = false; Cont_line_send.append( GetColor( temp.getColor() ) ); Cont_line_send.insert(5,temp.pts.size()); Cont_line_send.insert(6, ',' ); clientDef.zCommDispatch( "_PM_", Cont_line_send.length(), Cont_line_send.toString() ); break; } else { temp.storePoint(e.x,e.y); Cont_line_send.append( e.x ); Cont_line_send.append( ',' ); Cont_line_send.append( e.y ); Cont_line_send.append( ',' ); Point backPoint = new Point(0,0); backPoint.x = e.x; backPoint.y = e.y; backupPoints.addElement(backPoint); prevX = e.x; prevY=e.y; } backupMode = "D"; break; // ********************************************************************** // ********************************* Dharma's ************************** case 8: // undo this.Undo(); SendMe.append( "U" ); /* obj cc = null; int yy=items.size()-1, index,i; if (backupMode.equals("D")) { cc = ( obj ) items.elementAt( yy ); cc.erase( g, this ); items.removeElement( cc ); } else if (backupMode.equals("C")) { if (backupObj.type.equals("Contline")) { backupObj.pts.removeAllElements(); for (i=0;i < backupPoints.size(); i++) { backupObj.storePoint(backupPoints.elementAt(i)); } Point tp_pt = new Point(0,0); tp_pt = (Point) backupPoints.elementAt(backupPoints.size()-1); backupObj.setX2(tp_pt.x); backupObj.setY2(tp_pt.y); } else { backupObj.setX1(backupX1); backupObj.setY1(backupY1); backupObj.setX2(backupX2); backupObj.setY2(backupY2); } backupObj.draw(g); items.addElement(backupObj); } else if (backupMode.equals("M")) { cc = ( obj ) items.elementAt( findIndex1 ); cc.erase( g, this ); if (cc.type.equals("Contline")) { Point temp_pt = new Point(0,0); cc.pts.removeAllElements(); for (i=0;i < backupPoints.size(); i++) { temp_pt = (Point) backupPoints.elementAt(i); cc.storePoint(temp_pt.x,temp_pt.y); cc.setX2(temp_pt.x); cc.setY2(temp_pt.y); } } else { cc.setX1(backupX1); cc.setY1(backupY1); cc.setX2(backupX2); cc.setY2(backupY2); } cc.draw(g); } */ backupMode = "disabled"; break; // ************************************* D *****************************8 default: System.out.println( "Please click an item from the Tool Kit!!!\n" ); break; } break; case Event.MOUSE_DRAG: /* * Listen carefully, since you can drag the * mouse across the white board without being * in the process of drawing a shape, we need * to make sure that there are items in our * Vector prior to continuing, otherwise we * would try to draw on items in a vector * that don't exist... */ if( itemSize < 0 ) { return( true ); } if( tk.getMode() == 7 ) { return( true ); } if( tk.getMode() == 8 ) { return( true ); } if( ( tk.getMode() == 0 ) && ( moveMe == null ) ) { return( true ); } if( (tk.getMode() != 0)) { temp.erase( g, this ); // erase previous item } switch( tk.getMode() ) { case 0: // move moveMe.erase( g, this ); moveMe.borderErase(g, this); // ***************************** Dharma's ************************************* if (moveMe.type.equals("Contline")) { moveMe.rePosition(firstX, firstY, e.x, e.y); last_pt = (Point) moveMe.pts.elementAt((moveMe.pts.size()-1)); moveMe.setX2(last_pt.x); moveMe.setY2(last_pt.y); } else { // ************************************** D ******************************* if( e.x < firstX ) { moveMe.setX1( moveMe.getX1() - ( firstX - e.x ) ); moveMe.setX2( moveMe.getX2() - ( firstX - e.x ) ); } if( e.x > firstX ) { moveMe.setX1( moveMe.getX1() + ( e.x - firstX ) ); moveMe.setX2( moveMe.getX2() + ( e.x - firstX ) ); } if( e.y < firstY ) { moveMe.setY1( moveMe.getY1() - ( firstY - e.y ) ); moveMe.setY2( moveMe.getY2() - ( firstY - e.y ) ); } if( e.y > firstY ) { moveMe.setY1( moveMe.getY1() + ( e.y - firstY ) ); moveMe.setY2( moveMe.getY2() + ( e.y - firstY ) ); } } moveMe.draw( g ); moveMe.hilightObject( g ); firstX=e.x; firstY=e.y; break; case 6: if (moveMe != null) { Point lt_pt = new Point(0,0); if (stat == false) { moveMe.erase(g,this); } moveMe.erase(g,this); if (moveMe.type.equals("Contline")) { moveMe.rePosition(firstX, firstY, e.x, e.y); lt_pt = (Point) moveMe.pts.elementAt((moveMe.pts.size()-1)); moveMe.setX2(lt_pt.x); moveMe.setY2(lt_pt.y); } else { if( e.x < firstX ) { moveMe.setX1(moveMe.getX1() - (firstX - e.x)); moveMe.setX2( moveMe.getX2() - (firstX - e.x)); } if( e.x > firstX ) { moveMe.setX1( moveMe.getX1() + (e.x - firstX)); moveMe.setX2( moveMe.getX2() + (e.x - firstX)); } if( e.y < firstY ) { moveMe.setY1( moveMe.getY1() - (firstY - e.y)); moveMe.setY2( moveMe.getY2() - (firstY - e.y)); } if( e.y > firstY ) { moveMe.setY1( moveMe.getY1() + (e.y - firstY)); moveMe.setY2( moveMe.getY2() + (e.y - firstY)); } } moveMe.draw( g ); firstX=e.x; firstY=e.y; stat = false; } break; default: temp.setX2( e.x ); temp.setY2( e.y ); break; } if( (tk.getMode() != 0) && (tk.getMode() != 6) ) { temp.draw( g ); // draw } break; case Event.MOUSE_UP: moveMe = null; switch( tk.getMode() ) { case 4: case 1: case 2: case 0: case 6: SendMe.append( e.x ); SendMe.append( ',' ); SendMe.append( e.y ); SendMe.append( ',' ); SendMe.append( GetColor( temp.getColor() ) ); break; // ************** Graham Mehl made changes below this line ****************** case 9: SendMe.append( e.x ); SendMe.append( ',' ); SendMe.append( e.y ); SendMe.append( ',' ); SendMe.append( GetColor( temp.getColor() ) ); // ************** Graham Mehl made changes above this line ****************** break; case 3: SendMe.append( temp.getX2() ); SendMe.append( ',' ); SendMe.append( temp.getY2() ); SendMe.append( ',' ); SendMe.append( GetColor( temp.getColor() ) ); break; } if (tk.getMode() !=5) clientDef.zCommDispatch( "_PM_", SendMe.length(), SendMe.toString() ); /* * Make sure all current object are on the * current whiteboard */ repaint(); break; } /* * free graphics context */ g.dispose(); /* * we return true so that event does not cascade * up the class hierarchy */ return( true ); } }
Written By Graham L. Mehl
Last Modified on April 23, 1996
© Villanova University