All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jpos.transaction.gui.TMMonitor Maven / Gradle / Ivy

Go to download

jPOS is an ISO-8583 based financial transaction library/framework that can be customized and extended in order to implement financial interchanges.

There is a newer version: 2.1.9
Show newest version
/*
 * jPOS Project [http://jpos.org]
 * Copyright (C) 2000-2015 Alejandro P. Revilla
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see .
 */

package org.jpos.transaction.gui;

import org.jpos.transaction.TransactionStatusListener;
import org.jpos.transaction.TransactionStatusEvent;
import org.jpos.transaction.TransactionManager;
import org.jpos.ui.UI;
import org.jpos.util.TPS;

import javax.swing.*;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import javax.swing.table.TableModel;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumnModel;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TMMonitor extends JPanel
        implements TransactionStatusListener, SwingConstants, ActionListener, AncestorListener
{
    UI ui;
    TransactionManager txnmgr;
    JTable table;
    AbstractTableModel model;
    TransactionStatusEvent[] events;
    JLabel tps = new JLabel("0");
    JLabel tpsAvg = new JLabel("0.00");
    JLabel tpsPeak = new JLabel("0");
    JLabel inTransit = new JLabel("0");
    JLabel outstanding = new JLabel("0");
    Timer timer;

    static final Font SMALL  = Font.decode ("terminal-plain-8");
    static final Font LARGE  = Font.decode ("terminal-plain-18");

    Color[] color = new Color[] {
        /* READY               */ Color.white,
        /* PREPARING           */ new Color (0xb3, 0xb3, 0xff), // blue
        /* PREPARING_FOR_ABORT */ new Color (0xff, 0xa3, 0xa3), // red
        /* COMMITTING          */ new Color (0xd1, 0xff, 0xd1), // green
        /* ABORTING            */ new Color (0xff, 0xa3, 0xa3), // red
        /* DONE                */ Color.white,
        /* PAUSED              */ new Color (0xff, 0x7f, 0x50)  // orange
    };

    public TMMonitor (UI ui, TransactionManager tmmgr) {
        super();
        this.ui = ui;
        this.txnmgr = tmmgr;
        setLayout(new BorderLayout());
        setBorder(BorderFactory.createRaisedBevelBorder());
        model = createModel ();

        table = createTable (model);
        JScrollPane scrollPane = new JScrollPane(table);

        add(createTPSPanel(), BorderLayout.EAST);
        add(scrollPane, BorderLayout.CENTER);
        tmmgr.addListener(this);
        addAncestorListener(this);
    }
    public void update(TransactionStatusEvent e) {
        if (ui.isDestroyed()) {
            return;
        }
        int row = e.getSession();
        events[row] = e;
        model.fireTableRowsUpdated(row, row);
        // table.getSelectionModel().setSelectionInterval(row, row);
        setBackgroundColor (row, color[e.getState().intValue()]);
        inTransit.setText (Long.toString (txnmgr.getInTransit()));
        outstanding.setText (Long.toString (txnmgr.getOutstandingTransactions()));
    }
    private void setBackgroundColor (int row, Color color) {
        for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy