Friday May 30, 2008

Readonly Editors Mode Module

I just uploaded the Readonly Editors Mode module to the NetBeans Plugin Portal.

This module controls the editable property of the text editors. The initial state of the editable property of text editor is controlled by the Tools:Options:Miscellaneous:Read Only Editors Mode:Open editors in read-only mode option. The user can toggle the read-only mode using the editor toolbar action (button with open/closed lock icon). The default key binding for the toggle action is CTRL+R.

Screenshots:

Options:

options

Toggle Readonly mode button on editor toolbar:

editor toolbar

The sources can be found in main/contrib repository.

DISCLAIMER: This module is experimental. So no guarantees. Use the module at your own risk.

Friday May 23, 2008

Trunk NetBeans cluster dependency graph generated using dot

Here is a cluster dependency graph for the NetBeans trunk (post-6.1 aka 6.5) build. The graph was generated using the dot program from graphviz package on my Ubuntu laptop.
 

dependencies

To produce the necessary input file for the dot program I hacked the following method:

    private void generateGroupDependencies (File output, boolean implementationOnly) throws BuildException, IOException {
PrintWriter w = new PrintWriter (new FileWriter (output));

Map<Dependency,Set<ModuleInfo>> referrers = new HashMap<Dependency,Set<ModuleInfo>>();

TreeMap<String, Set<Dependency>> groups = new TreeMap<String, Set<Dependency>>();
for (ModuleInfo m : modules) {
if (regexp != null && !regexp.matcher(m.group).matches()) {
continue;
}
Set<Dependency> l = groups.get(m.group);
if (l == null) {
l = new TreeSet<Dependency>();
groups.put(m.group, l);
}
l.addAll(m.depends);
for (Dependency d : m.depends) {
Set<ModuleInfo> r = referrers.get(d);
if (r == null) {
r = new HashSet<ModuleInfo>();
referrers.put(d, r);
}
r.add(m);
}
}

w.println("digraph G {");
w.println(" ratio=auto;");
w.println(" concentrate=true;");
w.println(" node[shape=box,tailport=s];");
for (Map.Entry<String,Set<Dependency>> e : groups.entrySet()) {
String groupName = e.getKey();
Set<Dependency> depends = e.getValue();
Set<String> seenGroup = new HashSet<String>();
boolean first = true;
for (Dependency d : depends) {
String print = " REQUIRES ";
if (d.exact && d.compare != null) {
// ok, impl deps
} else {
if (implementationOnly) {
continue;
}
}

// special dependencies are ignored
if (d.isSpecial ()) {
continue;
}
// dependencies within one group are not important
Set<ModuleInfo> r = referrers.get(d);
ModuleInfo ref = findModuleInfo(d, r.size() == 1 ? r.iterator().next() : null);
if (groupName.equals (ref.group)) {
continue;
}
// Have we seen this group already - group == cluster
if(seenGroup.contains(ref.group)) {
// skip
continue;
}
seenGroup.add(ref.group);

w.print (" ");
w.print (groupName);
w.print (" -> ");
w.print (ref.group);
w.print (";");
w.println ();
}
}
w.println("}");
w.close ();
}

in nbbuild/antsrc/org/netbeans/nbbuild/ModuleDependencies.java file. Then I built and ran the ant task like this:

>  cd nbbuild
>  ant bootstrap generate-golden-files

to generate the dependency files in nbbuild/build/generated. This produced the following contents: 

digraph G {
ratio=auto;
concentrate=true;
node[shape=box,tailport=s];
apisupport -> ide;
apisupport -> java;
apisupport -> platform;
apisupport -> harness;
cnd -> platform;
cnd -> ide;
gsf -> platform;
gsf -> ide;
harness -> platform;
ide -> platform;
identity -> java;
identity -> platform;
identity -> j2ee;
identity -> ide;
j2ee -> java;
j2ee -> ide;
j2ee -> platform;
j2ee -> gsf;
java -> platform;
java -> ide;
mobility -> java;
mobility -> platform;
mobility -> ide;
mobility -> j2ee;
nb -> platform;
nb -> ide;
profiler -> java;
profiler -> platform;
profiler -> ide;
profiler -> j2ee;
ruby -> platform;
ruby -> ide;
ruby -> gsf;
soa -> java;
soa -> ide;
soa -> platform;
soa -> j2ee;
soa -> xml;
uml -> platform;
uml -> java;
uml -> ide;
visualweb -> java;
visualweb -> platform;
visualweb -> j2ee;
visualweb -> ide;
visualweb -> nb;
xml -> platform;
xml -> ide;
}

