register

Mattepuffo's logo
Creare un widget in Wordpress

Creare un widget in Wordpress

Tendenzialmente i template che installiamo in Wodpress hanno già parecchi widget.

A me è servito crearne qualcuno personalizzato, ed oggi vediamo come fare.

Premetto che dobbiamo modificare il functions.php, quindi conviene che usiate una tema child.

Mattepuffo's logo
Chiudere un JDialog con il tasto ESC

Chiudere un JDialog con il tasto ESC

Uso spesso dei JDialog personalizzati, utili soprattutto per visualizzare alcune informazioni.

In questi casi mi rimane comodo chiuderli semplicemente con il tasto ESC.

In sostanza dobbiamo registrare una registerKeyboardAction, impostando il tasto ESC.

Mattepuffo's logo
Monitorare il file system con Java

Monitorare il file system con Java

Finalmente vacanza, e finalmente posso dedicarmi di più al blog e alla programmazione per conto mio!

Oggi vediamo come monitorare il file system usando Java e il packaje NIO (incluso nel JDK ovviamente).

Qui potete leggere le differenze rispetto al più classico IO.

Partiamo dal main:

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.WatchService;
import static java.nio.file.StandardWatchEventKinds.ENTRY_CREATE;
import static java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY;
import static java.nio.file.StandardWatchEventKinds.ENTRY_DELETE;

public class Main {

    public static void main(String[] args) throws IOException, InterruptedException {
        Path folder = Paths.get("/path/to/dir");
        if (folder == null) {
            throw new UnsupportedOperationException("Directory not found");
        }
        WatchService ws = folder.getFileSystem().newWatchService();
        Watcher w = new Watcher(ws);
        Thread th = new Thread(w, "Watcher");
        th.start();
        folder.register(ws, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
        th.join();
    }

}

Come vedete usiamo praticamente solo classi e oggetti di NIO.