001package jmri.jmrit.display.layoutEditor;
002
003import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
004import java.awt.FlowLayout;
005import javax.annotation.Nonnull;
006import javax.swing.*;
007import javax.swing.border.*;
008
009/**
010 * This is the floating toolbar panel
011 *
012 * @author George Warner Copyright: (c) 2017-2019
013 */
014public class LayoutEditorFloatingToolBarPanel extends LayoutEditorToolBarPanel {
015
016    private JPanel floatEditTabsPanel = new JPanel();
017    private JTabbedPane floatEditTabsPane = new JTabbedPane();
018
019    /**
020     * constructor for LayoutEditorFloatingToolBarPanel
021     *
022     * @param layoutEditor the layout editor that this is for
023     */
024    public LayoutEditorFloatingToolBarPanel(@Nonnull LayoutEditor layoutEditor) {
025        super(layoutEditor);
026        localLayoutComponents();
027    }
028
029    // super.setupComponents() used as-is. super.layoutComponents() is
030    // suppressed, as it doesn't need to run. localLayoutComponents()
031    // is then invoked by this class's constructor after the initializers
032    // are complete. (Putting this into an override of layoutComponents would
033    // not be correct, as that is invoked from the superclass constructor before
034    // this classes initializers are run; local reference members will be
035    // overwritten when that happens.)
036
037    /**
038     * Deliberately not running the superclass
039     * {@link LayoutEditorToolBarPanel#layoutComponents()}
040     * method.
041     */
042    @Override
043    final protected void layoutComponents() {
044    }
045
046    /**
047     * Local configuration of Swing components run as
048     * last phase of construction.
049     */
050    private void localLayoutComponents() {
051        /*
052         *  JPanel - floatEditTabsPanel
053         *      JTabbedPane - floatEditTabsPane
054         *          ...
055         *      JPanel - floatEditLocationPanel
056         *          ...
057         *      JPanel - floatEditActionPanel  (currently disabled)
058         *          ...
059         *      JPanel - floatEditHelpPanel
060         *          ...
061         */
062
063        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
064
065        FlowLayout floatContentLayout = new FlowLayout(FlowLayout.CENTER, 5, 2); //5 pixel gap between items, 2 vertical gap
066
067        // Contains the block and sensor combo boxes.
068        // It is moved to the appropriate detail pane when the tab changes.
069        blockPropertiesPanel = new JPanel();
070        blockPropertiesPanel.setLayout(new BoxLayout(blockPropertiesPanel, BoxLayout.Y_AXIS));
071
072        JPanel blockPanel = new JPanel(floatContentLayout);
073        blockPanel.add(blockLabel);
074        blockPanel.add(blockIDComboBox);
075        blockPanel.add(highlightBlockCheckBox);
076        blockPropertiesPanel.add(blockPanel);
077
078        JPanel blockSensorPanel = new JPanel(floatContentLayout);
079        blockSensorPanel.add(blockSensorLabel);
080        blockSensorPanel.add(blockSensorComboBox);
081        blockSensorPanel.setBorder(new EmptyBorder(0, 20, 0, 0));
082        blockPropertiesPanel.add(blockSensorPanel);
083
084        // Begin the tabs structure
085        //
086        // Tab 0 - Turnouts
087        JPanel floatEditTurnout = new JPanel();
088        floatEditTurnout.setLayout(new BoxLayout(floatEditTurnout, BoxLayout.Y_AXIS));
089
090        JPanel turnoutGroup1 = new JPanel(floatContentLayout);
091        turnoutGroup1.add(turnoutRHButton);
092        turnoutGroup1.add(turnoutLHButton);
093        turnoutGroup1.add(turnoutWYEButton);
094        turnoutGroup1.add(layoutSingleSlipButton);
095        turnoutGroup1.add(layoutDoubleSlipButton);
096        floatEditTurnout.add(turnoutGroup1);
097
098        JPanel turnoutGroup2 = new JPanel(floatContentLayout);
099        turnoutGroup2.add(doubleXoverButton);
100        turnoutGroup2.add(rhXoverButton);
101        turnoutGroup2.add(lhXoverButton);
102        floatEditTurnout.add(turnoutGroup2);
103
104        JPanel turnoutGroup3 = new JPanel(floatContentLayout);
105        turnoutGroup3.add(turnoutNamePanel);
106        floatEditTurnout.add(turnoutGroup3);
107
108        JPanel turnoutGroup3a = new JPanel(floatContentLayout);
109        turnoutGroup3a.add(extraTurnoutPanel);
110        floatEditTurnout.add(turnoutGroup3a);
111
112        JPanel turnoutGroup4 = new JPanel(floatContentLayout);
113        turnoutGroup4.add(rotationPanel);
114        floatEditTurnout.add(turnoutGroup4);
115
116        floatEditTurnout.add(blockPropertiesPanel);
117
118        floatEditTabsPane.addTab(Bundle.getMessage("Turnouts"), null, floatEditTurnout, null);
119
120        // Tab 1 - Track
121        JPanel floatEditTrack = new JPanel();
122        floatEditTrack.setLayout(new BoxLayout(floatEditTrack, BoxLayout.Y_AXIS));
123
124        JPanel trackGroup1 = new JPanel(floatContentLayout);
125        trackGroup1.add(endBumperButton);
126        trackGroup1.add(anchorButton);
127        trackGroup1.add(edgeButton);
128        floatEditTrack.add(trackGroup1);
129
130        JPanel trackGroup2 = new JPanel(floatContentLayout);
131        trackGroup2.add(trackButton);
132        trackGroup2.add(levelXingButton);
133        floatEditTrack.add(trackGroup2);
134
135        JPanel trackGroup3 = new JPanel(floatContentLayout);
136        trackGroup3.add(trackSegmentPropertiesPanel);
137        floatEditTrack.add(trackGroup3);
138
139        floatEditTabsPane.addTab(Bundle.getMessage("TabTrack"), null, floatEditTrack, null);
140
141        // Tab 2 - Labels
142        JPanel floatEditLabel = new JPanel();
143        floatEditLabel.setLayout(new BoxLayout(floatEditLabel, BoxLayout.Y_AXIS));
144
145        JPanel labelGroup1 = new JPanel(floatContentLayout);
146        labelGroup1.add(textLabelButton);
147        labelGroup1.add(textLabelTextField);
148        floatEditLabel.add(labelGroup1);
149
150        JPanel labelGroup2 = new JPanel(floatContentLayout);
151        labelGroup2.add(memoryButton);
152        labelGroup2.add(textMemoryComboBox);
153        floatEditLabel.add(labelGroup2);
154
155        JPanel labelGroup4 = new JPanel(floatContentLayout);
156        labelGroup4.add(globalVariableButton);
157        labelGroup4.add(textGlobalVariableComboBox);
158        floatEditLabel.add(labelGroup4);
159
160        JPanel labelGroup3 = new JPanel(floatContentLayout);
161        labelGroup3.add(blockContentsButton);
162        labelGroup3.add(blockContentsComboBox);
163        floatEditLabel.add(labelGroup3);
164
165        floatEditTabsPane.addTab(Bundle.getMessage("TabLabel"), null, floatEditLabel, null);
166
167        // Tab 3 - Icons
168        JPanel floatEditIcon = new JPanel();
169        floatEditIcon.setLayout(new BoxLayout(floatEditIcon, BoxLayout.Y_AXIS));
170
171        JPanel iconGroup1 = new JPanel(floatContentLayout);
172        iconGroup1.add(multiSensorButton);
173        iconGroup1.add(changeIconsButton);
174        floatEditIcon.add(iconGroup1);
175
176        JPanel iconGroup2 = new JPanel(floatContentLayout);
177        iconGroup2.add(sensorButton);
178        iconGroup2.add(sensorComboBox);
179        floatEditIcon.add(iconGroup2);
180
181        JPanel iconGroup3 = new JPanel(floatContentLayout);
182        iconGroup3.add(signalMastButton);
183        iconGroup3.add(signalMastComboBox);
184        floatEditIcon.add(iconGroup3);
185
186        JPanel iconGroup4 = new JPanel(floatContentLayout);
187        iconGroup4.add(signalButton);
188        iconGroup4.add(signalHeadComboBox);
189        floatEditIcon.add(iconGroup4);
190
191        JPanel iconGroup5 = new JPanel(floatContentLayout);
192        iconGroup5.add(iconLabelButton);
193        iconGroup5.add(shapeButton);
194        floatEditIcon.add(iconGroup5);
195
196        floatEditTabsPane.addTab(Bundle.getMessage("TabIcon"), null, floatEditIcon, null);
197        floatEditTabsPanel.add(floatEditTabsPane);
198        add(floatEditTabsPanel);
199
200        // End the tabs structure
201        // The next 3 groups reside under the tab secton
202        JPanel floatEditLocationPanel = new JPanel();
203        floatEditLocationPanel.add(zoomPanel);
204        floatEditLocationPanel.add(locationPanel);
205        add(floatEditLocationPanel);
206
207        floatEditTabsPane.addChangeListener((e) -> {
208            //Move the block group between the turnouts and track tabs
209            int selIndex = floatEditTabsPane.getSelectedIndex();
210
211            if (selIndex == 0) {
212                floatEditTurnout.add(blockPropertiesPanel);
213            } else if (selIndex == 1) {
214                floatEditTrack.add(blockPropertiesPanel);
215            }
216        });
217        floatEditTabsPane.setSelectedIndex(0);
218        floatEditTurnout.add(blockPropertiesPanel);
219    }
220
221    public JTabbedPane getfloatEditTabsPane() {
222        return floatEditTabsPane;
223    }
224
225    // initialize logging
226    // private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LayoutEditorFloatingToolBarPanel.class);
227}