/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
- /*
- * DockingOptionPane.java - Dockable window options panel
- * Copyright (C) 2000, 2001 Slava Pestov
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- package org.gjt.sp.jedit.options;
- import javax.swing.table.*;
- import javax.swing.*;
- import java.awt.*;
- import java.util.Vector;
- import org.gjt.sp.jedit.gui.*;
- import org.gjt.sp.jedit.*;
- public class DockingOptionPane extends AbstractOptionPane
- {
- public DockingOptionPane()
- {
- super("docking");
- }
- public void _init()
- {
- Box box = new Box(BoxLayout.X_AXIS);
- ButtonGroup grp = new ButtonGroup();
- layout1 = new JToggleButton(GUIUtilities.loadIcon("dock_layout1.gif"));
- grp.add(layout1);
- box.add(layout1);
- box.add(Box.createHorizontalStrut(6));
- layout2 = new JToggleButton(GUIUtilities.loadIcon("dock_layout2.gif"));
- grp.add(layout2);
- box.add(layout2);
- if(jEdit.getBooleanProperty("view.docking.alternateLayout"))
- layout2.setSelected(true);
- else
- layout1.setSelected(true);
- addComponent(jEdit.getProperty("options.docking.layout"),box);
- // reuse properties defined by the general option pane
- String[] positions = {
- jEdit.getProperty("options.docking.top"),
- jEdit.getProperty("options.docking.bottom"),
- };
- tabsPos = new JComboBox(positions);
- tabsPos.setSelectedIndex(jEdit.getIntegerProperty(
- "view.docking.tabsPos",0));
- addComponent(jEdit.getProperty("options.docking.tabsPos"),tabsPos);
- addComponent(Box.createVerticalStrut(6));
- GridBagConstraints cons = new GridBagConstraints();
- cons.gridy = 3;
- cons.gridwidth = cons.gridheight = GridBagConstraints.REMAINDER;
- cons.fill = GridBagConstraints.BOTH;
- cons.weightx = cons.weighty = 1.0f;
- JScrollPane windowScroller = createWindowTableScroller();
- gridBag.setConstraints(windowScroller,cons);
- add(windowScroller);
- }
- public void _save()
- {
- jEdit.setBooleanProperty("view.docking.alternateLayout",
- layout2.isSelected());
- jEdit.setIntegerProperty("view.docking.tabsPos",
- tabsPos.getSelectedIndex());
- windowModel.save();
- }
- // private members
- private JToggleButton layout1;
- private JToggleButton layout2;
- private JComboBox tabsPos;
- private JTable windowTable;
- private WindowTableModel windowModel;
- private JScrollPane createWindowTableScroller()
- {
- windowModel = createWindowModel();
- windowTable = new JTable(windowModel);
- windowTable.getTableHeader().setReorderingAllowed(false);
- windowTable.setColumnSelectionAllowed(false);
- windowTable.setRowSelectionAllowed(false);
- windowTable.setCellSelectionEnabled(false);
- DockPositionCellRenderer comboBox = new DockPositionCellRenderer();
- comboBox.setRequestFocusEnabled(false);
- windowTable.setRowHeight(comboBox.getPreferredSize().height);
- TableColumn column = windowTable.getColumnModel().getColumn(1);
- column.setCellRenderer(comboBox);
- comboBox = new DockPositionCellRenderer();
- comboBox.setRequestFocusEnabled(false);
- column.setCellEditor(new DefaultCellEditor(comboBox));
- Dimension d = windowTable.getPreferredSize();
- d.height = Math.min(d.height,200);
- JScrollPane scroller = new JScrollPane(windowTable);
- scroller.setPreferredSize(d);
- return scroller;
- }
- private WindowTableModel createWindowModel()
- {
- return new WindowTableModel();
- }
- class DockPositionCellRenderer extends JComboBox
- implements TableCellRenderer
- {
- DockPositionCellRenderer()
- {
- super(new String[] {
- DockableWindowManager.FLOATING,
- DockableWindowManager.TOP,
- DockableWindowManager.LEFT,
- DockableWindowManager.BOTTOM,
- DockableWindowManager.RIGHT
- });
- }
- public Component getTableCellRendererComponent(JTable table,
- Object value, boolean isSelected, boolean hasFocus,
- int row, int column)
- {
- setSelectedItem(value);
- return this;
- }
- }
- }
- class WindowTableModel extends AbstractTableModel
- {
- private Vector windows;
- WindowTableModel()
- {
- windows = new Vector();
- // old dockable window API compatibility code
- Object[] list = EditBus.getNamedList(DockableWindow.DOCKABLE_WINDOW_LIST);
- if(list != null)
- {
- for(int i = 0; i < list.length; i++)
- {
- windows.addElement(new Entry((String)list[i]));
- }
- }
- // end compatibility code
- String[] dockables = DockableWindowManager.getRegisteredDockableWindows();
- for(int i = 0; i < dockables.length; i++)
- {
- windows.addElement(new Entry(dockables[i]));
- }
- sort();
- }
- public void sort()
- {
- MiscUtilities.quicksort(windows,new WindowCompare());
- fireTableDataChanged();
- }
- public int getColumnCount()
- {
- return 2;
- }
- public int getRowCount()
- {
- return windows.size();
- }
- public Class getColumnClass(int col)
- {
- switch(col)
- {
- case 0:
- case 1:
- return String.class;
- default:
- throw new InternalError();
- }
- }
- public Object getValueAt(int row, int col)
- {
- Entry window = (Entry)windows.elementAt(row);
- switch(col)
- {
- case 0:
- return window.title;
- case 1:
- return window.dockPosition;
- default:
- throw new InternalError();
- }
- }
- public boolean isCellEditable(int row, int col)
- {
- return (col != 0);
- }
- public void setValueAt(Object value, int row, int col)
- {
- if(col == 0)
- return;
- Entry window = (Entry)windows.elementAt(row);
- switch(col)
- {
- case 1:
- window.dockPosition = (String)value;
- break;
- default:
- throw new InternalError();
- }
- fireTableRowsUpdated(row,row);
- }
- public String getColumnName(int index)
- {
- switch(index)
- {
- case 0:
- return jEdit.getProperty("options.docking.title");
- case 1:
- return jEdit.getProperty("options.docking.dockPosition");
- default:
- throw new InternalError();
- }
- }
- public void save()
- {
- for(int i = 0; i < windows.size(); i++)
- {
- ((Entry)windows.elementAt(i)).save();
- }
- }
- class Entry
- {
- String name;
- String title;
- String dockPosition;
- Entry(String name)
- {
- this.name = name;
- title = jEdit.getProperty(name + ".title");
- if(title == null)
- title = name;
- dockPosition = jEdit.getProperty(name + ".dock-position");
- if(dockPosition == null)
- dockPosition = DockableWindowManager.FLOATING;
- }
- void save()
- {
- jEdit.setProperty(name + ".dock-position",dockPosition);
- }
- }
- class WindowCompare implements MiscUtilities.Compare
- {
- public int compare(Object obj1, Object obj2)
- {
- Entry e1 = (Entry)obj1;
- Entry e2 = (Entry)obj2;
- return MiscUtilities.compareStrings(
- e1.title,e2.title,true);
- }
- }
- }