| 1 | //  Copyright 2004-2007 Jean-Francois Poilpret | 
| 2 | // | 
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
| 4 | // you may not use this file except in compliance with the License. | 
| 5 | // You may obtain a copy of the License at | 
| 6 | // | 
| 7 | //     http://www.apache.org/licenses/LICENSE-2.0 | 
| 8 | // | 
| 9 | // Unless required by applicable law or agreed to in writing, software | 
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, | 
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
| 12 | // See the License for the specific language governing permissions and | 
| 13 | // limitations under the License. | 
| 14 |   | 
| 15 | package net.sourceforge.hiveboard.view; | 
| 16 |   | 
| 17 | import java.awt.FontMetrics; | 
| 18 | import java.awt.Point; | 
| 19 | import java.awt.Rectangle; | 
| 20 |   | 
| 21 | import javax.swing.JComponent; | 
| 22 | import javax.swing.JTextArea; | 
| 23 |   | 
| 24 | final public class MatteGeometry | 
| 25 | { | 
| 26 |         public MatteGeometry(JComponent pane, FullScreenPrefs prefs, String content) | 
| 27 |         { | 
| 28 |                 FontMetrics metrics = _fontField.getFontMetrics(prefs.getFont()); | 
| 29 |                  | 
| 30 |                 // Calculate limit coordinates of matte | 
| 31 |                 int height = pane.getHeight(); | 
| 32 |                 int y = (int) (prefs.getMatteY() * height); | 
| 33 |                 y = Math.max(y, MIN_MATTE_Y); | 
| 34 |                 y = Math.min(y, height - MATTE_BORDER - metrics.getAscent() - metrics.getDescent()); | 
| 35 |   | 
| 36 |                 _rectangle = new Rectangle(        0,  | 
| 37 |                                                                         y,  | 
| 38 |                                                                         metrics.stringWidth(content) + MATTE_BORDER,  | 
| 39 |                                                                         metrics.getHeight() + MATTE_BORDER); | 
| 40 |   | 
| 41 |                 _textOrigin = y; | 
| 42 |                 _origin = new Point(MATTE_HALF_BORDER, MATTE_HALF_BORDER + metrics.getAscent()); | 
| 43 |         } | 
| 44 |          | 
| 45 |         public Rectangle        getMatteRectangle() | 
| 46 |         { | 
| 47 |                 return _rectangle; | 
| 48 |         } | 
| 49 |          | 
| 50 |         public Point        getMatteTextOrigin() | 
| 51 |         { | 
| 52 |                 return _origin; | 
| 53 |         } | 
| 54 |          | 
| 55 |         public int                getMattePaintOrigin() | 
| 56 |         { | 
| 57 |                 return _textOrigin; | 
| 58 |         } | 
| 59 |          | 
| 60 |         static private final JTextArea        _fontField = new JTextArea(); | 
| 61 |   | 
| 62 |         private Rectangle                                _rectangle; | 
| 63 |         private int                                                _textOrigin; | 
| 64 |         private Point                                        _origin; | 
| 65 |          | 
| 66 |         static private final int                MATTE_BORDER = 8; | 
| 67 |         static private final int                MATTE_HALF_BORDER = MATTE_BORDER / 2; | 
| 68 |         static private final int                MIN_MATTE_Y = 0; | 
| 69 | } |