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.

DoubleStroke.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hssf.view.brush;
  16. import java.awt.*;
  17. /**
  18. * This Stroke implementation applies a BasicStroke to a shape twice. If you
  19. * draw with this Stroke, then instead of outlining the shape, you're outlining
  20. * the outline of the shape.
  21. *
  22. * @author Ken Arnold, Industrious Media LLC
  23. */
  24. public class DoubleStroke implements Brush {
  25. BasicStroke stroke1, stroke2; // the two strokes to use
  26. /**
  27. * Creates a new double-stroke brush. This surrounds a cell with a two
  28. * lines separated by white space between.
  29. *
  30. * @param width1 The width of the blank space in the middle
  31. * @param width2 The width of the each of the two drawn strokes.
  32. */
  33. public DoubleStroke(float width1, float width2) {
  34. stroke1 = new BasicStroke(width1); // Constructor arguments specify
  35. stroke2 = new BasicStroke(width2); // the line widths for the strokes
  36. }
  37. /**
  38. * Stroke the outline.
  39. *
  40. * @param s The shape in which to stroke.
  41. *
  42. * @return The created stroke as a new shape.
  43. */
  44. public Shape createStrokedShape(Shape s) {
  45. // Use the first stroke to create an outline of the shape
  46. Shape outline = stroke1.createStrokedShape(s);
  47. // Use the second stroke to create an outline of that outline.
  48. // It is this outline of the outline that will be filled in
  49. return stroke2.createStrokedShape(outline);
  50. }
  51. /** {@inheritDoc} */
  52. public float getLineWidth() {
  53. return stroke1.getLineWidth() + 2 * stroke2.getLineWidth();
  54. }
  55. }