Where does the below code fail? What does the JNI create controls do?
Thanks,
Rodney
Sergiy Uvarov wrote:
Rodney Dowdall wrote:
Can you please post the code where you added the extra widget? You
have to make sure that the mapping in the Display class is correct.
If it is off it will cause this problem.I added widgets as this article recommends:
http://www.eclipse.org/articles/Article-Writing%20Your%20Own%20Widget/Writing%20Your%20Own%20Widget.htm
By the way I moved all native calls for printing in separate library
so that I don’t need to recompile SWT native but printing also doesn’t
work. At first photon call (PpCreatePC) j9 throws unhandeled exception.This is the widget class:
package org.eclipse.swt.widgets;import org.eclipse.swt.internal.;
import org.eclipse.swt.internal.photon.;
import org.eclipse.swt.;
import org.eclipse.swt.graphics.;
import org.eclipse.swt.events.*;/**
- Wrapper around Photon PtTrend widget
*/
public class Trend extends Composite {
int handleTrend;
private static final int Pt_ARG_TREND_FLAGS = 0x11D2F;
private static final int Pt_ARG_TREND_GRID_COLOR = 0x11D30;
private static final int Pt_ARG_TREND_GRID_X = 0x11D29;
private static final int Pt_ARG_TREND_GRID_Y = 0x11D2A;
private static final int Pt_ARG_TREND_COUNT = 0x11D2B;
private static final int Pt_ARG_TREND_COLOR_LIST = 0x11D31;
private static final int Pt_ARG_TREND_ATTRIBUTES = 0x11D32;
private static final int Pt_ARG_TREND_DATA = 0x11D28;
private static final int Pt_ARG_TREND_MAX = 0x11D2C;
private static final int Pt_ARG_TREND_MIN = 0x11D2D;private static final int Pt_GRID = 2;
private static final int Pt_GRID_IS_TRANSLUCENT = 0x400;
private static final int Pt_GRID_FORCE = 0x800;
private static final int Pt_RESULT_GRID = (Pt_GRID |
Pt_GRID_IS_TRANSLUCENT | Pt_GRID_FORCE);private double min = 0,max = 100;
private short trendMin, trendMax;
private int [] handles = new int[2];static { System.loadLibrary(“jinf”); }
public Trend(Composite parent, int style) {
// create parent composite
super(parent,style);// create native widget
// PtOSContainer → handles[0]
// PtTrend → handles[1]
createControl(handle,handles);
handleTrend = handles[1];
if(handleTrend==0) SWT.error(SWT.ERROR_NO_HANDLES);
OS.PtSetResource(handleTrend,Pt_ARG_TREND_COUNT,1,0);
addControlListener(new ControlAdapter(){
public void controlResized(ControlEvent e) {
Rectangle rect = getClientArea();
resizeControl(handles[0], rect.x, rect.y, rect.width,
rect.height);
}
});addFocusListener( new FocusAdapter() {
public void focusGained(FocusEvent e) {
setFocus(handles[0]);
}
});/* Get min/mx biunds from trend */
int [] args = new int[] {Pt_ARG_TREND_MIN,0,0};
OS.PtGetResources(handleTrend,args.length / 3,args);
trendMin = (short) args[1];args = new int[] {Pt_ARG_TREND_MAX,0,0};
OS.PtGetResources(handleTrend,args.length / 3,args);
trendMax = (short) args[1];
}
public Point computeSize(int wHint, int hHint, boolean changed) {
checkWidget();
int [] result = new int[2];
computeSize(handles[0], result);
if (wHint != SWT.DEFAULT) result[0] = wHint;
if (hHint != SWT.DEFAULT) result[1] = hHint;
int border = getBorderWidth();
return new Point(result[0] + border2, result[1] + border2);
}
/** Enables the graphic widget to draw grid if argument is
code>true</code
- and disabes it otherwise.
- @param flag the new grid state /
public void setGrid(boolean flag) {
OS.PtSetResource(handleTrend, Pt_ARG_TREND_FLAGS, ((flag) ? -1 :
0), Pt_RESULT_GRID);
}
/*- Set grid’s lines color
/
public void setGridColor(Color c){
int color = (c.getRed() & 0xff) << 16 | (c.getGreen() & 0xff) << 8 |
(c.getBlue() & 0xff);
OS.PtSetResource(handleTrend, Pt_ARG_TREND_GRID_COLOR, color, 0);
}
/*- Set grid dimensions
/
public void setGridSize(int x,int y){
OS.PtSetResource(handleTrend, Pt_ARG_TREND_GRID_X, x, 0);
OS.PtSetResource(handleTrend, Pt_ARG_TREND_GRID_Y, y, 0);
}
/*- Set min/max boundaries for the trend
/
public void setMinMaxBounds(double min,double max){
this.min = min; this.max = max;
}
/*- Set pen’s color
*/
public void setPenColor(Color c){
int color = (c.getRed() & 0xff) << 16 | (c.getGreen() & 0xff) << 8 |
(c.getBlue() & 0xff);
int [] jarray = new int[] {color};
int ptr = OS.malloc(4);
OS.memmove(ptr,jarray,4);
OS.PtSetResource(handleTrend, Pt_ARG_TREND_COLOR_LIST, ptr, 1);jarray[0] = 1; // number of color here
OS.memset(ptr,0,4);
OS.memmove(ptr,jarray,4);OS.PtSetResource(handleTrend,Pt_ARG_TREND_ATTRIBUTES,ptr,1);
OS.free(ptr);
}
/**
- Push data at end of trend
*/
public void pushData(double v){
if(v>max) v = max;
if(v<min) v = min;
short data = (short)(v * (trendMax-trendMin)/(max-min) + trendMin);
int [] jarray = new int[] {data};
int ptr = OS.malloc(4);
OS.memmove(ptr,jarray,4);
OS.PtSetResource(handleTrend, Pt_ARG_TREND_DATA,ptr,1);
OS.free(ptr);
}static final native int createControl(int handleParent,int [] res);
static final native void resizeControl(int handle, int x, int y, int
width, int height);
static final native void setFocus(int handle);
static final native void computeSize(int handle, int [] result);
}This is the native code:
#include <unistd.h
#include <jni.h
#include <math.h#include <Ph.h
#include <Pt.h#define NATIVE(func) Java_org_eclipse_swt_widgets_Trend_##func
/**
- PtOSContainer → [0]
- PtTrend → [1]
*/
JNIEXPORT jint JNICALL NATIVE(createControl)(JNIEnv *env, jclass that,
jint parent, jintArray handles) {
jint *result = (*env)->GetIntArrayElements(env, handles, NULL);result[0] = (jint) PtCreateWidget(PtOSContainer,(PtWidget_t*)
parent,0,NULL);
result[1] = (jint) PtCreateWidget(PtTrend,(PtWidget_t*)
result[0],0,NULL);PtSetResource((PtWidget_t*) result[1], Pt_ARG_ANCHOR_FLAGS, Pt_TRUE,
Pt_LEFT_ANCHORED_LEFT |
Pt_RIGHT_ANCHORED_RIGHT | Pt_TOP_ANCHORED_TOP |
Pt_BOTTOM_ANCHORED_BOTTOM );
(env)->ReleaseIntArrayElements(env, handles, result, 0);
return result[0];
}
JNIEXPORT void JNICALL NATIVE(resizeControl)(JNIEnv env,jclass
that,jint handle,jint x,jint y,jint width,jint height){
PhArea_t area;
area.pos.x = x;
area.pos.y = y;
area.size.w = width;
area.size.h = height;
PtSetResource((PtWidget_t*)handle,Pt_ARG_AREA,&area,0);
PtUnrealizeWidget((PtWidget_t*)handle);
PtRealizeWidget((PtWidget_t*)handle);
}JNIEXPORT void JNICALL NATIVE(setFocus)(JNIEnv *env, jclass that, jint
handle){}
JNIEXPORT void JNICALL NATIVE(computeSize)(JNIEnv *env, jclass that,
jint handle, jintArray result){
jint *result1 = (*env)->GetIntArrayElements(env,result,NULL);
PhDim_t dim;PtWidgetPreferredSize((PtWidget_t*) handle,&dim);
result1[0] = dim.w;
result1[1] = dim.h;
(*env)->ReleaseIntArrayElements(env,result,result1,0);
}
Sergiy Uvarov wrote:Hi, All.
I use SWT to build gui applications and added some extra widgets to
SWT as eclipse recommending. In QNX6.2.1 all my applications work well
but in QNX6.3 during any photon call in JNI j9 is stopped by
unhandeled exception.What have changed that I can’t create widget in JNI?
–
Sergiy Uvarov