aboutsummaryrefslogtreecommitdiffstats
path: root/examples/plan/src/org/apache/fop
diff options
context:
space:
mode:
Diffstat (limited to 'examples/plan/src/org/apache/fop')
-rw-r--r--examples/plan/src/org/apache/fop/plan/ActionInfo.java80
-rw-r--r--examples/plan/src/org/apache/fop/plan/EventList.java39
-rw-r--r--examples/plan/src/org/apache/fop/plan/GroupInfo.java48
-rw-r--r--examples/plan/src/org/apache/fop/plan/Main.java95
-rw-r--r--examples/plan/src/org/apache/fop/plan/PlanDrawer.java33
-rw-r--r--examples/plan/src/org/apache/fop/plan/PlanElement.java101
-rw-r--r--examples/plan/src/org/apache/fop/plan/PlanElementMapping.java66
-rw-r--r--examples/plan/src/org/apache/fop/plan/PlanHints.java46
-rw-r--r--examples/plan/src/org/apache/fop/plan/PlanObj.java51
-rw-r--r--examples/plan/src/org/apache/fop/plan/PlanRenderer.java227
-rw-r--r--examples/plan/src/org/apache/fop/plan/PreloaderPlan.java135
-rw-r--r--examples/plan/src/org/apache/fop/plan/SimplePlanDrawer.java321
12 files changed, 0 insertions, 1242 deletions
diff --git a/examples/plan/src/org/apache/fop/plan/ActionInfo.java b/examples/plan/src/org/apache/fop/plan/ActionInfo.java
deleted file mode 100644
index 1535ed5ec..000000000
--- a/examples/plan/src/org/apache/fop/plan/ActionInfo.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.plan;
-
-import java.util.Date;
-
-public class ActionInfo {
-
- public static final int TASK = 1;
- public static final int MILESTONE = 2;
- public static final int GROUPING = 3;
-
- private Date startDate;
- private Date endDate;
- private String owner;
- private String label;
- private int type = TASK;
- private String dependant = "";
-
- public void setType(int t) {
- type = t;
- }
-
- public int getType() {
- return type;
- }
-
- public void setLabel(String str) {
- label = str;
- }
-
- public void setOwner(String str) {
- owner = str;
- }
-
- public void setStartDate(Date sd) {
- startDate = sd;
- if (endDate == null) {
- endDate = startDate;
- }
- }
-
- public void setEndDate(Date ed) {
- endDate = ed;
- }
-
- public String getLabel() {
- return label;
- }
-
- public String getOwner() {
- return owner;
- }
-
- public Date getStartDate() {
- return startDate;
- }
-
- public Date getEndDate() {
- return endDate;
- }
-
-}
diff --git a/examples/plan/src/org/apache/fop/plan/EventList.java b/examples/plan/src/org/apache/fop/plan/EventList.java
deleted file mode 100644
index 53b32f7c0..000000000
--- a/examples/plan/src/org/apache/fop/plan/EventList.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.plan;
-
-import java.util.List;
-
-public class EventList {
-
- private List data = new java.util.ArrayList();
-
- public void addGroupInfo(GroupInfo set) {
- data.add(set);
- }
-
- public int getSize() {
- return data.size();
- }
-
- public GroupInfo getGroupInfo(int count) {
- return (GroupInfo) data.get(count);
- }
-}
diff --git a/examples/plan/src/org/apache/fop/plan/GroupInfo.java b/examples/plan/src/org/apache/fop/plan/GroupInfo.java
deleted file mode 100644
index a83228197..000000000
--- a/examples/plan/src/org/apache/fop/plan/GroupInfo.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.plan;
-
-import java.util.List;
-
-public class GroupInfo {
-
- private String name;
- private List actions = new java.util.ArrayList();
-
- public GroupInfo(String n) {
- name = n;
- }
-
- public void addActionInfo(ActionInfo ai) {
- actions.add(ai);
- }
-
- public int getSize() {
- return actions.size();
- }
-
- public ActionInfo getActionInfo(int c) {
- return (ActionInfo) actions.get(c);
- }
-
- public String getName() {
- return name;
- }
-}
diff --git a/examples/plan/src/org/apache/fop/plan/Main.java b/examples/plan/src/org/apache/fop/plan/Main.java
deleted file mode 100644
index 7b6f5a05e..000000000
--- a/examples/plan/src/org/apache/fop/plan/Main.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.plan;
-
-import java.io.InputStream;
-import java.io.Writer;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import org.apache.batik.transcoder.svg2svg.SVGTranscoder;
-import org.apache.batik.transcoder.TranscoderInput;
-import org.apache.batik.transcoder.TranscoderOutput;
-
-/**
- * Sample command-line application for converting plan XML to SVG.
- */
-public class Main {
-
- /**
- * Main method.
- * @param args command-line arguments
- */
- public static void main(String[] args) {
- Main main = new Main();
- main.convert(args);
- System.exit(0);
- }
-
- /**
- * Runs the conversion
- * @param params command-line arguments
- */
- public void convert(String[] params) {
- if (params.length != 2) {
- System.out.println("arguments: plan.xml output.svg");
- return;
- }
- try {
- InputStream is = new java.io.FileInputStream(params[0]);
- Document doc = createSVGDocument(is);
- SVGTranscoder svgT = new SVGTranscoder();
- TranscoderInput input = new TranscoderInput(doc);
- Writer ostream = new java.io.FileWriter(params[1]);
- TranscoderOutput output = new TranscoderOutput(ostream);
- svgT.transcode(input, output);
- ostream.flush();
- ostream.close();
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- /**
- * Helper method to create the SVG document from the plan InputStream.
- * @param is InputStream
- * @return Document a DOM containing the SVG
- */
- public Document createSVGDocument(InputStream is) {
- Document doc = null;
-
- Element root = null;
- try {
- doc = javax.xml.parsers.DocumentBuilderFactory.newInstance().
- newDocumentBuilder().parse(is);
-
- root = doc.getDocumentElement();
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- PlanRenderer gr = new PlanRenderer();
- gr.setFontInfo("sansserif", 12);
- Document svgdoc = gr.createSVGDocument(doc);
- return svgdoc;
- }
-}
diff --git a/examples/plan/src/org/apache/fop/plan/PlanDrawer.java b/examples/plan/src/org/apache/fop/plan/PlanDrawer.java
deleted file mode 100644
index 7f79bb737..000000000
--- a/examples/plan/src/org/apache/fop/plan/PlanDrawer.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.plan;
-
-import java.util.HashMap;
-
-import org.w3c.dom.Document;
-
-/**
- * This interface defines how a plan drawer is converted.
- */
-public interface PlanDrawer {
-
- Document createDocument(EventList data, float w, float h,
- HashMap hints);
-}
diff --git a/examples/plan/src/org/apache/fop/plan/PlanElement.java b/examples/plan/src/org/apache/fop/plan/PlanElement.java
deleted file mode 100644
index e7fb8a1e7..000000000
--- a/examples/plan/src/org/apache/fop/plan/PlanElement.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.plan;
-
-import java.awt.geom.Point2D;
-
-import org.w3c.dom.Document;
-
-import org.xml.sax.Attributes;
-import org.xml.sax.Locator;
-
-import org.apache.fop.apps.FOPException;
-import org.apache.fop.fo.FONode;
-import org.apache.fop.fo.PropertyList;
-
-/**
- * This class defines the plan element.
- */
-public class PlanElement extends PlanObj {
-
- private Document svgDoc = null;
- private float width;
- private float height;
- private boolean converted;
-
- /**
- * @see org.apache.fop.fo.FONode#FONode(FONode)
- */
- public PlanElement(FONode parent) {
- super(parent);
- }
-
- /** {@inheritDoc} */
- public void processNode(String elementName, Locator locator,
- Attributes attlist, PropertyList propertyList)
- throws FOPException {
- super.processNode(elementName, locator, attlist, propertyList);
- createBasicDocument();
- }
-
- /**
- * Converts the element to SVG.
- */
- public void convertToSVG() {
- try {
- if (!converted) {
- converted = true;
- PlanRenderer pr = new PlanRenderer();
- pr.setFontInfo("Helvetica", 12);
- svgDoc = pr.createSVGDocument(doc);
- width = pr.getWidth();
- height = pr.getHeight();
-
- doc = svgDoc;
- }
- } catch (Throwable t) {
- getLogger().error("Could not convert Plan to SVG", t);
- width = 0;
- height = 0;
- }
-
- }
-
- /** {@inheritDoc} */
- public Document getDOMDocument() {
- convertToSVG();
- return doc;
- }
-
- /** {@inheritDoc} */
- public String getNamespaceURI() {
- if (svgDoc == null) {
- return PlanElementMapping.NAMESPACE;
- }
- return "http://www.w3.org/2000/svg";
- }
-
- /** {@inheritDoc} */
- public Point2D getDimension(Point2D view) {
- convertToSVG();
- return new Point2D.Float(width, height);
- }
-}
-
diff --git a/examples/plan/src/org/apache/fop/plan/PlanElementMapping.java b/examples/plan/src/org/apache/fop/plan/PlanElementMapping.java
deleted file mode 100644
index 5b8a0b5bb..000000000
--- a/examples/plan/src/org/apache/fop/plan/PlanElementMapping.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.plan;
-
-import org.w3c.dom.DOMImplementation;
-
-import org.apache.fop.fo.ElementMapping;
-import org.apache.fop.fo.FONode;
-
-/**
- * This class provides the element mapping for FOP.
- */
-public class PlanElementMapping extends ElementMapping {
-
- /** Plan Namespace */
- public static final String NAMESPACE = "http://xmlgraphics.apache.org/fop/plan";
-
- /** Main constructor. */
- public PlanElementMapping() {
- this.namespaceURI = NAMESPACE;
- }
-
- /** {@inheritDoc} */
- public DOMImplementation getDOMImplementation() {
- return getDefaultDOMImplementation();
- }
-
- /** {@inheritDoc} */
- protected void initialize() {
- if (foObjs == null) {
- foObjs = new java.util.HashMap<String, Maker>();
- foObjs.put("plan", new PE());
- foObjs.put(DEFAULT, new PlanMaker());
- }
- }
-
- static class PlanMaker extends ElementMapping.Maker {
- public FONode make(FONode parent) {
- return new PlanObj(parent);
- }
- }
-
- static class PE extends ElementMapping.Maker {
- public FONode make(FONode parent) {
- return new PlanElement(parent);
- }
- }
-
-}
diff --git a/examples/plan/src/org/apache/fop/plan/PlanHints.java b/examples/plan/src/org/apache/fop/plan/PlanHints.java
deleted file mode 100644
index a50d91139..000000000
--- a/examples/plan/src/org/apache/fop/plan/PlanHints.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.plan;
-
-/**
- * This interface defines some constants for use in the plan package.
- */
-public interface PlanHints {
-
- /** Border attribute */
- String PLAN_BORDER = "border";
- /** Legend attribute */
- String PLAN_LEGEND = "legend";
- /** Font family attribute */
- String FONT_FAMILY = "font-family";
- /** Font size attribute */
- String FONT_SIZE = "font-size";
- /** Legent type attribute */
- String LEGEND_TYPE = "legendType";
- /** Locale attribute */
- String LOCALE = "locale";
- /** Label type attribute */
- String LABEL_TYPE = "labelType";
- /** Label font size attribute */
- String LABEL_FONT_SIZE = "labelFontSize";
- /** Label font attribute */
- String LABEL_FONT = "labelFont";
-
-}
diff --git a/examples/plan/src/org/apache/fop/plan/PlanObj.java b/examples/plan/src/org/apache/fop/plan/PlanObj.java
deleted file mode 100644
index ca26a8039..000000000
--- a/examples/plan/src/org/apache/fop/plan/PlanObj.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.plan;
-
-// FOP
-import org.apache.fop.fo.FONode;
-import org.apache.fop.fo.XMLObj;
-
-/**
- * Since SVG objects are not layed out then this class checks
- * that this element is not being layed out inside some incorrect
- * element.
- */
-public class PlanObj extends XMLObj {
-
- /**
- * Creates a new Plan object.
- * @param parent the parent formatting object
- */
- public PlanObj(FONode parent) {
- super(parent);
- }
-
- /** {@inheritDoc} */
- public String getNamespaceURI() {
- return PlanElementMapping.NAMESPACE;
- }
-
- /** {@inheritDoc} */
- public String getNormalNamespacePrefix() {
- return "plan";
- }
-}
-
diff --git a/examples/plan/src/org/apache/fop/plan/PlanRenderer.java b/examples/plan/src/org/apache/fop/plan/PlanRenderer.java
deleted file mode 100644
index 7d41962fb..000000000
--- a/examples/plan/src/org/apache/fop/plan/PlanRenderer.java
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.plan;
-
-
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.StringTokenizer;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import org.apache.batik.dom.svg.SVGDOMImplementation;
-
-public class PlanRenderer {
-
- private static final String SVG_NAMESPACE = SVGDOMImplementation.SVG_NAMESPACE_URI;
-
- private String fontFamily = "sansserif";
- private float fontSize = 12;
- private String type = "";
- private String lang = "";
- private String country = "";
- private String variant = "";
- private float width;
- private float height;
- private float topEdge;
- private float rightEdge;
- private HashMap hints = new HashMap();
-
- private String[] colours;
- private String[] darkcolours;
-
- public void setFontInfo(String fam, float si) {
- fontFamily = fam;
- fontSize = si;
- }
-
- public float getWidth() {
- return width;
- }
-
- public float getHeight() {
- return height;
- }
-
- protected float toFloat(String str) {
- return Float.parseFloat(str);
- }
-
- public Document createSVGDocument(Document planDoc) {
-
- Element svgRoot = planDoc.getDocumentElement();
-
- width = toFloat(svgRoot.getAttribute("width"));
- height = toFloat(svgRoot.getAttribute("height"));
- type = svgRoot.getAttribute("type");
- lang = svgRoot.getAttribute("lang");
- country = svgRoot.getAttribute("country");
- variant = svgRoot.getAttribute("variant");
- String style = svgRoot.getAttribute("style");
- parseStyle(style);
-
- Locale locale = new Locale(lang, country == null ? "" : country,
- variant == null ? "" : variant);
-
- String start = svgRoot.getAttribute("start");
- String end = svgRoot.getAttribute("end");
- Date sd = getDate(start, locale);
- Date ed = getDate(end, locale);
-
- String title = "";
- EventList data = null;
- NodeList childs = svgRoot.getChildNodes();
- for (int i = 0; i < childs.getLength(); i++) {
- Node obj = childs.item(i);
- String nname = obj.getNodeName();
- if (nname.equals("title")) {
- title = ((Element) obj).getFirstChild().getNodeValue();
- } else if (nname.equals("events")) {
- data = getEvents((Element) obj, locale);
- }
- }
-
- SimplePlanDrawer planDrawer = new SimplePlanDrawer();
- planDrawer.setStartDate(sd);
- planDrawer.setEndDate(ed);
- hints.put(PlanHints.FONT_FAMILY, fontFamily);
- hints.put(PlanHints.FONT_SIZE, new Float(fontSize));
- hints.put(PlanHints.LOCALE, locale);
- Document doc
- = planDrawer.createDocument(data, width, height, hints);
- return doc;
- }
-
- protected void parseStyle(String style) {
- hints.put(PlanHints.PLAN_BORDER, new Boolean(true));
- hints.put(PlanHints.FONT_FAMILY, fontFamily);
- hints.put(PlanHints.FONT_SIZE, new Float(fontSize));
- hints.put(PlanHints.LABEL_FONT_SIZE, new Float(fontSize));
- hints.put(PlanHints.LABEL_FONT, fontFamily);
- hints.put(PlanHints.LABEL_TYPE, "textOnly");
-
- StringTokenizer st = new StringTokenizer(style, ";");
- while (st.hasMoreTokens()) {
- String pair = st.nextToken().trim();
- int index = pair.indexOf(":");
- String name = pair.substring(0, index).trim();
- String val = pair.substring(index + 1).trim();
- if (name.equals(PlanHints.PLAN_BORDER)) {
- hints.put(name, Boolean.valueOf(val));
- } else if (name.equals(PlanHints.FONT_SIZE)) {
- hints.put(name, Float.valueOf(val));
- } else if (name.equals(PlanHints.LABEL_FONT_SIZE)) {
- hints.put(name, Float.valueOf(val));
- } else {
- hints.put(name, val);
- }
- }
- }
-
- public ActionInfo getActionInfo(Element ele, Locale locale) {
- String t = ele.getAttribute("type");
-
- NodeList childs = ele.getChildNodes();
- ActionInfo data = new ActionInfo();
- if (t.equals("milestone")) {
- data.setType(ActionInfo.MILESTONE);
- } else if (t.equals("task")) {
- data.setType(ActionInfo.TASK);
- } else if (t.equals("grouping")) {
- data.setType(ActionInfo.GROUPING);
- } else {
- throw new IllegalArgumentException("Unknown action type: " + t);
- }
-
- for (int i = 0; i < childs.getLength(); i++) {
- Node obj = childs.item(i);
- String nname = obj.getNodeName();
- if (nname.equals("label")) {
- String dat = ((Element) obj).getFirstChild().getNodeValue();
- data.setLabel(dat);
- } else if (nname.equals("owner")) {
- String dat = ((Element) obj).getFirstChild().getNodeValue();
- data.setOwner(dat);
- } else if (nname.equals("startdate")) {
- Date dat = getDate((Element) obj, locale);
- data.setStartDate(dat);
- } else if (nname.equals("enddate")) {
- Date dat = getDate((Element) obj, locale);
- data.setEndDate(dat);
- }
- }
- return data;
- }
-
- public EventList getEvents(Element ele, Locale locale) {
- EventList data = new EventList();
- NodeList childs = ele.getChildNodes();
- for (int i = 0; i < childs.getLength(); i++) {
- Node obj = childs.item(i);
- if (obj.getNodeName().equals("group")) {
- GroupInfo dat = getGroupInfo((Element) obj, locale);
- data.addGroupInfo(dat);
- }
- }
- return data;
- }
-
- public GroupInfo getGroupInfo(Element ele, Locale locale) {
- NodeList childs = ele.getChildNodes();
- GroupInfo data = new GroupInfo(ele.getAttribute("name"));
- for (int i = 0; i < childs.getLength(); i++) {
- Node obj = childs.item(i);
- if (obj.getNodeName().equals("action")) {
- ActionInfo dat = getActionInfo((Element) obj, locale);
- data.addActionInfo(dat);
- }
- }
- return data;
- }
-
- public Date getDate(Element ele, Locale locale) {
- String label = ele.getFirstChild().getNodeValue();
- return getDate(label, locale);
- }
-
- public Date getDate(String label, Locale locale) {
- Calendar cal = Calendar.getInstance(locale);
-
- String str;
- str = label.substring(0, 4);
- int intVal = Integer.valueOf(str).intValue();
- cal.set(Calendar.YEAR, intVal);
-
- str = label.substring(4, 6);
- intVal = Integer.valueOf(str).intValue();
- cal.set(Calendar.MONTH, intVal - 1);
-
- str = label.substring(6, 8);
- intVal = Integer.valueOf(str).intValue();
- cal.set(Calendar.DATE, intVal);
- return cal.getTime();
- }
-}
-
diff --git a/examples/plan/src/org/apache/fop/plan/PreloaderPlan.java b/examples/plan/src/org/apache/fop/plan/PreloaderPlan.java
deleted file mode 100644
index d88658c37..000000000
--- a/examples/plan/src/org/apache/fop/plan/PreloaderPlan.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.plan;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.xml.transform.ErrorListener;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMResult;
-import javax.xml.transform.stream.StreamSource;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.apache.xmlgraphics.image.loader.Image;
-import org.apache.xmlgraphics.image.loader.ImageContext;
-import org.apache.xmlgraphics.image.loader.ImageInfo;
-import org.apache.xmlgraphics.image.loader.ImageSize;
-import org.apache.xmlgraphics.image.loader.impl.AbstractImagePreloader;
-import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM;
-import org.apache.xmlgraphics.image.loader.util.ImageUtil;
-import org.apache.xmlgraphics.io.XmlSourceUtil;
-
-import org.apache.fop.util.DefaultErrorListener;
-import org.apache.fop.util.UnclosableInputStream;
-
-/**
- * Image preloader for Plan images.
- */
-public class PreloaderPlan extends AbstractImagePreloader {
-
- /** Logger instance */
- private static Log log = LogFactory.getLog(PreloaderPlan.class);
-
- /** {@inheritDoc} */
- public ImageInfo preloadImage(String uri, Source src, ImageContext context)
- throws IOException {
- if (!ImageUtil.hasInputStream(src)) {
- //TODO Remove this and support DOMSource and possibly SAXSource
- return null;
- }
- ImageInfo info = getImage(uri, src, context);
- if (info != null) {
- ImageUtil.closeQuietly(src); //Image is fully read
- }
- return info;
- }
-
- private ImageInfo getImage(String uri, Source src, ImageContext context) throws IOException {
-
- InputStream in = new UnclosableInputStream(ImageUtil.needInputStream(src));
- try {
- Document planDoc = getDocument(in);
- Element rootEl = planDoc.getDocumentElement();
- if (!PlanElementMapping.NAMESPACE.equals(
- rootEl.getNamespaceURI())) {
- in.reset();
- return null;
- }
-
- //Have to render the plan to know its size
- PlanRenderer pr = new PlanRenderer();
- Document svgDoc = pr.createSVGDocument(planDoc);
- float width = pr.getWidth();
- float height = pr.getHeight();
-
- //Return converted SVG image
- ImageInfo info = new ImageInfo(uri, "image/svg+xml");
- final ImageSize size = new ImageSize();
- size.setSizeInMillipoints(
- Math.round(width * 1000),
- Math.round(height * 1000));
- //Set the resolution to that of the FOUserAgent
- size.setResolution(context.getSourceResolution());
- size.calcPixelsFromSize();
- info.setSize(size);
-
- //The whole image had to be loaded for this, so keep it
- Image image = new ImageXMLDOM(info, svgDoc,
- svgDoc.getDocumentElement().getNamespaceURI());
- info.getCustomObjects().put(ImageInfo.ORIGINAL_IMAGE, image);
-
- return info;
- } catch (TransformerException e) {
- try {
- in.reset();
- } catch (IOException ioe) {
- // we're more interested in the original exception
- }
- log.debug("Error while trying to parsing a Plan file: "
- + e.getMessage());
- return null;
- }
- }
-
- private Document getDocument(InputStream in) throws TransformerException {
- TransformerFactory tFactory = TransformerFactory.newInstance();
- //Custom error listener to minimize output to console
- ErrorListener errorListener = new DefaultErrorListener(log);
- tFactory.setErrorListener(errorListener);
- Transformer transformer = tFactory.newTransformer();
- transformer.setErrorListener(errorListener);
- Source source = new StreamSource(in);
- DOMResult res = new DOMResult();
- transformer.transform(source, res);
-
- Document doc = (Document)res.getNode();
- return doc;
- }
-
-}
diff --git a/examples/plan/src/org/apache/fop/plan/SimplePlanDrawer.java b/examples/plan/src/org/apache/fop/plan/SimplePlanDrawer.java
deleted file mode 100644
index a8ba062ed..000000000
--- a/examples/plan/src/org/apache/fop/plan/SimplePlanDrawer.java
+++ /dev/null
@@ -1,321 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.plan;
-
-import java.text.DateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashMap;
-
-import org.w3c.dom.DOMImplementation;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import org.apache.batik.dom.svg.SVGDOMImplementation;
-
-import org.apache.fop.svg.SVGUtilities;
-
-/**
- * Simple plan drawer implementation.
- */
-public class SimplePlanDrawer implements PlanDrawer {
-
- private static final String SVG_NAMESPACE = SVGDOMImplementation.SVG_NAMESPACE_URI;
-
- private float fontSize;
- private HashMap hints;
- private java.awt.Font font = null;
- private boolean bord = false;
- private float lSpace = 15;
- private float width;
- private float height;
- private float topEdge;
- private float rightEdge;
-
- private String[] colours;
- private String[] darkcolours;
-
- private Date startDate;
- private Date endDate;
-
- /**
- * Sets the start date.
- * @param sd start date
- */
- public void setStartDate(Date sd) {
- startDate = sd;
- }
-
- /**
- * Sets the end date.
- * @param ed end date
- */
- public void setEndDate(Date ed) {
- endDate = ed;
- }
-
- /**
- * @see org.apache.fop.plan.PlanDrawer#createDocument(EventList, float, float, HashMap)
- */
- public Document createDocument(EventList data, float w, float h,
- HashMap hints) {
- this.width = w;
- this.height = h;
- this.hints = hints;
- fontSize = ((Float) hints.get(PlanHints.FONT_SIZE)).floatValue();
- bord = ((Boolean) hints.get(PlanHints.PLAN_BORDER)).booleanValue();
-
- String title = "";
-
- DOMImplementation impl
- = SVGDOMImplementation.getDOMImplementation();
- Document doc = impl.createDocument(SVG_NAMESPACE, "svg", null);
-
- Element svgRoot = doc.getDocumentElement();
- svgRoot.setAttributeNS(null, "width", Float.toString(width));
- svgRoot.setAttributeNS(null, "height", Float.toString(height));
- svgRoot.setAttributeNS(null, "viewBox",
- "0 0 " + Float.toString(width) + " " + Float.toString(height));
- svgRoot.setAttributeNS(null, "style",
- "font-size:" + 8
- + ";font-family:"
- + hints.get(PlanHints.FONT_FAMILY));
-
- font = new java.awt.Font((String)hints.get(PlanHints.FONT_FAMILY),
- java.awt.Font.PLAIN, (int)fontSize);
-
- if (bord) {
- Element border
- = SVGUtilities.createRect(doc, 0, 0, width, height);
- border.setAttributeNS(null, "style", "stroke:black;fill:none");
- svgRoot.appendChild(border);
- }
-
- float strwidth = SVGUtilities.getStringWidth(title, font);
-
- Element text;
- float pos = (float)(80 - strwidth / 2.0);
- if (pos < 5) {
- pos = 5;
- }
- text = SVGUtilities.createText(doc, pos, 18, title);
- text.setAttributeNS(null, "style", "font-size:14");
- svgRoot.appendChild(text);
-
- topEdge = SVGUtilities.getStringHeight(title, font) + 5;
-
- // add the actual pie chart
- addPlan(doc, svgRoot, data);
- //addLegend(doc, svgRoot, data);
-
- return doc;
- }
-
- protected void addPlan(Document doc, Element svgRoot, EventList data) {
- Date currentDate = new Date();
-
- Date lastWeek = startDate;
- Date future = endDate;
- Calendar lw = Calendar.getInstance();
- if (lastWeek == null || future == null) {
- int dow = lw.get(Calendar.DAY_OF_WEEK);
- lw.add(Calendar.DATE, -dow - 6);
- lastWeek = lw.getTime();
- lw.add(Calendar.DATE, 5 * 7);
- future = lw.getTime();
- }
- long totalDays = (long)((future.getTime() - lastWeek.getTime() + 43200000) / 86400000);
- lw.setTime(lastWeek);
- int startDay = lw.get(Calendar.DAY_OF_WEEK);
-
- float graphTop = topEdge;
- Element g;
- Element line;
- line = SVGUtilities.createLine(doc, 0, topEdge, width, topEdge);
- line.setAttributeNS(null, "style", "fill:none;stroke:black");
- svgRoot.appendChild(line);
-
- Element clip1 = SVGUtilities.createClip(doc,
- SVGUtilities.createPath(doc,
- "m0 0l126 0l0 " + height + "l-126 0z"), "clip1");
- Element clip2 = SVGUtilities.createClip(doc,
- SVGUtilities.createPath(doc,
- "m130 0l66 0l0 " + height + "l-66 0z"), "clip2");
- Element clip3 = SVGUtilities.createClip(doc,
- SVGUtilities.createPath(doc,
- "m200 0l" + (width - 200) + " 0l0 " + height + "l-"
- + (width - 200) + " 0z"), "clip3");
- svgRoot.appendChild(clip1);
- svgRoot.appendChild(clip2);
- svgRoot.appendChild(clip3);
-
- DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
- Element text;
- text = SVGUtilities.createText(doc, 201, topEdge - 1,
- df.format(lastWeek));
- svgRoot.appendChild(text);
-
- text = SVGUtilities.createText(doc, width, topEdge - 1,
- df.format(future));
- text.setAttributeNS(null, "text-anchor", "end");
- svgRoot.appendChild(text);
-
- line = SVGUtilities.createLine(doc, 128, topEdge, 128, height);
- line.setAttributeNS(null, "style", "fill:none;stroke:rgb(150,150,150)");
- svgRoot.appendChild(line);
- int offset = 0;
- for (int count = startDay; count < startDay + totalDays - 1; count++) {
- offset++;
- if (count % 7 == 0 || count % 7 == 1) {
- Element rect = SVGUtilities.createRect(doc,
- 200 + (offset - 1) * (width - 200) / (totalDays - 2),
- (float)(topEdge + 0.5),
- (width - 200) / (totalDays - 3),
- height - 1 - topEdge);
- rect.setAttributeNS(null, "style", "stroke:none;fill:rgb(230,230,230)");
- svgRoot.appendChild(rect);
- }
- line = SVGUtilities.createLine(doc,
- 200 + (offset - 1) * (width - 200) / (totalDays - 2),
- (float)(topEdge + 0.5),
- 200 + (offset - 1) * (width - 200) / (totalDays - 2),
- (float)(height - 0.5));
- line.setAttributeNS(null, "style", "fill:none;stroke:rgb(200,200,200)");
- svgRoot.appendChild(line);
- }
-
-
- for (int count = 0; count < data.getSize(); count++) {
- GroupInfo gi = data.getGroupInfo(count);
- g = SVGUtilities.createG(doc);
- text = SVGUtilities.createText(doc, 1, topEdge + 12,
- gi.getName());
- text.setAttributeNS(null, "style", "clip-path:url(#clip1)");
- g.appendChild(text);
- if (count > 0) {
- line = SVGUtilities.createLine(doc, 0, topEdge + 2,
- width, topEdge + 2);
- line.setAttributeNS(null, "style", "fill:none;stroke:rgb(100,100,100)");
- g.appendChild(line);
- }
-
- float lastTop = topEdge;
- topEdge += 14;
- boolean showing = false;
- for (int count1 = 0; count1 < gi.getSize(); count1++) {
- ActionInfo act = gi.getActionInfo(count1);
- String name = act.getOwner();
- String label = act.getLabel();
- text = SVGUtilities.createText(doc, 8, topEdge + 12, label);
- text.setAttributeNS(null, "style", "clip-path:url(#clip1)");
- g.appendChild(text);
-
- text = SVGUtilities.createText(doc, 130, topEdge + 12,
- name);
- text.setAttributeNS(null, "style", "clip-path:url(#clip2)");
- g.appendChild(text);
- int type = act.getType();
- Date start = act.getStartDate();
- Date end = act.getEndDate();
- if (end.after(lastWeek) && start.before(future)) {
- showing = true;
- int left = 200;
- int right = 500;
-
- int daysToStart = (int)((start.getTime()
- - lastWeek.getTime() + 43200000) / 86400000);
- int days = (int)((end.getTime() - start.getTime()
- + 43200000) / 86400000);
- int daysFromEnd
- = (int)((future.getTime() - end.getTime()
- + 43200000) / 86400000);
- Element taskGraphic;
- switch (type) {
- case ActionInfo.TASK:
- taskGraphic = SVGUtilities.createRect(doc,
- left + daysToStart * 300 / (totalDays - 2),
- topEdge + 2, days * 300 / (totalDays - 2), 10);
- taskGraphic.setAttributeNS(null,
- "style",
- "stroke:black;fill:blue;stroke-width:1;clip-path:url(#clip3)");
- g.appendChild(taskGraphic);
- break;
- case ActionInfo.MILESTONE:
- taskGraphic = SVGUtilities.createPath(doc,
- "m " + (left
- + daysToStart * 300 / (totalDays - 2) - 6)
- + " " + (topEdge + 6) + "l6 6l6-6l-6-6z");
- taskGraphic.setAttributeNS(null,
- "style",
- "stroke:black;fill:black;stroke-width:1;clip-path:url(#clip3)");
- g.appendChild(taskGraphic);
- text = SVGUtilities.createText(doc,
- left + daysToStart * 300 / (totalDays - 2) + 8,
- topEdge + 9, df.format(start));
- g.appendChild(text);
-
- break;
- case ActionInfo.GROUPING:
- taskGraphic = SVGUtilities.createPath(doc,
- "m " + (left
- + daysToStart * 300 / (totalDays - 2) - 6)
- + " " + (topEdge + 6) + "l6 -6l"
- + (days * 300 / (totalDays - 2))
- + " 0l6 6l-6 6l-4-4l"
- + -(days * 300 / (totalDays - 2) - 8)
- + " 0l-4 4l-6-6z");
- taskGraphic.setAttributeNS(null,
- "style",
- "stroke:black;fill:black;stroke-width:1;clip-path:url(#clip3)");
- g.appendChild(taskGraphic);
- break;
- default:
- break;
- }
- }
-
- topEdge += 14;
- }
- if (showing) {
- svgRoot.appendChild(g);
- } else {
- topEdge = lastTop;
- }
- }
- int currentDays
- = (int)((currentDate.getTime() - lastWeek.getTime()
- + 43200000) / 86400000);
-
- text = SVGUtilities.createText(doc,
- (float)(200 + (currentDays + 0.5) * 300 / 35),
- graphTop - 1, df.format(currentDate));
- text.setAttributeNS(null, "text-anchor", "middle");
- text.setAttributeNS(null, "style", "stroke:rgb(100,100,100)");
- svgRoot.appendChild(text);
-
- line = SVGUtilities.createLine(doc,
- (float)(200 + (currentDays + 0.5) * 300 / 35), graphTop,
- (float)(200 + (currentDays + 0.5) * 300 / 35), height);
- line.setAttributeNS(null, "style", "fill:none;stroke:rgb(200,50,50);stroke-dasharray:5,5");
- svgRoot.appendChild(line);
-
-
- }
-}