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

Graphisme Java Discussion :

ImageDisplay et Panner non reconnu


Sujet :

Graphisme Java

  1. #1
    Membre du Club
    Inscrit en
    Août 2007
    Messages
    86
    Détails du profil
    Informations personnelles :
    Âge : 37

    Informations forums :
    Inscription : Août 2007
    Messages : 86
    Points : 46
    Points
    46
    Par défaut ImageDisplay et Panner non reconnu
    salut

    je débute avec JAI et j'ai pris le tutoriel ImageViewer à cette adresse http://java.sun.com/developer/online...jai/index.html et j'ai essayé de l'exécuter sur eclipse mais il ne reconnait pas ImageDisplay et Panner.

    est ce que qqn a une idée? car j'ai installé JAI sur eclipse


    merci

  2. #2
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Septembre 2009
    Messages
    1
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2009
    Messages : 1
    Points : 1
    Points
    1
    Par défaut
    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
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    /*
     * @(#)ImageDisplay.java    1.39 00/04/13 16:50:08
     *
     * Copyright (c) 1999 Sun Microsystems, Inc. All Rights Reserved.
     *
     * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
     * modify and redistribute this software in source and binary code form,
     * provided that i) this copyright notice and license appear on all copies of
     * the software; and ii) Licensee does not utilize the software in a manner
     * which is disparaging to Sun.
     *
     * This software is provided "AS IS," without a warranty of any kind. ALL
     * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
     * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
     * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
     * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
     * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
     * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
     * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
     * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
     * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
     * POSSIBILITY OF SUCH DAMAGES.
     *
     * This software is not designed or intended for use in on-line control of
     * aircraft, air traffic, aircraft navigation or aircraft communications; or in
     * the design, construction, operation or maintenance of any nuclear
     * facility. Licensee represents and warrants that it will not use or
     * redistribute the Software for such purposes.
     */
     
     
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import javax.media.jai.*;
    import javax.swing.*;
     
    /**
     * An output widget for a PlanarImage.  ImageDisplay subclasses
     * javax.swing.JComponent, and can be used in any context that calls for a
     * JComponent.  It monitors resize and update events and automatically
     * requests tiles from its source on demand.
     *
     * <p> Due to the limitations of BufferedImage, only TYPE_BYTE of band
     * 1, 2, 3, 4, and TYPE_USHORT of band 1, 2, 3 images can be displayed
     * using this widget.
     *
     * @author Daniel Rice
     * @author Dennis Sigel
     */
     
    public class ImageDisplay extends JComponent
                              implements MouseListener, MouseMotionListener {
     
        /** The source PlanarImage. */
        protected PlanarImage source;
        /** The image's SampleModel. */
        protected SampleModel sampleModel;
        /** The image's ColorModel or one we supply. */
        protected ColorModel colorModel;
     
        /** The image's min X tile. */
        protected int minTileX;
        /** The image's max X tile. */
        protected int maxTileX;
        /** The image's min Y tile. */
        protected int minTileY;
        /** The image's max Y tile. */
        protected int maxTileY;
        /** The image's tile width. */
        protected int tileWidth;
        /** The image's tile height. */
        protected int tileHeight;
        /** The image's tile grid X offset. */
        protected int tileGridXOffset;
        /** The image's tile grid Y offset. */
        protected int tileGridYOffset;
     
        protected int originX = 0;
        protected int originY = 0;
     
        protected int shift_x = 0;
        protected int shift_y = 0;
     
        protected JLabel odometer = null;
        protected int componentWidth;
        protected int componentHeight;
     
        /** Brightness control */
        protected BufferedImageOp biop = null;
        protected boolean brightnessEnabled = false;
        protected int brightness = 0;
        protected byte[] lutData;
     
        /** Initializes the ImageDisplay. */
        private synchronized void initialize() {
            if ( source == null ) return;
     
            componentWidth  = source.getWidth();
            componentHeight = source.getHeight();
     
            setPreferredSize(new Dimension(componentWidth, componentHeight));
     
            this.sampleModel = source.getSampleModel();
     
            // First check whether the opimage has already set a suitable ColorModel
            this.colorModel = source.getColorModel();
            if (this.colorModel == null) {
                // If not, then create one.
                this.colorModel = PlanarImage.createColorModel(this.sampleModel);
                if (this.colorModel == null) {
                    throw new IllegalArgumentException("no color model");
                }
            }
     
            minTileX = source.getMinTileX();
            maxTileX = source.getMinTileX() + source.getNumXTiles() - 1;
            minTileY = source.getMinTileY();
            maxTileY = source.getMinTileY() + source.getNumYTiles() - 1;
            tileWidth = source.getTileWidth();
            tileHeight = source.getTileHeight();
            tileGridXOffset = source.getTileGridXOffset();
            tileGridYOffset = source.getTileGridYOffset();
        }
     
        /**
         * Default constructor
         */
        public ImageDisplay() {
            super();
            source = null;
     
            lutData = new byte[256];
     
            for ( int i = 0; i < 256; i++ ) {
                lutData[i] = (byte)i;
            }
     
            componentWidth  = 64;
            componentHeight = 64;
            setPreferredSize(new Dimension(componentWidth, componentHeight));
            setOrigin(0, 0);
            setBrightnessEnabled(true);
        }
     
        /** 
         * Constructs an ImageDisplay to display a PlanarImage.
         *
         * @param source a PlanarImage to be displayed.
         */
        public ImageDisplay(PlanarImage im) {
            super();
            source = im;
            initialize();
     
            lutData = new byte[256];
     
            for ( int i = 0; i < 256; i++ ) {
                lutData[i] = (byte)i;
            }
     
            setOrigin(0, 0);
            setBrightnessEnabled(true);
        }
     
        /**
         * Constructs an ImageDisplay of fixed size (no image)
         *
         * @param width - display width
         * @param height - display height
         */
        public ImageDisplay(int width, int height) {
            super();
            source = null;
     
            lutData = new byte[256];
     
            for ( int i = 0; i < 256; i++ ) {
                lutData[i] = (byte)i;
            }
     
            componentWidth  = width;
            componentHeight = height;
            setPreferredSize(new Dimension(componentWidth, componentHeight));
            setOrigin(0, 0);
            setBrightnessEnabled(true);
        }
     
        /** Changes the source image to a new PlanarImage. */
        public void set(PlanarImage im) {
            source = im;
            initialize();
            repaint();
        }
     
        public void set(PlanarImage im, int x, int y) {
            source = im;
            initialize();
            setOrigin(x, y);
        }
     
        public PlanarImage getImage() {
            return source;
        }
     
        public final JLabel getOdometer() {
            if ( odometer == null ) {
                odometer = new JLabel();
                odometer.setVerticalAlignment(SwingConstants.CENTER);
                odometer.setHorizontalAlignment(SwingConstants.LEFT);
                odometer.setText(" ");
                addMouseListener(this);
                addMouseMotionListener(this);
            }
     
            return odometer;
        }
     
        /** Provides panning */
        public final void setOrigin(int x, int y) {
            // shift to box origin
            originX = -x;
            originY = -y;
            repaint();
        }
     
        public int getXOrigin() {
            return originX;
        }
     
        public int getYOrigin() {
            return originY;
        }
     
        /** Records a new size.  Called by the AWT. */
        public void setBounds(int x, int y, int width, int height) {
            Insets insets = getInsets();
            int w;
            int h;
     
            if ( source == null ) {
                w = width;
                h = height;
            } else {
                w = source.getWidth();
                h = source.getHeight();
     
                if ( width < w ) {
                    w = width;
                }
     
                if ( height < h ) {
                    h = height;
                }
            }
     
            componentWidth  = w + insets.left + insets.right;
            componentHeight = h + insets.top  + insets.bottom;
     
            super.setBounds(x+shift_x, y+shift_y, componentWidth, componentHeight);
        }
     
        public void setLocation(int x, int y) {
            shift_x = x;
            shift_y = y;
            super.setLocation(x, y);
        }
     
        private final int XtoTileX(int x) {
            return (int) Math.floor((double) (x - tileGridXOffset)/tileWidth);
        }
     
        private final int YtoTileY(int y) {
            return (int) Math.floor((double) (y - tileGridYOffset)/tileHeight);
        }
     
        private final int TileXtoX(int tx) {
            return tx*tileWidth + tileGridXOffset;
        }
     
        private final int TileYtoY(int ty) {
            return ty*tileHeight + tileGridYOffset;
        }
     
        private static final void debug(String msg) {
            System.out.println(msg);
        }
     
        private final byte clampByte(int v) {
            if ( v > 255 ) {
                return (byte)255;
            } else if ( v < 0 ) {
                return (byte)0;
            } else {
                return (byte)v;
            }
        }
     
        private final void setBrightnessEnabled(boolean v) {
            brightnessEnabled = v;
     
            if ( brightnessEnabled == true ) {
                biop = new AffineTransformOp(new AffineTransform(),
                                             AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
            } else {
                biop = null;
            }
        }
     
        public final boolean getBrightnessEnabled() {
            return brightnessEnabled;
        }
     
        public final void setBrightness(int b) {
            if ( b != brightness && brightnessEnabled == true ) {
                for ( int i = 0; i < 256; i++ ) {
                    lutData[i] = clampByte(i+b);
                }
     
                repaint();
            }
        }
     
        /**
         * Paint the image onto a Graphics object.  The painting is
         * performed tile-by-tile, and includes a grey region covering the
         * unused portion of image tiles as well as the general
         * background.  At this point the image must be byte data.
         */
        public synchronized void paintComponent(Graphics g) {
     
            Graphics2D g2D = null;
            if (g instanceof Graphics2D) {
                g2D = (Graphics2D)g;
            } else {
                return;
            }
     
            // if source is null, it's just a component
            if ( source == null ) {
                g2D.setColor(getBackground());
                g2D.fillRect(0, 0, componentWidth, componentHeight);
                return;
            }
     
            int transX = -originX;
            int transY = -originY;
     
            // Get the clipping rectangle and translate it into image coordinates.
            Rectangle clipBounds = g.getClipBounds();
     
            if (clipBounds == null) {
                clipBounds = new Rectangle(0, 0, componentWidth, componentHeight);
            }
     
            // clear the background (clip it) [minimal optimization here]
            if ( transX > 0 ||
                 transY > 0 ||
                 transX < (componentWidth-source.getWidth()) ||
                 transY < (componentHeight-source.getHeight())) {
                g2D.setColor(getBackground());
                g2D.fillRect(0, 0, componentWidth, componentHeight);
            }
     
            clipBounds.translate(-transX, -transY);
     
            // Determine the extent of the clipping region in tile coordinates.
            int txmin, txmax, tymin, tymax;
            int ti, tj;
     
            txmin = XtoTileX(clipBounds.x);
            txmin = Math.max(txmin, minTileX);
            txmin = Math.min(txmin, maxTileX);
     
            txmax = XtoTileX(clipBounds.x + clipBounds.width - 1);
            txmax = Math.max(txmax, minTileX);
            txmax = Math.min(txmax, maxTileX);
     
            tymin = YtoTileY(clipBounds.y);
            tymin = Math.max(tymin, minTileY);
            tymin = Math.min(tymin, maxTileY);
     
            tymax = YtoTileY(clipBounds.y + clipBounds.height - 1);
            tymax = Math.max(tymax, minTileY);
            tymax = Math.min(tymax, maxTileY);
            Insets insets = getInsets();
     
            // Loop over tiles within the clipping region
            for (tj = tymin; tj <= tymax; tj++) {
                for (ti = txmin; ti <= txmax; ti++) {
                    int tx = TileXtoX(ti);
                    int ty = TileYtoY(tj);
     
                    Raster tile = source.getTile(ti, tj);
                    if ( tile != null ) {
                        DataBuffer dataBuffer = tile.getDataBuffer();
     
                        WritableRaster wr = tile.createWritableRaster(sampleModel,
                                                                      dataBuffer,
                                                                      null);
     
                        BufferedImage bi = new BufferedImage(colorModel,
                                                             wr,
                                                             colorModel.isAlphaPremultiplied(),
                                                             null);
     
                        // correctly handles band offsets
                        if ( brightnessEnabled == true ) {
                            SampleModel sm = sampleModel.createCompatibleSampleModel(tile.getWidth(),
                                                                                     tile.getHeight());
     
                            WritableRaster raster = RasterFactory.createWritableRaster(sm, null);
     
                            BufferedImage bimg = new BufferedImage(colorModel,
                                                                   raster,
                                                                   colorModel.isAlphaPremultiplied(),
                                                                   null);
     
                            // don't move this code
                            ByteLookupTable lutTable = new ByteLookupTable(0, lutData);
                            LookupOp lookup = new LookupOp(lutTable, null);
                            lookup.filter(bi, bimg);
     
                            g2D.drawImage(bimg, biop, tx+transX+insets.left, ty+transY+insets.top);
                        } else {
                            AffineTransform transform;
     
                            transform = AffineTransform.getTranslateInstance(tx + transX + insets.left,
                                                                             ty + transY + insets.top);
     
                            g2D.drawRenderedImage(bi, transform);
                        }
                    }
                }
            }
        }
     
        // mouse interface
        public final void mouseEntered(MouseEvent e) {
        }
     
        public final void mouseExited(MouseEvent e) {
        }
     
        public void mousePressed(MouseEvent e) {
            Point p = e.getPoint();
            int mods = e.getModifiers();
     
            if ( odometer != null ) {
                 String output = " (" + p.x + ", " + p.y + ")";
                 odometer.setText(output);
            }
        }
     
        public final void mouseReleased(MouseEvent e) {
            Point p = e.getPoint();
     
            if ( odometer != null ) {
                 String output = " (" + p.x + ", " + p.y + ")";
                 odometer.setText(output);
            }
        }
     
        public final void mouseClicked(MouseEvent e) {
        }
     
        public final void mouseMoved(MouseEvent e) {
            Point p = e.getPoint();
     
            if ( odometer != null ) {
                 String output = " (" + p.x + ", " + p.y + ")";
                 odometer.setText(output);
            }
        }
     
        public final void mouseDragged(MouseEvent e) {
            mousePressed(e);
        }
    }
    voilà, c'est la code de ImageDisplay

Discussions similaires

  1. [Lomboz] [JBoss] JBoss 3.2.6 non reconnu par Lomboz ?
    Par romain3395 dans le forum Eclipse Java
    Réponses: 4
    Dernier message: 17/12/2004, 16h35
  2. Commandes non reconnues.
    Par Manu' dans le forum Administration système
    Réponses: 3
    Dernier message: 07/10/2004, 17h09
  3. [EJB] [JSP] Méthode EJB non reconnue dans jsp
    Par stago dans le forum Servlets/JSP
    Réponses: 2
    Dernier message: 06/07/2004, 09h52
  4. Creation de table, caractère non reconnu
    Par Missvan dans le forum PostgreSQL
    Réponses: 2
    Dernier message: 17/02/2004, 13h28
  5. xslt_create() non reconnu
    Par BRAUKRIS dans le forum XML/XSL et SOAP
    Réponses: 2
    Dernier message: 11/12/2003, 14h43

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