コード例 #1
1
ファイル: JavaLineStyler.java プロジェクト: abego/java2script
 /**
  * Event.detail line start offset (input) Event.text line text (input) LineStyleEvent.styles
  * Enumeration of StyleRanges, need to be in order. (output) LineStyleEvent.background line
  * background color (output)
  */
 public void lineGetStyle(LineStyleEvent event) {
   Vector styles = new Vector();
   int token;
   StyleRange lastStyle;
   // If the line is part of a block comment, create one style for the entire line.
   if (inBlockComment(event.lineOffset, event.lineOffset + event.lineText.length())) {
     styles.addElement(
         new StyleRange(event.lineOffset, event.lineText.length(), getColor(COMMENT), null));
     event.styles = new StyleRange[styles.size()];
     styles.copyInto(event.styles);
     return;
   }
   Color defaultFgColor = ((Control) event.widget).getForeground();
   scanner.setRange(event.lineText);
   token = scanner.nextToken();
   while (token != EOF) {
     if (token == OTHER) {
       // do nothing for non-colored tokens
     } else if (token != WHITE) {
       Color color = getColor(token);
       // Only create a style if the token color is different than the
       // widget's default foreground color and the token's style is not
       // bold.  Keywords are bolded.
       if ((!color.equals(defaultFgColor)) || (token == KEY)) {
         StyleRange style =
             new StyleRange(
                 scanner.getStartOffset() + event.lineOffset, scanner.getLength(), color, null);
         if (token == KEY) {
           style.fontStyle = SWT.BOLD;
         }
         if (styles.isEmpty()) {
           styles.addElement(style);
         } else {
           // Merge similar styles.  Doing so will improve performance.
           lastStyle = (StyleRange) styles.lastElement();
           if (lastStyle.similarTo(style) && (lastStyle.start + lastStyle.length == style.start)) {
             lastStyle.length += style.length;
           } else {
             styles.addElement(style);
           }
         }
       }
     } else if ((!styles.isEmpty())
         && ((lastStyle = (StyleRange) styles.lastElement()).fontStyle == SWT.BOLD)) {
       int start = scanner.getStartOffset() + event.lineOffset;
       lastStyle = (StyleRange) styles.lastElement();
       // A font style of SWT.BOLD implies that the last style
       // represents a java keyword.
       if (lastStyle.start + lastStyle.length == start) {
         // Have the white space take on the style before it to
         // minimize the number of style ranges created and the
         // number of font style changes during rendering.
         lastStyle.length += scanner.getLength();
       }
     }
     token = scanner.nextToken();
   }
   event.styles = new StyleRange[styles.size()];
   styles.copyInto(event.styles);
 }
コード例 #2
0
ファイル: JavaLineStyler.java プロジェクト: abego/java2script
  public void parseBlockComments(String text) {
    blockComments = new Vector();
    StringReader buffer = new StringReader(text);
    int ch;
    boolean blkComment = false;
    int cnt = 0;
    int[] offsets = new int[2];
    boolean done = false;

    try {
      while (!done) {
        switch (ch = buffer.read()) {
          case -1:
            {
              if (blkComment) {
                offsets[1] = cnt;
                blockComments.addElement(offsets);
              }
              done = true;
              break;
            }
          case '/':
            {
              ch = buffer.read();
              if ((ch == '*') && (!blkComment)) {
                offsets = new int[2];
                offsets[0] = cnt;
                blkComment = true;
                cnt++;
              } else {
                cnt++;
              }
              cnt++;
              break;
            }
          case '*':
            {
              if (blkComment) {
                ch = buffer.read();
                cnt++;
                if (ch == '/') {
                  blkComment = false;
                  offsets[1] = cnt;
                  blockComments.addElement(offsets);
                }
              }
              cnt++;
              break;
            }
          default:
            {
              cnt++;
              break;
            }
        }
      }
    } catch (IOException e) {
      // ignore errors
    }
  }
コード例 #3
0
 public void setFiles(String[] fileNames) {
   int size = Arrays.asList(fileNames).size();
   Vector iFileNames = new Vector();
   for (int i = 0; i < size; i++) {
     IResource resource = workspaceRoot.findMember(fileNames[i]);
     if (resource instanceof IFile) iFileNames.addElement(resource);
   }
   IFile[] dummyArray = new IFile[iFileNames.size()];
   this.fileNames = (IFile[]) (iFileNames.toArray(dummyArray));
 }
コード例 #4
0
ファイル: JavaLineStyler.java プロジェクト: abego/java2script
 boolean inBlockComment(int start, int end) {
   for (int i = 0; i < blockComments.size(); i++) {
     int[] offsets = (int[]) blockComments.elementAt(i);
     // start of comment in the line
     if ((offsets[0] >= start) && (offsets[0] <= end)) return true;
     // end of comment in the line
     if ((offsets[1] >= start) && (offsets[1] <= end)) return true;
     if ((offsets[0] <= start) && (offsets[1] >= end)) return true;
   }
   return false;
 }
コード例 #5
0
  private void removeMapping(Shell shell) {
    TableItem[] itemsIdMaps = fIdMapsTable.getSelection();
    TableItem[] itemsMappings = fMappingsTable.getSelection();

    if (itemsMappings.length > 0 && itemsIdMaps.length > 0) {
      Mapping mapping = (Mapping) itemsMappings[0].getData();
      IdMap idmap = (IdMap) itemsIdMaps[0].getData();
      HashMap idmapHS = (HashMap) fIdMaps.get(idmap.getName());
      idmapHS.remove(mapping.getKey());
      Vector mappings = idmap.getMappings();
      mappings.remove(mapping);
      itemsMappings[0].dispose(); // Table is single selection
    }
  }
コード例 #6
0
  private void editIdMap(Shell shell) {
    TableItem[] items = fIdMapsTable.getSelection();
    if (items.length > 0) {
      IdMap idmap = (IdMap) items[0].getData();
      XMLCompareEditCopyIdMapDialog dialog =
          new XMLCompareEditCopyIdMapDialog(shell, idmap, fIdMaps, fIdMapsInternal);
      if (dialog.open() == Window.OK) {
        String new_idmapName = dialog.getResult();
        if (!fIdMaps.containsKey(new_idmapName)) {
          // copy over id mappings
          Vector newMappings = new Vector();
          IdMap newIdMap = new IdMap(new_idmapName, false, newMappings);
          HashMap newIdmapHM = new HashMap();
          fIdMaps.put(newIdMap.getName(), newIdmapHM);
          Vector Mappings = idmap.getMappings();
          for (Enumeration enumeration = Mappings.elements(); enumeration.hasMoreElements(); ) {
            Mapping mapping = (Mapping) enumeration.nextElement();
            Mapping newMapping =
                new Mapping(mapping.getElement(), mapping.getSignature(), mapping.getIdAttribute());
            newMappings.add(newMapping);
            newIdmapHM.put(newMapping.getKey(), newMapping.getIdAttribute());
          }
          // copy over ordered entries
          ArrayList orderedAL = idmap.getOrdered();
          if (orderedAL != null && orderedAL.size() > 0) {
            ArrayList newOrderedAL = new ArrayList();
            newIdMap.setOrdered(newOrderedAL);
            ArrayList idmapOrdered = new ArrayList();
            fOrderedElements.put(newIdMap.getName(), idmapOrdered);
            for (Iterator iter = orderedAL.iterator(); iter.hasNext(); ) {
              Mapping ordered = (Mapping) iter.next();
              Mapping newOrdered = new Mapping(ordered.getElement(), ordered.getSignature());
              newOrderedAL.add(newOrdered);
              idmapOrdered.add(newOrdered.getKey());
            }
          }

          newIdMapsTableItem(newIdMap, true);
          selectionChanged();
        }
      }
    }
  }
コード例 #7
0
 private void fillIdMaps(boolean internal) {
   HashMap IdMaps = (internal) ? fIdMapsInternal : fIdMaps;
   HashMap OrderedElements = (internal) ? fOrderedElementsInternal : fOrderedElements;
   Set IdMapKeys = IdMaps.keySet();
   for (Iterator iter_internal = IdMapKeys.iterator(); iter_internal.hasNext(); ) {
     String IdMapName = (String) iter_internal.next();
     Vector Mappings = new Vector();
     IdMap idmap = new IdMap(IdMapName, internal, Mappings);
     // create mappings of internal idmaps
     HashMap idmapHM = (HashMap) IdMaps.get(IdMapName);
     Set idmapKeys = idmapHM.keySet();
     for (Iterator iter_idmap = idmapKeys.iterator(); iter_idmap.hasNext(); ) {
       Mapping mapping = new Mapping();
       String signature = (String) iter_idmap.next();
       int end_of_signature = signature.lastIndexOf(SIGN_SEPARATOR, signature.length() - 2);
       if (end_of_signature < XMLStructureCreator.ROOT_ID.length() + 1)
         mapping.setSignature(""); // $NON-NLS-1$
       else
         mapping.setSignature(
             signature.substring(XMLStructureCreator.ROOT_ID.length() + 1, end_of_signature));
       mapping.setElement(signature.substring(end_of_signature + 1, signature.length() - 1));
       mapping.setIdAttribute((String) idmapHM.get(signature));
       Mappings.add(mapping);
     }
     // create ordered mappings
     ArrayList idmapOrdered = (ArrayList) OrderedElements.get(IdMapName);
     if (idmapOrdered != null) {
       setOrdered(idmap, idmapOrdered);
     }
     // set extension
     if (fIdExtensionToName.containsValue(IdMapName)) {
       Set keySet = fIdExtensionToName.keySet();
       String extension = new String();
       for (Iterator iter = keySet.iterator(); iter.hasNext(); ) {
         extension = (String) iter.next();
         if (((String) fIdExtensionToName.get(extension)).equals(IdMapName)) break;
       }
       idmap.setExtension(extension);
     }
     newIdMapsTableItem(idmap, false);
   }
 }
コード例 #8
0
 public void setVisible(boolean visible) {
   if (visible == true) {
     if (fFilters != null) {
       sourceFileViewer.resetFilters();
       for (Iterator i = fFilters.iterator(); i.hasNext(); )
         sourceFileViewer.addFilter((ViewerFilter) i.next());
     }
     sourceFileViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
   }
   super.setVisible(visible);
 }
コード例 #9
0
 protected void selectionChanged() {
   TableItem[] items = fIdMapsTable.getSelection();
   if (items.length > 0) {
     // Refresh Mappings Table
     fMappingsTable.removeAll();
     Vector Mappings = ((IdMap) items[0].getData()).getMappings();
     for (Enumeration enumeration = Mappings.elements(); enumeration.hasMoreElements(); ) {
       newMappingsTableItem((Mapping) enumeration.nextElement(), false);
     }
     // Refresh Ordered Table
     fOrderedTable.removeAll();
     ArrayList Ordered = ((IdMap) items[0].getData()).getOrdered();
     if (Ordered != null) {
       for (Iterator iter_ordered = Ordered.iterator(); iter_ordered.hasNext(); ) {
         newOrderedTableItem((Mapping) iter_ordered.next(), false);
       }
     }
   }
   updateEnabledState();
 }
コード例 #10
0
 private void addMapping(Shell shell) {
   TableItem[] items = fIdMapsTable.getSelection();
   if (items.length > 0) {
     IdMap idmap = (IdMap) items[0].getData();
     Mapping mapping = new Mapping();
     HashMap idmapHM = (HashMap) fIdMaps.get(idmap.getName());
     XMLCompareEditMappingDialog dialog =
         new XMLCompareEditMappingDialog(shell, mapping, idmapHM, false);
     if (dialog.open() == Window.OK) {
       String idmapHMKey = mapping.getKey();
       if (idmapHM == null) idmapHM = new HashMap();
       if (!idmapHM.containsKey(idmapHMKey)) {
         idmapHM.put(idmapHMKey, mapping.getIdAttribute());
         newMappingsTableItem(mapping, true);
         Vector mappings = idmap.getMappings();
         mappings.add(mapping);
       }
     }
   }
 }
コード例 #11
0
 public void addFilter(ViewerFilter filter) {
   if (fFilters == null) fFilters = new Vector();
   fFilters.add(filter);
 }