SVGPath scale proportionally - and automatically

Hello

I am trying to use a SVG path to create a shot of a territory (country) on top of some nodes will be placed, to represent cities.

I tried style area to take the desired shape, but when resizing the stage, it loses its proportions. So, my country gets all distorted. :) Is it possible to force a region maintain its proportions globally?

Also, I tried with the old good SVGPath forms are not resizable by self (disappointment), so I had to use scaleX and scaleY, but still don't know how to make the link between these two dimensions of the parent StackPane.

Any ideas on how to achieve this?

Published by: scekics on 08.06.2012. 12.11

Here is a piece of code that does what you want. I hope it helps.

package jfxfeatures.graphics.shapes.paths.butterfly;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.shape.SVGPath;
import javafx.scene.shape.SVGPathBuilder;
import javafx.scene.transform.Scale;
import javafx.scene.transform.Translate;
import javafx.stage.Stage;

public class ScaleTest extends Application {

     private final static String svg = "M100 50 L150 0 L200 50 L150 100 Z";
     private Pane editPane;
     private Group graphics;
     private Node content;

     @Override
     public void start(final Stage stage) throws Exception {
        stage.setTitle(getClass().getSimpleName());

        editPane = new Pane();
        graphics = new Group();
     editPane.getChildren().add(graphics);

        StackPane root = new StackPane();
        root.getChildren().add(editPane);

        Scene scene = new Scene(root, 800, 800);
        stage.setScene(scene);
        stage.show();

        content = loadContent();
        graphics.getChildren().add(content);

        editPane.widthProperty().addListener(new ChangeListener(){
               @Override
               public void changed(ObservableValue observable, Number oldValue, Number newValue) {
                    adjustTransform();
               }});

        editPane.heightProperty().addListener(new ChangeListener(){
               @Override
               public void changed(ObservableValue observable, Number oldValue, Number newValue) {
                    adjustTransform();
               }});

        Platform.runLater(new Runnable() {
               @Override
               public void run() {
                    adjustTransform();
               }
          });
     }

     private Node loadContent() {
          SVGPath p = SVGPathBuilder.create().content(svg).style("-fx-stroke-width:5;-fx-fill:null;-fx-stroke:black").build();
          Group content = new Group();
          content.getChildren().add(p);
          return content;
     }

     private void adjustTransform() {
          graphics.getTransforms().clear();

          double cx = content.getBoundsInParent().getMinX();
          double cy = content.getBoundsInParent().getMinY();
          double cw = content.getBoundsInParent().getWidth();
          double ch = content.getBoundsInParent().getHeight();

          double ew = editPane.getWidth();
          double eh = editPane.getHeight();

          if (ew > 0.0 && eh > 0.0) {
               double scale = Math.min(ew/cw, eh/ch);

               // Offset to center content
               double sx = 0.5 * (ew - cw*scale);
               double sy = 0.5 * (eh - ch*scale);               

               graphics.getTransforms().add(new Translate(sx, sy));
               graphics.getTransforms().add(new Translate(-cx, -cy));
               graphics.getTransforms().add(new Scale(scale, scale, cx, cy));
          }
     }

     public static void main(String[] args) {
          launch(args);
     }

}

Tags: Java

Similar Questions

  • Why I can't scale proportionally by using the slide bar?

    I know there are other ways to change the size of an image, I would use Edit > Transform > scale to scale proportionately. It doesn't seem to work for me, as you can see below in this video that I created with audio included. What I am doing wrong? I use Photoshop CC 2015.1 on a 8.1 Windows machine.

    Appreciate any help you can offer.

    Your title is confusing: "moving bar. Usually people refer only to a bar in the space bar and the shift key. Are you pressing the SPACEBAR or shift key? The space bar will give you the hand, while the SHIFT key will scale proportionally. If you use the SHIFT key, you may have to reset your preferences.

  • How to fix stuck battery and automatic when restart updated ios 9.3.3

    How to fix stuck battery and automatic when restart updated ios 9.3.3

    Lambung writes:

    How to fix stuck battery and automatic when restart updated ios 9.3.3

    What do you mean battery stuck?

    the basic troubleshooting steps are: reboot, reset, restore from a backup or restore as a new.

  • iMac freezing and automatically restarts randomly

    Hello

    Hello

    I'm a new mac user. I got an imac, but I'm having problems from the beginning.

    Freeze the computer when using and automatically restarts randomly.

    iMac 27 inches, (end of 2015)

    3.2 GHz Intel Core i5 - 8 GB RAM - 1 TB FusionDrive

    AMD Radeon R9 M390

    OS X El Capitan 10.11.3


    I brought the computer to a genius bar. No known hardware issues. They reset the mac to factory settings, but already during the first launch of configuration, the computer froze again. For a few days, everything was ok while the problems started again. I only certified software: printer Canon and Adobe Creative Cloud. I tried to change the position, to connect the mac to the router with the cable to the same WiFi spot left offline, but the problem persists. sometimes with intervals of 2 hours to others 4 times in an hour. Write an email, with safari or even left (do not use)

    I tried new Apple Diagnostics and disk utility both without errors even if disk utility displays more ssd.

    The console since the last crash log:

    17/02/16 17:40:20, com.apple.AddressBook.InternetAccountsBridge [510 326]: dnssd_clientstub ConnectToServer: connect()-> test number: 2

    17/02/16 17:40:20, com.apple.AddressBook.ContactsAccountsService [328 548]: [accounts] current connection, connection of pid 459, doesn't have account access.

    17/02/16 17:40:20, com.apple.ncplugin.FindMyFriends [459 548]: [accounts] could not update the account with identifier 545110F6-2B83-4D5C-933D-5BA8942FA5FF, error: error Domain = ABAddressBookErrorDomain Code = 1002 '(null) '.

    17/02/16 17:40:20, com.apple.AddressBook.ContactsAccountsService [328 697]: [accounts] current connection, connection of pid 361, has no access to account.

    17/02/16 17:40:20, fmfd 697 [361]: [accounts] could not update the account with identifier 545110F6-2B83-4D5C-933D-5BA8942FA5FF, error: error Domain = ABAddressBookErrorDomain Code = 1002 '(null) '.

    17/02/16 17:40:21, 069 via [85]: location icon should now be in "inactive".

    17/02/16 17:40:21, com.apple.AddressBook.InternetAccountsBridge [510 426]: dnssd_clientstub ConnectToServer: connect()-> tent No.: 3

    17/02/16 17:40:21, 662 mds [64]: (DiskStore.Error:1417) file dev:16777228 unexpected storeDev:16777224 mode: 41ff Tip: 1294302 oid:1294302 ino:2 fsEvents:0 / / Volumes-Lexar/Volumes/Lexar

    17/02/16 17:40:21, 662 mds [64]: (DiskStore.Error:1417) file unexpected dev:16777226 storeDev:16777224 mode: 41ff Tip: 1294301 oid:1294301 ino:2 fsEvents:0 / Volumes/USB20FD/Volumes/USB20FD.

    17/02/16 17:40:21, 679 mds [64]: (DiskStore.Error:1417) file dev:754974722 unexpected storeDev:16777224 mode: 416 d Tip: 424484 oid:424484 ino:5 fsEvents:0 / home-/ home

    17/02/16 17:40:21, 679 mds [64]: (DiskStore.Error:1417) file dev:754974721 unexpected storeDev:16777224 mode: 416 d Tip: 424483 oid:424483 ino:3 fsEvents:0 / net-/ net

    17/02/16 17:40:22, com.apple.AddressBook.InternetAccountsBridge [510 518]: dnssd_clientstub ConnectToServer: connect() has no path: / var/run/mDNSResponder Socket: 4 Err:-1 Errno:1 operation not permitted

    17/02/16 17:40:22, com.apple.AddressBook.InternetAccountsBridge [510 525]: dnssd_clientstub ConnectToServer: connect()-> test number: 1

    17/02/16 17:40:22, com.apple.xpc.launchd [1 902]: (com.adobe.ARMDCHelper.cc24aef4a1b90ed56a725c38014c95072f92651fb65e1bf9c8e43c37 a23d420d [397]) Service came out with abnormal code: 111

    17/02/16 17:40:23, com.apple.AddressBook.InternetAccountsBridge [510 616]: dnssd_clientstub ConnectToServer: connect()-> test number: 2

    17/02/16 17:40:23, 871 safari [308]: KeychainGetICDPStatus: key :-25300

    17/02/16 17:40:23, 871 safari [308]: KeychainGetICDPStatus: status: power off

    17/02/16 17:40:24, 391 launchd [1]: BUG in libdispatch: 15 d 21-1631 - 0x0

    17/02/16 17:40:24, 392 networks [177]: BUG in libdispatch: 15 d 21-1631 - 0x0

    17/02/16 17:40:24, 392 configd [54]: BUG in libdispatch: 15 d 21-1631 - 0x0

    17/02/16 17:40:24, 711 com.apple.AddressBook.InternetAccountsBridge [510]: dnssd_clientstub ConnectToServer: connect()-> tent No.: 3

    17/02/16 17:40:25, com.apple.AddressBook.InternetAccountsBridge [510 810]: dnssd_clientstub ConnectToServer: connect() has no path: / var/run/mDNSResponder Socket: 4 Err:-1 Errno:1 operation not permitted

    17/02/16 17:40:29, 416 lsd [298]: LaunchServices: currently 0 installed placeholders:)

    )

    17/02/16 17:40:32, 027 warmd [63]: [_bootcachectl_filter_history_cpdk:1946] Impossible to pin 50623 scopes (1133,12 MB) to cpdk 2D7E6D8B-3BF4-4B7C-A6A3-70A35E72CFC6: 0xe00002c2

    17/02/16 17:40:33, 435 SpotlightNetHelper [367]: tcp_connection_destination_handle_tls_close_notify 2 Jack of closure due to the TLS CLOSE_NOTIFY alert

    17/02/16 17:40:33, 435 SpotlightNetHelper [367]: tcp_connection_tls_session_error_callback 2 __tcp_connection_tls_session_callback_write_block_invoke.434 error 32

    17/02/16 17:40:33, 459 DCs [307]: sync with system failure SOSAccountThisDeviceCanSyncWithCircle: Domain = com.apple.security.sos.error error Code = 1035 "account identity not defined' UserInfo = {NSDescription = identity account not defined}

    17/02/16 17:40:34, 031 SpotlightNetHelper [367]: tcp_connection_tls_session_error_callback 7 __tcp_connection_tls_session_callback_write_block_invoke.434 error 22

    17/02/16 17:40:34, 031 SpotlightNetHelper [367]: tcp_connection_tls_session_error_callback 6 __tcp_connection_tls_session_callback_write_block_invoke.434 error 22

    17/02/16 17:40:34, 031 SpotlightNetHelper [367]: tcp_connection_tls_session_error_callback 5 __tcp_connection_tls_session_callback_write_block_invoke.434 error 22

    17/02/16 17:40:34, 031 SpotlightNetHelper [367]: tcp_connection_tls_session_error_callback 3 __tcp_connection_tls_session_callback_write_block_invoke.434 error 22

    17/02/16 17:40:47, sandboxd 933 [137]: systemsoundserve (269) ([269]) deny/private/var/root file-read-metadata

    17/02/16 17:41:53, 678 safari [308]: KeychainGetICDPStatus: key :-25300

    17/02/16 17:41:53, 678 safari [308]: KeychainGetICDPStatus: status: power off

    17/02/16 17:43:59, 149 disk utility [554]: connected to the demon. Language: English

    17/02/16 17:43:59, 149 disk utility [554]: connected to the demon. Language: English

    17/02/16 17:44:09, 525 console [558]: unable to connect (_consoleX) out of (NSApplication) (ConsoleX): missing setter or instance variable

    17/02/16 17:44:17, 037 safari [308]: KeychainGetICDPStatus: key :-25300

    17/02/16 17:44:17, 037 safari [308]: KeychainGetICDPStatus: status: power off

    17/02/16 17:44:27, syncdefaultsd 220 [559]: accountsd has been removed from the sync of apps.

    17/02/16 17:49:54, 692 safari [308]: tcp_connection_tls_session_error_callback 9 __tcp_connection_tls_session_callback_write_block_invoke.434 error 22

    17/02/16 17:49:54, 000 syslogd [45]: sender ASL statistics

    17/02/16 17:56:55, 521 CalendarAgent [341]: [com.apple.calendar.store.log.caldav.coredav] [refusing to analysis for PROPPATCH response because of the content-type: text/html; charset = UTF-8].]

    17/02/16 17:56:55, CalendarAgent 566 [341]: [com.apple.calendar.store.log.caldav.coredav] [refusing to analysis for PROPPATCH response because of the content-type: text/html; charset = UTF-8].]

    17/02/16 17:56:55, 584 CalendarAgent [341]: [com.apple.calendar.store.log.caldav.coredav] [refusing to analysis for PROPPATCH response because of the content-type: text/html; charset = UTF-8].]

    17/02/16 17:56:55, 670 CalendarAgent [341]: [com.apple.calendar.store.log.caldav.coredav] [refusing to analysis for PROPPATCH response because of the content-type: text/html; charset = UTF-8].]

    17/02/16 17:56:55, 694 CalendarAgent [341]: [com.apple.calendar.store.log.caldav.coredav] [refusing to analysis for PROPPATCH response because of the content-type: text/html; charset = UTF-8].]

    17/02/16 17:56:55, CalendarAgent 742 [341]: [com.apple.calendar.store.log.caldav.coredav] [refusing to analysis for PROPPATCH response because of the content-type: text/html; charset = UTF-8].]

    17/02/16 18:00:16, 000 illegal product [0]: BOOT_TIME 1455750016 0

    17/02/16 18:00:18, 000 syslogd [45]: notice of Configuration:

    ASL Module 'com.apple.AccountPolicyHelper' claims the selected messages.

    These messages may not appear in the standard system log files or in the database of the ASL.

    Thanks for your help,

    Marco

    These must be run as administrator. If you have only one user account, you are the administrator.

    Please launch the Console application in one of the following ways:

    ☞ Enter the first letters of his name in a Spotlight search. Select from the results (it should be at the top).

    ☞ In the Finder, select go utilities ▹ of menu bar or press the combination of keys shift-command-U. The application is in the folder that opens.

    ☞ Open LaunchPad and start typing the name.

    In the Console window, select

    DIAGNOSIS AND diagnostic USE information reports ▹ System

    (not diagnose them and use Messages) in the list of logs on the left. If you don't see this list, select

    List of newspapers seen ▹ display

    in the menu bar.

    There is a disclosure triangle to the left of the list item. If the triangle is pointing to the right, click it so that it points downwards. You will see a list of reports. A report of panic has a name that begins with "Kernel" and ends with ".panic." Select the most recent. The content of the report is displayed at right. Allows you to copy and paste to validate all of the content, text, not a screenshot.

    If you don't see any report, but you know, there was a panic, you have chosen diagnostic and using the list of Log Messages. INFORMATION on the USE of DIAGNOSTIC AND choose instead.

    In the interest of privacy, I suggest that, before posting, you change the UUID ' anonymous, ' a long string of letters, numbers and dashes in the header of the report, if it is present (it cannot be). "

    Please do not post other types of diagnostic report.

    I know that the report is long, perhaps several hundred lines. Please report all this anyway.

    When you post the report, an error message may appear on the web page: "you have included content in your post that is not allowed", or "the message contains invalid characters." It's a bug in the forum software. Thanks for posting the text on Pastebin, then post here a link to the page you created.

    If you have an account on Pastebin, please do not select private in exposure menu to paste on the page, because no one else that you will be able to see it.

  • Is there a way to divide such ads and Add ons in a screen and automatically display search results in the other

    Original title: twomonitorsononepc

    I have two monitors on my pc is there any way for example divide ads and Add ons in a screen and automatically display search results in the other.

    or if facebook were used cat into one screen and status on the other screen please

    Hi Richard,

    What is the operating system installed on the computer?

    It seems that you need to divide the same application in several windows and place them in different monitors. Is this correct?

    Unfortunately, it is normal and you can not split the same application on two different monitors.

    Hope this information helps. Get back to us if you have more queries about Windows.

  • Let the "cliché" on the road and automatic

    Original title: another Q

    Had trouble with backup initially. Was told to go to "volume shadow copy" and turn it to automatic and started.

    It worked, but I wonder to leave the "cliché" on road and automatic?

    Thank you

    Hello

    Thanks for posting the question in the Microsoft Community!

    Windows operating system you are using?

    I suggest that you keep the Volume Shadow Copy service started and the type set to automatic startup. The Volume Shadow Copy Service provides the infrastructure of backup for Microsoft Windows operating systems.

    If you have additional questions on the computer, please ask your question about Windows and we will be happy to help you.

    Thank you.

  • Change the partition where to downloads and automatic updates

    My C partition is the main boot partition and it is full. 29G all exhausted. I copied the files of many program and pasted in the partition with 188 free G D. But it doesn't allow me to delete the original file from C to free up space. How do I do that? It says destination refused. Also, how can I change the partition of C to D that take downloads and automatic updates? I'm tired of this constant problem and I tried everything, including disk management to solve the problem. I'd appreciate a solution! Thank you

    Windows Vista Help: Strategies to free disk space:
    http://Windows.Microsoft.com/en-us/Windows-Vista/strategies-for-freeing-disk-space ~ Robear Dyer (PA Bear) ~ MS MVP (that is to say, mail, security, Windows & Update Services) since 2002 ~ WARNING: MS MVPs represent or work for Microsoft

  • How can I omit logon and automatically go directly on my desk?

    original title: logon...

    How can I omit logon and automatically go directly on my desk?

    Hello

    How to automatically connect at startup in Vista
    http://www.Vistax64.com/tutorials/66966-logon-automatically.html
     
    Or reverse the order:

    How to make Vista require a user name and password when connecting
    http://www.Vistax64.com/tutorials/89812-logon-username-password.html

    I hope this helps.

    Rob Brown - MS MVP - Windows Desktop Experience: Bike - Mark Twain said it right.

  • Windows 7 slow shutdown and automatic restart

    My Windows 7 Ultimate Service pack 1 64-bit takes a long time to shutdown and restarts itself. My PC all the hardware and software drivers are updated (iTunes, etc.) are fully updated and has the latest updates for Windows (optional but Important) Installed.When I select shut down, it is the screen of closing and will show 'Shutting Down' with this wheel that runs for a long time, the time and automatically restarts without BSOD or Errors.My PC configuration-i5 2500K Stock , 8 GB at 1333 MHz Ram, Intel DH67CL Mobo, Samsung SSD 840 120 GB SSD (with Windows 7 Ultimate SP1 and Windows XP Pro SP2 64 Bit time and installed in IDE Mode) 500 GB Seagate HDD, Zebronics PSU, LG DVD Writer.I currently had not tried all fixes. Please help me and thanks

    Hi Bilodeau,

    You did changes to the computer before the show?

    If your computer seems to close slowly (or not at all) starts slowly, or if it is not energy saving modes, it is possible that a program or device driver is interfering with Windows power settings.

    Method 1: I suggest you try the steps from the following link:

    Why my computer won't turn on or off quickly?
    http://Windows.Microsoft.com/en-CA/Windows/computer-wont-turn-on-off-quickly#1TC=Windows-7

    Method 2: I'll help you with this problem. I suggest you follow the steps in the article.

    Optimize Windows 7 for better performance

    Slow PC? Optimize your computer for peak performance

    Note: If bad sectors are found in the hard drive, then it could try to fix this particular sector. If you have any data on that, it can get lost.

    Note: The data files that are infected must be cleaned only by removing the file completely, which means that there is a risk of data loss.

    I hope this helps. Let us know if you need help with Windows related issues. We will be happy to help you.

  • minimize the browser and automatically adjust the text

    Hello

    How can I reduce the browser and automatically adjust the text in Adobe Muse?

    I want to get the same effect as on this page:

    http://Bienz-photography.ch/

    on the departure site, there is the "Welcome" text and if I reduce the browser the text adjusts automatically.

    How can I do?

    Thanks for your help.

    What you re looking is delicate design which is not yet supported by Muse.

  • How to change a solid without scale (height and width)

    How to change a solid without scale (height and width)

    Thank you!

    Select the solid and press Ctrl + Shift + Y (or CMD + SHIFT + Y on a Mac) or go to layer > solid settings

  • The latest changes to the 'Upload to the FTP host' function has made it useless - no point using a program such as Muse if I can't easily and automatically upload work to the Web server.

    The latest changes to the "Upload to Host FTP" function made it useless - no point using a program such as Muse if I can't easily and automatically upload work to the Web server.  I use BlueHost webhosting with a main area and I have several domains with this account (such as subdomains or folders on this server) - with older versions of Muse when downloading pages it simply opened a warning window to tell me (what I already know) the Web site I am downloading does not point to the main domain BUT now Muse is trying to create a new folder separated into the root directory of the main domain. completely ignoring the directory path that I am giving him - useless!  Why do these crazy changes to the program - and so often - it is very frustrating as amateur ware!

    Hello Stephen,

    There are some problems with the download of ftp through Muse, who knows the team of engineers and those will be corrected in a future version of Muse. At this point, the work around would be to export the html code of Muse and then download via some third party client like filezilla ftp.

    I would recommend that you keep an eye on our page of release notes to get updates more about it - Release notes | Adobe Muse CC

    - Abhishek Maurya

  • Save and automatically PUT the files

    Hello

    I think that I have disabled the function by which I can save a file and automatically PUT it the file to my Web site.

    Now, I can not enable this feature.  Can you tell me where it is?

    In CS4, it's in the area of the SITE to manage. Now, I think he moved to a location in the Preferences dialog box, but I can't seem to find it.

    Thank you.

    Jane

    In CS5, it's under the button advanced remote server.

  • How to put a box to scale proportionally?

    Is it possible to fix the box aspect ratio (width to height) so that it evolves in proportion (such as images)? Thanks in advance!

    The answer is somehow. Do you if you a padding top or bottom padding something like 20% and adjust the height of the automatic. Then the box will scale porpotinally. This works very well if you want just the div to have a background image or color. However, if you put something inside the box, then you should do some more laps for things inside because the padding fills the space they would sit.

    Here are the two parameters, you can play with and see if it fits your needs:

    Hope that helps and thanks for using the Reflow!

    Chris

  • Reduce consumption of battery motion and automatic brightness

    Hi, I would like to know some things.

    First: activation reduce motion put on iPhone save the battery life since perspective wallpapers are being turned off when the low power Mode is on?

    Second: Automatic Rotation of the brightness to the wide and holding the brightness at Midway to consume less energy than to have automatic brightness, allowing the iPhone to constantly check our environment and adjust the brightness?

    Thank you!

    To the first question, while I can't tell you with certainty, yes reducing motion should keep a battery life.

    To the second question, it depends. If automatic brightness is to keep the phone on a higher setting to half way then it would be. If A - B fits between a minimum and a high level, then probably not. I keep A - B on all the time and I have no problem with the battery life, but if I'm outside it would be a trade off between being able to read the screen and save battery.

Maybe you are looking for

  • Helps to remove the profile of someone else to my gmail login window.

    Someone else uses my computer to connect to their account gmail long ago. Now, whenever I want to access my gmail account, their profile appears. I can not connect to delete, and it's annoying because I always wonder to connect to their e-mail first.

  • iPad Pro 9.7 random reboot

    Normally don't think much this, but, I have an iPad 2 day old Pro 9.7 the GB 128 who has restart on me twice so far. In the middle of using it, it will cut the Apple logo on black background for a minute before returning to the password screen. Curio

  • Satellite A60-302: built in DVD - RW?

    Dear Toshiba I'm Maria of the Hungary. I brought a computer Toshiba laptop Satellite A60-302, because I wanted something to burn and read CD and DVD. In my view, that can read DVDs and CDs and burn CDs. I wish that mobile knowledge really cannot burn

  • memory card reader does not

    Compaq Presaro CQ3000 model series CQ3420AN memory card reader does not read SD cards. Where can I find download original driver.

  • Share button in the Finder, Safari and also does not

    I have been using the release of El Capitan for a while now, but recently the 'Action' button in the Finder, Safari and other applications when you press to share for example at the post office, leads the application unresponsive, ends up having to b