how to draw multiple arrow lines in extjs grid panel - extjs

i am tryting to draw multiple arrow lines between two grid panels, but i am able to draw only one arrow, when i start to draw the second arrow the first arrow is not showing.below is the code which i have tried.
This is where i am creating a arrow
Raphael.fn.arrow = function (x1, y1, x2, y2, size) {
// alert("raphael");
var angle = Math.atan2(x1-x2,y2-y1);
angle = (angle / (2 * Math.PI)) * 360;
var arrowPath = this.path("M" + x2 + " " + y2 + " L" + (x2 - size) + " " + (y2 - size) + " L" + (x2 - size) + " " + (y2 + size) + " L" + x2 + " " + y2 ).attr("fill","black").rotate((90+angle),x2,y2);
var linePath = this.path("M" + x1 + " " + y1 + " L" + x2 + " " + y2);
return [linePath,arrowPath];
};
drag initialization
onInitDrag : function(x,y){
var data = this.dragData;
this.ddel.innerHTML = this.grid.getDragDropText();
//alert("this.ddel :"+this.ddel.innerHTML);
this.proxy.update(this.ddel);
// fire start drag?
//i would say yes ;-)
this.onStartDrag(x,y);
},
/*
* onStartDrag is called when you initiate the drag action
* it stores the mouse coordinates and create the SVG canvas
*/
onStartDrag : function(x, y){
alert(Ext.getCmp('leftGridId'));
this.arrowStart = {x:x, y:y};
alert("on Start Drag :"+x+","+y);
this.raphaelCanvas = new Raphael(0,0,2000,2000); //could be better...
//apply body.no-cursor (cursor : none) to hide the cursor
//cursor:pointer is nice too
//alert("after StartDrag :"+x+","+y);
},
/*
* onDrag is called on mousemove
* it clears the canvas and draw the arrow again
*/
onDrag : function(e){
//alert("on drag");
//alert("raphael arrow");
this.raphaelCanvas.clear();
var arrow = this.raphaelCanvas.arrow(this.arrowStart.x, this.arrowStart.y, e.xy[0], e.xy[1],8);
// alert("after mapping");
},
/*
* onEndDrag is called when you drop whatever you were dragging
* it removes the SVG canvas from the document
*/
onEndDrag : function(){
alert("on end drag");
//this.raphaelCanvas.remove();
//delete this.raphaelCanvas;
this.raphaelCanvas.renderfix();
if(!onStartDrag){
/this.raphaelCanvas.remove();
//delete this.raphaelCanvas;
}
else{
onStartDrag();
}
}

There can be serious improvements to your code but try these quick changes if at;east your two arrows start appearing ....
Raphael.fn.arrow = function (x1, y1, x2, y2, size) {
// alert("raphael");
var angle = Math.atan2(x1-x2,y2-y1);
angle = (angle / (2 * Math.PI)) * 360;
var arrowPath = this.path("M" + x2 + " " + y2 + " L" + (x2 - size) + " " + (y2 - size) + " L" + (x2 - size) + " " + (y2 + size) + " L" + x2 + " " + y2 ).attr("fill","black").rotate((90+angle),x2,y2);
var linePath = this.path("M" + x1 + " " + y1 + " L" + x2 + " " + y2);
return [linePath,arrowPath];
};
this.raphaelCanvas = new Raphael(0,0,2000,2000);
this.raphaelCanvas.renderfix();
drag initialization
onInitDrag : function(x,y){
var data = this.dragData;
this.ddel.innerHTML = this.grid.getDragDropText();
//alert("this.ddel :"+this.ddel.innerHTML);
this.proxy.update(this.ddel);
// fire start drag?
//i would say yes ;-)
this.onStartDrag(x,y);
},
/*
* onStartDrag is called when you initiate the drag action
* it stores the mouse coordinates and create the SVG canvas
*/
onStartDrag : function(x, y){
alert(Ext.getCmp('leftGridId'));
this.arrowStart = {x:x, y:y};
alert("on Start Drag :"+x+","+y);
//this.raphaelCanvas = new Raphael(0,0,2000,2000); //could be better...
//apply body.no-cursor (cursor : none) to hide the cursor
//cursor:pointer is nice too
//alert("after StartDrag :"+x+","+y);
},
/*
* onDrag is called on mousemove
* it clears the canvas and draw the arrow again
*/
onDrag : function(e){
//alert("on drag");
//alert("raphael arrow");
//this.raphaelCanvas.clear();
var arrow = this.raphaelCanvas.arrow(this.arrowStart.x, this.arrowStart.y, e.xy[0], e.xy[1],8);
// alert("after mapping");
},
/*
* onEndDrag is called when you drop whatever you were dragging
* it removes the SVG canvas from the document
*/
onEndDrag : function(){
alert("on end drag");
//this.raphaelCanvas.remove();
//delete this.raphaelCanvas;
//this.raphaelCanvas.renderfix();
if(!onStartDrag){
//this.raphaelCanvas.remove();
//delete this.raphaelCanvas;
}
else{
onStartDrag();
}
}

Related

Leaflet map renderer L.svg changed already existing canvas markers

I have set renderer value L.svg with a padding of 100 for map as shown below
Before setting this option canvas markers were visible like this
After setting renderer option markers are visible like this
Code to render canvas marker is as follows
(function () {
var proto = L.Canvas.prototype;
var prev = proto._updateCircle;
proto._updateCircle = function (layer) {
// only circleMARKER, not the standard circle
if (layer instanceof L.Circle)
return prev.call(this, layer);
if (!this._drawing || layer._empty()) {
return;
}
var p = layer._point,
ctx = this._ctx,
r = Math.max(Math.round(layer._radius), 1)
//,s = (Math.max(Math.round(layer._radiusY), 1) || r) / r;
var options = layer.options;
var scale = Math.pow(2, this._map.getZoom()) * 256 / Math.PI / 6378137;
scale = Math.pow(scale, options.boostExp) * options.boostScale;
r = r * scale;
if (!options.boostType) {
ctx.beginPath();
ctx.arc(p.x, p.y, r, 0, Math.PI * 2, false);
this._fillStroke(ctx, layer);
}
else switch (options.boostType) {
case 'ball':
if (options.fill) {
if (options.stroke && options.weight !== 0)
r = r + options.weight * 0.5 * scale;
let grd = ctx.createRadialGradient(p.x - r / 2, p.y - r / 2, 0, p.x, p.y, 1.5 * r);
grd.addColorStop(0, options.fillColor);
grd.addColorStop(1, options.color);
ctx.beginPath();
ctx.fillStyle = grd;
ctx.arc(p.x, p.y, r, 0, Math.PI * 2, false);
ctx.fill(options.fillRule || 'evenodd');
}
break;
case 'balloon':
if (options.fill) {
if (options.stroke && options.weight !== 0)
r = r + options.weight * 0.5 * scale;
// this condition is used to identify if employee is at suggested location and draw a star on top of marker
let grd = ctx.createRadialGradient(p.x - r / 2, p.y - r / 2 - 2 * r, 0, p.x, p.y - 2 * r, 2.5 * r);
grd.addColorStop(0, options.fillColor);
grd.addColorStop(1, options.color);
ctx.beginPath();
ctx.fillStyle = grd;
ctx.moveTo(p.x, p.y);
ctx.lineTo(p.x - r, p.y - 2 * r);
ctx.lineTo(p.x + r, p.y - 2 * r);
ctx.lineTo(p.x, p.y);
ctx.arc(p.x, p.y - 2 * r, r, 0, Math.PI * 2, false);
ctx.closePath();
ctx.fill(options.fillRule = 'nonzero');
if(options.suggestedLocation)
drawStar(p.x, p.y - 2 * r, 5, 3, 1.5, ctx);
}
break;
case 'borderedball':
if (options.fill) {
if (options.stroke && options.weight !== 0)
r = r + options.weight * 0.5 * scale;
let grd = ctx.createRadialGradient(p.x - r / 2, p.y - r / 2, 0, p.x, p.y, 1.5 * r);
grd.addColorStop(0, options.fillColor);
grd.addColorStop(1, options.color);
ctx.beginPath();
drawStar(p.x, p.y, 5, r, r, ctx);
ctx.fillStyle = grd;
ctx.arc(p.x, p.y, r, 0, Math.PI * 2, false);
ctx.fill(options.fillRule || 'evenodd');
}
break;
default:
if (options.stroke && options.weight !== 0) {
ctx.beginPath();
ctx.arc(p.x, p.y, r + options.weight * 0.5 * scale, 0, Math.PI * 2, false);
ctx.fillStyle = options.color;
ctx.fill(options.fillRule || 'evenodd');
}
if (options.fill) {
ctx.beginPath();
ctx.arc(p.x, p.y, r - ((options.stroke && options.weight !== 0) ? options.weight * 0.5 * scale : 0), 0, Math.PI * 2, false);
ctx.fillStyle = options.fillColor || options.color;
ctx.fill(options.fillRule || 'evenodd');
}
}
};
var xproto = L.CircleMarker.prototype;
var xprev = xproto._containsPoint;
xproto._containsPoint = function (p) {
if (this instanceof L.Circle)
return xprev.call(this, p);
var r = this._radius;
var options = this.options;
var scale = Math.pow(2, this._map.getZoom()) * 256 / Math.PI / 6378137;
scale = Math.pow(scale, options.boostExp) * options.boostScale;
r = r * scale;
r = r + (this.options.stroke ? this.options.weight * scale / 2 : 0);
if (options.boostType === 'balloon')
p = new L.Point(p.x, p.y + 2 * r);
return p.distanceTo(this._point) <= r + this._clickTolerance();
// clickTolerance only for mobile! (seems to be fixed with LL1.4)
// return p.distanceTo(this._point) <= r + ((L.Browser.touch && L.Browser.mobile) ? 10 : 0);
};
var cproto = L.Layer.prototype;
var cprev = cproto._openPopup;
cproto._openPopup = function (e) {
var layer = e.layer || e.target;
if (!(layer instanceof L.CircleMarker) || (layer instanceof L.Circle))
return cprev.call(this, e);
if (!this._popup) {
return;
}
if (!this._map) {
return;
}
// prevent map click
L.DomEvent.stop(e);
// treat it like a marker and figure out
// if we should toggle it open/closed
if (this._map.hasLayer(this._popup) && this._popup._source === layer) {
this.closePopup();
} else {
this.openPopup(layer._latlng);
layer.on('preclick', L.DomEvent.stopPropagation);
}
};
var pproto = L.Popup.prototype;
var p_getAnchor = pproto._getAnchor;
pproto._getAnchor = function () {
if (!(this._source instanceof L.CircleMarker) || this._source instanceof L.Circle)
return p_getAnchor.call(this);
var r = this._source._radius;
var options = this._source.options;
//var zoomScale;
var scale = Math.pow(2, this._map.getZoom()) * 256 / Math.PI / 6378137;
scale = Math.pow(scale, options.boostExp) * options.boostScale;
if (options.boostType === 'balloon')
r = 2.5 * r * scale;
else
r = 0.5 * r * scale;
// Where should we anchor the popup on the source layer?
return L.point(this._source && this._source._getPopupAnchor ? this._source._getPopupAnchor() : [0, -r]);
};
})();
function drawDiamond(context, x, y, width, height) {
context.moveTo(x, y);
// top left edge
context.lineTo(x - width / 2, y + height / 2);
// bottom left edge
context.lineTo(x, y + height);
// bottom right edge
context.lineTo(x + width / 2, y + height / 2);
}
function drawStar(cx, cy, spikes, outerRadius, innerRadius, ctx) {
var rot = Math.PI / 2 * 3;
var x = cx;
var y = cy;
var step = Math.PI / spikes;
ctx.beginPath();
ctx.moveTo(cx, cy - outerRadius)
for (let i = 0; i < spikes; i++) {
x = cx + Math.cos(rot) * outerRadius;
y = cy + Math.sin(rot) * outerRadius;
ctx.lineTo(x, y)
rot += step
x = cx + Math.cos(rot) * innerRadius;
y = cy + Math.sin(rot) * innerRadius;
ctx.lineTo(x, y)
rot += step
}
ctx.lineTo(cx, cy - outerRadius);
ctx.closePath();
ctx.lineWidth = 5;
ctx.strokeStyle = 'blue';
ctx.stroke();
ctx.fillStyle = 'skyblue';
ctx.fill();
}
Please suggest a solution to render canvas markers as they were before setting renderer value to L.svg.

CS50 filter: I'm getting a new error which I'm not familiar with

I've been working on the edge filter function for cs50 for a few hours now. It looks fine to me but I'm receiving a pretty scary looking error which I don't understand here is my code:
// Detect edges
void edges(int height, int width, RGBTRIPLE image[height][width])
{
RGBTRIPLE copy[height][width];
for (int h = 0; h < height; h++)
{
for (int w = 0; w < width; w++)
{
copy[h][w] = image[h][w];
}
}
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
float gxred = 0;
float gxgreen = 0;
float gxblue = 0;
float gyred = 0;
float gygreen = 0;
float gyblue = 0;
for (int r = -1; r < 2; r++)
{
for (int s = -1; s < 2; s++)
{
if ((y + r < height && y + r >= 0) && (x + s < width && x + s >= 0))
{
if (r == -1)
{
gxred = copy[y + r][x + s].rgbtRed * s;
gxgreen = copy[y + r][x + s].rgbtGreen * s;
gxblue = copy[y + r][x + s].rgbtBlue * s;
gyred = copy[x + s][y + r].rgbtRed * s;
gygreen = copy[x + s][y + r].rgbtGreen * s;
gyblue = copy[x + s][y + r].rgbtBlue * s;
}
if (r == 0)
{
gxred = copy[y + r][x + s].rgbtRed * (s * 2);
gxgreen = copy[y + r][x + s].rgbtGreen * (s * 2);
gxblue = copy[y + r][x + s].rgbtBlue * (s * 2);
gyred = copy[x + s][y + r].rgbtRed * (s * 2);
gygreen = copy[x + s][y + r].rgbtGreen * (s * 2);
gyblue = copy[x + s][y + r].rgbtBlue * (s * 2);
}
if (r == 1)
{
if (s * s == 1)
{
gxred = copy[y + r][x + s].rgbtRed * (s * s);
gxgreen = copy[y + r][x + s].rgbtGreen * (s * s);
gxblue = copy[y + r][x + s].rgbtBlue * (s * s);
gyred = copy[x + s][y + r].rgbtRed * (s * s);
gygreen = copy[x + s][y + r].rgbtGreen * (s * s);
gyblue = copy[x + s][y + r].rgbtBlue * (s * s);
}
else
{
gxred = copy[y + r][x + s].rgbtRed * (s + 1);
gxgreen = copy[y + r][x + s].rgbtGreen * (s + 1);
gxblue = copy[y + r][x + s].rgbtBlue * (s + 1);
gyred = copy[x + s][y + r].rgbtRed * (s + 1);
gygreen = copy[x + s][y + r].rgbtGreen * (s + 1);
gyblue = copy[x + s][y + r].rgbtBlue * (s + 1);
}
}
}
}
}
image[y][x].rgbtRed = round(sqrt((gxred * gxred) + (gyred * gyred)));
image[y][x].rgbtGreen = round(sqrt((gxgreen * gxgreen) + (gygreen * gygreen)));
image[y][x].rgbtBlue = round(sqrt((gxblue * gxblue) + (gyblue * gyblue)));
image[y][x].rgbtRed = image[y][x].rgbtRed % 256;
image[y][x].rgbtGreen = image[y][x].rgbtGreen % 256;
image[y][x].rgbtBlue = image[y][x].rgbtBlue % 256;
}
}
return;
}
And here is my error
helpers.c:169:37: runtime error: 261 is outside the range of representable values of type
'unsigned char'
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==5405==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x7ffea18b01fa (pc
0x000000429bb3 bp 0x7ffea18af1a0 sp 0x7ffea17fe250 T5405)
==5405==The signal is caused by a READ memory access.
#0 0x429bb2 (/home/ubuntu/pset4/filter/filter+0x429bb2)
#1 0x42330e (/home/ubuntu/pset4/filter/filter+0x42330e)
#2 0x7f7c0b22eb96 (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#3 0x402e19 (/home/ubuntu/pset4/filter/filter+0x402e19)
UndefinedBehaviorSanitizer can not provide additional info.
==5405==ABORTING
This directs me to this line at the end:
image[y][x].rgbtGreen = round(sqrt((gxgreen * gxgreen) + (gygreen * gygreen)));
I'd be really grateful if someone could explain what this kind of error means. And also, any critique on my code would be much appreciated, I'm trying to get good at this.
RGB values can be any value between 0 and 255.
You are somehow assigning your RGB value in that line to 261 which is outside of the range.
I would print the value in the following code before assigning to rgb value.
round(sqrt((gxgreen * gxgreen) + (gygreen * gygreen)))
Then check why inside of round gives 261. Once you fix this you are good to go.

