| 1 |
/* |
| 2 |
* Copyright (c) 2005-2010 Laf-Widget Kirill Grouchnikov. All Rights Reserved. |
| 3 |
* |
| 4 |
* Redistribution and use in source and binary forms, with or without |
| 5 |
* modification, are permitted provided that the following conditions are met: |
| 6 |
* |
| 7 |
* o Redistributions of source code must retain the above copyright notice, |
| 8 |
* this list of conditions and the following disclaimer. |
| 9 |
* |
| 10 |
* o Redistributions in binary form must reproduce the above copyright notice, |
| 11 |
* this list of conditions and the following disclaimer in the documentation |
| 12 |
* and/or other materials provided with the distribution. |
| 13 |
* |
| 14 |
* o Neither the name of Laf-Widget Kirill Grouchnikov nor the names of |
| 15 |
* its contributors may be used to endorse or promote products derived |
| 16 |
* from this software without specific prior written permission. |
| 17 |
* |
| 18 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 20 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 21 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 22 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 23 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 24 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 25 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 26 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 27 |
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 28 |
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 |
*/ |
| 30 |
package org.pushingpixels.lafwidget.tabbed; |
| 31 |
|
| 32 |
import java.awt.*; |
| 33 |
|
| 34 |
import javax.swing.JFrame; |
| 35 |
import javax.swing.JTabbedPane; |
| 36 |
|
| 37 |
import org.pushingpixels.lafwidget.utils.LafConstants.TabOverviewKind; |
| 38 |
|
| 39 |
/** |
| 40 |
* Base class for tab preview painters. |
| 41 |
* |
| 42 |
* @author Kirill Grouchnikov |
| 43 |
*/ |
| 44 |
public abstract class TabPreviewPainter { |
| 45 |
/** |
| 46 |
* Draws a tab preview on the specified graphics. |
| 47 |
* |
| 48 |
* @param tabPane |
| 49 |
* Tabbed pane. |
| 50 |
* @param tabIndex |
| 51 |
* tabIndex Tab index for the preview paint. |
| 52 |
* @param g |
| 53 |
* Graphics context. |
| 54 |
* @param x |
| 55 |
* X coordinate of the preview area. |
| 56 |
* @param y |
| 57 |
* Y coordinate of the preview area. |
| 58 |
* @param w |
| 59 |
* Width of the preview area. |
| 60 |
* @param h |
| 61 |
* Height of the preview area. |
| 62 |
*/ |
| 63 |
public void previewTab(JTabbedPane tabPane, int tabIndex, Graphics g, |
| 64 |
int x, int y, int w, int h) { |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Checks whether the specified tab component is previewable. |
| 69 |
* |
| 70 |
* @param tabPane |
| 71 |
* Tabbed pane. |
| 72 |
* @param tabIndex |
| 73 |
* Tab index for the preview paint. |
| 74 |
* @return <code>true</code> if the specified tab component is |
| 75 |
* previewable, <code>false</code> otherwise. |
| 76 |
*/ |
| 77 |
public boolean hasPreview(JTabbedPane tabPane, int tabIndex) { |
| 78 |
return false; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Checks whether the specified tab component is sensitive to events. |
| 83 |
* Overriding implementation may decide that disabled tabs do not respond to |
| 84 |
* mouse and keyboard events, thus not allowing selecting the corresponding |
| 85 |
* tab. |
| 86 |
* |
| 87 |
* @param tabPane |
| 88 |
* Tabbed pane. |
| 89 |
* @param tabIndex |
| 90 |
* Tab index. |
| 91 |
* @return <code>true</code> if the specified tab component is sensitive |
| 92 |
* to events, <code>false</code> otherwise. |
| 93 |
*/ |
| 94 |
public boolean isSensitiveToEvents(JTabbedPane tabPane, int tabIndex) { |
| 95 |
return false; |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Returns the screen bounds of the tab preview dialog window. |
| 100 |
* |
| 101 |
* @param tabPane |
| 102 |
* Tabbed pane. |
| 103 |
* @return Screen bounds of the preview dialog window of the specified |
| 104 |
* tabbed pane. |
| 105 |
*/ |
| 106 |
public Rectangle getPreviewDialogScreenBounds(JTabbedPane tabPane) { |
| 107 |
Rectangle tabPaneBounds = tabPane.getBounds(); |
| 108 |
Point tabPaneScreenLoc = tabPane.getLocationOnScreen(); |
| 109 |
return new Rectangle(tabPaneScreenLoc.x, tabPaneScreenLoc.y, |
| 110 |
tabPaneBounds.width, tabPaneBounds.height); |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Returns the owner of the overview dialog of the specified tabbed pane. If |
| 115 |
* this function retuns a non-<code>null</code> value, the overview |
| 116 |
* dialog will be modal for the corresponding frame. |
| 117 |
* |
| 118 |
* @param tabPane |
| 119 |
* Tabbed pane. |
| 120 |
* @return If not <code>null</code>, the overview dialog for the |
| 121 |
* specified tabbed pane will be modal for the corresponding frame. |
| 122 |
*/ |
| 123 |
public JFrame getModalOwner(JTabbedPane tabPane) { |
| 124 |
return null; |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* Checks whether the specified tabbed pane has an overview dialog. |
| 129 |
* |
| 130 |
* @param tabPane |
| 131 |
* Tabbed pane. |
| 132 |
* @return <code>true</code> if the specified tabbed pane has an overview |
| 133 |
* dialog, <code>false</code> otherwise. |
| 134 |
*/ |
| 135 |
public boolean hasOverviewDialog(JTabbedPane tabPane) { |
| 136 |
return false; |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* Checks whether the specified tabbed pane has a preview window for the |
| 141 |
* specified tab. |
| 142 |
* |
| 143 |
* @param tabPane |
| 144 |
* Tabbed pane. |
| 145 |
* @param tabIndex |
| 146 |
* Tab index. |
| 147 |
* @return <code>true</code> if the specified tabbed pane has a preview |
| 148 |
* window for the specified tab, <code>false</code> otherwise. |
| 149 |
*/ |
| 150 |
public boolean hasPreviewWindow(JTabbedPane tabPane, int tabIndex) { |
| 151 |
return false; |
| 152 |
} |
| 153 |
|
| 154 |
/** |
| 155 |
* Returns the dimension for the tab preview window. |
| 156 |
* |
| 157 |
* @param tabPane |
| 158 |
* Tabbed pane. |
| 159 |
* @param tabIndex |
| 160 |
* Tab index. |
| 161 |
* @return Dimension of the tab preview window for the specified tab in the |
| 162 |
* specified tabbed pane. |
| 163 |
*/ |
| 164 |
public Dimension getPreviewWindowDimension(JTabbedPane tabPane, int tabIndex) { |
| 165 |
return new Dimension(300, 200); |
| 166 |
} |
| 167 |
|
| 168 |
/** |
| 169 |
* Returns extra delay (in milliseconds) for showing the tab preview window. |
| 170 |
* The base delay is 2000 milliseconds (2 seconds). This function must |
| 171 |
* return a non-negative value. |
| 172 |
* |
| 173 |
* @param tabPane |
| 174 |
* Tabbed pane. |
| 175 |
* @param tabIndex |
| 176 |
* Tab index. |
| 177 |
* @return Non-negative extra delay (in milliseconds) for showing the tab |
| 178 |
* preview window. |
| 179 |
*/ |
| 180 |
public int getPreviewWindowExtraDelay(JTabbedPane tabPane, int tabIndex) { |
| 181 |
return 0; |
| 182 |
} |
| 183 |
|
| 184 |
/** |
| 185 |
* Returns indication whether the thumbnail preview should be updated |
| 186 |
* periodically. If the return value is <code>true</code>, then the |
| 187 |
* implementation of {@link #getUpdateCycle(JTabbedPane)} returns the |
| 188 |
* refresh cycle length in milliseconds. |
| 189 |
* |
| 190 |
* @param tabPane |
| 191 |
* Tabbed pane. |
| 192 |
* @return <code>true</code> if the thumbnail preview of the specified |
| 193 |
* tabbed pane should be updated periodically, <code>false</code> |
| 194 |
* otherwise. |
| 195 |
*/ |
| 196 |
public boolean toUpdatePeriodically(JTabbedPane tabPane) { |
| 197 |
return false; |
| 198 |
} |
| 199 |
|
| 200 |
/** |
| 201 |
* If the result of {@link #toUpdatePeriodically(JTabbedPane)} is |
| 202 |
* <code>true</code>, returns the update cycle length in milliseconds. |
| 203 |
* |
| 204 |
* @param tabPane |
| 205 |
* Tabbed pane. |
| 206 |
* @return Update cycle length in milliseconds for the thumbnail preview of |
| 207 |
* the specified tabbed pane. |
| 208 |
*/ |
| 209 |
public int getUpdateCycle(JTabbedPane tabPane) { |
| 210 |
return 10000; |
| 211 |
} |
| 212 |
|
| 213 |
/** |
| 214 |
* Returns the tab overview kind for the specified tabbed pane. Relevant if |
| 215 |
* {@link #hasOverviewDialog(JTabbedPane)} returns <code>true</code> for |
| 216 |
* the same tabbed pane. If {@link #hasOverviewDialog(JTabbedPane)} returns |
| 217 |
* <code>true</code>, the result should be not <code>null</code>. |
| 218 |
* |
| 219 |
* |
| 220 |
* @param tabPane |
| 221 |
* Tabbed pane. |
| 222 |
* @return Tab overview kind for the specified tabbed pane. |
| 223 |
* @since version 3.0 |
| 224 |
*/ |
| 225 |
public TabOverviewKind getOverviewKind(JTabbedPane tabPane) { |
| 226 |
return TabOverviewKind.GRID; |
| 227 |
} |
| 228 |
|
| 229 |
/** |
| 230 |
* Returns indication whether the tab overview dialog should be |
| 231 |
* automatically disposed when it loses focus. |
| 232 |
* |
| 233 |
* @return if <code>true</code>, the tab overview dialog will be disposed |
| 234 |
* when it loses focus. |
| 235 |
*/ |
| 236 |
public boolean toDisposeOverviewOnFocusLoss() { |
| 237 |
return true; |
| 238 |
} |
| 239 |
} |