mirror of
https://github.com/SuspiciousActivity/ByteEdit.git
synced 2026-08-13 17:56:17 +00:00
Added code folding and formatted all files
This commit is contained in:
1 parent
11570d6b95
commit
66cd1dbd3e
233 files changed
+82245
-118134
No files matched your search
@@ -1,9 +1,7 @@
|
||||
/*
|
||||
* 02/24/2004
|
||||
*
|
||||
* RSyntaxTextAreaUI.java - UI for an RSyntaxTextArea.
|
||||
*
|
||||
* This library is distributed under a modified BSD license. See the included
|
||||
* This library is distributed under a modified BSD license. See the included
|
||||
* RSyntaxTextArea.License.txt file for details.
|
||||
*/
|
||||
package org.fife.ui.rsyntaxtextarea;
|
||||
@@ -28,40 +26,37 @@ import javax.swing.text.View;
|
||||
import org.fife.ui.rtextarea.RTextArea;
|
||||
import org.fife.ui.rtextarea.RTextAreaUI;
|
||||
|
||||
|
||||
/**
|
||||
* UI used by <code>RSyntaxTextArea</code>. This allows us to implement
|
||||
* UI used by <code>RSyntaxTextArea</code>. This allows us to implement
|
||||
* syntax highlighting.
|
||||
*
|
||||
* @author Robert Futrell
|
||||
* @version 0.1
|
||||
*/
|
||||
public class RSyntaxTextAreaUI extends RTextAreaUI {
|
||||
|
||||
private static final String SHARED_ACTION_MAP_NAME = "RSyntaxTextAreaUI.actionMap";
|
||||
private static final String SHARED_INPUT_MAP_NAME = "RSyntaxTextAreaUI.inputMap";
|
||||
private static final EditorKit DEFAULT_KIT = new RSyntaxTextAreaEditorKit();
|
||||
|
||||
|
||||
|
||||
private static final String SHARED_ACTION_MAP_NAME = "RSyntaxTextAreaUI.actionMap";
|
||||
private static final String SHARED_INPUT_MAP_NAME = "RSyntaxTextAreaUI.inputMap";
|
||||
private static final EditorKit DEFAULT_KIT = new RSyntaxTextAreaEditorKit();
|
||||
|
||||
public static ComponentUI createUI(JComponent ta) {
|
||||
return new RSyntaxTextAreaUI(ta);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public RSyntaxTextAreaUI(JComponent rSyntaxTextArea) {
|
||||
super(rSyntaxTextArea);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates the view for an element.
|
||||
*
|
||||
* @param elem The element.
|
||||
* @return The view.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates the view for an element.
|
||||
*
|
||||
* @param elem
|
||||
* The element.
|
||||
* @return The view.
|
||||
*/
|
||||
@Override
|
||||
public View create(Element elem) {
|
||||
RTextArea c = getRTextArea();
|
||||
@@ -70,16 +65,14 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
|
||||
View v;
|
||||
if (area.getLineWrap()) {
|
||||
v = new WrappedSyntaxView(elem);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
v = new SyntaxView(elem);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates the highlighter to use for syntax text areas.
|
||||
*
|
||||
@@ -89,10 +82,9 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
|
||||
protected Highlighter createHighlighter() {
|
||||
return new RSyntaxTextAreaHighlighter();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name to use to cache/fetch the shared action map. This
|
||||
* Returns the name to use to cache/fetch the shared action map. This
|
||||
* should be overridden by subclasses if the subclass has its own custom
|
||||
* editor kit to install, so its actions get picked up.
|
||||
*
|
||||
@@ -102,12 +94,12 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
|
||||
protected String getActionMapName() {
|
||||
return SHARED_ACTION_MAP_NAME;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetches the EditorKit for the UI.
|
||||
*
|
||||
* @param tc The text component for which this UI is installed.
|
||||
* @param tc
|
||||
* The text component for which this UI is installed.
|
||||
* @return The editor capabilities.
|
||||
* @see javax.swing.plaf.TextUI#getEditorKit
|
||||
*/
|
||||
@@ -115,10 +107,10 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
|
||||
public EditorKit getEditorKit(JTextComponent tc) {
|
||||
return DEFAULT_KIT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the InputMap to use for the UI.<p>
|
||||
* Get the InputMap to use for the UI.
|
||||
* <p>
|
||||
*
|
||||
* This method is not named <code>getInputMap()</code> because there is
|
||||
* a package-private method in <code>BasicTextAreaUI</code> with that name.
|
||||
@@ -129,110 +121,101 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
|
||||
@Override
|
||||
protected InputMap getRTextAreaInputMap() {
|
||||
InputMap map = new InputMapUIResource();
|
||||
InputMap shared = (InputMap)UIManager.get(SHARED_INPUT_MAP_NAME);
|
||||
if (shared==null) {
|
||||
InputMap shared = (InputMap) UIManager.get(SHARED_INPUT_MAP_NAME);
|
||||
if (shared == null) {
|
||||
shared = new RSyntaxTextAreaDefaultInputMap();
|
||||
UIManager.put(SHARED_INPUT_MAP_NAME, shared);
|
||||
}
|
||||
//KeyStroke[] keys = shared.allKeys();
|
||||
//for (int i=0; i<keys.length; i++)
|
||||
// System.err.println(keys[i] + " -> " + shared.get(keys[i]));
|
||||
// KeyStroke[] keys = shared.allKeys();
|
||||
// for (int i=0; i<keys.length; i++)
|
||||
// System.err.println(keys[i] + " -> " + shared.get(keys[i]));
|
||||
map.setParent(shared);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void paintEditorAugmentations(Graphics g) {
|
||||
super.paintEditorAugmentations(g);
|
||||
paintMatchedBracket(g);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Paints the "matched bracket", if any.
|
||||
*
|
||||
* @param g The graphics context.
|
||||
* @param g
|
||||
* The graphics context.
|
||||
*/
|
||||
protected void paintMatchedBracket(Graphics g) {
|
||||
RSyntaxTextArea rsta = (RSyntaxTextArea)textArea;
|
||||
RSyntaxTextArea rsta = (RSyntaxTextArea) textArea;
|
||||
if (rsta.isBracketMatchingEnabled()) {
|
||||
Rectangle match = rsta.getMatchRectangle();
|
||||
if (match!=null) {
|
||||
if (match != null) {
|
||||
paintMatchedBracketImpl(g, rsta, match);
|
||||
}
|
||||
if (rsta.getPaintMatchedBracketPair()) {
|
||||
Rectangle dotRect = rsta.getDotRectangle();
|
||||
if (dotRect!=null) { // should always be true
|
||||
if (dotRect != null) { // should always be true
|
||||
paintMatchedBracketImpl(g, rsta, dotRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void paintMatchedBracketImpl(Graphics g, RSyntaxTextArea rsta,
|
||||
Rectangle r) {
|
||||
|
||||
protected void paintMatchedBracketImpl(Graphics g, RSyntaxTextArea rsta, Rectangle r) {
|
||||
// We must add "-1" to the height because otherwise we'll paint below
|
||||
// the region that gets invalidated.
|
||||
if (rsta.getAnimateBracketMatching()) {
|
||||
Color bg = rsta.getMatchedBracketBGColor();
|
||||
final int arcWH = 5;
|
||||
if (bg!=null) {
|
||||
if (bg != null) {
|
||||
g.setColor(bg);
|
||||
g.fillRoundRect(r.x,r.y, r.width,r.height-1, arcWH, arcWH);
|
||||
g.fillRoundRect(r.x, r.y, r.width, r.height - 1, arcWH, arcWH);
|
||||
}
|
||||
g.setColor(rsta.getMatchedBracketBorderColor());
|
||||
g.drawRoundRect(r.x,r.y, r.width,r.height-1, arcWH, arcWH);
|
||||
}
|
||||
else {
|
||||
g.drawRoundRect(r.x, r.y, r.width, r.height - 1, arcWH, arcWH);
|
||||
} else {
|
||||
Color bg = rsta.getMatchedBracketBGColor();
|
||||
if (bg!=null) {
|
||||
if (bg != null) {
|
||||
g.setColor(bg);
|
||||
g.fillRect(r.x,r.y, r.width,r.height-1);
|
||||
g.fillRect(r.x, r.y, r.width, r.height - 1);
|
||||
}
|
||||
g.setColor(rsta.getMatchedBracketBorderColor());
|
||||
g.drawRect(r.x,r.y, r.width,r.height-1);
|
||||
g.drawRect(r.x, r.y, r.width, r.height - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets called whenever a bound property is changed on this UI's
|
||||
* <code>RSyntaxTextArea</code>.
|
||||
*
|
||||
* @param e The property change event.
|
||||
* @param e
|
||||
* The property change event.
|
||||
*/
|
||||
@Override
|
||||
protected void propertyChange(PropertyChangeEvent e) {
|
||||
|
||||
String name = e.getPropertyName();
|
||||
|
||||
// If they change the syntax scheme, we must do this so that
|
||||
// WrappedSyntaxView(_TEST) updates its child views properly.
|
||||
if (name.equals(RSyntaxTextArea.SYNTAX_SCHEME_PROPERTY)) {
|
||||
modelChanged();
|
||||
}
|
||||
|
||||
// Everything else is general to all RTextAreas.
|
||||
else {
|
||||
super.propertyChange(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Updates the view. This should be called when the underlying
|
||||
* Updates the view. This should be called when the underlying
|
||||
* <code>RSyntaxTextArea</code> changes its syntax editing style.
|
||||
*/
|
||||
public void refreshSyntaxHighlighting() {
|
||||
modelChanged();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the y-coordinate of the specified line.<p>
|
||||
* Returns the y-coordinate of the specified line.
|
||||
* <p>
|
||||
*
|
||||
* This method is quicker than using traditional
|
||||
* <code>modelToView(int)</code> calls, as the entire bounding box isn't
|
||||
@@ -241,16 +224,16 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
|
||||
@Override
|
||||
public int yForLine(int line) throws BadLocationException {
|
||||
Rectangle alloc = getVisibleEditorRect();
|
||||
if (alloc!=null) {
|
||||
RSTAView view = (RSTAView)getRootView(textArea).getView(0);
|
||||
if (alloc != null) {
|
||||
RSTAView view = (RSTAView) getRootView(textArea).getView(0);
|
||||
return view.yForLine(alloc, line);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the y-coordinate of the line containing a specified offset.<p>
|
||||
* Returns the y-coordinate of the line containing a specified offset.
|
||||
* <p>
|
||||
*
|
||||
* This is faster than calling <code>modelToView(offs).y</code>, so it is
|
||||
* preferred if you do not need the actual bounding box.
|
||||
@@ -258,12 +241,10 @@ public class RSyntaxTextAreaUI extends RTextAreaUI {
|
||||
@Override
|
||||
public int yForLineContaining(int offs) throws BadLocationException {
|
||||
Rectangle alloc = getVisibleEditorRect();
|
||||
if (alloc!=null) {
|
||||
RSTAView view = (RSTAView)getRootView(textArea).getView(0);
|
||||
if (alloc != null) {
|
||||
RSTAView view = (RSTAView) getRootView(textArea).getView(0);
|
||||
return view.yForLineContaining(alloc, offs);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user