File: G2OpStore.java

package info (click to toggle)
libpixie-java 1%3A0.8.4-1
  • links: PTS
  • area: contrib
  • in suites: etch, etch-m68k
  • size: 1,000 kB
  • ctags: 2,695
  • sloc: java: 11,136; xml: 114; makefile: 16
file content (81 lines) | stat: -rw-r--r-- 1,766 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
 * Date: Mar 9, 2003
 * Time: 1:43:29 PM
 *
 * $Id: G2OpStore.java,v 1.4 2004/11/21 16:29:31 taqua Exp $
 */
package org.jfree.pixie.g2recorder;

import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Hashtable;

import org.jfree.ui.Drawable;

public class G2OpStore implements Drawable
{
  private static class StoreCarrier
  {
    private G2Recorder source;
    private G2Operation op;

    public StoreCarrier (final G2Recorder source, final G2Operation op)
    {
      if (source == null)
      {
        throw new NullPointerException();
      }
      if (op == null)
      {
        throw new NullPointerException();
      }

      this.source = source;
      this.op = op;
    }

    public G2Recorder getSource ()
    {
      return source;
    }

    public G2Operation getOp ()
    {
      return op;
    }
  }

  private ArrayList store;

  public G2OpStore ()
  {
    store = new ArrayList();
  }

  public void addOperation (final G2Recorder source, final G2Operation operation)
  {
    store.add(new StoreCarrier(source, operation));
  }

  public void draw (final Graphics2D graphics, final Rectangle2D bounds)
  {
    final Hashtable usedGraphics = new Hashtable();

    final StoreCarrier[] scs = (StoreCarrier[]) store.toArray(new StoreCarrier[store.size()]);

    // the bounds are ignored ... we assume, that clipping is enabled by the caller..
    for (int i = 0; i < scs.length; i++)
    {
      final StoreCarrier sc = scs[i];
      final G2Recorder g2r = sc.getSource();
      Graphics2D g2 = (Graphics2D) usedGraphics.get(g2r);
      if (g2 == null)
      {
        g2 = (Graphics2D) graphics.create();
        usedGraphics.put(g2r, g2);
      }
      sc.getOp().draw(g2);
    }
  }
}