View Javadoc
1   package com.jsql.view.swing.panel.split;
2   
3   import com.jsql.view.swing.util.MediatorHelper;
4   
5   import javax.swing.*;
6   import java.awt.event.ActionEvent;
7   import java.awt.event.ActionListener;
8   
9   /**
10   * MouseAdapter to show/hide bottom panel.
11   */
12  public class ActionHideShowConsole implements ActionListener {
13      
14      /**
15       * Ersatz panel to display in place of tabbedpane.
16       */
17      private final JPanel panel;
18      
19      /**
20       * Create the hide/show bottom panel action.
21       */
22      public ActionHideShowConsole(JPanel panel) {
23          this.panel = panel;
24      }
25  
26      /**
27       * Hide bottom panel if both main and bottom are visible, also
28       * displays an ersatz bar replacing tabbedpane.
29       * Or else if only main panel is visible then displays bottom panel
30       * and hide ersatz panel.
31       */
32      @Override
33      public void actionPerformed(ActionEvent e) {
34          var split = MediatorHelper.frame().getSplitNS();
35          if (split.getTopComponent().isVisible() && split.getBottomComponent().isVisible()) {
36              MediatorHelper.panelConsoles().setDividerLocation(split.getDividerLocation());
37              split.getBottomComponent().setVisible(false);
38              this.panel.setVisible(true);
39              split.setDividerSize(0);  // required to hide bar
40          } else if (
41              this.panel.isVisible()
42              || !split.getTopComponent().isVisible()
43              && split.getBottomComponent().isVisible()
44          ) {
45              split.getBottomComponent().setVisible(true);
46              split.getTopComponent().setVisible(true);
47              this.panel.setVisible(false);
48              split.setDividerLocation(MediatorHelper.panelConsoles().getDividerLocation());
49              split.setDividerSize(UIManager.getInt("SplitPane.dividerSize"));
50              MediatorHelper.panelConsoles().getLabelShowNorth().setVisible(true);
51          }
52      }
53  }