oracc / nammu

Oracc GUI
GNU General Public License v3.0
12 stars 10 forks source link

Move line numbers in arabic pane to right of screen #327

Closed sgrieve closed 5 years ago

sgrieve commented 6 years ago

This may require modifying the TextLineNumber Java class.

giordano commented 5 years ago

I have looked into this, but it doesn't appear to be straightforward.

In the line-numbers-arabic branch you can find my attempt at addressing this issue. I made some minor adjustments to the Java class in order to be able to customise appearance of the line numbers panel depending on whether it's for a left-to-right or right-to-left text component.

The main problem is that the TextLineNumber class heavily relies on being attached to the text component with setRowHeader. In standard Java Swing there is no setRowFooter (note: there is in Jide: http://www.jidesoft.com/javadoc/com/jidesoft/swing/JideScrollPane.html). With @raquel-ucl, we tried attaching the line numbers to the panel in AtfAreaView.__init__ with:

        pref_size = Dimension(1, 500)
        self.edit_area.setPreferredSize(pref_size)
        self.container = JScrollPane(self.edit_area)
        outer_container = JPanel()
        outer_container.setLayout(BorderLayout())
        outer_container.add(self.container, BorderLayout.CENTER)
        outer_container.add(self.line_numbers_area, BorderLayout.EAST)
        outer_container.setPreferredSize(pref_size)
        self.add(outer_container, BorderLayout.CENTER)

In this way, TextLineNumber.paintComponent miscomputes clip = g.getClipBounds(), because g never changes. I tried setting clip = component.getVisibleRect(), but doesn't fully work and scrolling the text doesn't update the line numbers (probably because repainting is not triggered, as the text scrollbar now is somewhat separated from the line numbers).

I'll leave the branch here for reference in case anyone will want to have a look in the future.

ageorgou commented 5 years ago

According to this answer, switching the orientation of the JScrollPane that contains the numbers and the edit area should work. At the moment we're setting the orientation of the whole text pane (arabic_area), but not the scroll pane (secondary_editor), so maybe it's not "inherited" (or it's set after we create the scroll pane)?

Looking at it more, the JScrollPane's setComponentOrientation method does something beyond the default, so we probably need to invoke it, whereas for the JTextPane it's related to the text direction. Changing the orientiation of the scroll pane will also move the scroll bar to the left, but I guess that may be reasonable?

giordano commented 5 years ago

Changing the orientiation of the scroll pane will also move the scroll bar to the left, but I guess that may be reasonable?

I'm not familiar, but googling for Arabic text editors it seems that some of them do have scroll bar to the left, but not all.

ageorgou commented 5 years ago

Another (untested!) possible solution, with a variant of the TextLineNumber: https://stackoverflow.com/a/52326451/11658609

giordano commented 5 years ago

Well, it turned out that simply setting the orientation of the container of the Arabic line numbers to right-to-left was sufficient. I'm going to open a pull request