OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 17 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
17 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
182 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
17 ilm 5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 /*
15
 * Created on 2 sept. 2003
16
 *
17
 */
18
package org.openconcerto.ui;
19
 
20
import java.awt.Color;
21
import java.awt.Dimension;
22
import java.awt.Font;
23
import java.awt.Graphics;
24
import java.awt.Graphics2D;
25
import java.awt.RenderingHints;
26
import java.awt.geom.Rectangle2D;
27
import java.util.Vector;
28
 
29
import javax.swing.JComponent;
30
 
31
/**
32
 * @author ilm
33
 *
34
 * To change the template for this generated type comment go to
35
 * Window>Preferences>Java>Code Generation>Code and Comments
36
 */
37
public class RoundedComponentMenu extends JComponent {
38
	private String name;
39
	private Vector items = new Vector();
40
	/**
41
	 *
42
	 */
43
	public RoundedComponentMenu(String name) {
44
		super();
45
		this.name=name;
46
 
47
	}
48
 
49
	public void addMenuItem(RoundedMenuItem m){
50
		items.add(m);
51
	}
52
 
53
 
54
	/* (non-Javadoc)
55
	 * @see java.awt.Component#getPreferredSize()
56
	 */
57
	public Dimension getPreferredSize() {
58
		Dimension d=new Dimension(600,100*this.items.size());
59
		return d;
60
	}
61
 
62
	/* (non-Javadoc)
63
	 * @see java.awt.Component#paint(java.awt.Graphics)
64
	 */
65
	public void paint(Graphics g) {
66
		// fond
67
		g.setColor(bgColor);
68
		int h=this.getHeight();
69
		int w=this.getWidth();
70
		g.fillRect(0,0,w,h);
71
		// decoupe blanches
72
		((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
73
 
74
		g.setColor(fgColor);
75
		int m=(int)(1.8*h);
76
		g.fillOval(100,-m/3,m,m);
77
		// titre
78
		g.setColor(Color.BLACK);
79
		int fontSize=48;
80
		Font font=new Font("Arial",Font.BOLD,fontSize);
81
		g.setFont(font);
82
		g.drawString(name,50,30+fontSize);
83
 
84
		int d=60;
85
		int k=0;
86
		for (int y=-00;y<80*items.size();y+=80){
87
			float xx = m*m-4f*y*y;
88
			float x= -(int) ( (Math.sqrt(xx))/2 );
89
			System.out.println("xx:"+xx+"x"+x+"y:"+y);
90
			g.setColor(Color.WHITE);
91
			g.fillOval((int)x+m/2+100-(d*3)/5,y+m/6-d/2,d,d);
92
			g.setColor(Color.BLACK);
93
			g.drawOval((int)x+m/2+100-(d*3)/5,y+m/6-d/2,d,d);
94
			g.setColor(Color.lightGray);
95
			String label="Sous memu";
96
			Rectangle2D rect = font.getStringBounds(label, ((Graphics2D) g).getFontRenderContext());
97
 
98
			g.drawString(((RoundedMenuItem)items.elementAt(k)).getName(),(int)(x+m/2+160),(int)(y+m/6-d/2+(rect.getHeight())/2));
99
			k++;
100
		}
101
	}
102
 
103
	//private Color bgColor=new Color(240,240,200);
104
	private Color bgColor=new Color(174,4,21);
105
	private Color fgColor=Color.white;
106
}