AngularJS : using Two.js, Cannot read property 'appendChild' of null

I want to create an edit polygon using AngularJS : i used this function but i have error :Cannot read property 'appendChild' of null.
Controller AngularJS :
var two = new Two({ type: Two.Types.svg }).appendTo(document.getElementById("ImgCamera"));
var polygon = new Two.Polygon(10,10,5,4)
$scope.drawWheel = function () {
var center_X = 420;
var center_Y = 140;
var radius = 100;
var ellipse = $scope.two.makeEllipse(center_X, center_Y, radius, radius);
ellipse.linewidth = 0;
ellipse.fill = "#66BB6A";
var spoke_color = "#FF5722";
var x1 = center_X;
var y1 = center_Y;
for (var i = 0; i < self.spokes; i++) {
var x2 = x1 + radius * Math.cos(i * 5);
var y2 = y1 + radius * Math.sin(i * 5);
var line = self.two.makeLine(x1, y1, x2, y2);
line.linewidth = 3;
line.stroke = "white";
}
self.two.update();
}
HTML code :
<div id="ImgCamera">
<div ng-init="drawWheel()"></div>
</div>

Add header and footer to XPS print output

XpsDocument is loaded from disk
Create a FixedDocumentSequence via XpsDocument.GetFixedDocumentSequence Method ()
Display the via a DocumentViewer
Would like to add to add header and footer to print
I don't need to add the header and footer back to the XPS document - only to the print output
I tried implementing DocumentPaginator but cannot get the sizing or placement to work
NOT the same as this footer to FlowDocument
I use the solution there for FlowDocuments just fine
Convert XAML Flow Document to XPS with Style
On the FixedDocumentSequence the sizing comes from document (I guess)
For example could mix landscape and portrait
I cannot figure out how to hook into the sizing and make room for a header and footer
I can stamp a header on it but it is over the top of the page
And landscape pages are cut off
Cannot assign a PageSize when it comes from a FixedDocumentSequence
As stated in the link it is a suggested pages size
DocumentPage.Size is read only
Even if I create DocumentPage of the Size I want when the page is loaded using DocumentPaginator.GetPage then the Size is overwritten
Even worse the DocumentPaginator does not seem to be properly aware of the Size as it does not deal with mixed landscape and portrait properly. Landscape is printed portrait and just runs off the page.
some one asked me to post code
there also might be a just plain better approach
see footer to FlowDocument for how to use it
this is where it breaks
// this gets the page size from GetPage - ignores size above
public class DocumentPaginatorWrapperXPS : DocumentPaginator
{
System.Windows.Size m_PageSize;
System.Windows.Size m_Margin;
DocumentPaginator m_Paginator;
FixedDocumentSequence fixedDocumentSequence;
Typeface m_Typeface;
private string printHeader;
private int? sID;
private string docID;
public DocumentPaginatorWrapperXPS(FixedDocumentSequence FixedDocumentSequence, System.Windows.Size margin, string PrintHeader, int? SID, string DOCID)
{
//m_PageSize = pageSize;
//m_PageSize = new Size(800, 600);
fixedDocumentSequence = FixedDocumentSequence;
m_Margin = margin;
m_Paginator = fixedDocumentSequence.DocumentPaginator;
//m_Paginator.PageSize = new System.Windows.Size(m_PageSize.Width - margin.Width * 2,
// //m_PageSize.Height - margin.Width * 2);
printHeader = PrintHeader;
sID = SID;
docID = DOCID;
}
Rect Move(Rect rect)
{
if (rect.IsEmpty)
{
return rect;
}
else
{
return new Rect(rect.Left + m_Margin.Width, rect.Top + m_Margin.Height,
rect.Width, rect.Height);
}
}
private Size sizeXPS;
public override DocumentPage GetPage(int pageNumber)
{
System.Windows.Documents.DocumentPage page = m_Paginator.GetPage(pageNumber);
Debug.WriteLine(page.Size.Width + " " + page.Size.Height);
m_Paginator.PageSize = new System.Windows.Size(page.Size.Width/2 - m_Margin.Width * 2, page.Size.Height/2 - m_Margin.Height * 2);
page = m_Paginator.GetPage(pageNumber); // this get the page size from GetPage - ignores size above
Debug.WriteLine(page.Size.Width + " " + page.Size.Height);
DynamicDocumentPaginator paginatorPage = fixedDocumentSequence.DocumentPaginator as DynamicDocumentPaginator;
paginatorPage.PageSize = new System.Windows.Size(page.Size.Width / 2 - m_Margin.Width * 2, page.Size.Height / 2 - m_Margin.Height * 2);
sizeXPS = new System.Windows.Size(page.Size.Width / 2 - m_Margin.Width * 2, page.Size.Height / 2 - m_Margin.Height * 2);
page = paginatorPage.GetPage(pageNumber); // still does not change the page size
Debug.WriteLine(page.Size.Width + " " + page.Size.Height);
//page.PageSize = new System.Windows.Size(m_PageSize.Width - margin.Width * 2,
//m_PageSize.Height - margin.Width * 2);
//page.Size = new System.Windows.Size(page.Size.Width - m_Margin.Width * 2, page.Size.Height - m_Margin.Height * 2);
//page.Size.Width = page.Size.Width - m_Margin.Width * 2;
// Create a wrapper visual for transformation and add extras
ContainerVisual newpage = new ContainerVisual();
DrawingVisual title = new DrawingVisual();
using (DrawingContext ctx = title.RenderOpen())
{
if (m_Typeface == null)
{
m_Typeface = new Typeface("Segoe UI Symbol"); //Ariel
}
//FormattedText text = new FormattedText("Attorney eyes only \uE18B \u1F440 Page " + (pageNumber + 1),
// System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
// m_Typeface, 14, System.Windows.Media.Brushes.Black);
string pageS = "m_PageSize.Width " + m_PageSize.Width + " m_Margin.Width " + m_Margin.Width + " m_PageSize.Height " + m_PageSize.Height + " m_Margin.Height " + m_Margin.Height + Environment.NewLine +
"page.Size.Width " + page.Size.Width + " page.Size.Height " + page.Size.Height;
FormattedText header = new FormattedText("\u1F440 " + printHeader + Environment.NewLine + pageS,
System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
m_Typeface, 14, System.Windows.Media.Brushes.Black);
ctx.DrawText(header, new System.Windows.Point(96 / 2, -96 / 4)); // 1/4 inch above page content
//text = new FormattedText(pageS, System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
// m_Typeface, 14, System.Windows.Media.Brushes.Black);
string goGabe = string.Empty;
if (sID != null)
{
goGabe += Environment.NewLine + "Gabriel Docs™ sysDocID: " + sID;
if (!string.IsNullOrEmpty(docID))
goGabe += " docID: " + docID;
}
goGabe += Environment.NewLine + "Page: " + (pageNumber + 1) + " Date: " + DateTime.Now.ToString() + " User: " + App.StaticGabeLib.CurUserP.UserID;
FormattedText footer = new FormattedText(goGabe
, System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
m_Typeface, 14, System.Windows.Media.Brushes.Black);
ctx.DrawText(footer, new System.Windows.Point(96 / 2, page.Size.Height - m_Margin.Height));
//ctx.DrawText(footer, new System.Windows.Point(96 / 2, m_Paginator.PageSize.Height - m_Margin.Height));
}
DrawingVisual background = new DrawingVisual();
using (DrawingContext ctx = background.RenderOpen())
{
ctx.DrawRectangle(new SolidColorBrush(System.Windows.Media.Color.FromRgb(240, 240, 240)), null, page.ContentBox);
}
newpage.Children.Add(background); // Scale down page and center
ContainerVisual smallerPage = new ContainerVisual();
smallerPage.Children.Add(page.Visual);
smallerPage.Transform = new MatrixTransform(0.8, 0, 0, 0.8, 0.1 * page.ContentBox.Width, 0.1 * page.ContentBox.Height);
newpage.Children.Add(smallerPage);
newpage.Children.Add(title);
newpage.Transform = new TranslateTransform(m_Margin.Width, m_Margin.Height);
return new DocumentPage(newpage, m_PageSize, Move(page.BleedBox), Move(page.ContentBox));
}
public override bool IsPageCountValid
{
get
{
return m_Paginator.IsPageCountValid;
}
}
public override int PageCount
{
get
{
return m_Paginator.PageCount;
}
}
public override System.Windows.Size PageSize
{
get
{
Debug.WriteLine("PageSize " + sizeXPS.Width + " " + sizeXPS.Height);
return sizeXPS; // this is not called
//m_Paginator.PageSize;
}
set
{
sizeXPS = value;
// m_Paginator.PageSize = value;
}
}
public override IDocumentPaginatorSource Source
{
get
{
return m_Paginator.Source;
}
}
}

