首页 \ 问答 \ 以编程方式将SWT按钮设置为按下状态?(Setting the SWT Button to pressed state programmatically?)

以编程方式将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
更新时间:2023-02-22 12:02

最满意答案

我需要和你一样的东西,并遇到你没有答案的问题。 这是我写的代码(从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);
});

相关问答

更多
  • 工作解决方案是修改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 ...
  • 除非设置tabindex属性,否则无法对div元素进行聚焦(如果我没有错,则可以使用此属性聚焦任何元素)。 焦点动作通常用于表单/文本元素。 我做了一个工作的例子(见jsFiddle ): window.onload = function(){ var map = new google.maps.Map(document.getElementById('map'), { center: new google.maps.LatLng(22.669, 77.709), ...
  • 您基本上必须维护标记的关联数组。 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]. ...
  • 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 ...
  • 对于用户体验,您不应该在地图上添加太多标记,但有很多方法可以向地图添加大量标记,例如 基于网格的聚类 基于距离的聚类 视口标记管理 融合表 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 ...
  • 您的问题是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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)