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

Aggregated action listeners for rendering

parent 00305791
Loading
Loading
Loading
Loading
+11 −33
Original line number Diff line number Diff line
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.fidentis.analyst.gui.core;

import java.awt.BorderLayout;
import javax.swing.JPanel;
import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
@@ -14,6 +11,7 @@ import org.openide.util.NbBundle.Messages;
/**
 * Top component which displays something.
 */
/*
@ConvertAsProperties(
        dtd = "-//cz.fidentis.analyst.gui.core//ControlPanel//EN",
        autostore = false
@@ -25,7 +23,7 @@ import org.openide.util.NbBundle.Messages;
)
@TopComponent.Registration(mode = "properties", openAtStartup = true)
@ActionID(category = "Window", id = "cz.fidentis.analyst.gui.core.ControlPanelTC")
@ActionReference(path = "Menu/Window" /*, position = 333 */)
@ActionReference(path = "Menu/Window")
@TopComponent.OpenActionRegistration(
        displayName = "#CTL_ControlPanelAction",
        preferredID = "ControlPanelTopComponent"
@@ -35,13 +33,14 @@ import org.openide.util.NbBundle.Messages;
    "CTL_ControlPanelTopComponent=Control Panel",
    "HINT_ControlPanelTopComponent=This is a ControlPanel window"
})
public final class ControlPanelTC extends TopComponent {
*/
public final class ControlPanelTC extends JPanel {

    public ControlPanelTC() {
        initComponents();
        setName(Bundle.CTL_ControlPanelTopComponent());
        setToolTipText(Bundle.HINT_ControlPanelTopComponent());

        setLayout(new BorderLayout());
        //initComponents();
        //setName(Bundle.CTL_ControlPanelTopComponent());
        //setToolTipText(Bundle.HINT_ControlPanelTopComponent());
    }
    
    /**
@@ -66,25 +65,4 @@ public final class ControlPanelTC extends TopComponent {

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
    @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
    }
}
+0 −36
Original line number Diff line number Diff line
package cz.fidentis.analyst.gui.rndtoolbar;

import cz.fidentis.analyst.gui.canvas.Canvas;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JToggleButton;

/**
 * Switches between bark and blight background of the scene.
 * 
 * @author Radek Oslejsek
 */
public class BackgroundAction extends AbstractAction {
    
    private final Canvas canvas;
    
    /**
     * Constructor.
     * @param canvas OpenGL canvas
     */
    public BackgroundAction(Canvas canvas) {
        this.canvas = canvas;
    }
    
    @Override
    public void actionPerformed(ActionEvent e) {
        JToggleButton button = (JToggleButton) e.getSource();
        if (button.isSelected()) {
            canvas.getSceneRenderer().setBrightBackground();
        } else {
            canvas.getSceneRenderer().setDarkBackground();
        }
        canvas.renderScene();
    }
    
}
+0 −34
Original line number Diff line number Diff line
package cz.fidentis.analyst.gui.rndtoolbar;

import com.jogamp.opengl.GL2;
import cz.fidentis.analyst.gui.canvas.Canvas;
import cz.fidentis.analyst.gui.scene.DrawableMesh;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;

/**
 * Turns on the rending mode that draws triangle vertices only.
 * 
 * @author Radek Oslejsek
 */
public class PointCloudRenderingAction extends AbstractAction   {

    private final Canvas canvas;

    /**
     * Constructor.
     * @param canvas OpenGL canvas
     */
    public PointCloudRenderingAction(Canvas canvas) {
        this.canvas = canvas;
    }
    
    @Override
    public void actionPerformed(ActionEvent e) {
        for (DrawableMesh dm: canvas.getScene().getDrawables()) {
            dm.setRenderMode(GL2.GL_POINT);
        }
        canvas.renderScene();
    }
    
}
+0 −40
Original line number Diff line number Diff line
package cz.fidentis.analyst.gui.rndtoolbar;

import cz.fidentis.analyst.gui.canvas.Canvas;
import static cz.fidentis.analyst.gui.rndtoolbar.RenderingToolBar.REFLECTIONS_COLOR;
import cz.fidentis.analyst.gui.scene.DrawableMesh;
import java.awt.Color;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JToggleButton;

/**
 * Switches on/off surface reflections.
 * 
 * @author Radek Oslejsek
 */
public class ReflectionsAction extends AbstractAction {
    
    private final Canvas canvas;
    
    /**
     * Constructor.
     * @param canvas OpenGL canvas
     */
    public ReflectionsAction(Canvas canvas) {
        this.canvas = canvas;
    }
    
    @Override
    public void actionPerformed(ActionEvent e) {
        JToggleButton button = (JToggleButton) e.getSource();
        for (DrawableMesh dm: canvas.getScene().getDrawables()) {
            if (button.isSelected()) {
                dm.setHighlights(REFLECTIONS_COLOR);
            } else {
                dm.setHighlights(Color.BLACK);
            }
        }
        canvas.renderScene();
    }
}
+77 −0
Original line number Diff line number Diff line
package cz.fidentis.analyst.gui.rndtoolbar;

import com.jogamp.opengl.GL2;
import cz.fidentis.analyst.gui.canvas.Canvas;
import static cz.fidentis.analyst.gui.rndtoolbar.RenderingToolBar.REFLECTIONS_COLOR;
import cz.fidentis.analyst.gui.scene.DrawableMesh;
import java.awt.Color;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JToggleButton;

/**
 * Action listener form OpenGL canvas rendering modes.
 * 
 * @author Radek Oslejsek
 */
public class RenderingModeAction extends AbstractAction {
    
    public static final String ACTION_COMMAND_SMOOTH_MODE = "smooth";
    public static final String ACTION_COMMAND_WIREFRAME_MODE = "wireframe";
    public static final String ACTION_COMMAND_POINT_CLOUD_MODE = "point cloud";
    public static final String ACTION_COMMAND_BACKGROUND_CHANGE = "background";
    public static final String ACTION_COMMAND_REFLECTIONS_ON_OFF = "reflections";
    
    
    private final Canvas canvas;
    
    /**
     * Constructor.
     * @param canvas OpenGL canvas
     */
    public RenderingModeAction(Canvas canvas) {
        this.canvas = canvas;
    }
    
    @Override
    public void actionPerformed(ActionEvent ae) {
        String action = ae.getActionCommand();
        switch (action) {
            case ACTION_COMMAND_SMOOTH_MODE:
                for (DrawableMesh dm: canvas.getScene().getDrawables()) {
                   dm.setRenderMode(GL2.GL_FILL);
                }
                break;
            case ACTION_COMMAND_WIREFRAME_MODE:
                for (DrawableMesh dm: canvas.getScene().getDrawables()) {
                   dm.setRenderMode(GL2.GL_LINE);
                }
                break;
            case ACTION_COMMAND_POINT_CLOUD_MODE:
                for (DrawableMesh dm: canvas.getScene().getDrawables()) {
                   dm.setRenderMode(GL2.GL_POINT);
                }
                break;
            case ACTION_COMMAND_BACKGROUND_CHANGE:
                JToggleButton button1 = (JToggleButton) ae.getSource();
                if (button1.isSelected()) {
                    canvas.getSceneRenderer().setBrightBackground();
                } else {
                    canvas.getSceneRenderer().setDarkBackground();
                }
                break;
            case ACTION_COMMAND_REFLECTIONS_ON_OFF:
                JToggleButton button2 = (JToggleButton) ae.getSource();
                for (DrawableMesh dm: canvas.getScene().getDrawables()) {
                    if (button2.isSelected()) {
                        dm.setHighlights(REFLECTIONS_COLOR);
                    } else {
                        dm.setHighlights(Color.BLACK);
                    }
                }
                break;
        }
        canvas.renderScene();
    }
    
}
Loading