Statistics
| Revision:

root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / com / izforge / izpack / Pack.java @ 15280

History | View | Annotate | Download (5.33 KB)

1
/*
2
 *  $Id: Pack.java,v 1.1 2006/06/14 07:29:07 cesar Exp $
3
 *  IzPack
4
 *  Copyright (C) 2001-2004 Julien Ponge
5
 *
6
 *  File :               Pack.java
7
 *  Description :        Contains informations about a pack.
8
 *  Author's email :     julien@izforge.com
9
 *  Author's Website :   http://www.izforge.com
10
 *
11
 *  This program is free software; you can redistribute it and/or
12
 *  modify it under the terms of the GNU General Public License
13
 *  as published by the Free Software Foundation; either version 2
14
 *  of the License, or any later version.
15
 *
16
 *  This program is distributed in the hope that it will be useful,
17
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 *  GNU General Public License for more details.
20
 *
21
 *  You should have received a copy of the GNU General Public License
22
 *  along with this program; if not, write to the Free Software
23
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24
 */
25
package com.izforge.izpack;
26

    
27
import com.izforge.izpack.compiler.PackInfo;
28

    
29
import java.io.Serializable;
30
import java.text.DecimalFormat;
31
import java.util.List;
32
import java.util.HashMap;
33
import java.util.ArrayList;
34

    
35
/**
36
 *  Represents a Pack.
37
 *
38
 * @author     Julien Ponge
39
 */
40
public class Pack implements Serializable
41
{
42
  public boolean loose;
43

    
44
  /**  The pack name. */
45
  public String name;
46
  
47
  /** The langpack id */
48
  public String id;
49

    
50
  /**  The pack description. */
51
  public String description;
52

    
53
  /**  The target operation system of this pack */
54
  public List osConstraints = null;
55

    
56
  /**  The list of packs this pack depends on */
57
  public List dependencies = null;
58

    
59
  /** Reverse dependencies(childs) */
60
  public List revDependencies = null;
61

    
62
  /**  True if the pack is required. */
63
  public boolean required;
64

    
65
  /**  The bumber of bytes contained in the pack. */
66
  public long nbytes;
67

    
68
  /**  Whether this pack is suggested (preselected for installation). */
69
  public boolean preselected;
70

    
71
  /** The color of the node. This is used for the dependency graph algorithms */
72
  public int color;
73

    
74
  /** white colour*/
75
  public final static int WHITE = 0;
76
  /** grey colour*/
77
  public final static int GREY  = 1;
78
  /** black colour*/
79
  public final static int BLACK = 2;
80
  /**
81
   *  The constructor.
82
   *
83
   * @param  name         The pack name.
84
   * @param  description  The pack description.
85
   * @param  osConstraints the OS constraint (or null for any OS)
86
   * @param  required     Indicates wether the pack is required or not.
87
   * @param  preselected  This pack will be selected automatically.
88
   */
89
  public Pack(
90
    String name,
91
    String id, 
92
    String description,
93
    List osConstraints,
94
    List dependencies,
95
    boolean required,
96
    boolean preselected,
97
    boolean loose)
98
  {
99
    this.name = name;
100
    this.id = id;
101
    this.description = description;
102
    this.osConstraints = osConstraints;
103
    this.dependencies = dependencies;
104
    this.required = required;
105
    this.preselected = preselected;
106
    this.loose = loose;
107
    nbytes = 0;
108
    color = PackInfo.WHITE;
109
  }
110

    
111
  /**
112
   *  To a String (usefull for JLists).
113
   *
114
   * @return    The String representation of the pack.
115
   */
116
  public String toString()
117
  {
118
    return name + " (" + description + ")";
119
  }
120

    
121
  /** getter method */
122
  public List getDependencies()
123
  {
124
    return dependencies;
125
  }
126

    
127
  /**
128
   * This adds a reverse dependency. With a reverse dependency we imply a child
129
   * dependency or the dependents on this pack
130
   *
131
   * @param name The name of the pack that depents to this pack
132
   */
133
  public void addRevDep(String name)
134
  {
135
    if(revDependencies == null)
136
      revDependencies = new ArrayList();
137
    revDependencies.add(name);
138
  }
139
  /**
140
   * Creates a text list of all the packs it depend on
141
   * @return the created text
142
   */
143
  public String depString()
144
  {
145
    String text ="";
146
    if (dependencies==null)
147
      return text;
148
    String name = null;
149
    for (int i = 0; i < dependencies.size()-1; i++)
150
    {
151
      name = (String) dependencies.get(i);
152
      text += name+",";
153
    }
154
    name=(String) dependencies.get(dependencies.size()-1);
155
    text += name;
156
    return text;
157

    
158
  }
159

    
160
  /**  Used of conversions. */
161
  private final static double KILOBYTES = 1024.0;
162

    
163
  /**  Used of conversions. */
164
  private final static double MEGABYTES = 1024.0 * 1024.0;
165

    
166
  /**  Used of conversions. */
167
  private final static double GIGABYTES = 1024.0 * 1024.0 * 1024.0;
168

    
169
  /**  Used of conversions. */
170
  private final static DecimalFormat formatter = new DecimalFormat("#,###.##");
171

    
172
  /**
173
   *  Convert bytes into appropiate mesaurements.
174
   *
175
   * @param  bytes  A number of bytes to convert to a String.
176
   * @return        The String-converted value.
177
   */
178
  public static String toByteUnitsString(int bytes)
179
  {
180
    if (bytes < KILOBYTES)
181
      return String.valueOf(bytes) + " bytes";
182
    else if (bytes < (MEGABYTES))
183
    {
184
      double value = bytes / KILOBYTES;
185
      return formatter.format(value) + " KB";
186
    } else if (bytes < (GIGABYTES))
187
    {
188
      double value = bytes / MEGABYTES;
189
      return formatter.format(value) + " MB";
190
    } else
191
    {
192
      double value = bytes / GIGABYTES;
193
      return formatter.format(value) + " GB";
194
    }
195
  }
196
}