<commit_before>/*
 * $Id$
 *
 * 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.HotKeyConfigurer;
import VASSAL.configure.IconConfigurer;
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 KeyStrokeListener 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 KeyStrokeListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        if (isEnabled() && getParent() != null && getParent().isShowing()) {
          al.actionPerformed(e);
        }
      }
    });
    GameModule.getGameModule().addKeyStrokeListener(keyListener);
    addActionListener(al);
  }

  protected void fireActionPerformed(ActionEvent event) {
    super.fireActionPerformed(event);
    GameModule.getGameModule().getChatter().getInputField().requestFocus();
  }

  public String getNameAttribute() {
    return nameAtt;
  }

  public String getHotkeyAttribute() {
    return keyAtt;<commit_msg>Bug fix:  ToolbarMenu losing focus immediately in separate Map Window<commit_after>/*
 * $Id$
 *
 * 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.Component;
import java.awt.KeyboardFocusManager;
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.HotKeyConfigurer;
import VASSAL.configure.IconConfigurer;
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 KeyStrokeListener 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 KeyStrokeListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        if (isEnabled() && getParent() != null && getParent().isShowing()) {
          al.actionPerformed(e);
        }
      }
    });
    GameModule.getGameModule().addKeyStrokeListener(keyListener);
    addActionListener(al);
  }

  protected void fireActionPerformed(ActionEvent event) {
    // Return focus to the previously-focused component
    // This prevents annoying change of focus after hitting the hotkey for this LaunchButton
    Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    super.fireActionPerformed(event);
    if (c != null) {
      c.requestFocus();
    }
  }

  public String getNameAttribute() {
    return nameAtt;
  }

  public String getHotkeyAttribute() {
    return keyAtt;
{'fraction_non_alphanumeric': 0.07812966835972512, 'fraction_numerical': 0.004780400358530027, 'mean_word_length': 4.033834586466165, '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': '3371801', 'n_tokens_mistral': 1834, 'n_tokens_neox': 1776, 'n_words': 583}