Changeset 11197 in josm for trunk/src/org
- Timestamp:
- 2016-10-30T22:21:00+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java
r11167 r11197 127 127 private static final Font InfoFont = new Font("sansserif", Font.BOLD, 13); 128 128 129 /** additional layer menu actions */ 130 private static List<MenuAddition> menuAdditions = new LinkedList<>(); 131 129 132 /** minimum zoom level to show to user */ 130 133 public static final IntegerProperty PROP_MIN_ZOOM_LVL = new IntegerProperty(PREFERENCE_PREFIX + ".min_zoom_lvl", 2); … … 1764 1767 } 1765 1768 1769 /** 1770 * Class to store a menu action and the class it belongs to. 1771 */ 1772 private static class MenuAddition { 1773 final Action addition; 1774 @SuppressWarnings("rawtypes") 1775 final Class<? extends AbstractTileSourceLayer> clazz; 1776 1777 @SuppressWarnings("rawtypes") 1778 MenuAddition(Action addition, Class<? extends AbstractTileSourceLayer> clazz) { 1779 this.addition = addition; 1780 this.clazz = clazz; 1781 } 1782 } 1783 1784 /** 1785 * Register an additional layer context menu entry. 1786 * 1787 * @param addition additional menu action 1788 * @since 11197 1789 */ 1790 public static void registerMenuAddition(Action addition) { 1791 menuAdditions.add(new MenuAddition(addition, AbstractTileSourceLayer.class)); 1792 } 1793 1794 /** 1795 * Register an additional layer context menu entry for a imagery layer 1796 * class. The menu entry is valid for the specified class and subclasses 1797 * thereof only. 1798 * <p> 1799 * Example: 1800 * <pre> 1801 * TMSLayer.registerMenuAddition(new TMSSpecificAction(), TMSLayer.class); 1802 * </pre> 1803 * 1804 * @param addition additional menu action 1805 * @param clazz class the menu action is registered for 1806 * @since 11197 1807 */ 1808 public static void registerMenuAddition(Action addition, 1809 Class<? extends AbstractTileSourceLayer<?>> clazz) { 1810 menuAdditions.add(new MenuAddition(addition, clazz)); 1811 } 1812 1813 /** 1814 * Prepare list of additional layer context menu entries. The list is 1815 * empty if there are no additional menu entries. 1816 * 1817 * @return list of additional layer context menu entries 1818 */ 1819 private List<Action> getMenuAdditions() { 1820 final LinkedList<Action> menuAdds = new LinkedList<>(); 1821 for (MenuAddition menuAdd: menuAdditions) { 1822 if (menuAdd.clazz.isInstance(this)) { 1823 menuAdds.add(menuAdd.addition); 1824 } 1825 } 1826 if (!menuAdds.isEmpty()) { 1827 menuAdds.addFirst(SeparatorLayerAction.INSTANCE); 1828 } 1829 return menuAdds; 1830 } 1831 1766 1832 @Override 1767 1833 public Action[] getMenuEntries() { … … 1769 1835 actions.addAll(Arrays.asList(getLayerListEntries())); 1770 1836 actions.addAll(Arrays.asList(getCommonEntries())); 1837 actions.addAll(getMenuAdditions()); 1771 1838 actions.add(SeparatorLayerAction.INSTANCE); 1772 1839 actions.add(new LayerListPopup.InfoAction(this));
Note:
See TracChangeset
for help on using the changeset viewer.