<commit_before>package ch.ntb.inf.deep.eclipse.ui.view;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;

import ch.ntb.inf.deep.eclipse.ui.model.MemorySegment;
import ch.ntb.inf.deep.loader.Downloader;
import ch.ntb.inf.deep.loader.DownloaderException;
import ch.ntb.inf.deep.loader.UsbMpc555Loader;

public class MemoryView extends ViewPart implements Listener {
	public static final String ID = "ch.ntb.inf.deep.eclipse.ui.view.MemoryView";
	private TableViewer viewer;
	private Text addr;
	private Text count;
	private Button button;
	private Downloader bdi;
	
	static final byte slotSize = 4; // 4 bytes
	static {
		assert (slotSize & (slotSize - 1)) == 0; // assert: slotSize == power of
													// 2
	}

	class ViewLabelProvider extends LabelProvider implements
			ITableLabelProvider {

		public String getColumnText(Object obj, int index) {
			switch (index) {
			case 0:
				if (((MemorySegment) obj).addr == -1) {
					return "";
				}
				return String.format("0x%08X",((MemorySegment) obj).addr);
			case 1:
				if (((MemorySegment) obj).addr == -1) {
					return "";
				}
				return String.format("0x%08X", ((MemorySegment) obj).value);
			default:
				throw new RuntimeException("Should not happen");
			}
		}

		public Image getColumnImage(Object obj, int index) {
			return null;
		}
	}

	@Override
	public void createPartControl(Composite parent) {
		GridLayout layout = new GridLayout(5, false);
		parent.setLayout(layout);
		Label label = new Label(parent, SWT.NONE);
		label.setText("start address:   ");
		addr = new Text(parent, SWT.BORDER);
		addr.addListener(SWT.Verify, new Listener() {
			public void handleEvent(Event e) {
				String string = addr.getText() + e.text;
				char[] chars = new char[string.length()];
				string.getChars(0, chars.length, chars, 0);
				if (chars[0] == '0' && chars.length > 1) {// hex value
					if ((chars[1] == 'x' || chars[1] == 'X')) {
						if (chars.length > 2) {
							for (int i = 2; i < chars.length; i++) {
								if (!(('0' <= chars[i] && chars[i] <= '9')
										|| ('A' <= chars[i] && chars[i] <= 'F') || ('a' <= chars[i] && chars[i] <= 'f'))) {
									e.doit = false;
									return;
								}
							}
						}
					} else {
						e.doit = false;
						return;
					}
				} else {
					for (int i = 0; i < chars.length; i++) {
						if (!('0' <= chars[i] && chars[i] <= '9')) {
							e.doit = false;
							return;
						}
					}
				}
			}
		});
		Label label2 = new Label(parent, SWT.NONE);
		label2.setText("nofWords:   ");
		count = new Text(parent, SWT.BORDER);
		count.addListener(SWT.Verify, new Listener() {
			public void handleEvent(Event e) {
				String string = addr.getText() + e.text;
				char[] chars = new char[string.length()];
				string.getChars(0, chars.length, chars, 0);
				if (chars[0] == '0' && chars.length > 1) {// hex value
					if ((chars[1] == 'x' || chars[1] == 'X')) {
						if (chars.length > 2) {
							for (int i = 2; i < chars.length; i++) {
								if (!(('0' <= chars[i] && chars[i] <= '9')
										|| ('A' <= chars[i] && chars[i] <= 'F') || ('a' <= chars[i] && chars[i] <= 'f'))) {
									e.doit = false;
									return;
								}
							}
						}
					} else {
						e.doit = false;
						return;
					}
				} else {
					for (int i = 0; i < chars.length; i++) {
						if (!('0' <= chars[i] && chars[i] <= '9')) {
							e.doit = false;
							return;
						}
					}
				}
			}
		});

		button = new Button(parent, SWT.PUSH);
		button.setText("read");
		button.addListener(SWT.Selection, this);
		createViewer(parent);

	}

	private void createViewer(Composite parent) {
		viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
				| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
		String[] titels = { "Address", "Value" };
		int[] bounds = { 60, 230 };
		for (int i = 0; i < titels.length; i++) {
			TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
			column.getColumn().setText(titels[i]);
			column.getColumn().setWidth(bounds[i]);
			column.getColumn().setMoveable(false);
		}
		Table table = viewer.getTable();<commit_msg>fix problem with hex entries in startAddr field<commit_after>package ch.ntb.inf.deep.eclipse.ui.view;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;

import ch.ntb.inf.deep.eclipse.ui.model.MemorySegment;
import ch.ntb.inf.deep.loader.Downloader;
import ch.ntb.inf.deep.loader.DownloaderException;
import ch.ntb.inf.deep.loader.UsbMpc555Loader;

public class MemoryView extends ViewPart implements Listener {
	public static final String ID = "ch.ntb.inf.deep.eclipse.ui.view.MemoryView";
	private TableViewer viewer;
	private Text addr;
	private Text count;
	private Button button;
	private Downloader bdi;
	
	static final byte slotSize = 4; // 4 bytes
	static {
		assert (slotSize & (slotSize - 1)) == 0; // assert: slotSize == power of
													// 2
	}

	class ViewLabelProvider extends LabelProvider implements
			ITableLabelProvider {

		public String getColumnText(Object obj, int index) {
			switch (index) {
			case 0:
				if (((MemorySegment) obj).addr == -1) {
					return "";
				}
				return String.format("0x%08X",((MemorySegment) obj).addr);
			case 1:
				if (((MemorySegment) obj).addr == -1) {
					return "";
				}
				return String.format("0x%08X", ((MemorySegment) obj).value);
			default:
				throw new RuntimeException("Should not happen");
			}
		}

		public Image getColumnImage(Object obj, int index) {
			return null;
		}
	}

	@Override
	public void createPartControl(Composite parent) {
		GridLayout layout = new GridLayout(5, false);
		parent.setLayout(layout);
		Label label = new Label(parent, SWT.NONE);
		label.setText("start address:   ");
		addr = new Text(parent, SWT.BORDER);
		addr.addListener(SWT.Verify, new Listener() {
			public void handleEvent(Event e) {
				String string = addr.getText() + e.text;
				char[] chars = new char[string.length()];
				string.getChars(0, chars.length, chars, 0);
				if (chars[0] == '0' && chars.length > 1) {// hex value
					if ((chars[1] == 'x' || chars[1] == 'X')) {
						if (chars.length > 2) {
							for (int i = 2; i < chars.length; i++) {
								if (!(('0' <= chars[i] && chars[i] <= '9')
										|| ('A' <= chars[i] && chars[i] <= 'F') || ('a' <= chars[i] && chars[i] <= 'f'))) {
									e.doit = false;
									return;
								}
							}
						}
					} else {
						e.doit = false;
						return;
					}
				} else {
					for (int i = 0; i < chars.length; i++) {
						if (!('0' <= chars[i] && chars[i] <= '9')) {
							e.doit = false;
							return;
						}
					}
				}
			}
		});
		Label label2 = new Label(parent, SWT.NONE);
		label2.setText("nofWords:   ");
		count = new Text(parent, SWT.BORDER);
		count.addListener(SWT.Verify, new Listener() {
			public void handleEvent(Event e) {
				String string = count.getText() + e.text;
				char[] chars = new char[string.length()];
				string.getChars(0, chars.length, chars, 0);
				if (chars[0] == '0' && chars.length > 1) {// hex value
					if ((chars[1] == 'x' || chars[1] == 'X')) {
						if (chars.length > 2) {
							for (int i = 2; i < chars.length; i++) {
								if (!(('0' <= chars[i] && chars[i] <= '9')
										|| ('A' <= chars[i] && chars[i] <= 'F') || ('a' <= chars[i] && chars[i] <= 'f'))) {
									e.doit = false;
									return;
								}
							}
						}
					} else {
						e.doit = false;
						return;
					}
				} else {
					for (int i = 0; i < chars.length; i++) {
						if (!('0' <= chars[i] && chars[i] <= '9')) {
							e.doit = false;
							return;
						}
					}
				}
			}
		});

		button = new Button(parent, SWT.PUSH);
		button.setText("read");
		button.addListener(SWT.Selection, this);
		createViewer(parent);

	}

	private void createViewer(Composite parent) {
		viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
				| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
		String[] titels = { "Address", "Value" };
		int[] bounds = { 100, 100 };
		for (int i = 0; i < titels.length; i++) {
			TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
			column.getColumn().setText(titels[i]);
			column.getColumn().setWidth(bounds[i]);
			column.getColumn().setMoveable(false);
		}
		Table table = viewer.getTable();
{'fraction_non_alphanumeric': 0.1635926222935044, 'fraction_numerical': 0.011126704089815557, 'mean_word_length': 3.0262308313155772, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5557992', 'n_tokens_mistral': 4344, 'n_tokens_neox': 3466, 'n_words': 768}