Friday, March 30, 2007

Customizing the executable

I'm currently working on an NetBeans RCP based app, spending a huge
amount of my time on the platform. I got around to customizing the
application that I'm working on, and I did recall Geertjan's post about cleaning up
the app from the NetBeans specific stuff. Geertjan did mention that
you could fix the executable icon (on Windows) by using the resource
editor on the built zip file. Well, the altenative is to make a copy
of the executable from your ${harness.dir}/launchers/app.exe to your
local project dir, edit the executable resources by using the Resource
Hacker that Geertjan recommended, and modify the build script to use
the modified executable to use your updated executable for building
your app. So, the changes to my harness build file are as described
below. It is indeed a bit of a hack, as one I'd imagine that it
wouldn't be advisable to edit the global build scripts (that build for
all projects); however, it seems that this is a more universal need
for platform developers - one should be able to totally customize the
branding of the application. While the majority of the work is
possible to be done within NetBeans (with the excellent support of the
platform modules), the ability to customize the icon on the executable
is a very important one as well.

in the body of the build-launchers target ($platform_dir/harness/suite.xml):

right after :

<mkdir dir="${build.launcher.dir}/etc"/>
<mkdir dir="${build.launcher.dir}/bin"/>


Add the following :

<available file="branding/launcher/${app.name}.exe" property="local.launcher.found" />
<antcall target="make-local-launcher" inheritall="true"/>





then, add a new target in the same file

<target name="make-local-launcher" unless="local.launcher.found">
<mkdir dir="branding/launcher" />
<copy file="${harness.dir}/launchers/app.exe"
tofile="branding/launcher/${app.name}.exe" overwrite="false"/>
</target>

Sunday, March 25, 2007

Vanished "Sun Smart Ticket" demo app

I'm in the process of scrambling some resources together for my thesis project which has to do with J2ME and video delivery. Now, I've been working on this project (on and off) for the last 1.5 years, so it's been a while since I went back to look at all the resources that I had used at the very beginning.

So, one of the excellent resource that I used from the beginning was the Sun Smart Ticket J2ME & J2EE demo application. I used it to learn the "best practices" when I was getting started, and to a large degree I used it as a template for the first prototype that I built. So, I was quite surprised to find out that the application in question has just vanished from the internet : it was not on the Sun site, it was NOWHERE !!! It was mentioned on a couple of Sun publications, it was in Michael Yuan's excellent Enterprise J2ME book.. but the actual source to the server and j2me client has just vanished.. Evidently, it used to be a part of what the "Wireless Blueprints", which is no more, with nothing to replace it...

Well, to sum it up, I found a copy on a borland site, so I thought I'd give it a mention, just in case somebody else is scrambling to dig up this prescious resource. This just makes me wonder though, why is Sun trying to bury this demo... It was an excellent demo, with some pretty outstanding design ideas (which are a little complex, but after getting over the initial learning curve, they're sheer brilliance).. Well, that's a question that I should probably ask some of the J2ME people... it's open source now, right...

Saturday, March 24, 2007

(Mac vs PC) vs Linux

I'm laughing my head off, the Novel spoofs on the Mac/PC ads (here and here) are hillarious. As I mentioned on a previous post, the originals were quite annoying, and this really neatly hits the spot for me... Rock on, Novell !

Monday, March 19, 2007

NetBeans Groovy console

Alright, I didn't think I'd be putting it out there, but since
Geertjan blogged about it, here is the source to what I was doing with
the Groovy console in NetBeans.. I didn't think I'd be putting it
somewhere, since it's a bit of a hack (a proper solution to the
problem would probably use GroovyShell to interpret things and use
purely NetBeans for the creation of the UI end of things). But, since
it's out there in the wild, here is my "New and Improved" NetBeans groovy console.
One cool thing to note is that it picks up the Groovy Console key mappings, thus all shortcuts work exactly the same.



package com.troymaxventures.nbgroovyconsole;

import groovy.lang.Binding;
import java.awt.BorderLayout;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import javax.swing.MenuElement;
import org.openide.ErrorManager;
import org.openide.explorer.ExplorerManager;
import org.openide.explorer.ExplorerUtils;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;

