home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / prmjatgt / draw.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  20.0 KB  |  884 lines

  1. import java.awt.*;
  2. import java.util.*;
  3. import java.io.*;
  4.  
  5. /**
  6.  * A class that implements vector drawing
  7.  *
  8.  * @version     1.0 03/24/96
  9.  * @author         Kang, Dae Woong (namu@star.elim.net)
  10.  */
  11.  
  12. class Draw extends Rectangle
  13. {
  14.     int method;
  15.     int content;
  16.     int shape;
  17.     Color color = new Color(0);
  18.     /**
  19.       * parameter saving place
  20.       */
  21.     Vector intParams = null;
  22.  
  23.     double lineAngle = 0;
  24.  
  25.     int fontStyle;
  26.     String fontName = null;
  27.     String text = null;
  28.  
  29.     String urlName = null;
  30.  
  31.     // used OBJECT Drawing
  32.     ObjTank objTank;
  33.  
  34.     ///// used WorkPanel
  35.     static int curMethod;
  36.     static int curShape;
  37.     static int curContent;
  38.     static Color curColor;
  39.  
  40.     static int curFontStyle;
  41.     static String curFontName;
  42.     
  43.     boolean isSelected = false;
  44.  
  45.     /**
  46.      * final variables
  47.      */
  48.     static final int INVALID_PARAM = 0x7FFFFFFF;
  49.     
  50.     //draw method ======================
  51.     static final int LINE = 0;
  52.     static final int RECT = 1;
  53.     static final int ROUND_RECT = 2;
  54.     static final int POLYGON = 3;
  55.     static final int OVAL = 4;
  56.     static final int PIE = 5;
  57.     static final int ARC = 6;
  58.     static final int STRING = 7;
  59.     static final int IMAGE = 8;
  60.     static final int DRAW = 9;
  61.     static final int SELECT = 10;
  62.     static final int ANCHOR = 11;
  63.  
  64.     static final int METHOD_COUNT = 12;
  65.  
  66.     //draw content ======================
  67.     static final int CONTENT_FILL = 0;
  68.     static final int CONTENT_UNFILL = 1;
  69.  
  70.     static final int CONTENT_COUNT = 2;
  71.  
  72.     //draw shape =========================
  73.     static final int SHAPE_PLAIN = 0;
  74.     static final int SHAPE_UP =    1;
  75.     static final int SHAPE_DOWN =  2;
  76.  
  77.     static final int SHAPE_COUNT = 3;
  78.  
  79.     //=====================
  80.     static final int URL_FONT_HEIGHT = 20;
  81.     
  82.     //********** constructor's *********************************
  83.     public Draw(int method, int content, int shape, Color color, int x, int y, int width, int height)
  84.     {
  85.         super(x, y, width, height); 
  86.         this.method = method;
  87.         this.content = content;
  88.         this.shape = shape;
  89.         this.color = new Color(color.hashCode());
  90.     }
  91.     /**
  92.      * used in reading
  93.      */
  94.     public Draw() 
  95.     {
  96.     }
  97.  
  98.     public Draw(int x, int y, int width, int height)
  99.     {
  100.         super(x, y, width, height); 
  101.         this.method = curMethod;
  102.         this.content = curContent;
  103.         this.shape = curShape;
  104.         color = new Color(curColor.hashCode());
  105.     }
  106.  
  107.     public Draw(Draw dd)
  108.     {
  109.         reshape(dd.x, dd.y, dd.width, dd.height); 
  110.  
  111.         method = dd.method;
  112.         shape = dd.shape;
  113.         content = dd.content;
  114.         color = new Color(dd.color.hashCode());
  115.         
  116.         if (dd.hasText())
  117.         {
  118.             fontStyle = dd.fontStyle;
  119.             fontName = new String(dd.fontName);
  120.             text = new String(dd.text);
  121.         }
  122.         if (dd.hasURL())
  123.             urlName = new String(dd.urlName);
  124.  
  125.         if (method == IMAGE || method == DRAW)
  126.         {
  127.             dd.objTank.refContent(this);
  128.             width = dd.width;
  129.             height = dd.height;
  130.         }
  131.         lineAngle = dd.lineAngle;    
  132.         if (dd.intParams != null)
  133.         {
  134.             Enumeration e = dd.intParams.elements();
  135.             while (e.hasMoreElements())
  136.                 addParam( ( (Integer) e.nextElement() ).intValue() );
  137.         }
  138.     }
  139.         
  140.     //********** read/write    *********************************
  141.     public void write(DataOutputStream dos, Vector obj) throws IOException
  142.     {
  143.         
  144.         try 
  145.         {
  146.             dos.writeShort(x);
  147.             dos.writeShort(y);
  148.             dos.writeShort(width);
  149.             dos.writeShort(height);
  150.  
  151.             dos.writeByte(method);
  152.             dos.writeByte(shape);
  153.             dos.writeByte(content);
  154.             dos.writeInt(color.hashCode());
  155.  
  156.             int count = (intParams == null) ? 0 : intParams.size();
  157.             int i = 0;
  158.  
  159.             dos.writeShort(count);
  160.             while (i < count)
  161.             {
  162.                 dos.writeShort(getParam(i));
  163.                 i++;
  164.             }
  165.  
  166.             if (method == STRING)
  167.             {
  168.                 dos.writeInt(fontStyle);                
  169.                 dos.writeByte(fontName.length());
  170.                 dos.writeBytes(fontName);
  171.                 dos.writeByte(text.length());                    
  172.                 dos.writeBytes(text);                
  173.             }
  174.  
  175.             if (method == IMAGE || method == DRAW)
  176.                 dos.writeShort(obj.indexOf(objTank));
  177.  
  178.             if (hasURL())
  179.             {
  180.                 dos.writeByte(urlName.length());
  181.                 dos.writeBytes(urlName);
  182.             }
  183.             else
  184.             {
  185.                 dos.writeByte(0);
  186.             }
  187.         }
  188.         catch (IOException ioe)
  189.             throw ioe;
  190.     }
  191.  
  192.     public void read(DataInputStream dis, Vector obj) throws IOException
  193.     {
  194.         
  195.         try 
  196.         {
  197.             x = dis.readShort();
  198.             y = dis.readShort();
  199.             width = dis.readShort();
  200.             height = dis.readShort();
  201.  
  202.             method = dis.readByte();
  203.             shape = dis.readByte();
  204.             content = dis.readByte();
  205.             color = new Color(dis.readInt());
  206.  
  207.             int count = dis.readShort();
  208.             for (int i = 0; i < count; i++)
  209.                 addParam(dis.readShort() );
  210.  
  211.             if (method == STRING)
  212.             {
  213.                 int len;
  214.                 byte[] buf;
  215.  
  216.                 fontStyle = dis.readInt();                
  217.                 
  218.                 len = dis.readByte();
  219.                 buf = new byte[len];                
  220.                 dis.readFully(buf);
  221.                 fontName = new String(buf, 0);
  222.                             
  223.                 len = dis.readByte();
  224.                 buf = new byte[len];                
  225.                 dis.readFully(buf);
  226.                 text = new String(buf, 0);
  227.             }
  228.  
  229.             if (method == IMAGE || method == DRAW)
  230.             {
  231.                 int index = dis.readShort();
  232.                 if (obj != null)
  233.                 {
  234.                     objTank = (ObjTank) obj.elementAt(index);
  235.                 }
  236.             }
  237.  
  238.             int len;
  239.             len = dis.readByte();
  240.             if (len > 0)
  241.             {
  242.                 byte[] buf = new byte[len];                
  243.                 dis.readFully(buf);
  244.                 urlName = new String(buf, 0);
  245.             }
  246.  
  247.             if (method == LINE)
  248.                 setLineAngle();
  249.  
  250.         }
  251.         catch (IOException ioe)
  252.             throw ioe;
  253.     }
  254.  
  255.     //*****************  parameter function   ********************************
  256.     public int getParaCount()
  257.     {
  258.         return intParams.size();
  259.     }
  260.  
  261.     public void addParam(int p)
  262.     {
  263.         if (intParams == null)
  264.             intParams = new Vector();
  265.         intParams.addElement(new Integer(p));
  266.     }
  267.     public void addParam(int p1, int p2)
  268.     {
  269.         addParam(p1);
  270.         addParam(p2);
  271.     }
  272.     public void addParam(int p1, int p2, int p3, int p4)
  273.     {
  274.         addParam(p1);
  275.         addParam(p2);
  276.         addParam(p3);
  277.         addParam(p4);
  278.     }
  279.  
  280.     /** 
  281.     * index of param
  282.     * if error return INVALID_PARAM
  283.     */
  284.     public int getParam(int i)
  285.     {
  286.         try
  287.         {
  288.             return ((Integer) intParams.elementAt(i)).intValue();
  289.         }
  290.         catch (ArrayIndexOutOfBoundsException e)
  291.         {
  292.             System.err.println("Draw.getParam invalide index :" + i);
  293.             return INVALID_PARAM;
  294.         } 
  295.     }
  296.  
  297.  
  298.     public void setParam(int i, int value)
  299.     {
  300.         try
  301.         {
  302.             intParams.setElementAt(new Integer(value), i);
  303.         }
  304.         catch (ArrayIndexOutOfBoundsException e)
  305.         {
  306.             System.err.println("param set error");
  307.         } 
  308.     }
  309.  
  310.     public void setParam(int i, int value1, int value2)
  311.     {
  312.         setParam(i, value1);
  313.         setParam(i + 1, value2);
  314.     }
  315.  
  316.     //*********************  point function  *********************************
  317.     public Point getCenterPoint() {    return new Point(x + width/2, y + height/2); }
  318.     public int bottom() { return y + height; }
  319.     public int right()  { return x + width; }
  320.  
  321.     public int getPointsCount()
  322.     {
  323.         switch (method)
  324.         {
  325.         case LINE:
  326.         case POLYGON:
  327.             return getParaCount()/2;
  328.         case ROUND_RECT: return 1;
  329.         case PIE:
  330.         case ARC:
  331.             return 2;
  332.         default: return 0;
  333.         }
  334.     }
  335.  
  336.     public Point getPoint(int i)
  337.     {
  338.         switch (method)
  339.         {
  340.         case POLYGON:
  341.         case LINE:
  342.             return new Point(getParam(2*i), getParam(2*i + 1));
  343.         case ROUND_RECT:
  344.             return new Point(x + getParam(0)/2, y + getParam(1)/2);
  345.         case PIE:
  346.         case ARC:
  347.             Point pt = getCenterPoint();
  348.             double a = ((i == 0) ? getParam(0) : getParam(0) + getParam(1)) / 180.0 * Math.PI ;
  349.             return new Point(pt.x + (int)(width/2*Math.cos(a)), pt.y - (int)(height/2*Math.sin(a)));
  350.         default:
  351.             return null;
  352.         }
  353.     }
  354.  
  355.     public void setPoint(int i, int x, int y)
  356.     {
  357.         switch (method)
  358.         {
  359.         case POLYGON:
  360.         case LINE:
  361.             setParam(2*i, x, y);
  362.             break;
  363.         case ROUND_RECT:
  364.             setParam(0, (x - this.x)*2, (y - this.y)*2);
  365.             break;
  366.         case PIE:
  367.         case ARC:
  368.             Point pt = getCenterPoint();
  369.             int   a = (x == pt.x) ? ((y < pt.y) ? 90 : 270) : (int)(Math.atan( (double)(pt.y  - y) / (x - pt.x) ) * 180 / Math.PI);
  370.             if (x < pt.x)
  371.                 a += 180;
  372.             if (a < 0)
  373.                 a += 360;
  374.             if (i == 0)
  375.             {
  376.                 if (getParam(1) + getParam(0) >= a)
  377.                     setParam(0, a, (getParam(1) + getParam(0) - a) % 360);
  378.                 else
  379.                     setParam(0, a, (getParam(1) + getParam(0) - a) + 360);
  380.             }
  381.             else
  382.             {
  383.                 if (a < getParam(0))
  384.                     a += 360;
  385.                 setParam(1, (a - getParam(0)) % 360);    
  386.             }
  387.             break;
  388.         }
  389.     }
  390.  
  391.     public void setLastPoint(int value1, int value2)
  392.     {
  393.         int i = intParams.size() - 2;
  394.         setParam(i, value1);
  395.         setParam(i + 1, value2);
  396.     }
  397.     
  398.     public Polygon getPolygon()
  399.     {
  400.         Polygon plg = new Polygon();
  401.         
  402.         Enumeration e = intParams.elements();
  403.         while (e.hasMoreElements())
  404.             plg.addPoint(((Integer) e.nextElement()).intValue(), ((Integer) e.nextElement()).intValue());
  405.  
  406.         return plg;
  407.     }
  408.  
  409.     //************************************************************************
  410.     public void toggleSelect()
  411.     {
  412.         isSelected = !isSelected;
  413.     }
  414.     public boolean hasText()
  415.     {
  416.         return text != null && text.length() > 0;
  417.     }
  418.     public boolean hasURL()
  419.     {
  420.         return urlName != null && urlName.length() > 0;
  421.     }
  422.  
  423.     public boolean isPointsOnlyType()
  424.     {
  425.         return method == LINE || method == POLYGON;
  426.     }
  427.  
  428.     public boolean isLineType()
  429.     {
  430.         return method == LINE || method == ARC || (method == POLYGON && content == CONTENT_UNFILL);
  431.     }
  432.  
  433.     public boolean is3D()
  434.     {
  435.         return shape != SHAPE_PLAIN;
  436.     }
  437.  
  438.     public boolean isFill()
  439.     {
  440.         return content == CONTENT_FILL;
  441.     }
  442.  
  443.     public boolean isYNearAngle(int i) // is it near y line?
  444.     {
  445.         double angle = (getParam(i + 2) == getParam(i)) ? Math.PI/2 : Math.atan((double)(getParam(i + 3) - getParam(i + 1))/(getParam(i + 2) - getParam(i)));
  446.         return angle > Math.PI/4  || angle < -Math.PI/4;
  447.     }
  448.  
  449.     public boolean isTopLeftAngle(int angle)
  450.     {
  451.         angle %= 360;
  452.         return angle >= 45 && angle < 225;
  453.     }
  454.  
  455.     public void setRect(Rectangle rc)
  456.     {
  457.         x = rc.x;
  458.         y = rc.y;
  459.         width = rc.width;
  460.         height = rc.height;
  461.     }
  462.     public void setRect(int x, int y, int width, int height)
  463.     {
  464.         this.x = x;
  465.         this.y = y;
  466.         this.width = width;
  467.         this.height = height;
  468.     }
  469.  
  470.     public void setLineAngle()
  471.     {
  472.         lineAngle = (getParam(2) == getParam(0)) ? Math.PI/2 : Math.atan((double)(getParam(3) - getParam(1))/(getParam(2) - getParam(0)));
  473.     }
  474.  
  475.  
  476.     public Rectangle getClipRect()
  477.     {
  478.         Rectangle rc = new Rectangle(x, y, width, height);
  479.  
  480.         rc.grow(2, 2);
  481.         if (curMethod == ANCHOR && hasURL())
  482.         {
  483.             FontMetrics fm = WorkPanel.me.getFontMetrics(getURLFont());
  484.             int len = fm.stringWidth(urlName);
  485.             if (rc.width < len)
  486.             {
  487.                 rc.x -= (len - rc.width)/2;
  488.                 rc.width = len;
  489.             }
  490.  
  491.         }
  492.  
  493.         return rc;
  494.     }
  495.  
  496.     public void transelate(int w, int h)
  497.     {
  498.         super.translate(w, h);
  499.         if (isPointsOnlyType())
  500.         {
  501.             int count = getPointsCount();
  502.             for (int i = 0; i < count; i++)
  503.             {
  504.                 Point pt = getPoint(i);
  505.                 setPoint(i, pt.x + w, pt.y + h);
  506.             }
  507.         }
  508.     }
  509.  
  510.     public void move(int xx, int yy)
  511.     {
  512.         int w = xx - x;
  513.         int h = yy - y;
  514.         if (isPointsOnlyType())
  515.         {
  516.             int count = getPointsCount();
  517.             for (int i = 0; i < count; i++)
  518.             {
  519.                 Point pt = getPoint(i);
  520.                 setPoint(i, pt.x + w, pt.y + h);
  521.             }
  522.         }
  523.         super.move(xx, yy);
  524.     }
  525.  
  526.     public void multiply(double w, double h)
  527.     {
  528.         x *= w;
  529.         y *= h;
  530.         width *= w;
  531.         height *= h;
  532.         if (isPointsOnlyType())
  533.         {
  534.             int count = getPointsCount();
  535.             for (int i = 0; i < count; i++)
  536.             {
  537.                 Point pt = getPoint(i);
  538.                 setPoint(i, (int)(pt.x*w), (int)(pt.y*h));
  539.             }
  540.         }
  541.     }
  542.  
  543.     public int getFontSize()
  544.     {
  545.         return height*4/5;
  546.     }
  547.  
  548.  
  549.     public Font getURLFont()
  550.     {
  551.         return new Font("Dialog", Font.PLAIN, URL_FONT_HEIGHT*3/4);
  552.     }
  553.  
  554.  
  555.     public void drawAngleLine(Graphics g, int angle)
  556.     {
  557.         Point pt = getCenterPoint();
  558.         double a = angle / 180.0 * Math.PI;
  559.         
  560.         g.drawLine(pt.x, pt.y, pt.x + (int)(width/2*Math.cos(a)), pt.y - (int)(height/2*Math.sin(a)));
  561.     }
  562.  
  563.     public void draw(Graphics g)
  564.     {
  565.         Color clrTopLeft = null, clrBottomRight = null;
  566.  
  567.         if (shape == SHAPE_UP)
  568.         {
  569.             clrTopLeft = color.brighter();
  570.             clrBottomRight = color.darker();
  571.         }
  572.         else if (shape == SHAPE_DOWN)
  573.         {
  574.             clrTopLeft = color.darker();
  575.             clrBottomRight = color.brighter();
  576.         }
  577.  
  578.         switch (method)
  579.         {
  580.         case LINE:
  581.             g.setColor(color);
  582.             g.drawLine(getParam(0), getParam(1), getParam(2), getParam(3));
  583.             if (is3D())
  584.             {
  585.                 if (lineAngle > Math.PI / 4 || lineAngle < -Math.PI / 4)
  586.                 {
  587.                     g.setColor(clrTopLeft);
  588.                     g.drawLine(getParam(0) - 1, getParam(1), getParam(2) - 1, getParam(3));
  589.                     g.setColor(clrBottomRight);
  590.                     g.drawLine(getParam(0) + 1, getParam(1), getParam(2) + 1, getParam(3));
  591.                 }
  592.                 else
  593.                 {
  594.                     g.setColor(clrTopLeft);
  595.                     g.drawLine(getParam(0), getParam(1) - 1, getParam(2), getParam(3) - 1);
  596.                     g.setColor(clrBottomRight);
  597.                     g.drawLine(getParam(0), getParam(1) + 1, getParam(2), getParam(3) + 1);
  598.                 }
  599.             }
  600.             break;
  601.         case RECT:
  602.             g.setColor(color);
  603.             if (isFill())
  604.             {
  605.                 g.fillRect(x, y, width, height);
  606.             }
  607.             switch (shape)
  608.             {
  609.             case SHAPE_PLAIN:
  610.                 if (!isFill())
  611.                     g.drawRect(x, y, width, height);
  612.                 break;
  613.             case SHAPE_UP:
  614.                 g.draw3DRect(x, y, width, height, true);
  615.                 break;
  616.             case SHAPE_DOWN:
  617.                 g.draw3DRect(x, y, width, height, false);
  618.                 break;
  619.             }
  620.             break;
  621.         case ROUND_RECT:
  622.             if (isFill())
  623.             {
  624.                 g.setColor(color);
  625.                 g.fillRoundRect(x, y, width, height, getParam(0), getParam(1));
  626.             }
  627.  
  628.             if (is3D())
  629.             {
  630.                 Rectangle rcCorner = new Rectangle(x, y + height - getParam(1), getParam(0), getParam(1));
  631.                                      // bottom left corner
  632.                 int wid = rcCorner.width/2;
  633.                 int hgt = rcCorner.height/2;
  634.                 
  635.                 g.setColor(clrBottomRight);
  636.                 g.drawArc(rcCorner.x, rcCorner.y, rcCorner.width, rcCorner.height, 225, 45);
  637.                 g.setColor(clrTopLeft);
  638.                 g.drawArc(rcCorner.x, rcCorner.y, rcCorner.width, rcCorner.height, 180, 45); 
  639.  
  640.                 g.drawLine(x, bottom() - hgt, x, y + hgt); // left line
  641.                 
  642.                 g.drawArc(x, y, rcCorner.width, rcCorner.height, 90, 90); // top left corner
  643.                 
  644.                 // top right corner
  645.                 rcCorner.move(right() - rcCorner.width, y); 
  646.                 g.drawLine(x + wid, y, right() - wid, y); // top line
  647.                 g.drawArc(rcCorner.x, rcCorner.y, rcCorner.width, rcCorner.height, 45, 45); 
  648.                 g.setColor(clrBottomRight);
  649.                 g.drawArc(rcCorner.x, rcCorner.y, rcCorner.width, rcCorner.height,  0, 45); 
  650.                 
  651.                 // bottom right corner 
  652.                 g.drawLine(right(), y + hgt, right(), bottom() - hgt); // right line
  653.                 g.drawArc(right() - rcCorner.width, bottom() - rcCorner.height, rcCorner.width, rcCorner.height, 270, 90); // bottom right corner
  654.  
  655.                 g.drawLine(right() - rcCorner.width/2, bottom(), x + rcCorner.width/2, bottom()); // bottom line
  656.             }
  657.             else
  658.             {
  659.                 if (!isFill())
  660.                 {
  661.                     g.setColor(color);
  662.                     g.drawRoundRect(x, y, width, height, getParam(0), getParam(1));
  663.                 }
  664.             }
  665.             break;
  666.         case POLYGON:
  667.             if (isFill())
  668.             {
  669.                 g.setColor(color);
  670.                 if (getPointsCount() > 2)
  671.                     g.fillPolygon(getPolygon());
  672.                 else
  673.                     g.drawPolygon(getPolygon());
  674.                 if (is3D())
  675.                 {
  676.                     int count = getParaCount() - 2;
  677.                     int i = 0;
  678.                     while (i < count)
  679.                     {
  680.                         g.setColor
  681.                         (
  682.                           (  
  683.                               (getParam(i + 3) >  getParam(i + 1)) ||
  684.                             ( (getParam(i + 3) == getParam(i + 1)) && (getParam(i + 2) < getParam(i)) )
  685.                           )    ? clrBottomRight : clrTopLeft
  686.                         );
  687.                         g.drawLine(getParam(i), getParam(i + 1), getParam(i + 2), getParam(i + 3));
  688.                         i += 2;
  689.                     }
  690.                     //close line
  691.                     g.setColor
  692.                     (
  693.                       (  
  694.                           (getParam(1) >  getParam(i + 1)) ||
  695.                         ( (getParam(1) == getParam(i + 1)) && (getParam(0) < getParam(i)) )
  696.                       )    ? clrBottomRight : clrTopLeft
  697.                     );
  698.                     g.drawLine(getParam(i), getParam(i + 1), getParam(0), getParam(1));
  699.                 }
  700.             }
  701.             else
  702.             {
  703.                 if (is3D())
  704.                 {
  705.                     int count = getParaCount() - 2;
  706.                     int i = 0;
  707.                     while (i < count)
  708.                     {
  709.                         if (isYNearAngle(i))
  710.                         {
  711.                             g.setColor(clrTopLeft);
  712.                             g.drawLine(getParam(i) - 1, getParam(i + 1), getParam(i + 2) - 1, getParam(i + 3));
  713.                             g.setColor(clrBottomRight);
  714.                             g.drawLine(getParam(i) + 1, getParam(i + 1), getParam(i + 2) + 1, getParam(i + 3));
  715.                         }
  716.                         else
  717.                         {
  718.                             g.setColor(clrTopLeft);
  719.                             g.drawLine(getParam(i), getParam(i + 1) - 1, getParam(i + 2), getParam(i + 3) - 1);
  720.                             g.setColor(clrBottomRight);
  721.                             g.drawLine(getParam(i), getParam(i + 1) + 1, getParam(i + 2), getParam(i + 3) + 1);
  722.                         }
  723.                         i += 2;
  724.                     }
  725.                 }
  726.                 g.setColor(color);
  727.                 g.drawPolygon(getPolygon());
  728.             }
  729.             break;
  730.         case OVAL:
  731.             if (isFill())
  732.             {
  733.                 g.setColor(color);
  734.                 g.fillOval(x, y, width, height);
  735.             }
  736.  
  737.             if (is3D())
  738.             {
  739.                 g.setColor(clrTopLeft);
  740.                 g.drawArc(x, y, width, height, 45, 180);
  741.                 g.setColor(clrBottomRight);
  742.                 g.drawArc(x, y, width, height, 225, 180);
  743.             }
  744.             else
  745.             {
  746.                 if (!isFill())
  747.                 {
  748.                     g.setColor(color);
  749.                     g.drawOval(x, y, width, height);
  750.                 }
  751.             }
  752.             break;
  753.         case PIE:
  754.             if (isFill())
  755.             {
  756.                 g.setColor(color);
  757.                 g.fillArc(x, y, width, height, getParam(0), getParam(1));
  758.             }
  759.             if (is3D())
  760.             {
  761.                 int[] angleSep = { 45, 225, 405, 585, 765};
  762.                 int angleCur = getParam(0);
  763.                 int angleEnd = angleCur + getParam(1);
  764.                 int angleSize = 0;
  765.                 int i = (angleCur + 135) / 180;
  766.  
  767.                 // start line
  768.                 g.setColor( isTopLeftAngle(angleCur + 90) ? clrBottomRight : clrTopLeft);
  769.                 drawAngleLine(g, getParam(0));
  770.  
  771.                 while (angleCur < angleEnd)
  772.                 {
  773.                     angleSize = ((angleSep[i] >= angleEnd) ? angleEnd : angleSep[i]) - angleCur;
  774.  
  775.                     g.setColor( isTopLeftAngle(angleCur) ? clrTopLeft : clrBottomRight);
  776.                     g.drawArc(x, y, width, height, angleCur, angleSize);
  777.  
  778.                     angleCur = angleSep[i++];
  779.                 }
  780.  
  781.                 // end line
  782.                 g.setColor( isTopLeftAngle(getParam(0) + getParam(1) + 90) ? clrTopLeft : clrBottomRight);
  783.                 drawAngleLine(g, getParam(0) + getParam(1));
  784.  
  785.             }
  786.             else
  787.             {
  788.                 if (!isFill())
  789.                 {
  790.                     g.setColor(color);
  791.                     g.drawArc(x, y, width, height, getParam(0), getParam(1));
  792.                     drawAngleLine(g, getParam(0));
  793.                     drawAngleLine(g, getParam(0) + getParam(1));
  794.                 }
  795.             }
  796.  
  797.             break;
  798.         case ARC:
  799.             g.setColor(color);
  800.             g.drawArc(x, y, width, height, getParam(0), getParam(1));
  801.             if (is3D())
  802.             {
  803.                 int[] angleSep = { 45, 225, 405, 585, 765};
  804.                 int angleCur = getParam(0);
  805.                 int angleEnd = angleCur + getParam(1);
  806.                 int angleSize = 0;
  807.                 int i = (angleCur + 135) / 180;
  808.  
  809.                 while (angleCur < angleEnd)
  810.                 {
  811.                     angleSize = ((angleSep[i] >= angleEnd) ? angleEnd : angleSep[i]) - angleCur;
  812.  
  813.                     if ((angleCur % 360) >= 45 && (angleCur % 360) <  225)
  814.                     {
  815.                         g.setColor(clrTopLeft);
  816.                         g.drawArc(x - 1, y - 1, width + 2, height + 2, angleCur, angleSize);
  817.                         g.setColor(clrBottomRight);
  818.                         g.drawArc(x + 1, y + 1, width - 2, height - 2, angleCur, angleSize);
  819.                     }
  820.                     else
  821.                     {
  822.                         g.setColor(clrBottomRight);
  823.                         g.drawArc(x - 1, y - 1, width + 2, height + 2, angleCur, angleSize);
  824.                         g.setColor(clrTopLeft);
  825.                         g.drawArc(x + 1, y + 1, width - 2, height - 2, angleCur, angleSize);
  826.                     }
  827.                     
  828.                     angleCur = angleSep[i++];
  829.                 }
  830.             }
  831.             break;
  832.         case STRING:
  833.             if (hasText())
  834.             {
  835.                 g.setFont( new Font(fontName, fontStyle, getFontSize()) );
  836.                 if (is3D())
  837.                 {
  838.                     g.setColor(clrTopLeft);
  839.                     g.drawString(text, x - 1, y + getFontSize() - 1);
  840.                     g.setColor(clrBottomRight);
  841.                     g.drawString(text, x + 1, y + getFontSize() + 1);
  842.                 }
  843.                 g.setColor(color);
  844.                 g.drawString(text, x, y + getFontSize());
  845.  
  846.             }
  847.             break;
  848.         case IMAGE:
  849.             if (objTank.image != null)
  850.                 g.drawImage(objTank.image, x, y, WorkPanel.me);
  851.             break;
  852.         case DRAW:
  853.             if (objTank.obj != null)
  854.             {
  855.                 Enumeration enum = objTank.obj.elements();
  856.  
  857.                 while (enum.hasMoreElements())
  858.                 {
  859.                     Draw dd = (Draw) enum.nextElement();
  860.                     Draw clone = new Draw(dd);
  861.                     clone.multiply((double)width/objTank.dim.width, (double)height/objTank.dim.height);
  862.                     clone.transelate(x, y);
  863.                     clone.draw(g);
  864.                 }
  865.             }
  866.             break;
  867.         }
  868.         
  869.         if (curMethod == ANCHOR && hasURL())
  870.         { // draw urlName
  871.             g.setFont( getURLFont() ); 
  872.  
  873.             int swidth = g.getFontMetrics().stringWidth(urlName);
  874.             int sx = x + (width - swidth) / 2;
  875.             int sy = y + (height - URL_FONT_HEIGHT)/2;
  876.  
  877.             g.setColor(Color.white);
  878.             g.fillRect(sx, sy, swidth, URL_FONT_HEIGHT);
  879.             g.setColor(Color.blue);
  880.             g.drawString(urlName, sx, sy + URL_FONT_HEIGHT*3/4);
  881.         }
  882.     }
  883. }
  884.