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!.
martes, 23 de diciembre de 2008
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
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,
# 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,
lunes, 7 de abril de 2008
Simple solution for the ORA-01157 and ORA-01110 Errors
Did you erase a datafile?, do you still need that datafile?, if the answer for the last question was yes, this is not the solution for you!, otherwise, continue...
SQL>startup mount;
SQL>alter database datafile '/AS10g/oradata/asdb/users02.dbf' offline drop;
SQL>alter database open;
SQL>shutdown immediate;
SQL>startup;
and then, you will see something like this:
Total System Global Area 1048576000 bytes
Fixed Size 782524 bytes
Variable Size 892342084 bytes
Database Buffers 155189248 bytes
Redo Buffers 262144 bytes
It is done!
In my case, I did not need that datafile anymore, so my problem was solved just following the above solution.
Regards,
Héctor Suárez Barenca
SQL>startup mount;
SQL>alter database datafile '/AS10g/oradata/asdb/users02.dbf' offline drop;
SQL>alter database open;
SQL>shutdown immediate;
SQL>startup;
and then, you will see something like this:
Total System Global Area 1048576000 bytes
Fixed Size 782524 bytes
Variable Size 892342084 bytes
Database Buffers 155189248 bytes
Redo Buffers 262144 bytes
It is done!
In my case, I did not need that datafile anymore, so my problem was solved just following the above solution.
Regards,
Héctor Suárez Barenca
miércoles, 5 de marzo de 2008
Maximum subarray (java implementation)
You're given an array containing both positive and negative integers and required to find the subarray with the maximum sum.
This is an interesting problem, I read that the solution was given in 1977 in less than a minute, so I took the original algorithm for the article and I implemented with Java, enjoy it!
public static void main(String[] args)
{
int[] offset = new int[2];
int[] x = { 31, -41, 59, 26, -53, 58, 97, -93, -23, 18 };
int n = x.length;
int maxsofar = 0;
for (int i = 0; i < n; i++)
for (int j = i; j < n; j++)
{
int sum = 0;
for (int k = i; k <= j; k++)
sum += x[k];
/* sum is sum of x[i..j] */
if (sum > maxsofar)
{
offset[0] = i;
offset[1] = j;
maxsofar = sum;
}
}
System.out.println("Subarray [" + offset[0] + "..." + offset[1]
+ "] = " + maxsofar);
}
This is an interesting problem, I read that the solution was given in 1977 in less than a minute, so I took the original algorithm for the article and I implemented with Java, enjoy it!
public static void main(String[] args)
{
int[] offset = new int[2];
int[] x = { 31, -41, 59, 26, -53, 58, 97, -93, -23, 18 };
int n = x.length;
int maxsofar = 0;
for (int i = 0; i < n; i++)
for (int j = i; j < n; j++)
{
int sum = 0;
for (int k = i; k <= j; k++)
sum += x[k];
/* sum is sum of x[i..j] */
if (sum > maxsofar)
{
offset[0] = i;
offset[1] = j;
maxsofar = sum;
}
}
System.out.println("Subarray [" + offset[0] + "..." + offset[1]
+ "] = " + maxsofar);
}
Suscribirse a:
Entradas (Atom)