incubator-kato-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From monte...@apache.org
Subject svn commit: r807643 - in /incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin: ./ src/main/java/org/apache/kato/tools/plugins/hexeditor/editors/ src/main/java/org/apache/kato/tools/plugins/hexeditor/eyecatchers/ src/main/java/org...
Date Tue, 25 Aug 2009 14:10:12 GMT
Author: monteith
Date: Tue Aug 25 14:10:11 2009
New Revision: 807643

URL: http://svn.apache.org/viewvc?rev=807643&view=rev
Log:
Applying patch supplied in JIRA Issue KATO-7 by Adam Pilkington
https://issues.apache.org/jira/secure/attachment/12413243/org.apache.kato.tools.plugins.hexeditor.zip

Modified:
    incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/plugin.xml
    incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/editors/BinaryHexViewer.java
    incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/eyecatchers/Eyecatcher.java
    incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/eyecatchers/EyecatcherScanner.java
    incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/views/BinarySourceProvider.java
    incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/views/BookmarksView.java
    incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/views/EyecatcherView.java
    incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/views/RawByteModel.java

Modified: incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/plugin.xml
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/plugin.xml?rev=807643&r1=807642&r2=807643&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/plugin.xml (original)
+++ incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/plugin.xml Tue Aug 25 14:10:11 2009
@@ -1,91 +1,115 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.2"?>
-<plugin>
-
-   <extension
-         point="org.eclipse.ui.views">
-      <category
-            name="Apache Kato"
-            id="org.apache.kato.tools">
-      </category>
-      
-      <view
-            name="Bookmarks"
-            icon="icons/sample.gif"
-            category="org.apache.kato.tools"
-            class="org.apache.kato.tools.plugins.hexeditor.views.BookmarksView"
-            id="org.apache.kato.tools.plugins.hexeditor.views.BookmarksView">
-      </view>
-      <view
-            name="Eyecatchers"
-            icon="icons/sample.gif"
-            category="org.apache.kato.tools"
-            class="org.apache.kato.tools.plugins.hexeditor.views.EyecatcherView"
-            id="org.apache.kato.tools.plugins.hexeditor.views.EyecatcherView">
-      </view>
-   </extension>
-   <extension
-         point="org.eclipse.ui.perspectiveExtensions">
-      <perspectiveExtension
-            targetID="org.eclipse.jdt.ui.JavaPerspective">
-         <view
-               ratio="0.5"
-               relative="org.eclipse.ui.views.TaskList"
-               relationship="right"
-               id="org.apache.kato.tools.plugins.hexeditor.views.RawDumpView">
-         </view>
-      </perspectiveExtension>
-   </extension>
-   <extension
-         point="org.eclipse.help.contexts">
-      <contexts
-            file="contexts.xml">
-      </contexts>
-   </extension>
-   <extension
-         point="org.eclipse.ui.editors">
-      <editor
-            class="org.apache.kato.tools.plugins.hexeditor.editors.BinaryHexViewer"
-            contributorClass="org.apache.kato.tools.plugins.hexeditor.editors.MultiPageEditorContributor"
-            icon="icons/sample.gif"
-            id="org.apache.kato.tools.plugins.hexeditor.editors.BinaryHexViewer"
-            name="Binary Hex Viewer">
-      </editor>
-   </extension>
-   <extension
-         point="org.eclipse.ui.commands">
-      <category
-            id="org.apache.kato.plugins.hexeditor.commands"
-            name="Hex Viewer"
-            description="Hex viewer commands" />
-      <command
-            categoryId="org.apache.kato.plugins.hexeditor.commands"
-            id="org.apache.kato.plugins.hexeditor.commands.jumpto"
-            name="Jump to"
-            description="Jump to the specified position in the file" />
-      <command
-            categoryId="org.apache.kato.plugins.hexeditor.commands"
-            id="org.apache.kato.plugins.hexeditor.commands.find"
-            name="Find"
-            description="Find a sequence in the file" />
-   </extension>
-   <extension
-         point="org.eclipse.ui.bindings">
-         <key sequence="Ctrl+J"
-			commandId="org.apache.kato.plugins.hexeditor.commands.jumpto"
-			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" />
-		<key sequence="Ctrl+Shift+F"
-			commandId="org.apache.kato.plugins.hexeditor.commands.find"
-			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" />
-   </extension>
-	<extension
-	      point="org.eclipse.ui.services">
-	   <sourceProvider
-	         provider="org.apache.kato.tools.plugins.hexeditor.views.BinarySourceProvider">
-	      <variable
-	            name="org.apache.kato.tools.plugins.hexeditor.views.BinaryData"
-	            priorityLevel="workbench">
-	      </variable>
-	   </sourceProvider>
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+
+   <extension
+         point="org.eclipse.ui.views">
+      <category
+            name="Apache Kato"
+            id="org.apache.kato.tools">
+      </category>
+      
+      <view
+            name="Bookmarks"
+            icon="icons/sample.gif"
+            category="org.apache.kato.tools"
+            class="org.apache.kato.tools.plugins.hexeditor.views.BookmarksView"
+            id="org.apache.kato.tools.plugins.hexeditor.views.BookmarksView">
+      </view>
+      <view
+            name="Eyecatchers"
+            icon="icons/sample.gif"
+            category="org.apache.kato.tools"
+            class="org.apache.kato.tools.plugins.hexeditor.views.EyecatcherView"
+            id="org.apache.kato.tools.plugins.hexeditor.views.EyecatcherView">
+      </view>
+   </extension>
+   <extension
+         point="org.eclipse.ui.perspectiveExtensions">
+      <perspectiveExtension
+            targetID="org.eclipse.jdt.ui.JavaPerspective">
+         <view
+               ratio="0.5"
+               relative="org.eclipse.ui.views.TaskList"
+               relationship="right"
+               id="org.apache.kato.tools.plugins.hexeditor.views.RawDumpView">
+         </view>
+      </perspectiveExtension>
+   </extension>
+   <extension
+         point="org.eclipse.help.contexts">
+      <contexts
+            file="contexts.xml">
+      </contexts>
+   </extension>
+   <extension
+         point="org.eclipse.ui.editors">
+      <editor
+            class="org.apache.kato.tools.plugins.hexeditor.editors.BinaryHexViewer"
+            contributorClass="org.apache.kato.tools.plugins.hexeditor.editors.MultiPageEditorContributor"
+            icon="icons/sample.gif"
+            id="org.apache.kato.tools.plugins.hexeditor.editors.BinaryHexViewer"
+            name="Binary Hex Viewer">
+      </editor>
+   </extension>
+   <extension
+         point="org.eclipse.ui.commands">
+      <category
+            id="org.apache.kato.plugins.hexeditor.commands"
+            name="Hex Viewer"
+            description="Hex viewer commands" />
+      <command
+            categoryId="org.apache.kato.plugins.hexeditor.commands"
+            id="org.apache.kato.plugins.hexeditor.commands.jumpto"
+            name="Jump to"
+            description="Jump to the specified position in the file" />
+      <command
+            categoryId="org.apache.kato.plugins.hexeditor.commands"
+            id="org.apache.kato.plugins.hexeditor.commands.find"
+            name="Find"
+            description="Find the first sequence in the file" />
+       <command
+            categoryId="org.apache.kato.plugins.hexeditor.commands"
+            id="org.apache.kato.plugins.hexeditor.commands.findNext"
+            name="FindNext"
+            description="Find the next sequence in the file" />
+       <command
+            categoryId="org.apache.kato.plugins.hexeditor.commands"
+            id="org.apache.kato.plugins.hexeditor.commands.nextPage"
+            name="NextPage"
+            description="Next page" />
+       <command
+            categoryId="org.apache.kato.plugins.hexeditor.commands"
+            id="org.apache.kato.plugins.hexeditor.commands.previousPage"
+            name="PreviousPage"
+            description="Previous page" />
+   </extension>
+   <extension
+         point="org.eclipse.ui.bindings">
+         <key sequence="Ctrl+Shift+J"
+			commandId="org.apache.kato.plugins.hexeditor.commands.jumpto"
+			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" />
+		<key sequence="Ctrl+Shift+F"
+			commandId="org.apache.kato.plugins.hexeditor.commands.find"
+			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" />
+		<key sequence="Ctrl+Shift+V"
+			commandId="org.apache.kato.plugins.hexeditor.commands.findNext"
+			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" />
+		<key sequence="Ctrl+Shift++"
+			commandId="org.apache.kato.plugins.hexeditor.commands.nextPage"
+			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" />
+		<key sequence="Ctrl+Shift+-"
+			commandId="org.apache.kato.plugins.hexeditor.commands.previousPage"
+			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" />
+   </extension>
+	<extension
+	      point="org.eclipse.ui.services">
+	   <sourceProvider
+	         provider="org.apache.kato.tools.plugins.hexeditor.views.BinarySourceProvider">
+	      <variable
+	            name="org.apache.kato.tools.plugins.hexeditor.views.BinaryData"
+	            priorityLevel="workbench">
+	      </variable>
+	   </sourceProvider>
 	</extension>
-</plugin>
+</plugin>

Modified: incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/editors/BinaryHexViewer.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/editors/BinaryHexViewer.java?rev=807643&r1=807642&r2=807643&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/editors/BinaryHexViewer.java (original)
+++ incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/editors/BinaryHexViewer.java Tue Aug 25 14:10:11 2009
@@ -16,6 +16,8 @@
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
 
 import org.apache.kato.tools.plugins.hexeditor.eyecatchers.Eyecatcher;
 import org.apache.kato.tools.plugins.hexeditor.views.BinarySourceProvider;
@@ -130,8 +132,11 @@
 		}
 	}
 	private Action actionFind;
+	private Action actionFindNext;
 	private Action actionJump;
 	private Action actionBookmark;
+	private Action actionNextPage;
+	private Action actionPreviousPage;
 	
 	private Action doubleClickAction;
 	private FileEditorInput fileInput=null;
@@ -144,9 +149,13 @@
 	private long currentPos = -1;			//current position being displayed on the screen
 	private long maxPos = -1;				//the largest position to be displayed
 	private ArrayList<CellLocation> cells = new ArrayList<CellLocation>();
+	private long lastFindIndex = 0;			//index of the last found search term
+	private String lastFindString = "";		//last search string
+	private File file = null;				//file currently being edited
 
 
 	private final int pageSize = 40;
+	private final int columnCount = 0x10;
 		
 	 private ISelectionListener selectListener = null;
 
@@ -154,8 +163,6 @@
 
 	private void addMainPage() {
 		
-		
-		
 		Composite parent=getContainer();
 		
 		viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL);
@@ -172,6 +179,7 @@
 		hookContextMenu();
 		contributeToActionBars();
 		hookPageSelection();
+
 		addPage(viewer.getControl());
 	}
 	
