1 35 36 39 package demo.swingset; 40 41 import swingwtx.swing.*; 42 import swingwtx.swing.event.*; 43 import swingwtx.swing.text.*; 44 import swingwtx.swing.border.*; 45 import swingwtx.swing.colorchooser.*; 46 import swingwtx.swing.filechooser.*; 47 import javax.accessibility.*; 48 49 import swingwt.awt.*; 50 import swingwt.awt.event.*; 51 import java.beans.*; 52 import java.util.*; 53 import java.io.*; 54 import java.applet.*; 55 import java.net.*; 56 57 63 public class TabbedPaneDemo extends DemoModule implements ActionListener { 64 HeadSpin spin; 65 66 JTabbedPane tabbedpane; 67 68 ButtonGroup group; 69 70 JRadioButton top; 71 JRadioButton bottom; 72 JRadioButton left; 73 JRadioButton right; 74 75 78 public static void main(String [] args) { 79 TabbedPaneDemo demo = new TabbedPaneDemo(null); 80 demo.mainImpl(); 81 } 82 83 86 public TabbedPaneDemo(SwingSet2 swingset) { 87 super(swingset, "TabbedPaneDemo", "toolbar/JTabbedPane.gif"); 90 91 JPanel tabControls = new JPanel(); 93 tabControls.add(new JLabel(getString("TabbedPaneDemo.label"))); 94 top = (JRadioButton) tabControls.add(new JRadioButton(getString("TabbedPaneDemo.top"))); 95 left = (JRadioButton) tabControls.add(new JRadioButton(getString("TabbedPaneDemo.left"))); 96 bottom = (JRadioButton) tabControls.add(new JRadioButton(getString("TabbedPaneDemo.bottom"))); 97 right = (JRadioButton) tabControls.add(new JRadioButton(getString("TabbedPaneDemo.right"))); 98 getDemoPanel().add(tabControls, BorderLayout.NORTH); 99 100 group = new ButtonGroup(); 101 group.add(top); 102 group.add(bottom); 103 group.add(left); 104 group.add(right); 105 106 top.setSelected(true); 107 108 top.addActionListener(this); 109 bottom.addActionListener(this); 110 left.addActionListener(this); 111 right.addActionListener(this); 112 113 tabbedpane = new JTabbedPane(); 115 getDemoPanel().add(tabbedpane, BorderLayout.CENTER); 116 117 String name = getString("TabbedPaneDemo.laine"); 118 JLabel pix = new JLabel(createImageIcon("tabbedpane/laine.jpg", name)); 119 tabbedpane.add(name, pix); 120 121 name = getString("TabbedPaneDemo.ewan"); 122 pix = new JLabel(createImageIcon("tabbedpane/ewan.jpg", name)); 123 tabbedpane.add(name, pix); 124 125 name = getString("TabbedPaneDemo.hania"); 126 pix = new JLabel(createImageIcon("tabbedpane/hania.jpg", name)); 127 tabbedpane.add(name, pix); 128 129 name = getString("TabbedPaneDemo.bounce"); 130 spin = new HeadSpin(); 131 tabbedpane.add(name, spin); 132 133 tabbedpane.addChangeListener( 134 new ChangeListener() { 135 public void stateChanged(ChangeEvent e) { 136 if(tabbedpane.getSelectedIndex() == tabbedpane.getTabCount()-1) { 138 spin.go(); 139 } 140 } 141 } 142 ); 143 } 144 145 public void actionPerformed(ActionEvent e) { 146 if(e.getSource() == top) { 147 tabbedpane.setTabPlacement(JTabbedPane.TOP); 148 } else if(e.getSource() == left) { 149 tabbedpane.setTabPlacement(JTabbedPane.LEFT); 150 } else if(e.getSource() == bottom) { 151 tabbedpane.setTabPlacement(JTabbedPane.BOTTOM); 152 } else if(e.getSource() == right) { 153 tabbedpane.setTabPlacement(JTabbedPane.RIGHT); 154 } 155 } 156 157 class HeadSpin extends JComponent implements ActionListener { 158 swingwtx.swing.Timer animator; 159 160 ImageIcon icon[] = new ImageIcon[6]; 161 162 int tmpScale; 163 164 final static int numImages = 6; 165 166 double x[] = new double[numImages]; 167 double y[] = new double[numImages]; 168 169 int xh[] = new int[numImages]; 170 int yh[] = new int[numImages]; 171 172 double scale[] = new double[numImages]; 173 174 public HeadSpin() { 175 setBackground(Color.black); 176 icon[0] = createImageIcon("tabbedpane/ewan.gif", getString("TabbedPaneDemo.ewan")); 177 icon[1] = createImageIcon("tabbedpane/stephen.gif", getString("TabbedPaneDemo.stephen")); 178 icon[2] = createImageIcon("tabbedpane/david.gif", getString("TabbedPaneDemo.david")); 179 icon[3] = createImageIcon("tabbedpane/matthew.gif", getString("TabbedPaneDemo.matthew")); 180 icon[4] = createImageIcon("tabbedpane/blake.gif", getString("TabbedPaneDemo.blake")); 181 icon[5] = createImageIcon("tabbedpane/brooke.gif", getString("TabbedPaneDemo.brooke")); 182 183 setDoubleBuffered(true); 184 190 } 191 192 public void go() { 193 animator = new swingwtx.swing.Timer(22 + 22 + 22, this); 194 animator.start(); 195 } 196 197 public void paint(Graphics g) { 198 g.setColor(Color.black); 199 g.fillRect(0, 0, getWidth(), getHeight()); 200 201 for(int i = 0; i < numImages; i++) { 202 if(x[i] > 3*i) { 203 nudge(i); 204 squish(g, icon[i], xh[i], yh[i], scale[i]); 205 } else { 206 x[i] += .05; 207 y[i] += .05; 208 } 209 } 210 } 211 212 Random rand = new Random(); 213 214 public void nudge(int i) { 215 x[i] += (double) rand.nextInt(1000) / 8756; 216 y[i] += (double) rand.nextInt(1000) / 5432; 217 int tmpScale = (int) (Math.abs(Math.sin(x[i])) * 10); 218 scale[i] = (double) tmpScale / 10; 219 int nudgeX = (int) (((double) getWidth()/2) * .8); 220 int nudgeY = (int) (((double) getHeight()/2) * .60); 221 xh[i] = (int) (Math.sin(x[i]) * nudgeX) + nudgeX; 222 yh[i] = (int) (Math.sin(y[i]) * nudgeY) + nudgeY; 223 } 224 225 public void squish(Graphics g, ImageIcon icon, int x, int y, double scale) { 226 if(isVisible()) { 227 g.drawImage(icon.getImage(), x, y, 228 (int) (icon.getIconWidth()*scale), 229 (int) (icon.getIconHeight()*scale), 230 this); 231 } 232 } 233 234 public void actionPerformed(ActionEvent e) { 235 if(isVisible()) { 236 repaint(); 237 } else { 238 animator.stop(); 239 } 240 } 241 } 242 } 243 244 | Popular Tags |