text:
package com.beardedhen.bhbrowser.lib;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.beardedhen.androidbootstrap.FontAwesomeText;
import com.beardedhen.bhbrowser.R;

import java.util.List;

/**
 * A view that displays a List of FolderItems to the user
 */
public class FileBrowserView extends LinearLayout implements DirectoryView {

    public interface BrowserViewListener {
        /**
         * Callback for when the user clicks the Up navigation control
         */
        public void onUpClicked();

        public void onSelectClicked();

        /**
         * Callback for when the user selects an item to navigate to in the current dir
         *
         * @param navigationItem a folderitem
         */
        public void onNavigationItemClicked(FolderItem navigationItem);
    }

    private BrowserViewListener listener;
    private ListView listView;
    private TextView currentDirectory;
    private TextView browserTitle;
    private View backButton;
    private View selectControl;
    private View selectContainer;

    public FileBrowserView(Context context) {
        super(context);
        init();
    }

    public FileBrowserView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public FileBrowserView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {
        LayoutInflater inflater = LayoutInflater.from(getContext());
        View view = inflater.inflate(R.layout.view_file_browser, this, false);

        this.addView(view);
        listView = (ListView) view.findViewById(R.id.browser_list_view);
        currentDirectory = (TextView) view.findViewById(R.id.current_directory);
        browserTitle = (TextView) view.findViewById(R.id.browser_title);

        backButton = view.findViewById(R.id.back_button);
        selectControl = view.findViewById(R.id.dir_select);
        selectContainer = view.findViewById(R.id.select_container);

        backButton.setOnClickListener(new OnClickListener() {
            @Override public void onClick(View v) {
                if (listener != null) {
                    listener.onUpClicked();
                }
            }
        });

        selectControl.setOnClickListener(new OnClickListener() {
            @Override public void onClick(View v) {
                if (listener != null) {
                    listener.onSelectClicked();
                }
            }
        });
    }

    @Override public void setDisplayedFolderItems(List<FolderItem> folderItemList) {
        final FolderItemAdapter adapter = new FolderItemAdapter(getContext(), folderItemList);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (listener != null) {
                    listener.onNavigationItemClicked(adapter.getItem(position));
                }
            }
        });
    }

    @Override public void setCurrentDirectory(String text) {
        currentDirectory.setText(text);
    }

    @Override public void setBrowserTitle(String text) {
        browserTitle.setText(text);
    }

    @Override public void setUpControlEnabled(boolean enabled) {
        backButton.setEnabled(enabled);
    }

    @Override public void setSelectControlEnabled(boolean enabled) {
        selectContainer.setVisibility(enabled ? VISIBLE : GONE);
    }

    @Override public void setFileBrowserListener(BrowserViewListener listener) {
        this.listener = listener;
    }

    private class FolderItemAdapter extends ArrayAdapter<FolderItem> {

        private LayoutInflater inflater;

        public FolderItemAdapter(Context context, List<FolderItem> values) {
            super(context, R.layout.list_item_folder_item, values);
            inflater = LayoutInflater.from(context);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            if (convertView == null) {
                convertView = inflater.inflate(R.layout.list_item_folder_item, parent, false);
            }

            FolderItem folderItem = getItem(position);

            TextView folderName = (TextView) convertView.findViewById(R.id.folder_item_name);
            FontAwesomeText faIcon = (FontAwesomeText) convertView.findViewById(R.id.folder_item_icon);

            folderName.setText(folderItem.getFileName());
            faIcon.setIcon(folderItem.getFaCode());
            faIcon.setTextColor(getResources().getColor(folderItem.getColor()));

            return convertView;
        }
    }

}


text:
define(['dojo/_base/declare',
  'dijit/_WidgetBase',
  'dojo/dom-style',
  'dojo/dom-construct'
],
function(declare, _WidgetBase, domStyle, domConstruct) {
  return declare(_WidgetBase, {
    'baseClass': 'jimu-loading-indicator',
    declaredClass: 'jimu.dijit.LoadingIndicator',
    hidden:false,

    postCreate: function(){
      this.inherited(arguments);
      this.hidden = this.hidden === true;
      if(this.hidden){
        domStyle.set(this.domNode,{display:'none'});
      }
      domStyle.set(this.domNode, {width: '100%', height: '100%'});
      var str = '<img class="jimu-loading" src="'+require.toUrl('jimu')+'/images/loading.gif">';
      domConstruct.place(str, this.domNode);
    },

    show:function(){
      if(!this.domNode){
        return;
      }
      domStyle.set(this.domNode,'display','block');
    },

    hide:function(){
      if(!this.domNode){
        return;
      }
      domStyle.set(this.domNode,'display','none');
    }
  });
});

redpajama_set_name: RedPajamaGithub


text:
class CreateGutsUserGroups < ActiveRecord::Migration[4.2]
  def change
    create_table :guts_user_groups do |t|
      t.integer :user_id
      t.integer :group_id

      t.timestamps null: false
    end
  end
end


text:
package io.druid.indexing.overlord;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import io.druid.common.guava.SettableSupplier;
import io.druid.indexing.common.TaskLockType;
import io.druid.indexing.common.TaskStatus;
import io.druid.indexing.common.config.TaskStorageConfig;
import io.druid.indexing.common.task.NoopTask;
import io.druid.indexing.common.task.Task;
import io.druid.jackson.DefaultObjectMapper;
import io.druid.java.util.common.Intervals;
import io.druid.metadata.DerbyMetadataStorageActionHandlerFactory;
import io.druid.metadata.EntryExistsException;
import io.druid.metadata.TestDerbyConnector;
import org.joda.time.Interval;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class TaskLockBoxConcurrencyTest
{
  @Rule
  public final TestDerbyConnector.DerbyConnectorRule derby = new TestDerbyConnector.DerbyConnectorRule();

  private final ObjectMapper objectMapper = new DefaultObjectMapper();
  private ExecutorService service;
  private TaskStorage taskStorage;
  private TaskLockbox lockbox;

  @Before
  public void setup()
  {
    final TestDerbyConnector derbyConnector = derby.getConnector();
    derbyConnector.createTaskTables();
    taskStorage = new MetadataTaskStorage(
        derbyConnector,
        new TaskStorageConfig(null),
        new DerbyMetadataStorageActionHandlerFactory(
            derbyConnector,
            derby.metadataTablesConfigSupplier().get(),
            objectMapper
        )
    );

    lockbox = new TaskLockbox(taskStorage);
    service = Executors.newFixedThreadPool(2);
  }

  @After
  public void teardown()
  {
    service.shutdownNow();
  }

  @Test(timeout = 5000L)
  public void testDoInCriticalSectionWithDifferentTasks()
      throws ExecutionException, InterruptedException, EntryExistsException
  {
    final Interval interval = Intervals.of("2017-01-01/2017-01-02");
    final Task lowPriorityTask = NoopTask.create(10);
    final Task highPriorityTask = NoopTask.create(100);
    lockbox.add(lowPriorityTask);
    lockbox.add(highPriorityTask);
    taskStorage.insert(lowPriorityTask, TaskStatus.running(lowPriorityTask.getId()));
    taskStorage.insert(highPriorityTask, TaskStatus.running(highPriorityTask.getId()));

    final SettableSupplier<Integer> intSupplier = new SettableSupplier<>(0);
    final CountDownLatch latch = new CountDownLatch(1);

    // lowPriorityTask acquires a lock first and increases the int of intSupplier in the critical section
    final Future<Integer> lowPriorityFuture = service.submit(() -> {
      final LockResult result = lockbox.tryLock(TaskLockType.EXCLUSIVE, lowPriorityTask, interval);
      Assert.assertTrue(result.isOk());
      Assert.assertFalse(result.isRevoked());

      return lockbox.doInCriticalSection(
          lowPriorityTask,
          Collections.singletonList(interval),
          CriticalAction.<Integer>builder()
              .onValidLocks(
                  () -> {
                    latch.countDown();
                    Thread.sleep(100);
                    intSupplier.set(intSupplier.get() + 1);
                    return intSupplier.get();
                  }
              )
              .onInvalidLocks(
                  () -> {
                    Assert.fail();
                    return null;
                  }
              )
              .build()
      );
    });

    // highPriorityTask awaits for the latch, acquires a lock, and increases the int of intSupplier in the critical
    // section
    final Future<Integer> highPriorityFuture = service.submit(() -> {
      latch.await();
      final LockResult result = lockbox.lock(TaskLockType.EXCLUSIVE, highPriorityTask, interval);
      Assert.assertTrue(result.isOk());
      Assert.assertFalse(result.isRevoked());

      return lockbox.doInCriticalSection(
          highPriorityTask,
          Collections.singletonList(interval),
          CriticalAction.<Integer>builder()
              .onValidLocks(
                  () -> {
                    Thread.sleep(100);
                    intSupplier.set(intSupplier.get() + 1);
                    return intSupplier.get();
                  }
              )
              .onInvalidLocks(
                  () -> {
                    Assert.fail();
                    return null;
                  }
              )
              .build()
      );
    });

    Assert.assertEquals(1, lowPriorityFuture.get().intValue());
    Assert.assertEquals(2, highPriorityFuture.get().intValue());

    // the lock for lowPriorityTask must be revoked by the highPriorityTask after its work is done in critical section
    final LockResult result = lockbox.tryLock(TaskLockType.EXCLUSIVE, lowPriorityTask, interval);
    Assert.assertFalse(result.isOk());
    Assert.assertTrue(result.isRevoked());
  }

  @Test(timeout = 5000L)
  public void testDoInCriticalSectionWithOverlappedIntervals() throws Exception
  {
    final List<Interval> intervals = ImmutableList.of(
        Intervals.of("2017-01-01/2017-01-02"),
        Intervals.of("2017-01-02/2017-01-03"),
        Intervals.of("2017-01-03/2017-01-04")
    );
    final Task task = NoopTask.create();
    lockbox.add(task);
    taskStorage.insert(task, TaskStatus.running(task.getId()));

    for (Interval interval : intervals) {
      final LockResult result = lockbox.tryLock(TaskLockType.EXCLUSIVE, task, interval);
      Assert.assertTrue(result.isOk());
    }

    final SettableSupplier<Integer> intSupplier = new SettableSupplier<>(0);
    final CountDownLatch latch = new CountDownLatch(1);

    final Future<Integer> future1 = service.submit(() -> lockbox.doInCriticalSection(
        task,
        ImmutableList.of(intervals.get(0), intervals.get(1)),
        CriticalAction.<Integer>builder()
            .onValidLocks(
                () -> {
                  latch.countDown();
                  Thread.sleep(100);
                  intSupplier.set(intSupplier.get() + 1);
                  return intSupplier.get();
                }
            )
            .onInvalidLocks(
                () -> {
                  Assert.fail();
                  return null;
                }
            )
            .build()
    ));

    final Future<Integer> future2 = service.submit(() -> {
      latch.await();
      return lockbox.doInCriticalSection(
          task,
          ImmutableList.of(intervals.get(1), intervals.get(2)),
          CriticalAction.<Integer>builder()
              .onValidLocks(
                  () -> {
                    Thread.sleep(100);
                    intSupplier.set(intSupplier.get() + 1);
                    return intSupplier.get();
                  }
              )
              .onInvalidLocks(
                  () -> {
                    Assert.fail();
                    return null;
                  }
              )
              .build()
      );
    });

    Assert.assertEquals(1, future1.get().intValue());
    Assert.assertEquals(2, future2.get().intValue());
  }
}


text:
SYNONYM

#### According to
The Catalogue of Life, 3rd January 2011

#### Published in
Novit. fl. svec. 2: 40 (1814)

#### Original name
Hydnum agardhii Fr., 1814

### Remarks
null


text:
extern crate serde_json;

