Skip to content

Commit

Permalink
Add editor themening capabilities (very crude) Fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
aeris170 committed Sep 22, 2020
1 parent 3adea8c commit 2dbab43
Show file tree
Hide file tree
Showing 15 changed files with 1,337 additions and 708 deletions.
2 changes: 2 additions & 0 deletions .settings/org.sonarlint.eclipse.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
autoEnabled=false
eclipse.preferences.version=1
Binary file modified Mars4_5_1Unofficial.jar
Binary file not shown.
333 changes: 157 additions & 176 deletions mars/Settings.java

Large diffs are not rendered by default.

140 changes: 64 additions & 76 deletions mars/venus/EditPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public EditPane(final VenusUI appFrame) {
} else {
sourceCode = new JEditBasedTextArea(this, lineNumbers);
}

// sourceCode is responsible for its own scrolling
this.add(sourceCode.getOuterComponent(), BorderLayout.CENTER);

Expand All @@ -113,12 +114,18 @@ public void insertUpdate(final DocumentEvent evt) {
if (FileStatus.get() == FileStatus.OPENING) {
setFileStatus(FileStatus.NOT_EDITED);
FileStatus.set(FileStatus.NOT_EDITED);
if (showingLineNumbers()) { lineNumbers.setText(getLineNumbersList(sourceCode.getDocument())); }
if (showingLineNumbers()) {
lineNumbers.setText(getLineNumbersList(sourceCode.getDocument()));
}
return;
}
// End of 9-Aug-2011 modification.
if (getFileStatus() == FileStatus.NEW_NOT_EDITED) { setFileStatus(FileStatus.NEW_EDITED); }
if (getFileStatus() == FileStatus.NOT_EDITED) { setFileStatus(FileStatus.EDITED); }
if (getFileStatus() == FileStatus.NEW_NOT_EDITED) {
setFileStatus(FileStatus.NEW_EDITED);
}
if (getFileStatus() == FileStatus.NOT_EDITED) {
setFileStatus(FileStatus.EDITED);
}
if (getFileStatus() == FileStatus.NEW_EDITED) {
mainUI.editor.setTitle("", getFilename(), getFileStatus());
} else {
Expand All @@ -138,18 +145,16 @@ public void insertUpdate(final DocumentEvent evt) {

Globals.getGui().getMainPane().getExecutePane().clearPane(); // DPS 9-Aug-2011

if (showingLineNumbers()) { lineNumbers.setText(getLineNumbersList(sourceCode.getDocument())); }
if (showingLineNumbers()) {
lineNumbers.setText(getLineNumbersList(sourceCode.getDocument()));
}
}

@Override
public void removeUpdate(final DocumentEvent evt) {
insertUpdate(evt);
}
public void removeUpdate(final DocumentEvent evt) { insertUpdate(evt); }

@Override
public void changedUpdate(final DocumentEvent evt) {
insertUpdate(evt);
}
public void changedUpdate(final DocumentEvent evt) { insertUpdate(evt); }
});

showLineNumbers = new JCheckBox("Show Line Numbers");
Expand Down Expand Up @@ -193,13 +198,11 @@ public void changedUpdate(final DocumentEvent evt) {
/**
* For initalizing the source code when opening an ASM file
*
* @param s String containing text
* @param s String containing text
* @param editable set true if code is editable else false
*/

public void setSourceCode(final String s, final boolean editable) {
sourceCode.setSourceCode(s, editable);
}
public void setSourceCode(final String s, final boolean editable) { sourceCode.setSourceCode(s, editable); }

/**
* Get rid of any accumulated undoable edits. It is useful to call this method
Expand All @@ -208,9 +211,7 @@ public void setSourceCode(final String s, final boolean editable) {
* a freshly-opened file to appear with its Undo action enabled. But it will
* unless you call this after setting the text.
*/
public void discardAllUndoableEdits() {
sourceCode.discardAllUndoableEdits();
}
public void discardAllUndoableEdits() { sourceCode.discardAllUndoableEdits(); }

/**
* Form string with source code line numbers. Resulting string is HTML, for
Expand All @@ -228,9 +229,14 @@ public String getLineNumbersList(final javax.swing.text.Document doc) {
final String lineStr = Integer.toString(i);
final int leadingSpaces = digits - lineStr.length();
if (leadingSpaces == 0) {
lineNumberList.append(lineStr + "&nbsp;<br>");
lineNumberList.append(
lineStr
+ "&nbsp;<br>");
} else {
lineNumberList.append(spaces.substring(0, leadingSpaces * 6) + lineStr + "&nbsp;<br>");
lineNumberList.append(
spaces.substring(0, leadingSpaces * 6)
+ lineStr
+ "&nbsp;<br>");
}
}
lineNumberList.append("<br></html>");
Expand Down Expand Up @@ -272,9 +278,7 @@ public int getSourceLineCount() {
*
* @param FileStatus the status constant from class FileStatus
*/
public void setFileStatus(final int fileStatus) {
this.fileStatus.setFileStatus(fileStatus);
}
public void setFileStatus(final int fileStatus) { this.fileStatus.setFileStatus(fileStatus); }

/**
* Get the editing status for this EditPane's associated document. This will be
Expand All @@ -296,16 +300,12 @@ public void setFileStatus(final int fileStatus) {
/**
* Delegates to corresponding FileStatus method
*/
public void setPathname(final String pathname) {
fileStatus.setPathname(pathname);
}
public void setPathname(final String pathname) { fileStatus.setPathname(pathname); }

/**
* Delegates to corresponding FileStatus method
*/
public boolean hasUnsavedEdits() {
return fileStatus.hasUnsavedEdits();
}
public boolean hasUnsavedEdits() { return fileStatus.hasUnsavedEdits(); }

/**
* Delegates to corresponding FileStatus method
Expand All @@ -316,16 +316,12 @@ public boolean hasUnsavedEdits() {
* Delegates to text area's requestFocusInWindow method.
*/

public void tellEditingComponentToRequestFocusInWindow() {
sourceCode.requestFocusInWindow();
}
public void tellEditingComponentToRequestFocusInWindow() { sourceCode.requestFocusInWindow(); }

/**
* Delegates to corresponding FileStatus method
*/
public void updateStaticFileStatus() {
fileStatus.updateStaticFileStatus();
}
public void updateStaticFileStatus() { fileStatus.updateStaticFileStatus(); }

/**
* get the manager in charge of Undo and Redo operations
Expand Down Expand Up @@ -380,39 +376,29 @@ public void selectAllText() {
/**
* Undo previous edit
*/
public void undo() {
sourceCode.undo();
}
public void undo() { sourceCode.undo(); }

/**
* Redo previous edit
*/
public void redo() {
sourceCode.redo();
}
public void redo() { sourceCode.redo(); }

/**
* Update state of Edit menu's Undo menu item.
*/
public void updateUndoState() {
mainUI.editUndoAction.updateUndoState();
}
public void updateUndoState() { mainUI.editUndoAction.updateUndoState(); }

/**
* Update state of Edit menu's Redo menu item.
*/
public void updateRedoState() {
mainUI.editRedoAction.updateRedoState();
}
public void updateRedoState() { mainUI.editRedoAction.updateRedoState(); }

/**
* get editor's line number display status
*
* @return true if editor is current displaying line numbers, false otherwise.
*/
public boolean showingLineNumbers() {
return showLineNumbers.isSelected();
}
public boolean showingLineNumbers() { return showLineNumbers.isSelected(); }

/**
* enable or disable checkbox that controls display of line numbers
Expand All @@ -431,17 +417,19 @@ public void setShowLineNumbersEnabled(final boolean enabled) {
*
* @param pos Offset into the text stream of caret.
*/
public void displayCaretPosition(final int pos) {
displayCaretPosition(convertStreamPositionToLineColumn(pos));
}
public void displayCaretPosition(final int pos) { displayCaretPosition(convertStreamPositionToLineColumn(pos)); }

/**
* Display cursor coordinates
*
* @param p Point object with x-y (column, line number) coordinates of cursor
*/
public void displayCaretPosition(final Point p) {
caretPositionLabel.setText("Line: " + p.y + " Column: " + p.x);
caretPositionLabel.setText(
"Line: "
+ p.y
+ " Column: "
+ p.x);
}

/**
Expand Down Expand Up @@ -472,10 +460,10 @@ public Point convertStreamPositionToLineColumn(final int position) {
* Given line and column (position in the line) numbers, calculate its byte
* stream position in text being edited.
*
* @param line Line number in file (starts with 1)
* @param line Line number in file (starts with 1)
* @param column Position within that line (starts with 1)
* @return corresponding stream position. Returns -1 if there is no
* corresponding position.
* corresponding position.
*/
public int convertLineColumnToStreamPosition(final int line, final int column) {
final String textStream = sourceCode.getText();
Expand All @@ -499,8 +487,7 @@ public int convertLineColumnToStreamPosition(final int line, final int column) {
* consistent with line numbers displayed by the editor.
*
* @param line The desired line number of this TextPane's text. Numbering starts
* at 1, and nothing will happen if the parameter value is less than
* 1
* at 1, and nothing will happen if the parameter value is less than 1
*/
public void selectLine(final int line) {
if (line > 0) {
Expand All @@ -521,9 +508,8 @@ public void selectLine(final int line) {
* Select the specified editor text line. Lines are numbered starting with 1,
* consistent with line numbers displayed by the editor.
*
* @param line The desired line number of this TextPane's text. Numbering
* starts at 1, and nothing will happen if the parameter value is
* less than 1
* @param line The desired line number of this TextPane's text. Numbering starts
* at 1, and nothing will happen if the parameter value is less than 1
* @param column Desired column at which to place the cursor.
*/
public void selectLine(final int line, final int column) {
Expand All @@ -538,7 +524,7 @@ public void selectLine(final int line, final int column) {
* at the current cursor location, and wraps around when the end of the string
* is reached.
*
* @param find the text to locate in the string
* @param find the text to locate in the string
* @param caseSensitive true if search is to be case-sensitive, false otherwise
* @return TEXT_FOUND or TEXT_NOT_FOUND, depending on the result.
*/
Expand All @@ -552,16 +538,15 @@ public int doFindText(final String find, final boolean caseSensitive) {
* then find and select the next occurrence if any. Otherwise it performs a find
* operation. The replace can be undone with one undo operation.
*
* @param find the text to locate in the string
* @param replace the text to replace the find text with - if the find
* text exists
* @param find the text to locate in the string
* @param replace the text to replace the find text with - if the find text
* exists
* @param caseSensitive true for case sensitive. false to ignore case
* @return Returns TEXT_FOUND if not initially at end of selected match and
* matching occurrence is found. Returns TEXT_NOT_FOUND if the text is
* not matched. Returns TEXT_REPLACED_NOT_FOUND_NEXT if replacement is
* successful but there are no additional matches. Returns
* TEXT_REPLACED_FOUND_NEXT if reaplacement is successful and there is
* at least one additional match.
* matching occurrence is found. Returns TEXT_NOT_FOUND if the text is not
* matched. Returns TEXT_REPLACED_NOT_FOUND_NEXT if replacement is successful
* but there are no additional matches. Returns TEXT_REPLACED_FOUND_NEXT if
* reaplacement is successful and there is at least one additional match.
*/
public int doReplace(final String find, final String replace, final boolean caseSensitive) {
return sourceCode.doReplace(find, replace, caseSensitive);
Expand All @@ -572,9 +557,9 @@ public int doReplace(final String find, final String replace, final boolean case
* search. All replacements are bundled into one CompoundEdit, so one Undo
* operation will undo all of them.
*
* @param find the text to locate in the string
* @param replace the text to replace the find text with - if the find
* text exists
* @param find the text to locate in the string
* @param replace the text to replace the find text with - if the find text
* exists
* @param caseSensitive true for case sensitive. false to ignore case
* @return the number of occurrences that were matched and replaced.
*/
Expand All @@ -589,8 +574,8 @@ public int doReplaceAll(final String find, final String replace, final boolean c
@Override
public void update(final Observable fontChanger, final Object arg) {
sourceCode.setFont(Globals.getSettings().getEditorFont());
sourceCode.setLineHighlightEnabled(Globals.getSettings().getBooleanSetting(
Settings.EDITOR_CURRENT_LINE_HIGHLIGHTING));
sourceCode.setLineHighlightEnabled(
Globals.getSettings().getBooleanSetting(Settings.EDITOR_CURRENT_LINE_HIGHLIGHTING));
sourceCode.setCaretBlinkRate(Globals.getSettings().getCaretBlinkRate());
sourceCode.setTabSize(Globals.getSettings().getEditorTabSize());
sourceCode.updateSyntaxStyles();
Expand All @@ -612,8 +597,11 @@ public void update(final Observable fontChanger, final Object arg) {
* font for source code.
*/
private Font getLineNumberFont(final Font sourceFont) {
return sourceCode.getFont().getStyle() == Font.PLAIN ? sourceFont
: new Font(sourceFont.getFamily(), Font.PLAIN, sourceFont.getSize());
return sourceCode.getFont().getStyle() == Font.PLAIN ? sourceFont : new Font(
sourceFont.getFamily(),
Font.PLAIN,
sourceFont.getSize());
}

public void updateColors() { sourceCode.updateColors(); }
}
Loading

0 comments on commit 2dbab43

Please sign in to comment.