Skip to main content
summaryrefslogtreecommitdiffstats
blob: f8a91bd850786b699c3d2e7181ac50dc6ae515e9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*******************************************************************************
 * Copyright (c) 2006 Sybase, Inc. and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.pagedesigner.css2.marker;

import org.eclipse.jst.pagedesigner.css2.list.CSSHtmlListStyleData;

/**
 * @author mengbo
 */
/*package*/ class RomanCounter extends EnumerableCounter {
	RomanCounter() 
	{
	    // do nothing
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jst.pagedesigner.css2.list.EnumerableCounter#getString(int,
	 *      boolean)
	 */
	public String getNextString(int index, int type) {
		switch (type) {
		case CSSHtmlListStyleData.LIST_T_LOWER_ROMAN:
			return getString(index).toLowerCase();
		case CSSHtmlListStyleData.LIST_T_UPPER_ROMAN:
			return getString(index);
		default:
			return null;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jst.pagedesigner.css2.list.NumberCounter#getString(int)
	 */
	/*package*/ String getString(int index) {
		// FIXME: Need to enhance more.
		StringBuffer roman = new StringBuffer();
		int a, b, c, d;
		a = (index / 1000) * 1000;
		b = ((index / 100) % 10) * 100;
		c = ((index / 10) % 10) * 10;
		d = ((index / 1) % 10) * 1;

		if (a == 1000)
			roman.append("M"); //$NON-NLS-1$
		else if (a == 2000)
			roman.append("MM"); //$NON-NLS-1$
		else if (a == 3000)
			roman.append("MMM"); //$NON-NLS-1$

		if (b == 100)
			roman.append("C"); //$NON-NLS-1$
		else if (b == 200)
			roman.append("CC"); //$NON-NLS-1$
		else if (b == 300)
			roman.append("CCC"); //$NON-NLS-1$
		else if (b == 400)
			roman.append("CD"); //$NON-NLS-1$
		else if (b == 500)
			roman.append("D"); //$NON-NLS-1$
		else if (b == 600)
			roman.append("DC"); //$NON-NLS-1$
		else if (b == 700)
			roman.append("DCC"); //$NON-NLS-1$
		else if (b == 800)
			roman.append("DCCC"); //$NON-NLS-1$
		else if (b == 900)
			roman.append("CM"); //$NON-NLS-1$

		if (c == 10)
			roman.append("X"); //$NON-NLS-1$
		else if (c == 20)
			roman.append("XX"); //$NON-NLS-1$
		else if (c == 30)
			roman.append("XXX"); //$NON-NLS-1$
		else if (c == 40)
			roman.append("XL"); //$NON-NLS-1$
		else if (c == 50)
			roman.append("L"); //$NON-NLS-1$
		else if (c == 60)
			roman.append("LX"); //$NON-NLS-1$
		else if (c == 70)
			roman.append("LXX"); //$NON-NLS-1$
		else if (c == 80)
			roman.append("LXXX"); //$NON-NLS-1$
		else if (c == 90)
			roman.append("XC"); //$NON-NLS-1$

		if (d == 1)
			roman.append("I"); //$NON-NLS-1$
		else if (d == 2)
			roman.append("II"); //$NON-NLS-1$
		else if (d == 3)
			roman.append("III"); //$NON-NLS-1$
		else if (d == 4)
			roman.append("IV"); //$NON-NLS-1$
		else if (d == 5)
			roman.append("V"); //$NON-NLS-1$
		else if (d == 6)
			roman.append("VI"); //$NON-NLS-1$
		else if (d == 7)
			roman.append("VII"); //$NON-NLS-1$
		else if (d == 8)
			roman.append("VIII"); //$NON-NLS-1$
		else if (d == 9)
			roman.append("IX"); //$NON-NLS-1$

		return roman.toString();
	}
}

Back to the top