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 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.batik.gvt.font.FontFamilyResolver;
  21. import org.apache.fop.apps.FOUserAgent;
  22. /**
  23. * The SVG user agent. This is an implementation of the Batik SVG user agent.
  24. */
  25. public class SVGUserAgent extends SimpleSVGUserAgent {
  26. private SVGEventProducer eventProducer;
  27. private Exception lastException;
  28. /**
  29. * Creates a new SVGUserAgent.
  30. * @param foUserAgent the FO user agent to associate with this SVG user agent
  31. * @param fontFamilyResolver the font family resolver
  32. * @param at the current transform
  33. */
  34. public SVGUserAgent(FOUserAgent foUserAgent, FontFamilyResolver fontFamilyResolver, AffineTransform at) {
  35. super(foUserAgent.getSourcePixelUnitToMillimeter(), at, fontFamilyResolver);
  36. this.eventProducer = SVGEventProducer.Provider.get(foUserAgent.getEventBroadcaster());
  37. }
  38. /**
  39. * Creates a new SVGUserAgent.
  40. * @param foUserAgent the FO user agent to associate with this SVG user agent
  41. */
  42. public SVGUserAgent(FOUserAgent foUserAgent, FontFamilyResolver fontFamilyResolver) {
  43. this(foUserAgent, fontFamilyResolver, new AffineTransform());
  44. }
  45. /**
  46. * Returns the last exception sent to the {@link #displayError(Exception)} method.
  47. * @return the last exception or null if no exception occurred
  48. */
  49. public Exception getLastException() {
  50. return this.lastException;
  51. }
  52. /**
  53. * Displays an error message.
  54. * @param message the message to display
  55. */
  56. public void displayError(String message) {
  57. this.eventProducer.error(this, message, null);
  58. }
  59. /**
  60. * Displays an error resulting from the specified Exception.
  61. * @param ex the exception to display
  62. */
  63. public void displayError(Exception ex) {
  64. this.lastException = ex;
  65. this.eventProducer.error(this, ex.getLocalizedMessage(), ex);
  66. }
  67. /**
  68. * Displays a message in the User Agent interface.
  69. * The given message is typically displayed in a status bar.
  70. * @param message the message to display
  71. */
  72. public void displayMessage(String message) {
  73. this.eventProducer.info(this, message);
  74. }
  75. /**
  76. * Shows an alert dialog box.
  77. * @param message the message to display
  78. */
  79. public void showAlert(String message) {
  80. this.eventProducer.alert(this, message);
  81. }
  82. }