I have created a report using dynamic reports and add a page number component and set its horizontal Alignment as right. But in printed report, page number doesn't seem to be fully right aligned.
Check this image to see the alignment issue
Note :- No right padding for page number and no trailing white spaces in page number expression.
versions used :-
dynamicreports - 3.0.2
jasperreports - 4.8.0
After lots of time spent on debugging and checking source code of dynamic reports I found the issue. I am posting this for anyone who find its helpful.
When we add PageXofYBuilder, what dynamic reports actually doing is create two text fields for 'x' and 'y'. If the component is right aligned then text field for 'x' is right aligned and text field for 'y' is left aligned with fixed width. The width of text field for 'y' is calculated as width required for a 6 digit number based on the selected font, font size and horizontal padding.
Check out the below code of pageXofY method in the class ComponentTransform which is responsible for creating the page number field in jasper design for more details :
private DRDesignList pageXofY(DRIPageXofY pageXofY, DefaultStyleType defaultStyleType) throws DRException {
TemplateTransform templateTransform = accessor.getTemplateTransform();
DRIReportStyle pageXofYStyle = pageXofY.getStyle();
if (pageXofYStyle == null) {
pageXofYStyle = accessor.getTemplateTransform().getTextStyle();
}
DRDesignStyle style = accessor.getStyleTransform().transformStyle(pageXofYStyle, true, defaultStyleType);
Integer height = templateTransform.getPageXofYHeight(pageXofY, style);
HorizontalAlignment horizontalAlignment = templateTransform.getPageXofYHorizontalAlignment(pageXofY, style);
DRStyle newStylePageX = new DRStyle();
newStylePageX.setParentStyle(pageXofYStyle);
newStylePageX.getPadding().setRight(0);
DRPen pen = new DRPen();
pen.setLineWidth(0f);
newStylePageX.getBorder().setRightPen(pen);
DRStyle newStylePageY = new DRStyle();
newStylePageY.setParentStyle(pageXofYStyle);
newStylePageY.getPadding().setLeft(0);
newStylePageY.getBorder().setLeftPen(pen);
DRTextField<String> pageXField = new DRTextField<String>();
pageXField.setAnchorNameExpression(pageXofY.getAnchorNameExpression());
pageXField.setBookmarkLevel(pageXofY.getBookmarkLevel());
pageXField.setHyperLink((DRHyperLink) pageXofY.getHyperLink());
pageXField.setPrintWhenExpression(pageXofY.getPrintWhenExpression());
pageXField.setStyle(newStylePageX);
pageXField.setHeight(height);
pageXField.setHeightType(pageXofY.getHeightType());
pageXField.setHorizontalAlignment(HorizontalAlignment.RIGHT);
pageXField.setValueExpression(new PageXofYNumberExpression(pageXofY.getFormatExpression(), 0));
DRTextField<String> pageYField = new DRTextField<String>();
pageYField.setAnchorNameExpression(pageXofY.getAnchorNameExpression());
pageYField.setBookmarkLevel(pageXofY.getBookmarkLevel());
pageYField.setHyperLink((DRHyperLink) pageXofY.getHyperLink());
pageYField.setPrintWhenExpression(pageXofY.getPrintWhenExpression());
pageYField.setStyle(newStylePageY);
pageYField.setHeight(height);
pageYField.setHeightType(pageXofY.getHeightType());
pageYField.setHorizontalAlignment(HorizontalAlignment.LEFT);
pageYField.setValueExpression(new PageXofYNumberExpression(pageXofY.getFormatExpression(), 1));
DRIGroup pageYEvaluationGroup = accessor.getGroupTransform().getFirstResetPageNumberGroup();
if (pageYEvaluationGroup == null) {
pageYField.setEvaluationTime(Evaluation.REPORT);
}
else {
pageYField.setEvaluationTime(Evaluation.GROUP);
pageYField.setEvaluationGroup((DRGroup) pageYEvaluationGroup);
}
int pageXofYWidth = templateTransform.getPageXofYWidth(pageXofY, style);
switch (horizontalAlignment) {
case LEFT:
int pageXWidth = StyleResolver.getFontWidth(style, 4);
int pageYWidth = pageXofYWidth - pageXWidth;
if (pageYWidth <= 0) {
pageYWidth = 10;
}
pageXField.setWidth(pageXWidth);
pageXField.setWidthType(ComponentDimensionType.FIXED);
pageYField.setWidth(pageYWidth);
pageYField.setWidthType(pageXofY.getWidthType());
break;
case RIGHT:
pageYWidth = StyleResolver.getFontWidth(style, 6);
pageXWidth = pageXofYWidth - pageYWidth;
if (pageXWidth <= 0) {
pageXWidth = 10;
}
pageXField.setWidth(pageXWidth);
pageXField.setWidthType(pageXofY.getWidthType());
pageYField.setWidth(pageYWidth);
pageYField.setWidthType(ComponentDimensionType.FIXED);
break;
default:
pageXField.setWidth(pageXofYWidth / 2);
pageXField.setWidthType(pageXofY.getWidthType());
pageYField.setWidth(pageXofYWidth / 2);
pageYField.setWidthType(pageXofY.getWidthType());
break;
}
DRList listPageXofY = new DRList();
listPageXofY.addComponent(pageXField);
listPageXofY.addComponent(pageYField);
return list(listPageXofY, DefaultStyleType.TEXT, null, null);
}
StyleResolver.getFontWidth() method
protected static int getFontWidth(DRDesignStyle style, int columns) {
double width = getFont(style).getStringBounds("m", context).getWidth();
return (int) Math.ceil(width * columns) + getHorizontalPadding(style);
}
I am trying to show an object without tapping on the screen using ARCore. In the basic sample of ARCore Sceneform provided by Google, you need to tap on the screen after it detects the surface.
I want to implement that, AR shows the object without tapping on the screen.
Anchor newAnchor;
for (Plane plane : mSession.getAllTrackables(Plane.class)) {
if (plane.getType() == Plane.Type.HORIZONTAL_UPWARD_FACING
&& plane.getTrackingState() == TrackingState.TRACKING)
{
newAnchor = plane.createAnchor(plane.getCenterPose());
break;
}
}
I tried this for displaying without tapping on the screen.
if Anyone know how to do this please help me. Thanks in Advance
Although I suggest you place the object when a user taps & where s/he taps on the screen, what you're asking can be achieved like so. (this example is in Kotlin)
Before you begin placing an object, you need to create a ModelRenderable. Declare one #Nullable globally.
private var modelRenderable: ModelRenderable? = null
//Create the football renderable
ModelRenderable.builder()
//get the context of the ARFragment and pass the name of your .sfb file
.setSource(fragment.context, Uri.parse("FootBall.sfb"))
.build()
//I accepted the CompletableFuture using Async since I created my model on creation of the activity. You could simply use .thenAccept too.
//Use the returned modelRenderable and save it to a global variable of the same name
.thenAcceptAsync { modelRenderable -> this#MainActivity.modelRenderable = modelRenderable }
The major chunk of the programming has to be done on the frame's onUpdate method. So you attach a listener for frame updates like so
fragment.arSceneView.scene.addOnUpdateListener(this#MainActivity) //You can do this anywhere. I do it on activity creation post inflating the fragment
now you handle adding an object on the listener.
override fun onUpdate(frameTime: FrameTime?) {
//get the frame from the scene for shorthand
val frame = fragment.arSceneView.arFrame
if (frame != null) {
//get the trackables to ensure planes are detected
val var3 = frame.getUpdatedTrackables(Plane::class.java).iterator()
while(var3.hasNext()) {
val plane = var3.next() as Plane
//If a plane has been detected & is being tracked by ARCore
if (plane.trackingState == TrackingState.TRACKING) {
//Hide the plane discovery helper animation
fragment.planeDiscoveryController.hide()
//Get all added anchors to the frame
val iterableAnchor = frame.updatedAnchors.iterator()
//place the first object only if no previous anchors were added
if(!iterableAnchor.hasNext()) {
//Perform a hit test at the center of the screen to place an object without tapping
val hitTest = frame.hitTest(frame.screenCenter().x, frame.screenCenter().y)
//iterate through all hits
val hitTestIterator = hitTest.iterator()
while(hitTestIterator.hasNext()) {
val hitResult = hitTestIterator.next()
//Create an anchor at the plane hit
val modelAnchor = plane.createAnchor(hitResult.hitPose)
//Attach a node to this anchor with the scene as the parent
val anchorNode = AnchorNode(modelAnchor)
anchorNode.setParent(fragment.arSceneView.scene)
//create a new TranformableNode that will carry our object
val transformableNode = TransformableNode(fragment.transformationSystem)
transformableNode.setParent(anchorNode)
transformableNode.renderable = this#MainActivity.modelRenderable
//Alter the real world position to ensure object renders on the table top. Not somewhere inside.
transformableNode.worldPosition = Vector3(modelAnchor.pose.tx(),
modelAnchor.pose.compose(Pose.makeTranslation(0f, 0.05f, 0f)).ty(),
modelAnchor.pose.tz())
}
}
}
}
}
}
I used one extension method
//A method to find the screen center. This is used while placing objects in the scene
private fun Frame.screenCenter(): Vector3 {
val vw = findViewById<View>(android.R.id.content)
return Vector3(vw.width / 2f, vw.height / 2f, 0f)
}
This is the end result
If you don't want to use hit-testing or button's action methods for placing an object in a real environment, you can use, for instance, a camera's Pose for auto-placement (remember, you have to add an ARAnchor, its corresponding Node and a Renderable in front of the ARCamera i.e. along -Z direction):
if (this.anchorNode == null) {
Session session = arFragment.getArSceneView().getSession();
float[] position = { 0, 0, -0.75 }; // 75 cm away from camera
float[] rotation = { 0, 0, 0, 1 };
Anchor anchor = session.createAnchor(new Pose(position, rotation));
anchorNode = new AnchorNode(anchor);
anchorNode.setRenderable(yourModelRenderable);
anchorNode.setParent(arFragment.getArSceneView().getScene());
}
Hope this helps.
Here is the code snippet if you want to place only one object.. Thanks #clinkz
override fun onUpdate(frameTime: FrameTime?) {
arFragment?.let { fragment ->
fragment.arSceneView?.let { sceneView ->
sceneView.arFrame?.let { frame ->
if (!placed) {
val trackable = frame.getUpdatedTrackables(Plane::class.java).iterator()
if (trackable.hasNext()) {
val plane = trackable.next() as Plane
if (plane.trackingState == TrackingState.TRACKING) {
fragment.planeDiscoveryController?.hide()
val hitTest =
frame.hitTest(frame.screenCenter().x, frame.screenCenter().y)
val hitTestIterator = hitTest.iterator()
if (hitTestIterator.hasNext()) {
val hitResult = hitTestIterator.next()
val modelAnchor = plane.createAnchor(hitResult.hitPose)
val anchorNode = AnchorNode(modelAnchor)
anchorNode.setParent(sceneView.scene)
val transformableNode =
TransformableNode(fragment.transformationSystem)
transformableNode.setParent(anchorNode)
transformableNode.renderable = this#ARActivity.modelRenderable
transformableNode.worldPosition = Vector3(
modelAnchor.pose.tx(),
modelAnchor.pose.compose(
Pose.makeTranslation(
0f,
0.05f,
0f
)
).ty(),
modelAnchor.pose.tz()
)
placed = true
}
}
}
}
}
}
}
}
private fun Frame.screenCenter(): Vector3 {
val vw = findViewById<View>(android.R.id.content)
return Vector3(vw.width / 2f, vw.height / 2f, 0f)
}
I'm currently working on a project which takes pictures from camera and saves the photoPath in a Database, this is working fine and actually I'm handling the memory correctly generating thumbnails when I load all images.
The thing I want is that I'm trying to dedicate threads to go loading images one per one in the layout, because for example, if I have 50, with normal load it shows the layout until all 50 are loaded, meanwhile it doesn't show anything.
I've already tried to implement this threads to load one, and then another one, but it's the same, until it loads all, it shows all, here my code:
String query = "Select id_reg_mem, information from Memory_REG where type = 'PHOTO' and id_memory =" + id_memory;
final Cursor resultado = memoryDB.rawQuery(query, null);
if(resultado.moveToFirst())
noPhotos = resultado.getCount();
for(int i=0; i<noPhotos; i++)
{
new Thread()
{
public void run()
{
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
updateNewPhoto(resultado.getString(1)); // I send the path from the DB to a method I made to add a tablerow with the image (inside an imageview)
}
});
}
}.start();
if(i + 1 == noPhotos)
break;
resultado.moveToNext();
}
Here this method, where I'm loading a single image to an ImageView inside a TableRow. This method is actually working to load all images from DB.
protected void updateNewPhoto(String path)
{
ImageView iv;
if(rows == null) {
rows = new ArrayList<TableRow>();
rows.add(new TableRow(TL.getContext()));
iv = new ImageView(TL.getContext());
iv.setLayoutParams(new TableRow.LayoutParams(250,250));
iv.setTag(DB_Utils.maxIDRegMem(memoryDB) - 1);
iv.setImageBitmap(getBitmapThumbnail(path));
rows.get(0).addView(iv);
TL.addView(rows.get(0));
count = 2;
}
else
{
iv = new ImageView(TL.getContext());
iv.setLayoutParams(new TableRow.LayoutParams(250,250));
iv.setTag(DB_Utils.maxIDRegMem(memoryDB) - 1);
iv.setImageBitmap(getBitmapThumbnail(path));
if(count == 2)
{
rows.get(rows.size() - 1).addView(iv);
count = 1;
}
else
{
rows.add(new TableRow(TL.getContext()));
rows.get(rows.size() - 1).addView(iv);
TL.addView(rows.get(rows.size() - 1));
count = 2;
}
}
Unfortunately for me, all images aren't shown until all of them are loaded (kind of 3 seconds it takes). I'm thinking in no limit of images, that's why I want a way where images be loaded one per one, not all together.
Any ideas you have? I appreciate your help.
Thanks.
First question on Stack Overflow, so bear with me! I am new to d3.js, but have been consistently amazed by what others are able to accomplish with it... and almost as amazed by how little headway I've been able to make with it myself! Clearly I'm not grokking something, so I hope that the kind souls here can show me the light.
My intention is to make a connected graph based on the CSV data. My CSV data has different information some of them need to be represented as a nodes, some of them need to be used as an information for ltool-tip. I can read the data from CSV by using this snippet of code:
d3.csv("data/project.csv", function(links) {
var nodesByName = {};
// Create nodes for each unique source and target.
links.forEach(function(link) {
link.source = nodeByName(link.Project);
link.target = nodeByName(link.Problem);
});
Which will connect the node P1, to three nodes Problems (URLs).
The problem comes after, I could not see the label on the selected nodes, How could I use the extract information in the CSV files such as "Date, Summary, URL". Is there any way to use mouse click, when I click the node I need its information appears on SVG board to be used for further analysis, such as showing the URL, short text of the summary, and when the user click on the board it should show the the complete information.
Here is the code that I used from this link
var width = 800,
height = 600;
var svg = d3.select("#visualization")
.append("svg")
.attr("width", width)
.attr("height", height)
.append("svg:g");
var force = d3.layout.force()
.gravity(0.2)
.distance(200)
.charge(-1500)
.size([width, height]);
var container = svg.append("g")
.attr("id", "container");
d3.csv("data/project.csv", function(links) {
var nodesByName = {};
// Create nodes for each unique source and target.
links.forEach(function(link) {
link.source = nodeByName(link.Project);
link.target = nodeByName(link.Problem);
});
// Extract the array of nodes from the map by name.
var nodes = d3.values(nodesByName);
//define a scale for color mapping
var colormapping = d3.scale.ordinal()
.domain([0,nodes.length])
.range(['#A700E6','#D95B96','#F4DA88','#22C1BE','#F24957','#DBEF91','#CF8EE8','#FF9B58','#B8FFC4','#91AEFF','#E873D3','#CCB298']);
//create label node tooltip
var labeltooltip = d3.select("body").append("div")
.attr("class", "labeltooltip")
.style("opacity", 1e-6);
var zoom = d3.behavior.zoom()
.scaleExtent([1, 10])
.on("zoom", function() {
container.attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
});
svg.call(zoom);
//links
var link = container.selectAll(".line")
.data(links)
.enter()
.append("line")
.attr("stroke-width",4)
// .attr("stroke-width",function (d) { return linethickness(d.value); })
.style("stroke", "gray");
// Create the node circles.
var node = container.selectAll(".node")
.data(nodes)
.enter()
.append("circle")
.attr("class", "node")
.attr("r", 20)
.attr("fill", function (d,i) {return d3.rgb(colormapping(i)); })
.call(force.drag);
// Start the force layout.
force
.nodes(nodes)
.links(links)
.on("tick", tick)
.start();
node.on("mousemove", function(d) {
labeltooltip.selectAll("p").remove();
labeltooltip.style("left", (d3.event.pageX+15) + "px").style("top", (d3.event.pageY-10) + "px");
labeltooltip.append("p").attr("class", "tooltiptext").html("<span>Id: </span>" + d.Score );
labeltooltip.append("p").attr("class", "tooltiptext").html("<span>Score: </span>" + d.Score);
});
node.on("mouseover", function(d) {
labeltooltip.transition()
.duration(500)
.style("opacity", 1);
link.style('stroke', function(l) {
if (d === l.source || d === l.target)
return d3.rgb('#C20606');
else
return 'gray';
});
link.style('opacity', function(o) {
return o.source === d || o.target === d ? 1 : 0;
});
node.style("opacity", function(o) {
if (o.id != d.id)
return neighboring(d.id, o.id) ? 1 : 0;
});
});
node.on("mouseout", function(d) {
labeltooltip.transition()
.duration(500)
.style("opacity", 1e-6);
link.style('stroke', 'gray');
link.style('opacity', 1);
node.style("opacity", 1);
});
var circletext = node.append("svg:text")
.text(function(d) {return d.name;})
.attr("class","labelText");
function tick() {
link.attr("x1", function(d) { return d.source.x; })
.attr("y1", function(d) { return d.source.y; })
.attr("x2", function(d) { return d.target.x; })
.attr("y2", function(d) { return d.target.y; });
node.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; });
circletext.attr("x", function(d) { return d.x-25; });
circletext.attr("y", function(d) { return d.y-25;});
}
function nodeByName(name) {
return nodesByName[name] || (nodesByName[name] = {name: name});
}
addZoomMoveIcon("#labelgraph");
});
UPDATE
My CSV data
Project,Problem, Score,Data,Summary,id
p1,Problem1,10,2014-09-04T13:55:05.623-04:00, text text text text, 1
p1,Problem2,5,2014-09-04T13:55:05.623-04:00, text text text text,2
p1,Problem3,11,2014-09-04T13:55:05.623-04:00, text text text text,3
The final results that I am aiming for would be like the following figure:
Where the yellow box should appear on the SVG when the "problem" node clicked.
The first issue you need to address is where to correctly add the node text. Right now you are nesting the text inside the circles, but the text labels need to be siblings of the circles (they do not even need to live right next to each circle). You can replace this:
var circletext = node.append("svg:text")
.text(function(d) {return d.name;})
.attr("class","labelText");
With:
var circletext = container.selectAll("g")
.data(nodes)
.enter()
.append("text").text(function(d) {return d.name})
.attr("class", "labelText");
(Reference: https://www.dashingd3js.com/svg-text-element)
Next though, if you want to display the Score/Data/Summary note that these are attached to the links, not the nodes (there are only three of them, not four). However, at the point of node creation, you can pass this info from the link to the node. Modify the nodeByName function to add the new attributes for the nodes:
function nodeByName(name,score,data,summary) {
return nodesByName[name] || (nodesByName[name] = {name: name, score: score, data: data, summary: summary});
}
Then modify the call to this function when the links are being created:
links.forEach(function(link) {
link.source = nodeByName(link.Project);
link.target = nodeByName(link.Problem,link.Score,link.Data,link.Summary);
});
To get the labeltooltip to display in a stationary spot, and not next to the nodes, you'll need to remove the bits on the node mouseover and mouseout events that move the div around, and probably just add the div to the html instead of dynamically adding it.
I have a JEditorPane that displays a link containing an image like so:
<a href='http://somesite.com/'>
<img src='someImage.png' />
</a>
When the JEditorPane display this as HTML, it puts a blue border around the image which I am trying to remove without any luck.
I want it to look like this inside of the jeditorpane:
image: (http://randomcloud.net/img/prob/valid.png)
But this is how the JEditorPane displays it:
image(http://randomcloud.net/img/prob/jeditorpane.png)
This is what I have tried so far, and it still is not working
editorPane = new JEditorPane("http://randomcloud.net/ads/index.php?id=1");
StyleSheet style = ((HTMLDocument)editorPane.getDocument()).getStyleSheet();
style.addRule("a img {text-decoration: none; border: none;}");
Any suggestions or insight ?
-Michel
HTLEditorKit's ImageView source. As you can see borderSize is set to DEFAULT_BORDER (2 pixels). You can replace the ImageView creation in your implementation of ViewFactory and override the method to provide desired border (0 as I understand).
protected void setPropertiesFromAttributes() {
StyleSheet sheet = getStyleSheet();
this.attr = sheet.getViewAttributes(this);
// Gutters
borderSize = (short)getIntAttr(HTML.Attribute.BORDER, isLink() ?
DEFAULT_BORDER : 0);
leftInset = rightInset = (short)(getIntAttr(HTML.Attribute.HSPACE,
0) + borderSize);
topInset = bottomInset = (short)(getIntAttr(HTML.Attribute.VSPACE,
0) + borderSize);
borderColor = ((StyledDocument)getDocument()).getForeground
(getAttributes());
AttributeSet attr = getElement().getAttributes();
// Alignment.
// PENDING: This needs to be changed to support the CSS versions
// when conversion from ALIGN to VERTICAL_ALIGN is complete.
Object alignment = attr.getAttribute(HTML.Attribute.ALIGN);
vAlign = 1.0f;
if (alignment != null) {
alignment = alignment.toString();
if ("top".equals(alignment)) {
vAlign = 0f;
}
else if ("middle".equals(alignment)) {
vAlign = .5f;
}
}
AttributeSet anchorAttr = (AttributeSet)attr.getAttribute(HTML.Tag.A);
if (anchorAttr != null && anchorAttr.isDefined
(HTML.Attribute.HREF)) {
synchronized(this) {
state |= LINK_FLAG;
}
}
else {
synchronized(this) {
state = (state | LINK_FLAG) ^ LINK_FLAG;
}
}
}
I think the blue border is just selection of text. Try to deselect the content or use jEditorPaneInstance.getCaret().setSelectionVisible(false);
#Alien595: On img tags, you can add an attribute named border that is 0.
Example:
<a href="your_link.html">
<img border="0" src="your_image.png"/>
</a>