/**
* Top component which displays something.
*/
final class GroovyConsoleTopComponent extends TopComponent implements
ExplorerManager.Provider, Lookup.Provider {

private static GroovyConsoleTopComponent instance;
/** path to the icon used by the component and its open action */
// static final String ICON_PATH = "SET/PATH/TO/ICON/HERE";

private static final String PREFERRED_ID = "GroovyConsoleTopComponent";
private ExplorerManager manager;
private Lookup lookup;

private GroovyConsoleTopComponent() {
initComponents();
manager = new ExplorerManager();
setName(NbBundle.getMessage(GroovyConsoleTopComponent.class,
"CTL_GroovyConsoleTopComponent"));
setToolTipText(NbBundle.getMessage(GroovyConsoleTopComponent.class,
"HINT_GroovyConsoleTopComponent"));
Binding bind = new Binding();
groovy.ui.Console console = new
groovy.ui.Console(this.getClass().getClassLoader(),bind);
bind.setProperty("console",console);
try {
console.run();
add(console.getFrame().getJMenuBar(),BorderLayout.NORTH);
add(console.getFrame().getContentPane(),BorderLayout.CENTER);
ActionMap am = this.getActionMap();
InputMap im =
this.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
setShortcutMaps(console.getFrame().getJMenuBar(),am,im);
console.getFrame().setVisible(false);
this.revalidate();
lookup = ExplorerUtils.createLookup(manager, am);
} catch (Throwable e) {
e.printStackTrace();
ErrorManager.getDefault().notify(e);
}


// setIcon(Utilities.loadImage(ICON_PATH, true));
}

private void setShortcutMaps(JMenuBar jmb, ActionMap am, InputMap im) {

for (JMenuItem me3 : getMenuItems(jmb)) {
Action a = ((JMenuItem)me3).getAction();
KeyStroke k = ((JMenuItem)me3).getAccelerator();
im.put(k,a.getValue(Action.NAME));
am.put(a.getValue(Action.NAME),a);
}

}

private List getMenuItems(MenuElement me) {
List thisLevelMenuItems = new ArrayList();
if (me!=null && me.getSubElements()!=null &&
me.getSubElements().length>0) {
for (MenuElement me1 : me.getSubElements()) {
if (me1 instanceof JMenuItem && !(me1 instanceof JMenu)) {
thisLevelMenuItems.add((JMenuItem)me1);
} else {
thisLevelMenuItems.addAll(getMenuItems(me1));
}
}
}
return thisLevelMenuItems;
}

public ExplorerManager getExplorerManager() {
return manager;
}
public Lookup getLookup() {
return lookup;
}
// ...methods as before, but replace componentActivated and
// componentDeactivated with e.g.:
public void addNotify() {
super.addNotify();
ExplorerUtils.activateActions(manager, true);
}
public void removeNotify() {
ExplorerUtils.activateActions(manager, false);
super.removeNotify();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
//
private void initComponents() {
pnlButtons = new javax.swing.JPanel();
pnlMain = new javax.swing.JPanel();

setLayout(new java.awt.BorderLayout());

}//


// Variables declaration - do not modify
private javax.swing.JPanel pnlButtons;
private javax.swing.JPanel pnlMain;
// End of variables declaration

/**
* Gets default instance. Do not use directly: reserved for
*.settings files only,
* i.e. deserialization routines; otherwise you could get a
non-deserialized instance.
* To obtain the singleton instance, use {@link findInstance}.
*/
public static synchronized GroovyConsoleTopComponent getDefault() {
if (instance == null) {
instance = new GroovyConsoleTopComponent();
}
return instance;
}

/**
* Obtain the GroovyConsoleTopComponent instance. Never call
{@link #getDefault} directly!
*/
public static synchronized GroovyConsoleTopComponent findInstance() {
TopComponent win =
WindowManager.getDefault().findTopComponent(PREFERRED_ID);
if (win == null) {
ErrorManager.getDefault().log(ErrorManager.WARNING,
"Cannot find GroovyConsole component. It will not be located properly
in the window system.");
return getDefault();
}
if (win instanceof GroovyConsoleTopComponent) {
return (GroovyConsoleTopComponent)win;
}
ErrorManager.getDefault().log(ErrorManager.WARNING, "There
seem to be multiple components with the '" + PREFERRED_ID + "' ID.
That is a potential source of errors and unexpected behavior.");
return getDefault();
}

public int getPersistenceType() {
return TopComponent.PERSISTENCE_ALWAYS;
}

public void componentOpened() {
// TODO add custom code on component opening
}

public void componentClosed() {
// TODO add custom code on component closing
}

/** replaces this in object stream */
public Object writeReplace() {
return new ResolvableHelper();
}

protected String preferredID() {
return PREFERRED_ID;
}

final static class ResolvableHelper implements Serializable {
private static final long serialVersionUID = 1L;
public Object readResolve() {
return GroovyConsoleTopComponent.getDefault();
}
}

}

Popular Posts

Related Posts with Thumbnails