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

Similar Messages

  • Draw to an image using graphics object

    ive been trying to this. create a starfield 800px wide and twice the height of the screen 2x600. this image would be scrolling down the screen giving the appearance of moving through space. what i did was create an image the called "starField", and created a graphics object "starFieldObj" to draw dots (stars) to this image.
    is this the correct way to do this? my program seems to work differently depending on where i call "generateStarField()" which draws to "starFieldObj"
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class Alpha1 extends Canvas implements Runnable, MouseMotionListener, MouseListener, KeyListener {
         private Image buffer; //bufer image
         private Graphics gfx;
         private Graphics starFieldObj;
         private Image playerShip;
         private int frames = 60; //frames per second
         private MediaTracker mediaTracker; //tracks loaded images
         private boolean ready; //ready to  start animation
         private int [] keys = new int[256];
         private int playerShipX = 100;
         private int playerShipY = 100;
         private static Random random = new Random();
         private Image starField;
         private int starFieldSpeed = 5;
         private int starFieldX = 0;
         private int starFieldY = -600;
         public static void main(String[] args)
              Alpha1 t = new Alpha1();
              Frame f = new Frame("blah");
              f.setSize(800, 600);
              f.add(t, BorderLayout.CENTER);
              f.show();
              t.start();
              t.requestFocus();
              f.addWindowListener(new WindowAdapter(){
                   public void windowClosing(WindowEvent e){
                        System.exit(0);}});
         public Alpha1()
              addKeyListener(this);
              addMouseListener(this);
              ready = false;
              mediaTracker = new MediaTracker(this);
              playerShip = getToolkit().getImage("testship1.png");
              //starField = getToolkit().getImage("testbg.png");
              //mediaTracker.addImage(playerShip, 0);
              mediaTracker.addImage(starField, 0);
              try {
                   mediaTracker.waitForID(0);
              catch (InterruptedException e) {
                   e.printStackTrace();
         public void start()
              buffer = createImage(getSize().width,getSize().height);
              //starField = createImage(getSize().width,getSize().height * 2);
              gfx = buffer.getGraphics();
              //starFieldObj = starField.getGraphics();
              generateStarfield();
              ready = true;
              new Thread(this).start();
         public void mouseDragged(MouseEvent e)     {}
         public void mouseMoved(MouseEvent e)     
              playerShipX = e.getX();
              playerShipY = e.getY();
         public void mouseReleased(MouseEvent e)     {}
         public void mousePressed(MouseEvent e)     {}
         public void mouseExited(MouseEvent e)     {}
         public void mouseEntered(MouseEvent e)  {}
         public void mouseClicked(MouseEvent e)     {}
         public void keyTyped(KeyEvent keyevent)     {}
         public void keyPressed(KeyEvent keyevent)
              keys[keyevent.getKeyCode()] = 1;
              System.out.println(keyevent.getKeyCode());
         public void keyReleased(KeyEvent keyevent)     
              keys[keyevent.getKeyCode()] = 0;
         public void run()
              while (true)
                   if (isVisible())
                        repaint();
                        updatePositions();
                   }//end if
                   try 
                   { Thread.sleep(1000/frames); }
                   catch (InterruptedException e)
                   { e.printStackTrace(); }
              }//end while
         public void paint(Graphics g) {     /*empty etc*/ }
         public void updatePositions()
              if (keys[38] == 1 & keys[40] == 0) //IF UP IS PRESSED
              { playerShipY -= 3; }
              if (keys[40] == 1 & keys[38] == 0) //IF DOWN IS PRESSED
              { playerShipY += 6; }
              if (keys[37] == 1 & keys[39] == 0) //IF LEFT IS PRESSED
              { playerShipX -= 5; }
              if (keys[39] == 1 & keys[37] == 0) //IF RIGHT IS PRESSED
              { playerShipX += 5; }
              //starFieldY = starFieldY + starFieldSpeed;
              //if (starFieldY == 0)
              //     starFieldY = -600;
              //     System.out.println("dadssa");
         public int getRandom(int from, int to)
              if (from > to)
                   int randTemp;
                   randTemp = from;
                   from = to;
                   to = randTemp;
              return random.nextInt(to-from+1)+from;
         public void generateStarfield()
              starFieldObj.setColor(Color.black);
              starFieldObj.fillRect (0, 0, 800, 600 * 2);
              for (int td=0; td < 900 ; td++) //draw 900x2 dots on 800x1200 image
                        starFieldObj.fillRect (getRandom(1,800), getRandom(1,600), 1, 1);
                        starFieldObj.fillRect (getRandom(1,800) + 800, getRandom(1,600) + 800, 1, 1);
         public void update(Graphics g)
              if (ready)
                   gfx.setColor(Color.black);
                   gfx.fillRect (0, 0, this.getSize().width, this.getSize().height);
                   //gfx.drawImage(starField,starFieldX,starFieldY,null);
                   gfx.drawImage(playerShip,playerShipX,playerShipY,null);
                   //gfx.drawString(Integer.toString(showFps),5,5);
                   g.drawImage(buffer,0,0,null);
    }

    updated code, i cant get starField to be 1200px in height
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class Alpha1 extends Canvas implements Runnable, MouseMotionListener, MouseListener, KeyListener {
         private Image buffer; //bufer image
         private Graphics gfx;
         private Graphics starFieldObj;
         private Image playerShip;
         private int frames = 60; //frames per second
         private MediaTracker mediaTracker; //tracks loaded images
         private boolean ready; //ready to  start animation
         private int [] keys = new int[256];
         private int playerShipX = 100;
         private int playerShipY = 100;
         private static Random random = new Random();
         private Image starField;
         private int starFieldSpeed = 5;
         private int starFieldX = 0;
         private int starFieldY = -600;
         public static void main(String[] args)
              Alpha1 t = new Alpha1();
              Frame f = new Frame("blah");
              f.setSize(800, 600);
              f.add(t, BorderLayout.CENTER);
              f.show();
              t.start();
              t.requestFocus();
              f.addWindowListener(new WindowAdapter(){
                   public void windowClosing(WindowEvent e){
                        System.exit(0);}});
         public Alpha1()
              addKeyListener(this);
              addMouseListener(this);
              ready = false;
              mediaTracker = new MediaTracker(this);
              playerShip = getToolkit().getImage("testship1.png");
              //starField = getToolkit().getImage("testbg.png");
              //mediaTracker.addImage(playerShip, 0);
              mediaTracker.addImage(starField, 0);
              try {
                   mediaTracker.waitForID(0);
              catch (InterruptedException e) {
                   e.printStackTrace();
         public void start()
              buffer = createImage(getSize().width,getSize().height);
              starField = createImage(getSize().width,1200);
              gfx = buffer.getGraphics();
              starFieldObj = starField.getGraphics();
              ready = true;
              new Thread(this).start();
         public void mouseDragged(MouseEvent e)     {}
         public void mouseMoved(MouseEvent e)     
              playerShipX = e.getX();
              playerShipY = e.getY();
         public void mouseReleased(MouseEvent e)     {}
         public void mousePressed(MouseEvent e)     {}
         public void mouseExited(MouseEvent e)     {}
         public void mouseEntered(MouseEvent e)  {}
         public void mouseClicked(MouseEvent e)     {}
         public void keyTyped(KeyEvent keyevent)     {}
         public void keyPressed(KeyEvent keyevent)
              keys[keyevent.getKeyCode()] = 1;
              System.out.println(keyevent.getKeyCode());
         public void keyReleased(KeyEvent keyevent)     
              keys[keyevent.getKeyCode()] = 0;
         public void run()
              generateStarfield();
              while (true)
                   if (isVisible())
                        repaint();
                        updatePositions();
                   }//end if
                   try 
                   { Thread.sleep(1000/frames); }
                   catch (InterruptedException e)
                   { e.printStackTrace(); }
              }//end while
         public void paint(Graphics g) {     /*empty etc*/ }
         public void updatePositions()
              if (keys[38] == 1 & keys[40] == 0) //IF UP IS PRESSED
              { playerShipY -= 3; }
              if (keys[40] == 1 & keys[38] == 0) //IF DOWN IS PRESSED
              { playerShipY += 6; }
              if (keys[37] == 1 & keys[39] == 0) //IF LEFT IS PRESSED
              { playerShipX -= 5; }
              if (keys[39] == 1 & keys[37] == 0) //IF RIGHT IS PRESSED
              { playerShipX += 5; }
              starFieldY = starFieldY + starFieldSpeed;
              if (starFieldY == 0)
                   starFieldY = -600;
                   System.out.println("dadssa");
         public int getRandom(int from, int to)
              if (from > to)
                   int randTemp;
                   randTemp = from;
                   from = to;
                   to = randTemp;
              return random.nextInt(to-from+1)+from;
         public void generateStarfield()
              starFieldObj.setColor(Color.black);
              starFieldObj.fillRect (0, 0, 800, 1200);
              for (int td=0; td < 900 ; td++) //draw 900x2 dots on 800x1200 image
                        starFieldObj.setColor(Color.white);
                        starFieldObj.fillRect (getRandom(1,800), getRandom(1,600), 1, 1);
                        starFieldObj.fillRect (getRandom(1,800) + 800, getRandom(1,600) + 800, 1, 1);
         public void update(Graphics g)
              if (ready)
                   gfx.setColor(Color.black);
                   //gfx.fillRect (0, 0, this.getSize().width, this.getSize().height);
                   gfx.drawImage(starField,starFieldX,starFieldY,null);
                   gfx.drawImage(playerShip,playerShipX,playerShipY,null);
                   //gfx.drawString(Integer.toString(showFps),5,5);
                   g.drawImage(buffer,0,0,null);
    }

  • Parsing Query string using Client Object model [ECMA]

    hello
    i want to access querystring using client object model using ECMA script.
    for eg http://localhost:80/demopage.aspx?test=123
    can we read value of test using ECMA script
    regards
    Manish

    thanks ...
    i did that...using
    <script type="text/javascript">
    function queryString(parameter) {
    var loc = location.search.substring(1, location.search.length);
    var param_value = false;
    var params = loc.split("&");
    for (i=0; i<params.length;i++) {
    param_name = params[i].substring(0,params[i].indexOf('='));
    if (param_name == parameter) {
    param_value = params[i].substring(params[i].indexOf('=')+1)
    if (param_value) {
    return param_value;
    else {
    return false; //Here determine return if no parameter is found

  • Using graphics object in keyPressed

    hi,
    i'm extendig Canvas class in a ew class ad want to use the Graphics's object in the KeyPressed function.
    How can , i get the object in the same function.

    Instead of a relative path have you tried an absolute file path?
    In the CR Jupiter User Guide it states:
    http://technicalsupport.businessobjects.com/KanisaSupportSite/search.do?cmd=displayKC&docType=kc&externalId=xir2crusergdeenpdf&sliceId=&dialogID=9556855&stateId=1 0 9558242
    -     The JRC now supports dynamic locations for graphics.
    In the BOE XI R2 release notes it states:
    http://technicalsupport.businessobjects.com/KanisaSupportSite/search.do?cmd=displayKC&docType=kc&externalId=xir2windowsreleasenotesenpdf&sliceId=&dialogID=9556855&stateId=1 0 9558242
    -     The JRC fails to support reports that contain relative paths to dynamic images.
    So this will work if you use fully qualified path names.

  • 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();

  • How can I run graphic object on report. ( I got REP-1246 Chart not found)

    Hi All,
    I made a report that consists a chart object. When I run it on report builder, it works well. But When I call the report from client side, I got "Rep-1246 Char Document not found" . I tried to solve it , I couldn't solve the problem . If I delete chart object from report , then report works well on client side. I didn't use graphics builder to create graphs I used only report builder to do it. I read the threads about it , but I couldn't find the solution. All solutions are about path of graphic file. I don't understand it. Because I only have *.rdf *.rep file. There is no any graph file in my system. I can create it in graphic builder but I don't know how can I deploy the graph object into report layout and run ?
    I need urgent help ..
    Thanks in advice
    Suleyman

    Hi again , I used developer 2000. In order to show graphic object on report firstly
    I created my graphic object on oracle graph builder.After that I save it like mygraph.OGD . Then I added graphic object on report builder by using graphic object on report builder. When you click the graphic object you will see CHART FILENAME part in part of CHART. In this field , you should add graphic file path that you created on graphic builder. I added mygraph.OGD into this filename part. I worked well.
    Good LUck !

  • Graphics object under unix

    Hi
    I m using sun solaris and i want to create a graph using graphics object and then write on to jpg file. For the same i musing JPEGEncoder and able to do that sucessfully under win NT and also under solaris but only when that X windows is installed and that service is running.
    My concern is i want to do the above task where x windows is not installed , in such a case where will i get graphics object from and how will graph be plotted.
    Is there any work around without using 3rd party tool
    Please let me know

    look at this http://www.eteks.com/pja/en/

  • How to change font/ font color etc in a graphic object using JCombobox?

    Hello
    My program im writing recently is a small tiny application which can change fonts, font sizes, font colors and background color of the graphics object containing some strings. Im planning to use Jcomboboxes for all those 4 ideas in implementing those functions. Somehow it doesnt work! Any help would be grateful.
    So currently what ive done so far is that: Im using two classes to implement the whole program. One class is the main class which contains the GUI with its components (Jcomboboxes etc..) and the other class is a class extending JPanel which does all the drawing. Therefore it contains a graphics object in that class which draws the string. However what i want it to do is using jcombobox which should contain alit of all fonts available/ font sizes/ colors etc. When i scroll through the lists and click the one item i want - the graphics object properties (font sizes/ color etc) should change as a result.
    What ive gt so far is implemented the jcomboboxes in place. Problem is i cant get the font to change once selecting an item form it.
    Another problem is that to set the color of font - i need to use it with a graphics object in the paintcomponent method. In this case i dnt want to create several diff paint.. method with different property settings (font/ size/ color)
    Below is my code; perhaps you'll understand more looking at code.
    public class main...
    Color[] Colors = {Color.BLUE, Color.RED, Color.GREEN};
            ColorList = new JComboBox(Colors);
    ColorList.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ev) {
                     JComboBox cb = (JComboBox)ev.getSource();
                    Color colorType = (Color)cb.getSelectedItem();
                    drawingBoard.setBackground(colorType);
              });;1) providing the GUI is correctly implemented with components
    2) Combobox stores the colors in an array
    3) ActionListener should do following job: (but cant get it right - that is where my problem is)
    - once selected the item (color/ font size etc... as i would have similar methods for each) i want, it should pass the item into the drawingboard class (JPanel) and then this class should do the job.
    public class DrawingBoard extends JPanel {
           private String message;
           public DrawingBoard() {
                  setBackground(Color.white);
                  Font font = new Font("Serif", Font.PLAIN, fontSize);
                  setFont(font);
                  message = "";
           public void setMessage(String m) {
                message = m;
                repaint();
           public void paintComponent(Graphics g) {
                  super.paintComponent(g);
                  //setBackground(Color.RED);
                  Graphics2D g2 = (Graphics2D) g;
                  g2.setRenderingHint             
                  g2.drawString(message, 50, 50);
           public void settingFont(String font) {
                //not sure how to implement this?                          //Jcombobox should pass an item to this
                                   //it should match against all known fonts in system then set that font to the graphics
          private void settingFontSize(Graphics g, int f) {
                         //same probelm with above..              
          public void setBackgroundColor(Color c) {
               setBackground(c);
               repaint(); // still not sure if this done corretly.
          public void setFontColor(Color c) {
                    //not sure how to do this part aswell.
                   //i know a method " g.setColor(c)" exist but i need to use a graphics object - and to do that i need to pass it in (then it will cause some confusion in the main class (previous code)
           My problems have been highlighted in the comments of code above.
    Any help will be much appreciated thanks!!!

    It is the completely correct code
    I hope that's what you need
    Just put DrawingBoard into JFrame and run
    Good luck!
    public class DrawingBoard extends JPanel implements ActionListener{
         private String message = "message";
         private Font font = new Font("Serif", Font.PLAIN, 10);
         private Color color = Color.RED;
         private Color bg = Color.WHITE;
         private int size = 10;
         public DrawingBoard(){
              JComboBox cbFont = new JComboBox(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
              cbFont.setActionCommand("font");
              JComboBox cbSize = new JComboBox(new Integer[]{new Integer(14), new Integer(13)});
              cbSize.setActionCommand("size");
              JComboBox cbColor = new JComboBox(new Color[]{Color.BLUE, Color.RED, Color.GREEN});
              cbColor.setActionCommand("color");
              JComboBox cbBG = new JComboBox(new Color[]{Color.BLUE, Color.RED, Color.GREEN});
              cbBG.setActionCommand("bg");
              add(cbFont);
              cbFont.addActionListener(this);
              add(cbSize);
              cbSize.addActionListener(this);
              add(cbColor);
              cbColor.addActionListener(this);
              add(cbBG);
              cbBG.addActionListener(this);
         public void setMessage(String m){
              message = m;
              repaint();
         protected void paintComponent(Graphics g){
              super.paintComponent(g);
              Graphics2D g2 = (Graphics2D)g;
              g2.setColor(bg);//set background color
              g2.fillRect(0,0, getWidth(), getHeight());          
              g2.setColor(color);//set text color
              FontRenderContext frc = g2.getFontRenderContext();
              TextLayout tl = new TextLayout(message,font,frc);//set font and message
              AffineTransform at = new AffineTransform();
              at.setToTranslation(getWidth()/2-tl.getBounds().getWidth()/2,
                        getWidth()/2 + tl.getBounds().getHeight()/2);//set text at center of panel
              g2.fill(tl.getOutline(at));
         public void actionPerformed(ActionEvent e){
              JComboBox cb = (JComboBox)e.getSource();
              if (e.getActionCommand().equals("font")){
                   font = new Font(cb.getSelectedItem().toString(), Font.PLAIN, size);
              }else if (e.getActionCommand().equals("size")){
                   size = ((Integer)cb.getSelectedItem()).intValue();
              }else if (e.getActionCommand().equals("color")){
                   color = (Color)cb.getSelectedItem();
              }else if (e.getActionCommand().equals("bg")){
                   bg = (Color)cb.getSelectedItem();
              repaint();
    }

  • Trying to move a graphics object using buttons.

    Hello, im fairly new to GUI's. Anyway I have 1 class which makes my main JFrame, then I have another 2 classes, one to draw a lil square graphics component (which iwanna move around) which is placed in the center of my main frame and then another class to draw a Buttonpanel with my buttons on which is placed at the bottom of my main frame.
    I have then made an event handling class which implements ActionListner, I am confused at how I can get the graphics object moving, and where I need to place the updateGUI() method which the actionPerformed method calls from inside the event handling class.
    I am aware you can repaint() graphics and assume this would be used, does anyone have a good example of something simular being done or could post any help or code to aid me, thanks!

    Yeah.. here's an example of custom painting on a JPanel with a box. I used a mouse as it was easier for me to setup than a nice button panel on the side.
    Anyways... it should make it pretty clear how to get everything setup, just add a button panel on the side. and use it to move the box instead of the mouse.
    -Js
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.event.MouseEvent;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.event.MouseInputAdapter;
    public class MoveBoxAroundExample extends JFrame
         private final static int SQUARE_EDGE_LENGTH = 40;
         private JPanel panel;
         private int xPos;
         private int yPos;
         public MoveBoxAroundExample()
              this.setSize(500,500);
              this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
              this.setContentPane(getPanel());
              xPos = 250;
              yPos = 250;
              this.setVisible(true);     
         private JPanel getPanel()
              if(panel == null)
                   panel = new JPanel()
                        public void paintComponent(Graphics g)
                             super.paintComponent(g);
                             g.setColor(Color.RED);
                             g.fillRect(xPos-(SQUARE_EDGE_LENGTH/2), yPos-(SQUARE_EDGE_LENGTH/2), SQUARE_EDGE_LENGTH, SQUARE_EDGE_LENGTH);
                   MouseInputAdapter mia = new MouseInputAdapter()
                        public void mousePressed(MouseEvent e)
                            xPos = e.getX();
                            yPos = e.getY();
                            panel.repaint();
                        public void mouseDragged(MouseEvent e)
                            xPos = e.getX();
                            yPos = e.getY();
                            panel.repaint();
                   panel.addMouseListener(mia);
                   panel.addMouseMotionListener(mia);
              return panel;
         public static void main(String args[])
              new MoveBoxAroundExample();
    }

  • Best way to draw thousands of graphic objects on the screen

    Hello everybody, I'm wanting to develop a game where at times thousands of graphic objects are displayed on-screen. What better way to do this in terms of performance and speed?
    I have some options below. Do not know if the best way is included in these options.
    1 - Each graphical object is displayed on a MovieClip or Sprite.
    2 - There is a Bitmap that represents the game screen. All graphical objects that are displayed on screen have your images stored in BitmapData. Then the Bitmap that represents the game screen copies for themselves the BitmapData of graphical objects to be screened, using for this bitmapData.copyPixels (...) or BitmapData.draw  (...). The Bitmap that represents the screen is added to the stage via addChild (...).
    3 - The graphical objects that are displayed on screen will have their images drawn directly on stage or in a MovieClip/Sprite added to this stage by addChild (...). These objects are drawn using the methods of the Graphics class, as beginBitmapFill and beginFill.
    Recalling that the best way probably is not one of these 3 above.
    I really need this information to proceed with the creation of my game.
    Please do not be bothered with my English because I'm using Google translator.
    Thank you in advance any help.

    Thanks for the information kglad. =)
    Yes, my game will have many objects similar in appearance.
    Some other objects will use the same image stored, just in time to render these objects is that some effects (such as changing the colors) will be applied in different ways. But the picture for them all is the same.
    Using the second option, ie, BitmapDatas, which of these two methods would be more efficient? copyPixels or draw?
    Thank you in advance any help. =D

  • How to use a Graphics Object in a JSP?

    Hello, I do not know if this is a good or a silly question. Can anyone tell me if we can use a Graphics object in a JSP. For example to draw a line or other graphics, i am planning to use the JSP. Any help is much appreciated.
    Regards,
    Navin Pathuru.

    Hi Rob or Jennifer, could you pour some light here.
    I have not done a lot of research for this, but what i want to do is below the polygon i would like to display another image object like a chart... is it possible? If so how to do it? Any help is much appreciated.
    here is the code:
    <%
    // Create image
    int width=200, height=200;
    BufferedImage image = new BufferedImage(width,
    height, BufferedImage.TYPE_INT_RGB);
    // Get drawing context
    Graphics g = image.getGraphics();
    // Fill background
    g.setColor(Color.white);
    g.fillRect(0, 0, width, height);
    // Create random polygon
    Polygon poly = new Polygon();
    Random random = new Random();
    for (int i=0; i < 5; i++) {
    poly.addPoint(random.nextInt(width),
    random.nextInt(height));
    // Fill polygon
    g.setColor(Color.cyan);
    g.fillPolygon(poly);
    // Dispose context
    g.dispose();
    // Send back image
    ServletOutputStream sos = response.getOutputStream();
    JPEGImageEncoder encoder =
    JPEGCodec.createJPEGEncoder(sos);
    encoder.encode(image);
    %>
    Regards,
    Navin Pathuru

  • Drawing a Graphics object on a Graphics object

    Is there anyway to draw a Graphics object on another Graphics object? I'm trying to show 2 screens, side by side, on a Canvas and I'm trying to cheat a little :-P Basically, I want to take half of one screen and half of another and put them on top of each other to form one screen.
    OR is there a way to turn a Graphics object into an Image object?

    I'm not sure if this is what you're after, but you can
    - create an offscreen image using "createImage(int width, int height)" method of a Component , then
    - obtain the graphics context of the offscreen image using "getGraphics()",
    - you can then draw onto the offscreen image using the graphics context.
    hope that helps. =)

  • Ai, 3D effect - after using to either extrude or revolve the settings are retained in my drawing tools - pen, pencil and shapes. Example I draw a 50 pt extruded object in wireframe, isometric view and my pen and all drawing tools will only draw using thos

    Ai, 3D effect - after using to either extrude or revolve the settings are retained in my drawing tools - pen, pencil and shapes. Example I draw a 50 pt extruded object in wireframe, isometric view and my pen and all drawing tools will only draw using those settings. I can not exit, help please!

    Appearance panel menu > New art has basic appearance.

  • Draw a line using mouse

    Hello there:
    I'm trying to draw a line using mouse pointer: My code is:
    public class DrawLine extends JFrame implements MouseListener, MouseMotionListener
        int x0, y0, x1, y1;  
        public DrawLine()
             addMouseListener(this);
             addMouseMotionListener(this);
        public void mouseDragged(MouseEvent e)
             x1 = e.getX();
             y1 = e.getY();
             repaint();
        public void mouseMoved(MouseEvent e) { }
        public void mouseClicked(MouseEvent e){ }
        public void mouseEntered(MouseEvent e) { }
        public void mouseExited (MouseEvent e) { }
        public void mousePressed(MouseEvent e)
              x0 = e.getX();
              y0 = e.getY();           
        public void mouseReleased(MouseEvent e)
              x1 = e.getX();
              y1 = e.getY();
       public void paint(Graphics g)
                 g.setColor(Color.BLACK);
              g.drawLine(x0, y0, x1, y1);
        public static void main(String[] argv)
             DrawLine dr=new DrawLine("Test");
             dr.setVisible(true);
             dr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }when mouse is dragged, multiple lines are being drawn....
    could you else please tell me what should I've to do???
    thanks n regards...
    Dev

    You can implement the listeners on any class, even one that (implicitly) extends Object. What matters is that the listener is added to the component that needs to use it.
    That said, why do you want to extend JFrame? Are you adding functionality to the JFrame to justify extending the JFC class? Note that extending JFrame allows the users of your class to access the functionality of a JFrame, is that really indicated here?
    one class that extends JFrame, and one can draw a line on JLabel, embedded within JFrame!So you still have to override paintComponent of the JLabel, which implies using an anonymous inner class.
    Starting with the example already posted, that would be:
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.SwingUtilities;
    public class DrawLineTest
        implements MouseListener, MouseMotionListener {
      JLabel label;
      int x0, y0, x1, y1;
      private void makeUI() {
        JFrame frame = new JFrame("DrawLineTest");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        label = new JLabel("FFFF") {
          public void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.setColor(Color.BLACK);
            g.drawLine(x0, y0, x1, y1);
        label.setPreferredSize(new Dimension(500, 500));
        label.addMouseListener(this);
        label.addMouseMotionListener(this);
        frame.add(label);
        frame.pack();
        frame.setVisible(true);
      public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            new DrawLineTest().makeUI();
      public void mousePressed(MouseEvent e) {
        x0 = e.getX();
        y0 = e.getY();      
      public void mouseReleased(MouseEvent e) {
        x1 = e.getX();
        y1 = e.getY();
      public void mouseDragged(MouseEvent e) {
        x1 = e.getX();
        y1 = e.getY();
        label.repaint();
      public void mouseMoved(MouseEvent e) { }
      public void mouseClicked(MouseEvent e){ }
      public void mouseEntered(MouseEvent e) { }
      public void mouseExited (MouseEvent e) { }
    }Better spend more time with the tutorials, there's a separate section on writing event listeners.
    db

  • Drawing a String at an angle

    Hi,
    I have use the Graphics class to develope a map of streets etc and I wish to place the name of the streets running parallel to the streets themselves.
    The drawString method allows me to specifiy the string and start co-ordinates but can anyone tell me how I can specify the strings baseline or the start and end co-ordinates of the string in order to display the string parallel to the street.
    Thanks

    Assuming your using Swing and not AWT...
    1. Convert your graphics object into a graphics2D object;
    Graphics2D g2 = (Graphics) g;
    2. use translate(x, y) to recenter your world. In general, I like to return to the center when I'm done with operations at that point
    3. useGraphics2D.rotate(...) to rotate your string drawing. Always remember that strings draw from the bottom left hand corner.

Maybe you are looking for

  • How to get all properties for an item with search?

    How can I get all crawled / managed properties back of an item with the search API (REST, client, or server)? Currently I am only aware of specifying the applicable properties specifcally by using the selectproperties parameters via REST: http://host

  • 1.5.0_08 EXCEPTION_ACCESS_VIOLATION in deploy.dll

    Hello, We develop a java application that is deployed over the web via Apacha Tomcat servlet container using IE 6. Sometimes, sporadically throughout the life of this product, we have seen JVM crashes that close all IE browsers open and place the hs_

  • Error message when cutting a sequence into a sequence

    When we try to cut a sequence into another sequence, we either get a nested sequence (the nest tool is turned off) or we crash with this error message: We are in Premiere Pro 2014.2 with our media on a server.  I moved the entire project to  my local

  • Strange grinding noise from my superdrive on a specific disc!?!

    This is very weird. When I insert a specific software disc into my superdrive, there is a grinding and buzzing sound...like there is a weed whacker inside the computer. Again, this is really weird because no other disc has this problem... It appears

  • Icons in system tray

    on a non wired desktop pc, windows xp. sp2, I want to clean out the system tray of unneeded icon(programs)running there. I have: Linksys Router BEFW1154 adapter WUSB11Ver2.6 cable modem BEFCMU10  v.3 In the non wired computers system tray there are 2