示例#1
0
  @Test
  public void addAndRemoveAllComponents() {
    Entity entity = new Entity();

    entity.add(new ComponentA());
    entity.add(new ComponentB());

    assertEquals(2, entity.getComponents().size());

    Bits componentBits = entity.getComponentBits();
    int componentAIndex = ComponentType.getIndexFor(ComponentA.class);
    int componentBIndex = ComponentType.getIndexFor(ComponentB.class);

    for (int i = 0; i < componentBits.length(); ++i) {
      assertEquals(i == componentAIndex || i == componentBIndex, componentBits.get(i));
    }

    assertNotNull(am.get(entity));
    assertNotNull(bm.get(entity));
    assertTrue(am.has(entity));
    assertTrue(bm.has(entity));

    entity.removeAll();

    assertEquals(0, entity.getComponents().size());

    for (int i = 0; i < componentBits.length(); ++i) {
      assertFalse(componentBits.get(i));
    }

    assertNull(am.get(entity));
    assertNull(bm.get(entity));
    assertFalse(am.has(entity));
    assertFalse(bm.has(entity));
  }
  /**
   * Instantiate, configure and return a new component described by the supplied configuration. This
   * method does not manage the returned instance.
   *
   * @param config the configuration describing the component
   * @return the new component, or null if the component could not be successfully configured
   * @throws IllegalArgumentException if the component could not be configured properly
   */
  @SuppressWarnings("unchecked")
  protected ComponentType newInstance(ConfigType config) {
    String[] classpath = config.getComponentClasspathArray();
    final ClassLoader classLoader = this.getClassLoaderFactory().getClassLoader(classpath);
    assert classLoader != null;
    ComponentType newInstance = null;
    try {
      // Don't use ClassLoader.loadClass(String), as it doesn't properly initialize the class
      // (specifically static initializers may not be called)
      Class<?> componentClass = Class.forName(config.getComponentClassname(), true, classLoader);
      newInstance = doCreateInstance(componentClass);
      if (newInstance instanceof Component) {
        ((Component<ConfigType>) newInstance).setConfiguration(config);
      }

      if (config.getProperties() != null) {
        for (Map.Entry<String, Object> entry : config.getProperties().entrySet()) {
          // Set the JavaBean-style property on the RepositorySource instance ...
          Reflection reflection = new Reflection(newInstance.getClass());
          reflection.invokeSetterMethodOnTarget(entry.getKey(), newInstance, entry.getValue());
        }
      }
      configure(newInstance, config);
    } catch (Throwable e) {
      throw new SystemFailureException(e);
    }
    if (newInstance instanceof Component
        && ((Component<ConfigType>) newInstance).getConfiguration() == null) {
      throw new SystemFailureException(CommonI18n.componentNotConfigured.text(config.getName()));
    }
    return newInstance;
  }
 private boolean isHandleSelectionEnabled(@NotNull KeyType selected, boolean processIfUnfocused) {
   return myEnabled
       && myComponent.isEnabled()
       && myComponent.isShowing()
       && myComponent.getVisibleRect().intersects(getVisibleRect(selected))
       && (processIfUnfocused || myComponent.isFocusOwner())
       && !isPopup();
 }
  private void doHandleSelectionChange(@NotNull KeyType selected, boolean processIfUnfocused) {
    if (!myEnabled
        || !myComponent.isEnabled()
        || !myComponent.isShowing()
        || !myComponent.getVisibleRect().intersects(getVisibleRect(selected))
        || !myComponent.isFocusOwner() && !processIfUnfocused
        || isPopup()) {
      hideHint();
      return;
    }

    myKey = selected;

    Point location = createToolTipImage(myKey);

    if (location == null) {
      hideHint();
    } else {
      Rectangle bounds = new Rectangle(location, myTipComponent.getPreferredSize());
      myPopup.setBounds(bounds);
      myPopup.setVisible(noIntersections(bounds));
      repaintKeyItem();
    }
  }
  public JSONArray getCommands() {
    JSONArray commands = new JSONArray();
    JSONObject createCommand = new JSONObject();
    String parentId = parent != null ? parent.id : rootComponentId;

    createCommand.put("Command", "CREATE COMPONENT");
    createCommand.put("ComponentId", id);
    createCommand.put("ParentId", parentId);
    createCommand.put("Type", type.name());

    commands.add(createCommand);
    commands.addAll(attributes.getCommands());

    return commands;
  }
  protected AbstractExpandableItemsHandler(@NotNull final ComponentType component) {
    myComponent = component;
    myComponent.add(myRendererPane);
    myComponent.validate();
    myPopup = new MovablePopup(myComponent, myTipComponent);

    myTipComponent.addMouseWheelListener(
        new MouseWheelListener() {
          @Override
          public void mouseWheelMoved(MouseWheelEvent e) {
            dispatchEvent(myComponent, e);
          }
        });

    myTipComponent.addMouseListener(
        new MouseListener() {
          @Override
          public void mouseClicked(MouseEvent e) {
            dispatchEvent(myComponent, e);
          }

          @Override
          public void mousePressed(MouseEvent e) {
            dispatchEvent(myComponent, e);
          }

          @Override
          public void mouseReleased(MouseEvent e) {
            dispatchEvent(myComponent, e);
          }

          @Override
          public void mouseEntered(MouseEvent e) {}

          @Override
          public void mouseExited(MouseEvent e) {
            // don't hide the hint if mouse exited to owner component
            if (myComponent.getMousePosition() == null) {
              hideHint();
            }
          }
        });

    myTipComponent.addMouseMotionListener(
        new MouseMotionListener() {
          @Override
          public void mouseMoved(MouseEvent e) {
            dispatchEvent(myComponent, e);
          }

          @Override
          public void mouseDragged(MouseEvent e) {
            dispatchEvent(myComponent, e);
          }
        });

    myComponent.addMouseListener(
        new MouseListener() {
          @Override
          public void mouseEntered(MouseEvent e) {
            handleMouseEvent(e);
          }

          @Override
          public void mouseExited(MouseEvent e) {
            // don't hide the hint if mouse exited to it
            if (myTipComponent.getMousePosition() == null) {
              hideHint();
            }
          }

          @Override
          public void mouseClicked(MouseEvent e) {}

          @Override
          public void mousePressed(MouseEvent e) {
            handleMouseEvent(e);
          }

          @Override
          public void mouseReleased(MouseEvent e) {
            handleMouseEvent(e);
          }
        });

    myComponent.addMouseMotionListener(
        new MouseMotionListener() {
          @Override
          public void mouseDragged(MouseEvent e) {
            handleMouseEvent(e);
          }

          @Override
          public void mouseMoved(MouseEvent e) {
            handleMouseEvent(e, false);
          }
        });

    myComponent.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusLost(FocusEvent e) {
            onFocusLost();
          }

          @Override
          public void focusGained(FocusEvent e) {
            updateCurrentSelection();
          }
        });

    myComponent.addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentHidden(ComponentEvent e) {
            hideHint();
          }

          @Override
          public void componentMoved(ComponentEvent e) {
            updateCurrentSelection();
          }

          @Override
          public void componentResized(ComponentEvent e) {
            updateCurrentSelection();
          }
        });

    myComponent.addHierarchyBoundsListener(
        new HierarchyBoundsAdapter() {
          @Override
          public void ancestorMoved(HierarchyEvent e) {
            updateCurrentSelection();
          }

          @Override
          public void ancestorResized(HierarchyEvent e) {
            updateCurrentSelection();
          }
        });

    myComponent.addHierarchyListener(
        new HierarchyListener() {
          @Override
          public void hierarchyChanged(HierarchyEvent e) {
            hideHint();
          }
        });
  }
 protected Rectangle getVisibleRect(KeyType key) {
   return myComponent.getVisibleRect();
 }
 protected void doFillBackground(int height, int width, Graphics2D g) {
   g.setColor(myComponent.getBackground());
   g.fillRect(0, 0, width, height);
 }
 private void repaintKeyItem() {
   if (myKeyItemBounds != null) {
     myComponent.repaint(myKeyItemBounds);
   }
 }
 /**
  * コンポーネント名を設定します。<br>
  * コンポーネントの種類も同時に設定します。<br>
  *
  * @param componentName クラス名
  */
 public void setComponentName(final String componentName) {
   this.componentName_ = componentName;
   this.componentType_ = ComponentType.getComponentType(componentName);
   firePropertyChange(P_CLASS_NAME, null, this.componentName_);
 }
示例#11
0
 public void removeAll(Collection<ComponentType<?>> componentTypes) {
   for (ComponentType<?> type : componentTypes) type.remove(this);
 }
示例#12
0
 /**
  * Removes all components
  *
  * @param componentTypes All the types of components to remove
  */
 public void removeAll(ComponentType<?>... componentTypes) {
   for (ComponentType<?> type : componentTypes) type.remove(this);
 }
示例#13
0
 /**
  * Remove a component of a certain type
  *
  * @param componentType The type of component to remove
  */
 public <T extends Component> void remove(ComponentType<T> componentType) {
   componentType.remove(this);
 }
示例#14
0
 /**
  * Get the component value of a specific type
  *
  * @param componentType The type of component to get
  * @return The component of the specified type
  */
 public <T extends Component> T get(ComponentType<T> componentType) {
   return componentType.get(this);
 }
示例#15
0
 /**
  * Add a component of a certain type
  *
  * @param componentType The component type to add
  * @return The component of a specific type
  */
 public <T extends Component> T add(ComponentType<T> componentType) {
   return componentType.add(this);
 }