001: /*
002: * FindBugs - Find Bugs in Java programs
003: * Copyright (C) 2006, University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307, USA
018: */
019:
020: package edu.umd.cs.findbugs.gui2;
021:
022: import java.awt.Component;
023: import java.awt.Container;
024: import java.lang.reflect.InvocationTargetException;
025: import java.lang.reflect.Method;
026:
027: import javax.swing.JFileChooser;
028:
029: import edu.umd.cs.findbugs.SystemProperties;
030:
031: /**
032: * All FileChoosers are FBFileChoosers so font size will work
033: * @author Kristin
034: *
035: */
036: public class FBFileChooser extends JFileChooser {
037:
038: public FBFileChooser() {
039: super ();
040: assert java.awt.EventQueue.isDispatchThread();
041: this .setCurrentDirectory(GUISaveState.getInstance()
042: .getStarterDirectoryForLoadBugs());
043: }
044:
045: /**
046: * Sets size of font
047: * @param size
048: */
049: protected void setFontSize(float size) {
050: setFont(this .getFont().deriveFont(size));
051:
052: setFontSizeHelper(this .getComponents(), size);
053: }
054:
055: /*
056: * Helps above method, runs through all components recursively.
057: */
058: protected void setFontSizeHelper(Component[] comps, float size) {
059: if (comps.length <= 0)
060: return;
061:
062: for (Component comp : comps) {
063: comp.setFont(comp.getFont().deriveFont(size));
064: if (comp instanceof Container)
065: setFontSizeHelper(((Container) comp).getComponents(),
066: size);
067: }
068: }
069:
070: @Override
071: public void addNotify() {
072: super .addNotify();
073: setFontSize(Driver.getFontSize());
074:
075: }
076:
077: private static void workAroundJFileChooserBug() {
078: //Travis McLeskey
079: // http://www.mcleskey.org/bugs.html
080: try {
081: Object o = javax.swing.UIManager
082: .getBorder("TableHeader.cellBorder");
083: Method m = o.getClass().getMethod("setHorizontalShift",
084: new Class[] { int.class });
085: m.invoke(o, 0);
086: } catch (NoSuchMethodException e) {
087: assert false;
088: } catch (InvocationTargetException e) {
089: assert false;
090: } catch (IllegalAccessException e) {
091: assert false;
092: }
093: }
094:
095: @Override
096: public int showOpenDialog(Component parent) {
097: assert java.awt.EventQueue.isDispatchThread();
098: int x = super .showOpenDialog(parent);
099: if (SystemProperties.getProperty("os.name").startsWith("Mac"))
100: workAroundJFileChooserBug();
101:
102: GUISaveState.getInstance().setStarterDirectoryForLoadBugs(
103: getCurrentDirectory());
104:
105: return x;
106: }
107:
108: @Override
109: public int showSaveDialog(Component parent) {
110: assert java.awt.EventQueue.isDispatchThread();
111: int x = super .showSaveDialog(parent);
112: if (SystemProperties.getProperty("os.name").startsWith("Mac"))
113: workAroundJFileChooserBug();
114:
115: GUISaveState.getInstance().setStarterDirectoryForLoadBugs(
116: getCurrentDirectory());
117:
118: return x;
119: }
120:
121: @Override
122: public int showDialog(Component parent, String approveButtonText) {
123: assert java.awt.EventQueue.isDispatchThread();
124: int x = super .showDialog(parent, approveButtonText);
125: if (SystemProperties.getProperty("os.name").startsWith("Mac"))
126: workAroundJFileChooserBug();
127:
128: GUISaveState.getInstance().setStarterDirectoryForLoadBugs(
129: getCurrentDirectory());
130:
131: return x;
132: }
133:
134: }
|