blob: 94492d7fcb3ddb408c8ab2b43058fdd7d07273a9 (
plain) (
tree)
|
|
package org.openslx.dozmod.gui.window;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JScrollBar;
import org.apache.log4j.Logger;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.helper.MessageType;
import org.openslx.dozmod.gui.helper.UiFeedback;
import org.openslx.dozmod.gui.window.layout.GenericNoticeWindowLayout;
/**
* Window for showing the notice.
*/
@SuppressWarnings("serial")
public abstract class GenericNoticeWindow extends GenericNoticeWindowLayout implements UiFeedback {
final GenericNoticeWindow me = this;
private final static Logger LOGGER = Logger.getLogger(GenericNoticeWindow.class);
private boolean shouldBeShown = true;
public GenericNoticeWindow(Frame modalParent, boolean shouldBeShown) {
super(modalParent);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.shouldBeShown = shouldBeShown;
// agree box toggles the "Continue" button
chkAgreeBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
btnContinue.setEnabled(chkAgreeBox.isSelected());
}
});
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
closeWindow();
}
});
if (!shouldBeShown) {
chkAgreeBox.setVisible(false);
btnContinue.setText("Schließen");
btnContinue.setEnabled(true);
} else {
disclaimerPanel.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
@Override
public void adjustmentValueChanged(AdjustmentEvent e) {
JScrollBar scrollBar = (JScrollBar) e.getAdjustable();
int extent = scrollBar.getModel().getExtent();
int value = e.getValue() + extent;
int max = e.getAdjustable().getMaximum();
if (value >= max) {
chkAgreeBox.setEnabled(true);
}
}
});
}
}
@Override
public boolean wantConfirmQuit() {
return true;
}
@Override
public void escapePressed() {
closeWindow();
}
/**
* Check, whether to ask for confirmation, when notice hasn't been
* accepted or just close.
*/
private void closeWindow() {
if (shouldBeShown) {
if (Gui.showMessageBox(me,
"Wenn diesen rechtlichen Hinweis nicht akzeptieren, können Sie die Software nicht verwenden! "
+ "Sind Sie sicher, dass sie abbrechen wollen?", MessageType.QUESTION_YESNO,
LOGGER, null)) {
System.exit(ABORT);
}
} else {
me.dispose();
}
}
}
|