KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > fakepeer > FakeListPeer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.modules.form.fakepeer;
22
23 import java.awt.*;
24
25 /**
26  *
27  * @author Tran Duc Trung
28  */

29 class FakeListPeer extends FakeComponentPeer
30 {
31     FakeListPeer(List target) {
32         super(target);
33     }
34
35     Component createDelegate() {
36         return new Delegate();
37     }
38
39     public int[] getSelectedIndexes() {
40         return new int[0];
41     }
42
43     public void add(String JavaDoc item, int index) {
44     }
45
46     public void delItems(int start, int end) {
47     }
48
49     public void removeAll() {
50     }
51
52     public void select(int index) {
53     }
54
55     public void deselect(int index) {
56     }
57
58     public void makeVisible(int index) {
59     }
60
61     public void setMultipleMode(boolean b) {
62     }
63
64     public Dimension getPreferredSize(int rows) {
65         return new Dimension(40, 80);
66     }
67
68     public Dimension getMinimumSize(int rows) {
69         return new Dimension(40, 80);
70     }
71
72     public void addItem(String JavaDoc item, int index) {
73         add(item, index);
74     }
75
76     public void clear() {
77         removeAll();
78     }
79
80     public void setMultipleSelections(boolean v) {
81         setMultipleMode(v);
82     }
83
84     public Dimension preferredSize(int rows) {
85         return getPreferredSize(rows);
86     }
87
88     public Dimension minimumSize(int rows) {
89         return getMinimumSize(rows);
90     }
91
92     //
93
//
94
//
95

96     private class Delegate extends Component
97     {
98         Delegate() {
99             this.setBackground(SystemColor.window);
100             this.setForeground(SystemColor.windowText);
101         }
102         
103         public void paint(Graphics g) {
104             List target =(List) _target;
105             Dimension sz = target.getSize();
106             int w = sz.width;
107             int h = sz.height;
108
109             g.setColor(target.getBackground());
110             FakePeerUtils.drawLoweredBox(g,0,0,w,h);
111
112             int n = target.getItemCount();
113             if (n <= 0)
114                 return;
115
116             if (target.isEnabled()) {
117                 g.setColor(target.getForeground());
118             }
119             else {
120                 g.setColor(SystemColor.controlShadow);
121             }
122             
123             g.setFont(target.getFont());
124             g.setClip(1,1,w-5,h-4);
125
126             FontMetrics fm = g.getFontMetrics();
127             int th = fm.getHeight(),
128                 ty = th+2;
129             
130             for (int i=0; i < n; i++) {
131                 g.drawString(target.getItem(i), 4, ty);
132                 if (ty > h) break;
133                 ty += th;
134             }
135         }
136
137         public Dimension getMinimumSize() {
138             return FakeListPeer.this.getMinimumSize(1);
139         }
140     }
141 }
142
Popular Tags