<commit_before>/*
 *
 * Copyright (c) 2000-2003 by <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License (LGPL) as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, copies are available
 * at http://www.opensource.org.
 */
package VASSAL.tools;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.KeyStroke;

import VASSAL.build.GameModule;
import VASSAL.configure.Configurer;
import VASSAL.configure.IconConfigurer;
import VASSAL.configure.NamedHotKeyConfigurer;
import VASSAL.configure.StringConfigurer;
import VASSAL.i18n.Localization;
import VASSAL.i18n.Resources;

/**
 * A JButton for placing into a VASSAL component's toolbar.
 * Handles configuration of a hotkey shortcut, maintains appropriate
 * tooltip text, etc.
 */
public class LaunchButton extends JButton {
  private static final long serialVersionUID = 1L;
  public static final String UNTRANSLATED_TEXT = "unTranslatedText"; //$NON-NLS-1$
  protected String tooltipAtt;
  protected String nameAtt;
  protected String keyAtt;
  protected String iconAtt;
  protected IconConfigurer iconConfig;
  protected String toolTipText;
  protected NamedKeyStrokeListener keyListener;
  protected Configurer nameConfig, keyConfig;

  public LaunchButton(String text, String textAttribute,
                      String hotkeyAttribute, ActionListener al) {
    this(text, textAttribute, hotkeyAttribute, null, al);
  }

  public LaunchButton(String text, String tooltipAttribute,
                      String textAttribute, String hotkeyAttribute,
                      String iconAttribute, final ActionListener al) {
    this(text, textAttribute, hotkeyAttribute, iconAttribute, al);
    tooltipAtt = tooltipAttribute;
  }

  public LaunchButton(String text, String textAttribute, String hotkeyAttribute, String iconAttribute, final ActionListener al) {
    super(text);
    nameAtt = textAttribute;
    keyAtt = hotkeyAttribute;
    iconAtt = iconAttribute;
    iconConfig = new IconConfigurer(iconAtt, null, null);
    setAlignmentY(0.0F);
    keyListener = new NamedKeyStrokeListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        if (isEnabled() && getParent() != null && getParent().isShowing()) {
          al.actionPerformed(e);
        }
      }
    });
    if (al != null) {
      GameModule.getGameModule().addKeyStrokeListener(keyListener);
      addActionListener(al);
    }
    setFocusable(false);
    checkVisibility();
  }

  public String getNameAttribute() {<commit_msg>Stop setting a baseline for LaunchButtons; what's reported by the underlying Swing machinery doesn't match up neatly when the labels are a mix of nothing, HTML, and HTML having multiple lines.<commit_after>/*
 *
 * Copyright (c) 2000-2003 by <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License (LGPL) as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, copies are available
 * at http://www.opensource.org.
 */
package VASSAL.tools;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.KeyStroke;

import VASSAL.build.GameModule;
import VASSAL.configure.Configurer;
import VASSAL.configure.IconConfigurer;
import VASSAL.configure.NamedHotKeyConfigurer;
import VASSAL.configure.StringConfigurer;
import VASSAL.i18n.Localization;
import VASSAL.i18n.Resources;

/**
 * A JButton for placing into a VASSAL component's toolbar.
 * Handles configuration of a hotkey shortcut, maintains appropriate
 * tooltip text, etc.
 */
public class LaunchButton extends JButton {
  private static final long serialVersionUID = 1L;
  public static final String UNTRANSLATED_TEXT = "unTranslatedText"; //$NON-NLS-1$
  protected String tooltipAtt;
  protected String nameAtt;
  protected String keyAtt;
  protected String iconAtt;
  protected IconConfigurer iconConfig;
  protected String toolTipText;
  protected NamedKeyStrokeListener keyListener;
  protected Configurer nameConfig, keyConfig;

  public LaunchButton(String text, String textAttribute,
                      String hotkeyAttribute, ActionListener al) {
    this(text, textAttribute, hotkeyAttribute, null, al);
  }

  public LaunchButton(String text, String tooltipAttribute,
                      String textAttribute, String hotkeyAttribute,
                      String iconAttribute, final ActionListener al) {
    this(text, textAttribute, hotkeyAttribute, iconAttribute, al);
    tooltipAtt = tooltipAttribute;
  }

  public LaunchButton(String text, String textAttribute, String hotkeyAttribute, String iconAttribute, final ActionListener al) {
    super(text);
    nameAtt = textAttribute;
    keyAtt = hotkeyAttribute;
    iconAtt = iconAttribute;
    iconConfig = new IconConfigurer(iconAtt, null, null);
    setAlignmentY(0.0F);
    keyListener = new NamedKeyStrokeListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        if (isEnabled() && getParent() != null && getParent().isShowing()) {
          al.actionPerformed(e);
        }
      }
    });
    if (al != null) {
      GameModule.getGameModule().addKeyStrokeListener(keyListener);
      addActionListener(al);
    }
    setFocusable(false);
    checkVisibility();
  }

  @Override
  public int getBaseline(int width, int height) {
    // Without this, buttons with no text, buttons with single line HTML text,
    // and buttons with multiline HTML text end up having different baselines.
    // LaunchButtons go into toolbars only, so there should be no allignment
    // issues caused by indicating that the baseline is non-applicable.
    return -1;
  }

  public String getNameAttribute() {
{'fraction_non_alphanumeric': 0.0756797583081571, 'fraction_numerical': 0.004984894259818731, 'mean_word_length': 3.879145173176124, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4666383', 'n_tokens_mistral': 1803, 'n_tokens_neox': 1742, 'n_words': 624}