Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004, 2010 BREDEX GmbH.
 * 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:
 *     BREDEX GmbH - initial API and implementation and/or initial documentation
 *******************************************************************************/

import java.awt.Event;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import javax.swing.UIManager;

public class Main {
    /**
     * ID of Metal Look and Feel.
     */
    private static final String METAL_LAF_ID = "Metal";

    /**
     * gives default modifier of the current OS.
     * 
     * @return meta (command) for OSX, control for Windows/Linux etc 
     */
    public static int getSystemDefaultModifier() {
        if (!(UIManager.getLookAndFeel().getID().equals(METAL_LAF_ID))) {
            int mask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
            if (mask == Event.META_MASK) {
                return KeyEvent.VK_META;
            } else if (mask == Event.ALT_MASK) {
                return KeyEvent.VK_ALT;
            }
        }
        return KeyEvent.VK_CONTROL;
    }
}