All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.fx.ui.controls.styledtext.VerifyEvent Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
/*******************************************************************************
 * Copyright (c) 2014 BestSolution.at and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * 	Tom Schindl - initial API and implementation
 *******************************************************************************/
package org.eclipse.fx.ui.controls.styledtext;

import javafx.event.EventTarget;
import javafx.event.EventType;
import javafx.scene.input.InputEvent;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;

/**
 * Key event sent
 */
public class VerifyEvent extends InputEvent {
	/**
	 * the event type
	 */
	public static final EventType VERIFY = new EventType(InputEvent.ANY, "VERIFY"); //$NON-NLS-1$
	/**
	 * 
	 */
	private static final long serialVersionUID = -4592943665566096149L;
	private String character;
	private String text;
	private KeyCode code;
	private boolean shiftDown;
	private boolean controlDown;
	private boolean altDown;
	private boolean metaDown;

	/**
	 * The event
	 * 
	 * @param source
	 *            the source
	 * @param target
	 *            the target
	 * @param event
	 *            the key
	 */
	public VerifyEvent(Object source, EventTarget target, KeyEvent event) {
		super(source, target, VERIFY);
		boolean isKeyTyped = event.getEventType() == KeyEvent.KEY_TYPED;

		this.character = isKeyTyped ? event.getCharacter() : KeyEvent.CHAR_UNDEFINED;
		this.text = isKeyTyped ? "" : event.getText(); //$NON-NLS-1$
		this.code = isKeyTyped ? KeyCode.UNDEFINED : event.getCode();
		this.shiftDown = event.isShiftDown();
		this.controlDown = event.isControlDown();
		this.altDown = event.isAltDown();
		this.metaDown = event.isMetaDown();
	}

	/**
	 * @return the character
	 */
	public String getCharacter() {
		return this.character;
	}

	/**
	 * @return the text
	 */
	public String getText() {
		return this.text;
	}

	/**
	 * @return the key code
	 */
	public KeyCode getCode() {
		return this.code;
	}

	/**
	 * @return true when shift key is down
	 */
	public boolean isShiftDown() {
		return this.shiftDown;
	}
	
	/**
	 * @return true when control key is down
	 */
	public boolean isControlDown() {
		return this.controlDown;
	}
	
	/**
	 * @return true when alt key is down
	 */
	public boolean isAltDown() {
		return this.altDown;
	}

	/**
	 * @return true when meta key is down
	 */
	public boolean isMetaDown() {
		return this.metaDown;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy