| 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.preview; |
| 31 |
|
| 32 |
import java.awt.*; |
| 33 |
|
| 34 |
/** |
| 35 |
* Base class for component preview painters. |
| 36 |
* |
| 37 |
* @author Kirill Grouchnikov |
| 38 |
*/ |
| 39 |
public abstract class PreviewPainter { |
| 40 |
/** |
| 41 |
* Draws a component preview on the specified graphics. |
| 42 |
* |
| 43 |
* @param parent |
| 44 |
* Component parent. May be <code>null</code>. |
| 45 |
* @param component |
| 46 |
* Component. May be <code>null</code>. |
| 47 |
* @param componentIndex |
| 48 |
* Component index in its parent. May be negative. |
| 49 |
* @param g |
| 50 |
* Graphics context. |
| 51 |
* @param x |
| 52 |
* X coordinate of the preview area. |
| 53 |
* @param y |
| 54 |
* Y coordinate of the preview area. |
| 55 |
* @param w |
| 56 |
* Width of the preview area. |
| 57 |
* @param h |
| 58 |
* Height of the preview area. |
| 59 |
*/ |
| 60 |
public void previewComponent(Container parent, Component component, |
| 61 |
int componentIndex, Graphics g, int x, int y, int w, int h) { |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Checks whether the specified component is previewable. |
| 66 |
* |
| 67 |
* @param parent |
| 68 |
* Component parent. May be <code>null</code>. |
| 69 |
* @param component |
| 70 |
* Component. May be <code>null</code>. |
| 71 |
* @param componentIndex |
| 72 |
* Component index in its parent. May be negative. |
| 73 |
* @return <code>true</code> if the specified component is previewable, |
| 74 |
* <code>false</code> otherwise. |
| 75 |
*/ |
| 76 |
public boolean hasPreview(Container parent, Component component, |
| 77 |
int componentIndex) { |
| 78 |
return false; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Checks whether the specified component has a preview window. |
| 83 |
* |
| 84 |
* @param parent |
| 85 |
* Component parent. May be <code>null</code>. |
| 86 |
* @param component |
| 87 |
* Component. May be <code>null</code>. |
| 88 |
* @param componentIndex |
| 89 |
* Component index in its parent. May be negative. |
| 90 |
* @return <code>true</code> if the specified component has a preview |
| 91 |
* window, <code>false</code> otherwise. |
| 92 |
*/ |
| 93 |
public boolean hasPreviewWindow(Container parent, Component component, |
| 94 |
int componentIndex) { |
| 95 |
return false; |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Returns the dimension for the component preview window. |
| 100 |
* |
| 101 |
* @param parent |
| 102 |
* Component parent. May be <code>null</code>. |
| 103 |
* @param component |
| 104 |
* Component. May be <code>null</code>. |
| 105 |
* @param componentIndex |
| 106 |
* Component index in its parent. May be negative. |
| 107 |
* @return Dimension of the component preview window. |
| 108 |
*/ |
| 109 |
public Dimension getPreviewWindowDimension(Container parent, |
| 110 |
Component component, int componentIndex) { |
| 111 |
return new Dimension(300, 200); |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Returns extra delay (in milliseconds) for showing the component preview |
| 116 |
* window. The base delay is 2000 milliseconds (2 seconds). This function |
| 117 |
* must return a non-negative value. Note that this method may not be called |
| 118 |
* in some preview scenarios (that require immediate preview functionality). |
| 119 |
* |
| 120 |
* @param parent |
| 121 |
* Component parent. May be <code>null</code>. |
| 122 |
* @param component |
| 123 |
* Component. May be <code>null</code>. |
| 124 |
* @param componentIndex |
| 125 |
* Component index in its parent. May be negative. |
| 126 |
* @return Non-negative extra delay (in milliseconds) for showing the |
| 127 |
* component preview window. |
| 128 |
*/ |
| 129 |
public int getPreviewWindowExtraDelay(Container parent, |
| 130 |
Component component, int componentIndex) { |
| 131 |
return 0; |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Returns indication whether the thumbnail preview should be updated |
| 136 |
* periodically. If the return value is <code>true</code>, then the |
| 137 |
* implementation of {@link #getUpdateCycle(Container, Component, int)} |
| 138 |
* returns the refresh cycle length in milliseconds. |
| 139 |
* |
| 140 |
* @param parent |
| 141 |
* Component parent. May be <code>null</code>. |
| 142 |
* @param component |
| 143 |
* Component. May be <code>null</code>. |
| 144 |
* @param componentIndex |
| 145 |
* Component index in its parent. May be negative. |
| 146 |
* @return <code>true</code> if the thumbnail preview of the specified |
| 147 |
* component should be updated periodically, <code>false</code> |
| 148 |
* otherwise. |
| 149 |
*/ |
| 150 |
public boolean toUpdatePeriodically(Container parent, Component component, |
| 151 |
int componentIndex) { |
| 152 |
return false; |
| 153 |
} |
| 154 |
|
| 155 |
/** |
| 156 |
* If the result of {@link #toUpdatePeriodically(Container, Component, int)} |
| 157 |
* is <code>true</code>, returns the update cycle length in milliseconds. |
| 158 |
* |
| 159 |
* @param parent |
| 160 |
* Component parent. May be <code>null</code>. |
| 161 |
* @param component |
| 162 |
* Component. May be <code>null</code>. |
| 163 |
* @param componentIndex |
| 164 |
* Component index in its parent. May be negative. |
| 165 |
* @return Update cycle length in milliseconds for the thumbnail preview of |
| 166 |
* the specified component. |
| 167 |
*/ |
| 168 |
public int getUpdateCycle(Container parent, Component component, |
| 169 |
int componentIndex) { |
| 170 |
return 10000; |
| 171 |
} |
| 172 |
} |