@@ -195,6 +203,7 @@
 	private void fillContextMenu(IMenuManager manager) {
 		manager.add(actionJump);
 		manager.add(actionFind);
+		manager.add(actionFindNext);
 		manager.add(actionBookmark);
 		// Other plug-ins can contribute there actions here
 		manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
@@ -203,6 +212,7 @@
 	private void fillLocalToolBar(IToolBarManager manager) {
 		manager.add(actionJump);
 		manager.add(actionFind);
+		manager.add(actionFindNext);
 		
 	}
 	private void contributeToActionBars() {
@@ -229,7 +239,7 @@
 		TableColumn column = new TableColumn(table, SWT.LEFT);
 		column.setText("Offset");
 		column.setWidth(200);
-		for(int i = 0; i < 0x10; i++) {
+		for(int i = 0; i < columnCount; i++) {
 			column = new TableColumn(table, SWT.LEFT);
 			column.setText(Integer.toHexString(i));
 			column.setWidth(50);
@@ -249,13 +259,14 @@
 		};		
 	}
 
+	@SuppressWarnings("deprecation")
 	private void createFindButton() {
 		actionFind = new Action() {
 			public void run() {
 				InputDialog entry = new InputDialog(viewer.getControl().getShell(), "Find", "Search for a byte sequence", null, null);
 				entry.open();
 				if(entry.getReturnCode() == IDialogConstants.OK_ID) {
-					findBytes(entry.getValue());
+					findBytes(entry.getValue(), 0);			//search from the beginning for a new term
 				}
 			}
 		};
@@ -267,6 +278,30 @@
 				getImageDescriptor(ISharedImages.IMG_OPEN_MARKER));
 	}
 
+	private long getNumberOfElementsPerPage() {
+		return pageSize * columnCount;
+	}
+	
+	@SuppressWarnings("deprecation")
+	private void createFindNextButton() {
+		actionFindNext = new Action() {
+			public void run() {
+				if(lastFindIndex == -1) {		//the last search did not match anything
+					showMessage("No more matches found for search term : " + lastFindString);
+				} else {						//possibly more matches available
+					findBytes(lastFindString, currentPos + getNumberOfElementsPerPage());		//look on the next display page
+				}
+			}
+		};
+		actionFindNext.setActionDefinitionId("org.apache.kato.plugins.hexeditor.commands.findNext");		
+		getSite().getKeyBindingService().registerAction(actionFindNext);
+		actionFindNext.setText("find next");
+		actionFindNext.setToolTipText("Find next sequence");
+		actionFindNext.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
+				getImageDescriptor(ISharedImages.IMG_OPEN_MARKER));
+	}
+	
+	@SuppressWarnings("deprecation")
 	private void createJumpButton() {
 		actionJump = new Action() {
 			public void run() {
@@ -285,6 +320,7 @@
 				getImageDescriptor(ISharedImages.IMG_OBJS_BKMRK_TSK));
 	}
 	
+	@SuppressWarnings("deprecation")
 	private void createBookmarkButton() {
 		actionBookmark = new Action() {
 			public void run() {
@@ -367,8 +403,10 @@
 		
 	}
 	
-	private void findBytes(String searchFor) {
-		long result = model.findData(searchFor);
+	private void findBytes(String searchFor, long startIndex) {
+		long result = model.findData(searchFor, startIndex);
+		lastFindIndex = result;		//record the result of the search
+		lastFindString = searchFor;	//record the search terms
 		if(result == -1) {
 			showMessage("Could not find " + searchFor);
 		} else {
@@ -394,13 +432,14 @@
 		getSite().getPage().addPostSelectionListener(selectListener);
 	}
 	
+	@SuppressWarnings("deprecation")
 	public void init(IEditorSite site, IEditorInput input)
      throws PartInitException {
 		 
 		 if(input instanceof FileEditorInput) {
 			 fileInput=(FileEditorInput) input;
 			IPath fileLocation=fileInput.getPath();
-			File file=fileLocation.toFile();
+			file=fileLocation.toFile();
 			 openDumpFile(file.getAbsolutePath());
 			 setTitle(file.getName());
 			 maxPageNum = (int)(file.length() / pageSize);
@@ -437,22 +476,55 @@
 		updateDisplay(jumpto);
 		
 	}
-	
-//	private void jumpToAddress(long jumpto) {
-//		pageNum = (int)(jumpto / pageSize);
-//		
-//		updateDisplay();
-//	}
-	
+
 	private void makeActions() {
 		
 		createDoubleClick();
 		createJumpButton();
 		createFindButton();
+		createFindNextButton();
 		createBookmarkButton();
 		
+		//the following actions do not have any external visualisation such as a toolbar or context menu
+		
+		createNextPageAction();
+		createPreviousPageAction();
 	}
 
+	@SuppressWarnings("deprecation")
+	private void createNextPageAction() {
+		actionNextPage = new Action() {
+			public void run() {
+				updateDisplay(currentPos + getNumberOfElementsPerPage());
+			}
+		};
+		actionNextPage.setActionDefinitionId("org.apache.kato.plugins.hexeditor.commands.nextPage");		
+		getSite().getKeyBindingService().registerAction(actionNextPage);
+		actionNextPage.setText("Next Page");
+		actionNextPage.setToolTipText("Next Page");
+		actionNextPage.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
+				getImageDescriptor(ISharedImages.IMG_OPEN_MARKER));
+	}
+	
+	@SuppressWarnings("deprecation")
+	private void createPreviousPageAction() {
+		actionPreviousPage = new Action() {
+			public void run() {
+				long pos = currentPos - getNumberOfElementsPerPage();
+				if(pos < 0) {
+					pos = 0;
+				}
+				updateDisplay(pos);
+			}
+		};
+		actionPreviousPage.setActionDefinitionId("org.apache.kato.plugins.hexeditor.commands.previousPage");		
+		getSite().getKeyBindingService().registerAction(actionPreviousPage);
+		actionPreviousPage.setText("Previous Page");
+		actionPreviousPage.setToolTipText("Previous Page");
+		actionPreviousPage.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
+				getImageDescriptor(ISharedImages.IMG_OPEN_MARKER));
+	}
+	
 	private void openDumpFile(String path) {
 		if(model != null) {
 			model.dispose();
@@ -486,6 +558,7 @@
 		}
 		clearEyecatchers();
 		currentPos = jumpto;
+		pageNum = (int)(jumpto / pageSize);
 		labelProvider.setRowCount(0);		//reset the row count
 		viewer.setInput(model);
 		viewer.getTable().setSelection(0);
@@ -500,12 +573,14 @@
 	
 	private void signalSourceChange() {
 		ISourceProviderService service = (ISourceProviderService)getSite().getWorkbenchWindow().getService(ISourceProviderService.class);
-		BinarySourceProvider bsp = (BinarySourceProvider)service.getSourceProvider("org.apache.kato.tools.plugins.hexeditor.views.BinarySourceProvider");
+		BinarySourceProvider bsp = (BinarySourceProvider)service.getSourceProvider("org.apache.kato.tools.plugins.hexeditor.BinarySourceProvider");
 		if(bsp == null) {
 			System.err.println("HexViewer : Could not get BSP");
 			return;
 		}
-		bsp.sourceChanged(1, "test", "new value");
+		bsp.getCurrentState().put(BinarySourceProvider.STATE_LAST_EDITOR, this);		//set this editor instance as the last
+		bsp.getCurrentState().put(BinarySourceProvider.STATE_LAST_FILE, file);		//set the edited file instance
+		bsp.sourceChanged(1, "Editor", this);
 	}
 	
 	/**
@@ -524,15 +599,27 @@
 	}
 	
 	private void setEyecatchers(Color colour) {
+		setEyecatchers(model.getEyecatchers(), colour);
+	}
+	
+	private void setEyecatchers(Iterator<Eyecatcher> catchers, Color colour) {
 		Table table = viewer.getTable();
-		Eyecatcher eye = model.getEyecatcher();
-		for(int i = 0; i < (eye.getText().length() / 2); i++) {
-			long row = (eye.getLocation() + i) / 16;
-			long index = ((eye.getLocation() + i) % 16) + 1;				//+1 to skip offset column at the start
-			TableItem item = table.getItem((int)row);
-			CellLocation location = new CellLocation(item, (int)index, colour);
-			location.apply();
-			cells.add(location);
+		for(; catchers.hasNext(); ){
+			Eyecatcher eye = catchers.next();
+			for(int i = 0; i < eye.getText().length(); i++) {
+				long row = (eye.getLocation() + i) / 16;
+				long index = ((eye.getLocation() + i) % 16) + 1;				//+1 to skip offset column at the start
+				TableItem item = table.getItem((int)row);
+				CellLocation location = new CellLocation(item, (int)index, colour);
+				location.apply();
+				cells.add(location);
+			}
+		}
+	}
+	
+	public void setEyecatchers(Collection<Object> eyecatchers, Color colour) {
+		for(Object eyecatcher: eyecatchers) {
+			setEyecatchers(model.getEyecatchersOnPage(eyecatcher.toString()), colour);
 		}
 	}
 	

Modified: incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/eyecatchers/Eyecatcher.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/eyecatchers/Eyecatcher.java?rev=807643&r1=807642&r2=807643&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/eyecatchers/Eyecatcher.java (original)
+++ incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/eyecatchers/Eyecatcher.java Tue Aug 25 14:10:11 2009
@@ -1,49 +1,57 @@
-/*******************************************************************************
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *   http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- ******************************************************************************/
-package org.apache.kato.tools.plugins.hexeditor.eyecatchers;
-
-public class Eyecatcher {
-	private long location = 0;
-	private String text = null;
-
-	public Eyecatcher() {
-		//default constructor
-	}
-	
-	public Eyecatcher(String text) {
-		this.text = text;
-	}
-	
-	public long getLocation() {
-		return location;
-	}
-	
-	public void setLocation(long location) {
-		this.location = location;
-	}
-	
-	public String getText() {
-		return text;
-	}
-	
-	public void setText(String text) {
-		this.text = text;
-	}
-	
-	public Eyecatcher(long location, String text) {
-		super();
-		this.location = location;
-		this.text = text;
-	}
-}
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.tools.plugins.hexeditor.eyecatchers;
+
+public class Eyecatcher {
+	private long location = 0;
+	private byte[] searchFor = null;
+
+	public Eyecatcher() {
+		//default constructor
+	}
+	
+	public Eyecatcher(String text) {
+		this(0, text.getBytes());
+	}
+	
+	public long getLocation() {
+		return location;
+	}
+	
+	public void setLocation(long location) {
+		this.location = location;
+	}
+	
+	public byte[] getSearchFor() {
+		return searchFor;
+	}
+
+	public void setSearchFor(byte[] searchFor) {
+		this.searchFor = searchFor;
+	}
+
+	public String getText() {
+		return new String(searchFor);
+	}
+	
+	public void setText(String text) {
+		searchFor = text.getBytes();
+	}
+	
+	public Eyecatcher(long location, byte[] searchFor) {
+		super();
+		this.location = location;
+		this.searchFor = searchFor;
+	}
+}

Modified: incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/eyecatchers/EyecatcherScanner.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/eyecatchers/EyecatcherScanner.java?rev=807643&r1=807642&r2=807643&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/eyecatchers/EyecatcherScanner.java (original)
+++ incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/eyecatchers/EyecatcherScanner.java Tue Aug 25 14:10:11 2009
@@ -1,110 +1,157 @@
-/*******************************************************************************
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *   http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- ******************************************************************************/
-package org.apache.kato.tools.plugins.hexeditor.eyecatchers;
-//scans a given set of bytes for known eyecatchers
-public class EyecatcherScanner {
-	private static final int STATE_SCANNING = 1;
-	private static final int STATE_MATCHING = 2;
-	private static final int STATE_MATCHED = 3;
-	
-	private int state = STATE_SCANNING;
-	private int index = -1;				//index of any matched eye catcher
-	private int location = -1;			//location within search bytes
-	private Eyecatcher eyecatcher = null;
-
-	private String[] eyecatchers = new String[]{"C4D9F240"};
-	
-	//returns true if an eyecatcher was found
-	public boolean scan(byte[] bytes) {
-		for(int i = 0; i < eyecatchers.length; i++) {
-			byte[] searchfor = stringToBytes(eyecatchers[i]);
-			startScanning(searchfor, bytes);
-			if(state == STATE_MATCHED) {
-				index = 1;
-				eyecatcher = new Eyecatcher(location, eyecatchers[i]);
-				return true;
-			}
-		}
-		reset();		//remove any currently set eyecatcher
-		return false;
-	}
-	
-	//returns true if an eyecatcher was found
-	public boolean scan(byte[] bytes, String searchFor) {
-		byte[] searchfor = stringToBytes(searchFor);
-		startScanning(searchfor, bytes);
-		if(state == STATE_MATCHED) {
-			index = 1;
-			eyecatcher = new Eyecatcher(location, searchFor);
-			return true;
-		}
-		reset();		//remove any currently set eyecatcher
-		return false;
-	}
-	
-	//convert a hex string into a byte array equivalent
-	private byte[] stringToBytes(String hex) {
-		byte[] bytes= new byte[hex.length() / 2];
-		for(int i = 0, j = 0; i < hex.length(); i+=2, j++) {
-			int data = Integer.parseInt(hex.substring(i, i+2), 16);
-			bytes[j] = (byte)data;
-		}
-		return bytes;
-	}
-	
-	public void reset() {
-		eyecatcher = null;
-	}
-	
-	public boolean hasEyecatcher() {
-		return (eyecatcher != null);
-	}
-	
-	public Eyecatcher getEyecatcher() {
-		return eyecatcher;
-	}
-	
-	private void startScanning(byte[] searchfor, byte[] bytes) {
-		state = STATE_SCANNING;
-		int marker = 0;
-		for(int i = 0; i < bytes.length; i++) {
-			switch (state) {
-				case STATE_SCANNING :
-					if(bytes[i] == searchfor[0]) {
-						if(searchfor.length == 1) {			//only searching for a single byte
-							state = STATE_MATCHED;
-							location = i;
-							return;
-						}
-						marker = 1;
-						state = STATE_MATCHING;
-					}
-					break;
-				case STATE_MATCHING :
-					if(searchfor[marker] == bytes[i]) {
-						marker++;
-						if(marker == searchfor.length) {
-							state = STATE_MATCHED;
-						}
-					} else {			//no match
-						state = STATE_SCANNING;
-					}
-					break;
-				case STATE_MATCHED :
-					location = i - searchfor.length;
-					return;
-			}
-		}
-	}
-}
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.tools.plugins.hexeditor.eyecatchers;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+//scans a given set of bytes for known eyecatchers
+public class EyecatcherScanner implements Iterator<Eyecatcher> {
+	private static final int STATE_SCANNING = 1;
+	private static final int STATE_MATCHING = 2;
+	private static final int STATE_MATCHED = 3;
+	private static final int STATE_FINISHED = 4;
+	
+	private int state = STATE_SCANNING;
+	private int location = -1;			//location within search bytes
+	private Eyecatcher eyecatcher = null;
+	byte[] searchfor = null;
+	byte[] buffer = null;
+	boolean isDirty = true;
+
+//	private String[] eyecatchers = new String[]{"C4D9F240"};
+	
+	//returns true if an eyecatcher was found
+//	public boolean scan(byte[] bytes) {
+//		for(int i = 0; i < eyecatchers.length; i++) {
+//			byte[] searchfor = stringToBytes(eyecatchers[i]);
+//			scan(searchfor, bytes, 0);
+//			if(state == STATE_MATCHED) {
+//				eyecatcher = new Eyecatcher(location, eyecatchers[i]);
+//				return true;
+//			}
+//		}
+//		reset();		//remove any currently set eyecatcher
+//		return false;
+//	}
+	
+	//returns true if an eyecatcher was found
+	public void scan(byte[] bytes, String text) {
+		if(text.startsWith("0x")) {
+			searchfor = hexStringToBytes(text);
+		} else {
+			searchfor = text.getBytes();
+		}
+		buffer = bytes;
+		location = -1;
+		eyecatcher = null;
+		isDirty = true;
+	}
+	
+	public boolean hasNext() {
+		if(isDirty) {
+			getNextEyecather();
+		}
+		return !(state == STATE_FINISHED);
+	}
+
+	private void getNextEyecather() {
+		scan(searchfor, buffer, location + 1);
+		if(state == STATE_MATCHED) {
+			eyecatcher = new Eyecatcher(location, searchfor);
+		}
+		isDirty = false;
+	}
+	
+	public Eyecatcher next() {
+		if(isDirty) {
+			getNextEyecather();
+		}
+		if(state == STATE_FINISHED) {
+			throw new NoSuchElementException("There are no more eyecathers");
+		} else {
+			isDirty = true;
+			return eyecatcher;
+		}
+	}
+
+	public void remove() {
+		throw new UnsupportedOperationException("The eyecatcher iterator is read only");
+	}
+
+	//convert a hex string into a byte array equivalent
+	private byte[] hexStringToBytes(String hex) {
+		if(hex.startsWith("0x")) {
+			hex = hex.substring(2);
+		}
+		byte[] bytes= new byte[hex.length() / 2];
+		for(int i = 0, j = 0; i < hex.length(); i+=2, j++) {
+			int data = Integer.parseInt(hex.substring(i, i+2), 16);
+			bytes[j] = (byte)data;
+		}
+		return bytes;
+	}
+	
+	public void reset() {
+		eyecatcher = null;
+	}
+	
+	public boolean hasEyecatcher() {
+		return (eyecatcher != null);
+	}
+	
+	public Eyecatcher getEyecatcher() {
+		return eyecatcher;
+	}
+	
+	/**
+	 * Scan for a particular byte sequence
+	 * @param searchfor sequence to search for
+	 * @param bytes bytes to search
+	 * @param index starting index for the search
+	 */
+	private void scan(byte[] searchfor, byte[] bytes, int index) {
+		state = STATE_SCANNING;
+		int marker = 0;
+		for(int i = index; i < bytes.length; i++) {
+			switch (state) {
+				case STATE_SCANNING :
+					if(bytes[i] == searchfor[0]) {
+						if(searchfor.length == 1) {			//only searching for a single byte
+							state = STATE_MATCHED;
+							location = i;
+							return;
+						}
+						marker = 1;
+						state = STATE_MATCHING;
+					}
+					break;
+				case STATE_MATCHING :
+					if(searchfor[marker] == bytes[i]) {
+						marker++;
+						if(marker == searchfor.length) {
+							state = STATE_MATCHED;
+						}
+					} else {			//no match
+						state = STATE_SCANNING;
+					}
+					break;
+				case STATE_MATCHED :
+					location = i - searchfor.length;
+					return;
+			}
+		}
+		state = STATE_FINISHED;			//the entire buffer has been searched
+	}
+}

Modified: incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/views/BinarySourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/views/BinarySourceProvider.java?rev=807643&r1=807642&r2=807643&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/views/BinarySourceProvider.java (original)
+++ incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/views/BinarySourceProvider.java Tue Aug 25 14:10:11 2009
@@ -1,48 +1,53 @@
-/*******************************************************************************
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *   http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- ******************************************************************************/
-package org.apache.kato.tools.plugins.hexeditor.views;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.ui.AbstractSourceProvider;
-import org.eclipse.ui.services.IServiceLocator;
-
-public class BinarySourceProvider extends AbstractSourceProvider {
-	private HashMap<String, String> state = new HashMap<String, String>();
-	
-	public void dispose() {
-		System.err.println("Disposed of source provider");
-	}
-
-	public Map getCurrentState() {
-		return state;
-	}
-
-	public String[] getProvidedSourceNames() {
-		return new String[] {"org.apache.kato.tools.plugins.hexeditor.BinarySourceProvider"};
-	}
-
-	@Override
-	public void initialize(IServiceLocator locator) {
-		super.initialize(locator);
-		state.put("org.apache.kato.tools.plugins.hexeditor.views.BinaryData", "unused");
-		System.err.println("Initialised the service");
-	}
-
-	public void sourceChanged(int sourcePriority, String sourceName, Object sourceValue) {
-		fireSourceChanged(sourcePriority, sourceName, sourceValue);
-	}
-	
-}
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.tools.plugins.hexeditor.views;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.ui.AbstractSourceProvider;
+import org.eclipse.ui.services.IServiceLocator;
+
+public class BinarySourceProvider extends AbstractSourceProvider {
+	public static final String STATE_LAST_EDITOR = "org.apache.kato.tools.plugins.hexeditor.LastEditor";
+	public static final String STATE_LAST_FILE = "org.apache.kato.tools.plugins.hexeditor.LastFile";
+	
+	private HashMap<String, Object> state = new HashMap<String, Object>();
+	
+	public void dispose() {
+		System.err.println("Disposed of source provider");
+	}
+
+	public Map<String, Object> getCurrentState() {
+		return state;
+	}
+
+	public String[] getProvidedSourceNames() {
+		return new String[] {"org.apache.kato.tools.plugins.hexeditor.BinarySourceProvider"};
+	}
+
+	@Override
+	public void initialize(IServiceLocator locator) {
+		super.initialize(locator);
+		state.put("org.apache.kato.tools.plugins.hexeditor.views.BinaryData", "unused");
+		state.put(STATE_LAST_EDITOR, null);			//set the last editor to null
+		state.put(STATE_LAST_FILE, null);			//set the last file edited to null
+		System.err.println("Initialised the service");
+	}
+
+	public void sourceChanged(int sourcePriority, String sourceName, Object sourceValue) {
+		fireSourceChanged(sourcePriority, sourceName, sourceValue);
+	}
+	
+}

Modified: incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/views/BookmarksView.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/views/BookmarksView.java?rev=807643&r1=807642&r2=807643&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/views/BookmarksView.java (original)
+++ incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/views/BookmarksView.java Tue Aug 25 14:10:11 2009
@@ -23,6 +23,7 @@
 import java.security.NoSuchAlgorithmException;
 import java.util.Properties;
 
+import org.apache.kato.tools.plugins.hexeditor.editors.BinaryHexViewer;
 import org.apache.kato.tools.plugins.hexeditor.editors.FileEditorSelection;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IMenuListener;
@@ -56,6 +57,7 @@
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.part.ViewPart;
+import org.eclipse.ui.services.ISourceProviderService;
 
 import org.apache.kato.tools.plugins.hexeditor.Activator;
 
@@ -196,6 +198,7 @@
 		hookDoubleClickAction();
 		contributeToActionBars();
 		hookPageSelection();
+		hookHexEditor();
 	}
 
 	@Override
@@ -203,6 +206,15 @@
 		super.dispose();
 	}
 
+	private void hookHexEditor() {
+		ISourceProviderService service = (ISourceProviderService)getSite().getWorkbenchWindow().getService(ISourceProviderService.class);
+		BinarySourceProvider bsp = (BinarySourceProvider)service.getSourceProvider("org.apache.kato.tools.plugins.hexeditor.BinarySourceProvider");
+		if(bsp.getCurrentState().get(BinarySourceProvider.STATE_LAST_FILE) != null) {		//see if an editor is already active
+			File file = (File) bsp.getCurrentState().get(BinarySourceProvider.STATE_LAST_FILE);
+			updateBookmarks(file.getPath());
+		}
+	}
+	
 	private void configureProviders() {
 		viewer.setContentProvider(contentProvider);
 		viewer.setLabelProvider(new ViewLabelProvider());
@@ -250,13 +262,14 @@
 		if(!(selection instanceof IStructuredSelection)) return;
 		IStructuredSelection iss = (IStructuredSelection) selection;
 		if(iss.getFirstElement() instanceof FileEditorSelection) {
-			updateBookmarks((FileEditorSelection)iss.getFirstElement());
+			FileEditorSelection fes = (FileEditorSelection)iss.getFirstElement();
+			updateBookmarks(fes.getPath());
 			//this.getSite().getWorkbenchWindow().getWorkbench().getViewRegistry().find(arg0)
 		}
 	}
 	
-	private void updateBookmarks(FileEditorSelection selection) {
-		byte[] fingerprint = md5.digest(selection.getPath().getBytes());
+	private void updateBookmarks(String path) {
+		byte[] fingerprint = md5.digest(path.getBytes());
 		StringBuffer data = new StringBuffer();
 		for(int i = 0; i < fingerprint.length; i++) {
 			data.append(Integer.toHexString(fingerprint[i] & 0xff));

Modified: incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/views/EyecatcherView.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/views/EyecatcherView.java?rev=807643&r1=807642&r2=807643&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/views/EyecatcherView.java (original)
+++ incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/views/EyecatcherView.java Tue Aug 25 14:10:11 2009
@@ -23,6 +23,7 @@
 import java.util.Properties;
 
 import org.apache.kato.tools.plugins.hexeditor.Activator;
+import org.apache.kato.tools.plugins.hexeditor.editors.BinaryHexViewer;
 import org.apache.kato.tools.plugins.hexeditor.editors.FileEditorSelection;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IMenuListener;
@@ -43,6 +44,7 @@
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.jface.viewers.ViewerSorter;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.FileDialog;
@@ -63,34 +65,26 @@
 
 
 /**
- * This sample class demonstrates how to plug-in a new
- * workbench view. The view shows data obtained from the
- * model. The sample creates a dummy model on the fly,
- * but a real implementation would connect to the model
- * available either in this or another plug-in (e.g. the workspace).
- * The view is connected to the model using a content provider.
- * <p>
- * The view uses a label provider to define how model
- * objects should be presented in the view. Each
- * view can present the same model objects using
- * different labels and icons, if needed. Alternatively,
- * a single label provider can be shared between views
- * in order to ensure that objects of the same type are
- * presented in the same way everywhere.
- * <p>
+ * Eyecatchers are known sequences which are of interest to the user.
+ * This view provides a way of creating / editing / deleting these
+ * eyecatchers and is responsible for highlighting them in the current
+ * editor.
  */
 
 public class EyecatcherView extends ViewPart {
 	private TableViewer viewer;
-	private Action actionAdd;
-	private Action actionDelete;
-	private Action doubleClickAction;
-	private Properties model = new Properties();
-	private File currentFile = null;
-	private ViewContentProvider contentProvider = new ViewContentProvider();
-	private boolean isDirty = false;
-	private ISelectionListener selectListener = null;
+	private Action actionAdd;							//action to add an eyecatcher
+	private Action actionDelete;						//action to delete an eyecatcher
+	private Action doubleClickAction;					//not currently used
+	private Properties model = new Properties();		//eyecatchers are simple name - value pairs
+	private File currentFile = null;					//the file containing the currently loaded eyecatchers
+	private ViewContentProvider contentProvider = new ViewContentProvider();	//content provider for the view
+	@SuppressWarnings("unused")
+	private boolean isDirty = false;					//flag which is true if the eyecatchers have been modified and require saving
+	@SuppressWarnings("unused")
+	private ISelectionListener selectListener = null;	//hook for IDE selection events	
 	private IPartListener partListerner = null;
+	private Color highlight = new Color(null, 255, 128, 255);		//the colour to highlight eyecatchers in the editor
 	
 
 	/*
@@ -113,11 +107,23 @@
 			return model.keySet().toArray();
 		}
 		
+		/**
+		 * Adds an eyecatcher to the model
+		 * @param viewer the viewer to display the new eyecatcher in
+		 * @param id the identifier for the eyecatcher
+		 * @param description the eyecatcher description
+		 */
 		public void addEyecatcher(TableViewer viewer, String id, String description) {
 			model.put(id, description);
 			viewer.add(id);
 		}
 	}
+	
+	
+	/**
+	 * The label provider lists either the key or value for the underlying
+	 * properties file which represents the model
+	 */
 	class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
 		
 		public String getColumnText(Object obj, int index) {
@@ -134,14 +140,20 @@
 			//return getImage(obj);
 			return null;
 		}
+		
 		public Image getImage(Object obj) {
 			return PlatformUI.getWorkbench().
 					getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
 		}
 	}
+	
 	class NameSorter extends ViewerSorter {
 	}
 
+	/**
+	 * Loads a model
+	 * @param name the name of the property file from which to read the model. If null then the user is prompted for a file name
+	 */
 	private void loadData(String name) {
 		try {
 			if (name == null) {		//prompt if a null name is supplied
@@ -166,6 +178,11 @@
 		} 	
 	}
 	
+	/**
+	 * Add an eyecatcher
+	 * @param id identifier for this eyecatcher
+	 * @param description eyecatcher description
+	 */
 	public void addEyecatcher(String id, String description) {
 		contentProvider.addEyecatcher(viewer, id, description);
 		isDirty = true;
@@ -203,6 +220,9 @@
 		super.dispose();
 	}
 
+	/**
+	 * Set the data providers for this view
+	 */
 	private void configureProviders() {
 		viewer.setContentProvider(contentProvider);
 		viewer.setLabelProvider(new ViewLabelProvider());
@@ -211,6 +231,9 @@
 		getSite().setSelectionProvider(viewer);
 	}
 	
+	/**
+	 * This configures the table which shows the eyecatcher name - value pairs
+	 */
 	private void configureTable() {
 		Table table = viewer.getTable();
 		table.setHeaderVisible(true);
@@ -223,6 +246,9 @@
 		column.setWidth(200);
 	}
 	
+	/**
+	 * Setup the right click context menu for this view
+	 */
 	private void hookContextMenu() {
 		MenuManager menuMgr = new MenuManager("#PopupMenu");
 		menuMgr.setRemoveAllWhenShown(true);
@@ -236,12 +262,19 @@
 		getSite().registerContextMenu(menuMgr, viewer);
 	}
 
+	/* (non-Javadoc)
+	 * @see org.eclipse.ui.part.ViewPart#saveState(org.eclipse.ui.IMemento)
+	 * Ensures that any modifications to the eyecatchers are also saved
+	 */
 	@Override
 	public void saveState(IMemento memento) {
 		super.saveState(memento);
 		saveEyecatchers();
 	}
 
+	/**
+	 * Save the eyecatchers to the current property file
+	 */
 	private void saveEyecatchers() {
 		if (currentFile == null) return; 		//nothing to save
 		try {
@@ -255,6 +288,9 @@
 		}
 	}
 	
+	/**
+	 * Define listeners to respond to selection events
+	 */
 	private void hookPageSelection() {
 		selectListener = new ISelectionListener() {
 			public void selectionChanged(IWorkbenchPart part, ISelection selection) {
@@ -282,22 +318,34 @@
 		getSite().getPage().addPartListener(partListerner);
 	}
 	
+	/**
+	 * The hex editor and this view may be displayed independently of each other. The hex editor defines a custom service
+	 * which this view can respond to.
+	 */
 	private void hookHexEditor() {
 		ISourceProviderService service = (ISourceProviderService)getSite().getWorkbenchWindow().getService(ISourceProviderService.class);
-		BinarySourceProvider bsp = (BinarySourceProvider)service.getSourceProvider("org.apache.kato.tools.plugins.hexeditor.views.BinarySourceProvider");
+		BinarySourceProvider bsp = (BinarySourceProvider)service.getSourceProvider("org.apache.kato.tools.plugins.hexeditor.BinarySourceProvider");
 		if(bsp == null) {
 			System.err.println("Eyecatcher : Could not get BSP");
 			return;
 		}
 		bsp.addSourceProviderListener(new ISourceProviderListener() {
+			@SuppressWarnings("unchecked")
 			public void sourceChanged(int sourcePriority, Map sourceValuesByName) {
 				System.err.println("Source changed : map");
 			}
 			
 			public void sourceChanged(int sourcePriority, String sourceName, Object sourceValue)  {
-				System.err.println("Source changed : item");
+				if(sourceValue instanceof BinaryHexViewer) {
+					BinaryHexViewer bhv = (BinaryHexViewer) sourceValue;
+					bhv.setEyecatchers(model.keySet(), highlight);
+				}
 			}
 		});
+		if(bsp.getCurrentState().get(BinarySourceProvider.STATE_LAST_EDITOR) != null) {		//see if an editor is already active
+			BinaryHexViewer bhv = (BinaryHexViewer) bsp.getCurrentState().get(BinarySourceProvider.STATE_LAST_EDITOR);
+			bhv.setEyecatchers(model.keySet(), highlight);
+		}
 	}
 	
 	protected void pageSelectionChanged(IWorkbenchPart part, ISelection selection) {

Modified: incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/views/RawByteModel.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/views/RawByteModel.java?rev=807643&r1=807642&r2=807643&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/views/RawByteModel.java (original)
+++ incubator/kato/trunk/org.apache.kato.eclipse/plugins/kato.hexeditor.plugin/src/main/java/org/apache/kato/tools/plugins/hexeditor/views/RawByteModel.java Tue Aug 25 14:10:11 2009
@@ -1,136 +1,150 @@
-/*******************************************************************************
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * 
- *   http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- ******************************************************************************/
-package org.apache.kato.tools.plugins.hexeditor.views;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-
-import javax.imageio.stream.FileImageInputStream;
-
-import org.apache.kato.tools.plugins.hexeditor.eyecatchers.Eyecatcher;
-import org.apache.kato.tools.plugins.hexeditor.eyecatchers.EyecatcherScanner;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-
-//this is the model for the view i.e. the raw dump file
-public class RawByteModel implements IStructuredContentProvider {
-	private FileImageInputStream file = null;
-	private long ptrFile = 0;			//current seek pointer
-	private final int pageSize = 40 * 16;		//number of items to display on a page
-	private byte[] buffer = new byte[pageSize];	//byte buffer
-	private int bufferSize = 0;
-	private EyecatcherScanner scanner = new EyecatcherScanner();
-	
-	public RawByteModel(String path) {
-		try {
-			file = new FileImageInputStream(new RandomAccessFile(path, "r"));
-			readIntoBuffer(0);
-		} catch (FileNotFoundException e) {
-			throw new IllegalArgumentException("The file " + path + " does not exist or could not be found");
-		}
-	}
-
-	public long getOffset() {
-		return ptrFile;		//the offset into the file
-	}
-
-	//accepts either an ASCII or hex identified string
-	public long findData(String searchFor) {
-		String hex = null;
-		if (searchFor.startsWith("0x")) {
-			hex = searchFor.substring(2);			//strip the 0x prefix
-		} else {
-			StringBuffer buffer = new StringBuffer(searchFor.length() * 2);		//correctly intialise the buffer size
-			for(int i = 0; i < searchFor.length(); i++) {
-				buffer.append(Integer.toHexString(0xFF & searchFor.charAt(i)));
-			}
-			hex = buffer.toString();
-		}
-		scanner.reset();				//reset the scanner
-		long mark = ptrFile;			//note where we are in case we don't find the data we're looking for
-		readIntoBuffer(0);				//start searching from the beginning of the data
-		int bufferDiscardCount = 0;		//count how many times we discard the current buffer contents searching for a match
-		while(!isEOF()) {
-			if (scanner.scan(buffer, hex)) {	//found the search terms
-				long index = (bufferDiscardCount * bufferSize); // +  scanner.getEyecatcher().getLocation();		//position in file
-				readIntoBuffer(index);		//ensure that the buffer contains a complete display page to avoid overwriting the eyecatcher
-				return index;
-			}
-			bufferDiscardCount++;
-			readIntoBuffer(bufferDiscardCount * bufferSize);	//carry on reading from the current point
-		}
-		readIntoBuffer(mark);			//restore where we were
-		return -1;		//no match has been found
-	}
-	
-	public byte getData(long index) {
-		if((index < ptrFile) || ((ptrFile + bufferSize) <= index)) {		//currently have required index in buffer
-			readIntoBuffer(index);
-			scanner.reset();		//if we are reading a new buffer, then invalidate the scanner
-		}
-		return buffer[(int)(index - ptrFile)];
-	}
-	
-	public boolean isInRange(long index) {
-		return (!isEOF()) && (index < file.length());
-	}
-	
-	public boolean isEOF() {
-		return (bufferSize == -1);
-	}
-	
-	private void readIntoBuffer(long index) {
-		if (isEOF() || (index >= file.length())) {
-			throw new IllegalStateException("Cannot read beyond the end of a file");
-		}
-		try {
-			ptrFile = index;
-			file.seek(index);
-			bufferSize = file.read(buffer);
-		} catch (IOException e) {
-			throw new RuntimeException("Could not read data", e);
-		}
-		
-	}
-	
-	public Object[] getElements(Object arg0) {
-		return null;
-	}
-
-	public void dispose() {
-		try {
-			file.close();
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-	}
-
-	public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
-		// TODO Auto-generated method stub
-
-	}
-
-	public boolean hasEyeCatcher(Eyecatcher searchfor) {
-		return false;
-	}
-	
-	public boolean hasEyeCatcher() {
-		return scanner.hasEyecatcher();
-	}
-	
-	public Eyecatcher getEyecatcher() {
-		return scanner.getEyecatcher();
-	}
-}
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.tools.plugins.hexeditor.views;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.Iterator;
+
+import javax.imageio.stream.FileImageInputStream;
+
+import org.apache.kato.tools.plugins.hexeditor.eyecatchers.Eyecatcher;
+import org.apache.kato.tools.plugins.hexeditor.eyecatchers.EyecatcherScanner;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+//this is the model for the view i.e. the raw dump file
+public class RawByteModel implements IStructuredContentProvider {
+	private FileImageInputStream file = null;
+	private long ptrFile = 0;			//current seek pointer
+	private final int pageSize = 40 * 16;		//number of items to display on a page
+	private byte[] buffer = new byte[pageSize];	//byte buffer
+	private int bufferSize = 0;
+	private EyecatcherScanner scanner = new EyecatcherScanner();
+	
+	public RawByteModel(String path) {
+		try {
+			file = new FileImageInputStream(new RandomAccessFile(path, "r"));
+			readIntoBuffer(0);
+		} catch (FileNotFoundException e) {
+			throw new IllegalArgumentException("The file " + path + " does not exist or could not be found");
+		}
+	}
+
+	public long getOffset() {
+		return ptrFile;		//the offset into the file
+	}
+
+	//accepts either an ASCII or hex identified string
+	public long findData(String searchFor, long startIndex) {
+//		String hex = null;
+//		if (searchFor.startsWith("0x")) {
+//			hex = searchFor.substring(2);			//strip the 0x prefix
+//		} else {
+//			StringBuffer buffer = new StringBuffer(searchFor.length() * 2);		//correctly intialise the buffer size
+//			for(int i = 0; i < searchFor.length(); i++) {
+//				buffer.append(Integer.toHexString(0xFF & searchFor.charAt(i)));
+//			}
+//			hex = buffer.toString();
+//		}
+		scanner.reset();				//reset the scanner
+		long mark = ptrFile;			//note where we are in case we don't find the data we're looking for
+		readIntoBuffer(startIndex);		//start searching from the start index
+		int bufferDiscardCount = 0;		//count how many times we discard the current buffer contents searching for a match
+		while(!isEOF()) {
+			scanner.scan(buffer, searchFor);
+			if (scanner.hasNext()) {	//found the search terms
+				long index = startIndex + (bufferDiscardCount * bufferSize); // +  scanner.getEyecatcher().getLocation();		//position in file
+				readIntoBuffer(index);		//ensure that the buffer contains a complete display page to avoid overwriting the eyecatcher
+				return index;
+			}
+			bufferDiscardCount++;
+			readIntoBuffer(bufferDiscardCount * bufferSize);	//carry on reading from the current point
+		}
+		readIntoBuffer(mark);			//restore where we were
+		return -1;		//no match has been found
+	}
+	
+	public byte getData(long index) {
+		if((index < ptrFile) || ((ptrFile + bufferSize) <= index)) {		//currently have required index in buffer
+			readIntoBuffer(index);
+			scanner.reset();		//if we are reading a new buffer, then invalidate the scanner
+		}
+		return buffer[(int)(index - ptrFile)];
+	}
+	
+	public boolean isInRange(long index) {
+		return (!isEOF()) && (index < file.length());
+	}
+	
+	public boolean isEOF() {
+		return (bufferSize == -1);
+	}
+	
+	private void readIntoBuffer(long index) {
+		if (isEOF() || (index >= file.length())) {
+			throw new IllegalStateException("Cannot read beyond the end of a file");
+		}
+		try {
+			ptrFile = index;
+			file.seek(index);
+			bufferSize = file.read(buffer);
+		} catch (IOException e) {
+			throw new RuntimeException("Could not read data", e);
+		}
+		
+	}
+	
+	public Object[] getElements(Object arg0) {
+		return null;
+	}
+
+	public void dispose() {
+		try {
+			file.close();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+	public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+		// TODO Auto-generated method stub
+
+	}
+
+	public boolean hasEyeCatcher(Eyecatcher searchfor) {
+		return false;
+	}
+	
+	public boolean hasEyeCatcher() {
+		return scanner.hasEyecatcher();
+	}
+	
+	public Iterator<Eyecatcher> getEyecatchers() {
+		return scanner;
+	}
+	
+	/**
+	 * Locate an eyecatcher on the currently displayed
+	 * page.
+	 * @param text
+	 * @return
+	 */
+	public Iterator<Eyecatcher> getEyecatchersOnPage(String text) {
+		EyecatcherScanner scanner = new EyecatcherScanner();
+		scanner.scan(buffer, text);
+		return scanner;
+	}
+}



Mime
View raw message