Ejemplo n.º 1
0
 /** Attempt to find the editor keystroke for the given action. */
 private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey) {
   KeyStroke[] ret = new KeyStroke[] {defaultKey};
   JTextComponent comp = getComponent();
   if (editorActionName != null && comp != null) {
     TextUI textUI = comp.getUI();
     Keymap km = comp.getKeymap();
     if (textUI != null && km != null) {
       EditorKit kit = textUI.getEditorKit(comp);
       if (kit instanceof BaseKit) {
         Action a = ((BaseKit) kit).getActionByName(editorActionName);
         if (a != null) {
           KeyStroke[] keys = km.getKeyStrokesForAction(a);
           if (keys != null && keys.length > 0) {
             ret = keys;
           } else {
             // try kit's keymap
             Keymap km2 = ((BaseKit) kit).getKeymap();
             KeyStroke[] keys2 = km2.getKeyStrokesForAction(a);
             if (keys2 != null && keys2.length > 0) {
               ret = keys2;
             }
           }
         }
       }
     }
   }
   return ret;
 }
    /**
     * Paints a highlight.
     *
     * @param g the graphics context
     * @param offs0 the starting model offset >= 0
     * @param offs1 the ending model offset >= offs1
     * @param bounds the bounding box for the highlight
     * @param c the editor
     */
    public void paint(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c) {
      Rectangle alloc = bounds.getBounds();
      try {
        // --- determine locations ---
        TextUI mapper = c.getUI();
        Rectangle p0 = mapper.modelToView(c, offs0);
        Rectangle p1 = mapper.modelToView(c, offs1);

        // --- render ---
        Color color = getColor();

        if (color == null) {
          g.setColor(c.getSelectionColor());
        } else {
          g.setColor(color);
        }
        if (p0.y == p1.y) {
          // same line, render a rectangle
          Rectangle r = p0.union(p1);
          g.fillRect(r.x, r.y, r.width, r.height);
        } else {
          // different lines
          int p0ToMarginWidth = alloc.x + alloc.width - p0.x;
          g.fillRect(p0.x, p0.y, p0ToMarginWidth, p0.height);
          if ((p0.y + p0.height) != p1.y) {
            g.fillRect(alloc.x, p0.y + p0.height, alloc.width, p1.y - (p0.y + p0.height));
          }
          g.fillRect(alloc.x, p1.y, (p1.x - alloc.x), p1.height);
        }
      } catch (BadLocationException e) {
        // can't render
      }
    }
Ejemplo n.º 3
0
 /*     */ public void paint(Graphics paramGraphics) /*     */ {
   /* 127 */ if (isVisible())
     /*     */ try {
       /* 129 */ JTextComponent localJTextComponent = getComponent();
       /* 130 */ Color localColor =
           localJTextComponent.hasFocus()
               ? localJTextComponent.getCaretColor()
               : localJTextComponent.getDisabledTextColor();
       /*     */
       /* 132 */ TextUI localTextUI = localJTextComponent.getUI();
       /* 133 */ int i = getDot();
       /* 134 */ Rectangle localRectangle = localTextUI.modelToView(localJTextComponent, i);
       /* 135 */ int j = localRectangle.x - 2;
       /* 136 */ int k = localRectangle.x + 2;
       /* 137 */ int m = localRectangle.y + 1;
       /* 138 */ int n = localRectangle.y + localRectangle.height - 2;
       /* 139 */ paramGraphics.setColor(localColor);
       /* 140 */ paramGraphics.drawLine(localRectangle.x, m, localRectangle.x, n);
       /* 141 */ paramGraphics.drawLine(j, m, k, m);
       /* 142 */ paramGraphics.drawLine(j, n, k, n);
       /*     */ }
     /*     */ catch (BadLocationException localBadLocationException)
     /*     */ {
       /*     */ }
   /*     */ }
Ejemplo n.º 4
0
  public static void paintAboveline(Graphics g, JTextComponent tc, int pos0, int pos1)
      throws BadLocationException {
    g.setColor(Color.GREEN.darker());
    TextUI ui = tc.getUI();
    Rectangle r = ui.modelToView(tc, pos1 + 1);
    int h = r.y;

    int max = r.x - 2 + 1;
    int current = ui.modelToView(tc, pos0).x - 1;
    g.drawLine(current, h, max, h);
    g.drawLine(current, h + 1, current, h + 2);
    g.drawLine(max, h + 1, max, h + 2);
  }
Ejemplo n.º 5
0
  public static void paintUnderline(Graphics g, JTextComponent tc, int pos0, int pos1)
      throws BadLocationException {
    g.setColor(Color.RED);
    TextUI ui = tc.getUI();
    Rectangle r = ui.modelToView(tc, pos1 + 1);
    int h = r.y + r.height - 2;

    int max = r.x - 2;
    int current = ui.modelToView(tc, pos0).x;
    while (current <= max) {
      g.drawLine(current, h, Math.min(current + 2, max), h + 1);
      current += 3;
      if (current <= max) {
        g.drawLine(current, h, Math.min(current + 2, max), h);
        current += 3;
      }
    }
  }
    /** Executes range(s) damage and cleans range queue. */
    public synchronized void run() {
      if (component != null) {
        TextUI mapper = component.getUI();
        if (mapper != null && lastDoc == component.getDocument()) {
          // the Document should be the same to properly
          // display highlights
          int len = p0.size();
          for (int i = 0; i < len; i++) {
            mapper.damageRange(component, p0.get(i).getOffset(), p1.get(i).getOffset());
          }
        }
      }
      p0.clear();
      p1.clear();

      // release reference
      lastDoc = null;
    }