root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / com / izforge / izpack / gui / LabelFactory.java @ 15280
History | View | Annotate | Download (4.14 KB)
1 | 15280 | rgaitan | /*
|
---|---|---|---|
2 | * $Id: LabelFactory.java,v 1.1 2006/06/14 07:29:07 cesar Exp $
|
||
3 | * IzPack
|
||
4 | * Copyright (C) 2004 Klaus Bartz
|
||
5 | *
|
||
6 | * File : LabelFactory.java
|
||
7 | * Description : A LabelFactory.
|
||
8 | * Author's email : bartzkau@users.berlios.de
|
||
9 | *
|
||
10 | * This program is free software; you can redistribute it and/or
|
||
11 | * modify it under the terms of the GNU General Public License
|
||
12 | * as published by the Free Software Foundation; either version 2
|
||
13 | * of the License, or any later version.
|
||
14 | *
|
||
15 | * This program is distributed in the hope that it will be useful,
|
||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
18 | * GNU General Public License for more details.
|
||
19 | *
|
||
20 | * You should have received a copy of the GNU General Public License
|
||
21 | * along with this program; if not, write to the Free Software
|
||
22 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||
23 | */
|
||
24 | package com.izforge.izpack.gui; |
||
25 | |||
26 | import javax.swing.Icon; |
||
27 | import javax.swing.JLabel; |
||
28 | import javax.swing.SwingConstants; |
||
29 | |||
30 | /**
|
||
31 | * <p>A label factory which can handle modified look like to
|
||
32 | * present icons or present it not.</p>
|
||
33 | *
|
||
34 | * @author Klaus Bartz
|
||
35 | *
|
||
36 | */
|
||
37 | public class LabelFactory implements SwingConstants |
||
38 | { |
||
39 | |||
40 | private static boolean useLabelIcons = true; |
||
41 | /**
|
||
42 | * Returns whether the factory creates labels with
|
||
43 | * icons or without icons.
|
||
44 | * @return whether the factory creates labels with
|
||
45 | * icons or without icons
|
||
46 | */
|
||
47 | public static boolean isUseLabelIcons() |
||
48 | { |
||
49 | return useLabelIcons;
|
||
50 | } |
||
51 | |||
52 | /**
|
||
53 | * Sets the use icon state.
|
||
54 | * @param b flag for the icon state
|
||
55 | */
|
||
56 | public static void setUseLabelIcons(boolean b) |
||
57 | { |
||
58 | useLabelIcons = b; |
||
59 | } |
||
60 | /**
|
||
61 | * Returns a new JLabel with the horizontal alignment CENTER.
|
||
62 | * If isUseLabelIcons is true, the given image will be set
|
||
63 | * to the label, else an empty label returns.
|
||
64 | * @param image the image to be used as label icon
|
||
65 | * @return new JLabel with the given parameters
|
||
66 | */
|
||
67 | public static JLabel create( Icon image ) |
||
68 | { |
||
69 | return( create( image, CENTER ) );
|
||
70 | |||
71 | } |
||
72 | |||
73 | /**
|
||
74 | * Returns a new JLabel with the given horizontal alignment.
|
||
75 | * If isUseLabelIcons is true, the given image will be set
|
||
76 | * to the label, else an empty label returns.
|
||
77 | * @param image the image to be used as label icon
|
||
78 | * @param horizontalAlignment horizontal alignment of the label
|
||
79 | * @return new JLabel with the given parameters
|
||
80 | */
|
||
81 | public static JLabel create( Icon image , int horizontalAlignment) |
||
82 | { |
||
83 | return( create( null, image, horizontalAlignment ) ); |
||
84 | |||
85 | } |
||
86 | |||
87 | /**
|
||
88 | * Returns a new JLabel with the horizontal alignment CENTER.
|
||
89 | * @param text the text to be set
|
||
90 | * @return new JLabel with the given parameters
|
||
91 | */
|
||
92 | public static JLabel create( String text ) |
||
93 | { |
||
94 | return( create( text, CENTER ) );
|
||
95 | |||
96 | } |
||
97 | |||
98 | /**
|
||
99 | * Returns a new JLabel with the given horizontal alignment.
|
||
100 | * @param text the text to be set
|
||
101 | * @param horizontalAlignment horizontal alignment of the label
|
||
102 | * @return new JLabel with the given parameters
|
||
103 | */
|
||
104 | public static JLabel create( String text , int horizontalAlignment) |
||
105 | { |
||
106 | return( create( text, null, horizontalAlignment ) ); |
||
107 | |||
108 | } |
||
109 | |||
110 | /**
|
||
111 | * Returns a new JLabel with the given horizontal alignment.
|
||
112 | * If isUseLabelIcons is true, the given image will be set
|
||
113 | * to the label. The given text will be set allways to the label.
|
||
114 | * It is allowed, that image and/or text are null.
|
||
115 | * @param text the text to be set
|
||
116 | * @param image the image to be used as label icon
|
||
117 | * @param horizontalAlignment horizontal alignment of the label
|
||
118 | * @return new JLabel with the given parameters
|
||
119 | */
|
||
120 | public static JLabel create( String text, Icon image, int horizontalAlignment ) |
||
121 | { |
||
122 | JLabel retval = null; |
||
123 | if( image != null && isUseLabelIcons()) |
||
124 | { |
||
125 | retval = new JLabel( image ); |
||
126 | } |
||
127 | else
|
||
128 | { |
||
129 | retval = new JLabel( ); |
||
130 | } |
||
131 | if( text != null ) |
||
132 | retval.setText(text); |
||
133 | retval.setHorizontalAlignment(horizontalAlignment); |
||
134 | return( retval );
|
||
135 | } |
||
136 | } |