IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

NetBeans Java Discussion :

Debug avec API


Sujet :

NetBeans Java

  1. #1
    Membre averti
    Femme Profil pro
    Ingénieur intégration
    Inscrit en
    Juin 2010
    Messages
    50
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 38
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Santé

    Informations forums :
    Inscription : Juin 2010
    Messages : 50
    Par défaut Debug avec API
    Bonjour !

    Je code avec une API (JFreeChart). Je veux la surcharger donc j'ai crée des classes qui sont censées remplacer celles de l'API. Elles sont donc dans mon package de mon projet.

    Sauf qu'il semble qu'elles ne sont pas prises en compte :
    • pas de resultats des modif que j'ai fait

    • lors du debugg je ne vais pas dedans



    Etant donnée que je ne peux pas aller dans l'API quand on debug avec une API non surchargé (le step into fait un step over), je vois pas comment trouver où est le problème...
    Parce que logiquement comme c'est mes classes, quand je les appelle, normalement le debug va dedans puisque ce n'est pas l'API et que j'ai les .java.

    Des idées ?

  2. #2
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 483
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 483
    Par défaut
    t'as refait des classes avec exactement le même nom et même package??? Mauvaise idée, tu ne peux pas prévoir laquelle le classloader va utiliser.

    Si tu veux surcharger des choses, il faut créer des sous classes et les utiliser.


    Pour le debug, y a pas de raison que tu ne puisse pas descendre à l'intérieur des librairies, je le fais tous les jour, il te manque probablement juste les sources des librairies

  3. #3
    Membre averti
    Femme Profil pro
    Ingénieur intégration
    Inscrit en
    Juin 2010
    Messages
    50
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 38
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Santé

    Informations forums :
    Inscription : Juin 2010
    Messages : 50
    Par défaut
    Je vais aller dans plus de détails...

    Voilà ma classe qui utilise l'API, c'est une démo que j'ai remixé à ma sauce, j'ai encore le même nom de classe mais je vais le changer plus tard.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    /
    package ihm;
     
    import java.awt.Color;
    import java.io.Serializable;
    import java.text.SimpleDateFormat;
    import java.util.GregorianCalendar;
    import java.util.List;
     
    import javax.swing.JPanel;
    import optimisateur.Point;
     
    import org.jfree.chart.ChartPanel;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.axis.DateAxis;
    import org.jfree.chart.plot.XYPlot;
    import org.jfree.chart.renderer.xy.XYItemRenderer;
    import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
    import org.jfree.data.time.Millisecond;
    import org.jfree.data.time.RegularTimePeriod;
    import org.jfree.data.time.TimeSeries;
    import org.jfree.data.time.TimeSeriesCollection;
    import org.jfree.data.xy.XYDataset;
    import org.jfree.ui.ApplicationFrame;
    import org.jfree.ui.RectangleInsets;
     
    /**
     * An example of a time series chart.  For the most part, default settings are
     * used, except that the renderer is modified to show filled shapes (as well as
     * lines) at each data point.
     */
    public class TimeSeriesChartDemo1 extends ApplicationFrame implements Serializable {
     
        /** For serialization. */
        private static final long serialVersionUID = 1L;
        static List<List<Point>> listListPoint;
     
        /**
         * A demonstration application showing how to create a simple time series
         * chart.  This example uses monthly data.
         *
         * @param title  the frame title.
         */
        public TimeSeriesChartDemo1(String title, List<List<Point>> listListPoint) {
            super(title);
            TimeSeriesChartDemo1.listListPoint = listListPoint;
            final ChartPanel chartPanel = (ChartPanel) createDemoPanel();
            chartPanel.setPreferredSize(new java.awt.Dimension(1000, 900));
            chartPanel.setDisplayToolTips(true);
            chartPanel.setInitialDelay(1);
     
     
            setContentPane(chartPanel);
        }
     
        /**
         * Creates a chart.
         *
         * @param dataset  a dataset.
         *
         * @return A chart.
         */
        private static JFreeChart createChart(XYDataset dataset) {
     
            JFreeChart chart = MyChartFactory.createTimeSeriesChart(
                    "Activité du générateur", // title
                    "Temps", // x-axis label
                    "log de l'Activité", // y-axis label
                    dataset, // data
                    true, // create legend?
                    true, // generate tooltips?
                    false // generate URLs?
                    );
     
            chart.setBackgroundPaint(Color.WHITE);
     
            XYPlot plot = (XYPlot) chart.getPlot();
            plot.setBackgroundPaint(Color.BLACK);
            plot.setDomainGridlinePaint(Color.white);
            plot.setRangeGridlinePaint(Color.white);
            plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
            plot.setDomainCrosshairVisible(true);
            plot.setRangeCrosshairVisible(true);
     
            XYItemRenderer r = plot.getRenderer();
            if (r instanceof XYLineAndShapeRenderer) {
                XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
                renderer.setBaseShapesVisible(true);
                renderer.setBaseShapesFilled(true);
                renderer.setDrawSeriesLineAsPath(true);
            }
     
            DateAxis axis = (DateAxis) plot.getDomainAxis();
            axis.setDateFormatOverride(new SimpleDateFormat("HH:mm-dd/MM"));
     
            return chart;
     
        }
     
        /**
         * Creates a dataset, consisting of two series of monthly data.
         *
         * @return The dataset.
         */
        private static XYDataset createDataset() {
            TimeSeriesCollection dataset = new TimeSeriesCollection();
     
            for (int g = 0; g < listListPoint.size(); g++) {
     
                TimeSeries s1 = new TimeSeries("Generateur n" + (g + 1));
                List<Point> listPoint = listListPoint.get(g);
                for (int i = 0; i < listPoint.size(); i++) {
                    GregorianCalendar date = listPoint.get(i).x;
                    RegularTimePeriod time = new Millisecond(
                            date.get(GregorianCalendar.MILLISECOND),
                            date.get(GregorianCalendar.SECOND),
                            date.get(GregorianCalendar.MINUTE),
                            date.get(GregorianCalendar.HOUR_OF_DAY),
                            date.get(GregorianCalendar.DAY_OF_MONTH),
                            date.get(GregorianCalendar.MONTH),
                            date.get(GregorianCalendar.YEAR));
                    double lnA = Math.log(listPoint.get(i).y);
                    s1.add(time, lnA);
                }
     
                dataset.addSeries(s1);
            }
     
     
            return dataset;
     
        }
     
        /**
         * Creates a panel for the demo (used by SuperDemo.java).
         *
         * @return A panel.
         */
        public static JPanel createDemoPanel() {
            JFreeChart chart = createChart(createDataset());
            ChartPanel panel = new ChartPanel(chart);
            panel.setFillZoomRectangle(true);
            panel.setMouseWheelEnabled(true);
            return panel;
        }
     
    }
    Dedans j'utilise mes classes que j'ai surchargé : MyChartFactory et MyToolTipGenerator.

    MyChartFacotry herite de ChartFactory, il n'y a qu'une méthode que j'ai modifié :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    
    package ihm;
    
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.JFreeChart;
    import org.jfree.chart.axis.NumberAxis;
    import org.jfree.chart.labels.XYToolTipGenerator;
    import org.jfree.chart.plot.PlotOrientation;
    import org.jfree.chart.plot.XYPlot;
    import org.jfree.chart.renderer.xy.XYItemRenderer;
    import org.jfree.chart.renderer.xy.XYStepAreaRenderer;
    import org.jfree.chart.urls.StandardXYURLGenerator;
    import org.jfree.chart.urls.XYURLGenerator;
    import org.jfree.data.xy.XYDataset;
    
    /**
     *
     * @author sabine
     */
    public class MyChartFactory extends ChartFactory{
        public static JFreeChart createXYStepAreaChart(String title,
                                                       String xAxisLabel,
                                                       String yAxisLabel,
                                                       XYDataset dataset,
                                                       PlotOrientation orientation,
                                                       boolean legend,
                                                       boolean tooltips,
                                                       boolean urls) {
    
            if (orientation == null) {
                throw new IllegalArgumentException("Null 'orientation' argument.");
            }
            NumberAxis xAxis = new NumberAxis(xAxisLabel);
            xAxis.setAutoRangeIncludesZero(false);
            NumberAxis yAxis = new NumberAxis(yAxisLabel);
    
            XYToolTipGenerator toolTipGenerator = null;
            if (tooltips) {
                toolTipGenerator = new MyXYToolTipGenerator();
            }
    
            XYURLGenerator urlGenerator = null;
            if (urls) {
                urlGenerator = new StandardXYURLGenerator();
            }
            XYItemRenderer renderer = new XYStepAreaRenderer(
                    XYStepAreaRenderer.AREA_AND_SHAPES, toolTipGenerator,
                    urlGenerator);
    
            XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
            plot.setRenderer(renderer);
            plot.setOrientation(orientation);
            plot.setDomainCrosshairVisible(false);
            plot.setRangeCrosshairVisible(false);
            JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
                    plot, legend);
            ChartFactory.getChartTheme().apply(chart);
            return chart;
        }
    }
    Pour MyXYToolTipGenerator, au départ j'avais fait de l'héritage aussi mais comme ce que je voulais modifier c'était ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
        public static final String DEFAULT_TOOL_TIP_FORMAT = "{0}: ({1}, {2})";
    c'est à dire un attribut qui n'a pas de descendance. (c'est peut être là mon erreur, s'il n'y a pas de descendance c'est qu'il y a une raison...)
    bref, du coup j'ai copié l'original en modifiant juste cet attribut.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package ihm;
     
    import java.text.DateFormat;
    import java.text.NumberFormat;
    import org.jfree.chart.labels.AbstractXYItemLabelGenerator;
    import org.jfree.chart.labels.XYToolTipGenerator;
    import org.jfree.data.xy.XYDataset;
    import org.jfree.util.PublicCloneable;
     
    /**
     *
     * @author sabine
     */
    public class MyXYToolTipGenerator extends AbstractXYItemLabelGenerator
            implements XYToolTipGenerator, Cloneable, PublicCloneable {
     
            /** For serialization. */
        private static final long serialVersionUID = -3564164459039540785L;
     
        /** The default tooltip format. */
        static final String gen = "{0}";
        static final String date = "{1}";
        static final String activite = "{2}";
        static final String Newligne = System.getProperty("line.separator");
        static final String resultat = gen + Newligne + date + Newligne + activite;
        public static final String DEFAULT_TOOL_TIP_FORMAT = resultat;
     
        /**
         * Returns a tool tip generator that formats the x-values as dates and the
         * y-values as numbers.
         *
         * @return A tool tip generator (never <code>null</code>).
         */
        public static MyXYToolTipGenerator getTimeSeriesInstance() {
            return new MyXYToolTipGenerator(DEFAULT_TOOL_TIP_FORMAT,
                    DateFormat.getInstance(), NumberFormat.getInstance());
        }
     
        /**
         * Creates a tool tip generator using default number formatters.
         */
        public MyXYToolTipGenerator() {
            this(DEFAULT_TOOL_TIP_FORMAT, NumberFormat.getNumberInstance(),
                    NumberFormat.getNumberInstance());
        }
     
        /**
         * Creates a tool tip generator using the specified number formatters.
         *
         * @param formatString  the item label format string (<code>null</code> not
         *                      permitted).
         * @param xFormat  the format object for the x values (<code>null</code>
         *                 not permitted).
         * @param yFormat  the format object for the y values (<code>null</code>
         *                 not permitted).
         */
        public MyXYToolTipGenerator(String formatString,
                NumberFormat xFormat, NumberFormat yFormat) {
     
            super(formatString, xFormat, yFormat);
     
        }
     
        /**
         * Creates a tool tip generator using the specified number formatters.
         *
         * @param formatString  the label format string (<code>null</code> not
         *                      permitted).
         * @param xFormat  the format object for the x values (<code>null</code>
         *                 not permitted).
         * @param yFormat  the format object for the y values (<code>null</code>
         *                 not permitted).
         */
        public MyXYToolTipGenerator(String formatString, DateFormat xFormat,
                NumberFormat yFormat) {
     
            super(formatString, xFormat, yFormat);
     
        }
     
        /**
         * Creates a tool tip generator using the specified formatters (a
         * number formatter for the x-values and a date formatter for the
         * y-values).
         *
         * @param formatString  the item label format string (<code>null</code>
         *                      not permitted).
         * @param xFormat  the format object for the x values (<code>null</code>
         *                 permitted).
         * @param yFormat  the format object for the y values (<code>null</code>
         *                 not permitted).
         *
         * @since 1.0.4
         */
        public MyXYToolTipGenerator(String formatString,
                NumberFormat xFormat, DateFormat yFormat) {
     
            super(formatString, xFormat, yFormat);
        }
     
        /**
         * Creates a tool tip generator using the specified date formatters.
         *
         * @param formatString  the label format string (<code>null</code> not
         *                      permitted).
         * @param xFormat  the format object for the x values (<code>null</code>
         *                 not permitted).
         * @param yFormat  the format object for the y values (<code>null</code>
         *                 not permitted).
         */
        public MyXYToolTipGenerator(String formatString,
                DateFormat xFormat, DateFormat yFormat) {
     
            super(formatString, xFormat, yFormat);
     
        }
     
        /**
         * Generates the tool tip text for an item in a dataset.
         *
         * @param dataset  the dataset (<code>null</code> not permitted).
         * @param series  the series index (zero-based).
         * @param item  the item index (zero-based).
         *
         * @return The tooltip text (possibly <code>null</code>).
         */
        public String generateToolTip(XYDataset dataset, int series, int item) {
            return generateLabelString(dataset, series, item);
        }
     
        /**
         * Tests this object for equality with an arbitrary object.
         *
         * @param obj  the other object (<code>null</code> permitted).
         *
         * @return A boolean.
         */
        public boolean equals(Object obj) {
            if (obj == this) {
                return true;
            }
            if (!(obj instanceof MyXYToolTipGenerator)) {
                return false;
            }
            return super.equals(obj);
        }
     
        /**
         * Returns an independent copy of the generator.
         *
         * @return A clone.
         *
         * @throws CloneNotSupportedException if cloning is not supported.
         */
        public Object clone() throws CloneNotSupportedException {
            return super.clone();
        }
    }
    L'objectif de tout ça, c'est de modifier le contenu et la forme des tooltiptext.

  4. #4
    Membre averti
    Femme Profil pro
    Ingénieur intégration
    Inscrit en
    Juin 2010
    Messages
    50
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 38
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Santé

    Informations forums :
    Inscription : Juin 2010
    Messages : 50
    Par défaut
    En faite, l'absence d'heritage avec final c'est pour les méthodes pas pour les attributs. Du coup j'ai repris un héritage pour myXYToolTipGenerator en redéfinissant l'attribut :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    public class MyXYToolTipGenerator extends StandardXYToolTipGenerator {
     
        static final String gen = "{0}";
        static final String date = "{1}";
        static final String activite = "{2}";
        static final String Newligne = System.getProperty("line.separator");
        static final String resultat = gen + Newligne + date + Newligne + activite;
        public static final String DEFAULT_TOOL_TIP_FORMAT = resultat;
    }
    mais cela ne change pas les tooltip...

  5. #5
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 483
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 483
    Par défaut
    La première façon de faire me semble la bonne. Eventuellement surchargez l'ensemble des méthodes héritée sur votre generator pour savoir à travers lesquelles le code passe.


    La deuxième ne peux pas marcher, les champ statiques ne sont pas hérités. De plus les champs static final sont calculés à la compilation quand leur valeur est connue à ce moment là

  6. #6
    Membre averti
    Femme Profil pro
    Ingénieur intégration
    Inscrit en
    Juin 2010
    Messages
    50
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 38
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Santé

    Informations forums :
    Inscription : Juin 2010
    Messages : 50
    Par défaut
    Merci, maintenant mes classes sont bien appelées ! Bon je sais pas pourquoi le retour chariot ne fonctionne pas, ça concatène à la place... Mais ça marche !

    Sinon pour le debug, je dois ajouter la librairie que j'ai sous forme .zip où je sais qu'il y a les .java plutôt que le .jar trouvé aussi dans le .zip ?

    [Edit] : en faite, il fallait garder le .jar et spécifier les sources (et la javadoc héhé) dans les propriétés des librairies du projet !

  7. #7
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 483
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 483
    Par défaut
    ou faire un projet maven plutot que ant, où tout ça est automatique :p

  8. #8
    Membre averti
    Femme Profil pro
    Ingénieur intégration
    Inscrit en
    Juin 2010
    Messages
    50
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 38
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur intégration
    Secteur : Santé

    Informations forums :
    Inscription : Juin 2010
    Messages : 50
    Par défaut
    Je connaissais pas maven ! Maintenant je sais ce que c'est mais comme je vais utiliser javafx, je crois pas que ça soit compatible.

    En tous cas merci pour tout, encore une fois je clos le sujet

  9. #9
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 483
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 483

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Compiler en debug avec une librairie en release
    Par Philippe320 dans le forum MFC
    Réponses: 4
    Dernier message: 25/11/2005, 17h33
  2. problème avec "API Windows en C"
    Par Vince-le-fou dans le forum Windows
    Réponses: 2
    Dernier message: 23/11/2005, 15h22
  3. [EasyPHP] Plus de PHP ni de debugging avec EasyPHP 1.6
    Par JSuper_Kitten dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 4
    Dernier message: 23/09/2005, 08h19
  4. problème de liens avec API sous VC++
    Par xavynfive dans le forum MFC
    Réponses: 7
    Dernier message: 26/08/2005, 12h01
  5. [EXE] Problème avec Api
    Par Regis.C dans le forum Général Java
    Réponses: 5
    Dernier message: 14/03/2005, 11h09

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo