Search in sources :

Example 1 with CgResume

use of course_generator.CgResume in project Course_Generator by patrovite.

the class JPanelResume method refresh.

/**
 * Refresh the resume grid
 *
 * @param force
 */
public void refresh() {
    // Exit if the tab is not displayed
    // if (TabbedPaneMain.getSelectedIndex() != 4) // Resume
    // return;
    // StatusBar.Items["Message"].Visible = true;
    // StatusBar.Items["Message"].Text = "Mise à jour resumé en cours...";
    // StatusBar.Refresh();
    int i = 0;
    int k = 0;
    int old = 0;
    CgData OldData;
    if (Track == null)
        return;
    if (Track.data.isEmpty())
        return;
    CalcClimbResult ccr = new CalcClimbResult();
    CalcAvrSlopeResult casr = new CalcAvrSlopeResult();
    CalcAvrSpeedResult speedResult = new CalcAvrSpeedResult();
    Resume.data.clear();
    OldData = Track.data.get(0);
    for (CgData src : Track.data) {
        if ((src.getTag() & 32) != 0) {
            k++;
            CgResume dst = new CgResume();
            // ResGrid.Rows.Add();
            dst.setNum(k);
            dst.setName(src.getName());
            dst.setLine(src.getNum());
            dst.setElevation(src.getElevation(CgConst.UNIT_METER));
            ccr = Track.CalcClimb(0, i, ccr);
            dst.setClimbP(ccr.cp);
            dst.setClimbM(ccr.cm);
            dst.setDist(src.getTotal(CgConst.UNIT_METER) / 1000.0);
            dst.setTime(src.getTime());
            dst.setHour(src.getHour());
            dst.setTimeLimit(src.getTimeLimit());
            dst.setStationTime(src.getStation());
            dst.setdTime_f(src.getTime() - OldData.getTime());
            dst.setdDist((src.getTotal(CgConst.UNIT_METER) - OldData.getTotal(CgConst.UNIT_METER)) / 1000.0);
            ccr = Track.CalcClimb(old, i, ccr);
            casr = Track.CalcAvrSlope(old, i, casr);
            speedResult = Track.CalcAvrSpeed(old, i, speedResult);
            dst.setdClimbP(ccr.cp);
            dst.setdClimbM(ccr.cm);
            dst.setSpeedP(ccr.cp * 3600 / Math.abs(ccr.tp));
            dst.setSpeedM(ccr.cm * 3600 / Math.abs(ccr.tm));
            // if ((AvrSlopeP == 0) || (Double.IsNaN(AvrSlopeP) ))
            dst.setAvgSlopeP(casr.AvrSlopeP);
            dst.setAvgSlopeM(casr.AvrSlopeM);
            dst.setAvgSpeed(speedResult.getAvrspeed(CgConst.UNIT_METER));
            dst.setComment(src.getComment());
            Resume.data.add(dst);
            OldData = src;
            old = i;
        }
        i++;
    }
    // -- Refresh the grid
    TableResume.invalidate();
}
Also used : CalcClimbResult(course_generator.TrackData.CalcClimbResult) CgResume(course_generator.CgResume) CalcAvrSpeedResult(course_generator.TrackData.CalcAvrSpeedResult) CalcAvrSlopeResult(course_generator.TrackData.CalcAvrSlopeResult) CgData(course_generator.CgData)

Example 2 with CgResume

use of course_generator.CgResume in project Course_Generator by patrovite.

the class ResumeRenderer method getTableCellRendererComponent.

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    CgResume data = (CgResume) value;
    Double val = 0.0;
    String str;
    CgSettings settings = ((ResumeModel) table.getModel()).getSettings();
    setIcon(null);
    // Depending of the column number return the rendered label
    switch(column) {
        case // N°
        0:
            val = data.getNum();
            // -- Display the value
            setText(String.format("%1.0f ", val));
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Name
        1:
            str = data.getName();
            // -- Display the value
            setText(str);
            setHorizontalAlignment(LEFT);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Line
        2:
            val = data.getLine();
            // -- Display the value
            setText(String.format("%1.0f ", val));
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Elevation
        3:
            setText(data.getElevationString(settings.Unit, false));
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Positive climb
        4:
            setText(data.getClimbPString(settings.Unit, false));
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Negative climb
        5:
            setText(data.getClimbMString(settings.Unit, false));
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Distance
        6:
            setText(data.getDistString(settings.Unit, false));
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Time
        7:
            setText(data.getTimeString());
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Hour
        8:
            setText(data.getHourString());
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // dt Time
        9:
            setText(data.getdTime_f_String());
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Time limit
        10:
            setText(data.getTimeLimitString());
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Station Time
        11:
            setText(data.getStationTimeString());
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // dt Distance
        12:
            setText(data.getdDistString(settings.Unit, false));
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // dt positive climb
        13:
            setText(data.getdClimbPString(settings.Unit, false));
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // dt negative climb
        14:
            setText(data.getdClimbMString(settings.Unit, false));
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Ascend speed
        15:
            setText(data.getSpeedPString(settings.Unit, false));
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Descend speed
        16:
            setText(data.getSpeedMString(settings.Unit, false));
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Average ascend slope
        17:
            setText(data.getAvgSlopePString());
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Average descend slope
        18:
            setText(data.getAvgSlopeMString());
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Average speed
        19:
            setText(data.getAvgSpeedString(settings.Unit, false));
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Comment
        20:
            str = data.getComment();
            // -- Display the value
            // TODO Delete /n
            setText(str);
            setHorizontalAlignment(LEFT);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
    }
    return this;
}
Also used : CgResume(course_generator.CgResume) Color(java.awt.Color) CgSettings(course_generator.settings.CgSettings)

Aggregations

CgResume (course_generator.CgResume)2 CgData (course_generator.CgData)1 CalcAvrSlopeResult (course_generator.TrackData.CalcAvrSlopeResult)1 CalcAvrSpeedResult (course_generator.TrackData.CalcAvrSpeedResult)1 CalcClimbResult (course_generator.TrackData.CalcClimbResult)1 CgSettings (course_generator.settings.CgSettings)1 Color (java.awt.Color)1