📄 editorframe.java
字号:
/*
* EditorFrame.java ver 0.1.2
*
* Created on 2006年11月30日, 下午12:27
*
* The editor for the project
*
*History : 2006年11月30日 ver 0.1.0 create the class
* 2006年12月1日 ver 0.1.1 first release.
* 2006年12月9日 ver 0.1.2 second release,fix a bug that cannot update the disk usage of the system
*/
package ossimulation;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.event.*;
import javax.swing.JOptionPane;
import java.util.*;
import javax.swing.*;
/**
*
* @author Administrator
*/
public class EditorFrame extends javax.swing.JFrame {
/** Creates new form EditorFrame */
public EditorFrame(MainFrame argFrame,INode argINode){
initComponents();
targetINode = argINode;
this.setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
// this.addWindowListener(new WindowAdapter(){
// public void windowClosing(WindowEvent evt){
// int answer = JOptionPane.showConfirmDialog(null,"Real Want To Exit?","Need Confirm",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
// if(answer == JOptionPane.YES_OPTION){
// }
// }
// });
outputArea.setEditable(false);
inputArea.setEditable(false);
//read the content that store in the file
Iterator fileDescriptor = targetINode.readContent().iterator();
for(;fileDescriptor.hasNext();){
outputArea.append((String)fileDescriptor.next() + ";\n");
}
parentFrame = argFrame;
newContent = new ArrayList();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
inputTextField = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
inputArea = new javax.swing.JTextArea();
jScrollPane2 = new javax.swing.JScrollPane();
outputArea = new javax.swing.JTextArea();
inputLabel = new javax.swing.JLabel();
resultLabel = new javax.swing.JLabel();
permotedLabel = new javax.swing.JLabel();
saveButton = new javax.swing.JButton();
saveLabel = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("File Editor");
inputTextField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
inputTextFieldActionPerformed(evt);
}
});
inputArea.setColumns(20);
inputArea.setRows(5);
jScrollPane1.setViewportView(inputArea);
outputArea.setColumns(20);
outputArea.setRows(5);
jScrollPane2.setViewportView(outputArea);
inputLabel.setText("Here gose the input:");
resultLabel.setText("Here gose the content of the file:");
permotedLabel.setText("Please Input:");
saveButton.setText("Save");
saveButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
saveButtonActionPerformed(evt);
}
});
saveLabel.setForeground(new java.awt.Color(255, 51, 51));
saveLabel.setText("Remember to save the file!");
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(org.jdesktop.layout.GroupLayout.LEADING, inputLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE))
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(9, 9, 9)
.add(resultLabel))
.add(layout.createSequentialGroup()
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE))))
.add(layout.createSequentialGroup()
.add(permotedLabel)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 13, Short.MAX_VALUE)
.add(inputTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 366, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(saveLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 171, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 31, Short.MAX_VALUE)
.add(saveButton)
.add(206, 206, 206))))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(permotedLabel)
.add(inputTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(inputLabel)
.add(resultLabel))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(jScrollPane2)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 14, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(saveButton)
.add(saveLabel))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
// TODO add your handling code here:
targetINode.addContent(newContent);
parentFrame.calculateDisk();
newContent.clear();//clear the content add by the pervious edit
saveLabel.setForeground(Color.GREEN);
saveLabel.setText("File has been save!");
}//GEN-LAST:event_saveButtonActionPerformed
private void inputTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inputTextFieldActionPerformed
// TODO add your handling code here:
String inputText;
// String outputText;
String resultText;
inputText = inputTextField.getText();
if(inputText.matches("[a-zA-Z]=[0-9]")){
resultText = "A" + inputText.charAt(0) + inputText.charAt(2);
newContent.add(resultText);
inputArea.append(inputText + ";\n");
outputArea.append(resultText + ";\n");
} else if(inputText.matches("[a-zA-Z]\\+\\+")){
resultText = "B" + inputText.charAt(0);
newContent.add(resultText);
inputArea.append(inputText + ";\n");
outputArea.append(resultText + ";\n");
} else if(inputText.matches("[a-zA-Z]\\-\\-")){
resultText = "C" + inputText.charAt(0);
newContent.add(resultText);
inputArea.append(inputText + ";\n");
outputArea.append(resultText + ";\n");
} else if(inputText.matches("![a-zA-Z][0-9]")){
resultText = "D" + inputText.charAt(1) + inputText.charAt(2);
newContent.add(resultText);
inputArea.append(inputText + ";\n");
outputArea.append(resultText + ";\n");
} else if(inputText.matches("end")){
resultText = "E";
newContent.add(resultText);
inputArea.append(inputText + ";\n");
outputArea.append(resultText + ";\n");
} else{
inputArea.append(inputText + ";\n");
resultText = "";
}
inputTextField.setText("");
saveLabel.setForeground(Color.RED);
saveLabel.setText("Remember to save the file!");
// targetINode.addContent(newContent);
// parentFrame.calculateDisk();
// //Here the code for class debuging. when debuging is over,it must be commented
// Iterator contentIterator = targetINode.readContent().iterator();
// for(;contentIterator.hasNext();){
// System.out.println((String)contentIterator.next());
// }
}//GEN-LAST:event_inputTextFieldActionPerformed
/**
* @param Only existed for class debuging
*/
public static void main(String args[]) {
// java.awt.EventQueue.invokeLater(new Runnable() {
// public void run() {
// Disk simDisk = new Disk();
// INode testINode = new INode("TestINode",simDisk);
// new EditorFrame(testINode).setVisible(true);
// }
// });
//test the constructor of the class
ArrayList oldContent = new ArrayList();
Disk simDisk = new Disk();
INode testINode = new INode("Test",simDisk);
oldContent.add("Ax3");
oldContent.add("By");
testINode.addContent(oldContent);
EditorFrame frame = new EditorFrame(null,testINode);
frame.setVisible(true);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextArea inputArea;
private javax.swing.JLabel inputLabel;
private javax.swing.JTextField inputTextField;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextArea outputArea;
private javax.swing.JLabel permotedLabel;
private javax.swing.JLabel resultLabel;
private javax.swing.JButton saveButton;
private javax.swing.JLabel saveLabel;
// End of variables declaration//GEN-END:variables
private INode targetINode;
private MainFrame parentFrame;
private ArrayList newContent;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -