Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / fframes / gui / JPRotationView.java @ 36648

History | View | Annotate | Download (2.72 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.project.documents.layout.fframes.gui;
23

    
24
import java.awt.BasicStroke;
25
import java.awt.Color;
26
import java.awt.Graphics;
27
import java.awt.Graphics2D;
28
import java.awt.Rectangle;
29

    
30
import javax.swing.JPanel;
31

    
32
public class JPRotationView extends JPanel {
33

    
34
    private static final long serialVersionUID = -7134231921356704835L;
35
    private double rotation = 0;
36

    
37
    public void setRotation(double rot) {
38
        rotation = rot;
39
    }
40

    
41
    public double getRotation() {
42
        return rotation;
43
    }
44

    
45
    protected void paintComponent(Graphics g) {
46
        super.paintComponent(g);
47
        Rectangle r = new Rectangle(35, 15, 30, 25);
48
        ((Graphics2D) g).rotate(Math.toRadians(getRotation()), r.x
49
            + (r.width / 2), r.y + (r.height / 2));
50

    
51
        g.setColor(new Color(230, 150, 50));
52
        ((Graphics2D) g).setStroke(new BasicStroke(4));
53
        g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
54
            (int) r.getHeight());
55
        ((Graphics2D) g).setStroke(new BasicStroke(1));
56
        g.setColor(Color.RED);
57
        g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
58
            (int) r.getHeight());
59
        g.setColor(Color.black);
60
        g.drawRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(),
61
            (int) r.getHeight());
62
        ((Graphics2D) g).rotate(Math.toRadians(-getRotation()), r.x
63
            + (r.width / 2), r.y + (r.height / 2));
64
    }
65

    
66
    /**
67
     * This is the default constructor
68
     */
69
    public JPRotationView() {
70
        super();
71
        initialize();
72
    }
73

    
74
    /**
75
     * This method initializes this
76
     * 
77
     * @return void
78
     */
79
    private void initialize() {
80
        this.setSize(106, 67);
81
        this.setBackground(java.awt.SystemColor.controlShadow);
82
        this.setBackground(java.awt.Color.white);
83
    }
84

    
85
} // @jve:decl-index=0:visual-constraint="10,10"