以编程方式将SWT按钮设置为按下状态?(Setting the SWT Button to pressed state programmatically?)
我试图以编程方式将SWT按钮设置为“按下”状态。 这有可能吗?
更新:
我想要实现的是 - 渲染将一个按钮在其选定状态下绘制到一个图像上。Image buttonimg_mouseover = new Image(getDisplay(), 100, 100); Button button = new Button(parent.parent, SWT.PUSH); button.setAlignment(SWT.CENTER); button.setImage(arrowimg); button.setSize(100, 100); button.setSelection(true); // doesn't work GC gcbutton = new GC(buttonimg_mouseover); //draw an image of the button button.print(gcbutton);
I am trying to set a SWT Button into a "pressed" state programmatically. Is that possible somehow?
Update:
What I am trying to achieve - is render draw a Button in it's selected state onto an Image.Image buttonimg_mouseover = new Image(getDisplay(), 100, 100); Button button = new Button(parent.parent, SWT.PUSH); button.setAlignment(SWT.CENTER); button.setImage(arrowimg); button.setSize(100, 100); button.setSelection(true); // doesn't work GC gcbutton = new GC(buttonimg_mouseover); //draw an image of the button button.print(gcbutton);
原文:https://stackoverflow.com/questions/13308066
最满意答案
我需要和你一样的东西,并遇到你没有答案的问题。 这是我写的代码(从jVectorMap源复制,粘贴和修改斜线)为我自己解决问题。 我希望你和其他人发现它有帮助。
只需将scale,longitude和latitude传递给setFocusLatLng即可。
我可能试图将这个或类似的东西接受到GitHub上的jVectorMap项目中,所以稍后可能会有更好的方法。
免责声明:地图边缘的点不会居中。 不过,他们应该是这样认为的。
编辑:根据要求,这是jsfiddle上的整个事情: http : //jsfiddle.net/BryanTheScott/rs7H5/
编辑:还添加了下面的JS的其余部分:
$(function(){ var smallMap = $('#my_map_container').vectorMap({ map: 'world_mill_en', zoomOnScroll: true, zoomMax:5, zoomMin:5, regionStyle: { initial: { fill: '#222222', "fill-opacity": 1, stroke: '#444444', "stroke-width": 1, "stroke-opacity": 0.7 }, hover: { "fill-opacity": 0.8, fill: '#333333' } }, markerStyle: { initial: { fill: "#000000", "stroke": "#7FC556", "stroke-width": 2, r: 3 } }, markers: [[37.770172,-122.422771]] }); var mapObj = $('#my_map_container').vectorMap('get', 'mapObject'); mapObj.setFocusLatLng = function(scale, lat, lng){ var point, proj = jvm.WorldMap.maps[this.params.map].projection, centralMeridian = proj.centralMeridian, width = this.width - this.baseTransX * 2 * this.baseScale, height = this.height - this.baseTransY * 2 * this.baseScale, inset, bbox, scaleFactor = this.scale / this.baseScale, centerX, centerY; if (lng < (-180 + centralMeridian)) { lng += 360; } point = jvm.Proj[proj.type](lat, lng, centralMeridian); inset = this.getInsetForPoint(point.x, point.y); if (inset) { bbox = inset.bbox; centerX = (point.x - bbox[0].x) / (bbox[1].x - bbox[0].x); centerY = (point.y - bbox[0].y) / (bbox[1].y - bbox[0].y); this.setFocus(scale, centerX, centerY); } } mapObj.setFocusLatLng(5, 37.770172,-122.422771); });
I needed the same thing as you and came across your unanswered question. This is the code I wrote (slash copied, pasted & modified from jVectorMap source) to solve the problem for myself. I hope you and others find it helpful.
Simply pass the scale, longitude, and latitude to setFocusLatLng.
I may attempt to get this or something similar accepted into the jVectorMap project on GitHub, so there may be a better way to do this later.
Disclaimer: Points on the edge of the map will not be centered. They should be in the view, though.
EDIT: As requested, here is the whole thing on jsfiddle: http://jsfiddle.net/BryanTheScott/rs7H5/
EDIT: Also added the rest of the JS below:
$(function(){ var smallMap = $('#my_map_container').vectorMap({ map: 'world_mill_en', zoomOnScroll: true, zoomMax:5, zoomMin:5, regionStyle: { initial: { fill: '#222222', "fill-opacity": 1, stroke: '#444444', "stroke-width": 1, "stroke-opacity": 0.7 }, hover: { "fill-opacity": 0.8, fill: '#333333' } }, markerStyle: { initial: { fill: "#000000", "stroke": "#7FC556", "stroke-width": 2, r: 3 } }, markers: [[37.770172,-122.422771]] }); var mapObj = $('#my_map_container').vectorMap('get', 'mapObject'); mapObj.setFocusLatLng = function(scale, lat, lng){ var point, proj = jvm.WorldMap.maps[this.params.map].projection, centralMeridian = proj.centralMeridian, width = this.width - this.baseTransX * 2 * this.baseScale, height = this.height - this.baseTransY * 2 * this.baseScale, inset, bbox, scaleFactor = this.scale / this.baseScale, centerX, centerY; if (lng < (-180 + centralMeridian)) { lng += 360; } point = jvm.Proj[proj.type](lat, lng, centralMeridian); inset = this.getInsetForPoint(point.x, point.y); if (inset) { bbox = inset.bbox; centerX = (point.x - bbox[0].x) / (bbox[1].x - bbox[0].x); centerY = (point.y - bbox[0].y) / (bbox[1].y - bbox[0].y); this.setFocus(scale, centerX, centerY); } } mapObj.setFocusLatLng(5, 37.770172,-122.422771); });
相关问答
更多-
ACF MAP - 将标记放置在地图的左侧,而不是中央(ACF MAP - Put a marker to the left side of the map, not center)[2023-05-15]
工作解决方案是修改center_map()函数: function center_map( map ) { // vars var bounds = new google.maps.LatLngBounds(); // loop through all markers and create bounds $.each( map.markers, function( i, marker ){ var latlng = new google.maps.LatLng( marke ... -
在标记鼠标悬停上将焦点设置在谷歌地图的InfoWindow上(Set focus on google map's InfoWindow on marker mouseover)[2022-05-07]
除非设置tabindex属性,否则无法对div元素进行聚焦(如果我没有错,则可以使用此属性聚焦任何元素)。 焦点动作通常用于表单/文本元素。 我做了一个工作的例子(见jsFiddle ): window.onload = function(){ var map = new google.maps.Map(document.getElementById('map'), { center: new google.maps.LatLng(22.669, 77.709), ... -
点击地图外的链接时如何获得焦点来映射标记?(How to get focus to map marker when click on a link outside the map?)[2022-08-25]
您基本上必须维护标记的关联数组。 Paris // javascript var markers = {}; markers["paris"] = L.marker([48.85749, 2.35107]).addTo(mymap) .bindPopup("Hello world!
I am Paris."); function focusOn(city) { markers[city]. ... -
jVector - 意大利地区(jVector - Italian regions)[2023-11-06]
jVectorMap遵循iso-3166标准。 要设置意大利语区域的值,您需要使用此处描述的代码。 jVectorMap follows iso-3166 standard. To set values for italian regions you need to use codes described here. -
它差不多3个星期仍然没有回应。 幸运的是,这解释了蜜网地图的工作原理。 https://github.com/fw42/honeymap经过大量阅读后在谷歌地图中实现相同。 http://jsbin.com/ivedix/2/edit Its almost 3 weeks and still no response. Luckily got this which explains the working of honeynet map. https://github.com/fw42/honeymap Af ...
-
我需要和你一样的东西,并遇到你没有答案的问题。 这是我写的代码(从jVectorMap源复制,粘贴和修改斜线)为我自己解决问题。 我希望你和其他人发现它有帮助。 只需将scale,longitude和latitude传递给setFocusLatLng即可。 我可能试图将这个或类似的东西接受到GitHub上的jVectorMap项目中,所以稍后可能会有更好的方法。 免责声明:地图边缘的点不会居中。 不过,他们应该是这样认为的。 编辑:根据要求,这是jsfiddle上的整个事情: http : //jsfidd ...
-
谷歌地图最大标记(Google Map Maximum Marker)[2022-07-26]
对于用户体验,您不应该在地图上添加太多标记,但有很多方法可以向地图添加大量标记,例如 基于网格的聚类 基于距离的聚类 视口标记管理 融合表 MarkerClusterer MarkerManager 在这 ! 是一个如何在谷歌地图中实现标记群集的示例 您可以通过访问此链接选择其他方式 for user experience, you should not add too many markers on the map, but there are many ways to add a huge number ... -
你可以直接使用L.marker这里这里是lat和long的对象,map是你的地图持有者 L.marker(place, { draggable: true, title: "my point", alt: "my point", riseOnHover: true }).addTo(map) 请参阅http://jsfiddle.net/LnzN2/582/进行演示 You can direc ...
-
谢谢你,MKer,扩展课程。 下面,这是我在地图上显示文字的实现。 希望这有助于其他人。 public class MarkerWithLabel extends Marker { Paint textPaint = null; String mLabel = null; public MarkerWithLabel(MapView mapView, String label) { super( mapView); mLabel = label; textPaint = ne ...
-
Angular谷歌地图标记(Angular google map marker)[2021-10-07]
您的问题是ui-gmap-marker coords属性是对map.center的引用,每当您移动地图时都会更改。 您将希望为标记拥有自己的控制器变量,因此它具有自己的位置属性。 像这样的东西, 控制器: // Map initialization $scope.map = { center: { latitude: 32.0889, longitude: 34.8357 }, zoom: 16}; // Give the marker its own scope variable, you can at ...