1 /*
2  *
3  * created: Wed Aug 3 2004
4  *
5  * This file is part of Artemis
6  *
7  * Copyright(C) 2000  Genome Research Limited
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or(at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  */
24 
25 package uk.ac.sanger.artemis.editor;
26 
27 import javax.swing.*;
28 import java.util.*;
29 
30 /**
31 *
32 * Macros class
33 *
34 */
35 public class PlafMacros implements SwingConstants
36 {
37   // don't make these final, since the value is
38   // different on each platform
39   private static String LINE_SEPARATOR =
40                   System.getProperty("line.separator");
41   private static int LINE_SEPARATOR_LEN =
42                   LINE_SEPARATOR.length();
43 
44   /**
45   *
46   * Break text into separate lines
47   * @param text		text to break up
48   * @return		multiple lines in string array
49   *
50   */
breakupLines(String text)51   public static String[] breakupLines(String text)
52   {
53     int len = text.length();
54     if (len == 0)
55       return new String[] {""};
56     else
57     {
58       Vector data = new Vector(10);
59       int start=0;
60       int i=0;
61       while (i<len) {
62         if (text.startsWith(LINE_SEPARATOR,i))
63         {
64           data.addElement(text.substring(start,i));
65           start=i+LINE_SEPARATOR_LEN;
66           i=start;
67         }
68         else if (text.charAt(i)=='\n')
69         {
70           data.addElement(text.substring(start,i));
71           start=i+1;
72           i=start;
73         }
74         else { i++; }
75       }
76       if (start != len)
77         data.addElement(text.substring(start));
78       int numlines = data.size();
79       String lines[] = new String[numlines];
80       data.copyInto(lines);
81       return lines;
82     }
83   }
84 
85   /**
86   *
87   * Get the line separator string
88   * @return 	line separator
89   *
90   */
getLineSeparator()91   public static String getLineSeparator()
92   {
93     return LINE_SEPARATOR;
94   }
95 }
96 
97