All Downloads are FREE. Search and download functionalities are using the official Maven repository.

editor.EditorBasedPopup Maven / Gradle / Ivy

There is a newer version: 1.18.1
Show newest version
package editor;

import javax.swing.*;
import javax.swing.text.BadLocationException;
import java.awt.*;


public abstract class EditorBasedPopup extends JPopupMenu implements IValuePopup
{
  private GosuEditor _editor;
  private boolean _replaceWholeWord;


  public EditorBasedPopup( GosuEditor editor )
  {
    _editor = editor;
  }

  protected GosuEditor getEditor()
  {
    return _editor;
  }

  public void setVisible( boolean b )
  {
    super.setVisible( b );
    if( b && _editor != null )
    {
      try
      {
        Rectangle bounds = getParent().getBounds();
        Point popupLocation = getParent().getLocationOnScreen();
        Rectangle caretLocation = new Rectangle( _editor.getCaretLocation() );
        editor.util.EditorUtilities.convertRectangleToScreen( caretLocation, _editor );
        if( popupLocation.getY() < caretLocation.getY() + caretLocation.getHeight() )
        {
          Point loc = new Point( (int)(popupLocation.getX()), (int)(caretLocation.getY() - bounds.getHeight()) );
          SwingUtilities.convertPointFromScreen( loc, getParent().getParent() );
          getParent().setLocation( loc );
        }
      }
      catch( BadLocationException e )
      {
        // ignore
      }
    }
  }

  protected boolean endsWithInvalidChar( String strPrefix )
  {
    if( strPrefix != null && strPrefix.length() > 0 )
    {
      char c = strPrefix.charAt( strPrefix.length() - 1 );
      if( !Character.isJavaIdentifierPart( c ) &&
          !Character.isJavaIdentifierStart( c ) )
      {
        return true;
      }
    }
    return false;
  }

  public void setReplaceWholeWord( boolean replaceWholeWord )
  {
    _replaceWholeWord = replaceWholeWord;
  }
  public boolean isReplaceWholeWord()
  {
    return _replaceWholeWord;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy