Skip to content

Commit

Permalink
Merge branch 'line-numbers-arabic' into test-release-1.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano committed Jul 30, 2019
2 parents e99bd6a + 4ce6b6f commit 99e222f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
6 changes: 3 additions & 3 deletions python/nammu/controller/AtfAreaController.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def __init__(self, mainControler):
self.arabic_area = JTextPane()

# Create text panel to display the line numbers
self.line_numbers_area = TextLineNumber(self.edit_area)
self.secondary_line_numbers = TextLineNumber(self.secondary_area)
self.arabic_line_numbers = TextLineNumber(self.arabic_area)
self.line_numbers_area = TextLineNumber(self.edit_area, True)
self.secondary_line_numbers = TextLineNumber(self.secondary_area, True)
self.arabic_line_numbers = TextLineNumber(self.arabic_area, False)
# Ensure the line numbers update when the editor font is changed
self.line_numbers_area.setUpdateFont(True)
self.secondary_line_numbers.setUpdateFont(True)
Expand Down
1 change: 1 addition & 0 deletions python/nammu/view/AtfAreaView.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def setup_edit_area_split(self, split_orientation=None, arabic=False):
if arabic:
secondary_editor = JScrollPane(self.arabic_area)
secondary_editor.setRowHeaderView(self.arabic_line_numbers)
secondary_editor.setComponentOrientation(RIGHT_TO_LEFT)
self.controller.controller.arabic_edition_on = True
# Do not allow toggling arabic pane if there is text in it.
arabic_text = self.arabic_area.getText()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ public class TextLineNumber extends JPanel
public final static float CENTER = 0.5f;
public final static float RIGHT = 1.0f;

private final static Border OUTER = new MatteBorder(0, 0, 0, 2, Color.GRAY);

private final static int HEIGHT = Integer.MAX_VALUE - 1000000;

// Text component this TextTextLineNumber component is in sync with

private JTextComponent component;

// Other properties that will be set by constructor

private static Border OUTER;

// Properties that can be changed

private boolean updateFont;
Expand All @@ -50,9 +52,9 @@ public class TextLineNumber extends JPanel
// Keep history information to reduce the number of times the component
// needs to be repainted

private int lastDigits;
private int lastHeight;
private int lastLine;
private int lastDigits;
private int lastHeight;
private int lastLine;

private HashMap<String, FontMetrics> fonts;

Expand All @@ -61,28 +63,44 @@ public class TextLineNumber extends JPanel
* display width will be based on 3 digits.
*
* @param component the related text component
* @param left_to_right whether the text is left to right, this
* affects alignment of line numbers and the
* border of the panel
*/
public TextLineNumber(JTextComponent component)
public TextLineNumber(JTextComponent component, boolean left_to_right)
{
this(component, 3);
this(component, left_to_right, 3);
}

/**
* Create a line number component for a text component.
*
* @param component the related text component
* @param left_to_right whether the text is left to right, this
* affects alignment of line numbers and the
* border of the panel
* @param minimumDisplayDigits the number of digits used to calculate
* the minimum width of the component
*/
public TextLineNumber(JTextComponent component, int minimumDisplayDigits)
public TextLineNumber(JTextComponent component, boolean left_to_right,
int minimumDisplayDigits)
{
this.component = component;
if (left_to_right)
{
setDigitAlignment( RIGHT );
this.OUTER = new MatteBorder(0, 0, 0, 2, Color.GRAY);
}
else
{
setDigitAlignment( LEFT );
this.OUTER = new MatteBorder(0, 2, 0, 0, Color.GRAY);
}

setFont( component.getFont() );

setBorderGap( 5 );
setCurrentLineForeground( Color.RED );
setDigitAlignment( RIGHT );
setMinimumDisplayDigits( minimumDisplayDigits );

component.getDocument().addDocumentListener(this);
Expand Down Expand Up @@ -229,7 +247,6 @@ private void setPreferredWidth()
Dimension d = getPreferredSize();
d.setSize(preferredWidth, HEIGHT);
setPreferredSize( d );
setSize( d );
}
}

Expand All @@ -256,7 +273,7 @@ public void paintComponent(Graphics g)
while (rowStartOffset <= endOffset)
{
try
{
{
if (isCurrentLine(rowStartOffset))
g.setColor( getCurrentLineForeground() );
else
Expand All @@ -268,8 +285,8 @@ public void paintComponent(Graphics g)
String lineNumber = getTextLineNumber(rowStartOffset);
int stringWidth = fontMetrics.stringWidth( lineNumber );
int x = getOffsetX(availableWidth, stringWidth) + insets.left;
int y = getOffsetY(rowStartOffset, fontMetrics);
g.drawString(lineNumber, x, y);
int y = getOffsetY(rowStartOffset, fontMetrics);
g.drawString(lineNumber, x, y);

// Move to the next row

Expand Down Expand Up @@ -306,11 +323,11 @@ protected String getTextLineNumber(int rowStartOffset)

if (line.getStartOffset() == rowStartOffset)
return String.valueOf(index + 1);
// Need this clause to deal with right to left text encoding
// Need this clause to deal with right to left text encoding
else if (line.getEndOffset() == rowStartOffset + 1)
return String.valueOf(index + 1);
else
return "";
else
return "";
}

/*
Expand Down

0 comments on commit 99e222f

Please sign in to comment.