Mercurial > hg > digilib-old
changeset 340:fe6bd1ff2376 gen2_1
new directory and cache work
author | robcast |
---|---|
date | Wed, 17 Nov 2004 18:20:31 +0100 |
parents | 6d2032b6121d |
children | 37965a0014ef |
files | client/digitallibrary/digimage.jsp client/digitallibrary/dllib.js |
diffstat | 2 files changed, 586 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/digitallibrary/digimage.jsp Wed Nov 17 18:20:31 2004 +0100 @@ -0,0 +1,84 @@ +<%@ page language="java" %><%! +// -- JSP init ------------- + +// create DocumentBean instance for all JSP requests +digilib.servlet.DocumentBean docBean = new digilib.servlet.DocumentBean(); + +// initialize DocumentBean instance in JSP init +public void jspInit() { + try { + // set servlet init-parameter + docBean.setConfig(getServletConfig()); + } catch (javax.servlet.ServletException e) { + System.out.println(e); + } +} +// -- end of JSP init ------------- +%><% +// -- JSP request ------------- + +// parsing the query +// ----------------- +digilib.servlet.DigilibRequest dlRequest = new digilib.servlet.DigilibRequest(request); +docBean.setRequest(dlRequest); +// check if authentication is needed and redirect if necessary +docBean.doAuthentication(response); +// add number of pages +dlRequest.setValue("pt", docBean.getNumPages()); +// store objects for jsp:include +pageContext.setAttribute("docBean", docBean, pageContext.REQUEST_SCOPE); +%><html> +<head> + <title>Digital Document Library</title> + <script type="text/javascript" src="baselib.js"></script> + <script type="text/javascript" src="dllib.js"></script> +<script type="text/javascript"> + base_init(); + var dlTarget = window.name; + var baseUrl = '<%= dlRequest.getAsString("base.url") %>'; + var toolbarEnabledURL = window.location.href; + newParameter('fn', '', 1); + newParameter('pn', '1', 1); + newParameter('ws', '1.0', 1); + newParameter('mo', '', 1); + newParameter('mk', '', 3); + newParameter('wx', '0.0', 2); + newParameter('wy', '0.0', 2); + newParameter('ww', '1.0', 2); + newParameter('wh', '1.0', 2); + newParameter('pt', '<%= dlRequest.getAsString("pt") %>', 1); + newParameter('brgt', '0.0', 1); + newParameter('cont', '0.0', 1); + newParameter('rot', '0.0', 1); + newParameter('rgba', '', 1); + newParameter('rgbm', '', 1); + newParameter('ddpix', '', 9); + newParameter('ddpiy', '', 9); + document.id='digilib'; + dl_param_init(); +</script> +</head> +<body bgcolor="#666666" onload="dl_init();"> +<% if (dlRequest.hasOption("clop", "noarrows")) { +%><jsp:include page="digimage_img_inc.jsp" /><% +} else { +%><jsp:include page="digimage_tbl_inc.jsp" /><% +} +%> + + <div id="dot0" style="position:absolute; left:-20; top:100; visibility:hidden"><img src="img/mark1.gif" border="0"></div> + <div id="dot1" style="position:absolute; left:-20; top:100; visibility:hidden"><img src="img/mark2.gif" border="0"></div> + <div id="dot2" style="position:absolute; left:-20; top:100; visibility:hidden"><img src="img/mark3.gif" border="0"></div> + <div id="dot3" style="position:absolute; left:-20; top:100; visibility:hidden"><img src="img/mark4.gif" border="0"></div> + <div id="dot4" style="position:absolute; left:-20; top:100; visibility:hidden"><img src="img/mark5.gif" border="0"></div> + <div id="dot5" style="position:absolute; left:-20; top:100; visibility:hidden"><img src="img/mark6.gif" border="0"></div> + <div id="dot6" style="position:absolute; left:-20; top:100; visibility:hidden"><img src="img/mark7.gif" border="0"></div> + <div id="dot7" style="position:absolute; left:-20; top:100; visibility:hidden"><img src="img/mark8.gif" border="0"></div> + <div id="eck1" style="position:absolute; left:-20; top:100; visibility:hidden"><img src="img/olinks.gif" border="0"></div> + <div id="eck2" style="position:absolute; left:-20; top:100; visibility:hidden"><img src="img/orechts.gif" border="0"></div> + <div id="eck3" style="position:absolute; left:-20; top:100; visibility:hidden"><img src="img/ulinks.gif" border="0"></div> + <div id="eck4" style="position:absolute; left:-20; top:100; visibility:hidden"><img src="img/urechts.gif" border="0"></div> + +</body> + +</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/digitallibrary/dllib.js Wed Nov 17 18:20:31 2004 +0100 @@ -0,0 +1,502 @@ +/* Copyright (C) 2003,2004 IT-Group MPIWG, WTWG Uni Bern and others + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +Authors: + Christian Luginbuehl, 01.05.2003 (first version) + DW 24.03.2004 (Changed for digiLib in Zope) + Robert Casties, 2.11.2004 + + ! Requires baselib.js ! + +*/ + + +function identify() { + // used for identifying a digilib instance + // Relato uses that function - lugi + return "Digilib 0.6"; +} + + +/* + * more parameter handling + */ + +function parseArea() { + // returns area Rectangle from current parameters + return new Rectangle(getParameter("wx"), getParameter("wy"), getParameter("ww"), getParameter("wh")); +} + +function setParamFromArea(rect) { + // sets digilib wx etc. from rect + setParameter("wx", cropFloat(rect.x)); + setParameter("wy", cropFloat(rect.y)); + setParameter("ww", cropFloat(rect.width)); + setParameter("wh", cropFloat(rect.height)); + return true; +} + +function parseTrafo(elem) { + // returns Transform from current dlArea and picsize + var picsize = getElementRect(elem); + var trafo = new Transform(); + // subtract area offset and size + trafo.concat(getTranslation(new Position(-dlArea.x, -dlArea.y))); + trafo.concat(getScale(new Size(1/dlArea.width, 1/dlArea.height))); + // scale to screen size + trafo.concat(getScale(picsize)); + trafo.concat(getTranslation(picsize)); + // rotate + //trafo.concat(getRotation(- getParameter("rot"), new Position(0.5*picsize.width, 0.5*picsize.height))); + // mirror + //if (hasFlag("hmir")) { + //trafo.m00 = - trafo.m00; + //} + //if (hasFlag("vmir")) { + //trafo.m11 = - trafo.m11; + //} + return trafo; +} + + +function parseMarks() { + // returns marks array from current parameters + var marks = new Array(); + var ma; + var mk = getParameter("mk"); + if (mk.indexOf(";") >= 0) { + // old format with ";" + ma = mk.split(";"); + } else { + ma = mk.split(","); + } + for (var i = 0; i < ma.length ; i++) { + var pos = ma[i].split("/"); + if (pos.length > 1) { + marks.push(new Position(pos[0], pos[1])); + } + } + return marks; +} + +function getAllMarks() { + // returns a string with all marks in query format + var marks = new Array(); + for (var i = 0; i < dlMarks.length; i++) { + marks.push(cropFloat(dlMarks[i].x) + "/" + cropFloat(dlMarks[i].y)); + } + return marks.join(","); +} + +function addMark(pos) { + // add a mark + dlMarks.push(pos); + setParameter("mk", getAllMarks()); + return true; +} + +function deleteMark() { + // delete the last mark + dlMarks.pop(); + setParameter("mk", getAllMarks()); + return true; +} + +function hasFlag(mode) { + // returns if mode flag is set + return (dlFlags[mode]); +} + +function addFlag(mode) { + // add a mode flag + dlFlags[mode] = mode; + setParameter("mo", getAllFlags()); + return true; +} + +function removeFlag(mode) { + // remove a mode flag + if (dlFlags[mode]) { + delete dlFlags[mode]; + } + setParameter("mo", getAllFlags()); + return true; +} + +function toggleFlag(mode) { + // change a mode flag + if (dlFlags[mode]) { + delete dlFlags[mode]; + } else { + dlFlags[mode] = mode; + } + setParameter("mo", getAllFlags()); + return true; +} + +function getAllFlags() { + // returns a string with all flags in query format + var fa = new Array(); + for (var f in dlFlags) { + if ((f != "")&&(dlFlags[f] != null)) { + fa.push(f); + } + } + return fa.join(","); +} + +function parseFlags() { + // sets dlFlags from the current parameters + var flags = new Object(); + var fa = getParameter("mo").split(","); + for (var i = 0; i < fa.length ; i++) { + var f = fa[i]; + if (f != "") { + flags[f] = f; + } + } + return flags; +} + + +function bestPicSize(elem, inset) { + // returns a Size with the best image size for the given element + if (! defined(inset)) { + inset = 25; + } + var ws = getWinSize(); + var es = getElementPosition(elem); + if (es) { + ws.width = ws.width - es.x - inset; + ws.height = ws.height - es.y - inset; + } + return ws; +} + + +/* ********************************************** + * digilib specific routines + * ******************************************** */ + + +function dl_param_init() { + // parameter initialisation before onload + if (!baseScriptVersion) { + base_init(); + } + dlScriptVersion = "1.1b"; + dlArea = new Rectangle(0.0, 0.0, 1.0, 1.0); + dlMaxArea = new Rectangle(0.0, 0.0, 1.0, 1.0); + dlTrafo = new Transform(); + dlMarks = new Array(); + dlFlags = new Object(); + elemScaler = null; + picElem = null; + ZOOMFACTOR = Math.sqrt(2); + + // put the query parameters (sans "?") in the parameters array + parseParameters(location.search.slice(1)); + // treat special parameters + dlMarks = parseMarks(); + dlArea = parseArea(); + dlFlags = parseFlags(); +} + + +function dl_init() { + // initalisation on load + if (!dlScriptVersion) { + dl_param_init(); + } + elemScaler = getElement("scaler", true); + picElem = getElement("pic", true); + if (picElem == null && elemScaler) { + // in N4 pic is in the scaler layer + picElem = elemScaler.document.images[0]; + } + if ((!elemScaler)||(!picElem)) { + alert("Sorry, digilib doesn't work here!"); + return false; + } + // give a name to the window containing digilib + if (defined(dlTarget)&&(dlTarget)) { + window.name = dlTarget; + } else { + window.name = "digilib"; + } + // put the query parameters (sans "?") in the parameters array + parseParameters(location.search.slice(1)); + // treat special parameters + dlMarks = parseMarks(); + dlArea = parseArea(); + dlFlags = parseFlags(); + // wait for image to load and display marks + renderMarks(); + // done + focus(); + return; +} + + +function display(detail) { + // redisplay the page + if (! detail) { + detail = 9; + } + var queryString = getAllParameters(detail); + location.href = location.protocol + "//" + location.host + location.pathname + "?" + queryString; +} + + +/* ********************************************** + * interactive digilib functions + * ******************************************** */ + + +function renderMarks() { + // put the visible marks on the image + var mark_count = dlMarks.length; + // make shure the image is loaded so we know its size + if (defined(picElem.complete) && picElem.complete == false && ! browserType.isN4 ) { + setTimeout("renderMarks()", 100); + } else { + dlTrafo = parseTrafo(picElem); + for (var i = 0; i < 8; i++) { + var me = getElement("dot"+i); + if (i < mark_count) { + if (dlArea.containsPosition(dlMarks[i])) { + var mpos = dlTrafo.transform(dlMarks[i]); + // suboptimal to place -5 pixels and not half size of mark-image + mpos.x = mpos.x -5; + mpos.y = mpos.y -5; + moveElement(me, mpos); + showElement(me, true); + } + } else { + // hide the other marks + showElement(me, false); + } + } + } +} + + +function setMark(reload) { + // add a mark where clicked + if ( dlMarks.length > 7 ) { + alert("Only 8 marks are possible at the moment!"); + return; + } + window.focus(); + + function markEvent(evt) { + // event handler adding a new mark + unregisterEvent("mousedown", elemScaler, markEvent); + var p = dlTrafo.invtransform(evtPosition(evt)); + addMark(p); + if (defined(reload)&&(!reload)) { + // don't redisplay + renderMarks(); + return; + } + display(); + } + + // starting event capture + registerEvent("mousedown", elemScaler, markEvent); +} + + +function removeMark(reload) { + // remove the last mark + deleteMark(); + if (defined(reload)&&(!reload)) { + // don't redisplay + renderMarks(); + return; + } + display(); +} + + +function zoomArea() { + var click = 1; + var pt1, pt2; + var eck1pos, eck2pos, eck3pos, eck4pos; + window.focus(); + var eck1 = getElement("eck1"); + var eck2 = getElement("eck2"); + var eck3 = getElement("eck3"); + var eck4 = getElement("eck4"); + + function zoomClick(evt) { + // mouse click handler + if (click == 1) { + // first click -- start moving + click = 2; + pt1 = evtPosition(evt); + pt2 = pt1; + eck1pos = pt1; + eck2pos = new Position(pt1.x - 12, pt1.y); + eck3pos = new Position(pt1.x, pt1.y - 12); + eck4pos = new Position(pt1.y - 12, pt1.y - 12); + moveElement(eck1, eck1pos); + moveElement(eck2, eck2pos); + moveElement(eck3, eck3pos); + moveElement(eck4, eck4pos); + showElement(eck1, true); + showElement(eck2, true); + showElement(eck3, true); + showElement(eck4, true); + // show moving + registerEvent("mousemove", elemScaler, zoomMove); + registerEvent("mousemove", eck4, zoomMove); + // enable drag-to-zoom + registerEvent("mouseup", elemScaler, zoomClick); + registerEvent("mouseup", eck4, zoomClick); + } else { + // second click -- end moving + pt2 = evtPosition(evt); + showElement(eck1, false); + showElement(eck2, false); + showElement(eck3, false); + showElement(eck4, false); + unregisterEvent("mousemove", elemScaler, zoomMove); + unregisterEvent("mousemove", eck4, zoomMove); + unregisterEvent("mousedown", elemScaler, zoomClick); + unregisterEvent("mousedown", eck4, zoomClick); + var p1 = dlTrafo.invtransform(pt1); + var p2 = dlTrafo.invtransform(pt2); + var ww = p2.x-p1.x; + var wh = p2.y-p1.y; + if ((ww > 0)&&(wh > 0)) { + setParameter("wx", cropFloat(p1.x)); + setParameter("wy", cropFloat(p1.y)); + setParameter("ww", cropFloat(ww)); + setParameter("wh", cropFloat(wh)); + parseArea(); + // zoomed is always fit + setParameter("ws", 1); + display(); + } + } + } + + function zoomMove(evt) { + // mouse move handler + pt2 = evtPosition(evt); + // restrict marks to move right and down + eck1pos = pt1; + eck2pos = new Position(Math.max(pt1.x, pt2.x)-12, pt1.y); + eck3pos = new Position(pt1.x, Math.max(pt1.y, pt2.y)-12); + eck4pos = new Position(Math.max(pt1.x, pt2.x)-12, Math.max(pt1.y, pt2.y)-12); + moveElement(eck1, eck1pos); + moveElement(eck2, eck2pos); + moveElement(eck3, eck3pos); + moveElement(eck4, eck4pos); + } + + // starting event capture + registerEvent("mousedown", elemScaler, zoomClick); + registerEvent("mousedown", eck4, zoomClick); +} + +function zoomBy(factor) { + // zooms by the given factor + var newarea = dlArea.copy(); + newarea.width /= factor; + newarea.height /= factor; + newarea.x -= 0.5 * (newarea.width - dlArea.width); + newarea.y -= 0.5 * (newarea.height - dlArea.height); + newarea = dlMaxArea.fit(newarea); + setParamFromArea(newarea); + display(); +} + + +function zoomFullpage() { + // zooms out to show the whole image + setParameter("wx", 0.0); + setParameter("wy", 0.0); + setParameter("ww", 1.0); + setParameter("wh", 1.0); + display(); +} + + +function moveCenter() { + // move visible area so that it's centered around the clicked point + if ( (dlArea.width == 1.0) && (dlArea.height == 1.0) ) { + // noting to do + return; + } + window.focus(); + + function moveCenterEvent(evt) { + // move to handler + unregisterEvent("mousedown", elemScaler, moveCenterEvent); + var pt = dlTrafo.invtransform(evtPosition(evt)); + var newarea = new Rectangle(pt.x-0.5*dlArea.width, pt.y-0.5*dlArea.height, dlArea.width, dlArea.height); + newarea = dlMaxArea.fit(newarea); + // set parameters + setParamFromArea(newarea); + parseArea(); + display(); + } + + // starting event capture + registerEvent("mousedown", elemScaler, moveCenterEvent); +} + +function moveBy(movx, movy) { + // move visible area by movx and movy (in units of dw, dh) + if ((dlArea.width == 1.0)&&(dlArea.height == 1.0)) { + // nothing to do + return; + } + var newarea = dlArea.copy(); + newarea.x += parseFloat(movx)*dlArea.width; + newarea.y += parseFloat(movy)*dlArea.height; + newarea = dlMaxArea.fit(newarea); + // set parameters + setParamFromArea(newarea); + parseArea(); + display(); +} + + + + +function getRef() { + // returns a reference to the current digilib set + if (! baseUrl) { + var baseUrl = location.protocol + "//" + location.host + location.pathname; + } + var hyperlinkRef = baseUrl; + var par = getAllParameters(9); + if (par.length > 0) { + hyperlinkRef += "?" + par; + } + return hyperlinkRef; +} + +function getRefWin(type, msg) { + // shows an alert with a reference to the current digilib set + if (! msg) { + msg = "Link for HTML documents"; + } + prompt(msg, getRef()); +}