Wikipedia:Reference desk/Archives/Computing/2015 March 23
Computing desk | ||
---|---|---|
< March 22 | << Feb | March | Apr >> | March 24 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
March 23
[edit]Special magnification software wanted
[edit]I am guessing the answer will be "no such software exits", but I'm going to ask anyway.
I often find spreadsheets (actually PDF snapshots of spreadsheets), which are so large that I can't view a cell and both the row and column headings at once on a single screen. For example, this frequently comes up when viewing a nutrition data grid for a restaurant.
So then, what I would like is software that would allow me to click on a spot on the screen, magnify that, but also scroll all the way to the left, take a snapshot of that heading, and display that magnified, and then scroll all the way to the top, take a snapshot of that heading, and magnify it. So, if I had spreadsheet PDF with items A-Z in one direction and 1-99 in the other, then cell Y98 should be magnified like this:
+-----+ | 98 | +-----+ +---+ +-----+ | Y | | Y98 | +---+ +-----+
(Of course, "Y" would be something like "Chili-cheese fries", "98" would be something like "Trans fats (g)", and "Y98" would be something like "12".)
Now, once in a PDF, I don't think there's any concept of an actual cell any more, so the software would just have to magnify a certain area around the current selected point and a portion all the way to the left of it and all the way to the top of it. It might be necessary to be able to dynamically adjust the locations and sizes a bit to get it to work. Being able to toggle to view the right and bottom instead of left and top might also be useful, as I can imagine this tool being used to read a graph, too, and see the axis markings while doing so. Also, being able to scroll up and down while in this magnification mode would be useful, so I could scroll from cell Y98 to W93 without having to turn off the magnifier, find the new spot, then turn it back on.
So, does this tool exist, or do I need to write it ? StuRat (talk) 03:31, 23 March 2015 (UTC)
- The tool you're looking for does exist. It's an accessibility feature. In Adobe Reader, it's found under View->Zoom->Loupe Tool. --173.49.16.112 (talk) 03:38, 23 March 2015 (UTC)
- Hmm... I just noticed that you're looking for more than just a magnifier. The loupe tool in Adobe Reader doesn't do everything you wanted it to do, but I hope it's still helpful to you. --173.49.16.112 (talk) 03:47, 23 March 2015 (UTC)
- No, magnification is simple enough without that tool. However, I did find exactly what I want as "Window > Spreadsheet Split" for Adobe Acrobat X Standard, described here:[1]. Unfortunately, that functionality doesn't appear to be included in Acrobat Reader. StuRat (talk) 04:17, 23 March 2015 (UTC)
- The feature you mentioned is available in this freeware PDF viewer. --173.49.16.112 (talk) 04:40, 23 March 2015 (UTC)
- Thanks:
- 1) What are the commands to do so ?
- 2) Is that functionality only available during an evaluation period ? StuRat (talk) 18:09, 23 March 2015 (UTC)
- 1) To create a split view of a document, the command is Windows->Split. You can choose between Horizontal Split & Vertical Split. Let's say you choose Horizontal Split (which I think is incorrectly named), you now have 2 vertically=stacked panes showing different parts of the document. Adjust the zoom of both panes so that in both of them the width of the document fits the width of the pane. You can make the upper pane show only the header row of a spreadsheet, and use the bottom pane for the actual browsing. You can use the Loupe tool (View->Zoom->Loupe Tool) to magnify the tiny spreadsheet cells. If you want to see the corresponding column heading, move the loupe tool straight up to the upper pane to the upper pane. Unfortunately, you can't use this trick on both the column and row headings at the same time.
- 2) The basic version of the viewer is free. If you don't buy an upgrade, you just don't get the advanced features, but features in the free version don't expire. IMO, the publisher is really generous with features even with the free version. --173.49.16.112 (talk) 00:57, 24 March 2015 (UTC)
- Thanks. Re: "Unfortunately, you can't use this trick on both the column and row headings at the same time" ... that's rather critical, I'm afraid. StuRat (talk) 03:34, 24 March 2015 (UTC)
Note that while I mentioned PDF files in the Q, I would like a broader solution that works on any image or web page. I suppose other images can be converted to PDF files, but a web page too large for a screen grab and composed of multiple images might be difficult to convert to a single PDF image. Perhaps a browser add-on would be the best choice ? StuRat (talk) 18:14, 23 March 2015 (UTC)
- For what it's worth, in excel the feature is called freeze panes . Vespine (talk) 22:53, 23 March 2015 (UTC)
Formatting numbers in Java with Swing
[edit]I have a JTextField which has a double in it that I'm trying to format with two places behind the decimal. It's a dollar figure, so two places would be best. I was able to use NumberFormat when I was running the program in the console but now that I'm trying to display it in a GUI I can't seem to get the code figured out. Right now, I have this:
totalField.setText(Double.toString(total));
When I was using the console, I had this:
System.out.println("Your sales were " + nf.format(sales));
Can anyone help me out? Thanks, Dismas|(talk) 05:37, 23 March 2015 (UTC)
- As far as I'm concerned, you can use NumberFormat for this too. Or you can use String.format with "%.02f". But it may be best to use a JFormattedTextField with a genuine currency format (and not just the assumption that all currencies have the same format). This example uses all three (one per column) for some random values:
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
import java.text.*;
import java.util.*;
public class Num extends JFrame{
public static final void main (String [] args){
new Num();
}
public Num() {
setLocation(100,100);
setLayout(new GridLayout(0,3));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container content = getContentPane();
DecimalFormat df = new DecimalFormat("#.00");
Random rnd = new Random();
NumberFormat currency_format = NumberFormat.getCurrencyInstance(Locale.UK);
currency_format.setMaximumFractionDigits(2);
NumberFormatter currency_formatter = new NumberFormatter(currency_format);
currency_formatter.setAllowsInvalid(false);
content.add(new JLabel("String.format"));
content.add(new JLabel("DecimalFormat"));
content.add(new JLabel("FormattedField"));
for(int i=0; i < 20; i++){
float randval = rnd.nextFloat() * 1000f;
content.add(new JTextField(String.format("%.02f", randval)));
content.add(new JTextField(df.format(randval)));
JFormattedTextField ffield = new JFormattedTextField(currency_formatter);
ffield.setValue(randval);
content.add(ffield);
}
setVisible(true);
pack();
}
}
- But considerable caution should be used when storing and doing calculations with currencies using floats or doubles - cf Effective Java (§31 in first ed., §48 in second ed.). -- Finlay McWalterᚠTalk 14:47, 23 March 2015 (UTC)
- Yes, storing currency (or any integer) as a real numbers (floats, doubles, etc.) introduces potential problems with rounding in different ways. For example, the TGI Friday's Give Me More Stripes loyalty club uses floats for their loyalty points, and rounds differently depending on whether you look your points up at home (rounds up) or at the restaurant (rounds down). To avoid this, always store as integers. (To include cents, store the currency as cents and divide by 100 when displaying.) Also, using reals, your calc for 1.01 + .37 likely ends up with something like 1.37999999999999999873, so rounding is needed even in places you wouldn't expect, as truncating would produce the wrong answer half the time.
- One place you might want to use reals with money is in compound interest calculations, to preserve accuracy (just remember to round the final result consistently). StuRat (talk) 17:49, 23 March 2015 (UTC)
PHP function question
[edit]If I have 2 php files and in one php file:
function getMoneyRate($location){here is my if statement}
Okay so what would I need to write in the 2nd file to get the information from the function in the first php file into a variable in the 2nd file? — Preceding unsigned comment added by 204.42.31.250 (talk) 11:15, 23 March 2015 (UTC)
- Your question is very vague. This answer must, therefore, be very vague. Assume I have a PHP file with a function called getMoneyRate in it. I have another PHP file. In the second one, I want to use the function getMoneyRate. To do so, I just add this line in the second file: include("WhateverTheNameOfTheFirstPhpFileIs.php"); 209.149.113.207 (talk) 12:12, 23 March 2015 (UTC)
Sorry for the vague question. I am looking for more of a example i think? I am struggling to understand this. If I have $MoneyRate in the file without the fuction how do I assign the if then statement to the variable? — Preceding unsigned comment added by 204.42.31.250 (talk) 00:04, 24 March 2015 (UTC)
- Your questions indicate structural misunderstanding rather than that of detail. Examples (unless they happen to be exactly your program — i.e., unless someone writes it for you) will be of limited use, because you will have to infer the structure from them, rather than deduce the correct program (for your purpose) from general rules. I'll try to dispel a couple of misunderstandings:
- Your function getMoneyRate should return a value (or, in rare cases, set or modify an output parameter). Then calling it from any file will return the information "to that file". In particular, it should not assign to a global variable, which would then have to live in exactly one file. This is a principle of modular programming.
- You don't assign statements to variables, but rather values; if statements have no value (in PHP). (There is the conditional operator, which may or may not be useful to you here.)
- Hope that helps; do check your favorite PHP book for (generic) examples of functions and calls to them. --Tardis (talk) 02:11, 24 March 2015 (UTC)
All I want to know is if I have this code in one file: function getMoneyRate($location){10 + 5} How do I get the information of 10 + 5 to the other file based solely on what is seen in the code I just wrote. — Preceding unsigned comment added by 204.42.31.250 (talk) 02:33, 24 March 2015 (UTC)
- With a return statement? I said to return a value… --Tardis (talk) 13:38, 24 March 2015 (UTC)
- This has nothing at all to do with "in one file" and "in another file". You apparently do not understand how to return a value from a function - even if the function and the rest of the code is in one file. You need to use the "return" statement to return the value from the function. Then, you can set a variable to the return value from the function. 209.149.113.207 (talk) 13:52, 24 March 2015 (UTC)
I suggest reading Wikibooks: PHP Programming/Functions#Returning a value and Wikibooks: PHP Programming/PHP Include Files. If that doesn't make things clear, please make up 2 short files as an example of what you are trying to do -- example files that at least run and print something out, even if they don't print exactly the output you want -- and post those files with a more detailed question. You may get a quicker response by posting that question to Wikibooks: Talk:PHP Programming or http://stackoverflow.com/ (Stack Overflow) rather than to this reference desk. Once you've figured out this problem, please go back to Wikibooks: PHP Programming/Functions and make that book easier to understand for the next person. --DavidCary (talk) 16:02, 26 March 2015 (UTC)