From: <se...@us...> - 2008-05-19 21:35:49
|
Revision: 146 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=146&view=rev Author: sem62 Date: 2008-05-19 14:30:10 -0700 (Mon, 19 May 2008) Log Message: ----------- * added template for cimpileQ model * Moved all logic for tree into new class CourseTree Modified Paths: -------------- WebEditor/src/edu/lnu/FireFly/WebEditor/AppletWithApiHandle.java WebEditor/src/edu/lnu/FireFly/WebEditor/ItemModels/CompileQ/CompileQModel.java WebEditor/src/edu/lnu/FireFly/WebEditor/Settings.java WebEditor/src/edu/lnu/FireFly/WebEditor/WebEditor.java Added Paths: ----------- WebEditor/src/edu/lnu/FireFly/WebEditor/CourseTree.java WebEditor/template/CompileQModel.html WebEditor/template/global/compileQ.js Modified: WebEditor/src/edu/lnu/FireFly/WebEditor/AppletWithApiHandle.java =================================================================== --- WebEditor/src/edu/lnu/FireFly/WebEditor/AppletWithApiHandle.java 2008-05-18 17:35:26 UTC (rev 145) +++ WebEditor/src/edu/lnu/FireFly/WebEditor/AppletWithApiHandle.java 2008-05-19 21:30:10 UTC (rev 146) @@ -9,58 +9,59 @@ */ public class AppletWithApiHandle extends JApplet { /** - * - */ - private static final long serialVersionUID = 5396705469025038804L; - public static boolean initialized = false; + * + */ + private static final long serialVersionUID = 5396705469025038804L; + public static boolean initialized = false; public static boolean terminated = false; - static public String Initialize(String parameter){ - System.out.print("Initialize(" + parameter + ");\n"); - return "true"; + static public String Initialize(String parameter) { + System.out.print("Initialize(" + parameter + ");\n"); + return "true"; } - static public String Terminate(String parameter){ - System.out.print("Terminate(" + parameter + ");\n"); - return "true"; + static public String Terminate(String parameter) { + System.out.print("Terminate(" + parameter + ");\n"); + return "true"; } - static public String GetValue(String parameter){ - System.out.print("GetValue(" + parameter + ");\n"); - - if (parameter.endsWith("completionStatus")){ - return "incomplete"; - } - - return "6"; + static public String GetValue(String parameter) { + System.out.print("GetValue(" + parameter + ");\n"); + + if (parameter.endsWith("completionStatus")) { + return "incomplete"; + } + + return "6"; } - static public boolean SetValue(String parameter, String value){ - System.out.print("SetValue(" + parameter + ", " + value + ");\n"); - return true; + static public boolean SetValue(String parameter, String value) { + System.out.print("SetValue(" + parameter + ", " + value + ");\n"); + return true; } - static public String Commit(String parameter){ - System.out.print("Commit(" + parameter + ");\n"); - return "true"; + static public String Commit(String parameter) { + System.out.print("Commit(" + parameter + ");\n"); + return "true"; } - static public int GetLastError(){ - System.out.print("GetLastError();\n"); - return 0; + static public int GetLastError() { + System.out.print("GetLastError();\n"); + return 0; } - static public String GetErrorString(String parameter){ - int code = Integer.parseInt(parameter); + static public String GetErrorString(String parameter) { + int code = Integer.parseInt(parameter); - String result = ""; - if (code == 0) result = "No Error"; + String result = ""; + if (code == 0) + result = "No Error"; - return result; + return result; } - static public String GetDiagnostic(String parameter){ - System.out.print("GetDiagnostic(" + parameter + ");\n"); - return ""; + static public String GetDiagnostic(String parameter) { + System.out.print("GetDiagnostic(" + parameter + ");\n"); + return ""; } } Added: WebEditor/src/edu/lnu/FireFly/WebEditor/CourseTree.java =================================================================== --- WebEditor/src/edu/lnu/FireFly/WebEditor/CourseTree.java (rev 0) +++ WebEditor/src/edu/lnu/FireFly/WebEditor/CourseTree.java 2008-05-19 21:30:10 UTC (rev 146) @@ -0,0 +1,69 @@ +package edu.lnu.FireFly.WebEditor; + +import java.applet.AppletContext; +import java.net.URL; + +import javax.swing.JTree; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; + +import edu.lnu.FireFly.FFManifest.item.Item; +import edu.lnu.FireFly.FFManifest.resource.Resource; +import edu.lnu.FireFly.WebEditor.GUI.TreeDataModel; + +public class CourseTree extends JTree implements TreeSelectionListener { + + /** + * + */ + private static final long serialVersionUID = -8762602746961040949L; + + private AppletContext appletContext; + + public AppletContext getAppletContext() { + return appletContext; + } + + public void setAppletContext(AppletContext appletContext) { + this.appletContext = appletContext; + } + + public CourseTree(TreeDataModel dataModel, AppletContext appletContext) { + this.appletContext = appletContext; + this.addTreeSelectionListener(this); + } + + @Override + public void valueChanged(TreeSelectionEvent e) { + if (e.getNewLeadSelectionPath() == null) { + try { + getAppletContext().showDocument( + new URL(Settings.getInstance().getResourceLocation() + + "/empty.htm"), "ContentFrame"); + System.out.print("browse to empty document.\n"); + Thread.sleep(300); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + return; + } + + if (e.getNewLeadSelectionPath().getLastPathComponent().getClass() == Item.class) { + Item item = (Item) e.getNewLeadSelectionPath() + .getLastPathComponent(); + try { + Resource resource = WebEditor.instance.getManifest().resources + .findResourceByIdentifier(item.identifierref); + if (resource != null) { + getAppletContext().showDocument( + new URL(Settings.getInstance().getCourseLocation() + + resource.getFullHref()), "ContentFrame"); + System.out.print("redirected\n"); + } + } catch (Exception exc) { + exc.printStackTrace(); + } + } + } +} Modified: WebEditor/src/edu/lnu/FireFly/WebEditor/ItemModels/CompileQ/CompileQModel.java =================================================================== --- WebEditor/src/edu/lnu/FireFly/WebEditor/ItemModels/CompileQ/CompileQModel.java 2008-05-18 17:35:26 UTC (rev 145) +++ WebEditor/src/edu/lnu/FireFly/WebEditor/ItemModels/CompileQ/CompileQModel.java 2008-05-19 21:30:10 UTC (rev 146) @@ -1,11 +1,16 @@ package edu.lnu.FireFly.WebEditor.ItemModels.CompileQ; +import java.util.Iterator; + import edu.lnu.FireFly.FFManifest.TreeItem; +import edu.lnu.FireFly.FFManifest.item.Item; +import edu.lnu.FireFly.FFManifest.resource.Resource; import edu.lnu.FireFly.WebEditor.WebEditor; import edu.lnu.FireFly.WebEditor.GUI.TreeDataModel; import edu.lnu.FireFly.WebEditor.GUI.Dialogs.CompileQ.CompileQPropertiestsDlg; import edu.lnu.FireFly.WebEditor.ItemModels.ItemData; import edu.lnu.FireFly.WebEditor.ItemModels.ResourcedItemModel; +import edu.lnu.FireFly.WebEditor.ItemModels.Template; public class CompileQModel extends ResourcedItemModel { @Override @@ -64,29 +69,29 @@ @Override protected void updateResourceFile(TreeItem anItem) { -// Resource resource = WebEditor.instance.getManifest().resources -// .findResourceByIdentifier(((Item) anItem).identifierref); -// -// Template template = new Template(resource.getFullHref(), this); -// -// CompileQData itemData = getData(anItem); -// -// template.setProperty("Caption", itemData.getCaption()); -// template.setProperty("Question", itemData.getQuestion()); -// -// Iterator<CompileQPart> iter = itemData.getAnswers().questionParts -// .iterator(); -// String answers = "\r\nsetSingleVariant(" -// + itemData.getAnswers().getSingleVariant() + ");\r\n"; -// -// while (iter.hasNext()) { -// CompileQPart answer = iter.next(); -// answers += "addAnswer(\"" + answer.getAnswerText().replace("\"", "\\\"") + "\", " -// + answer.getAnswerPoint() + ");" + "\r\n"; -// } -// -// template.setProperty("answers", answers); -// template.updateResource(); + Resource resource = WebEditor.instance.getManifest().resources + .findResourceByIdentifier(((Item) anItem).identifierref); + + Template template = new Template(resource.getFullHref(), this); + + CompileQData itemData = getData(anItem); + + template.setProperty("Caption", itemData.getCaption()); + + Iterator<CompileQPart> iter = itemData.getParts().questionParts.iterator(); + String answers = "\r\nsetProgrammingLanguage(\"" + + itemData.getLanguge() + "\");\r\n"; + + while (iter.hasNext()) { + CompileQPart part = iter.next(); + answers += "addPart(\"" + part.getAnswerText().replace("\"", "\\\"") + "\", " + + part.getPartAttributes().isAnswer() + ", " + + part.getPartAttributes().isReadOnly() + ", " + + part.getPartAttributes().isVisible() + ");" + "\r\n"; + } + + template.setProperty("parts", answers); + template.updateResource(); } @Override Modified: WebEditor/src/edu/lnu/FireFly/WebEditor/Settings.java =================================================================== --- WebEditor/src/edu/lnu/FireFly/WebEditor/Settings.java 2008-05-18 17:35:26 UTC (rev 145) +++ WebEditor/src/edu/lnu/FireFly/WebEditor/Settings.java 2008-05-19 21:30:10 UTC (rev 146) @@ -9,7 +9,7 @@ private long autoSaveInterval = 5 * 60 * 1000; private long nopInterval = 60 * 1000; - public static Settings obj = null; + private static Settings obj = null; public static Settings getInstance(){ Modified: WebEditor/src/edu/lnu/FireFly/WebEditor/WebEditor.java =================================================================== --- WebEditor/src/edu/lnu/FireFly/WebEditor/WebEditor.java 2008-05-18 17:35:26 UTC (rev 145) +++ WebEditor/src/edu/lnu/FireFly/WebEditor/WebEditor.java 2008-05-19 21:30:10 UTC (rev 146) @@ -2,22 +2,17 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.net.URL; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JScrollPane; import javax.swing.JTree; -import javax.swing.event.TreeSelectionEvent; -import javax.swing.event.TreeSelectionListener; import edu.lnu.FireFly.FFManifest.Manifest; import edu.lnu.FireFly.FFManifest.TreeItem; -import edu.lnu.FireFly.FFManifest.item.Item; import edu.lnu.FireFly.FFManifest.parser.Parser; import edu.lnu.FireFly.FFManifest.parser.TestDocException; -import edu.lnu.FireFly.FFManifest.resource.Resource; import edu.lnu.FireFly.WebEditor.Data.AutoSaveThread; import edu.lnu.FireFly.WebEditor.Data.ManifestFactory; import edu.lnu.FireFly.WebEditor.Data.SummaryPageManager; @@ -28,7 +23,7 @@ import edu.lnu.FireFly.WebEditor.WSClients.WebEditorServiceClient; public class WebEditor extends AppletWithWYSIWYGEditor implements - ActionListener, TreeSelectionListener { + ActionListener { /** * @@ -115,11 +110,9 @@ CreateNewCourse(); } - tree = new JTree(TreeDataModel.getInstance()); + tree = new CourseTree(TreeDataModel.getInstance(), getAppletContext()); this.add(new JScrollPane(tree)); - tree.addTreeSelectionListener(this); - tree.addMouseListener(new CourseTreePopupMenu()); } @@ -186,38 +179,4 @@ // Install the menu bar in the frame this.setJMenuBar(menuBar); } - - @Override - public void valueChanged(TreeSelectionEvent e) { - if (e.getNewLeadSelectionPath() == null) { - try { - getAppletContext().showDocument( - new URL(Settings.getInstance().getResourceLocation() - + "/empty.htm"), "ContentFrame"); - System.out.print("browse to empty document.\n"); - Thread.sleep(300); - } catch (Exception e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - return; - } - - if (e.getNewLeadSelectionPath().getLastPathComponent().getClass() == Item.class) { - Item item = (Item) e.getNewLeadSelectionPath() - .getLastPathComponent(); - try { - Resource resource = manifest.resources - .findResourceByIdentifier(item.identifierref); - if (resource != null) { - getAppletContext().showDocument( - new URL(Settings.getInstance().getCourseLocation() - + resource.getFullHref()), "ContentFrame"); - System.out.print("redirected\n"); - } - } catch (Exception exc) { - exc.printStackTrace(); - } - } - } } Added: WebEditor/template/CompileQModel.html =================================================================== --- WebEditor/template/CompileQModel.html (rev 0) +++ WebEditor/template/CompileQModel.html 2008-05-19 21:30:10 UTC (rev 146) @@ -0,0 +1,26 @@ +<html> +<head> + <title>title</title> + <meta http-equiv="Content-Type" content="text/html; charset=utf8" /> + <script type="text/javascript" src="global/APIWrapper.js"></script> + <script type="text/javascript" src="global/compileQ.js"></script> +</head> + +<body onLoad="Initialize()" onunload="Terminate();"> + <div id="compileQ_caption"> + <!--caption start-->New caption<!--caption end--> + </div> + <div id="compileQ_content"> + <form onsubmit="return checkAnswer(this);"> + <div id="compileQ_part"> + <script language="javascript"> + <!--parts start--> + <!--parts end--> + show(); + </script> + </div> + <input type=submit value="Check"> + </form> + </div> +</body> +</html> \ No newline at end of file Added: WebEditor/template/global/compileQ.js =================================================================== --- WebEditor/template/global/compileQ.js (rev 0) +++ WebEditor/template/global/compileQ.js 2008-05-19 21:30:10 UTC (rev 146) @@ -0,0 +1,38 @@ +var singlepart = false; +var parts = new Array(); + +function setProgrammingLanguage(language){ +} + +function addPart(_text, _ispart, _isReadOnly, _isVisible){ + var part = { + text: _text, + ispart: _ispart, + isReadOnly: _isReadOnly, + isVisible: _isVisible, + id: "part" + parts.length + }; + parts.push(part); +} + +function show(){ + for (i=0; i < parts.length; i++){ + if (parts[i].isVisible){ + document.write("<div name='" + parts[i].id + "' id='" + parts[i].id + "'>"); + if (!parts[i].isReadOnly){ + document.write("<textarea rows='15' cols='60' id='part" + parts[i].id + "' name='part" + parts[i].id + "'>"); + } + document.write(parts[i].text); + if (!parts[i].isReadOnly){ + document.write("</textarea>"); + } + document.write("<div>"); + } + } +} + +function check7Answer(frm){ + Terminate(); + + return false; +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |