1 22 23 package org.gjt.sp.jedit.options; 24 25 import javax.swing.table.*; 27 import javax.swing.*; 28 import java.awt.*; 29 import java.util.Vector ; 30 import java.util.Collections ; 31 import java.util.Comparator ; 32 33 import org.gjt.sp.jedit.gui.*; 34 import org.gjt.sp.jedit.*; 35 import org.gjt.sp.util.StandardUtilities; 36 38 public class DockingOptionPane extends AbstractOptionPane 40 { 41 public DockingOptionPane() 43 { 44 super("docking"); 45 } 47 public void _init() 49 { 50 setLayout(new BorderLayout()); 51 add(BorderLayout.CENTER,createWindowTableScroller()); 52 } 54 public void _save() 56 { 57 windowModel.save(); 58 } 60 62 private JTable windowTable; 64 private WindowTableModel windowModel; 65 67 private JScrollPane createWindowTableScroller() 69 { 70 windowModel = createWindowModel(); 71 windowTable = new JTable(windowModel); 72 windowTable.getTableHeader().setReorderingAllowed(false); 73 windowTable.setColumnSelectionAllowed(false); 74 windowTable.setRowSelectionAllowed(false); 75 windowTable.setCellSelectionEnabled(false); 76 77 DockPositionCellRenderer comboBox = new DockPositionCellRenderer(); 78 windowTable.setRowHeight(comboBox.getPreferredSize().height); 79 TableColumn column = windowTable.getColumnModel().getColumn(1); 80 column.setCellRenderer(comboBox); 81 column.setCellEditor(new DefaultCellEditor(new DockPositionCellRenderer())); 82 83 Dimension d = windowTable.getPreferredSize(); 84 d.height = Math.min(d.height,50); 85 JScrollPane scroller = new JScrollPane(windowTable); 86 scroller.setPreferredSize(d); 87 return scroller; 88 } 90 private static WindowTableModel createWindowModel() 92 { 93 return new WindowTableModel(); 94 } 96 98 static class DockPositionCellRenderer extends JComboBox 100 implements TableCellRenderer 101 { 102 DockPositionCellRenderer() 103 { 104 super(new String [] { 105 DockableWindowManager.FLOATING, 106 DockableWindowManager.TOP, 107 DockableWindowManager.LEFT, 108 DockableWindowManager.BOTTOM, 109 DockableWindowManager.RIGHT 110 }); 111 DockPositionCellRenderer.this.setRequestFocusEnabled(false); 112 } 113 114 public Component getTableCellRendererComponent(JTable table, 115 Object value, boolean isSelected, boolean hasFocus, 116 int row, int column) 117 { 118 setSelectedItem(value); 119 return this; 120 } 121 } } 124 class WindowTableModel extends AbstractTableModel 126 { 127 private Vector windows; 128 129 WindowTableModel() 131 { 132 windows = new Vector (); 133 134 String [] dockables = DockableWindowManager 135 .getRegisteredDockableWindows(); 136 for(int i = 0; i < dockables.length; i++) 137 { 138 windows.addElement(new Entry(dockables[i])); 139 } 140 141 sort(); 142 } 144 public void sort() 146 { 147 Collections.sort(windows,new WindowCompare()); 148 fireTableDataChanged(); 149 } 151 public int getColumnCount() 153 { 154 return 2; 155 } 157 public int getRowCount() 159 { 160 return windows.size(); 161 } 163 public Class getColumnClass(int col) 165 { 166 switch(col) 167 { 168 case 0: 169 case 1: 170 return String .class; 171 default: 172 throw new InternalError (); 173 } 174 } 176 public Object getValueAt(int row, int col) 178 { 179 Entry window = (Entry)windows.elementAt(row); 180 switch(col) 181 { 182 case 0: 183 return window.title; 184 case 1: 185 return window.dockPosition; 186 default: 187 throw new InternalError (); 188 } 189 } 191 public boolean isCellEditable(int row, int col) 193 { 194 return col != 0; 195 } 197 public void setValueAt(Object value, int row, int col) 199 { 200 if(col == 0) 201 return; 202 203 Entry window = (Entry)windows.elementAt(row); 204 switch(col) 205 { 206 case 1: 207 window.dockPosition = (String )value; 208 break; 209 default: 210 throw new InternalError (); 211 } 212 213 fireTableRowsUpdated(row,row); 214 } 216 public String getColumnName(int index) 218 { 219 switch(index) 220 { 221 case 0: 222 return jEdit.getProperty("options.docking.title"); 223 case 1: 224 return jEdit.getProperty("options.docking.dockPosition"); 225 default: 226 throw new InternalError (); 227 } 228 } 230 public void save() 232 { 233 for(int i = 0; i < windows.size(); i++) 234 { 235 ((Entry)windows.elementAt(i)).save(); 236 } 237 } 239 static class Entry 241 { 242 String name; 243 String title; 244 String dockPosition; 245 246 Entry(String name) 247 { 248 this.name = name; 249 title = jEdit.getProperty(name + ".title"); 250 if(title == null) 251 title = name; 252 253 dockPosition = jEdit.getProperty(name + ".dock-position"); 254 if(dockPosition == null) 255 dockPosition = DockableWindowManager.FLOATING; 256 } 257 258 void save() 259 { 260 jEdit.setProperty(name + ".dock-position",dockPosition); 261 } 262 } 264 static class WindowCompare implements Comparator 266 { 267 public int compare(Object obj1, Object obj2) 268 { 269 Entry e1 = (Entry)obj1; 270 Entry e2 = (Entry)obj2; 271 272 return StandardUtilities.compareStrings( 273 e1.title,e2.title,true); 274 } 275 } } | Popular Tags |