001: /*
002: JSmooth: a VM wrapper toolkit for Windows
003: Copyright (C) 2003 Rodrigo Reyes <reyes@charabia.net>
004:
005: This program is free software; you can redistribute it and/or modify
006: it under the terms of the GNU General Public License as published by
007: the Free Software Foundation; either version 2 of the License, or
008: (at your option) any later version.
009:
010: This program is distributed in the hope that it will be useful,
011: but WITHOUT ANY WARRANTY; without even the implied warranty of
012: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: GNU General Public License for more details.
014:
015: You should have received a copy of the GNU General Public License
016: along with this program; if not, write to the Free Software
017: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
018:
019: */
020:
021: package net.charabia.jsmoothgen.application.gui.util;
022:
023: import net.charabia.jsmoothgen.application.*;
024: import java.util.*;
025:
026: /**
027: *
028: * @author Rodrigo
029: */
030: public class CompilationDialog extends javax.swing.JDialog implements
031: ExeCompiler.StepListener {
032: private ExeCompiler m_compiler;
033: private boolean m_result = false;
034: private boolean m_canceled = false;
035:
036: /** Creates new form CompilationDialog */
037: public CompilationDialog(java.awt.Frame parent, boolean modal) {
038: super (parent, modal);
039: initComponents();
040: }
041:
042: /** This method is called from within the constructor to
043: * initialize the form.
044: * WARNING: Do NOT modify this code. The content of this method is
045: * always regenerated by the Form Editor.
046: */
047: private void initComponents() {//GEN-BEGIN:initComponents
048: java.awt.GridBagConstraints gridBagConstraints;
049:
050: jLabel1 = new javax.swing.JLabel();
051: m_progress = new javax.swing.JProgressBar();
052: jScrollPane1 = new javax.swing.JScrollPane();
053: m_state = new javax.swing.JTextArea(10, 60);
054: m_state.setLineWrap(true);
055: m_cancelbutton = new javax.swing.JButton();
056:
057: getContentPane().setLayout(new java.awt.GridBagLayout());
058:
059: addWindowListener(new java.awt.event.WindowAdapter() {
060: public void windowClosing(java.awt.event.WindowEvent evt) {
061: closeDialog(evt);
062: }
063: });
064:
065: jLabel1
066: .setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
067: jLabel1.setText("Progress");
068: gridBagConstraints = new java.awt.GridBagConstraints();
069: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
070: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
071: gridBagConstraints.weightx = 1.0;
072: getContentPane().add(jLabel1, gridBagConstraints);
073:
074: gridBagConstraints = new java.awt.GridBagConstraints();
075: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
076: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
077: gridBagConstraints.insets = new java.awt.Insets(5, 20, 5, 20);
078: getContentPane().add(m_progress, gridBagConstraints);
079:
080: // jScrollPane1.setBorder(new javax.swing.border.TitledBorder("Compilation Information"));
081: // m_state.setBackground((java.awt.Color) javax.swing.UIManager.getDefaults().get("Button.background"));
082: // m_state.setBorder(null);
083: m_state.setEditable(false);
084: jScrollPane1.setViewportView(m_state);
085:
086: gridBagConstraints = new java.awt.GridBagConstraints();
087: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
088: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
089: gridBagConstraints.weightx = 1.0;
090: gridBagConstraints.weighty = 1.0;
091: gridBagConstraints.insets = new java.awt.Insets(5, 10, 5, 10);
092: getContentPane().add(jScrollPane1, gridBagConstraints);
093:
094: m_cancelbutton.setText("Cancel");
095: m_cancelbutton
096: .addActionListener(new java.awt.event.ActionListener() {
097: public void actionPerformed(
098: java.awt.event.ActionEvent evt) {
099: cancelbuttonActionPerformed(evt);
100: }
101: });
102:
103: gridBagConstraints = new java.awt.GridBagConstraints();
104: gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
105: gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
106: gridBagConstraints.weighty = 0.0001;
107: gridBagConstraints.fill = java.awt.GridBagConstraints.NONE;
108: getContentPane().add(m_cancelbutton, gridBagConstraints);
109:
110: java.awt.Dimension screenSize = java.awt.Toolkit
111: .getDefaultToolkit().getScreenSize();
112: setBounds((screenSize.width - 319) / 2,
113: (screenSize.height - 158) / 2, 319, 158);
114: }//GEN-END:initComponents
115:
116: private void cancelbuttonActionPerformed(
117: java.awt.event.ActionEvent evt)//GEN-FIRST:event_cancelbuttonActionPerformed
118: {//GEN-HEADEREND:event_cancelbuttonActionPerformed
119: // Add your handling code here:
120: m_result = false;
121: m_canceled = true;
122: dispose();
123: }//GEN-LAST:event_cancelbuttonActionPerformed
124:
125: /** Closes the dialog */
126: private void closeDialog(java.awt.event.WindowEvent evt)//GEN-FIRST:event_closeDialog
127: {
128: setVisible(false);
129: dispose();
130: }//GEN-LAST:event_closeDialog
131:
132: public void setCompiler(ExeCompiler comp) {
133: m_compiler = comp;
134: comp.addListener(this );
135: m_progress.setMaximum(100);
136: m_progress.setMinimum(0);
137: m_state.setText("");
138: }
139:
140: public void compile(Runnable r) {
141: Thread t = new Thread(r);
142: t.start();
143: setModal(true);
144: setVisible(true);
145: }
146:
147: /**
148: * @param args the command line arguments
149: */
150: public static void main(String args[]) {
151: new CompilationDialog(new javax.swing.JFrame(), true)
152: .setVisible(true);
153: }
154:
155: public void complete() {
156: if (!m_canceled) {
157: m_result = true;
158: setNewState(100, "Done");
159: m_cancelbutton.setText("Done");
160: m_cancelbutton.grabFocus();
161: }
162: }
163:
164: public void failed() {
165: if (!m_canceled) {
166: m_result = false;
167: StringBuffer buf = new StringBuffer();
168: buf.append("Compilation failed!\n");
169: Vector v = m_compiler.getErrors();
170: for (int i = 0; i < v.size(); i++) {
171: buf.append("\n- ");
172: buf.append(v.get(i).toString());
173: }
174: buf.append("\n");
175: setNewState(100, buf.toString());
176: }
177: }
178:
179: public void setNewState(int percentComplete, String state) {
180: m_progress.setValue(percentComplete);
181: m_state.append(state + "\n");
182: }
183:
184: public boolean getResult() {
185: return m_result;
186: }
187:
188: // Variables declaration - do not modify//GEN-BEGIN:variables
189: private javax.swing.JLabel jLabel1;
190: private javax.swing.JScrollPane jScrollPane1;
191: private javax.swing.JButton m_cancelbutton;
192: private javax.swing.JProgressBar m_progress;
193: private javax.swing.JTextArea m_state;
194: // End of variables declaration//GEN-END:variables
195:
196: }
|