Пример #1
0
    public void mousePressed(java.awt.event.MouseEvent e) {
      isClick = true;
      JButton b = (JButton) e.getSource();
      // check to see if the target button can be moved
      if (!solved && check(buttons.indexOf(b))) {
        // hide the target button
        b.setVisible(false);

        // Figure out the bounds of the areas where source
        // and target buttons are located
        int menuOffset = getJMenuBar().getHeight();
        dragSourceArea = b.getBounds();
        dragTargetArea = ((JButton) buttons.get(hiddenIndex)).getBounds();
        dragSourceArea.translate(0, menuOffset);
        dragTargetArea.translate(0, menuOffset);

        // setup the bounds of the panel to limit the locations on the drag
        // layer
        panelArea = new Rectangle(0, menuOffset, getJPanel().getWidth(), getJPanel().getHeight());

        // Setup and show the drag button on the upper layer
        getDragButton().setText(b.getText());
        getDragButton().setBounds(dragSourceArea);
        getDragButton().setVisible(true);

        // Offset when repositioning the drag button later
        cursorOffset = new Point(e.getX(), e.getY());
      }
    }
Пример #2
0
  /**
   * Moves this <code>ShapeGroup</code> to the specified location.
   *
   * <p>
   *
   * @param x the x coordinate of the top left corner of the shape in new location
   * @param y the y coordinate of the top left corner of the shape in new location
   */
  public void moveTo(int x, int y) {
    java.awt.Rectangle anchor = getAnchor();
    int dx = x - anchor.x;
    int dy = y - anchor.y;
    anchor.translate(dx, dy);
    setAnchor(anchor);

    Shape[] shape = getShapes();
    for (int i = 0; i < shape.length; i++) {
      java.awt.Rectangle chanchor = shape[i].getAnchor();
      chanchor.translate(dx, dy);
      shape[i].setAnchor(chanchor);
    }
  }
 protected boolean mouseOverComponent() {
   if (comp.isShowing()) {
     if (comp instanceof MainView) {
       final MainView view = (MainView) comp;
       Rectangle bounds = ((ZoomableLabelUI) view.getUI()).getIconR(view);
       final Point mousePosition = comp.getMousePosition(true);
       if (mousePosition == null) {
         return false;
       }
       if (bounds.contains(mousePosition)) {
         if (view.getIcon() instanceof MultipleImage) {
           Rectangle iconR =
               ((MultipleImage) view.getIcon())
                   .getIconR(PdfUtilitiesController.REFRESH_MONITORING_ICON);
           if (iconR != null) {
             float zoom = Controller.getCurrentController().getViewController().getZoom();
             iconR.setLocation((int) (iconR.x * zoom), iconR.y);
             iconR.setSize((int) (iconR.width * zoom), (int) (iconR.height * zoom));
             iconR.translate(bounds.x, bounds.y);
             if (iconR.contains(mousePosition)) {
               return true;
             }
           }
         }
       }
     }
   }
   return false;
 }
Пример #4
0
  @Override
  public void paintComponent(Graphics g) {

    // Get Graphics2D
    Graphics2D g2d = (Graphics2D) g;
    Rectangle box = new Rectangle(5, 10, 15, 20);
    g2d.setColor(new Color(255, 128, 222));
    g2d.draw(box);
    box.translate(
        10,
        30); // move shape and redraw box. cannot call Rectangle box2 = box.translate() as
             // translate() returns void
    g2d.draw(box);
    Ellipse2D comp2 = new Ellipse2D.Double(30, 100, 140, 220);

    Point2D from = new Point2D.Double(30, 90);
    Point2D to = new Point2D.Double(300, 320);
    Line2D comp3 = new Line2D.Double(from, to);
    g2d.draw(comp2);
    g2d.draw(comp3);

    double diffX = Math.abs(from.getX() - to.getX());
    double diffY = Math.abs(from.getY() - to.getY());
    System.out.println(String.format("diffX = %3.2f, diffY = %3.2f", diffX, diffY));
    double pythag = Math.sqrt(Math.pow(diffX, 2) + Math.pow(diffY, 2));
    g2d.drawString(String.format("Line Length = %3.3f", pythag), 200, 20);
  }
Пример #5
0
 public void repaint(Rectangle dirtyBounds) {
   if (panel != null && panel.getRoot() != null) {
     Point location = panel.getAbsoluteLocation();
     dirtyBounds.translate(location.x, location.y);
     panel.getRoot().addDirtyRegion(dirtyBounds);
   }
 }
