1 /* CanvasPanel.java 2 * 3 * created: Sat Jun 17 2000 4 * 5 * This file is part of Artemis 6 * 7 * Copyright(C) 2000 Genome Research Limited 8 * 9 * This program is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU General Public License 11 * as published by the Free Software Foundation; either version 2 12 * of the License, or(at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 * 23 * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/CanvasPanel.java,v 1.5 2009-02-06 14:58:40 tjc Exp $ 24 */ 25 26 package uk.ac.sanger.artemis.components; 27 28 import java.awt.BorderLayout; 29 import java.awt.FontMetrics; 30 import javax.swing.JPanel; 31 32 /** 33 * This is a JPanel that contains a JPanel containing a JComponent. Both Panels 34 * have BorderLayout. The JComponent is added at "Center". 35 * 36 * @author Kim Rutherford <kmr@sanger.ac.uk> 37 * @version $Id: CanvasPanel.java,v 1.5 2009-02-06 14:58:40 tjc Exp $ 38 **/ 39 40 abstract public class CanvasPanel extends JPanel 41 { 42 /** The height of the font used in this component. */ 43 private int font_ascent; 44 45 /** descent of the font used in this component. */ 46 private int font_descent; 47 48 /** The (maximum) width of the font used in this component. */ 49 private int font_width; 50 51 /** 52 * Create a new JPanel(mid_panel) and a JComponent. 53 **/ CanvasPanel()54 public CanvasPanel() 55 { 56 setLayout(new BorderLayout()); 57 setFontInfo(); 58 } 59 60 /** 61 * Set font_width and font_ascent from the default font. 62 **/ setFontInfo()63 private void setFontInfo() 64 { 65 FontMetrics fm = getFontMetrics(getFont()); 66 67 // find the width of a wide character 68 font_width = fm.charWidth('M'); 69 font_ascent = fm.getAscent(); 70 font_descent = fm.getDescent(); 71 } 72 73 /** 74 * Return the width of our font, as calculated by setFontInfo(). 75 **/ getFontWidth()76 protected int getFontWidth() 77 { 78 return font_width; 79 } 80 81 /** 82 * Return the ascent(height above the baseline) of our font, as calculated 83 * by setFontInfo(). 84 **/ getFontAscent()85 protected int getFontAscent() 86 { 87 return font_ascent; 88 } 89 90 /** 91 * Return the max ascent(height above the baseline) of our font, as 92 * calculated by setFontInfo(). 93 **/ getFontMaxAscent()94 protected int getFontMaxAscent() 95 { 96 return font_ascent; 97 } 98 99 /** 100 * Return the descent of our font, as calculated by setFontInfo(). 101 **/ getFontDescent()102 protected int getFontDescent() 103 { 104 return font_descent; 105 } 106 107 /** 108 * The max ascent + descent of the default font. 109 **/ getFontHeight()110 protected int getFontHeight() 111 { 112 return getFontMaxAscent() + getFontDescent(); 113 } 114 115 } 116