1 6 7 package analyzer.layout; 8 9 import java.io.*; 10 import java.util.*; 11 import org.netbeans.swing.gridsplit.*; 12 import java.awt.Component ; 13 14 15 19 public class LayoutBuilder { 20 21 LayoutParser xmlParser; 22 ArrayList layouts; 23 24 25 public LayoutBuilder() { 26 System.out.println("\nAttempting to redraw window layout..."); 27 slidingSideContent(); 28 layouts=new ArrayList(); 29 xmlParser=new LayoutParser(this); 30 openFiles(); 31 if(layouts.size()==0){ 32 System.err.println("no layout file found"); 33 return; 34 } 35 Test t=new Test(); 36 Component c=t.getFirstComponent(); 37 LayoutTree tree=new LayoutTree(layouts,t); 38 tree.splitComponent(c); 39 t.display(); 40 } 41 42 43 private void openFiles(){ 44 String currentPath=getCWD(); 45 try{ 46 String [] wsmodeFiles=filesEndingWith("wsmode",currentPath); 47 parseMode(wsmodeFiles); 48 String [] wswmgrFiles=filesEndingWith("wswmgr",currentPath); 49 parseMode(wswmgrFiles); 50 } catch(Exception e){ 51 e.printStackTrace(); 52 } 53 } 54 55 public static void analyzeMode(String modeName,String [] topComponents){ 56 String msg=""; 57 if(modeName.equals("explorer")){ 58 msg=compare(topComponents,new String []{"favorites","projectTab_tc","projectTabLogical_tc","runtime","VCSGROUPMENUACTION_GROUPEXPLORERPANEL","VERSIONINGEXPLORER_PANEL"}); 59 }else if(modeName.equals("navigator")){ 60 msg=compare(topComponents,new String []{"ComponentInspector","navigator"}); 61 }else if(modeName.equals("output")){ 62 msg=compare(topComponents,new String []{"find-usages","output","refactoring-preview","search-results","VCSCommandOutput","TODO-WINDOW","TRANSACTIONVIEW"}); 63 }else if(modeName.equals("debugger")){ 64 msg=compare(topComponents,new String []{"breakpoints","callstack","classes","locals","sessions","sources","threads","watches"}); 65 }else if(modeName.equals("properties")){ 66 msg=compare(topComponents,new String []{"properties"}); 67 }else if(modeName.equals("palette")){ 68 msg=compare(topComponents,new String []{"ComponentPalette"}); 69 }else if(modeName.equals("editor")){ 70 return; 71 }else { 72 msg=compare(topComponents,new String []{""}); 73 } 74 if(msg.length()>0)System.err.println("Mode "+modeName+" is customized with:"+msg); 75 } 76 77 private static String compare(String [] target,String [] model){ 78 boolean irregular; 79 StringBuffer msg=new StringBuffer (); 80 for(int i=0;i<target.length;i++){ 81 irregular=true; 82 for(int j=0;j<model.length;j++){ 83 if(target[i].equals(model[j])){ 84 irregular=false; 85 break; 86 } 87 } 88 if(irregular) msg.append("\n"+target[i]); 89 } 90 return msg.toString(); 91 } 92 93 private void parseMode(String [] files){ 94 if(files==null) return; 95 for(int i=0;i<files.length;i++){ 96 try{ 97 ModeLayout l=xmlParser.parse(files[i]); 98 if(l!=null)layouts.add((Object )l); 99 }catch(Exception e){ 100 e.printStackTrace(); 101 } 102 } 103 } 104 105 private void slidingSideContent(){ 106 String slidingDir[]=filesEndingWith("SlidingSide",getCWD()); 107 for(int i=0;i<slidingDir.length;i++){ 108 File dir=new File(slidingDir[i]); 109 if(dir.isDirectory()){ 110 String slideFiles[]=filesEndingWith("wstcref",dir.getPath()); 111 if(slideFiles.length>0) System.out.println("content of "+dir.getName()); 112 for(int j=0;j<slideFiles.length;j++)System.out.println(" + "+slideFiles[j]); 113 } 114 } 115 } 116 117 public String [] filesEndingWith(String extension, String path){ 118 try{ 119 File dir = new File(path); 120 final String openThis=extension; 121 FilenameFilter filter = new FilenameFilter() { 122 public boolean accept(File dir, String name) { 123 return name.endsWith(openThis); 124 } 125 }; 126 String files[] = dir.list(filter); 127 return files; 128 }catch(Exception e){ 129 System.out.println("no file with such extension?"); 130 e.printStackTrace(); 131 return null; 132 } 133 } 134 135 private static String getCWD() { 136 java.io.File f = new java.io.File ("."); 137 String cwd = f.getAbsolutePath(); 138 return cwd.substring(0, cwd.length() - 1); 139 } 140 } 141 | Popular Tags |