/*
 * Licensed Materials - Property of Rogue Wave Software, Inc. 
 * © Copyright Rogue Wave Software, Inc. 2014, 2015 
 * © Copyright IBM Corp. 2009, 2014
 * © Copyright ILOG 1996, 2009
 * All Rights Reserved.
 *
 * Note to U.S. Government Users Restricted Rights:
 * The Software and Documentation were developed at private expense and
 * are "Commercial Items" as that term is defined at 48 CFR 2.101,
 * consisting of "Commercial Computer Software" and
 * "Commercial Computer Software Documentation", as such terms are
 * used in 48 CFR 12.212 or 48 CFR 227.7202-1 through 227.7202-4,
 * as applicable.
 */

import ilog.views.*;
import java.awt.event.*;

/**
 * An object interactor for the marker selection.
 * When clicking on the selection handle, the marker changed its type.
 */
public class MyMarkerEdition
  extends IlvReshapeSelection
{ 
  /** 
   * Creates the new selection.
   */
  public MyMarkerEdition()
  {
    super();
  }

  /**
   * Processes the button down events.
   * @return <code>true</code> if the event has been processed,
   *         <code>false</code> otherwise.
   */
  protected boolean handleButtonDown(IlvDrawSelection sel, MouseEvent event,
                                     IlvObjectInteractorContext context)
  {
    if ((event.getModifiers() & InputEvent.BUTTON2_MASK) != 0 ||
        (event.getModifiers() & InputEvent.BUTTON3_MASK) != 0)
      return true;

    MyMarkerSelection msel = (MyMarkerSelection)sel;
    MyMarker marker = (MyMarker)msel.getObject();

    // even though the object interactor is on the selection, it
    // modifies the selected object, not the selection
    final int tp = (marker.getType() >= 512 ? 1 : marker.getType() * 2);
    IlvGraphicBag bag = marker.getGraphicBag();
    if (bag == null)
      marker.setType(tp);
    else
      bag.applyToObject(marker, new IlvApplyObject() {
          public void apply(IlvGraphic g, Object arg) {
            ((MyMarker)g).setType(tp);
          }
        }, null, true);
    return true;
  }
}