View Javadoc

1   /*
2    * Created on Feb 10, 2005
3    *
4    * TODO To change the template for this generated file go to
5    * Window - Preferences - Java - Code Style - Code Templates
6    */
7   package net.sf.gumshoe;
8   
9   import java.io.File;
10  import java.util.logging.Level;
11  import java.util.logging.Logger;
12  
13  import org.eclipse.swt.SWT;
14  import org.eclipse.swt.widgets.MenuItem;
15  import org.eclipse.swt.widgets.MessageBox;
16  import org.getopt.luke.Luke;
17  
18  import net.sf.gumshoe.indexer.DiskIndexer;
19  
20  /***
21   * @author Gabor
22   *
23   * TODO To change the template for this generated type comment go to
24   * Window - Preferences - Java - Code Style - Code Templates
25   */
26  public class Gumshoe extends TrayApp implements Runnable {
27  
28      private String searchRoot="C://Documents and Settings"; //$NON-NLS-1$
29  
30      private String indexStore=System.getProperty("user.home")+File.separator+".scavenger"; //$NON-NLS-1$ //$NON-NLS-2$
31      
32      private boolean threadSuspended=true;
33      
34  	protected Logger logger=null;
35  	
36  	protected Thread t=null;
37  
38      public static void main( String[] args ) {
39  		Gumshoe app = new Gumshoe();
40          app.setToolTip(Messages.getString("Gumshoe.applicationtitle")); //$NON-NLS-1$
41          app.setIcon("/images/gumshoe.ico"); //$NON-NLS-1$
42          app.start(args);
43      }
44  
45      /***
46  	 * 
47  	 */
48  	public Gumshoe() {
49  		super();
50  		logger=Logger.getLogger(getClass().getName());
51          startIndexing();
52      }
53  
54  	/* (non-Javadoc)
55  	 * @see net.sf.gumshoe.TrayApp#initGUI()
56  	 */
57  	public void initGUI() {
58  	    createLeftMenu();
59  	    createRightMenu();
60  	}
61  
62  	/***
63  	 * 
64  	 */
65  	private void createRightMenu() {
66  		// TODO Auto-generated method stub
67  		
68  	}
69  
70  	/***
71  	 * 
72  	 */
73  	private void createLeftMenu() {
74  		MenuItem miConfiguration = createMenu(reMenu, Messages.getString("Gumshoe.advancedsearch"), //$NON-NLS-1$
75  				new MenuCommand() {
76  					public void perform() {
77  						advancedSearch();
78  					}
79  				}, SWT.PUSH);
80  //		MenuItem miIndexing = createMenu(reMenu, "Start Indexing",
81  //				new MenuCommand() {
82  //					public void perform() {
83  //						// TODO: notification does not work ...
84  //			        	threadSuspended = false;
85  //			        	synchronized(this){
86  //			        		System.out.println("before notify ...");
87  //			    			notify();
88  //			        		System.out.println("after notify ...");
89  //			        	}
90  //					}
91  //				}, SWT.PUSH);
92  		MenuItem miOptions = createMenu(reMenu, Messages.getString("Gumshoe.options"), //$NON-NLS-1$
93  				new MenuCommand() {
94  					public void perform() {
95  						options();
96  					}
97  				}, SWT.PUSH);
98  		MenuItem miAbout = createMenu(reMenu, Messages.getString("Gumshoe.about"), //$NON-NLS-1$
99  				new MenuCommand() {
100 					public void perform() {
101 						about();
102 					}
103 				}, SWT.PUSH);
104 		MenuItem miExit = createMenu(reMenu, Messages.getString("Gumshoe.exit"), //$NON-NLS-1$
105 				new MenuCommand() {
106 					public void perform() {
107 						exit();
108 					}
109 				}, SWT.PUSH);
110 	}
111 
112 	/***
113 	 * 
114 	 */
115 	protected void advancedSearch() {
116     	String[] args={"-ro", "-index", indexStore}; //$NON-NLS-1$ //$NON-NLS-2$
117     	Luke.startLuke(args);
118 	}
119 
120 	/***
121 	 * 
122 	 */
123 	protected void options() {
124 		MessageBox mb=new MessageBox(getShell(), SWT.ICON_INFORMATION | SWT.OK);
125 		mb.setMessage("Coming soon :)"); //$NON-NLS-1$
126 		mb.open();
127 	}
128 
129 	/***
130 	 * 
131 	 */
132 	protected void about() {
133 		MessageBox mb=new MessageBox(getShell(), SWT.ICON_INFORMATION | SWT.OK);
134 		mb.setMessage(Messages.getString("Gumshoe.applicationtitle"));
135 		mb.open();
136 	}
137 
138 	/* (non-Javadoc)
139 	 * @see net.sf.gumshoe.TrayApp#processArgs(java.lang.String[])
140 	 */
141 	protected void processArgs(String[] args) {
142 		// currently no args		
143 	}
144 	
145 	/***
146 	 * 
147 	 */
148 	protected void startIndexing() {
149 		if (t==null){
150 			t=new Thread(this, "DiskIndexer"); //$NON-NLS-1$
151 			t.setDaemon(true);
152 			t.setPriority(Thread.MIN_PRIORITY);
153 			threadSuspended=false;
154 			t.start();			
155 		}
156 	}
157 	/* (non-Javadoc)
158 	 * @see java.lang.Runnable#run()
159 	 */
160 	public void run() {
161         while (true) {
162             try {
163                 Thread.sleep(1000L);
164 
165                 while (threadSuspended){
166                 	synchronized(this){
167                 		System.out.println("waiting ..."); //$NON-NLS-1$
168                         wait();
169                 		System.out.println("waiting ended ..."); //$NON-NLS-1$
170                 	}
171                 }
172             } catch (InterruptedException e){
173             	System.out.println("interrupted ..."); //$NON-NLS-1$
174             }
175 			try {
176 		        File indexDir = new File(indexStore);
177 		        File dataDir = new File(searchRoot);
178 		        new DiskIndexer().index(indexDir, dataDir, true);
179 			} catch (Throwable t){
180 				logger.log(Level.SEVERE, "indexing failed", t); //$NON-NLS-1$
181 			}
182 			threadSuspended=true;
183         }
184 	}
185 }