putValue(ACTION_COMMAND_KEY, "bitmapSelect");
// JFormDesigner - End of action initialization //GEN-END:initComponents
}
public void actionPerformed(ActionEvent e) {
ScreenSelectionOverlay overlay = new ScreenSelectionOverlay(MainWindow.this, false, ScreenSelectionOverlay.CloseMethod.CloseOnRelease);
overlay.addMouseListener(new MouseAdapter() {
private Point start
,
end;
public void mousePressed(MouseEvent e) {
start = e.getLocationOnScreen();
end = start; // in case they release straightway...
}
public void mouseReleased(MouseEvent e) {
end = e.getLocationOnScreen();
final int sX = Math.min(start.x, end.x);
final int sY = Math.min(start.y, end.y);
int eX = Math.max(start.x, end.x);
int eY = Math.max(start.y, end.y);
final int w = eX - sX;
final int h = eY - sY;
new Thread(new Runnable() {
public void run() {
setProgressEnabled(true);
setProgressUnknown();
try {
Thread.sleep(100); // Delay until the windows are hidden...
} catch (InterruptedException e1) {
/**/
}
Object img = WindowManager.getDesktop().captureImage(sX, sY, w + 1, h + 1).toImage();
SnippetManager.instance.addSnippet(img);
setProgressEnabled(false);
}
}).start();
}
});
overlay.setVisible(true);
}