Thread: Re: [Java-gnome-developer] JTable(Swing) to java-gnome
Brought to you by:
afcowie
From: Joao V. <jvi...@ya...> - 2005-03-24 13:25:01
|
--- Ka-Hing Cheung <ka...@gm...> wrote: > There's currently no way to implement the model(without copying)/renderer > with java-gnome, is there any plan to improve things in that area? Hum, didn't understand exactly what you mean by "There's currently no way to implement the model(without copying)/renderer"? You can make lists and trees, that's possible. A JTable from my understanding would be a multicolumn List, which is also possible. What isn't good, however, is the api to do this stuff... it's too 'C-ish' currently, and yup we're trying to improve things in that area. There's a discussion about this going on here: http://java-gnome.sourceforge.net/cgi-bin/bin/view/Main/JGDiscussionTreeViewEasier Cheers, J.V. Yahoo! Acesso Grátis - Internet rápida e grátis. Instale o discador agora! http://br.acesso.yahoo.com/ |
From: Joao V. <jvi...@ya...> - 2005-03-24 15:00:26
|
--- Robert Marcano <ro...@ma...> wrote: > I think what he wants is to be possible to do what any good user of a > JTable do: > > public class MyModel implements TableModel { > ..... > } > > instead of copying the data from the original source to the > DefaultTableModel class for example. A lot of GTK programmers develop > programs using the last option: copy the data to a GtkTreeStore or > GtkListStore instead of implementing the GtkTreeModel interface (this > was not possible the last time I used java-gnome) Indeed... when i was thinking about the improvements to make to the List/Tree i think i thought of this way, but didn't go on with it because it could be a major change in JG, so i was trying to find a mid-term instead. But this is definitely worth of discussion. Cheers, J.V. Yahoo! Acesso Grátis - Internet rápida e grátis. Instale o discador agora! http://br.acesso.yahoo.com/ |
From: Robert M. <ro...@ma...> - 2005-03-24 13:46:46
|
On Thu, 2005-03-24 at 10:24 -0300, Joao Victor wrote: > --- Ka-Hing Cheung <ka...@gm...> wrote: > > There's currently no way to implement the model(without copying)/renderer > > with java-gnome, is there any plan to improve things in that area? > > Hum, didn't understand exactly what you mean by "There's currently no way to implement the > model(without copying)/renderer"? You can make lists and trees, that's possible. A JTable from my > understanding would be a multicolumn List, which is also possible. I think what he wants is to be possible to do what any good user of a JTable do: public class MyModel implements TableModel { ..... } instead of copying the data from the original source to the DefaultTableModel class for example. A lot of GTK programmers develop programs using the last option: copy the data to a GtkTreeStore or GtkListStore instead of implementing the GtkTreeModel interface (this was not possible the last time I used java-gnome) > > What isn't good, however, is the api to do this stuff... it's too 'C-ish' currently, and yup we're > trying to improve things in that area. There's a discussion about this going on here: > http://java-gnome.sourceforge.net/cgi-bin/bin/view/Main/JGDiscussionTreeViewEasier > > Cheers, > J.V. > ________________________________________ Robert Marcano web: http://www.marcanoonline.com/ blog: http://www.marcanoonline.com/plog/ |
From: Ka-Hing C. <ka...@gm...> - 2005-03-25 03:02:02
|
On Thu, 24 Mar 2005 09:45:50 -0400, Robert Marcano <ro...@ma...> wrote: > I think what he wants is to be possible to do what any good user of a > JTable do: > > public class MyModel implements TableModel { > ..... > } > > instead of copying the data from the original source to the > DefaultTableModel class for example. A lot of GTK programmers develop > programs using the last option: copy the data to a GtkTreeStore or > GtkListStore instead of implementing the GtkTreeModel interface (this > was not possible the last time I used java-gnome) Yes that's what I meant, and there's no way to write your own renderer at all. -khc |
From: Ka-Hing C. <ka...@gm...> - 2005-03-27 02:39:08
|
On Thu, 24 Mar 2005 19:01:59 -0800, Ka-Hing Cheung <ka...@gm...> wrote: > On Thu, 24 Mar 2005 09:45:50 -0400, Robert Marcano > <ro...@ma...> wrote: > > I think what he wants is to be possible to do what any good user of a > > JTable do: > > > > public class MyModel implements TableModel { > > ..... > > } > > > > instead of copying the data from the original source to the > > DefaultTableModel class for example. A lot of GTK programmers develop > > programs using the last option: copy the data to a GtkTreeStore or > > GtkListStore instead of implementing the GtkTreeModel interface (this > > was not possible the last time I used java-gnome) > I just started to work on a CustomTreeModel which would let you do that. I am quite new to JNI and not sure if the whole thing would work at all, I will let you know what I find out within the next week or so. -khc |
From: Ka-Hing C. <ka...@gm...> - 2005-03-28 01:20:59
Attachments:
CustomTreeModel.java
org_gnu_gtk_CustomTreeModel.c
|
> I just started to work on a CustomTreeModel which would let you do > that. I am quite new to JNI and not sure if the whole thing would work > at all, I will let you know what I find out within the next week or > so. Attached is something that I hacked to together in a couple hours. Seems to work for a flat list with one column, didn't try anything more complex than that. Note that in order for the tree to display whatever's in the model, you still need to give it a renderer: /* NewStore is something that extends CustomTreeModel */ TreeView list = new TreeView(new NewStore()); TreeViewColumn col = new TreeViewColumn(); CellRendererText renderer = new CellRendererText(); list.appendColumn(col); col.packStart(renderer, true); col.setVisible(true); DataColumnString c = new DataColumnString(); // associate c with another model, but NOT NewStore, otherwise the next line // will complain col.addAttributeMapping(renderer, CellRendererText.Attribute.TEXT, c); Note that you will need to modify Makefile.am in order for those 2 files to build with java-gtk. -khc |
From: Joao V. <jvi...@ya...> - 2005-03-28 02:46:18
|
Looks nice... could you please attach those files to http://java-gnome.sourceforge.net/cgi-bin/bin/view/Main/JGDiscussionTreeViewEasier ? I think the way the columns are created (and the way the renderer is set) could be improved, maybe with some ideas which are on that topic. For example, ---- TreeViewColumn col = new TreeViewColumn(); list.appendColumn(col) ---- is not very Javaish. Something like: ---- TreeViewColumn col = list.newColumn(); ---- would be better, IMO. Anyways, we can work this. Cheers, J.V. --- Ka-Hing Cheung <ka...@gm...> escreveu: > > I just started to work on a CustomTreeModel which would let you do > > that. I am quite new to JNI and not sure if the whole thing would work > > at all, I will let you know what I find out within the next week or > > so. > > Attached is something that I hacked to together in a couple hours. > Seems to work for a flat list with one column, didn't try anything > more complex than that. Note that in order for the tree to display > whatever's in the model, you still need to give it a renderer: > > /* NewStore is something that extends CustomTreeModel */ > TreeView list = new TreeView(new NewStore()); > TreeViewColumn col = new TreeViewColumn(); > > CellRendererText renderer = new CellRendererText(); > list.appendColumn(col); > col.packStart(renderer, true); > col.setVisible(true); > > DataColumnString c = new DataColumnString(); > // associate c with another model, but NOT NewStore, otherwise the next line > // will complain > col.addAttributeMapping(renderer, CellRendererText.Attribute.TEXT, c); > > Note that you will need to modify Makefile.am in order for those 2 > files to build with java-gtk. > > -khc > > /* > * Java-Gnome Bindings Library > * > * Copyright 1998-2004 the Java-Gnome Team, all rights reserved. > * > * The Java-Gnome bindings library is free software distributed under > * the terms of the GNU Library General Public License version 2. > */ > > package org.gnu.gtk; > > import org.gnu.glib.Handle; > import org.gnu.glib.Type; > import org.gnu.glib.Value; > > public abstract class CustomTreeModel extends TreeModel { > > public CustomTreeModel() { > super(custom_tree_model_new()); > set_java_model(); > } > > > /** > * @return probably 0 > */ > public abstract int getFlags(); > > /** > * @return the number of columns > */ > public abstract int getColumnCount(); > > /** > * @return the type of the column > */ > public abstract Type getColumnType(int column); > > /** > * row is the object returned by getChild, non-null > * > * @return > */ > public abstract Value getValue(Object row, int column); > > /** > * @return the i'th child of obj, or if obj is null, return the i'th > * top level node > */ > public abstract Object getChild(Object obj, int i); > > /** > * if obj is null, return the number of top-level rows > */ > public abstract int getChildrenCount(Object obj); > > public abstract int getIndexOfChild(Object parent, Object child); > > public abstract Object getParent(Object child); > > native final private void set_java_model(); > > native static final protected Handle custom_tree_model_new(); > } > > /* > * Java-Gnome Bindings Library > * > * Copyright 1998-2004 the Java-Gnome Team, all rights reserved. > * > * The Java-Gnome bindings library is free software distributed under > * the terms of the GNU Library General Public License version 2. > */ > > #include <jni.h> > #include <gtk/gtk.h> > #include "jg_jnu.h" > > #ifdef __cplusplus > extern "C" > { > #endif > > > /* Some boilerplate GObject defines. 'klass' is used > * instead of 'class', because 'class' is a C++ keyword */ > > #define TREE_MODEL_TYPE (tree_model_get_type()) > #define TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), TREE_MODEL_TYPE, TreeModel)) > #define TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), TREE_MODEL_TYPE, > TreeModelClass)) > #define IS_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), TREE_MODEL_TYPE)) > #define IS_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), TREE_MODEL_TYPE)) > #define TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), TREE_MODEL_TYPE, > TreeModelClass)) > > > typedef struct _TreeModel TreeModel; > typedef struct _TreeModelClass TreeModelClass; > > > > /* CustomList: this structure contains everything we need for our > * model implementation. You can add extra fields to > * this structure, e.g. hashtables to quickly lookup > * rows or whatever else you might need, but it is > * crucial that 'parent' is the first member of the > * structure. */ > > struct _TreeModel > { > GObject parent; /* this MUST be the first member */ > > JNIEnv *java_env; > > jobject java_model; /* underly java model */ > > }; > > > /* CustomListClass: more boilerplate GObject stuff */ > > struct _TreeModelClass > { > GObjectClass parent_class; > }; > > > GType tree_model_get_type (void); > > TreeModel *tree_model_new (void); > > void tree_model_set_jobject(TreeModel *model, JNIEnv *env, jobject obj); > > > /* boring declarations of local functions */ > > static void tree_model_init (TreeModel *pkg_tree); > > static void tree_model_class_init (TreeModelClass *klass); > > static void tree_model_tree_model_init (GtkTreeModelIface *iface); > > static void tree_model_finalize (GObject *object); > > static GtkTreeModelFlags tree_model_get_flags (GtkTreeModel *tree_model); > > static gint tree_model_get_n_columns (GtkTreeModel *tree_model); > > static GType tree_model_get_column_type (GtkTreeModel *tree_model, > gint index); > > static gboolean tree_model_get_iter (GtkTreeModel *tree_model, > GtkTreeIter *iter, > GtkTreePath *path); > > static GtkTreePath *tree_model_get_path (GtkTreeModel *tree_model, > GtkTreeIter *iter); > > static void tree_model_get_value (GtkTreeModel *tree_model, > GtkTreeIter *iter, > gint column, > GValue *value); > > static gboolean tree_model_iter_next (GtkTreeModel *tree_model, > GtkTreeIter *iter); > > static gboolean tree_model_iter_children (GtkTreeModel *tree_model, > GtkTreeIter *iter, > GtkTreeIter *parent); > > static gboolean tree_model_iter_has_child (GtkTreeModel *tree_model, > GtkTreeIter *iter); > > static gint tree_model_iter_n_children (GtkTreeModel *tree_model, > GtkTreeIter *iter); > > static gboolean tree_model_iter_nth_child (GtkTreeModel *tree_model, > GtkTreeIter *iter, > GtkTreeIter *parent, > gint n); > > static gboolean tree_model_iter_parent (GtkTreeModel *tree_model, > GtkTreeIter *iter, > GtkTreeIter *child); > > > > static GObjectClass *parent_class = NULL; /* GObject stuff - nothing to worry about */ > > JNIEXPORT void JNICALL > Java_org_gnu_gtk_CustomTreeModel_set_1java_1model(JNIEnv *env, jobject obj) > { > TreeModel *model = (TreeModel *)getPointerFromJavaGObject(env, obj); > model->java_model = (*env)->NewGlobalRef(env, obj); > } > > JNIEXPORT jobject JNICALL > Java_org_gnu_gtk_CustomTreeModel_custom_1tree_1model_1new(JNIEnv *env, > jclass klass) > { > TreeModel *model = tree_model_new(); > model->java_env = env; > > return getHandleFromPointer(env, model); > } > > /***************************************************************************** > * > * tree_model_get_type: here we register our new type and its interfaces > * with the type system. If you want to implement > * additional interfaces like GtkTreeSortable, you > * will need to do it here. > * > *****************************************************************************/ > > GType > tree_model_get_type (void) > { > static GType tree_model_type = 0; > > if (tree_model_type) > return tree_model_type; > > /* Some boilerplate type registration stuff */ > if (1) > { > static const GTypeInfo tree_model_info = > { > sizeof (TreeModelClass), > NULL, /* base_init */ > NULL, /* base_finalize */ > (GClassInitFunc) tree_model_class_init, > NULL, /* class finalize */ > NULL, /* class_data */ > sizeof (TreeModel), > 0, /* n_preallocs */ > (GInstanceInitFunc) tree_model_init > }; > > tree_model_type = g_type_register_static (G_TYPE_OBJECT, "TreeModel", > &tree_model_info, (GTypeFlags)0); > } > > /* Here we register our GtkTreeModel interface with the type system */ > if (1) > { > static const GInterfaceInfo tree_model_info = > { > (GInterfaceInitFunc) tree_model_tree_model_init, > NULL, > NULL > }; > > g_type_add_interface_static (tree_model_type, GTK_TYPE_TREE_MODEL, &tree_model_info); > } > > return tree_model_type; > } > > > /***************************************************************************** > * > * tree_model_class_init: more boilerplate GObject/GType stuff. > * Init callback for the type system, > * called once when our new class is created. > === message truncated === Yahoo! Acesso Grátis - Internet rápida e grátis. Instale o discador agora! http://br.acesso.yahoo.com/ |