Пример #6
0
  /**
   * Paints this Node in the correct position in the TreeView Panel
   *
   * @param g2d The graphics Object which paints to the TreeView Panel
   * @param x The xPos start of the box which this Node can draw in
   * @param y The yPos start of the box which this Node can draw in
   * @param width The width of the box this node is allowed to draw in.
   * @param heigth The height of the box this node is allowed to draw in.
   * @param dimension The dimension of the rectangle that represents this node in the tree
   */
  public void drawInTree(
      final Graphics2D g2d,
      final int x,
      final int y,
      final int width,
      final int heigth,
      final int dimension) {
    // Calculate where the node shall be drawn
    final int nodeStartX = x + width / 2 - (maxChildrenPerNode * dimension) / 2;
    // Calculate the width of the childboxes
    final int childWidth = width / maxChildrenPerNode;
    // Calculate where the start of the first child-pointer
    int pointerStartX = nodeStartX + (dimension / 2);
    // Calculate where the end of the first child-pointer
    int pointerEndX = x + (childWidth / 2);

    final Rectangle rectangle = new Rectangle(nodeStartX, y, dimension, dimension);

    // Drawing the node and it's pointers
    for (int i = 0; i < maxChildrenPerNode; i++) {

      g2d.setColor(strokecolor);
      g2d.draw(rectangle);
      g2d.drawLine(pointerStartX, (y + dimension), pointerEndX, y + heigth);

      rectangle.translate(dimension, 0);
      pointerStartX += dimension;
      pointerEndX += childWidth;
    }
  }
 public Point locationSuggested(Widget widget, Point originalLocation, Point suggestedLocation) {
   Point widgetLocation = widget.getLocation();
   Rectangle widgetBounds = outerBounds ? widget.getBounds() : widget.getClientArea();
   Rectangle bounds = widget.convertLocalToScene(widgetBounds);
   bounds.translate(
       (suggestedLocation.x - widgetLocation.x), (suggestedLocation.y - widgetLocation.y));
   Insets insets = widget.getBorder().getInsets();
   if (!outerBounds) {
     suggestedLocation.x += insets.left;
     suggestedLocation.y += insets.top;
   }
   Point point =
       super.locationSuggested(
           widget,
           bounds,
           widget.getParentWidget().convertLocalToScene(suggestedLocation),
           true,
           true,
           true,
           true);
   if (!outerBounds) {
     point.x -= insets.left;
     point.y -= insets.top;
   }
   return widget.getParentWidget().convertSceneToLocal(point);
 }
Пример #8
0
 @Override
 public ScreenImage captureScreen(Rectangle rect) {
   Rectangle s = scr.getBounds();
   rect.translate(-s.x, -s.y);
   BufferedImage img = createScreenCapture(rect);
   Debug.log(4, "RobotDesktop: captureScreen: on %d using %s", scr.getID(), rect);
   return new ScreenImage(rect, img);
 }
Пример #9
0
  /**
   * Compute the bounding screen extent of a rotated rectangle.
   *
   * @param rect Rectangle to rotate.
   * @param x X coordinate of the rotation point.
   * @param y Y coordinate of the rotation point.
   * @param rotation Rotation angle.
   * @return The smallest rectangle that completely contains {@code rect} when rotated by the
   *     specified angle.
   */
  protected Rectangle computeRotatedScreenExtent(Rectangle rect, int x, int y, Angle rotation) {
    Rectangle r = new Rectangle(rect);

    // Translate the rectangle to the rotation point.
    r.translate(-x, -y);

    // Compute corner points
    Vec4[] corners = {
      new Vec4(r.getMaxX(), r.getMaxY()),
      new Vec4(r.getMaxX(), r.getMinY()),
      new Vec4(r.getMinX(), r.getMaxY()),
      new Vec4(r.getMinX(), r.getMinY())
    };

    // Rotate the rectangle
    Matrix rotationMatrix = Matrix.fromRotationZ(rotation);
    for (int i = 0; i < corners.length; i++) {
      corners[i] = corners[i].transformBy3(rotationMatrix);
    }

    // Find the bounding rectangle of rotated points.
    int minX = Integer.MAX_VALUE;
    int minY = Integer.MAX_VALUE;
    int maxX = -Integer.MAX_VALUE;
    int maxY = -Integer.MAX_VALUE;

    for (Vec4 v : corners) {
      if (v.x > maxX) maxX = (int) v.x;

      if (v.x < minX) minX = (int) v.x;

      if (v.y > maxY) maxY = (int) v.y;

      if (v.y < minY) minY = (int) v.y;
    }

    // Set bounds and translate the rectangle back to where it started.
    r.setBounds(minX, minY, maxX - minX, maxY - minY);
    r.translate(x, y);

    return r;
  }
Пример #10
0
 @Override
 public Rectangle getTextLocation(TextHitInfo offset) {
   Rectangle r =
       new Rectangle(
           myCursor.getCoordX() * myCharSize.width,
           (myCursor.getCoordY() + 1) * myCharSize.height,
           0,
           0);
   Point p = TerminalPanel.this.getLocationOnScreen();
   r.translate(p.x, p.y);
   return r;
 }
