Package jfix.zk

Source Code of jfix.zk.WebBrowser

/*
    Copyright (C) 2011 maik.jablonski@gmail.com

    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 3 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, see <http://www.gnu.org/licenses/>.
*/
package jfix.zk;

import jfix.zk.ActionListener;
import jfix.zk.Iframe;
import jfix.zk.Images;
import jfix.zk.Linkbutton;
import jfix.zk.Sessions;
import jfix.zk.Window;

import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.SizeEvent;
import org.zkoss.zul.Caption;

public class WebBrowser extends Window {

  private static final String VIEW_WIDTH = WebBrowser.class.getName()
      + ".Width";
  private static final String VIEW_HEIGHT = WebBrowser.class.getName()
      + ".Height";
  private static String DEFAULT_SIZE = "95%";

  public WebBrowser(String url) {
    setTitle(url);
    setPosition("center");
    setSizable(true);
    doHighlighted();
    addEventListener(Events.ON_SIZE, new ActionListener() {
      public void actionPerformed(Event event) {
        resize(((SizeEvent) event).getWidth(),
            ((SizeEvent) event).getHeight());
      }
    });

    Linkbutton fullscreen = new Linkbutton(null, Images.ViewFullscreen);
    fullscreen.setHref(url);
    fullscreen.setTarget("_blank");

    Caption caption = new Caption();
    caption.appendChild(fullscreen);
    caption.appendChild(newResizeButton("800x600", "800px", "600px"));
    caption.appendChild(newResizeButton("1024x768", "1024px", "768px"));
    caption.appendChild(newResizeButton("1280x1024", "1280px", "1024px"));
    appendChild(caption);

    appendChild(new Iframe(url
        + ((url.contains("?") ? "&" : "?") + System.currentTimeMillis())));

    resize(Sessions.get(VIEW_WIDTH, DEFAULT_SIZE),
        Sessions.get(VIEW_HEIGHT, DEFAULT_SIZE));
  }

  private void resize(String width, String height) {
    Sessions.set(VIEW_WIDTH, width);
    Sessions.set(VIEW_HEIGHT, height);
    setWidth(width);
    setHeight(height);
  }

  private Linkbutton newResizeButton(final String label, final String width,
      final String height) {
    return new Linkbutton(label, new ActionListener() {
      public void actionPerformed(Event event) {
        resize(width, height);
      }
    });
  }
}
TOP

Related Classes of jfix.zk.WebBrowser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.