From 254ee6f47eebfc00462c10756a92066e82cc1a96 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 21 Jun 2011 15:46:02 +0200 Subject: Initial commit --- source/com/c2kernel/gui/tabs/HistoryPane.java | 253 ++++++++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100755 source/com/c2kernel/gui/tabs/HistoryPane.java (limited to 'source/com/c2kernel/gui/tabs/HistoryPane.java') diff --git a/source/com/c2kernel/gui/tabs/HistoryPane.java b/source/com/c2kernel/gui/tabs/HistoryPane.java new file mode 100755 index 0000000..091ef5e --- /dev/null +++ b/source/com/c2kernel/gui/tabs/HistoryPane.java @@ -0,0 +1,253 @@ +/* + * StatusPane.java + * + * Created on March 20, 2001, 3:30 PM + */ + +package com.c2kernel.gui.tabs; + +/** + * @author abranson + * @version + */ +import java.awt.GridBagConstraints; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.Box; +import javax.swing.JButton; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.table.AbstractTableModel; + +import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.entity.C2KLocalObject; +import com.c2kernel.entity.proxy.EntityProxyObserver; +import com.c2kernel.events.Event; +import com.c2kernel.events.History; +import com.c2kernel.lifecycle.instance.stateMachine.Transitions; +import com.c2kernel.persistency.ClusterStorage; +import com.c2kernel.utils.Language; +import com.c2kernel.utils.Logger; + +/** + * Pane to display all work orders that this agent can execute, and activate + * them on request from the user. Subscribes to NodeItem for WorkOrder objects. + * @version $Revision: 1.22 $ $Date: 2005/04/26 06:48:13 $ + * @author $Author: abranson $ + */ +public class HistoryPane extends EntityTabPane implements ActionListener, EntityProxyObserver { + + History history; + HistoryTableModel model; + JTable eventTable; + JButton startButton = new JButton("<<"); + JButton prevButton = new JButton("<"); + JButton nextButton = new JButton(">"); + JButton endButton = new JButton(">>"); + public static final int SIZE = 30; + int currentSize = SIZE; + + public HistoryPane() { + super("History", "Event History"); + initPanel(); + + // add buttons + Box navBox = Box.createHorizontalBox(); + navBox.add(startButton); navBox.add(prevButton); + navBox.add(nextButton); navBox.add(endButton); + + // setup buttons + //startButton.setEnabled(false); nextButton.setEnabled(false); + //prevButton.setEnabled(false); endButton.setEnabled(false); + startButton.setActionCommand("start"); + startButton.addActionListener(this); + prevButton.setActionCommand("prev"); + prevButton.addActionListener(this); + nextButton.setActionCommand("next"); + nextButton.addActionListener(this); + endButton.setActionCommand("end"); + endButton.addActionListener(this); + getGridBagConstraints(); + c.gridx = 0; c.gridy = 1; + c.anchor = GridBagConstraints.NORTHWEST; + c.fill=GridBagConstraints.NONE; + c.weightx=0; c.weighty=0; + gridbag.setConstraints(navBox, c); + add(navBox); + + + // Create table + eventTable = new JTable(); + JScrollPane eventScroll= new JScrollPane(eventTable); + c.weightx = 1.0; c.weighty = 1.0; + c.fill = GridBagConstraints.BOTH; c.gridy++; + gridbag.setConstraints(eventScroll, c); + add(eventScroll); + + } + + public void reload() { + history.clear(); + jumpToEnd(); + } + + public void run() { + Thread.currentThread().setName("History Pane Builder"); + try { + history = (History)sourceEntity.getEntity().getObject(ClusterStorage.HISTORY); + sourceEntity.getEntity().subscribe(this, ClusterStorage.HISTORY, false); + } catch (ObjectNotFoundException e) { + Logger.error(e); + } + model = new HistoryTableModel(); + eventTable.setModel(model); + jumpToEnd(); + } + + public void jumpToEnd() { + int lastEvent = history.getLastId(); + int firstEvent = 0; currentSize = SIZE; + if (lastEvent > currentSize) firstEvent = lastEvent - currentSize + 1; + if (lastEvent < currentSize) currentSize = lastEvent + 1; + Logger.msg(5, "HistoryPane.run() - init table start "+firstEvent+" for "+currentSize); + model.setView(firstEvent, currentSize); + } + + public void add(C2KLocalObject contents) { + jumpToEnd(); + } + + public void remove(String id) { + // don't have to deal with this normally + } + + public void actionPerformed(ActionEvent e) { + if (e.getActionCommand().equals("end")) { + jumpToEnd(); + return; + } + + int lastEvent = history.getLastId(); + int startEvent = model.getStartId(); + if (e.getActionCommand().equals("start")) { + currentSize = SIZE; + startEvent = 0; + } + + else if (e.getActionCommand().equals("prev")) { + currentSize = SIZE; + startEvent-=currentSize; + if (startEvent<0) startEvent = 0; + } + else if (e.getActionCommand().equals("next")) { + currentSize = SIZE; + startEvent+=currentSize; + if (startEvent > lastEvent) + startEvent = lastEvent - currentSize +1; + } + else { // unknown action + return; + } + + model.setView(startEvent, currentSize); + } + + private class HistoryTableModel extends AbstractTableModel { + Event[] event; + Integer[] ids; + int loaded = 0; + int startId = 0; + + public HistoryTableModel() { + event = new Event[0]; + ids = new Integer[0]; + } + + public int getStartId() { + return startId; + } + + public void setView(int startId, int size) { + event = new Event[size]; + ids = new Integer[size]; + this.startId = startId; + for (int i=0; i