gdx-studio
git clone https://git.pyrossh.dev/gdx-studio
An IDE for creating Games using libgdx and Java supported on all platforms Android, iOS, Desktop
src/gdxstudio/Editor.java
| a9b2a64 | 1 | package gdxstudio; |
| a9b2a64 | 2 | import gdxstudio.panel.ConsolePanel; |
| a9b2a64 | 3 | |
| a62d533 | 4 | import java.awt.Color; |
| a62d533 | 5 | import java.awt.Insets; |
| a62d533 | 6 | import java.awt.event.ActionEvent; |
| a62d533 | 7 | import java.awt.event.ActionListener; |
| a62d533 | 8 | import java.awt.event.FocusEvent; |
| a62d533 | 9 | import java.awt.event.FocusListener; |
| a62d533 | 10 | import java.io.File; |
| a62d533 | 11 | import java.io.IOException; |
| a62d533 | 12 | |
| a62d533 | 13 | import javax.swing.Timer; |
| a62d533 | 14 | import javax.swing.ToolTipManager; |
| a62d533 | 15 | import javax.swing.event.CaretEvent; |
| a62d533 | 16 | import javax.swing.event.CaretListener; |
| a62d533 | 17 | import javax.swing.text.BadLocationException; |
| a62d533 | 18 | |
| a62d533 | 19 | import org.fife.rsta.ac.LanguageSupport; |
| a62d533 | 20 | import org.fife.rsta.ac.LanguageSupportFactory; |
| a62d533 | 21 | import org.fife.rsta.ac.java.JavaLanguageSupport; |
| a62d533 | 22 | import org.fife.ui.autocomplete.DefaultCompletionProvider; |
| a62d533 | 23 | import org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaHighlighter; |
| a62d533 | 24 | import org.fife.ui.rsyntaxtextarea.SyntaxConstants; |
| a62d533 | 25 | import org.fife.ui.rsyntaxtextarea.TextEditorPane; |
| a62d533 | 26 | import org.fife.ui.rtextarea.SearchContext; |
| a62d533 | 27 | import org.fife.ui.rtextarea.SearchEngine; |
| a62d533 | 28 | |
| a62d533 | 29 | final public class Editor extends TextEditorPane {
|
| a62d533 | 30 | private static final long serialVersionUID = 1L; |
| a62d533 | 31 | static DefaultCompletionProvider provider = new DefaultCompletionProvider(); |
| a62d533 | 32 | public static SearchContext context = new SearchContext(); |
| a62d533 | 33 | |
| 7c84877 | 34 | final private Timer saveTimer = new Timer(60000, new ActionListener(){
|
| a62d533 | 35 | @Override |
| a62d533 | 36 | public void actionPerformed(ActionEvent arg0) {
|
| a62d533 | 37 | save(); |
| a62d533 | 38 | } |
| a62d533 | 39 | }); |
| a62d533 | 40 | float zoomSize = 13; |
| a62d533 | 41 | |
| a62d533 | 42 | public Editor(){
|
| a62d533 | 43 | super(TextEditorPane.INSERT_MODE, true); |
| 7c84877 | 44 | saveTimer.start(); |
| a62d533 | 45 | setMargin(new Insets(0, 0, 0, 0)); |
| a62d533 | 46 | setMarginLineEnabled(true); |
| a62d533 | 47 | setMarginLineColor(new Color(248,248,248)); //FIXME color not changing |
| a62d533 | 48 | setAntiAliasingEnabled(true); |
| a62d533 | 49 | setAutoIndentEnabled(true); |
| a62d533 | 50 | setBracketMatchingEnabled(true); |
| a62d533 | 51 | setUseFocusableTips(true); |
| a62d533 | 52 | setTabSize(4); |
| a62d533 | 53 | setLineWrap(true); |
| a62d533 | 54 | setWrapStyleWord(true); |
| a62d533 | 55 | setTabsEmulated(true); |
| a9b2a64 | 56 | load(); |
| a62d533 | 57 | setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA); |
| a62d533 | 58 | LanguageSupportFactory lsf = LanguageSupportFactory.get(); |
| a62d533 | 59 | LanguageSupport support = lsf.getSupportFor(SYNTAX_STYLE_JAVA); |
| a62d533 | 60 | LanguageSupportFactory.get().register(this); |
| a62d533 | 61 | ToolTipManager.sharedInstance().registerComponent(this); |
| a62d533 | 62 | JavaLanguageSupport jls = (JavaLanguageSupport)support; |
| a62d533 | 63 | jls.getParser(this).setEnabled(false); |
| a62d533 | 64 | try {
|
| 0000000 | 65 | try {
|
| 0000000 | 66 | jls.getJarManager().addCurrentJreClassFileSource(); |
| 0000000 | 67 | } catch (IllegalArgumentException e) {
|
| 0000000 | 68 | // JDK 9+ has no rt.jar/classes.jar for LibraryInfo.getMainJreJarInfo() |
| 0000000 | 69 | // to find; core JDK classes just won't get autocomplete support. |
| 0000000 | 70 | } |
| a62d533 | 71 | jls.setAutoActivationEnabled(true); |
| a62d533 | 72 | jls.setAutoCompleteEnabled(true); |
| a62d533 | 73 | jls.setAutoActivationDelay(50); |
| a62d533 | 74 | String filename = this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile(); |
| a62d533 | 75 | if(filename.endsWith(".jar"))
|
| a62d533 | 76 | jls.getJarManager().addClassFileSource(new File(filename)); |
| a62d533 | 77 | jls.install(this); |
| a62d533 | 78 | } catch (IOException ioe) {
|
| a62d533 | 79 | ioe.printStackTrace(); |
| a62d533 | 80 | } |
| a62d533 | 81 | ((RSyntaxTextAreaHighlighter ) getHighlighter()).setDrawsLayeredHighlights(false); |
| a62d533 | 82 | addFocusListener(new FocusListener(){
|
| a62d533 | 83 | @Override |
| a62d533 | 84 | public void focusGained(FocusEvent arg0) {
|
| a62d533 | 85 | saveTimer.start(); |
| a62d533 | 86 | } |
| a62d533 | 87 | |
| a62d533 | 88 | @Override |
| a62d533 | 89 | public void focusLost(FocusEvent arg0) {
|
| a62d533 | 90 | saveTimer.stop(); |
| a62d533 | 91 | save(); |
| a62d533 | 92 | } |
| a62d533 | 93 | }); |
| a62d533 | 94 | |
| a62d533 | 95 | addCaretListener(new CaretListener(){
|
| a62d533 | 96 | @Override |
| a62d533 | 97 | public void caretUpdate(CaretEvent e) {
|
| a62d533 | 98 | StatusBar.updateCaret(getCaretLineNumber()+1, getCaretOffsetFromLineStart()+1); |
| a62d533 | 99 | } |
| a62d533 | 100 | }); |
| a62d533 | 101 | } |
| a62d533 | 102 | |
| a62d533 | 103 | public void load(){
|
| a9b2a64 | 104 | if(Frame.scenePanel.selectedValueExists()){
|
| a9b2a64 | 105 | setText(Export.readFile("source/"+Frame.scenePanel.getSelectedValue()+".java"));
|
| a62d533 | 106 | setCaretPosition(0); |
| a62d533 | 107 | setDirty(false); |
| a62d533 | 108 | } |
| a62d533 | 109 | } |
| a62d533 | 110 | |
| a62d533 | 111 | @Override |
| a62d533 | 112 | public void save(){
|
| a62d533 | 113 | if(isDirty()){
|
| a9b2a64 | 114 | if(Frame.scenePanel.selectedValueExists()){
|
| a9b2a64 | 115 | Export.writeFile("source/"+Frame.scenePanel.getSelectedValue()+".java", getText());
|
| a9b2a64 | 116 | ConsolePanel.compile(Frame.scenePanel.getSelectedValue()); |
| a62d533 | 117 | setDirty(false); |
| a62d533 | 118 | } |
| a62d533 | 119 | } |
| a62d533 | 120 | } |
| a62d533 | 121 | |
| a62d533 | 122 | public void zoomin(){
|
| a62d533 | 123 | zoomSize += 1; |
| a62d533 | 124 | setFont(getFont().deriveFont(zoomSize)); |
| a62d533 | 125 | } |
| a62d533 | 126 | |
| a62d533 | 127 | public void zoomout(){
|
| a62d533 | 128 | zoomSize -= 1; |
| a62d533 | 129 | setFont(getFont().deriveFont(zoomSize)); |
| a62d533 | 130 | } |
| a62d533 | 131 | |
| a62d533 | 132 | public void find(String text){
|
| a62d533 | 133 | context.setSearchFor(text); |
| a62d533 | 134 | SearchEngine.find(this, context); |
| a62d533 | 135 | } |
| a62d533 | 136 | |
| a62d533 | 137 | public void replace(String text, String replaceText){
|
| a62d533 | 138 | context.setSearchFor(text); |
| a62d533 | 139 | context.setReplaceWith(replaceText); |
| a62d533 | 140 | SearchEngine.replace(this, context); |
| a62d533 | 141 | } |
| a62d533 | 142 | |
| a62d533 | 143 | public void replaceAll(String text, String replaceText){
|
| a62d533 | 144 | context.setSearchFor(text); |
| a62d533 | 145 | context.setReplaceWith(replaceText); |
| a62d533 | 146 | SearchEngine.replaceAll(this, context); |
| a62d533 | 147 | } |
| a62d533 | 148 | |
| a62d533 | 149 | public void addWarning(int line, String tip){
|
| a62d533 | 150 | if(getLineCount() >= line){
|
| a62d533 | 151 | try {
|
| a62d533 | 152 | Content.editorScroll.getGutter().addLineTrackingIcon(line-1, Icon.icon("warning"), tip);
|
| a62d533 | 153 | } |
| a62d533 | 154 | catch (BadLocationException e){
|
| a62d533 | 155 | e.printStackTrace(); |
| a62d533 | 156 | } |
| a62d533 | 157 | } |
| a62d533 | 158 | } |
| a62d533 | 159 | |
| a62d533 | 160 | public void addError(int line, String tip){
|
| a62d533 | 161 | if(getLineCount() >= line){
|
| a62d533 | 162 | try {
|
| a62d533 | 163 | Content.editorScroll.getGutter().addLineTrackingIcon(line-1, Icon.icon("error"), tip);
|
| a62d533 | 164 | } |
| a62d533 | 165 | catch (BadLocationException e){
|
| a62d533 | 166 | e.printStackTrace(); |
| a62d533 | 167 | } |
| a62d533 | 168 | } |
| a62d533 | 169 | } |
| a62d533 | 170 | |
| a62d533 | 171 | public void clearIcons(){
|
| a62d533 | 172 | Content.editorScroll.getGutter().removeAllTrackingIcons(); |
| a62d533 | 173 | } |
| a62d533 | 174 | } |