<commit_before>/*
 * @(#)GlacierFrame.java  0.6 2013 May 5
 * 
 * Copyright (c) 2013 Amherst Robots, Inc.
 * All rigts reserved.
 * 
 * See LICENSE file accompanying this file.
 */
package com.vrane.metaGlacier.gui;

import com.vrane.metaGlacier.HumanBytes;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.services.glacier.AmazonGlacierClient;
import com.vrane.desktop.MainFrame;
import com.vrane.encryption.Encryption;
import com.vrane.metaGlacier.Main;
import com.vrane.metaGlacier.gui.search.SearchDialog;
import com.vrane.metaGlacierSDK.GlacierMetadata;
import com.vrane.metaGlacierSDK.MetadataProviderCredentials;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.UnknownHostException;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.Preferences;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JTextField;
import javax.swing.SwingWorker;

/**
 * This JFrame class creates the menu as well as providing an interface to account credentials.
 * Both AWS and metadata account credentials are provided by this interface.
 * It also initializes and saves various user settings. 
 * 
 * @author <NAME>
 */
public class GlacierFrame extends MainFrame
        implements AWSCredentials, MetadataProviderCredentials {
    
    static Encryption encryptionObj;
    
    private final static Logger LGR =
            Main.getLogger(GlacierFrame.class);
    
    private static String accessKeyString = "";
    private static String secretKeyString = "";
    private static String metadataUser = "";
    private static String metadataPassword = "";
    private static String computer_id;
    private static String selectedRegion = "";
    private static Level selectedLogLevel = Level.OFF;
    
    private final static String DEFAULT_COMPUTER_ID
            = "meta-glacier-software-computer";
    private final static String[] LEVEL_STRING 
            = {"off", "warning", "info", "verbose"};
    private final static Level[] LOG_LEVELS
            = {Level.OFF, Level.WARNING, Level.INFO, Level.FINE};
    private final static String SAVED_LOG_LEVEL = "saved log level";
    private final static int MS_IN_A_DAY = 86400000;
    private final static short COMPUTER_ID_LENGTH = 256;
    private final static byte[] ENCRYPTION_KEY
            = {38,-16,16,-45,74,-105,-3,26,10,17};
    private final static String SHOW_LOG_WINDOW_KEY = "hide log panel";
    private final static String AWS_ACCESS_KEY = "aws access";
    private final static String AWS_SECRET_KEY = "aws secret";
    private final static String METADATA_USER_KEY = "metadata username";
    private final static String METADATA_PASSWORD_KEY = "<PASSWORD>";
    private final static String REGION_KEY = "region";
    private final static String DISCARD_PHOTO_METADATA = "save photo metadata";
    private final static String COMPUTER_ID_KEY_LOCAL = "computer id";
    private final static String ALWAYS_GET_METADATA = "always get metadata";
    private final static String NUMBER_OF_AWS_API_CALLS
            = "number of aws api calls";
    private final static String GRANULARITY_KEY = "granularity";
    private final static String SHOW_DELETED_KEY = "show deleted";
    private final static MainPanel MAIN_PANEL = new MainPanel();

    private final static String LAST_AWS_API_CALL_RESET
            = "last time stamp of aws api call";
    private final static Preferences P
            = Preferences.userNodeForPackage(GlacierFrame.class);
    private final static String[] REGIONS
            = {"us-west-2", "us-west-1", "us-east-1", "eu-west-1", 
                "ap-northeast-1"};
    private final static String[] REGION_DESC
                = {"US West Oregon", "US West N California",
                    "US East N Virginia", "Ireland", "Tokyo"};
    private final static int[] GRANULARITIES
            = { (int)HumanBytes.MEGA, 2 * (int) HumanBytes.MEGA};
    private final static String[] GRANULARITY_STRINGS
            = { HumanBytes.convert(HumanBytes.MEGA),
                    HumanBytes.convert(HumanBytes.MEGA * 2)};
    private static SearchDialog search_dialog;
    
    private final JMenuItem SHOW_LOG_PANEL_MENU_ITEM
            = new JCheckBoxMenuItem("Show log window");
    private final JMenuItem SHOW_DELETED_ARCHIVES
            = new JCheckBoxMenuItem("Show deleted archives");
    private final JMenuItem alwaysGetMetadataMenuItem
            = new JCheckBoxMenuItem("Always get metadata");
    private final JMenuItem SAVE_PHOTO_MENU
            = new JCheckBoxMenuItem("Save photo-metadata");
    private final JMenuItem USE_SYSTEM_UI
            = new JCheckBoxMenuItem("Use System Theme");
    private final JMenuBar MENU_BAR = new JMenuBar();
    private final JMenu SETUP_PANEL = new JMenu("Set up");
    private final JMenu PREF_PANEL = new JMenu("Preferences");
    private final JMenuItem MANAGE_ACCOUNT = new JMenuItem("AWS account");
    private final JMenu REGION_MENU = new JMenu("Select region");
    private final ButtonGroup REGION_GROUPS = new ButtonGroup();
    private final ButtonGroup GRANULARITY_GROUP = new ButtonGroup();
    private final JMenu GRANULARITY_MENU = new JMenu("Granularity");
    private final JMenuItem metadataSignup
            = new JMenuItem("Sign up metadata account");
    private final JMenuItem COMPUTER_MENUITEM
            = new JMenuItem("Computer identifier");
    private final JMenuItem STAT_RESET_MENUITEM
            = new JMenuItem("Reset statistics");
    private final JMenu AWS_MENU = new JMenu("Glacier");
    private final JMenuItem BROWSE_MENU_ITEM = new JMenuItem("Browse");<commit_msg>allow no multipart upload and increase part size since AWS charges each call to multipart upload as one API call. For a very large file, breaking down into small part size will mean lots of API calls.<commit_after>/*
 * @(#)GlacierFrame.java  0.6 2013 May 5
 * 
 * Copyright (c) 2013 Amherst Robots, Inc.
 * All rigts reserved.
 * 
 * See LICENSE file accompanying this file.
 */
package com.vrane.metaGlacier.gui;

import com.vrane.metaGlacier.HumanBytes;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.services.glacier.AmazonGlacierClient;
import com.vrane.desktop.MainFrame;
import com.vrane.encryption.Encryption;
import com.vrane.metaGlacier.Main;
import com.vrane.metaGlacier.gui.search.SearchDialog;
import com.vrane.metaGlacierSDK.GlacierMetadata;
import com.vrane.metaGlacierSDK.MetadataProviderCredentials;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.UnknownHostException;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.Preferences;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JTextField;
import javax.swing.SwingWorker;

/**
 * This JFrame class creates the menu as well as providing an interface to account credentials.
 * Both AWS and metadata account credentials are provided by this interface.
 * It also initializes and saves various user settings. 
 * 
 * @author <NAME>
 */
public class GlacierFrame extends MainFrame
        implements AWSCredentials, MetadataProviderCredentials {
    
    static Encryption encryptionObj;
    
    private final static Logger LGR =
            Main.getLogger(GlacierFrame.class);
    
    private static String accessKeyString = "";
    private static String secretKeyString = "";
    private static String metadataUser = "";
    private static String metadataPassword = "";
    private static String computer_id;
    private static String selectedRegion = "";
    private static Level selectedLogLevel = Level.OFF;
    
    private final static String DEFAULT_COMPUTER_ID
            = "meta-glacier-software-computer";
    private final static String[] LEVEL_STRING 
            = {"off", "warning", "info", "verbose"};
    private final static Level[] LOG_LEVELS
            = {Level.OFF, Level.WARNING, Level.INFO, Level.FINE};
    private final static String SAVED_LOG_LEVEL = "saved log level";
    private final static int MS_IN_A_DAY = 86400000;
    private final static short COMPUTER_ID_LENGTH = 256;
    private final static byte[] ENCRYPTION_KEY
            = {38,-16,16,-45,74,-105,-3,26,10,17};
    private final static String SHOW_LOG_WINDOW_KEY = "hide log panel";
    private final static String AWS_ACCESS_KEY = "aws access";
    private final static String AWS_SECRET_KEY = "aws secret";
    private final static String METADATA_USER_KEY = "metadata username";
    private final static String METADATA_PASSWORD_KEY = "<PASSWORD>";
    private final static String REGION_KEY = "region";
    private final static String DISCARD_PHOTO_METADATA = "save photo metadata";
    private final static String COMPUTER_ID_KEY_LOCAL = "computer id";
    private final static String ALWAYS_GET_METADATA = "always get metadata";
    private final static String NUMBER_OF_AWS_API_CALLS
            = "number of aws api calls";
    private final static String GRANULARITY_KEY = "granularity";
    private final static String SHOW_DELETED_KEY = "show deleted";
    private final static MainPanel MAIN_PANEL = new MainPanel();

    private final static String LAST_AWS_API_CALL_RESET
            = "last time stamp of aws api call";
    private final static Preferences P
            = Preferences.userNodeForPackage(GlacierFrame.class);
    private final static String[] REGIONS
            = {"us-west-2", "us-west-1", "us-east-1", "eu-west-1", 
                "ap-northeast-1"};
    private final static String[] REGION_DESC
                = {"US West Oregon", "US West N California",
                    "US East N Virginia", "Ireland", "Tokyo"};
    private final static int[] GRANULARITIES
            = { 0, 8 * (int)HumanBytes.MEGA, 256 * (int) HumanBytes.MEGA};
    private final static String[] GRANULARITY_STRINGS
            = { "No multipart upload", HumanBytes.convert( 8 * HumanBytes.MEGA),
                    HumanBytes.convert(HumanBytes.MEGA * 256)};
    private static SearchDialog search_dialog;
    
    private final JMenuItem SHOW_LOG_PANEL_MENU_ITEM
            = new JCheckBoxMenuItem("Show log window");
    private final JMenuItem SHOW_DELETED_ARCHIVES
            = new JCheckBoxMenuItem("Show deleted archives");
    private final JMenuItem alwaysGetMetadataMenuItem
            = new JCheckBoxMenuItem("Always get metadata");
    private final JMenuItem SAVE_PHOTO_MENU
            = new JCheckBoxMenuItem("Save photo-metadata");
    private final JMenuItem USE_SYSTEM_UI
            = new JCheckBoxMenuItem("Use System Theme");
    private final JMenuBar MENU_BAR = new JMenuBar();
    private final JMenu SETUP_PANEL = new JMenu("Set up");
    private final JMenu PREF_PANEL = new JMenu("Preferences");
    private final JMenuItem MANAGE_ACCOUNT = new JMenuItem("AWS account");
    private final JMenu REGION_MENU = new JMenu("Select region");
    private final ButtonGroup REGION_GROUPS = new ButtonGroup();
    private final ButtonGroup GRANULARITY_GROUP = new ButtonGroup();
    private final JMenu GRANULARITY_MENU = new JMenu("Granularity");
    private final JMenuItem metadataSignup
            = new JMenuItem("Sign up metadata account");
    private final JMenuItem COMPUTER_MENUITEM
            = new JMenuItem("Computer identifier");
    private final JMenuItem STAT_RESET_MENUITEM
            = new JMenuItem("Reset statistics");
    private final JMenu AWS_MENU = new JMenu("Glacier");
    private final JMenuItem BROWSE_MENU_ITEM = new JMenuItem("Browse");
{'fraction_non_alphanumeric': 0.08256074168797954, 'fraction_numerical': 0.008391943734015346, 'mean_word_length': 3.7577946768060837, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1077791', 'n_tokens_mistral': 3659, 'n_tokens_neox': 3504, 'n_words': 1060}