/** * FIT TO SCREEN this function will set the scaling factors above such that all nodes are scaled * to within the screen viewing area */ public void FitToScreen() { // do not synchronize double largestXCoord = Double.MIN_VALUE; double smallestXCoord = Double.MAX_VALUE; double largestYCoord = Double.MIN_VALUE; double smallestYCoord = Double.MAX_VALUE; double x, y; // find the largest and smallest coords for all nodes DisplayManager.NodeInfo currentDisplayInfo; for (Enumeration nodes = MainClass.displayManager.GetNodeInfo(); nodes.hasMoreElements(); ) { currentDisplayInfo = (DisplayManager.NodeInfo) nodes.nextElement(); if (screenIsEmpty) { currentDisplayInfo.SetFitOnScreen(true); } // If the current node is displayed and old enough, // or if they are the first nodes to be drawn if (((currentDisplayInfo.GetDisplayThisNode() == true) && (currentDisplayInfo.GetFitOnScreen() == true))) { x = MainClass.locationAnalyzer.GetX(currentDisplayInfo.GetNodeNumber()); y = MainClass.locationAnalyzer.GetY(currentDisplayInfo.GetNodeNumber()); if (x > largestXCoord) { largestXCoord = x; } if (x < smallestXCoord) { smallestXCoord = x; } if (y > largestYCoord) { largestYCoord = y; } if (y < smallestYCoord) { smallestYCoord = y; } } } // here we use the following equations to set the scaling factors: // xScale*SmallestXCoord + XIntercept = 0 // xScale*LargestXCoord + XIntercept = window.width(); // // And the same for the y scaling factors. // Note that I want a border of <Margin>% of the screen on both sides Dimension d = getSize(); xScale = (d.width - 2 * (d.width / xMargin)) / (largestXCoord - smallestXCoord); yScale = (d.height - 2 * (d.height / yMargin)) / (largestYCoord - smallestYCoord); // this is to make sure that the x and y coordinates are not warped xScale = Math.min(xScale, yScale); yScale = xScale; xScaleIntercept = -xScale * smallestXCoord + d.width / xMargin; yScaleIntercept = -yScale * smallestYCoord + d.height / yMargin; screenIsEmpty = false; // if there are no nodes and none of this function was executed if (MainClass.displayManager.proprietaryNodeInfo.isEmpty()) { screenIsEmpty = true; xScale = 1; yScale = 1; xScaleIntercept = 0; yScaleIntercept = 0; } // System.out.println(xScale + " " + yScale); // System.out.println(xScaleIntercept + " " + yScaleIntercept); }