1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
| /**
* Graphic user interface.
*/
package com;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.TitledBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import com.SDrive.Item;
/**
* @author alfonso
*/
public class SGui {
private static SDrive drives = SDrive.getInstance();
private static Vector<Item> removables = drives.getRemovable();
//
private static final int SERIAL_COLUMN_INDEX = 4;
private JFrame frame;
private JList list;
private JTable table;
private JTextField textField;
/**
* Constructor.
*/
public SGui() {
try {
javax.swing.UIManager.setLookAndFeel("com.jgoodies.looks.plastic.Plastic3DLookAndFeel");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
initialize();
}
/**
* Initialize the contents of the frame
*/
public void initialize() {
frame = new JFrame();
frame.setMinimumSize(new Dimension(600, 500));
frame.getContentPane().setLayout(new GridBagLayout());
frame.setSize(600, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JMenuBar menuBar = new JMenuBar();
menuBar.setBorderPainted(false);
frame.setJMenuBar(menuBar);
final JMenu fileMenu = new JMenu();
fileMenu.setText("File");
menuBar.add(fileMenu);
fileMenu.addSeparator();
final JMenuItem exitMenuItem = new JMenuItem();
exitMenuItem.setText("Exit");
fileMenu.add(exitMenuItem);
final JMenu stiksMenu = new JMenu();
stiksMenu.setText("Sticks");
menuBar.add(stiksMenu);
final JMenuItem newMenuItem = new JMenuItem();
newMenuItem.setText("New ...");
stiksMenu.add(newMenuItem);
final JMenuItem removeMenuItem = new JMenuItem();
removeMenuItem.setText("Remove");
stiksMenu.add(removeMenuItem);
final JMenu menu = new JMenu();
menu.setText(" ? ");
menuBar.add(menu);
final JMenuItem aboutMenuItem = new JMenuItem();
aboutMenuItem.setText("Guide");
menu.add(aboutMenuItem);
final JMenuItem licenceMenuItem = new JMenuItem();
licenceMenuItem.setText("Licence");
menu.add(licenceMenuItem);
JScrollPane scrollPane;
final JPanel addStickPanel = new JPanel();
addStickPanel.setBorder(new TitledBorder(null, "Add a stick", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.BELOW_TOP, null, null));
addStickPanel.setLayout(new GridBagLayout());
final GridBagConstraints gridBagConstraints_6 = new GridBagConstraints();
gridBagConstraints_6.weighty = 1.0;
gridBagConstraints_6.fill = GridBagConstraints.BOTH;
gridBagConstraints_6.gridx = 0;
gridBagConstraints_6.gridy = 0;
frame.getContentPane().add(addStickPanel, gridBagConstraints_6);
final JButton refreshListButton = new JButton();
refreshListButton.setText("Refresh list");
final GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = GridBagConstraints.SOUTHWEST;
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.insets = new Insets(0, 0, 0, 0);
addStickPanel.add(refreshListButton, gridBagConstraints);
// refreshListButton.setIcon(new ImageIcon(getClass().getClassLoader().getResource("me/icon_txt.gif")));
final JButton addStickButton = new JButton();
addStickButton.setText("Add this stick");
final GridBagConstraints gridBagConstraints_1 = new GridBagConstraints();
gridBagConstraints_1.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints_1.gridwidth = 2;
gridBagConstraints_1.anchor = GridBagConstraints.SOUTHEAST;
gridBagConstraints_1.gridx = 2;
gridBagConstraints_1.gridy = 2;
gridBagConstraints_1.insets = new Insets(0, 0, 0, 0);
addStickPanel.add(addStickButton, gridBagConstraints_1);
final JLabel selectStickLabel = new JLabel();
selectStickLabel.setText("Select a stick :");
final GridBagConstraints gridBagConstraints_3 = new GridBagConstraints();
gridBagConstraints_3.anchor = GridBagConstraints.NORTHWEST;
gridBagConstraints_3.gridx = 0;
gridBagConstraints_3.gridy = 0;
addStickPanel.add(selectStickLabel, gridBagConstraints_3);
final JScrollPane scrollPane_1 = new JScrollPane();
scrollPane_1.setMinimumSize(new Dimension(180, 100));
scrollPane_1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane_1.setPreferredSize(new Dimension(180, 100));
scrollPane_1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
final GridBagConstraints gridBagConstraints_10 = new GridBagConstraints();
gridBagConstraints_10.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints_10.insets = new Insets(5, 0, 5, 0);
gridBagConstraints_10.gridy = 1;
gridBagConstraints_10.gridx = 0;
addStickPanel.add(scrollPane_1, gridBagConstraints_10);
list = new JList(removables);
list.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent arg0) {
String nameSuggestion = ((Item)list.getSelectedValue()).getVolumeName();
textField.setText(nameSuggestion);
System.out.println(((Item)list.getSelectedValue()).getValue());
}
});
scrollPane_1.setViewportView(list);
list.setAutoscrolls(false);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
final JSeparator separator = new JSeparator();
separator.setPreferredSize(new Dimension(20, 0));
final GridBagConstraints gridBagConstraints_12 = new GridBagConstraints();
gridBagConstraints_12.gridy = 1;
gridBagConstraints_12.gridx = 1;
addStickPanel.add(separator, gridBagConstraints_12);
final JLabel choseNameLabel = new JLabel();
choseNameLabel.setText("Chose a name : ");
final GridBagConstraints gridBagConstraints_11 = new GridBagConstraints();
gridBagConstraints_11.insets = new Insets(0, 0, 0, 0);
gridBagConstraints_11.gridy = 1;
gridBagConstraints_11.gridx = 2;
addStickPanel.add(choseNameLabel, gridBagConstraints_11);
textField = new JTextField();
textField.setMinimumSize(new Dimension(0, 0));
final GridBagConstraints gridBagConstraints_2 = new GridBagConstraints();
gridBagConstraints_2.ipadx = 150;
gridBagConstraints_2.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints_2.insets = new Insets(0, 0, 0, 0);
gridBagConstraints_2.gridy = 1;
gridBagConstraints_2.gridx = 3;
addStickPanel.add(textField, gridBagConstraints_2);
final JPanel registeredSticksPanel = new JPanel();
registeredSticksPanel.setLayout(new GridBagLayout());
registeredSticksPanel.setBorder(new TitledBorder(null, "Registered sticks", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.BELOW_TOP, null, null));
final GridBagConstraints gridBagConstraints_7 = new GridBagConstraints();
gridBagConstraints_7.weighty = 1.0;
gridBagConstraints_7.weightx = 1.0;
gridBagConstraints_7.fill = GridBagConstraints.BOTH;
gridBagConstraints_7.gridx = 0;
gridBagConstraints_7.gridy = 1;
frame.getContentPane().add(registeredSticksPanel, gridBagConstraints_7);
scrollPane = new JScrollPane();
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
final GridBagConstraints gridBagConstraints_4 = new GridBagConstraints();
gridBagConstraints_4.gridwidth = 2;
gridBagConstraints_4.weightx = 1.0;
gridBagConstraints_4.fill = GridBagConstraints.BOTH;
gridBagConstraints_4.weighty = 1.0;
gridBagConstraints_4.gridx = 0;
gridBagConstraints_4.gridy = 0;
gridBagConstraints_4.insets = new Insets(0, 0, 0, 0);
registeredSticksPanel.add(scrollPane, gridBagConstraints_4);
scrollPane.setMinimumSize(new Dimension(320, 160));
scrollPane.setPreferredSize(new Dimension(320, 160));
scrollPane.setName("scrollPane");
//
// table = new StickTable();
table = new JTable();
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setModel(new STableModel());
table.setAutoCreateRowSorter(true);
//
scrollPane.setViewportView(table);
final JButton refreshTableButton = new JButton();
refreshTableButton.setText("Refresh table");
final GridBagConstraints gridBagConstraints_5 = new GridBagConstraints();
gridBagConstraints_5.ipadx = 50;
gridBagConstraints_5.fill = GridBagConstraints.VERTICAL;
gridBagConstraints_5.anchor = GridBagConstraints.SOUTHWEST;
gridBagConstraints_5.gridy = 1;
gridBagConstraints_5.gridx = 0;
registeredSticksPanel.add(refreshTableButton, gridBagConstraints_5);
final JButton deleteSelectedRowButton = new JButton();
deleteSelectedRowButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent arg0) {
long serialID = Long.parseLong(table.getValueAt(table.getSelectedRow(), SERIAL_COLUMN_INDEX).toString());
System.out.println(serialID);
}
});
deleteSelectedRowButton.setText("Delete selected row");
final GridBagConstraints gridBagConstraints_9 = new GridBagConstraints();
gridBagConstraints_9.ipadx = 20;
gridBagConstraints_9.anchor = GridBagConstraints.SOUTHEAST;
gridBagConstraints_9.gridy = 1;
gridBagConstraints_9.gridx = 1;
registeredSticksPanel.add(deleteSelectedRowButton, gridBagConstraints_9);
final JPanel panel_3 = new JPanel();
panel_3.setLayout(new GridLayout(3, 0));
final GridBagConstraints gridBagConstraints_8 = new GridBagConstraints();
gridBagConstraints_8.anchor = GridBagConstraints.SOUTH;
gridBagConstraints_8.gridx = 0;
gridBagConstraints_8.gridy = 2;
gridBagConstraints_8.ipadx = 590;
gridBagConstraints_8.ipady = 20;
gridBagConstraints_8.insets = new Insets(0, 0, 0, 0);
frame.getContentPane().add(panel_3, gridBagConstraints_8);
frame.setVisible(true);
}
} |
Partager