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      private static final Logger LOGGER = LogManager.getRootLogger();
27  
28      /**
29       * Create tabs with ctrl-TAB, mouse-wheel.
30       */
31      public TabbedPaneWheeled() {
32          this(SwingConstants.TOP);
33      }
34  
35      public TabbedPaneWheeled(int tabPlacement) {
36          super(tabPlacement, JTabbedPane.SCROLL_TAB_LAYOUT);
37          this.addMouseWheelListener(new TabbedPaneMouseWheelListener());
38          HotkeyUtil.addShortcut(this);  // Hotkeys ctrl-TAB, ctrl-shift-TAB
39      }
40  
41      /**
42       * Highlight tab to mark when new content added
43       */
44      public void setBold(String label) {
45          int tabIndex = this.indexOfTab(label);
46          // Highlight only if tab not selected and tab exists
47          if (
48              this.getSelectedIndex() != tabIndex
49              && 0 <= tabIndex && tabIndex < this.getTabCount()
50          ) {
51              var tabHeader = this.getTabComponentAt(tabIndex);
52              // Unhandled ClassCastException #91158 on setFont()
53              try {
54                  tabHeader.setFont(tabHeader.getFont().deriveFont(Font.BOLD));
55              } catch (ClassCastException e) {
56                  LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
57              }
58          }
59      }
60  }