/*
* ConcreteSplitViewer program for analazing splits.
* Copyright (C) 2006-2007 Mytinski Leonid (Leonid.Mytinski@gmail.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
/*
* GlassStandartSplitViewerPanel.java
*
* Created on 5 Сентябрь 2007 г., 17:50
*/
package ru.concretesoft.concretesplitviewer;
import java.awt.AlphaComposite;
import java.awt.Point;
/**
*
* @author Mytinski Leonid
*/
public class GlassStandartSplitViewerPanel extends javax.swing.JPanel {
private AlphaComposite composite;
private AthleteIcon athlete;
private int cPsNumber;
private double scale;
private int yLocation;
private Point locationOnScreen;
private int[] xCoord;
private int yMax;
private int otst;
private int[] viewingSplits;
/** Creates new form GlassStandartSplitViewerPanel */
public GlassStandartSplitViewerPanel() {
setOpaque(false);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
setLayout(new java.awt.GridBagLayout());
}// </editor-fold>//GEN-END:initComponents
@Override
public void paintComponent(java.awt.Graphics g){
java.awt.Graphics2D g2 = (java.awt.Graphics2D) g;
if(athlete == null){
return ;
}
g2.setPaint(athlete.getColor());
Point p = locationOnScreen;
Point pl = this.getLocationOnScreen();
composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
g2.setComposite(composite);
Athlete a = athlete.getAthlete();
int yA = 0;
for(int k=0;k<cPsNumber;k++){
yA += athlete.getAthlete().getLap(viewingSplits[k]).getTimeInSeconds();
}
int xTemp = (cPsNumber==0) ? otst : xCoord[cPsNumber-1];
g2.drawLine((int)(p.getX()-pl.getX()) + xTemp,
(int)(p.getY()-pl.getY()) + (int)((yMax-yA)/scale),
(int)(p.getX()-pl.getX()) + xCoord[cPsNumber],
(int)(p.getY()-pl.getY()) + yLocation);
int diff = yA;
yA = yMax-(int)(yLocation*scale);
diff = yA - (diff + athlete.getAthlete().getLap(viewingSplits[cPsNumber]).getTimeInSeconds());
composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f);
g2.setComposite(composite);
Time t = new Time(0,2);
t.setTimeInSeconds(diff);
g2.drawString(athlete.getAthlete().getFamilyName() + " " + t.getTimeString(),
(int)(p.getX()-pl.getX()) + otst + 1,
(int)(p.getY()-pl.getY()) + 20);
composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
g2.setComposite(composite);
for(int i = cPsNumber; i < viewingSplits.length-1; i++){
int yANew = yA + a.getLap(viewingSplits[i+1]).getTimeInSeconds();
g2.drawLine((int)(p.getX()-pl.getX()) + xCoord[i],
(int)(p.getY()-pl.getY()) + (int)((yMax-yA)/scale),
(int)(p.getX()-pl.getX()) + xCoord[i+1],
(int)(p.getY()-pl.getY()) + (int)((yMax-yANew)/scale));
yA = yANew;
}
}
public void setAthlete(AthleteIcon athlete) {
this.athlete = athlete;
}
public void setCPsNumber(int cPsNumber) {
this.cPsNumber = cPsNumber;
}
public void setScale(double scale) {
this.scale = scale;
}
public void setYLocation(int yLocation) {
this.yLocation = yLocation;
repaint();
}
public void setLocationOnScreen(Point locationOnScreen) {
this.locationOnScreen = locationOnScreen;
}
public void setXCoord(int[] xCoord) {
this.xCoord = xCoord;
}
public void setYMax(int yMax) {
this.yMax = yMax;
}
public void setOtst(int otst) {
this.otst = otst;
}
public void setViewingSplits(int[] viewingSplits) {
this.viewingSplits = viewingSplits;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}