Giter VIP home page Giter VIP logo

syntaxpane's Introduction

SyntaxPane

SyntaxPane is a basic syntax pane supports:

  • customize syntax coloring
  • customize keyboard shortcuts
  • listen to user input easily

The libarary has implemented java syntax coloring adapter and other basic keyboard shortcuts.

  • Keyboard shortcuts have been implemented
  • Undo(CTRL + Z)
  • Redo(CTRL + Y)
  • Reduce one prefix tab of multi lines(Shift + tab when select more than zero text)

Screenshots

ScreenShot

Getting Started

  • Add jar file to your classpath

Java SyntaxEditPane example

Change fixed UI color which show in SyntaxEditPane by setter function of SyntaxManager. Other dynamically changeable characteristic can be changed by setter function of SyntaxEditPane.

JFrame frame = new JFrame();
try {
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	SyntaxEditPane pane = new SyntaxEditPane(new SyntaxManager(), new JavaCodeAdapter());
	frame.add(pane);
	frame.setSize(700, 500);
	frame.setVisible(true);
} catch (SyntaxException e) {
	e.printStackTrace();
}

Design customized CodeAdapter

  1. implement AbstractCodeAdapter
  2. use textArea.getStyledTextBody() to get all text, and change text on syntax pane
  3. use textArea.getSyntaxPainter() to get painter which help you color the syntax
  4. use textArea.getSyntaxHighlightingTool() to get highlight tool which help you highligh the text
  5. use textArea.getSyntaxDocumentToo() to get document tool which help you analyze text
class YourAdapter implements AbstractCodeAdapter {
	@Override
	public void insertString(int offset, String text, SyntaxTextArea textArea) {
		// listen to text insertsion
	}

	@Override
	public void remove(int offset, String text, SyntaxTextArea textArea) {
		// listen to text removement
	}

	@Override
	public boolean replace(int offset, int length, String text, SyntaxTextArea textArea) {
		// listen to text replacement.
		// return true to make SyntaxTextArea replace the text by calling remove and
		// insertString as referred to above.
		// That is if you want to do some changes by yourself, return false, otherwise return true.
	}

	@Override
	public AttributeSet getDefaultAttributeSet() {
		// SyntaxTextArea gets default AttributeSet through this function
		// and use it to set the characteristic attribute before call insertString()
	}
}

Design customized row header

  • Implement com.syntax.ui.AbstractSyntaxHeader. Actually, AbstractSyntaxHeader is a JPanel so you can add anything to it. Besides, the abstract methods of AbstractSyntaxHeader provide you with callbacks which listen to various changing in syntax pane.

Design customized caret

  • Implement com.syntax.ui.AbstractSyntaxCaret. The only abstract method should be implemented is the callback of font changing. You can override public void paint(Graphics g) to draw customized shape or apply another color.

Listen to caret position update

  • Register com.syntax.manage.SyntaxCaretListener in com.syntax.ui.SyntaxTextArea

Listen to selection update

  • comming soon

Document

Built With

  • Gradle - Dependency Management
  • JRE version 1.8

Authors

  • Alan Wu - Initial work - Github

License

This project is licensed under the MIT License - see the LICENSE.md file for details

syntaxpane's People

Contributors

w86763777 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.