cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r753292 - in /cayenne/main/trunk/framework: cayenne-jdk1.5-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/ cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/
Date Fri, 13 Mar 2009 15:07:36 GMT
Author: aadamchik
Date: Fri Mar 13 15:07:35 2009
New Revision: 753292

URL: http://svn.apache.org/viewvc?rev=753292&view=rev
Log:
CAY-1164  Implement EJBQL query support in the Modeler

a patch by Olga to support line breaks and tabs

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/EJBQLParser.jjt
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/JCayenneTextPane.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/TextPaneView.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/UnderlineHighlighterForText.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/EJBQLParser.jjt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/EJBQLParser.jjt?rev=753292&r1=753291&r2=753292&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/EJBQLParser.jjt
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/jjtree/org/apache/cayenne/ejbql/EJBQLParser.jjt
Fri Mar 13 15:07:35 2009
@@ -86,6 +86,7 @@
  	" "
 	| "\r"
 	| "\t"
+	| "\n"
 }
 
 

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/JCayenneTextPane.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/JCayenneTextPane.java?rev=753292&r1=753291&r2=753292&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/JCayenneTextPane.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/JCayenneTextPane.java
Fri Mar 13 15:07:35 2009
@@ -7,6 +7,8 @@
 import java.awt.Graphics;
 import java.awt.Point;
 import java.awt.Rectangle;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
@@ -67,7 +69,7 @@
             y = (int) caretCoords.getY();
         }
         catch (BadLocationException ex) {
-            logObj.warn("Error: " , ex);
+            logObj.warn("Error: ", ex);
         }
 
         int lineHeight = pane.getFontMetrics(pane.getFont()).getHeight();
@@ -131,10 +133,10 @@
                     if (pane.getText(evt.getOffset(), 1).toString().equals("/")
                             || pane.getText(evt.getOffset(), 1).toString().equals("*")) {
                         pane.repaint();
-                    } 
+                    }
                 }
                 catch (Exception e) {
-                    logObj.warn("Error: " , e);
+                    logObj.warn("Error: ", e);
                 }
             }
 
@@ -155,17 +157,26 @@
     }
 
     public void setHighlightText(int line, int lastIndex, int size) {
-
-        int position;
+        int k = 0;
+        try {
+            Matcher matcherTab = Pattern.compile("\t").matcher(
+                    pane.getText(getPosition(line, 0), getPosition(line, lastIndex)));
+            while (matcherTab.find()) {
+                k += 7;
+            }
+        }
+        catch (BadLocationException e1) {
+            logObj.warn("Error: ", e1);
+        }
         try {
-            position = getPosition(line, lastIndex);
+            int position = getPosition(line, lastIndex-k);
             int positionEnd = position + size;
             Highlighter highlighter = pane.getHighlighter();
             removeHighlightText(highlighter);
             highlighter.addHighlight(position, positionEnd, painter);
         }
         catch (BadLocationException e) {
-            logObj.warn("Error: " , e);
+            logObj.warn("Error: ", e);
         }
     }
 
