ProjektGraph/visualisation/DrawArea.java
2024-07-02 21:13:30 +02:00

132 lines
3.1 KiB
Java
Raw Permalink Blame History

/**
*
*/
package visualisation;
import logging.LogElement;
import logging.LogElementList;
import javax.swing.*;
import java.awt.*;
/**
* 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 HybridWindow
* @see JPanel
* @author Bj<42>rn Strobel<br><small>
* University of Cooperative Education Stuttgart,
* Campus Horb<br>
* Department of Information Technology<br>
* it2003<br></small>
*/
public abstract class DrawArea<LOG extends LogElement>extends 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 LogElementList<LOG>logList;
/** 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(LogElementList<LOG>logList, 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(LogElementList<LOG>logList){
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();
}
}