Ignore:
Timestamp:
06/05/08 18:59:42 (16 years ago)
Author:
ra33
Message:

Added parsing of annotation items

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gui/Frame.java

    r87 r88  
    1111import java.util.Collection;
    1212import java.util.Collections;
     13import java.util.HashMap;
    1314import java.util.LinkedList;
    1415import java.util.List;
     16import java.util.Map;
    1517import java.util.Stack;
    1618
     
    4648        private String _frameset = null;
    4749
    48         private boolean _throwsException = false;
    49        
    5050        private int _number = -1;
    5151
     
    346346                for (Item i : items) {
    347347                        if (i instanceof Text && i.getX() < UserSettings.TitlePosition
    348                                         && i.getY() < UserSettings.TitlePosition /*&& i.getY() > 0*/)
     348                                        && i.getY() < UserSettings.TitlePosition /*
     349                                                                                                                                 * && i.getY() >
     350                                                                                                                                 * 0
     351                                                                                                                                 */)
    349352                                return (Text) i;
    350353                }
     
    15851588        public void setActiveTime(String activeTime) {
    15861589                try {
    1587                         _activeTime = new Time(Time.valueOf(activeTime).getTime() + 12*60*60*1000);
     1590                        _activeTime = new Time(Time.valueOf(activeTime).getTime() + 12 * 60
     1591                                        * 60 * 1000);
    15881592                } catch (Exception e) {
    15891593                        _activeTime = new Time(0);
     
    15931597        public void setDarkTime(String darkTime) {
    15941598                try {
    1595                         _darkTime = new Time(Time.valueOf(darkTime).getTime() + 12*60*60*1000);
     1599                        _darkTime = new Time(Time.valueOf(darkTime).getTime() + 12 * 60
     1600                                        * 60 * 1000);
    15961601                } catch (Exception e) {
    15971602                        _darkTime = new Time(0);
     
    16301635        public Time getCometDarkTime(boolean topFrame) {
    16311636                Time base;
    1632                 if (topFrame && _frameName.Permission >= Item.PERMISSION_FULL )
     1637                if (topFrame && _frameName.Permission >= Item.PERMISSION_FULL)
    16331638                        base = SessionStats.getFrameDarkTime();
    16341639                else if (_darkTime == null)
     
    16611666        }
    16621667
    1663         public void setThrowsException(boolean b) {
    1664                 _throwsException = b;
    1665         }
    1666        
    1667         public boolean getThrowsException() {
    1668                 return _throwsException;
     1668        public void addAnnotation(Text item) {
     1669                // Check if this item has already been processed
     1670                String[] tokens = item.getProcessedText();
     1671                if (tokens != null) {
     1672                        if (tokens.length > 0) {
     1673                                _annotations.put(tokens[0], item);
     1674                        }
     1675                        return;
     1676                }
     1677
     1678                String text = item.getText().trim();
     1679                assert (text.charAt(0) == '@');
     1680                // Ignore annotations with spaces after the tag symbol
     1681                if (text.length() < 2 || !Character.isLetter(text.charAt(1))) {
     1682                        item.setProcessedText(new String[0]);
     1683                        return;
     1684                }
     1685                // The separator char must come before the first non letter otherwise we
     1686                // ignore the annotation item
     1687                for (int i = 2; i < text.length(); i++) {
     1688                        char ch = text.charAt(i);
     1689                        if (!Character.isLetterOrDigit(ch)) {
     1690                                // Must have an attribute value pair
     1691                                if (ch == AttributeUtils.SEPARATOR_CHAR) {
     1692                                        //Get the attribute
     1693                                        String attribute = text.substring(1,i).toLowerCase();
     1694                                        String value ="";
     1695                                        if(text.length() >1+ i ){
     1696                                                value = text.substring(i + 1).trim().toLowerCase();
     1697                                        }
     1698                                        item.setProcessedText(new String[]{attribute, value});
     1699                                        _annotations.put(attribute, item);
     1700                                        return;
     1701                                } else {
     1702                                        item.setProcessedText(new String[0]);
     1703                                        return;
     1704                                }
     1705                        }
     1706                }
     1707                // If it was nothing but letters and digits save the tag
     1708                String lowerCaseText = text.substring(1).toLowerCase();
     1709                item.setProcessedText(new String[]{lowerCaseText});
     1710                _annotations.put(lowerCaseText, item);
     1711        }
     1712
     1713        public boolean hasAnnotation(String annotation) {
     1714                return _annotations.containsKey(annotation.toLowerCase());
     1715        }
     1716
     1717        public String getAnnotationValue(String annotation) {
     1718                Text text = _annotations.get(annotation.toLowerCase());
     1719                if (text == null)
     1720                        return null;
     1721
     1722                String[] tokens = text.getProcessedText();
     1723                if (tokens != null || tokens.length > 1)
     1724                        return tokens[1];
     1725                return null;
     1726        }
     1727
     1728        Map<String, Text> _annotations = new HashMap<String, Text>();
     1729
     1730        public void clearAnnotations() {
     1731                _annotations.clear();
    16691732        }
    16701733}
Note: See TracChangeset for help on using the changeset viewer.