Пример #11
0
  @Override
  public void update(Observable o, Object arg) {
    SortedSet<Feature> fs = model.selectionModel().getFeatureSelection();

    if (fs.size() == 1) {

      if (fs.first().type() == listModel.getType()) {
        int row = listModel.getRow(fs.first());
        // getSelectionModel().setSelectionInterval(row, row);
        if (!(getParent() instanceof JViewport)) {
          return;
        }
        JViewport viewport = (JViewport) getParent();

        // This rectangle is relative to the table where the
        // northwest corner of cell (0,0) is always (0,0).
        Rectangle rect = getCellRect(row, 0, true);

        // The location of the view relative to the table
        Rectangle viewRect = viewport.getViewRect();

        int topVisible = viewport.getViewRect().y;
        int bottomVisible = viewport.getViewRect().height + topVisible;

        /* When the cell is visible, don't do anything */
        if (rect.y > topVisible && rect.y + rect.height < bottomVisible) {
          return;
        }
        // Translate the cell location so that it is relative
        // to the view, assuming the northwest corner of the
        // view is (0,0).
        rect.setLocation(rect.x - viewRect.x, rect.y - viewRect.y);

        // Calculate location of rect if it were at the center of view
        int centerX = (viewRect.width - rect.width) / 2;
        int centerY = (viewRect.height - rect.height) / 2;

        // Fake the location of the cell so that scrollRectToVisible
        // will move the cell to the center
        if (rect.x < centerX) {
          centerX = -centerX;
        }
        if (rect.y < centerY) {
          centerY = -centerY;
        }
        rect.translate(centerX, centerY);

        // Scroll the area into view.
        viewport.scrollRectToVisible(rect);
      }
    }
  }
Пример #12
0
 public void paintIcon(Component c, Graphics g, int x, int y) {
   Rectangle r = new Rectangle(x, y, WIDTH - 1, HEIGHT - 1);
   Graphics2D g2 = (Graphics2D) g;
   Color oldColor = g2.getColor();
   Rectangle r1 = new Rectangle(x, y, WIDTH / 4, HEIGHT - 1);
   for (int i = 0; i < 4; i++) {
     g2.setColor(getColor());
     g2.fill(r1);
     r1.translate(WIDTH / 4, 0);
   }
   g2.setColor(Color.BLACK);
   g2.draw(r);
   g2.setColor(oldColor);
 }
Пример #13
0
  public void paint(Graphics g) {
    Graphics2D gr = (Graphics2D) g;
    super.paint(g);
    Rectangle bounds = scene.getBounds();
    Dimension size = getSize();

    double sx = bounds.width > 0 ? (double) size.width / bounds.width : 0.0;
    double sy = bounds.width > 0 ? (double) size.height / bounds.height : 0.0;
    double scale = Math.min(sx, sy);

    int vw = (int) (scale * bounds.width);
    int vh = (int) (scale * bounds.height);
    int vx = (size.width - vw) / 2;
    int vy = (size.height - vh) / 2;

    if (image == null || vw != imageWidth || vh != imageHeight) {

      imageWidth = vw;
      imageHeight = vh;
      image = this.createImage(imageWidth, imageHeight);
      Graphics2D ig = (Graphics2D) image.getGraphics();
      ig.scale(scale, scale);
      scene.setRealZoomFactor(scale);
      scene.paint(ig);
      scene.setRealZoomFactor(0.0);
    }

    gr.drawImage(image, vx, vy, this);

    JComponent component = scene.getView();
    double zoomFactor = scene.getZoomFactor();
    Rectangle viewRectangle = component != null ? component.getVisibleRect() : null;
    if (viewRectangle != null) {
      Rectangle window =
          new Rectangle(
              (int) ((double) viewRectangle.x * scale / zoomFactor),
              (int) ((double) viewRectangle.y * scale / zoomFactor),
              (int) ((double) viewRectangle.width * scale / zoomFactor),
              (int) ((double) viewRectangle.height * scale / zoomFactor));
      window.translate(vx, vy);
      gr.setColor(new Color(200, 200, 200, 128));
      gr.fill(window);
      gr.setColor(Color.BLACK);
      gr.drawRect(window.x, window.y, window.width - 1, window.height - 1);
    }
  }
Пример #14
0
 private void recoverOldBounds() {
   // Make sure it is recoverable. If not, just do a simple
   // layout
   if (!isOldBoundsRecoverable()) {
     // Copy any known bounds
     if (oldIdToBounds != null) {
       for (Renderable r : componentsInHiearchy) {
         Rectangle bounds = oldIdToBounds.get(r.getID());
         if (bounds == null) continue;
         if (r.bounds != null) {
           r.bounds.width = bounds.width;
           r.bounds.height = bounds.height;
         } else r.bounds = new Rectangle(bounds);
       }
     }
     // Just do an auto layout. Should start from the smalled complexes
     for (Renderable r : componentsInHiearchy) {
       if (r instanceof RenderableComplex) ((RenderableComplex) r).layout();
     }
     layout();
     return;
   }
   Rectangle oldBounds = oldIdToBounds.get(getID());
   int dx = bounds.x - oldBounds.x;
   int dy = bounds.y - oldBounds.y;
   bounds.width = oldBounds.width;
   bounds.height = oldBounds.height;
   invalidateTextBounds();
   for (Renderable r : componentsInHiearchy) {
     oldBounds = oldIdToBounds.get(r.getID());
     oldBounds.translate(dx, dy);
     Rectangle newBounds = r.getBounds();
     if (newBounds == null) {
       newBounds = new Rectangle(oldBounds);
       r.setBounds(newBounds);
     } else {
       newBounds.x = oldBounds.x;
       newBounds.y = oldBounds.y;
       newBounds.width = oldBounds.width;
       newBounds.height = oldBounds.height;
     }
     ((Node) r).invalidateTextBounds();
   }
 }
