PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre3/org/gjt/sp/jedit/options/DockingOptionPane.java

#
Java | 301 lines | 235 code | 44 blank | 22 comment | 13 complexity | 6fdc122fd0103408bf831b59b411f34b MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * DockingOptionPane.java - Dockable window options panel
  3. * Copyright (C) 2000, 2001 Slava Pestov
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. package org.gjt.sp.jedit.options;
  20. import javax.swing.table.*;
  21. import javax.swing.*;
  22. import java.awt.*;
  23. import java.util.Vector;
  24. import org.gjt.sp.jedit.gui.*;
  25. import org.gjt.sp.jedit.*;
  26. public class DockingOptionPane extends AbstractOptionPane
  27. {
  28. public DockingOptionPane()
  29. {
  30. super("docking");
  31. }
  32. public void _init()
  33. {
  34. Box box = new Box(BoxLayout.X_AXIS);
  35. ButtonGroup grp = new ButtonGroup();
  36. layout1 = new JToggleButton(GUIUtilities.loadIcon("dock_layout1.gif"));
  37. grp.add(layout1);
  38. box.add(layout1);
  39. box.add(Box.createHorizontalStrut(6));
  40. layout2 = new JToggleButton(GUIUtilities.loadIcon("dock_layout2.gif"));
  41. grp.add(layout2);
  42. box.add(layout2);
  43. if(jEdit.getBooleanProperty("view.docking.alternateLayout"))
  44. layout2.setSelected(true);
  45. else
  46. layout1.setSelected(true);
  47. addComponent(jEdit.getProperty("options.docking.layout"),box);
  48. // reuse properties defined by the general option pane
  49. String[] positions = {
  50. jEdit.getProperty("options.docking.top"),
  51. jEdit.getProperty("options.docking.bottom"),
  52. };
  53. tabsPos = new JComboBox(positions);
  54. tabsPos.setSelectedIndex(jEdit.getIntegerProperty(
  55. "view.docking.tabsPos",0));
  56. addComponent(jEdit.getProperty("options.docking.tabsPos"),tabsPos);
  57. addComponent(Box.createVerticalStrut(6));
  58. GridBagConstraints cons = new GridBagConstraints();
  59. cons.gridy = 3;
  60. cons.gridwidth = cons.gridheight = GridBagConstraints.REMAINDER;
  61. cons.fill = GridBagConstraints.BOTH;
  62. cons.weightx = cons.weighty = 1.0f;
  63. JScrollPane windowScroller = createWindowTableScroller();
  64. gridBag.setConstraints(windowScroller,cons);
  65. add(windowScroller);
  66. }
  67. public void _save()
  68. {
  69. jEdit.setBooleanProperty("view.docking.alternateLayout",
  70. layout2.isSelected());
  71. jEdit.setIntegerProperty("view.docking.tabsPos",
  72. tabsPos.getSelectedIndex());
  73. windowModel.save();
  74. }
  75. // private members
  76. private JToggleButton layout1;
  77. private JToggleButton layout2;
  78. private JComboBox tabsPos;
  79. private JTable windowTable;
  80. private WindowTableModel windowModel;
  81. private JScrollPane createWindowTableScroller()
  82. {
  83. windowModel = createWindowModel();
  84. windowTable = new JTable(windowModel);
  85. windowTable.getTableHeader().setReorderingAllowed(false);
  86. windowTable.setColumnSelectionAllowed(false);
  87. windowTable.setRowSelectionAllowed(false);
  88. windowTable.setCellSelectionEnabled(false);
  89. DockPositionCellRenderer comboBox = new DockPositionCellRenderer();
  90. comboBox.setRequestFocusEnabled(false);
  91. windowTable.setRowHeight(comboBox.getPreferredSize().height);
  92. TableColumn column = windowTable.getColumnModel().getColumn(1);
  93. column.setCellRenderer(comboBox);
  94. comboBox = new DockPositionCellRenderer();
  95. comboBox.setRequestFocusEnabled(false);
  96. column.setCellEditor(new DefaultCellEditor(comboBox));
  97. Dimension d = windowTable.getPreferredSize();
  98. d.height = Math.min(d.height,200);
  99. JScrollPane scroller = new JScrollPane(windowTable);
  100. scroller.setPreferredSize(d);
  101. return scroller;
  102. }
  103. private WindowTableModel createWindowModel()
  104. {
  105. return new WindowTableModel();
  106. }
  107. class DockPositionCellRenderer extends JComboBox
  108. implements TableCellRenderer
  109. {
  110. DockPositionCellRenderer()
  111. {
  112. super(new String[] {
  113. DockableWindowManager.FLOATING,
  114. DockableWindowManager.TOP,
  115. DockableWindowManager.LEFT,
  116. DockableWindowManager.BOTTOM,
  117. DockableWindowManager.RIGHT
  118. });
  119. }
  120. public Component getTableCellRendererComponent(JTable table,
  121. Object value, boolean isSelected, boolean hasFocus,
  122. int row, int column)
  123. {
  124. setSelectedItem(value);
  125. return this;
  126. }
  127. }
  128. }
  129. class WindowTableModel extends AbstractTableModel
  130. {
  131. private Vector windows;
  132. WindowTableModel()
  133. {
  134. windows = new Vector();
  135. // old dockable window API compatibility code
  136. Object[] list = EditBus.getNamedList(DockableWindow.DOCKABLE_WINDOW_LIST);
  137. if(list != null)
  138. {
  139. for(int i = 0; i < list.length; i++)
  140. {
  141. windows.addElement(new Entry((String)list[i]));
  142. }
  143. }
  144. // end compatibility code
  145. String[] dockables = DockableWindowManager.getRegisteredDockableWindows();
  146. for(int i = 0; i < dockables.length; i++)
  147. {
  148. windows.addElement(new Entry(dockables[i]));
  149. }
  150. sort();
  151. }
  152. public void sort()
  153. {
  154. MiscUtilities.quicksort(windows,new WindowCompare());
  155. fireTableDataChanged();
  156. }
  157. public int getColumnCount()
  158. {
  159. return 2;
  160. }
  161. public int getRowCount()
  162. {
  163. return windows.size();
  164. }
  165. public Class getColumnClass(int col)
  166. {
  167. switch(col)
  168. {
  169. case 0:
  170. case 1:
  171. return String.class;
  172. default:
  173. throw new InternalError();
  174. }
  175. }
  176. public Object getValueAt(int row, int col)
  177. {
  178. Entry window = (Entry)windows.elementAt(row);
  179. switch(col)
  180. {
  181. case 0:
  182. return window.title;
  183. case 1:
  184. return window.dockPosition;
  185. default:
  186. throw new InternalError();
  187. }
  188. }
  189. public boolean isCellEditable(int row, int col)
  190. {
  191. return (col != 0);
  192. }
  193. public void setValueAt(Object value, int row, int col)
  194. {
  195. if(col == 0)
  196. return;
  197. Entry window = (Entry)windows.elementAt(row);
  198. switch(col)
  199. {
  200. case 1:
  201. window.dockPosition = (String)value;
  202. break;
  203. default:
  204. throw new InternalError();
  205. }
  206. fireTableRowsUpdated(row,row);
  207. }
  208. public String getColumnName(int index)
  209. {
  210. switch(index)
  211. {
  212. case 0:
  213. return jEdit.getProperty("options.docking.title");
  214. case 1:
  215. return jEdit.getProperty("options.docking.dockPosition");
  216. default:
  217. throw new InternalError();
  218. }
  219. }
  220. public void save()
  221. {
  222. for(int i = 0; i < windows.size(); i++)
  223. {
  224. ((Entry)windows.elementAt(i)).save();
  225. }
  226. }
  227. class Entry
  228. {
  229. String name;
  230. String title;
  231. String dockPosition;
  232. Entry(String name)
  233. {
  234. this.name = name;
  235. title = jEdit.getProperty(name + ".title");
  236. if(title == null)
  237. title = name;
  238. dockPosition = jEdit.getProperty(name + ".dock-position");
  239. if(dockPosition == null)
  240. dockPosition = DockableWindowManager.FLOATING;
  241. }
  242. void save()
  243. {
  244. jEdit.setProperty(name + ".dock-position",dockPosition);
  245. }
  246. }
  247. class WindowCompare implements MiscUtilities.Compare
  248. {
  249. public int compare(Object obj1, Object obj2)
  250. {
  251. Entry e1 = (Entry)obj1;
  252. Entry e2 = (Entry)obj2;
  253. return MiscUtilities.compareStrings(
  254. e1.title,e2.title,true);
  255. }
  256. }
  257. }