1 /*
2 * Copyright (c) 2002, 2016, 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
178 if ((c instanceof JButton) && ((JButton)c).isDefaultButton()) {
179 state |= DEFAULT;
180 }
181 return state;
182 }
183
184 /**
185 * {@inheritDoc}
186 */
187 @Override
188 public int getBaseline(JComponent c, int width, int height) {
189 if (c == null) {
190 throw new NullPointerException("Component must be non-null");
191 }
192 if (width < 0 || height < 0) {
193 throw new IllegalArgumentException(
194 "Width and height must be >= 0");
195 }
196 AbstractButton b = (AbstractButton)c;
197 String text = b.getText();
198 if (text == null || "".equals(text)) {
199 return -1;
200 }
201 Insets i = b.getInsets();
202 Rectangle viewRect = new Rectangle();
203 Rectangle textRect = new Rectangle();
204 Rectangle iconRect = new Rectangle();
205 viewRect.x = i.left;
206 viewRect.y = i.top;
207 viewRect.width = width - (i.right + viewRect.x);
208 viewRect.height = height - (i.bottom + viewRect.y);
209
210 // layout the text and icon
211 SynthContext context = getContext(b);
212 SynthStyle style;
213 if (context.getStyle() != null) {
214 style = context.getStyle();
215 } else {
216 style = SynthLookAndFeel.updateStyle(context, this);
217 }
218 FontMetrics fm = context.getComponent().getFontMetrics(
|
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
178 if ((c instanceof JButton) && ((JButton)c).isDefaultButton()) {
179 state |= DEFAULT;
180 }
181 return state;
182 }
183
184 /**
185 * {@inheritDoc}
186 */
187 @Override
188 public int getBaseline(JComponent c, int width, int height) {
189 if (c == null) {
190 throw new NullPointerException("Component must be non-null");
191 }
192 if (width < 0 || height < 0) {
193 throw new IllegalArgumentException(
194 "Width and height must be >= 0");
195 }
196 AbstractButton b = (AbstractButton)c;
197 String text = b.getText();
198 if (text == null || text.isEmpty()) {
199 return -1;
200 }
201 Insets i = b.getInsets();
202 Rectangle viewRect = new Rectangle();
203 Rectangle textRect = new Rectangle();
204 Rectangle iconRect = new Rectangle();
205 viewRect.x = i.left;
206 viewRect.y = i.top;
207 viewRect.width = width - (i.right + viewRect.x);
208 viewRect.height = height - (i.bottom + viewRect.y);
209
210 // layout the text and icon
211 SynthContext context = getContext(b);
212 SynthStyle style;
213 if (context.getStyle() != null) {
214 style = context.getStyle();
215 } else {
216 style = SynthLookAndFeel.updateStyle(context, this);
217 }
218 FontMetrics fm = context.getComponent().getFontMetrics(
|