/*
* Created on 2003/05/24
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package org.jpn.xucker.snacksoundtoolkit;
import java.util.List;
import java.util.Vector;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.jpn.xucker.commons.undo.Command;
import org.jpn.xucker.commons.undo.CommandControl;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/**
* @author ak
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class PitchCanvas extends Canvas implements PaintListener,SelectionListener{
CommandControl commandList=new CommandControl();
private Button buttonB;
private Button buttonA;
private Button undo;
private Button redo;
private List espsList;
private int maxpitch=400;
public PitchCanvas(Shell shell){
super(shell,SWT.NULL);
this.addPaintListener(this);
//System.out.println(shell.getClientArea());
this.setBounds(shell.getClientArea());
ESPSParser parser=new ESPSParser();
}
public static void main(String[] args) {
Display display=new Display();
Shell shell=new Shell(display);
new PitchCanvas(shell);
shell.open();
while(!shell.isDisposed()){
if (!display.readAndDispatch ()){
display.sleep ();
}
}
display.dispose();
}
/* (non-Javadoc)
* @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
*/
public void paintControl(PaintEvent e) {
e.gc.setBackground(new Color(e.display,255,255,255));
e.gc.fillRectangle(this.getClientArea());
drawGraphMemory(e.gc);
if(espsList!=null && espsList.size()>0){
e.gc.setForeground(new Color(null,0,0,0));
e.gc.setLineWidth(1);
int x1;
int x2;
int y;
int max=this.getClientArea().height;
int width=this.getClientArea().width;
double wpp=(double)width/espsList.size();
ESPS preEsps=null;
if(espsList!=null){
for(int i=0;i<espsList.size();i++){
e.gc.setLineWidth(1);
ESPS esps=(ESPS)espsList.get(i);
if(preEsps!=null){
x1=(int)((i-1)*wpp);
x2=(int)(i*wpp);
e.gc.setForeground(new Color(null,255,0,0));
if(!esps.isVoicing()){
// e.gc.drawLine(x1,max/2,x2,max/2);
}
e.gc.setForeground(new Color(null,0,255,0));
//System.out.println(esps.getCorrelation());
int g1=toCorrelation(preEsps,max);
int g2=toCorrelation(esps,max);
//e.gc.drawLine(x1,g1,x2,g2);
e.gc.setForeground(new Color(null,0,0,255));
//System.out.println(esps.getCorrelation());
int b1=toMeasurements(preEsps,max);
int b2=toMeasurements(esps,max);
e.gc.drawLine(x1,b1,x2,b2);
//if(i%2==0){
e.gc.setLineWidth(4);
e.gc.setForeground(new Color(null,0x33,0x33,0x33));
//int y1=toPitch(preEsps,max);
int y2=toPitch(esps,max);
if(y2!=max){
e.gc.drawLine(x2,y2,x2,y2);
}
// }
}
preEsps=esps;
}
}
}
}
/**
* @param gc
*/
private void drawGraphMemory(GC gc) {
gc.setForeground(new Color(null,0xcc,0xcc,0xcc));
int h100=toPitchY(100,this.getClientArea().height);
int h200=toPitchY(200,this.getClientArea().height);
int h300=toPitchY(300,this.getClientArea().height);
gc.drawLine(0,h100,10,h100);
gc.drawString("100",5,h100-6);
gc.drawLine(0,h200,10,h200);
gc.drawString("200",5,h200-6);
gc.drawLine(0,h300,10,h300);
gc.drawString("300",5,h300-6);
}
private int toPitchY(int y,int max){
return (int)(max-(max*(double)((double)y/maxpitch)));
}
public int toPitch(ESPS esps,int max){
return (int)(max-(max*(double)(esps.getPitch()/maxpitch)));
}
public int toMeasurements(ESPS esps,int max){
return (int)(max-(max*esps.getMeasurements()/15000));
}
public int toCorrelation(ESPS esps,int max){
return (int)(max*esps.getCorrelation());
}
public class CommandA implements Command{
/* (non-Javadoc)
* @see org.jpn.xucker.commons.undo.Command#execute()
*/
public void execute() {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.jpn.xucker.commons.undo.Command#unexecute()
*/
public void unexecute() {
// TODO Auto-generated method stub
}
public String toString(){
return "[a]";
}
}
public class CommandB implements Command{
/* (non-Javadoc)
* @see org.jpn.xucker.commons.undo.Command#execute()
*/
public void execute() {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.jpn.xucker.commons.undo.Command#unexecute()
*/
public void unexecute() {
// TODO Auto-generated method stub
}
public String toString(){
return "[b]";
}
}
/* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
public void widgetSelected(SelectionEvent e) {
// TODO Auto-generated method stub
if(e.widget == buttonA){
commandList.addCommand(new CommandA());
}
if(e.widget == buttonB){
commandList.addCommand(new CommandB());
}
if(e.widget == undo){
commandList.undo();
}
if(e.widget == redo){
commandList.redo();
}
undo.setEnabled(commandList.canUndo());
redo.setEnabled(commandList.canRedo());
redraw();
}
/* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
*/
public void widgetDefaultSelected(SelectionEvent e) {
// TODO Auto-generated method stub
}
public List getEspsList() {
return espsList;
}
public void setEspsList(List espsList) {
this.espsList = espsList;
}
}
|