<commit_before>package org.yamcs.ui.packetviewer;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Properties;
import java.util.prefs.Preferences;

import javax.naming.ConfigurationException;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JRootPane;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.SwingConstants;

import org.yamcs.YConfiguration;
import org.yamcs.client.ClientException;
import org.yamcs.client.YamcsClient;
import org.yamcs.protobuf.YamcsInstance;

/**
 * Dialog for entering yamcs connection parameters.
 * 
 * @author nm
 *
 */
public class ConnectDialog extends JDialog implements ActionListener {

    private static final long serialVersionUID = 1L;
    private static final String PREF_FILENAME = "YamcsConnectionProperties"; // relative to the <home>/.yamcs directory

    private String PREF_HOST = "host";
    private String PREF_PORT = "port";
    private String PREF_TLS = "tls";
    private String PREF_CONTEXT_PATH = "contextPath";
    private String PREF_USERNAME = "username";
    private String PREF_INSTANCE = "instance";

    private String host;
    private Integer port;
    private Boolean tls;
    private String contextPath;
    private String username;
    private String password;
    private String instance;

    JTextField hostTextField;
    JTextField portTextField;
    JCheckBox tlsCheckBox;
    JTextField contextPathTextField;
    JTextField usernameTextField;
    private JPasswordField passwordTextField;

    private JComboBox<String> instanceCombo;
    private JComboBox<String> localMdbConfigCombo;
    boolean getInstance = false;
    boolean getStreamName = false;

    String dbConfig;
    boolean isDbConfigLocal;
    int returnValue;
    Preferences prefs;
    boolean useServerMdb;
    JTextField streamName;

    /**
     * Return value if cancel is chosen.
     */
    public static final int CANCEL_OPTION = 1;

    /**
     * Return value if approve (yes, ok) is chosen.
     */
    public static final int APPROVE_OPTION = 0;

    private void loadConnectionPreferences() throws FileNotFoundException, IOException {
        String home = System.getProperty("user.home") + "/.yamcs";
        Properties prefs = new Properties();
        try (InputStream in = new FileInputStream(new File(home, PREF_FILENAME))) {
            prefs.load(in);
        }

        host = prefs.getProperty(PREF_HOST);
        try {
            port = Integer.parseInt(prefs.getProperty(PREF_PORT));
        } catch (NumberFormatException e) {
        }

        instance = prefs.getProperty(PREF_INSTANCE);
        if (prefs.containsKey(PREF_USERNAME)) {
            username = prefs.getProperty(PREF_USERNAME);
            password = <PASSWORD>;
        }
        contextPath = prefs.getProperty("contextPath", PREF_CONTEXT_PATH);
        tls = Boolean.parseBoolean(prefs.getProperty("tls", "false"));
    }

    private void saveConnectionPreferences() {
        String home = System.getProperty("user.home") + "/.yamcs";
        new File(home).mkdirs();
        Properties prefs = new Properties();
        if (host != null) {
            prefs.setProperty(PREF_HOST, host);
        }
        if (port != null) {
            prefs.setProperty(PREF_PORT, Integer.toString(port));
        }
        if (tls != null) {
            prefs.setProperty(PREF_TLS, Boolean.toString(tls));
        }
        if (contextPath != null) {
            prefs.setProperty(PREF_CONTEXT_PATH, contextPath);
        }
        if (instance != null) {
            prefs.setProperty(PREF_INSTANCE, instance);
        }<commit_msg>fix the default value for the context<commit_after>package org.yamcs.ui.packetviewer;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.Properties;
import java.util.prefs.Preferences;

import javax.naming.ConfigurationException;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JRootPane;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.SwingConstants;

import org.yamcs.YConfiguration;
import org.yamcs.client.ClientException;
import org.yamcs.client.YamcsClient;
import org.yamcs.protobuf.YamcsInstance;

/**
 * Dialog for entering yamcs connection parameters.
 * 
 * @author nm
 *
 */
public class ConnectDialog extends JDialog implements ActionListener {

    private static final long serialVersionUID = 1L;
    private static final String PREF_FILENAME = "YamcsConnectionProperties"; // relative to the <home>/.yamcs directory

    private String PREF_HOST = "host";
    private String PREF_PORT = "port";
    private String PREF_TLS = "tls";
    private String PREF_CONTEXT_PATH = "contextPath";
    private String PREF_USERNAME = "username";
    private String PREF_INSTANCE = "instance";

    private String host;
    private Integer port;
    private Boolean tls;
    private String contextPath;
    private String username;
    private String password;
    private String instance;

    JTextField hostTextField;
    JTextField portTextField;
    JCheckBox tlsCheckBox;
    JTextField contextPathTextField;
    JTextField usernameTextField;
    private JPasswordField passwordTextField;

    private JComboBox<String> instanceCombo;
    private JComboBox<String> localMdbConfigCombo;
    boolean getInstance = false;
    boolean getStreamName = false;

    String dbConfig;
    boolean isDbConfigLocal;
    int returnValue;
    Preferences prefs;
    boolean useServerMdb;
    JTextField streamName;

    /**
     * Return value if cancel is chosen.
     */
    public static final int CANCEL_OPTION = 1;

    /**
     * Return value if approve (yes, ok) is chosen.
     */
    public static final int APPROVE_OPTION = 0;

    private void loadConnectionPreferences() throws FileNotFoundException, IOException {
        String home = System.getProperty("user.home") + "/.yamcs";
        Properties prefs = new Properties();
        try (InputStream in = new FileInputStream(new File(home, PREF_FILENAME))) {
            prefs.load(in);
        }

        host = prefs.getProperty(PREF_HOST);
        try {
            port = Integer.parseInt(prefs.getProperty(PREF_PORT));
        } catch (NumberFormatException e) {
        }

        instance = prefs.getProperty(PREF_INSTANCE);
        if (prefs.containsKey(PREF_USERNAME)) {
            username = prefs.getProperty(PREF_USERNAME);
            password = <PASSWORD>;
        }
        contextPath = prefs.getProperty(PREF_CONTEXT_PATH, null);
        tls = Boolean.parseBoolean(prefs.getProperty("tls", "false"));
    }

    private void saveConnectionPreferences() {
        String home = System.getProperty("user.home") + "/.yamcs";
        new File(home).mkdirs();
        Properties prefs = new Properties();
        if (host != null) {
            prefs.setProperty(PREF_HOST, host);
        }
        if (port != null) {
            prefs.setProperty(PREF_PORT, Integer.toString(port));
        }
        if (tls != null) {
            prefs.setProperty(PREF_TLS, Boolean.toString(tls));
        }
        if (contextPath != null) {
            prefs.setProperty(PREF_CONTEXT_PATH, contextPath);
        }
        if (instance != null) {
            prefs.setProperty(PREF_INSTANCE, instance);
        }
{'fraction_non_alphanumeric': 0.09410190656706434, 'fraction_numerical': 0.0006689708997658602, 'mean_word_length': 3.394904458598726, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6080427', 'n_tokens_mistral': 2564, 'n_tokens_neox': 2556, 'n_words': 622}