📄 bsapplauncherplugin.java
字号:
package edu.ou.kmi.buddyspace.plugins.applauncher;
/*
* BSAppLauncherPlugin.java
*
* Project: BuddySpace
* (C) Copyright Knowledge Media Institute 2003
*
*
* Created on 7 April 2003, 10:19
*/
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.net.*;
import java.util.*;
import java.io.*;
import org.jabber.jabberbeans.util.*;
import edu.ou.kmi.buddyspace.core.*;
import edu.ou.kmi.buddyspace.gui.*;
import edu.ou.kmi.buddyspace.utils.*;
import edu.ou.kmi.buddyspace.plugins.*;
//import edu.ou.kmi.buddyspace.plugins.webbrowser.core.*;
import edu.ou.kmi.buddyspace.plugins.webbrowser.gui.*;
/**
* <code>BSAppLauncherPlugin</code> is provides launching of external applications.
*
* @author Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
*/
public class BSAppLauncherPlugin extends BSPlugin
implements ActionListener {
private JMenuItem lyceumMenuItem;
/*private JTextField lyceumPathTextField;
final static String DEF_LYCEUM_PATH = "C:\\Program Files\\Lyceum\\Lyceum.exe";
public static final String PREF_NAME_LYCEUM_PATH = "lyceumPath";
public static String lyceumPath = DEF_LYCEUM_PATH;*/
/** Constructor */
public BSAppLauncherPlugin(BSMainFrame mainFrame, JTabbedPane tabbedPane, BSCore core) {
super(mainFrame, tabbedPane, core);
}
/** Inits plugin core */
protected void initCore() {
//confBean = new BSConfBean();
}
/** Inits plugin GUI */
protected void initGUI() {
}
/** Adds plugin GUI controls */
protected void addGUIControls() {
/*lyceumMenuItem = new JMenuItem("Lyceum");
lyceumMenuItem.addActionListener(this);
mainFrame.addPluginJabberMenuItem(lyceumMenuItem);*/
}
/** Connects plugin to BuddySpace beans */
protected void connectBeans() {
}
/** Handles connection change to connected */
public void connected() {
super.connected();
}
/** Handles connection change to disconnected */
public void disconnected() {
}
/** Handles GUI controls actions */
public void actionPerformed(ActionEvent evt) {
/*if (evt.getSource() == lyceumMenuItem) {
launchApp(lyceumPath);
}*/
}
/** Loads preferences. */
protected void loadPreferences() {
/*String[] names = {PREF_NAME_LYCEUM_PATH};
String[] defaults = {DEF_LYCEUM_PATH};
Vector prefs = mainFrame.loadPreferences(names, defaults);
if (prefs != null && prefs.size() == 1)
lyceumPath = (String) prefs.elementAt(0);*/
}
/** Returns components and their names for display in preferences dialog.
* Empty implementation - returns null.
*/
public void getPreferencesTab(Vector components, Vector names) {
/*GridBagConstraints gbc;
JPanel prefsPanel = new JPanel(new GridBagLayout());
JLabel label = new JLabel("Path to Lyceum:");
gbc = new GridBagConstraints();
gbc.gridy = 1;
gbc.anchor = GridBagConstraints.WEST;
prefsPanel.add(label, gbc);
lyceumPathTextField = new JTextField(lyceumPath);
gbc = new GridBagConstraints();
gbc.gridy = 2;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 1;
prefsPanel.add(lyceumPathTextField, gbc);
components.add(prefsPanel);
names.add("Application Launcher");*/
}
/** Stores preferences from preferences tab.
* Empty implementation.
*/
public boolean storePreferences() {
/*lyceumPath = lyceumPathTextField.getText();
String[] names = {PREF_NAME_LYCEUM_PATH};
String[] values = {lyceumPath};
mainFrame.addAndSavePreferences(names, values);*/
return true;
}
/**
* Performs action within given namespace for given JID.
* Returns if action was performed.
*/
public boolean performAction(JID jid, String namespace) {
if (namespace != null && namespace.equals("app")) {
if (jid == null) return false;
String appPath = jid.toString();
return launchApp(appPath);
}
else
return false;
}
/** Adds supported namespaces and their names */
public void getSupportedNamespaces(Vector namespaces, Vector names) {
namespaces.addElement(new String("app"));
names.addElement(new String("Application"));
}
/** Updates LAF of all plug-ins */
public void updateLAF() {
}
private boolean launchApp(String appPath) {
try {
if (OSVersion.isWindowsPlatform()) {
//String command = new String("cmd.exe /c start \"BS app launcher\" \"" + appPath + "\"");
//String command = new String("cmd.exe /c start /D\"C:\\Program Files\\Far\" \"BS app launcher\" far.exe");
//String command = new String("cmd.exe /c start /D\"C:\\Program Files\\Far\" \"BS app launcher\" far.exe");
File f = new File(appPath);
String filename = f.getName();
String path = f.getParent();
String absPath = f.getAbsoluteFile().getParent();
String command = null;
/*if (absPath == null) {
if (OSVersion.isWindowsNTPlatform())
command = new String("cmd.exe /c start \"BS app launcher\" " + appPath);
else if (OSVersion.isWindows9xPlatform())
command = new String("command.com /c start " + appPath);
}
else {
absPath = absPath.substring(0, absPath.indexOf(filename));
if (OSVersion.isWindowsNTPlatform())
command = new String("cmd.exe /c start /D\"" + absPath + "\" \"BS app launcher\" " + filename);
else if (OSVersion.isWindows9xPlatform())
command = new String("command.com /c start \"" + absPath + filename);
}
if (command != null) {
System.out.println(command);
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
}*/
if (path == null) {
if (OSVersion.isWindowsNTPlatform())
command = new String("cmd.exe /c start \"BS app launcher\" \"" + appPath + "\"");
else if (OSVersion.isWindows9xPlatform())
command = new String("command.com /c start \"" + appPath + "\"");
}
else {
if (OSVersion.isWindowsNTPlatform())
command = new String("cmd.exe /c start /D\"" + absPath + "\" \"BS app launcher\" \"" + filename + "\"");
else if (OSVersion.isWindows9xPlatform())
command = new String("command.com /c start \"" + absPath + "\\" + filename + "\"");
}
if (command != null) {
System.out.println(command);
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
}
}
else {
String command = new String(appPath);
Process p = Runtime.getRuntime().exec(command);
//p.waitFor();
}
} catch (Exception e) {
JOptionPane.showMessageDialog(mainFrame,
"Cannot launch application.",
"Application launcher error",
JOptionPane.ERROR_MESSAGE);
return false;
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -