本文整理汇总了Java中java.awt.Desktop.Action类的典型用法代码示例。如果您正苦于以下问题:Java Action类的具体用法?Java Action怎么用?Java Action使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Action类属于java.awt.Desktop包,在下文中一共展示了Action类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isSupported
import java.awt.Desktop.Action; //导入依赖的package包/类
@Override
public boolean isSupported(Action action) {
switch(action) {
case OPEN:
case EDIT:
case PRINT:
case MAIL:
case BROWSE:
case MOVE_TO_TRASH:
case APP_SUDDEN_TERMINATION:
case APP_EVENT_SYSTEM_SLEEP:
return true;
case APP_EVENT_USER_SESSION:
return isEventUserSessionSupported;
default:
return false;
}
}
示例2: connectToServerUsingProtocol
import java.awt.Desktop.Action; //导入依赖的package包/类
/**
* Connects to the given server (IP and Port) using an empty (no) password.
* Other than
* {@link GTAController#connectToServer(String)} and
* {@link GTAController#connectToServer(String, String)}, this method uses the
* <code>samp://</code> protocol to connect to make the samp launcher connect to
* the server.
*
* @param ipAndPort
* the server to connect to
* @return true if it was most likely successful
*/
private static boolean connectToServerUsingProtocol(final String ipAndPort) {
if (!OSUtility.isWindows()) {
return false;
}
try {
Logging.info("Connecting using protocol.");
final Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Action.BROWSE)) {
desktop.browse(new URI("samp://" + ipAndPort));
return true;
}
}
catch (final IOException | URISyntaxException exception) {
Logging.warn("Error connecting to server.", exception);
}
return false;
}
示例3: display
import java.awt.Desktop.Action; //导入依赖的package包/类
/**
* Display user guide section.
*
* @param section the section
*/
public void display(String section) {
URL url = null;
try {
if (section == null) {
url = new URL(USER_GUIDE_URL);
} else {
url = new URL(USER_GUIDE_URL + "#" + section);
}
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) {
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(url.toURI());
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
}
示例4: display
import java.awt.Desktop.Action; //导入依赖的package包/类
/**
* Display report issue section.
*/
public void display() {
URL url = null;
try {
url = new URL(REPORT_ISSUE_URL);
} catch (MalformedURLException e1) {
ConsoleManager.getInstance().exception(this, e1);
}
if (url != null) {
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) {
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(url.toURI());
} catch (IOException | URISyntaxException e) {
ConsoleManager.getInstance().exception(this, e);
}
}
}
}
示例5: executeFile
import java.awt.Desktop.Action; //导入依赖的package包/类
/**
* Executes the given file.
* @param file The file to be executed
* @return True on success; false otherwise
*/
public static boolean executeFile(final File file) {
final boolean desktopSupported = Desktop.isDesktopSupported();
if (desktopSupported && file.exists()) {
final Desktop desktop = Desktop.getDesktop();
final boolean canOpen = desktop.isSupported(Action.OPEN);
if (canOpen) {
try {
desktop.open(file);
return true;
} catch (final Exception ex) {
ex.printStackTrace();
}
}
}
return false;
}
示例6: browse
import java.awt.Desktop.Action; //导入依赖的package包/类
public static void browse(String url) throws BrowseException {
if(Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
if(desktop.isSupported(Action.BROWSE)) {
try {
desktop.browse(new URI(url));
} catch (Exception e) {
throw new BrowseException();
}
}
else {
throw new BrowseException();
}
}
else {
throw new BrowseException();
}
}
示例7: openURL
import java.awt.Desktop.Action; //导入依赖的package包/类
/**
* Open the given URL in the system web browser.
*
* @param uri
* the {@link URI} to be opened
*
* @return <code>true</code> if call to open was successfully made,
* <code>false</code> otherwise. A value of <code>true</code> DOES
* NOT guarantee that the {@link URI} was opened, but only that the
* call was successfully made.
*/
public static boolean openURL(URI uri) {
if(!Desktop.isDesktopSupported()) {
return false;
}
Desktop d = Desktop.getDesktop();
if(!d.isSupported(Action.BROWSE)) {
return false;
}
try {
d.browse(uri);
return true;
} catch (IOException e) {
return false;
}
}
示例8: createOpenParentFolderAction
import java.awt.Desktop.Action; //导入依赖的package包/类
/**
* Utility method to create an action that opened a given file.
* @param path path to the file
* @return corresponding action
*/
public static SeerClickableLabelAction createOpenParentFolderAction(final String path) {
return () -> {
File file = new File(path);
try {
if (file.exists() && System.getProperty("os.name").startsWith("Windows"))
Runtime.getRuntime().exec("Explorer /select," + file.getParentFile().getAbsolutePath() + "\\" + file.getName());
else {
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Action.OPEN))
Desktop.getDesktop().open(file.getParentFile());
}
}
catch (IOException | RuntimeException e) {
// ignored
}
};
}
示例9: openURL
import java.awt.Desktop.Action; //导入依赖的package包/类
/**
* Launch the given URL in the system browser
* @param url the URL to launch
*/
public static void openURL(String url) {
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Action.BROWSE)) {
try {
desktop.browse(new URI(url));
} catch (Exception e) {
JOptionPane.showMessageDialog(null, errMsg + ":\n" + e.getLocalizedMessage());
}
} else {
fallbackURL(url);
}
}
示例10: gotoHomepage
import java.awt.Desktop.Action; //导入依赖的package包/类
/**
* Launches browser with homepage.
*/
public void gotoHomepage() {
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) {
try {
Desktop.getDesktop().browse(new URI(HOMEPAGE));
}
catch (Exception e) {
System.err.println("Failed to launch browser with homepage!");
e.printStackTrace();
}
}
}
示例11: showDownloadPage
import java.awt.Desktop.Action; //导入依赖的package包/类
/**
* Show download page.
*/
public void showDownloadPage() {
if (client != null) {
URL url = client.getDownloadURL();
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) {
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(url.toURI());
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
}
}
示例12: isSupported
import java.awt.Desktop.Action; //导入依赖的package包/类
public boolean isSupported(Action action)
{
String check = null;
switch(action)
{
case BROWSE:
check = _BROWSE;
break;
case MAIL:
check = _MAIL;
break;
case EDIT:
check = _EDIT;
break;
case PRINT:
check = _PRINT;
break;
case OPEN: default:
check = _OPEN;
break;
}
return this.supportCommand(check);
}
示例13: isSupported
import java.awt.Desktop.Action; //导入依赖的package包/类
public boolean isSupported(Action action)
{
String check = null;
switch(action)
{
case BROWSE:
check = _BROWSE;
break;
case MAIL:
check = _MAIL;
break;
case EDIT:
check = _EDIT;
break;
case PRINT:
check = _PRINT;
break;
case OPEN: default:
check = _OPEN;
break;
}
return this.supportCommand(check);
}
示例14: HyperlinkAction
import java.awt.Desktop.Action; //导入依赖的package包/类
/**
*
* @param uri the target uri, maybe null.
* @param desktopAction the type of desktop action this class should perform, must be
* BROWSE or MAIL
* @throws HeadlessException if {@link
* GraphicsEnvironment#isHeadless()} returns {@code true}
* @throws UnsupportedOperationException if the current platform doesn't support
* Desktop
* @throws IllegalArgumentException if unsupported action type
*/
public HyperlinkAction(URI uri, Action desktopAction) {
super();
if (!Desktop.isDesktopSupported()) {
throw new UnsupportedOperationException("Desktop API is not " +
"supported on the current platform");
}
if (desktopAction != Desktop.Action.BROWSE && desktopAction != Desktop.Action.MAIL) {
throw new IllegalArgumentException("Illegal action type: " + desktopAction +
". Must be BROWSE or MAIL");
}
this.desktopAction = desktopAction;
getURIVisitor();
setTarget(uri);
}
示例15: detectFromOs
import java.awt.Desktop.Action; //导入依赖的package包/类
public static LaunchingStrategy detectFromOs() {
if (Desktop.isDesktopSupported() &&
Desktop.getDesktop().isSupported(Action.BROWSE)) {
return DESKTOP_BROWSE;
} else {
String os = System.getProperty("os.name").toLowerCase();
if (os.contains("nix") || os.contains("nux") ||
os.contains("aix")) return XDG_OPEN_COMMAND;
else if (os.contains("mac")) return OPEN_COMMAND;
else return BROWSER_LAUNCHING_NOT_SUPPORTED;
}
}