GNU Classpath (0.95) | |
Frames | No Frames |
1: /* SynthGraphicsUtils.java -- Wrapper for graphics primitives used in Synth 2: Copyright (C) 2006 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: 39: package javax.swing.plaf.synth; 40: 41: import gnu.classpath.NotImplementedException; 42: 43: import java.awt.Component; 44: import java.awt.Dimension; 45: import java.awt.Font; 46: import java.awt.FontMetrics; 47: import java.awt.Graphics; 48: import java.awt.Rectangle; 49: 50: import javax.swing.Icon; 51: import javax.swing.SwingUtilities; 52: 53: /** 54: * Wrapper for graphics primitives used in Synth. 55: * 56: * @author Roman Kennke (kennke@aicas.com) 57: * 58: * @since 1.5 59: */ 60: public class SynthGraphicsUtils 61: 62: { 63: /** 64: * Creates a new <code>SynthGraphicsUtils</code> object. 65: */ 66: public SynthGraphicsUtils() 67: { 68: // Nothing to do here. 69: } 70: 71: /** 72: * Draws a line from (x1,y1) to (x2,y2). 73: * 74: * @param ctx the synth context, identifies the region 75: * @param paintKey identifies the portion of the component to be painted, may 76: * be <code>null</code> 77: * @param g the graphics context to use for painting 78: * @param x1 the x coordinate of the start point 79: * @param y1 the y coordinate of the start point 80: * @param x2 the x coordinate of the end point 81: * @param y2 the y coordinate of the end point 82: */ 83: public void drawLine(SynthContext ctx, Object paintKey, Graphics g, int x1, 84: int y1, int x2, int y2) 85: { 86: // TODO: Correct? 87: g.drawLine(x1, y1, x2, y2); 88: } 89: 90: /** 91: * Lays out a label and (if non-null) an icon. The calculated coordinates are 92: * then stored in <code>viewR</code>, <code>iconR</code> and 93: * <code>textR</code>. 94: * 95: * The alignment and position parameters may be one of the alignment or 96: * position constants defined in {@link javax.swing.SwingConstants}. 97: * 98: * @param ctx the synth context, identifies the current region 99: * @param fm the font metrics to use to fetch the text measures 100: * @param text the text to lay out, may be <code>null</code> 101: * @param icon the icon to lay out, may be <code>null</code> 102: * @param hAlign the horizontal alignment of the label 103: * @param vAlign the vertical alignment of the label 104: * @param hTextPos the horizontal text position 105: * @param vTextPos the vertical text position 106: * @param viewR the view rectangle (return parameter) 107: * @param iconR the icon rectangle (return parameter) 108: * @param textR the text rectangle (return parameter) 109: * @param iconTextGap the gap between text and label 110: * 111: * @return the label text, may be shortened 112: */ 113: public String layoutText(SynthContext ctx, FontMetrics fm, String text, 114: Icon icon, int hAlign, int vAlign, int hTextPos, 115: int vTextPos, Rectangle viewR, Rectangle iconR, 116: Rectangle textR, int iconTextGap) 117: { 118: return SwingUtilities.layoutCompoundLabel(fm, text, icon, vAlign, hAlign, 119: vTextPos, hTextPos, viewR, iconR, 120: textR, iconTextGap); 121: } 122: 123: /** 124: * Returns the width of the string <code>text</code> for the specified font 125: * and font metrics. 126: * 127: * @param ctx identifies the current region 128: * @param font the font 129: * @param fm the font metrics to use 130: * @param text the text to be measured 131: * 132: * @return the width of the string <code>text</code> for the specified font 133: * and font metrics 134: */ 135: public int computeStringWidth(SynthContext ctx, Font font, FontMetrics fm, 136: String text) 137: { 138: return fm.stringWidth(text); 139: } 140: 141: /** 142: * Calculates the minimums size that is needed to render the label with 143: * <code>text</code> and <code>icon</code> correctly. 144: * 145: * @param ctx identifies the current region 146: * @param font the font to use 147: * @param text the label text 148: * @param icon the label icon 149: * @param hAlign the horizontal alignment 150: * @param vAlign the vertical alignment 151: * @param hTextPosition the horizontal text position 152: * @param vTextPosition the vertical text position 153: * @param iconTextGap the gap between icon and text 154: * @param mnemonicIndex index to the mnemonic character within 155: * <code>text</code> 156: * 157: * @return the minimums size that is needed to render the label with 158: * <code>text</code> and <code>icon</code> correctly 159: */ 160: public Dimension getMinimumSize(SynthContext ctx, Font font, String text, 161: Icon icon, int hAlign, int vAlign, 162: int hTextPosition,int vTextPosition, 163: int iconTextGap,int mnemonicIndex) 164: throws NotImplementedException 165: { 166: // FIXME: Implement this correctly. 167: return new Dimension(0, 0); 168: } 169: 170: /** 171: * Calculates the preferred size that is needed to render the label with 172: * <code>text</code> and <code>icon</code> correctly. 173: * 174: * @param ctx identifies the current region 175: * @param font the font to use 176: * @param text the label text 177: * @param icon the label icon 178: * @param hAlign the horizontal alignment 179: * @param vAlign the vertical alignment 180: * @param hTextPosition the horizontal text position 181: * @param vTextPosition the vertical text position 182: * @param iconTextGap the gap between icon and text 183: * @param mnemonicIndex index to the mnemonic character within 184: * <code>text</code> 185: * 186: * @return the preferred size that is needed to render the label with 187: * <code>text</code> and <code>icon</code> correctly 188: */ 189: public Dimension getPreferredSize(SynthContext ctx, Font font, String text, 190: Icon icon, int hAlign, int vAlign, 191: int hTextPosition,int vTextPosition, 192: int iconTextGap,int mnemonicIndex) 193: throws NotImplementedException 194: { 195: // FIXME: Implement this correctly. 196: return new Dimension(0, 0); 197: } 198: 199: /** 200: * Calculates the maximum size that is needed to render the label with 201: * <code>text</code> and <code>icon</code> correctly. 202: * 203: * @param ctx identifies the current region 204: * @param font the font to use 205: * @param text the label text 206: * @param icon the label icon 207: * @param hAlign the horizontal alignment 208: * @param vAlign the vertical alignment 209: * @param hTextPosition the horizontal text position 210: * @param vTextPosition the vertical text position 211: * @param iconTextGap the gap between icon and text 212: * @param mnemonicIndex index to the mnemonic character within 213: * <code>text</code> 214: * 215: * @return the maximum size that is needed to render the label with 216: * <code>text</code> and <code>icon</code> correctly 217: */ 218: public Dimension getMaximumSize(SynthContext ctx, Font font, String text, 219: Icon icon, int hAlign, int vAlign, 220: int hTextPosition,int vTextPosition, 221: int iconTextGap,int mnemonicIndex) 222: throws NotImplementedException 223: { 224: // FIXME: Implement this correctly. 225: return new Dimension(0, 0); 226: } 227: 228: /** 229: * Returns the maximum character height of the font from the component of the 230: * passed in <code>context</code>. 231: * 232: * @param context identifies the current component and region 233: * 234: * @return the maximum character height of the font from the component of the 235: * passed in <code>context</code> 236: */ 237: public int getMaximumCharHeight(SynthContext context) 238: { 239: Component comp = context.getComponent(); 240: Font font = comp.getFont(); 241: return comp.getFontMetrics(font).getHeight(); 242: } 243: 244: /** 245: * Renders the specified <code>text</code> within the <code>bounds</code>. 246: * 247: * @param ctx identifies the component and region 248: * @param g the graphics context for drawing the tetx 249: * @param text the text to be rendered 250: * @param bounds the bounds within which the text should be rendered 251: * @param mnemonicIndex the index of the mnemonic character within 252: * <code>text</code> 253: */ 254: public void paintText(SynthContext ctx, Graphics g, String text, 255: Rectangle bounds, int mnemonicIndex) 256: { 257: // FIXME: This is very primitive and should be improved to paint the 258: // mnemonic char. 259: g.drawString(text, bounds.x, bounds.y); 260: } 261: 262: /** 263: * Renders the specified <code>text</code> at the specified location. 264: * 265: * @param ctx identifies the component and region 266: * @param g the graphics context for drawing the tetx 267: * @param text the text to be rendered 268: * @param x the X location where the text should be rendered 269: * @param y the Y location where the text should be rendered 270: * @param mnemonicIndex the index of the mnemonic character within 271: * <code>text</code> 272: */ 273: public void paintText(SynthContext ctx, Graphics g, String text, 274: int x, int y, int mnemonicIndex) 275: { 276: // FIXME: This is very primitive and should be improved to paint the 277: // mnemonic char. 278: g.drawString(text, x, y); 279: } 280: 281: public void paintText(SynthContext ctx, Graphics g, String text, Icon icon, 282: int hAlign, int vAlign, int hTextPosition, 283: int vTextPosition, int iconTextGap, int mnemonicIndex, 284: int textOffset) 285: throws NotImplementedException 286: { 287: // FIXME: Implement this correctly. 288: } 289: }
GNU Classpath (0.95) |