取消布局管理器中的滚动

发布于 2024-08-03 17:00:32 字数 241 浏览 3 评论 0原文

我找不到以下问题的解决方案。我有自定义列表字段,它与布局管理器的边界重叠。列表字段使用来自管理器的导航事件,以使用特殊颜色突出显示当前选定的行。布局管理器配置为支持滚动。当我向下滚动拨轮时,布局管理器会调用滚动,然后将导航事件传递给其子项(列表字段)。它会导致不正确的滚动,因为管理器将整个列表向下滚动到其底部,隐藏顶部的列表行,包括所选行。

我想要的是在当前选定的列表行仍然可见时忽略滚动,否则使用它。

我正在使用 JDE 4.2.1

I can't find solution for the following problem. I have custom list field, which overlaps the boundaries of its layout manager. List field consumes navigation events from manager to highlight currently selected row with special color. Layout manager is configured to support scrolling. When I scroll trackwheel down, layout manager invokes scrolling and then passes navigation event to its child, the list field. It results in inproper scrolling, because manager scrolls the whole list down to its bottom hiding list rows on the top including the selected row.

What I want is to ignore scrolling while currently selected list row is still visible and employ it otherwise.

I'm using JDE 4.2.1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨曦÷微暖 2024-08-10 17:00:32

假设我们有 ListField 实现:

    class LabelListField extends ListField implements ListFieldCallback {
 private Vector mValues;

 public LabelListField(Vector values) {
  super(0);
  setRowHeight(getFont().getHeight() + 10);
  setCallback(this);
  mValues = values;
  setSize(mValues.size());
 }

 public void drawListRow(ListField listField, Graphics g, int index, int y,
   int width) {
  g.drawText((String) mValues.elementAt(index), 0, y);
 }

 public Object get(ListField list, int index) {
  return mValues.elementAt(index);
 }

 public int indexOfList(ListField list, String prefix, int start) {
  for (int x = start; x < mValues.size(); ++x) {
   String value = (String) mValues.elementAt(x);
   if (value.startsWith(prefix)) {
    return x;
   }
  }
  return -1;
 }

 public int getPreferredWidth(ListField list) {
  return Display.getWidth();
 }
}

如果我们想以这种方式在上下字段中对齐此列表:
带滚动的ListField http://img6.imageshack.us/img6/7025/8800j.png
我们可以使用自定义管理器限制它的高度:

class ListManager extends HorizontalFieldManager {
 ListField mListField;

 public ListManager(ListField listField) {
  super(VERTICAL_SCROLL | VERTICAL_SCROLLBAR);
  mListField = listField;
  add(mListField);
 }

 public int getPreferredHeight() {
  int result = Display.getHeight();
  Manager manager = getManager();
  if (null != manager) {
   for (int i = 0, count = manager.getFieldCount(); i < count; i++) {
    if (manager.getField(i) != this)
     result -= manager.getField(i).getPreferredHeight();
   }
  }

  // size down to fit max rows without splitting
  result = result - result % mListField.getRowHeight();
  return result;
 }

 protected void sublayout(int maxWidth, int maxHeight) {
  super.sublayout(maxWidth, maxHeight);
  setExtent(maxWidth, getPreferredHeight());
 }
}

现在我们可以使用它:

class Scr extends FullScreen implements FieldChangeListener {
 LabelField mHeader;
 ListManager mHFMList;
 HorizontalFieldManager mHFMButton;
 LabelListField mListField;
 ButtonField mButton;

 public Scr() {
  super(DEFAULT_MENU | DEFAULT_CLOSE);

  mHeader = new LabelField("List Field", FIELD_HCENTER);
  add(mHeader);

  Vector values = new Vector();
  values.addElement("first");
  values.addElement("second");
  values.addElement("third");
  values.addElement("fourth");
  values.addElement("fifth");
  values.addElement("sixth");
  values.addElement("seventh");
  values.addElement("eight");
  mListField = new LabelListField(values);

  mHFMList = new ListManager(mListField);
  add(mHFMList);

  mHFMButton = new HorizontalFieldManager(FIELD_HCENTER);
  add(mHFMButton);

  mButton = new ButtonField("Exit", ButtonField.CONSUME_CLICK);
  mButton.setChangeListener(this);
  mHFMButton.add(mButton);
 }

 public void fieldChanged(Field field, int context) {
  if (mButton == field)
   close();
 }
}

在 eJDE 4.2.1.17 8800 上测试

Let's say we have ListField implementation:

    class LabelListField extends ListField implements ListFieldCallback {
 private Vector mValues;

 public LabelListField(Vector values) {
  super(0);
  setRowHeight(getFont().getHeight() + 10);
  setCallback(this);
  mValues = values;
  setSize(mValues.size());
 }

 public void drawListRow(ListField listField, Graphics g, int index, int y,
   int width) {
  g.drawText((String) mValues.elementAt(index), 0, y);
 }

 public Object get(ListField list, int index) {
  return mValues.elementAt(index);
 }

 public int indexOfList(ListField list, String prefix, int start) {
  for (int x = start; x < mValues.size(); ++x) {
   String value = (String) mValues.elementAt(x);
   if (value.startsWith(prefix)) {
    return x;
   }
  }
  return -1;
 }

 public int getPreferredWidth(ListField list) {
  return Display.getWidth();
 }
}

If we want to align this list within upper and lower fields this way:
ListField with scroll http://img6.imageshack.us/img6/7025/8800j.png
we can limit it's height using custom manager:

class ListManager extends HorizontalFieldManager {
 ListField mListField;

 public ListManager(ListField listField) {
  super(VERTICAL_SCROLL | VERTICAL_SCROLLBAR);
  mListField = listField;
  add(mListField);
 }

 public int getPreferredHeight() {
  int result = Display.getHeight();
  Manager manager = getManager();
  if (null != manager) {
   for (int i = 0, count = manager.getFieldCount(); i < count; i++) {
    if (manager.getField(i) != this)
     result -= manager.getField(i).getPreferredHeight();
   }
  }

  // size down to fit max rows without splitting
  result = result - result % mListField.getRowHeight();
  return result;
 }

 protected void sublayout(int maxWidth, int maxHeight) {
  super.sublayout(maxWidth, maxHeight);
  setExtent(maxWidth, getPreferredHeight());
 }
}

Now we can use it:

class Scr extends FullScreen implements FieldChangeListener {
 LabelField mHeader;
 ListManager mHFMList;
 HorizontalFieldManager mHFMButton;
 LabelListField mListField;
 ButtonField mButton;

 public Scr() {
  super(DEFAULT_MENU | DEFAULT_CLOSE);

  mHeader = new LabelField("List Field", FIELD_HCENTER);
  add(mHeader);

  Vector values = new Vector();
  values.addElement("first");
  values.addElement("second");
  values.addElement("third");
  values.addElement("fourth");
  values.addElement("fifth");
  values.addElement("sixth");
  values.addElement("seventh");
  values.addElement("eight");
  mListField = new LabelListField(values);

  mHFMList = new ListManager(mListField);
  add(mHFMList);

  mHFMButton = new HorizontalFieldManager(FIELD_HCENTER);
  add(mHFMButton);

  mButton = new ButtonField("Exit", ButtonField.CONSUME_CLICK);
  mButton.setChangeListener(this);
  mHFMButton.add(mButton);
 }

 public void fieldChanged(Field field, int context) {
  if (mButton == field)
   close();
 }
}

Tested on eJDE 4.2.1.17 8800

自由如风 2024-08-10 17:00:32

这就是对我有帮助的解决方案。通过以这种特定方式覆盖 moveFocus,我设法修改布局管理器中滚动的默认行为 - 它跳过列表字段的第一项,使它们保持在顶部。

public int moveFocus(int amount, int status, int time) {
    invalidate(getSelectedIndex());

    int unused = super.moveFocus(amount, status, time);
    return Math.abs(unused) + 1;
}

all here's the solution that helped me. By overriding moveFocus in such specific way I managed to modify default behavior of scrolling in layout manager - it skips first items of list field allowing them to stay on top.

public int moveFocus(int amount, int status, int time) {
    invalidate(getSelectedIndex());

    int unused = super.moveFocus(amount, status, time);
    return Math.abs(unused) + 1;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文