📄 hint_map.java
字号:
if (szParamValue == null)
return (null);
retArea = new hot_area(szParamValue,this);
if (!retArea.bInitialised)
return (null);
else
return (retArea);
}//HotAreaFromParam()
//----------------------------------------------------------------------------
public boolean mouseUp(Event evt,int x, int y)
// Description
// ===========
// Received whenever the user releases a mouse button
// within the applet. We pass this to all the hot areas.
{
int j = 0;
for (j=1;j<iMaxHotArea;j++)
HotAreas[j].MouseUp(x,y);
return(true);
}
//------------------------------------------------------------------------
public boolean mouseMove(Event evt,int x, int y)
// Description
// ===========
// Received whenever the cursor moves to a new position within the applet.
// We pass this message onto all of the hot-areas, for them to action.
{
bHintVisible = false;
bHintChanged = false;
int j = 0;
for (j=1;j<iMaxHotArea;j++)
HotAreas[j].MouseMove(x,y);
if (!bHintVisible)
setNewHintText(null);
if (bHintChanged )
{
// Copy the static stuff to screen
// Make it invisible temporarily, or CopyOfftoOn will draw in old
// position
bHintVisible = false;
copyOfftoOn();
bHintVisible = true;
//See if there is any text to draw..
if (szHintText != null)
{
// get the dimensions
int w = gcOn.getFontMetrics().stringWidth(szHintText+" ");
int h = gcOn.getFontMetrics().getHeight();
// try and ensure it doesn't go off the edge of applet..
if ((x+w) >= dimOffScreen.width-1)
{
x -= 1+ ((x+w)-dimOffScreen.width);
}
if ((y+h) >= dimOffScreen.height-1)
{
y -= 1+ ((y+h)-dimOffScreen.height);
}
//make sure we're not now off the lh edge...
if (x<0) x=0;
if (y<0) y=0;
// and draw it...
gcOn.setColor(Color.yellow);
gcOn.fillRect(x,y,w,h);
gcOn.setColor(Color.black);
gcOn.drawRect(x,y,w,h);
gcOn.drawString(szHintText,x+2,y+h-2);
// keep a copy of where and when drawn
lx = x;ly=y;lw=w;lh=h;
}
}
return (true);
}//mouseMove()
//-----------------------------------------------------------------------
public boolean mouseExit(Event evt,int x, int y)
{
// set the status bar to empty.
setStatusText("",true);
// set hint to nothing
setNewHintText(null);
//redraw
copyOfftoOn();
return(true);
}
//----------------------------------------------------------------------------
private void maintainOffScreenGC()
// Description
// ===========
// This method ensures that we have a graphics context to an offscreen
// image of the same size as applet window. It should be called whenever
// there is any chance that the on-screen size has changed.
//
{
// get the size of the applet window (may change, in some browswers)
Dimension d = size();
if ((imgStaticOffScreen == null)
||
(d.width != dimOffScreen.width)
||
(d.height != dimOffScreen.height)
||
(gcOff==null))
{
// create an image identical in size
// to the applet window.
imgStaticOffScreen = createImage(d.width, d.height);
// ..and save it's size
dimOffScreen = d;
// ..and get a graphics context to it.
gcOff = imgStaticOffScreen.getGraphics();
// ..fill the background with specified color.
gcOff.setColor(colBackground);
gcOff.fillRect(0, 0, dimOffScreen.width, dimOffScreen.height);
}
}//maintainOffScreenGC()
//----------------------------------------------------------------------------
private void maintainStaticImages()
// Description
// ===========
//
// Will fetch foreground & background images, and place them onto
// the offscreen image. The background image is drawn first, and tiled.
//
// The foreground is drawn second, and is always positioned in the
// top left hand corner of the applet.
{
int iBackWidth, iBackHeight;
//first off all, ensure that graphics contexts are ok and correct size
maintainOffScreenGC();
// only Draw if any images not yet fully retrieved.
if (iOutstandingImageCount != 0)
{
// tile image onto background, if one was specified.
if (bBackgroundOK)
{
// size of Applet Window - should be same as offscreen
Dimension mysize = size();
// check that the background image actually has a width..
if ((iBackWidth = imgBackground.getWidth(this))>0)
{
int bx,by;
// we tile the background with repeated draws, starting top left
// we don't tell applet if this data rrives, as it will overwrite
// foreground if drawn, causing a flicker. I might expect this to
// leave 'half drawn' backgrounds, but it doesn't seem to happen..
if((iBackHeight = imgBackground.getHeight(this))>0)
for (bx=0;bx < mysize.width;bx += iBackWidth)
for (by=0;by < mysize.height;by += iBackHeight)
gcOff.drawImage(imgBackground,bx,by,this);
}
}
else
{
// There is no background image, so fill background with solid color
gcOff.setColor(colBackground);
gcOff.fillRect(0, 0, dimOffScreen.width, dimOffScreen.height);
}
// Now draw the foreground in the top left hand corner..
if (bForegroundOK)
{
gcOff.drawImage(imgForeground,0,0,this);
}
} // done drawing images.
}//maintainStaticImages()
//-----------------------------------------------------------------------
private void copyOfftoOn()
//
// Description
// ===========
//
// Copies the Offscreen copy of the images (should be foreground,background
// and background colour combined) onto the onscreen display.
//
{
gcOn.drawImage(imgStaticOffScreen,0,0,null);
if (bHintVisible && (szHintText != null))
{
gcOn.setColor(Color.yellow);
gcOn.fillRect(lx,ly,lw,lh);
gcOn.setColor(Color.black);
gcOn.drawRect(lx,ly,lw,lh);
gcOn.drawString(szHintText,lx+2,ly+lh-2);
}
} // copyOfftoOn()
//------------------------------------------------------------------------
public boolean imageUpdate(Image img, int flags,
int x, int y, int w, int h)
// Description
// ===========
//
// This function is called whenever more data is recieved for the
// background image being drawn by g.drawImage(Imgbackground,bx,by,this);
//
// All this function does is prevent an auto repaint occuring when
// parts of the image are recieved, thus preventing flicker
{
if ((flags & (ALLBITS)) != 0)
{
//an Image has completed load across net
iOutstandingImageCount--;
// if (img == imgForeground)
// debug("Foreground loaded");
// else
// debug("Background loaded");
// 13-Feb-96/SBH Added repaint() because sometimes background or
// foreground doesn't display, though loaded. This ensures it does,
// though it may mean image appears suddenly rather than smoothly.
repaint();
// If the hint is currently visible, redisplay it onscreen
// Allows for case where mouse moved into a hot area whilst
// images being retrieved.
// if (bHintVisible && (szHintText != null))
// {
// gcOn.setColor(Color.yellow);
// gcOn.fillRect(lx,ly,lw,lh);
// gcOn.setColor(Color.black);
// gcOn.drawRect(lx,ly,lw,lh);
// gcOn.drawString(szHintText,lx+2,ly+lh-2);
// }
return (false);
}
else
{
// we only redraw when forground appears, as otherwise
// the asynchronous arrival of background data means that
// background overwrites foreground momentarily, resulting
// in flicker. Also increases performance not to draw background
// every step of the way.
if (img == imgForeground)
{
// Add newly retrieved data to the offscreen copy
maintainStaticImages();
//and display it
copyOfftoOn();
//if the hint is currently visible, redisplay it onscreen
// if (bHintVisible && (szHintText != null))
// {
// gcOn.setColor(Color.yellow);
// gcOn.fillRect(lx,ly,lw,lh);
// gcOn.setColor(Color.black);
// gcOn.drawRect(lx,ly,lw,lh);
// gcOn.drawString(szHintText,lx+2,ly+lh-2);
// }
}
//continue to give us updates, and stop repaint occurring.
return(true);
}
}
//----------------------------------------------------------------------------
Color getColorFromParam(String szParam,Color col_default)
// Description
// ===========
// Returns a Color based on a Hex triplet specified as a parameter to
// the applet. If the parameter doesn't exist, or doesn't parse
// correctly, we return col_default.
//
// 01-Jan-1996/SBH Created
{
String szColor; // The hex triplet specified as the value in the HTML
int Red,Blue,Green; // Individual RGB values
int offset = 0; // Where to start parsing in szColor
// Is the specified parameter valid?
if((szColor = getParameter(szParam)) == null)
{
//..no, so return the default color immediately
return (col_default);
}
else
{
// Hex triplets optionally start with '#'
// If this is the case with this once, start parsing 1 char in/
if (szColor.startsWith("#"))
{
offset = 1;
}
try
{
Red = Integer.parseInt(szColor.substring(0+offset,2+offset),16);
Green = Integer.parseInt(szColor.substring(2+offset,4+offset),16);
Blue = Integer.parseInt(szColor.substring(4+offset,6+offset),16);
}
catch (Exception e)
{
// any errors, and we return the default color
return (col_default);
}
// otherwise, create a new one, and return it.
return new Color ( Red,Green,Blue);
}
}//getColorFromParam()
//--------------------------------------------------------------------------
public void paint(Graphics g)
{
// debug("Entered paint()");
if (bInitComplete)
{
maintainStaticImages();
copyOfftoOn();
}
}//paint()
//--------------------------------------------------------------------------
public String getAppletInfo()
//Description
//===========
//
// This function is called in appletviewer if the user asks for applet info
// it should provide details of applets origin.
{
return(szVersion);
}//getAppletInfo()
//--------------------------------------------------------------------------
public String[][] getParameterInfo()
//Description
//===========
//
// This function is called in appletviewer if the user asks for applet info
// it should provide details of applets usage (ie, paramters)
{
String pinfo[][] =
{
{"bgcolor", "RGB hex triplet", "Color of background (optional)"},
{"foreground", "URL", "Image to display in foreground."},
{"background", "URL", "Image to tile on background.(optional)"},
{"hot_area<n>","Hot Area", "URL to action, Hint text, comma delimited co-ord list,[frame]"}
};
return (pinfo);
}
//--------------------------------------------------------------------------
public void debug(String szText)
{
System.out.println(szText);
}
//--------------------------------------------------------------------------
public void run()
{
// 22-Feb-1996/SBH Added code to kick a redraw off 0.75 Seconds into load
// because of problem where Netscape, when using frame, sometmes draws
// the background over the applet if it is in the cache and loads before
// the background is here. If this is not the case, an extra draw does no
// harm.
try
{
Thread.currentThread().join(750);
} catch (InterruptedException e){}
{
copyOfftoOn();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -