Uses the keyword key to retrieve a location from the preferences file. Returns null if the key is not found or the location is not valid (e.g., offscreen).
(String key)
| 696 | from the preferences file. Returns null if the |
| 697 | key is not found or the location is not valid (e.g., offscreen). */ |
| 698 | public static Point getLocation(String key) { |
| 699 | String value = ijPrefs.getProperty(KEY_PREFIX+key); |
| 700 | if (value==null) return null; |
| 701 | int index = value.indexOf(","); |
| 702 | if (index==-1) return null; |
| 703 | double xloc = Tools.parseDouble(value.substring(0, index)); |
| 704 | if (Double.isNaN(xloc) || index==value.length()-1) return null; |
| 705 | double yloc = Tools.parseDouble(value.substring(index+1)); |
| 706 | if (Double.isNaN(yloc)) return null; |
| 707 | Point p = new Point((int)xloc, (int)yloc); |
| 708 | Rectangle bounds = GUI.getScreenBounds(p); // get bounds of screen that contains p |
| 709 | if (bounds!=null && p.x+100<=bounds.x+bounds.width && p.y+ 40<=bounds.y+bounds.height) { |
| 710 | if (locKeys.get(key)==null) { // first time for this key? |
| 711 | locKeys.setProperty(key, ""); |
| 712 | Rectangle primaryScreen = GUI.getMaxWindowBounds(); |
| 713 | ImageJ ij = IJ.getInstance(); |
| 714 | Point ijLoc = ij!=null?ij.getLocation():null; |
| 715 | //System.out.println("getLoc: "+key+" "+(ijLoc!=null&&primaryScreen.contains(ijLoc)) + " "+!primaryScreen.contains(p)); |
| 716 | if ((ijLoc!=null&&primaryScreen.contains(ijLoc)) && !primaryScreen.contains(p)) |
| 717 | return null; // return null if "ImageJ" window on primary screen and this location is not |
| 718 | } |
| 719 | return p; |
| 720 | } else |
| 721 | return null; |
| 722 | } |
| 723 | |
| 724 | @AstroImageJ(reason = "Check if location is on the screen") |
| 725 | public static boolean isLocationOnScreen(Point loc) { |
no test coverage detected