-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(refactor) Extract interface from CaptureSupport.
- Loading branch information
Showing
6 changed files
with
207 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
subprojects/testfx-core/src/main/java/org/testfx/service/support/MatchAlgorithm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright 2013-2014 SmartBear Software | ||
* Copyright 2014-2015 The TestFX Contributors | ||
* | ||
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved by the | ||
* European Commission - subsequent versions of the EUPL (the "Licence"); You may | ||
* not use this work except in compliance with the Licence. | ||
* | ||
* You may obtain a copy of the Licence at: | ||
* http://ec.europa.eu/idabc/eupl | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed | ||
* under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR | ||
* CONDITIONS OF ANY KIND, either express or implied. See the Licence for the | ||
* specific language governing permissions and limitations under the Licence. | ||
*/ | ||
package org.testfx.service.support; | ||
|
||
public interface MatchAlgorithm { | ||
} |
113 changes: 113 additions & 0 deletions
113
...rojects/testfx-core/src/main/java/org/testfx/service/support/impl/CaptureSupportImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Copyright 2013-2014 SmartBear Software | ||
* Copyright 2014-2015 The TestFX Contributors | ||
* | ||
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved by the | ||
* European Commission - subsequent versions of the EUPL (the "Licence"); You may | ||
* not use this work except in compliance with the Licence. | ||
* | ||
* You may obtain a copy of the Licence at: | ||
* http://ec.europa.eu/idabc/eupl | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed | ||
* under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR | ||
* CONDITIONS OF ANY KIND, either express or implied. See the Licence for the | ||
* specific language governing permissions and limitations under the Licence. | ||
*/ | ||
package org.testfx.service.support.impl; | ||
|
||
import java.awt.image.BufferedImage; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import javax.imageio.ImageIO; | ||
|
||
import javafx.embed.swing.SwingFXUtils; | ||
import javafx.geometry.Pos; | ||
import javafx.geometry.Rectangle2D; | ||
import javafx.scene.Node; | ||
import javafx.scene.effect.BlendMode; | ||
import javafx.scene.image.Image; | ||
import javafx.scene.image.ImageView; | ||
import javafx.scene.layout.StackPane; | ||
import javafx.scene.shape.Shape; | ||
|
||
import org.testfx.api.annotation.Unstable; | ||
import org.testfx.robot.BaseRobot; | ||
import org.testfx.service.support.CaptureSupport; | ||
import org.testfx.service.support.MatchAlgorithm; | ||
|
||
@Unstable(reason = "needs more tests") | ||
public class CaptureSupportImpl implements CaptureSupport { | ||
|
||
//--------------------------------------------------------------------------------------------- | ||
// PRIVATE FIELDS. | ||
//--------------------------------------------------------------------------------------------- | ||
|
||
private BaseRobot baseRobot; | ||
|
||
//--------------------------------------------------------------------------------------------- | ||
// CONSTRUCTORS. | ||
//--------------------------------------------------------------------------------------------- | ||
|
||
public CaptureSupportImpl(BaseRobot baseRobot) { | ||
this.baseRobot = baseRobot; | ||
} | ||
|
||
//--------------------------------------------------------------------------------------------- | ||
// METHODS. | ||
//--------------------------------------------------------------------------------------------- | ||
|
||
@Override | ||
public Image captureRegion(Rectangle2D region) { | ||
return baseRobot.captureRegion(region); | ||
} | ||
|
||
@Override | ||
public Image captureNode(Node node) { | ||
return node.snapshot(null, null); | ||
} | ||
|
||
@Override | ||
public Image drawShape(Shape shape, | ||
Image image) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public Image blendImages(Image image0, | ||
Image image1, | ||
BlendMode blendMode) { | ||
StackPane stackPane = new StackPane(); | ||
stackPane.setAlignment(Pos.TOP_LEFT); | ||
stackPane.getChildren().add(new ImageView(image0)); | ||
stackPane.getChildren().add(new ImageView(image1)); | ||
stackPane.setBlendMode(blendMode); | ||
return captureNode(stackPane); | ||
} | ||
|
||
@Override | ||
public MatchResult<Image> matchImages(Image image0, | ||
Image image1, | ||
MatchAlgorithm algorithm) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public Image loadImage(File file) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public void saveImage(Image image, | ||
File file) { | ||
BufferedImage bufferedImage = SwingFXUtils.fromFXImage(image, null); | ||
try { | ||
ImageIO.write(bufferedImage, "png", file); | ||
} | ||
catch (IOException exception) { | ||
exception.printStackTrace(); | ||
} | ||
} | ||
|
||
} | ||
|
51 changes: 51 additions & 0 deletions
51
subprojects/testfx-core/src/main/java/org/testfx/service/support/impl/MatchResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2013-2014 SmartBear Software | ||
* Copyright 2014-2015 The TestFX Contributors | ||
* | ||
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved by the | ||
* European Commission - subsequent versions of the EUPL (the "Licence"); You may | ||
* not use this work except in compliance with the Licence. | ||
* | ||
* You may obtain a copy of the Licence at: | ||
* http://ec.europa.eu/idabc/eupl | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed | ||
* under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR | ||
* CONDITIONS OF ANY KIND, either express or implied. See the Licence for the | ||
* specific language governing permissions and limitations under the Licence. | ||
*/ | ||
package org.testfx.service.support.impl; | ||
|
||
public class MatchResult<T> { | ||
|
||
//--------------------------------------------------------------------------------------------- | ||
// PRIVATE FIELDS. | ||
//--------------------------------------------------------------------------------------------- | ||
|
||
private T result; | ||
|
||
private int distance; | ||
|
||
//--------------------------------------------------------------------------------------------- | ||
// CONSTRUCTORS. | ||
//--------------------------------------------------------------------------------------------- | ||
|
||
public MatchResult(T result, | ||
int distance) { | ||
this.result = result; | ||
this.distance = distance; | ||
} | ||
|
||
//--------------------------------------------------------------------------------------------- | ||
// METHODS. | ||
//--------------------------------------------------------------------------------------------- | ||
|
||
T getResult() { | ||
return result; | ||
} | ||
|
||
int getDistance() { | ||
return distance; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters