1*a1b4a26bSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*a1b4a26bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*a1b4a26bSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*a1b4a26bSAndrew Rist * distributed with this work for additional information 6*a1b4a26bSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*a1b4a26bSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*a1b4a26bSAndrew Rist * "License"); you may not use this file except in compliance 9*a1b4a26bSAndrew Rist * with the License. You may obtain a copy of the License at 10*a1b4a26bSAndrew Rist * 11*a1b4a26bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*a1b4a26bSAndrew Rist * 13*a1b4a26bSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*a1b4a26bSAndrew Rist * software distributed under the License is distributed on an 15*a1b4a26bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*a1b4a26bSAndrew Rist * KIND, either express or implied. See the License for the 17*a1b4a26bSAndrew Rist * specific language governing permissions and limitations 18*a1b4a26bSAndrew Rist * under the License. 19*a1b4a26bSAndrew Rist * 20*a1b4a26bSAndrew Rist *************************************************************/ 21*a1b4a26bSAndrew Rist 22*a1b4a26bSAndrew Rist 23cdf0e10cSrcweir package com.sun.star.wizards.db; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.wizards.common.JavaTools; 26cdf0e10cSrcweir import com.sun.star.wizards.common.PropertyNames; 27cdf0e10cSrcweir 28cdf0e10cSrcweir /** 29cdf0e10cSrcweir * 30cdf0e10cSrcweir * @author bc93774 31cdf0e10cSrcweir */ 32cdf0e10cSrcweir public class BlindtextCreator 33cdf0e10cSrcweir { 34cdf0e10cSrcweir 35cdf0e10cSrcweir public static final String BlindText = 36cdf0e10cSrcweir "Ut wisi enim ad minim veniam, quis nostrud exerci tation " + "ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor " + "in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at " + "vero et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore " + "te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy " + "nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, " + "quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. " + "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum " + "dolore eu feugiat nulla facilisis at vero et accumsan et iusto odio dignissim qui blandit praesent " + "luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis " + "eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum."; 37cdf0e10cSrcweir adjustBlindTextlength(String FieldTitle, int FieldWidth, boolean bIsCurLandscape, boolean bIsGroupTable, String[] _RecordFieldNames)38cdf0e10cSrcweir public static String adjustBlindTextlength(String FieldTitle, int FieldWidth, boolean bIsCurLandscape, boolean bIsGroupTable, String[] _RecordFieldNames) 39cdf0e10cSrcweir { 40cdf0e10cSrcweir String BlindTextString = PropertyNames.EMPTY_STRING; 41cdf0e10cSrcweir if (bIsGroupTable) 42cdf0e10cSrcweir { 43cdf0e10cSrcweir return getBlindTextString(FieldTitle, FieldWidth, FieldWidth); 44cdf0e10cSrcweir } 45cdf0e10cSrcweir int MaxFieldCount = getMaxFieldCount(bIsCurLandscape); 46cdf0e10cSrcweir if (_RecordFieldNames.length <= 2 * MaxFieldCount) 47cdf0e10cSrcweir { 48cdf0e10cSrcweir if (_RecordFieldNames.length <= MaxFieldCount) 49cdf0e10cSrcweir { 50cdf0e10cSrcweir BlindTextString = getBlindTextString(FieldTitle, FieldWidth, FieldWidth); 51cdf0e10cSrcweir } 52cdf0e10cSrcweir else 53cdf0e10cSrcweir { 54cdf0e10cSrcweir BlindTextString = getBlindTextString(FieldTitle, FieldWidth, (int) (0.5 * FieldWidth)); 55cdf0e10cSrcweir } 56cdf0e10cSrcweir } 57cdf0e10cSrcweir else 58cdf0e10cSrcweir { 59cdf0e10cSrcweir BlindTextString = getBlindTextString(FieldTitle, FieldWidth, (int) 1.1 * FieldTitle.length()); 60cdf0e10cSrcweir } 61cdf0e10cSrcweir return BlindTextString; 62cdf0e10cSrcweir } 63cdf0e10cSrcweir getBlindTextString(String FieldTitle, int FieldWidth, int MaxWidth)64cdf0e10cSrcweir public static String getBlindTextString(String FieldTitle, int FieldWidth, int MaxWidth) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir String[] BlindTextArray = JavaTools.ArrayoutofString(BlindText, PropertyNames.SPACE); 67cdf0e10cSrcweir String PartBlindText = BlindTextArray[0]; 68cdf0e10cSrcweir String NewPartBlindText; 69cdf0e10cSrcweir int MaxHeaderWidth; 70cdf0e10cSrcweir int Titlelength = (int) 1.1 * FieldTitle.length(); // We assume that the TableHeading is bold 71cdf0e10cSrcweir 72cdf0e10cSrcweir if (Titlelength > PartBlindText.length()) 73cdf0e10cSrcweir { 74cdf0e10cSrcweir MaxHeaderWidth = Titlelength; 75cdf0e10cSrcweir } 76cdf0e10cSrcweir else 77cdf0e10cSrcweir { 78cdf0e10cSrcweir MaxHeaderWidth = PartBlindText.length(); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir if (MaxHeaderWidth > MaxWidth) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir MaxWidth = MaxHeaderWidth; 83cdf0e10cSrcweir } 84cdf0e10cSrcweir int i = 1; 85cdf0e10cSrcweir do 86cdf0e10cSrcweir { 87cdf0e10cSrcweir NewPartBlindText = PartBlindText + PropertyNames.SPACE + BlindTextArray[i]; 88cdf0e10cSrcweir if (NewPartBlindText.length() < MaxWidth) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir PartBlindText = NewPartBlindText; 91cdf0e10cSrcweir i += 1; 92cdf0e10cSrcweir } 93cdf0e10cSrcweir } 94cdf0e10cSrcweir while (NewPartBlindText.length() < MaxWidth); 95cdf0e10cSrcweir return PartBlindText; 96cdf0e10cSrcweir } 97cdf0e10cSrcweir getMaxFieldCount(boolean bIsCurLandscape)98cdf0e10cSrcweir private static int getMaxFieldCount(boolean bIsCurLandscape) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir if (bIsCurLandscape) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir return 5; 103cdf0e10cSrcweir } 104cdf0e10cSrcweir else 105cdf0e10cSrcweir { 106cdf0e10cSrcweir return 3; 107cdf0e10cSrcweir } 108cdf0e10cSrcweir } 109cdf0e10cSrcweir } 110