KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > gui2 > FBFileChooser


1 /*
2  * FindBugs - Find Bugs in Java programs
3  * Copyright (C) 2006, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307, USA
18  */

19
20 package edu.umd.cs.findbugs.gui2;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.Container JavaDoc;
24 import java.lang.reflect.InvocationTargetException JavaDoc;
25 import java.lang.reflect.Method JavaDoc;
26
27 import javax.swing.JFileChooser JavaDoc;
28
29 import edu.umd.cs.findbugs.SystemProperties;
30 /**
31  * All FileChoosers are FBFileChoosers so font size will work
32  * @author Kristin
33  *
34  */

35 public class FBFileChooser extends JFileChooser JavaDoc {
36     
37     public FBFileChooser(){
38         super();
39         assert java.awt.EventQueue.isDispatchThread();
40         this.setCurrentDirectory(GUISaveState.getInstance().getStarterDirectoryForLoadBugs());
41     }
42     
43     /**
44      * Sets size of font
45      * @param size
46      */

47     protected void setFontSize(float size){
48         setFont(this.getFont().deriveFont(size));
49         
50         setFontSizeHelper(this.getComponents(), size);
51     }
52     
53     /*
54      * Helps above method, runs through all components recursively.
55      */

56     protected void setFontSizeHelper(Component JavaDoc[] comps, float size){
57         if(comps.length <= 0)
58             return;
59         
60         for(Component JavaDoc comp : comps){
61             comp.setFont(comp.getFont().deriveFont(size));
62             if(comp instanceof Container JavaDoc)
63                 setFontSizeHelper(((Container JavaDoc)comp).getComponents(), size);
64         }
65     }
66     
67     public void addNotify(){
68         super.addNotify();
69         setFontSize(Driver.getFontSize());
70         
71     }
72
73     private static void workAroundJFileChooserBug() {
74         //Travis McLeskey
75
try {
76             Object JavaDoc o = javax.swing.UIManager.getBorder( "TableHeader.cellBorder" );
77             Method JavaDoc m = o.getClass().getMethod( "setHorizontalShift",
78                     new Class JavaDoc[] { int.class } );
79             m.invoke( o, 0 );
80         }
81         catch ( NoSuchMethodException JavaDoc e ) { assert false; }
82         catch ( InvocationTargetException JavaDoc e ) { assert false; }
83         catch ( IllegalAccessException JavaDoc e ) { assert false; }
84     }
85     
86     public int showOpenDialog(Component JavaDoc parent)
87     {
88          assert java.awt.EventQueue.isDispatchThread();
89         int x=super.showOpenDialog(parent);
90         if (SystemProperties.getProperty("os.name").startsWith("Mac"))
91             workAroundJFileChooserBug();
92         
93         GUISaveState.getInstance().setStarterDirectoryForLoadBugs(getCurrentDirectory());
94         
95         return x;
96     }
97
98     public int showSaveDialog(Component JavaDoc parent){
99          assert java.awt.EventQueue.isDispatchThread();
100         int x=super.showSaveDialog(parent);
101         if (SystemProperties.getProperty("os.name").startsWith("Mac"))
102             workAroundJFileChooserBug();
103         
104         GUISaveState.getInstance().setStarterDirectoryForLoadBugs(getCurrentDirectory());
105         
106         return x;
107     }
108
109     public int showDialog(Component JavaDoc parent, String JavaDoc approveButtonText){
110          assert java.awt.EventQueue.isDispatchThread();
111         int x=super.showDialog(parent, approveButtonText);
112         if (SystemProperties.getProperty("os.name").startsWith("Mac"))
113             workAroundJFileChooserBug();
114         
115         GUISaveState.getInstance().setStarterDirectoryForLoadBugs(getCurrentDirectory());
116         
117         return x;
118     }
119
120     
121 }
Popular Tags