GeomVis  0.1
Набор классов Java для визуализации результатов работы геометрических алгоритмов
IndicatorLabel.java
См. документацию.
1 package control;
2 
3 import java.lang.reflect.InvocationTargetException;
4 import java.lang.reflect.Method;
5 
6 import javax.swing.JLabel;
7 
10 
11 public class IndicatorLabel extends JLabel implements IGeomContainerListener
12 {
13 
14  private String text = "";
15  // static method prototype: static String methodName(GeomContainer gObjects)
16  // from Indicators class
17  private String methodName = "";
18 
19  public IndicatorLabel(String text, String methodName, GeomContainer source) {
20  if (text != null)
21  {
22  this.text = text;
23  }
24  this.methodName = methodName;
25 
26  onDataChanged(source);
27  source.addListener(this);
28  }
29 
30  @Override
31  public void onDataChanged(GeomContainer gObjects)
32  {
33  Class c = Indicators.class;
34  String result = "";
35  try
36  {
37  Method method = c.getMethod(methodName, GeomContainer.class);
38  try
39  {
40  result = (String) method.invoke(null, gObjects);
41  } catch (IllegalAccessException | IllegalArgumentException
42  | InvocationTargetException e)
43  {
44  // TODO Auto-generated catch block
45  e.printStackTrace();
46  }
47  } catch (NoSuchMethodException e)
48  {
49  Message.out("No method " + methodName
50  + " in class Indicators!\nCheck the name.");
51  } catch (SecurityException e)
52  {
53  Message.out("�ethod " + methodName
54  + " in class Indicators is NOT public. �ake it public.");
55  }
56 
57  this.setText(text + ": " + result);
58  }
59 
60 }
IndicatorLabel(String text, String methodName, GeomContainer source)
Kласс для хранения графических объектов
Интерфейс слушателя контейнера. Функция вызывается при изменении контейнера
void onDataChanged(GeomContainer gObjects)