OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [javax/] [swing/] [plaf/] [multi/] [MultiFileChooserUI.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* MultiFileChooserUI.java --
2
   Copyright (C) 2005 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
package javax.swing.plaf.multi;
39
 
40
import java.awt.Dimension;
41
import java.awt.Graphics;
42
import java.io.File;
43
import java.util.Iterator;
44
import java.util.Vector;
45
 
46
import javax.accessibility.Accessible;
47
import javax.swing.JComponent;
48
import javax.swing.JFileChooser;
49
import javax.swing.LookAndFeel;
50
import javax.swing.UIManager;
51
import javax.swing.filechooser.FileFilter;
52
import javax.swing.filechooser.FileView;
53
import javax.swing.plaf.ComponentUI;
54
import javax.swing.plaf.FileChooserUI;
55
 
56
/**
57
 * A UI delegate that that coordinates multiple {@link FileChooserUI}
58
 * instances, one from the primary look and feel, and one or more from the
59
 * auxiliary look and feel(s).
60
 *
61
 * @see UIManager#addAuxiliaryLookAndFeel(LookAndFeel)
62
 */
63
public class MultiFileChooserUI extends FileChooserUI
64
{
65
 
66
  /** A list of references to the actual component UIs. */
67
  protected Vector uis;
68
 
69
  /**
70
   * Creates a new <code>MultiFileChooserUI</code> instance.
71
   *
72
   * @see #createUI(JComponent)
73
   */
74
  public MultiFileChooserUI()
75
  {
76
    uis = new Vector();
77
  }
78
 
79
  /**
80
   * Creates a delegate object for the specified component.  If any auxiliary
81
   * look and feels support this component, a <code>MultiFileChooserUI</code> is
82
   * returned, otherwise the UI from the default look and feel is returned.
83
   *
84
   * @param target  the component.
85
   *
86
   * @see MultiLookAndFeel#createUIs(ComponentUI, Vector, JComponent)
87
   */
88
  public static ComponentUI createUI(JComponent target)
89
  {
90
    MultiFileChooserUI mui = new MultiFileChooserUI();
91
    return MultiLookAndFeel.createUIs(mui, mui.uis, target);
92
  }
93
 
94
  /**
95
   * Calls the {@link ComponentUI#installUI(JComponent)} method for all
96
   * the UI delegates managed by this <code>MultiFileChooserUI</code>.
97
   *
98
   * @param c  the component.
99
   */
100
  public void installUI(JComponent c)
101
  {
102
    Iterator iterator = uis.iterator();
103
    while (iterator.hasNext())
104
    {
105
      ComponentUI ui = (ComponentUI) iterator.next();
106
      ui.installUI(c);
107
    }
108
  }
109
 
110
  /**
111
   * Calls the {@link ComponentUI#uninstallUI(JComponent)} method for all
112
   * the UI delegates managed by this <code>MultiFileChooserUI</code>.
113
   *
114
   * @param c  the component.
115
   */
116
  public void uninstallUI(JComponent c)
117
  {
118
    Iterator iterator = uis.iterator();
119
    while (iterator.hasNext())
120
    {
121
      ComponentUI ui = (ComponentUI) iterator.next();
122
      ui.uninstallUI(c);
123
    }
124
  }
125
 
126
  /**
127
   * Returns an array containing the UI delegates managed by this
128
   * <code>MultiFileChooserUI</code>.  The first item in the array is always
129
   * the UI delegate from the installed default look and feel.
130
   *
131
   * @return An array of UI delegates.
132
   */
133
  public ComponentUI[] getUIs()
134
  {
135
    return MultiLookAndFeel.uisToArray(uis);
136
  }
137
 
138
  /**
139
   * Calls the {@link ComponentUI#contains(JComponent, int, int)} method for all
140
   * the UI delegates managed by this <code>MultiFileChooserUI</code>,
141
   * returning the result for the UI delegate from the primary look and
142
   * feel.
143
   *
144
   * @param c  the component.
145
   * @param x  the x-coordinate.
146
   * @param y  the y-coordinate.
147
   *
148
   * @return <code>true</code> if the specified (x, y) coordinate falls within
149
   *         the bounds of the component as rendered by the UI delegate in the
150
   *         primary look and feel, and <code>false</code> otherwise.
151
   */
152
  public boolean contains(JComponent c, int x, int y)
153
  {
154
    boolean result = false;
155
    Iterator iterator = uis.iterator();
156
    // first UI delegate provides the return value
157
    if (iterator.hasNext())
158
      {
159
        ComponentUI ui = (ComponentUI) iterator.next();
160
        result = ui.contains(c, x, y);
161
      }
162
    // return values from auxiliary UI delegates are ignored
163
    while (iterator.hasNext())
164
      {
165
        ComponentUI ui = (ComponentUI) iterator.next();
166
        /* boolean ignored = */ ui.contains(c, x, y);
167
      }
168
    return result;
169
  }
170
 
171
  /**
172
   * Calls the {@link ComponentUI#update(Graphics, JComponent)} method for all
173
   * the UI delegates managed by this <code>MultiFileChooserUI</code>.
174
   *
175
   * @param g  the graphics device.
176
   * @param c  the component.
177
   */
178
  public void update(Graphics g, JComponent c)
179
  {
180
    Iterator iterator = uis.iterator();
181
    while (iterator.hasNext())
182
    {
183
      ComponentUI ui = (ComponentUI) iterator.next();
184
      ui.update(g, c);
185
    }
186
  }
187
 
188
  /**
189
   * Calls the <code>paint(Graphics, JComponent)</code> method for all the UI
190
   * delegates managed by this <code>MultiFileChooserUI</code>.
191
   *
192
   * @param g  the graphics device.
193
   * @param c  the component.
194
   */
195
  public void paint(Graphics g, JComponent c)
196
  {
197
    Iterator iterator = uis.iterator();
198
    while (iterator.hasNext())
199
    {
200
      ComponentUI ui = (ComponentUI) iterator.next();
201
      ui.paint(g, c);
202
    }
203
  }
204
 
205
  /**
206
   * Calls the {@link ComponentUI#getPreferredSize(JComponent)} method for all
207
   * the UI delegates managed by this <code>MultiFileChooserUI</code>,
208
   * returning the preferred size for the UI delegate from the primary look and
209
   * feel.
210
   *
211
   * @param c  the component.
212
   *
213
   * @return The preferred size returned by the UI delegate from the primary
214
   *         look and feel.
215
   */
216
  public Dimension getPreferredSize(JComponent c)
217
  {
218
    Dimension result = null;
219
    Iterator iterator = uis.iterator();
220
    // first UI delegate provides the return value
221
    if (iterator.hasNext())
222
      {
223
        ComponentUI ui = (ComponentUI) iterator.next();
224
        result = ui.getPreferredSize(c);
225
      }
226
    // return values from auxiliary UI delegates are ignored
227
    while (iterator.hasNext())
228
      {
229
        ComponentUI ui = (ComponentUI) iterator.next();
230
        /* Dimension ignored = */ ui.getPreferredSize(c);
231
      }
232
    return result;
233
  }
234
 
235
  /**
236
   * Calls the {@link ComponentUI#getMinimumSize(JComponent)} method for all
237
   * the UI delegates managed by this <code>MultiFileChooserUI</code>,
238
   * returning the minimum size for the UI delegate from the primary look and
239
   * feel.
240
   *
241
   * @param c  the component.
242
   *
243
   * @return The minimum size returned by the UI delegate from the primary
244
   *         look and feel.
245
   */
246
  public Dimension getMinimumSize(JComponent c)
247
  {
248
    Dimension result = null;
249
    Iterator iterator = uis.iterator();
250
    // first UI delegate provides the return value
251
    if (iterator.hasNext())
252
      {
253
        ComponentUI ui = (ComponentUI) iterator.next();
254
        result = ui.getMinimumSize(c);
255
      }
256
    // return values from auxiliary UI delegates are ignored
257
    while (iterator.hasNext())
258
      {
259
        ComponentUI ui = (ComponentUI) iterator.next();
260
        /* Dimension ignored = */ ui.getMinimumSize(c);
261
      }
262
    return result;
263
  }
264
 
265
  /**
266
   * Calls the {@link ComponentUI#getMaximumSize(JComponent)} method for all
267
   * the UI delegates managed by this <code>MultiFileChooserUI</code>,
268
   * returning the maximum size for the UI delegate from the primary look and
269
   * feel.
270
   *
271
   * @param c  the component.
272
   *
273
   * @return The maximum size returned by the UI delegate from the primary
274
   *         look and feel.
275
   */
276
  public Dimension getMaximumSize(JComponent c)
277
  {
278
    Dimension result = null;
279
    Iterator iterator = uis.iterator();
280
    // first UI delegate provides the return value
281
    if (iterator.hasNext())
282
      {
283
        ComponentUI ui = (ComponentUI) iterator.next();
284
        result = ui.getMaximumSize(c);
285
      }
286
    // return values from auxiliary UI delegates are ignored
287
    while (iterator.hasNext())
288
      {
289
        ComponentUI ui = (ComponentUI) iterator.next();
290
        /* Dimension ignored = */ ui.getMaximumSize(c);
291
      }
292
    return result;
293
  }
294
 
295
  /**
296
   * Calls the {@link ComponentUI#getAccessibleChildrenCount(JComponent)} method
297
   * for all the UI delegates managed by this <code>MultiFileChooserUI</code>,
298
   * returning the count for the UI delegate from the primary look and
299
   * feel.
300
   *
301
   * @param c  the component.
302
   *
303
   * @return The count returned by the UI delegate from the primary
304
   *         look and feel.
305
   */
306
  public int getAccessibleChildrenCount(JComponent c)
307
  {
308
    int result = 0;
309
    Iterator iterator = uis.iterator();
310
    // first UI delegate provides the return value
311
    if (iterator.hasNext())
312
      {
313
        ComponentUI ui = (ComponentUI) iterator.next();
314
        result = ui.getAccessibleChildrenCount(c);
315
      }
316
    // return values from auxiliary UI delegates are ignored
317
    while (iterator.hasNext())
318
      {
319
        ComponentUI ui = (ComponentUI) iterator.next();
320
        /* int ignored = */ ui.getAccessibleChildrenCount(c);
321
      }
322
    return result;
323
  }
324
 
325
  /**
326
   * Calls the {@link ComponentUI#getAccessibleChild(JComponent, int)} method
327
   * for all the UI delegates managed by this <code>MultiFileChooserUI</code>,
328
   * returning the child for the UI delegate from the primary look and
329
   * feel.
330
   *
331
   * @param c  the component
332
   * @param i  the child index.
333
   *
334
   * @return The child returned by the UI delegate from the primary
335
   *         look and feel.
336
   */
337
  public Accessible getAccessibleChild(JComponent c, int i)
338
  {
339
    Accessible result = null;
340
    Iterator iterator = uis.iterator();
341
    // first UI delegate provides the return value
342
    if (iterator.hasNext())
343
      {
344
        ComponentUI ui = (ComponentUI) iterator.next();
345
        result = ui.getAccessibleChild(c, i);
346
      }
347
    // return values from auxiliary UI delegates are ignored
348
    while (iterator.hasNext())
349
      {
350
        ComponentUI ui = (ComponentUI) iterator.next();
351
        /* Accessible ignored = */ ui.getAccessibleChild(c, i);
352
      }
353
    return result;
354
  }
355
 
356
  /**
357
   * Calls the {@link FileChooserUI#getAcceptAllFileFilter(JFileChooser)} method
358
   * for all the UI delegates managed by this <code>MultiFileChooserUI</code>,
359
   * returning the filter for the UI delegate from the primary look and
360
   * feel.
361
   *
362
   * @param chooser  the file chooser.
363
   *
364
   * @return The filter returned by the UI delegate from the primary
365
   *         look and feel.
366
   */
367
  public FileFilter getAcceptAllFileFilter(JFileChooser chooser) {
368
    FileFilter result = null;
369
    Iterator iterator = uis.iterator();
370
    // first UI delegate provides the return value
371
    if (iterator.hasNext())
372
      {
373
        FileChooserUI ui = (FileChooserUI) iterator.next();
374
        result = ui.getAcceptAllFileFilter(chooser);
375
      }
376
    // return values from auxiliary UI delegates are ignored
377
    while (iterator.hasNext())
378
      {
379
        FileChooserUI ui = (FileChooserUI) iterator.next();
380
        /* FileFilter ignored = */ ui.getAcceptAllFileFilter(chooser);
381
      }
382
    return result;
383
  }
384
 
385
  /**
386
   * Calls the {@link FileChooserUI#getFileView(JFileChooser)} method
387
   * for all the UI delegates managed by this <code>MultiFileChooserUI</code>,
388
   * returning the view for the UI delegate from the primary look and
389
   * feel.
390
   *
391
   * @param chooser  the file chooser.
392
   *
393
   * @return The view returned by the UI delegate from the primary
394
   *         look and feel.
395
   */
396
  public FileView getFileView(JFileChooser chooser) {
397
    FileView result = null;
398
    Iterator iterator = uis.iterator();
399
    // first UI delegate provides the return value
400
    if (iterator.hasNext())
401
      {
402
        FileChooserUI ui = (FileChooserUI) iterator.next();
403
        result = ui.getFileView(chooser);
404
      }
405
    // return values from auxiliary UI delegates are ignored
406
    while (iterator.hasNext())
407
      {
408
        FileChooserUI ui = (FileChooserUI) iterator.next();
409
        /* FileView ignored = */ ui.getFileView(chooser);
410
      }
411
    return result;
412
  }
413
 
414
  /**
415
   * Calls the {@link FileChooserUI#getApproveButtonText(JFileChooser)} method
416
   * for all the UI delegates managed by this <code>MultiFileChooserUI</code>,
417
   * returning the text for the UI delegate from the primary look and
418
   * feel.
419
   *
420
   * @param chooser  the file chooser.
421
   *
422
   * @return The text returned by the UI delegate from the primary
423
   *         look and feel.
424
   */
425
  public String getApproveButtonText(JFileChooser chooser) {
426
    String result = null;
427
    Iterator iterator = uis.iterator();
428
    // first UI delegate provides the return value
429
    if (iterator.hasNext())
430
      {
431
        FileChooserUI ui = (FileChooserUI) iterator.next();
432
        result = ui.getApproveButtonText(chooser);
433
      }
434
    // return values from auxiliary UI delegates are ignored
435
    while (iterator.hasNext())
436
      {
437
        FileChooserUI ui = (FileChooserUI) iterator.next();
438
        /* String ignored = */ ui.getApproveButtonText(chooser);
439
      }
440
    return result;
441
  }
442
 
443
  /**
444
   * Calls the {@link FileChooserUI#getDialogTitle(JFileChooser)} method
445
   * for all the UI delegates managed by this <code>MultiFileChooserUI</code>,
446
   * returning the title for the UI delegate from the primary look and
447
   * feel.
448
   *
449
   * @param chooser  the file chooser.
450
   *
451
   * @return The title returned by the UI delegate from the primary
452
   *         look and feel.
453
   */
454
  public String getDialogTitle(JFileChooser chooser) {
455
    String result = null;
456
    Iterator iterator = uis.iterator();
457
    // first UI delegate provides the return value
458
    if (iterator.hasNext())
459
      {
460
        FileChooserUI ui = (FileChooserUI) iterator.next();
461
        result = ui.getDialogTitle(chooser);
462
      }
463
    // return values from auxiliary UI delegates are ignored
464
    while (iterator.hasNext())
465
      {
466
        FileChooserUI ui = (FileChooserUI) iterator.next();
467
        /* String ignored = */ ui.getDialogTitle(chooser);
468
      }
469
    return result;
470
  }
471
 
472
  /**
473
   * Calls the {@link FileChooserUI#rescanCurrentDirectory(JFileChooser)}
474
   * method for all the UI delegates managed by this
475
   * <code>MultiFileChooserUI</code>.
476
   *
477
   * @param chooser  the file chooser.
478
   */
479
  public void rescanCurrentDirectory(JFileChooser chooser) {
480
    Iterator iterator = uis.iterator();
481
    while (iterator.hasNext())
482
    {
483
      FileChooserUI ui = (FileChooserUI) iterator.next();
484
      ui.rescanCurrentDirectory(chooser);
485
    }
486
  }
487
 
488
  /**
489
   * Calls the {@link FileChooserUI#ensureFileIsVisible(JFileChooser, File)}
490
   * method for all the UI delegates managed by this
491
   * <code>MultiFileChooserUI</code>.
492
   *
493
   * @param chooser  the file chooser.
494
   * @param file  the file.
495
   */
496
  public void ensureFileIsVisible(JFileChooser chooser, File file) {
497
    Iterator iterator = uis.iterator();
498
    while (iterator.hasNext())
499
    {
500
      FileChooserUI ui = (FileChooserUI) iterator.next();
501
      ui.ensureFileIsVisible(chooser, file);
502
    }
503
  }
504
 
505
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.