You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SVGUserAgent.java 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.svg;
  19. import java.awt.geom.AffineTransform;
  20. import org.apache.fop.apps.FOUserAgent;
  21. /**
  22. * The SVG user agent. This is an implementation of the Batik SVG user agent.
  23. */
  24. public class SVGUserAgent extends SimpleSVGUserAgent {
  25. private SVGEventProducer eventProducer;
  26. private Exception lastException;
  27. /**
  28. * Creates a new SVGUserAgent.
  29. * @param foUserAgent the FO user agent to associate with this SVG user agent
  30. * @param at the current transform
  31. */
  32. public SVGUserAgent(FOUserAgent foUserAgent, AffineTransform at) {
  33. super(foUserAgent.getSourcePixelUnitToMillimeter(), at);
  34. this.eventProducer = SVGEventProducer.Provider.get(foUserAgent.getEventBroadcaster());
  35. }
  36. /**
  37. * Creates a new SVGUserAgent.
  38. * @param foUserAgent the FO user agent to associate with this SVG user agent
  39. */
  40. public SVGUserAgent(FOUserAgent foUserAgent) {
  41. this(foUserAgent, new AffineTransform());
  42. }
  43. /**
  44. * Returns the last exception sent to the {@link #displayError(Exception)} method.
  45. * @return the last exception or null if no exception occurred
  46. */
  47. public Exception getLastException() {
  48. return this.lastException;
  49. }
  50. /**
  51. * Displays an error message.
  52. * @param message the message to display
  53. */
  54. public void displayError(String message) {
  55. this.eventProducer.error(this, message, null);
  56. }
  57. /**
  58. * Displays an error resulting from the specified Exception.
  59. * @param ex the exception to display
  60. */
  61. public void displayError(Exception ex) {
  62. this.lastException = ex;
  63. this.eventProducer.error(this, ex.getLocalizedMessage(), ex);
  64. }
  65. /**
  66. * Displays a message in the User Agent interface.
  67. * The given message is typically displayed in a status bar.
  68. * @param message the message to display
  69. */
  70. public void displayMessage(String message) {
  71. this.eventProducer.info(this, message);
  72. }
  73. /**
  74. * Shows an alert dialog box.
  75. * @param message the message to display
  76. */
  77. public void showAlert(String message) {
  78. this.eventProducer.alert(this, message);
  79. }
  80. }