Skip to content
Snippets Groups Projects
Commit d37a57e1 authored by Radek Ošlejšek's avatar Radek Ošlejšek
Browse files

Refactored major classes

parent 5a5a9176
No related branches found
No related tags found
No related merge requests found
Showing
with 1321 additions and 22 deletions
......@@ -202,6 +202,7 @@ public class GeneralGLEventListener implements GLEventListener {
*/
@Override
public void init(GLAutoDrawable glad) {
System.out.println("OLD GeneralGLEventListener.init");
this.gl = (GL2) glad.getGL();
glu = new GLU();
......
......@@ -5,8 +5,6 @@
*/
package cz.fidentis.analyst.gui;
import static cz.fidentis.analyst.gui.UserInterface.frameMain;
import java.awt.Color;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
......@@ -28,7 +26,7 @@ public class Installer extends ModuleInstall {
}
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(UserInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(Installer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(() -> {
//old JFrame, disabled
......
......@@ -10,11 +10,41 @@ import javax.vecmath.Vector3d;
*/
public class Camera {
public static final Vector3d DEFAULT_POSITION = new Vector3d(0, 0, 300);
private final Vector3d center = new Vector3d(0, 0, 0);
private final Vector3d defaultPosition = new Vector3d(0, 0, 300);
private final Vector3d currentPosition = new Vector3d(0, 0, 300);
private final Vector3d upDirection = new Vector3d(0, 1, 0);
/**
* Sets model to the initial position and orientation
*/
public void initLocation() {
this.upDirection.set(0, 1, 0);
this.currentPosition.set(this.DEFAULT_POSITION);
this.center.set(0, 0, 0);
}
/**
* Changes the camera position
* @param pos new position
*/
/*
public void setPosition(Vector3d pos) {
currentPosition.set(pos);
}
*/
/**
* Sets default camera position
*/
/*
public void setDefaultPosition() {
currentPosition.set(Camera.DEFAULT_POSITION);
}
*/
/**
* Returns center of the scene.
*
......@@ -169,15 +199,6 @@ public class Camera {
return new Vector3d(x, y, z);
}
/**
* Sets model to the initial position
*/
public void rotationAndSizeRestart() {
this.upDirection.set(0, 1, 0);
this.currentPosition.set(this.defaultPosition);
this.center.set(0, 0, 0);
}
/**
* Zooms in.
*
......
......@@ -15,13 +15,13 @@ import javax.vecmath.Vector3d;
import javax.vecmath.Vector4f;
/**
* An object responsible for handling GL context of the scene regardless of
* its content.
* An object responsible for handling {@link Drawable}s included in the scene
* (in the OpenGL context of the OpenGL canvas) and their rendering.
*
* @author Natalia Bebjakova
* @author Radek Oslejsek
*/
public class SceneRenderer {
public class Scene {
private static final Vector4f BRIGHT_BACKGROUND = new Vector4f(0.9f, 0.9f, 0.9f, 0);
private static final Vector4f DARK_BACKGROUND = new Vector4f(0.25f, 0.25f, 0.25f, 0);
......@@ -34,13 +34,21 @@ public class SceneRenderer {
private List<Drawable> drawables = new ArrayList<>();
private final Camera camera = new Camera();
public void addDrawale(Drawable dr) {
if (dr != null) {
drawables.add(dr);
}
}
/**
* Constructor.
*
* @param gl OpenGL context of drawable objects
* @throws IllegalArgumentException if the {@code gl} is null
*/
public SceneRenderer(GL2 gl) {
public void initSceneGLContext(GL2 gl) {
if (gl == null) {
throw new IllegalArgumentException("gl is null");
}
......@@ -107,7 +115,7 @@ public class SceneRenderer {
/**
* Clears the scene and prepares it for the re-drawing.
*/
public void clearScene() { // SPOJIT S redenrScene() ???
public void clearScene() { // join with the renderScene() ???
if (brightBackground) {
gl.glClearColor(BRIGHT_BACKGROUND.x, BRIGHT_BACKGROUND.y, BRIGHT_BACKGROUND.z, BRIGHT_BACKGROUND.w);
} else {
......@@ -118,11 +126,9 @@ public class SceneRenderer {
}
/**
* Renders drawable.
*
* @param camera Camera
* Renders drawable objects.
*/
public void renderScene(Camera camera) {
public void renderScene() {
// sets model to proper position
Vector3d currentPosition = camera.getPosition();
Vector3d center = camera.getCenter();
......@@ -151,6 +157,10 @@ public class SceneRenderer {
gl.glFlush();
}
public Camera getCamera() {
return camera;
}
/**
* Sets the wire-frame rendering mode
*/
......
package cz.fidentis.analyst.newgui.swing;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLEventListener;
/**
*
* @author oslejsek
*/
public class CanvasListener implements GLEventListener {
private CanvasPanel canvas;
/**
* Constructor.
*
* @param canvas Canvas
* @throws IllegalArgumentException if the canvas is {@code null}
*/
public CanvasListener(CanvasPanel canvas) {
if (canvas == null) {
throw new IllegalArgumentException("canvas is null");
}
this.canvas = canvas;
}
@Override
public void init(GLAutoDrawable glad) {
canvas.getScene().initSceneGLContext(glad.getGL().getGL2());
}
@Override
public void dispose(GLAutoDrawable glad) {
}
@Override
public void display(GLAutoDrawable glad) {
canvas.getScene().clearScene();
canvas.getScene().renderScene();
}
@Override
public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) {
System.out.println("CanvasListener.reshape");
canvas.getScene().setViewport(x, y, width, height);
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.9" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="0" green="0" red="0" type="rgb"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,93,0,0,1,-79"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
<SubComponents>
<Container class="javax.swing.JLayeredPane" name="jLayeredPane1">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="28" green="28" red="28" type="rgb"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value=""/>
<Property name="opaque" type="boolean" value="true"/>
</Properties>
<Events>
<EventHandler event="componentResized" listener="java.awt.event.ComponentListener" parameters="java.awt.event.ComponentEvent" handler="jLayeredPane1ComponentResized"/>
<EventHandler event="componentShown" listener="java.awt.event.ComponentListener" parameters="java.awt.event.ComponentEvent" handler="jLayeredPane1ComponentShown"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
<BorderConstraints direction="Center"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
<Property name="useNullLayout" type="boolean" value="true"/>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="resetButton">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/resetButton.png"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="Reset position of model"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Hand Cursor"/>
</Property>
</Properties>
<Events>
<EventHandler event="mouseMoved" listener="java.awt.event.MouseMotionListener" parameters="java.awt.event.MouseEvent" handler="resetButtonMouseMoved"/>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="resetButtonMouseClicked"/>
<EventHandler event="mouseExited" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="resetButtonMouseExited"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="60" y="40" width="30" height="30"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JButton" name="upNavigationButton">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/upButton.png"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="Rotate up"/>
<Property name="borderPainted" type="boolean" value="false"/>
<Property name="contentAreaFilled" type="boolean" value="false"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Hand Cursor"/>
</Property>
</Properties>
<Events>
<EventHandler event="mousePressed" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="upNavigationButtonMousePressed"/>
<EventHandler event="mouseReleased" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="upNavigationButtonMouseReleased"/>
</Events>
<AuxValues>
<AuxValue name="JLayeredPane.layer" type="java.lang.Integer" value="200"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="60" y="10" width="30" height="30"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JButton" name="leftNavigationButton">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/leftButton.png"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="Rotate left"/>
<Property name="borderPainted" type="boolean" value="false"/>
<Property name="contentAreaFilled" type="boolean" value="false"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Hand Cursor"/>
</Property>
</Properties>
<Events>
<EventHandler event="mousePressed" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="leftNavigationButtonMousePressed"/>
<EventHandler event="mouseReleased" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="leftNavigationButtonMouseReleased"/>
</Events>
<AuxValues>
<AuxValue name="JLayeredPane.layer" type="java.lang.Integer" value="200"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="30" y="40" width="30" height="30"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JButton" name="minusNavigationButton">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/minus.png"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="Zoom out"/>
<Property name="borderPainted" type="boolean" value="false"/>
<Property name="contentAreaFilled" type="boolean" value="false"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Hand Cursor"/>
</Property>
</Properties>
<Events>
<EventHandler event="mousePressed" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="minusNavigationButtonMousePressed"/>
<EventHandler event="mouseReleased" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="minusNavigationButtonMouseReleased"/>
</Events>
<AuxValues>
<AuxValue name="JLayeredPane.layer" type="java.lang.Integer" value="200"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="90" y="90" width="30" height="30"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JButton" name="downNavigationButton">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/downButton.png"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="Rotate down"/>
<Property name="borderPainted" type="boolean" value="false"/>
<Property name="contentAreaFilled" type="boolean" value="false"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Hand Cursor"/>
</Property>
</Properties>
<Events>
<EventHandler event="mousePressed" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="downNavigationButtonMousePressed"/>
<EventHandler event="mouseReleased" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="downNavigationButtonMouseReleased"/>
</Events>
<AuxValues>
<AuxValue name="JLayeredPane.layer" type="java.lang.Integer" value="200"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="60" y="70" width="30" height="30"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JButton" name="plusNavigationButton">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/plus.png"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="Zoom in"/>
<Property name="borderPainted" type="boolean" value="false"/>
<Property name="contentAreaFilled" type="boolean" value="false"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Hand Cursor"/>
</Property>
</Properties>
<Events>
<EventHandler event="mousePressed" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="plusNavigationButtonMousePressed"/>
<EventHandler event="mouseReleased" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="plusNavigationButtonMouseReleased"/>
</Events>
<AuxValues>
<AuxValue name="JLayeredPane.layer" type="java.lang.Integer" value="200"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="30" y="90" width="30" height="30"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/navigBackground.png"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="30" y="10" width="90" height="90"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="loadModelButton">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/loadCanva.png"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value=""/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Hand Cursor"/>
</Property>
</Properties>
<Events>
<EventHandler event="mouseMoved" listener="java.awt.event.MouseMotionListener" parameters="java.awt.event.MouseEvent" handler="loadModelButtonMouseMoved"/>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="loadModelButtonMouseClicked"/>
<EventHandler event="mouseExited" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="loadModelButtonMouseExited"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="200" y="100" width="210" height="220"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JButton" name="rightNavigationButton1">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/rightButton.png"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="Rotate right"/>
<Property name="borderPainted" type="boolean" value="false"/>
<Property name="contentAreaFilled" type="boolean" value="false"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Hand Cursor"/>
</Property>
</Properties>
<Events>
<EventHandler event="mousePressed" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="rightNavigationButton1MousePressed"/>
<EventHandler event="mouseReleased" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="rightNavigationButton1MouseReleased"/>
</Events>
<AuxValues>
<AuxValue name="JLayeredPane.layer" type="java.lang.Integer" value="200"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="90" y="40" width="30" height="30"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="whiteBackroundButton">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/whiteBackroundCanvas.png"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="White backround"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Hand Cursor"/>
</Property>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="whiteBackroundButtonMouseClicked"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="50" y="130" width="-1" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="blackBackroundButton">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/blackBackroundCanvas.png"/>
</Property>
<Property name="toolTipText" type="java.lang.String" value="Dark background"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Hand Cursor"/>
</Property>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="blackBackroundButtonMouseClicked"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="50" y="190" width="-1" height="-1"/>
</Constraint>
</Constraints>
</Component>
<Container class="javax.swing.JPanel" name="jPanel1">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="0" green="0" red="0" type="rgb"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="0" y="0" width="-1" height="-1"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
</Container>
</SubComponents>
</Container>
</SubComponents>
</Form>
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<Form version="1.4" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="canvas1" alignment="1" pref="685" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="canvas1" alignment="1" pref="476" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="cz.fidentis.analyst.newgui.swing.CanvasPanel" name="canvas1">
</Component>
</SubComponents>
</Form>
/*
* 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.newgui.swing;
import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.windows.TopComponent;
import org.openide.util.NbBundle.Messages;
/**
*
* @author Richard Pajerský
*
* Window for Canvas
*/
@ConvertAsProperties(
dtd = "-//cz.fidentis.analyst.gui//CanvasTC//EN",
autostore = false
)
@TopComponent.Description(
preferredID = "CanvasTC",
//iconBase="SET/PATH/TO/ICON/HERE",
persistenceType = TopComponent.PERSISTENCE_ALWAYS
)
@TopComponent.Registration(mode = "editor", openAtStartup = false)
@ActionID(category = "Window", id = "cz.fidentis.analyst.newgui.swing.CanvasTC")
@ActionReference(path = "Menu/Window" /*, position = 333 */)
@TopComponent.OpenActionRegistration(
displayName = "#CTL_CanvasAction",
preferredID = "CanvasTC"
)
@Messages({
"CTL_CanvasAction=Canvas2",
"CTL_CanvasTC=Canvas2",
"HINT_CanvasTC=This is a Canvas window"
})
public final class CanvasTC extends TopComponent {
public CanvasTC() {
initComponents();
setName(Bundle.CTL_CanvasTC());
setToolTipText(Bundle.HINT_CanvasTC());
//putClientProperty(TopComponent.PROP_CLOSING_DISABLED, Boolean.TRUE);
//putClientProperty(TopComponent.PROP_DRAGGING_DISABLED, Boolean.TRUE);
//putClientProperty(TopComponent.PROP_UNDOCKING_DISABLED, Boolean.TRUE);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
canvas1 = new cz.fidentis.analyst.newgui.swing.CanvasPanel();
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(canvas1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 685, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(canvas1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 476, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private cz.fidentis.analyst.newgui.swing.CanvasPanel canvas1;
// 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
}
public CanvasPanel getCanvas() {
return canvas1;
}
}
package cz.fidentis.analyst.newgui.swing;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import javax.swing.SwingUtilities;
/**
* 3D manipulation with mouse, using 3D movement from GeneralGLEventListener.
*
* @author Richard Pajersky
*/
public class MouseRotationListener extends MouseAdapter {
private final CanvasPanel canvas;
private float lastX = 0;
private float lastY = 0;
private static double rotationSpeed = 0.4;
private static double moveSpeed = 0.4;
/**
* Constructor.
*
* @param canvas Canvas
* @throws IllegalArgumentException if the canvas is {@code null}
*/
public MouseRotationListener(CanvasPanel canvas) {
if (canvas == null) {
throw new IllegalArgumentException("canvas is nuull");
}
this.canvas = canvas;
}
/**
* Left mouse button dragging rotates
* Right mouse button dragging moves
* Middle mouse button dragging resets rotation and zoom
*/
@Override
public void mouseDragged(MouseEvent evt) {
//JOptionPane.showMessageDialog(null, evt.getButton());
if (SwingUtilities.isLeftMouseButton(evt)) {
double rotateX = -(lastY - evt.getY()) * rotationSpeed;
double rotateY = +(lastX - evt.getX()) * rotationSpeed;
if (Math.abs(rotateX) < Math.abs(rotateY)) {
rotateX = 0;
} else if (Math.abs(rotateY) < Math.abs(rotateX)) {
rotateY = 0;
}
canvas.getScene().getCamera().rotate(rotateX, rotateY);
}
if (SwingUtilities.isRightMouseButton(evt)) {
double moveX = -(lastX - evt.getX()) * moveSpeed;
double moveY = -(lastY - evt.getY()) * moveSpeed;
canvas.getScene().getCamera().move(moveX, moveY);
}
if (SwingUtilities.isMiddleMouseButton(evt)) {
canvas.getScene().getCamera().initLocation();
}
lastX = evt.getX();
lastY = evt.getY();
canvas.getGLCanvas().display();
}
/**
* Actualize mouse movement
*/
@Override
public void mouseMoved(MouseEvent e) {
lastX = e.getX();
lastY = e.getY();
}
/**
* Zoom in or out based on mouse wheel movement
*/
@Override
public void mouseWheelMoved(MouseWheelEvent evt) {
if (evt.getWheelRotation() > 0) {
canvas.getScene().getCamera().zoomIn(-5 * evt.getWheelRotation());
} else {
canvas.getScene().getCamera().zoomOut(5 * evt.getWheelRotation());
}
canvas.getGLCanvas().display();
}
/**
* Middle mouse button click resets rotation and zoom
*/
@Override
public void mouseClicked(MouseEvent evt) {
if (SwingUtilities.isMiddleMouseButton(evt)) {
canvas.getScene().getCamera().initLocation();
canvas.getGLCanvas().display();
}
}
public static double getRotationSpeed() {
return rotationSpeed;
}
public static void setRotationSpeed(double rotationSpeed) {
MouseRotationListener.rotationSpeed = rotationSpeed;
}
public static double getMoveSpeed() {
return moveSpeed;
}
public static void setMoveSpeed(double moveSpeed) {
MouseRotationListener.moveSpeed = moveSpeed;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment