KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > render > LabelRenderer


1 package prefuse.render;
2
3 import java.awt.Dimension JavaDoc;
4 import java.awt.Font JavaDoc;
5 import java.awt.FontMetrics JavaDoc;
6 import java.awt.Graphics2D JavaDoc;
7 import java.awt.Image JavaDoc;
8 import java.awt.Shape JavaDoc;
9 import java.awt.geom.AffineTransform JavaDoc;
10 import java.awt.geom.Point2D JavaDoc;
11 import java.awt.geom.Rectangle2D JavaDoc;
12 import java.awt.geom.RectangularShape JavaDoc;
13 import java.awt.geom.RoundRectangle2D JavaDoc;
14
15 import prefuse.Constants;
16 import prefuse.util.ColorLib;
17 import prefuse.util.FontLib;
18 import prefuse.util.GraphicsLib;
19 import prefuse.util.StringLib;
20 import prefuse.visual.VisualItem;
21
22
23 /**
24  * Renderer that draws a label, which consists of a text string,
25  * an image, or both.
26  *
27  * <p>When created using the default constructor, the renderer attempts
28  * to use text from the "label" field. To use a different field, use the
29  * appropriate constructor or use the {@link #setTextField(String)} method.
30  * To perform custom String selection, subclass this Renderer and override the
31  * {@link #getText(VisualItem)} method. When the text field is
32  * <code>null</code>, no text label will be shown. Labels can span multiple
33  * lines of text, determined by the presence of newline characters ('\n')
34  * within the text string.</p>
35  *
36  * <p>By default, no image is shown. To show an image, the image field needs
37  * to be set, either using the appropriate constructor or the
38  * {@link #setImageField(String)} method. The value of the image field should
39  * be a text string indicating the location of the image file to use. The
40  * string should be either a URL, a file located on the current classpath,
41  * or a file on the local filesystem. If found, the image will be managed
42  * internally by an {@link ImageFactory} instance, which maintains a
43  * cache of loaded images.</p>
44  *
45  * <p>The position of the image relative to text can be set using the
46  * {@link #setImagePosition(int)} method. Images can be placed to the
47  * left, right, above, or below the text. The horizontal and vertical
48  * alignments of either the text or the image can be set explicitly
49  * using the appropriate methods of this class (e.g.,
50  * {@link #setHorizontalTextAlignment(int)}). By default, both the
51  * text and images are centered along both the horizontal and
52  * vertical directions.</p>
53  *
54  * @author <a HREF="http://jheer.org">jeffrey heer</a>
55  */

