📄 advanceoperatorpanel.java
字号:
/*
* 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
* (at your option) 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Created on 2004-12-9
*
* $Author$
* $Date$
* $Revision$
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package eti.bi.alphaminer.tools.SystemTools.OperatorToolPage;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import eti.bi.alphaminer.tools.SystemTools.SystemToolPanel;
import eti.bi.alphaminer.ui.StencilPanel;
import eti.bi.alphaminer.core.Node.NodeLoader;
import eti.bi.alphaminer.core.Node.Stencil;
import eti.bi.common.Locale.Resource;
import eti.bi.exception.SysException;
/**
* AdvanceOperatorPanel is an OperatorPanel showing different ETI operators for user to
* use.
*/
public class AdvanceOperatorPanel
extends SystemToolPanel implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
private Vector<Stencil> m_Stencils = new Vector<Stencil>();
private Vector<JButton> m_StencilButtons = new Vector<JButton>();
private Vector<StencilPanel> m_StencilPanels = new Vector<StencilPanel>();
private JPanel m_BasePanel;
private Font m_FontButton;
private Color m_FontColor;
private Color m_ButtonColor;
/**
* Constructs a AdvanceOperatorPanel.
* @throws SysException
*/
public AdvanceOperatorPanel(Vector<Stencil> aStencils) throws SysException {
super(Resource.srcStr("Operatorset"));
m_Stencils = aStencils;
createOperatorPanel();
}
/**
* @throws SysException
* @see eti.bi.alphaminer.ui.OperatorPanel#createOperatorPanel()
*/
public void createOperatorPanel() throws SysException {
m_FontButton = new Font("SansSerif", 0, 13);
m_FontColor = new Color(31,114,90);
m_ButtonColor = new Color(177,201,238);
m_BasePanel = new JPanel(new GridBagLayout());
for (int i=0;i<m_Stencils.size();i++)
{
Stencil aStencil = m_Stencils.elementAt(i);
JButton aButton = new JButton(aStencil.getDisplayName());
addStencilButton(aButton);
StencilPanel aStencilPanel = new StencilPanel(aStencil);
addStencilPanel(aStencilPanel);
}
// Select the first Stencil by default
//
if (m_Stencils.size()>0)
{
selectStencilPanel(0);
}
//this.setPreferredSize(new Dimension(180, 300));
this.setLayout(new BorderLayout());
this.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
this.add(m_BasePanel, BorderLayout.CENTER, 0);
}
@SuppressWarnings("unchecked")
private void addStencilButton(JButton aButton)
{
m_StencilButtons.add(aButton);
GridBagConstraints buttonConstraints = new GridBagConstraints();
buttonConstraints.gridx = 0;
buttonConstraints.gridy = m_StencilButtons.size()*2;
buttonConstraints.insets = new Insets(0, 0, 0, 0);
buttonConstraints.fill = GridBagConstraints.HORIZONTAL;
buttonConstraints.anchor = GridBagConstraints.LINE_START;
buttonConstraints.weightx = 1.0;
buttonConstraints.weighty = 0.0;
setButtonPropertiesAndAddListener(aButton);
m_BasePanel.add(aButton, buttonConstraints);
}
@SuppressWarnings("unchecked")
private void addStencilPanel(StencilPanel aPanel)
{
m_StencilPanels.add(aPanel);
GridBagConstraints panelConstraints = new GridBagConstraints();
panelConstraints.gridx = 0;
panelConstraints.gridy = ((m_StencilPanels.size()+1)*2)-1;
panelConstraints.insets = new Insets(0, 0, 0, 0);
panelConstraints.fill = GridBagConstraints.BOTH;
panelConstraints.anchor = GridBagConstraints.LINE_START;
panelConstraints.weightx = 1.0;
panelConstraints.weighty = 1.0;
m_BasePanel.add(aPanel, panelConstraints);
}
/**
* @see eti.bi.alphaminer.tools.SystemTools.ISystemToolPanel#addToolMouseListener(MouseListener)
* */
public void addToolMouseListener(MouseListener l) {
m_BasePanel.addMouseListener(l);
for(int i=0;i<m_StencilPanels.size();i++){
m_StencilPanels.get(i).addStencilPanelMouseListener(l);
}
}
/**
* @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
// Search for the triggered button
for (int i=0;i<m_StencilButtons.size();i++)
{
if (source == m_StencilButtons.elementAt(i))
{
selectStencilPanel(i);
}
}
}
/**
* Select the stencil panel
*/
private void selectStencilPanel(int aSelectedIndex)
{
for (int j=0;j<m_StencilPanels.size();j++)
{
StencilPanel stencilPanel = m_StencilPanels.elementAt(j);
// Open the selected panel
if (j==aSelectedIndex)
{
stencilPanel.setVisible(true);
}else
{
// Close all other panels
stencilPanel.setVisible(false);
}
}
}
/**
* Sets properties of a specific button and add ActionListener to it.
* @param a_Button the specific button.
*/
private void setButtonPropertiesAndAddListener(JButton a_Button) {
a_Button.setFont(m_FontButton);
a_Button.setForeground(m_FontColor);
a_Button.setBackground(m_ButtonColor);
a_Button.setRequestFocusEnabled(false);
a_Button.setFocusPainted(false);
a_Button.setFocusable(false);
a_Button.setHorizontalAlignment(SwingConstants.LEFT);
a_Button.setMargin(new Insets(3, 5, 3, 5));
a_Button.addActionListener(this);
}
public JComponent getTopComponentAt(Point point) {
int size = m_StencilPanels.size();
StencilPanel aPanel;
for(int i=0;i<size;i++) {
aPanel = m_StencilPanels.get(i);
if(aPanel.getBounds().contains(point)) {
return aPanel.getTopComponentAt(point);
}
}
return null;
}
//03/17/2006 Xiaojun Chen Add for
/**
* reset language
*/
public synchronized void resetLocale(Vector<Stencil> aStencils) throws SysException{
Stencil oldstencil = null;
Stencil newstencil = null;
JButton aButton = null;
StencilPanel aStencilPanel = null;
this.setName(Resource.srcStr("Operatorset"));
for(int i=0;i<aStencils.size();i++){
newstencil = aStencils.get(i);
for(int j=0;j<m_Stencils.size();j++){
oldstencil = m_Stencils.get(j);
if(newstencil.getName().equals(oldstencil.getName())){
m_Stencils.remove(j);
m_Stencils.add(j,newstencil);
aButton = m_StencilButtons.get(j);
aButton.setText(newstencil.getDisplayName());
aStencilPanel = m_StencilPanels.get(j);
aStencilPanel.resetLanguage(newstencil);
}
}
}
}
public void resetLocale() {
Vector<Stencil> aStencils = NodeLoader.getStencils();
try {
resetLocale(aStencils);
} catch (SysException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void dispose() {
m_Stencils.removeAllElements();
m_StencilButtons.removeAllElements();
m_StencilPanels.removeAllElements();
m_Stencils = null;
m_StencilButtons = null;
m_StencilPanels = null;
m_BasePanel.removeAll();
m_BasePanel = null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -