Ugly code

My jquery mobile code scripts are redundant and referencing older versions of the core library. I call two different jquery, and one jquery mobile files. The problem is that when I delete one or the other scripts it doesn't reference my stylesheets. Could someone provide feedback in the proper formating?
1
<html><head>
2
<meta charset="UTF-8">
3
<meta name="viewport" content="width=device-width, initial-scale=1">
4
<title>Park Seeker</title>
5
<link href="jquery.mobile-1.0.min.css" rel="stylesheet" type="text/css"/>
6
<style type="text/css">
</style>
7
<script src="http://code.jquery.com/jquery-1.6.4.min.js" type="text/javascript"></script>
8
<script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js" type="text/javascript"></script>
9
<script src="scripts/jquery.js" type="text/javascript"></script>
10
<script type="text/xml"></script>
11
<script src="cordova.js" type="text/javascript"></script>
12
<script src="phonegap.js"></script>
13
<script src="childbrowser.js"></script>
14
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js?ver=3.0.1"></script>
15
<script type="text/javascript" src="infinite-rotator.js"></script>
16
</head>

First:
Go to: http://jquerymobile.com/ and download the latest stable version of jQuery Mobile (version 1.2). Copy the appropriate files into your site folder to replace the old version of jQuery mobile referenced in your site. This includes jQuery 1.8.2 - use this instead of all the other versions of jQuery being called:
<script src="http://code.jquery.com/jquery-1.6.4.min.js" type="text/javascript"></script> (version 1.6.4)
<script src="scripts/jquery.js" type="text/javascript"></script> (unknown version)
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js?ver=3. 0.1"></script> (version 1.4.2)
So your code would look something like this (adjust filepaths as needed):
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Park Seeker</title>
<link href="css/jquery.mobile-1.2.0.min.css" rel="stylesheet" type="text/css"/>
<script src="js/jquery.1.8.2.min.js"><!-- or the jQuery.js found in the jQuery mobile "demo/js" folder --></script>
<script src="js/jquery.mobile-1.2.0.js"></script>
<script src="js/cordova.js" type="text/javascript"></script>
<script src="js/phonegap.js"></script>
<script src="js/childbrowser.js"></script>
<script src="js/infinite-rotator.js"></script>
</head>

Similar Messages

  • Ugly code please advise

    Hi
    When I need to access a text file I am using this type of code. I think it's ugly but at least it works. Can someone post the best practices.
    I do not want the method to throw an exception and I want to be sure the input stream is cleanly closed.
    The try block in the finally block looks really ugly... Give your opinion!
    Thanks
    static public String getInfo(File file, String info)
            String resu = null;
            InputStream source = null;
            try
                source = new FileInputStream(file);
                MimeMessage message = new MimeMessage(null, source);
                //  do some action that may fire an exception
            catch(Exception io)
                logger.warning("impossible to find info " + info + " in " + file.getName());
                logger.warning(printex(io));
            finally
                try
                    source.close();
                catch(IOException io)
                    Utilities.logger.warning("error "+io);
            return resu;
        }

    public static String getInfo(File file, String info)
              String resu = null;
              InputStream source = null;
              try
                   source = new FileInputStream(file);
                   MimeMessage message = new MimeMessage(null, source);
              catch (FileNotFoundException e)
                   e.printStackTrace();
              catch (MessagingException e)
                   e.printStackTrace();
              finally
                   try
                        if (null != source)
                             source.close();
                   catch (IOException io)
                        System.out.println("");
              return resu;
         }

  • [SOLVED]C some ugly code

    #include <stdio.h>
    #define N 4
    void main(){
    int a[][N] = {{2},{3,3,1},{1,8,8,2},{3,1}},*b = *a,*c = *(a+N-1),i,j;
    while(b < c) *b++ += *c--;
    for(i = N; i > 0;i--) printf("%d ",(*a)[i-1]);
    Can somebody explain to me wtf is this? :v
    is b type of ( int *b ) and i,j are ( int ), how this works?
    Last edited by ZoLA (2015-04-30 14:59:46)

    I expanded the code a bit:
    #include <stdio.h>
    #define N 4
    void main(){
    int a[][N] = {{2},{3,3,1},{1,8,8,2},{3,1}};
    int * b = a[0];
    int * c = a[3];
    int i;
    int j;
    while(b < c) {
    i = c[0];
    c -= 1;
    b[0] += i;
    b += 1;
    for(i = N; i > 0;i--) {
    printf("%d ",a[0][i-1]);

  • API : EventHandler and ugly code

    Hello,
    I'm playing with javafx2 api since I 've been disapointed by flex and silverlight api.
    My reference is forever the swing api and I want to know how to write beautiful code which will respect all best practices (pmd,checkstyle, findbugs, javancss)
    The problem is the genericsable class EventHandler ...
    In swing I can have a class that implements MouseListener and ActionListener interface, So if my control implements these interfaces I can have an actionPerformed, mouseMoved .... methods which will process all actions.
    public class MyClass extends JPanel implements ActionListener, MouseListener {
    mybutton.addActionListener(this);
    mycontrol.addMouseListener(this);
    public void actionPerformed(ActionEvent e){
        if(e.getSource.equals(mybutton)){
             // mybutton stuff
    public void mouseMoved(MouseEvent e){
        if(e.getSource.equals(mycontrol)){
             // mycontrol stuff
    }The JavaFX2 API use the same approach but since the eventHandler use a custom generics type, I must implements EventHandler (without type <XX>) and do a lot of cast everywhere to fill the gap.
    mybutton.setOnAction((EventHandler)this);then
    public class ControlPanel extends Region implements EventHandler<Event> {
    bt1.setOnAction((EventHandler)this);
    bt2.setOnAction((EventHandler)this);
    progressbar.setOnMouseClicked(this);
        public void handle(Event event) {
            if(MouseEvent.class.equals(event.getClass())){
                f(event.getSource().equals(progressbar)){
                     //stuff;
            }else if(ActionEvent.class.equals(event.getClass())){
                if(event.getSource().equals(bt1)){
                     //stuff;
                }else if(event.getSource().equals(bt2)){
                    //stuff;
        }IN fact with javafx2 it's more difficult to write code not using anonymous class which will be a very big problem for software maintainability and source code quality.
    Moreover the SetONXXX method which have a Runnable argument need anonymous class or dedicated inner class to manage threading priorities and I don't see any solution to make it cleaner.
    It would be nicer to use a custom Runnable class which have some fields used to identify the source and the kind of event.
    At the moment, a javafx2 developers have 2 options :
    _ Write a lot of anonymous class anywhere in its source code, the class will be unreadable because the code is not organized (components initialization, action processes, business logic)
    _ create a huge amount of dedicated class (runnable and eventhandler) which all reference the main control ...
    JavaFx2 code will be more complex and can be less adopted or misloved ....
    What do you think about this ?
    Edited by: Seb on 27 août 2011 00:15

    I do like a good architecture debate, everyone gets so passionate! :)
    Pure OO or otherwise, I feel your pain Sebastian: inner classes can be painful to work with. As mentioned above, (IMHO) this is mostly a result of Java's syntax being a little clunky in this area. What you really want to do is pass in a method pointer like this:
    void buildView() {
        Button myButtton = new Button();
        myButton.addActionHandler(onMyButtonAction);
    void onMyButtonAction(ActionEvent event) {
        // do custom event handling
    } But obviously Java doesn't support this at a language level. It does support it via Reflection however and in Swing (and now in JFX) I've often created a helper class that would let me bind the action to the method via Reflection (using inner classes internally - but this is all hidden under the helper).
    void buildView() {
        Button myButtton = new Button();
        bindAction(myButton.onActionProperty(), this, "onMyButtonAction");
    void onMyButtonAction(ActionEvent event) {
        // do custom event handling
    } Your code is now much simpler and more readable but the big (BIG!) drawback is that you lose compiler safety - it is up to you to decide whether this is worth it or not (I'm sure purists will passionately hate this idea but I'm all for 'developers choice').
    A simple implementation of the helper code would look something like:
    public void bindAction(ObjectProperty<EventHandler<ActionEvent>> onActionProperty, final Object target, final String methodName)
        final Method method = target.getClass().getMethod(methodName, EventHandler.class);
        onActionProperty.set(new EventHandler<ActionEvent>()
            public void handle(ActionEvent event)
                method.invoke(target, event);
    }I've left out exception handling for simplicity. You could obviously add a bindMouseClick method, and bindXYZ methods for all the other events that you want to handle.
    There's also an [url http://download.oracle.com/javafx/2.0/fxml_get_started/jfxpub-fxml_get_started.htm]emerging option with FXML, that does similar action to method binding. When you define your button in the XML you add a onAction="#myButtonHandlerMethod" and the FXML binder will bind this automagically to your method (I imagine using reflection like I have done above). It's still pretty raw and you have to build your UI layout in XML (a plus in some people's eyes, a negative in others) but it's worth a look. I haven't seen Mouse handler stuff in there yet but if it's not there yet, I imagine it will be added before too long.
    Like all free advice, take it or leave it :)
    Enjoy,
    zonski

  • Ugly code - teach me :-)

    Hi,
    I have the follow code in my Session Facade:
    Software os = (Software)em.createNamedQuery("Software.findById").setParameter("softwareId", operatingSystem).getSingleResult();
                    hardware.setOperatingSystem(os);Now, calling getSingleResult will throw an EJBException, which is a RuntimeException if there are no results. I would prefer to detect the fact that there are no results and throw an nicer error, because if I'm doing several quieries like this, the error message makes no hint as to which query caused the error. How should I rearrange this code?
    For example:
                try {
                    Software os = (Software)em.createNamedQuery("Software.findById").setParameter("softwareId", operatingSystem).getSingleResult();
                    hardware.setOperatingSystem(os);
                } catch (EJBException ejbe) {
                    throw new BusinessRuleException("Could not find Operating System with Id = " + operatingSystem);
                }(btw - that's just an example, I know it will never stop the exception)
    R

    My point being I don't like to catch runtime exceptions

  • Probably ugly code... hideous even???

    I have a class that contains a int-field and a Vector-field. The int is set to represent a type (Enum is not an option). The Vector is used to contain the different aspects of that type (type 0 would have an integer and a String stored in the Vector, while type 1 would have two integers, etc.). Now I've been wondering whether it would be better to replace this 'construction' with one that derives subclasses from a general type and then using instanceof to discover which type it is (this would eliminate the Vector construction).
    or is there an even better way....

    I've have a mobile device that generates event messages (text). I've decoded these messages into an Event class (which I lovingly call Wilbur). Objects of this class are passed around between the different threads of my program. I use an int to make sure that a thread knows what kind of event it is dealing with.
    As I really dislike the Vector-construction I would like to replace the Event class with subclasses of an abstract Event class. However even doing that, I still need to know which subclass I am dealing with, so I wouldn't be able to get rid of the int (unless I use instanceof).

  • Calling javac in java code- possible?

    I'm writing a reasonably large app which can be run with X11 (using swing etc) or as a CLI app. This is basically because it will be useful in many different circumstances, for instance where there is no swing or X support, it'd be pointless building it with those capabilities. Now the easy way to do this, of course, (and I'm pretty lazy so I'll do it this way) is to write the base app, and then on one copy of it create a CLI, the other a GUI, and then give users the option of which to use. Also because of the size of it, I believe it'd be better for users to compile it themselves, so it is tailored perfectly (esp. where different J/SDKs are used.
    Now what I decided to do was just fire out some javacode to take command line options to compile- makes sense I thought, then I hit a problem... Is it possible to call javac in a java app? Can I have a line of code to call javac in the same way I could in a bash script? For reference, here is my code thus far- the lines that need replacing are the print lines saying which option is being used...
    class MakeII {
         private int choice;
                    public static void main(String[] args) {
                             if (args.length != 1) {
                  System.out.println("Bad choice/ no choice- please try again");
              } else { MakeII myComp = new MakeII(args[0]); }
         public MakeII (String choose) {
              System.out.println(choose);
              if (choose.equals("--make-x11") ) {choice = 1;}
                             else if (choose.equals("--make-sh") ) {choice = 2;}
                             else if (choose.equals("--make-full") ) {choice = 3;}
                             else {choice = 3;} //any error, assume full version
                             switch (choice) {
                  case 1: System.out.println("x only"); break;
                  case 2: System.out.println("cli only"); break;
                  case 3: System.out.println("full ver"); break;
    }And yes I know its ugly code, I just prefer to seperate everything out at this stage- I also know I've done everything the long way too, its for maintainability.

    jamesCondron wrote:
    Employer? Nah- this is a none-paid bit of project, more voluntry than anything, but I regret saying I would. Can't turn around now and say no... And I can't use anything but java because of how the project started, and the guys I'm working with; because Its server side stuff that needs to be distributed and portable I'd rather use python (or perl, but not quite that good) but ah well- what can you do?First off: challenge the requirement that it must be portable. More often than not, that's bogus. Beyond that, dude, you hold all the aces. They don't wanna pay but they still expect you to do it? That means they don't have a clue where to start. Baffle 'em with science, shouldn't be too hard. If it's lines of code they want, write them a bit of custom JSTL and show 'em how 2 lines of JSP can equate to 200 lines of Java, thus proving that lines-of-code is an utterly worthless metric. Then ask them if they want it done or not, and mumble a lot about going to the beach

  • How to deal with poorly designed code

    Hello, everyone.
    I have a problem with some program that I wrote starting my career as a programmer.
    At first I studied a lot and wrote this program in java with poor design solutions in mind.
    My code looked like procedural(I studied c before) object oriented freak.
    And as a result even I could hardly modify my code. I had to spend hours
    remembering what each function in class did.
    And some time after that my boss asked me to write one new feature which actually changes
    architecture a lot. Even if it was good object oriented code, it would take some time. But now
    it takes a great amount of struggle and patience to rewrite my ugly code and implement this
    new feature.
    So I'm asking you developers out there: How do you deal with such situations when for example
    someone wrote very bad piece of code and you have to change/modify it to support new requirements?

    Dusty wrote:
    Xyne wrote:Refactoring isn't fun
    I'm filing this under 'complete and utter bullshit' I read on the first of the fourth month. :-P
    I love refactoring, taking something good and making it great. The eternal search for perfection just outside your grasp.
    Dusty
    Yarrrr, because what's more fun than pouring effort into something to end up with the exact same functionality that you started with?
    Finding new and better ways to do things is fun and you definitely improve your coding skills when you go back and pick apart the hack-n-slash stuff you've written before, but overall I don't think it's fun (unless you're truly doing it only for yourself, i.e. no obligations, no deadlines, etc).

  • Avoiding PageParserPath but still having code in your page layout

    I have a page layout that has some custom c# in it (yes, I realize that's not a great practice; it's some legacy stuff I don't have time to rework right now).
    I have this page layout deployed in our farm today... and it works just charming...  *and* there are no additions to our <PageParserPath>.  So, such a thing is possible, that's good news!
    Anybody know how? :)
    There is some (rather logical) explanation here http://msdn.microsoft.com/en-us/library/bb964680(v=office.12).aspx that suggests that as long as the item remains ghosted
    it's "safe".  But, after deploying from my fancy .wsp with the type set "GhostableInLibrary" ... I got the ugly "Code Blocks Are Not Allowed In This File" madness.
    Hmm... starting to wonder if I am crazy for thinking this could work w/ a Sandboxed solution?  Or... or theories?

    Yes, it is possible in SHAREPOINT 2013, but with some
    hacking.
    1. create custom configuration handler class
    public class MySafeModeConfigurationHandler : IConfigurationSectionHandler
            public object Create(object parent, object configContext, XmlNode section)
                var type = typeof(Microsoft.SharePoint.ApplicationRuntime.SPRequestModule);
                var field = type.GetField("s_excludedFileList", BindingFlags.Static | BindingFlags.NonPublic);
                object s_excludedFileList = field.GetValue(null);
                if (s_excludedFileList == null)
                    field.SetValue(null, Activator.CreateInstance(field.FieldType));
                type = Type.GetType("Microsoft.SharePoint.ApplicationRuntime.SafeModeConfigurationHandler, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
                var method = type.GetMethod("Create");
                object o = Activator.CreateInstance(type);
                object result = method.Invoke(o, new object[]{parent, configContext, section});
                return result;
    2. change web.config
          <!--section name="SafeMode" type="Microsoft.SharePoint.ApplicationRuntime.SafeModeConfigurationHandler, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /-->
          <section name="SafeMode" type="MyNamespace.MySafeModeConfigurationHandler, MyLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=fc475d95eb56414f" />

  • Ugly Switch Statement

    Hi;
    I have this ugly code:
                var i:Number = new Number(0);
                while (i > 6)
                    switch (i)
                        case (0):
                        container = container0;
                        break;
                        case (1):
                        container = container1;
                        break;
                        case (2):
                        container = container2;
                        break;
                        case (3):
                        container = container3;
                        break;
                        case (4):
                        container = container4;
                        break;
                        case (5):
                        container = container5;
                        break;
                    container.addChild(img);
                    i++;
    All of these containers are then added into a parent container with their x and y coordinates set separately so that they don't overlap. Is it possible to set those coordinates to either the img or the specific container (i.e., container2)? I tried the following:
                if (img.parent)
                    img.parent.removeChild(img);
                i = 0;
                while (i < _numOfSlides)
                    img.myArray = [imagesArray[_const*_numOfSlides+_mod+i], "index.py", _w, _h, ((_w+spacer)*j)+_x+600, _y];
                    container.addChild(img);
                    img.x = _w*i
    //                parent_container.addChild(container);
                    trace(i);
                    ++i;
    uncommenting the commented out portions, but to no avail. The trace traces but no images print to screen. The ugly code does in fact work. Please advise.
    TIA,
    beno

    Yes. It has been added and it displays as I indicated before.
    beno

  • Code beautifier for MXML and ActionScript?

    How do people reformat ugly code in FlexBuilder? I can eaisly
    format my Java, JSP, and XML in the same Eclipse environment, but
    why not MXML and ActionScript? I am very surprised this feature is
    missing. It's quite common that I copy code snippets from somewhere
    to FlexBuilder which are not well formatted.

    Hey guys, Be patient...
    Don't forget the years of Java development that have advanced
    Eclipse, not counting the 40 mil or so in prior development that
    IBM donated when they ported and open sourced their Visual Age
    product line. I used VA it back in 96 and it was slow and clunky,
    and never would have sold against Borland's Java products.
    I'm sure the decision was consciously made by Adobe product
    management to get core feature functionality out and concentrate on
    other stuff for the next release.
    The FLEX team has done a great job and for some who have ever
    been under their delivery schedule for the size of this
    undertaking, many can appreciate how well they have done.
    Also, considering that many eclipse plugins that are free are
    worth what you pay for them (I have tested quite a few), the paltry
    $700 bucks for FLEX and the fact that it has a great debugger and
    profiler makes it worth it.
    One final opinion, no matter what anyone says, software is
    not free. You pay in time, learning curve, more time, and
    sometimes, just plain old tail chasing!
    I'm not really being critical, both of you have valid points,
    just be patient, they'll get there.

  • Need your help on performance issue please

    Hello everyone!
    I need your help to understand an effect I notice with a Thread class I built. I currently work on enhancement of my application Playlist Editor (see http://www.lightdev.com/page74.htm) and a new release will be available soon.
    Among other extensions the new release will have a title filter function which is based on audio data that is recursively read from ID3 tags of files found in a given root directory. The data collection is done by a CollectionThread class which reads into a data model class AudioDataModel and the entire process works fine, no problem with that.
    However, when my application is started for the first time the CollectionThread runs approximately 3 minutes to collect data from approximately 4300 audio files on an Intel Pentium M 1,4 GHz, 512 MB RAM, Windows XP SP2. When the application is shut down and started again, it takes only a few seconds to do the same task for all subsequent launches.
    I already tried to start the application with java option -Xms40m to increase initial heap size. This increases performance in general but the effect is still the same, i.e. first run lasts significantly longer than subsequent runs.
    I also tried to build a pool mechanism which creates many empty objects in the data model and then releases them to contain the actual data at is being read in but this did not lead to better performance.
    It must have to do with how Java (or Windows?) allocates and caches memory. I wonder whether there is a way to pre-allocate memory or if there are any other ideas to improve performance so that the process always only takes seconds instead of minutes?
    I attach the key classes to this message. Any help or ideas is much appreciated!
    Thanks a lot a best regards
    Ulrich
    PS: You can use the news subscription service at
    http://www.lightdev.com/dynTemplate.php4?id=80&dynPage=subscribe.php4 to be informed when the new release of Playlist Editor is available.
    All classes posted here do not need debugging, they already have proven to run error free. The classes are only posted for information for the interested reader - no need to go through all the stuff in detail - only if it interests you.
    My application calls class CollectionThread wich is a subclass of InfoThread. CollectionThread recursively goes through a directory and file structure and stores found ID3 tag information in instances of class ID3v11Tag which in turn gets stored in one instance of class AudioDataModel. All classes are shown below.
    This is the mentioned CollectionThread
    * Light Development Playlist Editor
    * Copyright (C) 2004 Ulrich Hilger
    * This program is free software; you can redistribute it and/or
    * modify it under the terms of the GNU General Public License
    * as published by the Free Software Foundation; either version 2
    * of the License, or (at your option) any later version.
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    * GNU General Public License for more details.
    * You should have received a copy of the GNU General Public License
    * along with this program; if not, write to the Free Software
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    package com.lightdev.app.playlisteditor.data;
    import com.lightdev.lib.util.InfoThread;
    import java.io.File;
    * A class to collect audio data from a given storage location.
    * <p>
    * <code>CollectionThread</code> uses ID3 tag information to gain data.
    * </p>
    * <p>See <a href="http://www.id3.org">http://www.id3.org</a> for details about
    * ID3 tags.</p>
    * @author Ulrich Hilger
    * @author Light Development
    * @author <a href="http://www.lightdev.com">http://www.lightdev.com</a>
    * @author <a href="mailto:[email protected]">[email protected]</a>
    * @author published under the terms and conditions of the
    *      GNU General Public License,
    *      for details see file gpl.txt in the distribution
    *      package of this software as well as any licensing notes
    *      inside this documentation
    * @version 1, October 13, 2004
    public class CollectionThread extends InfoThread {
       * constructor
       * @param model  AudioDataModel  the data model to collect data to
      public CollectionThread(AudioDataModel model) {
        this.model = model;
       * constructor, creates a new empty AudioDataModel
      public CollectionThread() {
        this(new AudioDataModel());
       * set the data model to collect data to
       * @param model AudioDataModel  the model to collect data to
      public void setModel(AudioDataModel model) {
        this.model = model;
       * get the data model associated to this thread
       * @return AudioDataModel  the data model
      public AudioDataModel getModel() {
        return model;
       * set the directory to collect data from
       * @param rootDir File  the directory to collect data from
      public void setRootDirectory(File rootDir) {
        this.rootDir = rootDir;
       * do te actual work of this thread, i.e. iterate through a given directory
       * structure and collect audio data
       * @return boolean  true, if work is left
      protected boolean work() {
        boolean workIsLeft = true;
        maxValue = -1;
        filesProcessed = 0;
        if(getStatus() < STATUS_HALT_PENDING) {
          countElements(rootDir.listFiles());
        if(getStatus() < STATUS_HALT_PENDING) {
          workIsLeft = collect(rootDir.listFiles());
        return workIsLeft;
       * count the elements in a given file array including its subdirectories
       * @param files File[]
      private void countElements(File[] files) {
        int i = 0;
        while (i < files.length && getStatus() < STATUS_HALT_PENDING) {
          File file = files;
    if (file.isDirectory()) {
    countElements(file.listFiles());
    i++;
    maxValue++;
    * recursively read data into model
    * @param files File[] the file array representing the content of a given directory
    private boolean collect(File[] files) {
    int i = 0;
    while(i < files.length && getStatus() < STATUS_HALT_PENDING) {
    File file = files[i];
    if(file.isDirectory()) {
    collect(file.listFiles());
    else if(file.getName().toLowerCase().endsWith("mp3")) {
    try {
    model.addTrack(file);
    catch(Exception e) {
    fireThreadException(e);
    i++;
    filesProcessed++;
    fireThreadProgress(filesProcessed);
    return (i<files.length);
    /** the directory to collect data from */
    private File rootDir;
    /** the data model to collect data to */
    private AudioDataModel model;
    /** the number of files this thread processed so far while it is running */
    private long filesProcessed = 0;
    This is class InfoThread
    * Light Development Java Library
    * Copyright (C) 2003, 2004 Ulrich Hilger
    * This program is free software; you can redistribute it and/or
    * modify it under the terms of the GNU General Public License
    * as published by the Free Software Foundation; either version 2
    * of the License, or (at your option) any later version.
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    * GNU General Public License for more details.
    * You should have received a copy of the GNU General Public License
    * along with this program; if not, write to the Free Software
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    package com.lightdev.lib.util;
    import java.util.Vector;
    import java.util.Enumeration;
    * Abstract class <code>InfoThread</class> implements a status and listener concept.
    * An <code>InfoThread</code> object actively informs all objects registered as listeners about
    * status changes, progress and possible exceptions. This way the status of a running
    * thread does not require a polling mechanism to be monitored.
    * <p>
    * <code>InfoThread</code> implements the following working scheme
    * </p>
    * @author Ulrich Hilger
    * @author Light Development
    * @author <a href="http://www.lightdev.com">http://www.lightdev.com</a>
    * @author <a href="mailto:[email protected]">[email protected]</a>
    * @author published under the terms and conditions of the
    *      GNU General Public License,
    *      for details see file gpl.txt in the distribution
    *      package of this software
    * @version Version 1, October 13, 2004
    public abstract class InfoThread extends Thread {
       * construct an <code>InfoThread</code> object
       * <p>This class is meant to be used when a <code>Thread</code> object is needed that actively
       * informs other objects about its status</code>. It is a good idea therefore to register
       * one or more listeners with instances of this class before doing anything
       * else.</p>
       * @see addInfoThreadListener
      public InfoThread() {
       * set the amount of time this thread shall idle after it is through with one
       * work cycle and before a next work cycle is started. This influences the time
       * other threads have for their work.
       * @param millis long  the number of milliseconds to idle after one work cycle
      public void setIdleMillis(long millis) {
        idleMillis = millis;
       * Causes this thread to begin execution; the Java Virtual Machine calls the <code>run</code>
       * method of this thread. Calls method <code>prepareThread</code> before calling
       * <code>run</code>.
       * @see run
       * @see prepareThread
      public synchronized void start() {
        setStatus(STATUS_INITIALIZING);
        prepareThread();
        setStatus(STATUS_READY);
        super.start();
       * call method <code>start</code> instead of this method.
       * calling this method directly will lead to an exception
       * @see start
      public void run() {
        //System.out.println("InfoThread.run");
        if (status == STATUS_READY) {
          boolean workIsLeft = true;
          setStatus(STATUS_RUNNING);
          while (status < STATUS_STOP_PENDING && workIsLeft) {
            if (status < STATUS_HALT_PENDING) {
              workIsLeft = work();
              if(!workIsLeft) {
                setStatus(STATUS_WORK_COMPLETE);
            if (status == STATUS_HALT_PENDING) {
              setStatus(STATUS_HALTED);
            else if (status == STATUS_STOP_PENDING) {
              setStatus(STATUS_STOPPED);
            else {
              try {
                sleep(idleMillis);
              catch (InterruptedException e) {
                fireThreadException(e);
        else {
          // error: Thread is not ready to run
        setStatus(STATUS_THREAD_FINISHED);
       * stop this thread. This will terminate the thread irrevokably. Use method
       * <code>haltThread</code> to pause a thread with the possiblity to resume work later.
       * @see haltThread
      public void stopThread() {
        switch (status) {
          case STATUS_RUNNING:
            setStatus(STATUS_STOP_PENDING);
            break;
          case STATUS_HALT_PENDING:
            // exception: the thread already is about to halt
            break;
          case STATUS_STOP_PENDING:
            // exception: the thread already is about to stop
            break;
          default:
            // exception: a thread can not be stopped, when it is not running
            break;
       * halt this thread, i.e. pause working allowing to resume later
       * @see resumeThread
      public void haltThread() {
        switch (status) {
          case STATUS_RUNNING:
            setStatus(STATUS_STOP_PENDING);
            break;
          case STATUS_HALT_PENDING:
            // exception: the thread already is about to halt
            break;
          case STATUS_STOP_PENDING:
            // exception: the thread already is about to stop
            break;
          default:
            // exception: a thread can not be halted, when it is not running
            break;
       * resume this thread, i.e. resume previously halted work
       * @see haltThread
      public void resumeThread() {
        if(status == STATUS_HALTED || status == STATUS_HALT_PENDING) {
          setStatus(STATUS_RUNNING);
        else {
          // exception: only halted threads or threads that are about to halt can be resumed
       * this is the method to prepare a thread to run. It is not implemented in this abstract
       * class. Subclasses of <code>InfoThread</code> can implement this method to do anything
       * that might be required to put their thread into STATUS_READY. This method is called
       * automatically by method <code>start</code>.  When implementing this method, it should
       * call method <code>fireThreadException</code> accordingly.
       * @see start
       * @see fireThreadException
      protected void prepareThread() {
        // does nothing in this abstract class but might be needed in subclasses
       * this is the main activity method of this object. It is not implemented in this abstract
       * class. Subclasses of <code>InfoThread</code> must implement this method to do something
       * meaningful. When implementing this method, it should call methods
       * <code>fireThreadProgress</code> and <code>fireThreadException</code> accordingly.
       * @return boolean true, if work is left, false if not
       * @see fireThreadProgress
       * @see fireTreadException
      protected abstract boolean work();
       * add an <code>InfoTreadListener</code> to this instance of <code>InfoThread</code>
       * @param l InfoThreadListener  the listener to add
       * @see removeInfoThreadListener
      public void addInfoThreadListener(InfoThreadListener l) {
        listeners.add(l);
       * remove an <code>InfoTreadListener</code> from this instance of <code>InfoThread</code>
       * @param l InfoThreadListener  the listener to remove
      public void removeInfoThreadListener(InfoThreadListener l) {
        listeners.remove(l);
       * notify all <code>InfoThreadListener</code>s of a status change
       * @param fromStatus int  the status tis thread had before the change
       * @param toStatus int  the status this thread has now
      protected void fireThreadStatusChanged(int fromStatus, int toStatus) {
        Enumeration e = listeners.elements();
        while(e.hasMoreElements()) {
          Object l = e.nextElement();
          if(l instanceof InfoThreadListener) {
            ((InfoThreadListener) l).threadStatusChanged(this, fromStatus, toStatus);
       * notify all <code>InfoThreadListener</code>s of an exception in this thread
       * @param ex Exception  the exception that occurred
      protected void fireThreadException(Exception ex) {
        Enumeration e = listeners.elements();
        while(e.hasMoreElements()) {
          Object l = e.nextElement();
          if(l instanceof InfoThreadListener) {
            ((InfoThreadListener) l).threadException(this, ex);
       * notify all <code>InfoThreadListener</code>s of the progress of this thread
       * @param progressValue long  a value indicating the current thread progress
      protected void fireThreadProgress(long progressValue) {
        Enumeration e = listeners.elements();
        while(e.hasMoreElements()) {
          Object l = e.nextElement();
          if(l instanceof InfoThreadListener) {
            ((InfoThreadListener) l).threadProgress(this, progressValue, maxValue);
       * set the status of this thread and notify all listeners
       * @param newStatus int  the status this thread is to be changed to
      private void setStatus(int newStatus) {
        //System.out.println("InfoThread.setStatus oldStatus=" + status + ", newStatus=" + newStatus);
        int fromStatus = status;
        status = newStatus;
        fireThreadStatusChanged(fromStatus, newStatus);
       * get the current status of this thread
       * @return int  the status
      public int getStatus() {
        return status;
       * cleanup before actual destruction.
      public void destroy() {
        //System.out.println("InfoThread.destroy");
        cleanup();
        super.destroy();
       * cleanup all references this thread maintains
      private void cleanup() {
        //System.out.println("InfoThread.cleanup");
        listeners.removeAllElements();
        listeners = null;
      /* ----------------------- class fields start ------------------------ */
      /** storage for the objects this thread notifies about status changes and progress */
      private Vector listeners = new Vector();
      /** indicator for the status of this thread */
      private int status = STATUS_NONE;
      /** maximum value for threadProgress */
      protected long maxValue = -1;
      /** the idle time inside one work cycle in milliseconds */
      protected long idleMillis = 1;
      /* ----------------------- class fields end -------------------------- */
      /* ----------------------- constants start --------------------------- */
      /** constant value indicating that no status has been set so far */
      public static final int STATUS_NONE = 0;
      /** constant value indicating that the thread is currently initializing */
      public static final int STATUS_INITIALIZING = 1;
      /** constant value indicating that the thread is ready to run */
      public static final int STATUS_READY = 2;
      /** constant value indicating that the thread is running */
      public static final int STATUS_RUNNING = 3;
      /** constant value indicating that the thread is about to halt */
      public static final int STATUS_HALT_PENDING = 4;
      /** constant value indicating that the thread is halted */
      public static final int STATUS_HALTED = 5;
      /** constant value indicating that the work of this thread is complete */
      public static final int STATUS_WORK_COMPLETE = 6;
      /** constant value indicating that the thread is about to stop */
      public static final int STATUS_STOP_PENDING = 7;
      /** constant value indicating that the thread is stopped */
      public static final int STATUS_STOPPED = 8;
      /** constant value indicating that the thread is finished */
      public static final int STATUS_THREAD_FINISHED = 9;
      /* ----------------------- constants end --------------------------- */
    }this is the InfoThreadListener interface
    * Light Development Java Library
    * Copyright (C) 2003, 2004 Ulrich Hilger
    * This program is free software; you can redistribute it and/or
    * modify it under the terms of the GNU General Public License
    * as published by the Free Software Foundation; either version 2
    * of the License, or (at your option) any later version.
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    * GNU General Public License for more details.
    * You should have received a copy of the GNU General Public License
    * along with this program; if not, write to the Free Software
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    package com.lightdev.lib.util;
    * An interface classes interested to receive events from objects
    * of class <code>InfoThread</code> need to implement.
    * @author Ulrich Hilger
    * @author Light Development
    * @author <a href="http://www.lightdev.com">http://www.lightdev.com</a>
    * @author <a href="mailto:[email protected]">[email protected]</a>
    * @author published under the terms and conditions of the
    *      GNU General Public License,
    *      for details see file gpl.txt in the distribution
    *      package of this software
    * @version Version 1, October 13, 2004
    public interface InfoThreadListener {
       * method to receive a status change notification from a thread
       * @param thread InfoThread  the thread which status changed
       * @param fromStatus int  the status which the thread had before the change
       * @param toStatus int  the status which the thread has now
      public void threadStatusChanged(InfoThread thread, int fromStatus, int toStatus);
       * method to receive a notification about the progress of a thread
       * @param thread InfoThread  the thread which notified about its progress
       * @param progressValue long  the value (e.g. 10 if 100 percent completed, 20 of 1 million files processed, etc.)
      public void threadProgress(InfoThread thread, long progressValue, long maxValue);
       * method to receive a notifiaction about the fact that an exception occurred in a thread
       * @param thread InfoThread  the thread for which an exception occurred
       * @param e Exception  the exception that occurred
      public void threadException(InfoThread thread, Exception e);
    }This is class AudioFileDescriptor
    * Light Development Java Library
    * Copyright (C) 2004 Ulrich Hilger
    * This program is free software; you can redistribute it and/or
    * modify it under the terms of the GNU General Public License
    * as published by the Free Software Foundation; either version 2
    * of the License, or (at your option) any later version.
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    * GNU General Public License for more details.
    * You should have received a copy of the GNU General Public License
    * along with this program; if not, write to the Free Software
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    package com.lightdev.lib.audio;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.RandomAccessFile;
    import java.io.Serializable;
    import java.text.DecimalFormat;
    * This class models characteristics of an audio file such as the absolute path
    * of the file, its tag contents (if any) and the play duration, etc.
    * <p>See <a href="http://www.id3.org">http://www.id3.org</a> for details about
    * ID3 tags.</p>
    * @author Ulrich Hilger
    * @author Light Development
    * @author <a href="http://www.lightdev.com">http://www.lightdev.com</a>
    * @author <a href="mailto:[email protected]">[email protected]</a>
    * @author published under the terms and conditions of the
    *      GNU General Public License,
    *      for details see file gpl.txt in the distribution
    *      package of this software
    * @version Version 1, October 13, 2004
    public class AudioFileDescriptor implements Serializable, Comparable {
      public AudioFileDescriptor(String absolutePath) throws FileNotFoundException, IOException {
        load(absolutePath);
      public boolean equals(Object o) {
        if(o != null && o instanceof AudioFileDescriptor) {
          return ((AudioFileDescriptor) o).getAbsolutePath().equalsIgnoreCase(this.getAbsolutePath());
        else {
          return false;
      public void load(String absolutePath) throws FileNotFoundException, IOException {
        this.absolutePath = absolutePath;
        RandomAccessFile rf = new RandomAccessFile(absolutePath, "r");
        if(id3v11Tag == null) {
          id3v11Tag = new ID3v11Tag(rf, false);
        else {
          id3v11Tag.readTag(rf, rf.length() - 128);
        rf.close();
      public String getAbsolutePath() {
        return absolutePath;
      public ID3v11Tag getID3v11Tag() {
        return id3v11Tag;
      public void setID3v11Tag(ID3v11Tag tag) {
        this.id3v11Tag = tag;
      public String toString() {
        DecimalFormat df = new DecimalFormat("00");
        return id3v11Tag.getArtist() + ", " + id3v11Tag.getAlbum() + " - " +
            df.format(id3v11Tag.getTrackNumber()) + " " + id3v11Tag.getTitle();
       * Compares this object with the specified object for order.
       * @param o the Object to be compared.
       * @return a negative integer, zero, or a positive integer as this object is less than, equal to,
       *   or greater than the specified object.
       * @todo Implement this java.lang.Comparable method
      public int compareTo(Object o) {
        return toString().compareTo(o.toString());
      private String absolutePath;
      private ID3v11Tag id3v11Tag;
      private transient long duration = -1;
      private transient int type = TYPE_UNKNOWN;
      public static final transient int TYPE_UNKNOWN = 0;
      public static final transient int TYPE_MP3 = 1;
    }This is class ID3V11Tag into which the data is actually stored
    * Light Development Java Library
    * Copyright (C) 2004 Ulrich Hilger
    * This program is free software; you can redistribute it and/or
    * modify it under the terms of the GNU General Public License
    * as published by the Free Software Foundation; either version 2
    * of the License, or (at your option) any later version.
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    * GNU General Public License for more details.
    * You should have received a copy of the GNU General Public License
    * along with this program; if not, write to the Free Software
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    package com.lightdev.lib.audio;
    import java.io.File;
    import java.io.RandomAccessFile;
    import java.io.IOException;
    import java.io.Serializable;
    import java.text.DecimalFormat;
    * This class is a very simple implementation of an ID3v11Tag. It models an ID3 tag
    * pretty much the same way as it is physically stored inside an audio file.
    * <p>See <a href="http://www.id3.org">http://www.id3.org</a> for details about
    * ID3 tags.</p>
    * @author Ulrich Hilger
    * @author Light Development
    * @author <a href="http://www.lightdev.com">http://www.lightdev.com</a>
    * @author <a href="mailto:[email protected]">[email protected]</a>
    * @author published under the terms and conditions of the
    *      GNU General Public License,
    *      for details see file gpl.txt in the distribution
    *      package of this software
    * @version Version 1, October 13, 2004
    public class ID3v11Tag implements Serializable, Comparable {
       * construct an ID3v11Tag and read tag content from a given file
       * <p>This constructor can be used for cases where a RandomAccessFile has already
       * been opened and will be closed elsewhere</p>
       * @param rf RandomAccessFile  the open file to read from
       * @param isAtTagStartPos boolean  true, if the file pointer is at the
       * position where the ID3 tag starts; when false, the pointer is positioned accordingly here
       * @throws IOException
      public ID3v11Tag(RandomAccessFile rf, boolean isAtTagStartPos) throws IOException {
        if(isAtTagStartPos) {
          readTag(rf);
        else {
          readTag(rf, rf.length() - 128);
       * construct an ID3v11Tag and read tag content from a file at a given location
       * <p>This constructor opens and closes the audio file for reading</p>
       * @param absolutePath String  the absolute path to the audio file to open
       * @throws IOException
      public ID3v11Tag(String absolutePath) throws IOException {
        RandomAccessFile rf = new RandomAccessFile(absolutePath, "r");
        readTag(rf, rf.length() - 128);
        rf.close();
       * construct an ID3v11Tag and read tag content from a given file
       * <p>This constructor opens and closes the audio file for reading</p>
       * @param audioFile File  the audio file to read from
       * @throws IOException
      public ID3v11Tag(File audioFile) throws IOException {
        this(audioFile.getAbsolutePath());
       * get a string representation of this object
       * @return String
      public String toString() {
        DecimalFormat df = new DecimalFormat("00");
        return getArtist() + ", " + getAlbum() + " - " + df.format(getTrackNumber()) + " " + getTitle();
       * position to file pointer and read the tag
       * @param rf RandomAccessFile  the file to read from
       * @param jumpPos long  the position to jump to (the tag start position)
       * @throws IOException
      public void readTag(RandomAccessFile rf, long jumpPos) throws IOException {
        rf.seek(jumpPos);
        readTag(rf);
       * read the tag from a given file, assuming the file pointer to be at the tag start position
       * @param rf RandomAccessFile  the file to read from
       * @throws IOException
      public void readTag(RandomAccessFile rf) throws IOException {
        rf.read(tagBuf);
        if(tag.equalsIgnoreCase(new String(tagBuf))) {
          rf.read(title);
          rf.read(artist);
          rf.read(album);
          rf.read(year);
          rf.read(comment);
          rf.read(trackNo);
          rf.read(genre);
      public String getTitle() {
        return new String(title).trim();
      public String getArtist() {
        return new String(artist).trim();
      public String getAlbum() {
        return new String(album).trim();
      public String getYear() {
        return new String(year).trim();
      public String getComment() {
        return new String(comment).trim();
      public int getGenreId() {
        try {
          int id = new Byte(genre[0]).intValue();
          if(id < GENRE_ID_MIN || id > GENRE_ID_MAX) {
            return GENRE_ID_OTHER;
          else {
            return id;
        catch(Exception ex) {
          return GENRE_ID_OTHER;
      public String getGenreName() {
        return genreNames[getGenreId()];
      public int getTrackNumber() {
        try {
          return (int) trackNo[0];
        catch(Exception e) {
          return 0;
       * Compares this object with the specified object for order.
       * @param o the Object to be compared.
       * @return a negative integer, zero, or a positive integer as this object is less than, equal to,
       *                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Hi Franck,
    thank you, mate. I did what you suggested (changed class attached) but that did not change the mentioned behaviour.
    The first run is approximately 75 seconds with Java option -Xms40m and approx. double without, the second run and all subsequent runs are only 2-3 seconds each (!!!) even when terminating and re-starting the application between thread runs.
    I'm pretty clueless about that, any more help on this anyone?
    Thanks a lot and best regards
    Ulrich
    PS: BTW, I forgot to post the class that is filled with data by class CollectionThread, so here it is
    * Light Development Playlist Editor
    * Copyright (C) 2004 Ulrich Hilger
    * This program is free software; you can redistribute it and/or
    * modify it under the terms of the GNU General Public License
    * as published by the Free Software Foundation; either version 2
    * of the License, or (at your option) any later version.
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    * GNU General Public License for more details.
    * You should have received a copy of the GNU General Public License
    * along with this program; if not, write to the Free Software
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    package com.lightdev.app.playlisteditor.data;
    import java.io.File;
    import com.lightdev.lib.audio.ID3v11Tag;
    import javax.sound.sampled.UnsupportedAudioFileException;
    import java.io.IOException;
    import java.io.Serializable;
    import com.lightdev.lib.audio.AudioFileDescriptor;
    import com.lightdev.lib.ui.SortListModel;
    import java.util.Iterator;
    * Storage model for audio data.
    * <p>
    * <code>AudioDataModel</code> can be used to store ID3 tag data collected from
    * a directory with audio files to perform queries and reports on the found data.
    * </p>
    * <p>See <a href="http://www.id3.org">http://www.id3.org</a> for details about
    * ID3 tags.</p>
    * @author Ulrich Hilger
    * @author Light Development
    * @author <a href="http://www.lightdev.com">http://www.lightdev.com</a>
    * @author <a href="mailto:[email protected]">[email protected]</a>
    * @author published under the terms and conditions of the
    *      GNU General Public License,
    *      for details see file gpl.txt in the distribution
    *      package of this software as well as any licensing notes
    *      inside this documentation
    * @version 1, October 15, 2004
    public class AudioDataModel extends SortListModel implements Serializable {
       * constructor
      public AudioDataModel() {
       * add an audio track from a given audio file
       * <p>This will attempt to read ID3 tag data from the file.</p>
       * @param audioFile File  the file to add audio data for
       * @throws IOException
      public void addTrack(File audioFile) throws IOException {
        AudioFileDescriptor afd = new AudioFileDescriptor(audioFile.getAbsolutePath());
        if (!data.contains(afd)) {
          data.add(afd);
       * get all tracks for agiven combination of genre name, artist name and album name. Any of
       * the parameters may be null or AudioDataModel.FILTER_ALL
       * <p>Ugly code, I know, but it simply hard codes all combinations of the the mentioned
       * parameters. Any more elegant implementations welcome.</p>
       * @param genreName String  a genre name to get tracks for
       * @param artistName String  an artist name to get tracks for
       * @param albumName String  an album name to get tracks for
       * @return SortListModel   the found tracks in a list model
      public SortListModel getTracks(String genreName, String artistName, String albumName) {
        SortListModel foundTracks = new SortListModel();
        Iterator e = data.iterator();
        while(e.hasNext()) {
          AudioFileDescriptor afd = (AudioFileDescriptor) e.next();
          ID3v11Tag tag = afd.getID3v11Tag();
          if(genreName == null || genreName.equalsIgnoreCase(FILTER_ALL)) {
            if(artistName == null || artistName.equalsIgnoreCase(FILTER_ALL)) {
              if (tag.getAlbum().equalsIgnoreCase(albumName))
                foundTracks.add(afd);
            else {
              if(albumName == null || albumName.equalsIgnoreCase(FILTER_ALL)) {
                if (tag.getArtist().equalsIgnoreCase(artistName))
                  foundTracks.add(afd);
              else {
                if (tag.getArtist().equalsIgnoreCase(artistName) &&
                    tag.getAlbum().equalsIgnoreCase(albumName))
                  foundTracks.add(afd);
          else {
            if(artistName == null || artistName.equalsIgnoreCase(FILTER_ALL)) {
              if(albumName == null || albumName.equalsIgnoreCase(FILTER_ALL)) {
                if (tag.getGenreName().equalsIgnoreCase(genreName))
                  foundTracks.add(afd);
              else {
                if (tag.getGenreName().equalsIgnoreCase(genreName) &&
                    tag.getAlbum().equalsIgnoreCase(albumName))
                  foundTracks.add(afd);
            else {
              if(albumName == null || albumName.equalsIgnoreCase(FILTER_ALL)) {
                if (tag.getGenreName().equalsIgnoreCase(genreName) &&
                    tag.getArtist().equalsIgnoreCase(artistName))
                  foundTracks.add(afd);
              else {
                if (tag.getGenreName().equalsIgnoreCase(genreName) &&
                    tag.getArtist().equalsIgnoreCase(artistName) &&
                    tag.getAlbum().equalsIgnoreCase(albumName))
                  foundTracks.add(afd);
        foundTracks.sort();
        return foundTracks;
       * list all artists in this model
       * @return SortListModel
      public SortListModel listArtists() {
        SortListModel artists = new SortListModel();
        artists.add(FILTER_ALL);
        Iterator e = data.iterator();
        while (e.hasNext()) {
          ID3v11Tag tag = ((AudioFileDescriptor) e.next()).getID3v11Tag();
          String artistName = tag.getArtist();
          if (artists.indexOf(artistName) < 0) {
            artists.add(artistName);
        artists.sort();
        return artists;
       * list all artists in this model having titles belonging to a given genre
       * @param genreName String  name of the genre artists are searched for
       * @return SortListModel
      public SortListModel listArtists(String genreName) {
        SortListModel artists = new SortListModel();
        artists.add(FILTER_ALL);
        Iterator e = data.iterator();
        while (e.hasNext()) {
          ID3v11Tag tag = ((AudioFileDescriptor) e.next()).getID3v11Tag();
          String artistName = tag.getArtist();
          String genre = tag.getGenreName();
          if (artists.indexOf(artistName) < 0 && genre.equalsIgnoreCase(genreName)) {
            artists.add(artistName);
        artists.sort();
        return artists;
       * list all genres in this model
       * @return SortListModel
      public SortListModel listGenres() {
        SortListModel genres = new SortListModel();
        genres.add(FILTER_ALL);
        Iterator e = data.iterator();
        while (e.hasNext()) {
          ID3v11Tag tag = ((AudioFileDescriptor) e.next()).getID3v11Tag();
          String genreName = tag.getGenreName();
          if (genres.indexOf(genreName) < 0) {
            genres.add(genreName);
        genres.sort();
        return genres;
       * list all albums in this model
       * @return SortListModel
      public SortListModel listAlbums() {
        SortListModel albums = new SortListModel();
        albums.add(FILTER_ALL);
        Iterator e = data.iterator();
        while (e.hasNext()) {
          ID3v11Tag tag = ((AudioFileDescriptor) e.next()).getID3v11Tag();
          String albumName = tag.getAlbum();
          if (albums.indexOf(albumName) < 0) {
            albums.add(albumName);
        albums.sort();
        return albums;
       * list all albums in this model having titles belonging to a given genre
       * @param genreName String  name of the genre albums are searched for
       * @return SortListModel
      public SortListModel listAlbums(String genreName) {
        SortListModel albums = new SortListModel();
        albums.add(FILTER_ALL);
        Iterator e = data.iterator();
        while (e.hasNext()) {
          ID3v11Tag tag = ((AudioFileDescriptor) e.next()).getID3v11Tag();
          String albumName = tag.getAlbum();
          String genre = tag.getGenreName();
          if (albums.indexOf(albumName) < 0 && genre.equalsIgnoreCase(genreName)) {
            albums.add(albumName);
        albums.sort();
        return albums;
       * list all albums in this model having titles belonging to a given genre and artist
       * @param genreName String  name of the genre albums are searched for
       * @param artistName String  name of the artist albums are searched for
       * @return SortListModel
      public SortListModel listAlbums(String genreName, String artistName) {
        SortListModel albums = new SortListModel();
        albums.add(FILTER_ALL);
        Iterator e = data.iterator();
        while (e.hasNext()) {
          ID3v11Tag tag = ((AudioFileDescriptor) e.next()).getID3v11Tag();
          String albumName = tag.getAlbum();
          String genre = tag.getGenreName();
          String artist = tag.getArtist();
          if(genreName == null || genreName.equalsIgnoreCase(FILTER_ALL)) {
            if (albums.indexOf(albumName) < 0 &&
                artist.equalsIgnoreCase(artistName))
              albums.add(albumName);
          else {
            if (albums.indexOf(albumName) < 0 &&
                genre.equalsIgnoreCase(genreName) &&
                artist.equalsIgnoreCase(artistName))
              albums.add(albumName);
        albums.sort();
        return albums;
       * get the number of audio tracks stored in this data model
       * @return int  the number of tracks
      public int getTrackCount() {
        return data.size();
      /** constant to select all items of a given part */
      public static final String FILTER_ALL = "    all";
    }...and here the changed CollectionThread now caching found File objects in a vector
    * Light Development Playlist Editor
    * Copyright (C) 2004 Ulrich Hilger
    * This program is free software; you can redistribute it and/or
    * modify it under the terms of the GNU General Public License
    * as published by the Free Software Foundation; either version 2
    * of the License, or (at your option) any later version.
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    * GNU General Public License for more details.
    * You should have received a copy of the GNU General Public License
    * along with this program; if not, write to the Free Software
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    package com.lightdev.app.playlisteditor.data;
    import com.lightdev.lib.util.InfoThread;
    import java.io.File;
    import java.util.Vector;
    import java.util.Enumeration;
    * A class to collect audio data from a given storage location.
    * <p>
    * <code>CollectionThread</code> uses ID3 tag information to gain data.
    * </p>
    * <p>See <a href="http://www.id3.org">http://www.id3.org</a> for details about
    * ID3 tags.</p>
    * @author Ulrich Hilger
    * @author Light Development
    * @author <a href="http://www.lightdev.com">http://www.lightdev.com</a>
    * @author <a href="mailto:[email protected]">[email protected]</a>
    * @author published under the terms and conditions of the
    *      GNU General Public License,
    *      for details see file gpl.txt in the distribution
    *      package of this software as well as any licensing notes
    *      inside this documentation
    * @version 1, October 13, 2004
    public class CollectionThread extends InfoThread {
       * constructor
       * @param model  AudioDataModel  the data model to collect data to
      public CollectionThread(AudioDataModel model) {
        this.model = model;
       * constructor, creates a new empty AudioDataModel
      public CollectionThread() {
        this(new AudioDataModel());
       * set the data model to collect data to
       * @param model AudioDataModel  the model to collect data to
      public void setModel(AudioDataModel model) {
        this.model = model;
       * get the data model associated to this thread
       * @return AudioDataModel  the data model
      public AudioDataModel getModel() {
        return model;
       * set the directory to collect data from
       * @param rootDir File  the directory to collect data from
      public void setRootDirectory(File rootDir) {
        this.rootDir = rootDir;
       * this is the method to prepare a thread to run.
      protected void prepareThread() {
        maxValue = -1;
        filesProcessed = 0;
        innerCount = 0;
        fileList = new Vector();
       * do the actual work of this thread, i.e. iterate through a given directory
       * structure and collect audio data
       * @return boolean  true, if work is left
      protected boolean work() {
        boolean workIsLeft = true;
        if(getStatus() < STATUS_HALT_PENDING) {
          countElements(rootDir.listFiles());
        if(getStatus() < STATUS_HALT_PENDING) {
          workIsLeft = collect(); //collect(rootDir.listFiles());
          fileList.clear();
          fileList = null;
        return workIsLeft;
       * count the elements in a given file array including its subdirectories
       * @param files File[]
      private void countElements(File[] files) {
        int i = 0;
        while (i < files.length && getStatus() < STATUS_HALT_PENDING) {
          File file = files;
    if (file.isDirectory()) {
    countElements(file.listFiles());
    else {
    fileList.add(file);
    i++;
    maxValue++;
    * read data into model
    * @param files File[] the file array representing the content of a given directory
    * @return boolean true, if work is left
    private boolean collect(/*File[] files*/) {
    Enumeration files = fileList.elements();
    while(files.hasMoreElements() && getStatus() < STATUS_HALT_PENDING) {
    File file = (File) files.nextElement();
    try {
    model.addTrack(file);
    catch(Exception e) {
    fireThreadException(e);
    filesProcessed++;
    if(++innerCount > 99) {
    innerCount = 0;
    fireThreadProgress(filesProcessed);
    return false;
    int i = 0;
    while(i < files.length && getStatus() < STATUS_HALT_PENDING) {
    File file = files[i];
    if(file.isDirectory()) {
    collect(file.listFiles());
    else if(file.getName().toLowerCase().endsWith("mp3")) {
    try {
    model.addTrack(file);
    catch(Exception e) {
    fireThreadException(e);
    i++;
    filesProcessed++;
    fireThreadProgress(filesProcessed);
    return (i<files.length);
    /** the directory to collect data from */
    private File rootDir;
    /** the data model to collect data to */
    private AudioDataModel model;
    /** the number of files this thread processed so far while it is running */
    private long filesProcessed = 0;
    /** a list to temporary store found files */
    private Vector fileList;
    /** counter to determine when to fire progress messages */
    private int innerCount = 0;

  • How to enter a new Date and Time each day in a Numbers Spreadsheet...

    Hi... I have finally decided to move away from Excel and really give Numbers a shot... I have an application where each day I first enter the current date and time into a particular cell of a new row and then I enter some data in cells adjacent (in the same row) as that entered date-time. Then the next day I want to again enter the (new) current date and time and add more data next to that new date-time and so forth day after day... You can't use something as simple as =NOW() because then everyday, ALL of the date-times would change to the current time... Nope, now what I want... I just want to be able to EASILY and QUICKLY enter the current date-time value in one call and then have that specific value stay there forever... In Excel, this is accomplished with the keyboard shortcuts of
    <cntl> followed by a semicolon (;) for the date
    then enter a single space (for separation of date versus time) followed last by
    <command> followed again by a semicolon...
    So all together that is,
    <cntl><;><sp><command><;>
    and that puts something like
    4/10/2010 9:49:00 AM
    in a single cell...
    That's what I now want to be able to do in Numbers...
    How do I do that??? Do I use the menubar item "Insert Date and Time" and if so, how exactly do I get the current time to show up in the chosen cell??? With formatting??? Is there a keyboard shortcut method like the one I mentioned that works for Excel?? I've perused the manual and though I found lots on date-time, I didn't see how to do specifically what I want to do... I likely just missed it as surely it must be easy to do...
    Any feedback would be much appreciated... thanks... bob...

    Badunit wrote:
    The result of running that script is "UI Enabled = TRUE".
    I have cells named by the header values.
    This may be the problem.
    The script is an old one which deciphered only the letter+digit cell references.
    Here is a new version which works with every kind of cell reference.
    --[SCRIPT insertDateTime]
    Enregistrer le script en tant que Script : insertDateTime.scpt
    déplacer l'application créée dans le dossier
    <VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Numbers:
    Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
    Placez le curseur dans la cellule qui doit recevoir la date_heure
    menu Scripts > Numbers > insertDateTime
    La cellule pointée reçoit la date_heure.
    L'aide du Finder explique:
    L'Utilitaire AppleScript permet d'activer le Menu des scripts :
    Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
    Cochez la case "Afficher le menu des scripts dans la barre de menus".
    +++++++
    Save the script as a Script : insertDateTime.scpt
    Move the newly created application into the folder:
    <startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
    Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
    Put the cursor in the cell which must receive the date_time.
    menu Scripts > Numbers > insertDateTime
    The pointed cell receives the current date_time.
    The Finder's Help explains:
    To make the Script menu appear:
    Open the AppleScript utility located in Applications/AppleScript.
    Select the "Show Script Menu in menu bar" checkbox.
    Yvan KOENIG (VALLAURIS, France)
    2009/03/01
    2010/04/11 is now able to treat every kind of cell references
    property theApp : "Numbers"
    --=====
    on run
    set {dName, sName, tName, rname, rowNum1, colNum1, rowNum2, colNum2} to my getSelParams()
    my doYourDuty(colNum1, rowNum1, tName, sName, dName)
    end run
    --=====
    on doYourDuty(c, r, t, s, d) (*
    c = columnIndex
    r = rowIndex
    t = table's name
    s = sheet's name
    d = document's name *)
    local cdt
    set cdt to my cleanThisDate(current date) (* the new date_time as a clean date_time *)
    tell application "Numbers" to tell document d to tell sheet s to tell table t
    set value of cell r of column c to cdt as text
    end tell -- application …
    end doYourDuty
    --=====
    on cleanThisDate(dt)
    (* ugly code but once I got date_time with milliseconds so if necessary, I drop them *)
    local l
    set l to my decoupe(dt as text, ":")
    if (count of l) > 3 then set dt to date (my recolle(items 1 thru 3 of l, ":"))
    return dt
    end cleanThisDate
    --=====
    on getSelParams()
    local r_Name, t_Name, s_Name, d_Name, col_Num1, row_Num1, col_Num2, row_Num2
    set {d_Name, s_Name, t_Name, r_Name} to my getSelection()
    if r_Name is missing value then
    if my parleAnglais() then
    error "No selected cells"
    else
    error "Il n'y a pas de cellule sélectionnée !"
    end if
    end if
    set two_Names to my decoupe(r_Name, ":")
    set {row_Num1, col_Num1} to my decipher(item 1 of two_Names, d_Name, s_Name, t_Name)
    if item 2 of two_Names = item 1 of two_Names then
    set {row_Num2, col_Num2} to {row_Num1, col_Num1}
    else
    set {row_Num2, col_Num2} to my decipher(item 2 of two_Names, d_Name, s_Name, t_Name)
    end if
    return {d_Name, s_Name, t_Name, r_Name, row_Num1, col_Num1, row_Num2, col_Num2}
    end getSelParams
    --=====
    set {rowNumber, columnNumber} to my decipher(cellRef,docName,sheetName,tableName)
    apply to named row or named column !
    on decipher(n, d, s, t)
    tell application "Numbers" to tell document d to tell sheet s to tell table t to return {address of row of cell n, address of column of cell n}
    end decipher
    --=====
    set { d_Name, s_Name, t_Name, r_Name} to my getSelection()
    on getSelection()
    local _, theRange, theTable, theSheet, theDoc, errMsg, errNum
    tell application "Numbers" to tell document 1
    repeat with i from 1 to the count of sheets
    tell sheet i
    set x to the count of tables
    if x > 0 then
    repeat with y from 1 to x
    try
    (selection range of table y) as text
    on error errMsg number errNum
    set {_, theRange, _, theTable, _, theSheet, _, theDoc} to my decoupe(errMsg, quote)
    return {theDoc, theSheet, theTable, theRange}
    end try
    end repeat -- y
    end if -- x>0
    end tell -- sheet
    end repeat -- i
    end tell -- document
    return {missing value, missing value, missing value, missing value}
    end getSelection
    --=====
    on decoupe(t, d)
    local l
    set AppleScript's text item delimiters to d
    set l to text items of t
    set AppleScript's text item delimiters to ""
    return l
    end decoupe
    --=====
    on parleAnglais()
    local z
    try
    tell application theApp to set z to localized string "Cancel"
    on error
    set z to "Cancel"
    end try
    return (z is not "Annuler")
    end parleAnglais
    --=====
    --[/SCRIPT]
    It's available on my idisk :
    <http://public.me.com/koenigyvan>
    Download :
    For_iWork:iWork '09:for_Numbers09:insertDateTime.zip
    Yvan KOENIG (VALLAURIS, France) dimanche 11 avril 2010 14:16:41

  • Future Date Script in Acrobat, 6 months after current date

    Hey guys I have been working on this for hours and I am not sure why I cannot figure this out.  I am looking to have 1 field box in the form auto populate the current date and another field box to auto populate a date 6 months from the current date.  My current date code is attached, I have been playing around with so many variations that I do not want to confuse anyone with my other ugly code fragments.
    var bFirstTime=1;
    var f=this.getField("todaysDate");
    if (bFirstTime=1) {
    f.value=util.printd("mm/dd/yyyy",new Date());
    bFirstTime=0;
    //app.bFirstTime);

    Have you tried a document level funtction that runs when the PDF is opened. The following script fills in today's date if the field has not been field in and computes the date in 5 months using the parts of the date and the value of today's date.
    // one time use document level function
    ( function () {
    // update fields only if balnk
    if(this.getField('todaysDate').defaultValue == '') {
    // get current date time object
    var oNow = new Date();
    // get some date parts
    var fYear = oNow.getFullYear(); // 4 digit year
    var fMonth = oNow.getMonth(); // get zero based month
    var fDate = oNow.getDate(); // get date of month
    var sFormat = '%,302.0f/%,302.0f/%,304.0f';
    // fill in field
    this.getField('todaysDate').value = util.printf(sFormat, (fMonth + 1), fDate, fYear);
    // make permanent
    this.getField('todaysDate').defaultValue = this.getField('todaysDate').value;
    // compute date 6 months from today
    fMonth += 6;
    var oNew = new Date(fYear, fMonth, fDate);
    // get some date parts
    fYear = oNew.getFullYear(); // 4 digit year
    fMonth = oNew.getMonth(); // get zero based month
    fDate = oNew.getDate(); // get date of month
    // fill in field
    this.getField('newDate').value = util.printf(sFormat, (fMonth + 1), fDate, fYear);
    // make permanent
    this.getField('newDate').defaultValue = this.getField('newDate').value;
    // debugging aid
    app.alert('dates updated', 2, 0);
    } else {
    app.alert('dates not updated', 1, 0);
    } // end not empty
    return;
    } // end function
    () // call funtion
    ); // end document level function

  • LV 8.6: programatically pressing button only works in some VIs, not all?

    Setup is an old labview 8.6
    I'm tasked with fixing some strange old engine test bench which has a ~1E-6 measurement drift.
    The "easiest" work around fix would be to run the mechanics to a bottom end point then press the "reset" measurement button automatically.
    !!:  A "drive" vi and a "measurement" vi has to be running at the same time. The drive vi will then periodically drive the test bench to a mechanical end point and reset the measurement vi. This would get rid of the drift.
    !!:  Both vi's must be started manually and running. I cannot start one vi from the other. It messes things up. I know not why. There seems to be some strange dependency over compiled FPGA code somewhere.
    I'm no lab view wizard. It was 20 years since I touched it last.
    So digging through examples on how to press a button in one VI from another VI I found this:
    https://decibel.ni.com/content/docs/DOC-15962
    Which I built into a sub-vi and a test setup to see if I could make it work on the test bench. With some tweaking it works.
    A test "master" vi can press any button in a test "slave" vi.
    However. It is impossible to press the "reset" button in the "measurement" vi.
    Labview reports no errors, it just doesn't execute the value change event as far as I can understand.
    In fact, I can copy exactly the same code from the working "slave" vi into the "measurement" vi and it stops working. !!??
    How can code work perfectly well in one vi but not in another ?
    The "measurement" vi has some sort of compilation requirements, meaning any change to the vi takes >30min to "compile" before it can be run. Can this have something to do with why remote button pressing doesn't work?
    It also interfaces with some FPGA somewhere, can that have something to do with it ?
    I have no clue. Happy for any help here.

    Here it comes -- WARNING -- ugly code, this is my first labview in 20 years and I'm very short on time.
    press-button.vi
      the sub vi I mangle up from the example (https://decibel.ni.com/content/docs/DOC-15962)
    master.vi
      the test event sender
    slave.vi
      the test event receiver
    measurement.vi
      the real vi, where no buttons can be pressed
    In master.vi you can reconfigure the input to press-button to which vi and button to target. Right now it is set for the test slave vi (I think) to verify that it actually works as intended in the test environment.
    Hmm, seems there is a limit to 3 attachments, will post the measurement.vi in next post
    Attachments:
    press-button.vi ‏15 KB
    master.vi ‏19 KB
    slave.vi ‏29 KB

Maybe you are looking for