黑莓手机 - 与FieldManagers乐趣 [英] BlackBerry - Fun with FieldManagers

查看:144
本文介绍了黑莓手机 - 与FieldManagers乐趣的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个视图类,这取决于它是如何创建提供了一个水平或垂直布局。我使用的委托实现这一目标。

I am trying to make a View class that provides a Horizontal or Vertical layout depending on how it is created. I'm using a delegate to achieve this.

class View extends Manager {
    private Manager mDelegate;

    public View(Manager inDelegate) {
        mDelegate = inDelegate;
        // the delegate is the only child of "this" manager.
        super.add(mDelegate);
    }

    public void add(Field f) {
        // all other children go into the delegate.    
        mDelegate.add(f);
    }

    // other methods that also delegate

}

当我创建一个视图对象我通过在水平或垂直领域的经理,然后委托给来电。这是有点Screen类在做什么黑莓

When I instantiate a View object I pass in a Horizontal or Vertical field manager and then delegate calls to that. This is kinda what the Screen class does in blackberry.

其实我在看黑莓文档的屏幕上看到什么叫其委托(这样我就可以模仿)和我注意到像这样视屏通话...

Actually I am looking at the blackberry docs for Screen to see what calls it delegates (so I can emulate that) and I notice calls like this in Screen...

保护布尔keyChar(字符C,INT的地位,诠释时间)

protected boolean keyChar(char c, int status, int time)

代表密钥生成事件,重点控制领域。
  这种方法在此屏幕上的委托管理器调用Manager.keyChar(CHAR,INT,INT)。

Delegates key generation event to the controlled field with focus. This method invokes Manager.keyChar(char, int, int) on this screen's delegate manager.

于是立刻照在我,怎么在世界上,他们呼吁在屏幕的委托一个受保护的方法是什么?或者是文档错误的,这种方法没有下放?

So then it immediately dawns on me, how in the world are they calling a protected method on the screen's delegate? Or are the docs wrong and this method isn't delegated?

任何人都知道他们是如何做到这一点?

Anyone know how they accomplish this?

推荐答案

我设法与帮助,从其他SO问题制定出一个解决这个问题。

I managed to work out a solution to this problem with help from some other SO questions.

我的解决方案是创建一个提供公共接入点的保护方法的接口,然后继承经理类,并在该接口混用。那么公众方法将调用其超强的保护方法。

My solution is to create an interface that provides the public access points for the protected methods and then subclass the Manager class and mix in that interface. The public method will then call its super's protected method.

然后在视图类,然后通过这些管理的一个子类。

Then the View class is then passed one of these Manager subclasses.

public interface ManagerDelegate {
    Manager asManager();
    // Provide public access points to any protected methods needed.
    void doProtectedMethod();
}

public HorizontalDelegate extends HorizontalFieldManager implements ManagerDelegate {
    public Manager asManager() {
        return this;
    }
    public void doProtectedMethod() {
        // call the Manager's protected method.
        protectedMethod();
    }
}

public VerticalDelegate extends VerticalFieldManager implements ManagerDelegate {
    public Manager asManager() {
        return this;
    }
    public void doProtectedMethod() {
        // call the Manager's protected method.
        protectedMethod();
    }
}

public class View extends Manager {
    private final ManagerDelegate mDelegate;

    public View(ManagerDelegate inDelegate) {
        mDelegate = inDelegate;
    }

    protected void protectedMethod() {
        // Call into our delegate's public method to access its protected method.
        mDelegate.doProtectedMethod();
    }

    public void publicMethod() {
        // For public delegated methods I can just get the Manager instance from
        // the delegate and call directly.
        mDelegate.asManager().publicMethod();
    }
}

这篇关于黑莓手机 - 与FieldManagers乐趣的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