About draw GIF in "paintComponent(Graphics)" Method ???

I extends a new class A from JPanel and overwrite the method of "paintComponent(Graphics)", the code is like below:
public void paintComponent(Graphics g)
  super.paintComponent(g);
  // imgObj is a GIF file.
  g.drawImage(imgObj, 100, 100, this);
}it's OK, the GIF can be show like a movie.
but if the code in an other class B, and invoke in A.paintComponent method, it can not show like a movie, it only show a static frame. Code like below:
public void paintComponent(Graphics g)
  super.paintComponent(g);
  bClassObj.drawGIF(g);
public class B
  public void drawGIF(Graphics g)
    g.drawImage(imgObj, 100, 100, this);
} WHY !!!!???

I try it OK...
the last parameter of method drawImage() in B must be point to instance of A.

Similar Messages

  • Drawing with paintComponent(Graphics g) problem?

    hey, i just recently learnt from a response to previous posts not to put logic type stuff like if statements in the paintComponent method, but how do i get around the issue of drawing something different based on a boolean expression?
    i want to be able to do something like,
    paintComponent(Graphics g) {
          if(drawCircle == true) {
              g.drawCircle(....)
         }else{
              g.drawRectangle(......)
    }Yes, i know i shouldn't do that as i said i've been told NEVER to do this, but how do i work around this issue?
    thanks

    hey, i just recently learnt from a response to previous posts not to put logic type stuff like if statements in the paintComponent method, but how do i get around the issue of drawing something different based on a boolean expression?If you refer to that [my reply in your former thread|http://forums.sun.com/thread.jspa?messageID=10929900#10929900] , note that I warned you against putting business logic (+if (player.hasCollectedAllDiamonds()&&timer.hasNotTimedOut()&&allEnnemies.areDead()) { game.setState(FINISHED);}+) into your paintComponent(...) method, I didn't ask you to ban logic altogether (+if (player.hasCollectedAllDiamonds()) { Graphics.setColor(Color.GREEN); }+)
    EDIT: Oh, how pretentious I was; obviously you merely refer to [this Encephalopathic's post|http://forums.sun.com/thread.jspa?messageID=10929668#10929668], who warns against program logic in paint code; same misunderstanding though, he certainly only meant that the paintXXx's job is not to determine whether the game is over, only to render the game state (whichever it is, it has been determined somewhere else, not in painting code).

  • Drawing without paintComponent(Graphics g)

    Hi to all,
    I use paintComponent(Graphics g) to draw particular rectangles on the screen, then i add some event to these rectangles. So far so good.I handle the mouse click from -->
    public void mouseClicked(MouseEvent e){
    // handling goes here
    But an important part of my handling is to also draw something on the screen.
    How can i do that from the mouseClicked method? Can i draw without using paintComponent(...)?
    I mean that, once the paintComponent(...) method finishes, how can i still draw something on the screen?
    Thanks,
    John.

    You can use
    Graphics gg = component.getGraphics();
    gg.draw ....
    but it will be cleared in the paintComponent method
    Look at this sample, the red rectangle will show up when the mouse
    is presses, and gone when the mouse will be released.
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.util.*;
    public class Shapes extends JFrame
         DPanel pan = new DPanel();
    public Shapes()
         addWindowListener(new WindowAdapter()
              public void windowClosing(WindowEvent ev)
                   dispose();
                   System.exit(0);
         setBounds(10,10,400,350); 
         setContentPane(pan);
         setVisible(true);
    public class DPanel extends JPanel implements MouseListener
         Vector shapes = new Vector();
         Shape  cs;
    public DPanel()
         addMouseListener(this);
         shapes.add(new Rectangle(20,20,100,40));
         shapes.add(new Rectangle(40,80,130,60));
         shapes.add(new Line2D.Double(20,150,200,180));
    public void paintComponent(Graphics g)
         super.paintComponent(g);
         Graphics2D g2 = (Graphics2D)g;
         for (int j=0; j < shapes.size(); j++)
              g2.draw((Shape)shapes.get(j));
         g.setColor(Color.red);
         if (cs != null) g2.draw(cs);
    public void mouseClicked(MouseEvent m) {}
    public void mouseEntered(MouseEvent m) {}
    public void mouseExited(MouseEvent m)  {}
    public void mouseReleased(MouseEvent m)
         repaint();
    public void mousePressed(MouseEvent m)
         for (int j=0; j < shapes.size(); j++)
              Shape s = (Shape)shapes.get(j);
              Rectangle r = new Rectangle(m.getX()-1,m.getY()-1,2,2);
              if (s.intersects(r))
                   cs = s;
                   Graphics g = getGraphics();
                   g.setColor(Color.red);
                   g.fillRect(r.x-5,r.y-5,10,10);
    public static void main (String[] args) 
          new Shapes();
    }

  • Calling paintComponent(Graphics g) in another class

    Dear Friends,
    I have a class (Class Pee) where I implemented the paintComponent(Graphics g) and another class (Class Bee) where I generate some datas. My intention is to call the paintComponent(Graphics g) method in class Pee at class Bee to make use of the generated data to draw some figures.
    I imported java.awt .Graphics, java.awt.Graphics2D, Polygon and geom and declared Graphics2D g2d = (Graphics2D) g; as well, but still when I call paintComponent (Graphics g) it fails to recognize the g. What is actually wrong.
    See code:
    Class Pee
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Polygon;
    import javax.swing.JPanel;
    public class Pee extends JPanel{
    private int offset;
    public void paintComponent(Graphics g, int b[], int c[]){
    super.paintComponent(g);
    Graphics2D g2D = (Graphics2D) g;
    this.setBackground(Color.white);
    Class Bee
        import java.io.*;
        import java.util.*;
        import java.awt.Graphics;
        import java.awt.Graphics2D;
        import java.awt.geom.*;
        import java.awt.Polygon;
       import Graphic.Pee; //importing Pee Class
    public class Bee{
    int x[];
    int y[];
    // other variable declaration
    public Bee{
    x = new int [5];
    y = new int [5];
    Pee dr = new Pee();
    Graphics2D g2d = (Graphics2D) g;
    //code to generate data
    dr.paintComponent(g,x,y);
    }It always say that "g" cannot be resolved. Please how do I get over this.
    Thanks,
    Jona_T

    Swing calls the paintComponent method when we ask a component to draw itself. We do this by
    calling its repaint method. So the general approach is to change the data in the component
    that does the graphics for us and then ask the component to repaint itself. Swing does the
    rest. One benefit of this way of doing things is that the graphic component keeps the data
    and can render all or any part of it at any time. Trying to get a reference to the
    components graphics context from within another class and using it to draw graphics in the
    graphics component prevents this and the foreign class event code can never know when the
    graphics component needs to be re&#8211;rendered.
    So the idea is to keep the graphics/rendering component independent from the event code. The
    event code controls the state (member variables) in the graphics component and tells it when
    to re&#8211;render itself.
    There are a lot of (creative) ways of putting these things together. Here's an example.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.util.Random;
    import javax.swing.*;
    public class CallingGraphics implements ActionListener {
        GraphicComponentClass graphicComponent;
        DataGenerationClass   dataGenerator = new DataGenerationClass();
        public void actionPerformed(ActionEvent e) {
            Point2D.Double[] data = dataGenerator.getData();
            graphicComponent.setData(data);
        private JPanel getGraphicComponent() {
            graphicComponent = new GraphicComponentClass();
            return graphicComponent;
        private JPanel getLast() {
            JButton button = new JButton("send data to graphics");
            button.addActionListener(this);
            JPanel panel = new JPanel();
            panel.add(button);
            return panel;
        public static void main(String[] args) {
            CallingGraphics test = new CallingGraphics();
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(test.getGraphicComponent());
            f.getContentPane().add(test.getLast(), "Last");
            f.setSize(400,300);
            f.setLocation(200,200);
            f.setVisible(true);
    class GraphicComponentClass extends JPanel {
        Ellipse2D.Double[] circles = new Ellipse2D.Double[0];
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            for(int j = 0; j < circles.length; j++) {
                g2.draw(circles[j]);
        public void setData(Point2D.Double[] p) {
            double w = getWidth();
            double h = getHeight();
            double dia = 75.0;
            circles = new Ellipse2D.Double[p.length];
            for(int j = 0; j < circles.length; j++) {
                double x = p[j].x*(w - dia);
                double y = p[j].y*(h - dia);
                circles[j] = new Ellipse2D.Double(x,y,dia,dia);
            repaint();
    class DataGenerationClass {
        Random seed = new Random();
        public Point2D.Double[] getData() {
            int n = seed.nextInt(25);
            Point2D.Double[] locs = new Point2D.Double[n];
            for(int j = 0; j < n; j++) {
                double x = seed.nextDouble();
                double y = seed.nextDouble();
                locs[j] = new Point2D.Double(x, y);
            return locs;
    }

  • Class A extends B- where is paintComponent(Graphics) supposed to paint?

    Hi,
    i have the following problem: I thought ControlPanel.paintComponent(Graphics) was supposed to paint the GraphArea (since ConrolPanel.paintComponent(Graphics) overrides GraphAreaExtension.paintComponent(Graphics) ), but lines AND vertices appear on the ControlPanel. Any ideas?
    import ...
    public class GraphAreaExtension extends JPanel
        public int clickCounter;  //how many clicks have been performed, ie
                                    //how many vertices have been painted
        public int clickedX;
        public int clickedY;
        public Point[] darray;
        public GraphAreaExtension()
            setBorder(BorderFactory.createTitledBorder("Graph Area"));
            setPreferredSize(new Dimension(640, 450)); 
            setMaximumSize(new Dimension(640, 450));
            clickCounter=0;
            darray=new Point[8];
            clickedX=-50;
            clickedY=-50;      
            initializeDarray();
            addMouseListener(new MouseAdapter()
               public void mouseClicked (MouseEvent e)
                    clickCounter++;
                    if (clickCounter<=8)
                        clickedY=e.getY();               
                        clickedX=e.getX();
                        darray[clickCounter-1]=new Point(clickedX, clickedY);
                        System.out.print("Click counter "+clickCounter+" ");                   
                        System.out.println("Mouse clicked X: "+clickedX+" Y:"+clickedY);
                        repaint();
                        validate();
        }//GraphAreaExtension constructor
        public void paintComponent(Graphics g)
            System.out.println("paint vertex...");
            g.drawOval(clickedX,clickedY, 25,25);
            g.drawString(getVertexName(clickCounter),clickedX+11, clickedY+15);
            printDarray();
        private static String getVertexName(int num)
            num=num+96;
            char c=(char)num;
            String s=String.valueOf(c);
            return s.toUpperCase();
        private void initializeDarray()
            for (int i=0; i<darray.length; i++)
                darray=new Point(0,0);
    public void printDarray()
    for (int i=0; i<darray.length;i++)
    System.out.print(darray[i].getX()+"\t");
    System.out.println();
    for (int i=0; i<darray.length;i++)
    System.out.print(darray[i].getY()+"\t");
    System.out.println();
    import ...
    /*  This is the Control Panel. 3 kinds of visual objects exist here:
    *  -the JCheckBoxes, which indicate the incoming connections: in1-in8
    *  -the JCheckBoxes, which indicate the outcoming connections: out1-out8
    *  -the "Enter" button, which when pressed updates the in/out-coming
    *   connections -graphically designs the edges, between the vertices.
    *  The data taken from the in/out-coming JCheckBoxes are stored inside
    *  2 boolean arrays respectively: inCon and outCon.
    public class ControlPanel extends GraphAreaExtension implements ItemListener
        JPanel controlPanel;
        JButton jb;
        boolean[] inCon;
        boolean[] outCon;
        JCheckBox in1, in2, in3, in4, in5, in6, in7, in8;
        JCheckBox out1, out2, out3, out4, out5, out6, out7, out8;
        public ControlPanel()
            inCon= new boolean[8];
            outCon= new boolean[8];
            initializeBooleanTable(inCon);
            initializeBooleanTable(outCon);             
            setPreferredSize(new Dimension(800,150));
            setBackground(Color.LIGHT_GRAY);                  
            setBorder(BorderFactory.createTitledBorder("Connections"));
            setPreferredSize(new Dimension(120, 150));                   
            setMaximumSize(new Dimension(120, 150));
            JLabel in= new JLabel("Incoming connections");
            add(in);
            in1=new JCheckBox("A");
            in1.addItemListener(this);
            add(in1);
            in4=new JCheckBox("D");
            in4.addItemListener(this);
            add(in4);
            in8=new JCheckBox("H");
            in8.addItemListener(this);
            add(in8);
            JLabel out= new JLabel("Outcoming connections");
            add(out);          
            out1=new JCheckBox("A");
            add(out1);      
            out1.addItemListener(this);
            out3=new JCheckBox("C");           
            add(out3);  
            out3.addItemListener(this);
            out8=new JCheckBox("H");           
            add(out8);      
            out8.addItemListener(this);
            initializeCheckbox();
           /*  pressing the Enter button, the data concerning the connections,
            *  which the user has entered are transformed into edges between the
            * vertices.
            *  Incoming edges: Green and Outcoming: Red
            jb= new JButton("Enter");
            add(jb);
            jb.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    printConnectionArrays();
                    repaint();
                    validate();
        }//ControlPanel constructor
        public void paintComponent(Graphics g)
            System.out.println("paint edge...");
            for (int i=0; i<darray.length; i++)
                if (inCon==true)
    System.out.println("Entered incoming edges condition for node num "+ (i+1));
    g.drawLine(clickedX,clickedY,(int)darray[i].getX(), (int)darray[i].getY());
    System.out.println("baseX "+clickedX+" baseY "+clickedY+" destX "+(int)darray[i].getX()+" destY "+(int)darray[i].getY());
    g.setColor(Color.GREEN);
    if (outCon[i]==true)
    System.out.println("Entered outcoming edges condition for node num "+ (i+1));
    g.drawLine(clickedX, clickedY,(int)darray[i].getX(), (int)darray[i].getY());
    System.out.println("baseX "+clickedX+" baseY "+clickedY+" destX "+(int)darray[i].getX()+" destY "+(int)darray[i].getY());
    g.setColor(Color.RED);
    }//END for
    initializeCheckbox();
    initializeBooleanTable(inCon);
    initializeBooleanTable(outCon);
    /******************************Helper***Functions***************************/
    /* unchecks Checkboxes for next use
    public void initializeCheckbox()
    in1.setSelected(false); out1.setSelected(false);
    in8.setSelected(false); out8.setSelected(false);
    public void itemStateChanged(ItemEvent e)
    System.out.println("Entered ItemStateChanged()...");
    Object source = e.getItemSelectable();
    if (source.equals(in1)) inCon[0]=true;
    else if (source.equals(in2)) inCon[1]=true;
    else if (source.equals(in8)) inCon[7]=true;
    if (source.equals(out1)) outCon[0]=true;
    else if (source.equals(out2)) outCon[1]=true;
    else if (source.equals(out8)) outCon[7]=true;
    public void printConnectionArrays()
    System.out.print("Incoming ");
    for (int i=0; i<darray.length; i++)
    System.out.print(inCon[i]+" ");
    System.out.print("Outcoming ");
    for (int i=0; i<darray.length; i++)
    System.out.print(outCon[i]+" ");
    System.out.println();
    public static void initializeBooleanTable(boolean[] t)
    for (int i=0; i<t.length-1; i++)
    t[i]=false;

    I've not a clue which is faster, but from an OO point of view--the object should know how to draw itself.

  • Ridiculously dumb question about drawing in JPanel

    Howdy everyone,
    I gotta really stupid question that I cant figure out the answer to. How do I draw an image to a JPanel, when my class inherits from JFrame?
    Thanks,
    Rick

    Ok,
    Problem. The image isnt showing up in the Frame I set up for it. Heres my code. Im trying to get this image to show up in a scollable window. Can anyone tell what the problem with this code is??
    JPanel imgPanel= new JPanel(){
    protected void paintComponent(Graphics g){
    super.paintComponent(g);
    g.drawImage(getToolkit().createImage(imstr),imgw,imgh,this);
    imgPanel.setVisible(true);
    this.getContentPane().setLayout(new BorderLayout());
    this.getContentPane().add(new JScrollPane(imgPanel));
    this.setVisible(true);
    Any ideas?
    Thanks
    Rick

  • A question about drawing lines

    Dear experts,
    Plz can anybody let me know the syntax of line by which one could alter the thickness of line as much as possible or up to some fixed limit.
    Plz: if there is another alternative to do that such as ellipse,plz dont suggest.

    If you are drawing inside paintComponent you can use the BasicStroke class. See the class api for options. The Java2D app in your sdk demo folder has more.
    protected void paintComponent(Graphics g) {
        Graphics2D g2 = (Graphics2D)g;
        g2.setStroke(new BasicStroke(3f));

  • Using paintComponent(Graphics g)

    Hi,I need to know how to put a square to the screen using the paintComponent(Graphics g). The square must be put into the shapesArrayList. I know how to get a square to the screen but ive been asked to put it into the shapesArrayList.
    Tried a few things but im stumped!
    Any help would be great!
    Peter
    public void paintComponent(Graphics g){
    super.paintComponents(g);
    Shape nextShape;
    Iterator shapesIterator = shapesArrayList.iterator();
    while(shapesIterator.hasNext())
    nextShape = (Shape) shapesIterator.next();
    nextShape.draw(g);
    are to the panel in this class

    Never mind, it was just something I was doing wrong.

  • PaintComponent(Graphics g) problem

    hi, guys:
    Can someone tell me why my code is not work in paintComponent(Graphics g)
    below are my code:
    protected void paintComponent(Graphics g)
         g.drawLine(0, 0, 100, 100); //this line work
    this.getGraphics().drawLine(0,0,100,100); //this is not work
    I know I should use auto passed "Graphics g", however, I don't understand why this.getGraphics() can't do the same work. It should return the same Graphics object which I expected.
    Thanks for help.

    I just posted my code below (Applet), hope helpful.
    package mypackage;
    import java.applet.Applet;
    import java.awt.*;
    import javax.swing.*;
    class CatchTheCreaturePanel extends JPanel
         private Creature[] creature;
         public CatchTheCreaturePanel()
              this.setPreferredSize(new Dimension(400,300));          
         public void paintComponent(Graphics g)
              g.drawLine(50, 70, 100, 100); //work
              this.getGraphics().drawLine(0, 0, 100, 100); //not work
    public class Jmyass extends JApplet {
         private CatchTheCreaturePanel the_panel;
         public Jmyass() {
              super();
         public void init() {
              the_panel=new CatchTheCreaturePanel();
         public void start() {
              this.getContentPane().add(the_panel);          
    }

  • Draw Image out of paint(graphics) method

    Does anybody know who can I draw an image out of the paint method of the component??
    thx

    Create a BufferedImage, get it's graphics and draw on this image as much as you want.
    BufferedImage bI = new BufferedImage(200,200,BufferedImage.TYPE_3BYTE_BGR);
    Graphics      g  = bI.getGraphics();
    Graphics2D    g2 = bI.createGraphics();
    g.setColor(Color.red);
    g.drawLine(10,10,190,190);
    g2.setColor(Color.blue);
    g2.draw(new Rectangle(50,50,100,100));

  • Now draw your own ScriptUIGraphics graphics! (1st testing)

    Hey everyone, I've made this little system of drawing ScriptUIGraphics from your illustrator document.  Please be advised, the graphics resulting from this are not anti-aliased and look bad at medium sizes --> terrible at small sizes, but they may help with making some dynamic icons for some really specific scriptUI purposes.
    Basically, you just draw something in an AI doc, run this window and use the function from it as well as the object resource string to recreate that drawing in your own scriptUI windows.
    This method only uses straight lines and ellipses when it detects ellipses.  After seeing the quality of these drawings, I'm thinking for the prettier icons you'd surely want to embed images into your UI, but there may come a very very rare time when there exists a need for some dynamic image with many states, so this may be what it may end up perhaps being useful for.
    Attached are screenshots with original drawing (artboard is 100x100px), the captured image drawn in window and last, pretty much the same- is the result drawn from object resource string.  The screenshots JPEGs have smoothed out the little icons, making them look actually better than they really are!
    Edit: 
         Oh yes, I did need to mention: the colors used can be any color, spot/Lab included!  They just get changed to some version of RGB for rendering.
    // ScriptUI Graphics Display by Vasily
    function graphicsDisplay(){
        function itemShape(myShape){
            // Going to test for circles.
            var shapeKind={
                isrectangle: null,
                iscircle: null,
                isellipse: null
            if(myShape.typename=='PathItem' && myShape.pathPoints.length == 4){ // RECTANGLE CHECKER
                //--------------------2 diagonals-------------------------
                var recEquaDistOne = parseInt(Math.pow((myShape.pathPoints[0].anchor[0] - myShape.pathPoints[2].anchor[0]),2) +
                Math.pow((myShape.pathPoints[0].anchor[1] - myShape.pathPoints[2].anchor[1]),2)); // diagonal
                var recEquaDistTwo = parseInt(Math.pow((myShape.pathPoints[1].anchor[0] - myShape.pathPoints[3].anchor[0]),2) +
                Math.pow((myShape.pathPoints[1].anchor[1] - myShape.pathPoints[3].anchor[1]),2)); // diagonal
                //---------------------4 sides of rectangle---------------
                var sideA = parseInt(Math.pow((myShape.pathPoints[0].anchor[0] - myShape.pathPoints[1].anchor[0]),2) +
                Math.pow((myShape.pathPoints[0].anchor[1] - myShape.pathPoints[1].anchor[1]),2)); 
                var sideB = parseInt(Math.pow((myShape.pathPoints[1].anchor[0] - myShape.pathPoints[2].anchor[0]),2) +
                Math.pow((myShape.pathPoints[1].anchor[1] - myShape.pathPoints[2].anchor[1]),2)); 
                var sideC = parseInt(Math.pow((myShape.pathPoints[2].anchor[0] - myShape.pathPoints[3].anchor[0]),2) +
                Math.pow((myShape.pathPoints[2].anchor[1] - myShape.pathPoints[3].anchor[1]),2)); 
                var sideD = parseInt(Math.pow((myShape.pathPoints[3].anchor[0] - myShape.pathPoints[0].anchor[0]),2) +
                Math.pow((myShape.pathPoints[3].anchor[1] - myShape.pathPoints[0].anchor[1]),2)); 
                if(recEquaDistOne == recEquaDistTwo){ // If two diagonals connecting opposite points are same length, it's a 90 degree box               
                    if((sideA == sideC) && (sideB == sideD)){
                        for(var j=0; j<4; j++){
                            var point = myShape.pathPoints[j];             
                                if((point.leftDirection[0] == point.anchor[0]) &&
                                    (point.anchor[0] == point.rightDirection[0]) &&
                                    (point.leftDirection[1] == point.anchor[1]) &&
                                    (point.anchor[1] == point.rightDirection[1])){                                                   
                                    shapeKind.isrectangle = true;
                                } else {
                                    shapeKind.isrectangle = false;
                                    break;
                if(myShape.pathPoints.length == 4){  // CIRCLE CHECKER
                    if(shapeKind.isrectangle == false || shapeKind.isrectangle == null){
                        var circlePts = new Array();
                        var circleSlopes = new Array();
                        for (k=0; k<4; k++){
                        var point = myShape.pathPoints[k]; 
                        var leftHandleDist = parseInt(Math.pow((point.leftDirection[0] - point.anchor[0]),2) +
                        Math.pow((point.leftDirection[1] - point.anchor[1]),2));
                        var rightHandleDist = parseInt(Math.pow((point.rightDirection[0] - point.anchor[0]),2) +
                        Math.pow((point.rightDirection[1] - point.anchor[1]),2));
                        circlePts.push(leftHandleDist, rightHandleDist);
                        var leftHandleSlope = ((point.leftDirection[0] - point.anchor[0])/(point.leftDirection[1] - point.anchor[1])).toFixed(2);
                        var rightHandleSlope = ((point.rightDirection[0] - point.anchor[0])/(point.rightDirection[1] - point.anchor[1])).toFixed(2);
                        circleSlopes.push(leftHandleSlope, rightHandleSlope);
                    for(var f=0; f<8; f++){ // Allows non-rotated circles.
                        if(circleSlopes[f] == "-0.00"){
                            circleSlopes[f] = "0.00";
                        if(circleSlopes[f] == "-Infinity"){
                            circleSlopes[f] = "Infinity";
                    var cirEquaDistOne = parseInt(Math.pow((myShape.pathPoints[0].anchor[0] - myShape.pathPoints[2].anchor[0]),2) +
                    Math.pow((myShape.pathPoints[0].anchor[1] - myShape.pathPoints[2].anchor[1]),2));
                    var cirEquaDistTwo = parseInt(Math.pow((myShape.pathPoints[1].anchor[0] - myShape.pathPoints[3].anchor[0]),2) +
                    Math.pow((myShape.pathPoints[1].anchor[1] - myShape.pathPoints[3].anchor[1]),2));
                    if(circleSlopes[0] != "NaN"){ // Filters out asymmetric rhombus  <><><>^^^^^^<><><>
                        if((circlePts[0] == circlePts[1]) && // Filters out shapes with control handles not of equal distance from anchor point.
                            (circlePts[1] == circlePts[2]) &&
                            (circlePts[2] == circlePts[3]) &&
                            (circlePts[3] == circlePts[4]) &&
                            (circlePts[4] == circlePts[5]) &&
                            (circlePts[5] == circlePts[6]) &&
                            (circlePts[6] == circlePts[7]) &&
                            (circlePts[7] == circlePts[0])){
                            if((circleSlopes[0] == circleSlopes[1]) && // Filters out the equadistant 4-pointed Star shape (dismisses negative slopes).
                                (circleSlopes[2] == circleSlopes[3]) &&
                                (circleSlopes[4] == circleSlopes[5]) &&
                                (circleSlopes[6] == circleSlopes[7])){
                                if(cirEquaDistOne == cirEquaDistTwo){ // Filters out Ellipses (non-equadistant circles).
                                    // Filters out the very RARE 4-pointed star which has all control points in its center on top of each other!
                                    if(((myShape.pathPoints[0].leftDirection[0]).toFixed(2) != (myShape.pathPoints[1].leftDirection[0]).toFixed(2)) &&
                                        ((myShape.pathPoints[0].leftDirection[1]).toFixed(2) != (myShape.pathPoints[1].leftDirection[1]).toFixed(2))){
                                        shapeKind.iscircle = true;
                                    } else {
                                        shapeKind.iscircle = false;
                        } else {
                            if((circlePts[0]==circlePts[1]) &&
                                (circlePts[2]==circlePts[3]) &&
                                ((circlePts[4]==circlePts[5]) && (circlePts[4]==circlePts[1]) && (circlePts[5]==circlePts[1])) &&
                                ((circlePts[6]==circlePts[7]) && (circlePts[6]==circlePts[2]) && (circlePts[7]==circlePts[3]))){
                                shapeKind.isellipse=true;
        //~                     $.writeln(circlePts[0]+'\r'+circlePts[1]+'\r'+circlePts[2]+'\r'+circlePts[3]+'\r'+
        //~                     circlePts[4]+'\r'+circlePts[5]+'\r'+circlePts[6]+'\r'+circlePts[7]);
            return shapeKind;
        if(app.name=='Adobe Illustrator' && app.documents.length>0){
            function round2(num){
                return Math.round(num*100)/100;
            function convertToUIRGB(color){
                if(color=='[CMYKColor]'){
                    var c=color.cyan, m=color.magenta, y=color.yellow, k=color.black;
                    return [
                        round2((1-(c/100))*(1-(k/100))),
                        round2((1-(m/100))*(1-(k/100))),
                        round2((1-(y/100))*(1-(k/100)))
                } else if(color=='[GrayColor]'){
                    var k=color.gray;
                    var grayValue=1-(Math.round(((k/100)*255)*100)/100)/255;
                    return [grayValue,grayValue,grayValue];
                } else if(color=='[GradientColor]'){
                    $.writeln('Sorry, no gradient colors please.');
                    return [0,0,0];
                } else if(color=='[PatternColor]'){
                    $.writeln('Sorry, no pattern colors please.');
                    return [0,0,0,];
                } else if(color=='[SpotColor]'){
                    var clr=color.spot.getInternalColor();
                    if(color.spot.spotKind==SpotColorKind.SPOTCMYK){
                        var c=clr[0], m=clr[1], y=clr[2], k=clr[3];
                        return [
                            round2((1-(c/100))*(1-(k/100))),
                            round2((1-(m/100))*(1-(k/100))),
                            round2((1-(y/100))*(1-(k/100)))
                    } else if(color.spot.spotKind==SpotColorKind.SPOTRGB){
                        return [round2(clr[0]/255), round2(clr[1]/255), round2(clr[2]/255)];
                    } else if(color.spot.spotKind==SpotColorKind.SPOTLAB){
                        var clr=color.spot.getInternalColor();
                        var whiteRef={
                            D65: {X: 95.047,Y: 100, Z: 108.883},
                            D50: {X: 96.422,Y: 100, Z: 82.521},
                        var illuminant='D65';
                        var Y = (clr[0]+16)/116;
                        var X = clr[1]/500+Y;
                        var Z = Y-clr[2]/200;
                        if(Math.pow(Y,3) > 0.008856){Y=Math.pow(Y,3);}
                        else {Y = (Y-16/116)/7.787;}
                        if(Math.pow(X,3) > 0.008856){X=Math.pow(X,3);}
                        else {X = (X-16/116)/7.787;}
                        if(Math.pow(Z,3) > 0.008856){Z=Math.pow(Z,3);}
                        else {Z = (Z-16/116)/7.787;}
                        X*=whiteRef[illuminant].X,Y*=whiteRef[illuminant].Y,Z*=whiteRef[illuminant].Z;
                        //alert(X+" "+Y+" "+Z);
                        X/=100,Y/=100,Z/=100;
                        R=X*3.2406+Y*-1.5372+Z*-0.4986;
                        G=X*-0.9689+Y*1.8758+Z*0.0415;
                        B=X*0.0557+Y*-0.2040+Z*1.0570;
                        //alert(R+" "+G+" "+B);
                        if(R > 0.0031308){R=(1.055*(Math.pow(R,(1/2.4))))-0.055;}
                        else {R*= 12.92;}
                        if(G > 0.0031308){G=(1.055*(Math.pow(G,(1/2.4))))-0.055;}
                        else {G*= 12.92;}
                        if(B > 0.0031308){B=(1.055*(Math.pow(B,(1/2.4))))-0.055;}
                        else {B*= 12.92;}
                        if(R<0){R=0} else if(R>1){R=1};
                        if(G<0){G=0} else if(G>1){G=1};
                        if(B<0){B=0} else if(B>1){B=1};
                        return [round2(R),round2(G),round2(B)];
                } else if(color=='[RGBColor]'){
                    return [round2(color.red/255), round2(color.green/255), round2(color.blue/255)];
            function drawFromObjString(objString, canvasArea){
               function round2(num){
                   return Math.round(num*100)/100;
                var obj=eval(objString);
                var canvas=canvasArea.graphics;
                var counter=obj.total;
                while(counter>=0){
                    for(all in obj){
                        if(all.match(/\d{1,2}$/g) && all.match(/\d{1,2}$/g)==counter){
                            var thisShp=obj[all];
                            if(thisShp.ellipsePath!=true){
                                var vectorPts=thisShp.pathPoints;
                                canvas.newPath(); canvas.moveTo(thisShp.pathPoints[0][0],thisShp.pathPoints[0][1]);
                                for(var j=0; j<vectorPts.length; j++){
                                    var thisAnchor=vectorPts[j];
                                    var x=thisAnchor[0], y=thisAnchor[1];
                                    canvas.lineTo(x,y);
                                if(thisShp.closed==true){
                                    canvas.closePath();
                            } else {
                                var cirPts=thisShp.pathPoints;
                                canvas.newPath();
                                canvas.ellipsePath(cirPts[0], cirPts[1], cirPts[2], cirPts[3]);
                                canvas.closePath();
                            if(thisShp.fillColor!=null){
                                var clr=thisShp.fillColor;
                                var myBrush=canvas.newBrush(canvas.BrushType.SOLID_COLOR,clr);
                                canvas.fillPath(myBrush);
                            if(thisShp.strokeColor!=null){
                                var clr=thisShp.strokeColor;
                                var myPen=canvas.newPen(canvas.PenType.SOLID_COLOR,[clr[0],clr[1],clr[2],1], thisShp.strokeWidth);
                                canvas.strokePath(myPen);
                    counter-=1;
            var doc=app.activeDocument;
            if(doc.height<=400 && doc.width<=600){
                doc.rulerOrigin=[0,doc.height];
                doc.coordinateSystem=CoordinateSystem.DOCUMENTCOORDINATESYSTEM;
                var wDims=function(){
                    var dims={width: '', height: ''};
                    if(doc.width>220){
                        dims.width = Math.round(doc.width);
                    } else {
                        dims.width = 220;
                    if(doc.height>20){
                        dims.height = Math.round(doc.height);
                    } else {
                        dims.height = 20;
                    return dims;
                function drawCapture(vectors, dataDisplay, graphicDisplay){
                    // draws a preview and creates a drawing data object resource.
                    var drawData={total:0}; //Put drawing shapes here.  Properties: stroke (rgb color | null), fill (rgb color | null), pathPoints
                    var canvas=graphicDisplay.graphics;
                    for(var i=vectors.length-1; i>-1; i--){
                        var thisShp=vectors[i];
                        if((thisShp.filled || thisShp.stroked) && thisShp.editable==true){
                            drawData.total++;
                            drawData['shape_'+i]={};
                            drawData['shape_'+i].fillColor=null;
                            drawData['shape_'+i].strokeColor=null;
                            drawData['shape_'+i].pathPoints=[];
                            drawData['shape_'+i].ellipsePath=false;
                            if(itemShape(thisShp).iscircle==true || itemShape(thisShp).isellipse==true || thisShp.name=='ellipse' ||
                                thisShp.name=='circle' || thisShp.name=='cir'){
                                drawData['shape_'+i].ellipsePath=true;
                                drawData['shape_'+i].pathPoints=[thisShp.left, -thisShp.top, thisShp.width, thisShp.height];
                                canvas.newPath();
                                canvas.ellipsePath(thisShp.left, -thisShp.top, thisShp.width, thisShp.height);
                            } else {
                                var vectorPts=thisShp.pathPoints;
                                canvas.newPath(); canvas.moveTo(Math.round(vectorPts[0].anchor[0]),-Math.round(vectorPts[0].anchor[1]));
                                for(var j=0; j<vectorPts.length; j++){
                                    var thisAnchor=vectorPts[j].anchor;
                                    var x=Math.round(thisAnchor[0]), y=-Math.round(thisAnchor[1]);
                                    drawData['shape_'+i].pathPoints.push([x,y]);
                                    canvas.lineTo(x,y);
                            if(thisShp.closed || drawData['shape_'+i].ellipsePath==true){
                                drawData['shape_'+i].closed=true;
                                if(drawData['shape_'+i].ellipsePath!=true){
                                    canvas.closePath();
                            } else {
                                drawData['shape_'+i].closed=false;
                            if(thisShp.filled){
                                var clr=thisShp.fillColor;
                                var colorArray=convertToUIRGB(clr);
                                var myBrush=canvas.newBrush(canvas.BrushType.SOLID_COLOR,colorArray);
                                drawData['shape_'+i].fillColor=colorArray;
                                canvas.fillPath(myBrush);
                            if(thisShp.stroked){
                                var clr=thisShp.strokeColor;
                                var colorArray=convertToUIRGB(clr);
                                var myPen=canvas.newPen(canvas.PenType.SOLID_COLOR,[colorArray[0],colorArray[1],colorArray[2],1], Math.round(thisShp.strokeWidth));
                                drawData['shape_'+i].strokeColor=colorArray;
                                drawData['shape_'+i].strokeWidth=Math.round(thisShp.strokeWidth);
                                canvas.strokePath(myPen);
                    return drawData;
                function showDrawerFunc(objStringDisplay, wDims){
                    var w2=new Window('dialog','Drawer Function');
                    var containerG=w2.add('tabbedpanel');
                        var funcG=containerG.add('tab',undefined,'Drawer Function');
                            var dispE=funcG.add('edittext',undefined,funcSrc,{multiline:true}); dispE.size=[580,200];
                            var selBtn=funcG.add('button',undefined,'Select All');
                        var drawingG=containerG.add('tab',undefined,'Drawing:');
                            var drawG=drawingG.add('group');
                                var drawP=drawG.add('panel',undefined,''); drawP.size=[wDims.width, wDims.height];
                    var msgCntr=w2.add('panel',undefined,'Message Center:');
                        var msgE=msgCntr.add('edittext',undefined,'',{multiline:true});msgE.size=[560,40];
                    var btnG=w2.add('group');
                        var okBtn=btnG.add('button',undefined,'Ok',{name: 'ok'});
                    selBtn.onClick=function(){
                        dispE.active=false; dispE.active=true;
                    drawG.onDraw=function(){
                        if(objStringDisplay.text!=''){
                            try{
                                drawFromObjString(objStringDisplay.text, this);
                            } catch(e){
                                msgE.text=("Something isn't right:\r"+e);
                        } else {
                            msgE.text=('You must first put a valid object string into the object string display area--> "Get Source Object String" button, 1st window, 1st tab.');
                    w2.show();
                function instructions(){
                    var w3=new Window('dialog','instructions');
                    var instructions=w3.add('edittext',undefined,'',{multiline:true}); instructions.size=[400,100];
                    instructions.text="1)  Have a document open, smaller than 600x400.\r\r"+
                        "2)  Draw some stuff- use paths only, straight lines or ellipses only. To have script explicitly recognize ellipse, "+
                        "label the path 'cir', 'circle', or 'ellipse'. Right now there's a function to detect ellipses, but it is coarse.\r\r"+
                        "3)  Run this script and see if your drawing was captured below this box.\r\r"+
                        "4)  Click the 'Get Object String' button and see the drawing instruction string appear.\r\r"+
                        "5)  Click the 'View Drawer Function/Drawing' button to see the function used to draw scriptUI picture from"+
                        " the object string and use other tab to see the drawing made with this function from that object string.\r\r"+
                        "6)  Edit your string to see your picture change if needed!";
                    var okBtn=w3.add('button',undefined,'OK');
                    w3.show();
                var funcSrc=drawFromObjString.toSource();
                var dispWindow=function(){
                    var drawData;
                    var w=new Window('dialog','ScriptUI Graphics Display');
                    var panel=w.add('panel',undefined,''); panel.size=[wDims.width+6,wDims.height+6];
                    var list=w.add('edittext',undefined,'',{multiline:true}); list.size=[wDims.width,150];
                    var btnsG=w.add('group');
                        var clickBtn=btnsG.add('button',undefined,'Get Source Object String');
                        var selectBtn=btnsG.add('button',undefined,'Select All');
                    var btnG2=w.add('group');
                        var funcBtn=btnG2.add('button',undefined,'See Drawer Function/Drawing');
                        funcBtn.helpTip='Uses the Object String picture info to draw using ScriptUIGraphics lineTo commands.';
                        var helpBtn=btnG2.add('button',undefined,'?'); helpBtn.size=[25,25];
                    panel.onDraw=function(){
                        drawData=drawCapture(doc.pathItems, list, this);
                    clickBtn.addEventListener('mousedown',function(){
                        list.text=drawData.toSource();
                    funcBtn.onClick=function(){
                        showDrawerFunc(list, wDims);
                    helpBtn.onClick=function(){
                        instructions();
                    selectBtn.onClick=function(){
                        list.active=false; list.active=true;
                    var okBtn=w.add('button',undefined,'OK');
                    w.show();
            } else {
                alert('Please use a document with main artboard no larger than 600x400.');
        } else {
            alert('Must run in Illustrator with at least 1 document open.');
    graphicsDisplay();

    New-er update to this:
    // ScriptUI Graphics Display by Vasily
    #target illustrator
    function graphicsDisplay(){
        function itemShape(myShape){
            // Going to test for circles.
            var shapeKind={
                isrectangle: null,
                iscircle: null,
                isellipse: null
            if(myShape.typename=='PathItem' && myShape.pathPoints.length == 4){ // RECTANGLE CHECKER
                //--------------------2 diagonals-------------------------
                var recEquaDistOne = parseInt(Math.pow((myShape.pathPoints[0].anchor[0] - myShape.pathPoints[2].anchor[0]),2) +
                Math.pow((myShape.pathPoints[0].anchor[1] - myShape.pathPoints[2].anchor[1]),2)); // diagonal
                var recEquaDistTwo = parseInt(Math.pow((myShape.pathPoints[1].anchor[0] - myShape.pathPoints[3].anchor[0]),2) +
                Math.pow((myShape.pathPoints[1].anchor[1] - myShape.pathPoints[3].anchor[1]),2)); // diagonal
                //---------------------4 sides of rectangle---------------
                var sideA = parseInt(Math.pow((myShape.pathPoints[0].anchor[0] - myShape.pathPoints[1].anchor[0]),2) +
                Math.pow((myShape.pathPoints[0].anchor[1] - myShape.pathPoints[1].anchor[1]),2)); 
                var sideB = parseInt(Math.pow((myShape.pathPoints[1].anchor[0] - myShape.pathPoints[2].anchor[0]),2) +
                Math.pow((myShape.pathPoints[1].anchor[1] - myShape.pathPoints[2].anchor[1]),2)); 
                var sideC = parseInt(Math.pow((myShape.pathPoints[2].anchor[0] - myShape.pathPoints[3].anchor[0]),2) +
                Math.pow((myShape.pathPoints[2].anchor[1] - myShape.pathPoints[3].anchor[1]),2)); 
                var sideD = parseInt(Math.pow((myShape.pathPoints[3].anchor[0] - myShape.pathPoints[0].anchor[0]),2) +
                Math.pow((myShape.pathPoints[3].anchor[1] - myShape.pathPoints[0].anchor[1]),2)); 
                if(recEquaDistOne == recEquaDistTwo){ // If two diagonals connecting opposite points are same length, it's a 90 degree box               
                    if((sideA == sideC) && (sideB == sideD)){
                        for(var j=0; j<4; j++){
                            var point = myShape.pathPoints[j];             
                                if((point.leftDirection[0] == point.anchor[0]) &&
                                    (point.anchor[0] == point.rightDirection[0]) &&
                                    (point.leftDirection[1] == point.anchor[1]) &&
                                    (point.anchor[1] == point.rightDirection[1])){
                                    shapeKind.isrectangle = true;
                                } else {
                                    shapeKind.isrectangle = false;
                                    break;
                if(myShape.pathPoints.length == 4){  // CIRCLE CHECKER
                    if(shapeKind.isrectangle == false || shapeKind.isrectangle == null){
                        var circlePts = new Array();
                        var circleSlopes = new Array();
                        for (k=0; k<4; k++){
                        var point = myShape.pathPoints[k]; 
                        var leftHandleDist = parseInt(Math.pow((point.leftDirection[0] - point.anchor[0]),2) +
                        Math.pow((point.leftDirection[1] - point.anchor[1]),2));
                        var rightHandleDist = parseInt(Math.pow((point.rightDirection[0] - point.anchor[0]),2) +
                        Math.pow((point.rightDirection[1] - point.anchor[1]),2));
                        circlePts.push(leftHandleDist, rightHandleDist);
                        var leftHandleSlope = ((point.leftDirection[0] - point.anchor[0])/(point.leftDirection[1] - point.anchor[1])).toFixed(2);
                        var rightHandleSlope = ((point.rightDirection[0] - point.anchor[0])/(point.rightDirection[1] - point.anchor[1])).toFixed(2);
                        circleSlopes.push(leftHandleSlope, rightHandleSlope);
                    for(var f=0; f<8; f++){ // Allows non-rotated circles.
                        if(circleSlopes[f] == "-0.00"){
                            circleSlopes[f] = "0.00";
                        if(circleSlopes[f] == "-Infinity"){
                            circleSlopes[f] = "Infinity";
                    var cirEquaDistOne = parseInt(Math.pow((myShape.pathPoints[0].anchor[0] - myShape.pathPoints[2].anchor[0]),2) +
                    Math.pow((myShape.pathPoints[0].anchor[1] - myShape.pathPoints[2].anchor[1]),2));
                    var cirEquaDistTwo = parseInt(Math.pow((myShape.pathPoints[1].anchor[0] - myShape.pathPoints[3].anchor[0]),2) +
                    Math.pow((myShape.pathPoints[1].anchor[1] - myShape.pathPoints[3].anchor[1]),2));
                    if(circleSlopes[0] != "NaN"){ // Filters out asymmetric rhombus  <><><>^^^^^^<><><>
                        if((circlePts[0] == circlePts[1]) && // Filters out shapes with control handles not of equal distance from anchor point.
                            (circlePts[1] == circlePts[2]) &&
                            (circlePts[2] == circlePts[3]) &&
                            (circlePts[3] == circlePts[4]) &&
                            (circlePts[4] == circlePts[5]) &&
                            (circlePts[5] == circlePts[6]) &&
                            (circlePts[6] == circlePts[7]) &&
                            (circlePts[7] == circlePts[0])){
                            if((circleSlopes[0] == circleSlopes[1]) && // Filters out the equadistant 4-pointed Star shape (dismisses negative slopes).
                                (circleSlopes[2] == circleSlopes[3]) &&
                                (circleSlopes[4] == circleSlopes[5]) &&
                                (circleSlopes[6] == circleSlopes[7])){
                                if(cirEquaDistOne == cirEquaDistTwo){ // Filters out Ellipses (non-equadistant circles).
                                    // Filters out the very RARE 4-pointed star which has all control points in its center on top of each other!
                                    if(((myShape.pathPoints[0].leftDirection[0]).toFixed(2) != (myShape.pathPoints[1].leftDirection[0]).toFixed(2)) &&
                                        ((myShape.pathPoints[0].leftDirection[1]).toFixed(2) != (myShape.pathPoints[1].leftDirection[1]).toFixed(2))){
                                        shapeKind.iscircle = true;
                                    } else {
                                        shapeKind.iscircle = false;
                        } else {
                            if((circlePts[0]==circlePts[1]) &&
                                (circlePts[2]==circlePts[3]) &&
                                ((circlePts[4]==circlePts[5]) && (circlePts[4]==circlePts[1]) && (circlePts[5]==circlePts[1])) &&
                                ((circlePts[6]==circlePts[7]) && (circlePts[6]==circlePts[2]) && (circlePts[7]==circlePts[3]))){
                                shapeKind.isellipse=true;
        //~                     $.writeln(circlePts[0]+'\r'+circlePts[1]+'\r'+circlePts[2]+'\r'+circlePts[3]+'\r'+
        //~                     circlePts[4]+'\r'+circlePts[5]+'\r'+circlePts[6]+'\r'+circlePts[7]);
            return shapeKind;
        if(app.name=='Adobe Illustrator' && app.documents.length>0){
            function round2(num){
                return Math.round(num*100)/100;
            function convertToUIRGB(color){
                if(color=='[CMYKColor]'){
                    var c=color.cyan, m=color.magenta, y=color.yellow, k=color.black;
                    return [
                        round2((1-(c/100))*(1-(k/100))),
                        round2((1-(m/100))*(1-(k/100))),
                        round2((1-(y/100))*(1-(k/100)))
                } else if(color=='[GrayColor]'){
                    var k=color.gray;
                    var grayValue=1-(Math.round(((k/100)*255)*100)/100)/255;
                    return [grayValue,grayValue,grayValue];
                } else if(color=='[GradientColor]'){
                    $.writeln('Sorry, no gradient colors please.');
                    return [0,0,0];
                } else if(color=='[PatternColor]'){
                    $.writeln('Sorry, no pattern colors please.');
                    return [0,0,0,];
                } else if(color=='[SpotColor]'){
                    var clr=color.spot.getInternalColor();
                    if(color.spot.spotKind==SpotColorKind.SPOTCMYK){
                        var c=clr[0], m=clr[1], y=clr[2], k=clr[3];
                        return [
                            round2((1-(c/100))*(1-(k/100))),
                            round2((1-(m/100))*(1-(k/100))),
                            round2((1-(y/100))*(1-(k/100)))
                    } else if(color.spot.spotKind==SpotColorKind.SPOTRGB){
                        return [round2(clr[0]/255), round2(clr[1]/255), round2(clr[2]/255)];
                    } else if(color.spot.spotKind==SpotColorKind.SPOTLAB){
                        var clr=color.spot.getInternalColor();
                        var whiteRef={
                            D65: {X: 95.047,Y: 100, Z: 108.883},
                            D50: {X: 96.422,Y: 100, Z: 82.521},
                        var illuminant='D65';
                        var Y = (clr[0]+16)/116;
                        var X = clr[1]/500+Y;
                        var Z = Y-clr[2]/200;
                        if(Math.pow(Y,3) > 0.008856){Y=Math.pow(Y,3);}
                        else {Y = (Y-16/116)/7.787;}
                        if(Math.pow(X,3) > 0.008856){X=Math.pow(X,3);}
                        else {X = (X-16/116)/7.787;}
                        if(Math.pow(Z,3) > 0.008856){Z=Math.pow(Z,3);}
                        else {Z = (Z-16/116)/7.787;}
                        X*=whiteRef[illuminant].X,Y*=whiteRef[illuminant].Y,Z*=whiteRef[illuminant].Z;
                        //alert(X+" "+Y+" "+Z);
                        X/=100,Y/=100,Z/=100;
                        R=X*3.2406+Y*-1.5372+Z*-0.4986;
                        G=X*-0.9689+Y*1.8758+Z*0.0415;
                        B=X*0.0557+Y*-0.2040+Z*1.0570;
                        //alert(R+" "+G+" "+B);
                        if(R > 0.0031308){R=(1.055*(Math.pow(R,(1/2.4))))-0.055;}
                        else {R*= 12.92;}
                        if(G > 0.0031308){G=(1.055*(Math.pow(G,(1/2.4))))-0.055;}
                        else {G*= 12.92;}
                        if(B > 0.0031308){B=(1.055*(Math.pow(B,(1/2.4))))-0.055;}
                        else {B*= 12.92;}
                        if(R<0){R=0} else if(R>1){R=1};
                        if(G<0){G=0} else if(G>1){G=1};
                        if(B<0){B=0} else if(B>1){B=1};
                        return [round2(R),round2(G),round2(B)];
                } else if(color=='[RGBColor]'){
                    return [round2(color.red/255), round2(color.green/255), round2(color.blue/255)];
            function drawFromObjString(objString, canvasArea){
                function drawPath(shp){
                    var thisShp=shp;
                    if(thisShp.ellipsePath!=true){
                        var vectorPts=thisShp.pathPoints;
                        canvas.newPath(); canvas.moveTo(thisShp.pathPoints[0][0],thisShp.pathPoints[0][1]);
                        for(var j=0; j<vectorPts.length; j++){
                            var thisAnchor=vectorPts[j];
                            var x=thisAnchor[0], y=thisAnchor[1];
                            canvas.lineTo(x,y);
                        if(thisShp.closed==true){
                            canvas.closePath();
                    } else {
                        var cirPts=thisShp.pathPoints;
                        canvas.newPath();
                        canvas.ellipsePath(round2(cirPts[0]), round2(cirPts[1]), round2(cirPts[2]), round2(cirPts[3]));
                        canvas.closePath();
                    if(thisShp.fillColor!=null){
                        var clr=thisShp.fillColor;
                        var myBrush=canvas.newBrush(canvas.BrushType.SOLID_COLOR,clr);
                        canvas.fillPath(myBrush);
                    if(thisShp.strokeColor!=null){
                        var clr=thisShp.strokeColor;
                        var myPen=canvas.newPen(canvas.PenType.SOLID_COLOR,[clr[0],clr[1],clr[2],1], thisShp.strokeWidth);
                        canvas.strokePath(myPen);
            //$.writeln(objString.replace(/'\+\n*\r*'/g,'').replace(/(^'|';$)/g,''));
                var obj=eval(objString.replace(/'\+\n*\r*'/g,'').replace(/(^'|';$)/g,''));
                var canvas=canvasArea.graphics;
                var counter=obj.total;
                while(counter>=0){
                    for(all in obj){
                        if(all.match(/\d{1,2}$/g) && all.match(/\d{1,2}$/g)==counter){
                            var thisShp=obj[all];
                            if(all.match('group')){
                                var ctr=obj[all].total;
                                while(ctr>=0){
                                    for(paths in obj[all]){
                                        if(paths.match(/\d{1,2}$/g) && paths.match(/\d{1,2}$/g)==ctr){
                                            drawPath(obj[all][paths]);
                                    ctr--;
                            } else {
                                drawPath(thisShp);
                    counter-=1;
            var doc=app.activeDocument;
            if(doc.height<=400 && doc.width<=600){
                doc.rulerOrigin=[0,doc.height];
                doc.coordinateSystem=CoordinateSystem.DOCUMENTCOORDINATESYSTEM;
                var wDims=function(){
                    var dims={width: '', height: ''};
                    if(doc.width>220){
                        dims.width = Math.round(doc.width);
                    } else {
                        dims.width = 220;
                    if(doc.height>20){
                        dims.height = Math.round(doc.height);
                    } else {
                        dims.height = 20;
                    return dims;
                function drawCapture(docArt, dataDisplay, graphicDisplay){
                    function capturePathItem(pathItem, drawObj, count){
                        var thisShp=pathItem, drawData=drawObj, i=count;
                        if((thisShp.filled || thisShp.stroked) && thisShp.editable==true){
                            drawData['shape_'+i]={};
                            drawData['shape_'+i].fillColor=null;
                            drawData['shape_'+i].name=thisShp.name;
                            drawData['shape_'+i].tag=thisShp.note;
                            drawData['shape_'+i].strokeColor=null;
                            drawData['shape_'+i].pathPoints=[];
                            drawData['shape_'+i].ellipsePath=false;
                            if(itemShape(thisShp).iscircle==true || itemShape(thisShp).isellipse==true || thisShp.name=='ellipse' ||
                                thisShp.name=='circle' || thisShp.name=='cir'){
                                drawData['shape_'+i].ellipsePath=true;
                                drawData['shape_'+i].pathPoints=[Math.round(thisShp.left), Math.round(-thisShp.top), Math.round(thisShp.width), Math.round(thisShp.height)];
                                canvas.newPath();
                                canvas.ellipsePath(Math.round(thisShp.left), Math.round(-thisShp.top), Math.round(thisShp.width), Math.round(thisShp.height));
                            } else {
                                var vectorPts=thisShp.pathPoints;
                                canvas.newPath(); canvas.moveTo(Math.round(vectorPts[0].anchor[0]),-Math.round(vectorPts[0].anchor[1]));
                                for(var j=0; j<vectorPts.length; j++){
                                    var thisAnchor=vectorPts[j].anchor;
                                    var x=Math.round(thisAnchor[0]), y=-Math.round(thisAnchor[1]);
                                    drawData['shape_'+i].pathPoints.push([x,y]);
                                    canvas.lineTo(x,y);
                            if(thisShp.closed || drawData['shape_'+i].ellipsePath==true){
                                drawData['shape_'+i].closed=true;
                                if(drawData['shape_'+i].ellipsePath!=true){
                                    canvas.closePath();
                            } else {
                                drawData['shape_'+i].closed=false;
                            if(thisShp.filled){
                                var clr=thisShp.fillColor;
                                var colorArray=convertToUIRGB(clr);
                                var myBrush=canvas.newBrush(canvas.BrushType.SOLID_COLOR,colorArray);
                                drawData['shape_'+i].fillColor=colorArray;
                                canvas.fillPath(myBrush);
                            if(thisShp.stroked){
                                var clr=thisShp.strokeColor;
                                var colorArray=convertToUIRGB(clr);
                                var myPen=canvas.newPen(canvas.PenType.SOLID_COLOR,[colorArray[0],colorArray[1],colorArray[2] ,1], Math.round(thisShp.strokeWidth));
                                drawData['shape_'+i].strokeColor=colorArray;
                                drawData['shape_'+i].strokeWidth=Math.round(thisShp.strokeWidth);
                                canvas.strokePath(myPen);
                    // docArt is lately the layers[0].pageItems
                    // draws a preview and creates a drawing data object resource.
                    var drawData={total:0}; //Put drawing shapes here.  Properties: stroke (rgb color | null), fill (rgb color | null), pathPoints
                    var canvas=graphicDisplay.graphics;
                    vectors=function(){
                        var arr=[];
                        for(var i=0; i<docArt.length; i++){
                            var thisShp=docArt[i];
                            if(thisShp.typename=='PathItem' && thisShp.parent.typename!="GroupItem"){
                                if((thisShp.filled || thisShp.stroked) && thisShp.editable==true){
                                    arr.push(thisShp);
                            } else if(thisShp.typename=='GroupItem'){
                                if(thisShp.pathItems.length>0){
                                    var smArr=[];
                                    for(var j=0; j<thisShp.pathItems.length; j++){
                                        var thisPth=thisShp.pathItems[j];
                                        if((thisPth.filled || thisPth.stroked) && thisPth.editable==true){
                                            smArr.push(thisPth);
                                    if(smArr.length>0){arr.push(smArr);};
                        return arr;
                    drawData.total=vectors.length;
                    for(var i=vectors.length-1; i>-1; i--){
                        var thisShp=vectors[i];
                        if(thisShp instanceof Array){
                            var grpObj={};
                            for(var j=thisShp.length-1; j>-1; j--){
                                var thisPth=thisShp[j];
                                capturePathItem(thisPth, grpObj, j);
                            grpObj.total=thisShp.length;
                            var grpNm=function(){
                                if(thisShp[0].parent.name!=''){
                                    return thisShp[0].parent.name+"_";
                                return '';
                            drawData['group_'+grpNm+i]=grpObj;
                        } else {
                            capturePathItem(thisShp, drawData, i);
                    return drawData;
                function showDrawerFunc(objStringDisplay, wDims){
                    var w2=new Window('dialog','Drawer Function');
                    var containerG=w2.add('tabbedpanel');
                        var funcG=containerG.add('tab',undefined,'Drawer Function');
                            var dispE=funcG.add('edittext',undefined,funcSrc,{multiline:true}); dispE.size=[580,200];
                            var selBtn=funcG.add('button',undefined,'Select All');
                        var drawingG=containerG.add('tab',undefined,'Drawing:');
                            var drawG=drawingG.add('group');
                                var drawP=drawG.add('panel',undefined,''); drawP.size=[wDims.width, wDims.height];
                    var msgCntr=w2.add('panel',undefined,'Message Center:');
                        var msgE=msgCntr.add('edittext',undefined,'',{multiline:true});msgE.size=[560,40];
                    var btnG=w2.add('group');
                        var okBtn=btnG.add('button',undefined,'Ok',{name: 'ok'});
                    selBtn.onClick=function(){
                        dispE.active=false; dispE.active=true;
                    drawG.onDraw=function(){
                        if(objStringDisplay.text!=''){
                            try{
                                drawFromObjString(objStringDisplay.text, this);
                            } catch(e){
                                msgE.text=("Something isn't right:\r"+e);
                        } else {
                            msgE.text=('You must first put a valid object string into the object string display area--> "Get Source Object String" button, 1st window, 1st tab.');
                    w2.show();
                function instructions(){
                    var w3=new Window('dialog','instructions');
                    var instructions=w3.add('edittext',undefined,'',{multiline:true}); instructions.size=[400,100];
                    instructions.text="1)  Have a document open, smaller than 600x400.\r\r"+
                        "2)  Draw some stuff- use paths only, straight lines or ellipses only. To have script explicitly recognize ellipse, "+
                        "label the path 'cir', 'circle', or 'ellipse'. Right now there's a function to detect (non-rotated) ellipses, but it is coarse.\r\r"+
                        "3)  Run this script and see if your drawing was captured in the main window.\r\r"+
                        "4)  Click the 'Get Object String' button and see the drawing instruction string appear.\r\r"+
                        "5)  Click the 'View Drawer Function/Drawing' button to see the function used to draw scriptUI picture from"+
                        " the object string and use other tab to see the drawing made with this function from that object string.\r\r"+
                        "6)  Edit your string to see your picture change if needed!";
                    var okBtn=w3.add('button',undefined,'OK');
                    w3.show();
                var funcSrc=drawFromObjString.toSource();
                var dispWindow=function(){
                    var drawData;
                    var w=new Window('dialog','ScriptUI Graphics Display');
                    var panel=w.add('panel',undefined,''); panel.size=[wDims.width+6,wDims.height+6];
                    var list=w.add('edittext',undefined,'',{multiline:true}); list.size=[wDims.width,150];
                    var formatG=w.add('group');
                        var formatH=formatG.add('statictext',undefined, 'Format:');
                        var format_returns=formatG.add('button',undefined, 'Returns before "(group|shape)_"');
                    var btnsG=w.add('group');
                        var clickBtn=btnsG.add('button',undefined,'Get Source Object String');
                        var selectBtn=btnsG.add('button',undefined,'Select All');
                    var btnG2=w.add('group');
                        var funcBtn=btnG2.add('button',undefined,'See Drawer Function/Drawing');
                        funcBtn.helpTip='Uses the Object String picture info to draw using ScriptUIGraphics lineTo commands.';
                        var helpBtn=btnG2.add('button',undefined,'?'); helpBtn.size=[25,25];
                    panel.onDraw=function(){
                        drawData=drawCapture(doc.layers[0].pageItems, list, this);
                    clickBtn.addEventListener('mousedown',function(){
                        list.text=drawData.toSource();
                    format_returns.onClick=function(){
                        var str=list.text;
                        var rx=/(group|shape)_/g;
                        if(str!=''){
                            var rx=/(group_|shape_)/g;
                            var matches=str.match(rx);
                            for(var i=0; i<matches.length; i++){
                                var instance = rx.exec(str);
                                str=str.substring(0, rx.lastIndex-instance[0].length)+str.substr(rx.lastIndex-instance[0].length,).replace(ins tance[0],"'+\r'"+instance[0]);
                        list.text="'"+str+"';";
                    funcBtn.onClick=function(){
                        showDrawerFunc(list, wDims);
                    helpBtn.onClick=function(){
                        instructions();
                    selectBtn.onClick=function(){
                        list.active=false; list.active=true;
                    var okBtn=w.add('button',undefined,'OK');
                    w.show();
            } else {
                alert('Please use a document with main artboard no larger than 600x400.');
        } else {
            alert('Must run in Illustrator with at least 1 document open.');
    graphicsDisplay();

  • Drawing a String using Graphics Object

    When I am printing a long String using the following method
    String currentMessage // The size of the String is large
    g.drawString(currentMessage, x, y, Graphics.BOTTOM | Graphics.HCENTER);
    only the middle of the String is shown on the sreen.The first and last parts are stripped off because of the size of the screen.
    Anyone knows how to specify the size of the font, or how to force the string to continue on a new line if its size is bigger than the width of the screen?
    Cheers

    There is not native support for line wrapping in drawString().
    You can change the font by using g.setFont(),
    Create your on font, and specify the font size as small.
    The Font class includes a method to determine the length of a string. You can use this method to check the length of the String if the string is longer than the screen width, you can break the String into parts (substrings) and draw each of the parts.
    Alternatively, you can use this line wrapping class http://hostj2me.com/appdetails.html?id=6

  • The problem about drawing using netbean GUI?

    I am new to netbean gui,
    I creat the JFrame through netbent gui, but I do want to draw something in it, so I creat the WaveformPanel class, which extend the JPanel class,in which
    I will do some drawing, using paint method.
    so then I drag the button from the platte, and want to click the button, then the drawing will appear, in the actionperformed method, my code is
    JPanel wavepanel = new  WaveformPanel();
         super.setContentPane( wavepanel);
         super.setVisible(true);but in this way, the drawing will cover all the Frame, that is not what I want , how to draw it just in the right buttom, how to do it?
    I know for this code I have not drag the JPanel from the platte, I just do not know how to connect the JPanel from the platte and my created JPanel, any idea�H

    Andre_Uhres wrote:
    Do not use setContentPane. Try like this:
    getContentPane().setLayout(new BorderLayout());
    wavepanel.setPreferredSize(new Dimension(150, 0));
    getContentPane().add(wavepanel, BorderLayout.EAST);
    You may also want to read about [Using Layout Managers|http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html] .
    As has already been explained to Danielwang in his cross-post here: [http://forum.java.sun.com/thread.jspa?threadID=5296704|http://forum.java.sun.com/thread.jspa?threadID=5296704]
    Danielwang: when you cross-post like this, you waste both Andre's by having him answer questions already answered and you waste my time by making me feel like I spent time creating an answer that you never read and never responded to. If you keep doing this, you will likely be put on our lists of people not to help. Not a good way to start here.

  • Adobe Reader drawing without Comment Tools or Method to set "Make Properties Default" without popup

    Hi everyone,
    Spending a few days to find a solution for drawing lines, polylines, polygons, circles, rectangles, etc. It looks like a "dead end" since I want to develop a plugin for Adobe Reader that can draw custom Lines, Polylines, Polygons, ... (objects I can set my styles without using built-in style dialog). I want to use my custom dialog to set styles and do drawing without using Comment Tools. The problem is: when I use AVPageViewDrawingProc callback, I can draw only rectangle, polyline, polygon, no way to draw circle, text, etc.
    Another solution is to use Comment Tools. But when changing between tools I want to apply my styles to the tool (line color, text color, text size, ...), like the way you right click on an annotation and select "Properties", then mark "Make Properties Default" as checked before selecting "OK". I don't want to show the dialog to confuse user when he changes tools. So, is there any API method to help me selecting an annotation and mark this selected annotation to be default styles?
    I still can't find a way to change text size of FreeText realtime.
    Anybody can help me?
    Kind Regards

    If I were building something like this, I would have my plugin create custom annotations.  You can draw whatever you want in the appearance of the annotation.

  • Question about WOL (Wake on LAN) Unicast method

    Hi,  We are trying to get WOL working here on our enterprise network using the Unicast method.  It seems that this method depends on the machine you wish to wake having an entry in the router/switch ARP cache.  The problem is that this cache
    times out rather quickly by default and the suggestion was to increase this timeout setting so the entry stays in the cache longer when the device goes offline.  Our WAN guys are saying that is a bad idea and can cause all kinds of issues if we set this
    to say 12-24 hours.  How is everyone else using Unicast WOL dealing with this issue?

    A few corrections and notes:
    - Yes, unicast WoL traffic requires the system to be in the ARP cache of the final layer-3 device. This has nothing to do with WoL though. This is a requirement for *all* unicast traffic. That's simply how ethernet works.
    - Subnet-directed broadcasts aren't less secure. They can however be exploited enabling certain types of DoS attacks most notably the Smurf attack. This can be easily and reliably mitigated as mentioned though.
    - "Both methods require routers to forward UDP packets from your site server." This is a deceptive statement at best. In Unicast, the traffic is transmitted just like all other traffic on the network and requires nothing special on the network
    side and no configuration of any "forwarding". Only with subnet-directed broadcasts is the network required to "forward" traffic.
    - While a consideration, DHCP is usually not a factor with desktops unless you have a ridiculously short lease time. With laptops, same story unless they actually change subnets but then there's nothing you can really do about that. This is why I recommend
    setting the heartbeat to at least once a day if not more often however.
    Finally, do you know about Peer wakeup in 2012 SP1 and R2? Peer wakeup is much more reliable. You generally use unicast with peer wakeup but it overcomes the ARP cache limit.
    Jason | http://blog.configmgrftw.com | @jasonsandys

Maybe you are looking for

  • How do you change/adjust border width for all the cells in a table created in Pages?

    How do you change/adjust border width for all the cells in a table created in Pages? Note- I am trying to figure out how to create and format tables in the latest version of the Pages app on an iPad air (iOS 8.1.1.1) . Creating tables, adding or remo

  • Radius Accounting and AP1100

    Hello, I have lots of AP1121G, that authenticating users on a radius server (Radiator). I need to make accounting of octets in and out per user, but i have some problems with this. In general, the accounting is working fine, but the APs dont send som

  • Rewards on iPhone Apps

    Hi, We want to create an in-app contest in which users pay to enter the contest and the winner gets a reward, let's say a Macy's gift card (or e-gift card). According to Apple app rules, users cannot purchase physical goods for virtual money. We're t

  • "interface" datatype variable??

    While working with other people's Code I found the following: <code> public interface iMyClass //the interface public static string str = ""; public void setStr(String sStr); </code> and in the same package: <code> public class MyClass //the class pr

  • About an external drive

    About the HD: I will buy an external drive (it's easier than install it inside). My computer uses ATA drive. 1) Most brand do not mention if they are ATA or SATA. Does it matter if I buy an external drive ? 2) I see in my catalogue from Mac connectio