<commit_before>/* ###
 * IP: GHIDRA
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ghidra.app.plugin.core.select;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.math.BigInteger;

import javax.swing.*;

import docking.ComponentProvider;
import docking.DialogComponentProvider;
import docking.widgets.button.GRadioButton;
import docking.widgets.label.GLabel;
import docking.widgets.textfield.IntegerTextField;
import ghidra.app.nav.Navigatable;
import ghidra.app.nav.NavigationUtils;
import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.address.*;
import ghidra.program.util.ProgramSelection;
import ghidra.util.HelpLocation;

/**
 * Class to set up dialog box that will enable the user
 * to set the available options for block selection
 */
class SelectBlockDialog extends DialogComponentProvider {
	private static final String OVERFLOW_SELECTION_WARNING =
		"Selection is larger than available " + "bytes, using the end of the address space";

	private JTextField toAddressField;
	private IntegerTextField numberInputField; // AddressInput allows decimal and hex input 
	private JRadioButton forwardButton;
	private JRadioButton backwardButton;
	private JRadioButton allButton;
	private JRadioButton toButton;
	private Navigatable navigatable;
	private PluginTool tool;

	SelectBlockDialog(PluginTool tool, Navigatable navigatable) {
		super("Select Bytes", false);
		this.tool = tool;
		this.navigatable = navigatable;
//		navigatable.addNavigatableListener(this);

		addWorkPanel(buildPanel());
		addOKButton();
		setOkButtonText("Select Bytes");
		addDismissButton();
		setHelpLocation(new HelpLocation("SelectBlockPlugin", "Select_Block_Help"));

		// make sure the state of the widgets is correct
		setItemsEnabled(false);
		forwardButton.doClick();
	}

	private JPanel buildPanel() {
		setDefaultButton(okButton);
		JPanel mainPanel = new JPanel();
		mainPanel.setLayout(new GridBagLayout());
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.insets = new Insets(2, 2, 2, 2);
		gbc.gridx = 0;
		gbc.gridy = 0;
		mainPanel.add(methodPanel(), gbc);
		gbc.gridx++;
		mainPanel.add(buildBlockPanel(), gbc);

		return mainPanel;
	}

	private JPanel buildBlockPanel() {
		JPanel main = new JPanel();
		main.setBorder(BorderFactory.createTitledBorder("Byte Selection"));
		main.setLayout(new GridBagLayout());
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.insets = new Insets(2, 2, 2, 2);
		gbc.anchor = GridBagConstraints.WEST;
		gbc.gridx = 0;
		gbc.gridy = 0;

		main.add(new GLabel("Ending Address:"), gbc);
		gbc.gridx++;
		toAddressField = new JTextField(10);
		main.add(toAddressField, gbc);
		gbc.gridx = 0;
		gbc.gridy++;
		main.add(new GLabel("Length: "), gbc);
		gbc.gridx++;
		numberInputField = new IntegerTextField(10);
		numberInputField.setMaxValue(BigInteger.valueOf(Integer.MAX_VALUE));
		numberInputField.setAllowNegativeValues(false);
		main.add(numberInputField.getComponent(), gbc);
		return main;
	}

	private JPanel methodPanel() {
		ButtonGroup buttonGroup = new ButtonGroup();
		JPanel main = new JPanel();
		main.setBorder(BorderFactory.createTitledBorder("By Method"));
		main.setLayout(new GridBagLayout());
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.insets = new Insets(2, 2, 2, 2);
		gbc.anchor = GridBagConstraints.WEST;
<commit_msg>Corrected issue with the Select Bytes dialog resizing strangely.<commit_after>/* ###
 * IP: GHIDRA
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ghidra.app.plugin.core.select;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.math.BigInteger;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

import docking.ComponentProvider;
import docking.DialogComponentProvider;
import docking.widgets.button.GRadioButton;
import docking.widgets.label.GLabel;
import docking.widgets.textfield.IntegerTextField;
import ghidra.app.nav.Navigatable;
import ghidra.app.nav.NavigationUtils;
import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressFactory;
import ghidra.program.model.address.AddressFormatException;
import ghidra.program.model.address.AddressOutOfBoundsException;
import ghidra.program.model.address.AddressRange;
import ghidra.program.model.address.AddressRangeIterator;
import ghidra.program.model.address.AddressSet;
import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.address.AddressSpace;
import ghidra.program.model.address.OverlayAddressSpace;
import ghidra.program.util.ProgramSelection;
import ghidra.util.HelpLocation;
import ghidra.util.layout.PairLayout;

/**
 * Class to set up dialog box that will enable the user
 * to set the available options for block selection
 */
class SelectBlockDialog extends DialogComponentProvider {
	private static final String OVERFLOW_SELECTION_WARNING =
		"Selection is larger than available " + "bytes, using the end of the address space";

	private JTextField toAddressField;
	private IntegerTextField numberInputField; // AddressInput allows decimal and hex input 
	private JRadioButton forwardButton;
	private JRadioButton backwardButton;
	private JRadioButton allButton;
	private JRadioButton toButton;
	private Navigatable navigatable;
	private PluginTool tool;

	SelectBlockDialog(PluginTool tool, Navigatable navigatable) {
		super("Select Bytes", false);
		this.tool = tool;
		this.navigatable = navigatable;
//		navigatable.addNavigatableListener(this);

		addWorkPanel(buildPanel());
		addOKButton();
		setOkButtonText("Select Bytes");
		addDismissButton();
		setHelpLocation(new HelpLocation("SelectBlockPlugin", "Select_Block_Help"));

		// make sure the state of the widgets is correct
		setItemsEnabled(false);
		forwardButton.doClick();
	}

	private JPanel buildPanel() {
		setDefaultButton(okButton);
		JPanel mainPanel = new JPanel();
		mainPanel.setLayout(new GridBagLayout());
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.insets = new Insets(2, 2, 2, 2);
		gbc.gridx = 0;
		gbc.gridy = 0;
		mainPanel.add(methodPanel(), gbc);
		gbc.gridx++;
		mainPanel.add(buildBlockPanel(), gbc);

		return mainPanel;
	}

	private JPanel buildBlockPanel() {
		JPanel main = new JPanel();
		main.setBorder(BorderFactory.createTitledBorder("Byte Selection"));
		
		main.setLayout(new PairLayout());

		main.add(new GLabel("Ending Address:"));
		toAddressField = new JTextField(10);
		main.add(toAddressField);

		main.add(new GLabel("Length: "));
		numberInputField = new IntegerTextField(10);
		numberInputField.setMaxValue(BigInteger.valueOf(Integer.MAX_VALUE));
		numberInputField.setAllowNegativeValues(false);
		main.add(numberInputField.getComponent());
		return main;
	}

	private JPanel methodPanel() {
		ButtonGroup buttonGroup = new ButtonGroup();
		JPanel main = new JPanel();
		main.setBorder(BorderFactory.createTitledBorder("By Method"));
		main.setLayout(new GridBagLayout());
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.insets = new Insets(2, 2, 2, 2);
		gbc.anchor = GridBagConstraints.WEST;

{'fraction_non_alphanumeric': 0.10009487666034156, 'fraction_numerical': 0.0050996204933586335, 'mean_word_length': 5.307404637247569, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '144211', 'n_tokens_mistral': 2648, 'n_tokens_neox': 2477, 'n_words': 675}