Пример #15
0
 @Override
 protected Rectangle getWorkingRectangle(boolean withPaper) {
   Rectangle working = null;
   if (withPaper) {
     working = paperWidget.getPreferredBounds();
   }
   for (Object o : getObjects()) {
     Widget w = findWidget(o);
     if (w instanceof SubLayoutWidget) {
       Point wLoc = w.getPreferredLocation();
       Rectangle wRect = w.getBounds();
       if (wRect != null) {
         wRect.translate(wLoc.x, wLoc.y);
         if (working == null) {
           working = wRect;
         }
         working.add(wRect);
       }
     }
   }
   return working;
 }
Пример #16
0
  public static void renderCards(
      GameScreen screen,
      Graphics2D g,
      Iterable<Card> cards,
      Rectangle2D loc,
      Map<Card, Rectangle> cardLocations) {
    Shape clip = g.getClip();

    int x = 0;
    int col = 0;
    int row = 0;
    for (Card card : cards) {
      Rectangle r = getCardBounds(x, row, loc.getWidth(), loc.getHeight());
      if (x > 0 && r.getMaxX() > loc.getWidth() && col > 0) {
        x = 0;
        row++;
        r = getCardBounds(x, row, loc.getWidth(), loc.getHeight());
      }
      r.translate((int) loc.getX(), (int) loc.getY());

      cardLocations.put(card, r);

      BufferedImage bi = ClientCache.getCardImage(card.detailsID);

      if (clip.intersects(r) && card != screen.getPickedUpCard()) {
        CardRenderer.draw(card, bi, r, g);
      }

      if (screen.debug) {
        g.setColor(Color.white);
        g.setFont(new Font("Arial", Font.BOLD, 19));
        ClientUtils.drawCenteredString(g, r, card.id + "");
      }

      x += r.width + 10;
      col++;
    }
  }
Пример #17
0
 /*  48:    */
 /*  49:    */ public boolean inCheckBoxHitRegion(MouseEvent e) /*  50:    */ {
   /*  51: 88 */ TreePath path = this.tree.getPathForLocation(e.getX(), e.getY());
   /*  52: 90 */ if (path == null) {
     /*  53: 91 */ return false;
     /*  54:    */ }
   /*  55: 93 */ CategoryNode node = (CategoryNode) path.getLastPathComponent();
   /*  56: 94 */ boolean rv = false;
   /*  57:    */
   /*  58:    */
   /*  59:    */
   /*  60:    */
   /*  61:    */
   /*  62:100 */ Rectangle bounds = this.tree.getRowBounds(this.lastRow);
   /*  63:101 */ Dimension checkBoxOffset = this.renderer.getCheckBoxOffset();
   /*  64:    */
   /*  65:    */
   /*  66:104 */ bounds.translate(this.offset + checkBoxOffset.width, checkBoxOffset.height);
   /*  67:    */
   /*  68:    */
   /*  69:107 */ rv = bounds.contains(e.getPoint());
   /*  70:    */
   /*  71:109 */ return true;
   /*  72:    */ }
  public void mouseMoved(MouseEvent e) {
    if (e.getSource() instanceof MainView) {
      final MainView view = (MainView) e.getSource();
      Rectangle bounds = ((ZoomableLabelUI) view.getUI()).getIconR(view);
      Point p = e.getPoint();
      view.setCursor(Cursor.getDefaultCursor());
      if (bounds.contains(p)) {
        if (view.getIcon() instanceof MultipleImage) {
          Rectangle iconR =
              ((MultipleImage) view.getIcon())
                  .getIconR(PdfUtilitiesController.REFRESH_MONITORING_ICON);
          if (iconR != null) {
            view.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            float zoom = Controller.getCurrentController().getViewController().getZoom();
            iconR.setLocation((int) (iconR.x * zoom), iconR.y);
            iconR.setSize((int) (iconR.width * zoom), (int) (iconR.height * zoom));
            iconR.translate(bounds.x, bounds.y);
            if (iconR.contains(p)) {
              if (!showTimer.isRunning() && !hideTimer.isRunning()) {
                resetTimer();
                showTimer.addActionListener(new ShowToolTipAction(view));
                showTimer.start();
              }
              return;
            }
          } else {
            resetTimer();
          }
        } else {
          resetTimer();
        }
      }
    }

    this.mouseListener.mouseMoved(e);
  }
  public boolean expand(Writer output, Serializable object, Rule.RuleOptions options)
      throws IOException, RuleException {
    boolean expanded = false;

    try {
      DbORTableGo tableGo = (DbORTableGo) object;
      DbORDiagram diagram = (DbORDiagram) tableGo.getComposite();
      ;
      GraphicComponent gc;
      Rectangle rect;
      Point origin;

      DefaultMainFrame frame = null;
      try {
        Class claz = Class.forName("org.modelsphere.sms.MainFrame"); // NOT LOCALIZABLE
        java.lang.reflect.Method method =
            claz.getDeclaredMethod("getSingleton", new Class[] {}); // NOT LOCALIZABLE
        frame = (DefaultMainFrame) method.invoke(null, new Object[] {});
      } catch (Exception ex) {
        ex.printStackTrace(System.out);
      }
      DiagramInternalFrame diagramInternalFrame = frame.getDiagramInternalFrame(diagram);
      ApplicationDiagram appDiagram;
      boolean deleteApplicationDiagram = false;

      if (diagramInternalFrame == null) {
        DbSemanticalObject so = (DbSemanticalObject) diagram.getComposite();
        SMSToolkit kit = SMSToolkit.getToolkit(so);
        appDiagram =
            new ApplicationDiagram(
                so, diagram, kit.createGraphicalComponentFactory(), frame.getDiagramsToolGroup());
        deleteApplicationDiagram = true;
      } else {
        appDiagram = diagramInternalFrame.getDiagram();
      }

      gc = (GraphicComponent) tableGo.getGraphicPeer();
      rect = (Rectangle) gc.getRectangle().clone();
      origin =
          new Point(
              GraphicComponent.LINE_BOLD_WIDTH - appDiagram.getContentRect().x,
              GraphicComponent.LINE_BOLD_WIDTH - appDiagram.getContentRect().y);

      if (deleteApplicationDiagram) {
        appDiagram.delete();
      }

      rect.translate(origin.x, origin.y);

      if (prefixModifier != null) {
        prefixModifier.expand(output, object, options);
      }

      // write the converted text
      output.write(
          rect.x + "," + rect.y + "," + (rect.x + rect.width) + "," + (rect.y + rect.height));
      expanded = true;

      if (suffixModifier != null) {
        suffixModifier.expand(output, object, options);
      }

    } catch (DbException ex) {
      throw new RuleException(ex.getMessage());
    }

    return expanded;
  }
Пример #20
0
  private void drawStatusStrings(Graphics2D g, ArrayList<Status> statusStrings) {
    if (statusStrings.isEmpty()) return;

    // The small info blobs
    g.setFont(labelFont);

    Rectangle stR = new Rectangle(labelRect.x, labelRect.y, labelRect.height, labelRect.height);
    if (labelPos == Positioning.LEFT) {
      stR.translate(labelRect.width - labelRect.height, 0);
    }

    for (Status curStatus : statusStrings) {
      if (curStatus.small) {
        if (labelPos == Positioning.RIGHT) {
          stR.translate(-labelRect.height - 2, 0);
        } else {
          stR.translate(labelRect.height + 2, 0);
        }
        g.setColor(LABEL_BACK);
        g.fillRoundRect(stR.x, stR.y, stR.width, stR.height, 5, 5);
        if (curStatus.status == null) {
          Color damageColor = getDamageColor();
          if (damageColor != null) {
            g.setColor(damageColor);
            g.fillRoundRect(stR.x + 2, stR.y + 2, stR.width - 4, stR.height - 4, 5, 5);
          }

        } else {
          bv.drawCenteredText(
              g,
              curStatus.status,
              stR.x + stR.height * 0.5f - 0.5f,
              stR.y + stR.height * 0.5f - 2,
              curStatus.color,
              false);
        }
      }
    }

    // When zoomed far out, status wouldn't be readable, therefore
    // draw a big "!" (and the label is red)
    if (bv.scale < 0.55 && criticalStatus) {
      Font bigFont = new Font("SansSerif", Font.BOLD, (int) (42 * bv.scale));
      g.setFont(bigFont);
      Point pos = new Point(bv.hex_size.width / 2, bv.hex_size.height / 2);
      bv.drawTextShadow(g, "!", pos, bigFont);
      bv.drawCenteredText(g, "!", pos, Color.RED, false);
      return;
    }

    // Critical status text
    Font boldFont = new Font("SansSerif", Font.BOLD, (int) (12 * bv.scale));
    g.setFont(boldFont);
    int y = (int) (bv.hex_size.height * 0.6);
    for (Status curStatus : statusStrings) {
      if (!curStatus.small) { // Critical status
        bv.drawTextShadow(g, curStatus.status, new Point(bv.hex_size.width / 2, y), boldFont);
        bv.drawCenteredText(g, curStatus.status, bv.hex_size.width / 2, y, curStatus.color, false);
        y -= 14 * bv.scale;
      }
    }
  }
Пример #21
0
 public Raster getData(Rectangle rect) {
   Rectangle r = (Rectangle) rect.clone();
   r.translate(-deltaX, -deltaY);
   Raster ret = getSource().getData(r);
   return ret.createTranslatedChild(ret.getMinX() + deltaX, ret.getMinY() + deltaY);
 }
