亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? tspgui.java

?? Traveling Salesman Problem Java Genetic Algorithm Solution, Hope all enjoy it.
?? JAVA
字號:
/*
 * $Source: f:/cvs/prgm/tsp/src/org/saiko/ai/genetics/tsp/TSPGui.java,v $
 * $Id: TSPGui.java,v 1.2 2005/08/23 23:18:05 dsaiko Exp $
 * $Date: 2005/08/23 23:18:05 $
 * $Revision: 1.2 $
 * $Author: dsaiko $
 *
 * Traveling Salesman Problem genetic algorithm.
 * This source is released under GNU public licence agreement.
 * dusan@saiko.cz
 * http://www.saiko.cz/ai/tsp/
 * 
 * Change log:
 * $Log: TSPGui.java,v $
 * Revision 1.2  2005/08/23 23:18:05  dsaiko
 * Finished.
 *
 * Revision 1.1  2005/08/23 10:01:31  dsaiko
 * Gui and main program divided
 *
 * Revision 1.8  2005/08/22 22:25:11  dsaiko
 * Packages rearanged
 *
 * Revision 1.7  2005/08/22 22:13:53  dsaiko
 * Packages rearanged
 *
 * Revision 1.6  2005/08/22 22:08:51  dsaiko
 * Created engines with heuristics
 *
 * Revision 1.5  2005/08/13 15:02:49  dsaiko
 * build task
 *
 * Revision 1.4  2005/08/13 15:02:09  dsaiko
 * build task
 *
 * Revision 1.3  2005/08/13 14:41:35  dsaiko
 * *** empty log message ***
 *
 * Revision 1.2  2005/08/13 12:53:02  dsaiko
 * XML2PDF report finished
 *
 * Revision 1.1  2005/08/12 23:52:17  dsaiko
 * Initial revision created
 *
 */

package org.saiko.ai.genetics.tsp;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 * @author Dusan Saiko (dusan@saiko.cz)
 * Last change $Date: 2005/08/23 23:18:05 $
 *
 * GUI for representation of the traveling salesman problem.
 */
public class TSPGui extends JFrame {

   /** String containing the CVS revision. **/
   public final static String CVS_REVISION = "$Revision: 1.2 $";
   
   /**
    * generated serialVersionUID
    */
   protected static final long serialVersionUID =8917595268427032741L;

   /**
    * graphical window size. the window will be not resizable
    */
   protected static final Dimension windowSize      =new Dimension(785,580);

   /**
    * Menu handler class
    */
   protected TSPMenu menu;
   
   /**
    * virtual coordinates of the city maps 
    * the virtual coordinates will be translated to screen coordinates before
    * displaying
    * X0 - X minimum 
    */
   protected int virtualX0;
   /**
    * virtual coordinates of the city maps 
    * the virtual coordinates will be translated to screen coordinates before
    * displaying
    * X1 - X maximum 
    */
   protected int virtualX1;
   /**
    * virtual coordinates of the city maps 
    * the virtual coordinates will be translated to screen coordinates before
    * displaying
    * Y0 - Y minimum 
    */
   protected int virtualY0;
   /**
    * virtual coordinates of the city maps 
    * the virtual coordinates will be translated to screen coordinates before
    * displaying
    * Y1 - Y maximum 
    */
   protected int virtualY1;
   
   /**
    * JPanel for placing the map of the cities
    * This panel takes center of the display window
    */
   protected JPanel cityMap;
   
   /**
    * border of graphical window - x coordiates need border for label of city name displaying,
    * y coordinates for label and for status bar
    */
   protected int border;
   
   /**
    * scale of virtual coordinates into screen coordinates. 
    */
   protected double scale;   

   /**
    * status bar component displayed at the bottom of GUI
    */
   protected JTextField statusBar;
 
   /**
    * Bounds of client graphics space
    */
   protected Rectangle clientBounds;
   
   /**
    * Bounds of the map area (clientBounds - status ...)
    */
   protected Rectangle mapDisplayBounds;

   /**
    * Application title
    */
   protected final static String appTitle="Traveling salesman problem";

   /**
    * height of the status window
    */
   protected int statusHeight;


   /**
	 * parent application object 
	 */
	protected TSP parent;
   
   /**
    * class constructor
    * @param parent - parent application object
    */
   public TSPGui(TSP parent) {
      super();
      this.parent=parent;
   }

   
   /**
    * show the window
    */
   public void init() {
	  menu=new TSPMenu(parent);
	   
	  setIconImage(new ImageIcon(this.getClass().getResource("/org/saiko/etc/logo16.gif")).getImage());
	  setTitle(appTitle);
	      
      //window properties
      setSize(windowSize);
      setResizable(false);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      //create menu
      menu.createMenuBar();

      setVisible(true);

      //create and show the content
      putComponents();


      statusBar.setText("Ready");
      
      setVisible(true);
      
      invalidate();
      repaint(); 
   }
   

   /**
    * Places map and status bar on the window
    */
   public void putComponents() {
	  getContentPane().setBackground(Color.WHITE);
      getContentPane().setLayout(null);
      statusBar=new JTextField("Initializing ...");
      getContentPane().add(statusBar);
      clientBounds=getContentPane().getBounds();

      //compute status height from font
      statusHeight=(int)(1.5*statusBar.getFontMetrics(statusBar.getFont()).getHeight());
      
      statusBar.setBounds(
            0,
            clientBounds.height-statusHeight,
            clientBounds.width,
            statusHeight
      );
      
      //create map
      createCityMap(false);
   }

   
   /**
    * computes virtual coordinates bounds from the list of cities
    * through these virtual coordinates the recomputation into screen 
    * coordinates is made
    */
   private void computeVirtualBounds() {
      virtualX0=-1;
      virtualX1=-1;
      virtualY0=-1;
      virtualY1=-1;
      for(City city: parent.cities) {
         if(virtualX0==-1 || city.x<virtualX0) virtualX0=city.x;
         if(virtualX1==-1 || city.x>virtualX1) virtualX1=city.x;
         if(virtualY0==-1 || city.y<virtualY0) virtualY0=city.y;
         if(virtualY1==-1 || city.y>virtualY1) virtualY1=city.y;
      }

      //compute border for map according to the font height
      border=(int)(2.0*getGraphics().getFontMetrics().getHeight());
      
      //scale between virtual and screen distances
      scale=Math.min(
            (mapDisplayBounds.width-2.0*border)/(virtualX1-virtualX0),
            (mapDisplayBounds.height-2.0*border)/(virtualY1-virtualY0));
      
   }
   

   
   /**
    * transforms virtual X into screen X according to the screen dimensions and 
    * virtual bounds of the city map.
    * @param virtualX
    * @return X coordinate transormed into screen dimension
    */
   protected int transformVirtualX(int virtualX) {
      int x=(int)(border+scale*(virtualX-virtualX0));
      return x;
   }
   
   /**
    * transforms virtual Y into screen Y according to the screen dimensions and 
    * virtual bounds of the city map
    * @param virtualY
    * @return Y coordinate transormed into screen dimension
    */
   protected int transformVirtualY(int virtualY) {
      int y=(int)(border/2+scale*(virtualY-virtualY0));
      return y;
   }
   
   /**
    * creates map of cities in the form of jLabel and jTextFields components
    * @param reloadCities - should be cities reloaded ? (needed for changing the map)
    */
   protected void createCityMap(boolean reloadCities) {

      synchronized(TSP.mutex) {
         
         parent.bestChromosome=null;
         statusBar.setText("Loading ...");
         if(reloadCities) {
        	 parent.cities=null;
        	 parent.loadCities(null,true);
         }
         
         //remove cityMap panel, if already exists (selection of new map)
         if(cityMap!=null) {
            getContentPane().remove(cityMap);
         }
         cityMap=null;
         
         //create cityMap panel
         createMapPanel();
         getContentPane().add(cityMap);
         cityMap.setBounds(
               0,
               0,
               clientBounds.width,
               clientBounds.height-statusHeight
         );
         mapDisplayBounds=cityMap.getBounds();
         
         //place cities into map panel
         placeCities();
      }
      invalidate();
      repaint();
      statusBar.setText("Ready");
   }

