From 9f19a4e65bf65846c3cf0eeb32940ec8b9a53aed Mon Sep 17 00:00:00 2001 From: Stephan Schwaer Date: Tue, 6 Oct 2015 14:55:46 +0200 Subject: [client] code cleanup and formatting. --- .../openslx/dozmod/gui/window/ConfigWindow.java | 50 ++++++++++++++-------- .../openslx/dozmod/gui/window/ImageListWindow.java | 1 + .../dozmod/gui/window/LectureListWindow.java | 33 ++++---------- .../gui/window/layout/ConfigWindowLayout.java | 18 ++++---- 4 files changed, 50 insertions(+), 52 deletions(-) (limited to 'dozentenmodul/src/main/java') diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ConfigWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ConfigWindow.java index 5f921d75..ce18cf64 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ConfigWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ConfigWindow.java @@ -21,6 +21,7 @@ import org.openslx.dozmod.thrift.Session; import org.openslx.dozmod.thrift.ThriftError; import org.openslx.thrifthelper.ThriftManager; +@SuppressWarnings("serial") public class ConfigWindow extends ConfigWindowLayout implements UiFeedback, ActionListener { private final static Logger LOGGER = Logger.getLogger(ConfigWindow.class); @@ -32,17 +33,17 @@ public class ConfigWindow extends ConfigWindowLayout implements UiFeedback, Acti // -- PROXY -- // set proxy mode as saved in config - switch(Config.getProxyMode()) { - case NONE: - btnProxyNone.setSelected(true); - break; - case AUTO: - btnProxyAuto.setSelected(true); - break; - case HTTP_CONNECT: - case SOCKS: - default: - break; + switch (Config.getProxyMode()) { + case NONE: + btnProxyNone.setSelected(true); + break; + case AUTO: + btnProxyAuto.setSelected(true); + break; + case HTTP_CONNECT: + case SOCKS: + default: + break; } btnProxyNone.addActionListener(this); btnProxyAuto.addActionListener(this); @@ -74,16 +75,19 @@ public class ConfigWindow extends ConfigWindowLayout implements UiFeedback, Acti btnClose.addActionListener(this); // -- END BOTTOM BUTTONS -- } + @Override public void actionPerformed(ActionEvent e) { Object source = e.getSource(); - if (source == btnProxyAuto || source == btnProxyHttp || source == btnProxyNone || source == btnProxySocks) + if (source == btnProxyAuto || source == btnProxyHttp || source == btnProxyNone + || source == btnProxySocks) reactToInput(); if (source == btnSave) saveOptions(); if (source == btnClose) dispose(); } + private void reactToInput() { // our flag to en/disable the save button boolean changed = false; @@ -91,7 +95,7 @@ public class ConfigWindow extends ConfigWindowLayout implements UiFeedback, Acti ProxyMode initMode = Config.getProxyMode(); SatelliteUserConfig userConfig = getSatUserConfig(); int fontScaling = Config.getFontScaling(); - + // now check if the buttons represent another state if (btnProxyNone.isSelected() && initMode != ProxyMode.NONE) changed = true; @@ -99,22 +103,25 @@ public class ConfigWindow extends ConfigWindowLayout implements UiFeedback, Acti changed = true; else if (btnSendMeMail.isSelected() != userConfig.emailNotifications) changed = true; - else if ((Integer)btnFontSize.getValue() != fontScaling) + else if ((Integer) btnFontSize.getValue() != fontScaling) changed = true; // en/disable the save button btnSave.setEnabled(changed); } + private SatelliteUserConfig getSatUserConfig() { SatelliteUserConfig userConfig = null; // set mail me stuff as saved on the sat try { userConfig = ThriftManager.getSatClient().getUserConfig(Session.getSatelliteToken()); } catch (TException e) { - ThriftError.showMessage(this, LOGGER, e, "Konnte die benutzerspezifische Konfiguration nicht vom Satelliten holen!"); + ThriftError.showMessage(this, LOGGER, e, + "Konnte die benutzerspezifische Konfiguration nicht vom Satelliten holen!"); } return userConfig; } + private boolean setSatUserConfig(SatelliteUserConfig config) { if (config == null) return false; @@ -122,11 +129,13 @@ public class ConfigWindow extends ConfigWindowLayout implements UiFeedback, Acti try { ThriftManager.getSatClient().setUserConfig(Session.getSatelliteToken(), config); } catch (TException e) { - ThriftError.showMessage(this, LOGGER, e, "Konnte die benutzerspezifische Konfiguration nicht vom Satelliten holen!"); + ThriftError.showMessage(this, LOGGER, e, + "Konnte die benutzerspezifische Konfiguration nicht vom Satelliten holen!"); return false; } return true; } + private void saveOptions() { btnSave.setEnabled(false); // save proxy mode to config @@ -140,17 +149,20 @@ public class ConfigWindow extends ConfigWindowLayout implements UiFeedback, Acti } // save font scaling to config - Config.setFontScaling((Integer)btnFontSize.getValue()); + Config.setFontScaling((Integer) btnFontSize.getValue()); // NOTE this can fail! // save mail notification stuff to sat if (!setSatUserConfig(new SatelliteUserConfig(btnSendMeMail.isSelected()))) { - Gui.showMessageBox(this, "Konnte die Änderung nicht am Satelliten speichern!", MessageType.ERROR, LOGGER, null); + Gui.showMessageBox(this, "Konnte die Änderung nicht am Satelliten speichern!", MessageType.ERROR, + LOGGER, null); btnSave.setEnabled(true); } // let the user know he needs to restart for the changes to apply - Gui.showMessageBox(this, "Die Änderungen werden erst nach einem Programmneustart wirksam.", MessageType.INFO, LOGGER, null); + Gui.showMessageBox(this, "Die Änderungen werden erst nach einem Programmneustart wirksam.", + MessageType.INFO, LOGGER, null); } + public static boolean shouldBeShown() { return true; } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java index 31d047c9..2ea3ea94 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java @@ -254,6 +254,7 @@ public class ImageListWindow extends ImageListWindowLayout implements DownloadCa /** * Updates the buttons/popup menu items according to the user's permissions + * and the selection in the table * * @param item the image to check the user's permissions for */ diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java index 970e12fb..eb91739e 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java @@ -289,22 +289,6 @@ public class LectureListWindow extends LectureListWindowLayout { } private void processClick(MouseEvent e) { - // // left double click => open details - // if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2 && Session.canListImages()) { - // openLectureDetails(lectureTable.getSelectedItem()); - // return; - // } - // // else, check if we are a popup trigger - // int r = lectureTable.rowAtPoint(e.getPoint()); - // if (r >= 0 && r < lectureTable.getRowCount()) { - // // highlight the row and popup the menu - // lectureTable.setRowSelectionInterval(r, r); - // if (e.isPopupTrigger()) { - // pop.show(e.getComponent(), e.getX(), e.getY()); - // } - // } else { - // lectureTable.clearSelection(); - // } // rowIndex at mouse cursor int mouseRowIndex = lectureTable.rowAtPoint(e.getPoint()); @@ -382,15 +366,15 @@ public class LectureListWindow extends LectureListWindowLayout { * Updates the buttons/popup menu items according to the user's permissions, * status and number of selections * - * @param item the image to check the user's permissions for + * @param lecture the lecture to check the user's permissions for, can be + * null */ - //TODO rework the visibility of buttons? private void updateAvailableOptions(LectureSummary lecture) { boolean admin = LecturePerms.canAdmin(lecture); boolean singleSelection = !(lectureTable.getSelectedRows().length > 1); deleteButton.setEnabled(admin || !singleSelection); - popupItemDelete.setEnabled(admin); + popupItemDelete.setEnabled(admin || !singleSelection); popupItemLinked.setEnabled(Session.canListImages() && singleSelection); popupItemDownload.setEnabled(Session.canListImages() && singleSelection); popupItemNew.setEnabled(Session.canListImages() && singleSelection); @@ -446,7 +430,8 @@ public class LectureListWindow extends LectureListWindowLayout { } } if (failedToDeleteAll) { - Gui.showMessageBox("Folgende images konnten nicht gelöscht werden: " + builder.toString(), + Gui.showMessageBox( + "Folgende Veranstaltungen konnten nicht gelöscht werden: " + builder.toString(), MessageType.INFO, LOGGER, null); } } @@ -521,12 +506,10 @@ public class LectureListWindow extends LectureListWindowLayout { @Override public void requestShow() { - // en-/disable buttons when studentswitchViewButton.setEnabled(Session.canListImages()); + // en-/disable buttons when student + switchViewButton.setEnabled(Session.canListImages()); newButton.setEnabled(Session.canListImages()); - popupItemNew.setEnabled(Session.canListImages()); - popupItemLinked.setEnabled(Session.canListImages()); - popupItemEdit.setEnabled(Session.canListImages()); - editButton.setEnabled(Session.canListImages()); + updateAvailableOptions(null); refreshList(false); } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ConfigWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ConfigWindowLayout.java index a6b641a1..b1a0c761 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ConfigWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ConfigWindowLayout.java @@ -25,7 +25,7 @@ import org.openslx.dozmod.thrift.Session; @SuppressWarnings("serial") public class ConfigWindowLayout extends JDialog { - + private static String title = "bwLehrpool Suite - Konfiguration"; protected JRadioButton btnProxyNone; @@ -41,12 +41,13 @@ public class ConfigWindowLayout extends JDialog { protected ButtonGroup radioGroup; public ConfigWindowLayout(Frame modalParent) { - super(modalParent, title, modalParent != null ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS); + super(modalParent, title, modalParent != null ? ModalityType.APPLICATION_MODAL + : ModalityType.MODELESS); // regular layout as a helper for the whole page setLayout(new BorderLayout()); setMinimumSize(Gui.getScaledDimension(500, 300)); - + // Panel to add everything into, needed for the border. JPanel contentPanel = new JPanel(); getContentPane().add(contentPanel, BorderLayout.CENTER); @@ -59,13 +60,13 @@ public class ConfigWindowLayout extends JDialog { btnSendMeMail = new JCheckBox("Über Image- und Veranstaltungsänderungen per eMail informiert werden"); mailPanel.add(btnSendMeMail); // TODO center the label horizontally - JLabel mailNotice = new JLabel("Für diese Option muss der Server für den Mailversand konfiguriert sein!"); + JLabel mailNotice = new JLabel( + "Für diese Option muss der Server für den Mailversand konfiguriert sein."); mailPanel.add(mailNotice); JLabel mailNote = new JLabel("Ihre eMail-Adresse ist " + Session.getEMail()); mailNote.setFont(mailNote.getFont().deriveFont(Font.ITALIC)); mailPanel.add(mailNote); - // proxy config panel JPanel proxyPanel = new JPanel(); proxyPanel.setBorder(BorderFactory.createTitledBorder("Proxy")); @@ -86,7 +87,7 @@ public class ConfigWindowLayout extends JDialog { proxyGrid.add(radioGroupPanel, 2); proxyGrid.nextRow(); proxyGrid.finish(false); - + // font config panel JPanel fontPanel = new JPanel(); fontPanel.setBorder(BorderFactory.createTitledBorder("Schriftgröße (%)")); @@ -96,7 +97,8 @@ public class ConfigWindowLayout extends JDialog { fontGrid.add(fontNote); fontGrid.nextRow(); btnFontSize = new JSlider(JSlider.HORIZONTAL); - btnFontSize.setModel(new DefaultBoundedRangeModel(100, Config.FONT_SCALING_STEP, Config.FONT_SCALING_MIN, Config.FONT_SCALING_MAX)); + btnFontSize.setModel(new DefaultBoundedRangeModel(100, Config.FONT_SCALING_STEP, + Config.FONT_SCALING_MIN, Config.FONT_SCALING_MAX)); btnFontSize.setMinorTickSpacing(Config.FONT_SCALING_STEP); btnFontSize.setMajorTickSpacing(25); btnFontSize.setSnapToTicks(true); @@ -129,7 +131,7 @@ public class ConfigWindowLayout extends JDialog { grid.add(fontPanel).fill(true, false).expand(false, false); grid.nextRow(); grid.finish(false); - + add(buttonPanel, BorderLayout.PAGE_END); pack(); } -- cgit v1.2.3-55-g7522