Changeset 352


Ignore:
Timestamp:
10/08/08 13:59:53 (16 years ago)
Author:
bjn8
Message:

Improved widget linking... track-link coversion command

Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/greenstone/Greenstone3Connection.java

    r313 r352  
    1717import java.util.Set;
    1818
    19 import org.apache.xerces.parsers.DOMParser;
     19//import org.apache.xerces.parsers.DOMParser;
    2020import org.w3c.dom.Document;
    2121import org.w3c.dom.NamedNodeMap;
     
    425425                StringReader sr = new StringReader(result);
    426426                InputSource is = new InputSource(sr);
    427                 DOMParser p = new DOMParser();
    428 
    429                 try {
    430                         p.parse(is);
    431                 } catch (SAXException se) {
    432                         System.err.println(se);
    433                 } catch (IOException ioe) {
    434                         System.err.println(ioe);
    435                 }
    436                 Document d = p.getDocument();
    437                 NodeList metadataList = d.getElementsByTagName("metadata");
    438                 for (int i = 0; i < metadataList.getLength(); i++) {
    439                         Node n = metadataList.item(i);
    440                         NamedNodeMap nnm = n.getAttributes();
    441                         Node att = nnm.getNamedItem("name");
    442                         if (att.getNodeValue().compareTo("numDocsMatched") == 0) {
    443                                 queryOutcome.setHowManyDocsMatched(n.getFirstChild()
    444                                                 .getNodeValue());
    445                         } else if (att.getNodeValue().compareTo("numDocsReturned") == 0) {
    446                                 queryOutcome.setHowManyDocsReturned(n.getFirstChild()
    447                                                 .getNodeValue());
    448                         }
    449                 }
    450 
    451                 NodeList documentList = d.getElementsByTagName("documentNode");
    452                 for (int i = 0; i < documentList.getLength(); i++) {
    453                         Node n = documentList.item(i);
    454                         NamedNodeMap nnm = n.getAttributes();
    455                         Node nid = nnm.getNamedItem("nodeID");
    456                         Node nscore = nnm.getNamedItem("rank");
    457                         String docID = nid.getFirstChild().getNodeValue();
    458                         queryOutcome.addResult(docID, firstDoc + i, nscore.getFirstChild()
    459                                         .getNodeValue());
    460                 }
    461                 query.addQueryOutcome(queryOutcome);
    462                 Query q = (Query) query.clone();
    463                 queryList.add(q);
    464 
    465                 for (int i = 0; i < documentList.getLength(); i++) {
    466                         Node n = documentList.item(i);
    467                         NamedNodeMap nnm = n.getAttributes();
    468                         Node nid = nnm.getNamedItem("nodeID");
    469                         Node nscore = nnm.getNamedItem("rank");
    470                         String docID = nid.getFirstChild().getNodeValue();
    471 
    472                         QueryContext queryContext = new QueryContext(firstDoc + i, nscore
    473                                         .getFirstChild().getNodeValue(), q);
    474                         if (allResults.containsKey(docID)) {
    475                                 ResultDocument resultDocument = (ResultDocument) allResults
    476                                                 .get(docID);
    477                                 resultDocument.incrementFrequencyReturned();
    478                                 resultDocument.addQueryContext(queryContext);
    479                                 allResults.put(docID, resultDocument);
    480                         } else {
    481                                 ResultDocument resultDocument = new ResultDocument();
    482                                 resultDocument.addQueryContext(queryContext);
    483                                 allResults.put(docID, resultDocument);
    484                         }
    485                 }
    486                 return queryOutcome;
     427               
     428               
     429               
     430               
     431               
     432               
     433               
     434               
     435               
     436               
     437                return null;
     438               
     439//              DOMParser p = new DOMParser();
     440//
     441//              try {
     442//                      p.parse(is);
     443//              } catch (SAXException se) {
     444//                      System.err.println(se);
     445//              } catch (IOException ioe) {
     446//                      System.err.println(ioe);
     447//              }
     448//              Document d = p.getDocument();
     449//              NodeList metadataList = d.getElementsByTagName("metadata");
     450//              for (int i = 0; i < metadataList.getLength(); i++) {
     451//                      Node n = metadataList.item(i);
     452//                      NamedNodeMap nnm = n.getAttributes();
     453//                      Node att = nnm.getNamedItem("name");
     454//                      if (att.getNodeValue().compareTo("numDocsMatched") == 0) {
     455//                              queryOutcome.setHowManyDocsMatched(n.getFirstChild()
     456//                                              .getNodeValue());
     457//                      } else if (att.getNodeValue().compareTo("numDocsReturned") == 0) {
     458//                              queryOutcome.setHowManyDocsReturned(n.getFirstChild()
     459//                                              .getNodeValue());
     460//                      }
     461//              }
     462//
     463//              NodeList documentList = d.getElementsByTagName("documentNode");
     464//              for (int i = 0; i < documentList.getLength(); i++) {
     465//                      Node n = documentList.item(i);
     466//                      NamedNodeMap nnm = n.getAttributes();
     467//                      Node nid = nnm.getNamedItem("nodeID");
     468//                      Node nscore = nnm.getNamedItem("rank");
     469//                      String docID = nid.getFirstChild().getNodeValue();
     470//                      queryOutcome.addResult(docID, firstDoc + i, nscore.getFirstChild()
     471//                                      .getNodeValue());
     472//              }
     473//              query.addQueryOutcome(queryOutcome);
     474//              Query q = (Query) query.clone();
     475//              queryList.add(q);
     476//
     477//              for (int i = 0; i < documentList.getLength(); i++) {
     478//                      Node n = documentList.item(i);
     479//                      NamedNodeMap nnm = n.getAttributes();
     480//                      Node nid = nnm.getNamedItem("nodeID");
     481//                      Node nscore = nnm.getNamedItem("rank");
     482//                      String docID = nid.getFirstChild().getNodeValue();
     483//
     484//                      QueryContext queryContext = new QueryContext(firstDoc + i, nscore
     485//                                      .getFirstChild().getNodeValue(), q);
     486//                      if (allResults.containsKey(docID)) {
     487//                              ResultDocument resultDocument = (ResultDocument) allResults
     488//                                              .get(docID);
     489//                              resultDocument.incrementFrequencyReturned();
     490//                              resultDocument.addQueryContext(queryContext);
     491//                              allResults.put(docID, resultDocument);
     492//                      } else {
     493//                              ResultDocument resultDocument = new ResultDocument();
     494//                              resultDocument.addQueryContext(queryContext);
     495//                              allResults.put(docID, resultDocument);
     496//                      }
     497//              }
     498//              return queryOutcome;
    487499        }
    488500
     
    554566                StringReader sr = new StringReader(result);
    555567                InputSource is = new InputSource(sr);
    556                 DOMParser p = new DOMParser();
    557                 try {
    558                         p.parse(is);
     568                //DOMParser p = new DOMParser();
     569        /*      try {
     570                        //p.parse(is);
    559571                } catch (SAXException se) {
    560572                        System.err.println(se);
    561573                } catch (IOException ioe) {
    562574                        System.err.println(ioe);
    563                 }
    564                 Document d = p.getDocument();
     575                }*/
     576                //Document d = p.getDocument();
     577                Document d = null;
    565578                NodeList metadataList = d.getElementsByTagName("metadata");
    566579                String metadataval = null;
     
    690703                StringReader sr = new StringReader(result);
    691704                InputSource is = new InputSource(sr);
    692                 DOMParser p = new DOMParser();
    693                 try {
    694                         p.parse(is);
    695                 } catch (SAXException se) {
    696                         System.err.println(se);
    697                 } catch (IOException ioe) {
    698                         System.err.println(ioe);
    699                 }
     705//              DOMParser p = new DOMParser();
     706//              try {
     707//                      p.parse(is);
     708//              } catch (SAXException se) {
     709//                      System.err.println(se);
     710//              } catch (IOException ioe) {
     711//                      System.err.println(ioe);
     712//              }
    700713
    701714                String returnName = null;
    702715
    703                 Document d = p.getDocument();
     716                //Document d = p.getDocument();
     717                Document d = null;
    704718                NodeList metadataList = d.getElementsByTagName("metadata");
    705719                for (int i = 0; i < metadataList.getLength(); i++) {
     
    736750                StringReader sr = new StringReader(result);
    737751                InputSource is = new InputSource(sr);
    738                 DOMParser p = new DOMParser();
    739                 try {
    740                         p.parse(is);
    741                 } catch (SAXException se) {
    742                         System.err.println(se);
    743                 } catch (IOException ioe) {
    744                         System.err.println(ioe);
    745                 }
    746                 Document d = p.getDocument();
    747 
     752//              DOMParser p = new DOMParser();
     753//              try {
     754//                      p.parse(is);
     755//              } catch (SAXException se) {
     756//                      System.err.println(se);
     757//              } catch (IOException ioe) {
     758//                      System.err.println(ioe);
     759//              }
     760//              Document d = p.getDocument();
     761                Document d = null;
    748762                NodeList childList = d.getElementsByTagName("classifierNode");
    749763                NodeList documentList = d.getElementsByTagName("documentNode");
  • trunk/src/org/expeditee/gui/FrameMouseActions.java

    r348 r352  
    25432543
    25442544                                                        return remain;
    2545                                                 } else if (mergee instanceof WidgetCorner
    2546                                                                 || mergee instanceof WidgetEdge) {
     2545                                                } else if (mergee instanceof WidgetCorner) {
    25472546                                                        if (merger.size() == 1 && txt.getLink() != null) {
    25482547                                                                // If the text item is linked then use that
    2549                                                                 mergee.setLink(txt.getAbsoluteLink());
     2548                                                                ((WidgetCorner)mergee).setLink(txt.getAbsoluteLink(), txt);
     2549                                                        } else {
     2550                                                                remain.addAll(merger);
     2551                                                        }
     2552                                                        return remain;
     2553                                                } else if (mergee instanceof WidgetEdge) {
     2554                                                        if (merger.size() == 1 && txt.getLink() != null) {
     2555                                                                // If the text item is linked then use that
     2556                                                                ((WidgetEdge)mergee).setLink(txt.getAbsoluteLink(), txt);
    25502557                                                        } else {
    25512558                                                                remain.addAll(merger);
  • trunk/src/org/expeditee/items/widgets/DataFrameWidget.java

    r313 r352  
    108108
    109109        @Override
    110         public void setLink(String link) {
     110        public void setLink(String link, Text linker) {
    111111                String newLink = Item.convertToAbsoluteLink(link);
    112112                String oldLink = getSource().getAbsoluteLink();
     
    114114                                || (newLink != null && newLink.equals(oldLink)))
    115115                        return;
    116                 super.setLink(link);
     116                super.setLink(link, linker);
    117117                clearSubjects();
    118118                setDataFrame(null);
  • trunk/src/org/expeditee/items/widgets/InteractiveWidget.java

    r334 r352  
    899899                return Math.abs(_d4.getY() - _d1.getY());
    900900        }
     901       
     902        public Point getPosition() {
     903                return new Point(getX(), getY());
     904        }
    901905
    902906        /**
     
    15491553         *
    15501554         * @param link
    1551          *            The new frame link. Can be null (for no link)
    1552          *
    1553          */
    1554         public void setLink(String link) {
     1555         *          The new frame link. Can be null (for no link)
     1556         *
     1557         * @param linker
     1558         *                      The text item creating the link. Null if not created from
     1559         *                      a text item.
     1560         */
     1561        public void setLink(String link, Text linker) {
    15551562                // Make sure the link is redrawn when a link is added
    15561563                if (link == null)
  • trunk/src/org/expeditee/items/widgets/WidgetCorner.java

    r320 r352  
    88import org.expeditee.items.Dot;
    99import org.expeditee.items.ItemParentStateChangedEvent;
     10import org.expeditee.items.Text;
    1011
    1112public class WidgetCorner extends Dot {
     
    170171        @Override
    171172        public void setLink(String link) {
    172                 _widgetSource.setLink(link);
     173                _widgetSource.setLink(link, null);
     174        }
     175       
     176        /**
     177         * @param link
     178         *          The new frame link. Can be null (for no link)
     179         *
     180         * @param linker
     181         *                      The text item creating the link. Null if not created from
     182         *                      a text item.
     183         */
     184        public void setLink(String link, Text linker) {
     185                _widgetSource.setLink(link, linker);
    173186        }
    174187
  • trunk/src/org/expeditee/items/widgets/WidgetEdge.java

    r320 r352  
    77import org.expeditee.items.Item;
    88import org.expeditee.items.Line;
     9import org.expeditee.items.Text;
    910
    1011/**
     
    136137        }
    137138
    138         @Override
     139        @Override
    139140        public void setLink(String link) {
    140                 _widgetSource.setLink(link);
     141                _widgetSource.setLink(link, null);
     142        }
     143       
     144        /**
     145         * @param link
     146         *          The new frame link. Can be null (for no link)
     147         *
     148         * @param linker
     149         *                      The text item creating the link. Null if not created from
     150         *                      a text item.
     151         */
     152        public void setLink(String link, Text linker) {
     153                _widgetSource.setLink(link, linker);
    141154        }
    142155
  • trunk/src_apollo/org/apollo/AudioFrameMouseActions.java

    r344 r352  
    6060                        FrameMouseActions.MouseY = e.getY();
    6161                       
    62                 } else if (e.isShiftDown() &&
     62                } else if (e.isShiftDown() && !AudioFrameKeyboardActions.isControlDown &&
    6363                                !FreeItems.getInstance().isEmpty()) {
    6464                       
     
    143143         */
    144144        public static boolean isYAxisRestictionOn() {
    145                 return AudioFrameKeyboardActions.isControlDown && AudioFrameKeyboardActions.isShiftDown;
     145                return AudioFrameKeyboardActions.isControlDown && !AudioFrameKeyboardActions.isShiftDown;
    146146        }
    147147       
  • trunk/src_apollo/org/apollo/audio/structure/AudioStructureModel.java

    r349 r352  
    11991199                        if (odframe != null) { // is loaded?
    12001200                                AbstractTrackGraphNode tinf = odframe.getLinkedTrack(virtualFilename);
    1201                                 assert(tinf != null); // due to the assumption that the model is consistent
    1202                                 if (tinf.getName() != newName) {
     1201                                if (tinf != null && tinf.getName() != newName) {
    12031202                                        tinf.setName(newName);
    12041203                                        // Note: a fetch might be waiting on this - i.e in progress. Thus must be cancelled.
  • trunk/src_apollo/org/apollo/gui/EditableSampledTrackGraphView.java

    r342 r352  
    133133                case KeyEvent.VK_RIGHT:
    134134
    135                         float ftmp = (float)COARSE_PAN_PIXEL_LENGTH / (float)getWidth();
    136                         int pan = (int)(getTimeScaleLength() *  ftmp);
    137                         if (pan == 0) pan = 1;
    138                        
    139                         if (e.getKeyCode() == KeyEvent.VK_RIGHT &&
    140                                         (getSampledTrackModel().getSelectionStart() +
    141                                         getSampledTrackModel().getSelectionLength()) < getSampledTrackModel().getFrameCount()) { // RIGHT
    142                                
    143                                 getSampledTrackModel().setSelection(getSampledTrackModel().getSelectionStart() + pan,
    144                                                 getSampledTrackModel().getSelectionLength());
    145                                
    146                         } else if(e.getKeyCode() == KeyEvent.VK_LEFT &&
    147                                         getSampledTrackModel().getSelectionStart() > 0) { // LEFT
    148                                 getSampledTrackModel().setSelection(getSampledTrackModel().getSelectionStart() - pan,
    149                                                 getSampledTrackModel().getSelectionLength());
     135                        // Select to end of track?
     136                        if (e.isControlDown()) {
     137                                if (e.getKeyCode() == KeyEvent.VK_LEFT) {
     138                                       
     139                                        int oldStart = getSampledTrackModel().getSelectionStart();
     140                                        int oldLength = getSampledTrackModel().getSelectionLength();
     141                                        if (oldLength < 1) oldLength = 1;
     142                                       
     143                                        getSampledTrackModel().setSelection(0, oldStart + oldLength);
     144                                       
     145                                } else { // Right
     146               
     147                                        getSampledTrackModel().setSelection(
     148                                                        getSampledTrackModel().getSelectionStart(),
     149                                                        getSampledTrackModel().getFrameCount() - getSampledTrackModel().getSelectionStart());
     150                                       
     151                                }
     152                        } else {
     153                                float ftmp = (float)COARSE_PAN_PIXEL_LENGTH / (float)getWidth();
     154                                int pan = (int)(getTimeScaleLength() *  ftmp);
     155                                if (pan == 0) pan = 1;
     156                               
     157                                if (e.getKeyCode() == KeyEvent.VK_RIGHT &&
     158                                                (getSampledTrackModel().getSelectionStart() +
     159                                                getSampledTrackModel().getSelectionLength()) < getSampledTrackModel().getFrameCount()) { // RIGHT
     160                                       
     161                                        getSampledTrackModel().setSelection(getSampledTrackModel().getSelectionStart() + pan,
     162                                                        getSampledTrackModel().getSelectionLength());
     163                                       
     164                                } else if(e.getKeyCode() == KeyEvent.VK_LEFT &&
     165                                                getSampledTrackModel().getSelectionStart() > 0) { // LEFT
     166                                        getSampledTrackModel().setSelection(getSampledTrackModel().getSelectionStart() - pan,
     167                                                        getSampledTrackModel().getSelectionLength());
     168                                }
    150169                        }
    151170                        break;
  • trunk/src_apollo/org/apollo/gui/FrameRenderPasses.java

    r344 r352  
    1515import org.apollo.items.RecordOverdubLauncher;
    1616import org.apollo.widgets.LinkedTrack;
    17 import org.apollo.widgets.SampleRecorder;
    1817import org.apollo.widgets.SampledTrack;
    1918import org.expeditee.gui.Browser;
     
    195194                                       
    196195                                        if (iw != null && (iw instanceof SampledTrack ||
    197                                                         iw instanceof LinkedTrack || iw instanceof SampleRecorder)) {
     196                                                        iw instanceof LinkedTrack)) {
    198197                                               
    199198                                                if (seen == null) {
  • trunk/src_apollo/org/apollo/items/EmulatedTextItem.java

    r344 r352  
    201201                                                        (e.getKeyChar() == KeyEvent.VK_DELETE && !emulatedSource.isEmpty()) ||
    202202                                                        e.getKeyChar() == KeyEvent.VK_SPACE ||
    203                                                         e.getKeyChar() == KeyEvent.VK_UNDERSCORE)) {
     203                                                        e.getKeyChar() == KeyEvent.VK_UNDERSCORE) ||
     204                                                        e.getKeyChar() == KeyEvent.VK_AMPERSAND ||
     205                                                        e.getKeyChar() == KeyEvent.VK_OPEN_BRACKET ||
     206                                                        e.getKeyChar() == KeyEvent.VK_CLOSE_BRACKET ||
     207                                                        e.getKeyChar() == KeyEvent.VK_MINUS) {
    204208
    205209
  • trunk/src_apollo/org/apollo/util/Mutable.java

    r349 r352  
    1010 */
    1111public class Mutable {
    12        
    1312        private static Mutable instance = new Mutable();
    1413        private Mutable() {}
     
    2120        }
    2221       
     22        public class Long {
     23                public Long(long val) {
     24                        this.value = val;
     25                }
     26                public long value;
     27        }
     28       
    2329        public static Integer createMutableInteger(int val) {
    2430                return instance.new Integer(val);
    2531        }
    26 
     32       
     33        public static Long createMutableLong(long val) {
     34                return instance.new Long(val);
     35        }
    2736}
  • trunk/src_apollo/org/apollo/widgets/LinkedTrack.java

    r349 r352  
    208208
    209209                        public void keyPressed(KeyEvent e) {
    210                                 if (state != PLAYING && state != STOPPED) return;
     210                                if ((state != PLAYING && state != STOPPED) || e.isControlDown()) return;
    211211                                if (nameLabel.onKeyPressed(e, _swingComponent)) {
    212212                                        e.consume();
     
    216216
    217217                        public void keyReleased(KeyEvent e) {
    218                                 if (state != PLAYING && state != STOPPED) return;
     218                                if ((state != PLAYING && state != STOPPED) ||  e.isControlDown()) return;
    219219                                if (nameLabel.onKeyReleased(e, _swingComponent)) {
    220220                                        e.consume();
     
    771771         */
    772772        @Override
    773         public void setLink(String link) {
     773        public void setLink(String link, Text linker) {
    774774               
    775775                String oldABSLink = getAbsoluteLink();
    776776               
    777                 super.setLink(link);
     777                super.setLink(link, linker);
    778778               
    779779                String newABSLink = getAbsoluteLink();
     
    789789                                parentName);
    790790
    791                
    792791                // And adding a new one (if applicable)
    793792                if (parent != null && newABSLink != null) {
     
    798797
    799798                        if (initTime == null) initTime = 0L;
     799                       
     800                        String newName = (linker != null && linker.getText() != null) ? linker.getText() : getName();
     801                        if (newName != getName()) {
     802                                setName(newName);
     803                        }
    800804
    801805                        AudioStructureModel.getInstance().onLinkedTrackWidgetAnchored(
     
    804808                                        initTime, // TODO: Revise: actually would be better to get from model .. if possible
    805809                                        newABSLink,
    806                                         getName(),
     810                                        newName,
    807811                                        getY());
    808812
  • trunk/src_apollo/org/apollo/widgets/SampledTrack.java

    r349 r352  
    6363import org.expeditee.gui.Frame;
    6464import org.expeditee.gui.FrameGraphics;
     65import org.expeditee.gui.FrameIO;
    6566import org.expeditee.gui.MouseEventRouter;
    6667import org.expeditee.gui.PopupManager;
     
    393394
    394395                        public void keyPressed(KeyEvent e) {
    395                                 if (nameLabel != null) {
     396                                if (!e.isControlDown() && nameLabel != null) {
    396397                                        if (nameLabel.onKeyPressed(e, fulltrackView)) {
    397398                                                e.consume();
     
    401402
    402403                        public void keyReleased(KeyEvent e) {
    403                                 if (nameLabel != null) {
     404                                if (!e.isControlDown() && nameLabel != null) {
    404405                                        if (nameLabel.onKeyReleased(e, fulltrackView)) {
    405406                                                e.consume();
     
    414415                               
    415416                                // Delete-and-Split audio command
    416                                 if (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_DELETE) {
     417                                else if (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_DELETE) {
    417418                                       
    418419                                        // First is selection valid?
     
    481482                                       
    482483                                }
     484                                // Convert to linked track
     485                                else if (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_L) {
     486
     487                                        Frame current = DisplayIO.getCurrentFrame();
     488                                       
     489                                        if (current != null) {
     490                                               
     491                                                String name =  getName();
     492                                                if (name == null) name = "Unamed";
     493                                               
     494                                                long initTime = getInitiationTimeFromMeta();
     495                                               
     496                                                Text linkSource = new Text(current.getNextItemID());
     497                                                linkSource.addToData(TrackWidgetCommons.META_NAME_TAG + name);
     498                                                linkSource.setPosition(getPosition());
     499                                                linkSource.setParent(current);
     500                                                LinkedTrack linkedVersion = new LinkedTrack(linkSource, null);
     501
     502                                                // Save any changes in the audio - or save for the first time
     503                                                if (trackModel.isAudioModified())
     504                                                        saveWidgetData(); // a little lag is OK .. could make smarter if really need to
     505                                               
     506                                                // Create a new frame to hold the track
     507                                                Frame newFrame = FrameIO.CreateNewFrame(SampledTrack.this.getFirstCorner());
     508       
     509                                                // Remove track from current frame
     510                                                removeSelf();
     511                                               
     512                                                // Add to new frame
     513                                                newFrame.addAllItems(getItems());
     514                                               
     515                                                // Save changes
     516                                                FrameIO.SaveFrame(newFrame);
     517                                               
     518                                                // Link it
     519                                                linkedVersion.setLink(newFrame.getName(), null);
     520                                               
     521                                                // Add the new link
     522                                                current.addAllItems(linkedVersion.getItems());
     523                                               
     524                                                // Ensure initiation times are retained to the exact frame... avoiding loss due to resolution
     525                                                linkedVersion.setInitiationTime(initTime);
     526                                               
     527       
     528
     529                                        }
     530       
     531                                }
    483532
    484533                        }
Note: See TracChangeset for help on using the changeset viewer.