01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: SiteEditorView.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.gui.ui;
09:
10: import java.awt.*;
11:
12: import com.uwyn.rife.config.Config;
13:
14: public class SiteEditorView extends EditorView {
15: private float mScaleFactor = 1f;
16:
17: public SiteEditorView(EditorPane pane) {
18: super (pane);
19:
20: this .setBackground(Color.white);
21: }
22:
23: protected Dimension calculateDimensionReal() {
24: return new Dimension(800, 600);
25: }
26:
27: public void paintComponent(Graphics g) {
28: super .paintComponent(g);
29: if (Config.getRepInstance().getBool("GRID_SHOW")) {
30: Graphics2D g2d = (Graphics2D) g;
31: g2d.setColor(Color.gray);
32: Rectangle clip_bounds = g2d.getClipBounds();
33: int grid_size = Config.getRepInstance().getInt("GRID_SIZE");
34: double grid_size_scaled = grid_size * mScaleFactor;
35: if (grid_size_scaled > 0) {
36: while (grid_size_scaled < 5) {
37: grid_size_scaled = grid_size_scaled * 2;
38: }
39: double offset_x = clip_bounds.x
40: - (clip_bounds.x % grid_size_scaled);
41: double offset_y = clip_bounds.y
42: - (clip_bounds.y % grid_size_scaled);
43: double new_clip_width = clip_bounds.width
44: + (clip_bounds.x % grid_size_scaled);
45: double new_clip_height = clip_bounds.height
46: + (clip_bounds.y % grid_size_scaled);
47: int real_x = 0;
48: int real_y = 0;
49: for (double x = 0; x <= new_clip_width; x += grid_size_scaled) {
50: for (double y = 0; y <= new_clip_height; y += grid_size_scaled) {
51: real_x = (int) (offset_x + x);
52: real_y = (int) (offset_y + y);
53: g2d.drawLine(real_x, real_y, real_x, real_y);
54: }
55: }
56: }
57: }
58: }
59: }
|