Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (777)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
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 2323 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:

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.

(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 »

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.)


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).

|                         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  

hadezbladez (295 views)
2018-11-16 13:46:03

hadezbladez (164 views)
2018-11-16 13:41:33

hadezbladez (295 views)
2018-11-16 13:35:35

hadezbladez (75 views)
2018-11-16 13:32:03

EgonOlsen (2156 views)
2018-06-10 19:43:48

EgonOlsen (2183 views)
2018-06-10 19:43:44

EgonOlsen (1370 views)
2018-06-10 19:43:20

DesertCoockie (1988 views)
2018-05-13 18:23:11

nelsongames (1631 views)
2018-04-24 18:15:36

nelsongames (2279 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 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‑
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!