Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (746)
Games in Android Showcase (226)
games submitted by our members
Games in WIP (827)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Problem creating a timeline GUI  (Read 2111 times)
0 Members and 1 Guest are viewing this topic.
Offline Dreamcatchermatt

Junior Devvie





« Posted 2010-05-11 15:35:55 »

Hi all,

I'm working on a project for organising notes, photos, logbook/journal entrys, etc on a timeline.

This is an mockup of what I want to create:


(image permalink)

I'm haveing a problem normalising my binary-tree indexes (int timestamps) into the pixle-width of the timeline.

For example, My first node, 1234567890 should be drawn at 0px. my last, 2345678901 at say 800px (or the width of the timeline control).

all the nodes inbetween should be spaced along the x axis of the control reletive to the first and last node.

This is handled by the method:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
private int getTimelinePosition(BinaryTreeNode n)
    {
        int l = this.ctree.GetLowest().getKey();                     // the lowest timestamp
        int h = this.ctree.GetHighest().getKey();                   // the highest timestamp
       
        int tWidth = h - l;                              // the tine difference (in ms) between high and low

        double dtWidth = (double)this.getWidth()/tWidth;  // the pixle width of one milisecond

        int xPos = (int)(n.getKey() * dtWidth);                     // get the position on the line

        return xPos;
    }


for some reason, I'm getting negative numbers anywhere between -400 and -3500-ish.

I've been staring at this code for hours now, and have got myself totaly confised by it all, so i thought some fresh eyes might see where the error lies.  Undecided
 
If anyone can shed any light on this I would be much obliged.
Matt

(if its something realy simple, feel free to call me a muppet. I seriously have been stuck for hours on this highschool math  Grin )
Offline adon_y_coya

Senior Newbie





« Reply #1 - Posted 2010-05-11 16:38:46 »

if you're using System.currentTimeMillis() to get the timestamps (as you probably are seeing that they are milliseconds) then you should be using longs (instead of ints) to hold them.
Offline Dreamcatchermatt

Junior Devvie





« Reply #2 - Posted 2010-05-11 16:47:32 »

i'm using the getTime() method from the Date class.

Thanks, I'll try that Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline dishmoth
« Reply #3 - Posted 2010-05-12 08:49:04 »

Try:
1  
int xPos = (int)((n.getKey() - l) * dtWidth);

That's 'l' for 'low', not '1' for 'one'.  Wink

Try stepping through your code when n.getKey() is equal to the lowest value, and then the highest value, and you'll see why.

Also, as adon_y_coya says, you should be using longs rather than ints if your timestamps are as large as 1234567890.  (The maximum int size is +/- 2147483647, see Integer.MAX_VALUE/MIN_VALUE.)

Simon

Offline Dreamcatchermatt

Junior Devvie





« Reply #4 - Posted 2010-05-12 12:35:35 »

ahh, brillient, that works Smiley

Yeh, I see it now after a nights sleep and fresh eyes.

Thanks Dishmouth, Adon_Y_Coya!

Offline Dreamcatchermatt

Junior Devvie





« Reply #5 - Posted 2010-05-12 13:13:25 »

One other idea i was playing around with is to have the hight above or below the center-line calculated from the mouse X position (for testing, this would later be defined by the current time).

1  
2  
3  
4  
5  
6  
7  
|                         0
|                     0   |   0
|               0     |   |   |    0
|------0----------------------------------0-------------------------------------------
|0                                               0          |
|                         |                                 0
|                         ^ MouseX


is there a way to calculate something like the curve you would get on a graph with standard deviation?

The idea is that the height on the graph would be an idea of the importance or iminance of the task/apointment.

Thanks again for your input guys
Pages: [1]
  ignore  |  Print  
 
 

 
xxMrPHDxx (70 views)
2017-12-31 17:17:51

xxMrPHDxx (35 views)
2017-12-31 17:15:51

xxMrPHDxx (41 views)
2017-12-28 18:11:33

Ecumene (212 views)
2017-09-30 02:57:34

theagentd (310 views)
2017-09-26 18:23:31

cybrmynd (356 views)
2017-08-02 12:28:51

cybrmynd (399 views)
2017-08-02 12:19:43

cybrmynd (367 views)
2017-08-02 12:18:09

Sralse (335 views)
2017-07-25 17:13:48

Archive (1083 views)
2017-04-27 17:45:51
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!