package infosapient.ui;
/*
* Copyright (c) 2001, Workplace Performance Tools, All Rights Reserved.
*
* LICENSE TO USE THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE 0.5
* ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
* The license may be viewed at:
* http://www.opensource.org/licenses/cpl.html
*/
import infosapient.system.FSEvent;
import infosapient.system.FzySet;
import infosapient.util.Format;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;
import javax.swing.event.*;
/**
* InfoSapientSwingSetList is a JPanel with a table representing each FzySet.
* @author Michael McConnell
*/
public class InfoSapientSwingSetList extends javax.swing.JPanel {
static final long serialVersionUID = 551459254328587487L;
static final int SEQNUM = 0;
static final int NAME = 1;
static final int TYPE = 2;
static final int SIDE = 3;
static final int LODOM = 4;
static final int HIDOM = 5;
static final int CMPMEM = 6;
static Format Flt_Format, Exp_Format, Dec_Format;
static final String NAMES[] = { "SEQ NUM",
"NAME",
"SET TYPE",
"SIDE",
"LO DOMAIN",
"HI DOMAIN",
"100% MEM" };
transient protected int currentLastRow = 0;
transient protected int finalRow = 0;
transient protected boolean incRow = true;
transient protected Vector rowContents = null;
transient protected DefaultTableModel tableModel;
transient protected JScrollPane scrollpane;
transient protected MY_JTable theTable;
transient protected JPopupMenu pMenu;
transient protected JMenuItem createSetItem;
transient protected JMenuItem editSetItem;
transient protected JMenuItem deleteSetItem;
transient protected JMenuItem acceptSetItem;
transient protected PMenuListener pmenuListener;
transient protected Format dForm;
class PMenuListener implements ActionListener {
public void actionPerformed(ActionEvent ae) {
String cmd = ae.getActionCommand();
if (cmd.equals("Create Set")) do1();
if (cmd.equals("Edit Set")) do2();
if (cmd.equals("Delete Set")) do3();
}
void do1() {
int seqNum;
if ((seqNum = getSelectedRow()) < 0){
int result = JOptionPane.showConfirmDialog(InfoSapientSwingSetList.this,
"The new set will be inserted ABOVE the first set.\nClick ok to continue.",
"ARC Light Information", JOptionPane.OK_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE);
if (result == JOptionPane.CANCEL_OPTION) return;
}
}
void do2() {System.out.println("Edit Set " );}
void do3() {System.out.println("Delete Set " );}
}
class MY_JTable extends JTable {
public MY_JTable(DefaultTableModel t) {
super(t);
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
}
protected void processMouseEvent(MouseEvent e) {
switch (e.getModifiers()) {
case
InputEvent.BUTTON2_MASK :
handleButton2Click(e.getPoint());
break;
case
InputEvent.BUTTON3_MASK :
handleButton3Click(e.getPoint());
break;
default:
super.processMouseEvent(e);
}
}
void handleButton2Click(Point ap) {pMenu.show(this, ap.x, ap.y);}
void handleButton3Click(Point ap) {pMenu.show(this, ap.x, ap.y);}
}
public InfoSapientSwingSetList() {
super();
try {
Flt_Format = new Format("%10.3f");
Exp_Format = new Format("%10.3e");
Dec_Format = new Format("%13d");
} catch (IllegalArgumentException iae) {
}
setBackground(SystemColor.control);
setLayout(new BorderLayout());
setBorder(new EmptyBorder(5, 5, 5, 5));
setVisible(true);
tableModel = new DefaultTableModel(NAMES, 0);
theTable = new MY_JTable(tableModel);
scrollpane = JTable.createScrollPaneForTable((JTable) theTable);
this.add(scrollpane, BorderLayout.CENTER);
pMenu = new JPopupMenu();
pmenuListener = new PMenuListener();
createSetItem = new JMenuItem("Create Set");
createSetItem.addActionListener(pmenuListener);
pMenu.add(createSetItem);
editSetItem = new JMenuItem("Edit Set");
editSetItem.addActionListener(pmenuListener);
pMenu.add(editSetItem);
deleteSetItem = new JMenuItem("Delete Set");
deleteSetItem.addActionListener(pmenuListener);
pMenu.add(deleteSetItem);
pMenu.add(new JSeparator());
acceptSetItem = new JMenuItem("Accept Changes");
acceptSetItem.addActionListener(pmenuListener);
pMenu.add(acceptSetItem);
}
protected void addSet(FzySet theSet) {
RepaintManager repaintManager = RepaintManager.currentManager(this);
rowContents = new Vector(NAMES.length);
rowContents.insertElementAt(Integer.toString(currentLastRow), SEQNUM);
rowContents.insertElementAt(theSet.getName(), NAME);
rowContents.insertElementAt(theSet.typeAsString(), TYPE);
if (theSet.isLeftShouldered())
rowContents.insertElementAt("Left", SIDE);
else if (theSet.isRightShouldered())
rowContents.insertElementAt("Right", SIDE);
else
rowContents.insertElementAt("Two", SIDE);
rowContents.insertElementAt(Flt_Format.form(theSet.getLowDomain()), LODOM);
rowContents.insertElementAt(Flt_Format.form(theSet.getHighDomain()), HIDOM);
rowContents.insertElementAt(Flt_Format.form(theSet.getCmpMembership()), CMPMEM);
tableModel.addRow(rowContents);
incrementRowCnt();
repaintManager.markCompletelyDirty(this);
}
protected void decrementRowCnt(){
finalRow = --currentLastRow;
}
protected void editSelection(int rowNumber) {}
public int getSelectedRow() {
return theTable.getSelectedRow();
}
protected void incrementRowCnt() {
if (incRow) finalRow = ++currentLastRow;
else currentLastRow = finalRow;
}
public void insertSet(int rowNum, FzySet theSet) {
currentLastRow = rowNum;
incRow = false;
addSet(theSet);
incRow = true;
}
public void removeAll() {
RepaintManager repaintManager = RepaintManager.currentManager(this);
for (int cnt = tableModel.getRowCount();
cnt > 0;
cnt = tableModel.getRowCount())
tableModel.removeRow(cnt-1);
}
}