protected void installDefaults(AbstractButton b) {
    // load shared instance defaults
    String pp = getPropertyPrefix();

    defaultTextShiftOffset = UIManager.getInt(pp + "textShiftOffset");

    // set the following defaults on the button
    if (b.isContentAreaFilled()) {
      LookAndFeel.installProperty(b, "opaque", Boolean.TRUE);
    } else {
      LookAndFeel.installProperty(b, "opaque", Boolean.FALSE);
    }

    if (b.getMargin() == null || (b.getMargin() instanceof UIResource)) {
      b.setMargin(UIManager.getInsets(pp + "margin"));
    }

    LookAndFeel.installColorsAndFont(b, pp + "background", pp + "foreground", pp + "font");
    LookAndFeel.installBorder(b, pp + "border");

    Object rollover = UIManager.get(pp + "rollover");
    if (rollover != null) {
      LookAndFeel.installProperty(b, "rolloverEnabled", rollover);
    }

    LookAndFeel.installProperty(b, "iconTextGap", new Integer(4));
  }
 private InputMap getInputMap(int condition) {
   if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
     return (InputMap) UIManager.get("Grid.ancestorInputMap");
   } else {
     return null;
   }
 }
  @SuppressWarnings("HardCodedStringLiteral")
  private boolean togglePopup(KeyEvent e) {
    final KeyStroke stroke = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers());
    final Object action = ((InputMap) UIManager.get("ComboBox.ancestorInputMap")).get(stroke);
    if ("selectNext".equals(action)) {
      if (!isPopupShowing()) {
        return true;
      } else {
        return false;
      }
    } else if ("togglePopup".equals(action)) {
      if (isPopupShowing()) {
        closePopup();
      } else {
        suggestCompletion(true, true);
      }
      return true;
    } else {
      final Keymap active = KeymapManager.getInstance().getActiveKeymap();
      final String[] ids = active.getActionIds(stroke);
      if (ids.length > 0 && IdeActions.ACTION_CODE_COMPLETION.equals(ids[0])) {
        suggestCompletion(true, true);
      }
    }

    return false;
  }
  /** Creates new form gui */
  public gui() {
    super(new BorderLayout());
    initComponents();

    // Load user list and images
    images = new ImageIcon[userStrings.length];
    Integer[] intArray = new Integer[userStrings.length];
    for (int i = 0; i < userStrings.length; i++) {
      intArray[i] = new Integer(i);
      images[i] = createImageIcon("images/" + userStrings[i] + ".png");
      if (images[i] != null) {
        images[i].setDescription(userStrings[i]);
      }
    }
    users = new JComboBox(intArray);
    Color bg = (Color) UIManager.get("ComboBox.background");
    Color fg = (Color) UIManager.get("ComboBox.foreground");
    UIManager.put("ComboBox.selectionBackground", bg);
    UIManager.put("ComboBox.selectionForeground", fg);
    users.setUI(new MetalComboBoxUI());
    // ComboBoxRenderer renderer = new ComboBoxRenderer();
    ComboBoxRenderer renderer = new ComboBoxRenderer(userStrings, images);
    renderer.setPreferredSize(new Dimension(650, 150));
    users.setRenderer(renderer);
    users.setSize(renderer.getPreferredSize());
    users.setMaximumRowCount(4);
    users.setBounds(150, 250, 650, 200);
    add(users);
    // setBorder(BorderFactory.createEmptyBorder(20,20,20,20));

    // Set the user satisfaction labels
    jSlider1.setPaintTicks(true);
    Hashtable labelTable = new Hashtable();
    for (int i = 0; i < labels.length; i++) {
      labelTable.put(new Integer(i), new JLabel(labels[i]));
    }

    jSlider1.setLabelTable(labelTable);

    jSlider1.setPaintLabels(true);

    socket = new generalSocket(machine, 1099);

    statusThread thread = new statusThread(socket, jLabel4);
    Thread theThread = new Thread(thread);
    theThread.start();
  }
 private ActionMap getActionMap() {
   ActionMap actionMap = (ActionMap) UIManager.get("Grid.actionMap");
   if (actionMap == null) {
     actionMap = createActionMap();
     if (actionMap != null) {
       UIManager.put("Grid.actionMap", actionMap);
     }
   }
   return actionMap;
 }
  private int getMnemonic(String key, Locale l) {
    String value = (String) UIManager.get(key, l);

    if (value == null) {
      return 0;
    }
    try {
      return Integer.parseInt(value);
    } catch (NumberFormatException nfe) {
    }
    return 0;
  }
 protected void installDefaults() {
   Color defaultGridColor = UIManager.getColor("Table.gridColor");
   Color defaultForegroundColor = UIManager.getColor("Table.foreground");
   Color defaultBackgroundColor = UIManager.getColor("Table.background");
   Border defaultBorder = UIManager.getBorder("Table.scrollPaneBorder");
   Color defaultSelectionForeground = UIManager.getColor("Table.selectionForeground");
   Color defaultSelectionBackground = UIManager.getColor("Table.selectionBackground");
   Color defaultFocusCellForeground = UIManager.getColor("Table.focusCellForeground");
   Color defaultFocusCellBackground = new Color(153, 153, 204);
   Font defaultFont = UIManager.getFont("Table.font");
   Border defaultGridBorder = UIManager.getBorder("Table.border");
   InputMap inputMap = (InputMap) UIManager.get("Table.ancestorInputMap");
   if (!installed) {
     UIManager.getDefaults().put("Grid.gridColor", defaultGridColor);
     UIManager.getDefaults().put("Grid.foreground", defaultForegroundColor);
     UIManager.getDefaults().put("Grid.background", defaultBackgroundColor);
     UIManager.getDefaults().put("Grid.selectionForegroundColor", defaultSelectionForeground);
     UIManager.getDefaults().put("Grid.selectionBackgroundColor", defaultSelectionBackground);
     UIManager.getDefaults().put("Grid.focusForegroundColor", defaultFocusCellForeground);
     UIManager.getDefaults().put("Grid.focusBackgroundColor", defaultFocusCellBackground);
     UIManager.getDefaults().put("Grid.border", defaultGridBorder);
     UIManager.getDefaults().put("Grid.font", defaultFont);
     UIManager.getDefaults().put("Grid.scrollPaneBorder", defaultBorder);
     UIManager.getDefaults().put("Grid.ancestorInputMap", inputMap);
     installed = true;
   }
   Color foregroundColor = grid.getForeground();
   Color backgroundColor = grid.getBackground();
   Font font = grid.getFont();
   Border border = grid.getBorder();
   Color gridColor = grid.getGridColor();
   Color selectionForeground = grid.getSelectionForegroundColor();
   Color selectionBackground = grid.getSelectionBackgroundColor();
   Color focusForeground = grid.getFocusForegroundColor();
   Color focusBackground = grid.getFocusBackgroundColor();
   if (foregroundColor == null || foregroundColor instanceof UIResource)
     grid.setForeground(defaultForegroundColor);
   if (backgroundColor == null || backgroundColor instanceof UIResource)
     grid.setBackground(defaultBackgroundColor);
   if (font == null || font instanceof UIResource) grid.setFont(defaultFont);
   if (gridColor == null || gridColor instanceof UIResource) grid.setGridColor(defaultGridColor);
   if (border == null || border instanceof UIResource) grid.setBorder(defaultGridBorder);
   if (selectionForeground == null || selectionForeground instanceof UIResource)
     grid.setSelectionForegroundColor(defaultSelectionForeground);
   if (selectionBackground == null || selectionBackground instanceof UIResource)
     grid.setSelectionBackgroundColor(defaultSelectionBackground);
   if (focusForeground == null || focusForeground instanceof UIResource)
     grid.setFocusForegroundColor(defaultFocusCellForeground);
   if (focusBackground == null || focusBackground instanceof UIResource)
     grid.setFocusBackgroundColor(defaultFocusCellBackground);
 }
/**
 * Class that manages a JLF title bar
 *
 * @author Steve Wilson
 * @author Brian Beck
 * @since 1.3
 */
public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane {

  protected boolean isPalette = false;
  protected Icon paletteCloseIcon;
  protected int paletteTitleHeight;

  private static final Border handyEmptyBorder = new EmptyBorder(0, 0, 0, 0);

  /**
   * Key used to lookup Color from UIManager. If this is null, <code>getWindowTitleBackground</code>
   * is used.
   */
  private String selectedBackgroundKey;
  /**
   * Key used to lookup Color from UIManager. If this is null, <code>getWindowTitleForeground</code>
   * is used.
   */
  private String selectedForegroundKey;
  /**
   * Key used to lookup shadow color from UIManager. If this is null, <code>
   * getPrimaryControlDarkShadow</code> is used.
   */
  private String selectedShadowKey;
  /**
   * Boolean indicating the state of the <code>JInternalFrame</code>s closable property at <code>
   * updateUI</code> time.
   */
  private boolean wasClosable;

  int buttonsWidth = 0;

  MetalBumps activeBumps =
      new MetalBumps(
          0,
          0,
          MetalLookAndFeel.getPrimaryControlHighlight(),
          MetalLookAndFeel.getPrimaryControlDarkShadow(),
          (UIManager.get("InternalFrame.activeTitleGradient") != null)
              ? null
              : MetalLookAndFeel.getPrimaryControl());
  MetalBumps inactiveBumps =
      new MetalBumps(
          0,
          0,
          MetalLookAndFeel.getControlHighlight(),
          MetalLookAndFeel.getControlDarkShadow(),
          (UIManager.get("InternalFrame.inactiveTitleGradient") != null)
              ? null
              : MetalLookAndFeel.getControl());
  MetalBumps paletteBumps;

  private Color activeBumpsHighlight = MetalLookAndFeel.getPrimaryControlHighlight();
  private Color activeBumpsShadow = MetalLookAndFeel.getPrimaryControlDarkShadow();

  public MetalInternalFrameTitlePane(JInternalFrame f) {
    super(f);
  }

  public void addNotify() {
    super.addNotify();
    // This is done here instead of in installDefaults as I was worried
    // that the BasicInternalFrameUI might not be fully initialized, and
    // that if this resets the closable state the BasicInternalFrameUI
    // Listeners that get notified might be in an odd/uninitialized state.
    updateOptionPaneState();
  }

  protected void installDefaults() {
    super.installDefaults();
    setFont(UIManager.getFont("InternalFrame.titleFont"));
    paletteTitleHeight = UIManager.getInt("InternalFrame.paletteTitleHeight");
    paletteCloseIcon = UIManager.getIcon("InternalFrame.paletteCloseIcon");
    wasClosable = frame.isClosable();
    selectedForegroundKey = selectedBackgroundKey = null;
    if (MetalLookAndFeel.usingOcean()) {
      setOpaque(true);
    }
  }

  protected void uninstallDefaults() {
    super.uninstallDefaults();
    if (wasClosable != frame.isClosable()) {
      frame.setClosable(wasClosable);
    }
  }

  protected void createButtons() {
    super.createButtons();

    Boolean paintActive = frame.isSelected() ? Boolean.TRUE : Boolean.FALSE;
    iconButton.putClientProperty("paintActive", paintActive);
    iconButton.setBorder(handyEmptyBorder);

    maxButton.putClientProperty("paintActive", paintActive);
    maxButton.setBorder(handyEmptyBorder);

    closeButton.putClientProperty("paintActive", paintActive);
    closeButton.setBorder(handyEmptyBorder);

    // The palette close icon isn't opaque while the regular close icon is.
    // This makes sure palette close buttons have the right background.
    closeButton.setBackground(MetalLookAndFeel.getPrimaryControlShadow());

    if (MetalLookAndFeel.usingOcean()) {
      iconButton.setContentAreaFilled(false);
      maxButton.setContentAreaFilled(false);
      closeButton.setContentAreaFilled(false);
    }
  }

  /** Override the parent's method to do nothing. Metal frames do not have system menus. */
  protected void assembleSystemMenu() {}

  /** Override the parent's method to do nothing. Metal frames do not have system menus. */
  protected void addSystemMenuItems(JMenu systemMenu) {}

  /** Override the parent's method to do nothing. Metal frames do not have system menus. */
  protected void showSystemMenu() {}

  /**
   * Override the parent's method avoid creating a menu bar. Metal frames do not have system menus.
   */
  protected void addSubComponents() {
    add(iconButton);
    add(maxButton);
    add(closeButton);
  }

  protected PropertyChangeListener createPropertyChangeListener() {
    return new MetalPropertyChangeHandler();
  }

  protected LayoutManager createLayout() {
    return new MetalTitlePaneLayout();
  }

  class MetalPropertyChangeHandler extends BasicInternalFrameTitlePane.PropertyChangeHandler {
    public void propertyChange(PropertyChangeEvent evt) {
      String prop = (String) evt.getPropertyName();
      if (prop.equals(JInternalFrame.IS_SELECTED_PROPERTY)) {
        Boolean b = (Boolean) evt.getNewValue();
        iconButton.putClientProperty("paintActive", b);
        closeButton.putClientProperty("paintActive", b);
        maxButton.putClientProperty("paintActive", b);
      } else if ("JInternalFrame.messageType".equals(prop)) {
        updateOptionPaneState();
        frame.repaint();
      }
      super.propertyChange(evt);
    }
  }

  class MetalTitlePaneLayout extends TitlePaneLayout {
    public void addLayoutComponent(String name, Component c) {}

    public void removeLayoutComponent(Component c) {}

    public Dimension preferredLayoutSize(Container c) {
      return minimumLayoutSize(c);
    }

    public Dimension minimumLayoutSize(Container c) {
      // Compute width.
      int width = 30;
      if (frame.isClosable()) {
        width += 21;
      }
      if (frame.isMaximizable()) {
        width += 16 + (frame.isClosable() ? 10 : 4);
      }
      if (frame.isIconifiable()) {
        width += 16 + (frame.isMaximizable() ? 2 : (frame.isClosable() ? 10 : 4));
      }
      FontMetrics fm = frame.getFontMetrics(getFont());
      String frameTitle = frame.getTitle();
      int title_w = frameTitle != null ? SwingUtilities2.stringWidth(frame, fm, frameTitle) : 0;
      int title_length = frameTitle != null ? frameTitle.length() : 0;

      if (title_length > 2) {
        int subtitle_w =
            SwingUtilities2.stringWidth(frame, fm, frame.getTitle().substring(0, 2) + "...");
        width += (title_w < subtitle_w) ? title_w : subtitle_w;
      } else {
        width += title_w;
      }

      // Compute height.
      int height = 0;
      if (isPalette) {
        height = paletteTitleHeight;
      } else {
        int fontHeight = fm.getHeight();
        fontHeight += 7;
        Icon icon = frame.getFrameIcon();
        int iconHeight = 0;
        if (icon != null) {
          // SystemMenuBar forces the icon to be 16x16 or less.
          iconHeight = Math.min(icon.getIconHeight(), 16);
        }
        iconHeight += 5;
        height = Math.max(fontHeight, iconHeight);
      }

      return new Dimension(width, height);
    }

    public void layoutContainer(Container c) {
      boolean leftToRight = MetalUtils.isLeftToRight(frame);

      int w = getWidth();
      int x = leftToRight ? w : 0;
      int y = 2;
      int spacing;

      // assumes all buttons have the same dimensions
      // these dimensions include the borders
      int buttonHeight = closeButton.getIcon().getIconHeight();
      int buttonWidth = closeButton.getIcon().getIconWidth();

      if (frame.isClosable()) {
        if (isPalette) {
          spacing = 3;
          x += leftToRight ? -spacing - (buttonWidth + 2) : spacing;
          closeButton.setBounds(x, y, buttonWidth + 2, getHeight() - 4);
          if (!leftToRight) x += (buttonWidth + 2);
        } else {
          spacing = 4;
          x += leftToRight ? -spacing - buttonWidth : spacing;
          closeButton.setBounds(x, y, buttonWidth, buttonHeight);
          if (!leftToRight) x += buttonWidth;
        }
      }

      if (frame.isMaximizable() && !isPalette) {
        spacing = frame.isClosable() ? 10 : 4;
        x += leftToRight ? -spacing - buttonWidth : spacing;
        maxButton.setBounds(x, y, buttonWidth, buttonHeight);
        if (!leftToRight) x += buttonWidth;
      }

      if (frame.isIconifiable() && !isPalette) {
        spacing = frame.isMaximizable() ? 2 : (frame.isClosable() ? 10 : 4);
        x += leftToRight ? -spacing - buttonWidth : spacing;
        iconButton.setBounds(x, y, buttonWidth, buttonHeight);
        if (!leftToRight) x += buttonWidth;
      }

      buttonsWidth = leftToRight ? w - x : x;
    }
  }

  public void paintPalette(Graphics g) {
    boolean leftToRight = MetalUtils.isLeftToRight(frame);

    int width = getWidth();
    int height = getHeight();

    if (paletteBumps == null) {
      paletteBumps =
          new MetalBumps(
              0,
              0,
              MetalLookAndFeel.getPrimaryControlHighlight(),
              MetalLookAndFeel.getPrimaryControlInfo(),
              MetalLookAndFeel.getPrimaryControlShadow());
    }

    Color background = MetalLookAndFeel.getPrimaryControlShadow();
    Color darkShadow = MetalLookAndFeel.getPrimaryControlDarkShadow();

    g.setColor(background);
    g.fillRect(0, 0, width, height);

    g.setColor(darkShadow);
    g.drawLine(0, height - 1, width, height - 1);

    int xOffset = leftToRight ? 4 : buttonsWidth + 4;
    int bumpLength = width - buttonsWidth - 2 * 4;
    int bumpHeight = getHeight() - 4;
    paletteBumps.setBumpArea(bumpLength, bumpHeight);
    paletteBumps.paintIcon(this, g, xOffset, 2);
  }

  public void paintComponent(Graphics g) {
    if (isPalette) {
      paintPalette(g);
      return;
    }

    boolean leftToRight = MetalUtils.isLeftToRight(frame);
    boolean isSelected = frame.isSelected();

    int width = getWidth();
    int height = getHeight();

    Color background = null;
    Color foreground = null;
    Color shadow = null;

    MetalBumps bumps;
    String gradientKey;

    if (isSelected) {
      if (!MetalLookAndFeel.usingOcean()) {
        closeButton.setContentAreaFilled(true);
        maxButton.setContentAreaFilled(true);
        iconButton.setContentAreaFilled(true);
      }
      if (selectedBackgroundKey != null) {
        background = UIManager.getColor(selectedBackgroundKey);
      }
      if (background == null) {
        background = MetalLookAndFeel.getWindowTitleBackground();
      }
      if (selectedForegroundKey != null) {
        foreground = UIManager.getColor(selectedForegroundKey);
      }
      if (selectedShadowKey != null) {
        shadow = UIManager.getColor(selectedShadowKey);
      }
      if (shadow == null) {
        shadow = MetalLookAndFeel.getPrimaryControlDarkShadow();
      }
      if (foreground == null) {
        foreground = MetalLookAndFeel.getWindowTitleForeground();
      }
      activeBumps.setBumpColors(
          activeBumpsHighlight,
          activeBumpsShadow,
          UIManager.get("InternalFrame.activeTitleGradient") != null ? null : background);
      bumps = activeBumps;
      gradientKey = "InternalFrame.activeTitleGradient";
    } else {
      if (!MetalLookAndFeel.usingOcean()) {
        closeButton.setContentAreaFilled(false);
        maxButton.setContentAreaFilled(false);
        iconButton.setContentAreaFilled(false);
      }
      background = MetalLookAndFeel.getWindowTitleInactiveBackground();
      foreground = MetalLookAndFeel.getWindowTitleInactiveForeground();
      shadow = MetalLookAndFeel.getControlDarkShadow();
      bumps = inactiveBumps;
      gradientKey = "InternalFrame.inactiveTitleGradient";
    }

    if (!MetalUtils.drawGradient(this, g, gradientKey, 0, 0, width, height, true)) {
      g.setColor(background);
      g.fillRect(0, 0, width, height);
    }

    g.setColor(shadow);
    g.drawLine(0, height - 1, width, height - 1);
    g.drawLine(0, 0, 0, 0);
    g.drawLine(width - 1, 0, width - 1, 0);

    int titleLength = 0;
    int xOffset = leftToRight ? 5 : width - 5;
    String frameTitle = frame.getTitle();

    Icon icon = frame.getFrameIcon();
    if (icon != null) {
      if (!leftToRight) xOffset -= icon.getIconWidth();
      int iconY = ((height / 2) - (icon.getIconHeight() / 2));
      icon.paintIcon(frame, g, xOffset, iconY);
      xOffset += leftToRight ? icon.getIconWidth() + 5 : -5;
    }

    if (frameTitle != null) {
      Font f = getFont();
      g.setFont(f);
      FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g, f);
      int fHeight = fm.getHeight();

      g.setColor(foreground);

      int yOffset = ((height - fm.getHeight()) / 2) + fm.getAscent();

      Rectangle rect = new Rectangle(0, 0, 0, 0);
      if (frame.isIconifiable()) {
        rect = iconButton.getBounds();
      } else if (frame.isMaximizable()) {
        rect = maxButton.getBounds();
      } else if (frame.isClosable()) {
        rect = closeButton.getBounds();
      }
      int titleW;

      if (leftToRight) {
        if (rect.x == 0) {
          rect.x = frame.getWidth() - frame.getInsets().right - 2;
        }
        titleW = rect.x - xOffset - 4;
        frameTitle = getTitle(frameTitle, fm, titleW);
      } else {
        titleW = xOffset - rect.x - rect.width - 4;
        frameTitle = getTitle(frameTitle, fm, titleW);
        xOffset -= SwingUtilities2.stringWidth(frame, fm, frameTitle);
      }

      titleLength = SwingUtilities2.stringWidth(frame, fm, frameTitle);
      SwingUtilities2.drawString(frame, g, frameTitle, xOffset, yOffset);
      xOffset += leftToRight ? titleLength + 5 : -5;
    }

    int bumpXOffset;
    int bumpLength;
    if (leftToRight) {
      bumpLength = width - buttonsWidth - xOffset - 5;
      bumpXOffset = xOffset;
    } else {
      bumpLength = xOffset - buttonsWidth - 5;
      bumpXOffset = buttonsWidth + 5;
    }
    int bumpYOffset = 3;
    int bumpHeight = getHeight() - (2 * bumpYOffset);
    bumps.setBumpArea(bumpLength, bumpHeight);
    bumps.paintIcon(this, g, bumpXOffset, bumpYOffset);
  }

  public void setPalette(boolean b) {
    isPalette = b;

    if (isPalette) {
      closeButton.setIcon(paletteCloseIcon);
      if (frame.isMaximizable()) remove(maxButton);
      if (frame.isIconifiable()) remove(iconButton);
    } else {
      closeButton.setIcon(closeIcon);
      if (frame.isMaximizable()) add(maxButton);
      if (frame.isIconifiable()) add(iconButton);
    }
    revalidate();
    repaint();
  }

  /**
   * Updates any state dependant upon the JInternalFrame being shown in a <code>JOptionPane</code>.
   */
  private void updateOptionPaneState() {
    int type = -2;
    boolean closable = wasClosable;
    Object obj = frame.getClientProperty("JInternalFrame.messageType");

    if (obj == null) {
      // Don't change the closable state unless in an JOptionPane.
      return;
    }
    if (obj instanceof Integer) {
      type = ((Integer) obj).intValue();
    }
    switch (type) {
      case JOptionPane.ERROR_MESSAGE:
        selectedBackgroundKey = "OptionPane.errorDialog.titlePane.background";
        selectedForegroundKey = "OptionPane.errorDialog.titlePane.foreground";
        selectedShadowKey = "OptionPane.errorDialog.titlePane.shadow";
        closable = false;
        break;
      case JOptionPane.QUESTION_MESSAGE:
        selectedBackgroundKey = "OptionPane.questionDialog.titlePane.background";
        selectedForegroundKey = "OptionPane.questionDialog.titlePane.foreground";
        selectedShadowKey = "OptionPane.questionDialog.titlePane.shadow";
        closable = false;
        break;
      case JOptionPane.WARNING_MESSAGE:
        selectedBackgroundKey = "OptionPane.warningDialog.titlePane.background";
        selectedForegroundKey = "OptionPane.warningDialog.titlePane.foreground";
        selectedShadowKey = "OptionPane.warningDialog.titlePane.shadow";
        closable = false;
        break;
      case JOptionPane.INFORMATION_MESSAGE:
      case JOptionPane.PLAIN_MESSAGE:
        selectedBackgroundKey = selectedForegroundKey = selectedShadowKey = null;
        closable = false;
        break;
      default:
        selectedBackgroundKey = selectedForegroundKey = selectedShadowKey = null;
        break;
    }
    if (closable != frame.isClosable()) {
      frame.setClosable(closable);
    }
  }
}
  public void paintComponent(Graphics g) {
    if (isPalette) {
      paintPalette(g);
      return;
    }

    boolean leftToRight = MetalUtils.isLeftToRight(frame);
    boolean isSelected = frame.isSelected();

    int width = getWidth();
    int height = getHeight();

    Color background = null;
    Color foreground = null;
    Color shadow = null;

    MetalBumps bumps;
    String gradientKey;

    if (isSelected) {
      if (!MetalLookAndFeel.usingOcean()) {
        closeButton.setContentAreaFilled(true);
        maxButton.setContentAreaFilled(true);
        iconButton.setContentAreaFilled(true);
      }
      if (selectedBackgroundKey != null) {
        background = UIManager.getColor(selectedBackgroundKey);
      }
      if (background == null) {
        background = MetalLookAndFeel.getWindowTitleBackground();
      }
      if (selectedForegroundKey != null) {
        foreground = UIManager.getColor(selectedForegroundKey);
      }
      if (selectedShadowKey != null) {
        shadow = UIManager.getColor(selectedShadowKey);
      }
      if (shadow == null) {
        shadow = MetalLookAndFeel.getPrimaryControlDarkShadow();
      }
      if (foreground == null) {
        foreground = MetalLookAndFeel.getWindowTitleForeground();
      }
      activeBumps.setBumpColors(
          activeBumpsHighlight,
          activeBumpsShadow,
          UIManager.get("InternalFrame.activeTitleGradient") != null ? null : background);
      bumps = activeBumps;
      gradientKey = "InternalFrame.activeTitleGradient";
    } else {
      if (!MetalLookAndFeel.usingOcean()) {
        closeButton.setContentAreaFilled(false);
        maxButton.setContentAreaFilled(false);
        iconButton.setContentAreaFilled(false);
      }
      background = MetalLookAndFeel.getWindowTitleInactiveBackground();
      foreground = MetalLookAndFeel.getWindowTitleInactiveForeground();
      shadow = MetalLookAndFeel.getControlDarkShadow();
      bumps = inactiveBumps;
      gradientKey = "InternalFrame.inactiveTitleGradient";
    }

    if (!MetalUtils.drawGradient(this, g, gradientKey, 0, 0, width, height, true)) {
      g.setColor(background);
      g.fillRect(0, 0, width, height);
    }

    g.setColor(shadow);
    g.drawLine(0, height - 1, width, height - 1);
    g.drawLine(0, 0, 0, 0);
    g.drawLine(width - 1, 0, width - 1, 0);

    int titleLength = 0;
    int xOffset = leftToRight ? 5 : width - 5;
    String frameTitle = frame.getTitle();

    Icon icon = frame.getFrameIcon();
    if (icon != null) {
      if (!leftToRight) xOffset -= icon.getIconWidth();
      int iconY = ((height / 2) - (icon.getIconHeight() / 2));
      icon.paintIcon(frame, g, xOffset, iconY);
      xOffset += leftToRight ? icon.getIconWidth() + 5 : -5;
    }

    if (frameTitle != null) {
      Font f = getFont();
      g.setFont(f);
      FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g, f);
      int fHeight = fm.getHeight();

      g.setColor(foreground);

      int yOffset = ((height - fm.getHeight()) / 2) + fm.getAscent();

      Rectangle rect = new Rectangle(0, 0, 0, 0);
      if (frame.isIconifiable()) {
        rect = iconButton.getBounds();
      } else if (frame.isMaximizable()) {
        rect = maxButton.getBounds();
      } else if (frame.isClosable()) {
        rect = closeButton.getBounds();
      }
      int titleW;

      if (leftToRight) {
        if (rect.x == 0) {
          rect.x = frame.getWidth() - frame.getInsets().right - 2;
        }
        titleW = rect.x - xOffset - 4;
        frameTitle = getTitle(frameTitle, fm, titleW);
      } else {
        titleW = xOffset - rect.x - rect.width - 4;
        frameTitle = getTitle(frameTitle, fm, titleW);
        xOffset -= SwingUtilities2.stringWidth(frame, fm, frameTitle);
      }

      titleLength = SwingUtilities2.stringWidth(frame, fm, frameTitle);
      SwingUtilities2.drawString(frame, g, frameTitle, xOffset, yOffset);
      xOffset += leftToRight ? titleLength + 5 : -5;
    }

    int bumpXOffset;
    int bumpLength;
    if (leftToRight) {
      bumpLength = width - buttonsWidth - xOffset - 5;
      bumpXOffset = xOffset;
    } else {
      bumpLength = xOffset - buttonsWidth - 5;
      bumpXOffset = buttonsWidth + 5;
    }
    int bumpYOffset = 3;
    int bumpHeight = getHeight() - (2 * bumpYOffset);
    bumps.setBumpArea(bumpLength, bumpHeight);
    bumps.paintIcon(this, g, bumpXOffset, bumpYOffset);
  }
 protected Image createCrayonsImage() {
   return (Image) UIManager.get("ColorChooser.crayonsImage");
 }