// ConceptWebClient.java - a web applet for the development of concept maps
// A concept map drawing applet. Scott Harrison 2001-2007
// Scott Harrison, harris41@msu.edu
// Project investigators: Douglas Luckie, Diane Ebert-May
// Copyright 2001-2007 Michigan State University Board of Trustees
// =============================================================== INSTALLATION
//
// ConceptWebClient can be installed with the rest of
// the C-TOOLS software package. For information, see
// sourcetreepath/build/README
// cd sourcetreepath/build; aap install-javaclient
//
// The ConceptWebClient also supports a standalone mode, and the
// web page code in ctoolsapplet.html demonstrates basic deployment of
// the applet.
// ================================================================ COMPILATION
// For purposes of browser compatibility, JDK 1.3 (from Sun) is recommended.
// javac ConceptWebClient.java
// ==================================================================== LICENSE
//
// This software is eventually to be released under the General
// Public License, Version 2, June 1991. (It will be released
// when there is a "Gold Master" version ready.)
//
// Until then, if you would like to use this software, you should
// contact Dr. Douglas Luckie, luckie@msu.edu.
//
// Development of this software was funded by the National Science Foundation.
//
// Copyright 2001-2007 Michigan State University Board of Trustees
// ================================================================ DESCRIPTION
// This code allows students in a classroom setting to generate concept maps.
// Instructors are given significant flexibility for the modification of
// concept map assignments and exercises that are delivered through this
// software. Instructors can choose to enable or disable certain features
// of this applet, which is key for having this tool run in standalone mode
// versus integration with a courseware management system (like moodle).
// Instructors can also choose to define the concept
// map that students first begin to work with. For instance, an instructor
// might want the students to all start with three major concepts already
// present on a concept map.
//
// This is a "web client"; it is a java applet that is meant to run on a wide
// variety of browsers.
//
// Concept maps are made of "concept words", "linking words", and "links".
// For C-TOOLS, the term "words" is inclusive of both "concept words" and
// "linking words". Also, the term "concept word" is meant to be identical
// to the notion of a "concept phrase". Thus, "Pizza Hut" is considered
// to be a concept word (for the variable names inside this source code).
// ============================================================ DEVELOPER NOTES
// Also, for reasons of browser and compiler compatibility (JDK1.3)
// the goal with this code has been to keep the objects, processing,
// interface layout, and event handling simple so as to ensure robustness
// across diverse operating systems and browsers (e.g., a set
// of remotely connecting students). Additional considerations
// include promoting a common look and feel (something which differing AWT or
// Swing implementations can interfere with). Also, I want things to be
// kept "mobile" in the sense that the software can be modestly extended
// and enhanced in most any direction for special needs (without assuming
// in advance what those special user needs might be). The overall goal of
// this technology is not "a huge extensible basket of concept mapping
// features", but rather "a common browser-compatible billboard" for getting
// started with concept mapping in a classroom setting that can be configured
// to work in many different institutional scenarios. So, for the brave few
// who look at this code, prior to contorting its simplicity, please
// take time to consider that there may be reasons (and benefits) as
// to why the softwawre is structured the way it is.
//
// That said, the "VIEW" menu is being currently prototyped, and this
// is distorting the class structure a bit (BubbleMenuHelp, SubOption, etc).
//
// Also, Safari with JDK 1.4.1 is quite buggy and does not always read in the
// parameters correctly (i.e., getParameter). Therefore, after a getParameter
// is called, I need to check if it is null, and if so, do additional logic
// such as assigning a default value or sending a retry (rtry) request
// to the server.
// =========================================================== ACKNOWLEDGEMENTS
// The applet code emerged at Michigan State University (MSU) supported in
// large part by an NSF funded grant project. I would like to thank the
// following for helpful comments and contributions to help guide the
// ultimate outcome of this applet:
// Douglas Luckie, Diane Ebert-May, Janet Batzli, Duncan Sibley, Rett Weber,
// Joshua Wallace, Crystal Tobin, students of MSU's Lyman Briggs School as
// well as the variety of java applet coding tutorials and examples that
// other software developers have made publicly available over the internet.
// =============================================================== JAVA CLASSES
// ConceptWebClient
// |
// | +------- ConceptWebClient.class : main class for the web client
// | +------- MoveableWord.class : implement the "magnetic rectangle"
// | concept which can be dragged around
// | +------- Link.class : ordered pair structure by which one
// | concept is attached to another concept
// | +------- MenuButton.class : a menu button that can be clicked on;
// | menu buttons appear on the left side of
// | the applet
// | +------- BubbleMenuHelp.class : shows list of actions (SubOptions)
// | whenever a menu button is pressed;
// | brief help text is displayed for
// | each SubOption
// | +------- SubOption.class : a choice that is available after a
// | menu button is pressed; usually
// | there are multiple SubOptions associated
// | with each menu button
// | +------- Message.class : brief help messages which are displayed;
// | especially in concert with SubOptions
// | which are selected
// | +------- StatusMessage.class : status of concept map; SAVED, NOT
// | SAVED, or AUTOSAVED
// | +------- TargetArea.class : a set of coordinates
// | defining a target area (used to
// | interactively respond to events
// | on the user interface)
// | +------- ServerTalker.class : support capability to talk to server
// ========================================================= NECESSARY PACKAGES
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import java.util.Enumeration;
import java.net.*;
import java.io.*;
/**
* The GeneralThread class is the main background process for the applet.
* It was developed to support autosaving off of the applet.
* Its usage is presently disabled however since a variety of browsers and
* applet runtime environments seem to crash or be unstable with autonomous
* processes.
*/
class GeneralThread extends Thread
{
AppletContext ac;
URL url;
String mapname;
String expiration_key;
String sid;
MoveableWord words[];
Link links[];
int number_words;
int number_links;
String disable_string;
String gallery;
ServerTalker server_talker;
Graphics g;
String teststring;
/**
* Constructor. Set the parameters for running the background autosaving
* thread.
* (Parameters not yet listed.)
*/
GeneralThread(URL u, AppletContext a,
MoveableWord[] w, Link[] l,
int num_w, int num_l,
ServerTalker st, Graphics graphics,
String ekey)
{
url = u;
ac = a;
words = w;
links = l;
number_words = num_w;
number_links = num_l;
server_talker = st;
g = graphics;
expiration_key = ekey;
}
// END GeneralThread constructor
/**
* Run the thread. (Turns on every 20 seconds.)
*/
public void run()
{
while (true)
{
try {sleep(20000);} catch (Exception e) {}
// System.out.println("TESTSTR: "+teststring);
String data = new String();
String winfo = new String();
data += "command=AUTOSAVE&";
for (int j = 0; j < number_links; j++)
{
data += "c"+j+"="+
links[j].getIndex1()+"+"+
links[j].getIndex2()+"&";
}
for (int i = number_words - 1; i >= 0; i--)
{
if (words[i].word_type.equals("LINKINGWORD"))
{
winfo = words[i].info(g)+"+n";
}
else
{
winfo = words[i].info(g) + "+w";
}
data += "w" + i + "=" + winfo + "&";
}
if (disable_string != null)
{
data += "DISABLE="+disable_string;
}
if (disable_string != null && gallery != null)
{
data += "&gallery="+gallery;
}
// Authentication data for the CGI/Servlet.
data += "&mapname="+mapname;
data += "&expiration_key="+expiration_key;
data += "&sid="+sid; // Cannot trust cookie data to
// be available from applet.
// CGI/Servlet uniform resource locator
// is the url variable already manifest for this
// thread.
server_talker.put(url,data);
// The "official" url connection object.
// If the user tries to save an applet outside
// of user authentication, the page needs to
// be reloaded (and the CGI servlet layer
// subsequently takes the user through a
// login or registration process prior to
// the save procedure).
if (expiration_key.equals("NA"))
{
// ac.showDocument(url);
}
}
}
}
// END GeneralThread
/**
* The ConceptWebClient class is the main class for the web client.
* It presents a concept map drawing tool similar in functionality
* to Dia, Visio (tm) or other schematic tools. The feature set
* implemented by this class is not as exhaustive as standard schematic
* tools; rather, it is limited to those features necessary to draw
* a concept map generally involving ten words or less. This reduces
* the size of the applet so as to be realistic in terms of network
* bandwidth as well as simplifying users' ability to understand
* and work with the applet interface.
*