Changeset 1134


Ignore:
Timestamp:
Jul 2, 2011, 10:18:55 AM (6 years ago)
Author:
stefan
Message:

implemented task #175: replace classical tree icons with whether icons in compilation tree

Location:
trunk
Files:
11 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/CHANGELOG

    r1113 r1134  
    1616  - replaced buggy Java open dialog with a completely new one - better looking and better usability
    1717* minor enhancements:
    18   - prettied up tabs
     18  - prettied up tabs and icons in compile tree
    1919  - added icons to menu (thanks to Tango Desktop Project for the icons)
    2020  - svn merge conflicts are highlighted red
  • trunk/src/jlatexeditor/ErrorView.java

    r1110 r1134  
    11package jlatexeditor;
    22
    3 import com.google.inject.internal.cglib.core.MethodWrapper;
    43import jlatexeditor.errorhighlighting.LatexCompileError;
    54import sce.component.SCEPane;
    65import sce.component.SourceCodeEditor;
     6import util.StreamUtils;
    77
    88import javax.swing.*;
     
    1414import java.awt.*;
    1515import java.awt.event.*;
     16import java.io.IOException;
    1617import java.util.ArrayList;
    1718
     
    3233
    3334  private JTree tree;
    34   private DefaultMutableTreeNode nodeRoot, nodeError, nodeHbox, nodeWarning, nodeWarningCitation, nodeWarningReference, nodeOutput;
    35   private DefaultListModel lmError = new DefaultListModel();
    36   private DefaultListModel lmHbox = new DefaultListModel();
    37   private DefaultListModel lmWarning = new DefaultListModel();
    38   private DefaultListModel lmWarningCitation = new DefaultListModel();
    39   private DefaultListModel lmWarningReference = new DefaultListModel();
     35  private ErrorTreeNode nodeRoot, nodeError, nodeHbox, nodeWarning, nodeWarningCitation, nodeWarningReference, nodeOutput;
     36  private ErrorListModel lmError = new ErrorListModel();
     37  private WarningListModel lmHbox = new WarningListModel();
     38  private WarningListModel lmWarning = new WarningListModel();
     39  private WarningListModel lmWarningCitation = new WarningListModel();
     40  private WarningListModel lmWarningReference = new WarningListModel();
    4041  private JList listError = new JList(lmError);
    4142  private JList listHbox = new JList(lmHbox);
     
    5859    latexOutput.setFont(new Font("MonoSpaced", 0, 13));
    5960
    60     nodeRoot = new DefaultMutableTreeNode("compile...");
    61     nodeError = new DefaultMutableTreeNode();
     61    AggregatedErrors aggregatedErrors = new AggregatedErrors(new ErrorLevelInterface[]{lmError, lmHbox, lmWarning, lmWarningCitation, lmWarningReference});
     62    nodeRoot = new ErrorTreeNode(aggregatedErrors, "compile...", "black");
     63    nodeError = new ErrorTreeNode(lmError, "error", "red");
    6264    nodeRoot.add(nodeError);
    63     nodeHbox = new DefaultMutableTreeNode();
     65    nodeHbox = new ErrorTreeNode(lmHbox, "overfull hboxes", "black");
    6466    nodeRoot.add(nodeHbox);
    65     nodeWarning = new DefaultMutableTreeNode();
    66     nodeWarningCitation = new DefaultMutableTreeNode();
    67     nodeWarningReference = new DefaultMutableTreeNode();
     67    nodeWarning = new ErrorTreeNode(lmWarning, "warning", "black");
     68    nodeWarningCitation = new ErrorTreeNode(lmWarningCitation, "citations", "black");
     69    nodeWarningReference = new ErrorTreeNode(lmWarningReference, "references", "black");
    6870    nodeRoot.add(nodeWarning);
    6971    nodeRoot.add(nodeWarningCitation);
    7072    nodeRoot.add(nodeWarningReference);
    71     nodeOutput = new DefaultMutableTreeNode("output");
     73    nodeOutput = new ErrorTreeNode("output", "text-x-generic.png");
    7274    nodeRoot.add(nodeOutput);
    7375    update();
     
    9193    treePanel.setBackground(Color.WHITE);
    9294    treePanel.setLayout(new BorderLayout());
    93     treePanel.add(tree, BorderLayout.NORTH);
    94 
    95     working = new JLabel(new ImageIcon(getClass().getResource("/images/working32.gif")));
    96     working.setVisible(false);
    97     treePanel.add(working, BorderLayout.CENTER);
     95    working = new JLabel(new ImageIcon(getClass().getResource("/images/working32.gif")));
     96    working.setVisible(false);
     97    treePanel.add(working, BorderLayout.NORTH);
     98    JScrollPane treeScrollPane = new JScrollPane(tree);
     99    treeScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
     100    treePanel.add(treeScrollPane, BorderLayout.CENTER);
    98101
    99102    setLeftComponent(treePanel);
     
    125128
    126129  public void update() {
    127     nodeError.setUserObject("<html><font color=\"" + (lmError.getSize() > 0 ? "red" : "gray") + "\">errors (" + lmError.getSize() + ")</font></html>");
     130    nodeError.update();
     131    //nodeError.setUserObject("<html><font color=\"" + (lmError.getSize() > 0 ? "red" : "gray") + "\">errors (" + lmError.getSize() + ")</font></html>");
    128132    nodeHbox.setUserObject("<html><font color=\"" + (lmHbox.getSize() > 0 ? "black" : "gray") + "\">overfull hboxes (" + lmHbox.getSize() + ")</font></html>");
    129133    nodeWarning.setUserObject("<html><font color=\"" + (lmWarning.getSize() > 0 ? "black" : "gray") + "\">warnings (" + lmWarning.getSize() + ")</font></html>");
     
    340344
    341345  private class ErrorTreeCellRenderer extends DefaultTreeCellRenderer {
     346    /*
     347    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
     348        DefaultMutableTreeNode currentTreeNode = (DefaultMutableTreeNode) value;
     349        TreeEntry userObject = (TreeEntry) currentTreeNode
     350                .getUserObject();
     351        if (Vehicle.CAR.equals(userObject.getCategory())) {
     352            setLeafIcon(CAR_ICON);
     353        } else if (Vehicle.MOTO_BIKE.equals(userObject.getCategory())) {
     354            setLeafIcon(MOTOBIKE_ICON);
     355        }
     356        return super.getTreeCellRendererComponent(tree, value, sel,
     357                expanded, leaf, row, hasFocus);
     358    }
     359    */
     360
    342361    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
     362      ErrorTreeNode treeNode = (ErrorTreeNode) value;
     363
     364      ImageIcon icon = treeNode.getIcon();
     365      setLeafIcon(icon);
     366      setClosedIcon(icon);
     367      setOpenIcon(icon);
     368
    343369      Component component = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    344370      Dimension dimension = component.getPreferredSize();
     
    348374    }
    349375  }
     376
     377  public static class ErrorTreeNode extends DefaultMutableTreeNode {
     378    private final static ImageIcon ICON_CLEAR             = loadIcon("weather-clear.png");
     379    private final static ImageIcon ICON_FEW_CLOUDS        = loadIcon("weather-few-clouds.png");
     380    private final static ImageIcon ICON_OVERCASET         = loadIcon("weather-overcast.png");
     381    private final static ImageIcon ICON_SHOWERS_SCATTERED = loadIcon("weather-showers-scattered.png");
     382    private final static ImageIcon ICON_SHOWERS           = loadIcon("weather-showers.png");
     383    private final static ImageIcon ICON_STORM             = loadIcon("weather-storm.png");
     384    private final static ImageIcon ICON_SEVERE_ALERT      = loadIcon("weather-severe-alert.png");
     385    private final static ImageIcon[] icons = new ImageIcon[]{
     386      ICON_CLEAR, ICON_FEW_CLOUDS, ICON_OVERCASET, ICON_SHOWERS_SCATTERED, ICON_SHOWERS, ICON_STORM, ICON_SEVERE_ALERT
     387    };
     388
     389    private static ImageIcon loadIcon(String filename) {
     390      try {
     391        return new ImageIcon(StreamUtils.readBytesFromInputStream(StreamUtils.getInputStream("data/icons/tango/" + filename)));
     392      } catch (IOException e) {
     393        e.printStackTrace();
     394        return null;
     395      }
     396    }
     397
     398    private ErrorLevelInterface lm;
     399    private String errorColor;
     400    private String label;
     401    private ImageIcon icon = null;
     402
     403    public ErrorTreeNode(ErrorLevelInterface lm, String label, String errorColor) {
     404      super(label);
     405      this.lm = lm;
     406      this.errorColor = errorColor;
     407      this.label = label;
     408    }
     409
     410    public ErrorTreeNode() {
     411    }
     412
     413    public ErrorTreeNode(Object userObject, String iconFile) {
     414      super(userObject);
     415      icon = loadIcon(iconFile);
     416    }
     417
     418    public int getErrors() {
     419      return lm.getSize();
     420    }
     421
     422    public ImageIcon getIcon() {
     423      if (icon != null) return icon;
     424
     425      return icons[lm.getErrorLevel()];
     426    }
     427
     428    public void update() {
     429      setUserObject("<html><font color=\"" + (lm.getSize() > 0 ? errorColor : "gray") + "\">" + label + " (" + lm.getSize() + ")</font></html>");
     430    }
     431  }
     432
     433  public static class WarningListModel extends DefaultListModel implements ErrorLevelInterface {
     434    private final static int[] maxErrors = {0, 10, Integer.MAX_VALUE};
     435
     436    @Override
     437    public int getErrorLevel() {
     438      for (int i = 0; i < maxErrors.length; i++) {
     439        if (getSize() <= maxErrors[i]) {
     440          return i;
     441        }
     442      }
     443      return 0;
     444    }
     445  }
     446  public static class ErrorListModel extends DefaultListModel implements ErrorLevelInterface {
     447    private final static int[] maxErrors = {0, -1, -1, 3, 10, 99, Integer.MAX_VALUE};
     448
     449    @Override
     450    public int getErrorLevel() {
     451      for (int i = 0; i < maxErrors.length; i++) {
     452        if (getSize() <= maxErrors[i]) {
     453          return i;
     454        }
     455      }
     456      return 0;
     457    }
     458  }
     459  public static class AggregatedErrors implements ErrorLevelInterface {
     460    private ErrorLevelInterface[] errorLevels;
     461
     462    public AggregatedErrors(ErrorLevelInterface[] errorLevels) {
     463      this.errorLevels = errorLevels;
     464    }
     465
     466    @Override
     467    public int getSize() {
     468      int sum = 0;
     469      for (ErrorLevelInterface size : errorLevels) {
     470        sum += size.getSize();
     471      }
     472      return sum;
     473    }
     474
     475    public int getErrorLevel() {
     476      int maxErrorLevel = 0;
     477      for (ErrorLevelInterface errorLevel : errorLevels) {
     478        maxErrorLevel = Math.max(maxErrorLevel, errorLevel.getErrorLevel());
     479      }
     480      return maxErrorLevel;
     481    }
     482  }
     483
     484  public static interface ErrorLevelInterface {
     485    public int getSize();
     486    public int getErrorLevel();
     487  }
    350488
    351489  public class ErrorPopupMenu extends JPopupMenu {
Note: See TracChangeset for help on using the changeset viewer.