📄 cplusmpi.java
字号:
/*
* CplusMpi.java
*
* Created on 2007年5月30日, 上午9:35
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package lxz;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.undo.*;
import javax.swing.text.*;
import java.io.*;
import java.util.Stack;
import java.awt.datatransfer.*;
public class CplusMpi extends CplusMpiUI{
private JFileChooser fileChooser;
public static void main(String args[]){
//设置界面为WindowsLookAndFeel
try {
UIManager.setLookAndFeel(
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch(Exception e){
}
CplusMpi frame = new CplusMpi();
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
}
private char[] DataCopy(char[] content){
int tok = 0,count = 0;
while(tok < content.length - count){
if(content[tok] == '\r'){
for(int j = 0;j < content.length - tok - 1; j ++)
content[tok + j] = content[tok + j + 1];
count ++;
}
tok ++;
}
char[] temp = new char[content.length - count];
for(tok = 0; tok < content.length - count;tok ++)
temp[tok] = content[tok];
return temp;
}
private void newFile(){
textPane.setText("");
statusLabel.setText(" 新建文件");
this.setTitle("新建 - 并行程序编辑器");
isNewFile = true;
undo.discardAllEdits();
editMenu_Undo.setEnabled(false);
popupMenu_Undo.setEnabled(false);
undoButton.setEnabled(false);
editMenu_Redo.setEnabled(false);
popupMenu_Redo.setEnabled(false);
redoButton.setEnabled(false);
oldValue = textPane.getText();
};
private void openFile(){
String str = null;
fileChooser = new JFileChooser();
MyFilter cplusfile = new MyFilter();
fileChooser.setFileFilter(cplusfile);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setApproveButtonText("确定");
fileChooser.setDialogTitle("打开文件");
int result = fileChooser.showOpenDialog(this);
if(result == JFileChooser.CANCEL_OPTION){
statusLabel.setText("您没有选择任何文件");
return;
}
File fileName = fileChooser.getSelectedFile();
if(fileName == null||fileName.getName().equals(""))
JOptionPane.showMessageDialog(this,"不合法的文件名",
"不合法的文件名",JOptionPane.ERROR_MESSAGE);
else{
try{
setTitle(fileChooser.getSelectedFile().toString());
FileReader fr = new FileReader(fileName);
BufferedReader bfr = new BufferedReader(fr);
textPane.setText("");
while((str = bfr.readLine()) != null){
insertDoc(styledDoc,str+"\n","normalAttr");
}
textPane.setCaretPosition(0);
highShowPerformed();
this.setTitle(fileName.getName()+" 并行程序编辑器");
statusLabel.setText(" 当前打开文件:"+fileName.getAbsoluteFile());
fr.close();
isNewFile = false;
currentFile = fileName;
oldValue = textPane.getText();
} catch(IOException ioException){
}
}
};
private void exit(){
textPane.requestFocus();
String currentValue = textPane.getText();
boolean isTextChange = (currentValue.equals(oldValue))?false:true;
if(isTextChange){
int saveChoose = JOptionPane.showConfirmDialog(this,
"您的文件尚未保存。是否保存?",
"提示",JOptionPane.YES_NO_CANCEL_OPTION);
if(saveChoose == JOptionPane.YES_OPTION){
saveFilePerformed();
System.exit(0);
}else if(saveChoose == JOptionPane.NO_OPTION){
System.exit(0);
}else{
return;
}
}else{
System.exit(0);
}
};
private void saveFileAs(){
String str = null;
fileChooser = new JFileChooser();
MyFilter cplusFile = new MyFilter();
fileChooser.setFileFilter(cplusFile);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setApproveButtonText("确定");
fileChooser.setDialogTitle("另存为");
int result = fileChooser.showSaveDialog(this);
if(result == JFileChooser.CANCEL_OPTION){
statusLabel.setText("您没有选择任何文件");
return;
}
//File saveFileName = new File(getTitle());
File saveFileName = fileChooser.getSelectedFile();
setTitle(saveFileName.toString());
if(saveFileName == null||saveFileName.getName().equals(""))
JOptionPane.showMessageDialog(this,"不合法的文件名",
"不合法的文件名",JOptionPane.ERROR_MESSAGE);
else {
try{
saveFileName.createNewFile();
FileWriter fw = new FileWriter(saveFileName);
BufferedWriter bfw = new BufferedWriter(fw);
str = textPane.getText();
str = str.copyValueOf(DataCopy(str.toCharArray())).toString();
bfw.write(str,0,str.length());
bfw.flush();
fw.close();
isNewFile = false;
currentFile = saveFileName;
oldValue = textPane.getText();
this.setTitle(saveFileName.getName()+" - 并行程序编辑器");
statusLabel.setText(" 当前打开文件:"+saveFileName.getAbsoluteFile());
} catch(IOException ioException){
}
}
};
private void cut(){
textPane.requestFocus();
String text = textPane.getSelectedText();
StringSelection selection = new StringSelection(text);
clipBoard.setContents(selection,null);
textPane.replaceSelection("");
highShowPerformed();
checkMenuItemEnabled();
};
private void copy(){
textPane.requestFocus();
String text = textPane.getSelectedText();
StringSelection selection = new StringSelection(text);
clipBoard.setContents(selection,null);
checkMenuItemEnabled();
};
private void paste(){
textPane.requestFocus();
Transferable contents = clipBoard.getContents(this);
if(contents == null) return;
String text;
text = "";
try{
text = (String)contents.getTransferData(DataFlavor.stringFlavor);
} catch(Exception exception){
}
textPane.replaceSelection(text);
highShowPerformed();
checkMenuItemEnabled();
};
private void delete(){
textPane.requestFocus();
textPane.replaceSelection("");
highShowPerformed();
checkMenuItemEnabled();
};
private void undo(){
textPane.requestFocus();
if(undo.canUndo()){
try {
undo.undo();
editMenu_Redo.setEnabled(true);
popupMenu_Redo.setEnabled(true);
redoButton.setEnabled(true);
} catch(CannotUndoException ex){
System.out.println("Unable to undo: " + ex);
ex.printStackTrace();
}
if(!undo.canUndo()){
editMenu_Undo.setEnabled(false);
popupMenu_Undo.setEnabled(false);
undoButton.setEnabled(false);
editMenu_Redo.setEnabled(true);
popupMenu_Redo.setEnabled(true);
redoButton.setEnabled(true);
}
}
};
private void redo(){
textPane.requestFocus();
if(undo.canRedo()){
try{
undo.redo();
editMenu_Undo.setEnabled(true);
popupMenu_Undo.setEnabled(true);
undoButton.setEnabled(true);
} catch(CannotRedoException ex){
System.out.println("Unable to redo: " + ex);
ex.printStackTrace();
}
if(!undo.canRedo()){
editMenu_Redo.setEnabled(false);
popupMenu_Redo.setEnabled(false);
redoButton.setEnabled(false);
editMenu_Undo.setEnabled(true);
popupMenu_Undo.setEnabled(true);
undoButton.setEnabled(true);
}
}
};
private void selectAll(){
textPane.selectAll();
checkMenuItemEnabled();
};
private void about(){
Icon logo=new ImageIcon(CplusMpi.class.getResource("Icons/logo.gif"));
JOptionPane.showMessageDialog(this,
" \n"+
"* * * * * * * * * * * * * * * * * * * * * * * * * * * \n"+
"* Parallel Program Editor For C/Cplus V 1.0 *\n"+
"* *\n"+
"* 软件作者:西安交通大学计算机系35班 刘兴卓 *\n"+
"* *\n"+
"* 毕设题目:基于JAVA的并行程序编辑器研究与设计 *\n"+
"* *\n"+
"* 邮箱地址:humorl@163.com Q Q号码: 280290575 *\n"+
"* *\n"+
"* Copyright (c) 镯子 All Rights Reserved *\n"+
"* * * * * * * * * * * * * * * * * * * * * * * * * * *\n"
,"关于并行程序编辑器",JOptionPane.INFORMATION_MESSAGE);
};
private void helpTopics(){
textPane.requestFocus();
String helpTopicsStr=new String("<center><br>更多关于java并行编辑器"+
"<br>欢迎访问镯子的个人博客<br>"+
"<a href = http://blog.sina.com.cn/liuxingzhuo target=_blank>"+
"http://blog.sina.com.cn/liuxingzhuo</a></center>");
JEditorPane pane=new JEditorPane("text/html",helpTopicsStr);
pane.setEditable(false);
pane.addHyperlinkListener(new HyperlinkListener(){
public void hyperlinkUpdate(HyperlinkEvent hle){
if (hle.getEventType()
==HyperlinkEvent.EventType.ACTIVATED) {
try {
Process process =
Runtime.getRuntime().exec
("cmd.exe /c start http://280290575.qzone.qq.com");
} catch(Exception e) {
e.printStackTrace();
}
}
}
});
JFrame helpTopicsFrame=new JFrame("帮助主题");
helpTopicsFrame.setContentPane(new JScrollPane(pane));
helpTopicsFrame.setSize(250,200);
helpTopicsFrame.setLocation(300,300);
helpTopicsFrame.setVisible(true);
};
private void search(){
textPane.requestFocus();
final JDialog findDialog = new JDialog(this,"查找",true);
Container con = findDialog.getContentPane();
con.setLayout(new FlowLayout(FlowLayout.LEFT));
JLabel searchContentLabel = new JLabel("查找内容(N):");
final JTextField findText = new JTextField(22);
final JCheckBox matchcase = new JCheckBox("区分大小写(C)");
JButton searchNext = new JButton("查找下一个(F)");
ButtonGroup bGroup = new ButtonGroup();
final JRadioButton up = new JRadioButton("向上(U)");
final JRadioButton down = new JRadioButton("向下(D)");
down.setSelected(true);
bGroup.add(up);
bGroup.add(down);
up.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
downSelect = false;
}
});
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -