gvsig-scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.impl / src / main / java / org / gvsig / scripting / impl / DefaultScriptingDialog.java @ 139
History | View | Annotate | Download (2.82 KB)
1 |
package org.gvsig.scripting.impl; |
---|---|
2 |
|
3 |
import java.awt.event.ActionEvent; |
4 |
import java.awt.event.ActionListener; |
5 |
import java.io.File; |
6 |
|
7 |
import org.gvsig.scripting.ScriptingDialog; |
8 |
import org.gvsig.scripting.ScriptingLocator; |
9 |
import org.gvsig.scripting.ScriptingManager; |
10 |
import org.gvsig.scripting.ScriptingUIManager; |
11 |
import org.gvsig.scripting.swing.JThinlet; |
12 |
import org.ini4j.Ini; |
13 |
|
14 |
public class DefaultScriptingDialog extends DefaultScriptingScript implements ScriptingDialog, ActionListener{ |
15 |
|
16 |
private int showMode; |
17 |
|
18 |
public DefaultScriptingDialog(ScriptingManager manager) {
|
19 |
super(manager);
|
20 |
this.showMode=MODE_DIALOG;
|
21 |
} |
22 |
|
23 |
|
24 |
public void run(Object args[]) { |
25 |
ScriptingUIManager uimanager = ScriptingLocator.getUIManager(); |
26 |
|
27 |
JThinlet thinlet = uimanager.createJThinlet(); |
28 |
thinlet.addActionListener(this);
|
29 |
thinlet.load(this.getFileResource(".dlg")); |
30 |
|
31 |
//this.model = this.invokeFunction("dlgname", new Object[] { thinlet.getThinlet() });
|
32 |
|
33 |
this.manager.put("form", thinlet.getThinlet()); |
34 |
switch(this.getShowMode()){ |
35 |
case MODE_WINDOW:
|
36 |
uimanager.showWindow(thinlet, this.getName());
|
37 |
break;
|
38 |
case MODE_TOOL:
|
39 |
uimanager.showTool(thinlet, this.getName());
|
40 |
break;
|
41 |
default:
|
42 |
uimanager.showDialog(thinlet, this.getName());
|
43 |
break;
|
44 |
} |
45 |
uimanager.showDialog(thinlet, this.getName());
|
46 |
} |
47 |
|
48 |
protected void loadInf(Ini prefs){ |
49 |
super.loadInf(prefs);
|
50 |
this.showMode=Integer.parseInt(getInfValue(prefs,"Dialog","showMode",new Integer(MODE_DIALOG)).toString()); |
51 |
} |
52 |
|
53 |
protected void save(Ini prefs){ |
54 |
super.save(prefs);
|
55 |
prefs.put("Dialog","showMode", new Integer(this.showMode)); |
56 |
} |
57 |
|
58 |
public String[] getIconNames() { |
59 |
return new String[]{"scripting_dialog", null}; |
60 |
} |
61 |
|
62 |
|
63 |
public void actionPerformed(ActionEvent arg0) { |
64 |
try {
|
65 |
this.invokeFunction(arg0.getActionCommand(),null); |
66 |
} catch (NoSuchMethodException e) { |
67 |
throw new RuntimeException(e); |
68 |
} |
69 |
} |
70 |
|
71 |
public File getDialogFile(){ |
72 |
return this.getFileResource(".dlg"); |
73 |
} |
74 |
|
75 |
// public void save(){
|
76 |
// File f = getFileResource(".inf");
|
77 |
// if(!f.isFile()){
|
78 |
// try {
|
79 |
// f.createNewFile();
|
80 |
// } catch (IOException e) {
|
81 |
// e.printStackTrace();
|
82 |
// }
|
83 |
// }
|
84 |
//
|
85 |
// Ini prefs = null;
|
86 |
//
|
87 |
// try {
|
88 |
// prefs = new Ini(f);
|
89 |
// } catch (InvalidFileFormatException e) {
|
90 |
// e.printStackTrace();
|
91 |
// } catch (IOException e) {
|
92 |
// e.printStackTrace();
|
93 |
// }
|
94 |
//
|
95 |
// save(prefs);
|
96 |
//
|
97 |
// // Guardo el código en el fichero
|
98 |
// try{
|
99 |
// FileWriter fstream = new FileWriter(((DefaultScriptingFolder)this.getParent()).getPath()+File.separator+this.getId()+this.getExtension());
|
100 |
// BufferedWriter out = new BufferedWriter(fstream);
|
101 |
// out.write(this.getCode());
|
102 |
// out.close();
|
103 |
// }catch (Exception e){
|
104 |
// System.err.println("Error: " + e.getMessage());
|
105 |
// }
|
106 |
// }
|
107 |
|
108 |
|
109 |
public int getShowMode() { |
110 |
return this.showMode; |
111 |
} |
112 |
|
113 |
|
114 |
public void setShowMode(int mode) { |
115 |
this.showMode=mode;
|
116 |
} |
117 |
|
118 |
} |