33 lines
1.3 KiB
Java
33 lines
1.3 KiB
Java
package danielcortes.xyz.controllers;
|
|
|
|
import danielcortes.xyz.controllers.actions.BasicAction;
|
|
import danielcortes.xyz.data.Configuration;
|
|
|
|
import javax.swing.*;
|
|
import java.awt.*;
|
|
|
|
class BaseController {
|
|
static void moveTo(JComponent origin, JComponent destiny) {
|
|
KeyStroke next = KeyStroke.getKeyStroke("ENTER");
|
|
KeyStroke back = KeyStroke.getKeyStroke("ESCAPE");
|
|
origin.getInputMap(JComponent.WHEN_FOCUSED).put(next, "nextField");
|
|
destiny.getInputMap(JComponent.WHEN_FOCUSED).put(back, "previousField");
|
|
origin.getActionMap().put("nextField", (BasicAction) e -> destiny.requestFocus());
|
|
destiny.getActionMap().put("previousField", (BasicAction) e -> origin.requestFocus());
|
|
}
|
|
static void doAction(JComponent target, String name, KeyStroke keyStroke, BasicAction action){
|
|
target.getInputMap(JComponent.WHEN_FOCUSED).put(keyStroke, name);
|
|
target.getActionMap().put(name, action);
|
|
}
|
|
|
|
private void launchFrame(JComponent view, String title, Dimension d){
|
|
JFrame frame = new JFrame(title + ": " + Configuration.get("nombre_caja"));
|
|
frame.setContentPane(view);
|
|
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|
|
|
frame.setSize(d);
|
|
frame.setLocationRelativeTo(null);
|
|
frame.setVisible(true);
|
|
}
|
|
}
|