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

com.github.becausetesting.commonswindow.utils.ui.PlatformUIUtils Maven / Gradle / Ivy

package com.github.becausetesting.commonswindow.utils.ui;

/*-
 * false
 * commons-window
 * sectionDelimiter
 * Copyright (C) 2016 Alter Hu
 * sectionDelimiter
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

/*-
 * #%L
 * commons-window
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2016 Alter Hu
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */


import java.util.Locale;
import java.util.ResourceBundle;

import javax.swing.AbstractButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

import com.sun.jna.Platform;



public class PlatformUIUtils {

	
	private static ResourceBundle rs=ResourceBundle.getBundle("Message",Locale.getDefault());

	public static void quitWindow(JFrame frame) {
		int confirm = JMessageDialogUtils.confirm(frame, rs.getString("quit.title"), rs.getString("quit.message"));
		if (confirm == JOptionPane.YES_OPTION) {
			System.exit(0);
		}
	}
	/**
	 * Set mnemonic on button in a platform dependant manner.
	 *
	 * @param button
	 *            Button
	 * @param mnemonic
	 *            Mnemonic
	 */
	public static void setMnemonic(AbstractButton button, int mnemonic) {
		setMnemonic(button, (char) mnemonic, -1);
	}

	/**
	 * Set mnemonic on button in a platform dependant manner.
	 *
	 * @param button
	 *            Button
	 * @param mnemonic
	 *            Mnemonic
	 */
	public static void setMnemonic(AbstractButton button, char mnemonic) {
		setMnemonic(button, mnemonic, -1);
	}

	/**
	 * Set mnemonic on button in a platform dependant manner.
	 *
	 * @param button
	 *            Button
	 * @param mnemonic
	 *            Mnemonic
	 * @param index
	 *            Index of string to underline
	 */
	public static void setMnemonic(AbstractButton button, int mnemonic, int index) {
		setMnemonic(button, (char) mnemonic, index);
	}

	/**
	 * Set mnemonic on button in a platform dependant manner.
	 *
	 * @param button
	 *            Button
	 * @param mnemonic
	 *            Mnemonic
	 * @param index
	 *            Index of string to underline
	 */
	public static void setMnemonic(AbstractButton button, char mnemonic, int index) {
		/*
		 * Only set mnemonic if not using Mac OS - they are not recommended by
		 * the style guidelines there and clash with established commands
		 */
		if (!Platform.isMac()) {
			button.setMnemonic(mnemonic);

			if (index >= 0) {
				button.setDisplayedMnemonicIndex(index);
			}
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy