rod_design_compute.ShowPanel.java Source code

Java tutorial

Introduction

Here is the source code for rod_design_compute.ShowPanel.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package rod_design_compute;

import com.sun.glass.events.MouseEvent;
import java.awt.*;
import java.util.*;
import javafx.scene.chart.NumberAxis;
import javax.swing.*;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.time.Month;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.time.Year;
import org.jfree.data.xy.DefaultXYDataset;
import org.jfree.data.xy.XYDataset;

/**
 *
 * @author 
 */
public class ShowPanel extends javax.swing.JPanel {

    /**
     * Creates new form ShowPanel
     */
    MainFrame parent;
    private int originX;
    private int originY;
    private double ratio;

    //?
    int radiusBase;
    int lengthSlider;
    int lengthBlock;
    int minDistance;
    int radiusBaseDefault;
    int lengthSliderDefault;
    int lengthBlockDefault;

    int mouseX = 0;
    int mouseY = 0;
    int mouseStatus = NONE;

    Point choosePoint = null;
    Rod chooseRod = null;
    Point chooseRodPoint1 = null; //??
    Point chooseRodPoint2 = null;
    int chooseIndex = -1; ///???
    RodGroup chooseRodGroup = null;

    public final static int NONE = 0;
    public final static int LEFT = 1;
    public final static int RIGHT = 2;

    public ShowPanel() {
        initComponents();
    }

    public ShowPanel(MainFrame parent) {
        initComponents();
        setBackground(Color.white);
        setBorder(BorderFactory.createLineBorder(Color.blue, (int) 2.0));
        this.parent = parent;
        originX = 100;
        originY = 560 - 100;
        ratio = 1.0;
        radiusBase = 5;
        lengthSlider = 200;
        lengthBlock = 50;
        radiusBaseDefault = 5;
        lengthSliderDefault = 200;
        lengthBlockDefault = 50;
        minDistance = 15;
        jLabelThu.setOpaque(true);
    }

    public void reset() {
        originX = 100;
        originY = 560 - 100;
        ratio = 1.0;
        setCursor(Cursor.getDefaultCursor());
        choosePoint = null;
        chooseRod = null;
        repaint();
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);

        g.drawLine(originX, originY, originX + 50, originY);
        g.drawLine(originX + 50, originY, originX + 40, originY + 10);
        g.drawLine(originX + 50, originY, originX + 40, originY - 10);
        g.drawLine(originX, originY, originX, originY - 50);
        g.drawLine(originX, originY - 50, originX + 10, originY - 40);
        g.drawLine(originX, originY - 50, originX - 10, originY - 40);

        for (int i = 0; i < parent.arrayRodGroup.size(); i++) {
            switch (parent.arrayRodGroup.get(i).getType()) {
            case RodGroup.SR:
                paintSR((SR) parent.arrayRodGroup.get(i), g);
                break;
            case RodGroup.RRR:
                paintRRR((RRR) parent.arrayRodGroup.get(i), g);
                break;
            case RodGroup.RRP:
                paintRRP((RRP) parent.arrayRodGroup.get(i), g);
                break;
            default:
                break;
            }
        }

