001    /*
002     * Copyright 2007, 2012 Stephen Fisher and Junhyong Kim, University of
003     * Pennsylvania.
004     *
005     * This file is part of Glo-DB.
006     * 
007     * Glo-DB is free software: you can redistribute it and/or modify it
008     * under the terms of the GNU General Public License as published by
009     * the Free Software Foundation, either version 3 of the License, or
010     * (at your option) any later version.
011     * 
012     * Glo-DB is distributed in the hope that it will be useful, but
013     * WITHOUT ANY WARRANTY; without even the implied warranty of
014     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015     * General Public License for more details.
016     * 
017     * You should have received a copy of the GNU General Public License
018     * along with Glo-DB. If not, see <http://www.gnu.org/licenses/>.
019     *
020     * @(#)ViewParserDefs.java
021     */
022    
023    package edu.upenn.gloDB.gui;
024    
025    import java.awt.*;
026    //import java.awt.image.*;
027    import java.awt.event.*;
028    import javax.swing.*;
029    
030    /**
031     * View parser definitions.
032     *
033     * @author  Stephen Fisher
034     * @version $Id: ViewParserDefs.java,v 1.4.2.9 2007/03/01 21:17:33 fisher Exp $
035     */
036    
037    public class ViewParserDefs extends JFrame {
038             ViewParserDefs thisFrame;
039             
040             public ViewParserDefs() {
041                      super("GLODB: Parser Definitions");
042                      
043                      // keep pointer to self so can 'dispose' Frame below
044                      thisFrame = this;
045                      
046                      setDefaultCloseOperation(DISPOSE_ON_CLOSE);
047                      
048                      JTextArea text = new JTextArea(20, 110);
049                      text.setEditable(false);
050                      JScrollPane textSP = new JScrollPane(text);
051                      textSP.setBorder(BorderFactory.createLoweredBevelBorder());
052    
053                      // this should probably be in an HTML file that is displayed
054                      text.append(" Sequence:\n");
055                      text.append("      |------------------------------|\n");
056                      text.append("      |012345678901234567890123456789|\n");
057                      text.append("   t1:  r-s    t-------u v---w  x-y\n");
058                      text.append("   t2:  a-b   c-d e-f g---h i-j\n");
059                      text.append("\n Tracks:\n");
060                      text.append("   t1: {(r,s), (t,u), (v,w), (x,y)}\n");
061                      text.append("   t2: {(a,b), (c,d), (e,f), (g,h), (i,j)}\n");
062                      text.append("\n These treat Tracks as containing sets of intervals:\n");
063            text.append("   t1 AND t2:        {(r,s), (t,u), (v,w), (c,d), (e,f), (g,h), (i,j)}\n");
064            text.append("   t1 OR t2:         {(r,s), (t,u), (v,w), (x,y), (c,d), (e,f), (g,h), (i,j)}\n");
065            text.append("   t1 MINUS t2:      {(x,y)}\n");
066            text.append("   t2 MINUS t1:      {}\n");
067            text.append("   t1 sAND t2:       {(r,s)}\n");
068            text.append("   t1 sMINUS t2:     {(t,u), (v,w), (x,y)}\n");
069            text.append("   t2 sMINUS t1:     {(c,d), (e,f), (g,h), (i,j)}\n");
070            text.append("   t1 sMINUS t2 AND t2:   {(t,u), (v,w), (c,d), (e,f), (g,h), (i,j)}\n");
071            text.append("   t1 sMINUS (t2 AND t2): {(t,u), (v,w), (x,y)}\n");
072                      text.append("   (t1 MINUS t2) OR (t2 MINUS t1): {(x,y)}\n");
073                      text.append("   (t1 sMINUS t2) OR (t2 sMINUS t1): {(t,u), (v,w), (x,y), (c,d), (e,f), (g,h), (i,j)}\n");
074            text.append("   t1 POS{0} t2:     {}\n");
075            text.append("   t1 POS{5} t2:     {(t,u), (i,j)}\n");
076            text.append("   t2 POS{5} t1:     {(a,b), (t,u), (e,f), (v,w)}\n");
077            text.append("   t1 POS{-5} t2:    {(t,u), (e,f)}\n");
078            text.append("   t1 POS{3,6} t2:   {(r,s), (c,d), (t,u), (i,j)}\n");
079            text.append("   t1 POS{-5,-1} t2: {(r,s), (t,u), (e,f), (g,h), (v,w), (i,j)}\n");
080            text.append("\n These treat Tracks as masks over the Sequence string:\n");
081            text.append("   t1 && t2:         {(1,3), (8,9), (11,13), (15,16), (18,19), (21,22)}\n");
082            text.append("   t1 || t2:         {(1,3), (7,23), (25,27)}\n");
083            text.append("   t1 - t2:          {(10,10), (14,14), (20,20), (25,27)}\n");
084            text.append("   t2 - t1:          {(7,7), (17,17), (23,23)}\n");
085            text.append("   ! t1:             {(0,0), (4,7), (17,17), (23,24), (28,29)}\n");
086            text.append("   ! t2:             {(0,0), (4,6), (10,10), (14,14), (20,20), (24,29)}\n");
087            text.append("   ! t1 && t2:       {(7,7), (17,17), (23,23)}\n");
088            text.append("   t1 && ! t2:       {(10,10), (14,14), (20,20), (25,27)}\n");
089            text.append("   ! (t1 && t2):     {(0,0), (4,7), (10,10), (14,14), (17,17), (20,20), (23,29)}\n");
090            text.append("   ! (t1 || t2):     {(0,0), (4,6), (24,24), (28,29)}\n");
091            text.append("   ! (t1 - t2 && t1):   {(0,9), (11,13), (15,19), (21,24), (28,29)}\n");
092            text.append("   ! (t1 - (t2 && t1)): {(0,9), (11,13), (15,19), (21,24), (28,29)}\n");
093                      text.append("   (t1 - t2) || (t2 - t1): {(7,7), (10,10), (14,14), (17,17), (20,20), (23,23), (25,27)}\n");
094                      /*
095            text.append("   t1 .{0} t2:       {(1,3), (3,3), (8,16), (16,16), (18,22), (22,22)}\n");
096            text.append("   t1 .{5} t2:       {(1,3), (8,8), (8,16), (21,21)}\n");
097            text.append("   t2 .{5} t1:       {(1,3), (8,8), (7,9), (14,14), (11,13), (18,18)}\n");
098            text.append("   t1 .{-5} t2:      {(8,16), (11,11), (18,22), (17, 17), (25,27), (22,22)}\n");
099            text.append("   t1 .{3,6} t2:     {(1,3), (7,9), (8,16), (19,19), (21,22)}\n");
100            text.append("   t1 .{-5,-1} t2:   {(1,3), (1,2), (8,16), (11,13), (15,15), (18,22), (17,19), (25,27), (21,23)}\n");
101                      */
102    
103            text.append("\n\n\nTOKEN SYNTAX:\n");
104                      text.append("   EXPR      := <TRACK> (<opEXPR>)*\n");
105                      text.append("   opEXPR    := (<OPERATOR> | <POS> (<pREPEAT> | <oREPEAT>)?) <TRACK>\n");
106                      text.append("   TRACK     := (<IGNORE>)? (<bNOT>)? ( <GROUP> | <FEATURE>) (<QUALIFIER>)*\n");
107                      text.append("   GROUP     := \"(\" <EXPR> \")\"\n");
108                      text.append("   QUALIFIER := (<dREPEAT> | <oREPEAT> | <LENGTH> | <SEQUENCE>)\n");
109                      text.append("   OPERATOR  := <AND> | <OR> | <MINUS> | <sAND> | <sMINUS> | <bAND> | <bOR> | <bMINUS>\n");
110                      //              text.append("   POSITION  := <POS> | <bPOS>\n");
111                      text.append("   FEATURE   := <allTRACKS> | <TRACKREF>\n");
112                      text.append("   oREPEAT   := <HOOK> | <PLUS> | <STAR>\n");
113                      text.append("   pREPEAT   := <lREPEAT> <nINTEGER> (\",\" <nINTEGER>)? <rREPEAT>\n");
114                      text.append("   dREPEAT   := <lREPEAT> <INTEGER> (\",\" <INTEGER>)? (\";\" <INTEGER> (\",\" <INTEGER>)?)? <rREPEAT>\n");
115                      text.append("   LENGTH    := <lLENGTH2> <INTEGER> (\",\" <INTEGER>)? <rLENGTH> \n");
116                      text.append("   | <lLENGTH2> <INTEGER> (\",\" <INTEGER>)? (\";\" <INTEGER> (\",\" <INTEGER>)?)? <rLENGTH> \n");
117                      text.append("   | <lLENGTH2> <INTEGER> (\",\" <INTEGER>)? (\"from\" <INTEGER> (\",\" <INTEGER>)?)? <rLENGTH> \n");
118                      text.append("   | \"from\" <INTEGER> (\",\" <INTEGER>)? \n");
119    
120                      text.append("\n\n\nTOKENS:\n");
121                      text.append("     #SP0:      ( \" \" )*     // used to construct tokens below (0 or more spaces)\n");
122                      text.append("     #SP1:      ( \" \" )+     // used to construct tokens below (at least 1 space)\n");
123                      text.append("     EQUALS:    \"=\" \n");
124                      text.append("     SEPARATOR: \",\" \n");
125                      text.append("     INTEGER:   ( [\"0\"-\"9\"] )+ \n");
126                      text.append("     nINTEGER:  \"-\" <INTEGER> \n");
127                      text.append("     lLENGTH:   \"<\" \n");
128                      text.append("     lLENGTH2:  <lLENGTH> <SP0> \";\" \n");
129                      text.append("     rLENGTH:   \">\" \n");
130                      text.append("     LENGTH:    \"len\"\n");
131                      text.append("             |  \"length of\" \n");
132                      text.append("     FROM:      \"from\"\n");
133                      text.append("             |  \"from position\" \n");
134                      text.append("     lREPEAT:   \"{\" \n");
135                      text.append("     rREPEAT:   \"}\" \n");
136                      text.append("     lGROUP:    \"(\" \n");
137                      text.append("     rGROUP:    \")\" \n");
138                      text.append("     lSET:      \"[\" \n");
139                      text.append("     rSET:      \"]\" \n");
140                      text.append("     IGNORE:    \"~\" \n");
141                      text.append("     POS:       \"POS\" \n");
142                      //              text.append("     bPOS:      \".\" \n");
143                      text.append("     AND:       \"AND\" \n");
144                      text.append("     sAND:      \"sAND\" \n");
145                      text.append("     OR:        \"OR\" \n");
146                      text.append("     MINUS:     \"MINUS\"\n");
147                      text.append("     sMINUS:    \"sMINUS\"\n");
148                      text.append("     bAND:      \"&&\" \n");
149                      text.append("     bOR:       \"||\" \n");
150                      text.append("     bMINUS:    \"-\" \n");
151                      text.append("     bNOT:      \"!\" \n");
152                      text.append("     HOOK:      \"?\" \n");
153                      text.append("     PLUS:      \"+\" \n");
154                      text.append("     STAR:      \"*\" \n");
155                      text.append("     EOL:       \"\\n\" \n");
156                      text.append("     WITHIN:    \"within\" \n");
157                      text.append("     TIMES:     \"times\" \n");
158                      text.append("     REPEATED:  \"repeated\" \n");
159                      text.append("     POSITIONS: \"positions\" \n");
160                      text.append("     allTRACKS: \"__T\" \n");
161                      text.append("             |  \"a feature in any track\" \n");
162                      text.append("     OBJECT:    [\"a\"-\"z\",\"A\"-\"Z\",\"_\"] ( [\"a\"-\"z\",\"A\"-\"Z\",\"_\",\"0\"-\"9\"] )*  // a track or sequence name\n");
163                      text.append("     ASSIGN:    <OBJECT> <SPO> <EQUALS> \n");
164                      text.append("     TRACK:     \"a feature in track\" <SP1> \n");
165                      text.append("     SEQUENCE:  \"S:\" <SP0> \n");
166                      text.append("             |  \"seq\" <SP1> \n");
167                      text.append("             |  \"on sequence\" <SP1> \n");
168    
169                      // setup image area to display data
170                      //              ImageCanvas canvas = new ImageCanvas("C:\\Documents and Settings\\Gromit\\Desktop\\gloDB\\src\\documentation\\parser.gif");
171                      
172                      // setup close button
173                      JButton closeB = new JButton("Close Definitions Viewer");
174                      closeB.addActionListener(new ActionListener() {
175                                             public void actionPerformed(ActionEvent e) {
176                                                      thisFrame.dispose();
177                                             }
178                                    });
179                      
180                      getContentPane().setLayout(new BorderLayout());
181                      getContentPane().add(textSP, BorderLayout.CENTER);
182                      getContentPane().add(closeB, BorderLayout.SOUTH);
183                      pack();
184                      
185                      // set the default window size
186                      setSize(800, 900);
187                      
188                      // display the window
189                      //              setVisible(true);
190                      show();
191             }
192    
193             /*
194             private class ImageCanvas extends Canvas {
195                      Image image;
196    
197                      public ImageCanvas(String name) {
198                                    MediaTracker media = new MediaTracker(this);
199                                    image = Toolkit.getDefaultToolkit().getImage(name);
200                                    media.addImage(image, 0);
201                                    try { media.waitForID(0); }
202                                    catch (Exception e) {}
203                      }
204    
205                      public ImageCanvas(ImageProducer imageProducer) {
206                                    image = createImage(imageProducer);
207                      }
208    
209                      public void paint(Graphics g) {
210                                    g.drawImage(image, 0,0, this);
211                      }
212             }
213             */
214    
215    } // ViewParserDefs.java