KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > plugins > codeeditor > Rule


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23  
24 package org.infoglue.cms.plugins.codeeditor;
25
26 import java.awt.Color JavaDoc;
27 import java.awt.Dimension JavaDoc;
28 import java.awt.Font JavaDoc;
29 import java.awt.Graphics JavaDoc;
30 import java.awt.Rectangle JavaDoc;
31 import java.awt.Toolkit JavaDoc;
32
33 import javax.swing.JComponent JavaDoc;
34
35 public class Rule extends JComponent JavaDoc
36 {
37     public static final int INCH = Toolkit.getDefaultToolkit().getScreenResolution();
38     public static final int HORIZONTAL = 0;
39     public static final int VERTICAL = 1;
40     public static final int SIZE = 30;
41
42     public int orientation;
43     public boolean isMetric;
44     private int increment;
45     private int units;
46
47     public Rule(int o, boolean m)
48     {
49         orientation = o;
50         isMetric = m;
51         setIncrementAndUnits();
52     }
53
54     public void setIsMetric(boolean isMetric)
55     {
56         this.isMetric = isMetric;
57         setIncrementAndUnits();
58         repaint();
59     }
60
61     private void setIncrementAndUnits()
62     {
63         units = 17;
64         increment = units;
65     }
66
67     public boolean isMetric()
68     {
69         return this.isMetric;
70     }
71
72     public int getIncrement()
73     {
74         return increment;
75     }
76
77     public void setPreferredHeight(int ph)
78     {
79         setPreferredSize(new Dimension JavaDoc(SIZE, ph));
80     }
81
82     public void setPreferredWidth(int pw)
83     {
84         setPreferredSize(new Dimension JavaDoc(pw, SIZE));
85     }
86
87     public void paintComponent(Graphics JavaDoc g)
88     {
89         Rectangle JavaDoc drawHere = g.getClipBounds();
90
91         // Fill clipping area with dirty brown/orange.
92
g.setColor(new Color JavaDoc(128, 128, 128));
93         g.fillRect(drawHere.x, drawHere.y, drawHere.width, drawHere.height);
94
95         // Do the ruler labels in a small font that's black.
96
g.setFont(new Font JavaDoc("SansSerif", Font.PLAIN, 10));
97         g.setColor(Color.black);
98
99         int paintPosition = -4;
100          
101         for(int i=0; i<1000; i++)
102         {
103             g.drawString(Integer.toString(i), 1, paintPosition);
104             paintPosition += increment;
105         }
106     }
107 }
108
109
Popular Tags