   /**
    * Creates map panel with city and path draw functionality 
    */
   private void createMapPanel() {
      cityMap=new JPanel() {
         /** serialVersionUID  */
        private static final long serialVersionUID =4509704840522450842L;

        @Override
        public void paint(Graphics g) {
           //antialiazing feature - slows the graphics quite down
           if(parent.configuration.antialiasing) {
               Graphics2D g2 = (Graphics2D)g;
               g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                     RenderingHints.VALUE_ANTIALIAS_ON);
               g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);                 
               
           }

           //paint the components first
           //(cities)
           super.paint(g);
           
           //paint the paths from best chromosome
           if(parent.bestChromosome!=null) {
               g.setColor(Color.DARK_GRAY);
               
               //draw the paths for the best chromozone
               City bestCities[]=parent.bestChromosome.cities;
               for(int i=0; i < bestCities.length-1; i++) {
                  City city1=bestCities[i];
                  City city2=bestCities[i+1];
                  g.drawLine(
                        transformVirtualX(city1.getX()),
                        transformVirtualY(city1.getY()),
                        transformVirtualX(city2.getX()),
                        transformVirtualY(city2.getY())
                  );
               }
               //draw path back to city 0
              City city1=bestCities[bestCities.length-1];
              City city2=bestCities[0];
              g.drawLine(
                    transformVirtualX(city1.getX()),
                    transformVirtualY(city1.getY()),
                    transformVirtualX(city2.getX()),
                    transformVirtualY(city2.getY())
              );
            } //if bestChromosome!=null
         } // paint()        
     }; //new JPanel() {}
     cityMap.setOpaque(false);
     cityMap.setLayout(null); //free layout 
   }
   
   /**
    * place cities at cityMap JPanel 
    * city icon is JLabel component and city jabel is JTextField 
    */
   private void placeCities() {

      computeVirtualBounds();
      
      //place all cities
      for(int i=0; i<parent.cities.length; i++) {

         //place city icon
         JLabel cityIcon=new JLabel() {
            /** serialVersionUID */
            private static final long serialVersionUID =2395710541880785590L;

            @Override
            public void paint(Graphics g) {
               g.setColor(getBackground());
               if(parent.configuration.antialiasing) {
                  Graphics2D g2 = (Graphics2D)g;
                  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                     RenderingHints.VALUE_ANTIALIAS_ON);
                  g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);                 
                  
               }
               if(getText()==null || getText().length()==0) {
                  g.fillOval(0,0,4,4);
               } else {
                  g.fillRect(0,0,5,5);
               }
            }
         };
         
         //set the color for city
         Color color=Color.decode("0x00aa00");
         if(parent.cities[i].startCity) {
            color=Color.decode("0xff0000");
            //helper - set some text for icon on the first city
            cityIcon.setText("FIRST"); 
         }
         cityIcon.setBackground(color);
         
         //cityIcon.setBackground(color);
         cityIcon.setBounds(transformVirtualX(parent.cities[i].getX())-2,transformVirtualY(parent.cities[i].getY())-2,5,5);
         cityMap.add(cityIcon);

         //place label and center it
         //if name is not empty
         if(parent.cities[i].getName()!=null && parent.cities[i].getName().trim().length()>0) {
	         JTextField nameLabel=new JTextField(parent.cities[i].getName()) {
	            /** serialVersionUID **/
	            private static final long serialVersionUID =-1495233060258473325L;
	
	            @Override
	            public void paintComponent(Graphics g) {
	               if(parent.configuration.antialiasing) {
	                  Graphics2D g2 = (Graphics2D)g;
	                  g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
	                                      RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
	                  g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);                 
	                  
	               }
	               super.paintComponent(g);
	             }
	         };
	         nameLabel.setEditable(false);
	         Font font=new Font("Sans",Font.BOLD,9);
	         nameLabel.setFont(font);
	         nameLabel.setBorder(null);
	         nameLabel.setBackground(null);
	         nameLabel.setOpaque(false);
	         nameLabel.setForeground(Color.LIGHT_GRAY);
	        
	         //center the label position
	         Rectangle2D fm=font.getStringBounds(parent.cities[i].getName(),new FontRenderContext( this.getGraphicsConfiguration().getDefaultTransform(),false,true));
	         nameLabel.setBounds(
	               transformVirtualX(parent.cities[i].getX())-(int)fm.getWidth()/2,
	               transformVirtualY(parent.cities[i].getY()),
	               (int)(fm.getWidth()*1.1),
	               (int)(fm.getHeight()*1.05));
	         cityMap.add(nameLabel);
         } //if name is not empty
      }      
   }
   
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
首页综合国产亚洲丝袜| 99天天综合性| av不卡在线观看| 欧美日韩另类一区| 中文字幕在线一区二区三区| 青椒成人免费视频| 91蜜桃网址入口| 国产欧美日韩久久| 久久激情五月激情| 欧美性欧美巨大黑白大战| 亚洲国产电影在线观看| 捆绑紧缚一区二区三区视频| 精品视频999| 日韩伦理电影网| 国产成人精品亚洲777人妖 | 夜夜夜精品看看| 成人免费av在线| 久久综合av免费| 蜜桃精品在线观看| 欧美精品久久久久久久久老牛影院| 国产精品丝袜91| 国产成人午夜高潮毛片| 久久免费视频一区| 精品一区二区三区免费视频| 日韩一区二区三| 人人狠狠综合久久亚洲| 欧美日韩免费一区二区三区| 亚洲精品国产第一综合99久久| www.66久久| 中文字幕一区二区三区在线不卡 | 精品日韩在线观看| 日本在线不卡视频一二三区| 欧美日韩一区中文字幕| 亚洲午夜成aⅴ人片| 在线观看精品一区| 亚洲午夜免费福利视频| 欧美日韩精品专区| 石原莉奈在线亚洲三区| 日韩三级高清在线| 青青草国产成人av片免费| 欧美一区二区高清| 久久99久久精品| 久久久久久久久久久黄色| 国产成人av网站| 中文字幕欧美一区| 在线精品视频免费观看| 婷婷开心激情综合| 精品国产区一区| 福利电影一区二区三区| 亚洲欧洲国产日本综合| 色婷婷激情一区二区三区| 亚洲福利国产精品| 精品国产伦一区二区三区免费| 国产一区二区三区免费看 | 狠狠网亚洲精品| 久久精品在线免费观看| 99精品视频在线观看免费| 亚洲一区二区免费视频| 欧美va亚洲va| 不卡av在线网| 日韩中文欧美在线| 国产女同互慰高潮91漫画| 91同城在线观看| 喷水一区二区三区| 国产精品美女一区二区在线观看| 一本到三区不卡视频| 日本成人中文字幕| 136国产福利精品导航| 在线播放日韩导航| 不卡一二三区首页| 日韩av电影天堂| 一区在线观看免费| 日韩亚洲欧美一区| 91麻豆福利精品推荐| 另类综合日韩欧美亚洲| 最新国产精品久久精品| 日韩一二三四区| 色婷婷久久一区二区三区麻豆| 精品在线你懂的| 亚洲综合在线电影| 欧美国产欧美综合| 日韩丝袜美女视频| 欧美在线不卡视频| 国产成人在线观看| 日本 国产 欧美色综合| 亚洲日韩欧美一区二区在线| 欧美tk—视频vk| 欧美老年两性高潮| 91免费看视频| 高清不卡在线观看av| 日本va欧美va瓶| 亚洲夂夂婷婷色拍ww47| 一区二区三区产品免费精品久久75 | 成人免费高清在线观看| 天堂资源在线中文精品| 亚洲欧美日韩一区| 亚洲国产精品激情在线观看| 日韩欧美亚洲另类制服综合在线| 欧洲另类一二三四区| 99视频精品全部免费在线| 国产精品资源在线看| 理论电影国产精品| 日本不卡1234视频| 日本午夜一区二区| 丝袜美腿亚洲综合| 香蕉成人伊视频在线观看| 亚洲午夜影视影院在线观看| 亚洲人精品一区| 国产精品不卡视频| 中文字幕一区二区三区av| 欧美高清一级片在线观看| 国产农村妇女精品| 欧美国产精品劲爆| 国产精品久久久久久久久免费丝袜 | 亚洲福利电影网| 亚洲制服丝袜一区| 亚洲电影视频在线| 午夜久久福利影院| 日韩电影在线免费看| 日本免费在线视频不卡一不卡二| 香蕉久久夜色精品国产使用方法 | 综合激情成人伊人| 1024亚洲合集| 亚洲成人午夜电影| 天堂影院一区二区| 另类调教123区| 国产黑丝在线一区二区三区| 国产精品影视网| 国产福利一区二区| 91香蕉视频mp4| 欧美日韩在线直播| 日韩欧美美女一区二区三区| 久久婷婷国产综合国色天香 | 亚洲激情六月丁香| 亚洲第一av色| 久久精品99久久久| a在线欧美一区| 精品视频色一区| 精品国产凹凸成av人导航| 亚洲国产精品自拍| 美女视频黄 久久| 成人丝袜18视频在线观看| 97aⅴ精品视频一二三区| 欧美日本国产一区| 久久久久青草大香线综合精品| 国产精品久久久久久久岛一牛影视 | 精品国产一区二区三区久久久蜜月| 久久久久综合网| 亚洲一区二区在线播放相泽| 麻豆免费看一区二区三区| www.日韩在线| 欧美一区二区三区四区在线观看| 国产欧美日韩在线| 日韩精品视频网| 成人午夜免费电影| 欧美日韩国产综合视频在线观看| 久久久久久久性| 丝袜亚洲精品中文字幕一区| 成人免费观看男女羞羞视频| 欧美电影一区二区| 国产精品萝li| 麻豆一区二区三区| 欧美中文字幕不卡| 中文子幕无线码一区tr| 亚洲va国产天堂va久久en| 国产91丝袜在线观看| 91精品午夜视频| 亚洲人一二三区| 国产伦精品一区二区三区在线观看 | 亚洲制服丝袜一区| 国产jizzjizz一区二区| 欧美一级二级三级蜜桃| 亚洲三级在线播放| 懂色av中文一区二区三区| 91精品国产一区二区| 亚洲精品国产一区二区精华液 | 亚洲中国最大av网站| 粉嫩嫩av羞羞动漫久久久 | 欧美精品国产精品| 亚洲同性同志一二三专区| 国产一区二区三区香蕉| 欧美一区二区视频在线观看| 亚洲一二三四在线观看| 94色蜜桃网一区二区三区| 国产三级欧美三级日产三级99 | av一本久道久久综合久久鬼色| 日韩免费一区二区| 爽爽淫人综合网网站| 欧美视频在线观看一区| 亚洲精品免费视频| 99久久免费精品| 国产精品二三区| 成人99免费视频| 国产精品久久久久婷婷二区次| 国产精品亚洲综合一区在线观看| 欧美一级片在线看| 久久精品国产秦先生| 日韩欧美一区二区视频| 丝袜亚洲另类欧美| 91精品国产乱码久久蜜臀|