001: package Language.Editor;
002:
003: import Schmortopf.Utility.IniFile.*;
004: import Schmortopf.Utility.gui.*;
005: import Schmortopf.Utility.gui.dialogs.ProgressWindow;
006:
007: import Language.*;
008:
009: import java.awt.*;
010: import java.awt.event.*;
011: import javax.swing.*;
012: import javax.swing.event.*;
013: import javax.swing.table.*;
014: import java.util.*;
015: import java.io.*;
016: import java.net.*;
017:
018: public class SourceSentencesParserEditor extends JFrame {
019: IniFile iniFile;
020: JTextField sourcePathTF = new JTextField(
021: "c:/sources/schmortopf_ide", 28);
022: JButton parseButton;
023:
024: public SourceSentencesParserEditor() {
025: super ("Source Translation Parser 1.0");
026: getContentPane().setLayout(new BorderLayout());
027:
028: JPanel inputPanel = new JPanel(new GridLayout2(1, 2));
029: getContentPane().add(inputPanel, BorderLayout.CENTER);
030: inputPanel.add(new JLabel("Schmortopf IDE source path: "));
031: inputPanel.add(sourcePathTF);
032:
033: JPanel controlPanel = new JPanel(new FlowLayout());
034: getContentPane().add(controlPanel, BorderLayout.SOUTH);
035:
036: JButton closeButton = new JButton("Close");
037: closeButton.setBackground(Color.orange);
038: controlPanel.add(closeButton);
039: closeButton.addActionListener(new ActionListener() {
040: public void actionPerformed(ActionEvent e) {
041: terminateFrame();
042: }
043: });
044:
045: parseButton = new JButton("Parse");
046: parseButton.setBackground(Color.orange);
047: controlPanel.add(parseButton);
048: parseButton.addActionListener(new ActionListener() {
049: public void actionPerformed(ActionEvent e) {
050: Thread t = new Thread() {
051: public void run() {
052: parseSource();
053: }
054: };
055: t.setPriority(Thread.MIN_PRIORITY);
056: t.start();
057: }
058: });
059:
060: this .addWindowListener(new WindowAdapter() {
061: public void windowClosing(WindowEvent e) {
062: terminateFrame();
063: }
064:
065: public void windowClosed(WindowEvent e) {
066: terminateFrame();
067: }
068: });
069:
070: pack();
071: final Dimension screen = Toolkit.getDefaultToolkit()
072: .getScreenSize();
073: setLocation((int) (screen.getWidth() - getWidth()) / 2,
074: (int) (screen.getHeight() - getHeight()) / 2);
075: setVisible(true);
076:
077: } // Constructor
078:
079: private void parseSource() {
080: parseButton.setEnabled(false);
081: ProgressWindow pw = new ProgressWindow("Parsing source", null,
082: this , null, false);
083: pw.setLocation((int) getLocation().getX() + 100,
084: (int) getLocation().getY() - 10);
085: pw.setVisible(true);
086:
087: try {
088: String sourcePath = sourcePathTF.getText();
089:
090: File sourceBase = new File(sourcePath);
091: if (!sourceBase.exists())
092: throw new Exception("Source path "
093: + sourceBase.getAbsolutePath()
094: + " don't exist.");
095: StringBuffer warningBuffer = new StringBuffer();
096: String terminationMessage = SourceSentencesParser
097: .ParseWholeSourceAndSaveInFile(sourceBase,
098: warningBuffer);
099: // terminated...
100: pw.setVisible(false);
101:
102: if (warningBuffer.length() > 0) {
103: System.out.println("WARNING:"
104: + warningBuffer.toString());
105: JTextArea ta = new JTextArea(warningBuffer.toString()
106: .substring(1));
107: JOptionPane.showMessageDialog(this ,
108: new JScrollPane(ta), "Warning",
109: JOptionPane.WARNING_MESSAGE);
110: }
111:
112: JOptionPane.showMessageDialog(this , terminationMessage,
113: "Parse completed", JOptionPane.INFORMATION_MESSAGE);
114: terminateFrame();
115: } catch (Exception e) {
116: //e.printStackTrace();
117: JOptionPane.showMessageDialog(this , e.getMessage(),
118: "Error occured while parsing",
119: JOptionPane.ERROR_MESSAGE);
120: } finally {
121: parseButton.setEnabled(true);
122: pw.setVisible(false);
123: }
124: }
125:
126: private boolean standalone = false;
127:
128: private void terminateFrame() {
129: if (standalone)
130: System.exit(0);
131: }
132:
133: /*
134: public static void main(String[] a)
135: {
136: SourceSentencesParserEditor te = new SourceSentencesParserEditor();
137: te.standalone = true; // => exit with system.exit
138: }
139: */
140:
141: } // SourceSentencesParserFrame
|