![JAR search and dependency download from the Maven repository](/logo.png)
com.github.becausetesting.commonswindow.utils.PlatformUIUtils Maven / Gradle / Ivy
package com.github.becausetesting.commonswindow.utils;
/*-
* 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 org.apache.log4j.Logger;
import com.github.becausetesting.commonswindow.utils.ui.JMessageDialogUtils;
import com.sun.jna.Platform;
public class PlatformUIUtils {
private static Logger log=Logger.getLogger(PlatformUIUtils.class);
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) {
log.info("quit the window");
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