Initial commit after migrating repo and assuring the product launches
This commit is contained in:
375
src/edu/fichte/pbi/ide/views/ConsoleView.java
Normal file
375
src/edu/fichte/pbi/ide/views/ConsoleView.java
Normal file
@ -0,0 +1,375 @@
|
||||
package edu.fichte.pbi.ide.views;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.events.TraverseEvent;
|
||||
import org.eclipse.swt.events.TraverseListener;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
import edu.fichte.pbi.ide.Activator;
|
||||
import edu.fichte.pbi.run.PluginRunner;
|
||||
import edu.fichte.pbi.run.app.IConsole;
|
||||
import edu.fichte.pbi.vm.IRunWatcher;
|
||||
import edu.fichte.pbi.vm.Settings;
|
||||
import edu.fichte.pbi.vm.storage.IEEPROMMonitor;
|
||||
|
||||
public class ConsoleView extends ViewPart implements IConsole {
|
||||
public static final String ID = "edu.fichte.pbi.ide.consoleView";
|
||||
public StyledText text;
|
||||
private StyledText inputText;
|
||||
|
||||
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
parent = new Composite(parent, SWT.NULL);
|
||||
parent.setLayout(new GridLayout(1, false));
|
||||
Label debugLabel = new Label(parent, SWT.HORIZONTAL);
|
||||
debugLabel.setText("Console");
|
||||
text = new StyledText(parent, SWT.VERTICAL | SWT.HORIZONTAL | SWT.MULTI);
|
||||
text.setAlwaysShowScrollBars(false);
|
||||
text.setEditable(false);
|
||||
Label inputLabel = new Label(parent, SWT.HORIZONTAL);
|
||||
inputLabel.setText("Input");
|
||||
GridData textGridData = new GridData();
|
||||
textGridData.horizontalAlignment = GridData.FILL;
|
||||
textGridData.verticalAlignment = GridData.FILL;
|
||||
textGridData.grabExcessHorizontalSpace = true;
|
||||
textGridData.grabExcessVerticalSpace = true;
|
||||
text.setLayoutData(textGridData);
|
||||
setScheme();
|
||||
inputText = new StyledText(parent, SWT.SINGLE);
|
||||
|
||||
GridData inputTextGridData = new GridData();
|
||||
inputTextGridData.horizontalAlignment = GridData.FILL;
|
||||
inputTextGridData.verticalAlignment = GridData.FILL;
|
||||
inputText.setLayoutData(inputTextGridData);
|
||||
inputText.setEditable(false);
|
||||
inputText.addTraverseListener(new TraverseListener() {
|
||||
|
||||
@Override
|
||||
public void keyTraversed(TraverseEvent e) {
|
||||
if (e.keyCode == 13) {
|
||||
if (runnerLock != null) {
|
||||
inputText.setEditable(false);
|
||||
readlineText = inputText.getText();
|
||||
inputText.setText("");
|
||||
|
||||
String formerText = text.getText();
|
||||
// int formerLength = formerText.length();
|
||||
String textAdditionWithNewLines = "\r\n" + readlineText
|
||||
+ "\r\n";
|
||||
String newText = formerText + textAdditionWithNewLines;
|
||||
text.setText(newText);
|
||||
synchronized (runnerLock) {
|
||||
runnerLock.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
createPartMenu();
|
||||
}
|
||||
|
||||
private void stopCurrentExecution() {
|
||||
if (isRunning()) {
|
||||
// runner.stop();
|
||||
runner = null;
|
||||
if (runStateListener != null) {
|
||||
runStateListener.runStateChanged(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return runner != null && runner.isAlive();
|
||||
}
|
||||
|
||||
private void createPartMenu() {
|
||||
Action stopAction = new Action("Stop") {
|
||||
@Override
|
||||
public void run() {
|
||||
// Kill the runner
|
||||
stopCurrentExecution();
|
||||
text.setText(text.getText()+"\n[STOP]");
|
||||
|
||||
//now lock the debugview => notify it to lock itself
|
||||
System.out.println("Locking Pins...");
|
||||
((DebugView) getViewSite().getPage().findView(DebugView.ID)).lockPinState();
|
||||
}
|
||||
};
|
||||
getViewSite().getActionBars().getToolBarManager().add(stopAction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFocus() {
|
||||
|
||||
}
|
||||
|
||||
private Thread runner;
|
||||
private Object runnerLock;
|
||||
private String readlineText;
|
||||
private IRunStateListener runStateListener;
|
||||
|
||||
public void run(final File file, final IEEPROMMonitor monitor,
|
||||
final IRunWatcher runWatcher,
|
||||
final VariableView varView,
|
||||
final IRunStateListener runStateListener) {
|
||||
if (runner != null && runner.isAlive()) {
|
||||
runner.interrupt();
|
||||
}
|
||||
clearConsole();
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
runStateListener.runStateChanged(true);
|
||||
PluginRunner pluginRunner = new PluginRunner();
|
||||
pluginRunner.run(file, ConsoleView.this, monitor,
|
||||
runWatcher,getSettings(), varView);
|
||||
runStateListener.runStateChanged(false);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
runStateListener.runStateChanged(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
runner = new Thread(runnable);
|
||||
int priority = Thread.currentThread().getPriority() - 2;
|
||||
priority = Math.max(Thread.MIN_PRIORITY, priority);
|
||||
runnerLock = new Object();
|
||||
((DebugView) getViewSite().getPage().findView(DebugView.ID)).unlockPinState();
|
||||
runner.setPriority(priority);
|
||||
runner.start();
|
||||
}
|
||||
|
||||
private Settings getSettings() {
|
||||
|
||||
Bundle bundle = Activator.getDefault().getBundle();
|
||||
File targetRoot = bundle.getDataFile("");
|
||||
File file = new File(targetRoot, "config/set.cfg");
|
||||
if (!file.canRead()) {
|
||||
HelpView.copyPathFromBundleToFSRecursive(bundle, "config",
|
||||
targetRoot);
|
||||
}
|
||||
boolean emulate4Mhz = true, activateinfo = false, printInternComposition = false, nowarn = false;
|
||||
try {
|
||||
Scanner scanner = new Scanner(file);
|
||||
String line = "";
|
||||
while (scanner.hasNextLine()) {
|
||||
line = scanner.nextLine().trim();
|
||||
if (line.startsWith("##") || line.isEmpty())
|
||||
continue;
|
||||
if (line.startsWith("emulate 4Mhz")) {
|
||||
emulate4Mhz = evaluateBooleanExpression(line);
|
||||
} else if (line.startsWith("activate info")) {
|
||||
activateinfo = evaluateBooleanExpression(line);
|
||||
} else if (line.startsWith("print intern composition")) {
|
||||
printInternComposition = evaluateBooleanExpression(line);
|
||||
} else if (line.startsWith("ignore warnings")) {
|
||||
nowarn = evaluateBooleanExpression(line);
|
||||
} else {
|
||||
scanner.close();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
}
|
||||
scanner.close();
|
||||
} catch (FileNotFoundException | IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
err("[Error, run configurations]Couldn't read the configuration file -> using standard cfg\n");
|
||||
}
|
||||
return new Settings(activateinfo, emulate4Mhz, printInternComposition,
|
||||
nowarn);
|
||||
}
|
||||
|
||||
public void setScheme() {
|
||||
|
||||
Bundle bundle = Activator.getDefault().getBundle();
|
||||
File targetRoot = bundle.getDataFile("");
|
||||
File file = new File(targetRoot, "config/color.cfg");
|
||||
if (!file.canRead()) {
|
||||
HelpView.copyPathFromBundleToFSRecursive(bundle, "config",
|
||||
targetRoot);
|
||||
}
|
||||
try {
|
||||
Scanner scanner = new Scanner(file);
|
||||
String line = "";
|
||||
while (scanner.hasNextLine()) {
|
||||
line = scanner.nextLine().trim();
|
||||
if (line.startsWith("##") || line.isEmpty())
|
||||
continue;
|
||||
if (line.startsWith("console scheme")) {
|
||||
String[] split = line.split("=");
|
||||
if (split.length != 2) {
|
||||
scanner.close();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
if (split[1].trim().equals("blue")) {
|
||||
text.setBackground(Display.getCurrent().getSystemColor(
|
||||
SWT.COLOR_DARK_BLUE));
|
||||
text.setForeground(Display.getCurrent().getSystemColor(
|
||||
SWT.COLOR_WHITE));
|
||||
} else if (split[1].trim().equals("black")) {
|
||||
text.setBackground(Display.getCurrent().getSystemColor(
|
||||
SWT.COLOR_BLACK));
|
||||
text.setForeground(Display.getCurrent().getSystemColor(
|
||||
SWT.COLOR_WHITE));
|
||||
|
||||
} else if (split[1].trim().equals("white")) {
|
||||
text.setBackground(Display.getCurrent().getSystemColor(
|
||||
SWT.COLOR_WHITE));
|
||||
text.setForeground(Display.getCurrent().getSystemColor(
|
||||
SWT.COLOR_BLACK));
|
||||
|
||||
} else {
|
||||
scanner.close();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
} else {
|
||||
scanner.close();
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
}
|
||||
scanner.close();
|
||||
} catch (FileNotFoundException | IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
err("[Error, run configurations]Couldn't read the configuration file -> using standard cfg\n");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean evaluateBooleanExpression(String s) {
|
||||
String[] split = s.split("=");
|
||||
if (split.length != 2) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return split[1].trim().equals("true");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printLn(final String line) {
|
||||
print("\n" + line);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(final String s) {
|
||||
getSite().getShell().getDisplay().asyncExec(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
text.setText(text.getText() + s);
|
||||
text.setTopIndex(text.getLineCount() - 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readLn() {
|
||||
getSite().getShell().getDisplay().asyncExec(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ConsoleView.this.focusOnInput();
|
||||
}
|
||||
});
|
||||
|
||||
synchronized (runnerLock) {
|
||||
try {
|
||||
runnerLock.wait();
|
||||
} catch (InterruptedException ie) {
|
||||
// do nothing here, we have been killed.
|
||||
}
|
||||
}
|
||||
return readlineText;
|
||||
}
|
||||
|
||||
protected void focusOnInput() {
|
||||
inputText.setEditable(true);
|
||||
inputText.forceFocus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearConsole() {
|
||||
getSite().getShell().getDisplay().asyncExec(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
text.setText("");
|
||||
text.setTopIndex(text.getLineCount() - 1);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void err(final String err) {
|
||||
getSite().getShell().getDisplay().asyncExec(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// StyleRange styleRange = new StyleRange();
|
||||
// styleRange.start = text.getText().length();
|
||||
// styleRange.length = err.length();
|
||||
// styleRange.fontStyle = SWT.BOLD;
|
||||
// styleRange.foreground = Display.getCurrent().getSystemColor(
|
||||
// SWT.COLOR_RED);
|
||||
text.setText(text.getText() + err + "\n");
|
||||
text.setTopIndex(text.getLineCount() - 1);
|
||||
// text.setStyleRange(styleRange);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(final String warn) {
|
||||
getSite().getShell().getDisplay().asyncExec(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// StyleRange styleRange = new StyleRange();
|
||||
// styleRange.start = text.getText().length();
|
||||
// styleRange.length = warn.length();
|
||||
// styleRange.fontStyle = SWT.BOLD;
|
||||
// styleRange.foreground = Display.getCurrent().getSystemColor(
|
||||
// SWT.COLOR_RED);
|
||||
text.setText(text.getText() + warn + "\n");
|
||||
text.setTopIndex(text.getLineCount() - 1);
|
||||
// text.setStyleRange(styleRange);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(final String info) {
|
||||
getSite().getShell().getDisplay().asyncExec(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// StyleRange styleRange = new StyleRange();
|
||||
// styleRange.start = text.getText().length();
|
||||
// styleRange.length = info.length();
|
||||
// styleRange.fontStyle = SWT.BOLD;
|
||||
// styleRange.foreground = Display.getCurrent().getSystemColor(
|
||||
// SWT.COLOR_RED);
|
||||
text.setText(text.getText() + info + "\n");
|
||||
text.setTopIndex(text.getLineCount() - 1);
|
||||
// text.setStyleRange(styleRange);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
322
src/edu/fichte/pbi/ide/views/DebugView.java
Normal file
322
src/edu/fichte/pbi/ide/views/DebugView.java
Normal file
@ -0,0 +1,322 @@
|
||||
package edu.fichte.pbi.ide.views;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.swt.custom.CLabel;
|
||||
import org.eclipse.swt.custom.StackLayout;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
import edu.fichte.pbi.ide.Activator;
|
||||
import edu.fichte.pbi.util.CallbackVariableListener;
|
||||
import edu.fichte.pbi.vm.IRunWatcher;
|
||||
import edu.fichte.pbi.vm.Machine;
|
||||
import edu.fichte.pbi.vm.var.IVariable;
|
||||
|
||||
public class DebugView extends ViewPart implements IRunWatcher {
|
||||
|
||||
public static String ID = "edu.fichte.pbi.ide.debugView";
|
||||
|
||||
private Machine machine;
|
||||
|
||||
//GUI elements
|
||||
private Label[] label = new Label[8];
|
||||
private CLabel[] labelInOut = new CLabel[8];
|
||||
private CLabel[] labelHighLow = new CLabel[8];
|
||||
private Button[] buttonHighLow = new Button[8];
|
||||
private Composite[] widgetPin = new Composite[8];
|
||||
private StackLayout[] stackLayout = new StackLayout[8];
|
||||
|
||||
//load icons
|
||||
private Image imageHigh = loadIcon("status_red.gif");
|
||||
private Image imageLow = loadIcon("status_black.gif");
|
||||
|
||||
private Image imageInput = loadIcon("InputArrowSmall.gif");
|
||||
private Image imageOutput = loadIcon("OutputArrowSmall.gif");
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
//create layout Parent with GridLayout
|
||||
Composite layoutParent = new Composite(parent, 0);
|
||||
layoutParent.setLayout(new GridLayout(3, true));
|
||||
|
||||
//create Labels
|
||||
Label pin = new Label(layoutParent, 0);
|
||||
pin.setText("PIN");
|
||||
Label io = new Label(layoutParent, 0);
|
||||
io.setText("I/O");
|
||||
Label hl = new Label(layoutParent, 0);
|
||||
hl.setText("High/Low");
|
||||
|
||||
for (int i = widgetPin.length - 1; i >= 0; i--) {
|
||||
//first column: Pin Label
|
||||
label[i] = new Label(layoutParent, 0);
|
||||
label[i].setText("P" + String.valueOf(i));
|
||||
|
||||
//second column: Pin direction (Input/Output)
|
||||
labelInOut[i] = new CLabel(layoutParent, 0);
|
||||
labelInOut[i].setText("Input");
|
||||
labelInOut[i].setImage(imageInput);
|
||||
//default is input, see:
|
||||
//(http://www.parallax.com/go/PBASICHelp/Content\
|
||||
///LanguageTopics/Commands/INPUT.htm -> Explanation)
|
||||
|
||||
//third column: Pin state (High/Low)
|
||||
//changes between CLabel and Button, depending on if an
|
||||
//input is accepted or not (uses StackLayout for that)
|
||||
stackLayout[i] = new StackLayout();
|
||||
//create new composite in which stackLayout is active
|
||||
widgetPin[i] = new Composite(layoutParent, 0);
|
||||
widgetPin[i].setLayout(stackLayout[i]);
|
||||
//create first "page" of stackLayout: label (if pin is output)
|
||||
labelHighLow[i] = new CLabel(widgetPin[i], 0);
|
||||
labelHighLow[i].setText("Low");
|
||||
labelHighLow[i].setImage(imageLow);
|
||||
labelHighLow[i].pack();
|
||||
//create second "page" of stackLayout: button (if pin is input)
|
||||
buttonHighLow[i] = new Button(widgetPin[i], 0);
|
||||
buttonHighLow[i].setText("Low");
|
||||
buttonHighLow[i].setImage(imageLow);
|
||||
buttonHighLow[i].pack();
|
||||
//show second "page" first as pin is initialized as input pin
|
||||
stackLayout[i].topControl = buttonHighLow[i];
|
||||
//actions listeners are defined outside of the loop
|
||||
}
|
||||
//action listeners as you are not allowed to use
|
||||
//non-final variables in an inner class
|
||||
buttonHighLow[0].addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent arg0) {
|
||||
toggleVariable(0);
|
||||
}
|
||||
});
|
||||
buttonHighLow[1].addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent arg0) {
|
||||
toggleVariable(1);
|
||||
}
|
||||
});
|
||||
buttonHighLow[2].addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent arg0) {
|
||||
toggleVariable(2);
|
||||
}
|
||||
});
|
||||
buttonHighLow[3].addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent arg0) {
|
||||
toggleVariable(3);
|
||||
}
|
||||
});
|
||||
buttonHighLow[4].addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent arg0) {
|
||||
toggleVariable(4);
|
||||
}
|
||||
});
|
||||
buttonHighLow[5].addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent arg0) {
|
||||
toggleVariable(5);
|
||||
}
|
||||
});
|
||||
buttonHighLow[6].addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent arg0) {
|
||||
toggleVariable(6);
|
||||
}
|
||||
});
|
||||
buttonHighLow[7].addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent arg0) {
|
||||
toggleVariable(7);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFocus() {
|
||||
|
||||
}
|
||||
|
||||
private void toggleVariable(int varNum) {
|
||||
IVariable variable = machine.parseIVariable("PIN" + varNum);
|
||||
long value = variable.getValue();
|
||||
if (value == 0) {
|
||||
value = 1;
|
||||
} else {
|
||||
value = 0;
|
||||
}
|
||||
variable.setValue(value);
|
||||
}
|
||||
|
||||
public void setMachine(Machine machine) {
|
||||
this.machine = machine;
|
||||
|
||||
IVariable[] listener = new IVariable[labelHighLow.length];
|
||||
for (int i = 0; i < labelHighLow.length; i++) {
|
||||
listener[i] = this.machine.parseIVariable("PIN" + String.valueOf(i));
|
||||
listener[i].setVariableListener(
|
||||
new CallbackVariableListener(
|
||||
new PinCommObject(labelHighLow[i], buttonHighLow[i])) {
|
||||
|
||||
@Override
|
||||
public void variableChanged(IVariable variable) {
|
||||
final long value = variable.getValue();
|
||||
final boolean[] newState = new boolean[1];
|
||||
if (value == 1) {
|
||||
newState[0] = true;
|
||||
}
|
||||
getSite().getShell().getDisplay().syncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PinCommObject obj = (PinCommObject) callback;
|
||||
if (newState[0]) {
|
||||
obj.label.setText("High");
|
||||
obj.label.setImage(imageHigh);
|
||||
obj.button.setText("High");
|
||||
obj.button.setImage(imageHigh);
|
||||
} else {
|
||||
obj.label.setText("Low");
|
||||
obj.label.setImage(imageLow);
|
||||
obj.button.setText("Low");
|
||||
obj.button.setImage(imageLow);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
IVariable[] dirListener = new IVariable[labelInOut.length];
|
||||
for (int i = 0; i < labelInOut.length; i++) {
|
||||
dirListener[i] = this.machine.parseIVariable("DIR"
|
||||
+ String.valueOf(i));
|
||||
dirListener[i].setVariableListener(
|
||||
new CallbackVariableListener(
|
||||
new DirCommObject(
|
||||
labelInOut[i],
|
||||
labelHighLow[i],
|
||||
buttonHighLow[i],
|
||||
stackLayout[i],
|
||||
widgetPin[i])) {
|
||||
|
||||
@Override
|
||||
public void variableChanged(IVariable variable) {
|
||||
final long value = variable.getValue();
|
||||
final boolean[] newState = new boolean[1];
|
||||
if (value == 1) {
|
||||
newState[0] = true;
|
||||
}
|
||||
getSite().getShell().getDisplay().syncExec(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
DirCommObject obj = (DirCommObject) callback;
|
||||
if (newState[0]) {
|
||||
obj.labelDir.setText("Output");
|
||||
obj.labelDir.pack();
|
||||
obj.labelDir.setImage(imageOutput);
|
||||
obj.labelState.setVisible(true);
|
||||
obj.buttonState.setVisible(false);
|
||||
obj.stackLayout.topControl = obj.labelState;
|
||||
} else {
|
||||
obj.labelDir.setText("Input");
|
||||
obj.labelDir.pack();
|
||||
obj.labelDir.setImage(imageInput);
|
||||
obj.labelState.setVisible(false);
|
||||
obj.buttonState.setVisible(true);
|
||||
obj.stackLayout.topControl = obj.buttonState;
|
||||
}
|
||||
obj.widgetPin.layout();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static Image loadIcon(String iconFilename) {
|
||||
Bundle bundle = Activator.getDefault().getBundle();
|
||||
File targetRoot = bundle.getDataFile("");
|
||||
|
||||
File file = new File(targetRoot, "icons/" + iconFilename);
|
||||
if (!file.canRead()) {
|
||||
HelpView.copyPathFromBundleToFSRecursive(bundle, "icons",
|
||||
targetRoot);
|
||||
}
|
||||
return new Image(Display.getCurrent(), file.getAbsolutePath());
|
||||
}
|
||||
|
||||
public void lockPinState() {
|
||||
for (int i = 0; i < buttonHighLow.length; i++) {
|
||||
buttonHighLow[i].setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void unlockPinState() {
|
||||
for (int i = 0; i < buttonHighLow.length; i++) {
|
||||
buttonHighLow[i].setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private class PinCommObject {
|
||||
|
||||
protected CLabel label;
|
||||
|
||||
protected Button button;
|
||||
|
||||
private PinCommObject(CLabel label, Button button) {
|
||||
this.label = label;
|
||||
this.button = button;
|
||||
}
|
||||
}
|
||||
|
||||
private class DirCommObject {
|
||||
|
||||
protected CLabel labelDir;
|
||||
|
||||
protected CLabel labelState;
|
||||
|
||||
protected Button buttonState;
|
||||
|
||||
protected StackLayout stackLayout;
|
||||
|
||||
protected Composite widgetPin;
|
||||
|
||||
private DirCommObject(
|
||||
CLabel labelDir,
|
||||
CLabel labelState,
|
||||
Button buttonState,
|
||||
StackLayout stackLayout,
|
||||
Composite widgetPin) {
|
||||
this.labelDir = labelDir;
|
||||
this.labelState = labelState;
|
||||
this.buttonState = buttonState;
|
||||
this.stackLayout = stackLayout;
|
||||
this.widgetPin = widgetPin;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
167
src/edu/fichte/pbi/ide/views/EEPROMView.java
Normal file
167
src/edu/fichte/pbi/ide/views/EEPROMView.java
Normal file
@ -0,0 +1,167 @@
|
||||
package edu.fichte.pbi.ide.views;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.swt.events.MouseAdapter;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
|
||||
import edu.fichte.pbi.vm.storage.EEPROM;
|
||||
import edu.fichte.pbi.vm.storage.IEEPROMMonitor;
|
||||
|
||||
public class EEPROMView extends ViewPart implements IEEPROMMonitor {
|
||||
|
||||
public static final String ID = "edu.fichte.pbi.ide.eepromView";
|
||||
|
||||
private Label selected;
|
||||
private Label previous;
|
||||
|
||||
Label address;
|
||||
Label charValue;
|
||||
Label binaryValue;
|
||||
Label decimalValue;
|
||||
ArrayList<Label> allBytes = new ArrayList<Label>(EEPROM.SIZE);
|
||||
|
||||
Composite infoView;
|
||||
Composite eepromParent;
|
||||
Composite eepromViewLabelParent;
|
||||
|
||||
private Color writeAccess = new Color(Display.getCurrent(), 0, 255, 0);
|
||||
private Color highlighted = new Color(Display.getCurrent(), 255, 191, 0);
|
||||
// private Color special = new Color(Display.getCurrent(), 255, 0, 192);
|
||||
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
//parent element, one element wide
|
||||
eepromParent = new Composite(parent, 0);
|
||||
eepromParent.setLayout(new GridLayout(1, false));
|
||||
|
||||
//make composite for all labels representing the eeprom
|
||||
eepromViewLabelParent = new Composite(eepromParent, 0);
|
||||
eepromViewLabelParent.setLayout(new GridLayout(16, false));
|
||||
|
||||
//create the labels, set them to zero
|
||||
allBytes.ensureCapacity(EEPROM.SIZE);
|
||||
Label newLabel;
|
||||
for (int i = 0; i < EEPROM.SIZE; i++) {
|
||||
newLabel = new Label(eepromViewLabelParent, 0);
|
||||
newLabel.setText("00");
|
||||
newLabel.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseUp(MouseEvent event) {
|
||||
super.mouseUp(event);
|
||||
|
||||
if (event.getSource() instanceof Label) {
|
||||
//mark the label with color /highlighted/
|
||||
if (selected != null) {
|
||||
selected.setBackground(null);
|
||||
}
|
||||
Label label = (Label) event.getSource();
|
||||
selected = label;
|
||||
selected.setBackground(highlighted);
|
||||
|
||||
//calc details
|
||||
String pos = String.valueOf(allBytes.indexOf(label));
|
||||
int value = Integer.parseInt(label.getText(), 16);
|
||||
String ascii = String.valueOf((char) value);
|
||||
String binary = Integer.toBinaryString(value);
|
||||
String decimal = String.valueOf(value);
|
||||
|
||||
//set new values
|
||||
address.setText("Address: " + pos);
|
||||
charValue.setText("ASCII: " + ascii);
|
||||
binaryValue.setText("Binary: " + binary);
|
||||
decimalValue.setText("Decimal: " + decimal);
|
||||
|
||||
//update composite
|
||||
infoView.pack();
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
allBytes.add(i, newLabel);
|
||||
}
|
||||
|
||||
//initialize infoView Composite and labels
|
||||
infoView = new Composite(eepromParent, 0);
|
||||
infoView.setLayout(new GridLayout(4, false));
|
||||
|
||||
address = new Label(infoView, 0);
|
||||
charValue = new Label(infoView, 0);
|
||||
binaryValue = new Label(infoView, 0);
|
||||
decimalValue = new Label(infoView, 0);
|
||||
|
||||
address.setText("Address: --");
|
||||
charValue.setText("ASCII: --");
|
||||
binaryValue.setText("Binary: --");
|
||||
decimalValue.setText("Decimal: --");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(final String s) {
|
||||
getSite().getShell().getDisplay().asyncExec(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int value;
|
||||
String text;
|
||||
String tooltip;
|
||||
String[] newBytes = splitIntoParts(s, 2);
|
||||
for (int i = 0; i < EEPROM.SIZE; i++) {
|
||||
text = newBytes[i].toUpperCase();
|
||||
if (!allBytes.get(i).getText().equals(text)) {
|
||||
value = Integer.parseInt(text, 16);
|
||||
if (allBytes.get(i).equals(selected)) {
|
||||
//selected got updated, recalc details
|
||||
String ascii = String.valueOf((char) value);
|
||||
String binary = Integer.toBinaryString(value);
|
||||
String decimal = String.valueOf(value);
|
||||
|
||||
//set new values
|
||||
charValue.setText("ASCII: " + ascii);
|
||||
binaryValue.setText("Binary: " + binary);
|
||||
decimalValue.setText("Decimal: " + decimal);
|
||||
|
||||
//update composite
|
||||
infoView.pack();
|
||||
} else {
|
||||
allBytes.get(i).setBackground(writeAccess);
|
||||
}
|
||||
tooltip = "Ascii: " + String.valueOf((char) value);
|
||||
allBytes.get(i).setToolTipText(tooltip);
|
||||
}
|
||||
allBytes.get(i).setText(text);
|
||||
allBytes.get(i).pack();
|
||||
if (previous != selected) {
|
||||
previous.setBackground(null);
|
||||
}
|
||||
previous = allBytes.get(i);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setFocus() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
private static String[] splitIntoParts(String string, int partSize) {
|
||||
int size = Integer.valueOf((int) string.length() / partSize);
|
||||
String[] parts = new String[size + 1];
|
||||
for (int i = 0; i <= string.length(); i+=partSize) {
|
||||
parts[(int) i/partSize] = string.substring(i, Math.min(2*size, i + partSize));
|
||||
}
|
||||
return parts;
|
||||
}
|
||||
|
||||
}
|
287
src/edu/fichte/pbi/ide/views/FileExplorer.java
Normal file
287
src/edu/fichte/pbi/ide/views/FileExplorer.java
Normal file
@ -0,0 +1,287 @@
|
||||
package edu.fichte.pbi.ide.views;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.action.IMenuListener;
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.action.IToolBarManager;
|
||||
import org.eclipse.jface.action.MenuManager;
|
||||
import org.eclipse.jface.action.Separator;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.viewers.DoubleClickEvent;
|
||||
import org.eclipse.jface.viewers.IDoubleClickListener;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.jface.viewers.ViewerSorter;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.ui.IActionBars;
|
||||
import org.eclipse.ui.ISharedImages;
|
||||
import org.eclipse.ui.IWorkbenchActionConstants;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
|
||||
import edu.fichte.pbi.ide.editors.FileSystemFileEditorInput;
|
||||
import edu.fichte.pbi.ide.editors.PBIEditor;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
|
||||
public class FileExplorer extends ViewPart {
|
||||
|
||||
/**
|
||||
* The ID of the view as specified by the extension.
|
||||
*/
|
||||
public static final String ID = "edu.fichte.pbi.ide.views.FileExplorer";
|
||||
|
||||
private TreeViewer viewer;
|
||||
private Action doubleClickAction;
|
||||
private static final Image bs1File = AbstractUIPlugin
|
||||
.imageDescriptorFromPlugin("edu.fichte.pbi.ide",
|
||||
"icons/bs1.gif").createImage();
|
||||
|
||||
class ViewContentProvider implements IStructuredContentProvider,
|
||||
ITreeContentProvider {
|
||||
|
||||
@Override
|
||||
public void inputChanged(Viewer v, Object oldInput, Object newInput) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getElements(Object parent) {
|
||||
if (parent.equals(getViewSite())) {
|
||||
Iterable<Path> rootDirectories = FileSystems.getDefault()
|
||||
.getRootDirectories();
|
||||
ArrayList<File> retVal = new ArrayList<File>();
|
||||
retVal.add(new File(System.getProperty("user.home")));
|
||||
|
||||
for (Path path : rootDirectories) {
|
||||
retVal.add(path.toFile());
|
||||
}
|
||||
return retVal.toArray();
|
||||
}
|
||||
return getChildren(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getParent(Object child) {
|
||||
if (child instanceof File) {
|
||||
return ((File) child).getParentFile();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getChildren(Object parent) {
|
||||
if (parent instanceof File) {
|
||||
File parentFile = (File) parent;
|
||||
if (parentFile.isDirectory()) {
|
||||
File[] listFiles = parentFile.listFiles();
|
||||
ArrayList<File> retVal = new ArrayList<File>();
|
||||
if (listFiles == null) {
|
||||
listFiles = new File[0];
|
||||
}
|
||||
for (File file : listFiles) {
|
||||
if (!file.isHidden()
|
||||
&& (file.getName().endsWith(".bs1") || file
|
||||
.isDirectory())) {
|
||||
retVal.add(file);
|
||||
}
|
||||
}
|
||||
return retVal.toArray(new File[retVal.size()]);
|
||||
}
|
||||
return new Object[0];
|
||||
}
|
||||
return new Object[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasChildren(Object parent) {
|
||||
if (parent instanceof File) {
|
||||
File file = (File) parent;
|
||||
return file.isDirectory();
|
||||
} else if (parent instanceof Path) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ViewLabelProvider extends LabelProvider {
|
||||
|
||||
@Override
|
||||
public String getText(Object obj) {
|
||||
if (obj instanceof File) {
|
||||
File file = (File) obj;
|
||||
String name = file.getName();
|
||||
if (name.trim().length() == 0) {
|
||||
name = file.getPath();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
return "???";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getImage(Object obj) {
|
||||
String imageKey = ISharedImages.IMG_OBJ_FOLDER;
|
||||
|
||||
if (obj instanceof File) {
|
||||
File file = (File) obj;
|
||||
if (file.isDirectory()) {
|
||||
return PlatformUI.getWorkbench().getSharedImages()
|
||||
.getImage(imageKey);
|
||||
} else if(file.isFile()){
|
||||
return bs1File;
|
||||
}
|
||||
}
|
||||
return PlatformUI.getWorkbench().getSharedImages()
|
||||
.getImage(imageKey);
|
||||
}
|
||||
}
|
||||
|
||||
class NameSorter extends ViewerSorter {
|
||||
}
|
||||
|
||||
/**
|
||||
* The constructor.
|
||||
*/
|
||||
public FileExplorer() {
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a callback that will allow us to create the viewer and initialize
|
||||
* it.
|
||||
*/
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
viewer = new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL);
|
||||
// drillDownAdapter = new DrillDownAdapter(viewer);
|
||||
viewer.setContentProvider(new ViewContentProvider());
|
||||
viewer.setLabelProvider(new ViewLabelProvider());
|
||||
// viewer.setSorter(new NameSorter());
|
||||
viewer.setInput(getViewSite());
|
||||
|
||||
// Create the help context id for the viewer's control
|
||||
PlatformUI
|
||||
.getWorkbench()
|
||||
.getHelpSystem()
|
||||
.setHelp(viewer.getControl(),
|
||||
"edu.fichte.pbi.ide.viewer");
|
||||
makeActions();
|
||||
hookContextMenu();
|
||||
hookDoubleClickAction();
|
||||
contributeToActionBars();
|
||||
}
|
||||
|
||||
private void hookContextMenu() {
|
||||
MenuManager menuMgr = new MenuManager("#PopupMenu");
|
||||
menuMgr.setRemoveAllWhenShown(true);
|
||||
menuMgr.addMenuListener(new IMenuListener() {
|
||||
@Override
|
||||
public void menuAboutToShow(IMenuManager manager) {
|
||||
FileExplorer.this.fillContextMenu(manager);
|
||||
}
|
||||
});
|
||||
Menu menu = menuMgr.createContextMenu(viewer.getControl());
|
||||
viewer.getControl().setMenu(menu);
|
||||
getSite().registerContextMenu(menuMgr, viewer);
|
||||
}
|
||||
|
||||
private void contributeToActionBars() {
|
||||
IActionBars bars = getViewSite().getActionBars();
|
||||
fillLocalPullDown(bars.getMenuManager());
|
||||
fillLocalToolBar(bars.getToolBarManager());
|
||||
}
|
||||
|
||||
private void fillLocalPullDown(IMenuManager manager) {
|
||||
manager.add(new Separator());
|
||||
}
|
||||
|
||||
private void fillContextMenu(IMenuManager manager) {
|
||||
|
||||
// Other plug-ins can contribute there actions here
|
||||
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
|
||||
}
|
||||
|
||||
private void fillLocalToolBar(IToolBarManager manager) {
|
||||
manager.add(new Separator());
|
||||
}
|
||||
|
||||
private void makeActions() {
|
||||
|
||||
doubleClickAction = new Action() {
|
||||
@Override
|
||||
public void run() {
|
||||
ISelection selection = viewer.getSelection();
|
||||
Object obj = ((IStructuredSelection) selection)
|
||||
.getFirstElement();
|
||||
File file = (File) obj;
|
||||
if (file.isFile() && file.getName().endsWith(".bs1")) {
|
||||
FileSystemFileEditorInput fileSystemFileEditorInput = new FileSystemFileEditorInput(
|
||||
file);
|
||||
try {
|
||||
getViewSite().getPage().openEditor(
|
||||
fileSystemFileEditorInput, PBIEditor.ID);
|
||||
} catch (PartInitException e) {
|
||||
showMessage("File " + file.getAbsolutePath()
|
||||
+ " caused an error");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void hookDoubleClickAction() {
|
||||
viewer.addDoubleClickListener(new IDoubleClickListener() {
|
||||
@Override
|
||||
public void doubleClick(DoubleClickEvent event) {
|
||||
doubleClickAction.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showMessage(String message) {
|
||||
MessageDialog.openInformation(viewer.getControl().getShell(),
|
||||
"File Explorer", message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Passing the focus request to the viewer's control.
|
||||
*/
|
||||
@Override
|
||||
public void setFocus() {
|
||||
viewer.getControl().setFocus();
|
||||
}
|
||||
}
|
90
src/edu/fichte/pbi/ide/views/HelpView.java
Normal file
90
src/edu/fichte/pbi/ide/views/HelpView.java
Normal file
@ -0,0 +1,90 @@
|
||||
package edu.fichte.pbi.ide.views;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.browser.Browser;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
import edu.fichte.pbi.ide.Activator;
|
||||
|
||||
public class HelpView extends ViewPart {
|
||||
|
||||
public static final String ID = "edu.fichte.pbi.ide.browser";
|
||||
private Browser browser;
|
||||
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
browser = new Browser(parent, SWT.NONE);
|
||||
browser.setJavascriptEnabled(true);
|
||||
Bundle bundle = Activator.getDefault().getBundle();
|
||||
File targetRoot = bundle.getDataFile("");
|
||||
File indexhtml = new File(targetRoot, "help/index.html");
|
||||
if(!indexhtml.canRead()){
|
||||
// must copy the html from the bundle .jar to the data file location
|
||||
copyPathFromBundleToFSRecursive(bundle, "help", targetRoot);
|
||||
}
|
||||
try {
|
||||
browser.setUrl(indexhtml.toURI().toURL().toExternalForm());
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Action back = new Action("back") {
|
||||
@Override
|
||||
public void run() {
|
||||
browser.back();
|
||||
}
|
||||
};
|
||||
getViewSite().getActionBars().getToolBarManager().add(back);
|
||||
|
||||
// URL mainUrl = Activator.getDefault().getBundle().getEntry("help/Main.html");
|
||||
}
|
||||
|
||||
public static void copyPathFromBundleToFSRecursive(Bundle bundle, String path,
|
||||
File targetRoot) {
|
||||
Enumeration<String> entryPaths = bundle.getEntryPaths(path);
|
||||
while(entryPaths.hasMoreElements()){
|
||||
String entryPath = entryPaths.nextElement();
|
||||
if(entryPath.endsWith("/")) {
|
||||
copyPathFromBundleToFSRecursive(bundle, entryPath, targetRoot);
|
||||
} else {
|
||||
URL entry = bundle.getEntry(entryPath);
|
||||
File target = new File(targetRoot, entryPath);
|
||||
byte[] buf = new byte[10000];
|
||||
int c = 0;
|
||||
try {
|
||||
InputStream in = entry.openStream();
|
||||
target.getParentFile().mkdirs();
|
||||
target.createNewFile();
|
||||
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(target));
|
||||
while(-1!=(c=in.read(buf))){
|
||||
out.write(buf, 0, c);
|
||||
}
|
||||
out.close();
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Passing the focus request to the viewer's control.
|
||||
*/
|
||||
@Override
|
||||
public void setFocus() {
|
||||
browser.setFocus();
|
||||
}
|
||||
}
|
6
src/edu/fichte/pbi/ide/views/IRunStateListener.java
Normal file
6
src/edu/fichte/pbi/ide/views/IRunStateListener.java
Normal file
@ -0,0 +1,6 @@
|
||||
package edu.fichte.pbi.ide.views;
|
||||
|
||||
public interface IRunStateListener {
|
||||
|
||||
public void runStateChanged(boolean isRunnung);
|
||||
}
|
67
src/edu/fichte/pbi/ide/views/VariableView.java
Normal file
67
src/edu/fichte/pbi/ide/views/VariableView.java
Normal file
@ -0,0 +1,67 @@
|
||||
package edu.fichte.pbi.ide.views;
|
||||
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
|
||||
import edu.fichte.pbi.util.CallbackVariableListener;
|
||||
import edu.fichte.pbi.vm.IRunWatcher;
|
||||
import edu.fichte.pbi.vm.Machine;
|
||||
import edu.fichte.pbi.vm.var.IVariable;
|
||||
|
||||
public class VariableView extends ViewPart implements IRunWatcher {
|
||||
|
||||
public static String ID = "edu.fichte.pbi.ide.variableView";
|
||||
|
||||
private Machine machine;
|
||||
|
||||
private Label[] varLabel = new Label[14];
|
||||
private Label[] varValue = new Label[14];
|
||||
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
Composite layoutParent = new Composite(parent, 0);
|
||||
layoutParent.setLayout(new GridLayout(2, false));
|
||||
|
||||
for (int i = 0; i < varLabel.length; i++) {
|
||||
varLabel[i] = new Label(layoutParent, 0);
|
||||
varLabel[i].setText("B" + String.valueOf(i));
|
||||
varValue[i] = new Label(layoutParent, 0);
|
||||
varValue[i].setText("0");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMachine(Machine machine) {
|
||||
this.machine = machine;
|
||||
|
||||
IVariable[] listener = new IVariable[varLabel.length];
|
||||
for (int i = 0; i < varLabel.length; i++) {
|
||||
listener[i] = this.machine.parseIVariable("B" + String.valueOf(i));
|
||||
listener[i].setVariableListener(
|
||||
new CallbackVariableListener(varValue[i]) {
|
||||
|
||||
@Override
|
||||
public void variableChanged(IVariable variable) {
|
||||
final long value = variable.getValue();
|
||||
getSite().getShell().getDisplay().syncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
((Label) callback).setText(String.valueOf(value));
|
||||
((Label) callback).pack();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFocus() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user