001: /**
002: * L2FProd.com Common Components 7.3 License.
003: *
004: * Copyright 2005-2007 L2FProd.com
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package com.l2fprod.common.swing;
018:
019: import com.l2fprod.common.swing.plaf.JTaskPaneAddon;
020: import com.l2fprod.common.swing.plaf.LookAndFeelAddons;
021: import com.l2fprod.common.swing.plaf.TaskPaneUI;
022:
023: import java.awt.Dimension;
024: import java.awt.Rectangle;
025:
026: import javax.swing.JComponent;
027: import javax.swing.JViewport;
028: import javax.swing.Scrollable;
029:
030: /**
031: * <code>JTaskPane</code> provides an elegant view
032: * to display a list of tasks ordered by groups ({@link JTaskPane}.
033: *
034: * <p>
035: * Although {@link JTaskPaneGroup} can be added to any other
036: * container, the <code>JTaskPane</code> will provide better
037: * fidelity when it comes to matching the look and feel of the host operating
038: * system than any other panel. As example, when using on a Windows platform,
039: * the <code>JTaskPane</code> will be painted with light gradient
040: * background. Also <code>JTaskPane</code> takes care of using the
041: * right {@link java.awt.LayoutManager} (as required by
042: * {@link JCollapsiblePane}) so that
043: * {@link JTaskPaneGroup} behaves correctly when collapsing and
044: * expanding its content.
045: *
046: * <p>
047: * <code>JTaskPane<code> can be added to a JScrollPane.
048: *
049: * <p>
050: * Example:
051: * <pre>
052: * <code>
053: * JFrame frame = new JFrame();
054: *
055: * // a container to put all JTaskPaneGroup together
056: * JTaskPane taskPaneContainer = new JTaskPane();
057: *
058: * // add JTaskPaneGroups to the container
059: * JTaskPaneGroup actionPane = createActionPane();
060: * JTaskPaneGroup miscActionPane = createMiscActionPane();
061: * JTaskPaneGroup detailsPane = createDetailsPane();
062: * taskPaneContainer.add(actionPane);
063: * taskPaneContainer.add(miscActionPane);
064: * taskPaneContainer.add(detailsPane);
065: *
066: * // put the action list on the left in a JScrollPane
067: * // as we have several taskPane and we want to make sure they
068: * // all get visible.
069: * frame.add(new JScrollPane(taskPaneContainer), BorderLayout.EAST);
070: *
071: * // and a file browser in the middle
072: * frame.add(fileBrowser, BorderLayout.CENTER);
073: *
074: * frame.pack().
075: * frame.setVisible(true);
076: * </code>
077: * </pre>
078: *
079: * @author <a href="mailto:fred@L2FProd.com">Frederic Lavigne</a>
080: *
081: * @javabean.attribute
082: * name="isContainer"
083: * value="Boolean.TRUE"
084: * rtexpr="true"
085: *
086: * @javabean.class
087: * name="JTaskPane"
088: * shortDescription="A component that contains JTaskPaneGroups."
089: * stopClass="java.awt.Component"
090: *
091: * @javabean.icons
092: * mono16="JTaskPane16-mono.gif"
093: * color16="JTaskPane16.gif"
094: * mono32="JTaskPane32-mono.gif"
095: * color32="JTaskPane32.gif"
096: */
097: public class JTaskPane extends JComponent implements Scrollable {
098:
099: public final static String UI_CLASS_ID = "TaskPaneUI";
100:
101: // ensure at least the default ui is registered
102: static {
103: LookAndFeelAddons.contribute(new JTaskPaneAddon());
104: }
105:
106: /**
107: * Creates a new empty taskpane.
108: */
109: public JTaskPane() {
110: updateUI();
111: }
112:
113: /**
114: * Notification from the <code>UIManager</code> that the L&F has changed.
115: * Replaces the current UI object with the latest version from the <code>UIManager</code>.
116: *
117: * @see javax.swing.JComponent#updateUI
118: */
119: public void updateUI() {
120: setUI((TaskPaneUI) LookAndFeelAddons.getUI(this ,
121: TaskPaneUI.class));
122: }
123:
124: /**
125: * Sets the L&F object that renders this component.
126: *
127: * @param ui the <code>TaskPaneUI</code> L&F object
128: * @see javax.swing.UIDefaults#getUI
129: *
130: * @beaninfo bound: true hidden: true description: The UI object that
131: * implements the taskpane's LookAndFeel.
132: */
133: public void setUI(TaskPaneUI ui) {
134: super .setUI(ui);
135: }
136:
137: /**
138: * Returns the name of the L&F class that renders this component.
139: *
140: * @return the string {@link #UI_CLASS_ID}
141: * @see javax.swing.JComponent#getUIClassID
142: * @see javax.swing.UIDefaults#getUI
143: */
144: public String getUIClassID() {
145: return UI_CLASS_ID;
146: }
147:
148: /**
149: * Adds a new <code>JTaskPaneGroup</code> to this JTaskPane.
150: *
151: * @param group
152: */
153: public void add(JTaskPaneGroup group) {
154: super .add(group);
155: }
156:
157: /**
158: * Removes a new <code>JTaskPaneGroup</code> from this JTaskPane.
159: *
160: * @param group
161: */
162: public void remove(JTaskPaneGroup group) {
163: super .remove(group);
164: }
165:
166: /**
167: * @see Scrollable#getPreferredScrollableViewportSize()
168: */
169: public Dimension getPreferredScrollableViewportSize() {
170: return getPreferredSize();
171: }
172:
173: /**
174: * @see Scrollable#getScrollableBlockIncrement(java.awt.Rectangle, int, int)
175: */
176: public int getScrollableBlockIncrement(Rectangle visibleRect,
177: int orientation, int direction) {
178: return 10;
179: }
180:
181: /**
182: * @see Scrollable#getScrollableTracksViewportHeight()
183: */
184: public boolean getScrollableTracksViewportHeight() {
185: if (getParent() instanceof JViewport) {
186: return (((JViewport) getParent()).getHeight() > getPreferredSize().height);
187: } else {
188: return false;
189: }
190: }
191:
192: /**
193: * @see Scrollable#getScrollableTracksViewportWidth()
194: */
195: public boolean getScrollableTracksViewportWidth() {
196: return true;
197: }
198:
199: /**
200: * @see Scrollable#getScrollableUnitIncrement(java.awt.Rectangle, int, int)
201: */
202: public int getScrollableUnitIncrement(Rectangle visibleRect,
203: int orientation, int direction) {
204: return 10;
205: }
206:
207: }
|