        if (choosePoint != null) {
            drawChoosePoint(choosePoint, g);
        } else if (chooseRod != null) {
            drawChooseRod(chooseRodPoint1, chooseRodPoint2, g);
        }
    }

    private void paintSR(SR rodSR, Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setStroke(new BasicStroke(2f));

        if (rodSR.flag == true) {
            g2d.setColor(Color.red);
            g.drawLine(toScreenX(rodSR.getPointA().X), toScreenY(rodSR.getPointA().Y),
                    toScreenX(rodSR.getPointE().X), toScreenY(rodSR.getPointE().Y));
            g.drawLine(toScreenX(rodSR.getPointB().X), toScreenY(rodSR.getPointB().Y),
                    toScreenX(rodSR.getPointE().X), toScreenY(rodSR.getPointE().Y));
            drawOtherPoint(rodSR.getPointE(), g);
            g2d.setColor(Color.black);
        }

        g2d.setColor(Color.green);
        g.drawLine(toScreenX(rodSR.getPointA().X), toScreenY(rodSR.getPointA().Y), toScreenX(rodSR.getPointB().X),
                toScreenY(rodSR.getPointB().Y));
        g2d.setColor(Color.black);

        drawBasePoint(rodSR.getPointA(), g);
        drawJunctionPoint(rodSR.getPointB(), g);
    }

    private void paintRRR(RRR rodRRR, Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setStroke(new BasicStroke(2f));

        if (rodRRR.flag2 == true || rodRRR.flag3 == true) {
            g2d.setColor(Color.red);
            if (rodRRR.flag2 == true) {
                g.drawLine(toScreenX(rodRRR.getPointB().X), toScreenY(rodRRR.getPointB().Y),
                        toScreenX(rodRRR.getPointE().X), toScreenY(rodRRR.getPointE().Y));
            } else if (rodRRR.flag3 == true) {
                g.drawLine(toScreenX(rodRRR.getPointD().X), toScreenY(rodRRR.getPointD().Y),
                        toScreenX(rodRRR.getPointE().X), toScreenY(rodRRR.getPointE().Y));
            }
            g.drawLine(toScreenX(rodRRR.getPointC().X), toScreenY(rodRRR.getPointC().Y),
                    toScreenX(rodRRR.getPointE().X), toScreenY(rodRRR.getPointE().Y));
            drawOtherPoint(rodRRR.getPointE(), g);
            g2d.setColor(Color.black);
        }

        g.drawLine(toScreenX(rodRRR.getPointB().X), toScreenY(rodRRR.getPointB().Y),
                toScreenX(rodRRR.getPointC().X), toScreenY(rodRRR.getPointC().Y));

        g.drawLine(toScreenX(rodRRR.getPointC().X), toScreenY(rodRRR.getPointC().Y),
                toScreenX(rodRRR.getPointD().X), toScreenY(rodRRR.getPointD().Y));

        drawJunctionPoint(rodRRR.getPointB(), g);
        drawJunctionPoint(rodRRR.getPointC(), g);
        drawBasePoint(rodRRR.getPointD(), g);
    }

    private void paintRRP(RRP rodRRP, Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setStroke(new BasicStroke(2f));

        drawSlider(rodRRP.getrodslider(), rodRRP.getPointC(), g);

        drawBlock(rodRRP.getrodslider(), rodRRP.getPointC(), g);

        g.drawLine(toScreenX(rodRRP.getPointB().X), toScreenY(rodRRP.getPointB().Y),
                toScreenX(rodRRP.getPointC().X), toScreenY(rodRRP.getPointC().Y));

        drawJunctionPoint(rodRRP.getPointB(), g);
        drawJunctionPoint(rodRRP.getPointC(), g);
    }

    private int toScreenX(double x) {
        return (int) (ratio * x + originX);
    }

    private int toScreenY(double y) {
        return (int) (originY - ratio * y);
    }

    private void drawBasePoint(Point point, Graphics g) {
        int x = toScreenX(point.X);
        int y = toScreenY(point.Y);

        int lengthTri = 4 * radiusBase;
        int x1 = (int) (x - lengthTri * Math.sin(Math.toRadians(30)));
        int y1 = (int) (y + lengthTri * Math.cos(Math.toRadians(30)));
        int x2 = (int) (x + lengthTri * Math.sin(Math.toRadians(30)));
        int y2 = (int) (y + lengthTri * Math.cos(Math.toRadians(30)));

        g.drawLine(x, y, x1, y1);
        g.drawLine(x, y, x2, y2);
        g.drawLine(x1 - radiusBase, y1, x2 + radiusBase, y2);

        g.drawLine(x1, y1, x1 - radiusBase, y1 + radiusBase);
        g.drawLine(x1 + radiusBase, y1, x1 + radiusBase - radiusBase, y1 + radiusBase);
        g.drawLine(x1 + 2 * radiusBase, y1, x1 + 2 * radiusBase - radiusBase, y1 + radiusBase);
        g.drawLine(x1 + 3 * radiusBase, y1, x1 + 3 * radiusBase - radiusBase, y1 + radiusBase);
        g.drawLine(x1 + 4 * radiusBase, y1, x1 + 4 * radiusBase - radiusBase, y1 + radiusBase);

        g.setColor(Color.white);
        g.fillOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2);
        g.setColor(Color.black);
        g.drawOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2);
    }

    private void drawJunctionPoint(Point point, Graphics g) {
        int x = toScreenX(point.X);
        int y = toScreenY(point.Y);

        g.setColor(Color.white);
        g.fillOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2);
        g.setColor(Color.black);
        g.drawOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2);
    }

    private void drawOtherPoint(Point point, Graphics g) {
        int x = toScreenX(point.X);
        int y = toScreenY(point.Y);

        g.setColor(Color.white);
        g.fillOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2);
        g.setColor(Color.red);
        g.drawOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2);
    }

    private void drawChoosePoint(Point point, Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setStroke(new BasicStroke(2f));

        int x = toScreenX(point.X);
        int y = toScreenY(point.Y);

        g.setColor(Color.blue);
        g.fillOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2);
    }

    private void drawChooseRod(Point a, Point b, Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setStroke(new BasicStroke(2f));

        g.setColor(Color.blue);
        g.drawLine(toScreenX(a.X), toScreenY(a.Y), toScreenX(b.X), toScreenY(b.Y));
    }

    private void drawSlider(Rod rod, Point point, Graphics g) {
        int[] x = new int[3];
        int[] y = new int[3];
        int l = lengthSlider;
        double theta = rod.getAngle();

        x[0] = (int) (Math.cos(theta) * l / 2);
        y[0] = (int) (Math.sin(theta) * l / 2);
        x[1] = -x[0];
        y[1] = -y[0];

        theta += Math.toRadians(45);
        x[2] = (int) (Math.cos(theta) * l / 10);
        y[2] = (int) (Math.sin(theta) * l / 10);

        for (int i = 0; i < 2; i++) {
            x[i] = toScreenX(point.X) + x[i];
            y[i] = toScreenY(point.Y) - y[i];
        }

        g.drawLine(x[0], y[0], x[1], y[1]);
        g.drawLine((int) (0.9 * x[0] + 0.1 * x[1]), (int) (0.9 * y[0] + 0.1 * y[1]),
                (int) (0.9 * x[0] + 0.1 * x[1] + x[2]), (int) (0.9 * y[0] + 0.1 * y[1] + y[2]));
        g.drawLine((int) (0.8 * x[0] + 0.2 * x[1]), (int) (0.8 * y[0] + 0.2 * y[1]),
                (int) (0.8 * x[0] + 0.2 * x[1] + x[2]), (int) (0.8 * y[0] + 0.2 * y[1] + y[2]));
        g.drawLine((int) (0.1 * x[0] + 0.9 * x[1]), (int) (0.1 * y[0] + 0.9 * y[1]),
                (int) (0.1 * x[0] + 0.9 * x[1] + x[2]), (int) (0.1 * y[0] + 0.9 * y[1] + y[2]));
        g.drawLine((int) (0.2 * x[0] + 0.8 * x[1]), (int) (0.2 * y[0] + 0.8 * y[1]),
                (int) (0.2 * x[0] + 0.8 * x[1] + x[2]), (int) (0.2 * y[0] + 0.8 * y[1] + y[2]));
    }

    private void drawBlock(Rod rod, Point point, Graphics g) {
        int[] x = new int[4];
        int[] y = new int[4];
        int l = lengthBlock;
        double theta = rod.getAngle();

        x[0] = (int) ((2 * Math.cos(theta) + Math.sin(theta)) * l / 4);
        y[0] = (int) ((2 * Math.sin(theta) - Math.cos(theta)) * l / 4);
        x[1] = (int) ((2 * Math.cos(theta) - Math.sin(theta)) * l / 4);
        y[1] = (int) ((2 * Math.sin(theta) + Math.cos(theta)) * l / 4);
        x[2] = -x[0];
        y[2] = -y[0];
        x[3] = -x[1];
        y[3] = -y[1];

        Polygon block = new Polygon();
        for (int i = 0; i < 4; i++) {
            x[i] = toScreenX(point.X) + x[i];
            y[i] = toScreenY(point.Y) - y[i];
            block.addPoint(x[i], y[i]);
        }

        g.setColor(Color.white);
        g.fillPolygon(block);
        g.setColor(Color.black);
        g.drawPolygon(block);
    }

    private void chartPoint() {
        DefaultXYDataset dataset1 = new DefaultXYDataset();
        DefaultXYDataset dataset2 = new DefaultXYDataset();
        DefaultXYDataset dataset3 = new DefaultXYDataset();
        DefaultXYDataset dataset4 = new DefaultXYDataset();
        DefaultXYDataset dataset5 = new DefaultXYDataset();
        DefaultXYDataset dataset6 = new DefaultXYDataset();
        DefaultXYDataset dataset7 = new DefaultXYDataset();
        DefaultXYDataset dataset8 = new DefaultXYDataset();

        Point indicator = null;
        chooseRodGroup = parent.arrayRodGroup.get(chooseIndex);

        int amount;
        if (parent.upperLimit == -1)
            amount = parent.resolution;
        else
            amount = parent.upperLimit;

        double[][][] data = new double[8][2][amount];
        for (int i = 0; i < amount; i++) {
            for (int j = 0; j < 8; j++)
                data[j][0][i] = i;
            if (chooseRodGroup.getType() == RodGroup.SR) {
                if (choosePoint == ((SR) (chooseRodGroup)).getPointA())
                    indicator = ((SR) (parent.arrayRecord.get(i).get(chooseIndex))).getPointA();
                else if (choosePoint == ((SR) (chooseRodGroup)).getPointB())
                    indicator = ((SR) (parent.arrayRecord.get(i).get(chooseIndex))).getPointB();
                else if (((SR) (chooseRodGroup)).flag == true) {
                    if (choosePoint == ((SR) (chooseRodGroup)).getPointE())
                        indicator = ((SR) (parent.arrayRecord.get(i).get(chooseIndex))).getPointE();
                }
            } else if (chooseRodGroup.getType() == RodGroup.RRR) {
                if (choosePoint == ((RRR) (chooseRodGroup)).getPointB())
                    indicator = ((RRR) (parent.arrayRecord.get(i).get(chooseIndex))).getPointB();
                else if (choosePoint == ((RRR) (chooseRodGroup)).getPointC())
                    indicator = ((RRR) (parent.arrayRecord.get(i).get(chooseIndex))).getPointC();
                else if (choosePoint == ((RRR) (chooseRodGroup)).getPointD())
                    indicator = ((RRR) (parent.arrayRecord.get(i).get(chooseIndex))).getPointD();
                else if (((RRR) (chooseRodGroup)).flag2 == true || ((RRR) (chooseRodGroup)).flag3 == true) {
                    if (choosePoint == ((RRR) (chooseRodGroup)).getPointE())
                        indicator = ((RRR) (parent.arrayRecord.get(i).get(chooseIndex))).getPointE();
                }
            } else if (chooseRodGroup.getType() == RodGroup.RRP) {
                if (choosePoint == ((RRP) (chooseRodGroup)).getPointB())
                    indicator = ((RRP) (parent.arrayRecord.get(i).get(chooseIndex))).getPointB();
                else if (choosePoint == ((RRP) (chooseRodGroup)).getPointC())
                    indicator = ((RRP) (parent.arrayRecord.get(i).get(chooseIndex))).getPointC();
            }
            getPointData(data, indicator, i);
        }

        dataset1.addSeries("Vx", data[0]);
        dataset2.addSeries("Vy", data[1]);
        dataset3.addSeries("V", data[2]);
        dataset4.addSeries("ax", data[3]);
        dataset5.addSeries("ay", data[4]);
        dataset6.addSeries("a", data[5]);
        dataset7.addSeries("X", data[6]);
        dataset8.addSeries("Y", data[7]);

        JFreeChart chart1 = ChartFactory.createXYLineChart("Vx", "angle()", "Vx", dataset1,
                PlotOrientation.VERTICAL, false, false, false);
        JFreeChart chart2 = ChartFactory.createXYLineChart("Vy", "angle()", "Vy", dataset2,
                PlotOrientation.VERTICAL, false, false, false);
        JFreeChart chart3 = ChartFactory.createXYLineChart("V", "angle()", "V", dataset3,
                PlotOrientation.VERTICAL, false, false, false);
        JFreeChart chart4 = ChartFactory.createXYLineChart("ax", "angle()", "ax", dataset4,
                PlotOrientation.VERTICAL, false, false, false);
        JFreeChart chart5 = ChartFactory.createXYLineChart("ay", "angle()", "ay", dataset5,
                PlotOrientation.VERTICAL, false, false, false);
        JFreeChart chart6 = ChartFactory.createXYLineChart("a", "angle()", "a", dataset6,
                PlotOrientation.VERTICAL, false, false, false);
        JFreeChart chart7 = ChartFactory.createXYLineChart("X", "angle()", "X", dataset7,
                PlotOrientation.VERTICAL, false, false, false);
        JFreeChart chart8 = ChartFactory.createXYLineChart("Y", "angle()", "Y", dataset8,
                PlotOrientation.VERTICAL, false, false, false);

        ChartPanel panel1 = new ChartPanel(chart1);
        ChartPanel panel2 = new ChartPanel(chart2);
        ChartPanel panel3 = new ChartPanel(chart3);
        ChartPanel panel4 = new ChartPanel(chart4);
        ChartPanel panel5 = new ChartPanel(chart5);
        ChartPanel panel6 = new ChartPanel(chart6);
        ChartPanel panel7 = new ChartPanel(chart7);
        ChartPanel panel8 = new ChartPanel(chart8);

        JFrame frame = new JFrame("Chart");
        frame.setLayout(new GridLayout(3, 3, 0, 0));
        frame.add(panel1);
        frame.add(panel2);
        frame.add(panel3);
        frame.add(panel4);
        frame.add(panel5);
        frame.add(panel6);
        frame.add(panel7);
        frame.add(panel8);
        frame.pack();
        frame.setVisible(true);

        choosePoint = null;
    }

    private void chartRod() {
        DefaultXYDataset dataset1 = new DefaultXYDataset();
        DefaultXYDataset dataset2 = new DefaultXYDataset();
        DefaultXYDataset dataset3 = new DefaultXYDataset();

        Rod indicator = null;
        chooseRodGroup = parent.arrayRodGroup.get(chooseIndex);

        int amount;
        if (parent.upperLimit == -1)
            amount = parent.resolution;
        else
            amount = parent.upperLimit;

        double[][][] data = new double[3][2][amount];
        for (int i = 0; i < amount; i++) {
            for (int j = 0; j < 3; j++)
                data[j][0][i] = i;
            if (chooseRodGroup.getType() == RodGroup.SR) {
                if (chooseRod == ((SR) (chooseRodGroup)).getL_dangan())
                    indicator = ((SR) (parent.arrayRecord.get(i).get(chooseIndex))).getL_dangan();
            } else if (chooseRodGroup.getType() == RodGroup.RRR) {
                if (chooseRod == ((RRR) (chooseRodGroup)).getrodL2())
                    indicator = ((RRR) (parent.arrayRecord.get(i).get(chooseIndex))).getrodL2();
                else if (chooseRod == ((RRR) (chooseRodGroup)).getrodL3())
                    indicator = ((RRR) (parent.arrayRecord.get(i).get(chooseIndex))).getrodL3();
            } else if (chooseRodGroup.getType() == RodGroup.RRP) {
                if (chooseRod == ((RRP) (chooseRodGroup)).getrodL2())
                    indicator = ((RRP) (parent.arrayRecord.get(i).get(chooseIndex))).getrodL2();
            }
            getRodData(data, indicator, i);
        }

        dataset1.addSeries("Angle", data[0]);
        dataset2.addSeries("AngleSpeed", data[1]);
        dataset3.addSeries("AngleAcceleration", data[2]);

        JFreeChart chart1 = ChartFactory.createXYLineChart("Angle", "angle()", "Angle(rad)", dataset1,
                PlotOrientation.VERTICAL, false, false, false);
        JFreeChart chart2 = ChartFactory.createXYLineChart("AngleSpeed", "angle()", "AngleSpeed", dataset2,
                PlotOrientation.VERTICAL, false, false, false);
        JFreeChart chart3 = ChartFactory.createXYLineChart("AngleAcceleration", "angle()", "AngleAcceleration",
                dataset3, PlotOrientation.VERTICAL, false, false, false);

        ChartPanel panel1 = new ChartPanel(chart1);
        ChartPanel panel2 = new ChartPanel(chart2);
        ChartPanel panel3 = new ChartPanel(chart3);

        JFrame frame = new JFrame("Chart");
        frame.setLayout(new GridLayout(3, 1, 0, 0));
        frame.add(panel1);
        frame.add(panel2);
        frame.add(panel3);
        frame.pack();
        frame.setVisible(true);

        chooseRod = null;
    }

    private void getPointData(double[][][] data, Point point, int i) {
        data[0][1][i] = point.Vx;
        data[1][1][i] = point.Vy;
        data[2][1][i] = point.velocity;
        data[3][1][i] = point.ax;
        data[4][1][i] = point.ay;
        data[5][1][i] = point.accelerate;
        data[6][1][i] = point.X;
        data[7][1][i] = point.Y;
    }

    private void getRodData(double[][][] data, Rod rod, int i) {
        data[0][1][i] = rod.angle;
        data[1][1][i] = rod.angle_speed;
        data[2][1][i] = rod.angle_acc;
    }

    /**
     * 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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelThu = new javax.swing.JLabel();

        addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                formMouseDragged(evt);
            }

            public void mouseMoved(java.awt.event.MouseEvent evt) {
                formMouseMoved(evt);
            }
        });
        addMouseWheelListener(new java.awt.event.MouseWheelListener() {
            public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
                formMouseWheelMoved(evt);
            }
        });
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }

            public void mousePressed(java.awt.event.MouseEvent evt) {
                formMousePressed(evt);
            }

            public void mouseReleased(java.awt.event.MouseEvent evt) {
                formMouseReleased(evt);
            }
        });

        jLabelThu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/thu1.png"))); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                        layout.createSequentialGroup().addGap(0, 123, Short.MAX_VALUE).addComponent(jLabelThu,
                                javax.swing.GroupLayout.PREFERRED_SIZE, 277,
                                javax.swing.GroupLayout.PREFERRED_SIZE)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addComponent(jLabelThu,
                        javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 310, Short.MAX_VALUE)));
    }// </editor-fold>//GEN-END:initComponents

    private void formMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseMoved
        // TODO add your handling code here:
        if (parent.getStatus() == parent.FOCUS) {
            this.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
            choosePoint = null;
            chooseRod = null;

            for (int i = 0; i < parent.arrayRodGroup.size(); i++) {
                if (choosePoint != null || chooseRod != null)
                    break;
                chooseIndex = i;
                switch (parent.arrayRodGroup.get(i).getType()) {
                case RodGroup.SR:
                    SR sr = (SR) (parent.arrayRodGroup.get(i));
                    if (distance(evt.getX(), evt.getY(), sr.getPointA()) < minDistance)
                        choosePoint = sr.getPointA();
                    else if (distance(evt.getX(), evt.getY(), sr.getPointB()) < minDistance)
                        choosePoint = sr.getPointB();
                    else if (sr.flag == true && distance(evt.getX(), evt.getY(), sr.getPointE()) < minDistance)
                        choosePoint = sr.getPointE();
                    else if (distance(evt.getX(), evt.getY(), sr.getPointA(), sr.getPointB()) < minDistance) {
                        chooseRod = sr.getL_dangan();
                        chooseRodPoint1 = sr.getPointA();
                        chooseRodPoint2 = sr.getPointB();
                    }
                    break;
                case RodGroup.RRR:
                    RRR rrr = (RRR) (parent.arrayRodGroup.get(i));
                    if (distance(evt.getX(), evt.getY(), rrr.getPointB()) < minDistance)
                        choosePoint = rrr.getPointB();
                    else if (distance(evt.getX(), evt.getY(), rrr.getPointC()) < minDistance)
                        choosePoint = rrr.getPointC();
                    else if (distance(evt.getX(), evt.getY(), rrr.getPointD()) < minDistance)
                        choosePoint = rrr.getPointD();
                    else if ((rrr.flag2 == true || rrr.flag3 == true)
                            && distance(evt.getX(), evt.getY(), rrr.getPointE()) < minDistance)
                        choosePoint = rrr.getPointE();
                    else if (distance(evt.getX(), evt.getY(), rrr.getPointB(), rrr.getPointC()) < minDistance) {
                        chooseRod = rrr.getrodL2();
                        chooseRodPoint1 = rrr.getPointB();
                        chooseRodPoint2 = rrr.getPointC();
                    } else if (distance(evt.getX(), evt.getY(), rrr.getPointC(), rrr.getPointD()) < minDistance) {
                        chooseRod = rrr.getrodL3();
                        chooseRodPoint1 = rrr.getPointC();
                        chooseRodPoint2 = rrr.getPointD();
                    }
                    break;
                case RodGroup.RRP:
                    RRP rrp = (RRP) (parent.arrayRodGroup.get(i));
                    if (distance(evt.getX(), evt.getY(), rrp.getPointB()) < minDistance)
                        choosePoint = rrp.getPointB();
                    else if (distance(evt.getX(), evt.getY(), rrp.getPointC()) < minDistance)
                        choosePoint = rrp.getPointC();
                    else if (distance(evt.getX(), evt.getY(), rrp.getPointB(), rrp.getPointC()) < minDistance) {
                        chooseRod = rrp.getrodL2();
                        chooseRodPoint1 = rrp.getPointB();
                        chooseRodPoint2 = rrp.getPointC();
                    }
                    break;
                default:
                    break;
                }
            }
            repaint();
        }

        else
            this.setCursor(Cursor.getDefaultCursor());
    }//GEN-LAST:event_formMouseMoved

    private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
        // TODO add your handling code here:
        if (evt.getButton() == java.awt.event.MouseEvent.BUTTON1) {
            if (parent.getStatus() == parent.FOCUS) {
                if (choosePoint != null)
                    chartPoint();
                else if (chooseRod != null)
                    chartRod();
            }
        }
    }//GEN-LAST:event_formMouseClicked

    private void formMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseDragged
        // TODO add your handling code here:
        if (mouseStatus == RIGHT) {
            originX += (evt.getX() - mouseX);
            originY += (evt.getY() - mouseY);

            mouseX = evt.getX();
            mouseY = evt.getY();

            repaint();
        }

    }//GEN-LAST:event_formMouseDragged

    private void formMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMousePressed
        // TODO add your handling code here:
        if (evt.getButton() == java.awt.event.MouseEvent.BUTTON3) {
            mouseX = evt.getX();
            mouseY = evt.getY();
            mouseStatus = RIGHT;
        }
    }//GEN-LAST:event_formMousePressed

    private void formMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseReleased
        // TODO add your handling code here:
        if (evt.getButton() == java.awt.event.MouseEvent.BUTTON3) {
            mouseStatus = NONE;
        }
    }//GEN-LAST:event_formMouseReleased

    private void formMouseWheelMoved(java.awt.event.MouseWheelEvent evt) {//GEN-FIRST:event_formMouseWheelMoved
        // TODO add your handling code here:
        if (evt.getWheelRotation() > 0) {
            if (ratio >= 0.2) {
                ratio -= 0.1;
                radiusBase = (int) (radiusBaseDefault * ratio);
                lengthSlider = (int) (lengthSliderDefault * ratio);
                lengthBlock = (int) (lengthBlockDefault * ratio);
                repaint();
            }
        } else if (evt.getWheelRotation() < 0) {
            ratio += 0.1;
            radiusBase = (int) (radiusBaseDefault * ratio);
            lengthSlider = (int) (lengthSliderDefault * ratio);
            lengthBlock = (int) (lengthBlockDefault * ratio);
            repaint();
        }
    }//GEN-LAST:event_formMouseWheelMoved

    private double distance(int x, int y, Point p) {
        int px = toScreenX(p.X);
        int py = toScreenY(p.Y);
        return Math.sqrt(Math.pow(px - x, 2) + Math.pow(py - y, 2));
    }

    private double distance(int x, int y, Point a, Point b) {
        int x1 = toScreenX(a.X);
        int y1 = toScreenY(a.Y);
        int x2 = toScreenX(b.X);
        int y2 = toScreenY(b.Y);

        double cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1);
        if (cross <= 0)
            return minDistance + 1.0;

        double d2 = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
        if (cross >= d2)
            return minDistance + 1.0;

        double r = cross / d2;
        double px = x1 + (x2 - x1) * r;
        double py = y1 + (y2 - y1) * r;
        return Math.sqrt((x - px) * (x - px) + (y - py) * (y - py));
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabelThu;
    // End of variables declaration//GEN-END:variables
}