/* * Canvas3D.java */ import java.awt.*; /* 3D Canvas */ public class Canvas3D extends Canvas implements Setting { static int cx, cy; static long timeDrag = 0, lastDrag = 0; boolean active = true; int mode = -1; // -1: concave, 1: convex, 0: flat. /** Initialize a Concave 3D Canvas */ public Canvas3D() { setBackground(gray);} /** Initalize a Blank 3D Canvas with mode setting */ public Canvas3D(int _mode) { this(); mode = _mode;} /** Insets setting */ public Insets insets() { return insets;} /* Mode Setting */ public int getMode() { return mode;} public boolean setMode(int _mode) { if ( mode == _mode ) return false; mode = _mode; repaint(); return true; } /* Active Setting */ public boolean getActive() { return active;} public boolean setActive(boolean _active) { if ( active == _active ) return false; active = _active; repaint(); return true; } /* Draw 3D Rect Utility Method */ public void Draw3DRect(Graphics g, int depth, Color color) { Draw3DRect(g, 0, 0, size().width, size().height, depth, color);} static void Draw3DRect(Graphics g, int x, int y, int w, int h, int depth, Color color) { int i; Color LT, RB; if ( depth > 0 ) { LT = ltGray; RB = dkGray; } else { LT = dkGray; RB = ltGray; depth = -depth; } w += x-1; h += y-1; for (i=0; i 0 ) { Draw3DRect(g, depth, null); g.clipRect(depth, depth, w, h); } } /** Notify Parent Object */ public void Notify(Event ev, Object arg) { Component p = getParent(); while ( (p != null) && !p.action(ev, arg) ) p = p.getParent(); } /** Simulate a Delay Mouse Drag Action */ public boolean mouseDrag(Event ev, int x, int y) { if ( ev.key == 0 ) { /* Orginal Message */ cx = x; cy = y; timeDrag = ev.when; ev.key = -1; if ( System.currentTimeMillis() - lastDrag < 100 ) { new Delay(50, ev, this); } else { delayDrag(ev, cx, cy); lastDrag = System.currentTimeMillis(); } } else if ( ev.when == timeDrag ) { delayDrag(ev, cx, cy); lastDrag = System.currentTimeMillis(); } return true; } /** The actual Dealay Mose Drag Action here */ public boolean delayDrag(Event ev, int x, int y) { return true; } }