in nbbuild/build/generated/cluster-deps.txt and then I ran the following command on the file:

>  cd build/generated
>  dot -Tpng cluster-deps.txt -o cluster-deps.png

and we have the graph in cluster-deps.png file.

Similar technique could be applied to generate dependency graphs for modules dependencies etc. I will look into making it part of the build which could be invoked on demand to produce the dependency graphs.

Thursday May 08, 2008

NetBeans 6.1 and trunk compatible Code Template Tools NBMs

NetBeans 6.1 is out!

I have updated the Code Template Tools module to work with NetBeans 6.1 FCS and trunk. Here are the NBMs"

NetBeans 6.1 FCS compatible Code Templates Tools NBM

post 6.1 main compatible Code Templates Tools NBM

I need to figure out how to publish multiple NBMs on Plugin Portal. In the mean time you will have to use these.
 

Saturday Apr 26, 2008

YouTube Viewer add-on project

 

In this blog entry I talked about the YouTube Viewer add-on for Firefox. In the last blog I talked about how to use a freeform Web NetBeans 6.1 Project to build the iPhone mode add-on for Firefox. Download a similar freeform Web NetBeans 6.1 Project for YouTube Viewer.

YTV 

Using NetBeans 6.1 freeform project to build iPhone mode add-on for Firefox project.

 

In the last entry I talked about an iPhone mode add-on for Firefox. I used a free form Web Project of NetBeans 6.1 IDE to build the iPhone mode add-on. The NetBeans 6.1 IDE has a great JavaScript editor. That was a big plus. Here is a visual tour of the Web Project setup.

The Build Script

<?xml version="1.0" encoding="UTF-8"?>
<project name="iPhoneEmulator" default="all" basedir=".">
<description>iPhone Emulator for Firefox.</description>
<property name="build.dir" value="build"/>
<!-- build iphone -->
<target name="-create-iphone-jar">
<echo message="Build iphone.jar"/>
<mkdir dir="${build.dir}"/>
<zip destfile="${build.dir}/iphone.jar">
<zipfileset dir="." includes="content/\*\*" />
<zipfileset dir="." includes="locale/\*\*" />
<zipfileset dir="." includes="skin/\*\*" />
</zip>
</target>
<target name="-gen-manifest">
<echo message="Configuring chrome-manifest"/>
<mkdir dir="${build.dir}"/>
<copy file="chrome.manifest" tofile="${build.dir}/chrome.manifest" overwrite="true"/>
<replaceregexp file="${build.dir}/chrome.manifest"
match="\^(content\\s+\\S\*\\s+)(\\S\*/)$"
replace="\\1jar:chrome/iphone.jar!/\\2"
flags="g" byline="true"/>
<replaceregexp file="${build.dir}/chrome.manifest"
match="\^(skin|locale)(\\s+\\S\*\\s+\\S\*\\s+)(.\*/)$"
replace="\\1\\2jar:chrome/iphone.jar!/\\3"
flags="g" byline="true"/>
</target>
<target name="-create-iphone-xpi" depends="-create-iphone-jar,-gen-manifest">
<echo message="Build iphone.xpi"/>
<mkdir dir="${build.dir}"/>
<zip destfile="${build.dir}/iphone.xpi">
<zipfileset dir="${build.dir}" includes="iphone.jar" prefix="chrome" />
<zipfileset dir="${build.dir}" includes="chrome.manifest" />
<zipfileset dir="." includes="install.rdf" />
</zip>
</target>
<target name="all" depends="-create-iphone-xpi"/>

<target name="run" depends="clean,all">
<exec executable="firefox" osfamily="unix">
<arg file="${build.dir}/iphone.xpi"/>
</exec>
<exec executable="/usr/bin/open" osfamily="mac">
<arg value="-b"/>
<arg value="org.mozilla.firefox"/>
<arg file="${build.dir}/iphone.xpi"/>
</exec>
<exec executable="C:/Program Files/Mozilla Firefox/firefox.exe" osfamily="windows">
<arg file="${build.dir}/iphone.xpi"/>
</exec>
</target>

<target name="-clean-iphone">
<echo message="Clean iphone"/>
<delete file="${build.dir}/iphone.jar" failonerror="false"/>
<delete file="${build.dir}/chrome.manifest" failonerror="false"/>
<delete file="${build.dir}/iphone.xpi" failonerror="false"/>
</target>
<target name="clean" depends="-clean-iphone"/>
</project>

Here is the rest:

_

_

 

Projects and Files window showing the layout: 

 

__

 

The NetBeans IDE is slowly starting to take shape as a premium AJAX, Web 2.0 and Mobile development IDE. 

 

Saturday Apr 12, 2008

TIP: Displaying rich messages using JOptionPane and JEditorPane

In this and this blog entry I discussed technics to show images and multiline text in tooltips. The same technics can be applied to show rich messages using JEditorPane. Here is an example:

import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Window;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JEditorPane;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

public class NetBeansDay2008 {
public static void main(String[] args) {
// Turn anti-aliasing on
System.setProperty("awt.useSystemAAFontSettings", "on");
final JEditorPane editorPane = new JEditorPane();

// Enable use of custom set fonts
editorPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
editorPane.setFont(new Font("Arial", Font.BOLD, 13));

editorPane.setPreferredSize(new Dimension(520,180));
editorPane.setEditable(false);
editorPane.setContentType("text/html");
editorPane.setText(
"<html>"
+ "<body>"
+ "<table border='0px' cxellpadding='10px' height='100%'>"
+ "<tr>"
+ "<td valign='center'>"
+ "<img src='"
+ "http://www.netbeans.org/images/javaone/2008/nbday08_logo.gif"
// Alternatively an image stored next to the NetBeansDay2008
// class can be used like this.
//+ NetBeansDay2008.class.getResource("nbday08_logo.gif").toExternalForm()
+ "'>"
+ "</td>"
+ "<td>"
+ "<a href='http://www.netbeans.org/community/articles/javaone/2008/nb-day.html'><b>NetBeans Day</b></a><br>"
+ "San Francisco May 5th, 2008<br>"
+ "<br>"
+ "NetBeans - The only IDE you need!<br>"
+ "</td>"
+ "</tr>"
+ "</table>"
+ "</body>"
+ "</html>"
);

// TIP: Make the JOptionPane resizable using the HierarchyListener
editorPane.addHierarchyListener(new HierarchyListener() {
public void hierarchyChanged(HierarchyEvent e) {
Window window = SwingUtilities.getWindowAncestor(editorPane);
if (window instanceof Dialog) {
Dialog dialog = (Dialog)window;
if (!dialog.isResizable()) {
dialog.setResizable(true);
}
}
}
});

// TIP: Add Hyperlink listener to process hyperlinks
editorPane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(final HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) {
EventQueue.invokeLater(new Runnable() {
public void run() {
// TIP: Show hand cursor
SwingUtilities.getWindowAncestor(editorPane).setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
// TIP: Show URL as the tooltip
editorPane.setToolTipText(e.getURL().toExternalForm());
}
});
} else if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
EventQueue.invokeLater(new Runnable() {
public void run() {
// Show default cursor
SwingUtilities.getWindowAncestor(editorPane).setCursor(Cursor.getDefaultCursor());

// Reset tooltip
editorPane.setToolTipText(null);
}
});
} else if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
// TIP: Starting with JDK6 you can show the URL in desktop browser
if (Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(e.getURL().toURI());
} catch (Exception ex) {
Logger.getLogger(NetBeansDay2008.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
}
}
//System.out.println("Go to URL: " + e.getURL());
}
}
});
JOptionPane.showMessageDialog(null,
new JScrollPane(editorPane),
"NetBeans Day 2008",
JOptionPane.PLAIN_MESSAGE);
}
}

Based on a tip from a reader I have added the code to turn on anti-aliasing and use of custom set fonts in JEditorPane. This shows the following visually pleasing dialog:

NetBeans Day 2008, San Francisco May 5th 2008

See you there!

Wednesday Mar 12, 2008

Remove unused binding attribute from VisualWeb JSF pages

Prior to NetBeans IDE 6.0 release VisualWeb Pages use to generate a binding attribute in the tag for every component in the page.

For example, when a Grid Panel was dropped on Page1, the following tag was automatically generated in the Page1.jsp file:

<h:panelGrid binding="#{Page1.gridPanel1}" id="gridPanel1" style="height: 96px; left: 24px; top: 24px; position: absolute; width: 96px"/>

and the following field, getter and setter was generated in the Page1.java file:

    private HtmlPanelGrid gridPanel1 = new HtmlPanelGrid();

    public HtmlPanelGrid getGridPanel1() {
        return gridPanel1;
    }

    public void setGridPanel1(HtmlPanelGrid hpg) {
        this.gridPanel1 = hpg;
    }

This was good if you wanted to access the gridPane1 component programmatically. Otherwise it only served to bloat the .jsp and .java files. Therefore starting with NetBeans IDE 6.1 (M1+) release we decided to not generate the binding attribute automatically. Instead you can add and remove the binding attribute (and the corresponding field, getter and setter) by invoking the action in the component's pop up menu. For details, see the mini spec - On-demand binding attribute .

