views:

81

answers:

2

Executive summary: What kinds of sound architecture choices are there for displaying thread-safe, dynamic data in real time using Swing?

Details: I have recently completed writing a multi-threaded, automated trading platform in Java. I say "platform" because I have made it very easy to implement new and multiple trading programs by sub-classing virtual objects. I have encapsulated the trading code so I can use it in a Swing application, console application, or whatever. Currently I am running it with a Swing front-end.

I would say I am a Swing abuser rather than user. Not on purpose. It takes a special kind of thinking to develop a modern GUI and integrate it with dynamic data that I have yet to learn. I know the very basics, such as updating the screen only in the event dispatch thread. Here is how I display messages (from my SingleFrameApplication subclass):

 private class PrintTraderMsgTask extends SwingWorker<Void, String>{
    @Override
    protected Void doInBackground() {
        String msg;
        while(!isCancelled()){

               msg = m_data.m_TraderMsgs.poll();
               if(msg!=null){
                  publish(msg);
               }
        }
        return null;
    }

    @Override
    protected void process(List<String> chunks) {
     for (String item: chunks){
         m_view.displayTraderString(item);
     }
    }
}

The data element here is just

public ArrayBlockingQueue<String> m_TraderMsgs;

which any number of "Traders" (separate threads) might be sticking messages in at any time. The other type of data object I've used is a ConcurrentHashMap. I collect order logs, trade records, prices, and other sorts of data in these. So the picture I am trying to paint here is a large collection of time-dependent data, too much to display all at once.

What I would really like to do is display summary information and have the ability to drill down. Right now I am displaying messages in JTextAreas and other info in some JTextFields. I can read up on JCoolWhatever and stuff data in there. But before I start down that road I want to learn about other architecture choices.

Method 1: Use SwingWorkers to grab data and stick it in JWhatever which resides in my FrameView subclass.

Method 2: ???

...

We want:

(1) reasonable modularity.. enough to add/remove elements without ruining our evening

(2) interaction capability, specifically drill-down capability since there is so much data

Thanks... the real-time display of a complex set of dynamic data is an interesting subject and I hope we can get a good discussion going.

+1  A: 

One common approach to managing the complexity of hierarchical data is a collapsible tree. Used throughout the NetBeans IDE, org.netbeans.swing.outline.Outline is a particularly versatile implementation. NetBeans uses it in several windows, including Projects, Navigator, File, Services, etc. Because is derives from javax.swing.JTable, the usual Editors and Renderers mechanism is available. The article Announcing the new Swing Tree Table shows how it is used to model a file system. Although org-netbeans-swing-outline.jar is included with the IDE, it may be used in isolation.

Addendum:

"Drill down" could be clicking on the trading program triggering the display of all its trades in another pane.

JSplitPane is useful in this context: one pane might hold the tree, while the other displays expanded details of the selected node/row.

trashgod
+1  A: 

JIDE Grids has several types of hierarchical tables. I've only used the tree table. The "Hierarchical Table (Example 1)" screenshot seems to be pretty close to what you want:

alt text

Geoffrey Zheng