Browse Source

复用代码

master
yaoh.wu 7 years ago
parent
commit
c2de996fe1
  1. 16
      designer-base/src/main/java/com/fr/design/remote/ui/list/AddedMemberList.java
  2. 15
      designer-base/src/main/java/com/fr/design/remote/ui/list/AddingMemberList.java
  3. 19
      designer-base/src/main/java/com/fr/design/remote/ui/list/MemberList.java

16
designer-base/src/main/java/com/fr/design/remote/ui/list/AddedMemberList.java

@ -3,8 +3,6 @@ package com.fr.design.remote.ui.list;
import com.fr.workspace.server.authority.RemoteDesignMember;
import javax.swing.DefaultListModel;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.util.Vector;
public class AddedMemberList extends MemberList {
@ -25,20 +23,6 @@ public class AddedMemberList extends MemberList {
super(listData);
}
@Override
protected boolean shouldDisplaySelected(MouseEvent e) {
Point point = e.getPoint();
int rX = point.x;
int rY = point.y;
int index = this.getSelectedIndex();
int x = 270;
int y = 25 * index;
int width = 20;
int height = 25;
return x <= rX && rX <= x + width && y <= rY && rY <= y + height;
}
@Override
protected void displaySelected() {
RemoteDesignMember member = getSelectedValue();

15
designer-base/src/main/java/com/fr/design/remote/ui/list/AddingMemberList.java

@ -3,8 +3,6 @@ package com.fr.design.remote.ui.list;
import com.fr.workspace.server.authority.RemoteDesignMember;
import javax.swing.DefaultListModel;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.util.Vector;
public class AddingMemberList extends MemberList {
@ -36,19 +34,6 @@ public class AddingMemberList extends MemberList {
repaint();
fireSelectedChange();
}
@Override
protected boolean shouldDisplaySelected(MouseEvent e) {
Point point = e.getPoint();
int rX = point.x;
int rY = point.y;
int index = this.getSelectedIndex();
int x = 270;
int y = 25 * index;
int width = 25;
int height = 25;
return x <= rX && rX <= x + width && y <= rY && rY <= y + height;
}
}

19
designer-base/src/main/java/com/fr/design/remote/ui/list/MemberList.java

@ -7,6 +7,7 @@ import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.ListSelectionModel;
import java.awt.Color;
import java.awt.Point;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
@ -14,6 +15,12 @@ import java.awt.event.MouseEvent;
import java.util.Vector;
public abstract class MemberList extends JList<RemoteDesignMember> {
static final int TRIGGER_AREA_X = 270;
static final int TRIGGER_AREA_Y_EACH = 25;
static final int TRIGGER_AREA_WIDTH = 25;
static final int TRIGGER_AREA_HEIGHT = 25;
public MemberList(DefaultListModel<RemoteDesignMember> dataModel) {
super(dataModel);
@ -79,7 +86,13 @@ public abstract class MemberList extends JList<RemoteDesignMember> {
abstract protected void displaySelected();
abstract protected boolean shouldDisplaySelected(MouseEvent e);
protected boolean shouldDisplaySelected(MouseEvent e) {
Point point = e.getPoint();
int rX = point.x;
int rY = point.y;
int index = this.getSelectedIndex();
int x = TRIGGER_AREA_X;
int y = TRIGGER_AREA_Y_EACH * index;
return x <= rX && rX <= x + TRIGGER_AREA_WIDTH && y <= rY && rY <= y + TRIGGER_AREA_HEIGHT;
}
}

Loading…
Cancel
Save