summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/TabbedPanel.java
blob: 5de0751510599009ead123d8b99cde36a16e4996 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*     */ package NET.worlds.scape;
/*     */ 
/*     */ import NET.worlds.console.Console;
/*     */ import NET.worlds.console.DialogDisabled;
/*     */ import java.awt.BorderLayout;
/*     */ import java.awt.Color;
/*     */ import java.awt.Component;
/*     */ import java.awt.Dimension;
/*     */ import java.awt.Event;
/*     */ import java.awt.Font;
/*     */ import java.awt.FontMetrics;
/*     */ import java.awt.Graphics;
/*     */ import java.awt.Insets;
/*     */ import java.awt.Panel;
/*     */ import java.awt.Point;
/*     */ import java.util.Vector;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TabbedPanel
/*     */   extends Panel
/*     */   implements ClickEventHandler, DialogDisabled
/*     */ {
/*     */   private static final long serialVersionUID = 1L;
/*  36 */   private Vector<String> entries = new Vector();
/*     */   private int rows;
/*     */   private int itemWidth;
/*     */   private int itemHeight;
/*     */   private int itemsPerRow;
/*     */   private int choice;
/*     */   private Font nFont;
/*     */   private FontMetrics nFontMetrics;
/*     */   private Font bFont;
/*     */   private FontMetrics bFontMetrics;
/*     */   private int fontHeight;
/*  47 */   private TabbedDisplayPanel disp = new TabbedDisplayPanel();
/*     */   private ClickEventHandler handler;
/*     */   private boolean needRecalc;
/*     */   private boolean isDialogDisabled;
/*     */   
/*     */   public TabbedPanel(ClickEventHandler handler)
/*     */   {
/*  54 */     this.handler = handler;
/*  55 */     setLayout(new BorderLayout());
/*  56 */     add("Center", this.disp);
/*     */   }
/*     */   
/*     */   public TabbedPanel()
/*     */   {
/*  61 */     this(null);
/*  62 */     this.handler = this;
/*     */   }
/*     */   
/*     */   public void addItem(String name, Component c)
/*     */   {
/*  67 */     this.entries.addElement(name);
/*  68 */     this.needRecalc = true;
/*  69 */     repaint();
/*  70 */     this.disp.addItem(c);
/*     */   }
/*     */   
/*     */   public void insertItem(int index, String name, Component c)
/*     */   {
/*  75 */     this.entries.insertElementAt(name, index);
/*  76 */     this.disp.insertItem(index, c);
/*  77 */     if (index <= this.choice)
/*  78 */       this.choice = Math.min(this.choice + 1, this.entries.size() - 1);
/*  79 */     this.needRecalc = true;
/*  80 */     repaint();
/*     */   }
/*     */   
/*     */   public void removeItem(int index)
/*     */   {
/*  85 */     this.entries.removeElementAt(index);
/*  86 */     this.disp.removeItem(index);
/*  87 */     if (index == this.choice) {
/*  88 */       int count = this.entries.size();
/*  89 */       if (count > 0) {
/*  90 */         this.choice = Math.min(this.choice, count - 1);
/*  91 */         this.disp.setChoice(this.choice);
/*     */       }
/*     */     }
/*  94 */     else if (index < this.choice) {
/*  95 */       this.choice -= 1; }
/*  96 */     this.needRecalc = true;
/*  97 */     repaint();
/*     */   }
/*     */   
/*     */   public void select(int index)
/*     */   {
/* 102 */     this.choice = index;
/* 103 */     repaint();
/* 104 */     this.disp.setChoice(index);
/*     */   }
/*     */   
/*     */   public String getName(int index)
/*     */   {
/* 109 */     return (String)this.entries.elementAt(index);
/*     */   }
/*     */   
/*     */   public void setName(int index, String name)
/*     */   {
/* 114 */     this.entries.setElementAt(name, index);
/* 115 */     this.needRecalc = true;
/* 116 */     repaint();
/*     */   }
/*     */   
/*     */   public Component getComponent(int index)
/*     */   {
/* 121 */     if (index < this.entries.size())
/* 122 */       return this.disp.getComponent(index);
/* 123 */     return null;
/*     */   }
/*     */   
/*     */   public int selected()
/*     */   {
/* 128 */     return this.choice;
/*     */   }
/*     */   
/*     */   public int itemAt(Point p)
/*     */   {
/* 133 */     if (!this.needRecalc) {
/* 134 */       Point tab = new Point(0, 0);
/* 135 */       int count = this.entries.size();
/* 136 */       for (int i = 0; i < count; i++) {
/* 137 */         getPosition(i, tab);
/* 138 */         if ((p.x >= tab.x) && (p.y >= tab.y) && (p.x < tab.x + this.itemWidth) && 
/* 139 */           (p.y < tab.y + this.itemHeight))
/* 140 */           return i;
/*     */       }
/*     */     }
/* 143 */     return -1;
/*     */   }
/*     */   
/*     */   public void addNotify()
/*     */   {
/* 148 */     super.addNotify();
/* 149 */     this.nFont = new Font(Console.message("NotifyFont"), 0, 13);
/*     */     
/* 151 */     this.nFontMetrics = getFontMetrics(this.nFont);
/* 152 */     this.bFont = new Font(Console.message("NotifyFont"), 1, 14);
/*     */     
/* 154 */     this.bFontMetrics = getFontMetrics(this.bFont);
/* 155 */     this.fontHeight = Math.max(this.nFontMetrics.getHeight(), 
/* 156 */       this.bFontMetrics.getHeight());
/* 157 */     this.itemHeight = (this.fontHeight + 5);
/*     */   }
/*     */   
/*     */   public Insets insets()
/*     */   {
/* 162 */     if (this.needRecalc)
/* 163 */       recalc();
/* 164 */     return new Insets(this.rows * this.itemHeight, 0, 0, 0);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public void setBounds(int x, int y, int width, int height)
/*     */   {
/* 175 */     super.setBounds(x, y, width, height);
/* 176 */     this.needRecalc = true;
/* 177 */     repaint();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   private void recalc()
/*     */   {
/* 185 */     int count = this.entries.size();
/* 186 */     this.itemWidth = 0;
/* 187 */     for (int i = 0; i < count; i++) {
/* 188 */       String name = (String)this.entries.elementAt(i);
/* 189 */       int w = Math.max(this.bFontMetrics.stringWidth(name), 
/* 190 */         this.nFontMetrics.stringWidth(" " + name + " "));
/* 191 */       this.itemWidth = Math.max(w, this.itemWidth);
/*     */     }
/* 193 */     this.itemWidth += 4;
/* 194 */     this.itemsPerRow = Math.max(1, getSize().width / this.itemWidth);
/* 195 */     this.rows = ((count + this.itemsPerRow - 1) / this.itemsPerRow);
/* 196 */     this.needRecalc = false;
/* 197 */     invalidate();
/* 198 */     validate();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private void getPosition(int entry, Point pos)
/*     */   {
/* 207 */     int entryRow = entry / this.itemsPerRow;
/* 208 */     int displayRow = entryRow;
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 221 */     int column = entry - entryRow * this.itemsPerRow;
/* 222 */     pos.x = (column * this.itemWidth);
/* 223 */     pos.y = ((this.rows - 1 - displayRow) * this.itemHeight - 2);
/*     */   }
/*     */   
/*     */   private static void vLine(Graphics g, int x1, int y1, int y2)
/*     */   {
/* 228 */     g.drawLine(x1, y1, x1, y2);
/*     */   }
/*     */   
/*     */   private static void hLine(Graphics g, int x1, int y1, int x2)
/*     */   {
/* 233 */     g.drawLine(x1, y1, x2, y1);
/*     */   }
/*     */   
/*     */   public void paint(Graphics g)
/*     */   {
/* 238 */     if (this.needRecalc) {
/* 239 */       recalc();
/*     */     }
/* 241 */     g.setColor(getBackground());
/* 242 */     g.fillRect(0, 0, getSize().width, getSize().height);
/*     */     
/* 244 */     int count = this.entries.size();
/* 245 */     if (count != 0) {
/* 246 */       Point p = new Point(0, 0);
/* 247 */       int maxWidth = this.itemWidth - 4;
/* 248 */       for (int i = 0; i < count; i++) {
/* 249 */         getPosition(i, p);
/* 250 */         String ent = (String)this.entries.elementAt(i);
/* 251 */         int x1 = p.x;
/* 252 */         int y1 = p.y + 4;
/* 253 */         int y2 = y1 + this.fontHeight;
/* 254 */         int yFont = y1;
/* 255 */         Font font = this.nFont;
/* 256 */         FontMetrics fm = this.nFontMetrics;
/* 257 */         boolean selected = i == this.choice;
/* 258 */         if (selected) {
/* 259 */           y1 = p.y + 2;
/* 260 */           y2 = y1 + this.fontHeight + 4;
/* 261 */           yFont = y1 + 1;
/* 262 */           font = this.bFont;
/* 263 */           fm = this.bFontMetrics;
/*     */         }
/* 265 */         int width = fm.stringWidth(ent);
/* 266 */         int spacing = (maxWidth - width) / 2;
/* 267 */         int x2 = x1 + maxWidth;
/* 268 */         g.setFont(font);
/* 269 */         g.setColor(getBackground().brighter());
/* 270 */         if (selected) {
/* 271 */           hLine(g, 0, y2, x1);
/* 272 */           hLine(g, x2 + 3, y2, getSize().width);
/*     */         }
/* 274 */         vLine(g, x1, y2, y1 + 2);
/* 275 */         g.drawLine(x1, y1 + 2, x1 + 2, y1);
/* 276 */         hLine(g, x1 + 2, y1, x2);
/* 277 */         g.setColor(getBackground().darker());
/* 278 */         vLine(g, x2 + 1, y1 + 1, y2);
/* 279 */         vLine(g, x2 + 2, y1 + 2, y2);
/* 280 */         g.setColor(getForeground());
/* 281 */         g.drawString(ent, x1 + 1 + spacing, yFont + 
/* 282 */           fm.getAscent() + fm.getLeading());
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public void clickEvent(Component who, Point location, int flags) {}
/*     */   
/*     */   @Deprecated
/*     */   public boolean mouseDown(Event event, int x, int y)
/*     */   {
/* 292 */     Point p = new Point(x, y);
/* 293 */     int tmp = itemAt(p);
/* 294 */     if (tmp != -1) {
/* 295 */       this.choice = tmp;
/* 296 */       repaint();
/* 297 */       this.disp.setChoice(this.choice);
/* 298 */       int flags = 1;
/* 299 */       if (event.metaDown())
/* 300 */         flags |= 0x4;
/* 301 */       this.handler.clickEvent(this, p, flags);
/* 302 */       return true;
/*     */     }
/* 304 */     return false;
/*     */   }
/*     */   
/*     */   @Deprecated
/*     */   public boolean handleEvent(Event event)
/*     */   {
/* 310 */     if (this.isDialogDisabled)
/* 311 */       return false;
/* 312 */     return super.handleEvent(event);
/*     */   }
/*     */   
/*     */   public void dialogDisable(boolean disable)
/*     */   {
/* 317 */     this.isDialogDisabled = disable;
/* 318 */     Component c = getComponent(selected());
/* 319 */     if ((c != null) && ((c instanceof DialogDisabled))) {
/* 320 */       ((DialogDisabled)c).dialogDisable(disable);
/*     */     }
/*     */   }
/*     */ }


/* Location:              C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\TabbedPanel.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */