Commit d3b64386 authored by Radek Ošlejšek's avatar Radek Ošlejšek
Browse files

Refactored RegistrationPanel

parent da5bea19
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -83,7 +83,8 @@ public class Canvas extends javax.swing.JPanel {
    /**
     * Initializes the scene for the 1:1 comparison. Can be called only once.
     * 
     * @param face Human face
     * @param primary Primary face
     * @param secondary Secondary face
     * @throws UnsupportedOperationException the the scene is already initiated
     * @throws IllegalArgumentException if some face is missing
     */
+18 −0
Original line number Diff line number Diff line
package cz.fidentis.analyst.core;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

/**
 * An abstract class for control panels that can be docked in the {@link TopControlPanel}.
 * 
 * @author Radek Oslejsek
 */
public abstract class ControlPanel extends JPanel {
    
    /**
     * Returns panel's icon.
     * @return panel's icon
     */
    public abstract ImageIcon getIcon();
}
+89 −0
Original line number Diff line number Diff line
package cz.fidentis.analyst.core;

import cz.fidentis.analyst.canvas.Canvas;
import cz.fidentis.analyst.scene.DrawableFace;
import cz.fidentis.analyst.scene.Scene;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JTabbedPane;
import javax.swing.JToggleButton;

/**
 * Default action listener used to connect specific control panel with the rest of
 * the analytical tab, i.e. canvas and toolbar(s)
 * 
 * @author Radek Oslejsek
 */
public abstract class ControlPanelAction extends AbstractAction {
    
    /*
     * Handled actions
     */
    public static final String ACTION_COMMAND_SHOW_HIDE_PANEL = "show-hide control panel";
    
    /*
     * Top component - the space delimited for placing control panels
     */
    private final JTabbedPane topControlPanel;
    
    /**
     * Canvas component
     */
    private final Canvas canvas;
    
    /**
     * Constructor. 
     * 
     * @param canvas OpenGL canvas
     * @param topControlPanel Top component for placing control panels
     * @throws IllegalArgumentException if some param is missing
     */
    public ControlPanelAction(Canvas canvas, JTabbedPane topControlPanel) {
        if (canvas == null) {
            throw new IllegalArgumentException("canvas");
        }
        if (topControlPanel == null) {
            throw new IllegalArgumentException("topControlPanel");
        }
        this.canvas = canvas;
        this.topControlPanel = topControlPanel;
    }
    
    @Override
    public abstract void actionPerformed(ActionEvent ae);
    
    protected Canvas getCanvas() {
        return canvas;
    }
    
    /**
     * The generic code for showing/hiding the control panel
     * 
     * @param ae Action event
     */
    protected void hideShowPanelActionPerformed(ActionEvent ae, ControlPanel controlPanel) {
        if (((JToggleButton) ae.getSource()).isSelected()) {
            topControlPanel.addTab(controlPanel.getName(), controlPanel.getIcon(), controlPanel);
            topControlPanel.setSelectedComponent(controlPanel); // focus
        } else {
            topControlPanel.remove(controlPanel);
        }
    }
    
    protected Scene getScene() {
        return canvas.getScene();
    }
    
    protected DrawableFace getPrimaryDrawableFace() {
        return (canvas.getScene() != null) ? canvas.getScene().getDrawableFace(0) : null;
    }
    
    protected DrawableFace getSecondaryDrawableFace() {
        return (canvas.getScene() != null) ? canvas.getScene().getDrawableFace(1) : null;
    }
    
    protected void renderScene() {
        canvas.renderScene();
    }
    
}
+9 −31
Original line number Diff line number Diff line
package cz.fidentis.analyst.core;

import cz.fidentis.analyst.canvas.Canvas;
import cz.fidentis.analyst.face.HumanFace;
import cz.fidentis.analyst.toolbar.FaceToFaceToolBar;
import cz.fidentis.analyst.toolbar.RenderingToolBar;
import javax.swing.GroupLayout;
import javax.swing.LayoutStyle;
import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.windows.TopComponent;

/**
 * The non-singleton window/tab for the analysis of two faces.
 * For the discussion on crating non-singleton top component, 
 * see {@link http://netbeans.apache.org/wiki/DevFaqNonSingletonTopComponents.asciidoc}.
 *
 * @author Radek Oslejsek
 */
@ConvertAsProperties(
        dtd = "-//cz.fidentis.analyst.gui.tab//FaceToFaceTab//EN",
        autostore = false
)
public class FaceToFaceTab extends TopComponent {
    
    public static final int CONTROL_PANEL_WIDTH = 600;
    
    private final Canvas canvas = new Canvas();
    private final Canvas canvas ;
    private final FaceToFaceToolBar renderingToolBar;
    private final TopControlPanel controlPanel;

    /**
     * Constructor.
     * @param primary Primary face
     * @param secondary Secondary face
     * @param name Tab name
     */
    public FaceToFaceTab() {
    public FaceToFaceTab(HumanFace primary, HumanFace secondary, String name) {
        controlPanel = new TopControlPanel();
        canvas = new Canvas();
        renderingToolBar = new FaceToFaceToolBar(canvas, controlPanel);
        canvas.initScene(primary, secondary);
        setName(name);
        initComponents();
    }
    
@@ -65,28 +65,6 @@ public class FaceToFaceTab extends TopComponent {
        );
    }

    @Override
    public void componentOpened() {
        // TODO add custom code on component opening
    }

    @Override
    public void componentClosed() {
        // TODO add custom code on component closing
    }

    void writeProperties(java.util.Properties p) {
        // better to version settings since initial version as advocated at
        // http://wiki.apidesign.org/wiki/PropertyFiles
        p.setProperty("version", "1.0");
        // TODO store your settings
    }

    void readProperties(java.util.Properties p) {
        String version = p.getProperty("version");
        // TODO read your settings according to their version
    }
    
    public Canvas getCanvas() {
        return canvas;
    }
+2 −6
Original line number Diff line number Diff line
@@ -347,18 +347,14 @@ public final class ProjectTopComp extends TopComponent {
    }
    
    private void createSingleFaceTab(HumanFace face, String name) {
        SingleFaceTab newTab = new SingleFaceTab();
        newTab.setName(name);
        newTab.getCanvas().initScene(face);
        SingleFaceTab newTab = new SingleFaceTab(face, name);
        this.singleFaceTabs.put(face, newTab);
        newTab.open();
        newTab.requestActive();
    }

    private void createFaceToFaceTab(HumanFace face1, HumanFace face2, String name) {
        FaceToFaceTab newTab = new FaceToFaceTab();
        newTab.setName(name);
        newTab.getCanvas().initScene(face1, face2);
        FaceToFaceTab newTab = new FaceToFaceTab(face1, face2, name);
        this.faceToFaceTabs.put(face1, newTab);
        this.faceToFaceTabs.put(face2, newTab);
        newTab.open();
Loading