001 package nl.cwi.sen1.tide.tool.support; 002 003 import java.awt.Color; 004 import java.awt.Dimension; 005 import java.awt.Graphics; 006 import java.awt.event.MouseAdapter; 007 import java.awt.event.MouseEvent; 008 import java.awt.event.MouseListener; 009 010 import javax.swing.JComponent; 011 012 public class ProcessStatus 013 extends JComponent 014 implements ProcessStatusChangeListener 015 { 016 private final static int SIZE = 12; 017 private final static Color COLOR_GREEN = Color.green; 018 private final static Color COLOR_RED = Color.red; 019 private final static Color COLOR_BORDER = Color.black; 020 private final static Color COLOR_BACKGROUND = Color.gray; 021 private final static Color COLOR_OFF = Color.lightGray; 022 023 private DebugProcess process; 024 025 //{{{ public ProcessStatus(DebugProcess process) 026 027 public ProcessStatus(DebugProcess proc) 028 { 029 this.process = proc; 030 process.addProcessStatusChangeListener(this); 031 MouseListener mouseListener = 032 new MouseAdapter() 033 { 034 public void mouseClicked(MouseEvent evt) 035 { 036 if (evt.getX() > getSize().width/2) { 037 if (!process.isRunning()) { 038 process.requestResume(); 039 } 040 } else { 041 if (process.isRunning()) { 042 process.requestBreak(); 043 } 044 } 045 } 046 }; 047 048 addMouseListener(mouseListener); 049 } 050 051 //}}} 052 053 //{{{ public void processStatusChanged(DebugProcess process) 054 055 public void processStatusChanged(DebugProcess process) 056 { 057 repaint(); 058 } 059 060 //}}} 061 062 //{{{ public Dimension getPreferredSize() 063 064 public Dimension getPreferredSize() 065 { 066 return new Dimension(SIZE*2 + 3*2, SIZE+2*2); 067 } 068 069 //}}} 070 //{{{ public Dimension getMinimumSize() 071 072 public Dimension getMinimumSize() 073 { 074 return getPreferredSize(); 075 } 076 077 //}}} 078 //{{{ public Dimension getMaximumSize() 079 080 public Dimension getMaximumSize() 081 { 082 return getPreferredSize(); 083 } 084 085 //}}} 086 087 //{{{ public void paint(Graphics g) 088 089 public void paint(Graphics g) 090 { 091 Dimension dim = getSize(); 092 093 g.setColor(COLOR_BACKGROUND); 094 g.fillRect(0, 0, dim.width, dim.height); 095 096 g.setColor(COLOR_BORDER); 097 g.drawRect(0, 0, dim.width, dim.height); 098 099 if (!process.isRunning()) { 100 g.setColor(COLOR_RED); 101 } 102 else { 103 g.setColor(COLOR_OFF); 104 } 105 g.fillOval(dim.width/4 - SIZE/2, dim.height/2 - SIZE/2, SIZE, SIZE); 106 107 if (process.isRunning()) { 108 g.setColor(COLOR_GREEN); 109 } 110 else { 111 g.setColor(COLOR_OFF); 112 } 113 g.fillOval((dim.width/4)*3 - SIZE/2, dim.height/2 - SIZE/2, SIZE, SIZE); 114 } 115 116 //}}} 117 }