1 19 20 21 package org.netbeans.modules.form.fakepeer; 22 23 import java.awt.*; 24 25 29 class FakeListPeer extends FakeComponentPeer 30 { 31 FakeListPeer(List target) { 32 super(target); 33 } 34 35 Component createDelegate() { 36 return new Delegate(); 37 } 38 39 public int[] getSelectedIndexes() { 40 return new int[0]; 41 } 42 43 public void add(String item, int index) { 44 } 45 46 public void delItems(int start, int end) { 47 } 48 49 public void removeAll() { 50 } 51 52 public void select(int index) { 53 } 54 55 public void deselect(int index) { 56 } 57 58 public void makeVisible(int index) { 59 } 60 61 public void setMultipleMode(boolean b) { 62 } 63 64 public Dimension getPreferredSize(int rows) { 65 return new Dimension(40, 80); 66 } 67 68 public Dimension getMinimumSize(int rows) { 69 return new Dimension(40, 80); 70 } 71 72 public void addItem(String item, int index) { 73 add(item, index); 74 } 75 76 public void clear() { 77 removeAll(); 78 } 79 80 public void setMultipleSelections(boolean v) { 81 setMultipleMode(v); 82 } 83 84 public Dimension preferredSize(int rows) { 85 return getPreferredSize(rows); 86 } 87 88 public Dimension minimumSize(int rows) { 89 return getMinimumSize(rows); 90 } 91 92 96 private class Delegate extends Component 97 { 98 Delegate() { 99 this.setBackground(SystemColor.window); 100 this.setForeground(SystemColor.windowText); 101 } 102 103 public void paint(Graphics g) { 104 List target =(List) _target; 105 Dimension sz = target.getSize(); 106 int w = sz.width; 107 int h = sz.height; 108 109 g.setColor(target.getBackground()); 110 FakePeerUtils.drawLoweredBox(g,0,0,w,h); 111 112 int n = target.getItemCount(); 113 if (n <= 0) 114 return; 115 116 if (target.isEnabled()) { 117 g.setColor(target.getForeground()); 118 } 119 else { 120 g.setColor(SystemColor.controlShadow); 121 } 122 123 g.setFont(target.getFont()); 124 g.setClip(1,1,w-5,h-4); 125 126 FontMetrics fm = g.getFontMetrics(); 127 int th = fm.getHeight(), 128 ty = th+2; 129 130 for (int i=0; i < n; i++) { 131 g.drawString(target.getItem(i), 4, ty); 132 if (ty > h) break; 133 ty += th; 134 } 135 } 136 137 public Dimension getMinimumSize() { 138 return FakeListPeer.this.getMinimumSize(1); 139 } 140 } 141 } 142 | Popular Tags |