1 /*
2 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
98 state == SynthConstants.ENABLED) {
99 state = SynthLookAndFeel.getSelectedUIState() | SynthConstants.ENABLED;
100 }
101 return state;
102 }
103
104 /**
105 * {@inheritDoc}
106 */
107 @Override
108 public int getBaseline(JComponent c, int width, int height) {
109 if (c == null) {
110 throw new NullPointerException("Component must be non-null");
111 }
112 if (width < 0 || height < 0) {
113 throw new IllegalArgumentException(
114 "Width and height must be >= 0");
115 }
116 JLabel label = (JLabel)c;
117 String text = label.getText();
118 if (text == null || "".equals(text)) {
119 return -1;
120 }
121 Insets i = label.getInsets();
122 Rectangle viewRect = new Rectangle();
123 Rectangle textRect = new Rectangle();
124 Rectangle iconRect = new Rectangle();
125 viewRect.x = i.left;
126 viewRect.y = i.top;
127 viewRect.width = width - (i.right + viewRect.x);
128 viewRect.height = height - (i.bottom + viewRect.y);
129
130 // layout the text and icon
131 SynthContext context = getContext(label);
132 FontMetrics fm = context.getComponent().getFontMetrics(
133 context.getStyle().getFont(context));
134 context.getStyle().getGraphicsUtils(context).layoutText(
135 context, fm, label.getText(), label.getIcon(),
136 label.getHorizontalAlignment(), label.getVerticalAlignment(),
137 label.getHorizontalTextPosition(), label.getVerticalTextPosition(),
138 viewRect, iconRect, textRect, label.getIconTextGap());
|
1 /*
2 * Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
98 state == SynthConstants.ENABLED) {
99 state = SynthLookAndFeel.getSelectedUIState() | SynthConstants.ENABLED;
100 }
101 return state;
102 }
103
104 /**
105 * {@inheritDoc}
106 */
107 @Override
108 public int getBaseline(JComponent c, int width, int height) {
109 if (c == null) {
110 throw new NullPointerException("Component must be non-null");
111 }
112 if (width < 0 || height < 0) {
113 throw new IllegalArgumentException(
114 "Width and height must be >= 0");
115 }
116 JLabel label = (JLabel)c;
117 String text = label.getText();
118 if (text == null || text.isEmpty()) {
119 return -1;
120 }
121 Insets i = label.getInsets();
122 Rectangle viewRect = new Rectangle();
123 Rectangle textRect = new Rectangle();
124 Rectangle iconRect = new Rectangle();
125 viewRect.x = i.left;
126 viewRect.y = i.top;
127 viewRect.width = width - (i.right + viewRect.x);
128 viewRect.height = height - (i.bottom + viewRect.y);
129
130 // layout the text and icon
131 SynthContext context = getContext(label);
132 FontMetrics fm = context.getComponent().getFontMetrics(
133 context.getStyle().getFont(context));
134 context.getStyle().getGraphicsUtils(context).layoutText(
135 context, fm, label.getText(), label.getIcon(),
136 label.getHorizontalAlignment(), label.getVerticalAlignment(),
137 label.getHorizontalTextPosition(), label.getVerticalTextPosition(),
138 viewRect, iconRect, textRect, label.getIconTextGap());
|