Compiler error while writing to a file

I'm getting the error:-
error: cannot find symbol
tofile.println("Dancing" + " " + danceminutes + " " + bpm);
^
symbol: variable tofile
location: class CreateFile
I'm not sure why.
// writing to a file
PrintWriter toFile = new PrintWriter(new FileWriter("exLog.txt"));
Random randy = new Random();
int count = randy.nextInt(12) + 19;
for (int i = count; i > 0; i--) {
int exercise = randy.nextInt(3);
if (exercise == 0) {
int minutesOne = randy.nextInt(47) + 14;
int minutesTwo = randy.nextInt(62) + 59;
int minutesThree = randy.nextInt(122) + 119;
int roulette = randy.nextInt(100);
if (roulette <= 74) {
int runoneminutes = minutesOne;
double speed = 4.9 + (16.1 - 4.9) * randy.nextDouble();
double distance = speed * runoneminutes/60;
tofile.println("Running" + " " + runoneminutes + " " + distance);
}
else if (roulette > 74 && roulette < 96) {
int runtwominutes = minutesTwo;
double twospeed = 4.9 + (16.1 - 4.9) * randy.nextDouble();
double twodistance = twospeed * runtwominutes/60;
tofile.println("Running" + " " + runtwominutes + " " + twodistance);
}
else if (roulette >= 96) {
int runthreeminutes = minutesThree;
double threespeed = 4.9 + (16.1 - 4.9) * randy.nextDouble();
double threedistance = threespeed * runthreeminutes/60;
tofile.println("Running" + " " + runthreeminutes + " " + threedistance);
}
}
if (exercise == 1) {
int bikeminutesOne = randy.nextInt(62) + 29;
int bikeminutesTwo = randy.nextInt(212) + 89;
int bikeroulette = randy.nextInt(100);
if (bikeroulette <= 49) {
int bikeoneminutes = bikeminutesOne;
double bikeonespeed = 7.9 + (25.1 - 7.9) * randy.nextDouble();
double bikeonedistance = bikeonespeed * bikeoneminutes/60;
tofile.println("Biking" + " " + bikeoneminutes + " " + bikeonedistance);
}
else if (bikeroulette > 49) {
int biketwominutes = bikeminutesTwo;
double biketwospeed = 7.9 + (25.1 - 7.9) * randy.nextDouble();
double biketwodistance = biketwospeed * biketwominutes/60;
tofile.println("Biking" + " " + biketwominutes + " " + biketwodistance);
}
}
if (exercise == 2) {
int exercises = randy.nextInt(15) + 1;
int reps = randy.nextInt(37) + 9;
double liftminutes;
int liftminutes = 5*reps*exercises/60 + 2*(exercises-1);
tofile.println("Lifting" + " " + liftminutes + " " + reps);
}
if (exercise == 3) {
int danceminutes = randy.nextInt(90) + 29;
double bpm = 79.9 + (220 - 79.9) * randy.nextDouble();
tofile.println("Dancing" + " " + danceminutes + " " + bpm);
}
}
toFile.close(); //saving output file
} // end main
} // end CreateFile class
The variable name is toFile. The compiler is complaining about the use of 'tofile'.

Resources