Exemplo n.º 1
0
 public static void goToLineColumm(JTextArea component, int line, int column) {
   Element root = component.getDocument().getDefaultRootElement();
   int offset = 0;
   int lineStart;
   if (line < component.getLineCount()) {
     lineStart = root.getElement(line - 1).getStartOffset();
     offset = lineStart + (column - 1);
   } else {
     // in case we're asking to jump to a line that doesn't exist
     lineStart = root.getElement(component.getLineCount() - 1).getStartOffset();
     offset = lineStart;
   }
   component.setCaretPosition(offset);
 }
Exemplo n.º 2
0
  @SuppressWarnings("unchecked")
  @Override
  protected void processSource(final ColoredSourceFile source) throws CoreException {

    try {
      textArea.setText(StrUtils.strFromInputStream(source.getResource().getContents()));
      int lines = textArea.getLineCount();
      int pages = (int) Math.ceil((double) lines / (double) (LINES_PER_PAGE / 2));
      final HashSet<IFeature> featuresOnPage[] = new HashSet[pages];

      ISourceFile ast = source.getAST();

      ast.accept(
          new ASTVisitor() {
            @Override
            public boolean visit(IASTNode node) {
              Set<IFeature> nodeColor = source.getColorManager().getColors(node);
              if (nodeColor.size() > 0)
                try {
                  int startLine = textArea.getLineOfOffset(node.getStartPosition());
                  int endLine =
                      textArea.getLineOfOffset(node.getStartPosition() + node.getLength());

                  addFeaturesToPages(startLine, endLine, nodeColor);
                } catch (BadLocationException e) {
                  e.printStackTrace();
                }
              return super.visit(node);
            }

            private void addFeaturesToPages(int startLine, int endLine, Set<IFeature> nodeColor) {
              for (int i = 0; i < featuresOnPage.length; i++) {
                int pageStart = i * (LINES_PER_PAGE / 2);
                int pageEnd = pageStart + LINES_PER_PAGE;
                if (startLine < pageEnd && endLine >= pageStart) {
                  HashSet<IFeature> pageColors = featuresOnPage[i];
                  if (pageColors == null) featuresOnPage[i] = pageColors = new HashSet<IFeature>();
                  pageColors.addAll(nodeColor);
                }
              }
            }
          });

      int stats[] = new int[6];
      for (int i = 0; i < featuresOnPage.length; i++) {
        HashSet<IFeature> pageColors = featuresOnPage[i];
        if (pageColors == null) stats[0]++;
        else stats[colorsToP(pageColors.size())]++;
      }
      print(source, stats);
      addToGlobal(stats);

    } catch (IOException e) {
      e.printStackTrace();
    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Exemplo n.º 3
0
 /**
  * Prints messages to text area
  *
  * @param message the text to be printed
  */
 @Override
 public void displayMessage(String message) {
   if (message.length() == 0) return; // doesn't display empty lines
   if (textArea.getLineCount() >= 10) { // cleans the text area every 10 lines
     textArea.setText("");
   }
   textArea.append(message);
   textArea.append("\n");
 }
Exemplo n.º 4
0
 public void newPrompt(String prompt) {
   int lineCount = textArea.getLineCount();
   try {
     int end = textArea.getLineEndOffset(lineCount - 1);
     textArea.replaceRange(prompt, 0, end);
   } catch (BadLocationException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Exemplo n.º 5
0
 public void truncateTextArea() {
   int numLinesToRemove =
       console.getLineCount() - 1 - MAX_CONSOLE_LINES; // There's a blank at the end
   if (numLinesToRemove > 0) {
     try {
       int posOfLastLineToRemove = console.getLineEndOffset(numLinesToRemove - 1);
       console.replaceRange("", 0, posOfLastLineToRemove);
     } catch (javax.swing.text.BadLocationException ex) {
       log.error("trouble truncating SystemConsole window", ex);
     }
   }
 }
Exemplo n.º 6
0
  private void highlightError(int index) {
    String message = (String) messages.elementAt(index);
    int i = message.indexOf(":");

    if ((i != -1) && (i < 10)) {
      try {
        int lineNumber = Integer.parseInt(message.substring(0, i).trim()) - 1;
        if (lineNumber < sourceArea.getLineCount()) {
          int start = sourceArea.getLineStartOffset(lineNumber);
          int end = sourceArea.getLineEndOffset(lineNumber);

          sourceArea.requestFocus();
          sourceArea.setSelectionStart(start);
          sourceArea.setSelectionEnd(end - 1);
        }
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  }
  @Override
  public DataObject execute(ServiceInput serviceInput) {
    String warning_value =
        String.valueOf(serviceInput.getInput().getAttributeValue(WarningWidget.WARNING_FIRE));

    int last = warningTextArea.getLineCount() - 1;
    int start;
    int end;
    String lastLine = "";

    try {
      if (last > 0) {
        start = warningTextArea.getLineStartOffset(last - 1);
        end = warningTextArea.getLineEndOffset(last);
        lastLine = warningTextArea.getText().substring(start, end - 1);
      }
    } catch (BadLocationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    if (!warning_value.equals(lastLine)) warningTextArea.append(warning_value + "\n");

    return new DataObject(); // no particular info to return
  }
  /** Create the panel. */
  public ArtistInfoPanel(final ArtistNode a) {
    super();
    NumberFormat nf1 = NumberFormat.getInstance();

    // Own settings
    setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
    setBackground(Color.DARK_GRAY);
    setLayout(new BorderLayout(0, 0));
    Utils.fixSize(this, size);

    // COMPONENTS

    // listener
    MouseListener ML_CLOSE =
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            GroovesharkConnector.getInstance().stop();
            NavigationPanel.getInstance().hideArtistInfoBox();
          }
        };

    MouseListener ML_CONFIRM =
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            GroovesharkConnector.getInstance().stop();
            GUI.getInstance().search(a);
            NavigationPanel.getInstance().hideArtistInfoBox();
          }
        };

    // Name panel
    // =========================================================================================
    JPanel namePanel = new JPanel();
    namePanel.setBackground(Color.DARK_GRAY);

    // Name panel / Scrobble label

    this.add(namePanel, BorderLayout.NORTH);
    namePanel.setLayout(new GridLayout(0, 2, 0, 0));

    JPanel upperleftPanel = new JPanel();
    upperleftPanel.setBackground(Color.DARK_GRAY);
    namePanel.add(upperleftPanel);
    upperleftPanel.setLayout(new BorderLayout(0, 0));

    // Name panel / Name label

    JLabel nameTxt = new JLabel(a.getName());
    upperleftPanel.add(nameTxt, BorderLayout.NORTH);
    nameTxt.setForeground(Color.WHITE);
    nameTxt.setHorizontalAlignment(SwingConstants.LEFT);
    nameTxt.setFont(new Font("Tahoma", Font.BOLD, 16));
    JLabel playTxt =
        new JLabel(
            "("
                + nf1.format(a.getScrobbles())
                + " scrobbled tracks, "
                + nf1.format(a.getListener())
                + " listeners)");
    upperleftPanel.add(playTxt, BorderLayout.SOUTH);
    playTxt.setForeground(Color.WHITE);
    playTxt.setHorizontalAlignment(SwingConstants.LEFT);
    playTxt.setFont(new Font("Tahoma", Font.ITALIC, 13));

    JPanel closePanel = new JPanel();
    closePanel.setBackground(Color.DARK_GRAY);
    namePanel.add(closePanel);
    closePanel.setLayout(null);

    CloseButton btnX = new CloseButton("x");
    btnX.resizeButton(20, 20);
    btnX.setBounds(429, 0, 20, 20);
    btnX.addMouseListener(ML_CLOSE);
    closePanel.add(btnX);
    // =========================================================================================

    // content panel
    // =========================================================================================
    JTabbedPane contentPanel = new JTabbedPane(JTabbedPane.LEFT);
    contentPanel.setLayout(new BorderLayout(0, 0));
    contentPanel.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    contentPanel.setOpaque(true);
    contentPanel.setBackground(Color.DARK_GRAY);
    contentPanel.setForeground(Color.BLACK);

    // content panel / biography panel

    JScrollPane bioPanel = new JScrollPane();
    bioPanel.setLayout(new ScrollPaneLayout());

    // content panel / biography panel / biography TextArea

    JTextArea bioArea = new SanTextbox(Utils.deleteHTMLfromText(a.getWikiFull()));
    bioArea.setBorder(new LineBorder(new Color(0, 0, 0)));
    bioArea.setBounds(new Rectangle(500, 300));
    bioArea.setBackground(Color.DARK_GRAY);
    bioArea.setForeground(Color.WHITE);
    bioArea.setEditable(false);
    bioArea.setWrapStyleWord(true);
    bioArea.setLineWrap(true);
    bioArea.setSelectionColor(bioArea.getBackground());

    Font f = new Font(Font.SANS_SERIF, Font.PLAIN, 12);
    GridBagConstraints gbc_bioArea = new GridBagConstraints();
    gbc_bioArea.insets = new Insets(0, 0, 5, 0);
    gbc_bioArea.fill = GridBagConstraints.BOTH;
    gbc_bioArea.gridx = 0;
    gbc_bioArea.gridy = 0;
    FontMetrics fm = bioArea.getFontMetrics(f);
    bioArea.setSize(width, fm.getHeight() * bioArea.getLineCount());

    bioPanel.getViewport().setView(bioArea);
    VTextIcon contentIcon = new VTextIcon(contentPanel, "biography", VTextIcon.ROTATE_LEFT);

    // content panel / popular content panel

    JPanel popularPanel = new JPanel();
    popularPanel.setLayout(new GridLayout(1, 0));

    // content panel / popular content panel / container panel

    JPanel container = new JPanel();
    container.setLayout(new BorderLayout());

    // content panel / popular content panel / tracks panel
    JPanel tracksPanel = new JPanel();
    tracksPanel.setLayout(new GridLayout(Settings.TRACKFETCH, 0));
    tracksPanel.setBorder(
        new TitledBorder(
            new BevelBorder(BevelBorder.LOWERED, null, null, null, null),
            "top tracks:",
            TitledBorder.LEADING,
            TitledBorder.TOP,
            null,
            null));
    ContentTrackField.resetList();

    Iterator<Track> t = a.getTopTracks().iterator();

    // content panel / popular content panel / tracks panel / tracks
    for (int z = 0; t.hasNext(); z++) {
      Track track = t.next();
      JLabel feld = new ContentTrackField(track.getListeners());
      Dimension feldd = new Dimension(500, (20 - 3 * z));
      feld.setSize(feldd);
      Font fontor = new Font("Tahoma", z < 2 ? Font.BOLD : Font.PLAIN, 19 - z);
      feld.setFont(fontor);
      feld.setText(track.getName() + " (" + nf1.format(track.getListeners()) + " listeners)");
      tracksPanel.add(feld);
    }
    ContentTrackField.recalc();

    container.add(tracksPanel, BorderLayout.CENTER);

    // content panel / popular content panel / albums panel
    JPanel albumsPanel = new JPanel();
    albumsPanel.setSize(500, 100);
    albumsPanel.setLayout(new GridLayout(Settings.ALBUMFETCH, 0));
    albumsPanel.setBorder(
        new TitledBorder(
            new BevelBorder(BevelBorder.LOWERED, null, null, null, null),
            "top albums:",
            TitledBorder.LEADING,
            TitledBorder.TOP,
            null,
            null));
    ContentAlbumField.resetList();

    Iterator<Album> albI = a.getTopAlbums().iterator();

    // content panel / popular content panel / albums panel / albums
    for (int z = 0; albI.hasNext(); z++) {
      Album album = albI.next();
      JLabel feld = new ContentAlbumField(album.getListeners());
      Dimension feldd = new Dimension(500, (20 - 3 * z));
      feld.setSize(feldd);
      Font fontor = new Font("Tahoma", z < 2 ? Font.BOLD : Font.PLAIN, 19 - 2 * z);
      feld.setFont(fontor);
      feld.setText(album.getName());
      albumsPanel.add(feld);
    }
    ContentAlbumField.recalc();

    container.add(albumsPanel, BorderLayout.SOUTH);

    popularPanel.add(container);
    VTextIcon popularIcon = new VTextIcon(contentPanel, "popular content", VTextIcon.ROTATE_LEFT);

    // content panel / blogpost panel

    JScrollPane postPanel = new JScrollPane();
    postPanel.setLayout(new ScrollPaneLayout());
    postPanel.getVerticalScrollBar().setBlockIncrement(1);
    postPanel.setSize(500, 300);
    VTextIcon blogIcon = new VTextIcon(contentPanel, "blog posts", VTextIcon.ROTATE_LEFT);

    // content panel / blogpost panel / posts list

    JList<BlogPost> list = new JList<BlogPost>();
    DefaultListModel<BlogPost> model = new DefaultListModel<BlogPost>();
    BlogPost[] posts = Utils.sortBlogPostArray(a.getRelatedHypemPosts(), Settings.Sort.BYLIKES);
    if (posts != null) {
      for (BlogPost b : posts) {
        model.addElement(b);
      }
      list.setCellRenderer(new BlogPostListCellRenderer());
    } else {
      list.setSelectionBackground(Color.WHITE);
      list.setBorder(null);
    }
    list.setFixedCellHeight(150);
    list.setModel(model);

    postPanel.getViewport().setView(list);

    // composing the tab order for the content panel
    // 1. popular content, 2. biography, 3. blog posts
    contentPanel.addTab(TABLENGTH, popularIcon, popularPanel);
    contentPanel.addTab(TABLENGTH, contentIcon, bioPanel);
    contentPanel.addTab(TABLENGTH, blogIcon, postPanel);

    // adding the content panel to the main panel
    this.add(contentPanel, BorderLayout.CENTER);
    // =========================================================================================

    // west panel
    // =========================================================================================
    JPanel panel = new JPanel();
    panel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
    panel.setBackground(Color.DARK_GRAY);
    panel.setLayout(new BorderLayout(0, 0));

    // west panel / image panel

    JPanel imagePanel = new ImagePanel(a.getLargeImage());
    imagePanel.setBackground(Color.DARK_GRAY);

    panel.add(imagePanel, BorderLayout.CENTER);

    // west panel / tags panel
    JPanel tagsPanel = new JPanel();
    tagsPanel.setLayout(new BorderLayout(0, 0));
    tagsPanel.setBorder(
        new TitledBorder(
            new BevelBorder(BevelBorder.LOWERED, null, null, null, null),
            "tags:",
            TitledBorder.LEADING,
            TitledBorder.TOP,
            null,
            null));
    tagsPanel.setForeground(Color.WHITE);
    tagsPanel.setBackground(Color.DARK_GRAY);

    // west panel / image panel / textfield

    JTextArea tagField = new SanTextbox();
    tagField.setWrapStyleWord(true);
    tagField.setEnabled(false);
    tagField.setEditable(false);
    tagField.setLineWrap(true);
    tagField.setBorder(null);
    tagField.setBackground(null);
    tagField.setForeground(Color.WHITE);

    StringBuilder sb = new StringBuilder();
    for (Iterator<String> i = a.getTags().iterator(); i.hasNext(); ) {
      sb.append(i.next());
      if (i.hasNext()) sb.append(", ");
    }
    tagField.setText(sb.toString());
    tagField.setColumns(10);

    tagsPanel.add(tagField);

    panel.add(tagsPanel, BorderLayout.SOUTH);

    this.add(panel, BorderLayout.WEST);

    // =========================================================================================

    // south panel
    // =========================================================================================
    JPanel musicPanel = new JPanel();
    musicPanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
    // get tracks for element creation
    ArrayList<Track> tracks = (ArrayList<Track>) a.getTopTracks();
    musicPanel.setLayout(new GridLayout(0, 2));
    musicPanel.setBackground(Color.DARK_GRAY);

    // south panel / track play elements (according to artist node information)

    JPanel musicElementsPanel = new JPanel();
    musicElementsPanel.setSize(500, 300);
    musicElementsPanel.setBackground(Color.DARK_GRAY);
    musicPanel.add(musicElementsPanel);
    musicElementsPanel.setLayout(new GridLayout(0, 1));

    if (tracks != null && tracks.size() > 0) {
      for (int i = 0; i < 5; i++) {
        TrackPlayElement element = new TrackPlayElement(a.getName(), tracks.get(i).getName());
        if (element != null) {
          element.setForeground(Color.WHITE);
          musicElementsPanel.add(element);
        }
      }
    }

    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setLayout(null);

    JButton confirmButton = new JButton("<html>Save this artist & do another search</html>");
    confirmButton.setBounds(337, 9, 100, 100);
    confirmButton.addMouseListener(ML_CONFIRM);
    buttonsPanel.add(confirmButton);

    JButton abortButton = new JButton("Go back");
    abortButton.setBounds(337, 120, 99, 23);
    abortButton.addMouseListener(ML_CLOSE);
    buttonsPanel.add(abortButton);

    buttonsPanel.setBackground(Color.DARK_GRAY);

    musicPanel.add(buttonsPanel);

    this.add(musicPanel, BorderLayout.SOUTH);
    Dimension d = new Dimension(500, 150);
    Utils.fixSize(musicPanel, d);

    // =========================================================================================
  }