All this is well and good for projects developed using the NetBeans 6.1 (M1+) IDE and later. However the projects developed prior to NetBeanse 6.1 (M1+) IDE, do not benefit from this feature. That is where the new module - Remove unused binding attributes from VisualWeb JSF Pages comes for the rescue. This module installs the action - Remove unused binding attributes in the VisualWeb JSF Pages' in the projects pop up menu. When the action is invoked it shows a confirmation dialog:

Confirm Removing Binding Attributes Dialog 

Once you confirms the action, the unused binding attributes (and the corresponding field, getter and setter in the backing page bean) are removed from all the VisualWeb JSF pages in the VisualWeb project. The output window shows the processing messages. For example:

Removing unused binding attributes for components in the VisualWeb JSF Pages in the Project '/..../NetBeansProjects/WebApplication1'...
Modeling...
Modeling...Done
Processing '.../NetBeansProjects/WebApplication15/web/Page1.jsp'
:
:
:
Removed unused binding attribute for the component 'gridPanel1'.
:
:
:
Processing '.../NetBeansProjects/WebApplication15/web/Page1.jsp' Done

Processing '.../NetBeansProjects/WebApplication15/web/Page2.jsp'
:
:
Processing '.../NetBeansProjects/WebApplication15/web/Page2.jsp' Done
Processing '.../NetBeansProjects/WebApplication15/web/Page3.jsp'
:
:
Processing '.../NetBeansProjects/WebApplication15/web/Page3.jsp' Done
Removing unused binding attributes for components in the VisualWeb JSF Pages in the Project '/.../NetBeansProjects/WebApplication1'...Done

The process may take some time depending on the number of VisualWeb JSF pages in your project.

Please make sure you have backed up your project before you invoke the action. For best results invoke the action as soon as you open the project. Aftre you have processed all you projects you can remove the module by using Tools:Plugin action.

The module is available on the NetBeans 6.1 Beta Update center:

http://updates.netbeans.org/netbeans/updates/6.1/uc/beta/beta/catalog.xml.gz

You can configure the update center in the Tools:Plugins:Setting tab. NetBeans 6.1 Beta IDE is required to use this module.

Please send us your feedback here.

After processing, your project will become lean and mean, VisualWeb machine :)

Tuesday Dec 25, 2007

Reorder module on NetBeans Plugin POrtal


I have uploded the Reorder module to the NetBeans Plugin Portal.

The assymetry in the way ,  (comma)  is used to separate the items in parameter and arguments lists always causes problem when one wants to reorder that list in Java editor.  Is that why Java allows trailing commas in array initializer? ;) may be. This module supports single click swapping of a parameter, argument or array initializer expressions with pervious or next item in the list. Each item of the sequence can be a simple literal, an identifier or a more complex function call expression. The comma delimiter is correctly handled.

For example with caret at | in:

void method(int iii, String |sss, boolean bbb){}
pressing CTRL+ALT+. (i.e. period) or invoking Source:Swap Next action yields:
void method(int iii, boolean bbb, String |sss){}
or pressing CTRL+ALT+, (i.e. comma)
or invoking Source:Swap Previous action with the original source yields:
void method(String |sss, int iii, boolean bbb){}

Sources

DISCLAIMER: This module is experimental. So no guarantees. Use the module at your own risk.

Friday Dec 21, 2007

NetBeans 6.0 FCS compatible Code Templates Tools on NetBeans Plugin Portal

Only yesterday I discovered that the Code Template Tools module was not working with NetBeans 6.0 FCS. I have fixed the issue and uploaded the module on NetBean Plugin Portal. The older, NetBeans 5.x compatible module can be downloaded from here.

UPDATE: I have improved the Surround With... Action (Ctrl+J T) for interactive use. Now it shows a pop up dialog with a list of templates. You can select a template and type ENTER or double click to insert the template in the editor. If the editor has some selected text then the templates using the ${selection} parameter are shown at the top of the template list. You can just type the template prefix to select a matching template quickly.
 

Tuesday Dec 04, 2007

ScreenMetrics tool

Here is a simple (whacky) desktop utility to measure distances on your screen:

Screen Metric

You can drag the thin vertical and horizontal lines, horizontally and vertically respectively to measure distance between them which is displayed in the toolbar like gadgets. The format is max marker location - min marker location = distance. The location and distance values are continuously updated as you drag the lines. You can use the spinner controls to increment or decrement the location of minimum or maximum markers. You can directly type the location value also.You can move the toolbar gadgets around by dragging on the left or right edge of the toolbars.

This is not a NetBeans Module. It is a Desktop utility. It was built using NetBeans of course :)

To run:

Download ScreenMetrics.jar and type:

> java -jar ScreenMetrics.jar

Hacking: 

ScreenMetrics.zip contains the NetBeans project.

TODO:

  • Show the distance value in other units e.g. inches, cms, picas?, em?
  • Show the area
  • Handle multiple monitor scenarios correctly
  • ability to show and hide
  • Precise control on moving using spinners - Done

DISCLAIMER: This module is tool. So no guarantees. Use the module at your own risk.

Monday Dec 03, 2007

Add Property module functionality in trunk

With this check in the Add Property module's functionality is available in trunk. Thanks to Jan Lahoda. The functionality is available through the Add Property popup menu in the Generate Code (Alt+Insert) popup menu in Java Editor.
 

Thursday Nov 29, 2007

Which Tree module on NetBeans Plugin Portal

I have uploaded the WhichTree module to the NetBeans Plugin Portal.

This module shows information about the Javac Tree Path at the caret position in current Java editor in a read-only text field in the status bar. The information is updated as the caret moves. The text field can be hidden and shown using the button on it's left. The tool tip shows the full text so that it can be seen when it is wider than 40 columns.

Which Tree

 

Double clicking on the text field shows a dialog which shows the Tree Path in a tree. The source for the selected Tree is shown in a text area. This is a good tool to understand how the Javac sees the Java source. The IDs shown in the tree are the TreeKind enumeration values.

 

Tree Path details

 

This is along the lines of WhichElement module I blogged about a few months ago. 

 

Sources (on branch release60)

DISCLAIMER: This module is experimental. So no guarantees. Use the module at your own risk.

Friday Nov 23, 2007

Tip: api to show Java type chooser dialog in NetBeans 6.0

While implementing the Add Property module, Jan Lahoda pointed out an api available in NetBeans 6.0 Java support which can show a Java Type chooser dialog. Here is the snippet of code to show the dialog:

        FileObject fileObject = ...; // Some java file's file object in a NetBeans Project.

ElementHandle<TypeElement> type = TypeElementFinder.find(ClasspathInfo.create(fileObject), null);

if (type != null) {
// use the type somehow

which shows the dialog:

Find Type dialog

You can use this api in your module any time you want to select a Java type. You will have to add the following dependencies to your module:

  • Java Source
  • Java Source UI
  • Java Support APIs
  • Javac API Wrapper

The TypeElementFinder api is implemented in Java Source UI module. You can further customize the dialog by passing the second argument to the find() method.

For some reason this does not appear in the NetBeans 6.0 API docs - probably because this is not an official API yet.

Wednesday Nov 21, 2007

JPDA (Java) Debugger Threads View Enhancements module on NetBeans Plugin Portal

I have uploaded the JPDA (Java) Debugger Threads View Enhancements module module to the NetBeans Plugin Portal.

Enhanced Threads View

 
This module unifies Threads and Call stack view (somewhat like Eclipse Java Debugger Threads View). The call stack frames are shown as the children of suspended thread in the Threads view. It supports same actions on as Call Stack view and more. For example, it shows actions to jump to types of local variable of a Call stackframe as well as the Show Classes action. It also shows full method signature of the Call stack frame. It additionally shows the actual class of the 'this' variable if it differs from the class that declares the method of the call stack frames.

The Show Classes action shows all the classes loaded in the JVM along with the loading and initiating ClassLoaders. This is useful for debugging class loading in multi-ClassLoder appications such as NetBeans itself.

Classes view

Sources

DISCLAIMER: This module is experimental. So no guarantees. Use the module at your own risk.

Thursday Nov 15, 2007

Highlight Boxing Unboxing Varargs module on NetBeans Plugin Portal

I have uploaded the Highlight Boxing Unboxing Varargs module to the NetBeans Plugin Portal. It enables highlighting of occurences of boxing, unboxing and varargs in the Java editor. Obviously this only works for files belonging to projects with source level set to 1.5+.

UPDATE: The download link on the Plugin Portal has now been fixed.

The Java compiler silently applies the boxing and unboxing to the primitive types and the corresponding reference types as needed. This module reveals where that may be happening in your code. This module may help you diagnose mysterious NPEs when a reference type null value is attempted to be unboxed at runtime (well the example in the screen shot is not the best ;) ). To turn the highlighting on or off use the toggle buttons on the toolbar. Here is a screen shot:

NetBeans Java Editor showing highlighted boxing, unboxing and varargs occurences

Jan Lahoda contributed to this module.

Sources

DISCLAIMER: This module is experimental. So no guarantees. Use the module at your own risk.

About

sandipchitale

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today