Пример #22
0
 public void translate(int dx, int dy) {
   bounds.translate(dx, dy);
 }
 public void basicMoveBy(int x, int y) {
   fDisplayBox.translate(x, y);
 }
  public void mouseClicked(MouseEvent e) {
    if (e.getButton() == MouseEvent.BUTTON1 && e.getSource() instanceof MainView) {
      MainView view = (MainView) e.getSource();
      Rectangle bounds = ((ZoomableLabelUI) view.getUI()).getIconR(view);
      Point p = e.getPoint();
      if (bounds.contains(p)) {
        if (view.getIcon() instanceof MultipleImage) {
          Rectangle iconR =
              ((MultipleImage) view.getIcon())
                  .getIconR(PdfUtilitiesController.REFRESH_MONITORING_ICON);
          if (iconR != null) {
            float zoom = Controller.getCurrentController().getViewController().getZoom();
            iconR.setLocation((int) (iconR.x * zoom), iconR.y);
            iconR.setSize((int) (iconR.width * zoom), (int) (iconR.height * zoom));
            iconR.translate(bounds.x, bounds.y);
            if (iconR.contains(p)) {
              UpdateMonitoringFolderAction.updateNodesAgainstMonitoringDir(
                  getMonitorNodes(
                      Controller.getCurrentController().getViewController().getMap().getRootNode()),
                  false);
              return;
            }
          }
        }
      }
      //			StringBuilder sb = new StringBuilder();
      //			pdfHeaderExtraction(e, sb);
    }
    boolean openOnPage =
        ResourceController.getResourceController()
            .getBooleanProperty(PdfUtilitiesController.OPEN_PDF_VIEWER_ON_PAGE_KEY);

    if (!openOnPage) {
      this.mouseListener.mouseClicked(e);
      return;
    }

    if (
    /*wasFocused() && */ (e.getModifiers() & ~(InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK))
        == InputEvent.BUTTON1_MASK) {
      final MainView component = (MainView) e.getComponent();
      final ModeController modeController = Controller.getCurrentModeController();
      NodeModel node = null;
      try {
        node = ((MainView) e.getSource()).getNodeView().getModel();
      } catch (Exception ex) {
      }

      if (node == null) {
        node = modeController.getMapController().getSelectedNode();
      }

      if (component.isInFollowLinkRegion(e.getX())) {
        writeToLog(node);
      }
      if (!component.isInFollowLinkRegion(e.getX()) || !MonitoringUtils.isPdfLinkedNode(node)) {
        this.mouseListener.mouseClicked(e);
        return;
      }

      URI uri = Tools.getAbsoluteUri(node);
      if (uri == null) {
        this.mouseListener.mouseClicked(e);
        return;
      }

      IAnnotation annotation = null;
      try {
        annotation = node.getExtension(AnnotationModel.class);
      } catch (Exception ex) {
      }

      LinkController.getController().onDeselect(node);
      if (!PdfUtilitiesController.getController().openPdfOnPage(uri, annotation)) {
        this.mouseListener.mouseClicked(e);
        return;
      }
      LinkController.getController().onSelect(node);

    } else {
      this.mouseListener.mouseClicked(e);
    }
  }
Пример #25
0
  // Coordinates are that of the target
  // Called only on Toolkit thread
  public void reshape(WindowDimensions newDimensions, int op, boolean userReshape) {
    if (insLog.isLoggable(Level.FINE)) {
      insLog.fine(
          "Reshaping "
              + this
              + " to "
              + newDimensions
              + " op "
              + op
              + " user reshape "
              + userReshape);
    }
    if (userReshape) {
      // We handle only userReshape == true cases. It means that
      // if the window manager or any other part of the windowing
      // system sets inappropriate size for this window, we can
      // do nothing but accept it.
      Rectangle reqBounds = newDimensions.getBounds();
      Rectangle newBounds =
          constrainBounds(reqBounds.x, reqBounds.y, reqBounds.width, reqBounds.height);
      Insets insets = newDimensions.getInsets();
      Rectangle clientBounds =
          new Rectangle(
              newBounds.x,
              newBounds.y,
              newBounds.width - insets.left - insets.right,
              newBounds.height - insets.top - insets.bottom);
      newDimensions =
          new WindowDimensions(
              newDimensions.isClientSizeSet() ? clientBounds : newBounds,
              insets,
              newDimensions.isClientSizeSet());
    }
    XToolkit.awtLock();
    try {
      if (!isReparented() || !isVisible()) {
        insLog.log(
            Level.FINE,
            "- not reparented({0}) or not visible({1}), default reshape",
            new Object[] {Boolean.valueOf(isReparented()), Boolean.valueOf(visible)});

        // Fix for 6323293.
        // This actually is needed to preserve compatibility with previous releases -
        // some of licensees are expecting componentMoved event on invisible one while
        // its location changes.
        Point oldLocation = getLocation();

        Point newLocation =
            new Point(
                ComponentAccessor.getX((Component) target),
                ComponentAccessor.getY((Component) target));

        if (!newLocation.equals(oldLocation)) {
          handleMoved(newDimensions);
        }

        dimensions = new WindowDimensions(newDimensions);
        updateSizeHints(dimensions);
        Rectangle client = dimensions.getClientRect();
        checkShellRect(client);
        setShellBounds(client);
        if (content != null && !content.getSize().equals(newDimensions.getSize())) {
          reconfigureContentWindow(newDimensions);
        }
        return;
      }

      int wm = XWM.getWMID();
      updateChildrenSizes();
      applyGuessedInsets();

      Rectangle shellRect = newDimensions.getClientRect();

      if (gravityBug()) {
        Insets in = newDimensions.getInsets();
        shellRect.translate(in.left, in.top);
      }

      if ((op & NO_EMBEDDED_CHECK) == 0 && isEmbedded()) {
        shellRect.setLocation(0, 0);
      }

      checkShellRectSize(shellRect);
      if (!isEmbedded()) {
        checkShellRectPos(shellRect);
      }

      op = op & ~NO_EMBEDDED_CHECK;

      if (op == SET_LOCATION) {
        setShellPosition(shellRect);
      } else if (isResizable()) {
        if (op == SET_BOUNDS) {
          setShellBounds(shellRect);
        } else {
          setShellSize(shellRect);
        }
      } else {
        XWM.setShellNotResizable(this, newDimensions, shellRect, true);
        if (op == SET_BOUNDS) {
          setShellPosition(shellRect);
        }
      }

      reconfigureContentWindow(newDimensions);
    } finally {
      XToolkit.awtUnlock();
    }
  }
Пример #26
0
  public void write(IIOMetadata streamMetadata, IIOImage image, ImageWriteParam param)
      throws IOException {
    if (stream == null) {
      throw new IllegalStateException(I18N.getString("WBMPImageWriter3"));
    }

    if (image == null) {
      throw new IllegalArgumentException(I18N.getString("WBMPImageWriter4"));
    }

    clearAbortRequest();
    processImageStarted(0);
    if (param == null) param = getDefaultWriteParam();

    RenderedImage input = null;
    Raster inputRaster = null;
    boolean writeRaster = image.hasRaster();
    Rectangle sourceRegion = param.getSourceRegion();
    SampleModel sampleModel = null;

    if (writeRaster) {
      inputRaster = image.getRaster();
      sampleModel = inputRaster.getSampleModel();
    } else {
      input = image.getRenderedImage();
      sampleModel = input.getSampleModel();

      inputRaster = input.getData();
    }

    checkSampleModel(sampleModel);
    if (sourceRegion == null) sourceRegion = inputRaster.getBounds();
    else sourceRegion = sourceRegion.intersection(inputRaster.getBounds());

    if (sourceRegion.isEmpty()) throw new RuntimeException(I18N.getString("WBMPImageWriter1"));

    int scaleX = param.getSourceXSubsampling();
    int scaleY = param.getSourceYSubsampling();
    int xOffset = param.getSubsamplingXOffset();
    int yOffset = param.getSubsamplingYOffset();

    sourceRegion.translate(xOffset, yOffset);
    sourceRegion.width -= xOffset;
    sourceRegion.height -= yOffset;

    int minX = sourceRegion.x / scaleX;
    int minY = sourceRegion.y / scaleY;
    int w = (sourceRegion.width + scaleX - 1) / scaleX;
    int h = (sourceRegion.height + scaleY - 1) / scaleY;

    Rectangle destinationRegion = new Rectangle(minX, minY, w, h);
    sampleModel = sampleModel.createCompatibleSampleModel(w, h);

    SampleModel destSM = sampleModel;

    // If the data are not formatted nominally then reformat.
    if (sampleModel.getDataType() != DataBuffer.TYPE_BYTE
        || !(sampleModel instanceof MultiPixelPackedSampleModel)
        || ((MultiPixelPackedSampleModel) sampleModel).getDataBitOffset() != 0) {
      destSM = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, w, h, 1, w + 7 >> 3, 0);
    }

    if (!destinationRegion.equals(sourceRegion)) {
      if (scaleX == 1 && scaleY == 1)
        inputRaster =
            inputRaster.createChild(
                inputRaster.getMinX(), inputRaster.getMinY(), w, h, minX, minY, null);
      else {
        WritableRaster ras = Raster.createWritableRaster(destSM, new Point(minX, minY));

        byte[] data = ((DataBufferByte) ras.getDataBuffer()).getData();

        for (int j = minY, y = sourceRegion.y, k = 0; j < minY + h; j++, y += scaleY) {

          for (int i = 0, x = sourceRegion.x; i < w; i++, x += scaleX) {
            int v = inputRaster.getSample(x, y, 0);
            data[k + (i >> 3)] |= v << (7 - (i & 7));
          }
          k += w + 7 >> 3;
        }
        inputRaster = ras;
      }
    }

    // If the data are not formatted nominally then reformat.
    if (!destSM.equals(inputRaster.getSampleModel())) {
      WritableRaster raster =
          Raster.createWritableRaster(
              destSM, new Point(inputRaster.getMinX(), inputRaster.getMinY()));
      raster.setRect(inputRaster);
      inputRaster = raster;
    }

    // Check whether the image is white-is-zero.
    boolean isWhiteZero = false;
    if (!writeRaster && input.getColorModel() instanceof IndexColorModel) {
      IndexColorModel icm = (IndexColorModel) input.getColorModel();
      isWhiteZero = icm.getRed(0) > icm.getRed(1);
    }

    // Get the line stride, bytes per row, and data array.
    int lineStride = ((MultiPixelPackedSampleModel) destSM).getScanlineStride();
    int bytesPerRow = (w + 7) / 8;
    byte[] bdata = ((DataBufferByte) inputRaster.getDataBuffer()).getData();

    // Write WBMP header.
    stream.write(0); // TypeField
    stream.write(0); // FixHeaderField
    stream.write(intToMultiByte(w)); // width
    stream.write(intToMultiByte(h)); // height

    // Write the data.
    if (!isWhiteZero && lineStride == bytesPerRow) {
      // Write the entire image.
      stream.write(bdata, 0, h * bytesPerRow);
      processImageProgress(100.0F);
    } else {
      // Write the image row-by-row.
      int offset = 0;
      if (!isWhiteZero) {
        // Black-is-zero
        for (int row = 0; row < h; row++) {
          if (abortRequested()) break;
          stream.write(bdata, offset, bytesPerRow);
          offset += lineStride;
          processImageProgress(100.0F * row / h);
        }
      } else {
        // White-is-zero: need to invert data.
        byte[] inverted = new byte[bytesPerRow];
        for (int row = 0; row < h; row++) {
          if (abortRequested()) break;
          for (int col = 0; col < bytesPerRow; col++) {
            inverted[col] = (byte) (~(bdata[col + offset]));
          }
          stream.write(inverted, 0, bytesPerRow);
          offset += lineStride;
          processImageProgress(100.0F * row / h);
        }
      }
    }

    if (abortRequested()) processWriteAborted();
    else {
      processImageComplete();
      stream.flushBefore(stream.getStreamPosition());
    }
  }
