1 23 24 package com.sun.enterprise.tools.upgrade.gui; 25 26 import java.awt.*; 27 28 public class Header extends Canvas 29 { 30 31 private String headerText; 32 33 public Header() 34 { 35 this(""); 36 } 37 38 public Header(String s) 39 { 40 headerText = null; 41 headerText = s; 42 setForeground(Color.black); 43 try 44 { 45 setFont(new Font("SansSerif", 0, 12)); 46 } 47 catch(Error _ex) { } 48 } 49 50 public Dimension getMinimumSize() 51 { 52 return getPreferredSize(); 53 } 54 55 public Dimension getPreferredSize() 56 { 57 return new Dimension(getSize().width, 22); 58 } 59 60 public String getText() 61 { 62 return headerText; 63 } 64 65 public void paint(Graphics g) 66 { 67 Dimension dimension = getSize(); 68 g.setClip(0, 0, dimension.width, dimension.height); 69 FontMetrics fontmetrics = null; 70 g.setColor(getBackground()); 71 g.fillRect(0, 0, dimension.width + 1, dimension.height + 1); 72 g.setColor(getForeground()); 73 g.setFont(getFont()); 74 fontmetrics = Toolkit.getDefaultToolkit().getFontMetrics(getFont()); 75 int i = (dimension.height - (fontmetrics.getMaxAscent() + fontmetrics.getMaxDescent())) / 2 + fontmetrics.getMaxAscent(); 76 g.drawString(headerText, fontmetrics.stringWidth(""), i); 77 int j = dimension.height - fontmetrics.getMaxDescent() / 2; 78 g.drawLine(0, j, dimension.width, j); 79 } 80 81 public void setText(String s) 82 { 83 headerText = s; 84 repaint(); 85 } 86 } 87 | Popular Tags |