?? book.java
字號:
package ru.sakva.bsh;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
/** Book Object to be displayed on Shelf Applet */
public class Book
implements ImageObserver
/* * */ { /* * */
static int hmin=12;
static int hmax=0;
static int volume=16384;
static public int width=25;
static public int height=100;
static public int thickness=16;
static public Color defaultCoverColor = new Color(0x000080);
static public Color defaultTitleColor = new Color(0xFFC040);
/** Book is selected */
public boolean selected;
/** Color of cover */
public Color coverColor;
/** Color of title */
public Color titleColor;
/** Picture on cover */
public Image icon;
/** length of book */
public int a;
/** height of book */
public int b;
/** thickness of book */
public int c;
/** x-coordinate of book */
public int u;
/** y-coordinate of book */
public int v;
/** title of book */
String title;
public static void setMinimum(int a){ hmin = a; }
public static void setMaximum(int a){ hmax = a; }
public Book()
{
a=width; b=height; c=thickness; title="";
coverColor = defaultCoverColor;
titleColor = defaultTitleColor;
}
public Book(String s){ this(); setTitle(s); }
public Book(String s,int vol){ this(s); setVolume(vol); }
static Font[] font = new Font[12];
static FontMetrics[] fontMetrics = new FontMetrics[12];
static
{ // prepare Fonts
int i=0; while(i < 12)
{
font[i]=new Font("serif",1,2*i+8);
fontMetrics[i]=Toolkit.getDefaultToolkit().getFontMetrics(font[i]);
i++;
}
}
/** Sets volume of the book */
public void setVolume(int vol)
{
c=(int)((float)vol/volume*(hmin-2)+2);
if(c < hmin)c=hmin;
else { if(hmax != 0){ if(c > hmax)c=hmax; } else if(c > b)c=b; }
}
public void setTitle(String s){ title = new String(s); }
public void setReference(String s){ }
public void setIcon(Image im){ icon=im; }
public String getAuthor(){ return ""; }
public String getTitle(){ return title; }
/*
public int getWidth(){ return w; }
public int getHeight(){ return h; }
public int getLength(){ return l; }
*/
public void drawTitle(Graphics g,int u,int v,int icw)
{
int i,j,k,n,f,fh,l;
String s1,s2,s;
n = title.length();
if(n > 0)
{
k = title.indexOf(';');
if(k < 0){ s1=" "+title+" "; s2=null; }
else { s1 = " "+title.substring(0,k); s2 = " "+title.substring(k+1,n)+" "; }
fh = c; s=s1;
if(s2 != null)
{
fh/=2;
if(fontMetrics[0].stringWidth(s1) < fontMetrics[0].stringWidth(s2))s=s2;
}
if(fh > 30)fh=30; f = fh/2-4; l=0;
k=b-icw;
while(f >= 0)
{ if((l=fontMetrics[f].stringWidth(s)) < k)break; f--; fh-=2; }
if(f >= 0)
{
g.setFont(font[f]);
if(s2 == null)g.drawString(s1,(k-l)/2+u,v+(c+fh)/2-2);
else
{
i=u+(k-l)/2;
g.drawString(s1,i,v+c/2-2);
g.drawString(s2,i,v+c/2+fh-3);
}
}
}
}
// Draw vertical book
void drawVertical(Graphics g)
{
int i,j,k,l,f,fh;
String s0;
int[] p = new int[4];
int[] q = new int[4];
p[0]=u; p[1]=u+a; p[2]=p[1]; p[3]=u;
q[0]=v; q[1]=v-a; q[2]=q[1]+b; q[3]=v+b;
g.setColor(coverColor); g.fillPolygon(p,q,4);
g.setColor(Color.black); g.drawPolygon(p,q,4);
i=u+3; while(i < u+c-2)
{
g.setColor(Color.white);
g.drawLine(i,v,i+a-3,v-a+3); i++;
g.setColor(Color.black);
g.drawLine(i,v,i+a-3,v-a+3); i++;
}
if(icon != null)g.drawImage(icon,u,v,c,b,this);
else { g.setColor(coverColor); g.fillRect(u,v,c,b); }
g.setColor(Color.black); g.drawRect(u,v,c,b);
p[0]=u+c; p[1]=u+c+a; p[2]=p[1]; p[3]=p[0];
q[0]=v; q[1]=v-a; q[2]=q[1]+b; q[3]=v+b;
g.setColor(coverColor); g.fillPolygon(p,q,4);
g.setColor(Color.black); g.drawPolygon(p,q,4);
}
// Draw horisontal book
void drawHorisontal(Graphics g)
{
int i,j,k,l0,f,fh,iw,ih;
String s0;
int[] p = new int[4];
int[] q = new int[4];
p[0]=u; p[1]=u+b; p[2]=p[1]+a; p[3]=u+a; q[0]=q[1]=v+c; q[2]=q[3]=q[1]-a;
g.setColor(coverColor); g.fillPolygon(p,q,4);
g.setColor(Color.black); g.drawPolygon(p,q,4);
i=v; while(i < v+c-2)
{
g.setColor(Color.white);
g.drawLine(u+b,i,u+b+a-3,i-a+3); i++;
g.setColor(Color.black);
g.drawLine(u+b,i,u+b+a-3,i-a+3); i++;
}
p[0]=u; p[1]=u+b; p[2]=p[1]+a; p[3]=u+a; q[0]=q[1]=v; q[2]=q[3]=v-a;
g.setColor(coverColor); g.fillPolygon(p,q,4);
g.setColor(coverColor); g.fillRect(u,v,b,c);
k=0;
if(icon != null)
{
iw=icon.getWidth(this); ih=icon.getHeight(this);
k=(int)((float)iw/ih*c);
g.setColor(Color.black);
g.drawImage(icon,u+b-k,v,k,c,this);
g.setColor(coverColor); g.drawPolygon(p,q,4);
g.setColor(Color.black); g.drawRect(u,v,b,c);
}
g.setColor(Color.black); g.drawRect(u,v,b,c); g.drawPolygon(p,q,4);
g.setColor(titleColor);
drawTitle(g,u,v,k);
}
public boolean imageUpdate(Image img,int s,int x,int y,int w,int h)
{
if( (s & ALLBITS) == ALLBITS)
{
synchronized(this){ notify(); }
return false;
}
else if( (s & (ABORT|ERROR))!=0)
{
synchronized(this){ notify();}
return false;
}
else return true;
}
/* * */ } /* * */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -