1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-11 11:55:03 -05:00
filebot/source/net/sourceforge/tuned/ui/TunedUtil.java
Reinhard Pointner b5bee237d6 * refactored matching
* added ProgressDialog for long-running matching
* added delayed invokeLater to TunedUtil
* removed generics from ListEntry (only subclasses where used anyway)
* minor cleanup in notification package
2008-04-27 17:36:27 +00:00

57 lines
1.2 KiB
Java

package net.sourceforge.tuned.ui;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.KeyStroke;
import javax.swing.Timer;
public class TunedUtil {
public static void registerActionForKeystroke(JComponent component, KeyStroke keystroke, Action action) {
Integer key = action.hashCode();
component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keystroke, key);
component.getActionMap().put(key, action);
}
public static Point getPreferredLocation(JDialog dialog) {
Window owner = dialog.getOwner();
if (owner == null)
return new Point(120, 80);
Point p = owner.getLocation();
Dimension d = owner.getSize();
return new Point(p.x + d.width / 4, p.y + d.height / 7);
}
public static Timer invokeLater(int delay, final Runnable runnable) {
Timer timer = new Timer(delay, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
runnable.run();
}
});
timer.setRepeats(false);
timer.start();
return timer;
}
}