r3242 - in isis-fish/branches/3.3.1/src/main: java/fr/ifremer/isisfish/datastore/update java/fr/ifremer/isisfish/ui/input java/fr/ifremer/isisfish/util resources/i18n
Author: chatellier Date: 2011-04-08 16:34:33 +0000 (Fri, 08 Apr 2011) New Revision: 3242 Log: Fix equation editor layout and code Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/update/ImportFromV2.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/EquationEditorPaneUI.jaxx isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/InputAction.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/util/CompileHelper.java isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_en_GB.properties isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_fr_FR.properties Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/update/ImportFromV2.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/update/ImportFromV2.java 2011-04-08 16:01:10 UTC (rev 3241) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/datastore/update/ImportFromV2.java 2011-04-08 16:34:33 UTC (rev 3242) @@ -359,7 +359,7 @@ // frame.getEquationEditorPane().setEquation(eq); frame.setEquation(eq.getCategory(), eq.getName(), eq.getJavaInterface(), eq.getContent()); frame.setVisible(true); - if (frame.isOk()) { + if (frame.isResultOk()) { eq.setContent(frame.getEditor().getText()); } context.commitTransaction(); Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/EquationEditorPaneUI.jaxx =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/EquationEditorPaneUI.jaxx 2011-04-08 16:01:10 UTC (rev 3241) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/EquationEditorPaneUI.jaxx 2011-04-08 16:34:33 UTC (rev 3242) @@ -23,8 +23,11 @@ #L% --> <JDialog id="EquationEditorPane" modal="true" title="isisfish.equation.editor.title" - width="400" height="400" layout="{new BorderLayout()}"> + width="400" height="400" layout="{new BorderLayout()}" + modalityType="{Dialog.ModalityType.APPLICATION_MODAL}"> + <Boolean id="resultOk" javaBean="false" /> + <import> fr.ifremer.isisfish.util.CompileHelper; fr.ifremer.isisfish.util.EvaluatorHelper; @@ -41,55 +44,37 @@ </import> <script><![CDATA[ -boolean ok = false; Class javaInterface = null; protected void $afterCompleteSetup() { - setModalityType(Dialog.ModalityType.APPLICATION_MODAL); - doc.setEditable(false); - doc.setEditorKit(new HTMLEditorKit()); - doc.addHyperlinkListener(createHyperLinkListener()); - - editor.setAskIfNotSaved(false); - - checkWindow.setEditable(false); - split.setDividerLocation(0.8); } -public boolean isOk() { - return ok; -} - public void setEquation(String category, String name, Class javaInterface, String content) throws Exception { this.javaInterface = javaInterface; getDoc().setText(CompileHelper.extractDoc(category, name, javaInterface)); getEditor().open(FileUtil.getTempFile(content, ".java")); } -public HyperlinkListener createHyperLinkListener() { - return new HyperlinkListener() { - public void hyperlinkUpdate(HyperlinkEvent e) { - if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { - if (e instanceof HTMLFrameHyperlinkEvent) { - ((HTMLDocument)doc.getDocument()).processHTMLFrameHyperlinkEvent( - (HTMLFrameHyperlinkEvent)e); +public void docEditorHyperlinkUpdate(HyperlinkEvent e) { + if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { + if (e instanceof HTMLFrameHyperlinkEvent) { + ((HTMLDocument)doc.getDocument()).processHTMLFrameHyperlinkEvent( + (HTMLFrameHyperlinkEvent)e); + } else { + try { + if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { + Desktop.getDesktop().browse(e.getURL().toURI()); } else { - try { - if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { - Desktop.getDesktop().browse(e.getURL().toURI()); - } else { - doc.setPage(e.getURL()); - } - } catch (Exception ex) { - if (log.isErrorEnabled()) { - log.error("Error for : " + e.getURL(), ex); - } - } + doc.setPage(e.getURL()); } + } catch (Exception ex) { + if (log.isErrorEnabled()) { + log.error("Error for : " + e.getURL(), ex); + } } } - }; + } } public void check() { @@ -108,10 +93,10 @@ out.flush(); if (compileResult != 0) { checkWindow.setText(result.toString()); - checkWindow.setBackground(Color.red); + checkWindow.setBackground(Color.RED); } else { checkWindow.setText("Compilation Ok"); - checkWindow.setBackground(Color.white); + checkWindow.setBackground(Color.WHITE); } } catch(Exception e){ @@ -123,19 +108,20 @@ <Table constraints="BorderLayout.CENTER"> <row> - <cell columns='4' weighty="1" fill='both'> + <cell columns='3' weighty="1" fill='both'> <JScrollPane> - <JEditorPane id="doc" /> + <JEditorPane id="doc" editable="false" editorKit="{new HTMLEditorKit()}" + onHyperlinkUpdate="docEditorHyperlinkUpdate(event)" /> </JScrollPane> </cell> </row> - <row columns='4' weighty="5" fill='both'> + <row columns='3' weightx="1" weighty="5" fill='both'> <cell> <JSplitPane id='split' orientation='vertical' oneTouchExpandable='true' resizeWeight='0.8'> - <org.nuiton.widget.editor.Editor id="editor" /> + <org.nuiton.widget.editor.Editor id="editor" askIfNotSaved="false" /> <JScrollPane> - <JEditorPane id="checkWindow" /> + <JTextArea id="checkWindow" editable="false" /> </JScrollPane> </JSplitPane> </cell> @@ -144,10 +130,10 @@ <cell> <JButton text='isisfish.common.check' onActionPerformed='check()' /> </cell> - <cell> - <JButton id='okButton' text='isisfish.common.ok' onActionPerformed='ok=true; setVisible(false)' /> + <cell weightx="1" fill="none" anchor="east"> + <JButton id='okButton' text='isisfish.common.ok' onActionPerformed='setResultOk(true); setVisible(false)' /> </cell> - <cell> + <cell anchor="east"> <JButton id='cancelButton' text='isisfish.common.cancel' onActionPerformed='setVisible(false)' /> </cell> </row> Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/InputAction.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/InputAction.java 2011-04-08 16:01:10 UTC (rev 3241) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/input/InputAction.java 2011-04-08 16:34:33 UTC (rev 3242) @@ -304,17 +304,17 @@ return null; } - public Object openEditor(InputOneEquationUI ui, String category, String name, Class javaInterface, + public Object openEditor(InputOneEquationUI ui, String category, String name, Class<?> javaInterface, String content, Editor editor) { if (log.isTraceEnabled()) { log.trace("openEditor"); } try { - EquationEditorPaneUI pane = new EquationEditorPaneUI(); + EquationEditorPaneUI pane = new EquationEditorPaneUI(ui); pane.setEquation(category, name, javaInterface, content); pane.setLocationRelativeTo(ui); - pane.setVisible(true); - if (pane.isOk() && editor != null) { + pane.setVisible(true); // blocking call + if (pane.isResultOk() && editor != null) { editor.setText(pane.getEditor().getText()); } pane.dispose(); Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/util/CompileHelper.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/util/CompileHelper.java 2011-04-08 16:01:10 UTC (rev 3241) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/util/CompileHelper.java 2011-04-08 16:34:33 UTC (rev 3242) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2006 - 2010 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin + * Copyright (C) 2006 - 2011 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -98,8 +98,8 @@ * @param fqn le nom complet de la classe a charger * @return la classe souhaité ou null si la class n'est pas trouvée */ - public static Class loadClass(String fqn) { - Class result = null; + public static Class<?> loadClass(String fqn) { + Class<?> result = null; try { ClassLoader cl = IsisFish.config.getScriptClassLoader(); result = cl.loadClass(fqn); @@ -112,7 +112,7 @@ public static Object newInstance(String fqn) { Object result = null; try { - Class clazz = loadClass(fqn); + Class<?> clazz = loadClass(fqn); if (clazz != null) { result = clazz.newInstance(); @@ -310,19 +310,19 @@ } /** - * Extract documentation from interface (Equation) + * Extract documentation from interface (Equation). + * * @param category * @param name * @param javaInterface * @return doc */ public static String extractDoc(String category, String name, - Class javaInterface) { - String content = ""; - content = "<p>Equation : " + Class<?> javaInterface) { + String content = "<p>Equation : " + createHREF(javaInterface.getName(), category) + " - " + name + "</p>"; - content += "<h3>Parameter: name and type</h3>"; + content += "<h3>" + _("isisfish.editor.parametersnameandtypes") + " :</h3>"; Method[] methods = javaInterface.getDeclaredMethods(); Method interfaceMethod = methods[0]; @@ -336,7 +336,7 @@ stringTypes = argTypes.value(); } else { stringTypes = new String[names.length]; - Class[] types = interfaceMethod.getParameterTypes(); + Class<?>[] types = interfaceMethod.getParameterTypes(); for (int i = 0; i < types.length; i++) { stringTypes[i] = types[i].getName(); } @@ -344,29 +344,35 @@ for (int i = 0; i < names.length; i++) { content += "<li>" + names[i] + " : " + createHREF(stringTypes[i]); - // if (i+1<names.length) { - // content += "\n"; - // } } - try { - FileUtil.writeString(new File("/tmp/testDoc.html"), content); - } catch (IOException eee) { - if (log.isWarnEnabled()) { - log.warn("TODO untreated error", eee); - } - } return content; } - private static String createHREF(String type, String... texts) { - String ref = IsisFish.config.getJavadocURL() - + type.replaceAll("\\.", "/") + ".html"; + /** + * Create a html link to isis javadoc. + * + * @param type class type + * @param texts link display text + * @return + */ + protected static String createHREF(String type, String... texts) { + + // si pas de text, on affiche le type String text = type; if (texts.length > 0) { text = texts[0]; } - String result = "<a href='" + ref + "'>" + text + "</a>"; + + String result = null; + if (type.startsWith("fr.ifremer.isisfish")) { + String ref = IsisFish.config.getJavadocURL() + type.replaceAll("\\.", "/") + ".html"; + result = "<a href='" + ref + "'>" + text + "</a>"; + } else { + // n'affiche pas de lien pour les types + // genre "double" qui ne sont pas dans la javadoc d'isisfish + result = text; + } return result; } Modified: isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_en_GB.properties =================================================================== --- isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_en_GB.properties 2011-04-08 16:01:10 UTC (rev 3241) +++ isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_en_GB.properties 2011-04-08 16:34:33 UTC (rev 3242) @@ -212,6 +212,7 @@ isisfish.dataResult.export.csv=Export to CSV isisfish.dataResult.label=Value isisfish.date.toString=%1$s %2$s +isisfish.editor.parametersnameandtypes=Parameters (name and type) isisfish.effortDescription.crewFoodCost=Crew food cost isisfish.effortDescription.crewShareRate=Crew share rate isisfish.effortDescription.crewSize=Crew size Modified: isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_fr_FR.properties =================================================================== --- isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_fr_FR.properties 2011-04-08 16:01:10 UTC (rev 3241) +++ isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_fr_FR.properties 2011-04-08 16:34:33 UTC (rev 3242) @@ -212,6 +212,7 @@ isisfish.dataResult.export.csv=Exporter en CSV isisfish.dataResult.label=Valeur isisfish.date.toString=%1$s %2$s +isisfish.editor.parametersnameandtypes=Param\u00E8tres (nom et type) isisfish.effortDescription.crewFoodCost=Co\u00FBt de l'alimentation pour l'\u00E9quipage isisfish.effortDescription.crewShareRate=Taux de partage de l'\u00E9quipage isisfish.effortDescription.crewSize=Taille de l'\u00E9quipage
participants (1)
-
chatellier@users.labs.libre-entreprise.org