All pastes #464860 Raw Edit

hubris

public java v1 · immutable
#464860 ·published 2007-04-29 19:23 UTC
rendered paste body
package nl.ru.ai.tekenprogramma;/* * Created on Jan 31, 2006 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.Point;import java.awt.Polygon;import java.awt.Shape;import java.awt.Stroke;import java.awt.event.KeyEvent;import java.awt.event.MouseEvent;import java.awt.event.MouseWheelEvent;import java.awt.geom.Ellipse2D;import java.awt.geom.Line2D;import java.awt.geom.Point2D;import java.util.Random;import java.lang.Enum;import nl.ru.nici.cai.practica.DrawingCanvas;/** * @author dwillems * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */public class Tekenprogramma extends DrawingCanvas {    /* some predefined colors */	static final Color DRED = new Color(139, 0, 0);    static final Color LRED = new Color(255, 0, 0);    static final Color ORANGE = new Color(255, 127, 0);    static final Color YELLOW = new Color(255, 255, 0);    static final Color LGREEN = new Color(127, 255, 0);    static final Color GREEN = new Color(0, 255, 0);    static final Color DGREEN = new Color(0, 139, 0);    static final Color SEABLUE = new Color(70, 130, 180);    static final Color BLUE = new Color(0, 0, 255);    static final Color LBLUE = new Color(0, 191, 255);    static final Color LOTHBLUE = new Color(221, 225, 250);    static final Color MAGENTA = new Color(255, 0, 255);    static final Color PINK = new Color(255, 181, 197);    static final Color WHITE = new Color(255, 255, 255);    static final Color LGREY = new Color(230, 230, 230);    static final Color BUTTONGREY = new Color (199, 199, 199);    static final Color MGREY = new Color(166, 166, 166);    static final Color GREY = new Color(99, 99, 99);    static final Color BLACK = new Color(0, 0, 0);    private Color[] colors = {BUTTONGREY, ORANGE, LRED, DRED, YELLOW, LGREEN, DGREEN, PINK, MAGENTA, BLUE, WHITE, GREY, BLACK};	    private Shape draggingShape = null;    private Point2D dragoffset = null;    private int runningz = 0, base_menu_z = 1000, layer_z = base_menu_z + 130;        /* Dit is de geselecteerde shape!!11     * De oude gegevens van de stroke worden ook opgeslagen.    */    private Shape selectedShape = null;    private int ss_old_stroke_width = 1;    private Color ss_old_stroke_color;        /* modus:     * 0 = Uitleg     * 1 = Voor/na meting     * 2 = Meten!    */    private int modus = 0;        /* Test:     * Het nummer van de test (per persoon). Loopt van 1 - 20.    */    private int test = 0;        /* Testvariabelen     * Enkele vars om gegevens op te slaan    */    private double[] tijden = new double [30];    private int[] straal = new int [30];   		public Tekenprogramma() {        super();        init_vars();                werkomgeving();    }    /* Onze Code */		public void init_vars() {	    for (int i = 0; i < 31; i++) {	    	tijden[i] = -1;	    	straal[i] = -1;	    }	}        public void werkomgeving(){    	teken_omgeving();    	    }        public void info() {    	// Achtergrond voor infobalkje    	Shape achtergrond = addRectangle(0, 500, 1000, 100, 1);        this.setFillColorForShape(LOTHBLUE, achtergrond);        this.setNormalStrokeForShape(2,achtergrond);        this.setLineColorForShape(BLUE, achtergrond);                        int test = 8;        Shape procentbalk = addRectangle(550, 535, 400, 30, 2);        this.setFillColorForShape(GREY, procentbalk);        this.setNormalStrokeForShape(2,procentbalk);        this.setLineColorForShape(BLACK, procentbalk);                Shape voortgang = addRectangle(551, 536, (398/20)*test, 28, 3);        this.setFillColorForShape(MGREY, voortgang);        this.setNormalStrokeForShape(0,voortgang);        this.setLineColorForShape(BLUE, voortgang);                Shape percentage = addRectangle(750, 550 , 0, 0, 4);        this.setLabel(test*5 + "% voltooid", "Courier", Font.BOLD, 18, percentage);        this.setFillColorForShape(LGREY, percentage);        this.setNormalStrokeForShape(0,percentage);        this.setLineColorForShape(BLACK, percentage);    }        public void teken_omgeving() {    	int straal = 40;    	// dit is een werkomgevingetje.    	Ellipse2D startknop = addCircle(80, 250, 40, 101);         this.setLabel("Start", "Courier", Font.BOLD, 18, startknop);        this.setFillColorForShape(ORANGE, startknop);                Ellipse2D eindknop = addCircle(720, 250, 40, 102);         this.setLabel("EIND", "Courier", Font.BOLD, 18, eindknop);        this.setFillColorForShape(ORANGE, eindknop);                info();        repaint();    }        public void nieuwe_setup() {    	Random rnd = new Random();                        Shape start = this.getShapeAtPosition(80, 250);        Shape stop = this.getShapeAtPosition(720, 250);        this.setFillColorForShape(ORANGE, start);        this.removeShape(stop);        Ellipse2D nwstop = addCircle(720, 250, (int)((80 - 3 + 1) * Math.random() + 3), 102);         this.setLabel("EIND", "Courier", Font.BOLD, 18, nwstop);        this.setFillColorForShape(ORANGE, nwstop);        repaint();    	    }        public void start_meting(Shape shape) {    	modus = 2;		this.setFillColorForShape(GREEN, shape);    	System.out.println("START!");    	repaint();    }        public void stop_meting(Shape shape) {    	modus = 1;		this.setFillColorForShape(LRED, shape);    	System.out.println("STOP!");    	nieuwe_setup();    	repaint();    }            /* (non-Javadoc)     * @see java.awt.event.MouseWheelListener#mouseWheelMoved(java.awt.event.MouseWheelEvent)     */    public void mouseWheelMoved(MouseWheelEvent e) {        // TODO Auto-generated method stub    	    }    /* (non-Javadoc)     * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)     */    public void mouseClicked(MouseEvent e) {    }    /* (non-Javadoc)     * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)     */    public void mousePressed(MouseEvent e) {    	Shape shape = this.getShapeAtPosition(e.getPoint());    	if (shape != null) { // als er een shape is geselecteerd    		int shp_z = (int)this.getZPosition(shape);     		if (shp_z == 102 && modus == 2) {    			stop_meting(shape);    		}    	}     }    /* (non-Javadoc)     * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)     */    public void mouseReleased(MouseEvent e) {        //System.out.println("Mouse Released at position " + e.getPoint() +        //                   " clickcount:" + e.getClickCount() + " kleur: " + fill_color + " & " + line_color);    	Shape shape = this.getShapeAtPosition(e.getPoint());    	if (shape != null) { // als er een shape is geselecteerd    		int shp_z = (int)this.getZPosition(shape);     		if (shp_z == 101 && modus < 2) {    			start_meting(shape);    		}    		System.out.println("Mouse Released at position " + e.getPoint() +                    " clickcount:" + e.getClickCount() + " Z: " + shp_z);    	}    }    /* (non-Javadoc)     * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)     */    public void mouseEntered(MouseEvent e) {        // TODO Auto-generated method stub    	    }    /* (non-Javadoc)     * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)     */    public void mouseExited(MouseEvent e) {    }    /* (non-Javadoc)     * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)     */    public void mouseDragged(MouseEvent e) {    	/* System.out.println("Mouse Released at position " + e.getPoint() +                " clickcount:" + e.getClickCount() + " DRAGGED! ");         */    }    /* (non-Javadoc)     * @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)     */    public void mouseMoved(MouseEvent e) {        // TODO Auto-generated method stub    }    public void keyPressed(KeyEvent e) {    }    public void keyReleased(KeyEvent e) {    }    public void keyTyped(KeyEvent e) {    }    public void sampleButton() {        Shape[] shapes = this.getSortedShapes();        Shape oldShape = null;        runningz++;        //Shape shape = this.addTextShape(e.getPoint().x,e.getPoint().y,"Hello World","Courier",Font.BOLD,94,1.0f);        Shape shape = addRectangle(50, 50, 100, 53, runningz);        this.setLabel("Button", "Courier", Font.BOLD, 18, shape);        //this.setDashedStrokeForShape(5,12,12,shape);        Random rnd = new Random();        this.setFillColorForShape(new Color(rnd.nextFloat(), rnd.nextFloat(),                                            rnd.nextFloat(), rnd.nextFloat()),                                  shape);        this.applyTransformation(shape);        if (oldShape != null) {            shape = this.addUnionOfShapes(oldShape, shape, runningz);        }        //this.addRotation((float)(rnd.nextFloat()*Math.PI),e.getPoint().x,e.getPoint().y,shape);        //this.addTranslation(100,100,shape);        repaint();    }        public static void main(String[] args) { // hier is je main!        Tekenprogramma test = new Tekenprogramma();        test.setPreferredSize(new Dimension(1000, 600));        Tekenprogramma.createFrame(test);    }}