jueves, 15 de octubre de 2009

Mapping Windows Key (Super) in Ubuntu

Probably one of the functions that a Windows user is accustom to is the mapping of the Windows key + E (this opens the Explorer -not the Internet Explorer), this combination of key mapping is not enabled by default in Ubuntu (I have tested it in Ubuntu 9.04, XUbuntu 8.10 and 9.04).

So, let me show you how easy is to map the windows key + E in order to have the same behavior in Ubuntu as Windows does it.

First go to option menu System -->Preferences-->Keyboard and then choose the tab "Layouts" and then "Layout options", and go to the Alt/Win key behavior subtree, open it and click on the radio button Supper key is mapped to Win keys and then click on close (or accept) and click on the another close button.




Second, go to System --> Preferences --> Keyboard Shortcuts and look for the Desktop section and click on the Home folder row, now press at the same time the two keys Windows + E (like in Windows - plus symbol should not be pressed), once you have done it, the combination of keys (the shortcut) to open Nautilus is ready!, accept the change.



Now continue mapping the keys you are accustom to. I hope this short description is useful for you.


Best regards.




lunes, 22 de junio de 2009

Error: No JDK found on PATH, Please correct the SetJavaHome directive or add the directive

If you have seen the following error while trying to execute Oracle SQL Developer:

Error: No JDK found on PATH
Please correct the SetJavaHome directive or add the directive
in /home/barenca/bin/sqldeveloper/sqldeveloper/bin/sqldeveloper.conf or
sqldeveloper-Linux.conf
to point to the JDK installation.

You just need to indicate the J2SDK path in the file sqldeveloper/bin/sqldeveloper.conf and that's it!.

Edit the file ./sqldeveloper/bin/sqldeveloper.conf and add the path of your j2sdk installation (in Linux/unix which java and then follow the symbolic links):

SetJavaHome /usr/lib/jvm/java-6-sun

And that's it!, enjoy it.

jueves, 18 de junio de 2009

Sound Volume keys in IceWM (tested with Latitude D620)

Some days ago I took sometime and I installed Antix 8, not everything is according with the features I was waiting for, but It is OK.

One thing It was missing was the configuration for the Sound Volume keys, so this is what I did for enabling the keys on my Laptop.

Go to the Antix Control Center, click on Edit IceWM settings, click on keys tab and append the following to the file:

key "XF86AudioLowerVolume" amixer -q set Master playback 5-

key "XF86AudioRaiseVolume" amixer -q set Master playback 5+

key "XF86AudioMute" amixer sset Master toggle

Then save the file.

Now click on the statup tab and append the following lines:

xmodmap -e 'keycode 176 = XF86AudioRaiseVolume'

xmodmap -e 'keycode 174 = XF86AudioLowerVolume'

xmodmap -e 'keycode 160 = XF86AudioMute'

Then save the file.

Close the session and It's done!.

martes, 23 de diciembre de 2008

Static IP on Xubuntu 8.10 (Intrepid Ibex)

1) Remove the network manager (this will remove the applet), go to the "install and Remove applications" available in the option menu System, find the Network Manager and remove.
2) Edit /etc/network/interfaces according to your needs. In my case my ethernet card is eth0 and my static IP will be 192.168.1.253

barenca@development:~$ sudo vi /etc/network/interfaces

auto lo eth0
iface lo inet loopback

iface eth0 inet static
address 192.168.1.253
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255

gateway 192.168.1.1

3) Add your DNS in the file /etc/resolv.conf

barenca@development:~$ sudo vi /etc/resolv.conf

# Generated by NetworkManager
nameserver 200.33.146.241
nameserver 200.33.146.249

4) Restart the service

barenca@development:~$ sudo /etc/init.d/networking restart

5) Test your connection. If no connection, do not worry, just restart and that's it!.

viernes, 5 de septiembre de 2008

Netbeans Visual Library and a Multiline Label Widget

Some days ago I was trying to find a solution for a multiline label widget for the netbeans visual library, I tried some solutions (out of the box) like QLabel and others found on the web, without any success, after 2 weeks of frustrating research, I decided to continue with other features of my system, and then later on, I returned to this issue again and give it a try.

The problem:
I needed a Widget that supported Multiline label, auto-fit on resize, and drag and drop action, the first approach was to include QLabel within a ComponentWidget, It did not work for me, and then, I tried with a JTextArea in this way:


public class MultilineLabelWidget
extends ComponentWidget
{
public MultilineLabelWidget( Scene scene, String text )
{
super( scene, new JTextArea( text ) );
JTextArea jText = (JTextArea) this.getComponent();
jText.setOpaque( false );
jText.setEditable( false );
jText.setLineWrap( true );
jText.setWrapStyleWord( true );
jText.setHighlighter( null );
jText.setBorder( BorderFactory.createEmptyBorder() );

this.getActions().addAction( ActionFactory.createResizeAction() );
this.getActions().addAction( ActionFactory.createMoveAction() );
this.setBorder( org.netbeans.api.visual.border.BorderFactory.createLineBorder( 8 ) );
}
}

and It partially worked!!, the problem is that JTextArea is painted after the widget, so the MoveAction will not work! out-of-the-box, ummm, I tried another solution, not extending the ComponentWidget but creating an in-line ComponentWidget and trying to catch the Mouse Events and redirect the calls to its Action in the Widget, like this:

JTextArea jText = new JTextArea( hm );
jText.setOpaque( false );
jText.setEditable( false );
jText.setLineWrap( true );
jText.setWrapStyleWord( true );
jText.setBorder( BorderFactory.createEmptyBorder() );
final ComponentWidget widget = new ComponentWidget(scene,jText);
widget.getActions().addAction( ActionFactory.createResizeAction() );
widget.getActions().addAction( ActionFactory.createMoveAction() );
jText.addMouseMotionListener( new MouseMotionListener(){

@Override
public void mouseDragged( MouseEvent event )
{
widget.getActions().mouseDragged( widget, new WidgetAction.WidgetMouseEvent(new Date().getTime(),event) );
}

@Override
public void mouseMoved( MouseEvent event )
{
widget.getActions().mouseMoved( widget, new WidgetAction.WidgetMouseEvent(new Date().getTime(),event) );
}} );

jText.addMouseListener( new MouseListener(){

@Override
public void mouseClicked( MouseEvent event )
{
widget.getActions().mouseClicked( widget, new WidgetAction.WidgetMouseEvent(new Date().getTime(),event) );
}

@Override
public void mouseEntered( MouseEvent event )
{
widget.getActions().mouseEntered( widget, new WidgetAction.WidgetMouseEvent(new Date().getTime(),event) );
}

@Override
public void mouseExited( MouseEvent event )
{
widget.getActions().mouseExited( widget, new WidgetAction.WidgetMouseEvent(new Date().getTime(),event) );
}

@Override
public void mousePressed( MouseEvent event )
{
widget.getActions().mousePressed( widget, new WidgetAction.WidgetMouseEvent(new Date().getTime(),event) );
}

@Override
public void mouseReleased( MouseEvent event )
{
widget.getActions().mouseReleased( widget, new WidgetAction.WidgetMouseEvent(new Date().getTime(),event) );
}} );
jText.setHighlighter( null );
widget.setBorder( org.netbeans.api.visual.border.BorderFactory.createLineBorder( 8 ) );

It worked better than the previous solution!, BUT!!!!!!!!!, It just worked when I moved the mouse pointer slowly (of course, first click and then drag), but every time I moved the mouse pointer as I usually do, the component was not repainted (It did not followed the mouse pointer), and at the moment I released the left button on the mouse, the widget was painted!, frustrating for me because I think It should be easy to do it! (please developer of Visual Library, include a Multiline Label Widget Out-of-the-box).

The solution
Finally, I found a code on the net (It references to com.exalto.UI) and adapted it to fit within the Visual Library Widget, so the result It is this:

package test.designer.widget;

import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.font.LineBreakMeasurer;
import java.awt.font.TextAttribute;
import java.awt.font.TextLayout;
import java.text.AttributedCharacterIterator;
import java.text.AttributedString;

import org.netbeans.api.visual.widget.LabelWidget;
import org.netbeans.api.visual.widget.Scene;

public class MultilineLabelWidget
extends LabelWidget
{
private boolean justify;

public MultilineLabelWidget( Scene scene, String label )
{
super( scene );
this.setLabel( label );
this.setJustified( true );
}

@Override
protected void paintWidget()
{
paintOrGetSize( this.getGraphics() );
}

private void paintOrGetSize( Graphics2D gr )
{
float width = (float) ( this.getBounds() != null ? this.getBounds().getWidth() : this.getPreferredSize()
.getWidth() );
Insets insets = this.getBorder().getInsets();
float rwidth = width - ( insets.left + insets.right );// + margin.left + margin.right;
Rectangle rec = this.calculateClientArea();
gr.setFont( getFont() );

float x = 0.0F;//+ margin.left;
float y = (float) rec.getY();//+ margin.top;

if ( rwidth > 0 && this.getLabel() != null && this.getLabel().length() > 0 )
{
AttributedString as = new AttributedString( this.getLabel() );
as.addAttribute( TextAttribute.FONT, getFont() );
AttributedCharacterIterator aci = as.getIterator();
LineBreakMeasurer lbm = new LineBreakMeasurer( aci, gr.getFontRenderContext() );

while ( lbm.getPosition() < aci.getEndIndex() )
{
TextLayout textLayout = lbm.nextLayout( rwidth );
if ( gr != null && isJustified() && textLayout.getVisibleAdvance() > 0.80 * rwidth )
{
textLayout = textLayout.getJustifiedLayout( rwidth );
}
if ( gr != null )
{
textLayout.draw( gr, x, y + textLayout.getAscent() );
}
y += textLayout.getDescent() + textLayout.getLeading() + textLayout.getAscent();

}
}
}

public boolean isJustified()
{
return justify;
}

public void setJustified( boolean justify )
{
boolean old = this.justify;
this.justify = justify;
if ( old != this.justify )
{
repaint();
}
}
}

It worked for me, It worked for my purposes, I hope It works for you.
Please modify it, improve the code, see if It works for you, and feedback to me.

Thanks a lot.

References:
http://graph.netbeans.org/servlets/ReadMsg?listName=users&msgNo=1295
http://graph.netbeans.org/servlets/ReadMsg?list=users&msgNo=726
http://www.koders.com/java/fid9BE9B31AC9BED01828448BF91A61AFA5AE431E16.aspx

miércoles, 3 de septiembre de 2008

Fast delete of files or directories in Linux using find

Let's suppose you have an structure like this:


mx.com.CVS
mx.com.dtc.ayde
mx.com.dtc.ayde.applet
mx.com.dtc.ayde.applet.CVS
mx.com.dtc.ayde.busquedas
mx.com.dtc.ayde.busquedas.CVS
mx.com.dtc.ayde.client


and you want to delete those directories with the name CVS, so, go to the root
directory of those you want to delete (in this case
/ ), and execute the following:


find . -type d -name CVS -exec rm -rf {} . \;

or

find . -type f -name *.db -exec cp {} . \;

for files that end with extension
db

the
. and \; are very important!


Regards,

Barenca

jueves, 14 de agosto de 2008

Remote time synchronization using NTP on CentOS

If you want to know how to configure the Network Time Protocol service on CentOS, here you have:


# chkconfig ntpd on

# ntpdate pool.ntp.org

# /etc/init.d/ntpd start



If you have not installed ntp, then before the previous lines install it with:

# yum install ntp


Best regards,