1 19 20 package edu.umd.cs.findbugs.gui2; 21 22 import java.awt.Component ; 23 import java.awt.Container ; 24 import java.lang.reflect.InvocationTargetException ; 25 import java.lang.reflect.Method ; 26 27 import javax.swing.JFileChooser ; 28 29 import edu.umd.cs.findbugs.SystemProperties; 30 35 public class FBFileChooser extends JFileChooser { 36 37 public FBFileChooser(){ 38 super(); 39 assert java.awt.EventQueue.isDispatchThread(); 40 this.setCurrentDirectory(GUISaveState.getInstance().getStarterDirectoryForLoadBugs()); 41 } 42 43 47 protected void setFontSize(float size){ 48 setFont(this.getFont().deriveFont(size)); 49 50 setFontSizeHelper(this.getComponents(), size); 51 } 52 53 56 protected void setFontSizeHelper(Component [] comps, float size){ 57 if(comps.length <= 0) 58 return; 59 60 for(Component comp : comps){ 61 comp.setFont(comp.getFont().deriveFont(size)); 62 if(comp instanceof Container ) 63 setFontSizeHelper(((Container )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 try { 76 Object o = javax.swing.UIManager.getBorder( "TableHeader.cellBorder" ); 77 Method m = o.getClass().getMethod( "setHorizontalShift", 78 new Class [] { int.class } ); 79 m.invoke( o, 0 ); 80 } 81 catch ( NoSuchMethodException e ) { assert false; } 82 catch ( InvocationTargetException e ) { assert false; } 83 catch ( IllegalAccessException e ) { assert false; } 84 } 85 86 public int showOpenDialog(Component 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 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 parent, String 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 |