Skip to content
Snippets Groups Projects
Select Git revision
  • 4b6e8dfb35cc937c50fb480ecb9f04fc92a323a5
  • master default protected
2 results

Grapher.prob

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    MainPanel.java 6.23 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.Component;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.util.Arrays;
    
    import javax.swing.BoxLayout;
    import javax.swing.GroupLayout;
    import javax.swing.GroupLayout.Alignment;
    import javax.swing.Icon;
    import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JComponent;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    
    import org.cytoscape.application.swing.CytoPanelComponent;
    import org.cytoscape.application.swing.CytoPanelName;
    import org.cytoscape.work.AbstractTask;
    import org.cytoscape.work.TaskIterator;
    
    import de.hhu.ba.yoshikoWrapper.core.AlgorithmTask;
    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.core.YoshikoLoader;
    
    /**This class describes the Swing Panel that the user interacts with in cytoscape
     *
     */
    @SuppressWarnings("serial")
    public class MainPanel extends JPanel implements CytoPanelComponent {
    
    	//SWING COMPONENTS
    	
    	private final YoshikoHeader header;
    	
    	/**
    	 * Swing is a bit special sometimes, so a panel is used to wrap the lang-switcher.
    	 * This prevents stretching of the component
    	 */
    	private final JPanel langSwitcherWrapper;
    	private final LanguageSwitcher langSwitcher;
    	private final LibraryPanel libraryPanel;
    	private final EditCostPanel ecPanel;
    	private final ReductionRulesChooser reductionRulesChooser;
    	private final OperationModePanel opModePanel;
    	
    	//OTHER
    	
    	
    	/**
    	 * Main constructor, creates a new Panel and initializes subcomponents
    	 */
    	public MainPanel() {
    				
    		//SWING INIT
    
    		
    		//Initialize Swing components
    		header = new YoshikoHeader();
    		
    		langSwitcherWrapper = new JPanel();
    		langSwitcher = new LanguageSwitcher();
    		langSwitcherWrapper.add(new JLabel(LocalizationManager.get("switchLanguage")));
    		langSwitcherWrapper.add(langSwitcher);
    		langSwitcherWrapper.setLayout(new FlowLayout());
    		
    		libraryPanel = new LibraryPanel();
    		if (!YoshikoLoader.isLibraryLoaded()) {
    			libraryPanel.setCollapsed(false);
    		}
    		
    		ecPanel = new EditCostPanel();
    		ecPanel.setCollapsed(false);
    		
    		opModePanel = new OperationModePanel();
    		
    		reductionRulesChooser = new ReductionRulesChooser();
    		
    		JButton runButton = new JButton(LocalizationManager.get("run"));
    		runButton.addActionListener(buttonListener);
    
    		
    		SwingUtil.addAll(this,
    				header,
    				langSwitcherWrapper,
    				libraryPanel,
    				ecPanel,
    				reductionRulesChooser,
    				opModePanel,
    				runButton
    				);
    	
    		
    		//Layout
    		GroupLayout layout = new GroupLayout(this);
    		
    		layout.setHorizontalGroup(layout.createParallelGroup()
    				.addComponent(header)
    				.addComponent(langSwitcherWrapper)
    				.addComponent(libraryPanel)
    				.addComponent(ecPanel)
    				.addComponent(reductionRulesChooser)
    				.addComponent(opModePanel)
    				.addComponent(runButton)
    		);
    		
    		layout.setVerticalGroup(layout.createSequentialGroup()
    				.addComponent(header)
    				.addComponent(langSwitcherWrapper)
    				.addComponent(libraryPanel)
    				.addComponent(ecPanel)
    				.addComponent(reductionRulesChooser)
    				.addComponent(opModePanel)
    				.addComponent(runButton)	
    		);
    		
    		this.setLayout(layout);
    
    		this.setVisible(true);
    	}
    
    	/**
    	 * ButtonListener for the "Run" Button
    	 * Handles calling the algorithm and fetching/passing the arguments from swing components
    	 */
    	private ActionListener buttonListener = new ActionListener() {
    
    		@Override
    		public void actionPerformed(ActionEvent e) {
    			if (YoshikoLoader.isLibraryLoaded()){
    				AbstractTask yoshiko = new AlgorithmTask(
    					CyCore.cy.getCurrentNetwork(),
    					opModePanel.getTimeLimit(),
    					ecPanel.getWeightColumn(),
    					ecPanel.getPermanentColumn(),
    					ecPanel.getForbiddenColumn(),
    					ecPanel.getDefaultInsertionCost(),
    					ecPanel.getDefaultDeletionCost(),
    					reductionRulesChooser.getBitMask(),
    					reductionRulesChooser.getMultFactor(),
    					opModePanel.useTriangleCuts(),
    					opModePanel.usePartitionCuts(), 
    					opModePanel.useHeuristic(),
    					opModePanel.getSolCount()
    				);
    				CyCore.dialogTaskManager.execute(new TaskIterator(1,yoshiko));
    			}
    			else {
    				JOptionPane.showMessageDialog(	
    					null,
    					LocalizationManager.get("noLibTitle"),
    					LocalizationManager.get("noLibMessage"),
    					JOptionPane.ERROR_MESSAGE
    				);
    			}
    		}
    	};
    	
    
    	
    	//GETTER / SETTER
    
    	public Component getComponent() {
    		return this;
    	}
    
    	/* (non-Javadoc)
    	 * @see org.cytoscape.application.swing.CytoPanelComponent#getCytoPanelName()
    	 */
    	public CytoPanelName getCytoPanelName() {
    		//By convention most plugins that provide a "toolbox"-like interface use the WEST orientation
    		return CytoPanelName.WEST;
    	}
    
    	public String getTitle() {
    		//TODO: Be creative I guess
    		return "Yoshiko";
    	}
    	
    	public ColumnMapper getColumnMapper() {
    		return ecPanel.getColumnMapper();
    	}
    	
    	public Icon getIcon() {
    		return GraphicsLoader.getLogo(16);
    	}
    
    
    }