001: /**
002: * Copyright 2006 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.http.filter;
016:
017: import java.util.LinkedList;
018: import org.apache.commons.logging.Log;
019: import org.apache.commons.logging.LogFactory;
020: import org.araneaframework.Environment;
021: import org.araneaframework.InputData;
022: import org.araneaframework.core.StandardEnvironment;
023: import org.araneaframework.framework.core.BaseFilterWidget;
024: import org.araneaframework.http.WindowScrollPositionContext;
025:
026: /**
027: * @author Taimo Peelo (taimo@webmedia.ee)
028: */
029: public class StandardWindowScrollPositionFilterWidget extends
030: BaseFilterWidget implements WindowScrollPositionContext {
031: private static final Log log = LogFactory
032: .getLog(StandardWindowScrollPositionFilterWidget.class);
033:
034: private static final long serialVersionUID = 1L;
035: protected LinkedList savedCoordinates = new LinkedList();
036: protected String windowScrollX;
037: protected String windowScrollY;
038:
039: /* ************************************************************************
040: * WindowScrollPositionContext interface methods.
041: * ************************************************************************/
042: public void reset() {
043: resetCurrent();
044: savedCoordinates.clear();
045: log.debug("RESETTED all coords ");
046: }
047:
048: public void pop() {
049: if (!savedCoordinates.isEmpty()) {
050: String[] coords = (String[]) savedCoordinates.removeFirst();
051: windowScrollX = coords[0];
052: windowScrollY = coords[1];
053:
054: log.debug("popped to coords " + windowScrollX + " "
055: + windowScrollY);
056: }
057: }
058:
059: public void push() {
060: savedCoordinates.addFirst(new String[] { windowScrollX,
061: windowScrollY });
062: log.debug("pushed coords " + windowScrollX + " "
063: + windowScrollY);
064: resetCurrent();
065: }
066:
067: public void resetCurrent() {
068: windowScrollX = windowScrollY = null;
069: }
070:
071: public String getX() {
072: return windowScrollX;
073: }
074:
075: public String getY() {
076: return windowScrollY;
077: }
078:
079: public void scrollTo(String x, String y) {
080: windowScrollX = x;
081: windowScrollY = y;
082: log.debug("scrolled to " + x + " " + y);
083: }
084:
085: /* *********************************************************************** */
086: protected Environment getChildWidgetEnvironment() {
087: return new StandardEnvironment(super
088: .getChildWidgetEnvironment(),
089: WindowScrollPositionContext.class, this );
090: }
091:
092: protected void update(InputData input) throws Exception {
093: windowScrollX = (String) input.getGlobalData().get(
094: WINDOW_SCROLL_X_KEY);
095: windowScrollY = (String) input.getGlobalData().get(
096: WINDOW_SCROLL_Y_KEY);
097:
098: log.debug("REQUEST COORDS READ TO BE to " + windowScrollX
099: + " " + windowScrollY);
100:
101: super.update(input);
102: }
103: }
|