Search in sources :

Example 16 with CgData

use of course_generator.CgData in project Course_Generator by patrovite.

the class TrackDataRenderer 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);
    CgData data = null;
    CgSettings settings = ((TrackDataModel) table.getModel()).getSettings();
    setIcon(null);
    // Depending of the column number return the rendered label
    switch(column) {
        case // Num
        0:
            data = (CgData) value;
            Double num = data.getNum();
            // -- Set the value
            setText(String.format("%1.0f ", num));
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Latitude
        1:
            data = (CgData) value;
            Double lat = data.getLatitude();
            // -- Set the value
            setText(String.format("%1.7f", lat));
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 242, 193));
            return this;
        case // Longitude
        2:
            data = (CgData) value;
            Double lon = data.getLongitude();
            // -- Set the value
            setText(String.format("%1.7f", lon));
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 242, 193));
            return this;
        case // Elevation
        3:
            data = (CgData) value;
            Double slope = data.getSlope();
            setText(data.getElevationString(settings.Unit, false));
            setHorizontalAlignment(CENTER);
            // -- Set the icon next to the elevation value
            if (slope > 1.0) {
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/up_elev.png")));
            } else if (slope < -1.0) {
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/down_elev.png")));
            } else
                setIcon(new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/same_level_elev.png")));
            // -- Set the color of the background. Color depend of the slope
            // value
            float tmpslope = slope.floatValue();
            Color c = Color.WHITE;
            if (tmpslope > 2.0f) {
                if (tmpslope > 50.0f)
                    tmpslope = 50.0f;
                float vsl = 18.0f * tmpslope / 50.0f;
                c = Color.getHSBColor((18.0f - vsl) / 100.0f, 1f, 1f);
            } else if (tmpslope < -2.0f) {
                tmpslope = -tmpslope;
                if (tmpslope > 50.0f)
                    tmpslope = 50.0f;
                /*
					float vsl = 18f * tmpslope / 50.0f;
					c = Color.getHSBColor((48f + vsl) / 100.0f, 1f, 1f);
					*/
                float vsl = 40f * tmpslope / 50.0f;
                c = Color.getHSBColor(0.35f, 1f, (100f - vsl) / 100f);
            } else
                c = Color.WHITE;
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(c);
            return this;
        case // Tags
        4:
            data = (CgData) value;
            int tag = data.getTag();
            // -- Count the number of active tag
            int cmpt = 0;
            int i = 1;
            while (i < 65536) {
                if ((tag & i) != 0)
                    cmpt++;
                i = i * 2;
            }
            // X position in the resulting image
            int x = 0;
            if (cmpt > 0) {
                // -- Prepare the resulting image
                BufferedImage combined = new BufferedImage(18 * cmpt, 16, BufferedImage.TYPE_INT_ARGB);
                Graphics g = combined.getGraphics();
                // Higher point
                if ((tag & CgConst.TAG_HIGH_PT) != 0) {
                    ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/high_point.png"));
                    g.drawImage(image.getImage(), x, 0, null);
                    x += 18;
                }
                // Lower point
                if ((tag & CgConst.TAG_LOW_PT) != 0) {
                    ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/low_point.png"));
                    g.drawImage(image.getImage(), x, 0, null);
                    x += 18;
                }
                // Station
                if ((tag & CgConst.TAG_EAT_PT) != 0) {
                    ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/eat.png"));
                    g.drawImage(image.getImage(), x, 0, null);
                    x += 18;
                }
                // Drink
                if ((tag & CgConst.TAG_WATER_PT) != 0) {
                    ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/drink.png"));
                    g.drawImage(image.getImage(), x, 0, null);
                    x += 18;
                }
                // Mark
                if ((tag & CgConst.TAG_MARK) != 0) {
                    ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/flag.png"));
                    g.drawImage(image.getImage(), x, 0, null);
                    x += 18;
                }
                // Roadbook
                if ((tag & CgConst.TAG_ROADBOOK) != 0) {
                    ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/roadbook.png"));
                    g.drawImage(image.getImage(), x, 0, null);
                    x += 18;
                }
                // Photo
                if ((tag & CgConst.TAG_COOL_PT) != 0) {
                    ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/photo.png"));
                    g.drawImage(image.getImage(), x, 0, null);
                    x += 18;
                }
                // Note
                if ((tag & CgConst.TAG_NOTE) != 0) {
                    ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/note.png"));
                    g.drawImage(image.getImage(), x, 0, null);
                    x += 18;
                }
                // Info
                if ((tag & CgConst.TAG_INFO) != 0) {
                    ImageIcon image = new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/info.png"));
                    g.drawImage(image.getImage(), x, 0, null);
                    x += 18;
                }
                setIcon(new ImageIcon(combined));
            } else
                // No image
                setIcon(null);
            // -- Set the value
            setText("");
            setHorizontalAlignment(LEFT);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Distance
        5:
            data = (CgData) value;
            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 // Total distance
        6:
            data = (CgData) value;
            Double total = data.getTotal(settings.Unit);
            // -- Set the value
            setText(String.format("%1.3f", total / 1000.0));
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(221, 255, 155));
            return this;
        case // Difficulty
        7:
            data = (CgData) value;
            Double diff = data.getDiff();
            // -- Set the value
            setText(String.format("%1.0f ", diff));
            setHorizontalAlignment(CENTER);
            // -- Set the background color
            Color clDiff = Color.WHITE;
            if ((diff <= CgConst.DIFF_VERYEASY) && (diff > CgConst.DIFF_EASY)) {
                // Color.WHITE; //--
                clDiff = CgConst.CL_DIFF_VERYEASY;
            // paint in white
            } else if ((diff <= CgConst.DIFF_EASY) && (diff > CgConst.DIFF_AVERAGE)) {
                // new Color(170, 212, 0);
                clDiff = CgConst.CL_DIFF_EASY;
            // //-- Paint in green
            } else if ((diff <= CgConst.DIFF_AVERAGE) && (diff > CgConst.DIFF_HARD)) {
                // new Color(85, 153,
                clDiff = CgConst.CL_DIFF_AVERAGE;
            // 255); //-- Paint in
            // blue
            } else if ((diff <= CgConst.DIFF_HARD) && (diff > CgConst.DIFF_VERYHARD)) {
                // new Color(255, 0, 0); //--
                clDiff = CgConst.CL_DIFF_HARD;
            // Paint in red
            } else if (diff <= CgConst.DIFF_VERYHARD) {
                // new Color(77, 77, 77);
                clDiff = CgConst.CL_DIFF_VERYHARD;
            // //-- Paint in gray
            }
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(clDiff);
            return this;
        case // Coeff
        8:
            data = (CgData) value;
            Double coeff = data.getCoeff();
            // -- Set the value
            setText(String.format("%1.1f ", coeff));
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Recovery
        9:
            data = (CgData) value;
            Double recup = data.getRecovery();
            // -- Set the value
            if (recup != 0) {
                DecimalFormat myFormatter = new DecimalFormat("0.#");
                String output = myFormatter.format(recup);
                setText(output + " ");
            } else
                setText("");
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Time
        10:
            data = (CgData) value;
            // -- Set the value
            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 // Time limit
        11:
            data = (CgData) value;
            int timelimit = data.getTimeLimit();
            int time1 = data.getTime();
            // -- Set the value
            setText(data.getTimeLimitString(true));
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else {
                if ((timelimit != 0) && (time1 > timelimit))
                    setBackground(Color.PINK);
                else
                    setBackground(Color.WHITE);
            }
            return this;
        case // Hour
        12:
            TrackData track = (TrackData) value;
            DateTime hour = track.data.get(row).getHour();
            // -- Set the value
            setText(hour.toString("E HH:mm:ss "));
            setHorizontalAlignment(CENTER);
            // -- Set the background color
            // Color.LightGreen;
            Color clHour = new Color(221, 255, 155);
            int ts_val = hour.getSecondOfDay();
            int ts_start = track.StartNightTime.getSecondOfDay();
            int ts_end = track.EndNightTime.getSecondOfDay();
            if ((track.bNightCoeff) && ((ts_val > ts_start) || (ts_val < ts_end)))
                // 95,158,160); //CadetBlue;
                clHour = new Color(0, 128, 255);
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(clHour);
            return this;
        case // Station time
        13:
            data = (CgData) value;
            // -- Set the value
            setText(data.getStationString(true));
            setHorizontalAlignment(CENTER);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Name
        14:
            data = (CgData) value;
            // -- Set the value
            setText(data.getName());
            setHorizontalAlignment(LEFT);
            // -- Set the background
            if (isSelected)
                setBackground(CgConst.CL_LINE_SELECTION);
            else
                setBackground(new Color(255, 255, 255));
            return this;
        case // Comment
        15:
            data = (CgData) value;
            // -- Set the value
            setText(data.getComment());
            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 : ImageIcon(javax.swing.ImageIcon) Color(java.awt.Color) DecimalFormat(java.text.DecimalFormat) CgData(course_generator.CgData) BufferedImage(java.awt.image.BufferedImage) DateTime(org.joda.time.DateTime) Graphics(java.awt.Graphics) CgSettings(course_generator.settings.CgSettings) ImageIcon(javax.swing.ImageIcon) TrackData(course_generator.TrackData)

Aggregations

CgData (course_generator.CgData)16 ValueAxis (org.jfree.chart.axis.ValueAxis)4 XYPlot (org.jfree.chart.plot.XYPlot)4 XYSeries (org.jfree.data.xy.XYSeries)4 CalcLineResult (course_generator.utils.Utils.CalcLineResult)3 Color (java.awt.Color)2 Font (java.awt.Font)2 BufferedImage (java.awt.image.BufferedImage)2 DateTime (org.joda.time.DateTime)2 CgResume (course_generator.CgResume)1 TrackData (course_generator.TrackData)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 DrawStringMultiLine (course_generator.utils.DrawStringMultiLine)1 BasicStroke (java.awt.BasicStroke)1 Dimension (java.awt.Dimension)1 Graphics (java.awt.Graphics)1 Graphics2D (java.awt.Graphics2D)1