/* * Label3D.java */ import java.awt.*; /* 3D Label Object */ public class Label3D extends Canvas3D { String text = null; // Text String int base = 22; // size base (usually the height) int ratio = 2; // ratio = width/height boolean raise = false; // if string is raised (3D) boolean fill = true; // If fill background inside frame /** Initalize a Concave Text Label */ public Label3D(String _text) { setFont(bfont); setForeground(black); text = _text; ratio = (text.length()+1)/2; if ( ratio == 0 ) ratio++; } /** Initialize a Text Label with mode setting */ public Label3D(String _text, int _mode) { this(_text); mode = _mode; } /** Initialize a Text Label with mode/raise seetting */ public Label3D(String _text, int _mode, boolean _raise) { this(_text, _mode); raise = _raise; } /* Base Setting */ public int getBase() { return base;} public void setBase(int _base) { base = _base;} /* Ratio Setting */ public int getRatio() { return ratio;} public void setRatio(int _ratio) { ratio = _ratio;} /* Text Setting */ public String getText() { return text;} public boolean setText(String _text) { if ( text == _text ) return false; text = _text; repaint(); return true; } /* Raise Setting */ public boolean getRaise() { return raise;} public boolean setRaise(boolean _raise) { if ( raise == _raise ) return false; raise = _raise; repaint(); return true; } /* Overwrite the Panel's preferredSize */ public Dimension preferredSize() { return new Dimension(base*ratio, base); } /** Respond to a repaint request */ public void update(Graphics g) { if ( g == null ) return; int w = size().width-d2; int h = size().height-d2; Color color = (fill) ? getBackground() : null; if ( (mode < 0) || (mode != 0) && !getActive() ) { Draw3DRect(g, -depth, color); g.clipRect(depth, depth, w, h); } else if ( mode > 0 ) { Draw3DRect(g, depth, color); g.clipRect(depth, depth, w, h); } else if ( fill ) { g.setColor(color); g.fillRect(0, 0, size().width, size().height); } if ( text == null ) return; FontMetrics fm = g.getFontMetrics(); int x = (size().width-fm.stringWidth(text))/2; int y = (size().height-fm.getFont().getSize())/2; y += fm.getFont().getSize()-fm.getDescent(); if ( getActive() ) { if ( raise ) { g.setColor(ltGray); if ( mode < 0 ) g.drawString(text, x-1, y-1); else if ( mode > 0 ) g.drawString(text, x+1, y+1); } g.setColor(getForeground()); } else g.setColor(Color.blue); g.drawString(text, x, y); } /** Notify Parent the mouseDown Event */ public boolean mouseDown(Event ev, int x, int y) { if ( !getActive() ) return true; Notify(ev, this); return true; } }