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.tree.model;
12  
13  import com.jsql.model.bean.database.Column;
14  import com.jsql.util.I18nUtil;
15  import com.jsql.view.swing.util.UiStringUtil;
16  
17  import javax.swing.*;
18  import java.awt.*;
19  
20  /**
21   * Column model creating a checkbox.
22   * Used by renderer and editor.
23   */
24  public class NodeModelColumn extends NodeModelEmpty {
25      
26      /**
27       * Node as a column model.
28       * @param column Element column coming from model
29       */
30      public NodeModelColumn(Column column) {
31          super(column);
32      }
33  
34      @Override
35      public Component getComponent(
36          final JTree tree, Object nodeRenderer, final boolean isSelected, boolean isLeaf, boolean hasFocus
37      ) {
38          var checkbox = new JCheckBox(this.toString(), this.isSelected());
39          checkbox.setText(UiStringUtil.detectUtf8HtmlNoWrap(this.toString()));
40          checkbox.setComponentOrientation(ComponentOrientation.getOrientation(I18nUtil.getCurrentLocale()));
41          checkbox.setBackground(
42              isSelected ? UIManager.getColor("Tree.selectionBackground") : UIManager.getColor("Tree.background")
43          );  // required for transparency
44          checkbox.setForeground(  // required by macOS light (opposite text color)
45              isSelected ? UIManager.getColor("Tree.selectionForeground") : UIManager.getColor("Tree.foreground")
46          );
47          return checkbox;
48      }
49  }