001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.swinglets;
006:
007: /**
008: * A SToolBar is a menu bar for adding Components/Buttons to.
009: *
010: * @author Robin Sharp
011: */
012:
013: import java.awt.*;
014: import java.awt.event.*;
015: import java.io.*;
016: import java.util.*;
017:
018: import com.javelin.swinglets.event.*;
019:
020: public class SToolBar extends SContainer {
021: /**
022: * Construct a SToolBar.
023: */
024: public SToolBar() {
025: }
026:
027: /**
028: * Construct a SToolBar.
029: */
030: public SToolBar(int toolBarPlacement) {
031: this .toolBarPlacement = toolBarPlacement;
032: }
033:
034: /**
035: * Returns the name of the L&F class that renders this component.
036: */
037: public Class getUIClass() {
038: return SToolBar.class;
039: }
040:
041: /**
042: * Get the placement of the toolbars.
043: */
044: public int getToolBarPlacement() {
045: return toolBarPlacement;
046: }
047:
048: /**
049: * Sets the placement of toolbars. <br>
050: * One of SConstants.TOP, SConstants.BOTTOM, SConstants.LEFT, or SConstants.RIGHT.
051: */
052: public SToolBar setToolBarPlacement(int toolBarPlacement) {
053: firePropertyChange("toolBarPlacement", this .toolBarPlacement,
054: this .toolBarPlacement = toolBarPlacement);
055: return this ;
056: }
057:
058: /**
059: * Get the margin between the toolbar's border and its buttons.
060: */
061: public Dimension getMargin() {
062: return margin;
063: }
064:
065: /**
066: * Set the margin between the toolbar's border and its buttons.
067: */
068: public SToolBar setMargin(Dimension margin) {
069: firePropertyChange("margin", this .margin, this .margin = margin);
070: return this ;
071: }
072:
073: /**
074: * Check whether the border is painted.
075: */
076: public boolean isBorderPainted() {
077: return borderPainted;
078: }
079:
080: /**
081: * Set whether the border is painted.
082: */
083: public SToolBar setBorderPainted(boolean borderPainted) {
084: firePropertyChange("borderPainted", this .borderPainted,
085: this .borderPainted = borderPainted);
086: return this ;
087: }
088:
089: // EVENT //////////////////////////////////////////////////////////////////////
090:
091: /**
092: * Processes events occurring on this component.
093: *
094: * If the property STableHeader.SOURCE_COLUMN is set
095: * then pass an ActionEvent to the tableHeader, with
096: * an id set to the column number.
097: */
098: protected void processEvent(AWTEvent event) {
099: if (event instanceof FormEvent) {
100: processFormEvent((FormEvent) event);
101: } else {
102: super .processEvent(event);
103: }
104: }
105:
106: /**
107: * Process the FormEvent to compute which node has been
108: * expanded or contracted.
109: */
110: protected void processFormEvent(FormEvent event) {
111: int row = 0;
112:
113: //Get the name of the node that was pressed
114: for (Enumeration names = event.getParameterNames(); names
115: .hasMoreElements();) {
116: String name = (String) names.nextElement();
117:
118: if (name.equals(SConstants.SOURCE_CONTAINER))
119: continue;
120: if (name.equals(SConstants.SOURCE_COMPONENT))
121: continue;
122: if (name.equals(SConstants.TARGET_COMPONENT))
123: continue;
124:
125: //Ignore .y stuff
126: if (name.indexOf(".y") > 0)
127: continue;
128:
129: int index = name.indexOf(".x");
130: if (index >= 0) {
131: name = name.substring(0, index);
132: }
133:
134: SComponent c = getComponent(name);
135: if (c != null) {
136: c.processActionEvent(new ActionEvent(this ,
137: ActionEvent.ACTION_PERFORMED, name));
138: }
139: }
140:
141: }
142:
143: // PRIVATE /////////////////////////////////////////////////////////////////
144:
145: protected int toolBarPlacement = SConstants.TOP;
146: protected Dimension margin;
147: protected boolean borderPainted = true;
148: }
|