
Thursday June 29, 2006
Tuscany
Posted by sandipchitale
( Jun 29 2006, 08:16:30 PM PDT ) Permalink

Tuesday June 27, 2006
TIP: Structural selection in Netbeans Java editor
Alt+Shift+S - successively selects outer syntactic element. Statement -> Surrounding Block Statements -> Surrounding Block Statements -> Surrounding Method -> Surrounding Class and so on. I use this for quick selection for indentation using Ctrl+T or commenting using Ctrl+Shift+T.
Alt+Shift+A - successively selects inner syntactic element. This works only if you had expanded the selection using the Alt+Shift+S. This helps me fine tune the selection if I went too far.
Posted by sandipchitale
( Jun 27 2006, 07:47:24 AM PDT ) Permalink

Monday June 26, 2006
TIP: Use Netbeans Debugger breakpoints for tracing
Sometimes while debugging your program, you want to simply log the value of certain expression at a certain point in your program's logic. You do not want to neccessarily look at it every time a breakpoint is hit. In fact you may not even want the program to stop at the breakpoint at all. This is possible in Netbeans Debugger by customizing the breakpoint the following way:
- set Print Text: to what ever you want to print. The text is printed in the Debug Console tab of the Output window.
- set Suspend: to No Thread (continue). This makes the program to continue running after performing the Print Text: action.
For example given the following program:
with a breakpoint at line 7 customized like this:
gives the following output:
IMPORTANT: Notice the expressions like {=i} and {=sum} in the Print Text: field. The variables i and sum are from the user program. Using the {=expression} syntax you can print the value of any expressions that are valid in the context of the breakpoint. There is bug in Netbeans online help which shows a wrong syntax for embedded expressions i.e. {$expression} (incorrect!) instead of {=expression} (correct!). Hopefully this will get corrected soon (I have already filed a bug 79051 which has been fixed already!).
Note that there are several other built-in variables - such as {className}, {methodName} that can be used in Print Text: field. Not all the built-ins are available with all types of breakoints. See the online help for details.
Posted by sandipchitale
( Jun 26 2006, 06:56:51 AM PDT ) Permalink

Sunday June 25, 2006
Suspend All Breakpoints Module uploaded
I have uploaded the Suspend All Breakpoints Module to my NetBeans update center described (here).
The Suspend All Breakpoints module installs the Suspend/Resume All Breakpoints action in Run menu and Build toolbar, that supports temporary suspension of all the Breakpoints. It differs from the Disable/Enable All Breakpoints actions in that it remembers the enabled/disabled state of breakpoints before suspension and restores it after the Resume All Breakpoints action. When all the breakpoints are suspended it shows breakpoint names in italic font and inactive text color and it shows [Supended] in the Breakpoints View title bar. The original (enabled/disabled) state of the breakpoint is shown in the tooltip. In suspend all state, a newly added breakpoint is immidiately disabled. However it will be enabled as soon as all breakpoints are resumed.
This is roughly equivalent of the Skip All action of Eclipse Breakpoints View.
How does it work ?
The Suspend All Breakpoints module stores the enabled/disbaled state of the breakpoints in a map. It listenes to the change in enabled/disabled state of the breakpoints to update the map. The mechanism used for listening is based on PropertyChangeListener. It also listens to the Breakpoint addition/removal to manage entries in the map. For this it uses an implementation of org.netbeans.api.debugger.LazyDebuggerManagerListener. This implementation is registered using the META-INF/debugger/org.netbeans.api.debugger.LazyDebuggerManagerListener registration mechanism. When Suspend All Breakpoints is selected, it disables all the breakpoints. It shows [SUSPENDED] in the Name column. It shows the saved state of the breakpoint in the tooltip. It does that by using an implementation of org.netbeans.spi.viewmodel.NodeModelFilter. This implementation is registered using the META-INF/debugger/BreakpointsView/org.netbeans.spi.viewmodel.NodeModelFilter registration mechanism. When Resume All Breakpoints is selected it restores the state of breakpoints using the value saved in the map.
Sources
DISCLAIMER: This module is experimental. So no guarantees. Use the module at your own risk.
Posted by sandipchitale
( Jun 25 2006, 11:13:39 AM PDT ) Permalink

Saturday June 24, 2006
TIP: Netbeans Java Debugger Breakpoints Groups
When I am debugging a Java program I make heavy use of breakpoints. The breakpoints fall under various categories such as:
- Line breakpoints - I use these to detect logic problems in my code
- Exception breakpoints - I use these to track down where the exceptions are thrown. The exceptions can be further classified into JDK exceptions, Applications Exceptions. The JDK exceptions can be further classified into Run Time Exceptions - NPE, CCE, CNFE, AIOOBE, Errors -
java.lang.NoClassDefFoundError
and so on...
- ...
The Netbeans debugger allows you to classify your breakpoints using a concept of Breakpoints groups. AFAIK this functionality hidden inside the popup menu of the Breakpoint entries in the Breakpoints window. To put the java.lang.NullPointerException exception breakpoint into a group named "JDK RTEs" do the following:
- Create the exception breakpoint for
java.lang.NullPointerException using Run:New Breakpoint:Breakpoint Type=Exception,Package Name=java.lang,Exception Class Name=NullPointerException
- Open the Breakpoints window using Windows:Debugging:Breakpoints
- Right click on the entry for
java.lang.NullPointerException and select Set Group Name, type JDK RTEs in the dialog and click OK.
Exceptions breakpoints allow to stop the debugee whereever the exception is thrown.
You can add other JDK RTEs such as java.lang.ClassCastException, java.lang.ArrayIndexOutOfBoundsException to the JDK RTEs group. Now you can enable and disable these breakpoints as a group by enabling and disabling the JDK RTEs group. Now you can set this group up once and enable it when you are debugging the RTEs.
I wish it was possible to set the Breakpoints Group name in the New Breakpoint dialog itself. Time to file an RFE :)
It is also possible to enable and disable all the breakpoints at once. To access this functionality you need to invoke the popup menu in Breakpoints window in the blank area (i.e. not on top of any entry). There you will find Enable All, Disable All and Delete All actions.
I wish the Enable All and Disable All state was maintained separately from the enabled and disabled state of individual breakpoint. That way I could disable the breakpoints temporarily without loosing individual breakpoints state. Time to file an RFE :)
More tips to come...
Posted by sandipchitale
( Jun 24 2006, 10:08:26 AM PDT ) Permalink

Friday June 23, 2006
Desktop Integration module uploaded
I have uploaded the Desktop Integration Module to my NetBeans update center described (here).
The Desktop Integration module was developed as a part of the NetBeansTM 5.0: Plug-in Development Hand-on Lab at JavaOne 2006 (Session ID LAB-5106). The Desktop integration module supports the following features:
- Copy full path of selected file/folder to the clipboard.
- Drag files/projects from the desktop to Netbeans IDE to open them. (Hint: Try dragging and dropping an NBM file and see what happens).
- Launch your desktop file explorer focused on the path of file/folder/project selected in the Netbeans IDE. You can tweak the command to launch the desktop file explorer using the Tools:Options:Miscelleneous:Desktop Inetgration
You can download the zip file containing the lab documents
here. Unzip the zip file and open the file netbeansplugin/index.html. It explains how the Desktop Integration module is developed. It also has lots of useful links to FAQs and APIs.
DISCLAIMER: This module is experimental. So no guarantees. Use the module at your own risk.
Posted by sandipchitale
( Jun 23 2006, 12:29:03 PM PDT ) Permalink

Wednesday June 21, 2006
Copy FQN Module uploded
I have uploaded the Copy FQN Module to my NetBeans update center described (here).
The Copy FQN action (Ctrl+J Ctrl+C) copies the fully qualified name of the Java Class
under the caret in the editor or the Java Class of selected node in the
Projects/Files windows to the OS clipboard. For example with the
following code:
JPa|nel panel;
with caret in the JPanel (shown by |), the Copy FQN action copies the fully qualified class name
javax.swing.JPanel to the clipboard.
Sources
DISCLAIMER: This module is experimental. So no guarantees. Use the module at your own risk.
Posted by sandipchitale
( Jun 21 2006, 11:14:33 PM PDT ) Permalink

Friday June 16, 2006
Flash Demo of debugger enhancements modules
Here is a Flash Demo of Local Variables View and Call Stack View Enhancements modules. Download the modules from my update center described (here).
Posted by sandipchitale
( Jun 16 2006, 06:10:15 AM PDT ) Permalink

Sunday June 11, 2006
TIP: Wrap a Swing JComponent in a background image
One technique for showing a background image on a JPanel is to override paintComponent() method. This works, but requires subclassing.
There is a composition based alternative. It makes use of a transparent JComponent in front of a JLabel
that paints the background image (Icon). The overlap of the JComponent and JLabel is achieved using GridBagLayout.
In the following code there are two factory methods to wrap a Swing component in a background image (javax.swing.Icon) :
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class BackgroundImagePanelExample {
// Set up contraints so that the user supplied component and the
// background image label overlap and resize identically
private static final GridBagConstraints gbc;
static {
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
gbc.anchor = GridBagConstraints.NORTHWEST;
}
/**
* Wraps a Swing JComponent in a background image. Simply invokes the overloded
* variant with Top/Leading alignment for background image.
*
* @param component - to wrap in the a background image
* @param backgroundIcon - the background image (Icon)
* @return the wrapping JPanel
*/
public static JPanel wrapInBackgroundImage(JComponent component,
Icon backgroundIcon) {
return wrapInBackgroundImage(
component,
backgroundIcon,
JLabel.TOP,
JLabel.LEADING);
}
/**
* Wraps a Swing JComponent in a background image. The vertical and horizontal
* alignment of background image can be specified using the alignment
* contants from JLabel.
*
* @param component - to wrap in the a background image
* @param backgroundIcon - the background image (Icon)
* @param verticalAlignment - vertical alignment. See contants in JLabel.
* @param horizontalAlignment - horizontal alignment. See contants in JLabel.
* @return the wrapping JPanel
*/
public static JPanel wrapInBackgroundImage(JComponent component,
Icon backgroundIcon,
int verticalAlignment,
int horizontalAlignment) {
// make the passed in swing component transparent
component.setOpaque(false);
// create wrapper JPanel
JPanel backgroundPanel = new JPanel(new GridBagLayout());
// add the passed in swing component first to ensure that it is in front
backgroundPanel.add(component, gbc);
// create a label to paint the background image
JLabel backgroundImage = new JLabel(backgroundIcon);
// set minimum and preferred sizes so that the size of the image
// does not affect the layout size
backgroundImage.setPreferredSize(new Dimension(1,1));
backgroundImage.setMinimumSize(new Dimension(1,1));
// align the image as specified.
backgroundImage.setVerticalAlignment(verticalAlignment);
backgroundImage.setHorizontalAlignment(horizontalAlignment);
// add the background label
backgroundPanel.add(backgroundImage, gbc);
// return the wrapper
return backgroundPanel;
}
public static void main(String[] args) {
JFrame frame = new JFrame("Background Image Panel Example");
// Create some GUI
JPanel foregroundPanel = new JPanel(new BorderLayout(10, 10));
foregroundPanel.setBorder(
BorderFactory.createEmptyBorder(10,10,10,10));
foregroundPanel.setOpaque(false);
foregroundPanel.add(new JLabel("Comment:"), BorderLayout.NORTH);
foregroundPanel.add(new JScrollPane(new JTextArea(5,30)),
BorderLayout.CENTER);
foregroundPanel.add(
new JLabel(
"Please enter your comments in text box above." +
" HTML syntax is allowed."), BorderLayout.SOUTH);
frame.setContentPane(wrapInBackgroundImage(foregroundPanel,
new ImageIcon(
BackgroundImagePanelExample.class.getResource("bg.jpg"))));
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
The above code uses the following image as the background:
Note: Make sure to place this image in the same folder as the above java class.
Running the above code shows the following GUI:
The other advantage of this technique is that it only uses property settings. Therefore this can be used in the GUI builders like Matisse from Netbeans. Here is sample Netbeans project. Here is a screenshot of panel with a background image in Matisse GUI builer:
Posted by sandipchitale
( Jun 11 2006, 09:36:29 AM PDT ) Permalink

Wednesday June 07, 2006
Check this out!
Mark Occurrences Module's Flash Demo on Netbeans.org
Watch Netbeans.org website for Flash Demos of my other modules.
Posted by sandipchitale
( Jun 07 2006, 11:16:50 PM PDT ) Permalink

Saturday June 03, 2006
New Java Type Wizards Module uploded
I have uploaded the New Java Type Wizards Module to my NetBeans update center described (here).
Features
This module add two wizards to the New File wizards:
- Custom Class Wizard
- Custom Interface Wizard
- Browse and select classes to extend
- Browse and select interfaces to extend/implement
- Generate simple implementation of abstract methods
- Generate
public static void main(String[] args){} (in a Class only)
- Generate simple Javadoc (not shown in the demo)
Flash Demo
How to use
After installing the module use the New Files/Folder:Java Classes:Custom Class and Custom Interface to create classes and interface respectively.
Initially I developed this module on NB5.5Beta. Now I have back ported it to run on NB5.0.
TODO:
- Load the classes asynchronously in Browse... dialogs.
- Custom Enum Wizard.
- Custom Annotation Wizard.
- Handle generic methods while overriding.
DISCLAIMER: This module is experimental. So no guarantees. Use the module at your own risk.
Posted by sandipchitale
( Jun 03 2006, 08:26:12 PM PDT ) Permalink
|