001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI for
003: * visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or modify it under
008: * the terms of the GNU General Public License as published by the Free Software
009: * Foundation; either version 2 of the License, or (at your option) any later
010: * version.
011: *
012: * This program is distributed in the hope that it will be useful, but WITHOUT
013: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
014: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
015: * details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
019: * Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032:
033: package com.vividsolutions.jump.workbench.ui.renderer;
034:
035: import java.awt.AlphaComposite;
036: import java.awt.Graphics2D;
037: import java.awt.Image;
038:
039: import com.vividsolutions.jts.util.Assert;
040: import com.vividsolutions.jump.workbench.model.WMSLayer;
041: import com.vividsolutions.jump.workbench.ui.LayerViewPanel;
042:
043: public class WMSLayerRenderer extends ImageCachingRenderer {
044: public WMSLayerRenderer(WMSLayer layer, LayerViewPanel panel) {
045: super (layer, panel);
046: }
047:
048: public ThreadSafeImage getImage() {
049: if (!getLayer().isVisible()) {
050: return null;
051: }
052:
053: return super .getImage();
054: }
055:
056: public Runnable createRunnable() {
057: if (!LayerRenderer.render(getLayer(), panel)) {
058: return null;
059: }
060: return super .createRunnable();
061: }
062:
063: public void copyTo(Graphics2D graphics) {
064: if (!LayerRenderer.render(getLayer(), panel)) {
065: return;
066: }
067: super .copyTo(graphics);
068: }
069:
070: private WMSLayer getLayer() {
071: return (WMSLayer) getContentID();
072: }
073:
074: protected void renderHook(ThreadSafeImage image) throws Exception {
075: if (!getLayer().isVisible()) {
076: return;
077: }
078:
079: //Create the image outside the synchronized call to #draw, because it
080: // takes
081: //a few seconds, and we don't want to block repaints. [Jon Aquino]
082: final Image sourceImage = getLayer().createImage(panel);
083:
084: //Drawing can take a long time. If the renderer is cancelled during
085: // this
086: //time, don't draw when the request returns. [Jon Aquino]
087: if (cancelled) {
088: return;
089: }
090:
091: image.draw(new ThreadSafeImage.Drawer() {
092: public void draw(Graphics2D g) throws Exception {
093: //Not sure what the best rule is; SRC_OVER seems to work. [Jon
094: // Aquino]
095: g.setComposite(AlphaComposite.getInstance(
096: AlphaComposite.SRC_OVER,
097: getLayer().getAlpha() / 255f));
098: g.drawImage(sourceImage, 0, 0, null);
099: }
100: });
101: }
102: }
|