/*
*
* Perforce/JBuilder Opentool
* Copyright (C) 2001 David Freels
*
* 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.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.util.Vector;
import java.util.Date;
import java.text.SimpleDateFormat;
import com.borland.primetime.ide.Browser;
import com.dafreels.opentools.properties.PerforceGroup;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import com.dafreels.opentools.actions.ui.FileModel;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2001
* Company: DF Systems
* @author David Freels
* @version 1.0
*/
public final class SubmitDialog extends JDialog implements ActionListener
{
JPanel infoPanel = new JPanel();
GridBagLayout gridBagLayout1 = new GridBagLayout();
JPanel buttonPanel = new JPanel();
JPanel descriptionPanel = new JPanel();
JPanel filesPanel = new JPanel();
JButton submit = new JButton();
JButton cancel = new JButton();
GridLayout buttonLayout = new GridLayout();
JLabel descLabel = new JLabel();
GridBagLayout gridBagLayout2 = new GridBagLayout();
JScrollPane descSP = new JScrollPane();
GridBagLayout gridBagLayout3 = new GridBagLayout();
JTextArea descTA = new JTextArea();
JScrollPane filesSP = new JScrollPane();
JLabel fileLabel = new JLabel();
GridBagLayout gridBagLayout4 = new GridBagLayout();
JLabel changeLabel = new JLabel();
JLabel dateLabel = new JLabel();
JLabel clientLabel = new JLabel();
JLabel userLabel = new JLabel();
JLabel statusLabel = new JLabel();
JTextField changeTF = new JTextField();
JTextField dateTF = new JTextField();
JTextField clientTF = new JTextField();
JTextField userTF = new JTextField();
JTextField statusTF = new JTextField();
private boolean _submitVal = false;
private FileModel _dtm = new FileModel();
private final static String newLine = System.getProperty("line.separator");
JPanel tablePanel = new JPanel();
JTable fileTable = new JTable();
GridBagLayout tableLayout = new GridBagLayout();
public SubmitDialog(Frame frame, String title, boolean modal)
{
super(frame, title, modal);
this.adjustDialog();
try
{
jbInit();
//pack();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
private void adjustDialog()
{
//Set the size of the dialog
this.setSize(450,500);
//Position variables
double x = 0;
double y = 0;
double width = 0;
double height = 0;
//Get the position variables from the parent
if(this.getParent() != null)
{
width = this.getParent().getWidth() + this.getParent().getLocation().getX();
height = this.getParent().getHeight(); // - this.getParent().getLocation().getY();
} else //Make up the position variables
{
width = this.getToolkit().getDefaultToolkit().getScreenSize().getWidth();
height = this.getToolkit().getDefaultToolkit().getScreenSize().getHeight();
}
x = (width / 2) + (this.getSize().getWidth() / 2);
y = (height / 2) + (this.getSize().getHeight() / 2);
this.setLocation((int)x, (int)y);
}
public SubmitDialog()
{
this(null, "", false);
}
public void showSubmit(Vector files)
{
Vector columns = new Vector();
columns.add("submit");
columns.add("");
descTA.setText("<enter description here>");
descTA.select(0, 24);
//Reset the values in the form
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
dateTF.setText(sdf.format(new Date()));
changeTF.setText("new");
clientTF.setText(PerforceGroup.CLIENTSPEC.getValue(Browser.getActiveBrowser().getActiveProject()));
userTF.setText(PerforceGroup.USERNAME.getValue(Browser.getActiveBrowser().getActiveProject()));
statusTF.setText("new");
if(files == null)
{
_submitVal = false;
this.setModal(false);
return;
}
_dtm.setDataVector(files, columns);
fileTable.doLayout();
//Resize the checkbox column
fileTable.getColumnModel().getColumn(0).setMinWidth(15);
fileTable.getColumnModel().getColumn(0).setMaxWidth(15);
this.setModal(true);
this.setVisible(true);
}
public Vector getFiles()
{
//Get the data from the table
Vector files = _dtm.getDataVector();
//Count backwards, as Vector shifts data as it is removed
for(int i = files.size() - 1; i >= 0; i--)
{
if(! ((Boolean)((Vector)files.elementAt(i)).elementAt(0)).booleanValue())
{
files.removeElementAt(i);
}
}
return files;
}
public String getDescription()
{
int lines = descTA.getLineCount();
String change = descTA.getText();
StringBuffer changeList = new StringBuffer();
//Parse the description and make sure it is tabbed
for(int i = 0; i < lines; i++)
{
if(change.indexOf("\n") != -1)
{
changeList.append("\t"+change.substring(0,change.indexOf("\n"))+newLine);
change = change.substring(change.indexOf("\n") + 1);
} else if(change.indexOf("\r\n") != -1)
{
changeList.append("\t"+change.substring(0,change.indexOf("\r\n"))+newLine);
change = change.substring(change.indexOf("\r\n") + 1);
} else
{
changeList.append("\t"+change+newLine);
}
}
return changeList.toString();
}
public boolean getState()
{
return _submitVal;
}
void jbInit() throws Exception
{
infoPanel.setLayout(gridBagLayout4);
this.getContentPane().setLayout(gridBagLayout1);
descriptionPanel.setLayout(gridBagLayout2);
filesPanel.setLayout(gridBagLayout3);
buttonPanel.setLayout(buttonLayout);
submit.setActionCommand("submit");
submit.setText("Submit");
submit.addActionListener(this);
cancel.setActionCommand("cancel");
cancel.setText("Cancel");
cancel.addActionListener(this);
buttonLayout.setRows(2);
buttonLayout.setColumns(1);
buttonLayout.setHgap(5);
buttonLayout.setVgap(5);
descLabel.setText("Description:");
descSP.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
descSP.setMaximumSize(new Dimension(400, 70));
descTA.setWrapStyleWord(true);
descTA.setToolTipText("Add a description of the change here");
filesSP.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
filesSP.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
filesSP.setAutoscrolls(true);
filesSP.setMaximumSize(new Dimension(1000, 1000));
fileLabel.setText("Files:");
changeLabel.setText("Change:");
dateLabel.setText("Date:");
clientLabel.setText("Client:");
userLabel.setText("User:");
statusLabel.setText("Status:");
changeTF.setEditable(false);
dateTF.setEditable(false);
clientTF.setEditable(false);
userTF.setEditable(false);
statusTF.setEditable(false);
fileTable.setShowHorizontalLines(false);
fileTable.setShowVerticalLines(false);
fileTable.setPreferredSize(new Dimension(1000, 1000));
fileTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
fileTable.setCellSelectionEnabled(true);
fileTable.setColumnSelectionAllowed(true);
fileTable.setPreferredScrollableViewportSize(new Dimension(1000, 1000));
fileTable.setEditingColumn(0);
fileTable.setModel(_dtm);
fileTable.setRowSelectionAllowed(true);
fileTable.sizeColumnsToFit(1);
tablePanel.setLayout(tableLayout);
this.getContentPane().add(descriptionPanel, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 400, -3));
descriptionPanel.add(descLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
descriptionPanel.add(descSP, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 400, 70));
descSP.getViewport().add(descTA, null);
this.getContentPane().add(filesPanel, new GridBagConstraints(0, 2, 3, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 400, 4));
filesPanel.add(filesSP, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 400, 70));
filesSP.getViewport().add(tablePanel, null);
tablePanel.add(fileTable, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
filesPanel.add(fileLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
this.getContentPane().add(infoPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
,GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE, new Insets(3, 4, 3, 4), 548, 218));
infoPanel.add(dateLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 50, 0));
infoPanel.add(clientLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 50, 0));
infoPanel.add(userLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 50, 0));
infoPanel.add(statusLabel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 50, 0));
infoPanel.add(changeLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 50, 0));
infoPanel.add(changeTF, new GridBagConstraints(2, 0, 4, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 170, 0));
infoPanel.add(dateTF, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 170, 0));
infoPanel.add(clientTF, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 170, 0));
infoPanel.add(userTF, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 170, 0));
infoPanel.add(statusTF, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 170, 0));
this.getContentPane().add(buttonPanel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(10, 5, 0, 5), 3, 4));
buttonPanel.add(submit, null);
buttonPanel.add(cancel, null);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("cancel"))
{
_submitVal = false;
this.setVisible(false);
this.setModal(false);
} else if(e.getActionCommand().equals("submit"))
{
_submitVal = true;
this.setVisible(false);
this.setModal(false);
}
}
}