1 30 31 package com.jgoodies.animation.components; 32 33 import java.awt.Color ; 34 import java.awt.Graphics ; 35 import java.awt.Graphics2D ; 36 import java.awt.RenderingHints ; 37 38 import javax.swing.JComponent ; 39 40 import com.jgoodies.animation.AnimationFunction; 41 import com.jgoodies.animation.AnimationFunctions; 42 import com.jgoodies.animation.renderer.GlyphRenderer; 43 import com.jgoodies.animation.renderer.HeightMode; 44 45 51 public final class GlyphLabel extends JComponent { 52 53 private final GlyphRenderer renderer; 54 55 56 58 66 public GlyphLabel(String text, long duration, long glyphDelay) { 67 this(text, duration, glyphDelay, Color.darkGray); 68 } 69 70 80 public GlyphLabel( 81 String text, 82 long duration, 83 long glyphDelay, 84 Color baseColor) { 85 renderer = 86 new GlyphRenderer( 87 text, 88 defaultScaleFunction(duration), 89 AnimationFunctions.ZERO, 90 defaultColorFunction(duration, baseColor), 91 glyphDelay); 92 } 93 94 100 public static AnimationFunction defaultScaleFunction(long duration) { 101 return AnimationFunctions.linear( 102 duration, 103 new Float [] { 104 new Float (5.0f), 105 new Float (0.8f), 106 new Float (1.0f), 107 new Float (1.0f)}, 108 new float[] { 0.0f, 0.1f, 0.12f, 1.0f }); 109 } 110 111 119 public static AnimationFunction defaultColorFunction( 120 long duration, 121 Color baseColor) { 122 return AnimationFunctions.alphaColor( 123 AnimationFunctions.linear( 124 duration, 125 new Integer [] { 126 new Integer (0), 127 new Integer (255), 128 new Integer (255)}, 129 new float[] { 0.0f, 0.15f, 1.0f }), 130 baseColor); 131 } 132 133 134 136 public HeightMode getHeightMode() { 137 return renderer.getHeightMode(); 138 } 139 140 public String getText() { 141 return renderer.getText(); 142 } 143 144 public void setHeightMode(HeightMode heightMode) { 145 renderer.setHeightMode(heightMode); 146 } 147 148 public void setText(String newText) { 149 renderer.setText(newText); 150 repaint(); 151 } 152 153 public void setTime(long time) { 154 renderer.setTime(time); 155 repaint(); 156 } 157 158 159 161 167 public void paintComponent(Graphics g) { 168 Graphics2D g2 = (Graphics2D ) g; 169 170 g2.setRenderingHint( 171 RenderingHints.KEY_ANTIALIASING, 172 RenderingHints.VALUE_ANTIALIAS_ON); 173 g2.setRenderingHint( 174 RenderingHints.KEY_RENDERING, 175 RenderingHints.VALUE_RENDER_QUALITY); 176 177 renderer.setFont(getFont()); 178 renderer.render(g2, getWidth(), getHeight()); 179 } 180 181 } | Popular Tags |