1 7 8 package org.gjt.jclasslib.browser.detail; 9 10 import org.gjt.jclasslib.browser.AbstractDetailPane; 11 import org.gjt.jclasslib.browser.BrowserServices; 12 import org.gjt.jclasslib.util.ExtendedJLabel; 13 import org.gjt.jclasslib.util.GUIHelper; 14 15 import javax.swing.*; 16 import javax.swing.tree.TreePath ; 17 import java.awt.*; 18 import java.util.ArrayList ; 19 import java.util.Iterator ; 20 21 28 public abstract class FixedListDetailPane extends AbstractDetailPane { 29 30 32 private java.util.List detailPaneEntries; 33 private JScrollPane scrollPane; 34 35 39 protected FixedListDetailPane(BrowserServices services) { 40 super(services); 41 } 42 43 48 protected void addDetailPaneEntry(ExtendedJLabel key, ExtendedJLabel value) { 49 addDetailPaneEntry(key, value, null); 50 } 51 52 59 protected void addDetailPaneEntry(ExtendedJLabel key, 60 ExtendedJLabel value, 61 ExtendedJLabel comment) { 62 63 if (detailPaneEntries == null) { 64 detailPaneEntries = new ArrayList (); 65 } 66 67 detailPaneEntries.add( 68 new DetailPaneEntry(key, value, comment) 69 ); 70 } 71 72 protected void setupComponent() { 73 74 setupLabels(); 75 76 setLayout(new GridBagLayout()); 77 78 GridBagConstraints gKey = new GridBagConstraints(); 79 gKey.anchor = GridBagConstraints.NORTHWEST; 80 gKey.insets = new Insets(1,10,0,10); 81 82 GridBagConstraints gValue = new GridBagConstraints(); 83 gValue.gridx = 1; 84 gValue.anchor = GridBagConstraints.NORTHEAST; 85 gValue.insets = new Insets(1,0,0,5); 86 87 GridBagConstraints gComment = new GridBagConstraints(); 88 gComment.gridx = 2; 89 gComment.anchor = GridBagConstraints.NORTHWEST; 90 gComment.insets = new Insets(1,0,0,5); 91 gComment.fill = GridBagConstraints.HORIZONTAL; 92 93 GridBagConstraints gCommentOnly = (GridBagConstraints)gComment.clone(); 94 gCommentOnly.gridx = 1; 95 gCommentOnly.gridwidth = 2; 96 97 GridBagConstraints gRemainder = new GridBagConstraints(); 98 gRemainder.gridx = 2; 99 gRemainder.weightx = gRemainder.weighty = 1; 100 gRemainder.fill = GridBagConstraints.BOTH; 101 102 Iterator it = detailPaneEntries.iterator(); 103 while (it.hasNext()) { 104 DetailPaneEntry entry = (DetailPaneEntry)it.next(); 105 if (entry == null) { 106 continue; 107 } 108 109 gComment.gridy = gValue.gridy = ++gKey.gridy; 110 if (entry.key != null) { 111 add(entry.key, gKey); 112 } 113 if (entry.value != null) { 114 add(entry.value, gValue); 115 } 116 if (entry.comment != null) { 117 add(entry.comment, (entry.value == null) ? gCommentOnly : gComment); 118 119 entry.comment.setAutoTooltip(true); 120 } 121 122 } 123 124 gRemainder.gridy = gKey.gridy + 1; 125 gRemainder.gridy += addSpecial(gRemainder.gridy); 126 127 add(new JPanel(), gRemainder); 128 scrollPane = new JScrollPane(this); 129 GUIHelper.setDefaultScrollbarUnits(scrollPane); 130 scrollPane.setBorder(null); 131 132 } 133 134 138 public JScrollPane getScrollPane() { 139 return scrollPane; 140 } 141 142 public void show(TreePath treePath) { 143 144 scrollPane.getViewport().setViewPosition(new Point(0, 0)); 145 146 } 147 148 152 protected abstract void setupLabels(); 153 154 159 protected int addSpecial(int gridy) { 160 return 0; 161 } 162 163 private static class DetailPaneEntry { 164 public final ExtendedJLabel key; 165 public final ExtendedJLabel value; 166 public final ExtendedJLabel comment; 167 168 private DetailPaneEntry(ExtendedJLabel key, 169 ExtendedJLabel value, 170 ExtendedJLabel comment) { 171 this.key = key; 172 this.value = value; 173 this.comment = comment; 174 } 175 } 176 177 178 } 179 180 | Popular Tags |