Search in sources :

Example 1 with Node

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;
}
Also used : Execute(suite.os.Execute) Node(suite.editor.LayoutCalculator.Node) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) LayoutCalculator(suite.editor.LayoutCalculator) JFrame(javax.swing.JFrame) FontUtil(suite.editor.FontUtil)

Aggregations

Dimension (java.awt.Dimension)1 JButton (javax.swing.JButton)1 JFrame (javax.swing.JFrame)1 JLabel (javax.swing.JLabel)1 JTextField (javax.swing.JTextField)1 FontUtil (suite.editor.FontUtil)1 LayoutCalculator (suite.editor.LayoutCalculator)1 Node (suite.editor.LayoutCalculator.Node)1 Execute (suite.os.Execute)1