Ruben Laguna’s blog

NullPointerException in FontDesignMetrics$MetricsKey.init When Using Netbeans Visual Library

If you’re getting a NullPointerException stacktrace like the one below while using the Netbeans Visual Library to create your own GraphScene, check that your adding your widgets propertly to scene. A good idea is to use LayerWidgets, declaring them in the constructor of your GraphScene:

1
2
3
4

1
2
3
4
<span class='line'>mainLayer = new LayerWidget(this);
</span><span class='line'>addChild(mainLayer);
</span><span class='line'>connectionLayer = new LayerWidget(this);
</span><span class='line'>addChild(connectionLayer);</span>

and then add the widgets to those layers in attachNodeWidget and attachEdgeWidget:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<span class='line'>@Override
</span><span class='line'>    protected Widget attachNodeWidget(String node) {
</span><span class='line'>        LabelWidget w = new LabelWidget(this, node);
</span><span class='line'>        w.setBorder(BORDER4);
</span><span class='line'>        w.getActions().addAction(createSelectAction());
</span><span class='line'>        w.getActions().addAction(createObjectHoverAction());
</span><span class='line'>        w.getActions().addAction(ActionFactory.createMoveAction());
</span><span class='line'>        this.mainLayer.addChild(w);
</span><span class='line'>        return w;
</span><span class='line'>    }
</span><span class='line'>
</span><span class='line'>    @Override
</span><span class='line'>    protected Widget attachEdgeWidget(String edge) {
</span><span class='line'>        ConnectionWidget w = new ConnectionWidget(this);
</span><span class='line'>        w.setTargetAnchorShape(AnchorShape.TRIANGLE_FILLED);
</span><span class='line'>        this.connectionLayer.addChild(w);
</span><span class='line'>        return w;
</span><span class='line'>    }</span>

The stacktrace:

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<span class='line'>java.lang.NullPointerException
</span><span class='line'>at sun.font.FontDesignMetrics$MetricsKey.init(FontDesignMetrics.java:199)
</span><span class='line'>at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:267)
</span><span class='line'>at sun.java2d.SunGraphics2D.getFontMetrics(SunGraphics2D.java:973)
</span><span class='line'>at org.netbeans.api.visual.widget.LabelWidget.calculateClientArea(LabelWidget.java:260)
</span><span class='line'>at org.netbeans.api.visual.widget.Widget.calculatePreferredBounds(Widget.java:1005)
</span><span class='line'>at org.netbeans.api.visual.widget.Widget.getPreferredBounds(Widget.java:981)
</span><span class='line'>at org.netbeans.modules.visual.graph.layout.HierarchicalLayout$BuildDatastructure.run(HierarchicalLayout.java:262)
</span><span class='line'>at org.netbeans.modules.visual.graph.layout.HierarchicalLayout$AlgorithmPart.start(HierarchicalLayout.java:171)
</span><span class='line'>at org.netbeans.modules.visual.graph.layout.HierarchicalLayout.performGraphLayout(HierarchicalLayout.java:206)
</span><span class='line'>at org.netbeans.api.visual.graph.layout.GraphLayout.layoutGraph(GraphLayout.java:116)
</span><span class='line'>at org.netbeans.api.visual.layout.LayoutFactory$1.performLayout(LayoutFactory.java:284)
</span><span class='line'>at org.netbeans.api.visual.layout.SceneLayout$LayoutSceneListener.sceneValidated(SceneLayout.java:122)
</span><span class='line'>at org.netbeans.api.visual.widget.Scene.validate(Scene.java:420)
</span><span class='line'>at org.netbeans.api.visual.widget.SceneComponent.addNotify(SceneComponent.java:88)
</span><span class='line'>at java.awt.Container.addImpl(Container.java:1062)
</span><span class='line'>at java.awt.Container.add(Container.java:352)
</span><span class='line'>...
</span><span class='line'>...
</span><span class='line'>...
</span><span class='line'>at org.openide.windows.CloneableOpenSupport.openCloneableTopComponent(CloneableOpenSupport.java:197)
</span><span class='line'>at org.openide.windows.CloneableOpenSupport$1.run(CloneableOpenSupport.java:98)
</span><span class='line'>at org.openide.util.Mutex.doEvent(Mutex.java:1335)
</span><span class='line'>at org.openide.util.Mutex.writeAccess(Mutex.java:452)
</span><span class='line'>at org.openide.windows.CloneableOpenSupport.open(CloneableOpenSupport.java:95)
</span><span class='line'>at org.openide.actions.OpenAction.performAction(OpenAction.java:81)
</span><span class='line'>at org.openide.util.actions.NodeAction$DelegateAction$1.run(NodeAction.java:581)
</span><span class='line'>at org.netbeans.modules.openide.util.ActionsBridge.doPerformAction(ActionsBridge.java:77)
</span><span class='line'>at org.openide.util.actions.NodeAction$DelegateAction.actionPerformed(NodeAction.java:577)
</span><span class='line'>at org.openide.explorer.view.TreeView$PopupSupport.mouseClicked(TreeView.java:1492)
</span><span class='line'>at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253)
</span><span class='line'>at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:252)
</span><span class='line'>at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:252)
</span><span class='line'>at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:252)
</span><span class='line'>at java.awt.Component.processMouseEvent(Component.java:6129)
</span><span class='line'>at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
</span><span class='line'>at java.awt.Component.processEvent(Component.java:5891)
</span><span class='line'>at java.awt.Container.processEvent(Container.java:2102)
</span><span class='line'>at java.awt.Component.dispatchEventImpl(Component.java:4497)
</span><span class='line'>at java.awt.Container.dispatchEventImpl(Container.java:2160)
</span><span class='line'>at java.awt.Component.dispatchEvent(Component.java:4327)
</span><span class='line'>at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4366)
</span><span class='line'>at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4039)
</span><span class='line'>at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3960)
</span><span class='line'>at java.awt.Container.dispatchEventImpl(Container.java:2146)
</span><span class='line'>at java.awt.Window.dispatchEventImpl(Window.java:2440)
</span><span class='line'>at java.awt.Component.dispatchEvent(Component.java:4327)
</span><span class='line'>[catch] at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
</span><span class='line'>at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:104)
</span><span class='line'>at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:300)
</span><span class='line'>at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:210)
</span><span class='line'>at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:200)
</span><span class='line'>at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:195)
</span><span class='line'>at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:187)
</span><span class='line'>at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)</span>

Hopefully if you run into the same exception this will help you solve it.

Add Platform Sources Using Netbeans Platform Manager

To be able to do Navigate ⇒ Go to Source on netbeans classes like TopComponent you need to link the sources to the Netbeans Plaform using the Netbeans Plaform Manager as explained in Hyperlinking to NetBeans API Sources.

Be sure to download the proper source zip from the netbeans download page, otherwise the Platform Manager won’t let you attach the source file to the platform (all invalid options are greyed out/dimmed):

Opening Favorites Window at Startup in a Netbeans Platform Application

After learning about the Favorites window in the NetBeans Platform Quick Start. I wanted to use it in an application of my own.

graphbrowser3

This easy task became more difficult that I though because I was getting random results, sometimes after a clean build I got the Favorites window open and sometimes not.

But let’s start from the beginning, I put my hands at work, it was just a matter of adding the Favorites module to the Netbeans Platform Application (app’s properties ⇒ Libraries ⇒ Platform Modules ⇒ platform9 ⇒ Favorites) and edit one of my modules layer.xml to override Windows2/Modes/explorer/favorites.wstcref. Just go to Important Files ⇒ XML Layer ⇒ this layer in context ⇒ Windows2 ⇒ Modes ⇒ explore ⇒ favorites.wstcref and replace

1

1
<span class='line'>&lt;state opened="false" /></span>

with

1

1
<span class='line'>&lt;state opened="true" /></span>

So the layer.xml in the module ended like this

1
2
3
4
5
6
7
8
9
10
11

1
2
3
4
5
6
7
8
9
10
11
<span class='line'>&lt;?xml version="1.0" encoding="UTF-8"?>
</span><span class='line'>&lt;!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd">
</span><span class='line'>&lt;filesystem>
</span><span class='line'>    &lt;folder name="Windows2">
</span><span class='line'>        &lt;folder name="Modes">
</span><span class='line'>            &lt;folder name="explorer">
</span><span class='line'>                &lt;file name="favorites.wstcref" url="favoritesWstcref.xml"/>
</span><span class='line'>            &lt;/folder>
</span><span class='line'>        &lt;/folder>
</span><span class='line'>    &lt;/folder>
</span><span class='line'>&lt;/filesystem></span>

and the favoritesWstcref.xml file in my module look like this:

1
2
3
4
5
6
7
8
9
10
11

1
2
3
4
5
6
7
8
9
10
11
<span class='line'>&lt;?xml version="1.0" encoding="UTF-8"?>
</span><span class='line'>
</span><span class='line'>&lt;!DOCTYPE tc-ref PUBLIC
</span><span class='line'>          "-//NetBeans//DTD Top Component in Mode Properties 2.0//EN"
</span><span class='line'>          "http://www.netbeans.org/dtds/tc-ref2_0.dtd">
</span><span class='line'>
</span><span class='line'>&lt;tc-ref version="2.0">
</span><span class='line'>    &lt;module name="org.netbeans.modules.favorites/1" spec="1.1" />
</span><span class='line'>    &lt;tc-id id="favorites" />
</span><span class='line'>    &lt;state opened="true" />
</span><span class='line'>&lt;/tc-ref></span>

But it didn’t work as expected sometimes after doing a clean & build the favorites didn’t open at startup. So I asked in the forums and I got a tip that help me to resolve the issue. It was a module loading order problem. But how do you set the module loading order, easy, just click on your module properties ⇒ Libraries ⇒ Add Dependency ⇒ Non-API module ⇒ Favorites.

brandingmoduleproperties

Adding a dependency with the Favorites modules will ensure that Favorites is loaded before your module and thus ensuring that you layer.xml changes will override the values set by Favorites module (and not the other way around).

Sudden Voltage Drop on MAX756

I got the MAX756 that I was waiting for from Futurlec. The idea was to implement the very same circuit that comes in the MAX756 datasheet. In my first try I got very strange results which I posted to ladyada forum hoping to get some advice on how to solve. Eventually I set up the circuit in another breadboard and got it working the way I expected or at least I thought so.

MAX756

Now I have the SMPS laid out on a breadboard. I’m powering this SMPS based on MAX756 with a 1.5V battery and I get 3.3V output with no load. If I connect a load (1led+220ohm) I still got 3.3V. That’s ok. I even connected three leds in parallel (24mA). Still working, I get a sound 3.3V reading in my DMM.

But when I connect this 3.3V output to my arduino project (mounted on a breadboard too) things change, and they change in a bad way. It seems to work perfectly for 5 or 6 seconds, 3.3V the green led mounted in the Arduino Pro Mini blinks as it should (because the sketch loaded does that) and the power red led in on and shining bright. But after 5 seconds the voltage drops from 3.3V to 1.7V, the red led still on but dimmed and the green led goes off. This lasts 1 sec maybe 2, and then the voltage goes up to 3.3V again. the arduino resets and the whole process begins again.

I don’t know what happening, but I decided to give up on the SMPS for a while. I will power my design using two coin cells and the LDO regulator already mounted in the Arduino Pro Mini. Less efficient but much easier to use.

I’ll come back to the SMPS when I have more time to investigate and read more about SMPS design and troubleshooting.

References

High Speed USB in a Embedded Design

I’m looking at how to do a USRP clone. After evaluating a little bit the Altera Cyclone FPGA development/starter kits I realized that I would need an extra USB controller like the original USRP has. Right now, I’m trying to figure out how to use the Cypress FX2 CY7C68013, together with the FPGA. The USRP FAQ on FX2 CY7C68013 has proven quite helpful, also the Design of a hardware platform for narrow-band Software Defined Radio applications" by Kalen Watermeyer .

So now I think I’m going to order a Cypress FX2 CY7C68013 breakout card and read a little bit more about the FX2 – FPGA interface using the GPIF on Kalen’s thesis and reading gnu radio source code (there are some clues on the FAQ about which source files to look first).

GPIF interface

References:

Changed to Sandbox Theme Today

I think it was about time to change theme. I opted for Sandbox, I like the clean look. I was surprised on how well the change theme procedure was, just switch theme and the sidebar (with all the widgets) it’s still there.

Sandbox Theme

FPGAs, GNU Radio and Alternatives

A couple of day ago, I stumbled on GNU Radio. I was looking around electrokit online shop searching for components and I saw a Cyclone III FPGA Starter Kit for 1599 SEK (2000 SEK including taxes) and I thought : “uhmm, I could put one of this to some use” I was thinking that maybe there was a way to implement ZibBee radio using one of these FPGAs. So I started searching google about FPGAs and radio and I found GNU Radio.

GNU Radio is a really good idea. You can get a really good explanation about GNU Radio in the GNU Radio site. But the quick explanation is that you to signal processing in the PC by using something called an USRP that is a board that has an USB interface towards the PC, a FPGA and ADC, then you connect some RF frontend(s) (daughterboards) to the USRP. The RF frontend tunes the signal and puts in baseband, the ADC digitizes the signal and the FPGA runs a DDC (Digital down converter) and sends the samples to the PC via the USB controller.

USRP

If you want to know more about the USRP, I recommend reading USRP Hardware and Software description.

The only bad thing is the USRP hardware and the daughterboards are way too expensive for me (700 $USD for the USRP and 100 $USD for the TVRX daughterboards).

So I’m back at looking at the Cyclone III FPGA starter kit, it seems that there are extension boards for it (HSMC daughterboards).

HSMC

So now I’m thinking about using one of those HSMC that provides ADCs to connect an RF Tuner and do something similar as GNU Radio but on a budget.

Arduino Mega Released Today

Arduino Mega was released today. I already ordered mine from lawicel.

As stated in arduino mega page:

It has 54 digital input/output pins (of which 14 can be used as PWM outputs), 16 analog inputs, 4 UARTs (hardware serial ports), a 16 MHz crystal oscillator, a USB connection, a power jack, an ICSP header, and a reset button.

I definitely will use those additional USARTS. The lack of a second USART was the main drawback of previous Arduinos for me.

Arduino Library for MMA7260Q (Tilt Sensor)

In the past days I published a couple of arduino libraries. All coming from by XBee sensor development. I’m still waiting for the MAX756 to arrive from Futurlec, I need the MAX756 to power the xbee sensor with batteries and mount it in its final position. So in the meanwhile I’m cleaning a little bit the code, moving thing to libraries, etc. Now it’s the turn of the MMA7260Q, (see other posts about MMA7260q) .

I created an Arduino library to use MMA7260Q as a Tilt Sensor that does autozero calibration.

The library contains an example that can be accessed through the File ⇒ Sketchbook ⇒ Examples ⇒ Library-Mma7260q ⇒ SimpleTiltSensor.

SimpleTiltSensor library

The example looks like this (also available as gist):

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<span class='line'>#include "mma7260q.h"
</span><span class='line'>
</span><span class='line'>//set up MMA7260Q
</span><span class='line'>Mma7260q mma7260q = Mma7260q(0,1,2);
</span><span class='line'>
</span><span class='line'>long time = millis();
</span><span class='line'>
</span><span class='line'>void setup()  {  
</span><span class='line'>  
</span><span class='line'>  Serial.begin(9600);
</span><span class='line'>  delay(100);
</span><span class='line'>  
</span><span class='line'>  
</span><span class='line'>  //initial calibration of the MMA7260q 
</span><span class='line'>  // you can get the correct values for your MMA7260q
</span><span class='line'>  // by running this program and copying the max and min values
</span><span class='line'>  // after rotating the mma7260q 360degrees around all axis
</span><span class='line'>  mma7260q.autoZeroCalibration(173,192,258);
</span><span class='line'>  mma7260q.autoZeroCalibration(766,720,914);
</span><span class='line'>  
</span><span class='line'>  
</span><span class='line'>  Serial.print("RST\r\n");delay(100);  
</span><span class='line'>}
</span><span class='line'>
</span><span class='line'>
</span><span class='line'>void loop() 
</span><span class='line'>{
</span><span class='line'>     float rho, phi,theta;
</span><span class='line'>     mma7260q.readTilt(&rho,&phi,&theta);
</span><span class='line'>     
</span><span class='line'>     if ((millis()-time)>2000)
</span><span class='line'>     {
</span><span class='line'>       time = millis();
</span><span class='line'>       Serial.print("rho : ");
</span><span class='line'>       printFloat(rho,3);
</span><span class='line'>       Serial.print(" phi : ");
</span><span class='line'>       printFloat(phi,3);
</span><span class='line'>       Serial.print(" the: ");
</span><span class='line'>       printFloat(theta,3);
</span><span class='line'>       Serial.print("\r\n");    
</span><span class='line'> 
</span><span class='line'>       int minx,miny,minz,maxx,maxy,maxz;
</span><span class='line'>       mma7260q.getMinValues(&minx,&miny,&minz);
</span><span class='line'>       mma7260q.getMaxValues(&maxx,&maxy,&maxz);
</span><span class='line'>       Serial.print("minx: ");
</span><span class='line'>       Serial.print((int)minx,DEC);
</span><span class='line'>       Serial.print(" miny: ");
</span><span class='line'>       Serial.print((int)miny,DEC);
</span><span class='line'>       Serial.print(" minz: ");
</span><span class='line'>       Serial.print((int)minz,DEC);
</span><span class='line'>       Serial.print("\r\n");
</span><span class='line'>  
</span><span class='line'>       Serial.print("maxx: ");
</span><span class='line'>       Serial.print((int)maxx,DEC);
</span><span class='line'>       Serial.print(" maxy: ");
</span><span class='line'>       Serial.print((int)maxy,DEC);
</span><span class='line'>       Serial.print(" maxz: ");
</span><span class='line'>       Serial.print((int)maxz,DEC);
</span><span class='line'>       Serial.print("\r\n");
</span><span class='line'> 
</span><span class='line'>     }
</span><span class='line'>}
</span><span class='line'>
</span><span class='line'>void printFloat(float value, int places) {
</span><span class='line'>   // this is used to cast digits
</span><span class='line'>   int digit;
</span><span class='line'>   float tens = 0.1;
</span><span class='line'>   int tenscount = 0;
</span><span class='line'>   int i;
</span><span class='line'>   float tempfloat = value;
</span><span class='line'>
</span><span class='line'>   // if value is negative, set tempfloat to the abs value
</span><span class='line'>   // make sure we round properly. this could use pow from  
</span><span class='line'>   //&lt;math.h>, but doesn't seem worth the import
</span><span class='line'>   // if this rounding step isn't here, the value  54.321 prints as  
</span><span class='line'>   //54.3209
</span><span class='line'>
</span><span class='line'>   // calculate rounding term d:   0.5/pow(10,places)
</span><span class='line'>   float d = 0.5;
</span><span class='line'>   if (value &lt; 0)
</span><span class='line'>     d *= -1.0;
</span><span class='line'>   // divide by ten for each decimal place
</span><span class='line'>   for (i = 0; i &lt; places; i++)
</span><span class='line'>     d/= 10.0;
</span><span class='line'>   // this small addition, combined with truncation will round our  
</span><span class='line'>   // values properly
</span><span class='line'>   tempfloat +=  d;
</span><span class='line'>
</span><span class='line'>   // first get value tens to be the large power of ten less than value
</span><span class='line'>   // tenscount isn't necessary but it would be useful if you wanted  
</span><span class='line'>   // to know after this how many chars the number will take
</span><span class='line'>
</span><span class='line'>   if (value &lt; 0)
</span><span class='line'>     tempfloat *= -1.0;
</span><span class='line'>   while ((tens * 10.0) &lt;= tempfloat) {
</span><span class='line'>     tens *= 10.0;
</span><span class='line'>     tenscount += 1;
</span><span class='line'>   }
</span><span class='line'>
</span><span class='line'>
</span><span class='line'>   // write out the negative if needed
</span><span class='line'>   if (value &lt; 0)
</span><span class='line'>     Serial.print('-');
</span><span class='line'>
</span><span class='line'>   if (tenscount == 0)
</span><span class='line'>     Serial.print(0, DEC);
</span><span class='line'>
</span><span class='line'>   for (i=0; i&lt; tenscount; i++) {
</span><span class='line'>     digit = (int) (tempfloat/tens);
</span><span class='line'>     Serial.print(digit, DEC);
</span><span class='line'>     tempfloat = tempfloat - ((float)digit * tens);
</span><span class='line'>     tens /= 10.0;
</span><span class='line'>   }
</span><span class='line'>
</span><span class='line'>   // if no places after decimal, stop now and return
</span><span class='line'>   if (places &lt;= 0)
</span><span class='line'>     return;
</span><span class='line'>
</span><span class='line'>   // otherwise, write the point and continue on
</span><span class='line'>   Serial.print('.');
</span><span class='line'>
</span><span class='line'>   // now write out each decimal place by shifting digits one by one  
</span><span class='line'>   // into the ones place and writing the truncated value
</span><span class='line'>   for (i = 0; i &lt; places; i++) {
</span><span class='line'>     tempfloat *= 10.0;
</span><span class='line'>     digit = (int) tempfloat;
</span><span class='line'>     Serial.print(digit,DEC);
</span><span class='line'>     // once written, subtract off that digit
</span><span class='line'>     tempfloat = tempfloat - (float) digit;
</span><span class='line'>   }
</span><span class='line'>}</span>

References:

Copyright © 2015 - Ruben Laguna - Powered by Octopress