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

📄 operator.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

	/**
	 * Sets Operator Image for this operator.
	 * @param a_FileName file name of the image to be set.
	 * @param jarfile the plugin jar file in witch the operator is, null if this operator is not in a plugin
	 */
	public void setOperatorImage(String a_FileName,JarFile jarfile) {
		
		String imageFilePath = a_FileName;
		ImageIcon imageIcon=null;
        try {
            imageIcon = ResourceLoader.getOperatorImageIcon(imageFilePath,jarfile);
        } catch (SysException e) {
        	//TODO Auto-generated catch block
			e.printStackTrace();
        } catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		m_OperatorImage.setIcon(imageIcon);
	}

	/**
	 * Gets Operator Text of this operator.
	 * @return text of the description textarea.
	 */
	public String getLabel() {
//		return m_Label.getText();
		return m_OperatorLabel.getText();
	}

	/**
	 * Gets operator description
	 * @param a_Text
	 */
	public String getDescription()
	{
		return m_Description;
	}
	
	/**
	 * Set operator description
	 * @param a_Text
	 */
	public void setDescription(String a_Description)
	{
		m_Description = a_Description;
		setLabel(m_Description);
	}
	
	/**
	 * Sets Operator Text for this operator. This method will adjust the bounds of this operator
	 * @param a_Text the text to be set.
	 */
	public void setLabel(String a_Text) 
	{
/*		// a_Text length 
		int textlength = 0;
		
		int textAreaWidth = ICON_WIDTH;

		// multiplier for estimate the text area width needed 
		int multiplier = 5;
*/		
		if (a_Text == null)
		{
			a_Text ="";
		}

		m_OperatorLabel.setText(a_Text);
		
/*		StyledDocument doc = (StyledDocument)m_OperatorLabel.getDocument();
	    Style style = m_OperatorLabel.addStyle("TextStyle", null);
	    
//	    StyleConstants.setBold(style,true);
	    StyleConstants.setFontSize(style,9);
	    StyleConstants.setLineSpacing(style,0);
	    StyleConstants.setSpaceBelow(style,0);

	    try {
			doc.remove(0,doc.getLength());
			doc.insertString(0,a_Text,style);
		} catch (BadLocationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	*/    
		
		
		/*
		try {
			// Get the text length
			textlength = m_Label.getLineEndOffset(0);
		} catch (BadLocationException e) {
			MessageDialog.showError("Bad Text Location.","System Error");
			return;
		}
		
		// Estimate the required text area width
		if (textlength*multiplier<=TEXTAREA_WIDTH_MIN)
		{
			// Check the minimum
			m_TextAreaWidth = TEXTAREA_WIDTH_MIN;
		}else if (textlength*multiplier >= TEXTAREA_WIDTH_MAX)
		{
			// Check the Maximum
			m_TextAreaWidth = TEXTAREA_WIDTH_MAX;
		}else
		{
			// Set the width if it is within the allowed range
			m_TextAreaWidth = textlength*multiplier;
		}

		// Hard code m_TextAreaWidth to be TEXTAREA_WIDTH_MAX
		m_TextAreaWidth = TEXTAREA_WIDTH_MAX;
		
		// Estimate the reuqired text area height
		int numLines = (textlength*multiplier) / m_TextAreaWidth;
		int mod = (textlength*multiplier) % m_TextAreaWidth;
		if (mod>0)
		{
			numLines++;
		}
		m_TextAreaHeight = numLines * TEXTAREA_LINE_HEIGHT;

		// Calculate the offset between the operator bounds and image icon bounds
		int new_Icon_Offset_X = (m_TextAreaWidth - ICON_WIDTH)/2;
		if (new_Icon_Offset_X<0)
		{
			new_Icon_Offset_X = 0;
		}
		
		// Calculate the new Point of this Operator
		Point aPoint = this.getLocation();
		double newX = aPoint.getX()-(new_Icon_Offset_X-m_Icon_Offset_X);
		double newY = aPoint.getY();
		if (newX<0)
		{
			newX=0;
		}else
		{
			m_Icon_Offset_X = new_Icon_Offset_X;
		}
		Point newPoint = new Point();
		newPoint.setLocation(newX,newY);

		// Adjust the Operator
		setOperatorBounds(newPoint);
		
		// Adjust Bounds of the components
		m_ModePanel.setBounds(new Rectangle(m_Icon_Offset_X, m_Icon_Offset_Y, ICON_WIDTH, ICON_HEIGHT));
		m_OperatorImage.setBounds(new Rectangle(m_Icon_Offset_X+INTERVAL_IMAGE_MODE, m_Icon_Offset_Y+INTERVAL_IMAGE_MODE, IMAGE_HEIGHT, IMAGE_WIDTH));
		//m_Label.setBounds(new Rectangle(0, ICON_HEIGHT, m_TextAreaWidth, m_TextAreaHeight));
//		m_Description.setBorder(BorderFactory.createLineBorder(Color.BLACK));
 * */
	}

	/**
	 * Sets Operator bounds.
	 * @param a_Point the position at which this operator is to be added onto
	 * the CaseWindow.
	 */
	public void setOperatorBounds(Point a_Point) 
	{
		int xOffset = m_Icon_Offset_X;
		int yOffset = 0;
		
		int adjustedX = a_Point.x-xOffset;
		int adjustedY = a_Point.y-yOffset;
		
		// Left and Top boundary should not be negative
		if (adjustedX < 0)
		{
			adjustedX = 0;
		}
		if (adjustedY < 0)
		{
			adjustedY = 0;
		}
		
		this.setBounds(adjustedX, // Left Bounds
					   adjustedY, // Top Bounds
					   m_TextAreaWidth, // Width
					   m_TextAreaHeight+ICON_HEIGHT-ICON_TEXT_SPACE_OFFSET-INTERVAL_IMAGE_MODE // Height
					   );
	}

	/**
	 * Sets bounds for this operator.
	 * @param a_Point the position at which this operator is to be added onto
	 * the CaseWindow.
	 */
	public void setBounds(Point a_Point) {
//		this.setBounds(m_ModePanel.getBounds());
				this.setBounds((int) a_Point.getX(), (int) a_Point.getY(), m_TextAreaWidth, m_TextAreaHeight+ICON_HEIGHT);
	}

	/**
	 * Add MouseListener to this operator.
	 */
	public void addListener() {
		addMouseListener(this);
	}

	/**
	 * Remove the MouseListener of this operator.
	 */
	public void removeListener() {
		removeMouseListener(this);
	}

	/**
	 * @see java.awt.event.MouseListener#mouseClicked(MouseEvent)
	 */
	public void mouseClicked(MouseEvent e) {
/*		if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
			if (m_CaseWindow.getEditMode())
				setEdit();
		} else if (
			e.getClickCount() == 1 && e.getButton() == MouseEvent.BUTTON3) {
			if (!isEditing() && m_CaseWindow.getEditMode())
				showEditPopupMenu(e);
		} */
		//   else
		// 	getParent().dispatchEvent(e);
		// Do not dispatch the event to its parent -- m_PanelDiagramDrawing in CaseDiagramPanel,
		// since e.getX()/e.getY() is not in its parent's coordinaiotn system, will lead to
		// non-predictable results. Twang. Feb 26, 2005.
	}

	/**
	 * @see java.awt.event.MouseListener#mouseEntered(MouseEvent)
	 */
	public void mouseEntered(MouseEvent e) { 
	}
	/**
	 * @see java.awt.event.MouseListener#mouseExited(MouseEvent)
	 */
	public void mouseExited(MouseEvent e) {
	}
	/**
	 * @see java.awt.event.MouseListener#mousePressed(MouseEvent)
	 */
	public void mousePressed(MouseEvent e) {
	}
	/**
	 * @see java.awt.event.MouseListener#mouseReleased(MouseEvent)
	 */
	public void mouseReleased(MouseEvent e) {
	}

	/**
	 * @see java.awt.event.KeyListener#keyTyped(KeyEvent)
	 */
	public void keyTyped(KeyEvent e) {
		if (isEditing()) {
			if (getLabel().length() == 25)
				e.consume();
			else if (getLabel().length() > 25) {
				e.consume();
				setDescription(getLabel().substring(0, 25));
			}
		}
	}
	/**
	 * @see java.awt.event.KeyListener#keyPressed(KeyEvent)
	 */
	public void keyPressed(KeyEvent e) {
	}

	/**
	 * @see java.awt.event.KeyListener#keyReleased(KeyEvent)
	 */
	public void keyReleased(KeyEvent e) {
	}

	/**
	 * Shows an Edit right-click popup menu.
	 * @param e the MouseEvent.
	 */
	@SuppressWarnings("unused")
	private void showEditPopupMenu(MouseEvent e) {
		JPopupMenu menu = new JPopupMenu();
		JMenuItem edit = new JMenuItem("Edit");
		edit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setEdit();
			}
		});
		menu.add(edit);
		menu.addSeparator();
		menu.show(this, e.getX(), e.getY());
	}

	/**
	 * Sets description textarea to be editable.
	 */
	private void setEdit() {
		//m_Label.requestFocus();
		//m_Label.setEditable(true);
		//m_Label.setSelectionStart(m_Label.getSelectionEnd());
		//m_Label.getCaret().setVisible(true);
	}

	/**
	 * Method createOperator.
	 */
	private void createOperator() {
		m_ModePanel = new JPanel();
		m_ModePanel.setMaximumSize(new Dimension(30, 30));
		m_ModePanel.setMinimumSize(new Dimension(30, 30));
		m_ModePanel.setPreferredSize(new Dimension(30, 30));
		//m_ModePanel.setBounds(new Rectangle(0, 0, ICON_WIDTH, ICON_HEIGHT));
		m_ModePanel.setOpaque(false);

		m_OperatorImage = new JLabel();
		m_OperatorImage.setMaximumSize(new Dimension(30, 30));
		m_OperatorImage.setMinimumSize(new Dimension(30, 30));
		m_OperatorImage.setPreferredSize(new Dimension(30, 30));
		m_OperatorImage.setBounds(new Rectangle(20, 2, 30, 30));

		// << 21/07/2005 Kenneth Lai: Add for JHelp
		m_TransparentHelpButton = new JButton();
		m_TransparentHelpButton.setMaximumSize(new Dimension(30, 30));
		m_TransparentHelpButton.setMinimumSize(new Dimension(30, 30));
		m_TransparentHelpButton.setPreferredSize(new Dimension(30, 30));
	    m_TransparentHelpButton.setBorder(null);
	    m_TransparentHelpButton.setContentAreaFilled(false);
	    m_TransparentHelpButton.setFocusPainted(false);
		m_TransparentHelpButton.setEnabled(false); // default
		m_TransparentHelpButton.setOpaque(false);
		
		try
		{
		// <<17/08/2005: Kenneth Lai: Modified for helpHandler singleton
		AlphaminerHelpHandler HelpHandler = AlphaminerHelpHandler.getInstance();
//		   	new AlphaminerHelpHandler();
		// 17/08/2005: Kenneth Lai: Modified for helpHandler singleton>>
		HelpHandler.setHelpButton(m_TransparentHelpButton, getOperatorDefinitionID());
		}catch (Exception helpE)
		{
		    m_SystemMessageHandler.appendMessage("Cannot initiate on-help files.");
		}
		
		m_TransparentHelpButton.addActionListener(new ActionListener() {
		    public void actionPerformed(ActionEvent e) {
				setHelpMode(false);
				HelpObserveSubject.sendNotify(m_HelpState);
		    }
		});
		// 21/07/2005 Kenneth Lai: Add for JHelp>>
		
		/*
		m_Label = new JTextArea();
		m_Label.setBackground(Color.lightGray);
		m_Label.setFont(new java.awt.Font("Dialog", 0, 9));
		m_Label.setAlignmentX((float) 0.0);
		m_Label.setAlignmentY((float) 0.0);
		m_Label.setLineWrap(true);
		m_Label.setBorder(null);
		m_Label.setEditable(false);
		m_Label.setOpaque(false);
		m_Label.setWrapStyleWord(true);
		*/
		m_OperatorLabel = new JTextPane();
		m_OperatorLabel.setEditable(false);
		m_OperatorLabel.setOpaque(false);
		m_OperatorLabel.setFocusable(false);

		m_DropEventPanel = new JPanel();
		m_DropEventPanel.setOpaque(false);

		// Remove listeners so that the textpane would not block icon of other operators
		MouseListener[] mouseListeners = m_OperatorLabel.getMouseListeners();
		for (int i=0;i<mouseListeners.length;i++)
		{
			m_OperatorLabel.removeMouseListener(mouseListeners[i]);
		}
		MouseMotionListener[] mouseMotionListeners = m_OperatorLabel.getMouseMotionListeners();
		for (int i=0;i<mouseMotionListeners.length;i++)
		{
			m_OperatorLabel.removeMouseMotionListener(mouseMotionListeners[i]);
		}
/*		MouseWheelListener[] mouseWheelListeners = m_OperatorLabel.getMouseWheelListeners();
		for (int i=0;i<mouseWheelListeners.length;i++)
		{
			m_OperatorLabel.removeMouseWheelListener(mouseWheelListeners[i]);
		}*/
		FocusListener[] focusListeners = m_OperatorLabel.getFocusListeners();
		for (int i=0;i<focusListeners.length;i++)
		{
			m_OperatorLabel.removeFocusListener(focusListeners[i]);
		}
		

		InputMethodListener[] inputMethodListeners = m_OperatorLabel.getInputMethodListeners();
		for (int i=0;i<inputMethodListeners.length;i++)
		{
			m_OperatorLabel.removeInputMethodListener(inputMethodListeners[i]);
		}
		
		Style style = m_OperatorLabel.addStyle("ParagraphStyle", null);
	    
	    StyleConstants.setFontSize(style,FONT_SIZE);
	    StyleConstants.setAlignment(style, StyleConstants.ALIGN_CENTER);
	    StyleConstants.setFontFamily(style,FONT_FAMILY);
	    m_OperatorLabel.setParagraphAttributes(style,true);
	    
		// Set Bounds of each component
		m_ModePanel.setBounds(new Rectangle(m_Icon_Offset_X-INTERVAL_IMAGE_MODE, -INTERVAL_IMAGE_MODE, ICON_WIDTH, ICON_HEIGHT));
		m_OperatorImage.setBounds(new Rectangle(m_Icon_Offset_X+2, 2, IMAGE_HEIGHT, IMAGE_WIDTH));

⌨️ 快捷键说明

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