1 /*
2 * Copyright (c) 1996, 2015, 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
43 FontMetrics fm = getFontMetrics(((Choice)target).getFont());
44 Choice c = (Choice)target;
45 int w = 0;
46 for (int i = c.getItemCount() ; i-- > 0 ;) {
47 w = Math.max(fm.stringWidth(c.getItem(i)), w);
48 }
49 return new Dimension(28 + w, Math.max(fm.getHeight() + 6, 15));
50 }
51 @Override
52 public boolean isFocusable() {
53 return true;
54 }
55
56 // ChoicePeer implementation
57
58 @Override
59 public native void select(int index);
60
61 @Override
62 public void add(String item, int index) {
63 addItem(item, index);
64 }
65
66 @Override
67 public boolean shouldClearRectBeforePaint() {
68 return false;
69 }
70
71 @Override
72 public native void removeAll();
73 @Override
74 public native void remove(int index);
75
76 /**
77 * DEPRECATED, but for now, called by add(String, int).
78 */
79 public void addItem(String item, int index) {
80 addItems(new String[] {item}, index);
81 }
82 public native void addItems(String[] items, int index);
83
84 @Override
85 public synchronized native void reshape(int x, int y, int width, int height);
86
87 private WindowListener windowListener;
88
89 // Toolkit & peer internals
90
91 WChoicePeer(Choice target) {
92 super(target);
93 }
94
95 @Override
96 native void create(WComponentPeer parent);
97
98 @Override
99 void initialize() {
100 Choice opt = (Choice)target;
101 int itemCount = opt.getItemCount();
|
1 /*
2 * Copyright (c) 1996, 2018, 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
43 FontMetrics fm = getFontMetrics(((Choice)target).getFont());
44 Choice c = (Choice)target;
45 int w = 0;
46 for (int i = c.getItemCount() ; i-- > 0 ;) {
47 w = Math.max(fm.stringWidth(c.getItem(i)), w);
48 }
49 return new Dimension(28 + w, Math.max(fm.getHeight() + 6, 15));
50 }
51 @Override
52 public boolean isFocusable() {
53 return true;
54 }
55
56 // ChoicePeer implementation
57
58 @Override
59 public native void select(int index);
60
61 @Override
62 public void add(String item, int index) {
63 addItems(new String[] {item}, index);
64 }
65
66 @Override
67 public boolean shouldClearRectBeforePaint() {
68 return false;
69 }
70
71 @Override
72 public native void removeAll();
73 @Override
74 public native void remove(int index);
75
76 public native void addItems(String[] items, int index);
77
78 @Override
79 public synchronized native void reshape(int x, int y, int width, int height);
80
81 private WindowListener windowListener;
82
83 // Toolkit & peer internals
84
85 WChoicePeer(Choice target) {
86 super(target);
87 }
88
89 @Override
90 native void create(WComponentPeer parent);
91
92 @Override
93 void initialize() {
94 Choice opt = (Choice)target;
95 int itemCount = opt.getItemCount();
|