AlloyTools / org.alloytools.alloy

Alloy is a language for describing structures and a tool for exploring them. It has been used in a wide range of applications from finding holes in security mechanisms to designing telephone switching networks. This repository contains the code for the tool.
Other
695 stars 124 forks source link

Feature/line numbers, Issue #79 #170

Closed nigelkerr closed 2 years ago

nigelkerr commented 2 years ago

Add line numbers to the editor display, configured with a preference, issue AlloyTools#79 "Feature Request: Line Numbers."

The OurLineNumberWidget class is added, providing a rowHeader to the JScrollPane component of OurSyntaxWidget, based on data and events from the JTextPane pane also of OurSyntaxWidget. OurLineNumberWidget receives updates to the line-numbers preference, and also to the font-name and font-size preference, because we draw the line-number display in the same font as the main document. OurLineNumberWidget follows the anti-aliasing strategy expressed by the OurAntiAlias class, by anti-aliasing when we believe we are on a Mac or on Windows. The view of the line numbers scrolls with the contents of the text pane. The line of text where the caret is will have it's line number in yellow on a black background. The OurLineNumberWidget sets itself to 0 width, or a calculated width, depending on whether OurSyntaxWidget constructed or informs it later whether to display.

The code itself does not place a restriction on how many lines there are in the file or displaying the current line number. The width of OurLineNumberWidget grows or shrinks depending on the current number to display with the most digits. This author has tested up to seven digits.

The highlighting of the line of the caret could certainly be changed if there is need or preference. Size of the line number area, the exact font used, color and background, these are all on the table.

The preference for displaying line-numbers is in the Alloy Preferences window, in the Editor tab, at the end of the list of preferences there. The current value appears in the Options menu at the end of the third section, in the same section with the preferences from the Editor tab.

Testing of this feature has involved a Windows 11 machine with Java 8, and a Macos 11 with Java 8. Testing has involved combinations of:

I'd welcome further tests or requests.

nigelkerr commented 2 years ago

Hello @pkriens, herewith a PR for the line-numbers. There is absolutely no rush. If I should request review of other parties, do please advise. Cheers,

pkriens commented 2 years ago

LGTM I give a few days for others to look at.