/** * */ package visualization; import java.awt.Color; import java.awt.Graphics; import javax.swing.JPanel; import javax.swing.JScrollPane; import logging.LogElement; import logging.LogElementList; /** * This class provides the basic draw area for a HybridWindow. * Use it in assoziation with packages logging and visualization. * Just overwrite the draw(Graphics) method to get a graphic output from a log list element. * Parameters for algorithm processing are read from member parameterArea that ist part of the user interface. * @see LogElement * @see LogElementList * @see visualization.HybridWindow * @see javax.swing.JPanel * @author Björn Strobel
* University of Cooperative Education Stuttgart, * Campus Horb
* Department of Information Technology
* it2003
*/ public abstract class DrawAreaextends JPanel{ /** The draw area's scroll pane. */ protected JScrollPane scrollPane; /** The log element list where the draw area gets the log elements to draw. */ protected LogElementListlogList; /** The name to be displayed on the draw area's tab in the hybrid window. */ protected String drawAreaName; /** * Standard constructor. * Creates an empty draw area with scroll pane. */ public DrawArea() { super(); scrollPane=new JScrollPane(this); setBackground(new Color(194,177,255)); setForeground(new Color(0,0,0)); } /** * Creates an empty draw area with scroll pane and sets the specified log list and tab name. * @param logList the draw area's log list * @param drawAreaName the name for the draw area to be displayed on the hybrid window's tab */ public DrawArea(LogElementListlogList,String drawAreaName){ super(); scrollPane=new JScrollPane(this); setBackground(new Color(194,177,255)); setForeground(new Color(0,0,0)); this.logList=logList; this.drawAreaName=drawAreaName; } /** * Returns the draw area'a scroll pane. * @return the draw area'a scroll pane */ public JScrollPane getScrollPane(){ return scrollPane; } /** * Sets the draw area's log list. * @param logList the draw area's log list */ public void setLogList(LogElementListlogList){ this.logList=logList; } /** * Gets the draw area's name * @return the name to be returned */ public String getDrawAreaName() { return drawAreaName; } /** * Sets the draw area's name * @param drawAreaName the name to be set */ public void setDrawAreaName(String drawAreaName) { this.drawAreaName = drawAreaName; } /** * Calls repaint(). */ public void drawStep(){ repaint(); } /** * Paints the draw area background and calls draw(Graphics). */ public void paint(Graphics g){ super.paint(g); if(logList.isInitialized()){ draw(g); } } /** * Draws the actual log element's graphical output. * @param g Graphics object given by paint(Graphics); */ public void draw(Graphics g){ LogElement logElement=(LogElement)logList.get(); g.drawString(logElement.getDescription(),20,20); } /** * Provided for convenience. Does the same as drawStep. * Use it with logElementList.clear(). */ public void clear(){ repaint(); } }