1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.setup.Util; 25 26 import org.openoffice.setup.SetupData.PackageDescription; 27 import java.util.Vector; 28 import org.openoffice.setup.InstallData; 29 import org.openoffice.setup.ResourceManager; 30 31 public class Calculator { 32 Calculator()33 private Calculator() { 34 } 35 calculateInstallSize(Vector allPackages)36 static private int calculateInstallSize(Vector allPackages) { 37 38 int value = 0; 39 40 for (int i = 0; i < allPackages.size(); i++) { 41 PackageDescription packageData = (PackageDescription)allPackages.get(i); 42 int size = packageData.getSize(); 43 value = value + size; 44 } 45 46 return value; 47 } 48 missingDiscSpace(int required, int available)49 static private boolean missingDiscSpace(int required, int available) { 50 boolean missingDiscSpace = true; 51 52 if ( required < available ) { 53 missingDiscSpace = false; 54 } 55 56 // missingDiscSpace = true; // for testing reasons 57 return missingDiscSpace; 58 } 59 notEnoughDiscSpace(InstallData data)60 static public boolean notEnoughDiscSpace(InstallData data) { 61 62 Vector installPackages = data.getInstallPackages(); 63 // Calculate size of selected modules 64 int installationSize = calculateInstallSize(installPackages); 65 66 // Compare with available space 67 int availableDiscSpace = data.getAvailableDiscSpace(); 68 69 // Show warning and repeat dialog, if not sufficient disc space available 70 boolean insufficientDiscSpace = missingDiscSpace(installationSize, availableDiscSpace); 71 72 if ( insufficientDiscSpace ) { 73 String message = ResourceManager.getString("String_Discspace_Insufficient") + "\n" + 74 ResourceManager.getString("String_Discspace_Required") + ": " + installationSize + " kB." + "\n" + 75 ResourceManager.getString("String_Discspace_Available") + ": " + availableDiscSpace + " kB." + "\n" + 76 ResourceManager.getString("String_Discspace_Tip"); 77 String title = ResourceManager.getString("String_Error"); 78 Informer.showErrorMessage(message, title); 79 } 80 81 return insufficientDiscSpace; 82 } 83 84 } 85