Commit b0a66f79 authored by Catalina's avatar Catalina
Browse files

Done

parents
import de.bezier.data.sql.*; //Database
import java.awt.*; //Transfarable data + Clipboard
import java.awt.datatransfer.*;
import javax.swing.*;
import java.io.*; //EOF Clipboard
//import java.awt.event.*;
float midW, midH;
FormHolder currForm;
float R;
PApplet thisPapplet = this;
MySQL db;
boolean SENT = false;
PImage logo;
void setup() {
logo = loadImage("icon2-4-01.png");
surface.setIcon(logo);
fullScreen();
pixelDensity(displayDensity());
frameRate(60);
noStroke();
ellipseMode(RADIUS);
midW = width/2;
midH = height/2;
R = (height/25);
currForm = new FormHolder();
currForm.addForm(new Form(new PVector(10, 20 + height/8), c3, width - 20, height - (10 + height/8), 0.2, 1));
currForm.addForm(new Form(new PVector(10, 20 + height/8), c3, width - 20, height - (10 + height/8), 0.2, 2));
currForm.addForm(new Form(new PVector(10, 20 + height/8), c3, width - 20, height - (10 + height/8), 0.2, 3));
scTb=new scrollbar2(width/2-R/2 + R/3,height/6,R/2,height-R*2,(int)(lungTb()/4/R/3+1));
db = new MySQL(thisPapplet, "localhost", "ezgraphs", "root", ""); //localhost
}
void draw() {
background(c3);
currForm.show();
}
void mouseWheel(MouseEvent event) {
float e = event.getCount();
if (isBetween(scTb.y,scTb.y+scTb.h-scTb.h2,scTb.y2+e*scTb.h3)) {
scTb.y2+=e*scTb.h3;
scTb.decateori+=e;
}
}
color c1=color(0, 175, 234); //light blue
color c2=color(163, 205, 57); //green
color c3=color(0, 7, 40); //black-blue
color c4=color(247, 240, 150); //light yellow
color c5=color(255, 89, 94); //red-pink
color c6=color(125, 131, 255); //light purple
color c7=color(3, 0, 56); //dark purple-blue
color c8=color(97, 83, 204); //purple
color c1_o=color(60, 235, 294); //light blue
color c2_o=color(183, 225, 77); //green
color c3_o=color(48, 54, 60); //black-blue
color c4_o=color(267, 260, 170); //light yellow
color c5_o=color(275, 109, 114); //red-pink
color c6_o=color(145, 151, 275); //light purple
color c7_o=color(39, 80, 105); //dark purple-blue
color c8_o=color(117, 103, 224); //purple
int currentModule;
int delay=0, DELAY = 20;
boolean isBetween(float a,float b,float x) {
if (a<=x && x<=b) return true;
else return false;
}
scrollbar2 scTb;
float lungTb() {
if(currForm.forms.get(1).txtb==null)return 0;
return currForm.forms.get(1).txtb.y+currForm.forms.get(1).txtb.h+R*3;
}
String faCodGraf() {
int i;
String codGraf = "";
if (currForm.forms.get(1).grafLectie.oriented) codGraf+="1\n";
else codGraf+="0\n";
codGraf+=(currForm.forms.get(1).grafLectie.graf.size()-1)+"\n";
for (i=0;i<currForm.forms.get(1).grafLectie.nodes.size();i++) {
codGraf+=((int)currForm.forms.get(1).grafLectie.nodes.get(i).basePos.x+(int)currForm.forms.get(1).grafLectie.basePos.x)+" ";
codGraf+=((int)currForm.forms.get(1).grafLectie.nodes.get(i).basePos.y+(int)currForm.forms.get(1).grafLectie.basePos.y)+" ";
if (currForm.forms.get(1).grafLectie.nodes.get(i).active) codGraf+="1 ";
else codGraf+="0 ";
codGraf+=currForm.forms.get(1).grafLectie.nodes.get(i).index+" ";
codGraf+="\n";
}
codGraf+=currForm.forms.get(1).grafLectie.edges.size()+"\n";
for (i=0;i<currForm.forms.get(1).grafLectie.edges.size();i++) {
codGraf+=currForm.forms.get(1).grafLectie.edges.get(i).sIndex+" ";
codGraf+=currForm.forms.get(1).grafLectie.edges.get(i).fIndex+" ";
codGraf+="\n";
}
return codGraf;
}
\ No newline at end of file
class ToggleBtn extends Obj{ //toggle in mousePressed();
PVector addPos;
int index;
boolean toggle = false;
String name;
color normal, hover, active;
float baseAngle = 50, seekAngle = 0;
ToggleBtn(PVector pos, color c, float w, float h, float anim, color hov, color press, String text, int i){
super(pos, c, w, h, anim);
normal = c;
hover = hov;
active = press;
name = text;
index = i;
addPos = new PVector(0, 0);
}
void display(){
noStroke();
fill(baseCol);
rect(addPos.x + basePos.x, addPos.y + basePos.y, baseW, baseH, baseAngle);
textSize(round(baseH / 4));
textAlign(CENTER, CENTER);
fill(42);
text(name, addPos.x + basePos.x, addPos.y + basePos.y, baseW, baseH);
}
void update(){
this.animate();
baseAngle = lerp(baseAngle, seekAngle, animSpd);
if(toggle){
seekColor(active);
seekAngle = 50;
}
else if(isHovered(mouseX, mouseY)){
seekColor(hover);
seekAngle = 50;
}
else {
seekColor(normal);
seekAngle = 0;
}
}
boolean isHovered(float x, float y){
return(x>=addPos.x + basePos.x && x<=addPos.x + basePos.x + baseW && y>=addPos.y + basePos.y && y<=addPos.y + basePos.y + baseH);
}
}
\ No newline at end of file
class EdgeLectie{
color normal, hover, baseCol, seekCol;
Obj sPoint, fPoint, controlPS, controlPF;
int sIndex, fIndex;
EdgeLectie(NodeLectie nod, NodeLectie vec, int _n, int _v, color norm, color hov){
sPoint = new Obj(new PVector(nod.addPos.x + nod.basePos.x, nod.addPos.y + nod.basePos.y), norm, 4, 4, 0.15);
fPoint = new Obj(new PVector(vec.addPos.x + vec.basePos.x, vec.addPos.y + vec.basePos.y), norm, 4, 4, 0.15);
normal = baseCol = seekCol = norm;
hover = hov;
sIndex = _n;
fIndex = _v;
}
void displayOriented(){
//println("AM AFISAT");
noFill();
float w3, w11, w22, q, w1, w2;
int x1 = int(sPoint.basePos.x), y1 = int(sPoint.basePos.y), x2 = x1, y2 = y1, x3 = int(fPoint.basePos.x), y3 = int(fPoint.basePos.y), x4 = x3, y4 = y3;
if (x1!=x4) w3=atan((y1-y4)/(x1-x4));
else w3=PI/2;
if (y4<y1) w3=-w3;
PVector v1 = new PVector(x4-x1, y4-y1);
PVector v2 = new PVector(width, 0);
w3=radians(PVector.angleBetween(v2, v1));
if (y4<y1) w3=-w3;
w3=w3*180/PI;
q=dist(x1,y1,x4,y4)/3;
w1=q*cos(w3-PI/8);
w2=q*sin(w3-PI/8);
w11=q*cos(w3+PI/8+PI);
w22=q*sin(w3+PI/8+PI);
if (currForm.forms.get(1).grafLectie.indexBtn==5) {
stroke(256,0,0);
strokeWeight(1);
line(x4,y4,x2,y2);
}
stroke(c1);
strokeWeight(6);
bezier(x1,y1,x1+w1,y1+w2,x4+w11,y4+w22,x4,y4);
q=R;
w1=q*cos(w3+PI+PI/8);
w2=q*sin(w3+PI+PI/8);
w11=R*cos(w3+PI/10+PI+PI/8);
w22=R*sin(w3+PI/10+PI+PI/8);
line(x4+w1,y4+w2,x4+w1+w11,y4+w2+w22);
w11=R*cos(w3-PI/5+PI+PI/8);
w22=R*sin(w3-PI/5+PI+PI/8);
line(x4+w1,y4+w2,x4+w1+w11,y4+w2+w22);
}
void displayUnoriented(){
stroke(c1);
strokeWeight(6);
int x1 = int(sPoint.basePos.x), y1 = int(sPoint.basePos.y), x2 = x1, y2 = y1, x3 = int(fPoint.basePos.x), y3 = int(fPoint.basePos.y), x4 = x3, y4 = y3;
line(x1, y1, x4, y4);
}
void update(){
if(currForm.forms.get(1).grafLectie!=null){
NodeLectie nod = currForm.forms.get(1).grafLectie.nodes.get(sIndex), vec = currForm.forms.get(1).grafLectie.nodes.get(fIndex);
sPoint.seekPosition(new PVector(nod.addPos.x + nod.basePos.x, nod.addPos.y + nod.basePos.y));
fPoint.seekPosition(new PVector(vec.addPos.x + vec.basePos.x, vec.addPos.y + vec.basePos.y));
}
sPoint.animate();
fPoint.animate();
baseCol = lerpColor(baseCol, seekCol, 0.15);
if(isOnLine(sPoint.basePos, fPoint.basePos, new PVector(mouseX, mouseY))) seekCol = hover;
else seekCol = normal;
}
boolean isOnLine(PVector startP, PVector endP, PVector mouseP){
PVector closeP = new PVector(); //Can be returned as reference -> closest point to segment
PVector line = PVector.sub(endP, startP);
float ERR = 6; //size of border / stroke
float l2 = line.magSq();
if (l2 == 0.0) {
closeP.set(startP);
return false;
}
PVector dstLine = PVector.sub(mouseP, startP);
float t = dstLine.dot(line)/l2;
dstLine.normalize();
closeP.set(line);
closeP.mult(t);
closeP.add(startP);
float d = PVector.dist(mouseP, closeP);
if (t >= 0 && t <= 1 && d <= ERR) return true;
else return false;
}
boolean exist(int s, int f){
return (sIndex == s && fIndex == f);
}
int oneEnd(int nod){
if(sIndex == nod) return fIndex;
else if(fIndex == nod) return sIndex;
return -1;
}
void indexReplacement(int nod){
if(sIndex >= nod)sIndex--;
if(fIndex >= nod)fIndex--;
}
}
\ No newline at end of file
class Form extends Obj{
int index;
ArrayList<TextBox> txtboxes = new ArrayList<TextBox>();
ArrayList<ToggleBtn> btns = new ArrayList<ToggleBtn>();
txtbx numeLectie, utilizator, parola;
MultipleSelectionDropDown tipLectie; //Nume + Tip Lectie
GrafLectie grafLectie;
txtbx txtb;
Form(PVector pos, color c, float w, float h, float anim, int i){
super(pos, c, w, h, anim);
index = i;
switch(index){
case 1:{ //Nume + Tip Lectie
tipLectie = new MultipleSelectionDropDown(new PVector(pos.x, pos.y), c6, c6_o, 30, (width - 20), height/10, 0.2);
tipLectie.addMainTab("Tip Lectie", 1);
tipLectie.mainTabs.get(0).addSubTab("Grafuri Neorientate", 1);
tipLectie.mainTabs.get(0).addSubTab("Grafuri Orientate", 2);
//tipLectie.mainTabs.get(0).addSubTab("Amandoua", 3);
txtboxes.add(new TextBox(new PVector(2*seekW/6, 2*seekH/8), color(255, 100, 100), 2*seekW/6, seekH/8, 0.2, color(255, 120, 120), color(255, 140, 140), 30, 30, 1));
txtboxes.get(0).data = "NUME LECTIE";
numeLectie=new txtbx(2*seekW/6, 2*seekH/8,2*seekW/6, seekH/8,R,1,0);
break;
}
case 2:{ //Lectie + Graf Anim
grafLectie = new GrafLectie(new PVector(pos.x + w / 2, pos.y), c6, (w - 20)/2, h, 0.2);
txtb = new txtbx(basePos.x + R, basePos.y + R, ((baseW - 10)/2)-R, (baseH/2)-R, R*2/3, 0, 0);
break;
}
case 3:{ //Submit
utilizator=new txtbx(2*seekW/6, 2*seekH/8,2*seekW/6, seekH/8,R,1,0);
parola=new txtbx(2*seekW/6, 2*seekH/8,2*seekW/6, seekH/8,R,1,0);
//PVector pos, color c, float w, float h, float anim, color hov, color press, String text, int i
btns.add(new ToggleBtn(new PVector(basePos.x + baseW/2, basePos.y + baseH/2), c6, baseW/8, baseH/8, 0.2, c6_o, color(125, 131, 230), "SUBMIT", 1));
break;
}
}
}
void display(){
noStroke();
fill(baseCol);
rect(basePos.x, basePos.y, baseW, baseH, 10);
/*for(TextBox t : txtboxes){
if(t.focus)textAlign(LEFT);
else textAlign(CENTER, CENTER);
t.display();
}*/
switch (index) {
case 1:{
noStroke();
tipLectie.display();
numeLectie.display();
break;
}
case 2:{
grafLectie.display();
if(txtb!=null){
txtb.display();
scTb.display();
}
break;
}
case 3: {
fill(-1);
textSize(R);
textAlign(CENTER,CENTER);
text("Utilizator:",utilizator.x-R*6,utilizator.y,R*6,utilizator.h);
text("Parola:",parola.x-R*6,parola.y,R*6,parola.h);
utilizator.display();
parola.display();
btns.get(0).display();
fill(230);
textAlign(CENTER, CENTER);
textSize(30);
text("Press ENTER", basePos.x + width/2, basePos.y + height/2);
break;
}
}
}
void update(){
animate();
switch (index) {
case 1:{
tipLectie.update();
tipLectie.position = new PVector(basePos.x, basePos.y);
numeLectie.x=basePos.x+baseW/2-numeLectie.w/2;
numeLectie.y=basePos.y+baseH/2-numeLectie.h/2;
break;
}
case 2:{
if(currForm.forms.get(0).tipLectie!=null && currForm.forms.get(0).tipLectie.mainTabs!=null)
if(currForm.forms.get(0).tipLectie.mainTabs.get(0).indexSelected==1){
grafLectie.oriented = false;
}
else{
grafLectie.oriented = true;
}
grafLectie.addPos = new PVector(basePos.x, 0);
grafLectie.update();
if(txtb!=null){
txtb.w = ((baseW - 10)/2)-R;
txtb.h = (baseH/2)-R;
txtb.x = basePos.x + R;
txtb.y = basePos.y + R;
scTb.x = basePos.x + width/2;
scTb.y = basePos.y + 10;
}
break;
}
case 3: {
btns.get(0).update();
utilizator.x = basePos.x+baseW/2-utilizator.w/3;
utilizator.y = basePos.y+R*3;
parola.x = basePos.x+baseW/2-parola.w/3;
parola.y = utilizator.y + 10+utilizator.h;
break;
}
}
for(TextBox t : txtboxes){
t.addPos = new PVector(basePos.x, basePos.y);
t.update();
}
if(index==3 && keyPressed && key==ENTER){
if(SENT)return;
if(db.connect()){
db.query("SELECT * FROM users WHERE pass='"+parola.s+"' AND (nickname='"+utilizator.s+"' OR email='"+utilizator.s+"')");
if(db.next()){
int profID = db.getInt("userID");
String userName = db.getString("name");
db.execute("INSERT INTO lectiedata VALUES(NULL, "+profID+", '"+currForm.forms.get(1).txtb.s+"', '"+faCodGraf()+"', '"+currForm.forms.get(0).numeLectie.s+"', 0, 0)");
SENT=true;
}
}
else return;
}
}
void mouseEvents(){
for(TextBox t : txtboxes){
if(t.isHovered(mouseX, mouseY)) t.focus = true;
else t.focus = false;
}
if(index==2){
grafLectie.mouseEvents();
}
}
void keyEvents(){
for(TextBox t : txtboxes)
if(t.focus == true)
t.keyIsPressed();
if(txtb!=null) txtb.PressKeyProperly();
}
}
\ No newline at end of file
class FormHolder{
int currIndex;
TextBox notification;
ArrayList<Form> forms;
ArrayList<ToggleBtn> buttons;
FormHolder(){
forms = new ArrayList<Form>();
buttons = new ArrayList<ToggleBtn>();
for(int i=0;i<3;i++)
buttons.add(new ToggleBtn(new PVector(10 + (width/8 + 10) * i, 10), color(61, 164, 171), width/8, height/8, 0.2, color(14, 154, 167), color(0, 166, 166), int(i + 1) + "", i + 1));
notification = new TextBox(new PVector(10 + (width/8 + 10) * 3, 10), color(120, 120, 120), width - (5 * 10 + 3 * width/8), height/8, 0.2, color(150, 150, 150), color(160, 160, 160), 30, 30, 1);
currIndex = 1;
buttons.get(0).toggle = true;
}
void show(){
for(Form f : forms){
f.update();
f.display();
if(currIndex > f.index) f.seekPosition(new PVector(-width, 20 + height/8));
else if(currIndex < f.index) f.seekPosition(new PVector(width + 10, 20 + height/8));
else f.seekPosition(new PVector(10, 20 + height/8));
}
fill(49, 54, 142);
rect(0, 0, width, height/6);
for(ToggleBtn btn : buttons){
btn.update();
btn.display();
}
notification.update();
textAlign(CENTER, CENTER);
//notification.display();
}
void addForm(Form f){
forms.add(f);
}
void mouseEvents(){
for(ToggleBtn btn : buttons)
if(btn.isHovered(mouseX, mouseY)){
btn.toggle = true;
currIndex = btn.index;
}
for(ToggleBtn btn : buttons)
if(btn.index != currIndex)
btn.toggle = false;
/*if(notification.isHovered(mouseX, mouseY)) //+ Sum bonus shit
notification.focus = true;
else notification.focus = false;*/
for(Form f : forms)
f.mouseEvents();
}
void keyEvents(){
for(Form f : forms)
f.keyEvents();
}
}
\ No newline at end of file
class GrafLectie extends Obj{
PVector addPos;
int indexBtn = -1;
ArrayList<ToggleBtn> btns;
ArrayList<IntList> graf;
boolean oriented = true;
ArrayList<NodeLectie> nodes;
boolean nodeOnPossesion = false;
int nodeOnPossesionIndex = -1, nodePrime = -1, nodeNeighbor = -1;
ArrayList<EdgeLectie> edges;
GrafLectie(PVector pos, color c, float w, float h, float anim){
super(pos, c, w, h, anim);
addPos = new PVector(0, 0);
btns = new ArrayList<ToggleBtn>();
btns.add(new ToggleBtn(new PVector(addPos.x + basePos.x, addPos.y + basePos.y), color(51,133,198), w/6, h/7, 0.2, color(66,121,163), color(14,154,167), "Add point", 1));
btns.add(new ToggleBtn(new PVector(addPos.x + basePos.x + w/6, addPos.y + basePos.y), color(51,133,198), w/6, h/7, 0.2, color(66,121,163), color(14,154,167), "Move", 2));
btns.add(new ToggleBtn(new PVector(addPos.x + basePos.x + 2 * w/6, addPos.y + basePos.y), color(51,133,198), w/6, h/7, 0.2, color(66,121,163), color(14,154,167), "Delete graph", 3));
btns.add(new ToggleBtn(new PVector(addPos.x + basePos.x + 3 * w/6, addPos.y + basePos.y), color(51,133,198), w/6, h/7, 0.2, color(66,121,163), color(14,154,167), "Add edge", 4));
btns.add(new ToggleBtn(new PVector(addPos.x + basePos.x + 4 * w/6, addPos.y + basePos.y), color(51,133,198), w/6, h/7, 0.2, color(66,121,163), color(14,154