Re: [JAVA2D] How to make right click Action
If you read the JavaDocs for MouseListener MouseEvent you will find your answer much more quickly than if you send an email to this list and wait for a response. One way to do this is use the MouseEvent object (that is an argument to your mousePressed() ) and call getButton() on that MouseEvent object. This will return an int that you can compare against the constants in MouseEvent (MouseEvent.BUTTON1, MouseEvent.BUTTON2, etc) to determine which button has changed state. -Original Message- From: Discussion list for Java 2D API [mailto:[EMAIL PROTECTED]]On Behalf Of Ayman El_Gharabawy Sent: Monday, November 25, 2002 4:04 AM To: [EMAIL PROTECTED] Subject: [JAVA2D] How to make right click Action i want to make action using right click or press.how can in mousePressed() recognize the right mouse button? waiting fo reply .. == = 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. === 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.
Re: [JAVA2D] Compiling Problems with Printing Attributes
This is a basic access modifier issue. PrintQuality's [int] constructor is PROTECTED, so only a subclass of PrintQuality, OR another class within the javax.print.attribute.standard package may access that protected constructor. The [int] constructor for OrientationRequested is also protected, and you have the same issues with it as you do with PrintQuality as above. Rob - Original Message - From: Eric Kolotyluk mailto:[EMAIL PROTECTED] To: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] Sent: Wednesday, February 26, 2003 3:41 PM Subject: [JAVA2D] Compiling Problems with Printing Attributes Why does the compiler find a problem with this? I can't seem to use the defined constants cut and pasted from the API web pages, or even a literal integer. I do this sort of thing all the time with constants? I cannot see any problem with the constuctors. Any help would be appreciated. Cheers, Eric import javax.print.attribute.*; import javax.print.attribute.standard.*; // much more code OrientationRequested orientation = new OrientationRequested(OrientationRequested.LANDSCAPE); attributeSet.add((Attribute)orientation); PrintQuality printQuality = new PrintQuality(2); attributeSet.add((Attribute)printQuality); // much more code javac CinPrintFrame.java CinPrintFrame.java:217: cannot resolve symbol symbol : constructor OrientationRequested (javax.print.attribute.standard.OrientationRequested) location: class javax.print.attribute.standard.OrientationRequested new OrientationRequested(OrientationRequested.LANDSCAPE); ^ CinPrintFrame.java:221: PrintQuality(int) has protected access in javax.print.attribute.standard.PrintQuality PrintQuality printQuality = new PrintQuality(2); ^ === 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.
[JAVA2D] creating a JPEG
Hi. Can someone give me some pointers on how I go about creating a simple JPEG image and saving it to a file? I want to be able to draw a simple square with a given width/height in pixels, filled with a solid color given by a RGB value, rendered at 150 DPI. I have done some simple 2D drawing, but only in the context of a swing component. In this case, I don't even have a graphics or an image yet. So I need to 1) create a new image object 2) get the graphics of the object 3) draw my square in my color 4) convert the image into a JPEG with the right parameters (especially the DPI) 5) save it to a file. Any help would be appreciated! Thanks. Rob Ross [EMAIL PROTECTED] === 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.
Re: [JAVA2D] creating a JPEG
Can someone give me some pointers on how I go about creating a simple JPEG image and saving it to a file? I want to be able to draw a simple square with a given width/height in pixels, filled with a solid color given by a RGB value, rendered at 150 DPI. 1) create a new image object 2) get the graphics of the object 3) draw my square in my color 4) convert the image into a JPEG with the right parameters (especially the DPI) 5) save it to a file. Ok I have figured out how to do steps 1-3. But I don't know if I have to do something special when I draw into the Graphics2D so that later when I save it as a JPEG, I can get my resolution of 150 DPI, which is more than the standard ~72 DPI of a screen-drawn image. So, say I have drawn a 100x100 pixel blue square in my Graphics (at 72 DPI)...how do I turn it into a JPEG at 150 DPI? Thanks. Rob === 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.
Re: [JAVA2D] creating a JPEG
So, say I have drawn a 100x100 pixel blue square in my Graphics (at 72 DPI)...how do I turn it into a JPEG at 150 DPI? I believe you aren't thinking about this right. java images, eg buffered images are created in pixels not dpi. once you know that the phrase above says you want to create information that isn't there, or you want to claim its from a higher resolution source than is the fact. Well I think I was simplifying the issue for discussion; in drawing a square with a solid color I had the implicit understanding I could easily scale this to whatever DPI I needed - as a easy case to just get this to work as a first step. So if I wanted to draw a square on the screen 100 x 100 pixels, and it was really coming from a 150 DPI square with 200x200 pixels, obviously I would have to scale that square smaller when I draw it. The JPEG file I saved would really have to be (about) a 200 x 200 pixel square @ 150 DPI to save that extra density data. What I will eventually be doing is working with images with a much greater DPI than the screen, manipulating that data, and saving it in the higher resolution, and just rendering it to screen at a lower DPI, (or blowing it up so it looks bigger on the screen (in inches) than it really is, to allow the user to see all the actual detail of the image.) instead create a BufferedImage image at the pixel dimensions you want and you can scale it for on-screen drawing (see Graphics.drawImage(..) apis) Save it for example using javax.imageio.ImageIO.write(bimg, jpg, new File(blah.jpg)); ( I don't know how much easier we could make this!) Done. Yea that looks pretty easy, =) and I did see that API yesterday but didn't know how to deal with the DPI issue. For extra credit: Do you really want 150 dpi in the output jpeg? (ie so that viewers would also scale it appropriately?) If you want to save resolution information then YES you do have to do more. Go to the website and locate the imageio guide in pdf, ps or html and check out the JPEG metadata spec http://java.sun.com/j2se/1.4.1/docs/api/javax/imageio/metadata/doc -files/jpeg_metadata.html Ok, that looks promising, I'll take a look. I had planned on using the com.sun.image.codec.jpeg.JPEGEncodeParam's setDensityUnit() and setXDensity(), setYDensity(), but as the docs clearly warn, these classes aren't part of the Java API so I knew this couldn't be the permanent solution. So I'll take a look at the metadata doc and see what I can do with that and get back to you. Thanks! Rob === 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.
Re: [JAVA2D] creating a JPEG
For extra credit: Do you really want 150 dpi in the output jpeg? (ie so that viewers would also scale it appropriately?) If you want to save resolution information then YES you do have to do more. Go to the website and locate the imageio guide in pdf, ps or html and check out the JPEG metadata spec http://java.sun.com/j2se/1.4.1/docs/api/javax/imageio/metadata/doc-files/jpe g_metadata.html -phil. Ok, I'm stuck again. Here's what I have so far... public static void main(String[] args) { //create a colored square BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); Graphics2D biContext = bi.createGraphics(); biContext.setColor(Color.blue); biContext.fillRect(0, 0, 200, 200); Iterator i = ImageIO.getImageWritersByFormatName(jpeg); //are there any jpeg encoders available? if (i.hasNext()) //there's at least one ImageWriter, just use the first one { ImageWriter imageWriter = (ImageWriter) i.next(); //get the param ImageWriteParam param = imageWriter.getDefaultWriteParam(); ImageTypeSpecifier its = new ImageTypeSpecifier(bi.getColorModel(),bi.getSampleModel()); //get metadata IIOMetadata iomd = imageWriter.getDefaultImageMetadata(its,param); String formatName = javax_imageio_jpeg_image_1.0;//this is the DOCTYPE of the metadata we need IIOMetadataFormat format = iomd.getMetadataFormat(formatName); String[] strings = format.getAttributeNames(app0JFIF); //change density to 150DPI - how? for (int s = 0; s strings.length; s++) { String string = strings[s]; System.out.println(string); //print out the attribute names for the element I want to change } } } when I run this method I get this output: majorVersion minorVersion resUnits Xdensity Ydensity thumbWidth thumbHeight I want to change the resUnits, Xdensity, and Ydensity values.but every class I look at in metadata seems to have protected methods for changing attributes. I'm stumped. I don't even know how to querry what the current values for these attributes are. I want to give resUnits a value of 1 for dots/inch, and give Xdensity/Ydensity values of 150. Any clues for me? Thanks! Rob === 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.
[JAVA2D] Java 2D Api Graphics by Vincent Hardy
I just bought this book and can't get the demorunner or scriptrunner java apps to work on either Mac OS X 10.2.6, or WinXP. Both are running some version of JDK 1.4 (1.4.2 on windows, 1.4.1 on OS X). On the Mac, if I double-click the demorunner script file (I've chmod'ed it to be executable) OR if I manually invoke it via a terminal shell with demorunner, I do get the demo browser window to come up, but anything I try to double click results in an error dialog that states Could not start demo : runsnippet: not found. (I had to place the glf.jar file in the /Library/Java/Extensions directory to even get this far - including it in the classpath in the demorunner script wasn't working.). On Windows XP, if I double-click the demorunner.bat file, I do get the demo browser window, but double-clicking any actual demo in the tree gives me an error dialog such as: Could not start demo: CreateProcess: runsnippet HelloRenderingModel error=2. If I had the source code to the Main class object (DemoRunner) I could try to debug this myself, but the source is NOT included for the demo runner classes (just for the GLF), and I can't find an updated version on either the Prentice Hall, java.net, or java.sun.com sites. One thing that is immediately apparent is that the DemoRunner class is in the default package, and that's problematic in JDK version 1.3 and greater. But again, if I had the source code for this class I could figure out what the problem is. Any pointers to the source code, or an updated version of the source code/examples CD for the Java 2D API Graphics book? (It IS, after all, the 'official' Sun Microsystems Press.) Thanks! Rob === 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.
Re: [JAVA2D] Java 2D Api Graphics by Vincent Hardy
Thanks for the quick response Vincent. I can now get the demos running, at least on Windows XP. I wasn't sure where I was supposed to place the demos.properties file, as I couldn't find an existing file with that name. I placed it in the root directory of the examples folder, at the same level where I copied the new demorunner.bat file. So, I am now trying out the various demos as I read through the book. (Great book btw!) But I have run into a new problem/question with the FontAttribute example. I can't seem to get the demo to use the custom fonts as described in the book or in the sample source code. Here are the fonts being used: ... Font scriptFont = new Font(French Script MT, Font.PLAIN, 40); Font funFont = new Font(Curlz MT, Font.PLAIN, 40); ... But I just get regular plain boring text showing up. The first thing to point out is there are no font files with these names anywhere in the example code. In the res/fonts folder, the closest files with these names are crl_.ttf and frs_.ttf. So I don't know if that's a problem, or if there is some logical mapping that takes the label Curlz MT and knows to use the crl__.ttf file for that font. I have copied all the files in the res/fonts directory to just about anywhere I could find a font folder. (I started out with the jre/lib/fonts folder as the readme file instructs, but since that didn't seem to do anything,even after I rebooted the machine, I have since copied all the files to my %JAVA_HOME%\jre\lib\fonts folder as well, and that didn't make a difference. Am I missing something simple here? Thanks! Rob - Original Message - From: Vincent Hardy [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, January 05, 2004 11:37 PM Subject: Re: [JAVA2D] Java 2D Api Graphics by Vincent Hardy Hi Rob, The following should fix your problem on XP. === 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.
Re: [JAVA2D] Java 2D Api Graphics by Vincent Hardy
- Original Message - From: Vincent Hardy [EMAIL PROTECTED] On Mac OS, it looks like there is a path issue. The DemoRunner code invokes a script that is not found. I suggest you try to run: runsnippet ColorTransparency for example and see if that works from the command line. On OS X, I can manually type in runsnippet ColorTransparency and that works fine. (I copied the new demo.properties file you provided over to the Mac as well, just in case.) I also added the current directory (ie, './') to the CLASS_PATH variable in the runsnippet shell script. However, I still get this error if I try to run the demorunner script and double-click a demo, such as ColorTransparency: Could not start demo : runsnippet: not found. I wonder, in the DemoRunner class, could it be that you're assuming a relative path the that file, i.e, 'runsnippet' and not an explicit path such as ./runsnippet? If I had the source code for DemoRunner I could check this myself on OS X. Rob === 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.
[JAVA2D] transparent windows yet?
I'm in the middle of a project where being able to make a window's background translucent/semi-transparent would be a very very cool thing to have. Is this possible yet with 1.4? If not, how about 1.5? Is this feature really that hard to implement? I'm asking honestly, I don't know what's required in the JVM to make this happen. But since both OS X and WindowsXP seem to do this all the time now, I have to assume most of the hard code already has been written in those platform's native libraries. Rob Ross Senior Software Engineer E! Networks [EMAIL PROTECTED] === 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.
[JAVA2D] calling repaint()
This is semi-swing related, but since there's not a swing-interest list and since it's also semi 2D related, I thought I'd try here. I learned this past JavaOne that every swing app I have ever written has been broken, as I often do public static void main(String[] args) { JFrame f = new JFrame(); f.setVisible(true); } when in fact I should be calling this from the event handling thread via a SwingUtilities.invokeLater() call. My question is, can I call repaint() on a component from another thread, or does that also have to be called from within the event thread? Doesn't repaint just queue a request for later processing anyway? If so, why would I need to spawn a separate thread just to call the repaint? Rob === 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.
[JAVA2D] How to create Image on headless machine?
I want to create an Image from scratch, get its graphics, draw into it, then use the Image to create a Jpeg. I can do all of this on a client JVM, but I have never tried this on the server side, and now I'm running into HeadlessExceptions. I vaguely recall that Java 1.4 provided some way to create images even in a headless environment, and I hope my memory is correct. What's the proper way to do this? Thanks! Rob Ross, Senior Software Engineer E! Networks [EMAIL PROTECTED] --- Beware of he who would deny you access to information, for in his heart he dreams himself your master. -- Commissioner Pravin Lal === 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.
Re: [JAVA2D] Click detection
On Aug 27, 2004, at 7:33 PM, Thomas Busey wrote: Since we are talking about mice, here is a hard one. I need to be able to move the position of the cursor on the screen. That is, I need something like: SetMouse(258, 234) which in applications would put this at screen location 258,234. Yes, I know this breaks all kinds of user interface guidelines, but I really need it for a psychology experiment. There are lots of java routines for reading the mouse position, but I need one that will set the mouse to a new location. Any ideas? Thanks, Tom look at java.awt.Robot.mouseMove() Rob Ross, Senior Software Engineer E! Networks [EMAIL PROTECTED] --- Beware of he who would deny you access to information, for in his heart he dreams himself your master. -- Commissioner Pravin Lal Rob Ross, Senior Software Engineer E! Networks [EMAIL PROTECTED] --- Beware of he who would deny you access to information, for in his heart he dreams himself your master. -- Commissioner Pravin Lal === 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.
[JAVA2D] animating Swing components
Hi. This is (mostly) off-topic, but maybe someone can point me to the proper place to ask this. I am comfortable creating animations in general by using Java 2D drawing and background threads. I'm not sure how to apply some of these concepts when using Swing components, however. One thing I'd like to animate is a JSplitPane, so when a user clicks a button or chooses a menu item, the JSplitPane will be adjust to some certain size, but I don't want to just jump to the new size. I want to see the JSplitPane scroll in real-time to its final size. There are other such animations I'd like to do, like scrolling a JTable or JTree to some specific position, while showing all the intermediate scroll positions to the user. Any pointers? Thanks, Rob Ross, Senior Software Engineer E! Networks [EMAIL PROTECTED] --- Beware of he who would deny you access to information, for in his heart he dreams himself your master. -- Commissioner Pravin Lal === 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.
Re: [JAVA2D] animating Swing components
On Jun 10, 2005, at 8:24 AM, Chet Haase wrote: Rob: I'm talking about this very subject (animating Swing components) in the Advanced 2D session at JavaOne, so c'mon by if you're at the show. Also, come by the Ask the Experts forum on Monday evening (630-800) and the 2D and Swing BOFs on Tuesday nights; other good places to pick our brains on this and other subjects... Chet. Hey that's great! I plan on being there. Rob Ross, Senior Software Engineer E! Networks [EMAIL PROTECTED] --- Beware of he who would deny you access to information, for in his heart he dreams himself your master. -- Commissioner Pravin Lal === 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.
[JAVA2D] changing swing.volatileImageBufferEnabled dynamically?
Can this property be changed dynamically, ie, during program execution? Or will it only be read once - at startup? I have a media player application in Java, running on Windows, that uses the Windows Media Player 9 SDK via JNI to play WMV files from a a MMS (streaming) server. This has been working great in production for quite a while. I am now adding support for playing Quicktime movies, via Quicktime for Java. However, I've been having major redraw issues (I'm using the native QT widgets, not the Swing ones - ie, a QTComponent, not a QTJComponent). Basically, if I move the window, or trigger some kind of repaint/update on the playing window (like moving the JFrame or clicking on another window, then clicking back on my main JFrame, the video starts acting weird, including pausing, artifacts, no longer being centered, dropping frames, etc. I have found through painful trial-and-error that if I set swing.volatileImageBufferEnabled property to false in my main() method, these redraw issues magically disappear when playing movies using the Quicktime player component. However, since the Windows Media files have been working fine for some 2 years now, I don't want to blanket-disable this property. I just want to set it to true when I'm displaying a Windows Media component for playing video, and false when using the Quicktime component. Can I do this? If not by setting this property, is there some API method I can call to dynamically change this value on the fly? Thanks! Rob Ross, Senior Software Engineer E! Networks [EMAIL PROTECTED] --- Beware of he who would deny you access to information, for in his heart he dreams himself your master. -- Commissioner Pravin Lal === 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.
[JAVA2D] changing swing.volatileImageBufferEnabled dynamically?
I asked this about a week ago and didn't get a response, so let me try again. If there is another list that might be more appropriate, I'd appreciate that info too. Is there a way to change the behavior of a Java app at runtime that will switch from enabling and disabling the volatile image buffer in Swing? Ie, the equivalent of setting swing.volatileImageBufferEnabled to true or false while the app is running? Or is this property only read once, at JVM startup, and never consulted again? I have some code that draws fine with swing.volatileImageBufferEnabled=true, and other code that craps out on me, so I'd like to change the setting as needed depending on what is being drawn. Thanks! Rob Ross, Senior Software Engineer E! Networks [EMAIL PROTECTED] --- Beware of he who would deny you access to information, for in his heart he dreams himself your master. -- Commissioner Pravin Lal === 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.
[JAVA2D] converting Java Image to Mac OS native image
Hi. Long shot here, but having no luck finding sample code... I'm writing some JNI code that will run on Mac OS X. I need to call a native method and pass it a Java image object, and be able to convert that to a Mac OS X native image type, like an NSImage. I'm pretty sure that the Java2D team knows how to do for Windows, since it must happen at some point in your Java 2D Windows native/ implementation code. Maybe I just need to be able to pass the Java image data as a byte[] in some well-known byte structure that represents a JPEG or GIF, etc, and I can convert it from there. Any pointers? Thanks, Rob Ross, Lead Software Engineer E! Networks [EMAIL PROTECTED] --- Beware of he who would deny you access to information, for in his heart he dreams himself your master. -- Commissioner Pravin Lal === 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.
[JAVA2D] writing java.awt.Image to Output stream
Let me try asking this question a different way. Say I have an animated GIF file on my hard drive, and say I load that aGIF into an java.awt.Image instance. Now say I want to save that image back to a new, different file. First, after I have saved it, will the bits in the new file be the same as the original, ie, are they byte-for-byte copies? If not that, can I at least open the new file in say a web-browser, and see all the animated frames that were originally present in the first file? (Is the integrity of the aGIF data still there?) If so, then can you point me to some sample code where I can write out the java.awt.Image to an OutputStream (ie, the same bytes that would end up in the new file as mentioned above)? If I can get this much, I can take it the rest of the way. Thanks! Rob Ross, Lead Software Engineer E! Networks [EMAIL PROTECTED] --- Beware of he who would deny you access to information, for in his heart he dreams himself your master. -- Commissioner Pravin Lal On Sep 20, 2006, at 12:42 PM, Rob Ross wrote: Hi. Long shot here, but having no luck finding sample code... I'm writing some JNI code that will run on Mac OS X. I need to call a native method and pass it a Java image object, and be able to convert that to a Mac OS X native image type, like an NSImage. I'm pretty sure that the Java2D team knows how to do for Windows, since it must happen at some point in your Java 2D Windows native/ implementation code. Maybe I just need to be able to pass the Java image data as a byte[] in some well-known byte structure that represents a JPEG or GIF, etc, and I can convert it from there. Any pointers? Thanks, Rob Ross, Lead Software Engineer E! Networks [EMAIL PROTECTED] --- Beware of he who would deny you access to information, for in his heart he dreams himself your master. -- Commissioner Pravin Lal == = 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. === 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.