001: /*
002: * RadioButtonListener.java Copyright (c) 2006,07 Swaroop Belur
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008:
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013:
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
017: *
018: */
019:
020: package net.sf.jdec.ui.event;
021:
022: import java.awt.Component;
023: import java.awt.event.ActionEvent;
024: import java.awt.event.ActionListener;
025: import java.io.File;
026: import java.util.ArrayList;
027:
028: import javax.swing.JDialog;
029: import javax.swing.JEditorPane;
030: import javax.swing.JFrame;
031: import javax.swing.JOptionPane;
032: import javax.swing.JTabbedPane;
033:
034: import net.sf.jdec.main.ConsoleLauncher;
035: import net.sf.jdec.ui.adapter.DecompilerBridge;
036: import net.sf.jdec.ui.core.Console;
037: import net.sf.jdec.ui.core.JdecTree;
038: import net.sf.jdec.ui.core.Manager;
039: import net.sf.jdec.ui.main.UILauncher;
040: import net.sf.jdec.ui.util.ClassFileFilter;
041: import net.sf.jdec.ui.util.FileOpener;
042: import net.sf.jdec.ui.util.UIConstants;
043: import net.sf.jdec.ui.util.UIUtil;
044: import net.sf.jdec.config.Configuration;
045:
046: public class RadioButtonListener implements ActionListener {
047:
048: private void gotoSleep() {
049: try {
050: Thread.sleep(1000);
051: // i++;
052: } catch (InterruptedException e) {
053:
054: }
055: // System.out.println(i);
056:
057: }
058:
059: public void actionPerformed(ActionEvent event) {
060:
061: if (event.getActionCommand().equals("Decompile Class File")) {
062:
063: FileOpener chooser = new FileOpener(new ClassFileFilter());
064: Manager.getManager().setShowProgressBar(true);
065: //Thread main=Thread.currentThread();
066: JFrame tempframes[] = UILauncher.getTempFrames();
067: for (int i = 0; i < tempframes.length; i++) {
068: JFrame tempframe = tempframes[i];
069: if (tempframe != null) {
070: tempframe.setVisible(false);
071: tempframe.dispose();
072: }
073: }
074: final File chosenFile = chooser.getSelectedFile();
075: //System.out.println("XXX"+chosenFile.getAbsolutePath());
076:
077: Thread t1 = new Thread() {
078:
079: public void run() {
080:
081: decompileClass(chosenFile);
082: ConsoleLauncher.setFileDecompiled(true);
083: ConsoleLauncher.setCurrentSourceFile(chosenFile); // Why is this being set after call ? Add note
084:
085: }
086:
087: };
088:
089: Thread t2 = new Thread() {
090:
091: public void run() {
092:
093: JDialog proframe = UIUtil.launchProgressBarFrame();
094: if (proframe != null) {
095: proframe.setVisible(true);
096: }
097: //proframe.requestFocusInWindow();
098:
099: while (Manager.getManager().isShowProgressBar() == true) {
100:
101: gotoSleep();
102: }
103:
104: if (!Manager.getManager().isShowProgressBar()) {
105: if (proframe != null) {
106: proframe.setVisible(false);
107: proframe.dispose();
108: }
109: proframe = null;
110: if (ConsoleLauncher.fatalErrorOccured)
111: JOptionPane.showMessageDialog(UILauncher
112: .getMainFrame(),
113: UIConstants.jdecTaskError,
114: "Jdec Status",
115: JOptionPane.INFORMATION_MESSAGE);
116: }
117:
118: }
119:
120: };
121: t1.start();
122: t2.start();
123:
124: }
125: if (event.getActionCommand().equals("Decompile Jar File")) {
126: try {
127:
128: final FileOpener chooser = new FileOpener(null);
129: JFrame tempframes[] = UILauncher.getTempFrames();
130: for (int i = 0; i < tempframes.length; i++) {
131: JFrame tempframe = tempframes[i];
132: if (tempframe != null) {
133: tempframe.setVisible(false);
134: tempframe.dispose();
135: }
136: }
137: String message = "Jar Tab Has been Updated...\n";
138: message += "Would You like Jdec to Decompile Entire Jar ...\n\n";
139: message += "[Warning:] This May take some time depending on size of Jar ...\n";
140: message += "Would You Like to Proceed...?\n";
141:
142: JOptionPane option = new JOptionPane();//message,JOptionPane.QUESTION_MESSAGE,JOptionPane.YES_NO_CANCEL_OPTION);
143: Object[] options = { "OK", "CANCEL" };
144: int opt = option.showOptionDialog(UILauncher
145: .getMainFrame(), message,
146: "Jar Decompile Option",
147: JOptionPane.DEFAULT_OPTION,
148: JOptionPane.QUESTION_MESSAGE, null, options,
149: options[0]);
150: option.setVisible(true);
151: if (opt == JOptionPane.OK_OPTION) {
152: JTabbedPane tab = getLeftTabbedPane();
153: tab.setSelectedIndex(1);
154: //Writer outputwriter=Writer.getWriter("output");
155: //outputwriter.close("output");
156: ///
157: Thread t1 = new Thread() {
158:
159: public void run() {
160: Console c = UILauncher.getUIutil()
161: .getConsoleFrame();
162: if (c != null) {
163: JEditorPane rdwr = c.getComponent();
164: rdwr.setText("");
165: String s = "Jdec Started..\n";
166: s = rdwr.getText() + "\n\n" + s;
167: rdwr.setText(s);
168: }
169: Manager.getManager().setShowProgressBar(
170: true);
171: DecompilerBridge bridge = DecompilerBridge
172: .getInstance(UIUtil.getUIUtil());
173: //bridge.setClassFile(chooser.getSelectedFile().getAbsolutePath());
174: if (c != null) {
175: JEditorPane rdwr = c.getComponent();
176:
177: String s = "Current Task :Decompile Jar\n";
178: s = rdwr.getText() + "\n\n" + s;
179: rdwr.setText(s);
180: }
181: bridge.execute("decompileJar", "", false,
182: "null");
183: if (c != null) {
184: JEditorPane rdwr = c.getComponent();
185:
186: String s = "Current File :"
187: + Configuration.getJarPath()
188: + "\n";
189: // Reinitialize current executed files....
190: ConsoleLauncher
191: .setCurrentJarSourceFile(null);
192: Configuration.setJarPath(null);
193:
194: s = rdwr.getText() + "\n\n" + s;
195: rdwr.setText(s);
196: }
197: bridge.showResult(getRightTabbedPane());
198: if (c != null) {
199: JEditorPane rdwr = c.getComponent();
200:
201: String s = "Done...Please Wait for UI to render the output....\nPlease Check up the log files for any error(s)";
202: s = rdwr.getText() + "\n\n" + s;
203: rdwr.setText(s);
204: }
205:
206: }
207: };
208:
209: Thread t2 = new Thread() {
210:
211: public void run() {
212:
213: JDialog proframe = UIUtil
214: .launchProgressBarFrame();
215: if (proframe != null) {
216: proframe.setVisible(true);
217: }
218: //proframe.requestFocusInWindow();
219:
220: while (Manager.getManager()
221: .isShowProgressBar() == true) {
222:
223: gotoSleep();
224: }
225:
226: if (!Manager.getManager()
227: .isShowProgressBar()) {
228: if (proframe != null) {
229: proframe.setVisible(false);
230: proframe.dispose();
231: }
232: proframe = null;
233: if (ConsoleLauncher.fatalErrorOccured)
234: JOptionPane
235: .showMessageDialog(
236: UILauncher
237: .getMainFrame(),
238: UIConstants.jdecTaskError,
239: "Jdec Status",
240: JOptionPane.INFORMATION_MESSAGE);
241: }
242:
243: }
244:
245: };
246:
247: ///
248: if (chooser.getSelectedFile().getAbsolutePath()
249: .endsWith(".jar")) {
250: ConsoleLauncher.setCurrentJarSourceFile(chooser
251: .getSelectedFile());
252: UILauncher.getUIutil().setJarOption(true);
253: t1.start();
254: t2.start();
255: } else {
256: JOptionPane.showMessageDialog(UILauncher
257: .getMainFrame(),
258: "Chosen File is not a jar file",
259: "Jar Option",
260: JOptionPane.INFORMATION_MESSAGE);
261:
262: }
263:
264: }
265:
266: JOptionPane
267: .showMessageDialog(
268: UILauncher.getMainFrame(),
269: "Jar Tab has been updated with directory containing Decompiled Files..\nPlease Click on any File to see the output...",
270: "User Info...",
271: JOptionPane.INFORMATION_MESSAGE);
272: } catch (Exception jarexcep) {
273: // Handle todo
274: }
275:
276: }
277:
278: else {
279: JTabbedPane tab = getLeftTabbedPane();
280: tab.setSelectedIndex(tab.indexOfTab("Jar"));
281: }
282:
283: }
284:
285: int m_counter;
286:
287: private void decompileClass(File f) {
288:
289: DecompilerBridge bridge = DecompilerBridge.getInstance(UIUtil
290: .getUIUtil());
291: bridge.setClassFile(f.getAbsolutePath());
292: bridge.execute("decompileClass", "", false, "null");
293: JTabbedPane rightTab = getRightTabbedPane();
294: bridge.showResult(rightTab);
295: ConsoleLauncher.setCurrentDecompiledFile(Configuration
296: .getJavaClassFile());
297: //Configuration.setJavaClassFile(null);
298: //Configuration.setClassFilePath(null);
299: }
300:
301: private JTabbedPane getRightTabbedPane() {
302: Manager manager = Manager.getManager();
303: ArrayList paneList = manager.getCurrentSplitPaneComponents();
304: JTabbedPane tabs = null;
305: for (int s = 0; s < paneList.size(); s++) {
306: Object current = paneList.get(s);
307: if (current instanceof JTabbedPane) {
308: tabs = (JTabbedPane) current;
309: if (tabs.getTabCount() > 2) {
310: break;
311: }
312:
313: }
314: }
315:
316: return tabs;
317: }
318:
319: public JTabbedPane getLeftTabbedPane() {
320: Manager manager = Manager.getManager();
321: ArrayList paneList = manager.getCurrentSplitPaneComponents();
322: JTabbedPane tabs = null;
323: for (int s = 0; s < paneList.size(); s++) {
324: Object current = paneList.get(s);
325: if (current instanceof JTabbedPane) {
326: tabs = (JTabbedPane) current;
327: Component c = tabs.getComponent(0);
328: if (c instanceof JdecTree) {
329:
330: tabs = (JTabbedPane) current;
331: break;
332: }
333:
334: }
335: }
336:
337: return tabs;
338: }
339:
340: }
|