@@ -214,16 +225,22 @@
             }
         }
         catch (Exception e1) {
-            logObj.warn("Error: " , e1);
+            logObj.warn("Error: ", e1);
         }
 
         for (int line = startline, y = starting_y; line <= endline; y += fontHeight, line++)
{
             Color color = g.getColor();
-            g.setColor(Color.gray);
+
             Font f2 = SQLSyntaxConstants.DEFAULT_FONT;
             FontMetrics fm2 = getFontMetrics(f2);
             g.setFont(f2);
+            if (line - 1 == doc.getDefaultRootElement().getElementIndex(
+                    pane.getCaretPosition())) {
+                g.setColor(new Color(224, 224, 255));
+                g.fillRect(0, y - fontHeight + 3, 30, fontHeight + 1);
+            }
 
+            g.setColor(Color.gray);
             g.drawString(Integer.toString(line), (30 - fm2.stringWidth(Integer
                     .toString(line))) / 2, y);
             g.setColor(color);

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/TextPaneView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/TextPaneView.java?rev=753292&r1=753291&r2=753292&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/TextPaneView.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/TextPaneView.java
Fri Mar 13 15:07:35 2009
@@ -48,7 +48,7 @@
             String[] keywords2 = syntaxConstants.getKEYWORDS2();
             String[] operators = syntaxConstants.getOPERATORS();
             String[] types = syntaxConstants.getTYPES();
-            
+
             for (int i = 0; i < keywords.length; i++) {
                 String patern = "(" + keywords[i] + ")";
                 patternSyntaxStyle.put(Pattern.compile(patern, Pattern.UNICODE_CASE
@@ -66,7 +66,7 @@
                 patternSyntaxStyle.put(Pattern.compile(patern, Pattern.UNICODE_CASE
                         | Pattern.CASE_INSENSITIVE), style.syntaxStyleMap
                         .get(TextPaneStyleTypes.KEYWORDS));
-            }           
+            }
             for (int i = 0; i < types.length; i++) {
                 String patern = "(" + types[i] + ")";
                 patternSyntaxStyle.put(Pattern.compile(patern, Pattern.UNICODE_CASE
@@ -162,10 +162,14 @@
 
                 Matcher matcher = entry.getKey().matcher(text);
                 while (matcher.find()) {
-                    if ((text.length() == matcher.end()
+                     if ((text.length() == matcher.end()
+                            || text.charAt(matcher.end()) == '\t'
                             || text.charAt(matcher.end()) == ' ' || text.charAt(matcher
                             .end()) == '\n')
-                            && (matcher.start() == 0 || text.charAt(matcher.start()
- 1) == ' ')) {
+                            && (matcher.start() == 0
+                                    || text.charAt(matcher.start() - 1) == '\t'
+                                    || text.charAt(matcher.start() - 1) == '\n'
+                                    || text.charAt(matcher.start() - 1) == ' ')) {
                         boolean inComment = false;
                         for (Map.Entry<Integer, Integer> entryCommentInLine : commentInLine
                                 .entrySet()) {
@@ -175,7 +179,8 @@
                             }
                         }
                         if (!inComment) {
-                            startMap.put(matcher.start(), matcher.end());
+
+                            startMap.put(matcher.start(1), matcher.end());
                             syntaxStyleMap.put(matcher.start(1), entry.getValue());
                         }
                     }
@@ -189,9 +194,11 @@
                 while (matcher.find()) {
                     if ((text.length() == matcher.end()
                             || text.charAt(matcher.end()) == ' '
-                            || text.charAt(matcher.end()) == ')' || text.charAt(matcher
+                            || text.charAt(matcher.end()) == ')'
+                            || text.charAt(matcher.end()) == '\t' || text.charAt(matcher
                             .end()) == '\n')
                             && (matcher.start() == 0
+                                    || text.charAt(matcher.start() - 1) == '\t'
                                     || text.charAt(matcher.start() - 1) == ' '
                                     || text.charAt(matcher.start() - 1) == '=' || text
                                     .charAt(matcher.start() - 1) == '(')) {
@@ -210,7 +217,6 @@
                     }
                 }
             }
-
         }
         // TODO: check the map for overlapping parts
 

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/UnderlineHighlighterForText.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/UnderlineHighlighterForText.java?rev=753292&r1=753291&r2=753292&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/UnderlineHighlighterForText.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/swing/components/textpane/UnderlineHighlighterForText.java
Fri Mar 13 15:07:35 2009
@@ -82,19 +82,15 @@
 
             FontMetrics fm = c.getFontMetrics(c.getFont());
             int baseline = alloc.y + alloc.height - fm.getDescent() + 1;
-            int[] masY = {
-                    0, 1, 1, 0, -1, -1
-            };
-
-            int[] x = new int[alloc.width];
-            int[] y = new int[alloc.width];
-
-            for (int i = 0; i < alloc.width; i++) {
-                x[i] = alloc.x + i;
-                y[i] = baseline + masY[i % 6];
+
+            int i = alloc.x;
+            int end = alloc.x + alloc.width - 1;
+            while (i < end) {
+                g.drawLine(i, baseline, i + 2, baseline);
+                g.drawLine(i, baseline + 1, i + 2, baseline + 1);
+                i += 4;
             }
 
-            g.drawPolyline(x, y, alloc.width);
             return alloc;
         }
 



Mime
View raw message