Search in sources :

Example 1 with EditCoeffResult

use of course_generator.dialogs.frmFillCoeff.EditCoeffResult in project Course_Generator by patrovite.

the class frmMain method Create_MainToolbar.

/**
 * Create the Main toolbar
 */
private void Create_MainToolbar() {
    ToolBarMain = new javax.swing.JToolBar();
    ToolBarMain.setFloatable(false);
    ToolBarMain.setRollover(true);
    // -- Open GPX
    // ----------------------------------------------------------
    btOpenGPX = new javax.swing.JButton();
    btOpenGPX.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/openGPX.png")));
    btOpenGPX.setToolTipText(bundle.getString("frmMain.btOpenGPX.toolTipText"));
    btOpenGPX.setFocusable(false);
    btOpenGPX.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            OpenGPXDialog();
        }
    });
    ToolBarMain.add(btOpenGPX);
    // -- Open CGX
    // ----------------------------------------------------------
    btOpenCGX = new javax.swing.JButton();
    btOpenCGX.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/openCGX.png")));
    btOpenCGX.setToolTipText(bundle.getString("frmMain.btOpenCGX.toolTipText"));
    btOpenCGX.setFocusable(false);
    btOpenCGX.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            OpenCGXDialog();
        }
    });
    ToolBarMain.add(btOpenCGX);
    // -- Separator
    // ---------------------------------------------------------
    ToolBarMain.add(new javax.swing.JToolBar.Separator());
    // -- Save CGX
    // ----------------------------------------------------------
    btSaveCGX = new javax.swing.JButton();
    btSaveCGX.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/saveCGX.png")));
    btSaveCGX.setToolTipText(bundle.getString("frmMain.btSaveCGX.toolTipText"));
    btSaveCGX.setFocusable(false);
    btSaveCGX.setEnabled(false);
    btSaveCGX.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            SaveCGX();
        }
    });
    ToolBarMain.add(btSaveCGX);
    // -- Separator
    // ---------------------------------------------------------
    ToolBarMain.add(new javax.swing.JToolBar.Separator());
    // -- Undo
    // --------------------------------------------------------------
    btUndo = new javax.swing.JButton();
    btUndo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/undo.png")));
    btUndo.setToolTipText(bundle.getString("frmMain.btUndo.toolTipText"));
    btUndo.setFocusable(false);
    btUndo.setEnabled(false);
    btUndo.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            RestoreInCGX();
        }
    });
    ToolBarMain.add(btUndo);
    // -- Separator
    // ---------------------------------------------------------
    ToolBarMain.add(new javax.swing.JToolBar.Separator());
    // -- Search
    // ------------------------------------------------------------
    btSearch = new javax.swing.JButton();
    btSearch.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/search.png")));
    btSearch.setToolTipText(bundle.getString("frmMain.btSearch.toolTipText"));
    btSearch.setFocusable(false);
    btSearch.setEnabled(false);
    btSearch.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            SearchPointDialog();
        }
    });
    ToolBarMain.add(btSearch);
    // -- Previous mark
    // -----------------------------------------------------
    btGotoPreviousMark = new javax.swing.JButton();
    btGotoPreviousMark.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/prev.png")));
    btGotoPreviousMark.setToolTipText(bundle.getString("frmMain.btGotoPreviousMark.toolTipText"));
    btGotoPreviousMark.setFocusable(false);
    btGotoPreviousMark.setEnabled(false);
    btGotoPreviousMark.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            int p = GoToPreviousMark();
            if ((p >= 0) && (p < Track.data.size())) {
                panelMap.RefreshCurrentPosMarker(Track.data.get(p).getLatitude(), Track.data.get(p).getLongitude());
            }
        }
    });
    ToolBarMain.add(btGotoPreviousMark);
    // -- Next mark
    // ---------------------------------------------------------
    btGotoNextMark = new javax.swing.JButton();
    btGotoNextMark.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/next.png")));
    btGotoNextMark.setToolTipText(bundle.getString("frmMain.btGotoNextMark.toolTipText"));
    btGotoNextMark.setFocusable(false);
    btGotoNextMark.setEnabled(false);
    btGotoNextMark.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            int p = GoToNextMark();
            if ((p >= 0) && (p < Track.data.size())) {
                panelMap.RefreshCurrentPosMarker(Track.data.get(p).getLatitude(), Track.data.get(p).getLongitude());
            }
        }
    });
    ToolBarMain.add(btGotoNextMark);
    // -- Separator
    // ---------------------------------------------------------
    ToolBarMain.add(new javax.swing.JToolBar.Separator());
    // -- Mini roadbook
    // ------------------------------------------------
    btMiniRoadbook = new javax.swing.JButton();
    btMiniRoadbook.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/profil.png")));
    btMiniRoadbook.setToolTipText(bundle.getString("frmMain.btMiniRoadbook.toolTipText"));
    btMiniRoadbook.setFocusable(false);
    btMiniRoadbook.setEnabled(false);
    btMiniRoadbook.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            ShowMRB();
        }
    });
    ToolBarMain.add(btMiniRoadbook);
    // -- Display S/S curves
    // ------------------------------------------------
    btDisplaySSCurves = new javax.swing.JButton();
    btDisplaySSCurves.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/curve.png")));
    btDisplaySSCurves.setToolTipText(bundle.getString("frmMain.btDisplaySSCurves.toolTipText"));
    btDisplaySSCurves.setFocusable(false);
    btDisplaySSCurves.setEnabled(false);
    btDisplaySSCurves.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            EditSSCurves();
        }
    });
    ToolBarMain.add(btDisplaySSCurves);
    // -- Track settings
    // ----------------------------------------------------
    btTrackSettings = new javax.swing.JButton();
    btTrackSettings.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/settings.png")));
    btTrackSettings.setToolTipText(bundle.getString("frmMain.btTrackSettings.toolTipText"));
    btTrackSettings.setFocusable(false);
    btTrackSettings.setEnabled(false);
    btTrackSettings.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            TrackSettings();
        }
    });
    ToolBarMain.add(btTrackSettings);
    // -- Separator
    // ---------------------------------------------------------
    ToolBarMain.add(new javax.swing.JToolBar.Separator());
    // -- Fill difficulty
    // ----------------------------------------------------
    btFillDiff = new javax.swing.JButton();
    btFillDiff.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/fill_diff.png")));
    btFillDiff.setToolTipText(bundle.getString("frmMain.btFillDiff.toolTipText"));
    btFillDiff.setFocusable(false);
    btFillDiff.setEnabled(false);
    btFillDiff.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (Track.data.isEmpty())
                return;
            int start = panelTrackData.getSelectedRow();
            int end = start + panelTrackData.getSelectedRowCount();
            frmFillDiff frm = new frmFillDiff();
            EditDiffResult res = frm.showDialog(Settings, Track, start, end);
            if (res.Valid) {
                BackupInCGX();
                for (int i = res.Start; i <= res.End; i++) {
                    Track.data.get(i).setDiff(res.Difficulty);
                }
                Track.isCalculated = false;
                Track.isModified = true;
                panelTrackData.refresh();
                panelProfil.RefreshProfilChart();
                jPanelTimeDist.Refresh(Track, Settings);
                jPanelSpeed.Refresh(Track, Settings);
                jPanelSpeedSlope.Refresh(Track, Settings);
                RefreshStatusbar(Track);
            }
        }
    });
    ToolBarMain.add(btFillDiff);
    // -- Fill coeff
    // ----------------------------------------------------
    btFillCoeff = new javax.swing.JButton();
    btFillCoeff.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/tiredness.png")));
    btFillCoeff.setToolTipText(bundle.getString("frmMain.btFillCoeff.toolTipText"));
    btFillCoeff.setFocusable(false);
    btFillCoeff.setEnabled(false);
    btFillCoeff.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (Track.data.size() <= 0)
                return;
            int start = panelTrackData.getSelectedRow();
            int end = start + panelTrackData.getSelectedRowCount();
            frmFillCoeff frm = new frmFillCoeff();
            EditCoeffResult res = frm.showDialog(Settings, Track, start, end);
            if (res.Valid) {
                BackupInCGX();
                if (res.Start == res.End) {
                    Track.data.get(res.Start).setCoeff(res.Start_Coeff);
                } else {
                    double x1 = Track.data.get(res.Start).getTotal(// cd.data[frm.start].Total;
                    CgConst.UNIT_METER);
                    // frm.startval;
                    double y1 = res.Start_Coeff;
                    double x2 = Track.data.get(res.End).getTotal(// cd.data[frm.end].Total;
                    CgConst.UNIT_METER);
                    // frm.endval;
                    double y2 = res.End_Coeff;
                    CalcLineResult rc = new CalcLineResult();
                    rc = Utils.CalcLine(x1, y1, x2, y2, rc);
                    // Line equation calc with "Y"=distance and "X"=Coeff
                    double x = 0.0;
                    double offset = 0.0;
                    double coeff = 0;
                    for (int i = res.Start; i <= res.End; i++) {
                        x = Track.data.get(i).getTotal(CgConst.UNIT_METER);
                        offset = offset + Track.data.get(i).getRecovery();
                        coeff = (rc.a * x + rc.b) + offset;
                        // Validity tests
                        if (coeff > CgConst.MAX_COEFF)
                            coeff = CgConst.MAX_COEFF;
                        if (coeff < 0)
                            coeff = 0;
                        Track.data.get(i).setCoeff(coeff);
                    }
                }
                Track.isCalculated = false;
                Track.isModified = true;
                panelTrackData.refresh();
                panelProfil.RefreshProfilChart();
                jPanelTimeDist.Refresh(Track, Settings);
                jPanelSpeed.Refresh(Track, Settings);
                jPanelSpeedSlope.Refresh(Track, Settings);
                RefreshStatusbar(Track);
            }
        }
    });
    ToolBarMain.add(btFillCoeff);
    // -- Separator
    // ---------------------------------------------------------
    ToolBarMain.add(new javax.swing.JToolBar.Separator());
    // -- Calculate track time
    // ----------------------------------------------
    btCalculateTrackTime = new javax.swing.JButton();
    btCalculateTrackTime.setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/refresh.png")));
    btCalculateTrackTime.setToolTipText(bundle.getString("frmMain.btCalculateTrackTime.toolTipText"));
    btCalculateTrackTime.setFocusable(false);
    btCalculateTrackTime.setEnabled(false);
    btCalculateTrackTime.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            CalcTrackTime();
        }
    });
    ToolBarMain.add(btCalculateTrackTime);
}
Also used : EditDiffResult(course_generator.dialogs.frmFillDiff.EditDiffResult) JButton(javax.swing.JButton) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) course_generator.dialogs.frmFillCoeff(course_generator.dialogs.frmFillCoeff) EditCoeffResult(course_generator.dialogs.frmFillCoeff.EditCoeffResult) ImageIcon(javax.swing.ImageIcon) CalcLineResult(course_generator.utils.Utils.CalcLineResult) course_generator.dialogs.frmFillDiff(course_generator.dialogs.frmFillDiff)

Aggregations

course_generator.dialogs.frmFillCoeff (course_generator.dialogs.frmFillCoeff)1 EditCoeffResult (course_generator.dialogs.frmFillCoeff.EditCoeffResult)1 course_generator.dialogs.frmFillDiff (course_generator.dialogs.frmFillDiff)1 EditDiffResult (course_generator.dialogs.frmFillDiff.EditDiffResult)1 CalcLineResult (course_generator.utils.Utils.CalcLineResult)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ImageIcon (javax.swing.ImageIcon)1 JButton (javax.swing.JButton)1