content: /*
   * The MIT License (MIT)
   *
   * Copyright (c) 2011-2021 Broad Institute, Aiden Lab, Rice University, Baylor College of Medicine
   *
   * Permission is hereby granted, free of charge, to any person obtaining a copy
   * of this software and associated documentation files (the "Software"), to deal
   * in the Software without restriction, including without limitation the rights
   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   * copies of the Software, and to permit persons to whom the Software is
   * furnished to do so, subject to the following conditions:
   *
   * The above copyright notice and this permission notice shall be included in
   * all copies or substantial portions of the Software.
   *
   *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   *  FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
   *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   *  THE SOFTWARE.
   */
  
  package juicebox.windowui;
  
  import juicebox.HiCGlobals;
  
  import javax.swing.*;
  import javax.swing.border.Border;
  import javax.swing.border.EmptyBorder;
  import java.awt.*;
  import java.awt.event.KeyEvent;
  import java.awt.event.KeyListener;
  import java.awt.event.MouseAdapter;
  import java.awt.event.MouseMotionAdapter;
  
  /*
   * @author Rob Camick November 7, 2008
   *  Simple implementation of a Glass Pane that will capture and ignore all
   *  events as well paint the glass pane to give the frame a "disabled" look.
   *
   *  The background color of the glass pane should use a color with an
   *  alpha value to create the disabled look.
   */
  public class DisabledGlassPane extends JComponent implements KeyListener {
  
      private static final long serialVersionUID = 9000039;
      private final JLabel message = new JLabel();
  
      public DisabledGlassPane(int cursor) {
          super();
          //  Set glass pane properties
  
          setOpaque(false);
          setCursor(Cursor.getPredefinedCursor(cursor));
          Color base = UIManager.getColor("inactiveCaptionBorder");
          Color background = new Color(base.getRed(), base.getGreen(), base.getBlue(), 128);
          setBackground(background);
          setLayout(new GridBagLayout());
          message.setFont(HiCGlobals.font(30, true));
          //  Add a message label to the glass pane
  
          add(message, new GridBagConstraints());
          message.setOpaque(false);
          Border MESSAGE_BORDER = new EmptyBorder(20, 20, 20, 20);
          message.setBorder(MESSAGE_BORDER);
  
          //  Disable Mouse, Key and Focus events for the glass pane
          addMouseListener(new MouseAdapter() {
          });
          addMouseMotionListener(new MouseMotionAdapter() {
          });
  
          addKeyListener(this);
  
          setFocusTraversalKeysEnabled(false);
      }
  
      /*
       *  The component is transparent but we want to paint the background
       *  to give it the disabled look.
       */
      @Override
      protected void paintComponent(Graphics g) {
          g.setColor(getBackground());
          g.fillRect(0, 0, getSize().width, getSize().height);
      }
  
      /*
       *  The	background color of the message label will be the same as the
       *  background of the glass pane without the alpha value
       */
      @Override
      public void setBackground(Color background) {
          super.setBackground(background);
  
          Color messageBackground = new Color(background.getRGB());
          message.setBackground(messageBackground);
      }
  
      /*
       * Implement the KeyListener to consume events
       */
      public void keyPressed(KeyEvent e) {
          e.consume();
      }
  
      public void keyTyped(KeyEvent e) {
      }
  
      public void keyReleased(KeyEvent e) {
          e.consume();
      }
  
      /*
       *  Make the glass pane visible and change the cursor to the wait cursor
       *
       *  A message can be displayed and it will be centered on the frame.
       */
      public void activate(String text) {
          if (text != null && text.length() > 0) {
              message.setVisible(true);
              message.setText(text);
              message.setForeground(getForeground());
          } else
              message.setVisible(false);
  
          setVisible(true);
          requestFocusInWindow();
      }
  
      /*
       *  Hide the glass pane and restore the cursor
       */
      public void deactivate() {
          setVisible(false);
      }
  
  
  }
  
  
  