/* * * 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.Color; 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.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.DefaultListModel; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.SwingUtilities; import com.borland.primetime.ide.Browser; import com.borland.primetime.ide.Message; import com.dafreels.opentools.Main; import com.dafreels.opentools.MessageWriter; import com.dafreels.vcs.command.Command; import com.dafreels.vcs.command.CommandTool; import com.dafreels.vcs.command.MessageFormatter; import com.dafreels.vcs.command.PropertyInterface; /** * <p>Title: Perforce OpenTools </p> * <p>Description: display the results of the Perforce fstat command</p> * <p>Copyright: Copyright (c) 2000</p> * <p>Company: </p> * @author Mark Ackerman * */ public class StatusDialog extends JDialog { public static final String CLIENT_FILE = "clientFile"; public static final String DEPOT_FILE = "depotFile"; public static final String HEAD_REV = "headRev"; public static final String HAVE_REV = "haveRev"; public static final String OURLOCK = "ourLock"; public static final String ACTION = "action"; public static final String LEAD_IN = "... "; public static final String OTHER_OPEN = "otherOpen"; public static final String OTHER_LOCK = "otherLock"; public static final String OTHER_ACTION = "otherAction"; public static final String HEAD_CHANGE = "headChange"; public static final String HEAD_TYPE = "headType"; public static final String HEAD_TIME = "headTime"; public static final String HEAD_ACTION = "headAction"; public static final String SLASH_SLASH = "//"; private JTextField _clientFile; private JTextField _depotFile; private JTextField _fileType; private JTextField _headAction; private JTextField _lastModTime; private JTextField _headChange; private JTextField _depotRevision; private JTextField _clientRevision; private JList _actionBy; private JTextField _action; private JTextField _lockedBy; /** * create a new StatusDialog object * @param frame the parent Frame * @param title the title for this dialog * @param modal true if this dialog is to be modal */ public StatusDialog(Frame frame, String title, boolean modal) { super(frame, title, modal); buildControls(); } /** * build the controls for this dialog */ protected void buildControls() { getContentPane().setLayout(new GridBagLayout()); Insets insets = new Insets(5,5,0,5); JLabel label = new JLabel("Depot File:"); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.NONE; gbc.insets = insets; getContentPane().add(label, gbc); _depotFile = new JTextField(); _depotFile.setBackground(null); _depotFile.setEditable(false); gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 0; gbc.gridwidth = 3; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = insets; getContentPane().add(_depotFile, gbc); label = new JLabel("Client File:"); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 1; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.NONE; gbc.insets = insets; getContentPane().add(label, gbc); _clientFile = new JTextField(); _clientFile.setBackground(null); _clientFile.setEditable(false); gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 1; gbc.gridwidth = 3; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = insets; getContentPane().add(_clientFile, gbc); label = new JLabel("File Type:"); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 2; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.NONE; gbc.insets = insets; getContentPane().add(label, gbc); _fileType = new JTextField() { public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); d.width = 100; return d; } public Dimension getMinimumSize() { return getPreferredSize(); } }; _fileType.setBackground(null); _fileType.setHorizontalAlignment(SwingUtilities.RIGHT); _fileType.setEditable(false); gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 2; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = insets; getContentPane().add(_fileType, gbc); label = new JLabel("Head Revision:"); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 3; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.NONE; gbc.insets = insets; getContentPane().add(label, gbc); _depotRevision = new JTextField() { public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); d.width = 100; return d; } public Dimension getMinimumSize() { return getPreferredSize(); } }; _depotRevision.setBackground(null); _depotRevision.setEditable(false); _depotRevision.setHorizontalAlignment(SwingUtilities.RIGHT); gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 3; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = insets; getContentPane().add(_depotRevision, gbc); label = new JLabel("Have Revision:"); gbc = new GridBagConstraints(); gbc.gridx = 2; gbc.gridy = 3; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.NONE; gbc.insets = insets; getContentPane().add(label, gbc); _clientRevision = new JTextField() { public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); d.width = 100; return d; } public Dimension getMinimumSize() { return getPreferredSize(); } }; _clientRevision.setBackground(null); _clientRevision.setEditable(false); _clientRevision.setHorizontalAlignment(SwingUtilities.RIGHT); gbc = new GridBagConstraints(); gbc.gridx = 3; gbc.gridy = 3; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = insets; getContentPane().add(_clientRevision, gbc); label = new JLabel("Head Action:"); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 4; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.NONE; gbc.insets = insets; getContentPane().add(label, gbc); _headAction = new JTextField() { public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); d.width = 100; return d; } public Dimension getMinimumSize() { return getPreferredSize(); } }; _headAction.setBackground(null); _headAction.setEditable(false); _headAction.setHorizontalAlignment(SwingUtilities.RIGHT); gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 4; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = insets; getContentPane().add(_headAction, gbc); label = new JLabel("Head Change:"); gbc = new GridBagConstraints(); gbc.gridx = 2; gbc.gridy = 4; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.NONE; gbc.insets = insets; getContentPane().add(label, gbc); _headChange = new JTextField() { public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); d.width = 100; return d; } public Dimension getMinimumSize() { return getPreferredSize(); } }; _headChange.setBackground(null); _headChange.setEditable(false); _headChange.setHorizontalAlignment(SwingUtilities.RIGHT); gbc = new GridBagConstraints(); gbc.gridx = 3; gbc.gridy = 4; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = insets; getContentPane().add(_headChange, gbc); label = new JLabel("Last Mod Time:"); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 5; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.NONE; gbc.insets = insets; getContentPane().add(label, gbc); _lastModTime = new JTextField(); _lastModTime.setBackground(null); _lastModTime.setEditable(false); gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 5; gbc.gridwidth = 3; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = insets; getContentPane().add(_lastModTime, gbc); label = new JLabel("Opened By:"); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 6; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.NONE; gbc.insets = insets; getContentPane().add(label, gbc); _actionBy = new JList() { public Dimension getPreferredScrollableViewportSize() { Dimension d = super.getPreferredScrollableViewportSize(); d.height = 200; return d; } public Dimension getMinimumSize() { return getPreferredScrollableViewportSize(); } }; _actionBy.setBorder(_lastModTime.getBorder()); _actionBy.setBackground(null); gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 6; gbc.gridwidth = 4; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = insets; getContentPane().add(new JScrollPane(_actionBy), gbc); label = new JLabel("Locked By"); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 7; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = insets; getContentPane().add(label, gbc); _lockedBy = new JTextField(); _lockedBy.setBackground(null); _lockedBy.setEditable(false); gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 7; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = insets; getContentPane().add(_lockedBy, gbc); JPanel panel = new JPanel(new GridBagLayout()); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 8; gbc.gridwidth = 4; gbc.anchor = GridBagConstraints.SOUTHEAST; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = insets; getContentPane().add(panel, gbc); JButton closebutton = new JButton("Close"); gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 1; gbc.anchor = GridBagConstraints.SOUTH; gbc.fill = GridBagConstraints.NONE; gbc.insets = insets; panel.add(closebutton, gbc); closebutton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); } }); } /** * fill this dialog with the contents of formatter * @param formatter the output from the <code>fstat</code> command */ public void fillForm(MessageFormatter formatter) { String message, arg; Message errorMsg; MessageWriter.outputErrorMessages(MessageFormatter.getInstance()); PropertyInterface props = Main.m_props; DefaultListModel model = new DefaultListModel(); boolean showOutput = Main.m_props.showOutput(); String otherOpenUser = null; while( (message = formatter.getNextMessage()) != null) { if ( showOutput ) { Browser.getActiveBrowser().getMessageView().addMessage(Main.PERFORCEMESSAGES, new Message(message)); } if ( message.startsWith(LEAD_IN)) { message = message.substring(4); if ( message.startsWith(LEAD_IN)) { message = message.substring(4); } message = message.trim(); arg = getArg(message); if ( message.startsWith(CLIENT_FILE)) { _clientFile.setText(arg); } else if ( message.startsWith(DEPOT_FILE)) { if ( "".equals(_depotFile.getText()) ) { _depotFile.setText(arg); } else { // support multiple files being selected StatusDialog dialog = new StatusDialog((Frame)getParent(),getTitle(), false); dialog._depotFile.setText(arg); dialog.fillForm(formatter); dialog.setVisible(true); break; } } else if ( message.startsWith(HEAD_REV)) { _depotRevision.setText(arg); } else if ( message.startsWith(HAVE_REV)) { _clientRevision.setText(arg); } /* else if ( message.startsWith(OURLOCK)) { _lockedBy.setText(props.getUserName() +"@"+props.getClientSpec()); } else if ( message.startsWith(ACTION)) { model.addElement(props.getUserName() +"@"+props.getClientSpec()); } else if ( message.startsWith(OTHER_OPEN)) { String type = getType(message); if ( OTHER_OPEN.equals(type)) { continue; } type = type.substring(OTHER_OPEN.length()); int idx = -1; try { idx = Integer.parseInt(type); } catch ( Exception e) { // don't see this in JBuilderW System.out.println("Error parsing message "+message +" Error " + e); continue; } if ( idx == -1 ) { continue; } model.add(idx, arg); otherOpenUser = arg; } else if ( message.startsWith(OTHER_ACTION)) { String type = getType(message); if ( OTHER_ACTION.equals(type)) { continue; } type = type.substring(OTHER_ACTION.length()); int idx = -1; try { idx = Integer.parseInt(type); } catch ( Exception e) { // don't see this in JBuilderW System.out.println("Error parsing message "+message +" Error " + e); continue; } if ( idx == -1 ) { continue; } try { String value = (String)model.get(idx); value = value.concat(" (").concat(arg).concat(")"); model.removeElementAt(idx); model.add(idx, value); } catch (Exception e) { // don't see this in JBuilderW System.out.println("Invalid index " + idx+" " + e); continue; } } else if ( message.startsWith(OTHER_LOCK)) { if ( otherOpenUser != null ) { _lockedBy.setText(otherOpenUser); } } */ else if ( message.startsWith(HEAD_CHANGE)) { _headChange.setText(arg); } else if ( message.startsWith(HEAD_TYPE)) { _fileType.setText(arg); } else if ( message.startsWith(HEAD_ACTION)) { _headAction.setText(arg); } else if ( message.startsWith(HEAD_TIME)) { arg = arg+"000"; try { java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); java.util.Date date = new java.util.Date(Long.parseLong(arg)); _lastModTime.setText(format.format(date)); } catch (Exception e) { System.out.println("Error parsing long "+arg+" error:"+e); } } } } getOpenLockedStatus(); //_actionBy.setModel(model); if ( !_clientRevision.getText().equals(_depotRevision.getText())) { _clientRevision.setBackground(new Color(255,180,180)); } pack(); setLocation(); } private void getOpenLockedStatus() { Command cmd = new Command(Command.OPENED); cmd.addPath("-a"); cmd.addPath(_clientFile.getText()); CommandTool.runCommand(cmd, Main.m_props); boolean ranOk = MessageFormatter.getErrorMessageCount() == 0; MessageWriter.outputErrorMessages(MessageFormatter.getInstance()); DefaultListModel model = new DefaultListModel(); if ( ranOk ) { String line, who; StringBuffer buffer; int idx; // line looks like: // //hecjavadev/code/hec/resprm/client/AlternativeEditor.java#3 - edit default change (text) by richard@KYLE *locked* // format to richard@KYLE - default change (edit) while ( (line = MessageFormatter.getNextMessage() ) != null) { if ( line.startsWith(SLASH_SLASH)) { buffer = new StringBuffer(); idx = line.indexOf("-"); if ( idx < 0 ) { continue; } line = line.substring(idx+2); if ( line.startsWith("edit")) { buffer.append("(edit)"); line = line.substring(5); } else if ( line.startsWith("add")) { buffer.append("(add)"); line = line.substring(4); } else if ( line.startsWith("delete")) { buffer.append("(delete)"); line = line.substring(7); } idx = line.indexOf("("); if ( idx < 0 ) { continue; } buffer.insert(0, line.substring(0, idx)); idx = line.indexOf("by "); line = line.substring(idx+3); idx = line.indexOf(' '); if ( idx == -1 ) { who = line; } else { who = line.substring(0,idx); } buffer.insert(0,who+" - "); if ( line.endsWith ("*locked*")) { _lockedBy.setText(who); } model.addElement(buffer.toString()); } } } _actionBy.setModel(model); } /** * return the text after the first space character * @param message the text to parse * @return the second part of the message */ public static String getArg(String message) { if ( message == null ) { return ""; } int idx = message.indexOf(' '); if ( idx == -1 ) { return message; } return message.substring(idx+1); } /** * return the text before the first space character * @param message the text to parse * @return the first part of the message */ private String getType(String message) { if ( message == null ) { return ""; } int idx = message.indexOf(' '); if ( idx == -1 ) { return message; } return message.substring(0, idx); } /** * 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 StatusDialog(new Frame(), "File Information", false).setVisible(true); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 5093 | Hari Krishna Dara |
Populating perforce branch. I will be adding p4admin files to it. |
||
//guest/perforce_software/integrations/jbuilder/p4ot/xsrc/com/dafreels/opentools/actions/ui/StatusDialog.java | |||||
#1 | 4090 | David Freels |
Fixed bug where paths with spaces would not work. Also checked in new code or JBuilderX. |