Example #1
1
  public String getTextForGesture(long parId, Point topLeft, Point bottomRight) {

    try {
      Paragraph p = lockManager.getParFromId(parId);

      int parY = documentPanel.textPane.modelToView(p.getOffset()).y;

      topLeft.y = topLeft.y + parY;
      bottomRight.y = bottomRight.y + parY;

      int startOffset = documentPanel.textPane.viewToModel(topLeft);
      int endOffset = documentPanel.textPane.viewToModel(bottomRight);

      while (startOffset > 0
          && Character.isLetterOrDigit((document.getText(startOffset - 1, 1).charAt(0))))
        startOffset--;

      while (endOffset < document.getLength()
          && Character.isLetterOrDigit((document.getText(endOffset, 1).charAt(0)))) endOffset++;

      String text = document.getText(startOffset, endOffset - startOffset);
      return text;
    } catch (Exception e) {
      System.out.println("EditorClient: addGestureAction. error identifying text");
      e.printStackTrace();
      return "";
    }

    // return "PLACEBO";
  }
Example #2
0
 // ------------------------------
 public void
     scrollToCaret() { // not called - fixed with putting visible scrollbars on JScrollPane
   //
   Rectangle rect1 = scroller1.getViewport().getViewRect();
   double x1 = rect1.getX();
   double y1 = rect1.getY();
   double r1height = rect1.getHeight();
   double r1width = rect1.getWidth();
   Caret caret1 = editor1.getCaret();
   Point pt2 = caret1.getMagicCaretPosition(); // the end of the string
   double x2 = pt2.getX();
   double y2 = pt2.getY();
   if (((x2 > x1) && (x2 < (x1 + r1width))) && ((y2 > y1) && (y2 < (y1 + r1height)))) {
     // inview
   } else {
     double newheight = r1height / 2;
     double newwidth = r1width / 2;
     double x3 = pt2.getX() - newwidth;
     double y3 = pt2.getY() - newheight;
     if (x3 < 0) x3 = 0;
     if (y3 < 0) y3 = 0;
     Rectangle rect3 = new Rectangle((int) x3, (int) y3, (int) newwidth, (int) newheight);
     editor1.scrollRectToVisible(rect3);
   }
 } // end scrollToCaret
Example #3
0
 public Point getLocation() {
   if (inEditMode) {
     tmpLoc.x = defLoc.x;
     tmpLoc.y = defLoc.y;
   } else {
     tmpLoc.x = curLoc.x;
     tmpLoc.y = curLoc.y;
   }
   return tmpLoc;
 }
Example #4
0
 public void setSizeRatio(double x, double y) {
   xRatio = x;
   yRatio = y;
   if (x > 1.0) xRatio = x - 1.0;
   if (y > 1.0) yRatio = y - 1.0;
   if (defDim.width <= 0) defDim = getPreferredSize();
   curLoc.x = (int) ((double) defLoc.x * xRatio);
   curLoc.y = (int) ((double) defLoc.y * yRatio);
   curDim.width = (int) ((double) defDim.width * xRatio);
   curDim.height = (int) ((double) defDim.height * yRatio);
   if (!inEditMode) setBounds(curLoc.x, curLoc.y, curDim.width, curDim.height);
 }
Example #5
0
 public void reshape(int x, int y, int w, int h) {
   if (inEditMode) {
     defLoc.x = x;
     defLoc.y = y;
     defDim.width = w;
     defDim.height = h;
   }
   curLoc.x = x;
   curLoc.y = y;
   curDim.width = w;
   curDim.height = h;
   if (!inEditMode) {
     if ((h != nHeight) || (h < rHeight)) {
       adjustFont(w, h);
     }
   }
   super.reshape(x, y, w, h);
 }
Example #6
0
  /** Used internally */
  public void addNotify() {
    // Record the size of the window prior to calling parents addNotify.
    Dimension d = getSize();

    super.addNotify();

    if (fComponentsAdjusted) return;

    // Adjust components according to the insets
    Insets ins = getInsets();
    setSize(ins.left + ins.right + d.width, ins.top + ins.bottom + d.height);
    Component components[] = getContentPane().getComponents();
    for (int i = 0; i < components.length; i++) {
      Point p = components[i].getLocation();
      p.translate(ins.left, ins.top);
      components[i].setLocation(p);
    }
    fComponentsAdjusted = true;
  }
Example #7
0
  public void btnChoose_actionPerformed() {
    //            java.awt.Rectangle r = dateField.getBounds();
    //            Point pOnScreen = dateField.getLocationOnScreen();
    java.awt.Rectangle r = Jtext.getBounds();
    Point pOnScreen = Jtext.getLocationOnScreen();

    Point result = new Point(pOnScreen.x, pOnScreen.y + r.height);
    Point powner = owner.getLocation();
    int offsetX = (pOnScreen.x + width) - (powner.x + owner.getWidth());
    int offsetY = (pOnScreen.y + r.height + height) - (powner.y + owner.getHeight());

    if (offsetX > 0) {
      result.x -= offsetX;
    }

    if (offsetY > 0) {
      result.y -= height + r.height;
    }

    javax.swing.JDialog dateFrame = new javax.swing.JDialog();
    dateFrame.setModal(false);
    dateFrame.setUndecorated(true);
    dateFrame.setLocation(result);
    dateFrame.setSize(width, height);

    dateFrame.addWindowListener(
        new WindowAdapter() {
          // 鍦ㄤ换鎰忕殑闈炴棩鏈熼�夋嫨鍖哄崟鍑伙紝鍒欐棩鏈熼�夋嫨缁勪欢灏嗗彉涓洪潪娲诲姩鐘舵�侊紝鑷姩閲婃斁璧勬簮銆�
          public void windowDeactivated(WindowEvent e) {
            javax.swing.JDialog f = (javax.swing.JDialog) e.getSource();
            f.dispose();
          }
        });
    DatePanel datePanel = new DatePanel(dateFrame, parten);
    dateFrame.getContentPane().setLayout(new BorderLayout());
    dateFrame.getContentPane().add(datePanel);
    dateFrame.setVisible(true);
  }
Example #8
0
 public void setEditMode(boolean s) {
   if (s) {
     addMouseListener(ml);
     setOpaque(s);
     if (font != null) {
       setFont(font);
       fontH = font.getSize();
       rHeight = fontH;
     }
     defDim = getPreferredSize();
     curLoc.x = defLoc.x;
     curLoc.y = defLoc.y;
     curDim.width = defDim.width;
     curDim.height = defDim.height;
     xRatio = 1.0;
     yRatio = 1.0;
   } else {
     removeMouseListener(ml);
     if ((bg != null) || (isActive < 1)) setOpaque(true);
     else setOpaque(false);
   }
   inEditMode = s;
 }
  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Dimension asz = this.getSize();

    if (fullRefresh) {
      g2.clearRect(0, 0, asz.width, asz.height);
      fullRefresh = false;
    }
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    big.setColor(Color.black);
    offset.x = (int) (asz.width - iw) / 2;
    offset.y = (int) (asz.height - ih) / 2;
    big.drawImage(img, 0, 0, this);
    big.setPaint(Color.red);
    if ((rect.width > 0) && (rect.height > 0)) big.draw(rect);
    if (selected == 1) shadeExt(big, 0, 0, 0, 64);
    else if (selected == 2) {
      shadeExt(big, 0, 0, 0, 255);
      selected = 1;
    }
    g2.drawImage(bi, offset.x, offset.y, this);
  }
    public void mouseDragged(MouseEvent ev) {
      Window w = (Window) ev.getSource();
      Point pt = ev.getPoint();

      if (isMovingWindow) {
        Point windowPt;
        try {
          windowPt = (Point) AccessController.doPrivileged(getLocationAction);
          windowPt.x = windowPt.x - dragOffsetX;
          windowPt.y = windowPt.y - dragOffsetY;
          w.setLocation(windowPt);
        } catch (PrivilegedActionException e) {
        }
      } else if (dragCursor != 0) {
        Rectangle r = w.getBounds();
        Rectangle startBounds = new Rectangle(r);
        Dimension min = w.getMinimumSize();

        switch (dragCursor) {
          case Cursor.E_RESIZE_CURSOR:
            adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, 0);
            break;
          case Cursor.S_RESIZE_CURSOR:
            adjust(r, min, 0, 0, 0, pt.y + (dragHeight - dragOffsetY) - r.height);
            break;
          case Cursor.N_RESIZE_CURSOR:
            adjust(r, min, 0, pt.y - dragOffsetY, 0, -(pt.y - dragOffsetY));
            break;
          case Cursor.W_RESIZE_CURSOR:
            adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), 0);
            break;
          case Cursor.NE_RESIZE_CURSOR:
            adjust(
                r,
                min,
                0,
                pt.y - dragOffsetY,
                pt.x + (dragWidth - dragOffsetX) - r.width,
                -(pt.y - dragOffsetY));
            break;
          case Cursor.SE_RESIZE_CURSOR:
            adjust(
                r,
                min,
                0,
                0,
                pt.x + (dragWidth - dragOffsetX) - r.width,
                pt.y + (dragHeight - dragOffsetY) - r.height);
            break;
          case Cursor.NW_RESIZE_CURSOR:
            adjust(
                r,
                min,
                pt.x - dragOffsetX,
                pt.y - dragOffsetY,
                -(pt.x - dragOffsetX),
                -(pt.y - dragOffsetY));
            break;
          case Cursor.SW_RESIZE_CURSOR:
            adjust(
                r,
                min,
                pt.x - dragOffsetX,
                0,
                -(pt.x - dragOffsetX),
                pt.y + (dragHeight - dragOffsetY) - r.height);
            break;
          default:
            break;
        }
        if (!r.equals(startBounds)) {
          w.setBounds(r);
          // Defer repaint/validate on mouseReleased unless dynamic
          // layout is active.
          if (Toolkit.getDefaultToolkit().isDynamicLayoutActive()) {
            w.validate();
            getRootPane().repaint();
          }
        }
      }
    }
 public void setPopupLocation(Point location) {
   setPopupLocation((int) location.getX(), (int) location.getY());
 }
Example #12
0
 public Point getDefLoc() {
   tmpLoc.x = defLoc.x;
   tmpLoc.y = defLoc.y;
   return tmpLoc;
 }
Example #13
0
 public void setDefLoc(int x, int y) {
   defLoc.x = x;
   defLoc.y = y;
 }
    /**
     * Paints the border for the specified component with the specified position and size.
     *
     * @param c the component for which this border is being painted
     * @param g the paint graphics
     * @param x the x position of the painted border
     * @param y the y position of the painted border
     * @param width the width of the painted border
     * @param height the height of the painted border
     */
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {

      Border border = getBorder();

      if (label == null) {
        if (border != null) {
          border.paintBorder(c, g, x, y, width, height);
        }
        return;
      }

      Rectangle grooveRect =
          new Rectangle(
              x + EDGE_SPACING,
              y + EDGE_SPACING,
              width - (EDGE_SPACING * 2),
              height - (EDGE_SPACING * 2));

      Dimension labelDim = label.getPreferredSize();
      int baseline = label.getBaseline(labelDim.width, labelDim.height);
      int ascent = Math.max(0, baseline);
      int descent = labelDim.height - ascent;
      int diff;
      Insets insets;

      if (border != null) {
        insets = border.getBorderInsets(c);
      } else {
        insets = new Insets(0, 0, 0, 0);
      }

      diff = Math.max(0, ascent / 2 + TEXT_SPACING - EDGE_SPACING);
      grooveRect.y += diff;
      grooveRect.height -= diff;
      compLoc.y = grooveRect.y + insets.top / 2 - (ascent + descent) / 2 - 1;

      int justification;
      if (c.getComponentOrientation().isLeftToRight()) {
        justification = LEFT;
      } else {
        justification = RIGHT;
      }

      switch (justification) {
        case LEFT:
          compLoc.x = grooveRect.x + TEXT_INSET_H + insets.left;
          break;
        case RIGHT:
          compLoc.x =
              (grooveRect.x + grooveRect.width - (labelDim.width + TEXT_INSET_H + insets.right));
          break;
      }

      // If title is positioned in middle of border AND its fontsize
      // is greater than the border's thickness, we'll need to paint
      // the border in sections to leave space for the component's background
      // to show through the title.
      //
      if (border != null) {
        if (grooveRect.y > compLoc.y - ascent) {
          Rectangle clipRect = new Rectangle();

          // save original clip
          Rectangle saveClip = g.getClipBounds();

          // paint strip left of text
          clipRect.setBounds(saveClip);
          if (computeIntersection(clipRect, x, y, compLoc.x - 1 - x, height)) {
            g.setClip(clipRect);
            border.paintBorder(
                c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
          }

          // paint strip right of text
          clipRect.setBounds(saveClip);
          if (computeIntersection(
              clipRect,
              compLoc.x + labelDim.width + 1,
              y,
              x + width - (compLoc.x + labelDim.width + 1),
              height)) {
            g.setClip(clipRect);
            border.paintBorder(
                c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
          }

          // paint strip below text
          clipRect.setBounds(saveClip);
          if (computeIntersection(
              clipRect,
              compLoc.x - 1,
              compLoc.y + ascent + descent,
              labelDim.width + 2,
              y + height - compLoc.y - ascent - descent)) {
            g.setClip(clipRect);
            border.paintBorder(
                c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
          }

          // restore clip
          g.setClip(saveClip);

        } else {
          border.paintBorder(c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
        }

        label.setLocation(compLoc);
        label.setSize(labelDim);
      }
    }