56 public class LabelRenderer extends AbstractShapeRenderer {
57
58     protected ImageFactory m_images = null;
59     protected String JavaDoc m_delim = "\n";
60     
61     protected String JavaDoc m_labelName = "label";
62     protected String JavaDoc m_imageName = null;
63     
64     protected int m_xAlign = Constants.CENTER;
65     protected int m_yAlign = Constants.CENTER;
66     protected int m_hTextAlign = Constants.CENTER;
67     protected int m_vTextAlign = Constants.CENTER;
68     protected int m_hImageAlign = Constants.CENTER;
69     protected int m_vImageAlign = Constants.CENTER;
70     protected int m_imagePos = Constants.LEFT;
71     
72     protected int m_horizBorder = 2;
73     protected int m_vertBorder = 0;
74     protected int m_imageMargin = 2;
75     protected int m_arcWidth = 0;
76     protected int m_arcHeight = 0;
77
78     protected int m_maxTextWidth = -1;
79     
80     /** Transform used to scale and position images */
81     AffineTransform JavaDoc m_transform = new AffineTransform JavaDoc();
82     
83     /** The holder for the currently computed bounding box */
84     protected RectangularShape JavaDoc m_bbox = new Rectangle2D.Double JavaDoc();
85     protected Point2D JavaDoc m_pt = new Point2D.Double JavaDoc(); // temp point
86
protected Font JavaDoc m_font; // temp font holder
87
protected String JavaDoc m_text; // label text
88
protected Dimension JavaDoc m_textDim = new Dimension JavaDoc(); // text width / height
89

90     /**
91      * Create a new LabelRenderer. By default the field "label" is used
92      * as the field name for looking up text, and no image is used.
93      */

94     public LabelRenderer() {
95     }
96     
97     /**
98      * Create a new LabelRenderer. Draws a text label using the given
99      * text data field and does not draw an image.
100      * @param textField the data field for the text label.
101      */

102     public LabelRenderer(String JavaDoc textField) {
103         this.setTextField(textField);
104     }
105     
106     /**
107      * Create a new LabelRenderer. Draws a text label using the given text
108      * data field, and draws the image at the location reported by the
109      * given image data field.
110      * @param textField the data field for the text label
111      * @param imageField the data field for the image location. This value
112      * in the data field should be a URL, a file within the current classpath,
113      * a file on the filesystem, or null for no image. If the
114      * <code>imageField</code> parameter is null, no images at all will be
115      * drawn.
116      */

117     public LabelRenderer(String JavaDoc textField, String JavaDoc imageField) {
118         setTextField(textField);
119         setImageField(imageField);
120     }
121     
122     // ------------------------------------------------------------------------
123

124     /**
125      * Rounds the corners of the bounding rectangle in which the text
126      * string is rendered. This will only be seen if either the stroke
127      * or fill color is non-transparent.
128      * @param arcWidth the width of the curved corner
129      * @param arcHeight the height of the curved corner
130      */

131     public void setRoundedCorner(int arcWidth, int arcHeight) {
132         if ( (arcWidth == 0 || arcHeight == 0) &&
133             !(m_bbox instanceof Rectangle2D JavaDoc) ) {
134             m_bbox = new Rectangle2D.Double JavaDoc();
135         } else {
136             if ( !(m_bbox instanceof RoundRectangle2D JavaDoc) )
137                 m_bbox = new RoundRectangle2D.Double JavaDoc();
138             ((RoundRectangle2D JavaDoc)m_bbox)
139                 .setRoundRect(0,0,10,10,arcWidth,arcHeight);
140             m_arcWidth = arcWidth;
141             m_arcHeight = arcHeight;
142         }
143     }
144
145     /**
146      * Get the field name to use for text labels.
147      * @return the data field for text labels, or null for no text
148      */

149     public String JavaDoc getTextField() {
150         return m_labelName;
151     }
152     
153     /**
154      * Set the field name to use for text labels.
155      * @param textField the data field for text labels, or null for no text
156      */

157     public void setTextField(String JavaDoc textField) {
158         m_labelName = textField;
159     }
160     
161     /**
162      * Sets the maximum width that should be allowed of the text label.
163      * A value of -1 specifies no limit (this is the default).
164      * @param maxWidth the maximum width of the text or -1 for no limit
165      */

166     public void setMaxTextWidth(int maxWidth) {
167         m_maxTextWidth = maxWidth;
168     }
169     
170     /**
171      * Returns the text to draw. Subclasses can override this class to
172      * perform custom text selection.
173      * @param item the item to represent as a <code>String</code>
174      * @return a <code>String</code> to draw
175      */

176     protected String JavaDoc getText(VisualItem item) {
177         String JavaDoc s = null;
178         if ( item.canGetString(m_labelName) ) {
179             return item.getString(m_labelName);
180         }
181         return s;
182     }
183
184     // ------------------------------------------------------------------------
185
// Image Handling
186

187     /**
188      * Get the data field for image locations. The value stored
189      * in the data field should be a URL, a file within the current classpath,
190      * a file on the filesystem, or null for no image.
191      * @return the data field for image locations, or null for no images
192      */

193     public String JavaDoc getImageField() {
194         return m_imageName;
195     }
196     
197     /**
198      * Set the data field for image locations. The value stored
199      * in the data field should be a URL, a file within the current classpath,
200      * a file on the filesystem, or null for no image. If the
201      * <code>imageField</code> parameter is null, no images at all will be
202      * drawn.
203      * @param imageField the data field for image locations, or null for
204      * no images
205      */

206     public void setImageField(String JavaDoc imageField) {
207         if ( imageField != null ) m_images = new ImageFactory();
208         m_imageName = imageField;
209     }
210     
211     /**
212      * Sets the maximum image dimensions, used to control scaling of loaded
213      * images. This scaling is enforced immediately upon loading of the image.
214      * @param width the maximum width of images (-1 for no limit)
215      * @param height the maximum height of images (-1 for no limit)
216      */

217     public void setMaxImageDimensions(int width, int height) {
218         if ( m_images == null ) m_images = new ImageFactory();
219         m_images.setMaxImageDimensions(width, height);
220     }
221     
222     /**
223      * Returns a location string for the image to draw. Subclasses can override
224      * this class to perform custom image selection beyond looking up the value
225      * from a data field.
226      * @param item the item for which to select an image to draw
227      * @return the location string for the image to use, or null for no image
228      */

229     protected String JavaDoc getImageLocation(VisualItem item) {
230         return item.canGetString(m_imageName)
231                 ? item.getString(m_imageName)
232                 : null;
233     }
234     
235     /**
236      * Get the image to include in the label for the given VisualItem.
237      * @param item the item to get an image for
238      * @return the image for the item, or null for no image
239      */

240     protected Image JavaDoc getImage(VisualItem item) {
241         String JavaDoc imageLoc = getImageLocation(item);
242         return ( imageLoc == null ? null : m_images.getImage(imageLoc) );
243     }
244     
245     
246     // ------------------------------------------------------------------------
247
// Rendering
248

249     private String JavaDoc computeTextDimensions(VisualItem item, String JavaDoc text,
250                                          double size)
251     {
252         // put item font in temp member variable
253
m_font = item.getFont();
254         // scale the font as needed
255
if ( size != 1 ) {
256             m_font = FontLib.getFont(m_font.getName(), m_font.getStyle(),
257                                      size*m_font.getSize());
258         }
259         
260         FontMetrics JavaDoc fm = DEFAULT_GRAPHICS.getFontMetrics(m_font);
261         StringBuffer JavaDoc str = null;
262         
263         // compute the number of lines and the maximum width
264
int nlines = 1, w = 0, start = 0, end = text.indexOf(m_delim);
265         m_textDim.width = 0;
266         String JavaDoc line;
267         for ( ; end >= 0; ++nlines ) {
268             w = fm.stringWidth(line=text.substring(start,end));
269             // abbreviate line as needed
270
if ( m_maxTextWidth > -1 && w > m_maxTextWidth ) {
271                 if ( str == null )
272                     str = new StringBuffer JavaDoc(text.substring(0,start));
273                 str.append(StringLib.abbreviate(line, fm, m_maxTextWidth));
274                 str.append(m_delim);
275                 w = m_maxTextWidth;
276             } else if ( str != null ) {
277                 str.append(line).append(m_delim);
278             }
279             // update maximum width and substring indices
280
m_textDim.width = Math.max(m_textDim.width, w);
281             start = end+1;
282             end = text.indexOf(m_delim, start);
283         }
284         w = fm.stringWidth(line=text.substring(start));
285         // abbreviate line as needed
286
if ( m_maxTextWidth > -1 && w > m_maxTextWidth ) {
287             if ( str == null )
288                 str = new StringBuffer JavaDoc(text.substring(0,start));
289             str.append(StringLib.abbreviate(line, fm, m_maxTextWidth));
290             w = m_maxTextWidth;
291         } else if ( str != null ) {
292             str.append(line);
293         }
294         // update maximum width
295
m_textDim.width = Math.max(m_textDim.width, w);
296         
297         // compute the text height
298
m_textDim.height = fm.getHeight() * nlines;
299         
300         return str==null ? text : str.toString();
301     }
302     
303     /**
304      * @see prefuse.render.AbstractShapeRenderer#getRawShape(prefuse.visual.VisualItem)
305      */

306     protected Shape JavaDoc getRawShape(VisualItem item) {
307         m_text = getText(item);
308         Image JavaDoc img = getImage(item);
309         double size = item.getSize();
310         
311         // get image dimensions
312
double iw=0, ih=0;
313         if ( img != null ) {
314             ih = img.getHeight(null);
315             iw = img.getWidth(null);
316         }
317         
318         // get text dimensions
319
int tw=0, th=0;
320         if ( m_text != null ) {
321             m_text = computeTextDimensions(item, m_text, size);
322             th = m_textDim.height;
323             tw = m_textDim.width;
324         }
325         
326         // get bounding box dimensions
327
double w=0, h=0;
328         switch ( m_imagePos ) {
329         case Constants.LEFT:
330         case Constants.RIGHT:
331             w = tw + size*(iw +2*m_horizBorder
332                    + (tw>0 && iw>0 ? m_imageMargin : 0));
333             h = Math.max(th, size*ih) + size*2*m_vertBorder;
334             break;
335         case Constants.TOP:
336         case Constants.BOTTOM:
337             w = Math.max(tw, size*iw) + size*2*m_horizBorder;
338             h = th + size*(ih + 2*m_vertBorder
339                    + (th>0 && ih>0 ? m_imageMargin : 0));
340             break;
341         default:
342             throw new IllegalStateException JavaDoc(
343                 "Unrecognized image alignment setting.");
344         }
345         
346         // get the top-left point, using the current alignment settings
347
getAlignedPoint(m_pt, item, w, h, m_xAlign, m_yAlign);
348         
349         if ( m_bbox instanceof RoundRectangle2D JavaDoc ) {
350             RoundRectangle2D JavaDoc rr = (RoundRectangle2D JavaDoc)m_bbox;
351             rr.setRoundRect(m_pt.getX(), m_pt.getY(), w, h,
352                             size*m_arcWidth, size*m_arcHeight);
353         } else {
354             m_bbox.setFrame(m_pt.getX(), m_pt.getY(), w, h);
355         }
356         return m_bbox;
357     }
358     
359     /**
360      * Helper method, which calculates the top-left co-ordinate of an item
361      * given the item's alignment.
362      */

363     protected static void getAlignedPoint(Point2D JavaDoc p, VisualItem item,
364             double w, double h, int xAlign, int yAlign)
365     {
366         double x = item.getX(), y = item.getY();
367         if ( Double.isNaN(x) || Double.isInfinite(x) )
368             x = 0; // safety check
369
if ( Double.isNaN(y) || Double.isInfinite(y) )
370             y = 0; // safety check
371

372         if ( xAlign == Constants.CENTER ) {
373             x = x-(w/2);
374         } else if ( xAlign == Constants.RIGHT ) {
375             x = x-w;
376         }
377         if ( yAlign == Constants.CENTER ) {
378             y = y-(h/2);
379         } else if ( yAlign == Constants.BOTTOM ) {
380             y = y-h;
381         }
382         p.setLocation(x,y);
383     }
384     
385     /**
386      * @see prefuse.render.Renderer#render(java.awt.Graphics2D, prefuse.visual.VisualItem)
387      */

388     public void render(Graphics2D JavaDoc g, VisualItem item) {
389         RectangularShape JavaDoc shape = (RectangularShape JavaDoc)getShape(item);
390         if ( shape == null ) return;
391         
392         // fill the shape, if requested
393
int type = getRenderType(item);
394         if ( type==RENDER_TYPE_FILL || type==RENDER_TYPE_DRAW_AND_FILL )
395             GraphicsLib.paint(g, item, shape, getStroke(item), RENDER_TYPE_FILL);
396
397         // now render the image and text
398
String JavaDoc text = m_text;
399         Image JavaDoc img = getImage(item);
400         
401         if ( text == null && img == null )
402             return;
403                         
404         double size = item.getSize();
405         boolean useInt = 1.5 > Math.max(g.getTransform().getScaleX(),
406                                         g.getTransform().getScaleY());
407         double x = shape.getMinX() + size*m_horizBorder;
408         double y = shape.getMinY() + size*m_vertBorder;
409         
410         // render image
411
if ( img != null ) {
412             double w = size * img.getWidth(null);
413             double h = size * img.getHeight(null);
414             double ix=x, iy=y;
415             
416             // determine one co-ordinate based on the image position
417
switch ( m_imagePos ) {
418             case Constants.LEFT:
419                 x += w + size*m_imageMargin;
420                 break;
421             case Constants.RIGHT:
422                 ix = shape.getMaxX() - size*m_horizBorder - w;
423                 break;
424             case Constants.TOP:
425                 y += h + size*m_imageMargin;
426                 break;
427             case Constants.BOTTOM:
428                 iy = shape.getMaxY() - size*m_vertBorder - h;
429                 break;
430             default:
431                 throw new IllegalStateException JavaDoc(
432                         "Unrecognized image alignment setting.");
433             }
434             
435             // determine the other coordinate based on image alignment
436
switch ( m_imagePos ) {
437             case Constants.LEFT:
438             case Constants.RIGHT:
439                 // need to set image y-coordinate
440
switch ( m_vImageAlign ) {
441                 case Constants.TOP:
442                     break;
443                 case Constants.BOTTOM:
444                     iy = shape.getMaxY() - size*m_vertBorder - h;
445                     break;
446                 case Constants.CENTER:
447                     iy = shape.getCenterY() - h/2;
448                     break;
449                 }
450                 break;
451             case Constants.TOP:
452             case Constants.BOTTOM:
453                 // need to set image x-coordinate
454
switch ( m_hImageAlign ) {
455                 case Constants.LEFT:
456                     break;
457                 case Constants.RIGHT:
458                     ix = shape.getMaxX() - size*m_horizBorder - w;
459                     break;
460                 case Constants.CENTER:
461                     ix = shape.getCenterX() - w/2;
462                     break;
463                 }
464                 break;
465             }
466             
467             if ( useInt && size == 1.0 ) {
468                 // if possible, use integer precision
469
// results in faster, flicker-free image rendering
470
g.drawImage(img, (int)ix, (int)iy, null);
471             } else {
472                 m_transform.setTransform(size,0,0,size,ix,iy);
473                 g.drawImage(img, m_transform, null);
474             }
475         }
476         
477         // render text
478
int textColor = item.getTextColor();
479         if ( text != null && ColorLib.alpha(textColor) > 0 ) {
480             g.setPaint(ColorLib.getColor(textColor));
481             g.setFont(m_font);
482             FontMetrics JavaDoc fm = DEFAULT_GRAPHICS.getFontMetrics(m_font);
483
484             // compute available width
485
double tw;
486             switch ( m_imagePos ) {
487             case Constants.TOP:
488             case Constants.BOTTOM:
489                 tw = shape.getWidth() - 2*size*m_horizBorder;
490                 break;
491             default:
492                 tw = m_textDim.width;
493             }
494             
495             // compute available height
496
double th;
497             switch ( m_imagePos ) {
498             case Constants.LEFT:
499             case Constants.RIGHT:
500                 th = shape.getHeight() - 2*size*m_vertBorder;
501                 break;
502             default:
503                 th = m_textDim.height;
504             }
505             
506             // compute starting y-coordinate
507
y += fm.getAscent();
508             switch ( m_vTextAlign ) {
509             case Constants.TOP:
510                 break;
511             case Constants.BOTTOM:
512                 y += th - m_textDim.height;
513                 break;
514             case Constants.CENTER:
515                 y += (th - m_textDim.height)/2;
516             }
517             
518             // render each line of text
519
int lh = fm.getHeight(); // the line height
520
int start = 0, end = text.indexOf(m_delim);
521             for ( ; end >= 0; y += lh ) {
522                 drawString(g, fm, text.substring(start, end), useInt, x, y, tw);
523                 start = end+1;
524                 end = text.indexOf(m_delim, start);
525             }
526             drawString(g, fm, text.substring(start), useInt, x, y, tw);
527         }
528     
529         // draw border
530
if (type==RENDER_TYPE_DRAW || type==RENDER_TYPE_DRAW_AND_FILL) {
531             GraphicsLib.paint(g,item,shape,getStroke(item),RENDER_TYPE_DRAW);
532         }
533     }
534     
535     private final void drawString(Graphics2D JavaDoc g, FontMetrics JavaDoc fm, String JavaDoc text,
536             boolean useInt, double x, double y, double w)
537     {
538         // compute the x-coordinate
539
double tx;
540         switch ( m_hTextAlign ) {
541         case Constants.LEFT:
542             tx = x;
543             break;
544         case Constants.RIGHT:
545             tx = x + w - fm.stringWidth(text);
546             break;
547         case Constants.CENTER:
548             tx = x + (w - fm.stringWidth(text)) / 2;
549             break;
550         default:
551             throw new IllegalStateException JavaDoc(
552                     "Unrecognized text alignment setting.");
553         }
554         // use integer precision unless zoomed-in
555
// results in more stable drawing
556
if ( useInt ) {
557             g.drawString(text, (int)tx, (int)y);
558         } else {
559             g.drawString(text, (float)tx, (float)y);
560         }
561     }
562     
563     /**
564      * Returns the image factory used by this renderer.
565      * @return the image factory
566      */

567     public ImageFactory getImageFactory() {
568         if ( m_images == null ) m_images = new ImageFactory();
569         return m_images;
570     }
571     
572     /**
573      * Sets the image factory used by this renderer.
574      * @param ifact the image factory
575      */

576     public void setImageFactory(ImageFactory ifact) {
577         m_images = ifact;
578     }
579     
580     // ------------------------------------------------------------------------
581

582     /**
583      * Get the horizontal text alignment within the layout. One of
584      * {@link prefuse.Constants#LEFT}, {@link prefuse.Constants#RIGHT}, or
585      * {@link prefuse.Constants#CENTER}. The default is centered text.
586      * @return the horizontal text alignment
587      */

588     public int getHorizontalTextAlignment() {
589         return m_hTextAlign;
590     }
591     
592     /**
593      * Set the horizontal text alignment within the layout. One of
594      * {@link prefuse.Constants#LEFT}, {@link prefuse.Constants#RIGHT}, or
595      * {@link prefuse.Constants#CENTER}. The default is centered text.
596      * @param halign the desired horizontal text alignment
597      */

598     public void setHorizontalTextAlignment(int halign) {
599         if ( halign != Constants.LEFT &&
600              halign != Constants.RIGHT &&
601              halign != Constants.CENTER )
602            throw new IllegalArgumentException JavaDoc(
603                    "Illegal horizontal text alignment value.");
604         m_hTextAlign = halign;
605     }
606     
607     /**
608      * Get the vertical text alignment within the layout. One of
609      * {@link prefuse.Constants#TOP}, {@link prefuse.Constants#BOTTOM}, or
610      * {@link prefuse.Constants#CENTER}. The default is centered text.
611      * @return the vertical text alignment
612      */

613     public int getVerticalTextAlignment() {
614         return m_vTextAlign;
615     }
616     
617     /**
618      * Set the vertical text alignment within the layout. One of
619      * {@link prefuse.Constants#TOP}, {@link prefuse.Constants#BOTTOM}, or
620      * {@link prefuse.Constants#CENTER}. The default is centered text.
621      * @param valign the desired vertical text alignment
622      */

623     public void setVerticalTextAlignment(int valign) {
624         if ( valign != Constants.TOP &&
625              valign != Constants.BOTTOM &&
626              valign != Constants.CENTER )
627             throw new IllegalArgumentException JavaDoc(
628                     "Illegal vertical text alignment value.");
629         m_vTextAlign = valign;
630     }
631     
632     /**
633      * Get the horizontal image alignment within the layout. One of
634      * {@link prefuse.Constants#LEFT}, {@link prefuse.Constants#RIGHT}, or
635      * {@link prefuse.Constants#CENTER}. The default is a centered image.
636      * @return the horizontal image alignment
637      */

638     public int getHorizontalImageAlignment() {
639         return m_hImageAlign;
640     }
641     
642     /**
643      * Set the horizontal image alignment within the layout. One of
644      * {@link prefuse.Constants#LEFT}, {@link prefuse.Constants#RIGHT}, or
645      * {@link prefuse.Constants#CENTER}. The default is a centered image.
646      * @param halign the desired horizontal image alignment
647      */

648     public void setHorizontalImageAlignment(int halign) {
649         if ( halign != Constants.LEFT &&
650              halign != Constants.RIGHT &&
651              halign != Constants.CENTER )
652            throw new IllegalArgumentException JavaDoc(
653                    "Illegal horizontal text alignment value.");
654         m_hImageAlign = halign;
655     }
656     
657     /**
658      * Get the vertical image alignment within the layout. One of
659      * {@link prefuse.Constants#TOP}, {@link prefuse.Constants#BOTTOM}, or
660      * {@link prefuse.Constants#CENTER}. The default is a centered image.
661      * @return the vertical image alignment
662      */

663     public int getVerticalImageAlignment() {
664         return m_vImageAlign;
665     }
666     
667     /**
668      * Set the vertical image alignment within the layout. One of
669      * {@link prefuse.Constants#TOP}, {@link prefuse.Constants#BOTTOM}, or
670      * {@link prefuse.Constants#CENTER}. The default is a centered image.
671      * @param valign the desired vertical image alignment
672      */

673     public void setVerticalImageAlignment(int valign) {
674         if ( valign != Constants.TOP &&
675              valign != Constants.BOTTOM &&
676              valign != Constants.CENTER )
677             throw new IllegalArgumentException JavaDoc(
678                     "Illegal vertical text alignment value.");
679         m_vImageAlign = valign;
680     }
681     
682     /**
683      * Get the image position, determining where the image is placed with
684      * respect to the text. One of {@link Constants#LEFT},
685      * {@link Constants#RIGHT}, {@link Constants#TOP}, or
686      * {@link Constants#BOTTOM}. The default is left.
687      * @return the image position
688      */

689     public int getImagePosition() {
690         return m_imagePos;
691     }
692     
693     /**
694      * Set the image position, determining where the image is placed with
695      * respect to the text. One of {@link Constants#LEFT},
696      * {@link Constants#RIGHT}, {@link Constants#TOP}, or
697      * {@link Constants#BOTTOM}. The default is left.
698      * @param pos the desired image position
699      */

700     public void setImagePosition(int pos) {
701         if ( pos != Constants.TOP &&
702              pos != Constants.BOTTOM &&
703              pos != Constants.LEFT &&
704              pos != Constants.RIGHT &&
705              pos != Constants.CENTER )
706            throw new IllegalArgumentException JavaDoc(
707                    "Illegal image position value.");
708         m_imagePos = pos;
709     }
710     
711     // ------------------------------------------------------------------------
712

713     /**
714      * Get the horizontal alignment of this node with respect to its
715      * x, y coordinates.
716      * @return the horizontal alignment, one of
717      * {@link prefuse.Constants#LEFT}, {@link prefuse.Constants#RIGHT}, or
718      * {@link prefuse.Constants#CENTER}.
719      */

720     public int getHorizontalAlignment() {
721         return m_xAlign;
722     }
723     
724     /**
725      * Get the vertical alignment of this node with respect to its
726      * x, y coordinates.
727      * @return the vertical alignment, one of
728      * {@link prefuse.Constants#TOP}, {@link prefuse.Constants#BOTTOM}, or
729      * {@link prefuse.Constants#CENTER}.
730      */

731     public int getVerticalAlignment() {
732         return m_yAlign;
733     }
734     
735     /**
736      * Set the horizontal alignment of this node with respect to its
737      * x, y coordinates.
738      * @param align the horizontal alignment, one of
739      * {@link prefuse.Constants#LEFT}, {@link prefuse.Constants#RIGHT}, or
740      * {@link prefuse.Constants#CENTER}.
741      */

742     public void setHorizontalAlignment(int align) {
743         m_xAlign = align;
744     }
745     
746     /**
747      * Set the vertical alignment of this node with respect to its
748      * x, y coordinates.
749      * @param align the vertical alignment, one of
750      * {@link prefuse.Constants#TOP}, {@link prefuse.Constants#BOTTOM}, or
751      * {@link prefuse.Constants#CENTER}.
752      */

753     public void setVerticalAlignment(int align) {
754         m_yAlign = align;
755     }
756     
757     /**
758      * Returns the amount of padding in pixels between the content
759      * and the border of this item along the horizontal dimension.
760      * @return the horizontal padding
761      */

762     public int getHorizontalPadding() {
763         return m_horizBorder;
764     }
765     
766     /**
767      * Sets the amount of padding in pixels between the content
768      * and the border of this item along the horizontal dimension.
769      * @param xpad the horizontal padding to set
770      */

771     public void setHorizontalPadding(int xpad) {
772         m_horizBorder = xpad;
773     }
774     
775     /**
776      * Returns the amount of padding in pixels between the content
777      * and the border of this item along the vertical dimension.
778      * @return the vertical padding
779      */

780     public int getVerticalPadding() {
781         return m_vertBorder;
782     }
783     
784     /**
785      * Sets the amount of padding in pixels between the content
786      * and the border of this item along the vertical dimension.
787      * @param ypad the vertical padding
788      */

789     public void setVerticalPadding(int ypad) {
790         m_vertBorder = ypad;
791     }
792     
793     /**
794      * Get the padding, in pixels, between an image and text.
795      * @return the padding between an image and text
796      */

797     public int getImageTextPadding() {
798         return m_imageMargin;
799     }
800     
801     /**
802      * Set the padding, in pixels, between an image and text.
803      * @param pad the padding to use between an image and text
804      */

805     public void setImageTextPadding(int pad) {
806         m_imageMargin = pad;
807     }
808     
809 } // end of class LabelRenderer
810
Popular Tags