package so;
import java.text.*;
import java.util.*;
import java.util.ArrayList;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import util.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.XYConstraints;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author By SamZheng
* @version 1.0
*/
public class PMMShipingSpace
extends JFrame {
int cycle = 0;
private boolean trigTable = true;
JPanel contentPane;
JPanel jpnlTop2 = new JPanel();
XYLayout xYLayout1 = new XYLayout();
JPanel jPanel1 = new JPanel();
BorderLayout borderLayout1 = new BorderLayout();
BorderLayout borderLayout2 = new BorderLayout();
ButtonGroup buttonGroup = new ButtonGroup();
DefaultListModel listMode1 = new DefaultListModel();
JList jList1 = new JList(listMode1);
JScrollPane jscrollList1 = new JScrollPane(jList1);
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
JButton jButton4 = new JButton();
DefaultListModel listMode2 = new DefaultListModel();
JList jList2 = new JList(listMode2);
JScrollPane jscrollList2 = new JScrollPane(jList2);
public PMMShipingSpace() {
try {
jbInit();
this.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width-this.getWidth())/2,
(Toolkit.getDefaultToolkit().getScreenSize().height-this.getHeight())/2);
}
catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(borderLayout1);
contentPane = (JPanel) getContentPane();
contentPane.setLayout(borderLayout2);
jpnlTop2.setLayout(xYLayout1); //
jPanel1.setLayout(borderLayout1);
jPanel1.setMaximumSize(new Dimension(32767, 32767));
jPanel1.setMinimumSize(new Dimension(706, 350));
jPanel1.setPreferredSize(new Dimension(700, 220));
jpnlTop2.setMinimumSize(new Dimension(690, 350));
jpnlTop2.setPreferredSize(new Dimension(130, 160));
contentPane.setMinimumSize(new Dimension(706, 662));
jButton1.setMaximumSize(new Dimension(49, 25));
jButton1.setMinimumSize(new Dimension(49, 25));
jButton1.setPreferredSize(new Dimension(57, 25));
jButton1.setText("->");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jButton2.setPreferredSize(new Dimension(57, 25));
jButton2.setText("->>");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
jButton3.setMaximumSize(new Dimension(49, 25));
jButton3.setMinimumSize(new Dimension(49, 25));
jButton3.setPreferredSize(new Dimension(57, 25));
jButton3.setText("<-");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton3_actionPerformed(e);
}
});
jButton4.setPreferredSize(new Dimension(57, 25));
jButton4.setHorizontalAlignment(SwingConstants.CENTER);
jButton4.setText("<<-");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton4_actionPerformed(e);
}
}); //載入資料
contentPane.add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jpnlTop2, BorderLayout.CENTER);
jpnlTop2.add(jscrollList1, new XYConstraints(43, 22, 132, 193));
jpnlTop2.add(jButton4, new XYConstraints(178, 125, -1, 26));
jpnlTop2.add(jButton3, new XYConstraints(178, 92, -1, 26));
jpnlTop2.add(jButton2, new XYConstraints(177, 58, -1, 26));
jpnlTop2.add(jButton1, new XYConstraints(176, 25, -1, 26));
jpnlTop2.add(jscrollList2, new XYConstraints(235, 23, 129, 193));
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(480, 320);
this.setTitle("JListTest"); //訂艙資訊維護//save//close
setupList();
}
private void setupList() {
listMode1.addElement("aaa");
listMode1.addElement("bbb");
listMode1.addElement("ccc");
listMode1.addElement("ddd");
listMode1.addElement("111");
listMode1.addElement("222");
listMode1.addElement("444");
listMode1.addElement("555");
listMode1.addElement("000");
listMode1.addElement("888");
}
void jButton1_actionPerformed(ActionEvent e) {
if (jList1.getSelectedIndices().length > 1) {
int temp = -1;
int t[] = jList1.getSelectedIndices();
jList1.clearSelection();
for (int i = 0; i < t.length; i++) {
temp++;
jList1.setSelectedIndex(t[i] - temp);
listMode2.addElement(jList1.getSelectedValue().toString());
listMode1.remove(t[i] - temp);
}
//jList sort
listModelSort(listMode2);
if (listMode1.size() > 0) {
jList1.setSelectedIndex(0);
}
return;
}
if (jList1.getSelectedIndex() > -1) {
// if (jList1.getSelectedIndex() > listMode2.size()) listMode2.setSize(
// jList1.getSelectedIndex());
listMode2.addElement(jList1.getSelectedValue().toString().trim());
listMode1.remove(jList1.getSelectedIndex());
//listMode1.removeElement(jList1.getSelectedValue().toString().trim());
}
//jList sort
listModelSort(listMode2);
if (listMode1.size() > 0) {
jList1.setSelectedIndex(0);
}
}
void jButton3_actionPerformed(ActionEvent e) {
if (jList2.getSelectedIndices().length > 1) {
int temp = -1;
int t[] = jList2.getSelectedIndices();
jList2.clearSelection();
for (int i = 0; i < t.length; i++) {
temp++;
jList2.setSelectedIndex(t[i] - temp);
listMode1.addElement(jList2.getSelectedValue().toString());
listMode2.remove(t[i] - temp);
}
//jList sort
listModelSort(listMode1);
if (listMode2.size() > 0) {
jList2.setSelectedIndex(0);
}
return;
}
if (jList2.getSelectedIndex() > -1) {
// if (jList2.getSelectedIndex() > listMode1.size()) listMode1.setSize(
// jList2.getSelectedIndex());
listMode1.addElement(jList2.getSelectedValue().toString().trim());
listMode2.remove(jList2.getSelectedIndex());
//listMode1.removeElement(jList1.getSelectedValue().toString().trim());
}
//jList sort
listModelSort(listMode1);
if (listMode2.size() > 0) {
jList2.setSelectedIndex(0);
}
}
void jButton2_actionPerformed(ActionEvent e) {
if (listMode1.size() > 0) {
while (listMode1.size() > 0) {
//for (int i = 0; i < listMode1.size(); i++) {
jList1.setSelectedIndex(0);
listMode2.addElement(jList1.getSelectedValue().toString().trim());
listMode1.remove(jList1.getSelectedIndex());
}
//jList sort
listModelSort(listMode2);
}
}
void jButton4_actionPerformed(ActionEvent e) {
if (listMode2.size() > 0) {
while (listMode2.size() > 0) {
//for (int i = 0; i < listMode1.size(); i++) {
jList2.setSelectedIndex(0);
listMode1.addElement(jList2.getSelectedValue().toString().trim());
listMode2.remove(jList2.getSelectedIndex());
}
//jList sort
listModelSort(listMode1);
}
}
public void listModelSort(DefaultListModel defaultListModel) {
java.util.ArrayList list = new java.util.ArrayList(Arrays.asList(
defaultListModel.toArray()));
for (int i = 0; i < list.size(); i++) {
if (list.get(i) == null) {
list.set(i, "");
}
}
Collections.sort(list);
defaultListModel.removeAllElements();
for (int i = 0; i < list.size(); i++) {
defaultListModel.addElement(list.get(i).toString());
}
}
public static void main(String[] args) {
PMMShipingSpace test = new PMMShipingSpace();
test.show();
}
}