Package vg.modules.backlight.components

Source Code of vg.modules.backlight.components.CycleSearcher

package vg.modules.backlight.components;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.SwingUtilities;

import vg.core.AUserInterface;
import vg.core.AUserInterfaceElement;
import vg.core.IGraphView;
import vg.core.event.AUIEvent;
import vg.core.event.UIEventChangeView;
import vg.core.exception.PluginException;
import vg.core.plugin.IPlugin;
import vg.core.plugin.PluginParameter;
import vg.core.storableGraph.StorableSubGraph;
import vg.core.storableGraph.StorableVertex;

/**
* This plugin finds cycle in current subgraph.
* @author tzolotuhin
*/
public class CycleSearcher {
  private JButton button;
  private IGraphView view;

  // -------------------------------------------------------------------------
  public CycleSearcher() {
    // ---------------------------------------
    this.button = new JButton(new ImageIcon("./data/resources/textures/circle.png"));
    this.button.setToolTipText("Find all cycles, which have current vertex");
    this.button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        if (CycleSearcher.this.view == null)
          return;
        StorableSubGraph ssg = CycleSearcher.this.view.getSelectionSubGraph();
        if (ssg != null) {
          List<StorableVertex> lsv = ssg.getVertices();
          if (lsv != null && lsv.size() == 1) {
            StorableVertex sv = lsv.get(0);
            CycleSearcher.this.view.showCycles(sv);
          }
        }
      }
    });
    this.button.setEnabled(false);
  }

  // -------------------------------------------------------------------------
  public JComponent getView() {
    return (this.button);
  }
 
  public void setEnabled(boolean enable) {
    this.button.setEnabled(enable);
  }
  public void changeView(IGraphView igv) {   
    this.view = igv;
    if (view == null) {
      setEnabled(false);
    }
  }
}
TOP

Related Classes of vg.modules.backlight.components.CycleSearcher

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.