/* * A Java program that demonstrates a simple general-purpose drawing architecture * * Ben Bederson, April 18, 2002 */ import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.util.*; import javax.swing.*; public class Scene { ArrayList glyphs; JComponent component; public Scene(JComponent component) { this.component = component; glyphs = new ArrayList(); } public void addGlyph(Glyph glyph) { glyphs.add(glyph); repaint(); } public void repaint() { component.repaint(); } public void paint(Graphics2D g) { // Paint background g.setColor(Color.white); g.fillRect(0, 0, component.getWidth(), component.getHeight()); // Paint glyphs for (Iterator it = glyphs.iterator(); it.hasNext();) { Glyph glyph = (Glyph)it.next(); glyph.paint(g); } } // Returns the first glyph that contains this point in global coordinates (in top to bottom order) public Glyph pick(int x, int y) { Glyph hit = null; Glyph glyph; for (int i=glyphs.size()-1; i>=0; i--) { glyph = (Glyph)glyphs.get(i); if (glyph.contains(x, y)) { hit = glyph; break; } } return hit; } public void unselectAll() { for (Iterator it = glyphs.iterator(); it.hasNext();) { Glyph glyph = (Glyph)it.next(); if (glyph.isSelected()) { glyph.setSelected(false); } } } }