1 package text.list; 2 3 import text.*; 4 5 import java.awt.*; 6 import java.awt.event.*; 7 import java.util.*; 8 import javax.swing.*; 9 import javax.swing.event.*; 10 import java.awt.font.*; 11 12 import rero.config.*; 13 14 public class ListDisplayComponent extends JComponent implements ChangeListener, ClientStateListener 15 { 16 protected ListData data; 17 18 public ListDisplayComponent() 19 { 20 setOpaque(false); 21 setDoubleBuffered(false); 22 23 ClientState.getClientState().addClientStateListener("listbox.width", this); 24 25 propertyChanged(null, null); 26 } 27 28 public void installDataSource(ListData _data) 29 { 30 data = _data; 31 } 32 33 protected String test_string = ""; 34 private static final String widthstring = "1234567890123456789012345678901234567890123456789012345678901234567890"; 35 36 public void propertyChanged(String a, String b) 37 { 38 test_string = widthstring.substring(0, ClientState.getClientState().getInteger("listbox.width", ClientDefaults.listbox_width)); 39 revalidate(); 40 } 41 42 public void stateChanged(ChangeEvent e) 43 { 44 repaint(); 45 } 46 47 public Dimension getPreferredSize() 48 { 49 FontMetrics fm = TextSource.fontMetrics; 50 return new Dimension(fm.stringWidth(test_string) + TextSource.UNIVERSAL_TWEAK, 0); 51 } 52 53 54 public void paint (Graphics g) 55 { 56 TextSource.initGraphics(g); 57 58 data.setExtent(getHeight() / (TextSource.fontMetrics.getHeight() + 2)); 59 60 int checkY = (g.getClipBounds()).y - 10; int checkH = checkY+(g.getClipBounds()).height + 20; 63 int width = super.getWidth(); 64 int height = super.getHeight(); 65 66 g.setFont(TextSource.clientFont); 67 68 int baseline = TextSource.fontMetrics.getHeight() - 2; 70 synchronized (data.getSynchronizationKeyOuter()) 71 { 72 synchronized (data.getSynchronizationKeyInner()) 73 { 74 ListElement head = data.head(); 76 while (head != null && baseline < height) 77 { 78 if (baseline <= checkH && baseline >= checkY) 79 { 80 if (head.isSelected()) 81 { 82 g.setColor(UIManager.getColor("TextField.selectionBackground")); 84 int txtheight = TextSource.fontMetrics.getHeight(); 85 g.fillRect(0, baseline - txtheight + 2, width, txtheight + 2); } 87 TextSource.drawText(g, head.getAttributedText(), TextSource.UNIVERSAL_TWEAK, baseline); 88 } 89 90 baseline += (TextSource.fontMetrics.getHeight() + 2); 91 92 head = data.next(); 93 } 95 } } } 98 } 99 | Popular Tags |