MOA 12.03
Real Time Analytics for Data Streams
MOAClassOptionEditor.java
Go to the documentation of this file.
00001 /*
00002  * MOAClassOptionEditor.java
00003  * Copyright (C) 2009 University of Waikato, Hamilton, New Zealand
00004  */
00005 
00006 package weka.gui;
00007 
00008 import java.awt.BorderLayout;
00009 import java.awt.Component;
00010 import java.awt.Container;
00011 import java.awt.Dialog;
00012 import java.awt.FontMetrics;
00013 import java.awt.Graphics;
00014 import java.awt.Rectangle;
00015 import java.beans.PropertyEditorSupport;
00016 
00017 import javax.swing.BorderFactory;
00018 import javax.swing.JPanel;
00019 import javax.swing.event.ChangeEvent;
00020 import javax.swing.event.ChangeListener;
00021 
00022 import moa.gui.ClassOptionEditComponent;
00023 import moa.options.ClassOption;
00024 
00032 public class MOAClassOptionEditor
00033   extends PropertyEditorSupport {
00034 
00036         protected Component m_CustomEditor;
00037 
00039         protected ClassOptionEditComponent m_EditComponent;
00040 
00046         public boolean isPaintable() {
00047                 return false;
00048         }
00049 
00055         public boolean supportsCustomEditor() {
00056                 return true;
00057         }
00058 
00062         protected void closeDialog() {
00063                 if (m_CustomEditor instanceof Container) {
00064                         Dialog dlg = PropertyDialog.getParentDialog((Container) m_CustomEditor);
00065                         if (dlg != null)
00066                                 dlg.setVisible(false);
00067                 }
00068         }
00069 
00075         protected Component createCustomEditor() {
00076                 JPanel                  panel;
00077 
00078                 panel = new JPanel(new BorderLayout());
00079                 panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
00080                 m_EditComponent = (ClassOptionEditComponent) ((ClassOption) getValue()).getEditComponent();
00081                 m_EditComponent.addChangeListener(new ChangeListener() {
00082                         public void stateChanged(ChangeEvent e) {
00083                                 m_EditComponent.applyState();
00084                                 setValue(m_EditComponent.getEditedOption());
00085                         }
00086                 });
00087                 panel.add(m_EditComponent, BorderLayout.CENTER);
00088 
00089                 return panel;
00090         }
00091 
00097         public Component getCustomEditor() {
00098                 if (m_CustomEditor == null)
00099                         m_CustomEditor = createCustomEditor();
00100 
00101                 return m_CustomEditor;
00102         }
00103 
00110   public void paintValue(Graphics gfx, Rectangle box) {
00111     FontMetrics         fm;
00112     int                                         vpad;
00113     String                              val;
00114 
00115     fm   = gfx.getFontMetrics();
00116     vpad = (box.height - fm.getHeight()) / 2 ;
00117     val  = ((ClassOption) getValue()).getValueAsCLIString();
00118     gfx.drawString(val, 2, fm.getHeight() + vpad);
00119   }
00120 }
 All Classes Namespaces Files Functions Variables Enumerations