Пример #27
0
  /**
   * Paint the image onto a Graphics object. The painting is performed tile-by-tile, and includes a
   * grey region covering the unused portion of image tiles as well as the general background. At
   * this point the image must be byte data.
   */
  public synchronized void paintComponent(Graphics g) {

    Graphics2D g2D = null;
    if (g instanceof Graphics2D) {
      g2D = (Graphics2D) g;
    } else {
      return;
    }

    // if source is null, it's just a component
    if (source == null) {
      g2D.setColor(getBackground());
      g2D.fillRect(0, 0, componentWidth, componentHeight);
      return;
    }

    int transX = -originX;
    int transY = -originY;

    // Get the clipping rectangle and translate it into image coordinates.
    Rectangle clipBounds = g.getClipBounds();

    if (clipBounds == null) {
      clipBounds = new Rectangle(0, 0, componentWidth, componentHeight);
    }

    // clear the background (clip it) [minimal optimization here]
    if (transX > 0
        || transY > 0
        || transX < (componentWidth - source.getWidth())
        || transY < (componentHeight - source.getHeight())) {
      g2D.setColor(getBackground());
      g2D.fillRect(0, 0, componentWidth, componentHeight);
    }

    clipBounds.translate(-transX, -transY);

    // Determine the extent of the clipping region in tile coordinates.
    int txmin, txmax, tymin, tymax;
    int ti, tj;

    txmin = XtoTileX(clipBounds.x);
    txmin = Math.max(txmin, minTileX);
    txmin = Math.min(txmin, maxTileX);

    txmax = XtoTileX(clipBounds.x + clipBounds.width - 1);
    txmax = Math.max(txmax, minTileX);
    txmax = Math.min(txmax, maxTileX);

    tymin = YtoTileY(clipBounds.y);
    tymin = Math.max(tymin, minTileY);
    tymin = Math.min(tymin, maxTileY);

    tymax = YtoTileY(clipBounds.y + clipBounds.height - 1);
    tymax = Math.max(tymax, minTileY);
    tymax = Math.min(tymax, maxTileY);
    Insets insets = getInsets();

    // Loop over tiles within the clipping region
    for (tj = tymin; tj <= tymax; tj++) {
      for (ti = txmin; ti <= txmax; ti++) {
        int tx = TileXtoX(ti);
        int ty = TileYtoY(tj);

        Raster tile = source.getTile(ti, tj);
        if (tile != null) {
          DataBuffer dataBuffer = tile.getDataBuffer();

          WritableRaster wr = tile.createWritableRaster(sampleModel, dataBuffer, null);

          BufferedImage bi =
              new BufferedImage(colorModel, wr, colorModel.isAlphaPremultiplied(), null);

          // correctly handles band offsets
          if (brightnessEnabled == true) {
            SampleModel sm =
                sampleModel.createCompatibleSampleModel(tile.getWidth(), tile.getHeight());

            WritableRaster raster = RasterFactory.createWritableRaster(sm, null);

            BufferedImage bimg =
                new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);

            // don't move this code
            ByteLookupTable lutTable = new ByteLookupTable(0, lutData);
            LookupOp lookup = new LookupOp(lutTable, null);
            lookup.filter(bi, bimg);

            g2D.drawImage(bimg, biop, tx + transX + insets.left, ty + transY + insets.top);
          } else {
            AffineTransform transform;

            transform =
                AffineTransform.getTranslateInstance(
                    tx + transX + insets.left, ty + transY + insets.top);

            g2D.drawRenderedImage(bi, transform);
          }
        }
      }
    }
  }
Пример #28
0
 public Rectangle getViewBounds(Rectangle r) {
   r = getBounds(r);
   r.translate(getPanel().getX() + getParent().getX(), getPanel().getY() + getParent().getY());
   return r;
 }