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          
35          var splitHorizontalTopBottom = MediatorHelper.frame().getSplitHorizontalTopBottom();
36          
37          if (
38              splitHorizontalTopBottom.getTopComponent().isVisible()
39              && splitHorizontalTopBottom.getBottomComponent().isVisible()
40          ) {
41              
42              MediatorHelper.panelConsoles().setDividerLocation(splitHorizontalTopBottom.getDividerLocation());
43              splitHorizontalTopBottom.getBottomComponent().setVisible(false);
44              this.panel.setVisible(true);
45              splitHorizontalTopBottom.disableDragSize();
46              
47          } else if (
48              this.panel.isVisible()
49              || !splitHorizontalTopBottom.getTopComponent().isVisible()
50              && splitHorizontalTopBottom.getBottomComponent().isVisible()
51          ) {
52              
53              splitHorizontalTopBottom.getBottomComponent().setVisible(true);
54              splitHorizontalTopBottom.getTopComponent().setVisible(true);
55              this.panel.setVisible(false);
56              splitHorizontalTopBottom.setDividerLocation(MediatorHelper.panelConsoles().getDividerLocation());
57              splitHorizontalTopBottom.enableDragSize();
58              MediatorHelper.panelConsoles().getButtonShowNorth().setVisible(true);
59          }
60      }
61  }