The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   OS X Developer (http://hintsforums.macworld.com/forumdisplay.php?f=27)
-   -   applescript listen for apple event (http://hintsforums.macworld.com/showthread.php?t=73581)

tw 06-13-2007 12:45 AM

Quote:

Originally Posted by faezbhanji (Post 385470)
So you mean I have been struggling all these days for nothing, when all I had to do was embed the app in my page.....eek! why didn't you just say so;) just kidding...

Wittgenstein once said: "if no one ever did anything foolish, nothing intelligent would ever get done." ;)

Quote:

Originally Posted by faezbhanji (Post 385470)
Ok so I need add an idle loop, to my java app, are you able to tell me more about idle loops or point me in the right direction.

Will the java app quit itself when the user closes the page, or do I have to set it to quit when the user closes the page. If so how would the page know its being closed?

I'd try calling it just as you have it written, first, without building an idle loop. the java gets loaded and called once when the page loads - most likely you can just deal with it as a simple function call after that.

the java app automatically unloads when you close the page - no worries...

Quote:

Originally Posted by faezbhanji (Post 385470)
if I'm going to be calling a public function from within document.javaApp.doThisFunc() can I pass it parameters as well when I call it...so document.javaApp.doThisFunc(prm1, prm2, prm3)

yes. if the function is defined in the java to take a parameter, you can pass it just like normal from javascript. the only thing to consider is that (I think) the passed parameters will automatically be converted to text strings. if you're passing numbers or booleans you'll need to coerce them from text.

Quote:

Originally Posted by faezbhanji (Post 385470)
On another note, how do I get the position of the top of the document and the left of the document, when I do "window.screenTop" and "window.screenLeft" it gives me the top left position of the whole window, but I want the top left of the document.

I think you can safely assume that the top left of the document will always be {0,0} (relative to the window, of course - you don't need to account for the window position on the screen). getting the position of elements in DOM is sometimes a little tricky, though, because different browsers use different conventions. (if I remember correctly, IE gives coordinates relative to the top left of the document, even if it's off-screen, while Mozilla gives them relative to the top-left corner of the visible area; or maybe it's the other way around...)

tw 06-13-2007 01:18 AM

Quote:

Originally Posted by bunnz (Post 385548)
If a java app which resides locally (and acts locally) can be embedded so readily in a web page, why is there so much fear and loathing of running other _local_ scripts and apps from links in HTML?

Is the java sandbox that much more restricted than the Mac OS in terms of security?

cwtnospam (as usual) has it right: java isn't designed to interact with the file system as a whole, but rather to do self-contained processing with user interaction.

the fear and loathing, as you put it, of running other scripts and apps from links in HTML is (maybe) natural. I mean, every time you run any application or script on your machine, it's a bit like getting an injection - it goes right into the machine's bloodstream and bypasses a few levels of protection. the paranoia about running things from HTML is that it feels as though anyone in the world could walk up to you and give you an injection, maybe even without you knowing about it. keeping HTML from running local apps is good prophylaxis, and not one that most people want to relax.

faezbhanji 06-13-2007 05:45 AM

Quote:

Originally Posted by tw (Post 385599)
java isn't designed to interact with the file system as a whole, but rather to do self-contained processing with user interaction.

groan.....not again pleeeease...remember my "save" button. My java app that will get launched or in this case which will run in the background captures the image of the chart, converts it to a jpg and then saves it as a file. But it comes up with a dialog box which prompts the user for the name and location for the file. Then if as you say in your quote above, will I still be able to do this?? I don't mind if the user is only able to save to the same folder as where the java app resides.

tw 06-13-2007 05:56 AM

if you can make jave save to a file, it will do it from the web page.

faezbhanji 06-13-2007 06:01 AM

Quote:

Originally Posted by tw (Post 385624)
if you can make jave save to a file, it will do it from the web page.

hi tw, could you be a bit more specific, I don't quite understand what you mean?

tw 06-13-2007 11:05 AM

Quote:

Originally Posted by faezbhanji (Post 385625)
hi tw, could you be a bit more specific, I don't quite understand what you mean?

I'm just saying that the context of java is not going to impact on how it works. you said you had a java app that saved a file. if so, it will do that if you run it as a stand-alone or as a browser object.

you're in the realm here where you have to experiment and work out the kinks you find. I can't help you much with what amounts to debugging issues.

faezbhanji 06-14-2007 01:29 AM

Quote:

Originally Posted by tw (Post 385369)
lol -
to embed and use a java app in a web page do something like this...

Code:

    <applet id="javaApp" code="path.in.jar.to.main.class" name="name.of.mainroutine" Archive="javaAppName.jar" codebase="." style="...display considerations if necessary...">
    <param name="param1" value="default1-if needed">
    <param name="param2" value="default2-if needed">
  </applet>


hi tw, just trying to figure out where in the page I should put your code, I already have the <object> and <embed> tags in my page. They are being used to embed the flash charting utility. Should your code go in between the <object> tags as well, or should it reside outside the object tag.

I tried googling "java application embed webpage" and other variations on this to try and find out for myself, but I couldn't find any examples of places where a java app is actually being embedded, although there seem to be many where there are applets being embedded.

If you could also point me to some further reading material on this I would really appreciate it.

tw 06-14-2007 01:52 AM

Quote:

Originally Posted by faezbhanji (Post 385861)
hi tw, just trying to figure out where in the page I should put your code, I already have the <object> and <embed> tags in my page. They are being used to embed the flash charting utility. Should your code go in between the <object> tags as well, or should it reside outside the object tag.

honestly, you would normally the applet object in your page in the place where you would want it to display (outside of the object or embed tags that you're using for the flash - this is a separate object, yah?). since your java doesn't have a display component, and all you're trying to to is load it into the page so you can run it, you can place it anywhere in the body of the html that you like. you can just use the applet block, or convert it to an object format (see below): no need to enclose those in any other html block.

best thing to do is find someone who is giving the source code for an embedded java app. I first learned how to do this by looking at the source code for MyPhysicsLab, which I needed to adapt for a project I was doing. it's complex programming to start with (though very well done - hats off to Erik Neumann) - you might want to see if there's some other simpler source code out there.

maybe this will help, too - WC3 standards for objects and applets in HTML 4

faezbhanji 06-14-2007 03:12 AM

Hi Tw,
greetings from down-under, could you have a look at the code below, this is what I have put in my page, but the java app doesn't seem to want to run, it should pop-up with the SaveAs dialog, but it doesn't do anything.

Code:

<APPLET name="app1" code="savechart.class" archive="SaveChart.jar" codebase="." >
<param name="inputtop" value="0">
<param name="inputleft" value="0">
<param name="inputwidth" value="700">
<param name="inputheight" value="800">
</APPLET>

Also I'm not sure about the param names and what I should be putting there, the main in java always takes only one parameter which is args[], which in my case has 4 elements, these are then being saved into variables called inputtop, inputleft etc etc which is the reason why I show them here in the param name section I'm not sure if that's what I need to do.

I can launch the jar file from the terminal so that is working fine, which would mean something in my html code above is not right

I'm publishing my java code below, could you please compile it and save it as a jar file and see if you can get it to run.
to run it all you need to do is give the jar file 4 parameters say 0 0 500 700, these are the rectangle of the screen shot it will take of the screen.

Code:

import java.awt.image.BufferedImage;
    import java.io.*;
    import java.awt.*;
    import java.awt.Robot;
    import java.awt.Image.*;
    import com.sun.image.codec.jpeg.*;
   
public class savechart {
 
 
    public savechart(int top, int left, int width, int height) {
      try {
          BufferedImage capture = null;
          Rectangle area = new Rectangle(top, left, width, height);
          Robot robot = new Robot();
          capture = robot.createScreenCapture(area);
          Frame frame = new Frame();
          FileDialog fDialog = new FileDialog(frame,"Save Chart",FileDialog.SAVE);
          fDialog.setFile("*.jpeg");
          fDialog.setVisible(true);
          fDialog.requestFocus();
          String A = fDialog.getDirectory();
          String B = fDialog.getFile();
          String C = System.getProperty("file.seperator");
          String imgFile = fDialog.getDirectory() + fDialog.getFile();
          FileOutputStream out = new FileOutputStream(imgFile);
          JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
          encoder.encode(capture);
          out.flush();
          out.close();
          System.exit(0);
         
      } catch (Exception exc){
          System.out.println("errors ");
          exc.printStackTrace();
      }
     
      finally {
          System.out.println("Error Creating Image");
          System.exit(0);
         
      }
    }
   
    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
      int inputtop = Integer.parseInt(args[0]);
      int inputleft = Integer.parseInt(args[1]);
      int inputwidth = Integer.parseInt(args[2]);
      int inputheight = Integer.parseInt(args[3]);
           
      new savechart(inputtop,inputleft,inputwidth,inputheight);
    }
   
}


tw 06-14-2007 09:57 AM

faez,

you're almost there, I can see that. play with it for a week and see if you can iron out the kinks.

faezbhanji 06-14-2007 10:31 AM

Quote:

Originally Posted by tw (Post 385911)
faez,

you're almost there, I can see that. play with it for a week and see if you can iron out the kinks.

:eek: a week! this is due monday, I'm supposed to be doing a presentation on monday with my boss and the client! I have been struggling with this for the last two weeks....c'mon dude...you gotta help me out here.

I'm assuming my java code is ok and the problem is in my html tags am I right?
Also with those params how am I supposed to use them?

it would be kewl if you help, but if you can't well..then I'm up sh!t creek...:confused:

faezbhanji 06-17-2007 03:42 AM

I have worked on this all weekend, I'm not having much luck getting it to run
if anyone out there can help I would greatly appreciate it.


All times are GMT -5. The time now is 05:51 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.