public void test_parse_this() throws Exception {
   DockLayoutPanelInfo panel =
       parse(
           "// filler filler filler filler filler",
           "// filler filler filler filler filler",
           "<ui:UiBinder>",
           "  <g:DockLayoutPanel unit='CM'>",
           "    <g:west size='2.0'>",
           "      <g:Button wbp:name='button'/>",
           "    </g:west>",
           "  </g:DockLayoutPanel>",
           "</ui:UiBinder>");
   assertHierarchy(
       "// filler filler filler filler filler",
       "// filler filler filler filler filler",
       "<g:DockLayoutPanel unit='CM'>",
       "  <g:Button wbp:name='button'>");
   refresh();
   // "panel" bounds
   {
     Rectangle bounds = panel.getBounds();
     assertEquals(new Rectangle(0, 0, 450, 300), bounds);
   }
   // "button" bounds
   {
     WidgetInfo button = getObjectByName("button");
     Rectangle bounds = button.getBounds();
     int widthGreatThat =
         Expectations.get(75, new IntValue[] {new IntValue("flanker-windows", 70)});
     assertThat(bounds.width).isGreaterThan(widthGreatThat);
     assertThat(bounds.height).isEqualTo(300);
   }
 }
 /** Test for "Edge" property, contributed to child {@link WidgetInfo}. */
 public void test_propertyEdge() throws Exception {
   DockLayoutPanelInfo panel =
       parse(
           "// filler filler filler filler filler",
           "// filler filler filler filler filler",
           "<ui:UiBinder>",
           "  <g:DockLayoutPanel unit='CM'>",
           "    <g:west size='1.0'>",
           "      <g:Button wbp:name='button'/>",
           "    </g:west>",
           "  </g:DockLayoutPanel>",
           "</ui:UiBinder>");
   refresh();
   WidgetInfo button = getObjectByName("button");
   // prepare "Edge" property
   Property property = button.getPropertyByTitle("Edge");
   assertNotNull(property);
   assertEquals("WEST", getPropertyText(property));
   assertInstanceOf(StringListPropertyEditor.class, property.getEditor());
   // set value
   property.setValue("NORTH");
   assertXML(
       "// filler filler filler filler filler",
       "// filler filler filler filler filler",
       "<ui:UiBinder>",
       "  <g:DockLayoutPanel unit='CM'>",
       "    <g:north size='1.0'>",
       "      <g:Button wbp:name='button'/>",
       "    </g:north>",
       "  </g:DockLayoutPanel>",
       "</ui:UiBinder>");
   assertEquals("NORTH", panel.getEdge(button));
 }
Esempio n. 3
0
 ////////////////////////////////////////////////////////////////////////////
 //
 // Cell property
 //
 ////////////////////////////////////////////////////////////////////////////
 public void test_propertyCell_existingElement() throws Exception {
   parse(
       "// filler filler filler filler filler",
       "<ui:UiBinder>",
       "  <g:HorizontalPanel>",
       "    <g:Cell>",
       "      <g:Button wbp:name='button'/>",
       "    </g:Cell>",
       "  </g:HorizontalPanel>",
       "</ui:UiBinder>");
   refresh();
   WidgetInfo button = getObjectByName("button");
   // get "Cell" property
   {
     Property cellProperty = button.getPropertyByTitle("Cell");
     assertNotNull(cellProperty);
     assertTrue(cellProperty.getCategory().isSystem());
   }
   // "width"
   {
     Property property = PropertyUtils.getByPath(button, "Cell/width");
     // no value initially
     assertFalse(property.isModified());
     assertEquals(Property.UNKNOWN_VALUE, property.getValue());
     // set value
     property.setValue("100px");
     assertXML(
         "// filler filler filler filler filler",
         "<ui:UiBinder>",
         "  <g:HorizontalPanel>",
         "    <g:Cell width='100px'>",
         "      <g:Button wbp:name='button'/>",
         "    </g:Cell>",
         "  </g:HorizontalPanel>",
         "</ui:UiBinder>");
     // has value
     assertTrue(property.isModified());
     assertEquals("100px", property.getValue());
   }
 }
 private static void setSize(WidgetInfo widget, double size) {
   String signature = "setSize(" + WidgetInfo.class.getName() + ",double)";
   ReflectionUtils.invokeMethodEx(widget.getParent(), signature, widget, size);
 }
 private static Double getSize(WidgetInfo widget) {
   String signature = "getSize(" + WidgetInfo.class.getName() + ")";
   return (Double) ReflectionUtils.invokeMethodEx(widget.getParent(), signature, widget);
 }
Esempio n. 6
0
  protected void paint(Graphics g) {
    int w = getWidth();
    int h = getHeight();

    if (_fullRepaintPending) {
      boolean design =
          _state == STATE_CHOOSE_WIDGET
              || _state == STATE_MOVE_WIDGET
              || _state == STATE_RESIZE_WIDGET;
      if (design) g.setColor(0x202060);
      else g.setColor(0);
      g.fillRect(0, 0, w, h);

      // long start = System.currentTimeMillis();
      // paint all widgets
      WidgetInfo.update();
      for (int i = 0; i < _widgets.length; i++) {
        WidgetPosition wp = _widgets[i];
        g.setClip(
            w * wp.col / _ncols,
            h * wp.row / _nrows,
            w * (wp.col + wp.ncols) / _ncols - w * wp.col / _ncols,
            h * (wp.row + wp.nrows) / _nrows - h * wp.row / _nrows);

        if (design) {
          g.setColor(0);
          g.fillRect(g.getClipX(), g.getClipY(), g.getClipWidth(), g.getClipHeight());
        }

        try {
          wp.widget.paint(g, wp.settings);
        } catch (Exception e) {
          Log.error("Widget paint failed! widget=" + wp.widget.getName(), e);
        }
      }
      // Log.info("Widgets repaint: "+(System.currentTimeMillis()-start)+"ms");
      g.setClip(0, 0, getWidth(), getHeight());
      _fullRepaintPending = false;
    }

    if (_state == STATE_WIDGET_MENU
        || _state == STATE_CHOOSE_WIDGET
        || _state == STATE_MOVE_WIDGET
        || _state == STATE_RESIZE_WIDGET) {
      int x1, y1, x2, y2;
      WidgetPosition wp;
      // paint rectangle around all widgets
      for (int i = 0; i < _widgets.length; i++) {
        if (i != _widgetIndex) {
          wp = _widgets[i];
          x1 = wp.col * w / _ncols;
          y1 = wp.row * h / _nrows;
          x2 = (wp.col + wp.ncols) * w / _ncols - 1;
          y2 = (wp.row + wp.nrows) * h / _nrows - 1;
          g.setColor(0x808080);
          g.drawRect(x1, y1, x2 - x1, y2 - y1);
          g.drawRect(x1 - 1, y1 - 1, x2 - x1 + 2, y2 - y1 + 2);
        }
      }

      // paint rectangle around selected widget
      wp = _widgets[_widgetIndex];
      x1 = wp.col * w / _ncols;
      y1 = wp.row * h / _nrows;
      x2 = (wp.col + wp.ncols) * w / _ncols - 1;
      y2 = (wp.row + wp.nrows) * h / _nrows - 1;
      g.setColor(0xff0000);
      g.drawRect(x1, y1, x2 - x1, y2 - y1);
      g.drawRect(x1 - 1, y1 - 1, x2 - x1 + 2, y2 - y1 + 2);

      // paint move/resize icon
      if (_imageMove != null) {
        if (_state == STATE_MOVE_WIDGET)
          g.drawImage(
              _imageMove, (x1 + x2) / 2, (y1 + y2) / 2, Graphics.HCENTER | Graphics.VCENTER);
        else if (_state == STATE_RESIZE_WIDGET)
          g.drawImage(_imageMove, x2, y2, Graphics.HCENTER | Graphics.VCENTER);
      }
    }

    // paint menu
    if (_state == STATE_MAIN_MENU) {
      _mainMenu.paint(g);
    }

    if (_state == STATE_WIDGET_MENU) {
      _widgetMenu.paint(g);
    }

    if (isSoftkeyVisibleState()) {
      g.drawImage(
          _selectedSoftkey == KEY_LEFT ? _imgSoftkeyLeftSel : _imgSoftkeyLeft,
          _softkeysPanelX + _softkeyW / 2,
          _softkeysPanelY + _softkeyH * 3 / 2,
          Graphics.VCENTER | Graphics.HCENTER);
      g.drawImage(
          _selectedSoftkey == KEY_UP ? _imgSoftkeyUpSel : _imgSoftkeyUp,
          _softkeysPanelX + _softkeyW * 3 / 2,
          _softkeysPanelY + _softkeyH / 2,
          Graphics.VCENTER | Graphics.HCENTER);
      g.drawImage(
          _selectedSoftkey == KEY_FIRE ? _imgSoftkeyFireSel : _imgSoftkeyFire,
          _softkeysPanelX + _softkeyW * 3 / 2,
          _softkeysPanelY + _softkeyH * 3 / 2,
          Graphics.VCENTER | Graphics.HCENTER);
      g.drawImage(
          _selectedSoftkey == KEY_DOWN ? _imgSoftkeyDownSel : _imgSoftkeyDown,
          _softkeysPanelX + _softkeyW * 3 / 2,
          _softkeysPanelY + _softkeyH * 5 / 2,
          Graphics.VCENTER | Graphics.HCENTER);
      g.drawImage(
          _selectedSoftkey == KEY_RIGHT ? _imgSoftkeyRightSel : _imgSoftkeyRight,
          _softkeysPanelX + _softkeyW * 5 / 2,
          _softkeysPanelY + _softkeyH * 3 / 2,
          Graphics.VCENTER | Graphics.HCENTER);
    }

    if (_state == STATE_SHOW && _touchHintDisplayTimeout > System.currentTimeMillis()) {
      int s = (w < h ? w : h) / 3;
      g.setColor(0xFF0000);
      g.drawRect(w - s, 0, s - 1, s - 1);
      g.drawRect(w - s + 1, 1, s - 3, s - 3);
      _touchHintMenuPainter.paint(
          g, "MENU", 0, w - s, 0, s, s, Graphics.HCENTER | Graphics.VCENTER);
    }
  }