|
|
||
Pete Morgan's BlogProgramming 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 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 IP v IP. (Intellectual Property versus Innovation Protection) Part 1: Courts and CodersPosted by panaseam on September 27, 2006 at 01:44 PM | Permalink | Comments (5)There are numerous small open source projects hosted on java.net and whilst this post, in itself, is not Java specific it is as the owner of one of those small projects that I voice my concerns! It's a reasonable guess that many programmers find legal stuff boring as hell and as far as possible ignore it. Unfortunately in this world of patents and copyrights it could be only too easy for an ordinary open source coder to fall foul of alleged intellectual property infringement. Ignoring the legalities is not an option, in the eye of the law "Ignorance is no defense". Also complacency is anti-innovative and therefore unacceptable. If you program in a purely commercial environment you may feel legal issues don't affect you, but if you use any open source software at all then you should at least consider how legalities could affect that software and its future availability. Just to make a point consider this scenario: I have a project hosted on java.net. Now here's the essence of the problem: Far fetched isn't it? Unfortunately not! (apart from the implication that I could ever write some clever code) As an example of what can happen, although not IP related, consider UK based anti spam company Spamhaus being taken to court in Chicago [ http://arstechnica.com/news.ars/post/20060915-7757.html ]. The problem is that legal systems don't prevent you being sued even when you haven't done anything wrong. Consider SCO v IBM. Even though this case involves two large companies rather than large versus tiny, which is my real concern, it still shows how a business with enough money can launch a lawsuit against anyone on pretty tenuous grounds. There is also a far more sinister undertone in the popular belief that SCO were in fact "put up to" the action by a third party. Anyway, whether or not these cases are relevant, my point is that the patent/copyright jungle is a nightmare for ordinary hackers to even begin to cope with. Larger projects and especially commercially supported ones probably have the resources to at least give a supportive legal umbrella for its members. Any of us working alone or in small groups have no support whatsoever. Remember that open source is making it in the big league, some of the existing big league players could get seriously worried about losing their position and the money that goes with it. They will stop at nothing to maintain that position, these guys play dirty and enjoy bullying little guys so beware, things could get very nasty! One possible solution is to try to get your own ideas accepted as a sub project of an existing large commercially supported project. Even this could be problematic. Who do you contact? Do you send a detailed description or even source code to someone you don't even know? Remember, in this scenario, you probably haven't even published your work so if they chose to they could claim it as their own and you, an unknown outsider, wouldn't stand a chance of convincing anyone of the truth. Of course they could simply tell you your idea is rubbish because they genuinely think it is, or even because they think it could undermine their own cherished ideas. I know it sounds a very dark picture to paint but history is full of stories of people being fleeced, even Walt Disney got ripped off before he created Mickey Mouse. Innovation and the right to innovate do not just belong in the hands of the rich and powerful. It is no good pretending that innovation only occurs in large corporate environments. The beauty of computer programming, particularly in the Java environment, is that pretty well anyone can join in and innovate with minimal resources. The problem is that such individuals are potentially wide open to abuse by anyone with the money to employ a lawyer. You could point out that even in this hostile environment there have been plenty of successfully exploited innovations and many more will occur. But how many innovations have failed or been lost because of it? Taking the lame view that "it's always been like that" is simply not acceptable it is anti-innovative. So to conclude: There is one organization that is along the right lines, namely New York based Software Freedom Law Center Anybody got any thoughts or suggestions? Comments containing "sucks" and "go away you boring old fart" will be considered "off topic" and the poster should be "sued for every penny they have", although I have a preference for $100 bills myself.:). Sorry but there will be a follow up To anyone that read this far, thanks for your time. Happy hacking, | ||
|
|