use services::anoncreds::types::{PublicKey, RevocationPublicKey};
use utils::json::{JsonEncodable, JsonDecodable};
use services::ledger::constants::{
    NODE,
    NYM,
    ATTRIB,
    SCHEMA,
    GET_ATTR,
    GET_DDO,
    GET_NYM,
    GET_SCHEMA,
    CLAIM_DEF,
    GET_CLAIM_DEF,
    STEWARD,
    TRUSTEE,
    TRUST_ANCHOR,
    GET_TXN
};

#[derive(Serialize, PartialEq, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Request<T: JsonEncodable> {
    pub req_id: u64,
    pub identifier: String,
    pub operation: T,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub signature: Option<String>
}

impl<T: JsonEncodable> Request<T> {
    pub fn new(req_id: u64, identifier: String, operation: T) -> Request<T> {
        Request {
            req_id: req_id,
            identifier: identifier,
            operation: operation,
            signature: None
        }
    }
}

impl<T: JsonEncodable> JsonEncodable for Request<T> {}

#[derive(Deserialize, Serialize, PartialEq, Debug)]
pub enum Role {
    Steward = STEWARD,
    Trustee = TRUSTEE,
    TrustAnchor = TRUST_ANCHOR
}

#[derive(Serialize, PartialEq, Debug)]
pub struct NymOperation {
    #[serde(rename = "type")]
    pub _type: String,
    pub dest: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub verkey: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub alias: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub role: Option<String>
}

impl NymOperation {
    pub fn new(dest: String, verkey: Option<String>,
               alias: Option<String>, role: Option<String>) -> NymOperation {
        NymOperation {
            _type: NYM.to_string(),
            dest: dest,
            verkey: verkey,
            alias: alias,
            role: role
        }
    }
}

impl JsonEncodable for NymOperation {}

#[derive(Serialize, PartialEq, Debug)]
pub struct GetNymOperation {
    #[serde(rename = "type")]
    pub _type: String,
    pub dest: String
}

impl GetNymOperation {
    pub fn new(dest: String) -> GetNymOperation {
        GetNymOperation {
            _type: GET_NYM.to_string(),
            dest: dest
        }
    }
}

impl JsonEncodable for GetNymOperation {}

#[derive(Serialize, PartialEq, Debug)]
pub struct AttribOperation {
    #[serde(rename = "type")]
    pub _type: String,
    pub dest: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub hash: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub raw: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub enc: Option<String>
}

impl AttribOperation {
    pub fn new(dest: String, hash: Option<String>, raw: Option<String>,
               enc: Option<String>) -> AttribOperation {
        AttribOperation {
            _type: ATTRIB.to_string(),
            dest: dest,
            hash: hash,
            raw: raw,
            enc: enc,
        }
    }
}

impl JsonEncodable for AttribOperation {}

#[derive(Serialize, PartialEq, Debug)]
pub struct GetAttribOperation {
    #[serde(rename = "type")]
    pub _type: String,
    pub dest: String,
    pub raw: String
}

impl GetAttribOperation {
    pub fn new(dest: String, raw: String) -> GetAttribOperation {
        GetAttribOperation {
            _type: GET_ATTR.to_string(),
            dest: dest,
            raw: raw
        }
    }
}

impl JsonEncodable for GetAttribOperation {}

#[derive(Serialize, PartialEq, Debug)]
pub struct SchemaOperation {
    #[serde(rename = "type")]
    pub _type: String,
    pub data: SchemaOperationData,
}

impl SchemaOperation {
    pub fn new(data: SchemaOperationData) -> SchemaOperation {
        SchemaOperation {
            data: data,
            _type: SCHEMA.to_string()
        }
    }
}

impl JsonEncodable for SchemaOperation {}

#[derive(Serialize, PartialEq, Debug, Deserialize)]
pub struct SchemaOperationData {
    name: String,
    version: String,
    attr_names: Vec<String>
}

impl SchemaOperationData {
    pub fn new(name: String, version: String, keys: Vec<String>) -> SchemaOperationData {
        SchemaOperationData {
            name: name,
            version: version,
            attr_names: keys
        }
    }
}

impl JsonEncodable for SchemaOperationData {}

impl<'a> JsonDecodable<'a> for SchemaOperationData {}

#[derive(Serialize, PartialEq, Debug)]
pub struct GetSchemaOperation {
    #[serde(rename = "type")]
    pub _type: String,
    pub dest: String,
    pub data: GetSchemaOperationData
}

impl GetSchemaOperation {
    pub fn new(dest: String, data: GetSchemaOperationData) -> GetSchemaOperation {
        GetSchemaOperation {
            _type: GET_SCHEMA.to_string(),
            dest: dest,
            data: data
        }
    }
}

impl JsonEncodable for GetSchemaOperation {}

#[derive(Deserialize, PartialEq, Debug)]
#[serde(rename_all = "camelCase")]
pub struct GetSchemaResultData {
    pub attr_names: Vec<String>,
    pub name: String,
    pub origin: String,
    pub seq_no: String,
    #[serde(rename = "type")]
    pub _type: Option<String>,
    pub version: String
}

#[derive(Serialize, PartialEq, Debug, Deserialize)]
pub struct GetSchemaOperationData {
    pub name: String,
    pub version: String
}

impl GetSchemaOperationData {
    pub fn new(name: String, version: String) -> GetSchemaOperationData {
        GetSchemaOperationData {
            name: name,
            version: version
        }
    }
}

impl JsonEncodable for GetSchemaOperationData {}

impl<'a> JsonDecodable<'a> for GetSchemaOperationData {}

#[derive(Serialize, PartialEq, Debug)]
pub struct ClaimDefOperation {
    #[serde(rename = "ref")]
    pub _ref: i32,
    pub data: ClaimDefOperationData,
    #[serde(rename = "type")]
    pub _type: String,
    pub signature_type: String
}

impl ClaimDefOperation {
    pub fn new(_ref: i32, signature_type: String, data: ClaimDefOperationData) -> ClaimDefOperation {
        ClaimDefOperation {
            _ref: _ref,
            signature_type: signature_type,
            data: data,
            _type: CLAIM_DEF.to_string()
        }
    }
}

impl JsonEncodable for ClaimDefOperation {}

#[derive(Serialize, PartialEq, Debug, Deserialize)]
pub struct ClaimDefOperationData {
    pub primary: PublicKey,
    #[serde(serialize_with = "empty_map_instead_of_null")] //FIXME
    pub revocation: Option<RevocationPublicKey>
}

impl ClaimDefOperationData {
    pub fn new(primary: PublicKey, revocation: Option<RevocationPublicKey>) -> ClaimDefOperationData {
        ClaimDefOperationData {
            primary: primary,
            revocation: revocation
        }
    }
}

//FIXME workaround for ledger: serialize required dictionary as empty instead of using null
extern crate serde;
use self::serde::Serializer;
use self::serde::ser::SerializeMap;
fn empty_map_instead_of_null<S>(x: &Option<RevocationPublicKey>, s: S) -> Result<S::Ok, S::Error>
    where S: Serializer {
    if let &Some(ref x) = x {
        s.serialize_some(&x)
    } else {
        s.serialize_map(None)?.end()
    }
}
//FIXME

impl JsonEncodable for ClaimDefOperationData {}

impl<'a> JsonDecodable<'a> for ClaimDefOperationData {}

#[derive(Serialize, PartialEq, Debug)]
pub struct GetClaimDefOperation {
    #[serde(rename = "type")]
    pub _type: String,
    #[serde(rename = "ref")]
    pub _ref: i32,
    pub signature_type: String,
    pub origin: String
}

impl GetClaimDefOperation {
    pub fn new(_ref: i32, signature_type: String, origin: String) -> GetClaimDefOperation {
        GetClaimDefOperation {
            _type: GET_CLAIM_DEF.to_string(),
            _ref: _ref,
            signature_type: signature_type,
            origin: origin
        }
    }
}

impl JsonEncodable for GetClaimDefOperation {}

#[derive(Serialize, PartialEq, Debug)]
pub struct NodeOperation {
    #[serde(rename = "type")]
    pub _type: String,
    pub dest: String,
    pub data: NodeOperationData
}

impl NodeOperation {
    pub fn new(dest: String, data: NodeOperationData) -> NodeOperation {
        NodeOperation {
            _type: NODE.to_string(),
            dest: dest,
            data: data
        }
    }
}

impl JsonEncodable for NodeOperation {}

#[derive(Serialize, PartialEq, Debug, Deserialize)]
pub enum Services {
    VALIDATOR,
    OBSERVER
}

#[derive(Serialize, PartialEq, Debug, Deserialize)]
pub struct NodeOperationData {
    pub node_ip: String,
    pub node_port: i32,
    pub client_ip: String,
    pub client_port: i32,
    pub alias: String,
    pub services: Vec<Services>
}

impl NodeOperationData {
    pub fn new(node_ip: String, node_port: i32, client_ip: String, client_port: i32, alias: String, services: Vec<Services>) -> NodeOperationData {
        NodeOperationData {
            node_ip: node_ip,
            node_port: node_port,
            client_ip: client_ip,
            client_port: client_port,
            alias: alias,
            services: services
        }
    }
}

impl JsonEncodable for NodeOperationData {}

impl<'a> JsonDecodable<'a> for NodeOperationData {}

#[derive(Serialize, PartialEq, Debug)]
pub struct GetDdoOperation {
    #[serde(rename = "type")]
    pub _type: String,
    pub dest: String
}

impl GetDdoOperation {
    pub fn new(dest: String) -> GetDdoOperation {
        GetDdoOperation {
            _type: GET_DDO.to_string(),
            dest: dest
        }
    }
}

impl JsonEncodable for GetDdoOperation {}

#[derive(Serialize, PartialEq, Debug)]
pub struct GetTxnOperation {
    #[serde(rename = "type")]
    pub _type: String,
    pub data: i32
}

impl GetTxnOperation {
    pub fn new(data: i32) -> GetTxnOperation {
        GetTxnOperation {
            _type: GET_TXN.to_string(),
            data: data
        }
    }
}

impl JsonEncodable for GetTxnOperation {}

#[derive(Deserialize, Eq, PartialEq, Debug)]
pub struct Reply<T> {
    pub op: String,
    pub result: T,
}

impl<'a, T: JsonDecodable<'a>> JsonDecodable<'a> for Reply<T> {}

#[derive(Deserialize, Eq, PartialEq, Debug)]
#[serde(rename_all = "camelCase")]
pub struct GetNymReplyResult {
    pub identifier: String,
    pub req_id: u64,
    #[serde(rename = "type")]
    pub _type: String,
    pub data: String,
    pub dest: String
}

impl<'a> JsonDecodable<'a> for GetNymReplyResult {}

#[derive(Deserialize, Eq, PartialEq, Debug)]
#[serde(rename_all = "camelCase")]
pub struct GetNymResultData {
    pub identifier: Option<String>,
    pub dest: String,
    pub role: Option<String>,
    pub verkey: Option<String>
}

impl<'a> JsonDecodable<'a> for GetNymResultData {}


text:
<!DOCTYPE html>

    <meta name="viewport" content="width=device-width, minimal-ui">
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="../css/style.css">
    <title>H71 Example 2</title>

            Home > WCAG HTML Techniques

H71 Example 2: Providing a description for groups of form controls using fieldset and legend elements

        <fieldset>
        <legend>I am interested in the following (check all that apply):</legend>
        <input type="checkbox" id="photo" name="interests" value="ph">
        Photography

        <input type="checkbox" id="watercol" name="interests" checked="checked" value="wa">
        Watercolor

        <input type="checkbox" id="acrylic" name="interests" checked="checked" value="ac">
        Acrylic
        …
        </fieldset>

Source: WCAG H71

Tested on:

Windows 7, Firefox ESR 45.4.0, and JAWS 17

Result: Screen reader announces the legend, each checkbox text and the status of each checkbox.

iOS 10.2.1, Safari browser is based on the iOS version, VoiceOver on iPad

Result: iOS VoiceOver announces

I am interested in the following check all that apply. main.

Photography checkbox unchecked.

Watercolor checkbox checked.

Acrylic checkbox checked ellipsis.

Android 7.1.2; Pixel, Chrome 55.0.2883.91, and TalkBack Version: 5.0.4.3.

 Result: TalkBack announces

I am interested in the following check all that apply. Tap to activate.

Not checked, Photography checkbox. Tap to toggle.

Checked, Watercolor checkbox. Tap to toggle.

Checked, Acrylic checkbox. Tap to toggle.


text:
package com.tranek.chivalryserverbrowser;
import java.awt.BorderLayout;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URL;
import java.util.HashMap;
import java.util.Vector;

import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker.State;
import javafx.embed.swing.JFXPanel;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebEvent;
import javafx.scene.web.WebView;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JToggleButton;
import javax.swing.ScrollPaneConstants;
import javax.swing.text.DefaultCaret;

import netscape.javascript.JSObject;
import test.ButtonTabComponent;

import com.almworks.sqlite4java.SQLiteConnection;
import com.almworks.sqlite4java.SQLiteException;
import com.almworks.sqlite4java.SQLiteStatement;

/**
 *
 *The main class that creates the frame and all other components.
 *It also contains useful utility functions used by it and other
 *classes.
 *
 *
 */
public class MainWindow {

