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

📄 dsdesktopassociateevect.java

📁 用JAVA编写的绘图程序 功能简介: 支持存储
💻 JAVA
字号:
package drawsmart.itsv.swing;

import drawsmart.itsv.tool.DSMouseEvent;
import java.awt.Cursor;
import drawsmart.itsv.framework.*;
import javax.swing.ImageIcon;
import java.awt.event.MouseEvent;
import java.awt.*;

/**
 * <p>Title: 连接器绘制类</p>
 * <p>Description: 用于画线</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author 崔江
 * @version 2.0
 */

public class DSDesktopAssociateEvect
    extends DSMouseEvent {

  private JDSLineface jDSLineface;

  private JDSLineface jDSLinefaceClone;

  //
  private Point starPoint;

  //
  private JDSComponentface source;

  /**
   * 构造器
   * @param desk 桌面接口
   * @param imageIcon 图标
   */
  public DSDesktopAssociateEvect(JDSDesktopface desk,JDSLineface c, ImageIcon imageIcon) {
    super(desk);
    //设置图标
    setImageIcon(imageIcon);

    //初始化接口
    jDSLineface=c;
  }

  /**
   * 返回鼠标样式
   * @return
   */
  public Cursor getCursor() {
    return new Cursor(Cursor.CROSSHAIR_CURSOR);
  }

  /**
   * 鼠标压下事件
   * @param e
   */
  public void mousePressed(MouseEvent e) {
    starPoint = e.getPoint();
    //******************************************//
    //设置起点和终点
    JDSComponentface jDSComponentface = getJDSDesktopface().getJDSComponent(e.
        getPoint());
    if (jDSComponentface != null) {
      if (source == null) {
        jDSLinefaceClone = (JDSLineface) jDSLineface.cloneComponent();
        if (jDSLinefaceClone instanceof DSExtendLineAspect) {
          //添加到桌面
          getJDSDesktopface().addJDSLineface(jDSLinefaceClone);
        }
        source = jDSComponentface;
        int x = source.getComponentX() + (source.getComponentWidth() / 2);
        int y = source.getComponentY() + (source.getComponentHeight() / 2);
        starPoint = new Point(x, y);
      }
    }

  }

  /**
   * 鼠标拖拽事件
   * @param e
   */
  public void mouseDragged(MouseEvent e) {
    if (jDSLinefaceClone != null) {
      if (starPoint != null) {
        //设置矩形的大小
        if (jDSLinefaceClone instanceof DSExtendLineAspect) {
          ( (DSExtendLineAspect) jDSLinefaceClone).setLine(starPoint, e.getPoint());
        }

        //刷新桌面
        getJDSDesktopface().repaint();

        //
      }
    }
  }

  /**
   * 鼠标弹起事件
   * @param e
   */
  public void mouseReleased(MouseEvent e) {
    JDSComponentface jDSComponentface = getJDSDesktopface().getJDSComponent(e.
        getPoint());
    if (jDSComponentface!=null && source!=jDSComponentface && source!=null)
    {
      //获得圆心
      int x = jDSComponentface.getComponentX() + (jDSComponentface.getComponentWidth() / 2);
      int y = jDSComponentface.getComponentY() + (jDSComponentface.getComponentHeight() / 2);
      Point p=new Point(x,y);

      //添加连接源
      jDSLinefaceClone.setJDSComponentStart(source);

      //添加截止源
      jDSLinefaceClone.setJDSComponentEnd(jDSComponentface);

      //刷新直线
      ( (DSExtendLineAspect) jDSLinefaceClone).setLine(starPoint, p);

      //下面的删除、添加为了过滤掉重复的直线
      getJDSDesktopface().removeSelectionJDSLine(jDSLinefaceClone);

      getJDSDesktopface().addJDSLineface(jDSLinefaceClone);

      //在组件中添加该组件的连接线
      jDSComponentface.addAssociator(jDSLinefaceClone);
      source.addAssociator(jDSLinefaceClone);

    }
    else
    {
      getJDSDesktopface().removeSelectionJDSLine(jDSLinefaceClone);
    }
    //刷新桌面
    getJDSDesktopface().repaint();
    jDSLinefaceClone = null;
    source=null;
  }

}

⌨️ 快捷键说明

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