|
|
||
Pete Morgan's BlogOctober 2006 ArchivesOf Netbeans form files, Widget macros and Matisse.Posted by panaseam on October 29, 2006 at 01:18 PM | Permalink | Comments (0)Just recently I've been tinkering with my project particularly in the realm of “Widget tweaking”. I won't bore you with the details, but suffice to say that “Something strange happened to me on the way to the repository!” Basically I was editing my component source then checking that my changes worked OK in Netbeans. The problem occurred when I made a mistake in a container class and the IDE registered it as a component. I investigated the problem, saw my stupid mistake and rectified it. So having closed my test form in the IDE, I reopened it but, to my dismay, the damn thing was still not behaving like a container. My first thought was that the class was not being unloaded by the VM. So I put a bit of code in to fire a message box. This worked, so the IDE was obviously doing the right thing with class loading (I never doubted it really!) but the thing was still registered as a sub component. I then tried adding another instance of my container class and “lo and behold” this correctly registered itself as a container.Then the penny dropped. I opened the form file in another editor and sure enough there was my original instance tagged as a component and my new instance tagged as a container. Now I'm sure many people will think “how stupid can this guy be?” either because they think I should use Eclipse or simply that I should have known Netbeans would retain the original tag. Well firstly, as there is only me on this project, making my widgets usable with Eclipse is still on the “to do” list, secondly, I suppose I did know about the contents of the form file but it just didn't dawn on me at the time. Of course it is, perhaps, an example of why some people do not like the idea of the form file controlling what happens in the IDE. I can see there are pro's and con's to the concept of a separate IDE control file, with it the integrity of the IDE generated stuff is probably safer from inadvertently screwing up by editing the source in another editor. But on the con side it is another file that must be maintained and if somehow it got out of sync with the java source ar worse still if it got lost...! Well it just doesn't bear thinking about. Anyway, the aim of this blog was not to start another Netbeans vs Eclipse (or any other IDE) flame war, it's about my fun and games with creating compound components or widgets as I prefer to call them which leads me to my next point, which is more of a request for comment. Widget Macros (or Macro Widgets). Whilst getting confused with the niceties, or otherwise, of Netbeans form files, I started musing about the problem of compound widgets in an IDE. What I mean is creating a widget that contains sub components. Obviously the IDE has no visibility to the inner components of such a compound widget. This can be a pain if you just want to tweak an odd property as you either have to wrap the required sub component methods in your widget class API or you could provide access to the sub components with suitable getter methods, but it isn't very elegant. So what I wondered was, and this could apply to any IDE, would it be feasible to derive a sort of macro approach where a compound widget could be assembled using the IDE as if it were a normal form and then saved, in source form, as a macro “template” which could be inserted into a real form at design time, expanded out so that all the inner parts of the widget became separately visible to the IDE but bound together in some way to prevent breaking the predefined relationship of the widget's sub components. It's probably a daft idea, or it's already been done. But I just wondered what anyone thinks? Also: Matisse and ScollPanes who's in control? Whilst on the subject of IDEs, or Netbeans in particular. Is there any way to stop Matisse automatically adding a JScrollPane when you add a Scrollable component? I couldn't find any way but it could be I never looked in the right place! The reason I ask is that in the earlier version of my project I had created a JTextArea and a JList subclass that, at run time, automatically added a JScrollPane as an instance of either got added to my custom subclassed JPanel container. Matisse adding its own JScrollPane in such a case was a nuisance as it was not obvious to an end user that they must remove that JScrollPane. The new version of my widget appears to the IDE as a JComponent so Matisse ignores it, so the problem has gone away at the moment. I just wondered if there was an easy fix? If there isn't, then I would respectfully suggest there should be! Any automatic feature, no matter how brilliant should always allow the end user to switch it off if required. The switch should be a property associated with any form class so that templates can be created with the feature switched off if necessary. Or, alternatively, it should be possible to mark a widget class so that the feature was disabled even though the class implements Scrollable. Just my two pennies worth. Anyway enough of my ramblings! Happy hacking, Pete Java is on it's way out? Not from where I'm standing!Posted by panaseam on October 05, 2006 at 02:18 PM | Permalink | Comments (11)I've just been musing over the current java.net poll What do you prefer for enterprise Java persistence? and noticed that out of a total of 1425 votes cast 107 voted for "I don't develop enterprise Java". I am one of those 107. Now I know the poll is about enterprise Java so you may get a slightly higher response rate from people that do develop enterprise Java, but this roughly indicates that 92.5% of java developers do enterprise Java development and 7.5% don't. Yes I also know the old saying about “lies, damn lies and statistics” and I can't help wondering how many of those developers also do desktop application development. The reason for my interest in these numbers lies in the fact that in my nosing around the internet I often see posts by the “Java is dead” brigade, and whilst I have never tried quantifying anything, they also seem predominantly enterprise related rants. To get to my point, I honestly think that Java, from my desktop only perspective, is “top of the pile”. To my mind Java encapsulates such a high percentage of whatever I need to do the job that I actually don't have to look elsewhere to get the job done. Swing is being improved all the time plus you have the innovative work of people like Kirill Grouchnikov, or you can use SWT if you prefer. And all this is platform independent! So from my vantage point Java is very much alive and kicking. On the desktop you only really need one tool, an IDE, beyond that, with Java you have all you need to get developing. Yes you may prefer to use, for example third party widget libraries or re factoring tools etc., but you don't have to have them to be productive. Lets face it you could do without an IDE if you want. Yes just J2SE JDK, an editor and off you go! I know Java gets knocked as a desktop environment as well, but quite frankly, unless you are a “ ' softy” and want to be ensnared in the "net", what other languages give you all you need in one package? Yes I am aware of the Mono project, but I don't get a warm comfortable feeling about it, I still feel that "net" closing round me!:-) We all know nothing is perfect, there is always room for improvement but all too often whingers make statements like “C# has pass by reference so Java should have it too, otherwise I'll just have to move over to C#”. <rant>Well all I can say is if a dumbass like me can emulate the whole VB core language in Java, including, pass by ref, GoTos, weird operator precedence and pretty well every other VB strangeness then “Java don't need changing” and certainly not to keep some lame brain troll from “defecting to C#”!</rant> In the enterprise scenario, part of the problem, as I see it, is that if all or most of your development is geared around a browser at the client end, it isn't so much what the language does or doesn't give you in itself, but more about the tools and frameworks that are available for your chosen language. So often the ranters don't distinguish between the way Java enterprise solutions are created and the language they are created in. I have even seen Ajax used as a reason why Java is doomed. That is a weird view since I thought you can “do Ajax” in Java, but then what do I know? I wonder how many posts on non-Java sites there are praising Java? Not many I guess. Why? Because real Java developers know they are on to a good thing and don't waste their time trying to convince “non believers”. The language is only as good as the people who use it! Enough said! So from a lowly, part time, desktop bod to all you real Java developers I say ignore the trolls, let them get on with their latest “next best thing” you know you've already found it and its called Java. Happy hacking, Pete Projects Semplice, OpenOffice.org & PaNaSeaM: Supporting classic VB.Posted by panaseam on October 02, 2006 at 01:34 PM | Permalink | Comments (0)Earlier this year, at JavaOne, project Semplice was announced, the aim of which is to allow VB code to be compiled directly into Java bytecode. The development environment is an extension to Netbeans. Prior to this, Novell has been working on a sub project of OpenOffice.org to allow VBA scripts embedded in documents to be executed directly in OpenOffice. This is not a Java solution although the extended, VB compatible API will presumably be accessible to Java through the Java UNO binding but the execution of the VB code will presumably be via extensions to the OOBasic interpreter built into OOo. It is unclear as to whether or not editing and debugging of VB code will be allowed. There is also, a virtually unheard of java.net project, panaseam, that is also aimed at classic VB support using Java. This project uses the concept of conversion to Java, but attempts to maintain program semantics by emulating the VB runtime environment as closely as possible. Hence the converted code is recognizable when compared with the original. In order to do anything with VB code in another environment you have to emulate the functionality of the core VB language engine. I do not know any details as to how Semplice or OOo are doing this. Presumably, as OOBasic is conceptually very similar to VB, extending the interpreter was not too difficult. With Semplice they are presumably doing the “conversion” in the compiler so that the JVM actually sees nothing but perfectly standard Java bytecode. In order to avoid “surprises” for the end user it is very important to maintain total functional compatibility between the original and target environments. There are a few issues that they must have dealt with if the VB code is to run exactly as it did in the VB environment. I am not saying that they haven't dealt with these issues, but if they haven't there will be problems for the end user. VB passes parameters by reference normally. Java ALWAYS passes by value. Not to be confused with passing a referent by value this is not the same thing at all. It means an object passed by reference can be replaced by a new object in the called procedure and this new object will also appear in the scope of the calling procedure. This works the same for primitives as well, but, thankfully, not for constants. Whilst using this functionality may be considered bad programming practice, in order to maintain 100% functional compatibility it needs to be implemented. VB operator precedence is significantly different to Java. Good maintainable code should not rely on operator precedence however who said the VB code is going to be good? VB has a “Static” declaration that causes procedure local variables to retain their values between calls. This is nothing like the static modifier in Java. This functionality is probably little used but again it needs to be implemented. There are some legacy Basic elements in VB the worst ones are VB file handling is a bit odd. When files are opened they are allocated a number and all references to that file use that number.
VB has a wonderful “data type” called a Variant which can contain anything you like or don't like come to that. So all in all lots of fun! Neither Semplice or OOo are attempting any sort of code conversion, One advantage of this approach is that you maintain interoperability with the original environment. Hence, particularly in the OpenOffice case, you could share documents that include macros between Windows, Mac and Linux users for example. If, however, your only aim is unidirectional migration from a platform locked environment then retaining backward compatibility becomes moot. I see the three projects as primarily complimentary not competitive. Yes panaseam overlaps the other two in the sense that it is taking a holistic approach to VB but it is certainly not a compiler and it is definitely not an office productivity suite. One problem I see with both the Semplice and OOo approach is that if an end user hits a problem because either the compiler or runtime VB emulation, or whatever, is not quite right, they cannot do anything about it! All they have is VB code that doesn't work in the new environment. Even if both projects open source their work, Semplice will probably be deep JVM and compiler stuff, and OOo will all be implemented in C++ and UNO, neither of which is suitable for the likes of ex VB coders or even some Java coders to unravel. So all the end user will be able to do is send a bug report and wait. Also neither project appears designed for end users to directly add missing functionality. The panaseam approach is via code conversion, coupled with an open source Java runtime environment that emulates the whole VB core language in Java. If the end user hits a problem due to a drop off in translation or runtime emulation, they can compare the translated code with the original to see if the program semantics have been messed up by the translator and they can also delve into the runtime environment, which will be pure Java, to see what is going wrong there. Also as the environment will allow pluggable runtime modules to be used, the end user could even create their own tweaked version and simply plug it in place of the supplied module. It also means missing functionality can be added readily as it becomes available without having to be released as a complete update of the whole environment. A big advantage for the Semplice and OOo projects is that they can choose to keep their solutions closed and as a result they won't expose themselves to copyright infringement claims and anyway they are under the umbrella of large organizations. Yes I know closed source would be a problem for OpenOffice but at the moment the VBA extensions are still being developed by Novell and could be released as a closed source add on. The panaseam project has already proved that the concept works but has hit a “slight” problem. That leads me neatly on to the next part of my blog IPvIP Part2: Is a Java interface copyright protected? Happy hacking | ||
|
|