I have a JApplet that loads images from a jar file and then displays each
image on a seperate tab (JTabbedPane). These images are placed onto labels
which the tabs use and they can be scaled and moved (placed into a scroll
pane), but I am having problems trying to draw on them.

When I try to draw on an image, I get a duplicate image drawn in the upper
left hand corner with the marks I added (just working with lines for now).

I know that this image can be drawn at differet locations by using the
Graphics2D.drawImage(image, x, y,...) where x and y refer to the point
where the image is to be drawn, but what I REALLY want is to have the image
on the tab replaced by the newly drawn image instead of drawing a seperate
one to begin with.  Is this even possible?  Do I always have to draw a
seperate image?

Again, I want to draw a line on an image I got from a tab, and then replace
the original image with the one I just drew on so when you go back to the
tab the image with a line in it will be shown.  For some reason, it just
never seems to work that way!

Here is a code snippet of what I am currently doing:


private void drawLine()
{
        //Get the active scroll pane
        m_jsPane = (JScrollPane) m_tabbedPane.getSelectedComponent();
        m_port = m_jsPane.getViewport();

        //My version of a scroll label that allows grabbing to move it
        GrabAndScrollLabel gnsLabel = (GrabAndScrollLabel) m_port.getView();

        m_currentImageIcon = (ImageIcon) gnsLabel.getIcon();

        m_currentImage = m_currentImageIcon.getImage();

        try
        {
            MediaTracker tracker = new MediaTracker(this);
            tracker.addImage(m_currentImage, 0);
            tracker.waitForID(0);
        }
        catch (InterruptedException ie)
        {
            //Harmless...but show signs of for testing
            System.out.println("Interupted in draw");
        }

        int iw = m_currentImage.getWidth(this);
        int ih = m_currentImage.getHeight(this);

        m_buffIm = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);

        //Big is a BufferedImage at class level
        big = m_buffIm.createGraphics();

        //The X and Y offset the image within the rect, not the rect itself
        big.drawImage(m_currentImage, 0, 0, this);

        //Oraline just holds the begin and end points
        OraLine oraLine = new OraLine(m_startX, m_startY, m_endX, m_endY);

        //The imageModHolder keeps track of all the lines added to an image
        gnsLabel.get_oraImage().getImageModHolder().add_shape(oraLine);

        gnsLabel.applyModifications(big);

        //Now that the line is added, reset the image with  the new one
        ImageIcon newIcon = new ImageIcon(m_currentImage);

        gnsLabel.setIcon(newIcon);

        m_port.setView(gnsLabel);

        m_jsPane.setViewport(m_port);

        getRootPane().revalidate();
        getRootPane().repaint();
}

public void paint(Graphics g)
{
        super.paint(g);

        Graphics2D g2 = (Graphics2D) g;

        if (m_buffIm != null)
        {
            g2.drawImage(m_buffIm, 0, 0, this);
        }
}

//This is in the GrabAndScrollLabel class
public BufferedImage applyModifications(Graphics2D g2D)
{
      ImageIcon icon = oraImage.getImageIcon();
      BufferedImage bi = new BufferedImage(icon.getIconWidth(),
                                           icon.getIconHeight(),
                                           BufferedImage.TYPE_INT_ARGB);

      ImageModHolder mods = oraImage.getImageModHolder();

      g2D.rotate(mods.get_rotation());
      g2D.scale(mods.get_zoomFactor(), mods.get_zoomFactor());

      Iterator shapeIter = mods.get_shapeList().iterator();

      while(shapeIter.hasNext())
      {
        OraShape shape = (OraShape)shapeIter.next();
        shape.draw(g2D);
      }

      return bi;
}


That's about it.  THANKS for helping.

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to