Thread: [Java-gnome-developer] Create a custom GTK RoundedFrame in Java Gnome
Brought to you by:
afcowie
From: bob <loi...@pa...> - 2010-10-20 14:35:15
|
When I'm reading the banshee source (C# language), I found how to create a custom component in C#. It's very simple, the developer had to extend the Gtk.Bin Object. I search to do the same thing in Java but I don't found any "simple" solution, we couldn't extends the Bin object. I think it is possible to create this component in C and create binding like all object in java-gnome but it's not very simple (add C code and add Java binding working with java-gnome). There is a solution to create a custom widget in Java ? Could you update the java-gnome library to do it ? // // The custom GTK widget RoundedFrame // namespace Hyena.Widgets { public class RoundedFrame : Bin { private Theme theme; protected Theme Theme { get { return theme; } } private Widget child; private Gdk.Rectangle child_allocation; private bool fill_color_set; private Cairo.Color fill_color; private bool draw_border = true; private Pattern fill_pattern; private int frame_width; // Ugh, this is to avoid the GLib.MissingIntPtrCtorException seen by some; BGO #552169 protected RoundedFrame (IntPtr ptr) : base (ptr) { } public RoundedFrame () { } public void SetFillColor (Cairo.Color color) { fill_color = color; fill_color_set = true; QueueDraw (); } public void UnsetFillColor () { fill_color_set = false; QueueDraw (); } public Pattern FillPattern { get { return fill_pattern; } set { fill_pattern = value; QueueDraw (); } } public bool DrawBorder { get { return draw_border; } set { draw_border = value; QueueDraw (); } } #region Gtk.Widget Overrides protected override void OnStyleSet (Style previous_style) { base.OnStyleSet (previous_style); theme = Hyena.Gui.Theming.ThemeEngine.CreateTheme (this); frame_width = (int)theme.Context.Radius + 1; } protected override void OnSizeRequested (ref Requisition requisition) { if (child != null && child.Visible) { // Add the child's width/height Requisition child_requisition = child.SizeRequest (); requisition.Width = Math.Max (0, child_requisition.Width); requisition.Height = child_requisition.Height; } else { requisition.Width = 0; requisition.Height = 0; } // Add the frame border requisition.Width += ((int)BorderWidth + frame_width) * 2; requisition.Height += ((int)BorderWidth + frame_width) * 2; } protected override void OnSizeAllocated (Gdk.Rectangle allocation) { base.OnSizeAllocated (allocation); child_allocation = new Gdk.Rectangle (); if (child == null || !child.Visible) { return; } child_allocation.X = (int)BorderWidth + frame_width; child_allocation.Y = (int)BorderWidth + frame_width; child_allocation.Width = (int)Math.Max (1, Allocation.Width - child_allocation.X * 2); child_allocation.Height = (int)Math.Max (1, Allocation.Height - child_allocation.Y - (int)BorderWidth - frame_width); child_allocation.X += Allocation.X; child_allocation.Y += Allocation.Y; child.SizeAllocate (child_allocation); } protected override void OnSetScrollAdjustments (Adjustment hadj, Adjustment vadj) { // This is to satisfy the gtk_widget_set_scroll_adjustments // inside of GtkScrolledWindow so it doesn't complain about // its child not being scrollable. } protected override bool OnExposeEvent (Gdk.EventExpose evnt) { if (!IsDrawable) { return false; } Cairo.Context cr = Gdk.CairoHelper.Create (evnt.Window); try { DrawFrame (cr, evnt.Area); if (child != null) { PropagateExpose (child, evnt); } return false; } finally { CairoExtensions.DisposeContext (cr); } } private void DrawFrame (Cairo.Context cr, Gdk.Rectangle clip) { int x = child_allocation.X - frame_width; int y = child_allocation.Y - frame_width; int width = child_allocation.Width + 2 * frame_width; int height = child_allocation.Height + 2 * frame_width; Gdk.Rectangle rect = new Gdk.Rectangle (x, y, width, height); theme.Context.ShowStroke = draw_border; if (fill_color_set) { theme.DrawFrameBackground (cr, rect, fill_color); } else if (fill_pattern != null) { theme.DrawFrameBackground (cr, rect, fill_pattern); } else { theme.DrawFrameBackground (cr, rect, true); theme.DrawFrameBorder (cr, rect); } } #endregion #region Gtk.Container Overrides protected override void OnAdded (Widget widget) { child = widget; base.OnAdded (widget); } protected override void OnRemoved (Widget widget) { if (child == widget) { child = null; } base.OnRemoved (widget); } #endregion } } |
From: Andrew C. <an...@op...> - 2010-10-23 12:37:56
|
On Wed, 2010-10-20 at 16:15 +0200, bob wrote: > There is a solution to create a custom widget in Java? For what most people need, they just use (or subclass, whatever) DrawingArea. Could you perhaps explain what you're actually trying to do? > // The custom GTK widget RoundedFrame I don't read .Net, sorry. AfC A Coruña |
From: bob <loi...@pa...> - 2010-10-23 12:59:05
|
I work on the librebook project https://launchpad.net/librebook and for reproduce the same look that Rhythmbox or Banshee, I read the source of these projects and I saw that developers use custom widget for the tree navigator or for the list. It is very important that I could increase the look of my project so I would like to use some customs GTK widget. Do you think it's possible to create pure java like a complex navigator tree with the DrawingArea object ? Loïc Dreux Le samedi 23 octobre 2010 à 14:37 +0200, Andrew Cowie a écrit : > On Wed, 2010-10-20 at 16:15 +0200, bob wrote: > > > There is a solution to create a custom widget in Java? > > For what most people need, they just use (or subclass, whatever) > DrawingArea. Could you perhaps explain what you're actually trying to > do? > > > // The custom GTK widget RoundedFrame > > I don't read .Net, sorry. > > AfC > A Coruña > > > > ------------------------------------------------------------------------------ > Nokia and AT&T present the 2010 Calling All Innovators-North America contest > Create new apps & games for the Nokia N8 for consumers in U.S. and Canada > $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing > Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store > http://p.sf.net/sfu/nokia-dev2dev > _______________________________________________ > java-gnome-developer mailing list > jav...@li... > https://lists.sourceforge.net/lists/listinfo/java-gnome-developer n |
From: bob <loi...@pa...> - 2010-10-29 17:53:58
|
Hello, Good news, I successful create a custom CellRenderer in Vala and use this CellRenderer in Java with Java Gnome. Now I compile the vala source manually but I will update my configure and Makefile script. It's a hack but it's work, the screenshot is accessible at this URL : https://www.papaye.me/wiki/librebook/screenshot There are still some problems : I create my custom CellRenderer in the org.java.gnome package because a lot of generated methods are in package visibility so I couldn't use these object methods in another package. And I don't use the bindings_java_memory_cleanup() call in my JNI source because I don't how to do this, I'm not a C programmer and I don't know how to link my library with the libgtkjni.so. Best regards, Loïc Dreux Le samedi 23 octobre 2010 à 14:58 +0200, bob a écrit : > I work on the librebook project https://launchpad.net/librebook and for > reproduce the same look that Rhythmbox or Banshee, I read the source of > these projects and I saw that developers use custom widget for the tree > navigator or for the list. > > It is very important that I could increase the look of my project so I > would like to use some customs GTK widget. > > Do you think it's possible to create pure java like a complex navigator > tree with the DrawingArea object ? > > Loïc Dreux > > Le samedi 23 octobre 2010 à 14:37 +0200, Andrew Cowie a écrit : > > On Wed, 2010-10-20 at 16:15 +0200, bob wrote: > > > > > There is a solution to create a custom widget in Java? > > > > For what most people need, they just use (or subclass, whatever) > > DrawingArea. Could you perhaps explain what you're actually trying to > > do? > > > > > // The custom GTK widget RoundedFrame > > > > I don't read .Net, sorry. > > > > AfC > > A Coruña > > > > > > > > ------------------------------------------------------------------------------ > > Nokia and AT&T present the 2010 Calling All Innovators-North America contest > > Create new apps & games for the Nokia N8 for consumers in U.S. and Canada > > $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing > > Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store > > http://p.sf.net/sfu/nokia-dev2dev > > _______________________________________________ > > java-gnome-developer mailing list > > jav...@li... > > https://lists.sourceforge.net/lists/listinfo/java-gnome-developer > n > > > ------------------------------------------------------------------------------ > Nokia and AT&T present the 2010 Calling All Innovators-North America contest > Create new apps & games for the Nokia N8 for consumers in U.S. and Canada > $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing > Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store > http://p.sf.net/sfu/nokia-dev2dev > _______________________________________________ > java-gnome-developer mailing list > jav...@li... > https://lists.sourceforge.net/lists/listinfo/java-gnome-developer |
From: Andrew C. <an...@op...> - 2010-10-29 21:22:04
|
On Fri, 2010-10-29 at 19:53 +0200, bob wrote: > Good news, I successful create a custom CellRenderer in Vala Um. You're probably not going to be able to mix java-gnome code and Vala code and absolutely not if they use ToggleRefs. [The GEdit people are going through this right now trying to mix Python and JavaScript plugins. It won't work; only one (language) can have a ToggleRef to a GObject {shrug}] > I create my custom CellRenderer We had not really gone much further in talking about what you needed. Last you said you wanted to subclass Bin. Now you're talking about CellRenderer. Which is it? At the GTK Hackfest Vreixo and I talked about some possibilities for how to implement a subclassable Bin. We could also do this technique for CellRenderer too, though neither of us are hacking on that area right now. > the screenshot > So back to what you are trying to achieve. In that screenshot all I see is what looks to me like something you could do in a TreeView with a CellRendererPixbuf and a CellRendererText. What is it that you needed custom that we don't have in java-gnome right now? Why not just add 2 × CellRenderer to your TreeViewColumn? > I don't know > how to link my library with the libgtkjni.so. You can't. It's not a public library. It has no public symbols, and no API or ABI. It's not for linking against. AfC Granada |
From: Loïc D. <loi...@pa...> - 2010-11-03 14:39:07
|
Le vendredi 29 octobre 2010 à 23:21 +0200, Andrew Cowie a écrit : > On Fri, 2010-10-29 at 19:53 +0200, bob wrote: > > Good news, I successful create a custom CellRenderer in Vala > > Um. > > You're probably not going to be able to mix java-gnome code and Vala > code and absolutely not if they use ToggleRefs. > > [The GEdit people are going through this right now trying to mix Python > and JavaScript plugins. It won't work; only one (language) can have a > ToggleRef to a GObject {shrug}] Vala isn't an interpreted language like Python or JavaScript, Vala produce native code like the C language. But I don't know what are ToggleRef so I can't say if my code is good. > > > I create my custom CellRenderer > > We had not really gone much further in talking about what you needed. > Last you said you wanted to subclass Bin. Now you're talking about > CellRenderer. Which is it? I need to extends CellRenderer, I try to extends Bin for testing exclusively (with success). The first custum CellRenderer is for the "Navigator". I failed to create a good render with two native TextCellRenderer and PixbufCellRenderer (different height and different text position in the same tree) so I create a custom CellRenderer and that's work. I would like to create a second CellRenderer with stars for rating eBooks in future. > > At the GTK Hackfest Vreixo and I talked about some possibilities for how > to implement a subclassable Bin. We could also do this technique for > CellRenderer too, though neither of us are hacking on that area right > now. I'm waiting for extend CellRenderer (or bin) in pure Java ! > > > the screenshot > > > So back to what you are trying to achieve. In that screenshot all I see > is what looks to me like something you could do in a TreeView with a > CellRendererPixbuf and a CellRendererText. What is it that you needed > custom that we don't have in java-gnome right now? Why not just add 2 × > CellRenderer to your TreeViewColumn? See above I failed to produce the same renderer with 2 CellRenderers. > > > I don't know > > how to link my library with the libgtkjni.so. > > You can't. It's not a public library. It has no public symbols, and no > API or ABI. It's not for linking against. I know that libgtkjni isn't a public library, but if we couldn't extends CellRenderer in pure Java, I would like to create native components, but I can't call the bindings_java_memory_cleanup method in the code below because it's a libgtkjni function and I'm afraid that cause some problems with memory. JNIEXPORT jlong JNICALL Java_org_gnome_gtk_LibrebookCellRendererNavigator_librebook_1cell_1renderer_1navigator_1new (JNIEnv * env, jclass cls) { LibrebookCellRendererNavigator* result; jlong _result; // call function result = librebook_cell_renderer_navigator_new(); // translate return value to JNI type _result = (jlong) result; // cleanup return value //if (result != NULL) { // bindings_java_memory_cleanup((GObject*)result, TRUE); //} // and finally return _result; } Thanks for you helps and for your great works, I love developing Gnome application with a good integration in my desktop in Java. > > AfC > Granada > > ------------------------------------------------------------------------------ > Nokia and AT&T present the 2010 Calling All Innovators-North America contest > Create new apps & games for the Nokia N8 for consumers in U.S. and Canada > $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing > Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store > http://p.sf.net/sfu/nokia-dev2dev > _______________________________________________ java-gnome-developer mailing list jav...@li... https://lists.sourceforge.net/lists/listinfo/java-gnome-developer |