PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/org/gjt/sp/jedit/options/DockingOptionPane.java

#
Java | 362 lines | 268 code | 45 blank | 49 comment | 43 complexity | 5406bdaa5a33370624682942abd59cac 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. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2000, 2001, 2002 Slava Pestov
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package org.gjt.sp.jedit.options;
  23. //{{{ Imports
  24. import javax.swing.table.*;
  25. import javax.swing.*;
  26. import java.awt.event.*;
  27. import java.awt.*;
  28. import java.util.Vector;
  29. import org.gjt.sp.jedit.gui.*;
  30. import org.gjt.sp.jedit.*;
  31. //}}}
  32. //{{{ DockingOptionPane class
  33. public class DockingOptionPane extends AbstractOptionPane
  34. {
  35. //{{{ DockingOptionPane constructor
  36. public DockingOptionPane()
  37. {
  38. super("docking");
  39. } //}}}
  40. //{{{ _init() method
  41. public void _init()
  42. {
  43. addSeparator("options.docking.viewLayout");
  44. layoutIcon1 = GUIUtilities.loadIcon("dock_layout1.png");
  45. layoutIcon2 = GUIUtilities.loadIcon("dock_layout2.png");
  46. layoutIcon3 = GUIUtilities.loadIcon("dock_layout3.png");
  47. layoutIcon4 = GUIUtilities.loadIcon("dock_layout4.png");
  48. JPanel layoutPanel = new JPanel(new VariableGridLayout(
  49. VariableGridLayout.FIXED_NUM_COLUMNS,1,
  50. 6,6));
  51. if(jEdit.getBooleanProperty("view.docking.alternateLayout"))
  52. {
  53. layout = new JLabel(jEdit.getBooleanProperty(
  54. "view.toolbar.alternateLayout")
  55. ? layoutIcon4 : layoutIcon2);
  56. }
  57. else
  58. {
  59. layout = new JLabel(jEdit.getBooleanProperty(
  60. "view.toolbar.alternateLayout")
  61. ? layoutIcon3 : layoutIcon1);
  62. }
  63. layoutPanel.add(layout);
  64. layoutPanel.add(alternateDockingLayout = new JButton(jEdit.getProperty(
  65. "options.docking.alternateDockingLayout")));
  66. alternateDockingLayout.addActionListener(new ActionHandler());
  67. layoutPanel.add(alternateToolBarLayout = new JButton(jEdit.getProperty(
  68. "options.docking.alternateToolBarLayout")));
  69. alternateToolBarLayout.addActionListener(new ActionHandler());
  70. // center the layout panel
  71. GridBagConstraints cons = new GridBagConstraints();
  72. cons.gridy = y++;
  73. cons.gridwidth = GridBagConstraints.REMAINDER;
  74. cons.fill = GridBagConstraints.BOTH;
  75. cons.weightx = 1.0f;
  76. gridBag.setConstraints(layoutPanel,cons);
  77. add(layoutPanel);
  78. addSeparator("options.docking.windowDocking");
  79. cons = new GridBagConstraints();
  80. cons.gridy = y++;
  81. cons.gridwidth = cons.gridheight = GridBagConstraints.REMAINDER;
  82. cons.fill = GridBagConstraints.BOTH;
  83. cons.weightx = cons.weighty = 1.0f;
  84. JScrollPane windowScroller = createWindowTableScroller();
  85. gridBag.setConstraints(windowScroller,cons);
  86. add(windowScroller);
  87. } //}}}
  88. //{{{ _save() method
  89. public void _save()
  90. {
  91. jEdit.setBooleanProperty("view.docking.alternateLayout",
  92. layout.getIcon() == layoutIcon2
  93. || layout.getIcon() == layoutIcon4);
  94. jEdit.setBooleanProperty("view.toolbar.alternateLayout",
  95. layout.getIcon() == layoutIcon3
  96. || layout.getIcon() == layoutIcon4);
  97. windowModel.save();
  98. } //}}}
  99. //{{{ Private members
  100. //{{{ Instance variables
  101. private JLabel layout;
  102. private Icon layoutIcon1, layoutIcon2, layoutIcon3, layoutIcon4;
  103. private JButton alternateDockingLayout, alternateToolBarLayout;
  104. private JTable windowTable;
  105. private WindowTableModel windowModel;
  106. //}}}
  107. //{{{ createWindowTableScroller() method
  108. private JScrollPane createWindowTableScroller()
  109. {
  110. windowModel = createWindowModel();
  111. windowTable = new JTable(windowModel);
  112. windowTable.getTableHeader().setReorderingAllowed(false);
  113. windowTable.setColumnSelectionAllowed(false);
  114. windowTable.setRowSelectionAllowed(false);
  115. windowTable.setCellSelectionEnabled(false);
  116. DockPositionCellRenderer comboBox = new DockPositionCellRenderer();
  117. windowTable.setRowHeight(comboBox.getPreferredSize().height);
  118. TableColumn column = windowTable.getColumnModel().getColumn(1);
  119. column.setCellRenderer(comboBox);
  120. column.setCellEditor(new DefaultCellEditor(new DockPositionCellRenderer()));
  121. Dimension d = windowTable.getPreferredSize();
  122. d.height = Math.min(d.height,50);
  123. JScrollPane scroller = new JScrollPane(windowTable);
  124. scroller.setPreferredSize(d);
  125. return scroller;
  126. } //}}}
  127. //{{{ createWindowModel() method
  128. private WindowTableModel createWindowModel()
  129. {
  130. return new WindowTableModel();
  131. } //}}}
  132. //}}}
  133. //{{{ ActionHandler class
  134. class ActionHandler implements ActionListener
  135. {
  136. public void actionPerformed(ActionEvent evt)
  137. {
  138. if(evt.getSource() == alternateDockingLayout)
  139. {
  140. if(layout.getIcon() == layoutIcon1)
  141. layout.setIcon(layoutIcon2);
  142. else if(layout.getIcon() == layoutIcon2)
  143. layout.setIcon(layoutIcon1);
  144. else if(layout.getIcon() == layoutIcon3)
  145. layout.setIcon(layoutIcon4);
  146. else if(layout.getIcon() == layoutIcon4)
  147. layout.setIcon(layoutIcon3);
  148. }
  149. else if(evt.getSource() == alternateToolBarLayout)
  150. {
  151. if(layout.getIcon() == layoutIcon1)
  152. layout.setIcon(layoutIcon3);
  153. else if(layout.getIcon() == layoutIcon3)
  154. layout.setIcon(layoutIcon1);
  155. else if(layout.getIcon() == layoutIcon2)
  156. layout.setIcon(layoutIcon4);
  157. else if(layout.getIcon() == layoutIcon4)
  158. layout.setIcon(layoutIcon2);
  159. }
  160. }
  161. } //}}}
  162. //{{{ DockPositionCellRenderer class
  163. class DockPositionCellRenderer extends JComboBox
  164. implements TableCellRenderer
  165. {
  166. DockPositionCellRenderer()
  167. {
  168. super(new String[] {
  169. DockableWindowManager.FLOATING,
  170. DockableWindowManager.TOP,
  171. DockableWindowManager.LEFT,
  172. DockableWindowManager.BOTTOM,
  173. DockableWindowManager.RIGHT
  174. });
  175. DockPositionCellRenderer.this.setRequestFocusEnabled(false);
  176. }
  177. public Component getTableCellRendererComponent(JTable table,
  178. Object value, boolean isSelected, boolean hasFocus,
  179. int row, int column)
  180. {
  181. setSelectedItem(value);
  182. return this;
  183. }
  184. } //}}}
  185. } //}}}
  186. //{{{ WindowTableModel class
  187. class WindowTableModel extends AbstractTableModel
  188. {
  189. private Vector windows;
  190. //{{{ WindowTableModel constructor
  191. WindowTableModel()
  192. {
  193. windows = new Vector();
  194. String[] dockables = DockableWindowManager.getRegisteredDockableWindows();
  195. for(int i = 0; i < dockables.length; i++)
  196. {
  197. windows.addElement(new Entry(dockables[i]));
  198. }
  199. sort();
  200. } //}}}
  201. //{{{ sort() method
  202. public void sort()
  203. {
  204. MiscUtilities.quicksort(windows,new WindowCompare());
  205. fireTableDataChanged();
  206. } //}}}
  207. //{{{ getColumnCount() method
  208. public int getColumnCount()
  209. {
  210. return 2;
  211. } //}}}
  212. //{{{ getRowCount() method
  213. public int getRowCount()
  214. {
  215. return windows.size();
  216. } //}}}
  217. //{{{ getColumnClass() method
  218. public Class getColumnClass(int col)
  219. {
  220. switch(col)
  221. {
  222. case 0:
  223. case 1:
  224. return String.class;
  225. default:
  226. throw new InternalError();
  227. }
  228. } //}}}
  229. //{{{ getValueAt() method
  230. public Object getValueAt(int row, int col)
  231. {
  232. Entry window = (Entry)windows.elementAt(row);
  233. switch(col)
  234. {
  235. case 0:
  236. return window.title;
  237. case 1:
  238. return window.dockPosition;
  239. default:
  240. throw new InternalError();
  241. }
  242. } //}}}
  243. //{{{ isCellEditable() method
  244. public boolean isCellEditable(int row, int col)
  245. {
  246. return (col != 0);
  247. } //}}}
  248. //{{{ setValueAt() method
  249. public void setValueAt(Object value, int row, int col)
  250. {
  251. if(col == 0)
  252. return;
  253. Entry window = (Entry)windows.elementAt(row);
  254. switch(col)
  255. {
  256. case 1:
  257. window.dockPosition = (String)value;
  258. break;
  259. default:
  260. throw new InternalError();
  261. }
  262. fireTableRowsUpdated(row,row);
  263. } //}}}
  264. //{{{ getColumnName() method
  265. public String getColumnName(int index)
  266. {
  267. switch(index)
  268. {
  269. case 0:
  270. return jEdit.getProperty("options.docking.title");
  271. case 1:
  272. return jEdit.getProperty("options.docking.dockPosition");
  273. default:
  274. throw new InternalError();
  275. }
  276. } //}}}
  277. //{{{ save() method
  278. public void save()
  279. {
  280. for(int i = 0; i < windows.size(); i++)
  281. {
  282. ((Entry)windows.elementAt(i)).save();
  283. }
  284. } //}}}
  285. //{{{ Entry class
  286. class Entry
  287. {
  288. String name;
  289. String title;
  290. String dockPosition;
  291. Entry(String name)
  292. {
  293. this.name = name;
  294. title = jEdit.getProperty(name + ".title");
  295. if(title == null)
  296. title = name;
  297. dockPosition = jEdit.getProperty(name + ".dock-position");
  298. if(dockPosition == null)
  299. dockPosition = DockableWindowManager.FLOATING;
  300. }
  301. void save()
  302. {
  303. jEdit.setProperty(name + ".dock-position",dockPosition);
  304. }
  305. } //}}}
  306. //{{{ WindowCompare class
  307. class WindowCompare implements MiscUtilities.Compare
  308. {
  309. public int compare(Object obj1, Object obj2)
  310. {
  311. Entry e1 = (Entry)obj1;
  312. Entry e2 = (Entry)obj2;
  313. return MiscUtilities.compareStrings(
  314. e1.title,e2.title,true);
  315. }
  316. } //}}}
  317. } //}}}