use of suite.editor.LayoutCalculator.Node in project suite by stupidsing.
the class PopupMain method run.
@Override
protected boolean run(String[] args) throws Exception {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int centerX = screenSize.width / 2, centerY = screenSize.height / 2;
int width = screenSize.width / 2, height = screenSize.height / 8;
JTextField inTextField = new JTextField();
inTextField.setFont(new FontUtil().monoFont);
inTextField.addActionListener(event -> {
execute(inTextField.getText());
System.exit(0);
});
JLabel outLabel = new JLabel();
JFrame frame = new JFrame("Pop-up");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setLocation(centerX - width / 2, centerY - height / 2);
frame.setSize(new Dimension(width, height));
frame.setVisible(true);
Fun<String, Execute> volumeControl = (String c) -> {
inTextField.requestFocusInWindow();
return new Execute(new String[] { "/usr/bin/amixer", "set", "PCM", "2" + c });
};
JLabel volLabel = new JLabel("Volume");
JButton volUpButton = new JButton("+");
volUpButton.setMnemonic(KeyEvent.VK_A);
volUpButton.addActionListener(event -> volumeControl.apply("+"));
JButton volDnButton = new JButton("-");
volDnButton.setMnemonic(KeyEvent.VK_Z);
volDnButton.addActionListener(event -> volumeControl.apply("-"));
LayoutCalculator lay = new LayoutCalculator(frame.getContentPane());
Node layout = //
lay.boxv(lay.fx(32, //
lay.boxh(//
lay.ex(32, lay.c(inTextField)), //
lay.fx(64, lay.c(volLabel)), //
lay.fx(48, lay.c(volUpButton)), //
lay.fx(48, lay.c(volDnButton)))), lay.ex(32, lay.c(outLabel)));
Runnable refresh = () -> {
lay.arrange(layout);
frame.repaint();
};
Listen.componentResized(frame).wire(refresh::run);
refresh.run();
System.in.read();
return true;
}
Aggregations