Exemple #1
0
  /**
   * Search for a named bean in the indexed flow
   *
   * @param beanName the name of the bean to look for
   * @param tab varargs integer index of the flow to search in
   * @return a matching BeanInstance or null if no match was found
   */
  public static BeanInstance findInstance(String beanName, Integer... tab) {
    BeanInstance found = null;

    int index = 0;
    if (tab.length > 0) {
      index = tab[0].intValue();
    }

    Vector<Object> components = null;
    if (TABBED_COMPONENTS.size() > 0 && index < TABBED_COMPONENTS.size()) {
      components = TABBED_COMPONENTS.get(index);

      for (int i = 0; i < components.size(); i++) {
        BeanInstance t = (BeanInstance) components.elementAt(i);

        if (t.getBean() instanceof BeanCommon) {
          String bN = ((BeanCommon) t).getCustomName();

          if (bN.equals(beanName)) {
            found = t;
            break;
          }
        }
      }
    }

    return found;
  }
Exemple #2
0
  /**
   * Returns a list of start points (if any) in the indexed flow
   *
   * @param tab varargs integer index of the flow to search for start points. Defaults to 0 if not
   *     supplied.
   * @return a list of BeanInstances who's beans implement Startable
   */
  public static List<BeanInstance> getStartPoints(Integer... tab) {
    List<BeanInstance> startPoints = new ArrayList<BeanInstance>();

    int index = 0;
    if (tab.length > 0) {
      index = tab[0].intValue();
    }

    Vector<Object> components = null;
    if (TABBED_COMPONENTS.size() > 0 && index < TABBED_COMPONENTS.size()) {
      components = TABBED_COMPONENTS.get(index);

      for (int i = 0; i < components.size(); i++) {
        BeanInstance t = (BeanInstance) components.elementAt(i);
        if (t.getBean() instanceof Startable) {
          startPoints.add(t);
        }
      }
    }

    return startPoints;
  }
Exemple #3
0
  /**
   * Looks for a bean (if any) whose bounds contain the supplied point
   *
   * @param p a point
   * @return a bean that contains the supplied point or null if no bean contains the point
   */
  public static BeanInstance findInstance(Point p, Integer... tab) {
    int index = 0;
    if (tab.length > 0) {
      index = tab[0].intValue();
    }

    Vector<Object> components = null;
    if (TABBED_COMPONENTS.size() > 0 && index < TABBED_COMPONENTS.size()) {
      components = TABBED_COMPONENTS.get(index);
    }

    Rectangle tempBounds = new Rectangle();
    for (int i = 0; i < components.size(); i++) {

      BeanInstance t = (BeanInstance) components.elementAt(i);
      JComponent temp = (JComponent) t.getBean();

      tempBounds = temp.getBounds(tempBounds);
      if (tempBounds.contains(p)) {
        return t;
      }
    }
    return null;
  }
