diff options
| author | janna <unknown> | 2003-11-15 16:24:49 +0000 |
|---|---|---|
| committer | janna <unknown> | 2003-11-15 16:24:49 +0000 |
| commit | d749e2d7aa2e597890fd2e92412cf043f48fbeb4 (patch) | |
| tree | 4e7addfd54eedbd0906ac13c77f96573937a8cec | |
| parent | 5b3735e34e5e85e622fcadb520f84a9de783e48d (diff) | |
*** empty log message ***
| -rw-r--r-- | src/GF/Shell/Commands.hs | 2 | ||||
| -rw-r--r-- | src/JavaGUI/DynamicTree2.java | 272 | ||||
| -rw-r--r-- | src/JavaGUI/GFEditor2.java | 447 | ||||
| -rw-r--r-- | src/Makefile | 2 |
4 files changed, 563 insertions, 160 deletions
diff --git a/src/GF/Shell/Commands.hs b/src/GF/Shell/Commands.hs index 4fb3048ee..b5bd28e3c 100644 --- a/src/GF/Shell/Commands.hs +++ b/src/GF/Shell/Commands.hs @@ -432,7 +432,7 @@ displaySStateJavaX isNew env state = unlines $ tagXML "gfedit" $ concat [ zipper = stateSState state linAll = map lin lgrs gr = firstStateGrammar env - mark = if isNew then markOptXML else markOptJava + mark = markOptXML -- markOptJava langAbstract = language "Abstract" langXML = language "XML" diff --git a/src/JavaGUI/DynamicTree2.java b/src/JavaGUI/DynamicTree2.java new file mode 100644 index 000000000..9abd9671d --- /dev/null +++ b/src/JavaGUI/DynamicTree2.java @@ -0,0 +1,272 @@ +
+/*
+ * This code is based on an example provided by Richard Stanford,
+ * a tutorial reader.
+ */
+
+import java.awt.*;
+import javax.swing.*;
+import javax.swing.tree.*;
+import javax.swing.event.*;
+import java.util.Vector;
+import java.awt.event.*;
+
+public class DynamicTree2 extends JPanel implements KeyListener,
+ ActionListener{
+ public static DefaultMutableTreeNode rootNode;
+ protected DefaultTreeModel treeModel;
+ public JTree tree;
+ public int oldSelection = 0;
+ private Toolkit toolkit = Toolkit.getDefaultToolkit();
+ JPopupMenu popup = new JPopupMenu();
+ JMenuItem menuItem;
+ Timer timer = new Timer(500, this);
+ MouseEvent m;
+
+ public DynamicTree2() {
+ timer.setRepeats(false);
+ rootNode = new DefaultMutableTreeNode("Root Node");
+ treeModel = new DefaultTreeModel(rootNode);
+ treeModel.addTreeModelListener(new MyTreeModelListener());
+
+ tree = new JTree(treeModel);
+ tree.setRootVisible(false);
+ tree.setEditable(false);
+ tree.getSelectionModel().setSelectionMode
+ (TreeSelectionModel.SINGLE_TREE_SELECTION);
+ tree.addKeyListener(this);
+ menuItem = new JMenuItem("Paste");
+ menuItem.addActionListener(this);
+ popup.add(menuItem);
+
+ //Add listener to components that can bring up popup menus.
+ MouseListener popupListener = new PopupListener();
+ tree.addMouseListener(popupListener);
+
+ tree.addTreeSelectionListener(new TreeSelectionListener() {
+ public void valueChanged(TreeSelectionEvent e) {
+ if (tree.getSelectionRows()!=null) {
+ if (GFEditor2.nodeTable == null)
+ {if (GFEditor2.debug) System.out.println("null node table");}
+ else
+ {if (GFEditor2.debug) System.out.println("node table: "+
+ GFEditor2.nodeTable.contains(new Integer(0)) +" "+
+ GFEditor2.nodeTable.keys().nextElement()); }
+ if (tree.getSelectionPath() == null)
+ {if (GFEditor2.debug) System.out.println("null root path"); }
+ else
+ {if (GFEditor2.debug) System.out.println("selected path"+
+ tree.getSelectionPath());}
+ int i = ((Integer)GFEditor2.nodeTable.get(
+ tree.getSelectionPath())).intValue();
+ int j = oldSelection;
+ GFEditor2.treeChanged = true;
+ if (i>j) GFEditor2.send("> "+String.valueOf(i-j));
+ else GFEditor2.send("< "+String.valueOf(j-i));
+ }
+ }
+ });
+
+ tree.setCellRenderer(new MyRenderer());
+ tree.setShowsRootHandles(true);
+ setPreferredSize(new Dimension(200, 100));
+ JScrollPane scrollPane = new JScrollPane(tree);
+ setLayout(new GridLayout(1,0));
+ add(scrollPane);
+ }
+
+ /** Remove all nodes except the root node. */
+ public void clear() {
+ rootNode.removeAllChildren();
+ treeModel.reload();
+ }
+
+ /** Remove the currently selected node. */
+ public void removeCurrentNode() {
+ TreePath currentSelection = tree.getSelectionPath();
+ if (currentSelection != null) {
+ DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode)
+ (currentSelection.getLastPathComponent());
+ MutableTreeNode parent = (MutableTreeNode)(currentNode.getParent());
+ if (parent != null) {
+ treeModel.removeNodeFromParent(currentNode);
+ return;
+ }
+ }
+
+ // Either there was no selection, or the root was selected.
+ toolkit.beep();
+ }
+
+ /** Add child to the currently selected node. */
+ public DefaultMutableTreeNode addObject(Object child) {
+ DefaultMutableTreeNode parentNode = null;
+ TreePath parentPath = tree.getSelectionPath();
+
+ if (parentPath == null) {
+ parentNode = rootNode;
+ } else {
+ parentNode = (DefaultMutableTreeNode)
+ (parentPath.getLastPathComponent());
+ }
+
+ return addObject(parentNode, child, true);
+ }
+
+ public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent,
+ Object child) {
+ return addObject(parent, child, false);
+ }
+
+ public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent,
+ Object child,
+ boolean shouldBeVisible) {
+ DefaultMutableTreeNode childNode =
+ new DefaultMutableTreeNode(child);
+
+ if (parent == null) {
+ parent = rootNode;
+ }
+
+ treeModel.insertNodeInto(childNode, parent,
+ parent.getChildCount());
+
+ // Make sure the user can see the lovely new node.
+ if (shouldBeVisible) {
+ tree.scrollPathToVisible(new TreePath(childNode.getPath()));
+ }
+ return childNode;
+ }
+
+ class MyTreeModelListener implements TreeModelListener {
+ public void treeNodesChanged(TreeModelEvent e) {
+ DefaultMutableTreeNode node;
+ node = (DefaultMutableTreeNode)
+ (e.getTreePath().getLastPathComponent());
+
+ /*
+ * If the event lists children, then the changed
+ * node is the child of the node we've already
+ * gotten. Otherwise, the changed node and the
+ * specified node are the same.
+ */
+ try {
+ int index = e.getChildIndices()[0];
+ node = (DefaultMutableTreeNode)
+ (node.getChildAt(index));
+ } catch (NullPointerException exc) {}
+
+ if (GFEditor2.debug) System.out.println
+ ("The user has finished editing the node.");
+ if (GFEditor2.debug) System.out.println(
+ "New value: " + node.getUserObject());
+ }
+ public void treeNodesInserted(TreeModelEvent e) {
+ }
+ public void treeNodesRemoved(TreeModelEvent e) {
+ }
+ public void treeStructureChanged(TreeModelEvent e) {
+ }
+ }
+
+ private class MyRenderer extends DefaultTreeCellRenderer {
+ ImageIcon tutorialIcon;
+
+ public MyRenderer() {
+ tutorialIcon = new ImageIcon("images/middle.gif");
+ }
+
+ public Component getTreeCellRendererComponent(
+ JTree tree,
+ Object value,
+ boolean sel,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus) {
+
+ super.getTreeCellRendererComponent(
+ tree, value, sel,
+ expanded, leaf, row,
+ hasFocus);
+ if (leaf && isTutorialBook(value))
+ setIcon(tutorialIcon);
+
+ return this;
+ }
+ protected boolean isTutorialBook(Object value) {
+ DefaultMutableTreeNode node =
+ (DefaultMutableTreeNode)value;
+ String nodeInfo =
+ (String)(node.getUserObject());
+
+ if (nodeInfo.indexOf("?") >= 0) {
+ return true;
+ }
+
+ return false;
+ }
+
+ }//class
+
+ class PopupListener extends MouseAdapter {
+ public void mousePressed(MouseEvent e) {
+ int selRow = tree.getRowForLocation(e.getX(), e.getY());
+ tree.setSelectionRow(selRow);
+ if (GFEditor2.debug) System.out.println("selection changed!");
+ maybeShowPopup(e);
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ if (GFEditor2.debug) System.out.println("mouse released!");
+ maybeShowPopup(e);
+ }
+ }
+ void maybeShowPopup(MouseEvent e) {
+ if (GFEditor2.debug) System.out.println("may be!");
+ if (e.isPopupTrigger()) {
+ m=e;
+ timer.start();
+ }
+ }
+ void addMenuItem(String name){
+ menuItem = new JMenuItem(name);
+ menuItem.addActionListener(this);
+ popup.add(menuItem);
+
+ }
+
+ public void actionPerformed(ActionEvent ae)
+ {
+ if (ae.getSource()==timer){
+ if (GFEditor2.debug) System.out.println("changing menu!");
+ popup.removeAll();
+ for (int i = 0; i<GFEditor2.listModel.size() ; i++)
+ addMenuItem(GFEditor2.listModel.elementAt(i).toString());
+ popup.show(m.getComponent(), m.getX(), m.getY());
+ }
+ else{
+ GFEditor2.treeChanged = true;
+ GFEditor2.send((String)GFEditor2.commands.elementAt
+ (popup.getComponentIndex((JMenuItem)(ae.getSource()))));
+ }
+ }
+
+ /** Handle the key pressed event. */
+ public void keyPressed(KeyEvent e) {
+ int keyCode = e.getKeyCode();
+ switch (keyCode){
+ case 32: GFEditor2.send("'"); break;
+ case 127: GFEditor2.send("d"); break;
+ }
+ }
+ /** Handle the key typed event. */
+ public void keyTyped(KeyEvent e) {
+ }
+ /** Handle the key released event. */
+ public void keyReleased(KeyEvent e) {
+ }
+
+}
+
+
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("<focus");
i=result.indexOf("type=",l);
j=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 <focus>
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 ((i<Math.min(first.length()-1,second.length()-1))&&(first.substring(0,i+1).equals(second.substring(0,i+1))))
+ {
+ common=first.substring(0,i+1);
+ i+=2;
+ }
+ if (common.charAt(common.length()-1)==']')
+ return common;
+ else
+ return common+"]";
+ }
+ public String findMax(int begin, int end)
+ {
+ String max = ((MarkedArea)outputVector.elementAt(begin)).position;
+ for (int i = begin+1; i <= end; i++)
+ max = comparePositions(max,((MarkedArea)outputVector.elementAt(i)).position);
+ return max;
+ }
public void caretUpdate(CaretEvent e)
{
- String position ="";
- MarkedArea jElement;
+ String jPosition ="", iPosition="", position="";
+ MarkedArea jElement = null;
+ MarkedArea iElement = null;
int j = 0;
+ int i = outputVector.size()-1;
int start = output.getSelectionStart();
int end = output.getSelectionEnd();
- System.out.println("SELECTION START POSITION: "+start);
- System.out.println("SELECTION END POSITION: "+end);
- if (end>0&&(end<output.getText().length()))
- System.out.println(output.getText().charAt(end));
+ if (debug2)
+ System.out.println("SELECTION START POSITION: "+start);
+ if (debug2)
+ System.out.println("SELECTION END POSITION: "+end);
+ if ((debug2)&&(end>0&&(end<output.getText().length())))
+ System.out.println("CHAR: "+output.getText().charAt(end));
+ // not null selection:
if (start<output.getText().length()-1)
{
+ // localizing end:
while ((j< outputVector.size())&&(((MarkedArea)outputVector.elementAt(j)).end < end))
j++;
- if (j<outputVector.size())
+ // localising start:
+ while ((i>=0)&&(((MarkedArea)outputVector.elementAt(i)).begin > start))
+ i--;
+
+ if ((j<outputVector.size()))
{
- jElement = (MarkedArea)outputVector.elementAt(j);
- if (end>=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("<subtree");
l2 = restString.indexOf("</subtree");
while ((l2>-1)||(l>-1))
{
- if ((l<l2)&&(l>-1))
+ if ((l2==-1)||((l<l2)&&(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<n))
- { selectionCheck=false;
- System.out.println("SELECTION HAS A SEPARATE POSITION");
- if ((selEnd<l)&&(currentLength<l-1))
- {
- // register the selection first:
- newLength = l-1;
- outputVector.add(new MarkedArea(currentLength+oldLength, newLength+oldLength, focusPosition));
- addedLength = newLength-currentLength+1;
- resultCurrent = currentLength+oldLength;
- resultNew = newLength+oldLength;
- System.out.println("APPENDING SelectedZONE First Before Tag:"
- +restString.substring(currentLength+j-l+1,newLength+j-l+1)+
- "Length: "+addedLength+" POSITION: "+resultCurrent + " "+resultNew);
- currentLength = newLength+1;
-
- // register the rest:
- newLength = n-j-3+l;
- addedLength = newLength-currentLength+1;
- resultCurrent = currentLength+oldLength;
- resultNew = newLength+oldLength;
- outputVector.add(new MarkedArea(currentLength+oldLength, newLength+oldLength, position));
- System.out.println("APPENDING ZONE Second:"+restString.substring(currentLength+j-l+1,newLength+j-l+1)+
- "Length: "+addedLength+" POSITION: "+resultCurrent + " "+resultNew);
- }
- else
- if (n-selEnd<=3)
- if (selStart-j<=3)
- { // only selection is to register:
- addedLength = newLength-currentLength+1;
- resultCurrent = currentLength+oldLength;
- resultNew = newLength+oldLength;
- outputVector.add(new MarkedArea(resultCurrent, resultNew, focusPosition));
- System.out.println("APPENDING SelectedZONE ONLy:"+restString.substring(selStart,selEnd+1)+
- "Length: "+addedLength+" POSITION: "+resultCurrent + " "+resultNew);
- currentLength = newLength+1;
- }
- else
- {
- // register the rest:
- newLength = newLength - selEnd + selStart-1;
- resultCurrent = currentLength+oldLength;
- resultNew = newLength+oldLength;
- addedLength = newLength-currentLength+1;
- outputVector.add(new MarkedArea(resultCurrent, resultNew, position));
- System.out.println("APPENDING ZONE First:"+restString.substring(currentLength+j-l+2,newLength+j-l+3)+
- "Length: "+addedLength+" POSITION: "+resultCurrent + " "+resultNew);
- currentLength = newLength+1;
-
- //selection second:
- newLength = currentLength + selEnd - selStart;
- outputVector.add(new MarkedArea(currentLength+oldLength, newLength+oldLength, focusPosition));
- addedLength = newLength-currentLength+1;
- resultCurrent = currentLength+oldLength;
- resultNew = newLength+oldLength;
- System.out.println("APPENDING SelectedZONE Second:"+restString.substring(currentLength+j-l+2,newLength+j-l+3)+
- "Length: "+addedLength+" POSITION: "+resultCurrent + " "+resultNew);
- }
- else
- { // selection first?:
- newLength = selEnd-j+l-1;
- outputVector.add(new MarkedArea(currentLength+oldLength, newLength+oldLength, focusPosition));
- addedLength = newLength-currentLength+1;
- resultCurrent = currentLength+oldLength;
- resultNew = newLength+oldLength;
- System.out.println("APPENDING SelectedZONE First:"+restString.substring(currentLength+j-l+1,newLength+j-l+1)+
- "Length: "+addedLength+" POSITION: "+resultCurrent + " "+resultNew);
- currentLength = newLength+1;
-
- // register the rest:
- newLength = n-j-3+l;
- outputVector.add(new MarkedArea(currentLength+oldLength, newLength+oldLength, position));
- addedLength = newLength-currentLength+1;
- resultCurrent = currentLength+oldLength;
- resultNew = newLength+oldLength;
- System.out.println("APPENDING ZONE Second:"+restString.substring(currentLength+j-l+1,newLength+j-l+1)+
- "Length: "+addedLength+" POSITION: "+resultCurrent + " "+resultNew);
- }
- }// if selectionCheck
- else
- {
- addedLength = newLength-currentLength+1;
- resultCurrent = currentLength+oldLength;
- resultNew = newLength+oldLength;
- outputVector.add(new MarkedArea(resultCurrent, resultNew, position));
- System.out.println("APPENDNG ZONE:"+restString.substring(currentLength+j-l+2,newLength+j-l+3)+
- "Length: "+addedLength+" POSITION: "+resultCurrent + " "+resultNew);
- }
- } //some words to register
- currentLength = newLength+1;
- removeSubTreeTag(l,j+1);
- l = restString.indexOf("<subtree");
- l2 = restString.indexOf("</subtree");
+ if (debug2)
+ System.out.println("SOMETHING BEFORE THE TAG");
+ register(currentLength, l, currentPosition);
+ }
+ // nothing before the tag:
+ else
+ {
+ if (debug2)
+ System.out.println("NOTHING BEFORE THE TAG");
+ register(j+2, n, position);
+ removeSubTreeTag(l,j+1);
+ }
+ currentLength += newLength ;
} // l<l2
else
{ // cutting the </subtree> tags:
removeSubTreeTag(l2,l2+10);
- l2 = restString.indexOf("</subtree");
- l = restString.indexOf("<subtree");
}
+ l2 = restString.indexOf("</subtree");
+ l = restString.indexOf("<subtree");
+ if (debug2)
+ System.out.println("/subtree index: "+l2 + "<subtree"+l);
} //while
if (outputVector.size()>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&&(selEnd<end))
+ {
+ selectionCheck=false;
+ if (debug2)
+ System.out.println("SELECTION HAS A SEPARATE POSITION");
+ // selection Second:
+ if (end-selEnd<=3)
+ if (selStart-start<=1)
+ { // only selection is to register:
+ resultCurrent = currentLength + oldLength ;
+ resultNew = newLength + resultCurrent - 1;
+ outputVector.add(new MarkedArea(resultCurrent, resultNew, focusPosition));
+ if (debug2)
+ System.out.println("APPENDING SelectedZONE ONLy:"+restString.substring(selStart,selEnd+2)+
+ "Length: "+newLength+" POSITION: "+resultCurrent + " "+resultNew);
+ }
+ else
+ {
+ // register the rest:
+ resultCurrent = currentLength+oldLength;
+ resultNew = resultCurrent+ selStart-start -1;
+ addedLength = selStart -start;
+ outputVector.add(new MarkedArea(resultCurrent, resultNew, position));
+ if (debug2)
+ System.out.println("APPENDING ZONE First:"+restString.substring(start,start+addedLength)+
+ "Length: "+addedLength+" POSITION: "+resultCurrent + " "+resultNew);
+ currentLength += addedLength;
+
+ //selection second:
+ newLength = selEnd - selStart+2;
+ resultCurrent = currentLength+oldLength;
+ resultNew = resultCurrent+ newLength -1;
+ outputVector.add(new MarkedArea(resultCurrent, resultNew, focusPosition));
+ if (debug2)
+ System.out.println("APPENDING SelectedZONE Second:"+restString.substring(selStart,selEnd+2)+
+ "Length: "+newLength+" POSITION: "+resultCurrent + " "+resultNew);
+ }
+ else
+ { // selection first:
+ addedLength = selEnd - selStart +2;
+ resultCurrent = currentLength+oldLength;
+ resultNew = resultCurrent + addedLength-1;
+ outputVector.add(new MarkedArea(resultCurrent, resultNew, focusPosition));
+ if (debug2)
+ System.out.println("APPENDING SelectedZONE First:"+restString.substring(selStart,selEnd+2)+
+ "Length: "+addedLength+" POSITION: "+resultCurrent + " "+resultNew);
+ currentLength += addedLength;
+
+ // register the rest:
+ newLength = end-selEnd-2;
+ resultCurrent = currentLength+oldLength;
+ resultNew = resultCurrent + newLength -1;
+ outputVector.add(new MarkedArea(resultCurrent, resultNew, position));
+ if (debug2)
+ System.out.println("APPENDING ZONE Second:"+restString.substring(selEnd+2,end)+
+ "Length: "+newLength+" POSITION: "+resultCurrent + " "+resultNew);
+ }
+ }// if selectionCheck
+ else
+ {
+ resultCurrent = currentLength + oldLength ;
+ resultNew = newLength + resultCurrent - 1;
+ stringToAppend = restString.substring(start,end);
+ if (stringToAppend.trim().length()>0)
+ {
+ 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;
diff --git a/src/Makefile b/src/Makefile index a2e1ee8dd..5f739e040 100644 --- a/src/Makefile +++ b/src/Makefile @@ -28,4 +28,4 @@ hugs: today: runhugs util/MkToday javac: - cd java ; javac GFEditor.java ; cd .. + cd java ; javac *.java ; cd .. |
