/**
* Copyright 1999-2009 The Pegadi Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pegadi.storysketch.views;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.QuadCurve2D;
import javax.swing.JComponent;
public class Face extends JComponent {
int mood;
boolean anonymous;
QuadCurve2D moodCurve = new QuadCurve2D.Double();
public Face() {
mood = 50;
}
public Face(int mood, boolean anonymous) {
this.mood = mood;
this.anonymous = anonymous;
}
public void setMood(int mood) {
this.mood = mood;
}
public void setAnonymous(boolean anonymous) {
this.anonymous = anonymous;
}
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
int w = (int) getSize().getWidth();
int h = (int) getSize().getHeight();
//g2.drawLine(0,0,w,h);
//g2.drawLine(0,h,w,0);
// Diameter of head
int d = (int) (Math.min(w,h) * 0.90);
// Fill head
g2.setColor(Color.WHITE);
g2.fillOval((w-d)/2,0,d,d);
g2.setColor(Color.BLACK);
// Draw head
g2.drawOval((w-d)/2,0,d,d);
//Draw eyes
if (anonymous) {
g2.fillRect(w/2-d/5-d/12, d/3, d/5, d/8);
g2.fillRect(w/2+d/5-d/12, d/3, d/5, d/8);
double rad = 2*Math.PI*24/360;
int sin = (int) (d/2 * Math.sin(rad));
int cos = (int) (d/2 * Math.cos(rad));
g2.drawLine(w/2-d/5-d/12, d/3, w/2 -cos, d/2-sin);
g2.drawLine(w/2+d/5-d/12+d/5, d/3, w/2 +cos, d/2-sin);
g2.drawLine(w/2-d/5-d/12+d/5,
d/3 + d/20,
w/2+d/5-d/12,
d/3 +d/20);
}
else {
g2.fillOval(w/2-d/5-d/12, d/3, d/8, d/8);
g2.fillOval(w/2+d/5-d/12, d/3, d/8, d/8);
}
moodCurve.setCurve(w/2-d/4,
d*3/4,
w/2,
d/2 + mood*d/200+d/12,
w/2+d/4,
d*3/4);
g2.draw(moodCurve);
}
}