From d749e2d7aa2e597890fd2e92412cf043f48fbeb4 Mon Sep 17 00:00:00 2001 From: janna Date: Sat, 15 Nov 2003 16:24:49 +0000 Subject: *** empty log message *** --- src/JavaGUI/GFEditor2.java | 447 +++++++++++++++++++++++++++++---------------- 1 file changed, 289 insertions(+), 158 deletions(-) (limited to 'src/JavaGUI/GFEditor2.java') diff --git a/src/JavaGUI/GFEditor2.java b/src/JavaGUI/GFEditor2.java index 895781e50..e96e8abec 100644 --- a/src/JavaGUI/GFEditor2.java +++ b/src/JavaGUI/GFEditor2.java @@ -14,10 +14,18 @@ public class GFEditor2 extends JFrame implements ActionListener, CaretListener, KeyListener { public static boolean debug = false; - public static String focusPosition=""; + public static boolean debug2 = false; + public static boolean selectionCheck = false; + public static String focusPosition = ""; + public static String stringToAppend = ""; + public static String currentPosition = ""; public static int selStart = -1; public static int selEnd = -1; public static String restString = ""; + public static int currentLength = 0; + public static int newLength = 0; + public static int oldLength = 0; + public static int addedLength = 0; public static boolean newObject = false; public static boolean finished = false; @@ -54,7 +62,7 @@ public class GFEditor2 extends JFrame implements ActionListener, CaretListener, private static JTextArea output = new JTextArea(); public static DefaultListModel listModel= new DefaultListModel(); private JList list = new JList(listModel); - private static DynamicTree tree = new DynamicTree(); + private static DynamicTree2 tree = new DynamicTree2(); private JLabel grammar = new JLabel("No topic "); private JButton save = new JButton("Save"); @@ -379,7 +387,7 @@ public class GFEditor2 extends JFrame implements ActionListener, CaretListener, setSize(800,730); outputPanelUp.setPreferredSize(new Dimension(500,300)); treePanel.setDividerLocation(0.3); - nodeTable.put(new TreePath(DynamicTree.rootNode.getPath()), new Integer(0)); + nodeTable.put(new TreePath(DynamicTree2.rootNode.getPath()), new Integer(0)); setVisible(true); JRadioButton termButton = new JRadioButton("Term"); @@ -483,7 +491,8 @@ public class GFEditor2 extends JFrame implements ActionListener, CaretListener, try { output.setText(""); outputString = ""; - if (debug) System.out.println("output cleared"); + if (debug) + System.out.println("output cleared\n\n\n"); outputVector = new Vector(); toProc.write(text, 0, text.length()); toProc.newLine(); @@ -706,7 +715,8 @@ public class GFEditor2 extends JFrame implements ActionListener, CaretListener, result = fromProc.readLine(); if (debug) System.out.println("4 "+result); } - System.out.println("languageGroupElement formed"+ + if (debug) + System.out.println("languageGroupElement formed"+ languageGroup.getButtonCount()); langMenu.addSeparator(); fileMenuItem = new JMenuItem("Add..."); @@ -720,6 +730,8 @@ public class GFEditor2 extends JFrame implements ActionListener, CaretListener, public void outputAppend(){ int i, j, k, l, l2, selectionLength, m=0, n=0; + if (debug2) + System.out.println("INPUT:"+result); l = result.indexOf("',i); @@ -731,15 +743,15 @@ public class GFEditor2 extends JFrame implements ActionListener, CaretListener, if (debug) System.out.println("'POSITION START: "+m); n=result.indexOf("]",m); if (debug) System.out.println("POSITION END: "+n); -// if (debug) + if (debug) System.out.println("form Lin1: "+result); - focusPosition = result.substring(m+9,n); + focusPosition = result.substring(m+9,n+1); statusLabel.setText(" "+result.substring(i+5,j)); //cutting result= result.substring(0,l)+result.substring(j+2); i=result.indexOf("/focus",l); selectionLength = i-l-1; -// if (debug) + if (debug2) System.out.println("selection length: "+selectionLength); j=result.indexOf('>',i); k=result.length()-j-1; @@ -761,13 +773,16 @@ public class GFEditor2 extends JFrame implements ActionListener, CaretListener, // appending the resulting string // only one focus if (j==-1){ - System.out.println("ONE FOCUS"); - appendMarked(result+'\n',l,result.length()-k); + if (debug2) + System.out.println("ONE FOCUS"); + // last space is not included!: + appendMarked(result+'\n',l,l+selectionLength-2); } //several focuses else { - System.out.println("MANY FOCUSes"); - appendMarked(result.substring(0,j),l,l+selectionLength-1); + if (debug2) + System.out.println("MANY FOCUSes"); + appendMarked(result.substring(0,j),l,l+selectionLength-2); result = result.substring(j); outputAppend(); } @@ -1239,13 +1254,13 @@ public class GFEditor2 extends JFrame implements ActionListener, CaretListener, "Document is empty!","Error", JOptionPane.ERROR_MESSAGE); } } - public static void populateTree(DynamicTree treePanel) { + public static void populateTree(DynamicTree2 treePanel) { String p1Name = new String("Root"); DefaultMutableTreeNode p1; p1 = treePanel.addObject(null, p1Name); } - public static void formTree(DynamicTree treePanel) { + public static void formTree(DynamicTree2 treePanel) { Hashtable table = new Hashtable(); TreePath path=null; boolean treeStarted = false, selected = false; @@ -1412,189 +1427,206 @@ public class GFEditor2 extends JFrame implements ActionListener, CaretListener, /** Handle the key released event. */ public void keyReleased(KeyEvent e) { } + public String comparePositions(String first, String second) + { + String common ="[]"; + int i = 1; + while ((i0&&(end0&&(end=0)&&(((MarkedArea)outputVector.elementAt(i)).begin > start)) + i--; + + if ((j=jElement.begin) - { - position = jElement.position+"]"; - System.out.println("SELECTEDTEXT: "+position+"\n"); - treeChanged = true; - send("mp "+position); - } - } else - System.out.println("no position in vector of size: "+outputVector.size()); - } + jElement = (MarkedArea)outputVector.elementAt(j); + jPosition = jElement.position; + // less & before: + if (i==-1) + { // less: + if (end>=jElement.begin) + { + iElement = (MarkedArea)outputVector.elementAt(0); + iPosition = iElement.position; + if (debug2) + System.out.println("Less: "+jPosition+" and "+iPosition); + position = findMax(0,j); + if (debug2) + System.out.println("SELECTEDTEXT: "+position+"\n"); + treeChanged = true; + send("mp "+position); + } + // before: + else + if (debug2) + System.out.println("BEFORE vector of size: "+outputVector.size()); + } + // just: + else + { + iElement = (MarkedArea)outputVector.elementAt(i); + iPosition = iElement.position; + if (debug2) + System.out.println("SELECTEDTEXT: "+iPosition +" and "+jPosition+"\n"); + position = findMax(i,j); + if (debug2) + System.out.println("SELECTEDTEXT: "+position+"\n"); + treeChanged = true; + send("mp "+position); + } + } + else + // more && after: + if (i>=0) + { + iElement = (MarkedArea)outputVector.elementAt(i); + iPosition = iElement.position; + // more + if (start<=iElement.end) + { + jElement = (MarkedArea)outputVector.elementAt(outputVector.size()-1); + jPosition = jElement.position; + if (debug2) + System.out.println("MORE: "+iPosition+ " and "+jPosition); + position = findMax(i,outputVector.size()-1); + if (debug2) + System.out.println("SELECTEDTEXT: "+position+"\n"); + treeChanged = true; + send("mp "+position); + } + else + // after: + if (debug2) + System.out.println("AFTER vector of size: "+outputVector.size()); + } + else + // bigger: + { + iElement = (MarkedArea)outputVector.elementAt(0); + iPosition = iElement.position; + jElement = (MarkedArea)outputVector.elementAt(outputVector.size()-1); + jPosition = jElement.position; + if (debug2) + System.out.println("BIGGER: "+iPosition +" and "+jPosition+"\n"); + if (debug2) + System.out.println("SELECTEDTEXT: []\n"); + treeChanged = true; + send("mp []"); + } + }//not null selection } public static void appendMarked(String s, int selectionStart, int selectionEnd) { - System.out.println("STRING: "+s); - int oldLength = output.getText().length(); - int currentLength = 0; - int newLength=0; - int addedLength=0; - int resultCurrent=0; - int resultNew=0; - boolean selectionCheck ; - String position = ""; - int j, l, l2, n, m2, m1, pos, selStartTotal, selEndTotal; + if (debug2) + System.out.println("STRING: "+s); + currentLength = 0; + newLength=0; + oldLength = output.getText().length(); + int j, l, l2, n, pos, selStartTotal, selEndTotal, selEndT; restString = s; + int m2, m1; + String position = ""; if (selectionStart>-1) { selStart = selectionStart; selEnd = selectionEnd; - System.out.println("SELECTION: " + selStart + " "+selEnd+ "TOTAL: "+s.length()); + if (debug2) + System.out.println("SELECTION: " + selStart + " "+selEnd+ "TOTAL: "+s.length()); selectionCheck = (s.substring(selStart, selEnd).indexOf("<")==-1); l = restString.indexOf("-1)||(l>-1)) { - if ((l-1)) + if ((l2==-1)||((l-1))) { - m2 = restString.indexOf("]",l); - m1 = restString.indexOf("[",l); j = restString.indexOf(">",l); n = restString.indexOf("<",j); - // the tag has some words to register: - if ((n-j)>3) + m1 = restString.indexOf("[",l); + m2 = restString.indexOf("]",l); + //getting position: + position = restString.substring(m1,m2+1); + if (debug2) + System.out.println("<-POSITION: "+l+" CURRLENGTH: "+currentLength); + // something before the tag: + if (l-currentLength>1) { - //getting position: - - position = restString.substring(m1,m2); - - - newLength = n-j-3+l; - //focus has a separate position: - if (selectionCheck&&(selEnd tags: removeSubTreeTag(l2,l2+10); - l2 = restString.indexOf("0) { selStartTotal = selStart+oldLength; selEndTotal = selEnd+oldLength; + selEndT = selEndTotal+1; pos = ((MarkedArea)outputVector.elementAt(outputVector.size()-1)).end; - System.out.print("the last registered position: "+ pos); - System.out.println(" selStart: "+ selStartTotal+ " selEnd: "+selEndTotal); + if (debug2) + System.out.print("the last registered position: "+ pos); + if (debug2) + System.out.println(" selStart: "+ selStartTotal+ " selEnd: "+selEndTotal); if (selEnd+oldLength>pos) { - addedLength = selEnd-selStart+1; - outputVector.add(new MarkedArea(selStart+oldLength, selEnd+oldLength, focusPosition)); - System.out.println("APPENDNG Selection Last:"+restString.substring(selStart,selEnd+1)+ - "Length: "+addedLength+" POSITION: "+selStartTotal + " "+selEndTotal); + addedLength = selEnd-selStart+2; + outputVector.add(new MarkedArea(selStartTotal, selEndTotal+1, focusPosition)); + if (debug2) + System.out.println("APPENDNG Selection Last:"+restString.substring(selStart)+ + "Length: "+addedLength+" POSITION: "+selStartTotal + " "+selEndT); } } } //if selectionStart>-1 @@ -1602,15 +1634,114 @@ public class GFEditor2 extends JFrame implements ActionListener, CaretListener, output.append(restString); if (selectionStart>-1) try { - output.getHighlighter().addHighlight(selStart+oldLength, selEnd+oldLength, new DefaultHighlighter.DefaultHighlightPainter(Color.green) ); -// output.getHighlighter().addHighlight(selStart+oldLength, selEnd+oldLength, new DefaultHighlighter.DefaultHighlightPainter(Color.white) ); + output.getHighlighter().addHighlight(selStart+oldLength, selEnd+oldLength+1, new DefaultHighlighter.DefaultHighlightPainter(Color.green) ); +// output.getHighlighter().addHighlight(selStart+oldLength, selEnd+oldLength+1, new DefaultHighlighter.DefaultHighlightPainter(Color.white) ); } catch (Exception e) {System.out.println("highlighting problem!");} } + + + public static void register(int start, int end, String position) + { + oldLength = output.getText().length(); + addedLength = 0; + int resultCurrent = 0; + int resultNew = 0; + newLength = end-start; + // the tag has some words to register: + if (newLength>0) + { + //focus has a separate position: + if (selectionCheck&&(selEnd0) + { + outputVector.add(new MarkedArea(resultCurrent, resultNew, position)); + if (debug2) + System.out.println("APPENDING ZONE:"+stringToAppend+ + "Length: "+newLength+" POSITION: "+resultCurrent + " "+resultNew); + } + else + if (debug2) + System.out.println("whiteSpaces: "+newLength); + } + } //some words to register + } + //updating: public static void removeSubTreeTag (int start, int end) { + if (debug2) + System.out.println("removing: "+ start +" to "+ end); int difference =end-start+1; + int positionStart, positionEnd; + if ((newLength==0)&&(difference>20)) + { + positionStart = restString.indexOf("[", start); + positionEnd = restString.indexOf("]", start); + currentPosition = restString.substring(positionStart, positionEnd+1); + } restString = restString.substring(0,start)+restString.substring(end+1); if (selStart > end) { selStart -=difference; -- cgit v1.2.3