This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!

Sanam Chandrasekaran

Greenhorn
+ Follow
since May 05, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sanam Chandrasekaran

Hello,
Thanks a lot for ur reply,
I am basically developing an image viewer,
in which a image can be viewed, Zoomed in n out,
magnifier, mask(should be able to modify the image),
shoud be able to insert text on the image, etc,

If u have more idea n information, it would be kindful
if u could share

Thanks
Sanam
13 years ago
Hello,

I am working on applets,
i am passing a color parameter as shown below

/*
<applet code = "ZoominApplet3.class" width = 300 height = 200>

<param name = "color" value = "Font.RED">
</applet>
*/




fontColor =getParameter("color");


now fontColor is of String type,
i want to convert it to Color type, so that
i can pass it as shown below.

txtA.setBackground(fontColor);


It would be kindful if anyone could tell me how to convert a variable
from String to Color

Regards
Sanam
13 years ago
Hello,

I have a BufferImage displayed on a JScrollPane
and i want a JTextArea with vertical n horizontal scroll bars,

can we place a scrollpane on another existing scrollpane.

i.e i want a JTextArea with scrollbars to be placed on the image which is already displayed in scrollpane.


Could anone please help me with this.

Regards
Sanam
13 years ago
Hello,


Can please help me with this,

i am stuck up with a wnother problem.
It would be kindful if u could help me out with this.


i.e when i click on the mask button a mask(Rectangle box) should appear that can be resized , so that i can place it on any location
on the image. so that i can modify that part of the image ,
such as i should be able to change the color etc ( it should function like a mask)


Plz help. i dono how to do it
13 years ago
Hello,

Thanks a lot, It was a great help.
The magnifier works absolutely fine.

Thankyou.

Regards
Sanam
13 years ago
Thanks a lot for ur reply n ur suggestion.
Actuall what my applet has to do is,
i have an applet which displays an image when it is loaded,
n the following buttons have to be displayed at the top
of the panel


1. magnifier button - when i click on magnifier button , it has to display the magnifier on the image(same as the code u had sent)
2. zoom in button - the image has to be zoomed
3. joom out button
4. auto fit button- window as to auto fit in the window size
5. rotate button - the image has to rotate.

I am not able to get the modifier work when i click on the modifier button.

At all times no matter what oeration , i want all the buttons to be displayed.

Can u please tell how can i get the magnifier when i click on the magnification button.

Rest all operations r working fine.

I am just not able to get the modifier when i click on modification button.

Please help
13 years ago
this is the code i have written ,

u can try out the code by just changing the image name ,

when i click on the magnifier, i want the magnifier tool to appear,
and even all the buttons should appear.

can u please tell how do i club ur code into mine.

it would be kindful if u could help me with this.


import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.*;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.util.Vector;
import java.applet.*;

import java.awt.image.*;
import javax.swing.*;
import javax.swing.event.*;


// **************************************** ZoominApplet1 class ***************************************
public class ZoominApplet2 extends JApplet
{
public static JFrame f;
public AppletZoomPanel2 zoomPanel;
public static Container cp;
public BufferedImage image;
JTextArea textArea;
public Graphics g;


public void init()
{
zoomPanel = new AppletZoomPanel2();
ZoomAction2 action = new ZoomAction2(zoomPanel);

cp = getContentPane();
cp.setLayout(new BorderLayout());
cp.add(action, "North");
cp.add(new JScrollPane(zoomPanel));
txtArea();

}


public void txtArea()
{

zoomPanel.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
textArea = new JTextArea();
textArea.setBorder(BorderFactory.createLineBorder(Color.BLACK));
zoomPanel.add(textArea);
textArea.setBounds(e.getX(), e.getY(), 100,50);
}
});

SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
f.pack();
f.show();
}
});
}

public static void main(String[] args)
{
JApplet applet = new ZoominApplet2();
f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(applet);
f.setSize(300,300);
//f.setLocation(100,100);
applet.init();
f.setVisible(true);

}
}



// *********************************** AppletZoompanel class ******************************
class AppletZoomPanel2 extends JPanel
{

public BufferedImage image;
public double scale, scaleInc;
public boolean autofit = false;

public String actionType = "";
public String drawType ="";
private double currentAngle;

public int box_x = 0;
public int box_y = 0;
public int box_width = 100;
public int box_height = 100;
public int width = 900;
public int height = 900;


Graphics g = getGraphics();


public AppletZoomPanel2()
{

loadImage();

scale = 1.0;
scaleInc = 0.01;
setBackground(Color.white);
//Set to null
setLayout(null);
repaint();
}


protected void paintComponent(Graphics g)
{
super.paintComponent(g);

if(actionType.equals("Auto Fit"))
{

Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
int parentWidth = getParent().getWidth();
int parentHeight = getParent().getHeight();
double imageWidth = image.getWidth();
double imageHeight = image.getHeight();
double newImageHeight;
double newImageWidth;

if(parentHeight < parentWidth)
{
newImageHeight = parentHeight;
newImageWidth = (newImageHeight * imageWidth) / imageHeight;

double scaleX = newImageWidth / imageWidth ;

double scaleY = newImageHeight / imageHeight ;

AffineTransform xform1 = AffineTransform.getTranslateInstance(0, 0);
xform1.scale(scaleX,scaleY);
g2.drawRenderedImage(image, xform1);
}
else
{
newImageWidth = parentWidth;
newImageHeight = (newImageWidth * imageHeight) / imageWidth;
double scaleX = newImageWidth / imageWidth ;
double scaleY = newImageHeight / imageHeight ;
AffineTransform xform1 = AffineTransform.getTranslateInstance(0, 0);
xform1.scale(scaleX,scaleY);
g2.drawRenderedImage(image, xform1);
}
}
else if(actionType.equals("Not Auto Fit"))
{

Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
int w = getWidth();

int h = getHeight();

double imageWidth = scale * image.getWidth();
double imageHeight = scale * image.getHeight();

double x = (w - imageWidth)/2;
double y = (h - imageHeight)/2;

AffineTransform xform = AffineTransform.getTranslateInstance(x, y);
xform.scale(scale, scale);
g2.drawRenderedImage(image, xform);
}

else if(actionType.equals("Rotate"))
{
Graphics2D g2 = (Graphics2D)g;
AffineTransform origXform = g2.getTransform();
AffineTransform newXform = (AffineTransform)(origXform.clone());
//center of rotation is center of the panel
int xRot = this.getWidth()/2;
int yRot = this.getHeight()/2;
newXform.rotate(Math.toRadians(currentAngle), xRot, yRot);
g2.setTransform(newXform);
//draw image centered in panel
int x = (getWidth() - image.getWidth(this))/2;
int y = (getHeight() - image.getHeight(this))/2;
g2.drawImage(image, x, y, this);
g2.setTransform(origXform);

}


else if(actionType.equals("Magnify"))
{

}
else
{
Graphics2D g11 = (Graphics2D)g;
g11.drawImage(image, null, 100, 100);
}
}




public void rotate()
{
//Rotate five degrees at a time
currentAngle+=5.0;
if (currentAngle >= 360.0)
{
currentAngle = 0;
}
repaint();
}

public Dimension getPreferredSize()
{
Dimension d = new Dimension();
d.width = (int)(scale * image.getWidth());
d.height = (int)(scale * image.getHeight());
return d;
}


public void setScale (int inc)
{
scale += inc * scaleInc;
revalidate();
repaint();
}

private void loadImage()
{
String fileName = "plot4_g.gif";
try
{
URL url = getClass().getResource(fileName);
image = ImageIO.read(url);
}
catch(MalformedURLException mue)
{
System.out.println("url: " + mue.getMessage());
}
catch(IOException ioe)
{
System.out.println("read: " + ioe.getMessage());
}
}
}


// ******************************* ZoomAction Class **************************************
class ZoomAction2 extends JPanel
{
static final String[] fontStyleString = new String[] {"Font.PLAIN", "Font.ITALIC", "Font.BOLD", "Font.ITALIC+Font.BOLD"};
static final int[] fontStyleInt = new int[] { Font.PLAIN , Font.ITALIC , Font.BOLD , Font.ITALIC+Font.BOLD };
AppletZoomPanel2 zoomPanel;


public ZoomAction2(AppletZoomPanel2 azp)
{
zoomPanel = azp;

final JButton zoomIn = new JButton("zoom in"), zoomOut = new JButton("zoom out"), magnifier = new JButton("Magnifier"), autoFit = new JButton("Auto Fit"), rotate = new JButton("Rotate"), txtButton = new JButton("Text Area");

JComboBox fontCombo;
JComboBox styleCombo;
String[] fontNames = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();

Vector visFonts = new Vector(fontNames.length);
for(int i=0; i<fontNames.length; i++)
{
Font f = new Font(fontNames[i], Font.PLAIN, 12);
if (f.canDisplay('a'))
{
visFonts.add(fontNames[i]);
}
else
{
//System.out.println("No alphabetics in " + fontNames[i]);
}
}

fontCombo = new JComboBox(visFonts);
styleCombo = new JComboBox(fontStyleString);

ActionListener l = new ActionListener()
{
int inc;

public void actionPerformed(ActionEvent e)
{
JButton button = (JButton)e.getSource();
zoomPanel.actionType = "Not Auto Fit";

if(button == zoomIn)
inc = 5;
if(button == zoomOut)
inc = -5;
zoomPanel.setScale(inc);
//zoomPanel.repaint();
}
};
zoomIn.addActionListener(l);
zoomOut.addActionListener(l);


ActionListener af = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JButton button = (JButton)e.getSource();

if(button == autoFit)
{
//System.out.println("autofit");
//System.out.println("ZoomPanel Parent Width: " +zoomPanel.getParent().getWidth());
zoomPanel.actionType = "Auto Fit";
zoomPanel.repaint();
}
/*if(button == txtButton)
{

}*/

}
};

autoFit.addActionListener(af);
txtButton.addActionListener(af);

ActionListener ro = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JButton button = (JButton)e.getSource();

if(button == rotate)
{
zoomPanel.actionType = "Rotate";
zoomPanel.rotate();
//zoomPanel.repaint();
}
}
};
rotate.addActionListener(ro);


ActionListener ma = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JButton button = (JButton)e.getSource();

if(button == magnifier)
{/*
zoomPanel.actionType = "Magnify";
System.out.println("Magnify");
zoomPanel.repaint();
*/

//MagnifierTest mm = new MagnifierTest();
}
}
};
magnifier.addActionListener(ma);

add(txtButton);
add(zoomIn);
add(zoomOut);
add(magnifier);
add(autoFit);
add(rotate);
add(fontCombo);
add(styleCombo);

}
}
13 years ago
Thanks a lot for the reply, ill try it out n let u know.
13 years ago
Hello,

I have a BufferedImage displayed on an applet,
I wnat a magnifier ,
so that when i move the magnifier on the image only that part of the image
on which the magnifier is there is magnified.

Could anyone plz help me out with this.
It will be kindful if anyone could get me the code.

Plz help.


Regards
Sanam
13 years ago
Hello,


Ca please help me with this,

i am stuck up with a problem.
It would be kindful if any of u could help me out with this.

I have an applet on which a BufferedImage is displayed,
I want a part of the image to be blocked ( i.e where ever i click)
so that i can modify that part of the image can be changed ,
such as i should be able to change the color etc ( it should function like a mask);

i.e when i click on the mask buuton a mask should appear , so that i can place it
on the image.

Plz help. i dono how to do it
13 years ago
hello,

1more problem
I have an auto fit button on my JApplet, when i click on the JButton,
I want the Image to be resized to the screen size.

how to do this
can anyone get me a solution for this

Regards
Sanam
13 years ago
Hello,

Thanks for the reply,

actually i dont want any text box,

i directly want to insert text at any mouse clicked location.

could u plz tell how to do it.

Thanks
Sanam
13 years ago
Hello,


I have a JApplet on which an image is displayed
and i want to ENTER text on the image at any mouse clicked location. and the
entered text should persist.

Can anyone help me out with this.

Sanam
13 years ago
Hello,

i have an applet,
and an image displayed on the applet and i want a text area to appear
at which ever location i click on the applet
. could someone help me out with a solution.



Regards
sanam
13 years ago