Пример #1
0
  @Override
  public void focusGained(final FocusEvent e) {
    final JTextComponent component = getComponent();
    if (!component.isEnabled() || !component.isEditable()) {
      super.focusGained(e);
      return;
    }

    mFocused = true;
    if (!shouldSelectAllOnFocus) {
      shouldSelectAllOnFocus = true;
      super.focusGained(e);
      return;
    }

    if (isMultiLineEditor) {
      super.focusGained(e);
      return;
    }

    final int end = component.getDocument().getLength();
    final int dot = getDot();
    final int mark = getMark();
    if (dot == mark) {
      if (dot == 0) {
        component.setCaretPosition(end);
        component.moveCaretPosition(0);
      } else if (dot == end) {
        component.setCaretPosition(0);
        component.moveCaretPosition(end);
      }
    }

    super.focusGained(e);
  }
Пример #2
0
 public void focusGained(FocusEvent e) {
   inModalMode = true;
   if (debug) System.out.println("gained focus");
   setBlinkRate(500);
   // setCaretValue(caretValue);
   super.focusGained(e);
 }
Пример #3
0
 // This fixes the problem where when on the mac you have to ctrl left click to
 // get popup triggers the caret has code that only looks at button number.
 // see radar # 3125390
 @Override
 public void mousePressed(final MouseEvent e) {
   if (!e.isPopupTrigger()) {
     super.mousePressed(e);
     shouldSelectAllOnFocus = false;
   }
 }
Пример #4
0
  @Override
  protected void fireStateChanged() {
    // If we have focus the caret should only flash if the range length is zero
    if (mFocused) setVisible(getComponent().isEditable());

    super.fireStateChanged();
  }
Пример #5
0
 // See <rdar://problem/3833837> 1.4.2_05-141.3: JTextField performance with
 // Aqua L&F. We are getting into a circular condition with the BasicCaret
 // paint code since it doesn't know about the fact that our damage routine
 // above elminates the border. Sadly we can't easily change either one, so
 // we will add a painting flag and not damage during a repaint.
 @Override
 public void paint(final Graphics g) {
   if (isVisible()) {
     fPainting = true;
     super.paint(g);
     fPainting = false;
   }
 }
Пример #6
0
 @Override
 public void focusLost(final FocusEvent e) {
   mFocused = false;
   shouldSelectAllOnFocus = true;
   if (isMultiLineEditor) {
     setVisible(false);
     getComponent().repaint();
   } else {
     super.focusLost(e);
   }
 }
Пример #7
0
  private void setCaretValue(int i) {

    caret.setVisible(true);

    caretValue = i;
    int min = 0;
    int max = getText().length();

    if (i < min) i = min;
    if (i > max) i = max;

    if (debug) System.out.println("setSelectionStart: " + i);
    setSelectionStart(i);
    setSelectionEnd(i);
  }
Пример #8
0
 public LineCursorTextArea() {
   super();
   caret =
       new DefaultCaret() {
         @Override
         protected synchronized void damage(Rectangle r) {
           if (r != null) {
             JTextComponent c = getComponent();
             x = 0;
             y = r.y;
             width = c.getSize().width;
             height = r.height;
             c.repaint();
           }
         }
       };
   caret.setBlinkRate(getCaret().getBlinkRate());
   setCaret(caret);
 }
Пример #9
0
 /** Only show the flashing caret if the selection range is zero */
 @Override
 public void setVisible(boolean e) {
   if (e) e = getDot() == getMark();
   super.setVisible(e);
 }
Пример #10
0
 @Override
 public void deinstall(final JTextComponent c) {
   c.removePropertyChangeListener(this);
   super.deinstall(c);
 }
Пример #11
0
 @Override
 public void install(final JTextComponent c) {
   super.install(c);
   isMultiLineEditor = c instanceof JTextArea || c instanceof JEditorPane;
   c.addPropertyChangeListener(this);
 }
  /**
   * Constructs a X509 certificate panel.
   *
   * @param certificates <tt>X509Certificate</tt> objects
   */
  public X509CertificatePanel(Certificate[] certificates) {
    setLayout(new BorderLayout(5, 5));

    // Certificate chain list
    TransparentPanel topPanel = new TransparentPanel(new BorderLayout());
    topPanel.add(
        new JLabel(
            "<html><body><b>"
                + R.getI18NString("service.gui.CERT_INFO_CHAIN")
                + "</b></body></html>"),
        BorderLayout.NORTH);

    DefaultMutableTreeNode top = new DefaultMutableTreeNode();
    DefaultMutableTreeNode previous = top;
    for (int i = certificates.length - 1; i >= 0; i--) {
      Certificate cert = certificates[i];
      DefaultMutableTreeNode next = new DefaultMutableTreeNode(cert);
      previous.add(next);
      previous = next;
    }
    JTree tree = new JTree(top);
    tree.setBorder(new BevelBorder(BevelBorder.LOWERED));
    tree.setRootVisible(false);
    tree.setExpandsSelectedPaths(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setCellRenderer(
        new DefaultTreeCellRenderer() {

          @Override
          public Component getTreeCellRendererComponent(
              JTree tree,
              Object value,
              boolean sel,
              boolean expanded,
              boolean leaf,
              int row,
              boolean hasFocus) {
            JLabel component =
                (JLabel)
                    super.getTreeCellRendererComponent(
                        tree, value, sel, expanded, leaf, row, hasFocus);
            if (value instanceof DefaultMutableTreeNode) {
              Object o = ((DefaultMutableTreeNode) value).getUserObject();
              if (o instanceof X509Certificate) {
                component.setText(getSimplifiedName((X509Certificate) o));
              } else {
                // We don't know how to represent this certificate type,
                // let's use the first 20 characters
                String text = o.toString();
                if (text.length() > 20) {
                  text = text.substring(0, 20);
                }
                component.setText(text);
              }
            }
            return component;
          }
        });
    tree.getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {

              @Override
              public void valueChanged(TreeSelectionEvent e) {
                valueChangedPerformed(e);
              }
            });
    tree.setSelectionPath(
        new TreePath((((DefaultTreeModel) tree.getModel()).getPathToRoot(previous))));
    topPanel.add(tree, BorderLayout.CENTER);

    add(topPanel, BorderLayout.NORTH);

    // Certificate details pane
    Caret caret = infoTextPane.getCaret();
    if (caret instanceof DefaultCaret) {
      ((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    }

    /*
     * Make JEditorPane respect our default font because we will be using it
     * to just display text.
     */
    infoTextPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);

    infoTextPane.setOpaque(false);
    infoTextPane.setEditable(false);
    infoTextPane.setContentType("text/html");
    infoTextPane.setText(toString(certificates[0]));

    final JScrollPane certScroll = new JScrollPane(infoTextPane);
    certScroll.setPreferredSize(new Dimension(300, 500));
    add(certScroll, BorderLayout.CENTER);
  }