Skip to content

Commit e125879

Browse files
author
zhourenjian
committed
1. Add ALAA options
2. Fixed bug that SWT_LIBRARY is not widely supported except VE is installed. 3. Fixed bug that exporting Java2Script projects from update manager installed Java2Script environment may result in errors 4. Add "Powered by Java2Script" in generated page
1 parent 10e9965 commit e125879

10 files changed

+561
-59
lines changed

sources/net.sf.j2s.ui/plugin.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
<plugin>
44
<extension-point id="externalResourceProvider" name="External Resource Provider" schema="schema/externalResourceProvider.exsd"/>
55

6+
<extension
7+
point="org.eclipse.jdt.core.classpathVariableInitializer">
8+
<classpathVariableInitializer
9+
class="net.sf.j2s.ui.variables.SWTVariableInitializer"
10+
variable="ECLIPSE_SWT"/>
11+
</extension>
12+
613
<extension
714
point="org.eclipse.ui.views">
815
<category

sources/net.sf.j2s.ui/src/net/sf/j2s/ui/launching/IJ2SLauchingConfiguration.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ public interface IJ2SLauchingConfiguration {
66
public static final String FAST_VIEW_J2S_CONSOLE = "fast.view.j2s.console";
77
public static final String MAXIMIZE_J2S_CONSOLE = "maximize.j2s.console";
88

9+
public static final String USE_GLOBAL_ALAA_URL = "use.global.alaa.url";
10+
public static final String GLOBAL_J2SLIB_URL = "global.j2slib.url";
11+
public static final String GLOBAL_BINARY_URL = "global.bin.url";
12+
913
public static final String USE_XHTML_HEADER = "use.xhtml.header";
1014
public static final String TAIL_BODY_HTML = "tail.body.html";
1115
public static final String HEAD_BODY_HTML = "head.body.html";

sources/net.sf.j2s.ui/src/net/sf/j2s/ui/launching/J2SConsoleOptionsTab.java

Lines changed: 205 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
package net.sf.j2s.ui.launching;
22

3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.FileNotFoundException;
6+
import java.io.IOException;
7+
import java.util.Properties;
38
import net.sf.j2s.ui.Java2ScriptUIPlugin;
49
import net.sf.j2s.ui.preferences.PreferenceConstants;
10+
import net.sf.j2s.ui.property.FileUtil;
11+
import net.sf.j2s.ui.resources.ExternalResources;
12+
import org.eclipse.core.resources.ResourcesPlugin;
513
import org.eclipse.core.runtime.CoreException;
614
import org.eclipse.debug.core.ILaunchConfiguration;
715
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
816
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
17+
import org.eclipse.jdt.core.IJavaModel;
18+
import org.eclipse.jdt.core.IJavaProject;
19+
import org.eclipse.jdt.core.JavaCore;
20+
import org.eclipse.jdt.core.JavaModelException;
921
import org.eclipse.jdt.internal.debug.ui.JavaDebugImages;
22+
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
1023
import org.eclipse.jface.preference.IPreferenceStore;
1124
import org.eclipse.swt.SWT;
25+
import org.eclipse.swt.events.FocusAdapter;
26+
import org.eclipse.swt.events.FocusEvent;
27+
import org.eclipse.swt.events.FocusListener;
28+
import org.eclipse.swt.events.ModifyEvent;
29+
import org.eclipse.swt.events.ModifyListener;
1230
import org.eclipse.swt.events.SelectionAdapter;
1331
import org.eclipse.swt.events.SelectionEvent;
1432
import org.eclipse.swt.graphics.Font;
@@ -18,18 +36,32 @@
1836
import org.eclipse.swt.widgets.Button;
1937
import org.eclipse.swt.widgets.Composite;
2038
import org.eclipse.swt.widgets.Group;
39+
import org.eclipse.swt.widgets.Label;
40+
import org.eclipse.swt.widgets.Text;
2141

2242
public class J2SConsoleOptionsTab extends AbstractLaunchConfigurationTab {
2343

24-
private Button btnInner;
44+
Button btnInner;
2545

26-
private Button btnCompatiable;
46+
Button btnCompatiable;
2747

28-
private Button btnCompatiableRawJS; // whether import or include mozilla.addon.js
48+
Button btnCompatiableRawJS; // whether import or include mozilla.addon.js
2949

30-
private Button btnFastView;
50+
Button btnFastView;
3151

32-
private Button btnMaximize;
52+
Button btnMaximize;
53+
54+
Button btnUseGlobalURL;
55+
56+
Button btnExternal;
57+
58+
Label lblJ2SLib;
59+
60+
Text txtJ2SLib;
61+
62+
Label lblBin;
63+
64+
Text txtBin;
3365

3466
public J2SConsoleOptionsTab() {
3567
super();
@@ -50,13 +82,13 @@ public void createControl(Composite parent) {
5082
group.setFont(font);
5183
layout = new GridLayout();
5284
group.setLayout(layout);
53-
group.setLayoutData(new GridData(GridData.FILL_BOTH));
85+
group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
5486

55-
String controlName = "Console Misc Options";
87+
String controlName = "Java2Script Console Misc Options";
5688
group.setText(controlName);
5789

58-
btnInner = new Button(group, SWT.CHECK);
59-
btnInner.setText("View Java2Script application in J2S console");
90+
btnInner = new Button(group, SWT.RADIO);
91+
btnInner.setText("Inner J2S Console");
6092
btnInner.addSelectionListener(new SelectionAdapter() {
6193
public void widgetSelected(SelectionEvent e) {
6294
updateLaunchConfigurationDialog();
@@ -87,16 +119,26 @@ public void widgetSelected(SelectionEvent e) {
87119
}
88120
});
89121

90-
btnCompatiable = new Button(group, SWT.CHECK);
91-
btnCompatiable.setText("Generate codes with Mozilla Addon compatiabilities");
122+
btnExternal = new Button(group, SWT.RADIO);
123+
btnExternal.setText("Registered external browsers, like Firefox, IE");
124+
btnExternal.addSelectionListener(new SelectionAdapter() {
125+
public void widgetSelected(SelectionEvent e) {
126+
updateLaunchConfigurationDialog();
127+
btnFastView.setEnabled(btnInner.getSelection());
128+
btnMaximize.setEnabled(btnInner.getSelection());
129+
}
130+
});
131+
132+
btnCompatiable = new Button(comp, SWT.CHECK);
133+
btnCompatiable.setText("Generate codes with Mozilla Add-on supports");
92134
btnCompatiable.addSelectionListener(new SelectionAdapter() {
93135
public void widgetSelected(SelectionEvent e) {
94136
updateLaunchConfigurationDialog();
95137
btnCompatiableRawJS.setEnabled(btnCompatiable.getSelection());
96138
}
97139
});
98140

99-
btnCompatiableRawJS = new Button(group, SWT.CHECK);
141+
btnCompatiableRawJS = new Button(comp, SWT.CHECK);
100142
GridData gdjs = new GridData();
101143
gdjs.horizontalIndent = 32;
102144
btnCompatiableRawJS.setLayoutData(gdjs);
@@ -106,6 +148,56 @@ public void widgetSelected(SelectionEvent e) {
106148
updateLaunchConfigurationDialog();
107149
}
108150
});
151+
152+
btnUseGlobalURL = new Button(comp, SWT.CHECK);
153+
btnUseGlobalURL.setText("Use global *.js URL");
154+
btnUseGlobalURL.addSelectionListener(new SelectionAdapter() {
155+
public void widgetSelected(SelectionEvent e) {
156+
updateLaunchConfigurationDialog();
157+
boolean selection = btnUseGlobalURL.getSelection();
158+
lblJ2SLib.setEnabled(selection);
159+
lblBin.setEnabled(selection);
160+
txtJ2SLib.setEnabled(selection);
161+
txtBin.setEnabled(selection);
162+
}
163+
});
164+
165+
Composite txtComp = new Composite(comp, SWT.NONE);
166+
GridData gdtxt = new GridData();
167+
gdtxt.horizontalIndent = 32;
168+
txtComp.setLayoutData(gdtxt);
169+
txtComp.setLayout(new GridLayout(2, false));
170+
171+
lblJ2SLib = new Label(txtComp, SWT.NONE);
172+
lblJ2SLib.setText("J2SLib base URL:");
173+
174+
txtJ2SLib = new Text(txtComp, SWT.BORDER);
175+
GridData gdtxt1 = new GridData();
176+
gdtxt1.widthHint = 240;
177+
txtJ2SLib.setLayoutData(gdtxt1);
178+
FocusListener focusListener = new FocusAdapter() {
179+
public void focusGained(FocusEvent e) {
180+
// select txt
181+
((Text) e.widget).selectAll();
182+
}
183+
};
184+
ModifyListener modifyListener = new ModifyListener() {
185+
public void modifyText(ModifyEvent e) {
186+
updateLaunchConfigurationDialog();
187+
}
188+
};
189+
txtJ2SLib.addFocusListener(focusListener);
190+
txtJ2SLib.addModifyListener(modifyListener);
191+
192+
lblBin = new Label(txtComp, SWT.NONE);
193+
lblBin.setText("Binary folder URL:");
194+
195+
txtBin = new Text(txtComp, SWT.BORDER);
196+
GridData gdtxt2 = new GridData();
197+
gdtxt2.widthHint = 240;
198+
txtBin.setLayoutData(gdtxt2);
199+
txtBin.addFocusListener(focusListener);
200+
txtBin.addModifyListener(modifyListener);
109201
}
110202

111203
public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
@@ -129,6 +221,16 @@ public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
129221

130222
configuration.setAttribute(
131223
IJ2SLauchingConfiguration.J2S_MOZILLA_ADDON_COMPATIABLE_RAW_JS, true);
224+
225+
configuration.setAttribute(
226+
IJ2SLauchingConfiguration.USE_GLOBAL_ALAA_URL, false);
227+
228+
configuration.setAttribute(
229+
IJ2SLauchingConfiguration.GLOBAL_J2SLIB_URL,
230+
"http://archive.java2script.org/" + getCurrentReleaseAlias(configuration) + "/");
231+
232+
configuration.setAttribute(
233+
IJ2SLauchingConfiguration.GLOBAL_BINARY_URL, getCurrentBinPath(configuration));
132234
}
133235

134236
public void initializeFrom(ILaunchConfiguration configuration) {
@@ -148,6 +250,7 @@ public void initializeFrom(ILaunchConfiguration configuration) {
148250
boolean external = configuration.getAttribute(
149251
IJ2SLauchingConfiguration.VIEW_IN_INNER_J2S_CONSOLE, preferred);
150252
btnInner.setSelection(external);
253+
btnExternal.setSelection(!external);
151254
btnFastView.setEnabled(external);
152255
btnMaximize.setEnabled(external);
153256

@@ -158,11 +261,95 @@ public void initializeFrom(ILaunchConfiguration configuration) {
158261
btnCompatiable.setSelection(compatiable);
159262
btnCompatiableRawJS.setEnabled(compatiable);
160263

264+
boolean useGlobal = configuration.getAttribute(
265+
IJ2SLauchingConfiguration.USE_GLOBAL_ALAA_URL, false);
266+
btnUseGlobalURL.setSelection(useGlobal);
267+
lblJ2SLib.setEnabled(useGlobal);
268+
lblBin.setEnabled(useGlobal);
269+
txtJ2SLib.setEnabled(useGlobal);
270+
txtBin.setEnabled(useGlobal);
271+
272+
txtJ2SLib.setText(configuration.getAttribute(
273+
IJ2SLauchingConfiguration.GLOBAL_J2SLIB_URL,
274+
"http://archive.java2script.org/" + getCurrentReleaseAlias(configuration) + "/"));
275+
276+
txtBin.setText(configuration.getAttribute(
277+
IJ2SLauchingConfiguration.GLOBAL_BINARY_URL, getCurrentBinPath(configuration)));
278+
161279
} catch (CoreException e) {
162280
e.printStackTrace();
163281
}
164282
}
165283

284+
private String getCurrentBinPath(ILaunchConfiguration configuration) {
285+
IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
286+
try {
287+
String projectName = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String)null);
288+
if ((projectName == null) || (projectName.trim().length() < 1)) {
289+
return null;
290+
}
291+
IJavaProject javaProject = javaModel.getJavaProject(projectName);
292+
if ((javaProject == null) || !javaProject.exists()) {
293+
return null;
294+
}
295+
String path = javaProject.getOutputLocation().toString();
296+
int idx = path.indexOf('/', 2);
297+
String relativePath = "";
298+
if (idx != -1) {
299+
relativePath = path.substring(idx + 1);
300+
}
301+
return relativePath;
302+
} catch (JavaModelException e) {
303+
e.printStackTrace();
304+
} catch (CoreException e) {
305+
e.printStackTrace();
306+
}
307+
return "bin/";
308+
}
309+
private String getCurrentJ2SLibPath(File workingDir) {
310+
String[][] allResources = ExternalResources.getAllResources();
311+
String j2sLibPath = null;
312+
if (allResources != null && allResources.length != 0 && allResources[0].length != 0) {
313+
if ((allResources[0][0]).startsWith("|")) {
314+
allResources[0][0] = FileUtil.toRelativePath(allResources[0][0].substring(1),
315+
workingDir.getAbsolutePath());;
316+
}
317+
j2sLibPath = allResources[0][0].substring(0, allResources[0][0].lastIndexOf("/") + 1);
318+
} else {
319+
j2sLibPath = "../net.sf.j2s.lib/j2slib/";
320+
}
321+
return j2sLibPath;
322+
}
323+
private String getCurrentReleaseAlias(ILaunchConfiguration configuration) {
324+
File workingDir = null;
325+
try {
326+
workingDir = J2SLaunchingUtil.getWorkingDirectory(configuration);
327+
String j2sLibPath = getCurrentJ2SLibPath(workingDir);
328+
329+
File j2slibFolder = new File(workingDir.getAbsolutePath(), j2sLibPath);
330+
File j2sRelease = new File(j2slibFolder, ".release");
331+
Properties release = new Properties();
332+
String alias = "1.0.0";
333+
String version = "20070304";
334+
release.put("alias", alias);
335+
release.put("version", version);
336+
if (j2sRelease.exists()) {
337+
try {
338+
release.load(new FileInputStream(j2sRelease));
339+
} catch (FileNotFoundException e) {
340+
e.printStackTrace();
341+
} catch (IOException e) {
342+
e.printStackTrace();
343+
}
344+
alias = release.getProperty("alias");
345+
version = release.getProperty("version");
346+
}
347+
return alias;
348+
} catch (CoreException e) {
349+
e.printStackTrace();
350+
return "1.0.0";
351+
}
352+
}
166353
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
167354
configuration.setAttribute(IJ2SLauchingConfiguration.FAST_VIEW_J2S_CONSOLE,
168355
btnFastView.getSelection());
@@ -174,6 +361,12 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
174361
IJ2SLauchingConfiguration.J2S_MOZILLA_ADDON_COMPATIABLE, btnCompatiable.getSelection());
175362
configuration.setAttribute(
176363
IJ2SLauchingConfiguration.J2S_MOZILLA_ADDON_COMPATIABLE_RAW_JS, btnCompatiableRawJS.getSelection());
364+
configuration.setAttribute(
365+
IJ2SLauchingConfiguration.USE_GLOBAL_ALAA_URL, btnUseGlobalURL.getSelection());
366+
configuration.setAttribute(
367+
IJ2SLauchingConfiguration.GLOBAL_J2SLIB_URL, txtJ2SLib.getText());
368+
configuration.setAttribute(
369+
IJ2SLauchingConfiguration.GLOBAL_BINARY_URL, txtBin.getText());
177370
}
178371

179372
public String getName() {

0 commit comments

Comments
 (0)