diff options
author | Stephan Schwaer | 2015-09-15 17:45:22 +0200 |
---|---|---|
committer | Stephan Schwaer | 2015-09-15 17:45:22 +0200 |
commit | e407b8814bdb45c8b7ab7343b53647ea6a84bc95 (patch) | |
tree | 3d89adb782686d6e32e9f61c6694e7ccacf64d94 | |
parent | [client] Fix shade goal removing required logging classes (diff) | |
download | tutor-module-e407b8814bdb45c8b7ab7343b53647ea6a84bc95.tar.gz tutor-module-e407b8814bdb45c8b7ab7343b53647ea6a84bc95.tar.xz tutor-module-e407b8814bdb45c8b7ab7343b53647ea6a84bc95.zip |
[client] Reworked the satellite selection window.
3 files changed, 65 insertions, 100 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/SatelliteTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/SatelliteTable.java deleted file mode 100644 index 83fd0650..00000000 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/SatelliteTable.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.openslx.dozmod.gui.control.table; - -import org.openslx.bwlp.thrift.iface.Satellite; - -@SuppressWarnings("serial") -public class SatelliteTable extends ListTable<Satellite> { - - public static final ListTableColumn COL_NAME = new ListTableColumn("Name"); - public static final ListTableColumn COL_ADDRESSES = new ListTableColumn("Adressen"); - - public SatelliteTable() { - super(COL_NAME, COL_ADDRESSES); - } - - @Override - protected Object getValueAtInternal( Satellite sat, ListTableColumn column) { - if (column == COL_NAME) - return sat.getDisplayName(); - if (column == COL_ADDRESSES) - return sat.getAddressList(); - throw new IndexOutOfBoundsException(); - } - -} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/SatelliteListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/SatelliteListWindow.java index 8ab78823..3980f315 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/SatelliteListWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/SatelliteListWindow.java @@ -3,12 +3,11 @@ package org.openslx.dozmod.gui.window; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; import javax.swing.JFrame; +import javax.swing.JRadioButton; import org.apache.log4j.Logger; import org.openslx.bwlp.thrift.iface.Satellite; @@ -35,43 +34,49 @@ public class SatelliteListWindow extends SatelliteListWindowLayout implements Ui * Don't use this, use the static function open instead. */ public SatelliteListWindow(final Window modalParent, List<Satellite> satList) { - super(modalParent); + super(modalParent, satList); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + // Check, whether we have any satellites if (satList != null && !satList.isEmpty()){ - satelliteTable.setData(satList, true); - radioSatelliteTable.setSelected(true); + satelliteButtons[0].setSelected(true); customIpField.setEnabled(false); - satelliteTable.setSelectedItem(satelliteTable.getModelRow(0)); } else { - radioSatelliteTable.setEnabled(false); radioCustomIp.setSelected(true); } + // deactivate the custom field when selecting a satellite to make things clearer for user + for ( int i = 0; i < satCount; i++ ){ + satelliteButtons[i].addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + customIpField.setEnabled(false); + } + }); + } + radioCustomIp.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { - satelliteTable.setEnabled(false); customIpField.setEnabled(true); - satelliteTable.clearSelection(); - } - }); - - radioSatelliteTable.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent arg0) { - satelliteTable.setEnabled(true); - customIpField.setEnabled(false); - satelliteTable.setSelectedItem(satelliteTable.getModelRow(0)); } }); exitButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - if(radioSatelliteTable.isSelected() && satelliteTable.getSelectedItem() != null) - satellite = satelliteTable.getSelectedItem(); - else { + // satellite is selected + if(!radioCustomIp.isSelected()){ + // check, which satellite is selected + for (JRadioButton button : satelliteButtons) { + if(button.isSelected()){ + // return it. + satellite = radioToSat.get(button); + } + } + } + // custom button selected or something went wrong + if (satellite == null || radioCustomIp.isSelected()) { satellite = new Satellite(); satellite.addressList = new ArrayList<String>(); satellite.addressList.add(customIpField.getText()); @@ -82,16 +87,6 @@ public class SatelliteListWindow extends SatelliteListWindowLayout implements Ui getRootPane().setDefaultButton(exitButton); - satelliteTable.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - if(satelliteTable.isEnabled()){ - if (e.getClickCount() == 2) { - exitButton.doClick(); - } - } - } - }); Gui.centerShellOverShell(modalParent, this); } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/SatelliteListWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/SatelliteListWindowLayout.java index d404a082..cb1dc3a1 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/SatelliteListWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/SatelliteListWindowLayout.java @@ -2,6 +2,8 @@ package org.openslx.dozmod.gui.window.layout; import java.awt.Dimension; import java.awt.Window; +import java.util.HashMap; +import java.util.List; import javax.swing.BorderFactory; import javax.swing.Box; @@ -11,62 +13,58 @@ import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JPanel; import javax.swing.JRadioButton; -import javax.swing.JScrollPane; import javax.swing.JTextField; -import javax.swing.UIManager; -import org.openslx.dozmod.gui.Gui; -import org.openslx.dozmod.gui.control.table.SatelliteTable; +import org.openslx.bwlp.thrift.iface.Satellite; import org.openslx.dozmod.gui.helper.GridManager; @SuppressWarnings("serial") public class SatelliteListWindowLayout extends JDialog { - protected final SatelliteTable satelliteTable; - protected final JButton exitButton; protected final JTextField customIpField; protected final JRadioButton radioCustomIp; - protected final JRadioButton radioSatelliteTable; - + protected final JRadioButton[] satelliteButtons; + protected final int satCount; + protected final HashMap<JRadioButton, Satellite> radioToSat = new HashMap<JRadioButton, Satellite>(); + protected final ButtonGroup btnGroup; + private static String title = "Liste an Satelliten"; - protected SatelliteListWindowLayout(Window modalParent) { + protected SatelliteListWindowLayout(Window modalParent, List<Satellite> satList) { super(modalParent, title, modalParent != null ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS); - GridManager grid = new GridManager(this, 1); + GridManager windowGrid = new GridManager(this, 1); + JPanel radioPanel = new JPanel(); + radioPanel.setBorder(BorderFactory.createTitledBorder( "Satelliten Auswahl")); + GridManager selectionPanelGrid = new GridManager(radioPanel, 2); + btnGroup = new ButtonGroup(); + // --------------- radio buttons sat selection -------------------------------------- + satCount = satList.size(); + satelliteButtons = new JRadioButton[satCount]; + // create the radioButtons, add them to the map, button group and the selection grid. + for (int index = 0; index < satCount; index++ ){ + satelliteButtons[index] = new JRadioButton(satList.get(index).getDisplayName()); + radioToSat.put(satelliteButtons[index], satList.get(index)); + btnGroup.add(satelliteButtons[index]); + selectionPanelGrid.add(satelliteButtons[index], 2).fill(true, false).expand(true, false); + selectionPanelGrid.nextRow(); + } + // --------------- end radio buttons for sat selection ------------------------------------ - - // --------------- radio buttons for selection -------------------------------------- - radioCustomIp = new JRadioButton("Benutzerdefinierte Adresse"); - radioSatelliteTable = new JRadioButton("Satelliten Auswahl"); - ButtonGroup btnGroup = new ButtonGroup(); - btnGroup.add(radioSatelliteTable); + // --------------- custom ip button and field -------------------------------------- + radioCustomIp = new JRadioButton("Benutzerdefiniert"); btnGroup.add(radioCustomIp); - // --------------- end radio buttons ------------------------------------ - - // --------------- satellite list -------------------------------------- - JPanel listPane = new JPanel(); - listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS)); - listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - satelliteTable = new SatelliteTable(); - JScrollPane jsp = new JScrollPane(satelliteTable); - jsp.setBackground(UIManager.getColor("Table.background")); - listPane.add(radioSatelliteTable); - listPane.add(jsp); - // --------------- end satellite list ------------------------------------ - - // --------------- custom ip field -------------------------------------- - JPanel customIpPanel = new JPanel(); - customIpPanel.setLayout(new BoxLayout(customIpPanel, BoxLayout.PAGE_AXIS)); - customIpPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10)); customIpField = new JTextField(); - customIpPanel.add(radioCustomIp); - customIpPanel.add(customIpField); + customIpField.setPreferredSize(new Dimension(120, 25)); + selectionPanelGrid.add(radioCustomIp).fill(true, false).expand(false, false); + selectionPanelGrid.add(customIpField).fill(true, false).expand(true, false); + selectionPanelGrid.nextRow(); + selectionPanelGrid.finish(true); // --------------- end custom ip field -------------------------------- - + // --------------- button panel -------------------------------------- JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); @@ -78,15 +76,11 @@ public class SatelliteListWindowLayout extends JDialog { // --------------- end button panel ---------------------------------- // pack it all - grid.add(listPane).fill(true, true).expand(true, true); - grid.nextRow(); - grid.add(customIpPanel).fill(true, false).expand(true, false); - grid.nextRow(); - grid.add(buttonPane).fill(true, false).expand(true, false); - grid.nextRow(); - grid.finish(false); - - setPreferredSize(Gui.getScaledDimension(300, 350)); + windowGrid.add(radioPanel).fill(true, true).expand(true, true); + windowGrid.nextRow(); + windowGrid.add(buttonPane).fill(true, false).expand(true, false); + windowGrid.nextRow(); + windowGrid.finish(false); pack(); } } |