KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SnowMailClient > Language > Editor > SourceSentencesParserEditor


1 package SnowMailClient.Language.Editor;
2
3 import SnowMailClient.Language.*;
4 import SnowMailClient.utils.storage.*;
5 import snow.utils.gui.*;
6 import java.awt.*;
7 import java.awt.event.*;
8 import javax.swing. *;
9 import javax.swing.event.*;
10 import javax.swing.table.*;
11 import java.util.*;
12 import java.io.*;
13 import java.net.*;
14
15 public final class SourceSentencesParserEditor extends JFrame
16 {
17   final JTextField sourcePathTF = new JTextField("c:/projects/mail/client", 28);
18   final JButton parseButton;
19
20   public SourceSentencesParserEditor()
21   {
22      super("Source Translation Parser 1.0");
23      getContentPane().setLayout(new BorderLayout());
24
25      JPanel inputPanel = new JPanel(new GridLayout(1,2));
26      getContentPane().add(inputPanel, BorderLayout.CENTER);
27      inputPanel.add(new JLabel("SnowMail source path: "));
28      inputPanel.add(sourcePathTF);
29
30      JPanel controlPanel = new JPanel(new FlowLayout());
31      getContentPane().add(controlPanel, BorderLayout.SOUTH);
32
33      JButton closeButton = new JButton("Close", Icons.CrossIcon.shared10);
34      closeButton.setBackground(Color.orange);
35      controlPanel.add(closeButton);
36      closeButton.addActionListener(new ActionListener()
37      {
38        public void actionPerformed(ActionEvent e)
39        {
40           terminateFrame();
41        }
42      });
43
44      parseButton = new JButton("Parse");
45      parseButton.setBackground(Color.orange);
46      controlPanel.add(parseButton);
47      parseButton.addActionListener(new ActionListener()
48      {
49        public void actionPerformed(ActionEvent e)
50        {
51          Thread JavaDoc t = new Thread JavaDoc()
52          {
53            public void run()
54            {
55              parseSource();
56            }
57          };
58          t.setPriority(Thread.MIN_PRIORITY);
59          t.start();
60        }
61      });
62
63      this.addWindowListener( new WindowAdapter()
64       {
65         @Override JavaDoc public void windowClosing(WindowEvent e)
66         {
67             terminateFrame();
68         }
69         @Override JavaDoc public void windowClosed(WindowEvent e)
70         {
71             terminateFrame();
72         }
73       }
74      );
75
76      pack();
77      this.setLocationRelativeTo(null);
78      setVisible(true);
79   } // Constructor
80

81   private void parseSource()
82   {
83     parseButton.setEnabled(false);
84     ProgressModalDialog pw = new ProgressModalDialog(this, "Parsing source", false, false);
85     pw.setLocationRelativeTo( this );
86     pw.start();
87
88     try
89     {
90       String JavaDoc sourcePath = sourcePathTF.getText();
91
92       File sourceBase = new File(sourcePath);
93       if(!sourceBase.exists()) throw new Exception JavaDoc("Source path "+sourceBase.getAbsolutePath()+" don't exist.");
94       StringBuffer JavaDoc warningBuffer = new StringBuffer JavaDoc();
95       String JavaDoc terminationMessage = SourceSentencesParser.parseWholeSourceAndSaveInFile(sourceBase, warningBuffer);
96       // terminated...
97
pw.setVisible(false);
98
99       if(warningBuffer.length()>0)
100       {
101          System.out.println("WARNING:"+warningBuffer.toString());
102          JTextArea ta = new JTextArea(warningBuffer.toString().substring(1));
103          JOptionPane.showMessageDialog(this, new JScrollPane(ta), "Warning", JOptionPane.WARNING_MESSAGE);
104       }
105
106       JOptionPane.showMessageDialog(this, terminationMessage, "Parse completed", JOptionPane.INFORMATION_MESSAGE);
107       terminateFrame();
108     }
109     catch(Exception JavaDoc e)
110     {
111       //e.printStackTrace();
112
JOptionPane.showMessageDialog(this, e.getMessage(), "Error occured while parsing", JOptionPane.ERROR_MESSAGE);
113     }
114     finally
115     {
116       parseButton.setEnabled(true);
117       pw.closeDialog();
118     }
119   }
120
121
122   private boolean standalone = false;
123   private void terminateFrame()
124   {
125     if(standalone) System.exit(0);
126   }
127
128
129   public static void main(String JavaDoc[] a)
130   {
131      SourceSentencesParserEditor te = new SourceSentencesParserEditor();
132      te.standalone = true; // => exit with system.exit
133
}
134
135
136 } // SourceSentencesParserFrame
Popular Tags