📄 dockingoptionpane.java
字号:
/* * DockingOptionPane.java - Dockable window options panel * :tabSize=8:indentSize=8:noTabs=false: * :folding=explicit:collapseFolds=1: * * Copyright (C) 2000, 2001, 2002 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;//{{{ Importsimport javax.swing.table.*;import javax.swing.*;import java.awt.event.*;import java.awt.*;import java.util.Vector;import org.gjt.sp.jedit.gui.*;import org.gjt.sp.jedit.*;//}}}//{{{ DockingOptionPane classpublic class DockingOptionPane extends AbstractOptionPane{ //{{{ DockingOptionPane constructor public DockingOptionPane() { super("docking"); } //}}} //{{{ _init() method public void _init() { addSeparator("options.docking.viewLayout"); layoutIcon1 = GUIUtilities.loadIcon("dock_layout1.png"); layoutIcon2 = GUIUtilities.loadIcon("dock_layout2.png"); layoutIcon3 = GUIUtilities.loadIcon("dock_layout3.png"); layoutIcon4 = GUIUtilities.loadIcon("dock_layout4.png"); JPanel layoutPanel = new JPanel(new VariableGridLayout( VariableGridLayout.FIXED_NUM_COLUMNS,1, 6,6)); if(jEdit.getBooleanProperty("view.docking.alternateLayout")) { layout = new JLabel(jEdit.getBooleanProperty( "view.toolbar.alternateLayout") ? layoutIcon4 : layoutIcon2); } else { layout = new JLabel(jEdit.getBooleanProperty( "view.toolbar.alternateLayout") ? layoutIcon3 : layoutIcon1); } layoutPanel.add(layout); layoutPanel.add(alternateDockingLayout = new JButton(jEdit.getProperty( "options.docking.alternateDockingLayout"))); alternateDockingLayout.addActionListener(new ActionHandler()); layoutPanel.add(alternateToolBarLayout = new JButton(jEdit.getProperty( "options.docking.alternateToolBarLayout"))); alternateToolBarLayout.addActionListener(new ActionHandler()); // center the layout panel GridBagConstraints cons = new GridBagConstraints(); cons.gridy = y++; cons.gridwidth = GridBagConstraints.REMAINDER; cons.fill = GridBagConstraints.BOTH; cons.weightx = 1.0f; gridBag.setConstraints(layoutPanel,cons); add(layoutPanel); addSeparator("options.docking.windowDocking"); cons = new GridBagConstraints(); cons.gridy = y++; 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); } //}}} //{{{ _save() method public void _save() { jEdit.setBooleanProperty("view.docking.alternateLayout", layout.getIcon() == layoutIcon2 || layout.getIcon() == layoutIcon4); jEdit.setBooleanProperty("view.toolbar.alternateLayout", layout.getIcon() == layoutIcon3 || layout.getIcon() == layoutIcon4); windowModel.save(); } //}}} //{{{ Private members //{{{ Instance variables private JLabel layout; private Icon layoutIcon1, layoutIcon2, layoutIcon3, layoutIcon4; private JButton alternateDockingLayout, alternateToolBarLayout; private JTable windowTable; private WindowTableModel windowModel; //}}} //{{{ createWindowTableScroller() method 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(); windowTable.setRowHeight(comboBox.getPreferredSize().height); TableColumn column = windowTable.getColumnModel().getColumn(1); column.setCellRenderer(comboBox); column.setCellEditor(new DefaultCellEditor(new DockPositionCellRenderer())); Dimension d = windowTable.getPreferredSize(); d.height = Math.min(d.height,50); JScrollPane scroller = new JScrollPane(windowTable); scroller.setPreferredSize(d); return scroller; } //}}} //{{{ createWindowModel() method private WindowTableModel createWindowModel() { return new WindowTableModel(); } //}}} //}}} //{{{ ActionHandler class class ActionHandler implements ActionListener { public void actionPerformed(ActionEvent evt) { if(evt.getSource() == alternateDockingLayout) { if(layout.getIcon() == layoutIcon1) layout.setIcon(layoutIcon2); else if(layout.getIcon() == layoutIcon2) layout.setIcon(layoutIcon1); else if(layout.getIcon() == layoutIcon3) layout.setIcon(layoutIcon4); else if(layout.getIcon() == layoutIcon4) layout.setIcon(layoutIcon3); } else if(evt.getSource() == alternateToolBarLayout) { if(layout.getIcon() == layoutIcon1) layout.setIcon(layoutIcon3); else if(layout.getIcon() == layoutIcon3) layout.setIcon(layoutIcon1); else if(layout.getIcon() == layoutIcon2) layout.setIcon(layoutIcon4); else if(layout.getIcon() == layoutIcon4) layout.setIcon(layoutIcon2); } } } //}}} //{{{ DockPositionCellRenderer class class DockPositionCellRenderer extends JComboBox implements TableCellRenderer { DockPositionCellRenderer() { super(new String[] { DockableWindowManager.FLOATING, DockableWindowManager.TOP, DockableWindowManager.LEFT, DockableWindowManager.BOTTOM, DockableWindowManager.RIGHT }); DockPositionCellRenderer.this.setRequestFocusEnabled(false); } public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { setSelectedItem(value); return this; } } //}}}} //}}}//{{{ WindowTableModel classclass WindowTableModel extends AbstractTableModel{ private Vector windows; //{{{ WindowTableModel constructor WindowTableModel() { windows = new Vector(); String[] dockables = DockableWindowManager.getRegisteredDockableWindows(); for(int i = 0; i < dockables.length; i++) { windows.addElement(new Entry(dockables[i])); } sort(); } //}}} //{{{ sort() method public void sort() { MiscUtilities.quicksort(windows,new WindowCompare()); fireTableDataChanged(); } //}}} //{{{ getColumnCount() method public int getColumnCount() { return 2; } //}}} //{{{ getRowCount() method public int getRowCount() { return windows.size(); } //}}} //{{{ getColumnClass() method public Class getColumnClass(int col) { switch(col) { case 0: case 1: return String.class; default: throw new InternalError(); } } //}}} //{{{ getValueAt() method 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(); } } //}}} //{{{ isCellEditable() method public boolean isCellEditable(int row, int col) { return (col != 0); } //}}} //{{{ setValueAt() method 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); } //}}} //{{{ getColumnName() method 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(); } } //}}} //{{{ save() method public void save() { for(int i = 0; i < windows.size(); i++) { ((Entry)windows.elementAt(i)).save(); } } //}}} //{{{ Entry class 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); } } //}}} //{{{ WindowCompare class 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); } } //}}}} //}}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -