diff --git a/app/PdeBase.java b/app/PdeBase.java index 0820e1aa6..9427295f6 100644 --- a/app/PdeBase.java +++ b/app/PdeBase.java @@ -1,12 +1,14 @@ import java.awt.*; import java.awt.event.*; -//import java.applet.Applet; import java.io.*; import java.net.*; import java.util.*; import java.util.zip.*; import javax.comm.*; +// for getStyle method (may be temporary) +import javax.swing.text.*; + public class PdeBase implements ActionListener { static Properties properties; @@ -783,7 +785,7 @@ public class PdeBase implements ActionListener { static public SimpleAttributeSet getStyle(String what, SimpleAttributeSet otherwise) { - String str = get("editor.program." + which + ".style"); + String str = get("editor.program." + what + ".style"); if (str == null) return otherwise; // ENABLE LATER StringTokenizer st = new StringTokenizer(str, ","); @@ -795,7 +797,7 @@ public class PdeBase implements ActionListener { StyleConstants.setBold(style, s.indexOf("bold") != -1); StyleConstants.setItalic(style, s.indexOf("italic") != -1); - StyleConstants.setSize(style, Integer.parseInt(st.nextToken())); + StyleConstants.setFontSize(style, Integer.parseInt(st.nextToken())); s = st.nextToken(); if (s.indexOf("#") == 0) s = s.substring(1); diff --git a/app/PdeEditor.java b/app/PdeEditor.java index 318b2e916..b8e4d0186 100644 --- a/app/PdeEditor.java +++ b/app/PdeEditor.java @@ -40,8 +40,9 @@ public class PdeEditor extends Panel { PdeEditorHeader header; PdeEditorStatus status; PdeEditorConsole console; - //TextArea textarea; - JEditorPane textarea; + + //JEditorPane textarea; + PdeEditorTextPane textarea; boolean externalEditor; @@ -105,44 +106,29 @@ public class PdeEditor extends Panel { header = new PdeEditorHeader(this); rightPanel.add("North", header); - /* - textarea = - new TextArea("", - PdeBase.getInteger("editor.program.rows", 20), - PdeBase.getInteger("editor.program.columns", 60), - TextArea.SCROLLBARS_VERTICAL_ONLY); - */ try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } + textarea = new PdeEditorTextPane(); + JScrollPane scroller = new JScrollPane(); JViewport viewport = scroller.getViewport(); - - textarea = new JEditorPane("text/java", ""); - + //textarea = new JEditorPane("text/java", ""); viewport.add(textarea); - //viewport.setBackingStoreEnabled(true); - textarea.setFont(PdeBase.getFont("editor.program.font", - new Font("Monospaced", - Font.PLAIN, 12))); - textarea.setForeground(PdeBase.getColor("editor.program.fgcolor", - Color.black)); - textarea.setBackground(PdeBase.getColor("editor.program.bgcolor", - Color.white)); - /* - textarea.addMouseMotionListener(new MouseMotionAdapter() { - public void mouseMoved(MouseEvent e) { - frame.setCursor(Frame.CROSSHAIR_CURSOR); - } - }); - */ + //textarea.setFont(PdeBase.getFont("editor.program.font", + // new Font("Monospaced", + // Font.PLAIN, 12))); + //textarea.setForeground(PdeBase.getColor("editor.program.fgcolor", + // Color.black)); + //textarea.setBackground(PdeBase.getColor("editor.program.bgcolor", + // Color.white)); - //rightPanel.add("Center", textarea); rightPanel.add("Center", scroller); + //rightPanel.add("Center", textarea); Panel statusPanel = new Panel(); statusPanel.setLayout(new BorderLayout()); @@ -154,13 +140,10 @@ public class PdeEditor extends Panel { add("Center", rightPanel); - //if (!PdeBase.isMacintosh()) { // this still relevant? - /* - // hopefully these are no longer needed w/ swing - PdeEditorListener listener = new PdeEditorListener(this); - textarea.addKeyListener(listener); - textarea.addFocusListener(listener); - */ + // hopefully these are no longer needed w/ swing + //PdeEditorListener listener = new PdeEditorListener(this); + //textarea.addKeyListener(listener); + //textarea.addFocusListener(listener); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); if ((PdeBase.platform == PdeBase.MACOSX) || diff --git a/app/PdeEditorTextPane.java b/app/PdeEditorTextPane.java index 7aaeb63cc..e9e39e928 100644 --- a/app/PdeEditorTextPane.java +++ b/app/PdeEditorTextPane.java @@ -31,7 +31,8 @@ import java.io.*; import java.util.*; -public class PdeEditorTextPane extends JPanel { +//public class PdeEditorTextPane extends JPanel { +public class PdeEditorTextPane extends JTextPane { protected JTextPane textPane; // styled document that is the model for the textPane @@ -55,24 +56,38 @@ public class PdeEditorTextPane extends JPanel { // initial set up that sets the title //super("Programmer's Editor Demonstration"); + //setBackground(Color.orange); + // Create the document model. document = new HighLightedDocument(); // Create the text pane and configure it. - textPane = new JTextPane(document); - textPane.setCaretPosition(0); + + //textPane = new JTextPane(document); + setStyledDocument(document); + textPane = this; + + //textPane.setCaretPosition(0); //textPane.setMargin(new Insets(5,5,5,5)); - JScrollPane scrollPane = new JScrollPane(textPane); + + //JScrollPane scroller = new JScrollPane(); + //JViewport viewport = scroller.getViewport(); + //viewport.add(textPane); + + //// JScrollPane scrollPane = new JScrollPane(textPane); // specify the initial size and location for the window. //scrollPane.setPreferredSize(new Dimension(620, 460)); + //scrollPane.pack(); //setLocation(50, 50); // Add the components to the frame. //JPanel contentPane = new JPanel(new BorderLayout()); //contentPane.add(scrollPane, BorderLayout.CENTER); //setContentPane(contentPane); - add(scrollPane, BorderLayout.CENTER); + //// add(scrollPane, BorderLayout.CENTER); + + //scrollPane.setPreferredSize(getPreferredSize()); // Set up the menu bar. // JMenu styleMenu = createStyleMenu(); @@ -107,23 +122,23 @@ public class PdeEditorTextPane extends JPanel { StyleConstants.setItalic(dstyle, false); //styles.put("body", style); - styles.put("body", PdeBase.getStyle("body"), dstyle); - styles.put("tag", PdeBase.getStyle("tag"), dstyle); - styles.put("endtag", PdeBase.getStyle("tag"), dstyle); // same - styles.put("reference", PdeBase.getStyle("reference"), dstyle); - styles.put("name", PdeBase.getStyle("name"), dstyle); - styles.put("value", PdeBase.getStyle("value"), dstyle); - styles.put("text", PdeBase.getStyle("text"), dstyle); - styles.put("reservedWord", PdeBase.getStyle("reserved_word"), dstyle); - styles.put("identifier", PdeBase.getStyle("identifier"), dstyle); - styles.put("literal", PdeBase.getStyle("literal"), dstyle); - styles.put("separator", PdeBase.getStyle("separator"), dstyle); - styles.put("operator", PdeBase.getStyle("operator"), dstyle); - styles.put("comment", PdeBase.getStyle("comment"), dstyle); - styles.put("preprocessor", PdeBase.getStyle("preprocessor"), dstyle); - styles.put("whitespace", PdeBase.getStyle("whitespace"), dstyle); - styles.put("error", PdeBase.getStyle("error"), dstyle); - styles.put("unknown", PdeBase.getStyle("unknown"), dstyle); + styles.put("body", PdeBase.getStyle("body", dstyle)); + styles.put("tag", PdeBase.getStyle("tag", dstyle)); + styles.put("endtag", PdeBase.getStyle("tag", dstyle)); // same + styles.put("reference", PdeBase.getStyle("reference", dstyle)); + styles.put("name", PdeBase.getStyle("name", dstyle)); + styles.put("value", PdeBase.getStyle("value", dstyle)); + styles.put("text", PdeBase.getStyle("text", dstyle)); + styles.put("reservedWord", PdeBase.getStyle("reserved_word", dstyle)); + styles.put("identifier", PdeBase.getStyle("identifier", dstyle)); + styles.put("literal", PdeBase.getStyle("literal", dstyle)); + styles.put("separator", PdeBase.getStyle("separator", dstyle)); + styles.put("operator", PdeBase.getStyle("operator", dstyle)); + styles.put("comment", PdeBase.getStyle("comment", dstyle)); + styles.put("preprocessor", PdeBase.getStyle("preprocessor", dstyle)); + styles.put("whitespace", PdeBase.getStyle("whitespace", dstyle)); + styles.put("error", PdeBase.getStyle("error", dstyle)); + styles.put("unknown", PdeBase.getStyle("unknown", dstyle)); // create the new document. documentReader = new DocumentReader(document); @@ -131,19 +146,20 @@ public class PdeEditorTextPane extends JPanel { // Put the initial text into the text pane and // set it's initial coloring style. // initDocument(); - String initString = - ("/**\n" + - " * Simple common test program.\n" + - " */\n" + - "public class HelloWorld {\n" + - " public static void main(String[] args) {\n" + - " // Display the greeting.\n" + - " System.out.println(\"Hello World!\");\n" + - " }\n" + - "}\n"); + // String initString = + // ("/**\n" + + // " * Simple common test program.\n" + + // " */\n" + + // "public class HelloWorld {\n" + + // " public static void main(String[] args) {\n" + + // " // Display the greeting.\n" + + // " System.out.println(\"Hello World!\");\n" + + // " }\n" + + // "}\n"); syntaxLexer = new JavaLexer(documentReader); + /* try { document.insertString(document.getLength(), initString, @@ -151,6 +167,7 @@ public class PdeEditorTextPane extends JPanel { } catch (BadLocationException ble) { System.err.println("Couldn't insert initial text."); } + */ // put it all together and show it. //pack(); @@ -158,6 +175,54 @@ public class PdeEditorTextPane extends JPanel { } + ////////////////////////////////////////////////////////////// + + + /* + public void setText(String program) { + try { + document.remove(0, document.getLength()); + document.insertString(0, program, grabStyle("text")); + + } catch (BadLocationException ble) { + System.err.println("PdeEditorTextPane.setText() failed"); + } + } + + public String getText() { + try { + return document.getText(0, document.getLength()); + + } catch (BadLocationException ble) { + System.err.println("PdeEditorTextPane.getText() failed"); + } + return null; + } + + + public void setCaretPosition(int what) { + textPane.setCaretPosition(what); + } + + public int getCaretPosition() { + return textPane.getCaretPosition(); + } + + + public void setEditable(boolean maybe) { + textPane.setEditable(maybe); + } + + + public void select(int start, int stop) { + textPane.select(start, stop); + } + */ + + + ////////////////////////////////////////////////////////////// + + /** * Run the Syntax Highlighting as a separate thread. * Things that need to be colored are messaged to the @@ -347,7 +412,7 @@ public class PdeEditorTextPane extends JPanel { document.setCharacterAttributes( t.getCharBegin() + change, t.getCharEnd()-t.getCharBegin(), - getStyle(t.getDescription()), + grabStyle(t.getDescription()), true ); // record the position of the last bit of text that we colored @@ -556,7 +621,7 @@ public class PdeEditorTextPane extends JPanel { * or null if the styleName is not known. * @return the style */ - private SimpleAttributeSet getStyle(String styleName){ + private SimpleAttributeSet grabStyle(String styleName){ return ((SimpleAttributeSet)styles.get(styleName)); } @@ -727,7 +792,9 @@ public class PdeEditorTextPane extends JPanel { * removes to color them. */ private class HighLightedDocument extends DefaultStyledDocument { - public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { + public void insertString(int offs, String str, AttributeSet a) + throws BadLocationException { + synchronized (doclock){ super.insertString(offs, str, a); color(offs, str.length()); @@ -745,6 +812,7 @@ public class PdeEditorTextPane extends JPanel { } } + /** * A wrapper for a position in a document appropriate for storing * in a collection. @@ -815,6 +883,7 @@ class DocPosition { } } + /** * A comparator appropriate for use with Collections of * DocPositions. @@ -861,6 +930,7 @@ class DocPositionComparator implements Comparator{ } } + /** * A reader interface for an abstract document. Since * the syntax highlighting packages only accept Stings and diff --git a/build/windows/make.sh b/build/windows/make.sh index ece3fecaf..aa8cf1109 100755 --- a/build/windows/make.sh +++ b/build/windows/make.sh @@ -68,7 +68,7 @@ cd app CLASSPATH=../build/windows/work/classes:../build/windows/work/lib/kjc.jar:../build/windows/work/lib/oro.jar:../build/windows/work/java/lib/rt.jar:../build/windows/work/java/lib/ext/comm.jar -perl ../bagel/buzz.pl "jikes +D -classpath $CLASSPATH -d ../build/windows/work/classes" -dJDK13 *.java +perl ../bagel/buzz.pl "jikes +D -classpath $CLASSPATH -d ../build/windows/work/classes" -dJDK13 *.java lexer/*.java cd ../build/windows/work/classes rm -f ../lib/pde.jar