Sunday Dec 20, 2009

Marry Christmas, to everyone who cares

In my office, on my table...

Before the Christmass, in the NetBeans office

What it looks like: A bit bored IT guy (Petr Dvorak;o)) wants to check how fast he can complete 50-piece SnowWhite puzzle after drinking 3 litres of vodka with juice (ehm... juice with vodka)...

What it is: We will have a small private party in the end of the day with the NetBeans QE guys, everyone gets a "welcome shot", the weak ones get a juice too... Yeah, and I almost forgot I have a 3-years-old sister and I was looking for some creative present in the last minute...

Marry Christmas! :)

Friday Dec 18, 2009

A quick JFileChooser demo

Today, I noticed that many new NetBeans users have a difficulty of implementing a file chooser functionality. Usually, you just write all the code by hand, but there is also a way how to achieve several goals using the designer in the NetBeans IDE.

This tutorial should demonstrate how to leverage the NetBeans GUI Builder for implementing a custom file chooser. As a setup, we will also create a small Java desktop application.

You can download the resulting project with file chooser.

Prerequisites

Before you start, make sure you have NetBeans IDE 6.8 and JDK 1.6.

Step-by-step guide

As a first thing, we create a new Java Desktop Application:

  1. Invoke File>New Project, select Java category and choose Java Desktop Application project type
  2. Click Next, fill in some application name ("JFileChooserDemo") and make sure Basic Application is selected
  3. Click Finish

At this moment, a new Java Desktop application with three important files is created:

  • JFileChooserDemoApp
  • JFileChooserDemoView
  • JFileChooserDemoAboutBox

 Just as on this picture:


Projects view

 Double-click the JFileChooserDemoView to make sure it is opened in the designer.


Java Desktop Application - GUI Builder

Open the component palette (Ctrl+Shift+8).

Drag a new Menu Item (JMenuItem, from Swing Menus category) in the menu bar that was created by default.

Right-click this item in the designer and invoke Change Variable Name - rename the item to openFileMenuItem. Then, press Space (to start editing the text of the component that is selected in the designer) and change the text to "Open text file".

To set an action to this menu item, right click it and invoke Events>Action>Action Performed. A new method is generated, it is called for example openFileMenuItemActionPerformed - copy the name to the clipboard for a while.


Changing menu item variable name

Drag a Tool Bar (from Swing Containers category) to the designer and add one button (JButton, from Swing Controls) to the tool bar.

Change the button's text to "Open" by selecting it and pressing Space.

Rename both components' variable names again using the context menu, so that you don't have to stick with the ugly "jButton1"-like names.

Currently, you have an event handler for the "Open" menu item. To set the same event handler to the button, single-click the button and select Events tab in the Properties view. Paste the name of the method in the "actionPerformed" event and press Enter to confirm.

At this moment, the method "openFileMenuItemActionPerformed" (or similar name) is set as an event handler for both button in the toolbar and menu item.

Finally, add a JTextArea (Swing Controls) in the form (and rename the variable). The form should look like this:


Java Desktop Application - GUI Builder

So, now we have finished the basics. Let's add a JFileChooser to the form.

Open the inspector window if it is not opened (Window>Navigating>Inspector) and right-click Form JFileChooserDemoView node.

Invoke "Add From Palette>Swing Windows>File Chooser".

A JFileChooser is added in the inspector. Right-click the node and rename the variable to "fileChooser".


Add JFileChooser using the inspector view

Note: You can also drag&drop the File Chooser from the palette to the white area of the GUI Builder - it will have the same result. It is a bit harder, though, because the default preview of the JFileChooser is rather big and you might end up with the window being inserted inside some of the panels, which is not what you want.

Note: If you don't create a Java Desktop Application or if you just have a JFrame form, you can right-click the "Other components" node instead of the "Form JFileChooserDemoView" node - it will add the JFileChooser component to the JFrame (to the JFrame class) but not in its visual part...


Inspector contains Other Components node for the default JFrame forms

Now, you can click the JFileChooser in the inspector and edit some of its properties in the Properties view. For example, you can edit the title of the dialog by editing the dialogTitle property (change it to "This is open dialog").

To display the file chooser from your application, just paste this code to the openFileMenuItemActionPerformed method and press Ctrl+Shift+I to fix the imports (otherwise, there will be some errors in your code):

    int returnVal = fileChooser.showOpenDialog(this.getFrame());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fileChooser.getSelectedFile();
        // ... code that loads the contents of the file in the text area
    } else {
        // ...
    }

