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