⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guimanager.java

📁 一个开源的用java开发的遗传算法的封装好的工程
💻 JAVA
字号:
/*
 * This file is part of JGAP.
 *
 * JGAP offers a dual license model containing the LGPL as well as the MPL.
 *
 * For licencing information please see the file license.txt included with JGAP
 * or have a look at the top of class org.jgap.Chromosome which representatively
 * includes the JGAP license policy applicable for any file delivered with JGAP.
 */
package org.jgap.gui;

import java.util.*;

import javax.swing.*;

import org.jgap.*;
import org.jgap.data.config.*;

/**
 * Singleton GUIManager for the JGAP Configurator.
 * Creates a ConfigFrame on request, for a Configurable. Currently it only
 * creates a ConfigFrame for the root object, that is a Configuration itself.
 * In the future it will do the same for objects on the Root ConfigFrame that
 * are in turn Configurable.
 *
 * @author Siddhartha Azad
 * @author Klaus Meffert
 * @since 2.3
 */
public class GUIManager {
  /** String containing the CVS revision. Read out via reflection!*/
  private final static String CVS_REVISION = "$Revision: 1.10 $";

  // The root frame
  private ConfigFrame m_frame;

  // the children frames
  private List m_childFrames;

  // children configurables, one to one mapping with childFrames
  private List m_childCons;

  // The entity to configure
  private Configurable m_con;

  /**
   * Singleton instance of GUIManager
   */
  private static GUIManager m_gm;

  /**
   * @return a singleton GUIManager instance
   *
   * @author Siddhartha Azad
   * @since 2.3
   */
  public static GUIManager getInstance() {
    if (m_gm == null) {
      m_gm = new GUIManager();
    }
    return m_gm;
  }

  /**
   * Constructor for the frame.
   *
   * @author Siddhartha Azad
   * @since 2.3
   */
  private GUIManager() {
    m_frame = null;
    m_childFrames = Collections.synchronizedList(new ArrayList());
    m_childCons = Collections.synchronizedList(new ArrayList());
  }

  /**
   * Create and show a new frame for a Configurable.
   * @param a_con configurable to use
   *
   * @author Siddhartha Azad
   * @since 2.3
   */
  public void showFrame(final ConfigFrame a_parent, final Configurable a_con)
      throws Exception {
    try {
      // TODO add edit-components for configurable properties

      // create the frame
      if (a_con.getClass() == Configuration.class) {
        m_frame = new ConfigFrame(null, "JGAP Configurator: "
                                  + "Configuration",
                                  true);
        m_con = a_con;
        m_frame.createAndShowGUI(a_con);
      }
      else {
        ConfigFrame tmpFrame =
            new ConfigFrame(a_parent, "JGAP Configurator: "
                            + "Unknown Title",
                            false);
        m_childCons.add(a_con);
        m_childFrames.add(tmpFrame);
        tmpFrame.createAndShowGUI(a_con);
      }
    }
    catch (Exception ex) {
      JOptionPane.showMessageDialog(null,
                                    "Could not show configuration frame. This"
                                    + " attribute may not be configurable.",
                                    "Configuration Error",
                                    JOptionPane.INFORMATION_MESSAGE);
    }
  }

  /**
   * Main method for the GUI
   * @param args not used
   * @throws Exception
   *
   * @author Siddhartha Azad
   * @since 2.3
   */
  public static void main(String[] args) {
    try {
      SwingUtilities.invokeLater(new Runnable() {
        public void run() {
          Configuration con = new Configuration();
          // parent is null for the root frame
          try {
            GUIManager.getInstance().showFrame(null, con);
          }
          catch (Exception ex) {
          }
        }
      });
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -