ListSelectionModel의 자체 구현을 작성하려고하는데 현재는 insertIndexInterval
을 구현하는 동안 멈추었습니다. 나는 Sun/Oracle의 DefautListSelectionModel
구현에서이 방법의 결과를 이해하지 못한다. 이 코드를 실행하면이 출력을 얻을 것이다ListSelectionModel.insertIndexInterval()은 정확히 무엇입니까?
ListSelectionModel model = new DefaultListSelectionModel();
model.setSelectionInterval(3, 5);
model.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
System.out.println("Changed range reported by event: " +
e.getFirstIndex() + "-" + e.getLastIndex());
}
});
System.out.print("Selected indices before insert: ");
for (int i = model.getMinSelectionIndex(); i <= model.getMaxSelectionIndex(); i++)
if (model.isSelectedIndex(i)) System.out.print(i + " ");
System.out.println();
model.insertIndexInterval(3, 3, true);
System.out.print("Selected indices after insert: ");
for (int i = model.getMinSelectionIndex(); i <= model.getMaxSelectionIndex(); i++)
if (model.isSelectedIndex(i)) System.out.print(i + " ");
System.out.println();
: 예를 들면 다음과 같습니다
Selected indices before insert: 3 4 5
Changed range reported by event: 3-8
Selected indices after insert: 3 4 5 6 7 8
그래서 초기 선택은 3-5이고 새로운 인덱스를 삽입 할 때 그것은 3-8로 확대되었다 . 그러나 3-5가 이미 선택되었으므로 실제 변경 사항은 6-8에 불과하므로 이벤트 3-8 범위가 변경되었다고 말하는 이유는 무엇입니까?
model.insertIndexInterval(3, 3, false);
지금 출력은 이것이다 :
Selected indices before insert: 3 4 5
Changed range reported by event: 5-8
Selected indices after insert: 3 4 5 6 7 8
내가보고 변화가 5-8 왜 아무 생각이에 insertIndexInterval
전화를 변경할 때 더욱 혼란 스럽다.
이 메소드의 API 문서는 너무 짧아서 현재 진행중인 작업을 이해할 수 없습니다. 특히이 before
매개 변수는 선택에 아무런 영향을 미치지 않으므로 미스터리이지만 이벤트 및 리드 및 앵커 인덱스에 영향을 미치는 것으로 보입니다.
단순히 예상 결과를 모르기 때문에 구현에 대한 단위 테스트를 작성할 수 없습니다.
누군가가이 방법 (특히 before
플래그)을 수행하고 있으며 선택 모델 및 ListSelectionEvent
에 어떤 부작용이 있는지 자세히 설명 할 수 있습니까?
예, 0은 실제로 존재하지 않습니다. 그렇게 쉽게 비교할 수 있습니다. 그러나 나는 아직도 그것을 얻지 못한다. 이벤트는 데이터 모델이 아닌 선택 모델에 바인딩됩니다. 인덱스 3-5는 새로운 데이터를 삽입하기 전에 이미 선택되었으므로 (데이터 모델이 아닌 선택 모델에 대한) 유일한 실제 변경 사항은 6-8의 추가 선택 범위입니다. 그러나보고 된 변경 사항은 3-8 (이전 = true) 및 5-8 (이전 = false)입니다. 특히이 5-8은 지금까지 의미가 없습니다. – kayahr
예, 3-8을 설명합니다 (1이 이동되었고 2가 추가 되었기 때문에)하지만 before = false를 사용할 때보고 된 5-8 범위를 어떻게 설명합니까? 3 상태로 시각화하면 세 개의 1은 이동하지 않고 세 개의 2는 5가 아닌 6의 인덱스에 삽입됩니다. – kayahr
BTW : 인덱스 3 이후에 삽입 할 때 0001222110이어야하고 0001112220이 아닌가요? 문서에 "길이 인덱스 시작 전/후에 인덱스 삽입"이 나와 있습니다. – kayahr