javax.swing.text.JTextComponent#getParent ( )源码实例Demo

下面列出了javax.swing.text.JTextComponent#getParent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: FlatLaf   文件: FlatTextFieldUI.java
static void paintPlaceholder( Graphics g, JTextComponent c, Color placeholderForeground ) {
	// check whether text component is empty
	if( c.getDocument().getLength() > 0 )
		return;

	// check for JComboBox
	Container parent = c.getParent();
	JComponent jc = (parent instanceof JComboBox) ? (JComboBox<?>) parent : c;

	// get placeholder text
	Object placeholder = jc.getClientProperty( FlatClientProperties.PLACEHOLDER_TEXT );
	if( !(placeholder instanceof String) )
		return;

	// compute placeholder location
	Insets insets = c.getInsets();
	FontMetrics fm = c.getFontMetrics( c.getFont() );
	int x = insets.left;
	int y = insets.top + fm.getAscent() + ((c.getHeight() - insets.top - insets.bottom - fm.getHeight()) / 2);

	// paint placeholder
	g.setColor( placeholderForeground );
	FlatUIUtils.drawString( c, g, (String) placeholder, x, y );
}
 
源代码2 项目: consulo   文件: DarculaTextFieldUI.java
@Override
protected void paintBackground(Graphics g) {
  JTextComponent component = getComponent();
  if (component != null) {
    Container parent = component.getParent();
    if (parent != null && component.isOpaque()) {
      g.setColor(parent.getBackground());
      g.fillRect(0, 0, component.getWidth(), component.getHeight());
    }

    if (component.getBorder() instanceof DarculaTextBorder && !DarculaUIUtil.isTableCellEditor(component)) {
      paintDarculaBackground(g, component);
    }
    else if (component.isOpaque()) {
      super.paintBackground(g);
    }
  }
}
 
源代码3 项目: consulo   文件: MacIntelliJTextFieldUI.java
@Override
protected void paintBackground(Graphics graphics) {
  Graphics2D g = (Graphics2D)graphics;
  final JTextComponent c = getComponent();
  final Container parent = c.getParent();
  final Rectangle r = getDrawingRect();
  if (c.isOpaque() && parent != null) {
    g.setColor(parent.getBackground());
    g.fillRect(0, 0, c.getWidth(), c.getHeight());
  }

  if (isSearchField(c)) {
    paintSearchField(g, c, r);
  }
  else {
    if (c.getBorder() instanceof MacIntelliJTextBorder) {
      g.setColor(c.getBackground());
      g.fillRect(JBUI.scale(3), JBUI.scale(3), c.getWidth() - JBUI.scale(6), c.getHeight() - JBUI.scale(6));
    }
    else {
      super.paintBackground(g);
    }
  }
}
 
源代码4 项目: netbeans   文件: HintsUI.java
private int getUsableWidth(JTextComponent component) {
    Container parent = component.getParent();
    if (parent instanceof JLayeredPane) {
        parent = parent.getParent();
    }
    return (parent instanceof JViewport)
        ? ((JViewport)parent).getExtentSize().width
        : component.getSize().width;
}
 
源代码5 项目: netbeans   文件: BraceMatchingSidebarComponent.java
@SuppressWarnings("LeakingThisInConstructor")
public BraceMatchingSidebarComponent(JTextComponent editor) {
    this.editor = editor;
    this.mimeType = DocumentUtilities.getMimeType(editor);
    this.prefs = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class);
    
    final Lookup.Result r = MimeLookup.getLookup(org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(editor)).lookupResult(
            FontColorSettings.class);
    prefListenerGC = new PrefListener();
    this.colorResult = r;
    r.addLookupListener(WeakListeners.create(LookupListener.class, this , r));
    prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, prefListenerGC, prefs));
    loadPreferences();
    
    editorPane = findEditorPane(editor);
    Component parent = editor.getParent();
    if (parent instanceof JLayeredPane) {
        parent = parent.getParent();
    }
    if (parent instanceof JViewport) {
        this.viewport = (JViewport)parent;
        // see #219015; need to listen on viewport change to show/hide the tooltip
        viewport.addChangeListener(WeakListeners.change(this, viewport));
    }
    TextUI ui = editor.getUI();
    if (ui instanceof BaseTextUI) {
        baseUI = (BaseTextUI)ui;
        MasterMatcher.get(editor).addMatchListener(this);
    } else {
        baseUI = null;
    }
    setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
    updatePreferredSize();
}
 
源代码6 项目: netbeans   文件: NbURLMapper.java
protected URL getUrl(JTextComponent comp) {
    FileObject f = null;
    
    if (comp instanceof Lookup.Provider) {
        f = ((Lookup.Provider) comp).getLookup().lookup(FileObject.class);
    }
    
    if (f == null) {
        Container container = comp.getParent();
        while (container != null) {
            if (container instanceof Lookup.Provider) {
                f = ((Lookup.Provider) container).getLookup().lookup(FileObject.class);
                if (f != null) {
                    break;
                }
            }
            
            container = container.getParent();
        }
    }
    
    if (f != null) {
        try {
            return f.getURL();
        } catch (FileStateInvalidException e) {
            LOG.log(Level.WARNING, "Can't get URL for " + f, e); //NOI18N
        }
    }
    
    return null;
}
 
源代码7 项目: visualvm   文件: LineNumbersRuler.java
/**
 * Get the JscrollPane that contains this EditorPane, or null if no
 * JScrollPane is the parent of this editor
 * @param editorPane
 * @return
 */
public JScrollPane getScrollPane(JTextComponent editorPane) {
    Container p = editorPane.getParent();
    while (p != null) {
        if (p instanceof JScrollPane) {
            return (JScrollPane) p;
        }
        p = p.getParent();
    }
    return null;
}
 
源代码8 项目: jpexs-decompiler   文件: QuickFindDialog.java
public void showFor(final JTextComponent target) {
    oldCaretPosition = target.getCaretPosition();
    Container view = target.getParent();
    Dimension wd = getPreferredSize();
    //wd.width = target.getVisibleRect().width;
    Point loc = new Point(0, view.getHeight());
    setSize(wd);
    setLocationRelativeTo(view);
    SwingUtilities.convertPointToScreen(loc, view);
    setLocation(loc);
    jTxtFind.setFont(target.getFont());
    jTxtFind.getDocument().addDocumentListener(this);
    WindowAdapter closeListener = new WindowAdapter() {

        @Override
        public void windowDeactivated(WindowEvent e) {
            target.getDocument().removeDocumentListener(QuickFindDialog.this);
            Markers.removeMarkers(target, marker);
            if (escaped) {
                Rectangle aRect;
                try {
                    aRect = target.modelToView(oldCaretPosition);
                    target.setCaretPosition(oldCaretPosition);
                    target.scrollRectToVisible(aRect);
                } catch (BadLocationException ex) {
                }
            }
            dispose();
        }
    };
    addWindowListener(closeListener);
    this.target = new WeakReference<JTextComponent>(target);
    Pattern p = dsd.get().getPattern();
    if (p != null) {
        jTxtFind.setText(p.pattern());
    }
    jChkWrap.setSelected(dsd.get().isWrap());
    setVisible(true);
    jTxtFind.selectAll();
}
 
源代码9 项目: jpexs-decompiler   文件: LineNumbersRuler.java
/**
 * Get the JscrollPane that contains this EditorPane, or null if no
 * JScrollPane is the parent of this editor
 *
 * @param editorPane
 * @return
 */
public JScrollPane getScrollPane(JTextComponent editorPane) {
    Container p = editorPane.getParent();
    while (p != null) {
        if (p instanceof JScrollPane) {
            return (JScrollPane) p;
        }
        p = p.getParent();
    }
    return null;
}
 
源代码10 项目: Darcula   文件: DarculaPasswordFieldUI.java
@Override
protected void paintBackground(Graphics graphics) {
  Graphics2D g = (Graphics2D)graphics;
  final JTextComponent c = getComponent();
  final Container parent = c.getParent();
  if (parent != null) {
    g.setColor(parent.getBackground());
    g.fillRect(0, 0, c.getWidth(), c.getHeight());
  }
  final Border border = c.getBorder();
  if (border instanceof DarculaTextBorder) {
    g.setColor(c.getBackground());
    final int width = c.getWidth();
    final int height = c.getHeight();
    final Insets i = border.getBorderInsets(c);
    if (c.hasFocus()) {
      final GraphicsConfig config = new GraphicsConfig(g);
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

      g.fillRoundRect(i.left - 5, i.top - 2, width - i.left - i.right + 10, height - i.top - i.bottom + 6, 5, 5);
      config.restore();
    }
    else {
      g.fillRect(i.left - 5, i.top - 2, width - i.left - i.right + 12, height - i.top - i.bottom + 6);
    }
  } else {
    super.paintBackground(g);
  }
}
 
源代码11 项目: consulo   文件: ModernPasswordFieldUI.java
@Override
protected void paintBackground(Graphics graphics) {
  Graphics2D g = (Graphics2D)graphics;
  final JTextComponent c = getComponent();
  final Container parent = c.getParent();
  if (parent != null) {
    g.setColor(parent.getBackground());
    g.fillRect(0, 0, c.getWidth(), c.getHeight());
  }
  final Border border = c.getBorder();
  if (border instanceof ModernTextBorder) {
    g.setColor(c.getBackground());
    final int width = c.getWidth();
    final int height = c.getHeight();
    final Insets i = border.getBorderInsets(c);
    if (c.hasFocus()) {
      final GraphicsConfig config = new GraphicsConfig(g);
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

      g.fillRect(i.left - 5, i.top - 2, width - i.left - i.right + 10, height - i.top - i.bottom + 6);
      config.restore();
    }
    else {
      g.fillRect(i.left - 5, i.top - 2, width - i.left - i.right + 12, height - i.top - i.bottom + 6);
    }
  }
  else {
    super.paintBackground(g);
  }
}
 
源代码12 项目: consulo   文件: DarculaPasswordFieldUI.java
@Override
protected void paintBackground(Graphics graphics) {
  Graphics2D g = (Graphics2D)graphics;
  final JTextComponent c = getComponent();
  final Container parent = c.getParent();
  if (parent != null) {
    g.setColor(parent.getBackground());
    g.fillRect(0, 0, c.getWidth(), c.getHeight());
  }
  final Border border = c.getBorder();
  if (border instanceof DarculaTextBorder) {
    g.setColor(c.getBackground());
    final int width = c.getWidth();
    final int height = c.getHeight();
    final Insets i = border.getBorderInsets(c);
    if (c.hasFocus()) {
      final GraphicsConfig config = new GraphicsConfig(g);
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

      g.fillRoundRect(i.left - 5, i.top - 2, width - i.left - i.right + 10, height - i.top - i.bottom + 6, 5, 5);
      config.restore();
    }
    else {
      g.fillRect(i.left - 5, i.top - 2, width - i.left - i.right + 12, height - i.top - i.bottom + 6);
    }
  } else {
    super.paintBackground(g);
  }
}
 
源代码13 项目: netbeans   文件: HintsUI.java
boolean invokeDefaultAction(boolean onlyActive) {
    JTextComponent comp = getComponent();
    if (comp == null) {
        Logger.getLogger(HintsUI.class.getName()).log(Level.WARNING, "HintsUI.invokeDefaultAction called, but comp == null");
        return false;
    }

    Document doc = comp.getDocument();

    cancel.set(false);
    
    if (doc instanceof BaseDocument) {
        try {
            Rectangle carretRectangle = comp.modelToView(comp.getCaretPosition());
            int line = Utilities.getLineOffset((BaseDocument) doc, comp.getCaretPosition());
            FixData fixes;
            String description;

            if (!onlyActive) {
                refresh(doc, comp.getCaretPosition());
                AnnotationHolder holder = getAnnotationHolder(doc);
                Pair<FixData, String> fixData = holder != null ? holder.buildUpFixDataForLine(line) : null;

                if (fixData == null) return false;

                fixes = fixData.first();
                description = fixData.second();
            } else {
                AnnotationDesc activeAnnotation = ((BaseDocument) doc).getAnnotations().getActiveAnnotation(line);
                if (activeAnnotation == null) {
                    return false;
                }
                String type = activeAnnotation.getAnnotationType();
                if (!FixAction.getFixableAnnotationTypes().contains(type) && onlyActive) {
                    return false;
                }
                if (onlyActive) {
                    refresh(doc, comp.getCaretPosition());
                }
                Annotations annotations = ((BaseDocument) doc).getAnnotations();
                AnnotationDesc desc = annotations.getAnnotation(line, type);
                ParseErrorAnnotation annotation = null;
                if (desc != null) {
                    annotations.frontAnnotation(desc);
                    annotation = findAnnotation(doc, desc, line);
                }

                if (annotation == null) {
                    return false;
                }
                
                fixes = annotation.getFixes();
                description = annotation.getDescription();
            }

            Point p = comp.modelToView(Utilities.getRowStartFromLineOffset((BaseDocument) doc, line)).getLocation();
            p.y += carretRectangle.height;
            if(comp.getParent() instanceof JViewport) {
                p.x += ((JViewport)comp.getParent()).getViewPosition().x;
            }
            if(comp.getParent() instanceof JLayeredPane &&
                    comp.getParent().getParent() instanceof JViewport) {
                p.x += ((JViewport)comp.getParent().getParent()).getViewPosition().x;
            }

            showPopup(fixes, description, comp, p);

            return true;
        } catch (BadLocationException ex) {
            ErrorManager.getDefault().notify(ex);
        }
    }

    return false;
}