mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup
This commit is contained in:
@@ -76,8 +76,8 @@ public class IpnbUtils {
|
||||
editorPane.setBackground(IpnbEditorUtil.getBackground());
|
||||
editorPane.setContentType(new HTMLEditorKit().getContentType());
|
||||
editorPane.setEditorKit(new HTMLEditorKit());
|
||||
|
||||
final StyleSheet sheet = ((HTMLDocument)editorPane.getDocument()).getStyleSheet();
|
||||
final HTMLDocument document = (HTMLDocument)editorPane.getDocument();
|
||||
final StyleSheet sheet = document.getStyleSheet();
|
||||
sheet.addRule(ourBodyRule);
|
||||
sheet.addRule(ourCodeRule);
|
||||
sheet.addRule(ourAlertRule);
|
||||
@@ -86,7 +86,7 @@ public class IpnbUtils {
|
||||
|
||||
editorPane.setEditable(false);
|
||||
|
||||
final String html = convertToHtml(source, editorPane);
|
||||
final String html = convertToHtml(source, document);
|
||||
editorPane.setText("<html><body>" + html + "</body></html>");
|
||||
|
||||
editorPane.addMouseListener(new MouseAdapter() {
|
||||
@@ -103,7 +103,8 @@ public class IpnbUtils {
|
||||
return editorPane;
|
||||
}
|
||||
|
||||
private static String convertToHtml(@NotNull final String source, @NotNull final JEditorPane editorPane) {
|
||||
|
||||
private static String convertToHtml(@NotNull final String source, @NotNull final HTMLDocument document) {
|
||||
final StringBuilder result = new StringBuilder();
|
||||
StringBuilder markdown = new StringBuilder();
|
||||
StringBuilder formula = new StringBuilder();
|
||||
@@ -162,7 +163,7 @@ public class IpnbUtils {
|
||||
markdown.append(charAt);
|
||||
}
|
||||
if (formula.length() != 0) {
|
||||
addFormula(formula.toString(), editorPane, imageIndex, result);
|
||||
addFormula(formula.toString(), document, imageIndex, result);
|
||||
|
||||
imageIndex += 1;
|
||||
formula = new StringBuilder();
|
||||
@@ -176,7 +177,7 @@ public class IpnbUtils {
|
||||
|
||||
}
|
||||
if (formula.length() != 0) {
|
||||
addFormula(formula.toString(), editorPane, imageIndex, result);
|
||||
addFormula(formula.toString(), document, imageIndex, result);
|
||||
}
|
||||
if (markdown.length() != 0) {
|
||||
result.append(markdown.toString());
|
||||
@@ -184,7 +185,7 @@ public class IpnbUtils {
|
||||
return markdown2Html(result.toString());
|
||||
}
|
||||
|
||||
private static void addFormula(@NotNull final String formulaText, JEditorPane editorPane, int imageIndex, StringBuilder result) {
|
||||
private static void addFormula(@NotNull final String formulaText, @NotNull final HTMLDocument editorDocument, int imageIndex, StringBuilder result) {
|
||||
final SnuggleEngine engine = new SnuggleEngine();
|
||||
engine.getPackages().add(0, IpnbTexPackageDefinitions.getPackage());
|
||||
|
||||
@@ -209,11 +210,11 @@ public class IpnbUtils {
|
||||
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
Dictionary<URL, BufferedImage> cache = (Dictionary<URL, BufferedImage>)editorPane.getDocument().getProperty("imageCache");
|
||||
Dictionary<URL, BufferedImage> cache = (Dictionary<URL, BufferedImage>)editorDocument.getProperty("imageCache");
|
||||
if (cache == null) {
|
||||
//noinspection UseOfObsoleteCollectionType
|
||||
cache = new Hashtable<URL, BufferedImage>();
|
||||
editorPane.getDocument().putProperty("imageCache", cache);
|
||||
editorDocument.putProperty("imageCache", cache);
|
||||
}
|
||||
|
||||
final URL u = new URL(ourImagePrefix + imageIndex + ".jpg");
|
||||
|
||||
@@ -9,8 +9,6 @@ import org.jetbrains.plugins.ipnb.editor.IpnbEditorUtil;
|
||||
import org.jetbrains.plugins.ipnb.format.cells.IpnbEditableCell;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.Utilities;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
@@ -166,22 +164,6 @@ public abstract class IpnbEditablePanel<T extends JComponent, K extends IpnbEdit
|
||||
return textArea;
|
||||
}
|
||||
|
||||
public int getLineCount(@NotNull final JTextArea textArea) {
|
||||
int totalCharacters = textArea.getText().length();
|
||||
int lineCount = 1;
|
||||
|
||||
try {
|
||||
int offset = totalCharacters;
|
||||
while (offset > 0) {
|
||||
offset = Utilities.getRowStart(textArea, offset) - 1;
|
||||
lineCount++;
|
||||
}
|
||||
} catch (BadLocationException e) {
|
||||
return 1;
|
||||
}
|
||||
return lineCount;
|
||||
}
|
||||
|
||||
public boolean contains(int y) {
|
||||
return y>= getTop() && y<=getBottom();
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ public class IpnbErrorPanel extends IpnbCodeOutputPanel<IpnbErrorOutputCell> {
|
||||
}
|
||||
else {
|
||||
substring = addString.substring(position, mIndex + 1);
|
||||
//noinspection AssignmentToStaticFieldFromInstanceMethod
|
||||
currentColor = getANSIColor(substring);
|
||||
}
|
||||
position = mIndex + 1;
|
||||
|
||||
Reference in New Issue
Block a user