ptshotspot._java


// Static hotspots in PTViewer

	// Static hotspots in frame
	
	int numshs				= 0;			// Number of static hotspots
	int curshs				= -1;			// Current active static hotspot, if exists, else -1;
	
	int 		shs_x1[];					// coordinates
	int 		shs_x2[];
	int 		shs_y1[];
	int 		shs_y2[];
	String		shs_url[];					// url linked to hotspot
	String		shs_target[];				// target in url, if any
	Object		shs_him[];					// image displayed while mouse is over hotspot
	boolean		shs_active[];				// is mouse over hotspot?
	int			shs_imode[];				// 0 - normal, 1 - popup, 2 - always visible

	Vector		shotspots = null;

void shs_init(){
	shotspots = new Vector();
}

void shs_setup(){
	if( shotspots.size() > 0 ){
		shs_allocate(shotspots.size());
		for(int i=0; i<numshs; i++){
			ParseStaticHotspotLine( (String)shotspots.elementAt(i), i );
		}
	}
}

void shs_allocate(int n){
	try{
		shs_x1  		= new int[n];					
		shs_x2  		= new int[n];	
		shs_y1  		= new int[n];	
		shs_y2  		= new int[n];	
		shs_url  		= new String[n];
		shs_target  	= new String[n];
		shs_him			= new Object[n];
		shs_imode		= new int[n];
		shs_active  	= new boolean[n];
		numshs = n;
	}catch(Exception e){
		numshs = 0;
	}
}

void shs_dispose(){
	int i;
	
	for(i=0; i<numshs; i++){
		if( shs_him[i] != null ){
			shs_him[i] = null;
		}
	}
	numshs = 0;
}


	// Parse one Hotspotdescription line for 
	// Static Hotspot No n
   	void ParseStaticHotspotLine( String s, int n )
   	{
   		int i=0,k,length = s.length();
    	StringBuffer w = new StringBuffer();
   		
   		// Set defaults

		shs_x1[n] 		= 0;					
		shs_x2[n] 		= 0;
		shs_y1[n] 		= 0;
		shs_y2[n] 		= 0;
		shs_url[n] 		= null;
		shs_target[n] 	= null;
		shs_him[n] 		= null;
		shs_imode[n] 	= IMODE_NORMAL;
		shs_active[n]	= false;

   		while(i<length)
   		{
   			switch( s.charAt(i++))
   			{
   				case 'x':i = getNextWord(i,s,w); shs_x1[n] = Integer.parseInt(w.toString());  break;
   				case 'y':i = getNextWord(i,s,w); shs_y1[n] = Integer.parseInt(w.toString());  break;
   				case 'a':i = getNextWord(i,s,w); shs_x2[n] = Integer.parseInt(w.toString());  break;
    			case 'b':i = getNextWord(i,s,w); shs_y2[n] = Integer.parseInt(w.toString());  break;
  				case 'u':i = getNextWord(i,s,w); shs_url[n] = w.toString(); break;
  				case 't':i = getNextWord(i,s,w); shs_target[n] = w.toString(); break;
  				case 'p':shs_imode[n] = IMODE_POPUP; break;	
  				case 'q':shs_imode[n] = IMODE_ALWAYS;break;	
  				case 'i':i = getNextWord(i,s,w);
   						if( w.toString().startsWith("ptviewer:") || w.toString().startsWith("javascript:") ){
   							shs_him[n] = w.toString()  ;
   						}else shs_him[n] = loadImage( w.toString() );
   						break;	
   			}
   		}
   	}
   		
 
final void shs_draw(Graphics g ){
	int i;
 		
	for(i=0; i<numshs; i++){
		if( shs_him[i] != null ){
	    	if( (shs_imode[i] & IMODE_ALWAYS) > 0  
	       		|| (shs_active[i] && (shs_imode[i] & IMODE_POPUP) > 0 ) )
 				if( shs_him[i] instanceof Image )
       					g.drawImage(	(Image)shs_him[i], shs_x1[i], shs_y1[i], this	);
       			if( (shs_him[i] instanceof String) && shs_active[i] )
       				JumpToLink( (String)shs_him[i], null );
       	}
 	}
}

// Return number of static hotspot under x/y coordinate
// or -1, if there is none
final int OverStaticHotspot( int x, int y ){
	int i;
	int result = -1;
		
		
	for( i = 0; i < numshs; i++){
		if( shs_url[i] != null && x >= shs_x1[i] && x <= shs_x2[i] &&
			(( y >= shs_y1[i] && y <= shs_y2[i] ) || ( y >= shs_y2[i] && y <= shs_y1[i] ) )){
			shs_active[i] = true;
			if( i > result ) result = i;
		}else
			shs_active[i] = false;
	}
	return result;
}
	
	



	
	


Back