1 22 23 package org.gjt.sp.jedit.gui; 24 25 import javax.swing.border.*; 27 import javax.swing.*; 28 import java.awt.event.*; 29 import java.awt.*; 30 import java.util.*; 31 import org.gjt.sp.jedit.*; 32 34 public class AboutDialog extends EnhancedDialog 35 { 36 public AboutDialog(View view) 38 { 39 super(view,jEdit.getProperty("about.title"),true); 40 41 JPanel content = new JPanel(new BorderLayout()); 42 content.setBorder(new EmptyBorder(12,12,12,12)); 43 setContentPane(content); 44 45 content.add(BorderLayout.CENTER,new AboutPanel()); 46 47 JPanel buttonPanel = new JPanel(); 48 buttonPanel.setLayout(new BoxLayout(buttonPanel,BoxLayout.X_AXIS)); 49 buttonPanel.setBorder(new EmptyBorder(12,0,0,0)); 50 51 buttonPanel.add(Box.createGlue()); 52 close = new JButton(jEdit.getProperty("common.close")); 53 close.addActionListener(new ActionHandler()); 54 getRootPane().setDefaultButton(close); 55 buttonPanel.add(close); 56 buttonPanel.add(Box.createGlue()); 57 content.add(BorderLayout.SOUTH,buttonPanel); 58 59 pack(); 60 setResizable(false); 61 setLocationRelativeTo(view); 62 setVisible(true); 63 } 65 public void ok() 67 { 68 dispose(); 69 } 71 public void cancel() 73 { 74 dispose(); 75 } 77 private JButton close; 79 80 class ActionHandler implements ActionListener 82 { 83 public void actionPerformed(ActionEvent evt) 84 { 85 dispose(); 86 } 87 } 89 static class AboutPanel extends JComponent 91 { 92 ImageIcon image; 93 Vector text; 94 int scrollPosition; 95 AnimationThread thread; 96 int maxWidth; 97 FontMetrics fm; 98 99 public static int TOP = 120; 100 public static int BOTTOM = 30; 101 102 AboutPanel() 103 { 104 setFont(UIManager.getFont("Label.font")); 105 fm = getFontMetrics(getFont()); 106 107 setForeground(new Color(96,96,96)); 108 image = new ImageIcon(getClass().getResource( 109 "/org/gjt/sp/jedit/icons/about.png")); 110 111 setBorder(new MatteBorder(1,1,1,1,Color.gray)); 112 113 text = new Vector(50); 114 StringTokenizer st = new StringTokenizer( 115 jEdit.getProperty("about.text"),"\n"); 116 while(st.hasMoreTokens()) 117 { 118 String line = st.nextToken(); 119 text.addElement(line); 120 maxWidth = Math.max(maxWidth, 121 fm.stringWidth(line) + 10); 122 } 123 124 scrollPosition = -250; 125 126 thread = new AnimationThread(); 127 } 128 129 public void paintComponent(Graphics g) 130 { 131 g.setColor(new Color(96,96,96)); 132 image.paintIcon(this,g,1,1); 133 134 FontMetrics fm = g.getFontMetrics(); 135 136 String [] args = { jEdit.getVersion(), System.getProperty("java.version") }; 137 String version = jEdit.getProperty("about.version",args); 138 g.drawString(version,(getWidth() - fm.stringWidth(version)) / 2, 139 getHeight() - 5); 140 141 g = g.create((getWidth() - maxWidth) / 2,TOP,maxWidth, 142 getHeight() - TOP - BOTTOM); 143 144 int height = fm.getHeight(); 145 int firstLine = scrollPosition / height; 146 147 int firstLineOffset = height - scrollPosition % height; 148 int lines = (getHeight() - TOP - BOTTOM) / height; 149 150 int y = firstLineOffset; 151 152 for(int i = 0; i <= lines; i++) 153 { 154 if(i + firstLine >= 0 && i + firstLine < text.size()) 155 { 156 String line = (String )text.get(i + firstLine); 157 g.drawString(line,(maxWidth - fm.stringWidth(line))/2,y); 158 } 159 y += fm.getHeight(); 160 } 161 } 162 163 public Dimension getPreferredSize() 164 { 165 return new Dimension(1 + image.getIconWidth(), 166 1 + image.getIconHeight()); 167 } 168 169 public void addNotify() 170 { 171 super.addNotify(); 172 thread.start(); 173 } 174 175 public void removeNotify() 176 { 177 super.removeNotify(); 178 thread.kill(); 179 } 180 181 class AnimationThread extends Thread 182 { 183 private boolean running = true; 184 private long last; 185 186 AnimationThread() 187 { 188 super("About box animation thread"); 189 setPriority(Thread.MIN_PRIORITY); 190 } 191 192 public void kill() 193 { 194 running = false; 195 } 196 197 public void run() 198 { 199 FontMetrics fm = getFontMetrics(getFont()); 200 int max = (text.size() * fm.getHeight()); 201 202 while (running) 203 { 204 scrollPosition += 2; 205 206 if(scrollPosition > max) 207 scrollPosition = -250; 208 209 if(last != 0) 210 { 211 long frameDelay = 212 System.currentTimeMillis() 213 - last; 214 215 try 216 { 217 Thread.sleep( 218 75 219 - frameDelay); 220 } 221 catch(Exception e) 222 { 223 } 224 } 225 226 last = System.currentTimeMillis(); 227 228 repaint(getWidth() / 2 - maxWidth, 229 TOP,maxWidth * 2, 230 getHeight() - TOP - BOTTOM); 231 } 232 } 233 } 234 } } 236 | Popular Tags |