⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 advanceddialog.java

📁 这是外国一个开源推理机
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			int selectedRow = _accessControlTable.getSelectedRow();			// Disable removeButton when no Sail has been selected (idx == -1),			// or '-anonymous-' has been selected (idx == 0).			_removeButton.setEnabled(selectedRow > 0);		}	}/*-----------------------------------+| Inner class SailStackPanel         |+-----------------------------------*/	/** Sail stack JPanel of AdvancedDialog */	protected class SailStackPanel extends JPanel		implements ActionListener, ListSelectionListener	{	/*----------------------------------+	| Variables                         |	+----------------------------------*/		protected JButton _upButton;		protected JButton _downButton;		protected JButton _addButton;		protected JButton _removeButton;	/*----------------------------------+	| Constructors                      |	+----------------------------------*/		/** Creates a new SailStackPanel */		public SailStackPanel() {			setLayout(new GridBagLayout());			Border emptyBorder = BorderFactory.createEmptyBorder(8, 8, 8, 8);			this.setBorder(emptyBorder);			// Title			JLabel title = new JLabel("Sail stack:");			GridBagUtil.constrain(this, title,				0, 0, 1, 1,				GridBagConstraints.BOTH, GridBagConstraints.CENTER, 1, 1,				0, 0, 0, 0);			// Sail stack			GridBagUtil.constrain(this, _createList(),				0, 1, 1, 1,				GridBagConstraints.BOTH, GridBagConstraints.CENTER, 1, 1,				0, 0, 0, 0);			// Up/down buttons			GridBagUtil.constrain(this, _createUpDownButtons(),				1, 1, 1, 1,				GridBagConstraints.NONE, GridBagConstraints.EAST, 0, 0,				0, 4, 0, 0);			// OK/Cancel buttons			GridBagUtil.constrain(this, _createOkCancelButtons(),				0, 2, 1, 1,				GridBagConstraints.NONE, GridBagConstraints.EAST, 1, 0,				4, 0, 0, 0);			// Parameter panel			ParameterPanel parameterPanel = new ParameterPanel();			GridBagUtil.constrain(this, parameterPanel,				0, 3, 1, 1,				GridBagConstraints.BOTH, GridBagConstraints.CENTER, 1, 1,				12, 0, 0, 0);			// Add listeners for Sail selections:			_sailTable.getSelectionModel().addListSelectionListener(this);			_sailTable.getSelectionModel().addListSelectionListener(parameterPanel);			// Enable/disable buttons			_updateButtonStatus();		}		protected JScrollPane _createList() {			JScrollPane scrollPane = new JScrollPane();			_sailTable = new SailTable(_id, _config);			JViewport viewport = scrollPane.getViewport();			viewport.add(_sailTable);			viewport.setBackground(Color.white);			scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);			// Set preferred size			Insets insets = scrollPane.getInsets();			Dimension scrollBarSize = scrollPane.getVerticalScrollBar().getPreferredSize();			Dimension tableSize = _sailTable.getPreferredSize();			int width = insets.left + scrollBarSize.width + tableSize.width + insets.right;			scrollPane.setPreferredSize(new Dimension(width, DEFAULT_HEIGHT));			return scrollPane;		}		protected JPanel _createUpDownButtons() {			// Use a GridLayout to ensure the buttons get equal sizes:			JPanel buttonPanel = new JPanel(new GridLayout(2, 1, 0, 4));			// Up button			URL upArrowImg = getClass().getResource("icons/uparrow.png");			_upButton = new JButton(new ImageIcon(upArrowImg));			_upButton.setToolTipText("Move Sail upwards in stack");			buttonPanel.add(_upButton);			_upButton.addActionListener(this);			// Down button			URL downArrowImg = getClass().getResource("icons/downarrow.png");			_downButton = new JButton(new ImageIcon(downArrowImg));			_downButton.setToolTipText("Move Sail downwards in stack");			buttonPanel.add(_downButton);			_downButton.addActionListener(this);			return buttonPanel;		}		protected JPanel _createOkCancelButtons() {			// Use a GridLayout to ensure the buttons get equal sizes:			JPanel buttonPanel = new JPanel(new GridLayout(1, 2, 4, 0));			// Add button			_addButton = new JButton("Add...");			_addButton.setToolTipText("Add new Sail to stack");			buttonPanel.add(_addButton);			_addButton.addActionListener(this);			// Remove button			_removeButton = new JButton("Remove");			_removeButton.setToolTipText("Remove Sail from stack");			buttonPanel.add(_removeButton);			_removeButton.addActionListener(this);			return buttonPanel;		}	/*-----------------------------+	| Methods                      |	+-----------------------------*/		public void actionPerformed(ActionEvent e) {			Object source = e.getSource();			if (_sailTable.stopCellEditing()) {				if (source == _upButton) {					_sailTable.sailUp();				}				else if (source == _downButton) {					_sailTable.sailDown();				}				else if(_parameterTable.stopCellEditing()) {					if (source == _addButton) {						_sailTable.addNewRow();					}					else if (source == _removeButton) {						_sailTable.removeRow();					}				}			}			if (_sailTable.isEditing()) {				_sailTable.requestFocus();			}			else if (_parameterTable.isEditing()) {				_parameterTable.requestFocus();			}		}		public void valueChanged(ListSelectionEvent e) {			_updateButtonStatus();		}		/**		 * Enables/disables buttons according to the current		 * selection in the Sail stack table.		 **/		protected void _updateButtonStatus() {			int selectedRow = _sailTable.getSelectedRow();			if (selectedRow == -1) {				// No Sail selected				_removeButton.setEnabled(false);				_upButton.setEnabled(false);				_downButton.setEnabled(false);			}			else {				_removeButton.setEnabled(true);				// Enable upButton when the selected Sail is				// not the first Sail.				_upButton.setEnabled(selectedRow > 0);				// Enable downButton when the selected Sail				// is not the last Sail.				_downButton.setEnabled(selectedRow < _sailTable.getRowCount() - 1);			}		}	/*-----------------------------------+	| Inner-inner class Parameter Panel  |	+-----------------------------------*/		/** Parameter JPanel of SailStackPanel */		protected class ParameterPanel extends JPanel			implements ActionListener, ListSelectionListener {		/*-------------------------------+		| Variables                      |		+-------------------------------*/			/** Class */			protected String _class;			protected JScrollPane _scrollPane;			/** Title */			protected JLabel _title;			protected JButton _addButton;			protected JButton _removeButton;		/*----------------------------------+		| Constructors                      |		+----------------------------------*/			/** Creates a new ParameterPanel */			public ParameterPanel() {				setLayout(new GridBagLayout());				// Title				_title = new JLabel("Parameters for selected Sail:");				GridBagUtil.constrain(this, _title,					0, 0, 1, 1,					GridBagConstraints.NONE, GridBagConstraints.WEST, 1, 0,					0, 0, 0, 0);				// Parameters				GridBagUtil.constrain(this, _createList(),					0, 1, 1, 1,					GridBagConstraints.BOTH, GridBagConstraints.CENTER, 1, 1,					4, 0, 0, 0);				// Add/Remove buttons				GridBagUtil.constrain(this, _createButtons(),					0, 2, 1, 1,					GridBagConstraints.NONE, GridBagConstraints.EAST, 1, 0,					4, 0, 0, 0);				// ParameterPanel is disabled until a Sail is selected				// in the SailStackPanel				_enableDisableComponents();			}			protected JScrollPane _createList() {				_parameterTable = new ParameterTable(_id, _config);				_scrollPane = new JScrollPane();				JViewport viewport = _scrollPane.getViewport();				viewport.add(_parameterTable);				viewport.setBackground(Color.white);				_scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);				// Set preferred size				Insets insets = _scrollPane.getInsets();				Dimension scrollBarSize = _scrollPane.getVerticalScrollBar().getPreferredSize();				Dimension tableSize = _parameterTable.getPreferredSize();				int width = insets.left + scrollBarSize.width + tableSize.width + insets.right;				_scrollPane.setPreferredSize(new Dimension(width, DEFAULT_HEIGHT));				return _scrollPane;			}			protected JPanel _createButtons() {				// Use a GridLayout to ensure the buttons get equal sizes:				JPanel buttonPanel = new JPanel(new GridLayout(1, 2, 4, 0));				// Add button				_addButton = new JButton("Add...");				_addButton.setToolTipText("Add new parameter to list");				buttonPanel.add(_addButton);				_addButton.addActionListener(this);				// Remove button				_removeButton = new JButton("Remove");				_removeButton.setToolTipText("Remove parameter from list");				buttonPanel.add(_removeButton);				_removeButton.addActionListener(this);				return buttonPanel;			}		/*-----------------------------+		| Methods                      |		+-----------------------------*/			/**			 * Enables/disables components according to which items			 * are selected.			 **/			protected void _enableDisableComponents() {				int selectedSailIdx = _sailTable.getSelectedRow();				if (selectedSailIdx == -1) {					// No Sail selected					_title.setEnabled(false);					_scrollPane.setEnabled(false);					_scrollPane.getViewport().setBackground(getBackground());					_addButton.setEnabled(false);					_removeButton.setEnabled(false);				}				else {					// Sail selected					_title.setEnabled(true);					_scrollPane.setEnabled(true);					_scrollPane.getViewport().setBackground(Color.white);					_addButton.setEnabled(true);					int selectedParamIdx = _parameterTable.getSelectedRow();					_removeButton.setEnabled(selectedParamIdx >= 0);				}			}			public void actionPerformed(ActionEvent e) {				Object source = e.getSource();				if (_sailTable.stopCellEditing() && _parameterTable.stopCellEditing()) {					if (source == _addButton) {						_parameterTable.addNewRow();					}					else if (source == _removeButton) {						_parameterTable.removeRow();					}				}				if (_sailTable.isEditing()) {					_sailTable.requestFocus();				}				else if (_parameterTable.isEditing()) {					_parameterTable.requestFocus();				}			}			public void valueChanged(ListSelectionEvent e) {				String sailClass = _sailTable.getIdentifierForSelectedRow();				_parameterTable.setSailClass(sailClass);				_enableDisableComponents();			}		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -