Change origin of canvas

hey, i have a canvas that positions itself in the middle of the screen with two lines (x and y axis). the problem is that i want to be able to move the origin, which then draws the axis again.
thanks
Pedge
// GCanvas.java
import java.awt.*;
import java.awt.event.*;
import java.util.*;
* This class extends the canvas class to include the input and drawing of a polygon
* @author Geoff Hobson
* @version 1.1 (24 Nov 99)
class GCanvas extends Canvas
* the polygon object associated with this canvas.
private GPolygon polygon;
* indicates whether currently in process of colecting the vertices of a polygon.
private boolean building = false;
* the size of one pixel in the logical coordinates of the polygon - the scaling factor.
float pixelSize;
* the screen x coordinate of the logical origin - screen x position of y-axis.
int centerX;
* the screen y coordinate of the logical origin - screen y position of x-axis.
int centerY;
* the radius of the circle around the start point,
* a mouse press anywhere in this circle will be treated as selecting the centre point.
private int circleSize = 3;
* Constructs a GCanvas and associates it with the given Polygon poly.
* @param poly the polygon object which is to be drawn and manipulated
GCanvas(GPolygon poly)
polygon = poly;
addMouseListener
(new MouseAdapter()
{ public void mousePressed(MouseEvent evt)
pointSelected(evt.getX(), evt.getY());
); // end of new MouseAdapter
setBackground(Color.gray);
private int cX, cY;
* clears the canvas and sets it ready for the input of a new polygon.
public void newPoly()
building = true;
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
repaint();
* The action to be performed when a point is selected by a mouse press.
* @param x the x coordinate of the selected point
* @param y the y coordinate of the selected point
private void pointSelected(int x, int y)
if (building)
addVertex(x, y);
* Add a new vertex to the polygon object
* @param x the x coordinate of the new vertex
* @param y the y coordinate of the new vertex
private void addVertex(int x, int y)
if (polygon.size() == 0)
polygon.addVertex(new Point2D(fX(x), fY(y))); // add first vertex to a polygon
else
Point2D v0 = polygon.getVertex(0);
int dx = x - iX(v0.x), dy = y - iY(v0.y);
if (dx * dx + dy * dy < circleSize * circleSize)
{    // mouse in circle around first vertex
polygon.closePolygon(); // the polygon has been closed
building = false;
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
else
polygon.addVertex(new Point2D(fX(x), fY(y))); // add an other vertex to polygon
repaint();
* Converts logical to screen x coordinate
* @param x the logical x coordinate
* @return the screen x coordinate
int iX(float x)
return Math.round(centerX + x/pixelSize);
* Converts logical to screen y coordinate
* @param x the logical y coordinate
* @return the screen y coordinate
int iY(float y)
return Math.round(centerY - y/pixelSize);
* Converts screen to logical x coordinate
* @param x the screen x coordinate
* @return the logical x coordinate
float fX(int x)
return (x - centerX) * pixelSize;
* Converts screen to logical y coordinate
* @param x the screen y coordinate
* @return the logical y coordinate
float fY(int y)
return (centerY - y) * pixelSize;
* Paints the canvas with current state of polygon
* @param g the graphic context for the paint method
public void paint(Graphics g)
// initialise a blank canvas and draw axes etc
int maxX = getSize().width - 1; // get size of screen
int maxY = getSize().height - 1;
float rWidth = polygon.logicalWidth(); // get logical size of polygon
float rHeight = polygon.logicalHeight();
pixelSize = Math.max(rWidth/maxX, rHeight/maxY); // calculate scaling factor
centerX = maxX/2; // calculate position of axes
centerY = maxY/2;
int left = iX(-rWidth/2); // calculate edges of logical polygon
int right = iX(rWidth/2);
int bottom = iY(-rHeight/2);
int top = iY(rHeight/2);
// draw white rectangle for logical polygon
g.setColor(Color.white);
g.fillRect(left, top, right - left+1, bottom - top+1);
// draw frame around logical polygon rectangle
g.setColor(Color.darkGray);
g.drawRect(left, top, right - left, bottom - top);
g.setColor(Color.lightGray);
g.drawLine(left,centerY, right,centerY); // draw x axis
g.drawLine(centerX,top, centerX,bottom); // draw y-axis
// draw current state of the polygon
int n = polygon.size();
if (n == 0) return; // if there are no vertices
Point2D A, B;
A = (polygon.getVertex(0));
// Show tiny circle around first vertex:
g.setColor(Color.red);
if (!polygon.isClosed())
g.drawOval(iX(A.x)-circleSize, iY(A.y)-circleSize, circleSize*2, circleSize*2);
// draw the polygon
g.setColor(Color.blue);
for (int i=1; i<n; i++)
B = (polygon.getVertex(i));
g.drawLine(iX(A.x), iY(A.y), iX(B.x), iY(B.y));
A = B;
if (polygon.isClosed()) // draw side from last to first vertex
B = (polygon.getVertex(0));
g.drawLine(iX(A.x), iY(A.y), iX(B.x), iY(B.y));
} // end of paint
} // end of class GCanvas

How about declaring changing centerx and centery in the constructor?

Similar Messages

  • Changing Original System and Transport Target System for Objects

    Hi Gurus,
             I need to do mass transport of all the Infoobjects to newly defined system. Since these objects have different Original system. Its giving me error. Again, for other objects, Transport Target system is QAS, But we want to change it to NBW (A new system to which we want to send transport) . I am able to change package of Infoobjects. Is there mechanism to change Original System and Transport Target for System? Please let me know ASAP.
    Regards,
    Harpal
    Message was edited by:
            Harpalsinh Gohil

    If you simply edit your original post, it will go to the top of the list. There's no need to post duplicates.
    Subjects with a subject of "Urgent" will be filtered out by a lot of responders.
    Why not close this thread and bump the other one?
    Rob

  • How to change original source system of objects at one time

    Hi, experts !
    I installed extra devlopment server using system copy of orignal
    delveopment system.
    We have planed that new objects applied to orginal server after developing
    finished on extra devlopement server.
    The problem is we can not modify or add old objects for specific
    package because orignal source system is different
    and I know this is SAP policy.
    Of course original source server can be changeed on t-code SE03 or
    function module TRINT_TADIR_MODIFY
    but it should be applied to every objects. This is big job to BC admin.
    Is there any solution to possible it at one time?
    Best Regards

    You can transport all relevant packages from the old to the new development box including a change of the original system using a special transport request of type "relocation of complete package". Check with your system administrators.
    Please close your similar post here:
    How to change original system SID to objects by batch?
    Thomas

  • I have changed my background canvas color... but it hasn't changed. HELP

    I have changed my background canvas color too White through the preferences system... but it hasn't changed. Can anyone help me with this as I'm tearing my hair out!!
    S

    somanna wrote:
    I guess that you should have first done this and can even do it even now:
    Have the entire project selected first; then open your preferences and choose your white background. This should allow your entire work to have a white background.
    That is NOT the way it is supposed to work. The background color preference is global to the application, it does not work on a project by project basis. This preference setting determines what FCP X displays in the Viewer in areas where you have no content (or where the content is transparent) - as in the present case, where the photos do not cover the whole viewer area.
    You can easily confirm this. Open some project with a transparent area, and set the background to say, white.
    You should see white showing through any transparent area (that's what the OP was expecting, and it should happen!).
    Now close this project, open something else. Switch to, say, checkerboard background.
    Open the previous project and see the checkerboard (not white!) background.
    One workaround for the present problem is to place a custom generator behind the content, and set its color to white. But of course this should not have been necessary.

  • Anybody know how to 'change' original ID username with OLD deleted email account on my iPad 2? New email and password work on website, but can't access iPad - thanks.

    Does anyone know how I can change original e-mail / user ID on the iPad II itself?  On the website, I can use new email/user ID and password; but NOT on the iPad!? Thanks for any assistance.

    Hi,
    In order to fix the problem regarding Adobe ID you can follow the steps as suggested below.
    1) Open Adobe Digital Editions and connect your Reader
       Press the keys Ctrl + Shift + E  on your keyboard.
       Now a Deauthorize screen will come up asking you to deauthorize your Reader.
       Follow the screen instructions and unauthorize the Reader.
       Now Press the keys Ctrl + Shift + D  on your keyboard.
        Now a Deauthorize screen will come up asking you to deauthorize your Computer.
        Follow the screen instructions and unauthorize the computer.
    Click Start>>Run and Type "Regedit" without quotes in the box
         A window will open with name Registry Editor
         Search for ADEPT in given location.
         HKEY_CURRENT_USER>Software>Adobe>Adept
         Delete the full folder
         Now open Digital Editions and it will ask you to authorize enter your New Adobe ID and password.
         Now connect your Reader and it will again ask you to authorize enter your Adobe ID and password.
    Please Note : Your Adobe ID and password which you are entering while authorizing your Reader should match with the ID which you are using with Adobe Digital Editions.
    Now for your second problem that your Reader is not getting recognized by your computer I would suggest you to contact sony support in order to fix it. They might have some firmware update for your Reader.
    I hope this will help you!!!
    Regards
    Rizwan

  • Iwork-Pages totally changes original doc file. Why?

    Hi,
    Today morning I download .doc extension file from my email, it asked to open in iWork-pages. Opening it so changed the format by merging cells and changed original document style. Can anybody suggest me a better alternative, so I can edit without changing original format?

    You can try Docs2Go, Office2, Goodreader and probably others.

  • Change Original Budget

    Hi all,
    I use transaction KO22 in order to change original budget amount allocated to IO, but here we have to enter IO each time to see the budget and change it.
    Is there any other transaction which displays list of IOs and relative budgets and gives the possibility to change them simoltaneously?
    Thank you in advance.

    I think it would be possible if you use 'Order group' and maintain multiple order under it and then do KO22. Foe change supplement,return you can use KO24, KO26.
    Explore more on order group and let us know if it helps.
    Thanks

  • How to Create a New Admin Account and Change Original to Standard Account?

    I have a single user admin account that I set up when I got my PowerBook. Now I want to have two accounts with the new one being the admin account. This way I can leave most of the data files, email accounts, etc. with the old account and use the new one for personal data and admininistration. Then I could give out the password for the original account without fear that a user could change permissions and get access to the new account with the personal data. Can I create a new admin account and then change the original account to "Standard" instead of "admin"? What problems will this create?
    PowerBook G4   Mac OS X (10.3.9)  

    i2:
    Not sure if you are asking if or how. Templeton has
    answered if. Here's how.
    Apple Menu > System Prefs > Accounts. Click on the +
    under User Options to create new account. Go to
    Security and check box at bottom to make account
    admin. You can take care of the other items, picture
    etc, login options etc.
    To make the other account Standard select the
    account, go to Security and deselect box "Allow User
    to Administer".
    Hope this answers your questions.
    Good luck.
    cornelius
    PismoG4 550,
    100GB 5400 Toshiba internal, 1 GB RAM; Pismo 500 OS
    (10.4.4)   Mac OS X (10.3.9)   Beige G3 OS
    8.6
    Thanks, I'm tying to find out if I will run into problems, such as not being able to use the new admin account to change permissions in the old.

  • CHANGING ORIGINAL NAME OF AN APP ANSWER QUICKMY PLS

    Hey guys
    I downloaded an app called Minecraft Hub. When you run it, it appears 3 site about minecraft. I changed script file and made My Sites. But the original name (appears on the left top corner) is stil Minecraft Hub.
    Help Me Plllleeeaaaasseee Quickkk

    You've wandered into the forum for Apple's discontinued productivity program 'AppleWorks' and I've asked the Hosts to move you to the iTunes Store forum in the hope that it may be more applicable.
    ' It was PPC when we bought it.' - believe me, it still is .

  • How to change color of canvas?

    I made sure the background color swatch in the lower left of the tool box was set to blue.  Then I went to Image>Resize>Canvas Size> and changed the sizes.  Then I set the Color Extension to the background color blue, and the little box to the right of this showed the blue I wanted.
    Then I clicked OK.
    The sizes changed properly, but the color won't change colors at all.  It stays an ugly putty brown, no matter that I have tried every single way in that color extension box pull-down menu.
    Any help will be much appreciated.

    Try this:
    Set the background color (lower left) to blue
    Go to File>new>blank file. Enter width & height in inches for the desired document, resolution 240-300px/in for printing, background contents: background color.
    OK

  • Edit photo in album without changing original

    In iPhoto '08, it seems like any photo that I edit in an album also edits the original. This is why I stopped using one of the earlier versions of iPhoto. It seemed like this was fixed in iPhoto 6, so that iPhoto would automatically preserve the original and save the changes in a copy of the photo.
    Is there a setting that can be changed in the preferences somewhere? If I'm working on two albums (i.e. one for each child) I often want to use the same photos but crop them differently, and I'd rather not have to remember to make a copy any time I do so.

    No, all occurrences of a photo in the library other than in an event is just an alias of the original or the edited version. Change one and you change all.
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've created an Automator workflow application (requires Tiger), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. It's compatible with iPhoto 08 libraries and Leopard. iPhoto does not have to be closed to run the application, just idle. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.

  • Change original language for table

    Hi,
    I created a table and some reason the Orginal language from the Attribute tab is DE. How can I changed this to EN? I looked at all the menu selections and nothing saids about it. I deleted the table and recreated using the same name but it still taking on the DE language.
    Thanks
    Ellen

    Hello,
    Login in EN language and try to change the text of the table. The system will ask two options
    1 . Maintain in Original Language
    2. Change Orginal Language
    Click the option Change Orginal Language and change to language of ur desire.
    Vasanth

  • Function to change proportions of canvas

    hello,
    I hope someone can help me with this.
    I have an canvas that is representing a piece of paper.
    By chosing an option in the radiobuttongroup i wanna change
    the proportions and position of my canvas.
    chosing landscape or normal to rotate the canvas (paper).
    i have no idea to let the canvas change live, Please some
    help here.

    solution:
    ------------------------------- one canvas
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:states>
    <mx:State name="landscapeState">
    <mx:SetProperty target="{paperCanvas}" name="width"
    value="250"/>
    <mx:SetProperty target="{paperCanvas}" name="height"
    value="193"/>
    </mx:State>
    </mx:states>
    <mx:transitions>
    <mx:Transition fromState="*" toState="*">
    <mx:Resize targets="{paperCanvas}" />
    </mx:Transition>
    </mx:transitions>
    <mx:Canvas width="193" height="250"
    horizontalCenter="0.5" top="55" backgroundColor="#ffff80"
    id="paperCanvas">
    <mx:filters>
    <f:DropShadowFilter alpha=".7" distance="8"
    xmlns:f="flash.filters.*" />
    </mx:filters>
    <mx:Text text="Click the RadioButtons below to change the
    shape of this &quot;paper&quot; canvas." left="10"
    right="10" top="101" bottom="10"/>
    <mx:Label text="Paper" fontWeight="bold" fontSize="16"
    left="10" top="10"/>
    </mx:Canvas>
    <mx:RadioButton selected="true" y="330" label="Portrait"
    click="currentState=''" horizontalCenter="-61"/>
    <mx:RadioButton y="330" label="Landscape"
    click="currentState='landscapeState'" horizontalCenter="58.5"/>
    </mx:Application>
    ------------------ two canvases ontop of eachother (rotate at
    the same time) ------------------
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:states>
    <mx:State name="landscapeState">
    <mx:SetProperty target="{paperCanvas}" name="width"
    value="250"/>
    <mx:SetProperty target="{paperCanvas}" name="height"
    value="193"/>
    <mx:SetProperty target="{paperCanvas2}" name="width"
    value="250"/>
    <mx:SetProperty target="{paperCanvas2}" name="height"
    value="193"/>
    </mx:State>
    </mx:states>
    <mx:transitions>
    <mx:Transition fromState="*" toState="*">
    <mx:Resize targets="{[paperCanvas,paperCanvas2]}" />
    </mx:Transition>
    </mx:transitions>
    <mx:Canvas width="193" height="250"
    horizontalCenter="0.5" top="55" backgroundColor="#ffff80"
    id="paperCanvas">
    <mx:filters>
    <f:DropShadowFilter alpha=".7" distance="8"
    xmlns:f="flash.filters.*" />
    </mx:filters>
    <mx:Text text="Click the RadioButtons below to change the
    shape of this &quot;paper&quot; canvas." left="10"
    right="10" top="101" bottom="10"/>
    <mx:Label text="Paper" fontWeight="bold" fontSize="16"
    left="10" top="10"/>
    </mx:Canvas>
    <mx:Canvas width="193" height="250"
    horizontalCenter="0.5" top="55" backgroundColor="#ffffff"
    id="paperCanvas2">
    </mx:Canvas>
    <mx:RadioButton selected="true" y="330" label="Portrait"
    click="currentState=''" horizontalCenter="-61"/>
    <mx:RadioButton y="330" label="Landscape"
    click="currentState='landscapeState'" horizontalCenter="58.5"/>
    </mx:Application>

  • Mass change original system for objects

    Is there a way to change the original systems for multiple objects at once?
    So instead of changing them one by one, can the original system for objects be changed for multiple objects at once?
    Kind regards,
    Ben

    I've checked with the Basis team, but they couldn't help me further.
    For the moment we'll leave the objects like they are and Overwrite the originals when transporting.
    Kind regards and thanks,
    Ben

  • MovieClip button changes original

    I have searched around but can't find the exact solution to
    my problem....so here it is.
    I have a Movie Clip button in my library and I drag multiple
    copies onto the stage. I start to change the text and other
    attributes of the different instances. Whenever I do this the
    changes happen to all. I am not sure why this is. It is probably
    something I should know.
    I didn't create these library items so I am not sure what the
    original developer did. None of the library items I create do this.
    I can add as many of mine as i want and change text for each
    instance.
    This has to be something simple.
    Thanks for any help
    -Ken

    In the library, right click on the movie clip and select
    duplicate and give
    the new movie clip a different. It is the new movie clip that
    you want to
    change. When you are finished, place an instance of the new
    clip on the
    stage and give it an instance name.
    The changes you made before worked exactly as they should but
    it was the
    wrong approach for your purposes.

Maybe you are looking for

  • How do i get music from my iPhone on to a new iTunes library?

    I have my iphone synced with an itunes library, but that laptop was recently died. completley. I want to sync my phone to my iMac now. how do I transfer all the stuff on my phone to the computer? i really dont want to lose anything!

  • Weird problem with vertical text in a table

    Hello, I am new on this forum, usually I don't post because I always find the answer to my question, but this is something quite weird... I have a table with vertical text in it (it has to be vertical because the cells are narrow). And I want it to b

  • KDL-40BX450 - problem

    A year or two ago I purchased a KDL-40BX450 HDTV for our vacation home. This product has had little use - well less than 100 hours.  A couple of days ago it came on by itself emitting a high pitched, siren like, sound.  I turned it off and then back

  • Reg net price disable in ME22n for production purchase order

    Hi All, Can any body tell me how I can make disable(suppress) the field of netprice of a particular purchase order. My requirement is if PO is of type prod order I should disable netprice field of the line item of a purch order How can I will do that

  • Oracle in not responsing to connect requests via sqlplus

    Hi, I am trying to connect to oracle 10.2.0.3 on linux via sqlplus. All the oracle process are up. tnsping and ping are response OK. I check the uptime, and it show: 01:58:21 up 3 days, 23:47, 1 user, load average: 0.09, 0.03, 0.01 THE PROBLEM IS : O