📄 bswebpanel.java
字号:
package edu.ou.kmi.buddyspace.plugins.webbrowser.gui;
/*
* BSWebPanel.java
*
* Project: BuddySpace
* (C) Copyright Knowledge Media Institute 2002
*
*
* Created on 27 September 2002, 17:45
*/
import javax.swing.*;
import javax.swing.event.*;
import java.net.*;
import java.awt.*;
import java.io.*;
import java.util.*;
import edu.ou.kmi.buddyspace.gui.*;
import edu.ou.kmi.buddyspace.utils.*;
/**
* <code>BSWebPanel</code> is the web browser plugin view.
*
* @author Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
*/
public class BSWebPanel extends JPanel
implements HyperlinkListener {
private JEditorPane htmlEditorPane;
private JScrollPane htmlEditorScrollPane;
/** Constructor */
public BSWebPanel(URL url) {
super(new BorderLayout());
htmlEditorPane = new JEditorPane();
htmlEditorPane.addHyperlinkListener(this);
htmlEditorPane.setEditable(false);
//URL url;
try {
htmlEditorPane.setPage(url);
} catch (IOException e) {
System.out.println("Couldn't load the url");
} catch (NullPointerException e2) {
System.out.println("Couldn't load the url");
}
htmlEditorScrollPane = new JScrollPane(htmlEditorPane);
add(htmlEditorScrollPane, BorderLayout.CENTER);
}
/** Goes to given URL - works only under Windows - opens external web browser. */
public void goToURL(String url) {
/*try {
htmlEditorPane.setPage(url);
} catch (IOException e) {
//System.out.println("Couldn't load the url");
JOptionPane.showMessageDialog(this,
"Cannot open url " + url,
"Web browser error",
JOptionPane.ERROR_MESSAGE);
}*/
try {
if (OSVersion.isWindowsNTPlatform()) {
String command = new String("cmd.exe /c start \"BuddySpace - browsing link\" \"" + url + "\"");
System.out.println(command);
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
}
else if (OSVersion.isWindows9xPlatform()) {
String command = new String("command.com /c start \"" + url + "\"");
System.out.println(command);
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
}
else
System.out.println("Sorry, no web browsing support for nonWin yet");
//htmlEditorPane.setPage(url);
} catch (Exception e) {
//System.out.println("Couldn't load the url: " + e.getMessage());
JOptionPane.showMessageDialog(this,
"Cannot open url " + url,
"Web browser error",
JOptionPane.ERROR_MESSAGE);
}
}
/** Called when link action performed - calls open link in external browser */
public void hyperlinkUpdate(HyperlinkEvent evt) {
if (HyperlinkEvent.EventType.ACTIVATED == evt.getEventType()) {
URL url = evt.getURL();
goToURL(url.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -