001package jmri.util.swing.multipane;
002
003import java.awt.BorderLayout;
004import java.awt.FlowLayout;
005import javax.swing.BoxLayout;
006import javax.swing.JComponent;
007import javax.swing.JMenu;
008import javax.swing.JMenuBar;
009import javax.swing.JPanel;
010import javax.swing.JSplitPane;
011import javax.swing.JToolBar;
012import jmri.util.swing.JMenuUtil;
013import jmri.util.swing.JToolBarUtil;
014import jmri.util.swing.WindowInterface;
015
016/**
017 * MultiPane JMRI window with a "top" area over "left" and "right" lower panes,
018 * optional toolbar and menu.
019 *
020 * @author Bob Jacobsen Copyright 2010
021 * @since 2.9.4
022 */
023public class ThreePaneTLRWindow extends jmri.util.JmriJFrame {
024
025    /**
026     * Create and initialize a multi-pane GUI window.
027     *
028     * @param name        the name and title of the window
029     * @param menubarFile path to the XML file for the menubar
030     * @param toolbarFile path to the XML file for the toolbar
031     */
032    public ThreePaneTLRWindow(String name, String menubarFile, String toolbarFile) {
033        super(name);
034        buildGUI(menubarFile, toolbarFile);
035        pack();
036    }
037
038    JSplitPane upDownSplitPane;
039    JSplitPane leftRightSplitPane;
040
041    JPanel top = new JPanel();
042
043    JPanel left = new JPanel();
044    JPanel right = new JPanel();
045
046    public JComponent getTop() {
047        return top;
048    }
049
050    public JComponent getRight() {
051        return right;
052    }
053
054    public JComponent getLeft() {
055        return left;
056    }
057
058    WindowInterface rightTopWI;
059
060    protected void buildGUI(String menubarFile, String toolbarFile) {
061        configureFrame();
062        addMainMenuBar(menubarFile);
063        addMainToolBar(toolbarFile);
064    }
065
066    protected void configureFrame() {
067
068        rightTopWI = new jmri.util.swing.sdi.JmriJFrameInterface();  // TODO figure out what WI is used here
069
070        //rightTop.setBorder(BorderFactory.createLineBorder(Color.black));
071        top.setLayout(new BoxLayout(top, BoxLayout.X_AXIS));
072        right.setLayout(new FlowLayout());
073        left.setLayout(new FlowLayout());
074
075        leftRightSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right);
076        leftRightSplitPane.setOneTouchExpandable(true);
077        leftRightSplitPane.setResizeWeight(0.0);  // emphasize right part
078
079        upDownSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
080                top,
081                leftRightSplitPane);
082        upDownSplitPane.setOneTouchExpandable(true);
083        upDownSplitPane.setResizeWeight(1.0);  // emphasize top part
084
085        add(upDownSplitPane, BorderLayout.CENTER);
086    }
087
088    public void resetRightToPreferredSizes() {
089        leftRightSplitPane.resetToPreferredSizes();
090    }
091
092    protected void addMainMenuBar(String menuFile) {
093        if (menuFile == null) {
094            return;
095        }
096        JMenuBar menuBar = new JMenuBar();
097
098        JMenu[] menus = JMenuUtil.loadMenu(menuFile, rightTopWI, null);
099        for (JMenu j : menus) {
100            menuBar.add(j);
101        }
102
103        setJMenuBar(menuBar);
104    }
105
106    protected void addMainToolBar(String toolBarFile) {
107        if (toolBarFile == null) {
108            return;
109        }
110
111        JToolBar toolBar = JToolBarUtil.loadToolBar(toolBarFile, rightTopWI, null);
112
113        // this takes up space at the top until pulled to floating
114        add(toolBar, BorderLayout.NORTH);
115    }
116
117    /**
118     * Only close frame, etc, dispose() disposes of all cached panes
119     */
120    @Override
121    public void dispose() {
122        rightTopWI.dispose();
123        super.dispose();
124    }
125
126}