<commit_before>/**
 * 
 */
package org.mwc.cmap.core.custom_widget;

import java.text.ParseException;
import java.util.Vector;

import org.eclipse.nebula.widgets.formattedtext.FormattedText;
import org.eclipse.nebula.widgets.formattedtext.MaskFormatter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.mwc.cmap.core.CorePlugin;
import org.mwc.cmap.gridharness.data.base60.Sexagesimal;
import org.mwc.cmap.gridharness.data.base60.SexagesimalFormat;

import MWC.GenericData.WorldLocation;

/**
 * This is a custom composite to specify the world location
 * in lat and long
 * @author Ayesha
 *
 */
public class CWorldLocation extends Composite
{
  private FormattedText myLatitude;

  private FormattedText myLongitude;
  
  private Vector<LocationModifiedListener> _locationModifiedListeners = new Vector<>();

  public CWorldLocation(Composite parent, int style)
  {
    super(parent, style);
    final GridLayout rows = new GridLayout(2,true);
    rows.marginLeft = rows.marginRight = 0;
    rows.marginTop = rows.marginBottom = 0;
    setLayout(rows);
    GridData gd = new GridData();
    gd.heightHint=40;
    setLayoutData(gd);
    myLatitude = new FormattedText(this, SWT.BORDER);
    myLongitude = new FormattedText(this, SWT.BORDER);
    GridData data1 = new GridData();
    data1.widthHint = 90;
    myLatitude.getControl().setLayoutData(data1);
    GridData data2 = new GridData();    
    data2.widthHint = 100;
    myLongitude.getControl().setLayoutData(data2);
    myLatitude.setFormatter(new IgnoreTabsMaskFormatter(getFormat().getNebulaPattern(false)));
    myLongitude.setFormatter(new IgnoreTabsMaskFormatter(getFormat().getNebulaPattern(true)));

    myLatitude.getControl().addModifyListener(new ModifyListener() {

      @Override
      public void modifyText(ModifyEvent event)
      {
        valueModified(event.getSource());
      }});
    myLatitude.getControl().addModifyListener(new ModifyListener() {

      @Override
      public void modifyText(ModifyEvent event)
      {
        valueModified(event.getSource());
      }});
  }
  
  public void addLocationModifiedListener(LocationModifiedListener listener) {
    _locationModifiedListeners.add(listener);
  }
 
  
  private void valueModified(final Object source)
  {
    LocationModifiedEvent event = new LocationModifiedEvent(source,myLatitude.getValue(),myLongitude.getValue());
    for(LocationModifiedListener listener:_locationModifiedListeners) {
      listener.modifyValue(event);
    }
  }
  

  private SexagesimalFormat getFormat() {
    //intentionally reevaluated each time
    return CorePlugin.getDefault().getLocationFormat();
  }
  <commit_msg>Provide both MS-Windows and MACOS event handlers for CWorldLocation editor controls.<commit_after>/**
 * 
 */
package org.mwc.cmap.core.custom_widget;

import java.text.ParseException;
import java.util.Vector;

import org.eclipse.nebula.widgets.formattedtext.FormattedText;
import org.eclipse.nebula.widgets.formattedtext.MaskFormatter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SegmentEvent;
import org.eclipse.swt.events.SegmentListener;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.mwc.cmap.core.CorePlugin;
import org.mwc.cmap.gridharness.data.base60.Sexagesimal;
import org.mwc.cmap.gridharness.data.base60.SexagesimalFormat;

import MWC.GenericData.WorldLocation;

/**
 * This is a custom composite to specify the world location
 * in lat and long
 * @author Ayesha
 *
 */
public class CWorldLocation extends Composite
{
  private FormattedText myLatitude;

  private FormattedText myLongitude;
  
  private Vector<LocationModifiedListener> _locationModifiedListeners = new Vector<>();

  public CWorldLocation(Composite parent, int style)
  {
    super(parent, style);
    final GridLayout rows = new GridLayout(2,true);
    rows.marginLeft = rows.marginRight = 0;
    rows.marginTop = rows.marginBottom = 0;
    setLayout(rows);
    GridData gd = new GridData();
    gd.heightHint=40;
    setLayoutData(gd);
    myLatitude = new FormattedText(this, SWT.BORDER);
    myLongitude = new FormattedText(this, SWT.BORDER);
    GridData data1 = new GridData();
    data1.widthHint = 90;
    myLatitude.getControl().setLayoutData(data1);
    GridData data2 = new GridData();    
    data2.widthHint = 100;
    myLongitude.getControl().setLayoutData(data2);
    myLatitude.setFormatter(new IgnoreTabsMaskFormatter(getFormat().getNebulaPattern(false)));
    myLongitude.setFormatter(new IgnoreTabsMaskFormatter(getFormat().getNebulaPattern(true)));

    // note, we're having trouble hearing the correct events.
    // we only hear SegmentListener events on MS-Windows, and 
    // we only hear ModifyListener events on MACOS.  So,
    // we'll listen to both
    
    myLatitude.getControl().addModifyListener(new ModifyListener()
    {
      @Override
      public void modifyText(ModifyEvent event)
      {
        valueModified(event.getSource());
      }
    });
    myLongitude.getControl().addModifyListener(new ModifyListener()
    {
      @Override
      public void modifyText(ModifyEvent event)
      {
        valueModified(event.getSource());
      }
    });
    myLatitude.getControl().addSegmentListener(new SegmentListener()
    {
      @Override
      public void getSegments(SegmentEvent event)
      {
        valueModified(event.getSource());
      }
    });
    myLongitude.getControl().addSegmentListener(new SegmentListener()
    {
      @Override
      public void getSegments(SegmentEvent event)
      {
        valueModified(event.getSource());
      }
    });

  }
  
  public void addLocationModifiedListener(LocationModifiedListener listener) {
    _locationModifiedListeners.add(listener);
  }
 
  
  private void valueModified(final Object source)
  {
    LocationModifiedEvent event = new LocationModifiedEvent(source,myLatitude.getValue(),myLongitude.getValue());
    for(LocationModifiedListener listener:_locationModifiedListeners) {
      listener.modifyValue(event);
    }
  }
  

  private SexagesimalFormat getFormat() {
    //intentionally reevaluated each time
    return CorePlugin.getDefault().getLocationFormat();
  }
  
{'fraction_non_alphanumeric': 0.10136570561456752, 'fraction_numerical': 0.006069802731411229, 'mean_word_length': 4.101393188854489, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6962891', 'n_tokens_mistral': 2007, 'n_tokens_neox': 1959, 'n_words': 374}