lcdproc / lcdjava

Java client for LCDproc
MIT License
7 stars 5 forks source link

Add menu support #1

Closed StefanKrupop closed 8 years ago

StefanKrupop commented 9 years ago

This adds support for LCDd's menu system. Menu items support ActionListeners to be called when they are executed or change value.

Sample usage:

        Submenu mainMenu = Submenu.construct(mLCD.getRootMenu(), "Main menu");
        mainMenu.activate();        

        SliderMenuItem slider = SliderMenuItem.construct(mainMenu, "Slider", 1, 18);
        slider.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                mLog.debug("Slider changed. Value=" + ((SliderMenuItem)e.getSource()).getValue());
            }
        });
        slider.activate();

        Submenu shutdownMenu = Submenu.construct(mainMenu, "Shutdown");
        shutdownMenu.activate();
        ActionMenuItem.construct(shutdownMenu, "Cancel", MenuResult.Close).activate();
        ActionMenuItem shutdown = ActionMenuItem.construct(shutdownMenu, "OK", MenuResult.Quit);
        shutdown.activate();
        shutdown.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("Power off!");
            }
        });

        ActionMenuItem.construct(mainMenu, "Exit", MenuResult.Quit).activate();
        mainMenu.setAsMainMenu();
boncey commented 8 years ago

Thanks for this.
I don't really use lcdjava anymore so this is kind of a dormant project. Therefore I'm unable to try out your changes.