View Javadoc
1   /*******************************************************************************
2    * Copyhacked (H) 2012-2025.
3    * This program and the accompanying materials
4    * are made available under no term at all, use it like
5    * you want, but share and discuss it
6    * every time possible with every body.
7    * 
8    * Contributors:
9    *      ron190 at ymail dot com - initial implementation
10   ******************************************************************************/
11  package com.jsql.view.swing.tab;
12  
13  import com.jsql.util.LogLevelUtil;
14  import com.jsql.view.swing.action.HotkeyUtil;
15  import org.apache.logging.log4j.LogManager;
16  import org.apache.logging.log4j.Logger;
17  
18  import javax.swing.*;
19  import java.awt.*;
20  
21  /**
22   * Tabs with mouse-wheel and right click action.
23   */
24  public class TabbedPaneWheeled extends JTabbedPane {
25  
26      /**
27       * Log4j logger sent to view.
28       */
29      private static final Logger LOGGER = LogManager.getRootLogger();
30  
31      /**
32       * Create tabs with ctrl-TAB, mouse-wheel.
33       */
34      public TabbedPaneWheeled() {
35          this(SwingConstants.TOP);
36      }
37  
38      public TabbedPaneWheeled(int tabPlacement) {
39          super(tabPlacement, JTabbedPane.SCROLL_TAB_LAYOUT);
40          this.addMouseWheelListener(new TabbedPaneMouseWheelListener());
41          HotkeyUtil.addShortcut(this);  // Hotkeys ctrl-TAB, ctrl-shift-TAB
42      }
43  
44      /**
45       * Highlight tab to mark when new content added
46       */
47      public void setBold(String label) {
48          int tabIndex = this.indexOfTab(label);
49          // Highlight only if tab not selected and tab exists
50          if (
51              this.getSelectedIndex() != tabIndex
52              && 0 <= tabIndex && tabIndex < this.getTabCount()
53          ) {
54              var tabHeader = this.getTabComponentAt(tabIndex);
55              // Unhandled ClassCastException #91158 on setFont()
56              try {
57                  tabHeader.setFont(tabHeader.getFont().deriveFont(Font.BOLD));
58              } catch (ClassCastException e) {
59                  LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
60              }
61          }
62      }
63  }