View Javadoc

1   /*
2    * Copyright 1999-2006 Faculty of Mathematics, Physics
3    * and Informatics, Comenius University, Bratislava. This file is protected by
4    * the Mozilla Public License version 1.1 (the License); you may not use this
5    * file except in compliance with the License. You may obtain a copy of the
6    * License at http://euromath2.sourceforge.net/license.html Unless required by
7    * applicable law or agreed to in writing, software distributed under the
8    * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
9    * OF ANY KIND, either express or implied. See the License for the specific
10   * language governing permissions and limitations under the License.
11   */
12  package sk.uniba.euromath.foRenderer.figures;
13  
14  import org.eclipse.draw2d.ColorConstants;
15  import org.eclipse.draw2d.Graphics;
16  import org.eclipse.draw2d.IFigure;
17  import org.eclipse.draw2d.LineBorder;
18  import org.eclipse.draw2d.geometry.Insets;
19  import org.eclipse.swt.graphics.Color;
20  
21  /***
22   * @author TV Created on 12.12.2004
23   * 
24   */
25  public class LineRuleBorder extends LineBorder {
26  
27      public static final double DPI = 96;
28  
29      public static final double PX2CM = DPI / 2.54f;
30  
31  //    private Color rulerColor = ColorConstants.black;
32  
33  //    private Color innerRulerBorder = ColorConstants.buttonDarker;
34  
35      private Color rulerColor = ColorConstants.white;
36  
37      private Color innerRulerBorder = ColorConstants.lightGray;
38      
39     public LineRuleBorder() {
40  //        super(ColorConstants.white, 5);
41          super(ColorConstants.buttonDarker, 10);
42      }
43  
44      public void paint(IFigure figure, Graphics g, Insets insets) {
45          super.paint(figure, g, insets);
46         
47          tempRect.setBounds(getPaintRectangle(figure, insets));
48  //        tempRect.setBounds(tempRect.getExpanded(2,2));
49  
50          g.setForegroundColor(rulerColor);
51          g.setLineWidth(1);
52          g.translate(tempRect.getLocation());
53          // draw horizontal rule line
54          int w = getWidth();
55          float x = w;
56          int xCoord = Math.round(x);
57          while (xCoord <= tempRect.width) {
58              g.drawLine(xCoord, 0, xCoord, w - 1);
59              g.drawLine(xCoord, tempRect.height - w, xCoord,
60                              tempRect.height - 1);
61              x += PX2CM;
62              xCoord = Math.round(x);
63          }
64  
65          // draw vertical rule line
66          float y = w;
67          int yCoord = Math.round(y);
68          while (yCoord <= tempRect.height) {
69              g.drawLine(0, yCoord, w - 1, yCoord);
70              g.drawLine(tempRect.width - w, yCoord, tempRect.width - 1, yCoord);
71              y += PX2CM;
72              yCoord = Math.round(y);
73          }
74          // draw 3d border
75          g.setForegroundColor(innerRulerBorder);
76          g.setLineWidth(2);
77          g.drawRectangle(w-1, w-1, tempRect.width - 2*w,
78                  tempRect.height - 2*w);
79  
80          g.translate(tempRect.getLocation().getNegated());
81       
82      }
83      
84  }