1 /*
2 * Copyright (c) 2011, 2012, 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
163 final int baseline = (metrics.titleBarHeight + fm.getAscent() - fm.getLeading() - fm.getDescent()) / 2;
164
165 // max button is the rightmost so use it
166 final int usedWidth = fThisLeftSideTotal + sRightSideTitleClip;
167 int iconWidth = getIconWidth(frame);
168 if (iconWidth > 0) iconWidth += sAfterIconPad;
169
170 final int totalWidth = w;
171
172 // window title looks like: | 0 0 0(sAfterButtonPad)IconWidth Title(right pad) |
173 final int availTextWidth = totalWidth - usedWidth - iconWidth - sAfterButtonPad;
174
175 final String title = frame.getTitle();
176
177 String text = title;
178 int totalTextWidth = 0;
179
180 int startXPosition = fThisLeftSideTotal;
181 boolean wasTextShortened = false;
182 // shorten the string to fit in the
183 if ((text != null) && !(text.equals(""))) {
184 totalTextWidth = SwingUtilities.computeStringWidth(fm, text);
185 final String clipString = "\u2026";
186 if (totalTextWidth > availTextWidth) {
187 wasTextShortened = true;
188 totalTextWidth = SwingUtilities.computeStringWidth(fm, clipString);
189 int nChars;
190 for (nChars = 0; nChars < text.length(); nChars++) {
191 final int nextCharWidth = fm.charWidth(text.charAt(nChars));
192 if ((totalTextWidth + nextCharWidth) > availTextWidth) {
193 break;
194 }
195 totalTextWidth += nextCharWidth;
196 }
197 text = text.substring(0, nChars) + clipString;
198 }
199
200 if (!wasTextShortened) {
201 // center it!
202 startXPosition = (totalWidth - (totalTextWidth + iconWidth)) / 2;
203 if (startXPosition < fThisLeftSideTotal) {
|
1 /*
2 * Copyright (c) 2011, 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
163 final int baseline = (metrics.titleBarHeight + fm.getAscent() - fm.getLeading() - fm.getDescent()) / 2;
164
165 // max button is the rightmost so use it
166 final int usedWidth = fThisLeftSideTotal + sRightSideTitleClip;
167 int iconWidth = getIconWidth(frame);
168 if (iconWidth > 0) iconWidth += sAfterIconPad;
169
170 final int totalWidth = w;
171
172 // window title looks like: | 0 0 0(sAfterButtonPad)IconWidth Title(right pad) |
173 final int availTextWidth = totalWidth - usedWidth - iconWidth - sAfterButtonPad;
174
175 final String title = frame.getTitle();
176
177 String text = title;
178 int totalTextWidth = 0;
179
180 int startXPosition = fThisLeftSideTotal;
181 boolean wasTextShortened = false;
182 // shorten the string to fit in the
183 if (text != null && !text.isEmpty()) {
184 totalTextWidth = SwingUtilities.computeStringWidth(fm, text);
185 final String clipString = "\u2026";
186 if (totalTextWidth > availTextWidth) {
187 wasTextShortened = true;
188 totalTextWidth = SwingUtilities.computeStringWidth(fm, clipString);
189 int nChars;
190 for (nChars = 0; nChars < text.length(); nChars++) {
191 final int nextCharWidth = fm.charWidth(text.charAt(nChars));
192 if ((totalTextWidth + nextCharWidth) > availTextWidth) {
193 break;
194 }
195 totalTextWidth += nextCharWidth;
196 }
197 text = text.substring(0, nChars) + clipString;
198 }
199
200 if (!wasTextShortened) {
201 // center it!
202 startXPosition = (totalWidth - (totalTextWidth + iconWidth)) / 2;
203 if (startXPosition < fThisLeftSideTotal) {
|