KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > webapp > data > ToolbarButton


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.internal.webapp.data;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15 import java.util.StringTokenizer JavaDoc;
16
17 /**
18  * This class calls eclipse API's directly, so it should only be instantiated in
19  * the workbench scenario, not in the infocenter.
20  */

21 public class ToolbarButton {
22     private String JavaDoc name;
23     private String JavaDoc tooltip;
24     private String JavaDoc image;
25     private String JavaDoc action;
26     private String JavaDoc param;
27     private String JavaDoc styleClass;
28     private boolean state;
29     private boolean isSeparator;
30
31     public ToolbarButton() {
32         isSeparator = true;
33     }
34
35     public ToolbarButton(String JavaDoc name, String JavaDoc tooltip, String JavaDoc image,
36             String JavaDoc action, String JavaDoc param, String JavaDoc state) {
37         this.name = name;
38         this.tooltip = tooltip;
39         this.image = image;
40         this.action = action;
41         this.param = param;
42         this.state = state.equalsIgnoreCase("on")?true:false; //$NON-NLS-1$
43
if (state.startsWith("hid")) //$NON-NLS-1$
44
this.styleClass = "buttonHidden"; //$NON-NLS-1$
45
else if ("menu".equals(action)) { //$NON-NLS-1$
46
this.styleClass = "buttonMenu"; //$NON-NLS-1$
47
}
48         else
49             this.styleClass = state.equalsIgnoreCase("on")?"buttonOn":"button"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
50
}
51
52     public boolean isSeparator() {
53         return isSeparator;
54     }
55
56     public boolean isMenu() {
57         return "menu".equals(action); //$NON-NLS-1$
58
}
59
60     public String JavaDoc getName() {
61         return name;
62     }
63
64     public String JavaDoc[][] getMenuData() {
65         List JavaDoc list = new ArrayList JavaDoc();
66         StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(param, ","); //$NON-NLS-1$
67
while(tok.hasMoreTokens()) {
68             String JavaDoc token = tok.nextToken();
69             int index = token.indexOf('=');
70             list.add(new String JavaDoc[] { token.substring(0, index), token.substring(index + 1) });
71         }
72         return (String JavaDoc[][])list.toArray(new String JavaDoc[list.size()][]);
73     }
74     
75     public String JavaDoc getTooltip() {
76         return tooltip;
77     }
78
79     /**
80      * Returns the enabled gray image
81      *
82      * @return String
83      */

84     public String JavaDoc getImage() {
85         int i = image.lastIndexOf('/');
86         return image.substring(0, i) + "/e_" + image.substring(i + 1); //$NON-NLS-1$
87
}
88
89     /**
90      * Returns the image when selected
91      *
92      * @return String
93      */

94     public String JavaDoc getOnImage() {
95         return getImage();
96     }
97
98     public String JavaDoc getAction() {
99         return action;
100     }
101
102     public String JavaDoc getParam() {
103         return param;
104     }
105     
106     public boolean isOn() {
107         return state;
108     }
109     
110     public String JavaDoc getStyleClass() {
111         return styleClass;
112     }
113 }
114
Popular Tags