I don't manage to give user mouse interaction to a ColorCube by using a MouseRotate. However, when i use a KeyNavigatorBehaviour, i can control the cube with keyboard as needed.
Here the code i used to test MouseRotate :
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.GraphicsConfigTemplate3D;
import javax.media.j3d.TransformGroup;
import javax.swing.JFrame;
import javax.vecmath.Point3d;
import com.sun.j3d.exp.swing.JCanvas3D;
import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;
public class MovingAroundCube extends JFrame {
private static final long serialVersionUID = 1L;
public MovingAroundCube(){
setTitle("Moving around cube");
setSize(300,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
JCanvas3D jCanvas3D = new JCanvas3D(new GraphicsConfigTemplate3D());
jCanvas3D.setSize(300, 300);
add(jCanvas3D);
SimpleUniverse universe = new SimpleUniverse(jCanvas3D.getOffscreenCanvas3D());
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(createSceneGraph());
}
public BranchGroup createSceneGraph() {
BranchGroup objRoot = new BranchGroup();
TransformGroup listenerGroup = new TransformGroup();
listenerGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
listenerGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
objRoot.addChild(listenerGroup);
//KeyNavigatorBehavior behaviour = new KeyNavigatorBehavior(listenerGroup);
MouseRotate behaviour = new MouseRotate(listenerGroup);
behaviour.setSchedulingBounds(new BoundingSphere(new Point3d(), 100));
listenerGroup.addChild(behaviour);
listenerGroup.addChild(new ColorCube(0.4));
return objRoot;
}
public static void main(String[] args) {
new MovingAroundCube().setVisible(true);
}
}
If I uncomment the line creating the KeyNavigatorBehaviour and comment the line creating the MouseRotate, user interaction this time is possible .
So, why can't the cube react to the mouse (when i use MouseRotate behaviour instance) ?
Any help will be appreciated.
System : Xubuntu 11.04
Java3D version : 1.5.2
There are two ways to solve this dilemma:
Use this constructor:
MouseRotate behaviour = new MouseRotate(jCanvas3D, listenerGroup);
or
Enable mouse events as long as no MouseListeners are added:
import java.awt.AWTEvent;
JCanvas3D jCanvas3D = new JCanvas3D(new GraphicsConfigTemplate3D()) {
{
this.enableEvents(AWTEvent.MOUSE_EVENT_MASK |
AWTEvent.MOUSE_MOTION_EVENT_MASK |
AWTEvent.MOUSE_WHEEL_EVENT_MASK);
}
};
Key events are enabled because 'setFocusable(true)' is set in JCanvas3D.
August, InteractiveMesh
Related
I am using Com.GitHub.java parser for generating java code. i am facing a problem for generating extends keywords
This line "extendsList.add(new ClassOrInterfaceType("CustomEndpointResource"));".
This statement is showing deprecated .that means it gives a warning.
How can i avoid this warning ? So, i can not use this statement. any alternative
way other than this deprecated statement (extendsList.add(new ClassOrInterfaceType).
My Source code:
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Modifier;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.expr.StringLiteralExpr;
import com.github.javaparser.ast.type.ClassOrInterfaceType;
public class ProductCreate2 {
public static void main(String[] args) {
CompilationUnit compilationUnit = new CompilationUnit();
compilationUnit.setPackageDeclaration("org.meveo.mymodule.resource");
compilationUnit.addImport("java.util", false, true);
ClassOrInterfaceDeclaration restEndpointClass = compilationUnit.addClass("ProductCreate",Modifier.Keyword.PUBLIC);
restEndpointClass.addSingleMemberAnnotation("Path",new StringLiteralExpr("myproduct"));
restEndpointClass.addMarkerAnnotation("RequestScoped");
var injectedfield=restEndpointClass.addField("CreateMyProduct", "CreateMyProduct", Modifier.Keyword.PRIVATE);
injectedfield.addMarkerAnnotation("Inject");
NodeList<ClassOrInterfaceType> extendsList = new NodeList<>();
extendsList.add(new ClassOrInterfaceType("CustomEndpointResource"));
restEndpointClass.setExtendedTypes(extendsList);
System.out.println(compilationUnit);
}
}
Expected output of my code:
class productCreate extends ABC
{
}
There can be multiple ways to avoid using the deprecated constructor. E.g. you can use the following instead:
ClassOrInterfaceType extendClass = new ClassOrInterfaceType();
extendClass.setName(new SimpleName("CustomEndpointResource"));
extendsList.add(extendClass);
i am facing another problem for generating this annotation line : #Path("/{uuid}").
Expected output of my code:
class productGet {
#Path("/{uuid}")
public Response getProduct() throws ServletException {
}
}
Hi I am trying to automate https://emicalculator.net/
.I tried many approach but did not get success Below is my code for automating Interest rate slider
package seleniumBasics;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class AdjustSliderValue {
static String baseUrl = "https://emicalculator.net/";
public static WebDriver driver;
#BeforeTest
public WebDriver createDriver() {
driver = DriverSetup.getWebDriver();
driver.get(baseUrl);
return driver;
}
#AfterMethod
public void CloseDriver() {
driver.quit();
}
public static int GetPixelsToMove(WebElement Slider, double Amount, double SliderMax, double SliderMin) {
int pixels = 0;
int tempPixels = Slider.getSize().getWidth();
System.out.println(tempPixels);
tempPixels = (int)(tempPixels / (SliderMax - SliderMin));
System.out.println(tempPixels);
tempPixels = (int) (tempPixels * (Amount - SliderMin));
System.out.println(tempPixels);
pixels = tempPixels;
return pixels;
}
#Test
public static void verifySlider() throws InterruptedException {
WebElement Slider = driver.findElement(By.xpath("//*[#id=\"loaninterestslider\"]"));
int PixelsToMove = GetPixelsToMove(Slider, 15, 20, 5);
Actions SliderAction = new Actions(driver);
SliderAction.clickAndHold(Slider).moveByOffset((-(int) Slider.getSize().getWidth() / 2), 0)
.moveByOffset(PixelsToMove, 0).release().perform();
}
}
I want a method which can automate any slider. Could any one who knows please help me. Thanks in advance.
You may also try Key actions using Send Keys
// Set Loop counter to get desired value
<Your_Slider_Element>.sendKeys(Keys.ARROW_LEFT); // Or ARROW_RIGHT
// End loop
dragAndDropBy usually work best with slider. Make sure the way you calculate pixel is correct then it good to go.
driver.get("https://emicalculator.net/");
WebElement Slider = driver.findElement(By.xpath("//*[#id=\"loaninterestslider\"]"));
int PixelsToMove = GetPixelsToMove(Slider, 15, 20, 5);
Actions move = new Actions(driver);
Action action = (Action) move.dragAndDropBy(Slider, PixelsToMove, 0).build();
action.perform();
Import package
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
Sliderwidth is basically just 100% of the size here but you can add whatever pixel you want.
driver.get("https://emicalculator.net/");
WebElement Slider = driver.findElement(By.xpath("//*[#id=\"loaninterestslider\"]"));
Dimension sliderSize = Slider.getSize();
int sliderWidth = sliderSize.getWidth();
int xCoord = Slider.getLocation().getX();
Actions builder = new Actions(driver);
builder.moveToElement(Slider)
.click()
.dragAndDropBy
(Slider,xCoord + sliderWidth, 0)
.build()
.perform();
Import
import org.openqa.selenium.Dimension;
import org.openqa.selenium.interactions.Actions;
WebDriver driver = new ChromeDriver();
driver.get("https://emicalculator.net/");
WebElement a = driver.findElement(By.cssSelector("#loanamountslider span"));
Actions action = new Actions(driver);
action.clickAndHold(a).moveByOffset(500, 0).perform();
Here you go , you have to click the slider element and drag it
As the topicstarter correctly mentioned, the question is about how to automate any slider. So let me extend existing answers with requested solution.
The solution is not new - Selenium already has sample with Select. Let's build similar solution.
So assume we wanted to have some object of type EmiSlider so we could use it the way:
...
EmiSlider slider = new EmiSlider(driver.findElement(By.id("loanamountslider")));
slider.slide(100);
...
We are explicitly mentioning the desired locator and passing into constructor of class EmiSlider. The EmiSlider class then would be:
public class EmiSlider {
private final WebElement sliderRoot;
private final WebDriver driver;
public EmiSlider(WebElement slider) {
// Simply store passed root WebElement
this.sliderRoot = slider;
// We require driver instance for internal use so resolve it and store
this.driver = ((WrapsDriver) slider).getWrappedDriver();
}
/**
* Moves slider left or right
* #param x pixels to move slider by. Positive value moves right, negative - left
*/
public void slide(int x) {
// Find the slider WebElement, which is child of root element, using relative search
WebElement sliderElement = this.sliderRoot.findElement(By.cssSelector("span"));
// Perform slide action
new Actions(this.driver)
.clickAndHold(sliderElement)
.moveByOffset(x, 0)
.release()
.perform();
}
}
The current slider implementation had few drawbacks:
It does not count on the current and extreme positions
Different sliders might have different scales (and they do)
The amout inputs are left alone while
Hope one can add missed functionality
I have a project which is based on the serenity-bdd/serenity-cucumber-starter project. I'm using test-containers to start a couple of Docker containers as well as a Selenium Grid container to run the test against.
new GenericContainer<>(SELENIUM_IMAGE)
...
.withExposedPorts(SELENIUM_CONTAINER_PORT, SELENIUM_CONTAINER_NOVNC_PORT)
...
);
When the tests start, test-containers will ramp up the containers and bind random host ports to all exposed ports of the containers.
Because of that, I cannot define a fixed value in serenity.conf for the url of the remote driver
webdriver.remote.url = "http://localhost:????/wd/hub"
Thus I need a way to set webdriver.remote.url programmatically.
One option would be to use the FixedHostPortGenericContainer, which allows you define the host port on which the container exposed port will be bound to.
I'd rather would like to use a different approach though, as the developers state that
While this works, we strongly advise against using fixed ports, since this will automatically lead to integrated tests (which are an anti pattern).
So the question is: How can I modify the value of webdriver.remote.url at runtime? Is there any option provided by serenity-bdd to reload the net.thucydides.core.util.SystemEnvironmentVariables at runtime?
Faced recently the same issue, but was lucky enough to find a solution:
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import net.serenitybdd.core.webdriver.driverproviders.FirefoxDriverCapabilities;
import net.thucydides.core.guice.Injectors;
import net.thucydides.core.util.EnvironmentVariables;
import net.thucydides.core.webdriver.DriverSource;
public class CustomWebDriverFactory implements DriverSource {
#Override
public WebDriver newDriver() {
try {
String ip = "your_dynamic_ip";
return new RemoteWebDriver(
new URL("http://" + ip + ":4444/wd/hub"),
new FirefoxDriverCapabilities(Injectors.getInjector().getProvider(EnvironmentVariables.class).get()).getCapabilities());
}
catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
#Override
public boolean takesScreenshots() {
return true;
}
}
So you have to add such factory implementation and define in serenity.properties:
webdriver.driver = provided
webdriver.provided.type = mydriver
webdriver.provided.mydriver = <your_factory_package>.CustomWebDriverFactory
thucydides.driver.capabilities = mydriver
we use a spreadsheetview with different kind of cell types.
In the documentation to SpreadsheetCellEditor we found the following text:
The policy regarding validation of a given value is defined in
SpreadsheetCellType.match(Object). If the value doesn't meet the requirements
when saving the cell, nothing happens and the editor keeps editing.
now we facing the following problem:
if you enter "abcd" in an integer cell as a wrong entry and push enter key, nothing happens. Editor is still in edit mode. This is exactly the behaviour as descripted in the documentation. that is what we want.
if you have a date cell and enter a wrong date or something else and push enter key, cell stops editing mode and set value return to "old" value.
how can we prevent this behaviour?
Maybe its a bug in the Date SpreadsheetCellType?
we use a lot of custom cellType Classes, but the behaviour is also comprehensibly with this little example.
I hope everything is well explained.
Thanks for your help.
import java.time.LocalDate;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import org.controlsfx.control.spreadsheet.GridBase;
import org.controlsfx.control.spreadsheet.SpreadsheetCell;
import org.controlsfx.control.spreadsheet.SpreadsheetCellType;
import org.controlsfx.control.spreadsheet.SpreadsheetView;
public class SpreadSheetExample extends Application {
private SpreadsheetView getSpreadSheet() {
SpreadsheetView spreadSheetView;
GridBase grid;
grid = new GridBase(10, 2);
spreadSheetView = new SpreadsheetView(grid);
ObservableList<ObservableList<SpreadsheetCell>> rows = FXCollections.observableArrayList();
for (int row = 0; row < grid.getRowCount(); ++row) {
final ObservableList<SpreadsheetCell> list = FXCollections.observableArrayList();
for (int column = 0; column < grid.getColumnCount(); ++column) {
if (column < 1) {
list.add(SpreadsheetCellType.DATE.createCell(row, column, 1, 1, LocalDate.now()));
} else {
list.add(SpreadsheetCellType.INTEGER.createCell(row, column, 1, 1, column));
}
}
rows.add(list);
}
spreadSheetView.getColumns().forEach((column) -> {
column.setPrefWidth(280);
});
grid.setRows(rows);
return spreadSheetView;
}
#Override
public void start(Stage primaryStage) {
StackPane root = new StackPane();
root.getChildren().add(getSpreadSheet());
Scene scene = new Scene(root, 800, 400);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Update:
are there no controlsfx experts?
Solved:
https://groups.google.com/forum/#!topic/controlsfx-dev/ro7-MvLFD1A
It is solved.
i got some help from one of the major contributor of ControlsFX.
The documentation was a bit unclearly.
In order to get the described behavior, a custom Cell Type + Editor based on the existing ones can be created.
For all details take a look in this thread:
https://groups.google.com/forum/#!topic/controlsfx-dev/ro7-MvLFD1A
Below is Monte Media Library.
http://www.randelshofer.ch/monte/
I am using MonteScreenRecorder jar for record screen.
I am able to store video file in avi format but i want to store in mp4 format
Here is code for avi
import java.awt.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.monte.media.Format;
import org.monte.media.math.Rational;
import org.monte.screenrecorder.ScreenRecorder;
import static org.monte.media.VideoFormatKeys.*;
...
private ScreenRecorder screenRecorder;
public void startRecording() throws Exception
{
GraphicsConfiguration gc = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice()
.getDefaultConfiguration();
this.screenRecorder = new ScreenRecorder(gc,
new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_AVI),
new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE,
CompressorNameKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE,
DepthKey, 24, FrameRateKey, Rational.valueOf(15),
QualityKey, 1.0f,
KeyFrameIntervalKey, 15 * 60),
new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, "black",
FrameRateKey, Rational.valueOf(30)),
null);
this.screenRecorder.start();
}
public void stopRecording() throws Exception
{
this.screenRecorder.stop();
}
...
What are the change is required let me know.
Please Help
Thank you