🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #1015

Re: help, GUI redrawing is obviously confusing me

#1015
From: PeterH
Date: Mon, 29 Apr 2002 00:19
260 lines
8307 bytes
I thought you were going to ask for that, sorry about that.  I should have
known.

Here's the class:

(thanks again for any input)
----------------------------------------------------------------------
package com.pchenry.photomaster;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;

import java.io.File;
import java.io.IOException;
import javax.swing.*;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
/**
 *  Photo Individual photo class representing one photo
 *
 *@author     peter
 *@created    April 11, 2002
 */
public class Photo extends JPanel {
   private static int count = 0;
   private String pathFrom;
   private String newName;
   private String newPath;
   private String description;
   private Image image;

   private final static int WEBVIEW = 0;
   private final static int THUMBNAILVIEW = 1;
   private final static int WEBVIEWFACTOR = 2;
   private final static int THUMBNAILVIEWFACTOR = 8;

   /**
    *  Constructor for the Photo object
    */
   public Photo() {
      pathFrom = null;
      newName = null;
      description = null;
      Image image = null;
   }

   /**
    *  Constructor for the Photo object
    *
    *@param  pathFrom     path from where the photo is coming from, this is
the
    *      original location or the current location depending on if the
photo
    *      has been transfered or not
    *@param  newName      the new name of the photo, this is what the photo
is
    *      going to be named if not already changed
    *@param  description  Description of the Parameter
    */
   public Photo( String pathFrom, String newName, String description ) {
      this.pathFrom = pathFrom;
      this.newName = newName;
      this.description = description;
      setImage( this.pathFrom );
   }

   /**
    *  Sets the image attribute of the Photo object
    *
    *@param  filename  The new image value
    */
   public void setImage( String filename ) {
      image = Toolkit.getDefaultToolkit().getImage( filename );
   }

   /**
    *  Gets the image attribute of the Photo object
    *
    *@return    The image value
    */
   public Image getImage() {
      return image;
   }

   /**
    *  Gets the image attribute of the Photo object
    *
    *@param  width        Description of the Parameter
    *@param  height       Description of the Parameter
    *@param  scaleFactor  Description of the Parameter
    *@return              The image value
    */
   public Image getImage( int width, int height, int scaleFactor ) {
      Image scaledImage = image.getScaledInstance( width, height,
scaleFactor );
      return scaledImage;
   }

   /**
    *  Gets the webViewImage attribute of the Photo object
    *
    *@return    The webViewImage value
    */
   private Image getImageWebView() {
      int width = image.getWidth( null ) / WEBVIEWFACTOR;
      int height = image.getHeight( null ) / WEBVIEWFACTOR;
      Image img = image.getScaledInstance( width, height,
Image.SCALE_FAST );
      return img;
   }

   /**
    *  Gets the thumbnailViewImage attribute of the Photo object
    *
    *@return    The thumbnailViewImage value
    */
   private Image getImageThumbnailView() {
      int width = image.getWidth( null ) / THUMBNAILVIEWFACTOR;
      int height = image.getHeight( null ) / THUMBNAILVIEWFACTOR;
      Image img = image.getScaledInstance( width, height,
Image.SCALE_FAST );
      return img;
   }

   /**
    *  Gets the photoMasterViewImage attribute of the Photo object
    *
    *@param  viewFactor  Description of the Parameter
    *@return             The photoMasterViewImage value
    */
   private Image getPhotoMasterViewImage( int viewFactor ) {
      Image img = null;

      if( viewFactor == this.WEBVIEW ) {
         img = getImageWebView();
      } else {
         //use the small one as the default
         img = this.getImageThumbnailView();
      }
      return img;
   }

   /**
    *  the description attribute of the Photo object
    *
    *@return    The description value
    */
   public String getDescription() {
      return description;
   }

   /**
    *  Constructor for the setDescription object
    *
    *@param  description  Description of the Parameter
    */
   public void setDescription( String description ) {
      this.description = description;
   }

   /**
    *  Gets the name attribute of the Photo object
    *
    *@return    The name value
    */
   public String getName() {
      return newName;
   }

   /**
    *  Sets the newName attribute of the Photo object
    *
    *@param  newName  The new newName value
    */
   public void setNewName( String newName ) {
      this.newName = newName;
   }

   /**
    *  Gets the newPath attribute of the Photo object
    *
    *@return    The newPath value
    */
   public String getNewPath() {
      return newPath;
   }

   /**
    *  Sets the newPath attribute of the Photo object
    *
    *@param  newPath  The new newPath value
    */
   public void setNewPath( String newPath ) {
      this.newPath = newPath;
   }

   /**
    *  Description of the Method
    *
    *@param  g  Description of the Parameter
    */
   public void paint( Graphics g ) {
      if( image != null ){
System.err.println( count++ + "painting an image " + image.getHeight(this));
         g.drawImage( this.getImageWebView(), 0, 0, 200, 200, this );
      } else {
System.err.println( count++ + "nothing to paint");
      };
   }

   /**
    *  Description of the Method
    *
    *@param  g  Description of the Parameter
    */
   public void paintComponent( Graphics g ) {
      System.err.println( "Being asked to paintComponent" );
      if( getImage() != null ){
System.err.println( count++ + "painting an image " + image.getHeight(this));
         g.drawImage( getImage(), 0, 0, 200, 200, this );
      } else {
System.err.println( count++ + "nothing to paint");
      };

   }

}
//Photo


----------------------------------------------------------------------
"John McGrath [TeamB]" <ng-b@JPMcGrath.net> wrote in message
news:MPG.17343aafe3bf00ad98b59e@newsgroups.borland.com...
> On Fri, 26 Apr 2002 22:40:34 -0400, PeterH wrote:
>
> > I have a class here that is a piece of a project and I'm just
> > about to scream! :<  The code seems to do absolutely everything
> > but what I thought I was coding it to do. :<  Can you take a
> > look and see what I'm doing wrong to have the right hand side
> > panel be painted exactly like the left hand side panel, even
> > though it's totally another class that is supposed to have an
> > image in it?
>
> The right hand panel is painted by the Photo component, and you have
> not included the code for that.  It would also help if you would
> include a main program, so it is possible to run the code and see what
> it is doing.
>
> --
> Regards,
>
> John McGrath [TeamB]
>
> ---------------------------------------------------
> Before sending me e-mail, please read:
>     http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID: <3ccc933c_2@dnews>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!supernews.com!newsswitch.lcs.mit.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-hog.berkeley.edu!ucberkeley!enews.sgi.com!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!dnews
References: <3cca1147_2@dnews> <MPG.17343aafe3bf00ad98b59e@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,da4fdf29b67dc0d2
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2002-04-28 17:38:02 PST
From: "PeterH" <!Sorry-TooMuchSpam!nope@nope.com>
Newsgroups: borland.public.jbuilder.java.api
References: <3cca1147_2@dnews> <MPG.17343aafe3bf00ad98b59e@newsgroups.borland.com>
Subject: Re: help, GUI redrawing is obviously confusing me
Date: Sun, 28 Apr 2002 20:19:34 -0400
Lines: 262
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
NNTP-Posting-Host: 24.112.10.56
Message-ID: <3ccc933c_2@dnews>
X-Trace: dnews 1020039996 24.112.10.56 (28 Apr 2002 17:26:36 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!supernews.com!newsswitch.lcs.mit.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-hog.berkeley.edu!ucberkeley!enews.sgi.com!news.xtra.co.nz!newsfeeds.ihug.co.nz!ihug.co.nz!dnews