/*
*
* Perforce/JBuilder Opentool
* Copyright (C) 2002 Mark Ackerman
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.dafreels.opentools.actions.ui;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Rectangle;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import com.dafreels.opentools.MessageWriter;
import com.dafreels.vcs.command.MessageFormatter;
/**
* Title: Perforce Open Tool
* Description:
* Copyright: Copyright (c) 2005
* Company:
* @author George Lindholm
* @version 1.0
*
* Cloned from HistoryDialog
*/
public class JobsDialog extends JDialog
{
protected static final Vector _columnNames = new Vector(4);
private JTable _historyTable;
static
{
_columnNames.add("Job");
_columnNames.add("Date");
_columnNames.add("Username");
_columnNames.add("State");
_columnNames.add("Description");
}
public JobsDialog(Frame frame, String title, boolean modal)
{
super(frame, title, modal);
buildControls();
}
protected void buildControls()
{
getContentPane().setLayout(new GridBagLayout());
JPanel buttonPanel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 2;
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 5, 5, 5);
gbc.weightx = 1.0;
getContentPane().add(buttonPanel, gbc);
//Color gray = new Color(200,200,200);
JLabel label = new JLabel("File:");
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.fill = GridBagConstraints.NONE;
gbc.insets = new Insets(5, 5, 0, 5);
//getContentPane().add(label, gbc);
gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(5, 5, 5, 5);
//getContentPane().add(_fileName, gbc);
_historyTable = new JTable()
{
public boolean isCellEditable(int row, int col)
{
return false;
}
public Dimension getPreferredScrollableViewportSize()
{
Dimension d = super.getPreferredScrollableViewportSize();
d.height = getRowHeight() * 10;
return d;
}
};
_historyTable.setBackground(null);
//_historyTable.setEnabled(false);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 2;
gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(5, 5, 5, 5);
gbc.weightx = 1.0;
gbc.weighty = 1.0;
getContentPane().add(new JScrollPane(_historyTable), gbc);
JPanel panel = new JPanel(new GridBagLayout());
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 6;
gbc.gridwidth = 2;
gbc.anchor = GridBagConstraints.SOUTH;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(0, 0, 0, 0);
getContentPane().add(panel, gbc);
JButton button = new JButton("Close");
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.SOUTH;
gbc.fill = GridBagConstraints.NONE;
gbc.insets = new Insets(5, 5, 5, 5);
panel.add(button, gbc);
}
/**
* fill this dialog with the contents of formatter
* @param formatter the output from the <code>fstat</code> command
*/
public void fillForm(final MessageFormatter formatter)
{
String message, arg;
StringTokenizer tokenizer;
String token;
int field;
Vector row;
Vector table = new Vector();
MessageWriter.outputErrorMessages(MessageFormatter.getInstance());
while ((message = formatter.getNextMessage()) != null)
{
System.out.println(message);
if (message.equals(com.dafreels.vcs.command.ProcessReader.OUTPUTHEADER))
{
continue; // Ignore our noise in response
}
// format of message s/b:
// INF-276 on 2002/04/08 by gnl@Q *state* 'job description'
tokenizer = new StringTokenizer(message, " ");
field = 0;
row = new Vector(7);
while (tokenizer.hasMoreTokens() && field <= 7)
{
token = tokenizer.nextToken();
field++;
switch (field)
{
case 1: // Job
row.add(token);
break;
case 3: // Date
row.add(token);
break;
case 5: // Username
row.add(token);
break;
case 6: // State
row.add(token);
break;
case 7: // Description
int idx = message.indexOf("'");
if (idx == -1)
{
continue;
}
row.add(message.substring(idx + 1, message.length() - 1));
break;
case 2: // word 'on'
case 4: // word 'by'
break;
}
}
table.add(row);
}
DefaultTableModel model = new DefaultTableModel(table, _columnNames)
{
public boolean isCellEditable(int row, int column)
{
return false;
}
};
_historyTable.setModel(model);
pack();
setLocation();
}
/**
* set the dialogs location centered on its parent. If it doesn't
* hava a parent then center it on the screen.
*/
public void setLocation()
{
Component parent = getParent();
int ix, iy, bx, by;
Dimension d = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
Dimension dd = getSize();
if (parent == null)
{
ix = (d.width - dd.width) / 2;
iy = (d.height - dd.height) / 2;
} else
{
Rectangle bounds = parent.getBounds();
Rectangle abounds = getBounds();
ix = bounds.x + (bounds.width - abounds.width) / 2;
iy = bounds.y + (bounds.height - abounds.height) / 2;
}
if (iy < 10)
{
iy = 10;
}
if (ix < 10)
{
ix = 10;
}
bx = ix + dd.width;
by = iy + dd.height;
// see if the dialog is off the screen.
if (bx > d.width)
{
ix -= bx - d.width;
}
if (by > d.height)
{
iy -= by - d.height;
}
setLocation(ix, iy);
}
public static void main(String[] args)
{
new JobsDialog(new JFrame(), "Jobs", false).setVisible(true);
}
}