Let's do some minor work to add some custom filter.

Note: Users who used to work with MS Visual Studio and .NET might be familiar with a quick but ugly way of making custom filters - typing extensions and descriptions of the filter with a vertical separator in a special property, like this:

openFileDialog.Filter = "Bitmap images|\*.bmp|All files|\*.\*";

see - http://msdn.microsoft.com/en-us/magazine/cc300434.aspx#S1. Java does it in a more difficult but cleaner way...

Select the File Chooser in the Inspector window. Click the asterisk ("...") button by the File Filter property in the properties view.

Select Custom code from the combobox in the dialog that shows up and type "new MyCustomFilter()" in the text field and confirm the dialog - yes, the code will not be compilable now, we will fix it.

All we need to do is to write an inner (or outer, if you like) class that extends the FileFilter class. Just copy and paste following code in the source of your class to create an inner class.

    class MyCustomFilter extends javax.swing.filechooser.FileFilter {

        @Override
        public boolean accept(File file) {
            // Allow just directories and files with ".txt" extension...
            return file.isDirectory() || file.getAbsolutePath().endsWith(".txt");
        }

        @Override
        public String getDescription() {
            // This description will be displayed in the dialog,
            // hard-coded = ugly, should be done via I18N
            return "Text documents (\*.txt)";
        }

    }

OK, so that should be it. If there is still something unclear, do not hesitate to ask in the discussion below. If you start the sample project, the result should look something like this:


JFileChooser demo - result

If you want to have more switchable file filters, see addChoosableFileFilter method. You can indeed implement all the stuff yourself, following the tutorial on How to use File Choosers.

Sunday Nov 15, 2009

How Glassfish powers Eqyptian seafood restaurants

Me and my friend were walking in the streets of Luxor, desperately looking for something to eat in an early night. In spite of being the center of an Egyptian tourism, it is quite hard to find a clean restaurant in the city.

Suddenly, I glimpsed a seafood restaurant and - well - the picture on its board was at least quite familiar to me...

Glassfish on the board of Egyptian restaurant

I spent some time staring at the board, trying to make sure I am not mistaken... Well, in the end, we didn't eat there but still the restaurant left a great impression... :)

This just makes me wonder - do local Mexican restaurants cook from NetBeans?

Use the new Netbeans.org site the right way - from the IDE

A story of a young boy's dream...

When I was a young boy, I wanted to be a NetBeans developer. Since the age of five, I dreamt of writing my first line of the NetBeans code. (Well, when I was five, there was no NetBeans nor Java but since I am trying to advertise a bit, the story doesn't really have to make sense, right?)

I had to wait until I was 23 before the guys from the NetBeans team picked me for a tester, and half a year more before they allowed me to touch the code ("Hey, you, could you fix that typo in the message there? I am having a lunch and I don't want to touch my keyboard..."). Now, I am trying to learn how to write a code without hearing smart boys' (translate as "Jesse Glick's") remarks on what strange thing my code does - I am trying to become a good occasional NetBeans programmer...

During the wonderful time I spent in the NetBeans team so far, I learned almost all the stuff around the NetBeans community and majority of the NetBeans related processes. I learned how to submit an issue with a description that actually makes sense (hopefully, no developer reads this...) and how to work with the IDE's sources. I slowly got accustomed to the ancient idea of mailing lists and I happily observed how we introduced the forums integrated with them. I almost started to understand why we have a wiki that looks completely different from the website. I became a young but already a bit gray NetBeans wolf... Well - now, these days of beautiful complexity are gone...

Beautiful simplicity of Kenai

Since our website is now Kenai-smart (after the months of nervous devil's engineering, we managed to do that), anyone who is interested in the participation in NetBeans community can achieve in about one hour (maybe I should add "depending on the connection speed") what I achieved in more than a year and a half. Let me share with you how to submit bugs for the NetBeans IDE and how to get the NetBeans IDE sources right from the NetBeans IDE.

But first - to give you better insight - everything starts here: https://netbeans.org/api

The NetBeans.org website is actually a "smart website", defining the description of the components/projects of the NetBeans IDE using the Kenai API. One could say that this approach blurs the border between a project and its website as those two things are now tightly connected.

Since the NetBeans IDE includes the support for the Kenai API, it is not surprising you can work with the NetBeans IDE components using the NetBeans IDE itself. One of the big positives is that the NetBeans team "eats its own dog food" - we work on the infrastructure that we try to support.

Getting started - Connect with the NetBeans website

So - ready to find out about the new NetBeans infrastructure? Here is what you need to get started:

  1. Download the development version of the NetBeans IDE (this thing is implement just recently - you can try it while it's hot)
  2. Start the NetBeans IDE and open the Services view (Ctrl+5) - you should see a new node Kenai Instances
  3. Right-click the Kenai Instances node and choose Add Instance
  4. Fill in the name ("NetBeans.org"), server ("https://netbeans.org" - mind it's HTTPS) and confirm the dialog
  5. Right-click the new instance and invoke Set As Default - the NetBeans.org node get's bold
Now, you should see a new Kenai instance pointing to the NetBeans.org website and you can start exploring the Kenai projects located on this server.
Adding a Kenai instance

Understand the structure, get started...

... with sources

Before I tell you how to work with the sources and so on, I will describe how the NetBeans sources physically look. This should help you to understand some choices we made while designing Kenai projects on NetBeans.org website.

The NetBeans sources consist of many modules. Each module provides a part of the NetBeans IDE functionality. However, the modules are not very useful on their own - they make sense only with the rest of the modules (or - at least - with a relatively large subset of the modules, such as openide modules, API support modules, project or editor infrastructure modules, etc.). Therefore, there is not any direct mapping of the NetBeans functionalities (for example Ruby or Java support) to unique set of the NetBeans modules (both Java and Ruby support use editor and projects infrastructure modules, for example, and doesn't work without those).

Accordingly, if you are not a NetBeans expert (which I am still not) and if you need to get the NetBeans sources for playing with them a bit, you should get it all or nothing. Also - if you think you are a NetBeans expert and you want to get just partial sources, this will disappoint you -  as we use the Mercurial for versioning, you have no other choice: you can clone the whole repository or nothing...

Because of above mentioned points, it makes no sense to have sources under all Kenai projects on NetBeans.org (cloning the sources for project Java would clone the same repository as cloning the sources for project Ruby). Instead, all NetBeans repositories are located under a single project, called simply "IDE".

Conclusion: If you need to get the NetBeans sources, you will find them in the IDE project. No matter which specific repository you need...

So - let's do it:

  1. Make sure the Mercurial is installed on your machine - if not, install it and restart the NetBeans IDE (... sorry for the inconvenience...)
  2. Open the Kenai dashboard (Ctrl+8)
  3. Click the button for opening a new Kenai project and wait until featured projects load. You should see the IDE project right at the top - open it...
  4. A new project should show up in the Kenai dashboard (Ctrl+8) - expand it's Sources node (it can take a while)
  5. Find main-golden repository (this is the one we use for the daily builds) and click "get" link
  6. Specify a location for the clone and click Get From Kenai button - a clone should start, you can see the progress in the lower right corner or in the Output view (Ctrl+4). Clone should take some time depending on the connection speed - do not be impatient. Keep on reading this post while waiting! :)
  7. Set up your environment and build the NetBeans sources (you need to use Java5 and give some more memory to ant and javac).
  8. The most important step: develop the code + enter issues with your patches attached (you won't be able to push code changes directly into the repository).

Open the IDE project


This is how you became a NetBeans community developer...

... with issues

In contrast to how we have dealt with the sources, it makes a perfect sense to submit an issue for example for the Java support, as issues are specific for given functionality. Therefore, every Kenai project on NB.org has an issue tracker associated with it. The "IDE" project also has an issue tracker - use this one if you are not sure where to report an issue.

Try to open some other project, for example a project for the Kenai infrastructure support:

  1. Invoke the Open Kenai Project dialog again
  2. Search for "ConnectedDeveloper" (write it as a one word, note the list of all projects can be found on http://netbeans.org/projects).
  3. Expand the Issues node - it takes a bit (30s) for the very first time (then it's fast). You should see a link for finding an issue or for submitting a new report. Also, if you are a registered member of the NetBeans.org community already, you can login and see the issues you submitted (in the case, you will see a link "My Issues" too).
  4. Try searching for the issues using the "Fins issues" link, submitting issues will work for you only if you are registered on NetBeans.org website (for obvious reasons...).
Issues for NetBeans from NetBeans


OK - this was a pretty brief startup for the NetBeans community tester... Once you register on NetBeans, you can do my job from the comfort of your home;-)!

... with other features, just to keep you posted

You can review the details of any project by clicking the "Details" link in the Kenai dashboard -  this opens a view with Kenai project details. Try it for the "ConnectedDeveloper" project you just opened or for some other nice project - for example the project for Japanese speaking community members called "ja" :) - this one even has a project picture and it's own wiki...

The project details view provides a nice and comprehensive access to all Kenai project features, even to those that cannot be directly accessed via the NetBeans IDE, such as the wikis, mailing lists or downloads. This view should help you to find the good ways to keep in touch with what is going on in the particular project. But please note that project mailing lists are usually more about receiving the information (notification about the project issues or commits, for example) and you should not post to them directly. If you want to complain on how horrible the NetBeans IDE is (in any areas) or ask a question related to NetBeans, please use the public mailing lists that are all available under project WWW. List "NBUsers" is probably the right one for you (mailing lists are still integrated with forums on http://forums.netbeans.org/)...

Kenai project details page


By commenting on the mailing lists, you will give us a valuable feedback and you will become a community commentator;)...

Conclusion

While the Kenai support in the NetBeans IDE works pretty well in our opinions, we are still looking for the community feedback and for some new ideas on how to improve it. Generally speaking, you can improve the way the NetBeans+Kenai marriage works in 2 ways: by participating in the NetBeans community or by participating in the Kenai community. I think it is worth the try one of those, even if it wasn't your dream when you were five... :)


Friday Aug 14, 2009

Another step further - Kenai services on NetBeans projects

While the Kenai integration in the NetBeans IDE works pretty well overall, we are not resting on one's laurels. There are still many things that have to be done to make this marriage perfect. After we released NetBeans 6.7, a wild discussion on this matter started: "The UI is not cool enough!", "I don't like it done this way!", "It is not working together closely enough!", etc..

But this would lead us nowhere. As we are rational people at Sun, we had several very productive meetings (with several very unproductive moments) and we collected the set of use-cases for the NetBeans/Kenai integration. Subsequently, we have requested some new server API's, we started to slightly rethink the concept of the Kenai dashboard to make it more comprehensive and - the most important thing - we started to integrate Kenai services in the NetBeans stuff (and vice versa, indeed). An improvement from the last category is what I am going to show you today.

If you have a NetBeans project opened in your NB IDE, the IDE knows the remote repository information for the project. If the project is versioned and its repository is a Kenai repository, the NetBeans project has to be a part of some Kenai project. This way, we are able to determine what Kenai project the NetBeans project belongs to. When a project is already on Kenai, there is no point of having the "Share on Kenai" action on it - instead, we replaced this action with a "Kenai" submenu. Currently, you can use it to navigate to the associated Kenai project in the Kenai dashboard or to file/find a bug on the Kenai project:


Kenai actions on NetBeans project

Note: For implementation reasons, the project must be opened in the Kenai dashboard before you can file/find a bug for it (as we need to know an information that is stored on the server side - the presence of an issue tracker). If the corresponding Kenai project is not opened in the Kenai dashboard yet, only the "Open Corresponding Kenai Project..." action is available in the Kenai menu at this point...

We are also thinking about how to integrate versioning in this popup (maybe some SCM independent "Synchronise" action?) and if we should place some other Kenai services to this menu...

What do you think?

Friday Aug 07, 2009

Issue recognition in the chat window - Freshly baked!

Today, I am faster than the last time I was writing about the chat feature as I am writing about it before you can try it yourself. The changes I have made in the Kenai chat window are not in the trunk builds yet, they are pushed just a few minutes ago... But since it is Friday and I might not survive tomorrow (it's a "paintball war" day), I am going to share the new feature with you right now...

Since every chatroom is associated with a Kenai project and most of the Kenai projects have an issue tracker, it is now possible to navigate to an issue from the chat window and to send an issue reference. See the screenshot:

Issue recognition in the Kenai chat

Now just a few words about how it works (loosely copied from my closing text to issue 169037):

  • Kenai project related to the chatroom must have an issue tracker for the links to be recognized
  • Bugzilla issues are opened in the IDE
  • Jira issues are opened in the web browser
  • patterns "issue 123", "issue #123", "bug 123" and "bug #123" are recognized
  • for Jira, the form "bug JIRA_ISSUE-123" is equivalent with "bug 123" (the "JIRA_ISSUE" string representing a Jira category does not have to be included - chatroom is associated with the Kenai project)
  • for Bugzilla, if you specify an issue that is not in your project, it gets opened (problem with the fact that the
    issue numbering is global for BZ). You can see that the issue is not in your project in the issue details.
So that's about it for today - any comments and suggestions are welcome!

Thursday Jul 23, 2009

Stack-trace recognition in the Kenai chat

While I was testing the Kenai chat functionality in the NetBeans IDE, I came across a message sent by "mbien". It said:

mbien (Jul 17, 2009 in 12:32am):
"auto hyperlinking of stack traces to project sources would be a chat killer feature"

I am sure many of you folks can imagine that this feature would be pretty cool, heh? OK - so here you go:

Stack trace recognition in the Kenai chat window...

The feature is present in the development builds of 6.8 - the testing and comments are welcome, as usual!

Thursday Jul 09, 2009

How to get the userdir of your NetBeans RCP application?

Userdir is a directory where NetBeans RCP applications store settings and cache. Sometimes it can be helpful to be able to get the directory from the NetBeans RCP application itself. Most of the users initially go with something like:

String user_dir = System.getProperty("user.dir");

... and then they realize this returns a different folder from what they need. Instead, they are looking for this:

String user_dir = System.getProperty("netbeans.user");

Monday Jun 22, 2009

Student projects wanted!

The university/student projects have their own specifics. One of the most visible one is that the innovation and enthusiasm is often combined with rather weak software engineering and poor execution. I know it from my own experience. When I and my team of three students started our software project at the MatFyz (Charles University in Prague), we had to deal with a lot of issues on our own.

For example, we were looking for the right development tools and for the infrastructure for our project... As we didn't have much practical experience with this, we ended up with our own instance of wiki (MediaWiKi on a freehosting), we used our own issue tracker (really - I am serious, we wrote our own PHP application just for the purpose - yeah, we were... young...), we placed our code in the Mercurial repository located on our faculty server and we used Google Groups as an alternative to the mailing lists.

...

[Read More]

Friday Jun 19, 2009

NetBeans IDE is scanning/parsing/indexing for ages? Yeah, it's a bug!

"Scanning in progress..." - I believe that everyone have met the issue. You open some larger project and you can not use the NetBeans IDE for a few minutes until the sources are "scanned", whatever it means...[Read More]

Wednesday Jun 17, 2009

Enhancements of the NetBeans Output view

... or rather "Finally, a font size can be configured for Output view"?

Today, I was sitting in my office with Tomas Holy, a dev guy who was responsible for the Output view (the view where build output is written, for example). We were chatting for a while as we needed to relax a bit after the hard labor we do.

I suddenly recalled a very commonly heard RFE's:

"Thomas, you know what you should implement? Settings for the font size in the Output view..."

Tomas's reply was plain as usual - with his traditionally bored voice he said:

"Yeah, it is already there..."

He was right, it really showed up in NetBeans 6.7... Those are great news for many people (especially for teachers/professors who use NB IDE at their lessons).

So currently, you can right-click the output window a do quite a lot of cool stuff, such as:

  • Resize the font (Ctrl+MouseWheel works as well)
  • Change a font ("wrapping mode" must be disabled)
  • Set a filter for the output lines (so that only lines matching a regexp can be shown, for example)
The new Output view


Furthermore, Tomas told me he did some rather major enhancements regarding the search functionality (in the Output window), therefore the search should be much faster and should be more memory efficient. I bet everyone has noticed better coloring of the text output...

I hope you will be happy of this enhancement as much as I am! :)

Hudson integration in NetBeans 6.7

Are you a Java developer and did you ever need to build your sources automatically? In this case, you must have already heard about Hudson... If you have used this tool, you must also know how great it is... But there is one more cool thing now (get ready to get excited:-)). We have integrated Hudson in the NetBeans IDE 6.7.[Read More]

Tuesday Jun 16, 2009

Dialogs in NetBeans RCP, DialogDisplayer class

Friends of mine who tried to play around with the NetBeans platform usually didn't know how to correctly create a custom dialog. They tend to reason about this task in the basic "swingy" way: create a new JOptionPane, set it visible when needed and hide it when not needed anymore... But the NetBeans platform has much better and more structured way of displaying a dialog.[Read More]

Saturday May 23, 2009

NetBeans chat window tweaking... and thinking afterwards

If there is not enough time to implement a feature, the main focus is put on the functionality, not on the UI. Logical but sometimes sad reasoning. And this was exactly the case with the IM feature in the NetBeans IDE...

[Read More]

Thursday Mar 26, 2009

Build the latest NetBeans yourself

This blog post describes how to clone and build NetBeans from the Hg repository. It also contains some notes that I received from my friends who followed my original instructions.[Read More]
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