Examples of PaintBean


Examples of net.wigis.graph.PaintBean

   * @param response
   *            the response
   */
  private void drawNode( HttpServletRequest request, HttpServletResponse response )
  {
    PaintBean pb = (PaintBean)ContextLookup.lookup( "paintBean", request );
    if( pb == null )
      return;

    int id = ServletHelper.getIntParameter( "id", request );
    DNVNode node = (DNVNode)pb.getGraph().getNodeById( id );
    if( node == null )
      return;

    float red = node.getColor().getX();
    float green = node.getColor().getY();
    float blue = node.getColor().getZ();
    String label = node.getLabel();

    Vector3D color = new Vector3D( red, green, blue );
    int size = ServletHelper.getIntParameter( "s", request );
    String icon = node.getIcon();
    boolean showIcons = true;
    if( icon == null || icon.equals( "" ) )
    {
      showIcons = false;
    }

    if( pb != null )
    {
      boolean showLabels = pb.isShowLabels() && pb.isCurvedLabels();
      int imageSize = size + 2;
      if( label == null || label.equals( "" ) )
      {
        showLabels = false;
        label = "";
      }
      else if( showLabels )
      {
        imageSize = getImageSize( label, size, pb );
      }

      BufferedImage img = new BufferedImage( imageSize, imageSize, BufferedImage.TYPE_INT_ARGB );
      Graphics g = img.createGraphics();
      Graphics2D g2d = (Graphics2D)g;
      g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );

      // g.clearRect( 0, 0, size + 1, size + 1 );
      Vector2D pos = new Vector2D( imageSize / 2, imageSize / 2 );
      size /= node.getRadius();
      try
      {
        ImageRenderer.drawLabel( g2d, node, pos, size, label, pb.isShowLabels(), pb.isCurvedLabels(), pb.isOutlinedLabels(),
            pb.getLabelSize(), 1, 1, 1, pb.isScaleNodesOnZoom(), pb.isHighlightNeighbors(), pb.getMaxLabelLength(),
            pb.getCurvedLabelAngle(), pb.isDrawLabelBox(), pb.isBoldLabels(),
            ImageRenderer.highlightNode( pb.isHighlightNeighbors(), node ), null );
        ImageRenderer.drawNode( g2d, showIcons, node, icon, pos, color, size, ImageRenderer.CIRCLE, -1 );
        response.setContentType( "image/png" );
        ImageIO.write( img, "png", response.getOutputStream() );
      }
      catch( MalformedURLException e )
View Full Code Here

Examples of net.wigis.graph.PaintBean

  //=======================================
  public static String PARAM_NAME = "param"
 
  public static String getHtml_forHyperlink_toCall_JavaBean(String text, String formId, String hiddenButtonId, String param)
  {
    PaintBean pb = PaintBean.getCurrentInstance();
    return
      "<a href='#' " +
      "  onclick=\"" +
      "    A4J.AJAX.Submit('_viewRoot','" + formId + "',event,{'similarityGroupingId':'" + formId + ":" + hiddenButtonId + "','parameters':{'" + PARAM_NAME + "':'" + param + "','" + formId + ":" + hiddenButtonId + "':'" + formId + ":" + hiddenButtonId + "'} ,'actionUrl':'" + pb.getContextPath() + "/wigi/WiGiViewerPanel.faces'} );" +
      "\">" +
        text +
      "</a>";
   
//    return "<a href='#' onclick=\"" +
View Full Code Here

Examples of net.wigis.graph.PaintBean

   */
  private void drawGraph( HttpServletRequest request, HttpServletResponse response )
  {
    try
    {
      PaintBean pb = (PaintBean)ContextLookup.lookup( "paintBean", request );
      if( pb == null )
      {
        System.out.println( "paintBean is null" );
        return;
      }

      ImageCacher.updateConstants( request );

      DNVGraph graph = pb.getGraph();
      int level = (int)pb.getLevel();

      // pb.setHasBeenDisplayed( true );

      int width = -1;
      width = getWidth( request, width );
      int height = -1;
      height = getHeight( request, height );

      boolean overview = false;
      overview = getOverview( request, overview );

      if( width == -1 )
        width = (int)pb.getWidth();

      if( height == -1 )
        height = (int)pb.getHeight();

      double minX = 0;
      double minY = 0;
      double maxX = 1;
      double maxY = 1;

      String minXStr = request.getParameter( "minX" );
      if( minXStr != null && !minXStr.equals( "" ) )
      {
        minX = getMinX( request, minX );
        pb.setMinX( minX );
      }

      String minYStr = request.getParameter( "minY" );
      if( minYStr != null && !minYStr.equals( "" ) )
      {
        minY = getMinY( request, minY );
        pb.setMinY( minY );
      }

      String maxXStr = request.getParameter( "maxX" );
      if( maxXStr != null && !maxXStr.equals( "" ) )
      {
        maxX = getMaxX( request, maxX );
        pb.setMaxX( maxX );
      }

      String maxYStr = request.getParameter( "maxY" );
      if( maxYStr != null && !maxYStr.equals( "" ) )
      {
        maxY = getMaxY( request, maxY );
        pb.setMaxY( maxY );
      }

      String renderingStr = request.getParameter( "r" );
      int rendering = BufferedImage.TYPE_BYTE_INDEXED;
      if( renderingStr != null && renderingStr.equals( "qual" ) )
      {
        rendering = BufferedImage.TYPE_INT_RGB;
      }

      Timer pickingTimer = new Timer( Timer.MILLISECONDS );
     
      // ------------------------------------
      // interaction with static image
      // ------------------------------------
      String mouseDownXstr = request.getParameter( "mouseDownX" );
      // boolean mouseDown = false;
      if( mouseDownXstr != null && !mouseDownXstr.equals( "" ) )
      {
        // mouseDown = true;
        pickingTimer.setStart();
        // drag closest node to this position
        int mouseDownX = Integer.parseInt( mouseDownXstr );
        int mouseDownY = Integer.parseInt( request.getParameter( "mouseDownY" ) );

        // drag it to here
        int mouseUpX = Integer.parseInt( request.getParameter( "mouseUpX" ) );
        int mouseUpY = Integer.parseInt( request.getParameter( "mouseUpY" ) );

        boolean sameNode = Boolean.parseBoolean( request.getParameter( "sameNode" ) );
        boolean ctrlPressed = Boolean.parseBoolean( request.getParameter( "ctrlPressed" ) );

        // - - - - - - - - - - -
        // find closest node
        // - - - - - - - - - - -
        // float maxDepth = Integer.MAX_VALUE;

        double globalMinX = GraphFunctions.getMinXPosition( graph, level, true );
        double globalMaxX = GraphFunctions.getMaxXPosition( graph, level, true );
        double globalMinY = GraphFunctions.getMinYPosition( graph, level, true );
        double globalMaxY = GraphFunctions.getMaxYPosition( graph, level, true );
        if( globalMinY == globalMaxY )
        {
          globalMinY -= 10;
          globalMaxY += 10;
        }
        if( globalMinX == globalMaxX )
        {
          globalMinX -= 10;
          globalMaxX += 10;
        }
        double yBuffer = ( globalMaxY - globalMinY ) * pb.getWhiteSpaceBuffer();
        double xBuffer = ( globalMaxX - globalMinX ) * pb.getWhiteSpaceBuffer();
        DNVNode selectedNode = null;
        globalMaxY += yBuffer;
        globalMinY -= yBuffer;
        globalMaxX += xBuffer;
        globalMinX -= xBuffer;

        if( !sameNode )
        {
          List<DNVNode> nodes = graph.getNodes( level );
          SortByLabelSize sbls = new SortByLabelSize( pb.isHighlightNeighbors() );
          Collections.sort( nodes, sbls );
          DNVNode node;
          Vector2D screenPosition;
          double distance;
          double minDistance = Integer.MAX_VALUE;
          int nodeI = -1;
          int distX = 0; // dist b/w this node and mouse click
          int distY = 0;

          // Check if user clicked on a solid node label
          for( int i = nodes.size() - 1; i >= 0; i-- )
          {
            node = nodes.get( i );
            if( node.isVisible() && ( node.isForceLabel() || pb.isShowLabels() ) && node.getProperty( "faded" ) == null )
            {
              screenPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX, minY, maxY,
                  width, height, node.getPosition( true ) );
              ImageRenderer.Rectangle boundingRectangle = ImageRenderer.getRectangleBoundingTheLabel( node, screenPosition, null,
                  (int)Math.round( pb.getNodeSize() * node.getRadius() ), node.getLabel( pb.isInterpolationLabels() ), pb
                      .isCurvedLabels()
                      || node.isCurvedLabel(), pb.getLabelSize(), minX, maxX, width / pb.getWidth(), pb.isScaleLabels(), pb
                      .getMaxLabelLength(), pb.getCurvedLabelAngle(), pb.isBoldLabels(), false, false );
              if( mouseDownX >= boundingRectangle.left() && mouseDownX <= boundingRectangle.right()
                  && mouseDownY <= boundingRectangle.bottom() && mouseDownY >= boundingRectangle.top() )
              {
                distX = (int)( mouseDownX - screenPosition.getX() );
                distY = (int)( mouseDownY - screenPosition.getY() );
                node.setProperty( "distX", "" + distX );
                node.setProperty( "distY", "" + distY );
                minDistance = 0;
                nodeI = i;
                break;
              }
            }
          }

          if( nodeI == -1 )
          {
            // loop thru all nodes to find closest node
            for( int i = nodes.size() - 1; i >= 0; i-- )
            {
              node = nodes.get( i );
              if( node.isVisible() )
              {
                screenPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX, minY,
                    maxY, width, height, node.getPosition( true ) );

                // find node closest to mouseDown
                distX = (int)( mouseDownX - screenPosition.getX() );
                distY = (int)( mouseDownY - screenPosition.getY() );

                distance = distX * distX + distY * distY;

                if( distance < minDistance )
                {
                  node.setProperty( "distX", "" + distX );
                  node.setProperty( "distY", "" + distY );

                  minDistance = distance;
                  nodeI = i;
                }
              }
            }
          }

          if( nodes.size() > 0 && nodeI != -1 )
          {
            node = nodes.get( nodeI );

            double nodeWidth;
            nodeWidth = getNodeWidth( pb, width, minX, maxX, node.getRadius() );
            // check if selected node is close enough to mouseDown
            if( Settings.DEBUG )
              System.out.println( "Minimum distance was " + Math.sqrt( minDistance ) );

            if( Math.sqrt( minDistance ) >= nodeWidth )
            {
              // Still no node selected so check nodes with faded
              // labels
              for( int i = nodes.size() - 1; i >= 0; i-- )
              {
                node = nodes.get( i );
                if( node.isVisible() && ( node.isForceLabel() || pb.isShowLabels() ) && node.getProperty( "faded" ) != null
                    && Float.parseFloat( node.getProperty( "faded" ) ) > 0.1 )
                {
                  screenPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX,
                      minY, maxY, width, height, node.getPosition( true ) );
                  ImageRenderer.Rectangle boundingRectangle = ImageRenderer.getRectangleBoundingTheLabel( node, screenPosition,
                      null, (int)Math.round( pb.getNodeSize() * node.getRadius() ),
                      node.getLabel( pb.isInterpolationLabels() ), pb.isCurvedLabels() || node.isCurvedLabel(), pb
                          .getLabelSize(), minX, maxX, width / pb.getWidth(), pb.isScaleLabels(), pb.getMaxLabelLength(),
                      pb.getCurvedLabelAngle(), pb.isBoldLabels(), false, false );
                  if( mouseDownX >= boundingRectangle.left() && mouseDownX <= boundingRectangle.right()
                      && mouseDownY <= boundingRectangle.bottom() && mouseDownY >= boundingRectangle.top() )
                  {
                    distX = (int)( mouseDownX - screenPosition.getX() );
                    distY = (int)( mouseDownY - screenPosition.getY() );
                    node.setProperty( "distX", "" + distX );
                    node.setProperty( "distY", "" + distY );
                    minDistance = 0;
                    nodeI = i;
                    break;
                  }
                }
              }
            }

            node = nodes.get( nodeI );

            nodeWidth = getNodeWidth( pb, width, minX, maxX, node.getRadius() );
            // check if selected node is close enough to mouseDown
            if( Settings.DEBUG )
              System.out.println( "Minimum distance was " + Math.sqrt( minDistance ) );
            if( Math.sqrt( minDistance ) < nodeWidth )
            {
              // if( node.isSelected() )
              // {
              // sameNode = true;
              // }
              pb.setSelectedNode( node, ctrlPressed );
              selectedNode = node;
            }
            else
            {
              if( pb.getSelectedNode() != null )
              {
                pb.setSelectedNode( null, ctrlPressed );
//                runDocumentTopicsCircularLayout( request, pb, graph, level );
              }
            }
          }

          if( selectedNode == null )
          {
            minDistance = Integer.MAX_VALUE;
            List<DNVEdge> edges = graph.getEdges( level );
            DNVEdge edge;
            Vector2D screenPosition2;
            int edgeI = 0;
            for( int i = 0; i < edges.size(); i++ )
            {
              edge = edges.get( i );
              if( edge.isVisible() )
              {
                screenPosition = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX, minY,
                    maxY, width, height, edge.getFrom().getPosition( true ) );
                screenPosition2 = ImageRenderer.transformPosition( globalMinX, globalMaxX, globalMinY, globalMaxY, minX, maxX, minY,
                    maxY, width, height, edge.getTo().getPosition( true ) );
                distance = getPointLineDistance( screenPosition, screenPosition2, mouseDownX, mouseDownY );
                if( distance < minDistance )
                {
                  minDistance = distance;
                  edgeI = i;
                }
              }
            }

            if( edges.size() > 0 )
            {
              edge = edges.get( edgeI );

              double edgeWidth = Math.max( edge.getThickness(), 4 );
              // check if selected node is close enough to
              // mouseDown
              if( Settings.DEBUG )
                System.out.println( "Minimum distance was " + Math.sqrt( minDistance ) );
              if( Math.sqrt( minDistance ) < edgeWidth / 2.0 )
              {
                if( edge.isSelected() )
                {
                  sameNode = true;
                }
                pb.setSelectedEdge( edge, ctrlPressed );
              }
              else
              {
                pb.setSelectedEdge( null, ctrlPressed );
              }
            }
          }
        }

        pickingTimer.setEnd();
        if( Settings.DEBUG )
          System.out.println( "Picking took " + pickingTimer.getLastSegment( Timer.SECONDS ) + " seconds." );

        String releasedStr = request.getParameter( "released" );
        boolean released = false;
        if( releasedStr != null )
        {
          try
          {
            released = Boolean.parseBoolean( releasedStr );
          }
          catch( Exception e )
          {}
        }
       
        moveSelectedNode( request, pb, graph, level, width, height, minX, minY, maxX, maxY, mouseUpX, mouseUpY, sameNode, globalMinX,
            globalMaxX, globalMinY, globalMaxY, selectedNode, released );
      }

      // ------------------------------------

      Timer paintTimer = new Timer( Timer.MILLISECONDS );
      paintTimer.setStart();
      response.setContentType( "image/gif" );
      pb.paint( response.getOutputStream(), width, height, overview, rendering );
      paintTimer.setEnd();

      if( Settings.DEBUG && !overview && !pb.isRenderJS() )
        System.out.println( "Drawing took " + paintTimer.getLastSegment( Timer.SECONDS ) + " seconds." );
    }
    catch( IOException e )
    {
      // e.printStackTrace();
View Full Code Here

Examples of net.wigis.graph.PaintBean

   * @throws IOException
   *             Signals that an I/O exception has occurred.
   */
  private void setPosition( HttpServletRequest request, HttpServletResponse response ) throws IOException
  {
    PaintBean pb = (PaintBean)ContextLookup.lookup( "paintBean", request );
    Enumeration<?> names = request.getParameterNames();
    HashMap<Integer, Node> nodes = new HashMap<Integer, Node>();
    Node tempNode;
    String parameterName;
    int index;
    int id = 0;
    double x = 0;
    double y = 0;
    double minX = 0;
    double maxX = 1;
    double minY = 0;
    double maxY = 1;
    boolean selected = false;
    boolean noOneSelected = true;

    while( names.hasMoreElements() )
    {
      parameterName = (String)names.nextElement();
      if( parameterName.equals( "minX" ) )
      {
        minX = ServletHelper.getDoubleParameter( "minX", request );
      }
      else if( parameterName.equals( "maxX" ) )
      {
        maxX = ServletHelper.getDoubleParameter( "maxX", request );
      }
      else if( parameterName.equals( "minY" ) )
      {
        minY = ServletHelper.getDoubleParameter( "minY", request );
      }
      else if( parameterName.equals( "maxY" ) )
      {
        maxY = ServletHelper.getDoubleParameter( "maxY", request );
      }
      else
      {
        index = getIndex( parameterName );
        tempNode = nodes.get( index );

        if( tempNode == null )
        {
          tempNode = new Node();
        }

        if( parameterName.startsWith( "id_" ) )
        {
          id = ServletHelper.getIntParameter( parameterName, request );
          tempNode.setId( id );
        }
        else if( parameterName.startsWith( "x_" ) )
        {
          x = ServletHelper.getDoubleParameter( parameterName, request );
          tempNode.setX( x );
        }
        else if( parameterName.startsWith( "y_" ) )
        {
          y = ServletHelper.getDoubleParameter( parameterName, request );
          tempNode.setY( y );
        }
        else if( parameterName.startsWith( "s_" ) )
        {
          selected = ServletHelper.getBooleanParameter( parameterName, request );
          tempNode.setSelected( selected );
        }

        nodes.put( index, tempNode );
      }
    }

    // int level = (int)pb.getLevel();
    DNVGraph graph = pb.getGraph();

    Vector2D nodeWorldPos;

    Iterator<Node> nodeIterator = nodes.values().iterator();
    while( nodeIterator.hasNext() )
    {
      tempNode = nodeIterator.next();
      x = tempNode.getX();
      y = tempNode.getY();
      id = tempNode.getId();
      selected = tempNode.isSelected();
      nodeWorldPos = ImageRenderer.transformScreenToWorld( x, y, minX, maxX, minY, maxY, pb.getGlobalMinX(), pb.getGlobalMaxX(), pb
          .getGlobalMinY(), pb.getGlobalMaxY(), pb.getWidth(), pb.getHeight() );
      DNVNode node = (DNVNode)graph.getNodeById( id );
      if( node != null )
      {
        Vector2D movement = ImageRenderer.getMovement( node, nodeWorldPos );
        node.moveRelatedNodes( movement, true, false );
        node.setPosition( nodeWorldPos );
        if( selected )
        {
          pb.setSelectedNode( node, false );
          noOneSelected = false;
        }
      }
      else
      {
        System.out.println( "Unable to find node with id=[" + id + "]" );
      }
    }

    if( noOneSelected )
    {
      pb.setSelectedNode( null, false );
    }

    OutputStreamWriter writer = new OutputStreamWriter( response.getOutputStream() );
    writer.write( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
        + "<html><div>Done!</div></html>" );
View Full Code Here

Examples of net.wigis.graph.PaintBean

    String fileName = searchQuery.substring( 0, firstSpaceIndex ) + " " + now();
    String selectedFile = OUTPUT_FILE_PATH + CITESEER_SEARCH_PREFIX + fileName + OUTPUT_FILE_EXTENSION;
    // this.searchResults = null;
    g.writeGraph( selectedFile );
    FacesContext fc = FacesContext.getCurrentInstance();
    PaintBean pb = PaintBean.getCurrentInstance();
    GraphsBean gb = (GraphsBean)ContextLookup.lookup( "graphsBean", fc );
    if( gb != null )
      gb.buildFileList();
    // set the graph value here
    pb.setSelectedFile( selectedFile );
    // Lay out the graph
    pb.runLayout();
    // Save the graph again
    pb.saveGraph();
    // Clear the original search info
    newSearch();
    // return the paintBean to the external context
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext ec = facesContext.getExternalContext();
    ec.getRequestMap().put( "paintBean", pb );

    // redirect to visualizer
    try
    {
      showMessage( "" );
      ec.redirect( pb.getContextPath() + IFV_URL );

    }
    catch( IOException e )
    {
      e.printStackTrace();
View Full Code Here

Examples of net.wigis.graph.PaintBean

   * @return String, link
   */
  public static String createLinkDk3(String text, String formId, String hiddenButtonId, HashSet<DNVNode> nodes, HashSet<DNVEdge> edges)
  {
 
    PaintBean pb = PaintBean.getCurrentInstance();
    StringBuilder sb = new StringBuilder();
    sb.append( "<a href='#' onclick=\"" ).append("A4J.AJAX.Submit('_viewRoot','" + formId + "',event,{'similarityGroupingId':'" + formId + ":" + hiddenButtonId + "','parameters': {");
    int index = 0;
    for(DNVNode node : nodes){
      sb.append("'node").append(index).append("':'").append(node.getId()).append("',");
      index++;
    }
    index = 0;
    for(DNVEdge edge : edges){
      sb.append("'edge").append(index).append("':'").append(edge.getId()).append("',");
      index++;
    }
    sb.append("'"+formId + ":" + hiddenButtonId + "':'" + formId + ":" + hiddenButtonId).
    append("'},'actionUrl':'" + pb.getContextPath() + "/wigi/WiGiViewerPanel.faces'} );").
    append("\">" + text + "</a>");
 
    return sb.toString();
  }
View Full Code Here

Examples of net.wigis.graph.PaintBean

   * @return String, link
   */
  public String createLinkDk1(String text, String formId, String hiddenButtonId, ArrayList<DNVNode> params)
  {
 
    PaintBean pb = PaintBean.getCurrentInstance();
    StringBuilder sb = new StringBuilder();
    sb.append("<a href='#' onclick=\"").append("A4J.AJAX.Submit('_viewRoot','" + formId + "',event,{'similarityGroupingId':'" + formId + ":" + hiddenButtonId + "','parameters': {");
    for(int x=0;x<params.size();x++){
      sb.append("'node").append(x).append("':'").append(params.get(x).getId()).append("',");
    }
    sb.append("'"+formId + ":" + hiddenButtonId + "':'" + formId + ":" + hiddenButtonId).
      append("'},'actionUrl':'" + pb.getContextPath() + "/wigi/WiGiViewerPanel.faces'} );").
      append("\">" + text + "</a>");
     
    return sb.toString();
  }
View Full Code Here

Examples of net.wigis.graph.PaintBean

   * Getter of the paintBean
   *
   * @return
   */
  private static PaintBean getPaintBean() {
    PaintBean pb = PaintBean.getCurrentInstance();

    if (pb == null) {
      p("pb is null, creating new instance...");
      pb = new PaintBean();
      HttpSession session = (HttpSession) FacesContext
          .getCurrentInstance().getExternalContext().getSession(true);
      session.setAttribute("paintBean", pb);
    }

View Full Code Here

Examples of net.wigis.graph.PaintBean

    if( sb == null )
    {
      System.out.println( "statsBean is null" );
      return;
    }
    PaintBean pb = (PaintBean)ContextLookup.lookup("paintBean", request);
    sb.bufferedImageSubGraphChart(response.getOutputStream(), pb);
   
  }
View Full Code Here

Examples of net.wigis.graph.PaintBean

    {
      System.out.println( "statsBean is null" );
      return;
    }
   
    PaintBean pb = (PaintBean)ContextLookup.lookup("paintBean", request);
    sb.bufferedImageChart( response.getOutputStream(), pb );
    //sb.bufferedImageSubGraphChart(response.getOutputStream());
   
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.