Mercurial > projects > dwt-addons
view dwtx/jface/bindings/keys/formatting/EmacsKeyFormatter.d @ 39:644f1334b451
fix anon classes
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 08 Apr 2008 22:05:42 +0200 |
parents | e0f0aaf75edd |
children | ea8ff534f622 |
line wrap: on
line source
/******************************************************************************* * Copyright (c) 2004, 2005 IBM Corporation 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: * IBM Corporation - initial API and implementation * Port to the D programming language: * Frank Benoit <benoit@tionex.de> *******************************************************************************/ module dwtx.jface.bindings.keys.formatting.EmacsKeyFormatter; import dwtx.jface.bindings.keys.formatting.AbstractKeyFormatter; import dwtx.jface.bindings.keys.IKeyLookup; import dwtx.jface.bindings.keys.KeyLookupFactory; import dwtx.jface.bindings.keys.KeySequence; import dwtx.jface.bindings.keys.KeyStroke; import dwtx.jface.util.Util; import dwt.dwthelper.utils; import dwt.dwthelper.ResourceBundle; /** * <p> * A key formatter providing the Emacs-style accelerators using single letters * to represent the modifier keys. * </p> * * @since 3.1 */ public final class EmacsKeyFormatter : AbstractKeyFormatter { /** * The resource bundle used by <code>format()</code> to translate formal * string representations by locale. */ private const static ResourceBundle RESOURCE_BUNDLE; static this(){ RESOURCE_BUNDLE = ResourceBundle.getBundle( import("dwtx.jface.bindings.keys.formatting.EmacsKeyFormatter.properties")); } /** * Formats an individual key into a human readable format. This converts the * key into a format similar to Xemacs. * * @param key * The key to format; must not be <code>null</code>. * @return The key formatted as a string; should not be <code>null</code>. */ public String format(int key) { IKeyLookup lookup = KeyLookupFactory.getDefault(); if (lookup.isModifierKey(key)) { String formattedName = Util.translateString(RESOURCE_BUNDLE, lookup .formalNameLookup(key), null); if (formattedName !is null) { return formattedName; } } return super.format(key).toLowerCase(); } /* * (non-Javadoc) * * @see dwtx.jface.bindings.keys.AbstractKeyFormatter#getKeyDelimiter() */ protected String getKeyDelimiter() { return Util.translateString(RESOURCE_BUNDLE, KEY_DELIMITER_KEY, KeyStroke.KEY_DELIMITER); } /* * (non-Javadoc) * * @see dwtx.jface.bindings.keys.AbstractKeyFormatter#getKeyStrokeDelimiter() */ protected String getKeyStrokeDelimiter() { return Util.translateString(RESOURCE_BUNDLE, KEY_STROKE_DELIMITER_KEY, KeySequence.KEY_STROKE_DELIMITER); } /* * (non-Javadoc) * * @see dwtx.jface.bindings.keys.AbstractKeyFormatter#sortModifierKeys(int) */ protected int[] sortModifierKeys(int modifierKeys) { IKeyLookup lookup = KeyLookupFactory.getDefault(); int[] sortedKeys = new int[4]; int index = 0; if ((modifierKeys & lookup.getAlt()) !is 0) { sortedKeys[index++] = lookup.getAlt(); } if ((modifierKeys & lookup.getCommand()) !is 0) { sortedKeys[index++] = lookup.getCommand(); } if ((modifierKeys & lookup.getCtrl()) !is 0) { sortedKeys[index++] = lookup.getCtrl(); } if ((modifierKeys & lookup.getShift()) !is 0) { sortedKeys[index++] = lookup.getShift(); } return sortedKeys; } }