public EditorDividerPanel(NaviView naviview, boolean expanded) { super(); // display consists of a label with an image nav = naviview; this.expanded = expanded; openNavArrow = Config.getImageAsIcon("image.editordivider.open"); closeNavArrow = Config.getImageAsIcon("image.editordivider.close"); setPreferredSize(new Dimension(closeNavArrow.getIconWidth() + 2, 0)); setMaximumSize(new Dimension(closeNavArrow.getIconWidth() + 2, Integer.MAX_VALUE)); setLayout(new DBoxLayout(DBox.X_AXIS, 0, 0)); expandCollapseButton = new JLabel(); expandCollapseButton.setName(EXPAND_COLLAPSE_NAVIVIEW); addMouseListener(this); add(expandCollapseButton, BorderLayout.CENTER); if (isExpanded()) expandCollapseButton.setIcon(closeNavArrow); else { nav.setVisible(false); expandCollapseButton.setIcon(openNavArrow); } }
/** * Syntax colouring for the codepad. * * @author Bruce Quig * @author Michael Kolling */ public class TextEvalSyntaxView extends BlueJSyntaxView { public static final short TAG_WIDTH = 14; protected static final int BREAKPOINT_OFFSET = TAG_WIDTH + 2; protected static final int LEFT_MARGIN = BREAKPOINT_OFFSET + 5; // Attributes for lines and document public static final String OUTPUT = "output"; public static final String ERROR = "error"; public static final String CONTINUE = "continue"; public static final String OBJECT = "object-ref"; static final Image promptImage = Config.getImageAsIcon("image.eval.prompt").getImage(); static final Image continueImage = Config.getImageAsIcon("image.eval.continue").getImage(); static final Image objectImage = Config.getImageAsIcon("image.eval.object").getImage(); static final Color outputColor = new Color(0, 120, 0); static final Color errorColor = new Color(200, 0, 20); /** * Creates a new TextEvalSyntaxView for painting the specified element. * * @param elem The element */ public TextEvalSyntaxView(Element elem) { super(elem, LEFT_MARGIN); } /** Draw a line for the text eval area. */ public void paintTaggedLine( Segment lineText, int lineIndex, Graphics g, int x, int y, MoeSyntaxDocument document, Color def, Element line, TabExpander tx) { if (hasTag(line, OUTPUT)) { g.setColor(outputColor); Utilities.drawTabbedText(lineText, x, y, g, tx, 0); } else if (hasTag(line, ERROR)) { g.setColor(errorColor); Utilities.drawTabbedText(lineText, x, y, g, tx, 0); } else if (hasObject(line, OBJECT)) { g.drawImage(objectImage, x - 1 - LEFT_MARGIN, y + 3 - objectImage.getHeight(null), null); g.setColor(outputColor); Utilities.drawTabbedText(lineText, x, y, g, tx, 0); } else if (hasTag(line, CONTINUE)) { g.drawImage(continueImage, x - 1 - LEFT_MARGIN, y + 3 - continueImage.getHeight(null), null); paintSyntaxLine(lineText, lineIndex, x, y, g, document, def, tx); } else { g.drawImage(promptImage, x - 1 - LEFT_MARGIN, y + 3 - promptImage.getHeight(null), null); paintSyntaxLine(lineText, lineIndex, x, y, g, document, def, tx); } } /** * Check whether a given line is tagged with a given tag. * * @param line The line to check * @param tag The name of the tag * @return True, if the tag is set */ protected final boolean hasObject(Element line, String tag) { return line.getAttributes().getAttribute(tag) != null; } /** redefined paint method to paint breakpoint area */ public void paint(Graphics g, Shape allocation) { Rectangle bounds = allocation.getBounds(); // paint the lines super.paint(g, allocation); // paint the tag separator line g.setColor(Color.lightGray); g.drawLine(bounds.x + TAG_WIDTH, 0, bounds.x + TAG_WIDTH, bounds.y + bounds.height); } }