001: package tide.project;
002:
003: import javax.swing.event.DocumentEvent;
004: import javax.swing.event.DocumentListener;
005: import java.awt.FlowLayout;
006: import java.awt.Component;
007: import java.awt.Insets;
008: import tide.editor.*;
009: import java.util.prefs.*;
010: import javax.swing.*;
011: import java.awt.BorderLayout;
012: import java.awt.event.*;
013: import javax.swing.border.*;
014: import java.util.*;
015: import java.io.*;
016: import snow.utils.*;
017: import snow.utils.storage.*;
018: import snow.utils.gui.*;
019: import tide.utils.FileUtilities;
020:
021: /** With clever global default discovering for projects !
022: * Warns if source not ending with src or source !
023: * Warns if no doc set, warns if not generating debug info for variable names.
024: */
025: public class ProjectSettingsEditorDialog extends JDialog {
026: private final JToggleButton advancedModeBT = new JToggleButton(
027: "Advanced mode >>");
028: private List<Component> advancedItems = new ArrayList<Component>();
029:
030: final private FileField javaHomeField;
031: final private FileField genClassesField;
032: private FileField customTideSettingsFolder = null; // may be null if not experimental mode
033:
034: final private JButton viewCompOpts = new JButton(" ? ");
035: final private JButton viewRuntimeOpts = new JButton(" ? ");
036: final private CloseControlPanel ccp;
037: final private FileListField extJavaDocs;
038: final private FileField jdkDocRoot;
039: final JToggleButton autoSetGenClass = new JToggleButton("Auto",
040: true);
041: final JCheckBox ramDiskModeCB = new JCheckBox(
042: "RAMDISK mode, move classes on startup and on end", true);
043:
044: // used to know if a reload is requested after this edit
045: private boolean reloadProjectMandatory = false;
046:
047: final ProjectSettings actualProject;
048:
049: /** Saves back if user changed something and accepted.
050: * MODAL dialog
051: *
052: * @param firstCall on first call, changing name will autocomplete the other path fields accordingly
053: * is true when creating a new project.
054: */
055: public ProjectSettingsEditorDialog(final MainEditorFrame parent,
056: final ProjectSettings projDef, final boolean firstCall,
057: final boolean exitIfCancelled) {
058: super (parent, (firstCall ? "New Project Definition"
059: : "Project settings edition"), true);
060:
061: actualProject = projDef;
062:
063: // a little help
064: if (firstCall) {
065: String name = ""
066: + JOptionPane
067: .showInputDialog(
068: MainEditorFrame.instance,
069: "Enter the new project name:"
070: + "\n(without special chars, because it will be used in filenames)\n\n",
071: "Creating a new Java project",
072: JOptionPane.OK_CANCEL_OPTION, null,
073: null, projDef.getProjectName());
074: if (name == null || name.trim().length() == 0) {
075: // abort
076: if (exitIfCancelled) {
077: System.exit(0);
078: }
079: //throw new RuntimeException("Cancelled");
080: }
081: actualProject.setProjectName(name.trim());
082:
083: // clever guess
084: if (actualProject.getSources_Home() == null) {
085: File projectsRoot = new File(Preferences.userRoot()
086: .get(
087: "tide_guessed_java_projects_home",
088: new File(System
089: .getProperty("user.home"),
090: "javaprojects/")
091: .getAbsolutePath()));
092:
093: File defHome = new File(projectsRoot, name + "/src");
094: actualProject.setSources_Home(defHome);
095:
096: File defClasses = new File(projectsRoot, name
097: + "/classes");
098: actualProject.setClasses_Home(defClasses);
099: }
100:
101: final SelectJDKDialog sjd = new SelectJDKDialog(
102: parent,
103: "Please select a Java Development Kit (JDK) to use:"
104: + "\n (It's time to ensure you've got the newest from java.sun.com)\n" // TODO: say apt-get for debian ubuntu
105: );
106:
107: final File jh = sjd.getSelectedJDKHomeOrNull();
108: if (jh != null) {
109: actualProject.setJava_Home(jh);
110: }
111: }
112:
113: ccp = new CloseControlPanel(this , true, true,
114: (firstCall ? "Save settings" : "Ok"));
115: add(ccp, BorderLayout.SOUTH);
116:
117: final JPanel controlPanelNorth = new JPanel(new FlowLayout(
118: FlowLayout.LEFT, 10, 5));
119: add(controlPanelNorth, BorderLayout.NORTH);
120: controlPanelNorth.add(advancedModeBT);
121: controlPanelNorth.add(new JLabel(
122: " Hint: right-click on fields!"));
123: advancedModeBT.setFocusPainted(false);
124: advancedModeBT.setMargin(new Insets(0, 1, 0, 1));
125: advancedModeBT.setSelected(actualProject.getBooleanProperty(
126: "Project_advancedModeBT", false));
127: advancedModeBT.addActionListener(new ActionListener() {
128: public void actionPerformed(ActionEvent ae) {
129: updateAdvancedOrSimpleMode();
130: }
131: });
132:
133: JPanel cpPanel = new JPanel();
134: add(cpPanel, BorderLayout.CENTER);
135: GridLayout3 gl3 = new GridLayout3(2, cpPanel);
136: cpPanel.setBorder(new EmptyBorder(5, 2, 2, 2));
137:
138: gl3.addTitleSeparator("Projects settings");
139: gl3.add("Project name");
140: final JTextField nameField = new JTextField(projDef
141: .getProjectName(), 20);
142: nameField.setMinimumSize(nameField.getPreferredSize()); // important ! allow nice resizes !!
143: gl3.add(nameField);
144:
145: String oldSourceLoc = (projDef.getSources_Home() != null ? projDef
146: .getSources_Home().getAbsolutePath()
147: : ""); // may be null !!
148: gl3.add("Sources home");
149: final FileField srcHomeField = new FileField(oldSourceLoc,
150: false, "Select the sources root directory",
151: JFileChooser.DIRECTORIES_ONLY);
152: srcHomeField.getTextField().setColumns(30);
153: gl3.add(srcHomeField);
154: srcHomeField.setAutoColorized();
155:
156: advancedItems.add(gl3.add("Main class source"));
157: File f = projDef.getMainSourceFile();
158: FileField mainClassField = new FileField((f != null ? f
159: .getAbsolutePath() : ""), false,
160: "Select the main class source file",
161: JFileChooser.FILES_ONLY);
162: advancedItems.add(gl3.add(mainClassField));
163: mainClassField.getTextField().setColumns(30);
164: mainClassField.setAutoColorized();
165: mainClassField.allowedExtensions.add("java");
166: mainClassField.fileTypeDescription = "Java Files";
167:
168: advancedItems.add(gl3.add("Application arguments "));
169: final JTextField progArgsField = new JTextField(projDef
170: .getAppArgs(), 28);
171: progArgsField.setMinimumSize(progArgsField.getPreferredSize());
172: JPanel appArgsPanel = new JPanel(new FlowLayout(
173: FlowLayout.LEFT, 0, 0));
174: advancedItems.add(gl3.add(appArgsPanel));
175: appArgsPanel.add(progArgsField);
176: // [May2007] offer completion:
177: GUIUtils.offerRightClickAddCompletion(progArgsField, projDef
178: .getProps().getArrayProperty(
179: "progArgsField_known_items_",
180: new String[] { "-debug" }));
181: JButton appOptsDialog = new JButton("+");
182: appOptsDialog.setFocusPainted(false);
183: appArgsPanel.add(appOptsDialog);
184: appOptsDialog.setMargin(new Insets(0, 1, 0, 1));
185: appOptsDialog.addActionListener(new ActionListener() {
186: public void actionPerformed(ActionEvent ae) {
187: String ret = viewArgumentsDialog(progArgsField
188: .getText(),
189: "Application arguments (one per line)");
190: if (ret != null) {
191: progArgsField.setText(ret);
192: }
193: }
194: });
195:
196: advancedItems.add(gl3.add("Class path (jars and dirs)"));
197: FileListField includeJars = new FileListField("Class path",
198: JFileChooser.FILES_AND_DIRECTORIES, null, this );
199: includeJars.setFiles(projDef.getClassPath(false, true)); // aux class path
200: includeJars.getTextField().setColumns(30);
201: String oldCP = includeJars.getTextField().getText();
202: advancedItems.add(gl3.add(includeJars));
203: includeJars.defaultFile = srcHomeField.getPath();
204: includeJars.offerRememberedPaths(
205: MainEditorFrame.instance.globalProperties,
206: "Global_extJars_hist");
207:
208: // clever global default !
209: gl3.add("Generated classes home");
210: genClassesField = new FileField(projDef.getClasses_Home(),
211: false,
212: "Select the directory to place the generated classes",
213: JFileChooser.DIRECTORIES_ONLY);
214: genClassesField.getTextField().setColumns(27);
215: JPanel clapan = new JPanel(
216: new FlowLayout(FlowLayout.LEFT, 0, 0));
217: gl3.add(clapan);
218:
219: boolean autoGenClassOn = true;
220: if (projDef.getClasses_Home().exists()
221: && projDef.getSources_Home().exists()) {
222: if (!projDef.getClasses_Home().getParentFile().equals(
223: projDef.getSources_Home().getParentFile())) {
224: autoGenClassOn = false;
225: }
226: }
227: autoSetGenClass.setSelected(autoGenClassOn); // no action.
228: autoSetGenClass
229: .setToolTipText("<html><body>Auto: use a sibling folder of the source folder named classes");
230: autoSetGenClass.setFont(UIManager
231: .getFont("CheckBoxMenuItem.acceleratorFont")); // small...
232: autoSetGenClass.setMargin(new Insets(0, 0, 0, 0));
233:
234: clapan.add(autoSetGenClass);
235: clapan.add(Box.createHorizontalStrut(4));
236: clapan.add(genClassesField);
237: clapan.setMinimumSize(clapan.getPreferredSize());
238: if (!firstCall) {
239: genClassesField.setAutoColorized();
240: }
241:
242: //no... genClassesField.setAutoColorized(); it is red if not existing but at creation it really doesn't exist !
243: ActionListener autoSetGenClassAction = new ActionListener() {
244: public void actionPerformed(ActionEvent ae) {
245: genClassesField.setEditable(!autoSetGenClass
246: .isSelected());
247: }
248: };
249: autoSetGenClass.addActionListener(autoSetGenClassAction);
250: autoSetGenClassAction.actionPerformed(null);
251:
252: srcHomeField.getTextField().getDocument().addDocumentListener(
253: new DocumentListener() {
254: public final void changedUpdate(
255: final DocumentEvent de) {
256: update();
257: }
258:
259: public final void insertUpdate(
260: final DocumentEvent de) {
261: update();
262: }
263:
264: public final void removeUpdate(
265: final DocumentEvent de) {
266: update();
267: }
268:
269: void update() {
270: if (autoSetGenClass.isSelected()) {
271: try {
272: File pp = srcHomeField.getPath();
273: if (pp != null)
274: genClassesField
275: .setPath(new File(pp
276: .getParentFile(),
277: "classes"));
278: } catch (Exception e) {
279: e.printStackTrace();
280: }
281: }
282: }
283:
284: });
285:
286: gl3.addTitleSeparator("Java JDK settings");
287: gl3.add("JDK home");
288: javaHomeField = new FileField(
289: projDef.getJava_Home().getAbsolutePath(),
290: false,
291: "Select the java development kit home directory (where /bin is)",
292: JFileChooser.DIRECTORIES_ONLY);
293:
294: // remember occurs in the setJavaHome method.
295: List<File> allKnownJDKPaths = FileUtils.getFilesFromList(
296: MainEditorFrame.instance.globalProperties.getProperty(
297: "JDK_paths", ""), true);
298: javaHomeField.setAlternatePaths(allKnownJDKPaths);
299:
300: javaHomeField.getTextField().setColumns(30);
301: javaHomeField.setMinimumSize(javaHomeField.getPreferredSize());
302: gl3.add(javaHomeField);
303: javaHomeField.setAutoColorized();
304: String oldJDKHome = javaHomeField.getPath().getAbsolutePath();
305:
306: advancedItems.add(gl3.add("Compiler arguments "));
307: JPanel compOptionsPanel = new JPanel(new FlowLayout(
308: FlowLayout.LEFT, 0, 0));
309: viewCompOpts.setMargin(new Insets(0, 2, 0, 2));
310: viewCompOpts.setFocusPainted(false);
311: final JTextField compilerArgsField = new JTextField(projDef
312: .getCompilerOptions(), 28);
313: compilerArgsField.setMinimumSize(compilerArgsField
314: .getPreferredSize());
315: advancedItems.add(gl3.add(compOptionsPanel));
316: compOptionsPanel.add(compilerArgsField);
317: GUIUtils.offerRightClickAddCompletion(compilerArgsField,
318: projDef.getProps().getArrayProperty(
319: "compilerArgsField_known_items_"));
320:
321: JButton viewCompOptsDialog = new JButton("+");
322: viewCompOptsDialog.setFocusPainted(false);
323: compOptionsPanel.add(viewCompOptsDialog);
324: viewCompOptsDialog.setMargin(new Insets(0, 1, 0, 1));
325:
326: compOptionsPanel.add(viewCompOpts);
327: compOptionsPanel.setMinimumSize(compOptionsPanel
328: .getPreferredSize());
329: viewCompOpts.addActionListener(new ActionListener() {
330: public void actionPerformed(ActionEvent ae) {
331: displayCompilerOptions();
332: }
333: });
334: viewCompOptsDialog.addActionListener(new ActionListener() {
335: public void actionPerformed(ActionEvent ae) {
336: String ret = viewArgumentsDialog(compilerArgsField
337: .getText(), "Compiler arguments (one per line)");
338: if (ret != null) {
339: compilerArgsField.setText(ret);
340: }
341: }
342: });
343:
344: advancedItems.add(gl3.add("Runtime JVM arguments "));
345: JPanel runtimeOptionsPanel = new JPanel(new FlowLayout(
346: FlowLayout.LEFT, 0, 0));
347: final JTextField runtimeArgsField = new JTextField(projDef
348: .getRuntimeArgs(), 28);
349: runtimeArgsField.setMinimumSize(runtimeArgsField
350: .getPreferredSize());
351: advancedItems.add(gl3.add(runtimeOptionsPanel));
352: runtimeOptionsPanel.add(runtimeArgsField);
353: GUIUtils.offerRightClickAddCompletion(runtimeArgsField, projDef
354: .getProps().getArrayProperty(
355: "runtimeArgsField_known_items_"));
356:
357: JButton viewJvmOptsDialog = new JButton("+");
358: runtimeOptionsPanel.add(viewJvmOptsDialog);
359: viewJvmOptsDialog.setMargin(new Insets(0, 1, 0, 1));
360: viewJvmOptsDialog.setFocusPainted(false);
361: runtimeOptionsPanel.add(viewRuntimeOpts);
362: runtimeOptionsPanel.setMinimumSize(runtimeOptionsPanel
363: .getPreferredSize());
364: viewRuntimeOpts.setMargin(new Insets(0, 2, 0, 2));
365: viewRuntimeOpts.setFocusPainted(false);
366: viewRuntimeOpts.addActionListener(new ActionListener() {
367: public void actionPerformed(ActionEvent ae) {
368: displayJavaRuntimeOptions();
369: }
370: });
371: viewJvmOptsDialog.addActionListener(new ActionListener() {
372: public void actionPerformed(ActionEvent ae) {
373: String ret = viewArgumentsDialog(runtimeArgsField
374: .getText(), "JVM arguments (one per line)");
375: if (ret != null) {
376: runtimeArgsField.setText(ret);
377: }
378: }
379: });
380:
381: // Documentation
382: //
383:
384: gl3.addTitleSeparator("Documentation");
385: gl3.add("JDK documentation root");
386: jdkDocRoot = new FileField(
387: projDef.getJDKDoc_Home(),
388: false,
389: "Select the folder od the JDK docs (separate ~50MB download) (where /api is)",
390: JFileChooser.DIRECTORIES_ONLY);
391: jdkDocRoot.getTextField().setColumns(30);
392: jdkDocRoot.setMinimumSize(jdkDocRoot.getPreferredSize());
393: gl3.add(jdkDocRoot);
394: jdkDocRoot.setAutoColorized();
395: jdkDocRoot.offerRememberedGlobalCompletion(
396: MainEditorFrame.instance.globalProperties,
397: "Global_jdkDocRoot_hist");
398:
399: advancedItems.add(gl3.add("external JavaDocs roots"));
400: extJavaDocs = new FileListField(
401: "Java docs roots (\"api\" folders)",
402: JFileChooser.DIRECTORIES_ONLY, null, this );
403: extJavaDocs.setFiles(projDef.getExternalJavaDocsRoots());
404: extJavaDocs.getTextField().setColumns(30);
405: advancedItems.add(gl3.add(extJavaDocs));
406: extJavaDocs.offerRememberedPaths(
407: MainEditorFrame.instance.globalProperties,
408: "Global_jdkExtDocsRoot_hist");
409:
410: if (MainEditorFrame.enableExperimental) {
411: gl3.addTitleSeparator("Experimental settings");
412: customTideSettingsFolder = new FileField(
413: projDef.getProjectSettingsFolder(),
414: false,
415: "Select the directory to place the project settings (will contain a subfolder named .tide)",
416: JFileChooser.DIRECTORIES_ONLY);
417: customTideSettingsFolder.getTextField().setColumns(30);
418:
419: gl3.add("Project settings folder");
420: gl3.add(customTideSettingsFolder);
421:
422: JButton bt = GUIUtils.makeNiceButton(new JButton(
423: "Reset working time"));
424: gl3.add("");
425: gl3.add(bt);
426: bt.addActionListener(new ActionListener() {
427: public void actionPerformed(ActionEvent ae) {
428: projDef.resetWorkingTime(0, 0);
429: }
430: });
431:
432: /*
433: // Security ! (=> Also encrypt ! ?)
434: gl3.add("");
435: gl3.add(new JCheckBox("Delete classes on exit", true));
436: */
437:
438: /*gl3.add("");
439: gl3.add(ramDiskModeCB);
440: ramDiskModeCB.setSelected(projDef.getBooleanProperty("Project_ramDiskMode", false));
441: */
442: }
443:
444: this .pack();
445: updateAdvancedOrSimpleMode();
446:
447: this .setLocationRelativeTo(parent);
448: nameField.selectAll();
449: nameField.requestFocus();
450:
451: this .setVisible(true);
452: // Modal => wait until closed
453:
454: if (ccp.getWasCancelled()) {
455: if (exitIfCancelled) {
456: System.exit(0);
457: }
458: return;
459: }
460:
461: // save (first java home) => version known
462: projDef.setJava_Home(javaHomeField.getPath());
463: projDef.setSources_Home(srcHomeField.getPath());
464: projDef.setClasses_Home(genClassesField.getPath());
465: projDef.setProjectName(nameField.getText());
466: projDef.setMainSourceFile(mainClassField.getPath());
467: projDef.setExternalJars(includeJars.getAllFiles());
468: includeJars.rememberPathForGlobalCompletion(
469: MainEditorFrame.instance.globalProperties,
470: "Global_extJars_hist");
471: String cop = compilerArgsField.getText();
472: if (projDef.getJavaVersion().compareTo("1.5") < 0) {
473: cop = ProjectUtils.removeXlints(cop);
474: }
475: projDef.setCompilerOptions(cop);
476: projDef.setAppArgs(progArgsField.getText());
477: projDef.setRuntimeArgs(runtimeArgsField.getText());
478: projDef.setJDKDoc_Home(jdkDocRoot.getPath()); // may be null (and may be overridden below)
479: projDef.setExternalJavaDocs(extJavaDocs.getAllFiles());
480: extJavaDocs.rememberPathForGlobalCompletion(
481: MainEditorFrame.instance.globalProperties,
482: "Global_jdkExtDocsRoot_hist");
483:
484: projDef.setBooleanProperty("Project_advancedModeBT",
485: advancedModeBT.isSelected());
486: projDef.setBooleanProperty("Project_ramDiskMode", ramDiskModeCB
487: .isSelected());
488:
489: projDef.getProps().setArrayProperty(
490: "progArgsField_known_items_",
491: ProjectUtils.splitArgs(progArgsField.getText(), true));
492: projDef.getProps().setArrayProperty(
493: "runtimeArgsField_known_items_",
494: ProjectUtils
495: .splitArgs(runtimeArgsField.getText(), true));
496: projDef.getProps().setArrayProperty(
497: "compilerArgsField_known_items_",
498: ProjectUtils.splitArgs(compilerArgsField.getText(),
499: true));
500:
501: if (customTideSettingsFolder != null) {
502: projDef
503: .setCustomTideSettingsFolder(customTideSettingsFolder
504: .getPath());
505: } else {
506: //.. cancel ??
507: }
508:
509: // clever global default !
510: try {
511: Preferences.userRoot().put(
512: "tIDE_classes_gen_root",
513: genClassesField.getPath().getParentFile()
514: .getAbsolutePath());
515:
516: File srcPath = srcHomeField.getPath();
517: String nameLow = srcPath.getName().toLowerCase();
518: if (nameLow.endsWith("src") || nameLow.endsWith("source")
519: || nameLow.endsWith("sources")
520: || nameLow.startsWith("quell")) // ?? (
521: {
522: File projectRoot = srcPath.getParentFile();
523: if (projectRoot != null) {
524: File root = projectRoot.getParentFile();
525: Preferences.userRoot().put(
526: "tide_guessed_java_projects_home",
527: root.getAbsolutePath());
528: }
529: } else {
530: JOptionPane
531: .showMessageDialog(
532: MainEditorFrame.instance,
533: "The source path you provided\n\n "
534: + srcPath
535: + "\n\ndoesn't end with src or source(s). This is mandatory and surely a good idea to use a"
536: + "\nsrc folder in your project for the sources. The IDE's work is easyer, temp, dest, pub,"
537: + "\ndoc and dev folders are easy to generate automatically as siblings of src.",
538: "Sources Folder Naming Convention Violation",
539: JOptionPane.ERROR_MESSAGE);
540: }
541:
542: } catch (Exception ignored) {
543: }
544:
545: if (!oldSourceLoc.equals(srcHomeField.getPath()
546: .getAbsolutePath())
547: || !oldCP.equals(includeJars.getTextField().getText())
548: || !oldJDKHome.equals(javaHomeField.getPath()
549: .getAbsolutePath()) || firstCall) {
550: this .reloadProjectMandatory = true;
551: }
552:
553: // read jdk version and test
554: File javaExe = projDef.getJava_TOOL();
555: if (!javaExe.exists()) {
556: JOptionPane
557: .showMessageDialog(
558: MainEditorFrame.instance,
559: "The JDK home you provided doesn't exist."
560: + "\nYou can't develop without a valid JDK !"
561: + "\nPlease select one or download it from\n http://java.sun.com/javase/downloads/.",
562: "Java exe not found",
563: JOptionPane.ERROR_MESSAGE);
564: }
565:
566: // create src dir if not existing
567: if (!srcHomeField.getPath().exists()) {
568: srcHomeField.getPath().mkdirs();
569: }
570:
571: // clever guess !
572: if (extJavaDocs.getAllFiles() == null
573: || extJavaDocs.getAllFiles().isEmpty()) {
574: // be clever...
575: if (jdkDocRoot.getPath() == null
576: || !jdkDocRoot.getPath().exists()) {
577: searchJavaDocs(parent.globalProperties);
578: }
579:
580: projDef.setExternalJavaDocs(extJavaDocs.getAllFiles());
581: }
582:
583: // warning if not successful
584:
585: if (jdkDocRoot.getPath() == null
586: || !jdkDocRoot.getPath().exists()) {
587: // be clever...
588: String dd = parent.globalProperties.getProperty(
589: "lastKnownJDKDocsDir", "");
590: if (dd.length() > 0 && new File(dd).exists()) {
591: actualProject.setJDKDoc_Home(new File(dd));
592: } else {
593: // warn
594: JOptionPane
595: .showMessageDialog(
596: this ,
597: "You don't provided the path to the standard JDK documentation."
598: + "\nThis folder is not mandatory but very useful to see the javadocs helps in the completions."
599: + "\nIf not already made, please download and install the jdk documentation and set the path"
600: + "\nfolder in the projects settings.",
601: "No JDK documentation defined",
602: JOptionPane.WARNING_MESSAGE);
603: }
604: } else {
605: // remember for later projects
606: if (jdkDocRoot.getPath() != null
607: && jdkDocRoot.getPath().exists()) {
608: parent.globalProperties.setProperty(
609: "lastKnownJDKDocsDir", jdkDocRoot.getPath()
610: .getAbsolutePath());
611: }
612:
613: jdkDocRoot.rememberPathForGlobalCompletion(
614: MainEditorFrame.instance.globalProperties,
615: "Global_jdkDocRoot_hist");
616: }
617:
618: // verify that the compiler generates the variable names
619: if (cop.indexOf("-g") == -1) {
620: JOptionPane
621: .showMessageDialog(
622: this ,
623: "The compiler option -g is missing, no debug info and especially no variable names will be written in the bytecode."
624: + "\nTherefore tIDE will not be able to display the argument names in the completion dialogs."
625: + "\nNote that if your intent is to shrink the bytecode, you'll get better results using"
626: + "\nProGard to shrink the generated project jar. Please let at least -g:vars in the options.",
627: "No variable names in bytecode",
628: JOptionPane.WARNING_MESSAGE);
629: } else if (cop.indexOf("-g:") >= 0) {
630: if (cop.indexOf("-g:none") >= 0) {
631: JOptionPane
632: .showMessageDialog(
633: this ,
634: "The compiler option -g:none disables writing the debugging info and especially the variable names in the bytecode."
635: + "\nTherefore tIDE will not be able to display the argument names in the completion dialogs."
636: + "\nNote that if your intent is to shrink the bytecode, you'll get better results using"
637: + "\nProGard to shrink the generated project jar.\nPlease let at least -g:vars in the options.",
638: "No variable names in bytecode",
639: JOptionPane.WARNING_MESSAGE);
640: } else if (cop.indexOf("-g:all") >= 0) {
641: // ok
642: } else if (cop.indexOf("-g:vars") >= 0) {
643: // ok
644: } else if (cop.indexOf("-g:vars") == -1) {
645: JOptionPane
646: .showMessageDialog(
647: this ,
648: "The compiler option -g is missing, no debug info and especially no variable names will be written in the bytecode."
649: + "\nTherefore tIDE will not be able to display the argument names in the completion dialogs."
650: + "\nNote that if your intent is to shrink the bytecode, you'll get better results using"
651: + "\nProGard to shrink the generated project jar.\nPlease let at least -g:vars in the options.",
652: "No variable names in bytecode",
653: JOptionPane.WARNING_MESSAGE);
654: }
655:
656: } // else ok, we have "-g" but not "-g:"
657:
658: String rtt = runtimeArgsField.getText().trim();
659: if (rtt.indexOf("-server") > 0) {
660: JOptionPane.showMessageDialog(MainEditorFrame.instance,
661: "The runtime argument -server must be the first.",
662: "Bad JVM -server argument position",
663: JOptionPane.ERROR_MESSAGE);
664: }
665:
666: // takes no time (call it always to keep up to date).
667: try {
668: actualProject.reloadJavaDocManager().call();
669: } catch (Exception e) {
670: e.printStackTrace();
671: }
672:
673: // remember javadocs (only the one containing the folder "java", this is the api of rt.jar (with great probability)
674: //
675: fl: for (File docRoot : extJavaDocs.getAllFiles()) {
676: File tf = new File(docRoot, "java");
677: if (tf.exists()) {
678: // used above
679: parent.globalProperties
680: .setProperty("lastKnownJDKAPIDir", docRoot
681: .getAbsolutePath());
682: break fl;
683: }
684: }
685:
686: } // Constructor
687:
688: /** Registers as javadocs the folders named api found as subfolders of the jdk home.
689: * If not found, takes known folder from previous projects
690: * TODO: ameliorate, think more here...
691: */
692: private void searchJavaDocs(AppProperties globalProps) {
693: if (true)
694: return; // TODO...
695:
696: ArrayList<File> dirs = new ArrayList<File>();
697: FileUtilities.getAllDirectoriesRecurse_depthFirst(dirs,
698: javaHomeField.getPath());
699: System.out.println("Looking for api docs in " + dirs.size()
700: + " directories");
701: for (int i = dirs.size() - 1; i >= 0; i--) {
702: if (dirs.get(i).getName().equals("api")) {
703: System.out.println("Found javaDoc folder: "
704: + dirs.get(i));
705: java.util.List<File> af = extJavaDocs.getAllFiles();
706: af.add(dirs.get(i));
707: extJavaDocs.setFiles(af);
708: }
709: }
710:
711: if (extJavaDocs.getAllFiles().isEmpty()) {
712: // use docs from an old project... if present
713: String f = globalProps.getProperty("lastKnownJDKDocsDir",
714: "");
715: if (f.length() > 0) {
716: File fi = new File(f, "api/");
717: if (fi.exists()) {
718: java.util.List<File> af = extJavaDocs.getAllFiles();
719: af.add(fi);
720: extJavaDocs.setFiles(af);
721: }
722: }
723: }
724:
725: if (extJavaDocs.getAllFiles().isEmpty()) {
726: // use docs from an old project... if present
727: String f = globalProps
728: .getProperty("lastKnownJDKAPIDir", "");
729: if (f.length() > 0) {
730: File fi = new File(f);
731: if (fi.exists()) {
732: List<File> af = extJavaDocs.getAllFiles();
733: af.add(fi);
734: extJavaDocs.setFiles(af);
735: }
736: }
737: }
738: }
739:
740: /** @return false if the user has pressed the cancel button.
741: */
742: public boolean getHasBeenAccepted() {
743: return !ccp.getWasCancelled();
744: }
745:
746: /** When the source path has changed OR the class path.
747: */
748: public boolean mustReloadProjectBecauseOfChanges() {
749: return reloadProjectMandatory;
750: }
751:
752: /**
753:
754: Xlints:
755: 1.7.0b: all,cast,deprecation,divzero,empty,unchecked,fallthrough,path,serial,finally,overrides
756: 1.6.0_01 all,cast,deprecation,divzero,empty,unchecked,fallthrough,path,serial,finally,overrides
757: 1.5.0_08: all, deprecation, unchecked,fallthrough,path,serial,finally
758:
759: */
760: private void displayCompilerOptions() {
761: //ProjectSettings actualProject = MainEditorFrame.instance.getActualProject();
762: StringBuilder comp = new StringBuilder();
763: try {
764: List<String> args = new ArrayList<String>();
765: args.add(actualProject.getJavaC_TOOL().getAbsolutePath());
766: args.add("-help");
767: comp.append(ProcessUtils.readWholeProcessStack(args));
768:
769: comp.append("\r\nNonstandard options\r\n");
770: args.remove(args.size() - 1);
771:
772: args.add("-X");
773: comp.append(ProcessUtils.readWholeProcessStack(args));
774:
775: } catch (Exception e) {
776: comp.append("\r\nError: " + e.getMessage());
777: e.printStackTrace();
778: }
779:
780: JDialog optionsDialog = new JDialog(
781: ProjectSettingsEditorDialog.this ,
782: "Available compiler options", false);
783: JTextPane tp = new JTextPane();
784: tp.setFont(MainEditorFrame.fixedWidthFontForProcesses);
785: tp.setText(comp.toString().trim());
786: optionsDialog.add(new JScrollPane(tp), BorderLayout.CENTER);
787: CloseControlPanel ccp = new CloseControlPanel(optionsDialog,
788: false, true, "Close");
789: optionsDialog.add(ccp, BorderLayout.SOUTH);
790: tp.setEditable(false);
791: tp.setCaretPosition(0);
792: optionsDialog.setSize(800, 600);
793: optionsDialog.setLocationRelativeTo(viewCompOpts);
794: optionsDialog.setVisible(true);
795:
796: }
797:
798: private void displayJavaRuntimeOptions() {
799: //ProjectSettings actualProject = MainEditorFrame.instance.getActualProject();
800: StringBuilder comp = new StringBuilder();
801: try {
802: List<String> args = new ArrayList<String>();
803: args.add(actualProject.getJava_TOOL().getAbsolutePath());
804: args.add("-help");
805: comp.append(ProcessUtils.readWholeProcessStack(args));
806:
807: comp.append("\r\nNonstandard options\r\n");
808: args = new ArrayList<String>();
809: args.add(actualProject.getJava_TOOL().getAbsolutePath());
810: args.add("-X");
811: comp.append(ProcessUtils.readWholeProcessStack(args));
812:
813: comp.append("\r\n\r\nHere some selected system properties");
814: comp
815: .append("\r\n-Dcom.sun.management.jmxremote \tenables JMX (not necessary since Java6)");
816: comp.append("\r\n-Dcom.sun.management.jmxremote.port=9999");
817: comp
818: .append("\r\n-Dcom.sun.management.jmxremote.authenticate=true");
819: comp.append("\r\n-Dcom.sun.management.jmxremote.ssl=false");
820: comp
821: .append("\r\n-Dcom.sun.management.jmxremote.password.file=\"C:\\Documents and Settings\\your_name\\jmxremote.password\"");
822: // http://java.sun.com/javase/6/docs/technotes/guides/2d/flags.html
823: comp
824: .append("\r\n-Dsun.java2d.opengl=true\tsilently enable the OpenGL-based pipeline");
825: comp
826: .append("\r\n-Dsun.java2d.opengl=True\twith additional verbose console output");
827: comp
828: .append("\r\n-Dsun.java2d.trace=[log[,timestamp]],[count],[out:<filename>],[help],[verbose]");
829: comp
830: .append("\r\n-Dsun.java2d.d3d=false\tdisable use of direct3D. Some rare systems are instable");
831:
832: comp
833: .append("\r\n\r\nHere some selected debug properties\r\n (Inofficial list at "
834: + Tips.JVMOptionsURL + ")");
835: comp
836: .append("\r\n-XX:+PrintClassHistogram\tprints a class histogram in the console on CTRL+break");
837: comp.append("\r\n-XX:+HeapDumpOnOutOfMemoryError");
838: comp.append("\r\n-XX:+OnError=\"pmap %p\"");
839: comp.append("\r\n-XX:+ErrorFile=...");
840: comp.append("\r\n-XX:+HeapDumpPath=...");
841: comp.append("\r\n-Xcheck:jni");
842:
843: comp.append("\r\n-XX:+OnOutOfMemoryError=\"...\"");
844: comp.append("\r\n-XX:+ShowMessageBoxOnError");
845: comp.append("\r\n-XX:+PrintCommandLineFlags");
846: comp.append("\r\n-XX:+PrintConcurrentLocks");
847: comp
848: .append("\r\n-Djava.security.debug=\"access,failure\"\topts: {access,jar,policy,scl}, {stack,domain,failure}");
849:
850: comp.append("\r\n\r\nJava debugger settings:");
851: comp
852: .append("\r\n-agentlib:jdwp=transport=dt_shmem,address=jdbconn,server=y,suspend=n\twindows example, start jdb with \"jdb -attach jdbconn\"");
853: comp
854: .append("\r\n-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n\tlinux example, start jdb with \"jdb -attach 8000\"");
855:
856: } catch (Exception e) {
857: comp.append("\r\nError: " + e.getMessage());
858: e.printStackTrace();
859: }
860:
861: JDialog optionsDialog = new JDialog(
862: ProjectSettingsEditorDialog.this ,
863: "Available runtime options", false);
864: JTextPane tp = new JTextPane();
865: tp.setFont(MainEditorFrame.fixedWidthFontForProcesses);
866: tp.setText(comp.toString().trim());
867: optionsDialog.add(new JScrollPane(tp), BorderLayout.CENTER);
868: CloseControlPanel ccp = new CloseControlPanel(optionsDialog,
869: false, true, "Close");
870: optionsDialog.add(ccp, BorderLayout.SOUTH);
871: tp.setEditable(false);
872: tp.setCaretPosition(0);
873: optionsDialog.setSize(800, 600);
874: optionsDialog.setLocationRelativeTo(viewRuntimeOpts);
875: optionsDialog.setVisible(true);
876:
877: }
878:
879: private void updateAdvancedOrSimpleMode() {
880: for (Component c : advancedItems) {
881: c.setVisible(advancedModeBT.isSelected());
882: }
883:
884: if (advancedModeBT.isSelected()) {
885: advancedModeBT
886: .setText("Return to the essential settings mode <<");
887: } else {
888: advancedModeBT.setText("See advanced options >>");
889: }
890:
891: pack();
892: }
893:
894: /** Better options view, one per line.
895: * @return null if not accepted
896: */
897: private String viewArgumentsDialog(String optText, String title) {
898: StringBuilder sb = new StringBuilder();
899: for (String line : ProjectUtils.splitArgs(optText, true)) {
900: line = line.trim();
901: sb.append("\n" + line);
902: }
903:
904: JDialog d = new JDialog(this , title, true); // modal
905: d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
906: JTextArea ta = new JTextArea(sb.toString().trim(), 8, 42);
907: d.add(new JScrollPane(ta), BorderLayout.CENTER);
908: final CloseControlPanel ccp2 = new CloseControlPanel(d, true,
909: true, "close");
910: d.add(ccp2, BorderLayout.SOUTH);
911: //d.setSize(400,200);
912: d.pack();
913: d.setLocationRelativeTo(this );
914: d.setVisible(true);
915: if (!ccp2.getWasAccepted())
916: return null;
917: return ta.getText().replace('\n', ' ');
918: }
919:
920: }
|