	/** The JFrame for the application. */
	protected JFrame frmChivalryServers;
	/** A flag for the first startup of the application. */
	private boolean firstTimeShown = true;
	/** The message center at the bottom of the application to display messages to the user. */
	protected JTextArea messageCenter;
	/** The currently queried list of normal servers. */
	protected Vector<ChivServer> servers = new Vector<ChivServer>();
	/** The currently queried list of beta servers. */
	protected Vector<ChivServer> serversBeta = new Vector<ChivServer>();
	/** The currently queried list of favorite servers. */
	protected Vector<ChivServer> serversFav = new Vector<ChivServer>();
	/** The currently queried list of server history. */
	protected Vector<ChivServer> serversHist = new Vector<ChivServer>();
	/** The currently queried list of servers that the users friends are on. */
	protected Vector<ChivServer> serversFriends;
	/** The {@link ChivServer} currently shown as a white marker on the map. */
	protected ChivServer mapShownServer;
	/** A reference to the MainWindow object to pass to other objects. */
	private MainWindow mw;
	/** The JScrollPane for the message center. */
	private JScrollPane messageScrollPane;
	/** The JTabbedPane that holds all of the tabs. */
	protected JTabbedPane tabbedPane;
	/** Tab for normal server list. */
	protected ServerListNormalTab serverListTab;
	/** Tab for beta server list. */
	protected ServerListBetaTab serverListBetaTab;
	/** Tab for favorite server list. */
	protected ServerListFavTab serverListFavTab;
	/** Tab for server history list. */
	protected ServerListHistoryTab serverListHistoryTab;
	/** Tab for friends list. */
	protected FriendsTab friendsTab;
	/** Tab for map. */
	protected JPanel mapTab;
	/** Tab for gamepad keybinds. */
	protected JPanel gamepadKeybindTab;
	/** Tab for settings. */
	protected SettingsTab settingsTab;
	/** The JFXPanel that hosts the embedded web browser for the map. */
	protected JFXPanel browserFxPanel;
	/** WebEngine for the map. */
	protected WebEngine webEngine;
	/** JCheckBox for whether or not to display normal server makers on the map. */
	protected JCheckBox chckbxNormalServers;
	/** JCheckBox for whether or not to display beta server makers on the map. */
	protected JCheckBox chckbxBetaServers;
	/** JCheckBox for whether or not to display favorite server makers on the map. */
	protected JCheckBox chckbxFavoriteServers;
	/** JCheckBox for whether or not to display server history makers on the map. */
	protected JCheckBox chckbxServerHistory;
	/** JToggleButton for the player heatmap on the map. */
	private JToggleButton tglbtnTogglePlayerHeat;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainWindow window = new MainWindow();
					window.frmChivalryServers.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public MainWindow() {
		mw = this;
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmChivalryServers = new JFrame();
		frmChivalryServers.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				exit();
			}
		});
		frmChivalryServers.setTitle("Chivalry: Medieval Warfare Server Browser by ReMixx");
		frmChivalryServers.setBounds(100, 100, 1024, 768);
		frmChivalryServers.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		frmChivalryServers.setResizable(false);

		tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		frmChivalryServers.getContentPane().add(tabbedPane, BorderLayout.CENTER);

		tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
		serverListTab = new ServerListNormalTab(this);
		tabbedPane.addTab("Server List", null, serverListTab, null);

		mapTab = new JPanel();
		JPanel mapSettingsPanel = new JPanel();
		mapSettingsPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));

		chckbxNormalServers = new JCheckBox("Normal Servers");
		chckbxNormalServers.setSelected(true);
		chckbxNormalServers.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if ( chckbxNormalServers.isSelected() ) {
						for ( ChivServer cs : servers ) {
							addMarker(serverListTab, cs);
						}
				} else {
					removeMarkers(serverListTab);
				}
			}
		});
		mapSettingsPanel.add(chckbxNormalServers);

		chckbxBetaServers = new JCheckBox("Beta Servers");
		chckbxBetaServers.setSelected(true);
		chckbxBetaServers.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if ( chckbxBetaServers.isSelected() ) {
					for ( ChivServer cs : serversBeta ) {
						addMarker(serverListBetaTab, cs);
					}
				} else {
					removeMarkers(serverListBetaTab);
				}
			}
		});
		mapSettingsPanel.add(chckbxBetaServers);

		chckbxFavoriteServers = new JCheckBox("Favorite Servers");
		chckbxFavoriteServers.setSelected(true);
		chckbxFavoriteServers.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if ( chckbxFavoriteServers.isSelected() ) {
					for ( ChivServer cs : serversFav ) {
						addMarker(serverListFavTab, cs);
					}
				} else {
					removeMarkers(serverListFavTab);
				}
			}
		});
		mapSettingsPanel.add(chckbxFavoriteServers);

		chckbxServerHistory = new JCheckBox("Server History");
		chckbxServerHistory.setSelected(true);
		chckbxServerHistory.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if ( chckbxServerHistory.isSelected() ) {
					for ( ChivServer cs : serversHist ) {
						addMarker(serverListHistoryTab, cs);
					}
				} else {
					removeMarkers(serverListHistoryTab);
				}
			}
		});
		mapSettingsPanel.add(chckbxServerHistory);
		browserFxPanel = new JFXPanel();
		browserFxPanel.setPreferredSize(new Dimension(1010, 535));
		mapTab.add(mapSettingsPanel, BorderLayout.NORTH);

		tglbtnTogglePlayerHeat = new JToggleButton("Toggle Player Heat Map");
		tglbtnTogglePlayerHeat.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if ( tglbtnTogglePlayerHeat.isSelected() ) {
					enablePlayerHeatMap();
				} else {
					disablePlayerHeatMap();
				}
			}
		});
		mapSettingsPanel.add(tglbtnTogglePlayerHeat);
		mapTab.add(browserFxPanel, BorderLayout.CENTER);
		createScene();
		tabbedPane.addTab("Map", null, mapTab, null);

		serverListBetaTab = new ServerListBetaTab(this);
		tabbedPane.addTab("Beta Server List", null, serverListBetaTab, null);
		serverListFavTab = new ServerListFavTab(this);
		tabbedPane.addTab("Favorite Servers", null, serverListFavTab, null);
		serverListHistoryTab = new ServerListHistoryTab(this);
		tabbedPane.addTab("Server History", null, serverListHistoryTab, null);
		friendsTab = new FriendsTab(this);
		tabbedPane.addTab("Friends List", null, friendsTab, null);
		settingsTab = new SettingsTab(this);
		tabbedPane.addTab("Settings", null, settingsTab, null);
		gamepadKeybindTab = wrapInBackgroundImage(new GamepadKeybindTab(mw),
				new ImageIcon(getClass().getResource("images/gamepad.png")));
		tabbedPane.addTab("Gamepad Keybinds", null, gamepadKeybindTab, null);

		JMenuBar menuBar = new JMenuBar();
		frmChivalryServers.getContentPane().add(menuBar, BorderLayout.NORTH);

		JMenu mnFile = new JMenu("File");
		menuBar.add(mnFile);

		JMenuItem mntmExit = new JMenuItem("Exit");
		mntmExit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				exit();
			}
		});
		mnFile.add(mntmExit);

		JMenu mnView = new JMenu("View");
		menuBar.add(mnView);

		final JMenuItem mntmServerListBeta = new JMenuItem("Beta Servers");
		mntmServerListBeta.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if ( tabbedPane.indexOfComponent(serverListBetaTab) < 0 ) {
					tabbedPane.addTab("Beta Server List", null, serverListBetaTab, null);
					initTabComponent(tabbedPane, tabbedPane.getTabCount()-1);
				}
				tabbedPane.setSelectedComponent(serverListBetaTab);
			}
		});
		mnView.add(mntmServerListBeta);
		final JMenuItem mntmServerListFav = new JMenuItem("Favorite Servers");
		mntmServerListFav.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if ( tabbedPane.indexOfComponent(serverListFavTab) < 0 ) {
					tabbedPane.addTab("Favorite Servers", null, serverListFavTab, null);
					initTabComponent(tabbedPane, tabbedPane.getTabCount()-1);
				}
				tabbedPane.setSelectedComponent(serverListFavTab);
			}
		});
		mnView.add(mntmServerListFav);
		final JMenuItem mntmServerListHistory = new JMenuItem("Server History");
		mntmServerListHistory.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if ( tabbedPane.indexOfComponent(serverListHistoryTab) < 0 ) {
					tabbedPane.addTab("Server History", null, serverListHistoryTab, null);
					initTabComponent(tabbedPane, tabbedPane.getTabCount()-1);
				}
				tabbedPane.setSelectedComponent(serverListHistoryTab);
			}
		});
		mnView.add(mntmServerListHistory);
		final JMenuItem mntmFriends = new JMenuItem("Friends List");
		mntmFriends.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if ( tabbedPane.indexOfComponent(friendsTab) < 0 ) {
					tabbedPane.addTab("Friends List", null, friendsTab, null);
					initTabComponent(tabbedPane, tabbedPane.getTabCount()-1);
				}
				tabbedPane.setSelectedComponent(friendsTab);
			}
		});
		mnView.add(mntmFriends);
		final JMenuItem mntmSettings = new JMenuItem("Settings");
		mntmSettings.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if ( tabbedPane.indexOfComponent(settingsTab) < 0 ) {
					tabbedPane.addTab("Settings", null, settingsTab, null);
					initTabComponent(tabbedPane, tabbedPane.getTabCount()-1);
				}
				tabbedPane.setSelectedComponent(settingsTab);
			}
		});
		mnView.add(mntmSettings);
		final JMenuItem mntmGamepadKeybinds = new JMenuItem("Gamepad Keybinds");
		mntmGamepadKeybinds.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if ( tabbedPane.indexOfComponent(gamepadKeybindTab) < 0 ) {
					tabbedPane.addTab("Gamepapd Keybinds", null, gamepadKeybindTab, null);
					initTabComponent(tabbedPane, tabbedPane.getTabCount()-1);
				}
				tabbedPane.setSelectedComponent(gamepadKeybindTab);
			}
		});
		mnView.add(mntmGamepadKeybinds);

		JPanel messagePanel = new JPanel();
		frmChivalryServers.getContentPane().add(messagePanel, BorderLayout.SOUTH);
		int mpwidth = messagePanel.getParent().getWidth();
		messagePanel.setPreferredSize(new Dimension(mpwidth, 100));
		messagePanel.setLayout(new BorderLayout(0, 0));

		messageCenter = new JTextArea();
		messageCenter.setEditable(false);
		//these two lines make the jtextarea always update to the furthest position
		DefaultCaret caret = (DefaultCaret)messageCenter.getCaret();
		caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

		messageScrollPane = new JScrollPane(messageCenter); // Adds messageCenter directly to scrollpane
		messageScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		messageScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		messagePanel.add(messageScrollPane);

		if( firstTimeShown ) {
			serverListTab.loadFilters();
			serverListBetaTab.loadFilters();
			serverListFavTab.loadFilters();
			serverListHistoryTab.loadFilters();
			serverListTab.RefreshServers();
			loadSettings();
			firstTimeShown = false;
			addMajorTabComponent();
		}
	}

	/**
	 * Prints a single line of text to the {@link MainWindow#messageCenter}
	 * without adding a new line before it.
	 *
	 * @param msg the String to be printed
	 * @see #checkMCBuffer()
	 */
	public void printMC(String msg) {
		checkMCBuffer();
		messageCenter.append(msg);
	}

	/**
	 * Prints a single line of text to the {@link MainWindow#messageCenter}
	 * with adding a new line before it.
	 *
	 * @param msg the String to be printed
	 * @see #checkMCBuffer()
	 */
	public void printlnMC(String msg) {
		checkMCBuffer();
		messageCenter.append("\n" + msg);
	}

	/**
	 * Keeps the {@link MainWindow#messageCenter} at no more than 30 lines of text.
	 */
	public void checkMCBuffer() {
		String mctext = messageCenter.getText();
		String[] numlines = mctext.split("\\r?\\n");
		if ( numlines.length > 30 ) {
			int index = mctext.indexOf('\n');
			if ( index > -1 ) {
				mctext = mctext.substring(index);
			}
			messageCenter.setText(mctext);
		}
	}

	/**
	 * Saves all tabs' filters and the application's settings before exiting
	 * the application.
	 */
	public void exit() {
		serverListTab.saveFilters();
		serverListBetaTab.saveFilters();
		serverListFavTab.saveFilters();
		serverListHistoryTab.saveFilters();
		saveGameConfig();
		saveSettings();
		System.exit(0);
	}

	/**
	 * Returns the {@link ChivServer} for the given ip address, gameport, and ServerListInterface.
	 *
	 * @param ip the ip address of the {@link ChivServer}
	 * @param gameport the gameport of the {@link ChivServer}
	 * @param sl the {@link ServerListInterface} that requested the lookup
	 * @return	the {@link ChivServer} if found, null otherwise
	 * @see #findChivServer(String, String, Vector)
	 */
	public ChivServer findChivServer(String ip, String gameport, ServerListInterface sl) {
		Vector<ChivServer> s = null;
		if ( sl == serverListTab ) {
			s = servers;
		} else if ( sl == serverListBetaTab ) {
			s = serversBeta;
		} else if ( sl == serverListFavTab ) {
			s = serversFav;
		} else if ( sl == serverListHistoryTab ) {
			s = serversHist;
		}

		return findChivServer(ip, gameport, s);
	}

	/**
	 * Returns the {@link ChivServer} for the given ip address, gameport, and list of servers.
	 *
	 * @param ip the ip address of the {@link ChivServer}
	 * @param gameport the gameport of the {@link ChivServer}
	 * @param servers the {@link Vector} of {@link ChivServer} to look in
	 * @return	the {@link ChivServer} if found, null otherwise
	 */
	public ChivServer findChivServer(String ip, String gameport, Vector<ChivServer> servers) {
		if ( servers != null ) {
			for ( ChivServer cs : servers ) {
				if ( cs.mIP.equals(ip) && cs.mGamePort.equals(gameport) ) {
					return cs;
				}
			}
		}
		return null;
	}

	/**
	 * Adds a {@link ButtonTabComponent} to a tab to close the tab.
	 *
	 * @param pane the {@link JTabbedPane} with the tabs
	 * @param i	the index of the tab to add the button component to
	 */
	private void initTabComponent(JTabbedPane pane, int i) {
        pane.setTabComponentAt(i,
                 new ButtonTabComponent(pane));
    }

	/**
	 * Calls {@link #initTabComponent(JTabbedPane, int)} on all the standard tabs.
	 *
	 * @see #initTabComponent(JTabbedPane, int)
	 */
	private void addMajorTabComponent() {
		int numtabs = tabbedPane.getTabCount();
		if ( numtabs > 2) {
			for (int i=2; i<numtabs; i++) {
				initTabComponent(tabbedPane, i);
			}
		}
	}

	/**
	 * Adds a new tab with details about a specific server.
	 *
	 * @param ip_port a string of the "ipaddress:gameport" of the server
	 * @param sl the {@link ServerListInterface} that called this method
	 * @param switchToTab whether or not to automatically switch to the new tab
	 * @see #addServerTab(ChivServer, boolean)
	 */
	public void addServerTab(String ip_port, ServerListInterface sl, boolean switchToTab) {
		String stripped = ip_port;
		stripped = stripped.split("<")[0];
		String[] ipaddress = stripped.split(":");
		String ip = ipaddress[0];
		String gameport = ipaddress[1];
		ChivServer cs = findChivServer(ip, gameport, sl);
		if ( cs != null ) {
			addServerTab(cs, switchToTab);
		}
	}

	/**
	 * Adds a new tab with details about the server that is currently shown on the map (white marker).
	 *
	 * @param switchToTab whether or not to automatically switch to the new tab
	 * @see #addServerTab(ChivServer, boolean)
	 */
	public void addServerTabShownServer(boolean switchToTab) {
		ChivServer cs = mapShownServer;
		if ( cs != null ) {
			addServerTab(cs, switchToTab);
		}
	}

	/**
	 * Adds a new tab with details about a specific server. It looks up the
	 * "ipaddress:gameport" combination from the database of previously seen
	 * servers. If the server is not found, it does nothing.
	 *
	 * @param ip_port the "ipaddress:gameport" of the server
	 * @param switchToTab whether or not to automatically switch to the new tab
	 * @see #addServerTab(ChivServer, boolean)
	 */
	public void addServerTab(String ip_port, boolean switchToTab) {
		String ip = ip_port.split(":")[0];
		String gameport = ip_port.split(":")[1];
		ChivServer cs = getServerFromDB(ip, gameport);
		if ( cs != null ) {
			addServerTab(cs, switchToTab);
		} else {
			printlnMC("Server not found in database. Please refresh all servers to update the database.");
		}
	}

	/**
	 * Adds a new tab with details about a specific server.
	 *
	 * @param cs the {@link ChivServer} of the new tab
	 * @param switchToTab whether or not to automatically switch to the new tab
	 * @see #initTabComponent(JTabbedPane, int)
	 */
	public void addServerTab(ChivServer cs, boolean switchToTab) {
		if ( cs != null) {
			boolean tabExists = false;
			for ( int i=0; i<tabbedPane.getTabCount(); i++ ) {
				if ( tabbedPane.getTitleAt(i).equals( cs.mName ) )
				{
					tabExists = true;
					if ( switchToTab ) {
						tabbedPane.setSelectedIndex(i);
					}
					break;
				}
			}
			if ( !tabExists ) {

				System.out.println("Chiv server found.");
				ServerTab st = new ServerTab(mw, cs);
				tabbedPane.addTab(cs.mName, null, st, null);
				initTabComponent(tabbedPane, tabbedPane.getTabCount() - 1);
				if ( switchToTab ) {
					tabbedPane.setSelectedIndex(tabbedPane.getTabCount()-1);
				}
			} else {
			}
		}
	}

	/**
	 * The method that the map javascript calls to add a new tab with details
	 * about a specific server. Since javascript can't send actual java objects,
	 * it includes a string parameter representing the server list tab where
	 * this server could be found in a lookup.
	 *
	 * @param ip_port the "ipaddress:gameport" of the server
	 * @param sl a string denoting which server list tab that this server originally came from
	 * @see #addServerTab(ChivServer, boolean)
	 * @see #addServerTabShownServer(boolean)
	 */
	public void addServerTabJS(String ip_port, String sl) {
		if ( sl.equals("n") ) {
			addServerTab(ip_port, serverListTab, true);
		} else if ( sl.equals("b") ) {
			addServerTab(ip_port, serverListBetaTab, true);
		} else if ( sl.equals("f") ) {
			addServerTab(ip_port, serverListBetaTab, true);
		} else if ( sl.equals("h") ) {
			addServerTab(ip_port, serverListBetaTab, true);
		} else if ( sl.equals("s") ) {
			addServerTabShownServer(true);
		}
	}

	/**
	 * Adds a {@link ChivServer} as a favorite server to the database.
	 *
	 * @param cs the {@link ChivServer} to add
	 * @see SQLiteConnection
	 * @see SQLiteStatement
	 * @see SQLiteException
	 */
	public void addFavorite(ChivServer cs) {

		printlnMC("Adding server to favorites...");

		SQLiteConnection db = new SQLiteConnection(new File("browserdb"));
		try {
			db.open(true);
			SQLiteStatement st = db.prepare("CREATE TABLE IF NOT EXISTS favorite_servers" +
					"(" +
					"id INTEGER PRIMARY KEY AUTOINCREMENT," +
					"name varchar(255) not null default ''," +
					"ip varchar(255) not null default ''," +
					"port varchar(255) not null default '' )");
			try {
				st.step();
			} finally {
				st.dispose();
			}

			//check if exists
			int id = -1;
			st = db.prepare("SELECT id FROM favorite_servers WHERE ip = '" + cs.mIP + "' AND  port = '" + cs.mQueryPort + "'");
			try {
				st.step();
				if ( st.hasRow() ) {
					id = st.columnInt(0);
				}
			} finally {
				st.dispose();
			}

			if ( id > -1 ) {
				printlnMC("Server already a favorite.");
				st = db.prepare("INSERT OR REPLACE INTO favorite_servers (id, name, ip, port) " +
						"VALUES ( " + id + ",'" + cs.mName + "', '" + cs.mIP + "', '" + cs.mQueryPort + "' )");
				try {
					st.step();
				} finally {
					st.dispose();
				}
			} else {
				st = db.prepare("INSERT INTO favorite_servers (name, ip, port) " +
						"VALUES ('" + cs.mName + "', '" + cs.mIP + "', '" + cs.mQueryPort + "' )");
				try {
					st.step();
				} finally {
					st.dispose();
				}
				printlnMC("Added to favorites: " + cs.mName);
			}

		} catch (SQLiteException e) {
			e.printStackTrace();
		}
		db.dispose();
	}

	/**
	 * Removes a {@link ChivServer} from the favorites database.
	 *
	 * @param cs the {@link ChivServer} to remove
	 * @return if the server was successfully found and removed
	 * @see SQLiteConnection
	 * @see SQLiteStatement
	 * @see SQLiteException
	 */
	public boolean removeFavorite(ChivServer cs) {
		boolean removed = false;
		System.out.println("Removing from favorites...");
		printlnMC("Removing server from favorites...");

		SQLiteConnection db = new SQLiteConnection(new File("browserdb"));
		try {
			db.open(true);
			SQLiteStatement st = db.prepare("CREATE TABLE IF NOT EXISTS favorite_servers" +
					"(" +
					"id INTEGER PRIMARY KEY AUTOINCREMENT," +
					"name varchar(255) not null default ''," +
					"ip varchar(255) not null default ''," +
					"port varchar(255) not null default '' )");
			try {
				st.step();
			} finally {
				st.dispose();
			}

			//check if exists
			int id = -1;
			st = db.prepare("SELECT id FROM favorite_servers WHERE ip = '" + cs.mIP + "' AND  port = '" + cs.mQueryPort + "'");
			try {
				st.step();
				if ( st.hasRow() ) {
					id = st.columnInt(0);
				}
			} finally {
				st.dispose();
			}

			if ( id > -1 ) {
				st = db.prepare("DELETE FROM favorite_servers WHERE id = " + id);
				try {
					st.step();

					for ( int i=0; i<serversFav.size(); i++ ) {
						ChivServer c = serversFav.get(i);
						if ( cs.mIP.equals(c.mIP) && cs.mQueryPort.equals(c.mQueryPort) ) {
							serversFav.remove(i);
							break;
						}
					}

					printlnMC("Removed favorite: " + cs.mName);
					removed = true;
				} finally {
					st.dispose();
				}
			} else {
				printlnMC("Didn't find server in database. This is probably a bad thing.");
			}

		} catch (SQLiteException e) {
			e.printStackTrace();
		}
		db.dispose();

		return removed;
	}

	/**
	 * Stops all server list tabs from refreshing.
	 *
	 * @see RefresherNormal
	 * @see RefresherBeta
	 * @see RefresherFav
	 * @see RefresherHistory
	 */
	public void stopAllRefreshing() {
		serverListTab.refresher.stopRefreshing();
		if ( serverListBetaTab.refresher != null ) {
			serverListBetaTab.refresher.stopRefreshing();
		}
		if ( serverListFavTab.refresher != null ) {
			serverListFavTab.refresher.stopRefreshing();
		}
		if ( serverListHistoryTab.refresher != null ) {
			serverListHistoryTab.refresher.stopRefreshing();
		}
	}

	/**
	 * Adds a {@link ChivServer} to the server history database. This is typically called
	 * when the user joins a server.
	 *
	 * @param cs the {@link ChivServer} to add
	 * @see SQLiteConnection
	 * @see SQLiteStatement
	 * @see SQLiteException
	 */
	public void addServerToHistory(ChivServer cs) {
		System.out.println("Adding server to history list.");
		SQLiteConnection db = new SQLiteConnection(new File("browserdb"));
		try {
			db.open(true);
			SQLiteStatement st = db.prepare("CREATE TABLE IF NOT EXISTS server_history" +
					"(" +
					"id INTEGER PRIMARY KEY AUTOINCREMENT," +
					"name varchar(255) not null default ''," +
					"ip varchar(255) not null default ''," +
					"port varchar(255) not null default '' )");
			try {
				st.step();
			} finally {
				st.dispose();
			}

			//check if exists
			int id = -1;
			st = db.prepare("SELECT id FROM server_history WHERE ip = '" + cs.mIP + "' AND  port = '" + cs.mQueryPort + "'");
			try {
				st.step();
				if ( st.hasRow() ) {
					id = st.columnInt(0);
				}
			} finally {
				st.dispose();
			}

			if ( id > -1 ) {
				st = db.prepare("INSERT OR REPLACE INTO server_history (id, name, ip, port) " +
						"VALUES ( " + id + ",'" + cs.mName + "', '" + cs.mIP + "', '" + cs.mQueryPort + "' )");
				try {
					st.step();
				} finally {
					st.dispose();
				}
			} else {
				st = db.prepare("INSERT INTO server_history (name, ip, port) " +
						"VALUES ('" + cs.mName + "', '" + cs.mIP + "', '" + cs.mQueryPort + "' )");
				try {
					st.step();
				} finally {
					st.dispose();
				}
			}

		} catch (SQLiteException e) {
			e.printStackTrace();
		}
		db.dispose();
	}

	/**
	 * Removes a {@link ChivServer} from the history database.
	 *
	 * @param cs the {@link ChivServer} to remove
	 * @return if the {@link ChivServer} was successfully found and removed
	 * @see SQLiteConnection
	 * @see SQLiteStatement
	 * @see SQLiteException
	 */
	public boolean removeServerFromHistory(ChivServer cs) {
		boolean removed = false;
		System.out.println("Removing from history...");
		printlnMC("Removing server from history...");

		SQLiteConnection db = new SQLiteConnection(new File("browserdb"));
		try {
			db.open(true);
			SQLiteStatement st = db.prepare("CREATE TABLE IF NOT EXISTS server_history" +
					"(" +
					"id INTEGER PRIMARY KEY AUTOINCREMENT," +
					"name varchar(255) not null default ''," +
					"ip varchar(255) not null default ''," +
					"port varchar(255) not null default '' )");
			try {
				st.step();
			} finally {
				st.dispose();
			}

			//check if exists
			int id = -1;
			st = db.prepare("SELECT id FROM server_history WHERE ip = '" + cs.mIP + "' AND  port = '" + cs.mQueryPort + "'");
			try {
				st.step();
				if ( st.hasRow() ) {
					id = st.columnInt(0);
				}
			} finally {
				st.dispose();
			}

			if ( id > -1 ) {
				st = db.prepare("DELETE FROM server_history WHERE id = " + id);
				try {
					st.step();

					for ( int i=0; i<serversFav.size(); i++ ) {
						ChivServer c = serversFav.get(i);
						if ( cs.mIP.equals(c.mIP) && cs.mQueryPort.equals(c.mQueryPort) ) {
							serversFav.remove(i);
							break;
						}
					}

					printlnMC("Removed history: " + cs.mName);
					removed = true;
				} finally {
					st.dispose();
				}
			} else {
				printlnMC("Didn't find server in database. This is probably a bad thing.");
			}

		} catch (SQLiteException e) {
			e.printStackTrace();
		}
		db.dispose();

		return removed;
	}

	/**
	 * Launches the game and joins a specific server via the Steam URL.
	 *
	 * @param urlstring the Steam URL to launch the game and join the server
	 * @param ip the ip address of the server
	 * @param port the gameport of the server
	 * @param serverName the name of the server
	 * @param sl the {@link ServerListInterface} where this server is found for lookup
	 * @see ChivServer
	 * @see #findChivServer(String, String, ServerListInterface)
	 * @see #joinServer(String, String, String, String, ChivServer)
	 */
	public void joinServer(String urlstring, String ip, String port, String serverName, ServerListInterface sl) {
		ChivServer cs = findChivServer(ip, port, sl);
		joinServer(urlstring, ip, port, serverName, cs);
	}

	/**
	 * Launches the game ad joins a specific server via the Steam URL.
	 *
	 * @param urlstring the Steam URL to launch the game and join the server
	 * @param ip the ip address of the server
	 * @param port the gameport of the server
	 * @param serverName the name of the server
	 * @param cs the {@link ChivServer} to join
	 * @see Desktop
	 * @see URI
	 * @see #addServerToHistory(ChivServer)
	 * @see #saveGameConfig()
	 * @see #getLaunchOptions()
	 */
	public void joinServer(String urlstring, String ip, String port, String serverName, ChivServer cs) {
		saveGameConfig();
		Desktop dt = Desktop.getDesktop();
		URI url = null;
		try {
			url = new URI(urlstring + getLaunchOptions());
			System.out.println(urlstring + getLaunchOptions());
			dt.browse(url);
			mw.printlnMC("Joining server: " + serverName + " " + ip + ":" + port + " ...");
			addServerToHistory(cs);
			mw.stopAllRefreshing();
		} catch (Exception e1) {
			e1.printStackTrace();
		}
	}

	/**
	 * Launches the game and joins a specific server via the Steam URL that a Steam friend is playing on.
	 *
	 * @param urlstring	the Steam URL to launch the game and join the server
	 * @param ip the ip address of the server
	 * @param port the gameport of the server
	 * @param friendName the name of the Steam friend on the server
	 * @see Desktop
	 * @see URI
	 * @see #saveGameConfig()
	 * @see #getLaunchOptions()
	 */
	public void joinServer(String urlstring, String ip, String port, String friendName) {
		saveGameConfig();
		Desktop dt = Desktop.getDesktop();
		URI url = null;
		try {
			url = new URI(urlstring + getLaunchOptions());
			dt.browse(url);
			mw.printlnMC("Joining friend: " + friendName + " at " + ip + ":" + port + " ...");
			mw.stopAllRefreshing();
		} catch (Exception e1) {
			e1.printStackTrace();
		}
	}

	/**
	 * Method called by the map's javascript to join a specific server via the Steam URL.
	 *
	 * @param ip the ip of the server
	 * @param queryport the queryport of the server
	 * @see ChivServer
	 * @see #joinServer(String, String, String, String, ChivServer)
	 */
	public void joinServerJS(String ip, String queryport) {
		ChivServer cs = ChivServer.createChivServer(mw, ip, Integer.parseInt(queryport));
		String urlstring = "";
		if ( cs.mHasPassword.equals("1") ) {
			String password = javax.swing.JOptionPane.showInputDialog("Please enter a password");
			if ( !password.equals("") ) {
				urlstring = "steam://run/219640/en/" + ip + ":" + cs.mGamePort + "%3fpassword=" + password;
				joinServer(urlstring, ip, cs.mGamePort, cs.mName, cs);
			}
		} else {
			urlstring = "steam://run/219640/en/" + ip + ":" + cs.mGamePort;
			joinServer(urlstring, ip, cs.mGamePort, cs.mName, cs);
		}
	}

	/**
	 * Loads the application settings from the database.
	 *
	 * @see SQLiteConnection
	 * @see SQLiteStatement
	 * @see SQLiteException
	 */
	public void loadSettings() {
		SQLiteConnection db = new SQLiteConnection(new File("browserdb"));
		try {
			db.open(true);
			SQLiteStatement st = db.prepare("CREATE TABLE IF NOT EXISTS settings" +
					"(" +
					"id INTEGER PRIMARY KEY AUTOINCREMENT," +
					"steam_url varchar(255) not null default ''," +
					"show_chiv_only int not null default 1," +
					"servers_beta_visible int not null default 1," +
					"servers_fav_visible int not null default 1," +
					"servers_hist_visible int not null default 1," +
					"friends_visible int not null default 1," +
					"map_visible int not null default 1," +
					"map_normal_chckbox int not null default 1," +
					"map_beta_chckbox int not null default 1," +
					"map_favorite_chckbox int not null default 1," +
					"map_history_chckbox int not null default 1," +
					"settings_visible int not null default 1," +
					"launch_opt_window int not null default 0," +
					"launch_opt_resx varchar (255) not null default ''," +
					"launch_opt_resy varchar (255) not null default ''," +
					"launch_opt_enable int not null default 0," +
					"gamepad_visible int not null default 1" +
					")");
			try {
				st.step();
			} finally {
				st.dispose();
			}

			st = db.prepare("SELECT * FROM settings WHERE id = 1 ");
			try {
				st.step();
				if ( st.hasRow() ) {
					friendsTab.urlField.setText(st.columnString(1));
					settingsTab.tfSteamCommunityUrl.setText(st.columnString(1));
					if ( st.columnInt(2) == 1 ) {
						friendsTab.chckbxInChiv.setSelected(true);
					} else {
						friendsTab.chckbxInChiv.setSelected(false);
					}
					if ( st.columnInt(3) == 0 ) {
						tabbedPane.remove(serverListBetaTab);
					}
					if ( st.columnInt(4) == 0 ) {
						tabbedPane.remove(serverListFavTab);
					}
					if ( st.columnInt(5) == 0 ) {
						tabbedPane.remove(serverListHistoryTab);
					}
					if ( st.columnInt(6) == 0 ) {
						tabbedPane.remove(friendsTab);
					}
					if ( st.columnInt(8) == 1 ) {
						chckbxNormalServers.setSelected(true);
					} else {
						chckbxNormalServers.setSelected(false);
					}
					if ( st.columnInt(9) == 1 ) {
						chckbxBetaServers.setSelected(true);
					} else {
						chckbxBetaServers.setSelected(false);
					}
					if ( st.columnInt(10) == 1 ) {
						chckbxFavoriteServers.setSelected(true);
					} else {
						chckbxFavoriteServers.setSelected(false);
					}
					if ( st.columnInt(11) == 1 ) {
						chckbxServerHistory.setSelected(true);
					} else {
						chckbxServerHistory.setSelected(false);
					}
					if ( st.columnInt(12) == 0 ) {
						tabbedPane.remove(settingsTab);
					}
					settingsTab.cbScreen.setSelectedIndex(st.columnInt(13));
					settingsTab.tfLaunchResX.setText(st.columnString(14));
					settingsTab.tfLaunchResY.setText(st.columnString(15));
					if ( st.columnInt(16) == 1 ) {
						settingsTab.tglbtnEnableLaunchOptions.setSelected(true);
					} else {
						settingsTab.tglbtnEnableLaunchOptions.setSelected(false);
					}
					if ( st.columnInt(17) == 0 ) {
						tabbedPane.remove(gamepadKeybindTab);
					}
				}
			} finally {
				st.dispose();
			}

		} catch (SQLiteException e) {
			e.printStackTrace();
		}
		db.dispose();
	}

	/**
	 * Saves the application settings to the database.
	 *
	 * @see SQLiteConnection
	 * @see SQLiteStatement
	 * @see SQLiteException
	 */
	public void saveSettings() {
		SQLiteConnection db = new SQLiteConnection(new File("browserdb"));
		try {
			db.open(true);
			SQLiteStatement st = db.prepare("CREATE TABLE IF NOT EXISTS settings" +
					"(" +
					"id INTEGER PRIMARY KEY AUTOINCREMENT," +
					"steam_url varchar(255) not null default ''," +
					"show_chiv_only int not null default 1," +
					"servers_beta_visible int not null default 1," +
					"servers_fav_visible int not null default 1," +
					"servers_hist_visible int not null default 1," +
					"friends_visible int not null default 1," +
					"map_visible int not null default 1," +
					"map_normal_chckbox int not null default 1," +
					"map_beta_chckbox int not null default 1," +
					"map_favorite_chckbox int not null default 1," +
					"map_history_chckbox int not null default 1," +
					"settings_visible int not null default 1," +
					"launch_opt_window int not null default 0," +
					"launch_opt_resx varchar (255) not null default ''," +
					"launch_opt_resy varchar (255) not null default ''," +
					"launch_opt_enable int not null default 0," +
					"gamepad_visible int not null default 1" +
					")");
			try {
				st.step();
			} finally {
				st.dispose();
			}

			String steamURL = friendsTab.urlField.getText();
			int showChivOnly = 1;
			if ( !friendsTab.chckbxInChiv.isSelected() ) {
				showChivOnly = 0;
			}
			int beta_visible = 1;
			if ( tabbedPane.indexOfComponent(serverListBetaTab) < 0 ) {
				beta_visible = 0;
			}
			int fav_visible = 1;
			if ( tabbedPane.indexOfComponent(serverListFavTab) < 0 ) {
				fav_visible = 0;
			}
			int hist_visible = 1;
			if ( tabbedPane.indexOfComponent(serverListHistoryTab) < 0 ) {
				hist_visible = 0;
			}
			int friends_visible = 1;
			if ( tabbedPane.indexOfComponent(friendsTab) < 0 ) {
				friends_visible = 0;
			}
			int settings_visible = 1;
			if ( tabbedPane.indexOfComponent(settingsTab) < 0 ) {
				settings_visible = 0;
			}
			int map_visible = 1;
			if ( tabbedPane.indexOfComponent(mapTab) < 0 ) {
				//map_visible = 0;
			}
			int gamepad_visible = 1;
			if ( tabbedPane.indexOfComponent(gamepadKeybindTab) < 0 ) {
				gamepad_visible = 0;
			}
			int map_normal_chckbox = 1;
			if ( !chckbxNormalServers.isSelected() ) {
				map_normal_chckbox = 0;
			}
			int map_beta_chckbox = 1;
			if ( !chckbxBetaServers.isSelected() ) {
				map_beta_chckbox = 0;
			}
			int map_favorite_chckbox = 1;
			if ( !chckbxFavoriteServers.isSelected() ) {
				map_favorite_chckbox = 0;
			}
			int map_history_chckbox = 1;
			if ( !chckbxServerHistory.isSelected() ) {
				map_history_chckbox = 0;
			}
			int launch_opt_enable = 0;
			if ( settingsTab.tglbtnEnableLaunchOptions.isSelected() ) {
				launch_opt_enable = 1;
			}

			st = db.prepare("INSERT OR REPLACE INTO settings (id, steam_url, show_chiv_only, " +
					"servers_beta_visible, servers_fav_visible, servers_hist_visible, friends_visible, " +
					"settings_visible, map_visible, map_normal_chckbox, map_beta_chckbox, " +
					"map_favorite_chckbox, map_history_chckbox, launch_opt_window, launch_opt_resx, " +
					"launch_opt_resy, launch_opt_enable, gamepad_visible) " +
					"VALUES (  1, '" + steamURL + "', " + showChivOnly + ", " + beta_visible +
					", " + fav_visible + ", " + hist_visible + ", " + friends_visible + ", " +
					settings_visible + ", " + map_visible + ", " + map_normal_chckbox + ", " +
					map_beta_chckbox + ", " + map_favorite_chckbox + ", " + map_history_chckbox +
					", " + settingsTab.cbScreen.getSelectedIndex() + ", '" + settingsTab.tfLaunchResX.getText() +
					"', '" + settingsTab.tfLaunchResY.getText() + "', " + launch_opt_enable + ", " +
					gamepad_visible + ")");
			try {
				st.step();
			} finally {
				st.dispose();
			}

		} catch (SQLiteException e) {
			e.printStackTrace();
		}
		db.dispose();
	}

	/**
	 * Creates the JavaFX scene for the Map tab. It creates a new {@link WebEngine} and loads the
	 * map.html resource.
	 *
	 * @see WebView
	 * @see JSObject#setMember(String, Object)
	 * @see #browserFxPanel
	 */
	private void createScene() {
		Platform.runLater(new Runnable() {
			@Override
			public void run() {
				WebView view = new WebView();
		        webEngine = view.getEngine();

		        webEngine.setOnAlert(new EventHandler<WebEvent<String>>() {
		            public void handle(WebEvent<String> ev) {
		            	System.out.println(ev.getData());
		            	if ( ev.getData().equals("jquery works!") ) {
		            		webEngine.executeScript("javacall('helloworld')");
		            	}
		            	if ( ev.getData().equals("loaded") ) {
		            		HashMap<String, String> loc = getLoc();
		            		String lat = loc.get("latitude");
		            		String lon = loc.get("longitude");
		            		String func = "addUserLoc('" + lat + "', '" + lon + "')";
		            		if ( !lat.equals("") && !lon.equals("") ) {
		            			webEngine.executeScript(func);
		            		}
		            	}
		            }
		        });

		        String url = getClass().getResource("map.html").toExternalForm();
		        webEngine.load(url);

		        webEngine.getLoadWorker().stateProperty().addListener(
			        new ChangeListener<State>(){

			            @Override
			            public void changed(ObservableValue<? extends State> ov, State oldState, State newState) {
			                if(newState == State.SUCCEEDED){
			                    JSObject window = (JSObject)webEngine.executeScript("window");
			                    window.setMember("app", mw);
			                }
			            }
			        });
		        JSObject window = (JSObject)webEngine.executeScript("window");
		        window.setMember("app", mw);

		        browserFxPanel.setScene(new Scene(view));
			}
		});
	}

	/**
	 * Gets the location of the user by querying http://checkip.amazonaws.com.
	 *
	 * @return the latitude and longitude of the user
	 * @see URL
	 * @see LocationRIPE#getLocation(String)
	 * @see HashMap
	 */
	public HashMap<String, String> getLoc() {
		try {
			URL whatismyip = new URL("http://checkip.amazonaws.com");
			BufferedReader in = new BufferedReader(new InputStreamReader(
			                whatismyip.openStream()));
			String ip = in.readLine(); //you get the IP as a String
			LocationRIPE l = new LocationRIPE();
    		HashMap<String, String> loc = l.getLocation(ip);
    		String lat = loc.get("latitude");
    		String lon = loc.get("longitude");
    		HashMap<String, String> result = new HashMap<String, String>();
    		result.put("latitude", lat);
    		result.put("longitude", lon);
    		return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * Removes all markers from the map from servers found in the server list tab.
	 *
	 * @param sl the {@link ServerListInterface} with the markers to remove from the map
	 * @see WebEngine#executeScript(String)
	 */
	public void removeMarkers(final ServerListInterface sl) {
		Platform.runLater(new Runnable() {
			@Override
			public void run() {
				String func = "";
				if ( sl == serverListTab ) {
					func = "clearMarkers('n')";
				} else if ( sl == serverListBetaTab ) {
					func = "clearMarkers('b')";
				} else if ( sl == serverListFavTab ) {
					func = "clearMarkers('f')";
				} else if ( sl == serverListHistoryTab ) {
					func = "clearMarkers('h')";
				}
				if ( !func.equals("") ) {
					webEngine.executeScript(func);
				}
			}
		});
	}

	/**
	 * Adds a marker for a given {@link ChivServer} to the map.
	 *
	 * @param sl the {@link ServerListInterface} that the {@link ChivServer} came from
	 * @param cs the {@link ChivServer} to add to the map as a marker
	 * @see WebEngine#executeScript(String)
	 */
	public void addMarker(final ServerListInterface sl, final ChivServer cs) {
		if ( !cs.mLatitude.equals("") && !cs.mLongitude.equals("") ) {
			Platform.runLater(new Runnable() {
				@Override
				public void run() {
					String title = cs.mName;
					String hasPassword = "No";
					if ( cs.mHasPassword.equals("1") ) {
						hasPassword = "Yes";
					}
					String html = "<p>" + cs.mName + "</p>" +
							"<a href='javascript:joinServer(\\\"" + cs.mIP + "\\\", \\\"" + cs.mQueryPort + "\\\")'>" +
							"Connect to server: " + cs.mIP + ":" + cs.mGamePort + "</a>" +
							"<p>Map: " + cs.mMap + "</p>" +
							"<p>Players: " + cs.mCurrentPlayers + " / " + cs.mMaxPlayers + "</p>" +
							"<p>Ping: " + cs.mPing + "<span style='float:right'>Password: " + hasPassword + "</span></p>";
					String func = "";
					if ( sl == serverListTab ) {
						html += "<a href='javascript:moreInfoTab(\\\"" + cs.mIP + ":" + cs.mGamePort +
								"\\\", \\\"n\\\")'>More info</a>";
						func = "addMarker('" + cs.mLatitude + "', '" + cs.mLongitude + "', '" + "n" +
								"', \"" + title + "\", \"" + html + "\", " + cs.mCurrentPlayers + ")";
					} else if ( sl == serverListBetaTab ) {
						html += "<a href='javascript:moreInfoTab(\\\"" + cs.mIP + ":" + cs.mGamePort +
								"\\\", \\\"b\\\")'>More info</a>";
						func = "addMarker('" + cs.mLatitude + "', '" + cs.mLongitude + "', '" + "b" +
								"', \"" + title + "\", \"" + html + "\", " + cs.mCurrentPlayers + ")";
					} else if ( sl == serverListFavTab ) {
						html += "<a href='javascript:moreInfoTab(\\\"" + cs.mIP + ":" + cs.mGamePort +
								"\\\", \\\"f\\\")'>More info</a>";
						func = "addMarker('" + cs.mLatitude + "', '" + cs.mLongitude + "', '" + "f" +
								"', \"" + title + "\", \"" + html + "\", " + cs.mCurrentPlayers + ")";
					} else if ( sl == serverListHistoryTab ) {
						html += "<a href='javascript:moreInfoTab(\\\"" + cs.mIP + ":" + cs.mGamePort +
								"\\\", \\\"h\\\")'>More info</a>";
						func = "addMarker('" + cs.mLatitude + "', '" + cs.mLongitude + "', '" + "h" +
								"', \"" + title + "\", \"" + html + "\", " + cs.mCurrentPlayers + ")";
					}
					if ( !func.equals("") ) {
						webEngine.executeScript(func);
					}
				}
			});
		}
	}

	/**
	 * Shows a specific {@link ChivServer} on the map as a white marker.
	 *
	 * @param cs the {@link ChivServer} to show
	 * @see WebEngine#executeScript(String)
	 */
	public void showInMap(final ChivServer cs) {
		mapShownServer = cs;
		Platform.runLater(new Runnable() {
			@Override
			public void run() {
				String title = cs.mName;
				String hasPassword = "No";
				if ( cs.mHasPassword.equals("1") ) {
					hasPassword = "Yes";
				}
				String html = "<p>" + cs.mName + "</p>" +
						"<a href='javascript:joinServer(\\\"" + cs.mIP + "\\\", \\\"" + cs.mQueryPort + "\\\")'>" +
						"Connect to server: " + cs.mIP + ":" + cs.mGamePort + "</a>" +
						"<p>Map: " + cs.mMap + "</p>" +
						"<p>Players: " + cs.mCurrentPlayers + " / " + cs.mMaxPlayers + "</p>" +
						"<p>Ping: " + cs.mPing + "<span style='float:right'>Password: " + hasPassword + "</span></p>" +
						"<a href='javascript:moreInfoTab(\\\"" + cs.mIP + ":" + cs.mGamePort +
						"\\\", \\\"s\\\")'>More info</a>";
				String func = "addMarker('" + cs.mLatitude + "', '" + cs.mLongitude + "', '" + "s" +
						"', \"" + title + "\", \"" + html + "\", " + cs.mCurrentPlayers + ")";
				webEngine.executeScript(func);
				func = "showIW()";
				webEngine.executeScript(func);
			}
		});
		tabbedPane.setSelectedComponent(mapTab);
	}

	/**
	 * Enables the player heatmap on the map.
	 *
	 * @see WebEngine#executeScript(String)
	 * @see "https://developers.google.com/maps/documentation/javascript/reference#HeatmapLayer"
	 */
	public void enablePlayerHeatMap() {
		System.out.println("enable player heat map called");
		Platform.runLater(new Runnable() {
			@Override
			public void run() {
				webEngine.executeScript("enablePlayerHeatMap()");
			}
		});
	}

	/**
	 * Disables the player heatmap on the map.
	 *
	 * @see WebEngine#executeScript(String)
	 * @see "https://developers.google.com/maps/documentation/javascript/reference#HeatmapLayer"
	 */
	public void disablePlayerHeatMap() {
		System.out.println("disable player heat map called");
		Platform.runLater(new Runnable() {
			@Override
			public void run() {
				webEngine.executeScript("disablePlayerHeatMap()");
			}
		});
	}

	/**
	 * Gets the launch options from the Settings tab to be applied to joining a server.
	 *
	 * @return the launch options as a String
	 */
	public String getLaunchOptions() {
		if ( !settingsTab.tglbtnEnableLaunchOptions.isSelected() ) {
			return "";
		}
		String opts = "";
		if ( !settingsTab.tfLaunchResX.getText().equals("") ) {
			opts += "&-resx=" + settingsTab.tfLaunchResX.getText();
		}
		if ( !settingsTab.tfLaunchResY.getText().equals("") ) {
			opts += "&-resy=" + settingsTab.tfLaunchResY.getText();
		}
		String window = (String) settingsTab.cbScreen.getSelectedItem();
		if ( window.equals("Fullscreen") ) {
			opts += "&-fullscreen";
		} else if ( window.equals("Windowed") ) {
			opts += "&-windowed";
		} else if ( window.equals("Borderless Window") ) {
			opts += "&-borderless";
		}
		return opts;
	}

	/**
	 * Adds a server found during a refresh to the database. If the server already exists, this does nothing.
	 *
	 * @param cs the {@link ChivServer} to add to the database
	 * @see SQLiteConnection
	 * @see SQLiteStatement
	 * @see SQLiteException
	 */
	public void addServerToDatabase(ChivServer cs) {
		SQLiteConnection db = new SQLiteConnection(new File("browserdb"));
		try {
			db.open(true);
			SQLiteStatement st = db.prepare("CREATE TABLE IF NOT EXISTS servers" +
					"(" +
					"id INTEGER PRIMARY KEY AUTOINCREMENT," +
					"ip varchar(255) not null default ''," +
					"queryport varchar(255) not null default ''," +
					"gameport varchar(255) not null default ''" +
					")");
			try {
				st.step();
			} finally {
				st.dispose();
			}

			st = db.prepare("SELECT id FROM servers WHERE ip = '" + cs.mIP + "' AND queryport = '" + cs.mQueryPort +
					"' AND gameport = '" + cs.mGamePort + "'");
			boolean exists = false;
			try {
				st.step();
				if ( st.hasRow() ) {
					exists = true;
				}
			} finally {
				st.dispose();
			}

			if ( !exists ) {
				st = db.prepare("INSERT INTO servers (ip, queryport, gameport) VALUES ( '" + cs.mIP + "', '" +
						cs.mQueryPort + "', '" + cs.mGamePort + "')");
				try {
					st.step();
				} finally {
					st.dispose();
				}
			}

		} catch (SQLiteException e) {
			e.printStackTrace();
		}
		db.dispose();
	}

	/**
	 * Updates the database of servers found during a refresh. These are used for looking up server
	 * ip addresses and gameports from the Friends tab to find the queryport to query the server
	 * for more information. This method uses {@link MainWindow#servers} to update the database.
	 */
	public void updateServerDB() {
		if ( mw.servers != null ) {
			new Thread() {
				@Override
				public void run() {
					@SuppressWarnings("unchecked")
					Vector<ChivServer> serversCopy = (Vector<ChivServer>) mw.servers.clone();
					for ( ChivServer cs : serversCopy ) {
						addServerToDatabase(cs);
					}
				}
			}.start();
		}
	}

	/**
	 * Updates the database of servers found during a refresh. These are used for looking up server
	 * ip addresses and gameports from the Friends tab to find the queryport to query the server
	 * for more information.
	 *
	 * @param s the {@link Vector} of {@link ChivServer} to update into the database
	 */
	public void updateServerDB(final Vector<ChivServer> s) {
		if ( s != null ) {
			new Thread() {
				@Override
				public void run() {
					for ( ChivServer cs : s ) {
						addServerToDatabase(cs);
					}
				}
			}.start();
		}
	}

	/**
	 * Searches the database for a server matching the ip address and gameport to find the
	 * associated queryport.
	 *
	 * @param ip the ip address of the server
	 * @param gameport the gameport of the server
	 * @return returns the {@link ChivServer}; or null if not found
	 * @see SQLiteConnection
	 * @see SQLiteStatement
	 * @see SQLiteException
	 */
	public ChivServer getServerFromDB(String ip, String gameport) {
		String queryport = "";
		SQLiteConnection db = new SQLiteConnection(new File("browserdb"));
		try {
			db.open(true);
			SQLiteStatement st = db.prepare("CREATE TABLE IF NOT EXISTS servers" +
					"(" +
					"id INTEGER PRIMARY KEY AUTOINCREMENT," +
					"ip varchar(255) not null default ''," +
					"queryport varchar(255) not null default ''," +
					"gameport varchar(255) not null default ''" +
					")");
			try {
				st.step();
			} finally {
				st.dispose();
			}
			st = db.prepare("SELECT queryport FROM servers WHERE ip = '" + ip + "' AND gameport = '" + gameport + "'");
			try {
				st.step();
				if ( st.hasRow() ) {
					queryport = st.columnString(0);
				}
			} finally {
				st.dispose();
			}

		} catch (SQLiteException e) {
			e.printStackTrace();
		}
		db.dispose();
		if ( !queryport.equals("") ) {
			return ChivServer.createChivServer(mw, ip, Integer.parseInt(queryport));
		}
		return null;
	}

	/**
	 * Deep copies a {@link Vector} of {@link ChivServer}.
	 *
	 * @param s the {@link Vector} of {@link ChivServer} to be copied
	 * @return a deep copy of the {@link Vector} of {@link ChivServer}
	 */
	public Vector<ChivServer> deepCopyCSVector(Vector<ChivServer> s) {
		Vector<ChivServer> result = new Vector<ChivServer>();
		for (ChivServer cs : s) {
			result.add(cs.clone());
		}
		return s;
	}

	/**
	 * Saves all of the game settings from the Settings Tab to the config
	 * files.
	 *
	 * @see SettingsTab#writeUDKConfigSetting(String, String, String)
	 */
	public void saveGameConfig() {
		settingsTab.writeUDKConfigSetting("UDKSystemSettings.ini", "AmbientOcclusion", (String)settingsTab.tblGameSettings.getValueAt(0, 1));
		settingsTab.writeUDKConfigSetting("UDKSystemSettings.ini", "Bloom", (String)settingsTab.tblGameSettings.getValueAt(1, 1));
		settingsTab.writeUDKConfigSetting("UDKSystemSettings.ini", "DynamicLights", (String)settingsTab.tblGameSettings.getValueAt(2, 1));
		settingsTab.writeUDKConfigSetting("UDKSystemSettings.ini", "DynamicShadows", (String)settingsTab.tblGameSettings.getValueAt(3, 1));
		settingsTab.writeUDKConfigSetting("UDKSystemSettings.ini", "MotionBlur", (String)settingsTab.tblGameSettings.getValueAt(4, 1));
		settingsTab.writeUDKConfigSetting("UDKSystemSettings.ini", "ResX", (String)settingsTab.tblGameSettings.getValueAt(5, 1));
		settingsTab.writeUDKConfigSetting("UDKSystemSettings.ini", "ResY", (String)settingsTab.tblGameSettings.getValueAt(6, 1));
		settingsTab.writeUDKConfigSetting("UDKSystemSettings.ini", "UseVsync", (String)settingsTab.tblGameSettings.getValueAt(7, 1));
	}

	/**
	 * Set up constraints so that the user supplied component and the
     * background image label overlap and resize identically
     *
     * @see "http://www.java-tips.org/java-se-tips/javax.swing/wrap-a-swing-jcomponent-in-a-background-image.html"
	 */
    private static final GridBagConstraints gbc;
    static {
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        gbc.anchor = GridBagConstraints.NORTHWEST;
    }

    /**
     * Wraps a Swing {@link JComponent} in a background image. Simply invokes the overloded
     * variant with Top/Leading alignment for background image.
     *
     * @param component to wrap in the a background image
     * @param backgroundIcon the background image (Icon)
     * @return the wrapping JPanel
     * @see "http://www.java-tips.org/java-se-tips/javax.swing/wrap-a-swing-jcomponent-in-a-background-image.html"
     */
    public static JPanel wrapInBackgroundImage(JComponent component,
            Icon backgroundIcon) {
        return wrapInBackgroundImage(
                component,
                backgroundIcon,
                JLabel.TOP,
                JLabel.LEADING);
    }

    /**
     * Wraps a Swing {@link JComponent} in a background image. The vertical and horizontal
     * alignment of background image can be specified using the alignment
     * constants from {@link JLabel}.
     *
     * @param component to wrap in the a background image
     * @param backgroundIcon the background image (Icon)
     * @param verticalAlignment vertical alignment. See constants in JLabel.
     * @param horizontalAlignment horizontal alignment. See constants in JLabel.
     * @return the wrapping JPanel
     * @see "http://www.java-tips.org/java-se-tips/javax.swing/wrap-a-swing-jcomponent-in-a-background-image.html"
     */
    public static JPanel wrapInBackgroundImage(JComponent component,
            Icon backgroundIcon,
            int verticalAlignment,
            int horizontalAlignment) {

        // make the passed in swing component transparent
        component.setOpaque(false);

        // create wrapper JPanel
        JPanel backgroundPanel = new JPanel(new GridBagLayout());

        // add the passed in swing component first to ensure that it is in front
        backgroundPanel.add(component, gbc);

        // create a label to paint the background image
        JLabel backgroundImage = new JLabel(backgroundIcon);

        // set minimum and preferred sizes so that the size of the image
        // does not affect the layout size
        backgroundImage.setPreferredSize(new Dimension(1,1));
        backgroundImage.setMinimumSize(new Dimension(1,1));

        // align the image as specified.
        backgroundImage.setVerticalAlignment(verticalAlignment);
        backgroundImage.setHorizontalAlignment(horizontalAlignment);

        // add the background label
        backgroundPanel.add(backgroundImage, gbc);

        // return the wrapper
        return backgroundPanel;
    }

}


text:
/* EXPERIMENTAL (really) */
/* Copyright (c) 2009 Google Inc.
 *
 * 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 com.google.orkut.client.api;

/**
 * Factory for creating transaction related to friends. Use this class if you
 * want to:
 * <ul>
 * <li> Fetch list of friends of a user
 * <li> Send or Revoke a friend request
 * <li> Accept or Reject a friend request
 * <li> Remove a user from your friend list
 * <li> Fetch list of pending friend requests
 * </ul>
 *
 * @author Sachin Shenoy
 */
public class FriendTxFactory {

  /**
   * Returns {@link GetFriendTx} object to fetch self friends.
   */
  public GetFriendTx getSelfFriends() {
    return new GetFriendTx(Constants.USERID_ME, 0);
  }

  /**
   * Returns {@link GetFriendTx} object to fetch friends of the given user.
   */
  public GetFriendTx getFriendsOf(String userId) {
    return new GetFriendTx(userId, 0);
  }

  /**
   * Returns a {@link GetFriendTx} object to fetch the next set of friends.
   *
   * @param prev the previous {@link GetFriendTx} to fetch friends
   */
  public GetFriendTx getNextFriends(GetFriendTx prev) {
    return new GetFriendTx(prev);
  }

  /**
   * Returns {@link FriendRequestTx} object to send a friend request.
   *
   * @param personId id of the person to send the friend request to
   */
  public FriendRequestTx sendFriendRequest(String personId) {
    return new FriendRequestTx(MethodNames.FRIEND_REQUEST_SEND, personId);
  }

  /**
   * Returns {@link FriendRequestTx} object to accept a friend request.
   *
   * @param personId id of the person whose friend request to accept to
   */
  public FriendRequestTx acceptFriendRequest(String personId) {
    return new FriendRequestTx(MethodNames.FRIEND_REQUEST_ACCEPT, personId);
  }

  /**
   * Returns {@link Transaction} object to revoke a friend request. Use this
   * when you want to revoke (or take back) a friend request that you have sent.
   *
   * @param personId
   */
  public Transaction revokeFriendRequest(String personId) {
    return denyFriendRequestHelper(MethodNames.FRIEND_REQUEST_REVOKE, personId);
  }

  /**
   * Returns {@link Transaction} object to reject a friend request.
   *
   * @param personId id of the person whose friend request is to be rejected
   */
  public Transaction rejectFriendRequest(String personId) {
    return denyFriendRequestHelper(MethodNames.FRIEND_REQUEST_REJECT, personId);
  }

  /**
   * Removes a friend request.
   */
  public Transaction removeFriendRequest(String personId) {
    return denyFriendRequestHelper(MethodNames.FRIEND_REMOVE, personId);
  }

  /**
   * Gets pending friend requests.
   */
  public PendingFriendRequestTx getPendingFriendRequest() {
    return new PendingFriendRequestTx();
  }

  /**
   * Gets birthday notification of your friends.
   */
  public BirthdayNotificationTx getBirthdayNotification() {
    return new BirthdayNotificationTx();
  }

  /**
   * Helper to handle all the negative cases of friend request, like reject,
   * revoke, remove etc.
   */
  private Transaction denyFriendRequestHelper(String method, String personId) {
    Transaction transaction = new Transaction(method);
    transaction.getOrkutRequest().setUserId(Constants.USERID_ME)
        .setGroupId(Group.FRIENDS)
        .addParameter(Params.PERSON_ID, personId);
    return transaction;
  }
}


text:
namespace Machete.Translators.Results
{
    using System.Collections.Generic;

    public class TranslateResultCollection<TSchema> :
        ITranslateResultCollection<TSchema>
        where TSchema : Entity
    {
        readonly TranslateContext<TSchema> _context;
        readonly List<TranslateResult<TSchema>> _results;

        public TranslateResultCollection(TranslateContext<TSchema> context)
        {
            _context = context;
            _results = new List<TranslateResult<TSchema>>();
        }

        public void Add(TranslateResult<TSchema> result)
        {
            _results.Add(result);
        }

        public TranslateResult<TSchema> ToResult()
        {
            return new CompositeTranslateResult<TSchema>(_context, _results);
        }
    }
}


text:
[![Build Status](https://asottile.visualstudio.com/asottile/_apis/build/status/pre-commit.pre-commit-hooks?branchName=master)](https://asottile.visualstudio.com/asottile/_build/latest?definitionId=17&branchName=master)
[![Azure DevOps coverage](https://img.shields.io/azure-devops/coverage/asottile/asottile/17/master.svg)](https://dev.azure.com/asottile/asottile/_build/latest?definitionId=17&branchName=master)

pre-commit-hooks
================

Some out-of-the-box hooks for pre-commit.

See also: https://github.com/pre-commit/pre-commit

### Using pre-commit-hooks with pre-commit

Add this to your `.pre-commit-config.yaml`

    -   repo: https://github.com/pre-commit/pre-commit-hooks
        rev: v2.1.0  # Use the ref you want to point at
        hooks:
        -   id: trailing-whitespace
        # -   id: ...

### Hooks available

- `check-added-large-files` - Prevent giant files from being committed.
    - Specify what is "too large" with `args: ['--maxkb=123']` (default=500kB).
    - If `git-lfs` is installed, lfs files will be skipped
      (requires `git-lfs>=2.2.1`)
- `check-ast` - Simply check whether files parse as valid python.
- `check-builtin-literals` - Require literal syntax when initializing empty or zero Python builtin types.
    - Allows calling constructors with positional arguments (e.g., `list('abc')`).
    - Allows calling constructors from the `builtins` (`__builtin__`) namespace (`builtins.list()`).
    - Ignore this requirement for specific builtin types with `--ignore=type1,type2,…`.
    - Forbid `dict` keyword syntax with `--no-allow-dict-kwargs`.
- `check-byte-order-marker` - Forbid files which have a UTF-8 byte-order marker
- `check-case-conflict` - Check for files with names that would conflict on a
  case-insensitive filesystem like MacOS HFS+ or Windows FAT.
- `check-docstring-first` - Checks for a common error of placing code before
  the docstring.
- `check-executables-have-shebangs` - Checks that non-binary executables have a
  proper shebang.
- `check-json` - Attempts to load all json files to verify syntax.
- `check-merge-conflict` - Check for files that contain merge conflict strings.
- `check-symlinks` - Checks for symlinks which do not point to anything.
- `check-vcs-permalinks` - Ensures that links to vcs websites are permalinks.
- `check-xml` - Attempts to load all xml files to verify syntax.
- `check-yaml` - Attempts to load all yaml files to verify syntax.
    - `--allow-multiple-documents` - allow yaml files which use the
      [multi-document syntax](http://www.yaml.org/spec/1.2/spec.html#YAML)
    - `--unsafe` - Instead of loading the files, simply parse them for syntax.
      A syntax-only check enables extensions and unsafe constructs which would
      otherwise be forbidden.  Using this option removes all guarantees of
      portability to other yaml implementations.
      Implies `--allow-multiple-documents`.
- `debug-statements` - Check for debugger imports and py37+ `breakpoint()`
  calls in python source.
- `detect-aws-credentials` - Checks for the existence of AWS secrets that you
  have set up with the AWS CLI.
  The following arguments are available:
  - `--credentials-file CREDENTIALS_FILE` - additional AWS CLI style
    configuration file in a non-standard location to fetch configured
    credentials from. Can be repeated multiple times.
  - `--allow-missing-credentials` - Allow hook to pass when no credentials are
    detected.
- `detect-private-key` - Checks for the existence of private keys.
- `double-quote-string-fixer` - This hook replaces double quoted strings
  with single quoted strings.
- `end-of-file-fixer` - Makes sure files end in a newline and only a newline.
- `fix-encoding-pragma` - Add `# -*- coding: utf-8 -*-` to the top of python files.
    - To remove the coding pragma pass `--remove` (useful in a python3-only codebase)
- `file-contents-sorter` - Sort the lines in specified files (defaults to alphabetical). You must provide list of target files as input to it. Note that this hook WILL remove blank lines and does NOT respect any comments.
- `flake8` - Run flake8 on your python files.
- `forbid-new-submodules` - Prevent addition of new git submodules.
- `mixed-line-ending` - Replaces or checks mixed line ending.
    - `--fix={auto,crlf,lf,no}`
        - `auto` - Replaces automatically the most frequent line ending. This is the default argument.
        - `crlf`, `lf` - Forces to replace line ending by respectively CRLF and LF.
        - `no` - Checks if there is any mixed line ending without modifying any file.
- `name-tests-test` - Assert that files in tests/ end in `_test.py`.
    - Use `args: ['--django']` to match `test*.py` instead.
- `no-commit-to-branch` - Protect specific branches from direct checkins.
    - Use `args: [--branch, staging, --branch, master]` to set the branch.
      `master` is the default if no argument is set.
    - `-b` / `--branch` may be specified multiple times to protect multiple
      branches.
- `pretty-format-json` - Checks that all your JSON files are pretty.  "Pretty"
  here means that keys are sorted and indented.  You can configure this with
  the following commandline options:
    - `--autofix` - automatically format json files
    - `--indent ...` - Control the indentation (either a number for a number of spaces or a string of whitespace).  Defaults to 4 spaces.
    - `--no-sort-keys` - when autofixing, retain the original key ordering (instead of sorting the keys)
    - `--top-keys comma,separated,keys` - Keys to keep at the top of mappings.
- `requirements-txt-fixer` - Sorts entries in requirements.txt and removes incorrect entry for `pkg-resources==0.0.0`
- `sort-simple-yaml` - Sorts simple YAML files which consist only of top-level keys, preserving comments and blocks.
- `trailing-whitespace` - Trims trailing whitespace.
    - To preserve Markdown [hard linebreaks](https://github.github.com/gfm/#hard-line-break)
      use `args: [--markdown-linebreak-ext=md]` (or other extensions used
      by your markdownfiles).  If for some reason you want to treat all files
      as markdown, use `--markdown-linebreak-ext=*`.

### Deprecated / replaced hooks

- `autopep8-wrapper`: instead use
  [mirrors-autopep8](https://github.com/pre-commit/mirrors-autopep8)
- `pyflakes`: instead use `flake8`

### As a standalone package

If you'd like to use these hooks, they're also available as a standalone
package.

Simply `pip install pre-commit-hooks`