Exemple #4
0
  /**
   * Adds all beans to the supplied component
   *
   * @param container a <code>JComponent</code> value
   */
  public static void addAllBeansToContainer(JComponent container, Integer... tab) {
    int index = 0;
    if (tab.length > 0) {
      index = tab[0].intValue();
    }

    Vector<Object> components = null;
    if (TABBED_COMPONENTS.size() > 0 && index < TABBED_COMPONENTS.size()) {
      components = TABBED_COMPONENTS.get(index);
    }

    if (container != null) {
      if (components != null) {
        for (int i = 0; i < components.size(); i++) {
          BeanInstance tempInstance = (BeanInstance) components.elementAt(i);
          Object tempBean = tempInstance.getBean();
          if (Beans.isInstanceOf(tempBean, JComponent.class)) {
            container.add((JComponent) tempBean);
          }
        }
      }
      container.revalidate();
    }
  }
  protected void newFlow() {
    m_newFlowBut.setEnabled(false);

    String user = m_viewer.getUser();
    String password = m_viewer.getPassword();
    String uRL = m_viewer.getURL();
    String query = m_viewer.getQuery();

    if (query == null) {
      query = "";
    }

    try {
      DatabaseLoader dbl = new DatabaseLoader();
      dbl.setUser(user);
      dbl.setPassword(password);
      dbl.setUrl(uRL);
      dbl.setQuery(query);

      BeanContextSupport bc = new BeanContextSupport();
      bc.setDesignTime(true);

      Loader loaderComp = new Loader();
      bc.add(loaderComp);
      loaderComp.setLoader(dbl);

      KnowledgeFlowApp singleton = KnowledgeFlowApp.getSingleton();
      m_mainPerspective.addTab("DBSource");
      BeanInstance beanI =
          new BeanInstance(
              m_mainPerspective.getBeanLayout(m_mainPerspective.getNumTabs() - 1),
              loaderComp,
              50,
              50,
              m_mainPerspective.getNumTabs() - 1);
      Vector beans = BeanInstance.getBeanInstances(m_mainPerspective.getNumTabs() - 1);
      Vector connections = BeanConnection.getConnections(m_mainPerspective.getNumTabs() - 1);
      singleton.integrateFlow(beans, connections, true, false);
      singleton.setActivePerspective(0); // switch back to the main perspective

      m_newFlowBut.setEnabled(true);

    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Exemple #6
0
  /**
   * Looks for all beans (if any) located within the supplied bounding box. Also adjusts the
   * bounding box to be a tight fit around all contained beans
   *
   * @param boundingBox the bounding rectangle
   * @return a Vector of BeanInstances
   */
  public static Vector<Object> findInstances(Rectangle boundingBox, Integer... tab) {
    int index = 0;
    if (tab.length > 0) {
      index = tab[0].intValue();
    }

    Vector<Object> components = null;
    if (TABBED_COMPONENTS.size() > 0 && index < TABBED_COMPONENTS.size()) {
      components = TABBED_COMPONENTS.get(index);
    }

    Graphics gx = null;
    FontMetrics fm = null;

    int centerX, centerY;
    int minX = Integer.MAX_VALUE;
    int minY = Integer.MAX_VALUE;
    int maxX = Integer.MIN_VALUE;
    int maxY = Integer.MIN_VALUE;
    Vector<Object> result = new Vector<Object>();
    for (int i = 0; i < components.size(); i++) {
      BeanInstance t = (BeanInstance) components.elementAt(i);
      centerX = t.getX() + (t.getWidth() / 2);
      centerY = t.getY() + (t.getHeight() / 2);
      if (boundingBox.contains(centerX, centerY)) {
        result.addElement(t);

        // adjust bounding box stuff
        // int hf = 0;
        if (gx == null) {
          gx = ((JComponent) t.getBean()).getGraphics();
          gx.setFont(new Font(null, Font.PLAIN, 9));
          fm = gx.getFontMetrics();
          // hf = fm.getAscent();
        }
        String label = "";
        if (t.getBean() instanceof Visible) {
          label = ((Visible) t.getBean()).getVisual().getText();
        }
        int labelwidth = fm.stringWidth(label);
        /*
         * if (label.length() == 0) { heightMultiplier = 0; }
         */
        int brx = 0;
        int blx = 0;
        if (centerX - (labelwidth / 2) - 2 < t.getX()) {
          blx = (centerX - (labelwidth / 2) - 2);
          brx = centerX + (labelwidth / 2) + 2;
        } else {
          blx = t.getX() - 2;
          brx = t.getX() + t.getWidth() + 2;
        }

        if (blx < minX) {
          minX = blx;
        }
        if (brx > maxX) {
          maxX = brx;
        }
        if (t.getY() - 2 < minY) {
          minY = t.getY() - 2;
        }
        if (t.getY() + t.getHeight() + 2 > maxY) {
          maxY = t.getY() + t.getHeight() + 2;
        }
      }
    }
    boundingBox.setBounds(minX, minY, maxX - minX, maxY - minY);

    return result;
  }
Exemple #7
0
  /**
   * Renders the textual labels for the beans.
   *
   * @param gx a <code>Graphics</code> object on which to render the labels
   */
  public static void paintLabels(Graphics gx, Integer... tab) {
    int index = 0;
    if (tab.length > 0) {
      index = tab[0].intValue();
    }

    Vector<Object> components = null;
    if (TABBED_COMPONENTS.size() > 0 && index < TABBED_COMPONENTS.size()) {
      components = TABBED_COMPONENTS.get(index);
    }

    if (components != null) {
      gx.setFont(new Font(null, Font.PLAIN, 9));
      FontMetrics fm = gx.getFontMetrics();
      int hf = fm.getAscent();
      for (int i = 0; i < components.size(); i++) {
        BeanInstance bi = (BeanInstance) components.elementAt(i);
        if (!(bi.getBean() instanceof Visible)) {
          continue;
        }
        int cx = bi.getX();
        int cy = bi.getY();
        int width = ((JComponent) bi.getBean()).getWidth();
        int height = ((JComponent) bi.getBean()).getHeight();
        String label = ((Visible) bi.getBean()).getVisual().getText();
        int labelwidth = fm.stringWidth(label);
        if (labelwidth < width) {
          gx.drawString(label, (cx + (width / 2)) - (labelwidth / 2), cy + height + hf + 2);
        } else {
          // split label

          // find mid point
          int mid = label.length() / 2;
          // look for split point closest to the mid
          int closest = label.length();
          int closestI = -1;
          for (int z = 0; z < label.length(); z++) {
            if (label.charAt(z) < 'a') {
              if (Math.abs(mid - z) < closest) {
                closest = Math.abs(mid - z);
                closestI = z;
              }
            }
          }
          if (closestI != -1) {
            String left = label.substring(0, closestI);
            String right = label.substring(closestI, label.length());
            if (left.length() > 1 && right.length() > 1) {
              gx.drawString(
                  left,
                  (cx + (width / 2)) - (fm.stringWidth(left) / 2),
                  cy + height + (hf * 1) + 2);
              gx.drawString(
                  right,
                  (cx + (width / 2)) - (fm.stringWidth(right) / 2),
                  cy + height + (hf * 2) + 2);
            } else {
              gx.drawString(
                  label,
                  (cx + (width / 2)) - (fm.stringWidth(label) / 2),
                  cy + height + (hf * 1) + 2);
            }
          } else {
            gx.drawString(
                label,
                (cx + (width / 2)) - (fm.stringWidth(label) / 2),
                cy + height + (hf * 1) + 2);
          }
        }
      }
    }
  }