I have an application whereby I am creating tabs in a TabNavigator dynamically. As you can see as per my codes I am basically having 5 tabs with specific names. Now I also have 5 mxml components with the same names as the tabs (that is the names of the mxml components are same as the tabs, that is Tab1,Tab2 etc. The non-dynamic way would be to use myTab1:Tab1 = new Tab1();myTab1:Tab2 = new Tab2); etc. Thus I will have to do this for each tab which I don't want.
What I want to do is to load the mxml components in each tab while I am looping through the Array. Hope I am clear enough.
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.containers.VBox;
import mx.controls.Label;
import mx.events.FlexEvent;
import spark.components.NavigatorContent;
protected function tabNavigator_creationCompleteHandler(event:FlexEvent):void
{
var superModules:Array =["Tab1","Tab2","Tab3","Tab4","Tab5"];
for each (var superModule in superModules)
{
var myNavigatorContent:NavigatorContent = new NavigatorContent();
myNavigatorContent.percentHeight = 100;
myNavigatorContent.percentWidth = 100;
myNavigatorContent.label = superModule;
myNavigatorContent.addChild(superModule as DisplayObject);
tabNavigator.addChild(myNavigatorContent);
}
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:TabNavigator id="tabNavigator" width="100%" height="100%" creationComplete="tabNavigator_creationCompleteHandler(event)">
</mx:TabNavigator>
</s:Application>
Can somebody help on achieving this.
Many thanks.
Yes you can do it.Please find my solution below.
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.containers.VBox;
import mx.controls.Label;
import mx.core.IVisualElement;
import mx.core.UIComponent;
import mx.events.FlexEvent;
import spark.components.NavigatorContent;
/*The class "Tab1","Tab2" not compiled with the application
because the linker and the compiler do not add classes
that are not referenced in the code.
Even though you’ll never use the _dummyVarToAddTabToAppCompilation1
variable it is necessary to use that line to instruct the compiler
to include Tab1,Tab2 in the compilation.*/
private var _dummyVarToAddTabToAppCompilation1:Tab1;
private var _dummyVarToAddTabToAppCompilation2:Tab2;
protected function tabNavigator_creationCompleteHandler(event:FlexEvent):void
{
var superModules:Array =["Tab1","Tab2"];
for each (var superModule in superModules)
{
var myNavigatorContent:NavigatorContent = new NavigatorContent();
myNavigatorContent.percentHeight = 100;
myNavigatorContent.percentWidth = 100;
myNavigatorContent.label = superModule;
// Convert class name to Class object.
var cls:Class = getDefinitionByName(superModule) as Class;
// Create a new instance of the class.
var instance:UIComponent = new cls();
myNavigatorContent.addElement(instance);
tabNavigator.addChild(myNavigatorContent);
}
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:TabNavigator id="tabNavigator" width="100%" height="100%" creationComplete="tabNavigator_creationCompleteHandler(event)">
</mx:TabNavigator>
Related
I am using POM with extent report and everything is working fine, also on clicking screen shot its opening in big size but as per the client requirement he need screen shot in bigger size without click on it. I got some suggestion from my senior he said like i need to remove the thumbnail so that it will appear in bigger size, no where i found this option.
<?xml version="1.0" encoding="UTF-8"?>
<extentreports>
<configuration>
<!-- report theme -->
<!-- standard, dark -->
<theme>dark</theme>
<!-- document encoding -->
<!-- defaults to UTF-8 -->
<encoding>UTF-8</encoding>
<!-- protocol for script and stylesheets -->
<!-- defaults to https -->
<protocol>https</protocol>
<!-- title of the document -->
<documentTitle>Dimension Data Automation Reports</documentTitle>
<!-- report name - displayed at top-nav -->
<reportName>Dimension Data - </reportName>
<!-- report headline - displayed at top-nav, after reportHeadline -->
<reportHeadline>Test Automation Report</reportHeadline>
<!-- global date format override -->
<!-- defaults to yyyy-MM-dd -->
<dateFormat>yyyy-MM-dd</dateFormat>
<!-- global time format override -->
<!-- defaults to HH:mm:ss -->
<timeFormat>HH:mm:ss</timeFormat>
<!-- custom javascript -->
<scripts>
<![CDATA[
$(document).ready(function() {
});
]]>
</scripts>
<!-- custom styles -->
<styles>
<![CDATA[
]]>
</styles>
</configuration>
</extentreports>
public class ExtentManager {
private static ExtentReports extent;
public static ExtentReports getInstance() {
if (extent == null) {
Date d = new Date();
//String fileName = d.toString().replace(":", "_").replace(" ", "_") + ".html";
String fileName="index"+".html";
String reportPath = Constants.REPORTS_PATH + fileName;
extent = new ExtentReports(reportPath, true, DisplayOrder.NEWEST_FIRST);
extent.loadConfig(new File(System.getProperty("user.dir") + "/config/ReportsConfig.xml"));
// optional
extent.addSystemInfo("Selenium Version", "2.53.0").addSystemInfo(
"Environment", Constants.ENV).addSystemInfo("Qa","Shiva");
}
return extent;
}
}
This can be done through javascript. Use the <scripts> tag to add the below script
$(document).ready(function() {
var imageElements = $('img.r-img');
for (var i=0; i<imageElements.length; i++) {
imageElements[i].setAttribute('style', 'width:25%;');
}
});
You can set the style for the screenshot (img elements) as per your need.
I am very much new to JavaFX, I started this week basing my knowledge solely off of small tutorials and sample projects learning the syntax. I have created a simple Table of Stock information that you can add and delete information in and would like to implement a login window to this program. I created the login window but am unsure of how to implement it in my main function properly.
Main.java
This contains my code for the stock application.
package sample;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application {
Stage window;
TableView<Stock> table;
TextField symbolInput, nameInput, openingPriceInput, closingPriceInput, changeInPriceInput;
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
window = primaryStage;
window.setTitle("Stock Application");
//Symbol column
TableColumn<Stock, String> symbolColumn = new TableColumn<>("Symbol");
symbolColumn.setMinWidth(100);
symbolColumn.setCellValueFactory(new PropertyValueFactory<>("symbol"));
//Name column
TableColumn<Stock, String> nameColumn = new TableColumn<>("Name");
nameColumn.setMinWidth(100);
nameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
//Opening Price column
TableColumn<Stock, Double> openingPriceColumn = new TableColumn<>("Opening Price");
openingPriceColumn.setMinWidth(100);
openingPriceColumn.setCellValueFactory(new PropertyValueFactory<>("openingPrice"));
//Closing Price column
TableColumn<Stock, Double> closingPriceColumn = new TableColumn<>("Closing Price");
closingPriceColumn.setMinWidth(100);
closingPriceColumn.setCellValueFactory(new PropertyValueFactory<>("closingPrice"));
//Change in Price column
TableColumn<Stock, Double> changeInPriceColumn = new TableColumn<>("Change in Price");
changeInPriceColumn.setMinWidth(100);
changeInPriceColumn.setCellValueFactory(new PropertyValueFactory<>("changeInPrice"));
//Symbol input
symbolInput = new TextField();
symbolInput.setPromptText("Symbol");
symbolInput.setMinWidth(100);
//Name input
nameInput = new TextField();
nameInput.setPromptText("Name");
//Opening Price input
openingPriceInput = new TextField();
openingPriceInput.setPromptText("Opening Price");
//Closing Price input
closingPriceInput = new TextField();
closingPriceInput.setPromptText("Closing Price");
//Change in Price Input
changeInPriceInput = new TextField();
closingPriceInput.setPromptText("Change in Price");
//Button
Button addButton = new Button("Add");
addButton.setOnAction(e -> addButtonClicked());
Button deleteButton = new Button("Delete");
deleteButton.setOnAction(e -> deleteButtonClicked());
HBox hBox = new HBox();
hBox.setPadding(new Insets(10,10,10,10));
hBox.setSpacing(10);
hBox.getChildren().addAll(symbolInput, nameInput, openingPriceInput, closingPriceInput, changeInPriceInput, addButton, deleteButton);
table = new TableView<>();
table.setItems(getStock());
table.getColumns().addAll(symbolColumn, nameColumn, openingPriceColumn, closingPriceColumn, changeInPriceColumn);
VBox vBox = new VBox();
vBox.getChildren().addAll(table, hBox);
Scene scene = new Scene(vBox);
window.setScene(scene);
window.show();
}
//Add button clicked
public void addButtonClicked(){
Stock Stock = new Stock();
Stock.setSymbol(symbolInput.getText());
Stock.setName(nameInput.getText());
Stock.setOpeningPrice(Double.parseDouble(openingPriceInput.getText()));
Stock.setClosingPrice(Double.parseDouble(closingPriceInput.getText()));
Stock.setChangeInPrice(Double.parseDouble(changeInPriceInput.getText()));
table.getItems().add(Stock);
symbolInput.clear();
nameInput.clear();
openingPriceInput.clear();
closingPriceInput.clear();
changeInPriceInput.clear();
}
//Delete button clicked
public void deleteButtonClicked(){
ObservableList<Stock> StockSelected, allStocks;
allStocks = table.getItems();
StockSelected = table.getSelectionModel().getSelectedItems();
StockSelected.forEach(allStocks::remove);
}
//Get all of the Stocks
public ObservableList<Stock> getStock(){
ObservableList<Stock> stocks = FXCollections.observableArrayList();
stocks.add(new Stock("AMZN", "Amazon", 571, 576.4583, 5.4583));
stocks.add(new Stock("EBAY", "eBay", 24.10, 23.7318 , -0.3682));
stocks.add(new Stock("AAPL", "Apple Inc.", 103.91, 104.516, 0.606));
stocks.add(new Stock("SNEJF", "Sony Corp", 24.375, 24.375, 0.00));
stocks.add(new Stock("SBUX", "Starbucks", 58.32, 58.86, 0.54));
return stocks;
}
}
Controller.java
This contains the code for my login window.
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
public class Controller {
#FXML
private Label labelStatus;
#FXML
private TextField textUsername;
#FXML
private TextField textPassword;
public void Login(ActionEvent event) throws Exception {
if (textUsername.getText().equals("CS1113") && textPassword.getText().equals("Section011")) {
labelStatus.setText("Login is Successful");
Stage primaryStage = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("/sample/Main.fxml"));
Scene scene = new Scene(root,400,400);
primaryStage.setScene(scene);
primaryStage.show();
} else {
labelStatus.setText("Login failed!!");
}
}
}
The accompanying FXML file.
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.text.*?>
<AnchorPane prefHeight="300.0" prefWidth="300.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="sample.Controller">
<children>
<Button fx:id="buttonLogin" layoutX="113.0" layoutY="224.0" mnemonicParsing="false" text="Login">
<font>
<Font size="18.0" fx:id="x1" />
</font>
</Button>
<TextField fx:id="textUsername" layoutX="50.0" layoutY="68.0" prefWidth="200.0" promptText="username" />
<PasswordField id="txtPassword" fx:id="textPassword" layoutX="50.0" layoutY="150.0" prefWidth="200.0" promptText="password" />
<Label fx:id="labelStatus" font="$x1" layoutX="14.0" layoutY="14.0" prefWidth="272.0" text="Status" textAlignment="LEFT" textFill="#cc0000" />
</children>
</AnchorPane>
I am sure there is an easier way to implement a large amount of my code or an easier way to implement some of the methods or functions I have created.
Any help is greatly appreciated.
A few ways you can achieve this. When you load from an FXML file, you are loading a Parent node. So, in order to swap from one screen to another, you can either set the Parent node of the existing scene to be the new Parent node, or you can create a new Scene based on the new node and set the new Scene on the Stage of the main application. You may need to expose some methods that will allow you to do this or ensure that your screens have access to the Stage or Scene objects created in the main application class.
This isn't too bad a tutorial in how to implement a possible screen management aspect to your JavaFX application: https://blogs.oracle.com/acaicedo/entry/managing_multiple_screens_in_javafx1. I rolled my own to cater for FXML and manually created screens, inspired by this initial stab at it.
I do not know how to disable PDF download and print in ZUML(ZK User Interface Markup Language). Do I need to embed a customized PDF viewer as I can only open PDF file by using Iframe tag in ZK and it uses browser pdf viewer.Therefore, it makes the task of disabling print and download pdf even harder.
There are two other solution:
Convert the file to HTML, image, or any other format that can be directly viewed in the browser. This conversion can be on-the-fly using a server-side (written in Java in this case), or you can just pre-convert all files to a readable one.
The other approach, which is the best, is to use a Flash-based PDF viewer (such as http://flexpaper.devaldi.com/). This is easy, flexible and doesn't require writing server-side code. This approach is used by many Document-sharing sites (e.g. http://www.scribd.com/, http://www.slideshare.net/, http://www.docstoc.com/)
(For reference only, If you don't want disable download pdf file, there are few solutions:
http://zkfiddle.org/sample/1dnhepc/11-PDF-viewer
http://zkfiddle.org/sample/3ojd4og/1-PDF-Viewer-in-ZK-using-Iframe#source-2 )
After this question I discovered the existence of PDFObject, a simple javascript plugin to embed PDF documents inside a page. I've made a fiddle so you can see it in action.
index.zul
<?script type="text/javascript" src="http://pdfobject.com/scripts/pdfobject.js"?>
<zk>
<script type='text/javascript'>
function embedPDF(_url){
var myPDF = new PDFObject({
url: _url
}).embed('pdfContainer');
}
</script>
<vlayout apply="org.zkoss.bind.BindComposer" viewModel="#id('vm') #init('pkg$.TestVM')" xmlns:w="http://www.zkoss.org/2005/zk/client">
<listbox model="#load(vm.pdfUrls)">
<template name="model" var="url">
<listitem>
<listcell label="#load(url)" />
<listcell>
<button label="load" onClick="#command('loadPdf', url=url)" />
</listcell>
</listitem>
</template>
</listbox>
<vlayout xmlns:n="native">
<n:object id="pdfContainer"></n:object>
</vlayout>
</vlayout>
</zk>
TestVM.java
import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.BindingParam;
import java.util.List;
import java.util.ArrayList;
import org.zkoss.zk.ui.util.Clients;
public class TestVM {
List<String> pdfUrls;
#AfterCompose
public void afterCompose() {
pdfUrls = new ArrayList<String>();
pdfUrls.add("http://www.pdf995.com/samples/pdf.pdf");
pdfUrls.add("https://partners.adobe.com/public/developer/en/xml/AdobeXMLFormsSamples.pdf");
pdfUrls.add("https://www.iscp.ie/sites/default/files/pdf-sample.pdf");
}
#Command
public void loadPdf(#BindingParam("url")String url) {
Clients.evalJavaScript("embedPDF('"+ url +"')");
}
public List<String> getPdfUrls() {
return pdfUrls;
}
}
Cheers, Alex
I am trying to add a new tab to an actionscript TabBar control at runtime. When I use addChild() to add a tab to the tab bar I get an exception at runtime:
Error: addChild() is not available in this class. Instead, use addElement() or modify the skin, if you have one.
However, when I tried using addElement() instead I get an error at compile time:
1061: Call to a possibly undefined method addElement through a reference with static type spark.components:TabBar.
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="100%"
height="100%">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
private var _lastAddedNumber:int = 1;
protected function btnAddNewTab_clickHandler(event:MouseEvent):void
{
tabby.dataProvider.addItem('New '+_lastAddedNumber);
_lastAddedNumber++;
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:Button id="btnSave"
click="btnAddNewTab_clickHandler(event)"
label="Add New Tab"/>
<mx:Form top="50">
<mx:FormItem label="tabWidth:">
<s:HSlider id="slider"
minimum="40"
maximum="120"
value="100"/>
</mx:FormItem>
</mx:Form>
<s:TabBar id="tabby"
horizontalCenter="0"
verticalCenter="0">
<s:layout>
<s:HorizontalLayout gap="-1"
columnWidth="{slider.value}"
variableColumnWidth="false"/>
</s:layout>
<s:dataProvider>
<s:ArrayList source="[red,orange,yellow,green,blue]"/>
</s:dataProvider>
</s:TabBar></s:Application>
may this will help you!!!
I am creating an openlaszlo application where an html tag will be present and i have some components that are draggable in the swf. I want to drag these components over the html. This is not possible.
So what i am thinking of is to take a screenshot of the html content and replace it with the actual html content when i need to drag over it.
Theoretically this should be possible and it's possible in flex I verified my self. I am trying to do the same thing in Openlaszlo. But i am not getting any leads
So far i have tried like this
And i am getting an error that the html tag is not object of IBitmapDrawable
<canvas width="800" height="600" bgcolor="white" debug="true">
<script when="immediate"><![CDATA[
class MagUtils {
#passthrough (toplevel: true) {
import flash.display.DisplayObject;
import flash.geom.Rectangle;
import flash.geom.Matrix;
import flash.geom.ColorTransform;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.filters.*;
import flash.events.MouseEvent;
import mx.graphics.ImageSnapshot;
import flash.utils.ByteArray;
import flash.display.IBitmapDrawable;
}#
var temp:lz.view;
var colorTransform:ColorTransform;
var rect:Rectangle;
public function snap (m:IBitmapDrawable, t:lz.view):void {
temp = t;
var temp_mc = temp.sprite; // getMCRef();
var mainView_mc = main.sprite; // getMCRef();
var scale = 1;
var x;
var y;
var w;
var h;
var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(m);
var imageByteArray:ByteArray = imageSnap.data;
colorTransform = new flash.geom.ColorTransform();
rect = new flash.geom.Rectangle(0, 0, temp.width, temp.height);
var bitmap:BitmapData = new flash.display.BitmapData(w, h, false);
bitmap.setPixels(rect, imageByteArray);
var bm:Bitmap = new Bitmap(bitmap);
temp.sprite.addChild (bm);
bitmap = null;
}
}
lz.MagUtils = new MagUtils();
]]>
</script>
<button name="magnifier" text="magnifyingtool" >
<handler name="onclick">
lz.MagUtils.snap(canvas.main.ht,canvas.temp);
</handler>
</button>
<view name="main" x="5" y="15" width="200" height="200" bgcolor="yellow">
<html name="ht" width="200" height="200" src="http:hello.html"/>
</view>
<view id="temp" name="temp" x="5" y="300" visible="true" width="200" height="200" bgcolor="gray">
</view>
</canvas>
And the HTML Content is
<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML>
<HEAD>
<TITLE>
A Small Hello
</TITLE>
</HEAD>
<BODY>
<H1>Hi</H1>
<P>Test Page</P>
</BODY>
</HTML>
It's no possible to take a screenshot in Flash of elements which are not managed by the Flash display list, which includes iFrame content placed below the SWF movie in the browser. And that seems to be what you are trying to do.
If you want to drag a visual object from the iFrame into the SWF movie area, one approach might be to render the content in HTML into an HTML5 canvas element, extract the bitmap data and push that into the SWF movie to be displayed in an OpenLaszlo view. But that would mean that all visual elements you want to drag need to be drawn into an HTML5 canvas.
Here is an example where uses Flash Player's filter functionality to apply the filter to an image in an HTML5 canvas element:
http://www.quasimondo.com/archives/000695.php
Here are the links to the relevant files for this example:
The HTML page embedding an invisible SWF for processing the image.
JavaScript file with functions for sending the data to the SWF movie clip.
ActionScript class processing the image data sent from JavaScript, and passing the processed data back to the HTML page.
But I'm not sure that all the content you have in your iFrame can be rendered into a canvas element.