KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > gui > objects > DumpFileObject


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.console.gui.objects;
26
27 import java.awt.Color JavaDoc;
28 import java.io.File JavaDoc;
29 import java.text.DateFormat JavaDoc;
30 import java.text.SimpleDateFormat JavaDoc;
31 import java.util.Date JavaDoc;
32
33 import javax.swing.BorderFactory JavaDoc;
34 import javax.swing.SwingConstants JavaDoc;
35
36 import org.objectweb.cjdbc.common.util.Zipper;
37 import org.objectweb.cjdbc.console.gui.constants.GuiConstants;
38 import org.objectweb.cjdbc.console.gui.constants.GuiIcons;
39
40 /**
41  * This class defines a DumpFileObject to represent graphically dump files
42  *
43  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
44  * @version 1.0
45  */

46 public class DumpFileObject extends AbstractGuiObject
47 {
48   private File JavaDoc dumpFile;
49   private String JavaDoc dumpFileName;
50   private String JavaDoc displayName;
51   private DateFormat JavaDoc df;
52
53   /**
54    * Creates a new <code>DumpFileObject.java</code> object
55    *
56    * @param dumpFile name of the dump file
57    */

58   public DumpFileObject(File JavaDoc dumpFile)
59   {
60     this.dumpFile = dumpFile;
61     this.dumpFileName = dumpFile.getName();
62     this.df = new SimpleDateFormat JavaDoc();
63     this.setActionCommand(GuiConstants.BACKEND_STATE_RESTORE);
64     setIcon(GuiIcons.DUMP_FILE_ICON);
65     setBackground(Color.white);
66     setDisplayName();
67     setVerticalTextPosition(SwingConstants.BOTTOM);
68     setFont(GuiConstants.CENTER_PANE_FONT);
69
70     setToolTipText("File:" + dumpFileName + "\nLast Modified:"
71         + df.format(new Date JavaDoc(dumpFile.lastModified())));
72   }
73
74   void setDisplayName()
75   {
76     displayName = dumpFileName.substring(0, dumpFileName.length()
77         - Zipper.ZIP_EXT.length());
78     int ind = displayName.indexOf('-');
79     if (ind != -1)
80     {
81       setBorder(BorderFactory.createTitledBorder(GuiConstants.LINE_BORDER,
82           displayName.substring(0, ind)));
83       displayName = displayName.substring(ind + 1);
84     }
85     int index = displayName.indexOf(' ');
86     if (index == -1)
87       setText(displayName);
88     else
89       setText(displayName.substring(0, index));
90   }
91
92   /**
93    * Returns the dumpFile value.
94    *
95    * @return Returns the dumpFile.
96    */

97   public File JavaDoc getDumpFile()
98   {
99     return dumpFile;
100   }
101
102   /**
103    * Return the dump file name.
104    *
105    * @return the dump name
106    */

107   public String JavaDoc getDumpName()
108   {
109     String JavaDoc name = dumpFile.getName();
110     return name.substring(0, name.indexOf(Zipper.ZIP_EXT));
111   }
112 }
Popular Tags