Source Code Cross Referenced for LabelRenderer.java in  » Database-Client » prefuse » prefuse » render » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » prefuse » prefuse.render 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package prefuse.render;
002:
003:        import java.awt.Dimension;
004:        import java.awt.Font;
005:        import java.awt.FontMetrics;
006:        import java.awt.Graphics2D;
007:        import java.awt.Image;
008:        import java.awt.Shape;
009:        import java.awt.geom.AffineTransform;
010:        import java.awt.geom.Point2D;
011:        import java.awt.geom.Rectangle2D;
012:        import java.awt.geom.RectangularShape;
013:        import java.awt.geom.RoundRectangle2D;
014:
015:        import prefuse.Constants;
016:        import prefuse.util.ColorLib;
017:        import prefuse.util.FontLib;
018:        import prefuse.util.GraphicsLib;
019:        import prefuse.util.StringLib;
020:        import prefuse.visual.VisualItem;
021:
022:        /**
023:         * Renderer that draws a label, which consists of a text string,
024:         * an image, or both.
025:         * 
026:         * <p>When created using the default constructor, the renderer attempts
027:         * to use text from the "label" field. To use a different field, use the
028:         * appropriate constructor or use the {@link #setTextField(String)} method.
029:         * To perform custom String selection, subclass this Renderer and override the 
030:         * {@link #getText(VisualItem)} method. When the text field is
031:         * <code>null</code>, no text label will be shown. Labels can span multiple
032:         * lines of text, determined by the presence of newline characters ('\n')
033:         * within the text string.</p>
034:         * 
035:         * <p>By default, no image is shown. To show an image, the image field needs
036:         * to be set, either using the appropriate constructor or the
037:         * {@link #setImageField(String)} method. The value of the image field should
038:         * be a text string indicating the location of the image file to use. The
039:         * string should be either a URL, a file located on the current classpath,
040:         * or a file on the local filesystem. If found, the image will be managed
041:         * internally by an {@link ImageFactory} instance, which maintains a
042:         * cache of loaded images.</p>
043:         * 
044:         * <p>The position of the image relative to text can be set using the
045:         * {@link #setImagePosition(int)} method. Images can be placed to the
046:         * left, right, above, or below the text. The horizontal and vertical
047:         * alignments of either the text or the image can be set explicitly
048:         * using the appropriate methods of this class (e.g.,
049:         * {@link #setHorizontalTextAlignment(int)}). By default, both the
050:         * text and images are centered along both the horizontal and
051:         * vertical directions.</p>
052:         * 
053:         * @author <a href="http://jheer.org">jeffrey heer</a>
054:         */
055:        public class LabelRenderer extends AbstractShapeRenderer {
056:
057:            protected ImageFactory m_images = null;
058:            protected String m_delim = "\n";
059:
060:            protected String m_labelName = "label";
061:            protected String m_imageName = null;
062:
063:            protected int m_xAlign = Constants.CENTER;
064:            protected int m_yAlign = Constants.CENTER;
065:            protected int m_hTextAlign = Constants.CENTER;
066:            protected int m_vTextAlign = Constants.CENTER;
067:            protected int m_hImageAlign = Constants.CENTER;
068:            protected int m_vImageAlign = Constants.CENTER;
069:            protected int m_imagePos = Constants.LEFT;
070:
071:            protected int m_horizBorder = 2;
072:            protected int m_vertBorder = 0;
073:            protected int m_imageMargin = 2;
074:            protected int m_arcWidth = 0;
075:            protected int m_arcHeight = 0;
076:
077:            protected int m_maxTextWidth = -1;
078:
079:            /** Transform used to scale and position images */
080:            AffineTransform m_transform = new AffineTransform();
081:
082:            /** The holder for the currently computed bounding box */
083:            protected RectangularShape m_bbox = new Rectangle2D.Double();
084:            protected Point2D m_pt = new Point2D.Double(); // temp point
085:            protected Font m_font; // temp font holder
086:            protected String m_text; // label text
087:            protected Dimension m_textDim = new Dimension(); // text width / height
088:
089:            /**
090:             * Create a new LabelRenderer. By default the field "label" is used
091:             * as the field name for looking up text, and no image is used.
092:             */
093:            public LabelRenderer() {
094:            }
095:
096:            /**
097:             * Create a new LabelRenderer. Draws a text label using the given
098:             * text data field and does not draw an image.
099:             * @param textField the data field for the text label.
100:             */
101:            public LabelRenderer(String textField) {
102:                this .setTextField(textField);
103:            }
104:
105:            /**
106:             * Create a new LabelRenderer. Draws a text label using the given text
107:             * data field, and draws the image at the location reported by the
108:             * given image data field.
109:             * @param textField the data field for the text label
110:             * @param imageField the data field for the image location. This value
111:             * in the data field should be a URL, a file within the current classpath,
112:             * a file on the filesystem, or null for no image. If the
113:             * <code>imageField</code> parameter is null, no images at all will be
114:             * drawn.
115:             */
116:            public LabelRenderer(String textField, String imageField) {
117:                setTextField(textField);
118:                setImageField(imageField);
119:            }
120:
121:            // ------------------------------------------------------------------------
122:
123:            /**
124:             * Rounds the corners of the bounding rectangle in which the text
125:             * string is rendered. This will only be seen if either the stroke
126:             * or fill color is non-transparent.
127:             * @param arcWidth the width of the curved corner
128:             * @param arcHeight the height of the curved corner
129:             */
130:            public void setRoundedCorner(int arcWidth, int arcHeight) {
131:                if ((arcWidth == 0 || arcHeight == 0)
132:                        && !(m_bbox instanceof  Rectangle2D)) {
133:                    m_bbox = new Rectangle2D.Double();
134:                } else {
135:                    if (!(m_bbox instanceof  RoundRectangle2D))
136:                        m_bbox = new RoundRectangle2D.Double();
137:                    ((RoundRectangle2D) m_bbox).setRoundRect(0, 0, 10, 10,
138:                            arcWidth, arcHeight);
139:                    m_arcWidth = arcWidth;
140:                    m_arcHeight = arcHeight;
141:                }
142:            }
143:
144:            /**
145:             * Get the field name to use for text labels.
146:             * @return the data field for text labels, or null for no text
147:             */
148:            public String getTextField() {
149:                return m_labelName;
150:            }
151:
152:            /**
153:             * Set the field name to use for text labels.
154:             * @param textField the data field for text labels, or null for no text
155:             */
156:            public void setTextField(String textField) {
157:                m_labelName = textField;
158:            }
159:
160:            /**
161:             * Sets the maximum width that should be allowed of the text label.
162:             * A value of -1 specifies no limit (this is the default).
163:             * @param maxWidth the maximum width of the text or -1 for no limit
164:             */
165:            public void setMaxTextWidth(int maxWidth) {
166:                m_maxTextWidth = maxWidth;
167:            }
168:
169:            /**
170:             * Returns the text to draw. Subclasses can override this class to
171:             * perform custom text selection.
172:             * @param item the item to represent as a <code>String</code>
173:             * @return a <code>String</code> to draw
174:             */
175:            protected String getText(VisualItem item) {
176:                String s = null;
177:                if (item.canGetString(m_labelName)) {
178:                    return item.getString(m_labelName);
179:                }
180:                return s;
181:            }
182:
183:            // ------------------------------------------------------------------------
184:            // Image Handling
185:
186:            /**
187:             * Get the data field for image locations. The value stored
188:             * in the data field should be a URL, a file within the current classpath,
189:             * a file on the filesystem, or null for no image.
190:             * @return the data field for image locations, or null for no images
191:             */
192:            public String getImageField() {
193:                return m_imageName;
194:            }
195:
196:            /**
197:             * Set the data field for image locations. The value stored
198:             * in the data field should be a URL, a file within the current classpath,
199:             * a file on the filesystem, or null for no image. If the
200:             * <code>imageField</code> parameter is null, no images at all will be
201:             * drawn.
202:             * @param imageField the data field for image locations, or null for
203:             * no images
204:             */
205:            public void setImageField(String imageField) {
206:                if (imageField != null)
207:                    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)
219:                    m_images = new ImageFactory();
220:                m_images.setMaxImageDimensions(width, height);
221:            }
222:
223:            /**
224:             * Returns a location string for the image to draw. Subclasses can override 
225:             * this class to perform custom image selection beyond looking up the value
226:             * from a data field.
227:             * @param item the item for which to select an image to draw
228:             * @return the location string for the image to use, or null for no image
229:             */
230:            protected String getImageLocation(VisualItem item) {
231:                return item.canGetString(m_imageName) ? item
232:                        .getString(m_imageName) : 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 getImage(VisualItem item) {
241:                String imageLoc = getImageLocation(item);
242:                return (imageLoc == null ? null : m_images.getImage(imageLoc));
243:            }
244:
245:            // ------------------------------------------------------------------------
246:            // Rendering
247:
248:            private String computeTextDimensions(VisualItem item, String text,
249:                    double size) {
250:                // put item font in temp member variable
251:                m_font = item.getFont();
252:                // scale the font as needed
253:                if (size != 1) {
254:                    m_font = FontLib.getFont(m_font.getName(), m_font
255:                            .getStyle(), size * m_font.getSize());
256:                }
257:
258:                FontMetrics fm = DEFAULT_GRAPHICS.getFontMetrics(m_font);
259:                StringBuffer str = null;
260:
261:                // compute the number of lines and the maximum width
262:                int nlines = 1, w = 0, start = 0, end = text.indexOf(m_delim);
263:                m_textDim.width = 0;
264:                String line;
265:                for (; end >= 0; ++nlines) {
266:                    w = fm.stringWidth(line = text.substring(start, end));
267:                    // abbreviate line as needed
268:                    if (m_maxTextWidth > -1 && w > m_maxTextWidth) {
269:                        if (str == null)
270:                            str = new StringBuffer(text.substring(0, start));
271:                        str.append(StringLib.abbreviate(line, fm,
272:                                m_maxTextWidth));
273:                        str.append(m_delim);
274:                        w = m_maxTextWidth;
275:                    } else if (str != null) {
276:                        str.append(line).append(m_delim);
277:                    }
278:                    // update maximum width and substring indices
279:                    m_textDim.width = Math.max(m_textDim.width, w);
280:                    start = end + 1;
281:                    end = text.indexOf(m_delim, start);
282:                }
283:                w = fm.stringWidth(line = text.substring(start));
284:                // abbreviate line as needed
285:                if (m_maxTextWidth > -1 && w > m_maxTextWidth) {
286:                    if (str == null)
287:                        str = new StringBuffer(text.substring(0, start));
288:                    str.append(StringLib.abbreviate(line, fm, m_maxTextWidth));
289:                    w = m_maxTextWidth;
290:                } else if (str != null) {
291:                    str.append(line);
292:                }
293:                // update maximum width
294:                m_textDim.width = Math.max(m_textDim.width, w);
295:
296:                // compute the text height
297:                m_textDim.height = fm.getHeight() * nlines;
298:
299:                return str == null ? text : str.toString();
300:            }
301:
302:            /**
303:             * @see prefuse.render.AbstractShapeRenderer#getRawShape(prefuse.visual.VisualItem)
304:             */
305:            protected Shape getRawShape(VisualItem item) {
306:                m_text = getText(item);
307:                Image img = getImage(item);
308:                double size = item.getSize();
309:
310:                // get image dimensions
311:                double iw = 0, ih = 0;
312:                if (img != null) {
313:                    ih = img.getHeight(null);
314:                    iw = img.getWidth(null);
315:                }
316:
317:                // get text dimensions
318:                int tw = 0, th = 0;
319:                if (m_text != null) {
320:                    m_text = computeTextDimensions(item, m_text, size);
321:                    th = m_textDim.height;
322:                    tw = m_textDim.width;
323:                }
324:
325:                // get bounding box dimensions
326:                double w = 0, h = 0;
327:                switch (m_imagePos) {
328:                case Constants.LEFT:
329:                case Constants.RIGHT:
330:                    w = tw
331:                            + size
332:                            * (iw + 2 * m_horizBorder + (tw > 0 && iw > 0 ? m_imageMargin
333:                                    : 0));
334:                    h = Math.max(th, size * ih) + size * 2 * m_vertBorder;
335:                    break;
336:                case Constants.TOP:
337:                case Constants.BOTTOM:
338:                    w = Math.max(tw, size * iw) + size * 2 * m_horizBorder;
339:                    h = th
340:                            + size
341:                            * (ih + 2 * m_vertBorder + (th > 0 && ih > 0 ? m_imageMargin
342:                                    : 0));
343:                    break;
344:                default:
345:                    throw new IllegalStateException(
346:                            "Unrecognized image alignment setting.");
347:                }
348:
349:                // get the top-left point, using the current alignment settings
350:                getAlignedPoint(m_pt, item, w, h, m_xAlign, m_yAlign);
351:
352:                if (m_bbox instanceof  RoundRectangle2D) {
353:                    RoundRectangle2D rr = (RoundRectangle2D) m_bbox;
354:                    rr.setRoundRect(m_pt.getX(), m_pt.getY(), w, h, size
355:                            * m_arcWidth, size * m_arcHeight);
356:                } else {
357:                    m_bbox.setFrame(m_pt.getX(), m_pt.getY(), w, h);
358:                }
359:                return m_bbox;
360:            }
361:
362:            /**
363:             * Helper method, which calculates the top-left co-ordinate of an item
364:             * given the item's alignment.
365:             */
366:            protected static void getAlignedPoint(Point2D p, VisualItem item,
367:                    double w, double h, int xAlign, int yAlign) {
368:                double x = item.getX(), y = item.getY();
369:                if (Double.isNaN(x) || Double.isInfinite(x))
370:                    x = 0; // safety check
371:                if (Double.isNaN(y) || Double.isInfinite(y))
372:                    y = 0; // safety check
373:
374:                if (xAlign == Constants.CENTER) {
375:                    x = x - (w / 2);
376:                } else if (xAlign == Constants.RIGHT) {
377:                    x = x - w;
378:                }
379:                if (yAlign == Constants.CENTER) {
380:                    y = y - (h / 2);
381:                } else if (yAlign == Constants.BOTTOM) {
382:                    y = y - h;
383:                }
384:                p.setLocation(x, y);
385:            }
386:
387:            /**
388:             * @see prefuse.render.Renderer#render(java.awt.Graphics2D, prefuse.visual.VisualItem)
389:             */
390:            public void render(Graphics2D g, VisualItem item) {
391:                RectangularShape shape = (RectangularShape) getShape(item);
392:                if (shape == null)
393:                    return;
394:
395:                // fill the shape, if requested
396:                int type = getRenderType(item);
397:                if (type == RENDER_TYPE_FILL
398:                        || type == RENDER_TYPE_DRAW_AND_FILL)
399:                    GraphicsLib.paint(g, item, shape, getStroke(item),
400:                            RENDER_TYPE_FILL);
401:
402:                // now render the image and text
403:                String text = m_text;
404:                Image img = getImage(item);
405:
406:                if (text == null && img == null)
407:                    return;
408:
409:                double size = item.getSize();
410:                boolean useInt = 1.5 > Math.max(g.getTransform().getScaleX(), g
411:                        .getTransform().getScaleY());
412:                double x = shape.getMinX() + size * m_horizBorder;
413:                double y = shape.getMinY() + size * m_vertBorder;
414:
415:                // render image
416:                if (img != null) {
417:                    double w = size * img.getWidth(null);
418:                    double h = size * img.getHeight(null);
419:                    double ix = x, iy = y;
420:
421:                    // determine one co-ordinate based on the image position
422:                    switch (m_imagePos) {
423:                    case Constants.LEFT:
424:                        x += w + size * m_imageMargin;
425:                        break;
426:                    case Constants.RIGHT:
427:                        ix = shape.getMaxX() - size * m_horizBorder - w;
428:                        break;
429:                    case Constants.TOP:
430:                        y += h + size * m_imageMargin;
431:                        break;
432:                    case Constants.BOTTOM:
433:                        iy = shape.getMaxY() - size * m_vertBorder - h;
434:                        break;
435:                    default:
436:                        throw new IllegalStateException(
437:                                "Unrecognized image alignment setting.");
438:                    }
439:
440:                    // determine the other coordinate based on image alignment
441:                    switch (m_imagePos) {
442:                    case Constants.LEFT:
443:                    case Constants.RIGHT:
444:                        // need to set image y-coordinate
445:                        switch (m_vImageAlign) {
446:                        case Constants.TOP:
447:                            break;
448:                        case Constants.BOTTOM:
449:                            iy = shape.getMaxY() - size * m_vertBorder - h;
450:                            break;
451:                        case Constants.CENTER:
452:                            iy = shape.getCenterY() - h / 2;
453:                            break;
454:                        }
455:                        break;
456:                    case Constants.TOP:
457:                    case Constants.BOTTOM:
458:                        // need to set image x-coordinate
459:                        switch (m_hImageAlign) {
460:                        case Constants.LEFT:
461:                            break;
462:                        case Constants.RIGHT:
463:                            ix = shape.getMaxX() - size * m_horizBorder - w;
464:                            break;
465:                        case Constants.CENTER:
466:                            ix = shape.getCenterX() - w / 2;
467:                            break;
468:                        }
469:                        break;
470:                    }
471:
472:                    if (useInt && size == 1.0) {
473:                        // if possible, use integer precision
474:                        // results in faster, flicker-free image rendering
475:                        g.drawImage(img, (int) ix, (int) iy, null);
476:                    } else {
477:                        m_transform.setTransform(size, 0, 0, size, ix, iy);
478:                        g.drawImage(img, m_transform, null);
479:                    }
480:                }
481:
482:                // render text
483:                int textColor = item.getTextColor();
484:                if (text != null && ColorLib.alpha(textColor) > 0) {
485:                    g.setPaint(ColorLib.getColor(textColor));
486:                    g.setFont(m_font);
487:                    FontMetrics fm = DEFAULT_GRAPHICS.getFontMetrics(m_font);
488:
489:                    // compute available width
490:                    double tw;
491:                    switch (m_imagePos) {
492:                    case Constants.TOP:
493:                    case Constants.BOTTOM:
494:                        tw = shape.getWidth() - 2 * size * m_horizBorder;
495:                        break;
496:                    default:
497:                        tw = m_textDim.width;
498:                    }
499:
500:                    // compute available height
501:                    double th;
502:                    switch (m_imagePos) {
503:                    case Constants.LEFT:
504:                    case Constants.RIGHT:
505:                        th = shape.getHeight() - 2 * size * m_vertBorder;
506:                        break;
507:                    default:
508:                        th = m_textDim.height;
509:                    }
510:
511:                    // compute starting y-coordinate
512:                    y += fm.getAscent();
513:                    switch (m_vTextAlign) {
514:                    case Constants.TOP:
515:                        break;
516:                    case Constants.BOTTOM:
517:                        y += th - m_textDim.height;
518:                        break;
519:                    case Constants.CENTER:
520:                        y += (th - m_textDim.height) / 2;
521:                    }
522:
523:                    // render each line of text
524:                    int lh = fm.getHeight(); // the line height
525:                    int start = 0, end = text.indexOf(m_delim);
526:                    for (; end >= 0; y += lh) {
527:                        drawString(g, fm, text.substring(start, end), useInt,
528:                                x, y, tw);
529:                        start = end + 1;
530:                        end = text.indexOf(m_delim, start);
531:                    }
532:                    drawString(g, fm, text.substring(start), useInt, x, y, tw);
533:                }
534:
535:                // draw border
536:                if (type == RENDER_TYPE_DRAW
537:                        || type == RENDER_TYPE_DRAW_AND_FILL) {
538:                    GraphicsLib.paint(g, item, shape, getStroke(item),
539:                            RENDER_TYPE_DRAW);
540:                }
541:            }
542:
543:            private final void drawString(Graphics2D g, FontMetrics fm,
544:                    String text, boolean useInt, double x, double y, double w) {
545:                // compute the x-coordinate
546:                double tx;
547:                switch (m_hTextAlign) {
548:                case Constants.LEFT:
549:                    tx = x;
550:                    break;
551:                case Constants.RIGHT:
552:                    tx = x + w - fm.stringWidth(text);
553:                    break;
554:                case Constants.CENTER:
555:                    tx = x + (w - fm.stringWidth(text)) / 2;
556:                    break;
557:                default:
558:                    throw new IllegalStateException(
559:                            "Unrecognized text alignment setting.");
560:                }
561:                // use integer precision unless zoomed-in
562:                // results in more stable drawing
563:                if (useInt) {
564:                    g.drawString(text, (int) tx, (int) y);
565:                } else {
566:                    g.drawString(text, (float) tx, (float) y);
567:                }
568:            }
569:
570:            /**
571:             * Returns the image factory used by this renderer.
572:             * @return the image factory
573:             */
574:            public ImageFactory getImageFactory() {
575:                if (m_images == null)
576:                    m_images = new ImageFactory();
577:                return m_images;
578:            }
579:
580:            /**
581:             * Sets the image factory used by this renderer.
582:             * @param ifact the image factory
583:             */
584:            public void setImageFactory(ImageFactory ifact) {
585:                m_images = ifact;
586:            }
587:
588:            // ------------------------------------------------------------------------
589:
590:            /**
591:             * Get the horizontal text alignment within the layout. One of
592:             * {@link prefuse.Constants#LEFT}, {@link prefuse.Constants#RIGHT}, or
593:             * {@link prefuse.Constants#CENTER}. The default is centered text.
594:             * @return the horizontal text alignment
595:             */
596:            public int getHorizontalTextAlignment() {
597:                return m_hTextAlign;
598:            }
599:
600:            /**
601:             * Set the horizontal text alignment within the layout. One of
602:             * {@link prefuse.Constants#LEFT}, {@link prefuse.Constants#RIGHT}, or
603:             * {@link prefuse.Constants#CENTER}. The default is centered text.
604:             * @param halign the desired horizontal text alignment
605:             */
606:            public void setHorizontalTextAlignment(int halign) {
607:                if (halign != Constants.LEFT && halign != Constants.RIGHT
608:                        && halign != Constants.CENTER)
609:                    throw new IllegalArgumentException(
610:                            "Illegal horizontal text alignment value.");
611:                m_hTextAlign = halign;
612:            }
613:
614:            /**
615:             * Get the vertical text alignment within the layout. One of
616:             * {@link prefuse.Constants#TOP}, {@link prefuse.Constants#BOTTOM}, or
617:             * {@link prefuse.Constants#CENTER}. The default is centered text.
618:             * @return the vertical text alignment
619:             */
620:            public int getVerticalTextAlignment() {
621:                return m_vTextAlign;
622:            }
623:
624:            /**
625:             * Set the vertical text alignment within the layout. One of
626:             * {@link prefuse.Constants#TOP}, {@link prefuse.Constants#BOTTOM}, or
627:             * {@link prefuse.Constants#CENTER}. The default is centered text.
628:             * @param valign the desired vertical text alignment
629:             */
630:            public void setVerticalTextAlignment(int valign) {
631:                if (valign != Constants.TOP && valign != Constants.BOTTOM
632:                        && valign != Constants.CENTER)
633:                    throw new IllegalArgumentException(
634:                            "Illegal vertical text alignment value.");
635:                m_vTextAlign = valign;
636:            }
637:
638:            /**
639:             * Get the horizontal image alignment within the layout. One of
640:             * {@link prefuse.Constants#LEFT}, {@link prefuse.Constants#RIGHT}, or
641:             * {@link prefuse.Constants#CENTER}. The default is a centered image.
642:             * @return the horizontal image alignment
643:             */
644:            public int getHorizontalImageAlignment() {
645:                return m_hImageAlign;
646:            }
647:
648:            /**
649:             * Set the horizontal image alignment within the layout. One of
650:             * {@link prefuse.Constants#LEFT}, {@link prefuse.Constants#RIGHT}, or
651:             * {@link prefuse.Constants#CENTER}. The default is a centered image.
652:             * @param halign the desired horizontal image alignment
653:             */
654:            public void setHorizontalImageAlignment(int halign) {
655:                if (halign != Constants.LEFT && halign != Constants.RIGHT
656:                        && halign != Constants.CENTER)
657:                    throw new IllegalArgumentException(
658:                            "Illegal horizontal text alignment value.");
659:                m_hImageAlign = halign;
660:            }
661:
662:            /**
663:             * Get the vertical image alignment within the layout. One of
664:             * {@link prefuse.Constants#TOP}, {@link prefuse.Constants#BOTTOM}, or
665:             * {@link prefuse.Constants#CENTER}. The default is a centered image.
666:             * @return the vertical image alignment
667:             */
668:            public int getVerticalImageAlignment() {
669:                return m_vImageAlign;
670:            }
671:
672:            /**
673:             * Set the vertical image alignment within the layout. One of
674:             * {@link prefuse.Constants#TOP}, {@link prefuse.Constants#BOTTOM}, or
675:             * {@link prefuse.Constants#CENTER}. The default is a centered image.
676:             * @param valign the desired vertical image alignment
677:             */
678:            public void setVerticalImageAlignment(int valign) {
679:                if (valign != Constants.TOP && valign != Constants.BOTTOM
680:                        && valign != Constants.CENTER)
681:                    throw new IllegalArgumentException(
682:                            "Illegal vertical text alignment value.");
683:                m_vImageAlign = valign;
684:            }
685:
686:            /**
687:             * Get the image position, determining where the image is placed with
688:             * respect to the text. One of {@link Constants#LEFT},
689:             * {@link Constants#RIGHT}, {@link Constants#TOP}, or
690:             * {@link Constants#BOTTOM}.  The default is left.
691:             * @return the image position
692:             */
693:            public int getImagePosition() {
694:                return m_imagePos;
695:            }
696:
697:            /**
698:             * Set the image position, determining where the image is placed with
699:             * respect to the text. One of {@link Constants#LEFT},
700:             * {@link Constants#RIGHT}, {@link Constants#TOP}, or
701:             * {@link Constants#BOTTOM}.  The default is left.
702:             * @param pos the desired image position
703:             */
704:            public void setImagePosition(int pos) {
705:                if (pos != Constants.TOP && pos != Constants.BOTTOM
706:                        && pos != Constants.LEFT && pos != Constants.RIGHT
707:                        && pos != Constants.CENTER)
708:                    throw new IllegalArgumentException(
709:                            "Illegal image position value.");
710:                m_imagePos = pos;
711:            }
712:
713:            // ------------------------------------------------------------------------
714:
715:            /**
716:             * Get the horizontal alignment of this node with respect to its
717:             * x, y coordinates.
718:             * @return the horizontal alignment, one of
719:             * {@link prefuse.Constants#LEFT}, {@link prefuse.Constants#RIGHT}, or
720:             * {@link prefuse.Constants#CENTER}.
721:             */
722:            public int getHorizontalAlignment() {
723:                return m_xAlign;
724:            }
725:
726:            /**
727:             * Get the vertical alignment of this node with respect to its
728:             * x, y coordinates.
729:             * @return the vertical alignment, one of
730:             * {@link prefuse.Constants#TOP}, {@link prefuse.Constants#BOTTOM}, or
731:             * {@link prefuse.Constants#CENTER}.
732:             */
733:            public int getVerticalAlignment() {
734:                return m_yAlign;
735:            }
736:
737:            /**
738:             * Set the horizontal alignment of this node with respect to its
739:             * x, y coordinates.
740:             * @param align the horizontal alignment, one of
741:             * {@link prefuse.Constants#LEFT}, {@link prefuse.Constants#RIGHT}, or
742:             * {@link prefuse.Constants#CENTER}.
743:             */
744:            public void setHorizontalAlignment(int align) {
745:                m_xAlign = align;
746:            }
747:
748:            /**
749:             * Set the vertical alignment of this node with respect to its
750:             * x, y coordinates.
751:             * @param align the vertical alignment, one of
752:             * {@link prefuse.Constants#TOP}, {@link prefuse.Constants#BOTTOM}, or
753:             * {@link prefuse.Constants#CENTER}.
754:             */
755:            public void setVerticalAlignment(int align) {
756:                m_yAlign = align;
757:            }
758:
759:            /**
760:             * Returns the amount of padding in pixels between the content 
761:             * and the border of this item along the horizontal dimension.
762:             * @return the horizontal padding
763:             */
764:            public int getHorizontalPadding() {
765:                return m_horizBorder;
766:            }
767:
768:            /**
769:             * Sets the amount of padding in pixels between the content 
770:             * and the border of this item along the horizontal dimension.
771:             * @param xpad the horizontal padding to set
772:             */
773:            public void setHorizontalPadding(int xpad) {
774:                m_horizBorder = xpad;
775:            }
776:
777:            /**
778:             * Returns the amount of padding in pixels between the content 
779:             * and the border of this item along the vertical dimension.
780:             * @return the vertical padding
781:             */
782:            public int getVerticalPadding() {
783:                return m_vertBorder;
784:            }
785:
786:            /**
787:             * Sets the amount of padding in pixels between the content 
788:             * and the border of this item along the vertical dimension.
789:             * @param ypad the vertical padding
790:             */
791:            public void setVerticalPadding(int ypad) {
792:                m_vertBorder = ypad;
793:            }
794:
795:            /**
796:             * Get the padding, in pixels, between an image and text.
797:             * @return the padding between an image and text
798:             */
799:            public int getImageTextPadding() {
800:                return m_imageMargin;
801:            }
802:
803:            /**
804:             * Set the padding, in pixels, between an image and text.
805:             * @param pad the padding to use between an image and text
806:             */
807:            public void setImageTextPadding(int pad) {
808:                m_imageMargin = pad;
809:            }
810:
811:        } // end of class LabelRenderer
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.