001package jmri.jmrit.sample;
002
003import java.util.ArrayList;
004import java.util.List;
005
006import javax.swing.Icon;
007import javax.swing.JLabel;
008import javax.swing.JMenu;
009
010import jmri.jmrit.swing.ToolsMenuAction;
011import jmri.util.swing.JmriAbstractAction;
012import jmri.util.swing.JmriPanel;
013import jmri.util.swing.WindowInterface;
014
015// import org.openide.util.lookup.ServiceProvider;
016
017/**
018 * Sample Action to create a new user-defined item in the Tools menu.
019 *<P>
020 * This is disabled by default so it doesn't appear in the default Tools menu.
021 * Uncomment the line indicated below to allow this to appear in the Tools menu.
022 *<P>
023 * For more on why this inherits from {@link jmri.util.swing.JmriAbstractAction}
024 * and the use of {@link jmri.util.swing.JmriPanel} and {@link jmri.util.swing.WindowInterface},
025 * please see 
026 * <a href="https://www.jmri.org/help/en/html/doc/Technical/Swing.shtml">JMRI's Use of Swing page</a>.
027 *
028 * @author Paul Bender   Copyright (C) 2003
029 * @author Bob Jacobsen  Copyright (C) 2023
030 */
031 
032// Remove the // from the next line and the import statement above to activate this sample.
033//@ServiceProvider(service = jmri.jmrit.swing.ToolsMenuAction.class)
034
035public class SampleToolsMenuItem extends JmriAbstractAction implements ToolsMenuAction {
036
037    public SampleToolsMenuItem(String s, WindowInterface wi) {
038        super(s, wi);
039    }
040
041    public SampleToolsMenuItem(String s, Icon i, WindowInterface wi) {
042        super(s, i, wi);
043    }
044
045    public SampleToolsMenuItem(String s) {
046        super(s);
047    }
048
049    public SampleToolsMenuItem() {
050        this("Sample Tools Menu Item");  // better to use a bundle here
051    }
052
053    @Override
054    public JmriPanel makePanel() {
055
056        // create a new panel of your specific type here
057        var retval = new SampleToolsMenuPanel();
058
059        retval.initComponents();
060        return retval;
061    }
062
063
064    // Example JmriPanel
065    // Yours should be a separate class in a separate file usually.
066    static class SampleToolsMenuPanel extends JmriPanel {
067    
068        /**
069         * Your initialization code for your GUI goes here.
070         * {@inheritDoc}
071         */
072        @Override
073        public void initComponents() {
074            super.initComponents();
075            
076            add(new JLabel("Sample Contents"));
077            
078        }
079            
080        /**
081         * This is where you define the title of your new pane.
082         * {@inheritDoc}
083         */
084        @Override
085        public String getTitle() {
086            return "Sample Frame's Title"; // this should come from a Bundle in your package
087        }
088    
089        /**
090         * This is where you define menus that go with your new panel.
091         * {@inheritDoc}
092         */
093        @Override
094        public List<JMenu> getMenus() {
095            List<JMenu> menuList = new ArrayList<>();
096            return menuList;
097        }
098
099    }
100    
101}