public static String findUrl(PsiFile file, int offset, String uri) {
    final PsiElement currentElement = file.findElementAt(offset);
    final XmlAttribute attribute = PsiTreeUtil.getParentOfType(currentElement, XmlAttribute.class);

    if (attribute != null) {
      final XmlTag tag = PsiTreeUtil.getParentOfType(currentElement, XmlTag.class);

      if (tag != null) {
        final String prefix = tag.getPrefixByNamespace(XmlUtil.XML_SCHEMA_INSTANCE_URI);
        if (prefix != null) {
          final String attrValue =
              tag.getAttributeValue(XmlUtil.SCHEMA_LOCATION_ATT, XmlUtil.XML_SCHEMA_INSTANCE_URI);
          if (attrValue != null) {
            final StringTokenizer tokenizer = new StringTokenizer(attrValue);

            while (tokenizer.hasMoreElements()) {
              if (uri.equals(tokenizer.nextToken())) {
                if (!tokenizer.hasMoreElements()) return uri;
                final String url = tokenizer.nextToken();

                return url.startsWith(HTTP_PROTOCOL) ? url : uri;
              }

              if (!tokenizer.hasMoreElements()) return uri;
              tokenizer.nextToken(); // skip file location
            }
          }
        }
      }
    }
    return uri;
  }
Exemple #2
0
  /** Set the matching descriptors. */
  private void setMatchingFileNames() {
    StringTokenizer st = new StringTokenizer(matchingTF.getText(), ",");

    int numTokens = st.countTokens();

    if (numTokens == 0) {
      descriptors = new String[1];
      descriptors[0] = "*";
      return;
    }

    descriptors = new String[numTokens];

    int i = 0;
    while (st.hasMoreElements()) {
      descriptors[i++] = st.nextToken().trim();
    }
  }
 public void parseChatMessage(String response) {
   int counter = 0;
   String side = null;
   String playerName = null;
   String chatMessage = null;
   response = response.substring(5);
   StringTokenizer st = new StringTokenizer(response);
   while (st.hasMoreElements()) {
     if (counter > 1) break;
     if (counter == 0) playerName = st.nextToken();
     if (counter == 1) side = st.nextToken();
     counter++;
   }
   chatMessage = response.substring(playerName.length() + side.length() + 2);
   if (playerName.equals(gameData.getPlayerName())) playerName = "Me";
   String finalString = playerName + " (" + side + ") says: " + chatMessage;
   mw.v.enqueEvent(new CustomEvent(CustomEvent.CHAT_MESSAGE, finalString));
 }
  protected void _init() {
    setLayout(new BorderLayout());

    JPanel panel = new JPanel(new GridLayout(2, 1));

    showToolbar = new JCheckBox(jEdit.getProperty("options.toolbar.showToolbar"));
    showToolbar.setSelected(jEdit.getBooleanProperty("view.showToolbar"));
    panel.add(showToolbar);

    panel.add(new JLabel(jEdit.getProperty("options.toolbar.caption")));

    add(BorderLayout.NORTH, panel);

    String toolbar = jEdit.getProperty("view.toolbar");
    StringTokenizer st = new StringTokenizer(toolbar);
    listModel = new DefaultListModel();
    while (st.hasMoreTokens()) {
      String actionName = (String) st.nextToken();
      if (actionName.equals("-"))
        listModel.addElement(new ToolBarOptionPane.Button("-", null, null, "-"));
      else {
        EditAction action = jEdit.getAction(actionName);
        if (action == null) continue;
        String label = action.getLabel();
        if (label == null) continue;

        Icon icon;
        String iconName;
        if (actionName.equals("-")) {
          iconName = null;
          icon = null;
        } else {
          iconName = jEdit.getProperty(actionName + ".icon");
          if (iconName == null) icon = GUIUtilities.loadIcon("BrokenImage.png");
          else {
            icon = GUIUtilities.loadIcon(iconName);
            if (icon == null) icon = GUIUtilities.loadIcon("BrokenImage.png");
          }
        }
        listModel.addElement(new Button(actionName, iconName, icon, label));
      }
    }

    list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.addListSelectionListener(new ListHandler());
    list.setCellRenderer(new ButtonCellRenderer());

    add(BorderLayout.CENTER, new JScrollPane(list));

    JPanel buttons = new JPanel();
    buttons.setBorder(new EmptyBorder(3, 0, 0, 0));
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
    ActionHandler actionHandler = new ActionHandler();
    add = new RolloverButton(GUIUtilities.loadIcon("Plus.png"));
    add.setToolTipText(jEdit.getProperty("options.toolbar.add"));
    add.addActionListener(actionHandler);
    buttons.add(add);
    buttons.add(Box.createHorizontalStrut(6));
    remove = new RolloverButton(GUIUtilities.loadIcon("Minus.png"));
    remove.setToolTipText(jEdit.getProperty("options.toolbar.remove"));
    remove.addActionListener(actionHandler);
    buttons.add(remove);
    buttons.add(Box.createHorizontalStrut(6));
    moveUp = new RolloverButton(GUIUtilities.loadIcon("ArrowU.png"));
    moveUp.setToolTipText(jEdit.getProperty("options.toolbar.moveUp"));
    moveUp.addActionListener(actionHandler);
    buttons.add(moveUp);
    buttons.add(Box.createHorizontalStrut(6));
    moveDown = new RolloverButton(GUIUtilities.loadIcon("ArrowD.png"));
    moveDown.setToolTipText(jEdit.getProperty("options.toolbar.moveDown"));
    moveDown.addActionListener(actionHandler);
    buttons.add(moveDown);
    buttons.add(Box.createHorizontalStrut(6));
    edit = new RolloverButton(GUIUtilities.loadIcon("ButtonProperties.png"));
    edit.setToolTipText(jEdit.getProperty("options.toolbar.edit"));
    edit.addActionListener(actionHandler);
    buttons.add(edit);
    buttons.add(Box.createGlue());

    updateButtons();
    add(BorderLayout.SOUTH, buttons);

    iconList = new DefaultComboBoxModel();
    st = new StringTokenizer(jEdit.getProperty("icons"));
    while (st.hasMoreElements()) {
      String icon = st.nextToken();
      iconList.addElement(new IconListEntry(GUIUtilities.loadIcon(icon), icon));
    }
  }