Changeset 1110


Ignore:
Timestamp:
Jun 25, 2011, 8:05:45 PM (6 years ago)
Author:
stefan
Message:

scroll to error in compiler output

Location:
trunk/src/jlatexeditor
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/jlatexeditor/ErrorView.java

    r1014 r1110  
    11package jlatexeditor;
    22
     3import com.google.inject.internal.cglib.core.MethodWrapper;
    34import jlatexeditor.errorhighlighting.LatexCompileError;
    45import sce.component.SCEPane;
     
    1011import javax.swing.event.TreeSelectionEvent;
    1112import javax.swing.event.TreeSelectionListener;
    12 import javax.swing.tree.DefaultMutableTreeNode;
    13 import javax.swing.tree.DefaultTreeCellRenderer;
    14 import javax.swing.tree.TreeNode;
    15 import javax.swing.tree.TreeSelectionModel;
     13import javax.swing.tree.*;
    1614import java.awt.*;
    17 import java.awt.event.KeyEvent;
    18 import java.awt.event.KeyListener;
    19 import java.awt.event.MouseEvent;
    20 import java.awt.event.MouseListener;
     15import java.awt.event.*;
    2116import java.util.ArrayList;
    2217
     
    5550
    5651  private JLabel working;
     52
     53  ErrorPopupMenu popup = new ErrorPopupMenu();
    5754
    5855  public ErrorView(JLatexEditorJFrame latexEditor) {
     
    140137  }
    141138
     139  public int getLinesCount() {
     140    return latexOutput.getLineCount();
     141  }
     142
    142143  public void addError(LatexCompileError error) {
    143144    errors.add(error);
     
    215216    LatexCompileError error = errorComponent.getError();
    216217
    217     SourceCodeEditor editor = latexEditor.open(new Doc.FileDoc(error.getFile()));
     218    SourceCodeEditor<Doc> editor = latexEditor.open(new Doc.FileDoc(error.getFile()));
    218219    SCEPane pane = editor.getTextPane();
    219220
     
    250251
    251252  public void mousePressed(MouseEvent e) {
     253    if (e.getButton() == 3) {
     254      if (e.getSource() instanceof JList) {
     255        JList list = (JList) e.getSource();
     256        int index = list.locationToIndex(e.getPoint());
     257        Object elementAt = list.getModel().getElementAt(index);
     258        if (elementAt instanceof ErrorComponent) {
     259          ErrorComponent ec = (ErrorComponent) elementAt;
     260          popup.show(list, ec.error, e.getX(), e.getY());
     261        }
     262      }
     263    }
    252264  }
    253265
     
    336348    }
    337349  }
     350
     351  public class ErrorPopupMenu extends JPopupMenu {
     352    private JList jList;
     353    private LatexCompileError error;
     354
     355    public ErrorPopupMenu() {
     356      add(new JMenuItem("View compiler output") {{
     357        addActionListener(new ActionListener() {
     358          @Override
     359          public void actionPerformed(ActionEvent e) {
     360            try {
     361              int line = error.getOutputLine();
     362              int start = latexOutput.getLineStartOffset(line);
     363              int end = latexOutput.getLineEndOffset(line);
     364              tree.getSelectionModel().setSelectionPath(new TreePath(new Object[]{nodeRoot, nodeOutput}));
     365              //setRightComponent(scrollOutput);
     366              latexOutput.scrollRectToVisible(new Rectangle(0, 30*latexOutput.getLineCount(), 0, 30*latexOutput.getLineCount()));
     367              latexOutput.setCaretPosition(start);
     368            } catch (Exception e1) {
     369              e1.printStackTrace();
     370            }
     371          }
     372        });
     373      }});
     374    }
     375
     376    public void show(JList jList, LatexCompileError error, int x, int y) {
     377      this.jList = jList;
     378      this.error = error;
     379      show(jList, x, y);
     380    }
     381  }
    338382}
  • trunk/src/jlatexeditor/errorhighlighting/LatexCompileError.java

    r744 r1110  
    1818  private int type = TYPE_ERROR;
    1919
     20  private int outputLine;
    2021  private File file = null;
    2122  private String fileName = null;
     
    3738  }
    3839
    39   public File getFile() {
     40  public int getOutputLine() {
     41    return outputLine;
     42  }
     43
     44  public void setOutputLine(int outputLine) {
     45    this.outputLine = outputLine;
     46  }
     47
     48  public File getFile() {
    4049    return file;
    4150  }
  • trunk/src/jlatexeditor/errorhighlighting/LatexCompiler.java

    r1054 r1110  
    112112        if (line.startsWith("!") || errorMatcher.matches()) {
    113113          error = new LatexCompileError();
     114          error.setOutputLine(errorView.getLinesCount()-2);
    114115          error.setType(LatexCompileError.TYPE_ERROR);
    115116          if (line.startsWith("!")) {
     
    171172        if (line.startsWith("LaTeX Warning:") || line.startsWith("LaTeX Font Warning:")) {
    172173          error = new LatexCompileError();
     174          error.setOutputLine(errorView.getLinesCount()-2);
    173175          error.setType(LatexCompileError.TYPE_WARNING);
    174176          String fileName = fileStack.get(fileStack.size() - 1);
     
    180182            try {
    181183              error.setLine(Integer.parseInt(line.substring(linePos, line.indexOf('.', linePos))));
    182             } catch (Exception e) {
     184            } catch (Exception ignored) {
    183185            }
    184186          }
     
    200202        if (line.startsWith("Overfull \\hbox") || line.startsWith("Underfull \\hbox")) {
    201203          error = new LatexCompileError();
     204          error.setOutputLine(errorView.getLinesCount()-2);
    202205          error.setType(LatexCompileError.TYPE_OVERFULL_HBOX);
    203206          String fileName = fileStack.get(fileStack.size() - 1);
     
    219222            line = in.readLine();
    220223            errorView.appendLine(line);
    221             if (line.indexOf("/10") == -1) break;
     224            if (!line.contains("/10")) break;
    222225          }
    223226
     
    229232
    230233        // opening and closing files
    231         if ((line.indexOf("(") != -1 && !line.startsWith("(see")) || line.startsWith(")") ||
     234        if ((line.contains("(") && !line.startsWith("(see")) || line.startsWith(")") ||
    232235                (line.indexOf(')') != -1 && (line.startsWith("[") || line.indexOf(".tex") != 0 || line.indexOf(".sty") != 0 || line.indexOf(".bbl") != 0 || line.indexOf(".aux") != 0))) {
    233236          int position = 0;
Note: See TracChangeset for help on using the changeset viewer.