Skip to main content


Showing posts from 2014

Old Java Swing style fadeIn / fadeOut on image

As my open source project (Violet UML Editor) has a GUI developed in Swing (wich is not a problem because I massively use the Graphics2D canvas which should be portable to other tehnologies), I sometimes have to find tricks to enhance UX. That was my last challenge. I decided to implement fade effects on image. After googlings, I didn't find anything ready to use. So, I developed a quick and simple piece of code I share with you. The idea is to embed my image as an ImageIcon attached to a JLabel. Then, to trigger fade effects, I just use a mouse listener.

import java.awt.AlphaComposite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.Timer;

public class FadeImage extends JLabel implements ActionListener {

    // Up to 1f
    private float opacity = 0f;
    private Timer fadeTimer;
    private int fadeIndicator = 1;

    public FadeImage(ImageI…

José Paumard & Rémi Forax : two Java french stars interviewed on Java 8

Rémi is one of my favorite Java superstars.
If you understand french, you should see this :
First partSecond partThird part

DCcduino usb drivers (CH340 / CH341 chipset)

I've just received my first arduino platform. It's a DCcduino board (a clone of Arduino Uno). As I had some difficulties to have it recognised by my MacBook, I decided to share its drivers. This card has a CH340 USB-to-serial chip. You can find drivers for this chip on the web site of the chinese manufacturer, here :

Or download it directly from my Google Drive. The archive contains drivers for Mac, Linux and Windows platforms.

I hope this will help somebody.

UPDATE for Mac users with Yosemite :

Please, follow this extra instructions :
Install the CH340 driverRun the command in Terminal: sudo nvram boot-args="kext-dev-mode=1"Reboot

Find Oracle apparent deallocks

Your application is blocked? Perhaps it is due to deadlock on database objects. So, if you have an Oracke DB Server, you can verify this with these few requests I found on the web :

List blocked sessions  :  select sid, serial#, username, command, lockwait, osuser from v$session where lockwait is not nullFind SQL requests concerned : select sql_text from v$sqltext where (address,hash_value) in (select sql_address,sql_hash_value from v$session where lockwait is not null) order by address, hash_value, pieceKill concerned session (you need to have dba priviledges) : alter system kill session 'sid, serial#';

How to synchronized two folders with a Python script

That's what I wanted to do. So, I wrote my first Python (3) script. Don't hesitate to use or modified this code. It can synchronized two folders in two-way directions. It never deletes files or folders in its strategy. It only replicates older or missing files and folders from the two folders to synchronized.


PS : Be cool with me, this is my first steps with Python

__author__ = 'Alexandre de Pellegrin'
import os
import shutil

srcDir = '/home/user/folder1'
dstDir = '/home/user/folder2'

def main():
        print("Begin sync")
        checkIfRootDirsExist(srcDir, dstDir)
        syncDirs(srcDir, dstDir)
        syncFiles(srcDir, dstDir)
        print("End sync with success")
    except Exception as e:
        print("End sync with failure!")

def checkIfRootDirsExist(rootDir1, rootDir2) :
    if (not os.path.exists(rootDir1) and not os.path.isdir(rootDir1)) :
        raise Exception(rootDir1 + " doesn't e…

Automatic date stamping of Hibernate entities

That's what I was looking for today and I found it on Stackoverflow. You can do that with three elegant JPA annotations :

@PrePersist : automatically invoke the annoted method before persist the new entity@PreUpdate : automatically invoke the annoted method before update the existing entity@Temporal : very important to set the temporal type to timestamp. Otherwise, Hibernate could store date without hours, minutes and seconds (only day, month and year)
Enjoy Hibernate and JPA!!! (On small projects, this is always a pleasure. On large one, things are always different...)

Here is the example I found : 
import java.util.Date;import javax.persistence.Column;import javax.persistence.MappedSuperclass;import javax.persistence.PrePersist;import javax.persistence.PreUpdate;import javax.persistence.Temporal;import javax.persistence.TemporalType;@MappedSuperclasspublicabstractclassAbstractTimestampEntity{@Temporal(TemporalType.TIMESTAMP)@Column(name ="created", nullable =false)privat…

Start a java program from another java program programmatically

That's the thing I had to perform today. Let's introduce the need : I developed last year a standalone java program that I can start from command line. Now, I want to start it from a web application. As the program is complex (some Spring Batch stuffs), I don't want to make an heavy integration. So, I decided to embed its jar in my webapp (WEB-INF/lib). All I had to do was to find an elegant way to start a dedicated java virtual machine from my webapp to run my program without consequence on my web application.

The most elegant way I found was to use ANT... programmatically. In the following example, I wrote two classes. The MainProgram represents my webapp and the ProgramToRun represents my Spring Batch application. To simplify the code,  I didn't create a specific classpath for the ANT task but keep in mind that it's possible.

Look at the code, isn't it easy and cool?

public class MainProgram {

public static void main(String[] args) {
Project project = new Proje…