From e40680f5089106941c0d4bd960faa175b616de32 Mon Sep 17 00:00:00 2001 From: benfry Date: Sun, 5 Jan 2003 20:45:46 +0000 Subject: [PATCH] working on editor and fixing colors --- app/PdeBase.java | 32 +++++++++++--------------------- app/PdeEditor.java | 4 ++++ 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/app/PdeBase.java b/app/PdeBase.java index 7554057b3..3ca615a6b 100644 --- a/app/PdeBase.java +++ b/app/PdeBase.java @@ -1006,42 +1006,32 @@ public class PdeBase extends Frame implements ActionListener { return parsed; } + static public Font getFont(String which, Font otherwise) { //System.out.println("getting font '" + which + "'"); String str = get(which); if (str == null) return otherwise; // ENABLE LATER StringTokenizer st = new StringTokenizer(str, ","); - return new Font(st.nextToken(), - st.nextToken().equals("bold") ? Font.BOLD : Font.PLAIN, + return new Font(st.nextToken(), Font.PLAIN, Integer.parseInt(st.nextToken())); } - static public SimpleAttributeSet getStyle(String what, - SimpleAttributeSet otherwise) { - String str = get("editor.program." + what + ".style"); - if (str == null) return otherwise; // ENABLE LATER + static public SyntaxStyle getStyle(String what, String dflt) { + String str = get("editor.program." + what + ".style", dflt); + StringTokenizer st = new StringTokenizer(str, ","); - SimpleAttributeSet style = new SimpleAttributeSet(); - - StyleConstants.setFontFamily(style, st.nextToken()); - String s = st.nextToken(); - StyleConstants.setBold(style, s.indexOf("bold") != -1); - StyleConstants.setItalic(style, s.indexOf("italic") != -1); - - StyleConstants.setFontSize(style, Integer.parseInt(st.nextToken())); + if (s.indexOf("#") == 0) s = s.substring(1); + Color color = new Color(Integer.parseInt(s, 16)); s = st.nextToken(); - if (s.indexOf("#") == 0) s = s.substring(1); - StyleConstants.setForeground(style, new Color(Integer.parseInt(s, 16))); + boolean bold = (s.indexOf("bold") != -1); + boolean italic = (s.indexOf("italic") != -1); + //System.out.println(str + " " + bold + " " + italic); - s = st.nextToken(); - if (s.indexOf("#") == 0) s = s.substring(1); - StyleConstants.setBackground(style, new Color(Integer.parseInt(s, 16))); - - return style; + return new SyntaxStyle(color, italic, bold); } diff --git a/app/PdeEditor.java b/app/PdeEditor.java index b655aefe2..dbe68c33f 100644 --- a/app/PdeEditor.java +++ b/app/PdeEditor.java @@ -587,6 +587,7 @@ public class PdeEditor extends Panel { } //textarea.editorSetText(buffer.toString()); textarea.setText(buffer.toString()); + textarea.select(0, 0); historyLast = textarea.getText(); setSketchModified(false); @@ -990,6 +991,7 @@ afterwards, some of these steps need a cleanup function //System.out.print(program); //textarea.editorSetText(program); textarea.setText(program); + textarea.select(0, 0); //System.out.print(textarea.getText()); @@ -1027,6 +1029,7 @@ afterwards, some of these steps need a cleanup function //System.out.println("new guy, so setting empty"); // style info only gets set if there's text textarea.setText(""); + textarea.select(0, 0); //textarea.editorSetText(" "); // now set to now text. yay hack! //textarea.editorSetText(""); // this doesn't work. oh well @@ -1703,6 +1706,7 @@ afterwards, some of these steps need a cleanup function } //textarea.editorSetText(buffer.toString()); textarea.setText(buffer.toString()); + textarea.select(0, 0); setSketchModified(true); buttons.clear(); }