E Vogel

Greenhorn
+ Follow
since Dec 27, 2014
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by E Vogel

My first attempt at programming a Thread; want an sinewave graph to run in a thread. Simplified code posted here, as long as the sinewave is running, the main window is unresponsive.


import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class WBthreadBare {

protected Shell shell;


/**
* Launch the application.
*
* @param args
*/
public static void main(String[] args) {
try {
WBthreadBare window = new WBthreadBare();
window.open();

} catch (Exception e) {
e.printStackTrace();
}

}

/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}

/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Thread Test");

// Trace trace = new Trace();
(new Trace()).start();

}

class Trace extends Thread {

public Trace() {
Run();
}

public void Run() {

shell.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {

for (int b = 0; b < 720; b++) {
for (int a = 1; a < 120 * Math.PI; a++) {

double theta1 = +(b + a - 1) % 360 * 2 * Math.PI / 180;
double theta2 = +(b + a) % 360 * 2 * Math.PI / 180;
int y1 = ((int) (Math.sin((theta1)) * 1000)) / 15 + 90;
int y2 = ((int) (Math.sin((theta2)) * 1000)) / 15 + 90;

e.gc.setForeground(e.display
.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
e.gc.drawLine(a, y1, a + 1, y2);

e.gc.setForeground(e.display
.getSystemColor(SWT.COLOR_GREEN));
e.gc.drawLine(a - 1, y1, a, y2);

} // end for a
} // end for b

} // end paintControl
}); // end PaintListener

} // end Run()

} // end class Trace

}

Code doesn't look like it is formatted as code; not sure how to do that here.
I have a hierarchal data structure (Machine, Component, Measurement, Fault are classes) displayed in a TreeViewer. I have added SelectionChanged and DoubleClick listeners, but can't find a way to get to the data stored in the selected instance of the data structure class. For example, the selection is a Measurement which has a String name field. I can see the data in the Element in Debug-Variables, but I can't find any getters to access it. I tried casting the selection as a Measurement but it is an ISelection, or TreeSelection class and it won't accept the cast.

It seems there should be get methods to access the data in the selection, but there aren't, so I'm must be missing something fundamental.

9 years ago