Skip to content
Snippets Groups Projects
Select Git revision
  • 97ac73ff1cc8a0b1216fb3d87637fcc9ed32ffcc
  • master default protected
  • update-goal-generator
  • add-overrides==4.1.2
  • eval-v1
  • eval-v2
  • dev
7 results

evaluate.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ResultPanel.java 5.80 KiB
    /*******************************************************************************
     * Copyright (C) 2017 Philipp Spohr
     * 
     * Permission is hereby granted, free of charge, to any person obtaining a copy
     * of this software and associated documentation files (the "Software"), to deal
     * in the Software without restriction, including without limitation the rights
     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     * copies of the Software, and to permit persons to whom the Software is
     * furnished to do so, subject to the following conditions:
     * 
     * The above copyright notice and this permission notice shall be included in
     * all copies or substantial portions of the Software.
     * 
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     * SOFTWARE.
     ******************************************************************************/
    package de.hhu.ba.yoshikoWrapper.gui;
    
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.BoxLayout;
    import javax.swing.GroupLayout;
    import javax.swing.Icon;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JTabbedPane;
    
    import org.cytoscape.application.swing.CytoPanelComponent;
    import org.cytoscape.application.swing.CytoPanelName;
    import org.cytoscape.util.swing.BasicCollapsiblePanel;
    
    import de.hhu.ba.yoshikoWrapper.core.CyCore;
    import de.hhu.ba.yoshikoWrapper.core.GraphicsLoader;
    import de.hhu.ba.yoshikoWrapper.core.LocalizationManager;
    import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoResult;
    import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoSolution;
    
    /**Swing component that contains ALL solutions that are found during one run.
     * Conforms to CY 3.5 by being a CytoPanelComponent which is the norm for "result" panels
     */
    @SuppressWarnings("serial")//Will never be serialized
    public class ResultPanel extends JPanel implements CytoPanelComponent{
    	
    	private final JTabbedPane solutionTabs;
    	private final JButton destroyButton;
    	
    	private BasicCollapsiblePanel marker;
    	
    	private final YoshikoResult result;
    		
    	public ResultPanel(YoshikoResult result) {
    				
    		this.result = result;
    				
    		//Init subcomponents
    		solutionTabs = new JTabbedPane();
    		for (YoshikoSolution s : result.solutions) {
    			addSolutionTab(s);
    		}
    
    		if (result.flags.getIlpGenerated()) {
    			System.out.println("Setting up ILP Info Marker");
    			//Optional Markers
    			marker = new BasicCollapsiblePanel(LocalizationManager.get("ilpMarker"));
    			marker.setLayout(new BoxLayout(marker,BoxLayout.Y_AXIS));
    			if(result.flags.getOptimal()) {
    				JLabel optimalLabel;
    				optimalLabel = new JLabel(LocalizationManager.get("optimal"));
    				optimalLabel.setForeground(GraphicsLoader.yoshikoGreen);
    				marker.add(optimalLabel);
    			}
    			else {
    				JLabel optimalLabel;
    				optimalLabel = new JLabel(LocalizationManager.get("notOptimal"));
    				optimalLabel.setForeground(Color.RED);
    				marker.add(optimalLabel);
    				marker.add(new JLabel(LocalizationManager.get("gap")+" "+(int)(100*result.flags.getGapSize())+"%"));
    			}
    			JLabel costLabel = new JLabel(LocalizationManager.get("cost")+" "+result.flags.getTotalCost());
    			marker.add(costLabel);
    			if (result.flags.getTimedOut()) {
    				marker.add(new JLabel(LocalizationManager.get("timeoutMarker")));
    			}
    			marker.setCollapsed(false);
    			this.add(marker);
    		}
    		
    		destroyButton = new JButton(LocalizationManager.get("discardSolution"));
    		destroyButton.addActionListener(new ActionListener() {
    
    			@Override
    			public void actionPerformed(ActionEvent e) {
    				deleteSolution();
    			}
    			
    		});
    		
    		SwingUtil.addAll(this,solutionTabs,destroyButton);
    		
    		//Layout
    		GroupLayout layout = new GroupLayout(this);
    		
    		layout.setAutoCreateGaps(true);
    		layout.setAutoCreateContainerGaps(true);
    		
    		if (result.flags.getIlpGenerated()) {
    			layout.setVerticalGroup(layout.createSequentialGroup()
    					.addComponent(marker)
    					.addComponent(solutionTabs)
    					.addComponent(destroyButton)
    				);
    					
    				layout.setHorizontalGroup(layout.createParallelGroup()
    					.addComponent(marker)
    					.addComponent(solutionTabs)
    					.addComponent(destroyButton)
    				);
    		}
    		else {
    			layout.setVerticalGroup(layout.createSequentialGroup()
    					.addComponent(solutionTabs)
    					.addComponent(destroyButton)
    				);
    					
    				layout.setHorizontalGroup(layout.createParallelGroup()
    					.addComponent(solutionTabs)
    					.addComponent(destroyButton)
    				);
    		}
    
    		this.setLayout(layout);
    	}
    	
    	public void deleteSolution() {
    		int dialogResult = JOptionPane.showConfirmDialog (
    				null,
    				LocalizationManager.get("deleteSolution"),
    				LocalizationManager.get("warning"),
    				JOptionPane.YES_NO_OPTION
    		);
    		if (dialogResult != JOptionPane.YES_OPTION) {
    			return;
    		}
    		
    		CyCore.registrar.unregisterService(this,CytoPanelComponent.class);
    		removeAll();
    		super.setVisible(false);
    	}
    	
    	private void addSolutionTab(YoshikoSolution s) {
    		SolutionTab tab = new SolutionTab(s);
    		solutionTabs.add(
    				LocalizationManager.get("solution")+" "+(s.id+1),
    				tab
    		);
    	}
    
    	@Override
    	public Component getComponent() {
    		return this;
    	}
    
    	@Override
    	public CytoPanelName getCytoPanelName() {
    		return CytoPanelName.EAST;
    	}
    
    	@Override
    	public String getTitle() {
    		return LocalizationManager.get("resultsPanelTitle");
    	}
    
    	@Override
    	public Icon getIcon() {
    		return GraphicsLoader.getSolvedLogo(16);
    	}
    
    	public YoshikoResult getResult() {
    		return result;
    	}
    
    }