Пример #1
0
 private void absoluteBehavior(GElement sel, int key) {
   int x = sel.getNiftyElement().getX();
   int y = sel.getNiftyElement().getY();
   if (key == KeyEvent.VK_DOWN) {
     y++;
     sel.addAttribute("y", "" + y);
     sel.lightRefresh();
   } else if (key == KeyEvent.VK_UP) {
     y--;
     sel.addAttribute("y", "" + y);
     sel.lightRefresh();
   } else if (key == KeyEvent.VK_LEFT) {
     x--;
     sel.addAttribute("x", "" + x);
     sel.lightRefresh();
   } else if (key == KeyEvent.VK_RIGHT) {
     x++;
     sel.addAttribute("x", "" + x);
     sel.lightRefresh();
   }
   v.displayRect(x, y, sel.getNiftyElement().getHeight(), sel.getNiftyElement().getWidth());
   this.selected.setRect(
       sel.getNiftyElement().getX(),
       sel.getNiftyElement().getY(),
       sel.getNiftyElement().getWidth(),
       sel.getNiftyElement().getHeight());
 }
Пример #2
0
  private void horizontalBeahvior(GElement sel, int key) {
    VerticalAlign current = null;
    int index = 0;
    try {
      current = VerticalAlign.valueOf(sel.getAttribute("valign"));
      index = current.ordinal();
    } catch (IllegalArgumentException e) {
      current = VerticalAlign.verticalDefault;
      index = 1;
    }

    if (key == KeyEvent.VK_UP && index > 1) {
      index--;
      VerticalAlign newAlign = VerticalAlign.values()[index];
      sel.addAttribute("valign", newAlign.name());
      sel.lightRefresh();
    } else if (key == KeyEvent.VK_DOWN && index < VerticalAlign.values().length) {
      index++;
      VerticalAlign newAlign = VerticalAlign.values()[index];
      sel.addAttribute("valign", newAlign.name());
      sel.lightRefresh();
    } else {
      index = sel.getParent().getNiftyElement().getElements().indexOf(sel.getNiftyElement());
      if (key == KeyEvent.VK_RIGHT
          && ++index < sel.getParent().getNiftyElement().getElements().size()) {

        sel.setIndex(index);
        sel.lightRefresh();
      } else if (key == KeyEvent.VK_LEFT && --index >= 0) {
        sel.setIndex(index);
        sel.lightRefresh();
      }
    }
    v.displayRect(
        sel.getNiftyElement().getX(),
        sel.getNiftyElement().getY(),
        sel.getNiftyElement().getHeight(),
        sel.getNiftyElement().getWidth());
    this.selected.setRect(
        sel.getNiftyElement().getX(),
        sel.getNiftyElement().getY(),
        sel.getNiftyElement().getWidth(),
        sel.getNiftyElement().getHeight());
  }
Пример #3
0
  @Override
  public void mouseDragged(MouseEvent e) {
    if (this.selecting) {
      int to;
      this.dragging = true;
      switch (curDir) {
        case DIR_E:
          to = (int) (e.getX() - this.selected.getMaxX());
          if ((this.selected.width + to) > 0) {
            this.selected.width += to;
            this.gui.getSelected().getNiftyElement().setWidth(selected.width);
            this.gui.getSelected().addAttribute("width", "" + selected.width + "px");
          }
          break;
        case DIR_W:
          to = (int) (this.selected.getMinX() - e.getX());
          if ((this.selected.width + to) > 0) {
            this.selected.x = e.getX();
            this.selected.width += to;
            this.gui.getSelected().addAttribute("width", "" + selected.width + "px");
            if (this.gui.getSelected().getParent().getAttribute("childLayout").equals("absolute")) {
              int x = gui.getSelected().getParent().getNiftyElement().getX();
              this.gui.getSelected().addAttribute("x", "" + (e.getX() - x) + "px");
            }
          }
          break;
        case DIR_S:
          to = (int) (e.getY() - this.selected.getMaxY());
          if ((this.selected.height + to) > 0) {
            this.selected.height += to;

            this.gui.getSelected().getNiftyElement().setHeight(selected.height);
            this.gui.getSelected().addAttribute("height", "" + selected.height + "px");
          }
          break;
        case DIR_SE:
          to = (int) (e.getX() - this.selected.getMaxX());
          int toy = (int) (e.getY() - this.selected.getMaxY());
          if (((this.selected.width + to) > 0) && (this.selected.height + to) > 0) {
            if (e.isControlDown()) this.selected.height += to;
            else this.selected.height += toy;

            this.gui.getSelected().getNiftyElement().setHeight(selected.height);
            this.gui.getSelected().addAttribute("height", "" + selected.height + "px");

            this.selected.width += to;

            this.gui.getSelected().getNiftyElement().setWidth(selected.width);
            this.gui.getSelected().addAttribute("width", "" + selected.width + "px");

            if (e.isControlDown()) {
              Point gtry = new Point((int) selected.getMaxX(), (int) selected.getMaxY());
              //  SwingUtilities.convertPointToScreen(gtry, this);
              // mouseBot.mouseMove(gtry.x,gtry.y);
            }
          }
          break;
        case DIR_N:
          to = (int) (this.selected.getMinY() - e.getY());
          if ((this.selected.height + to) > 0) {
            this.selected.height += to;
            this.selected.y = e.getY();

            this.gui.getSelected().addAttribute("height", "" + selected.height + "px");
            if (this.gui.getSelected().getParent().getAttribute("childLayout").equals("absolute")) {
              int y = gui.getSelected().getParent().getNiftyElement().getY();
              this.gui.getSelected().addAttribute("y", "" + (e.getY() - y) + "px");
            }
          }
          break;
        default:
          dragging = false;
      }
      v.displayRect(selected.x, selected.y, selected.height, selected.width);
    }
  }