diff options
4 files changed, 107 insertions, 86 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/StatusHeader.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/StatusHeader.java new file mode 100644 index 00000000..ae2e8adb --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/StatusHeader.java @@ -0,0 +1,64 @@ +package org.openslx.dozmod.gui.helper; + +import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.control.QLabel; +import org.openslx.dozmod.util.ResourceLoader; + +import javax.swing.*; +import java.awt.*; + +/** + * StatusHeader can be used in GUI-Dialogs to inform a user about a current + * state of an Input. See {@link org.openslx.dozmod.gui.window.layout.ContainerBindMountWindowLayout} how to + * use it. + */ +public class StatusHeader extends JPanel { + + private final QLabel titleLabel; + private final QLabel messageLabel; + + + public StatusHeader(Container contentPane, String message) { + this(contentPane, "", message); + } + + public StatusHeader(Container contentPane, String title, String message) { + + this.setMinimumSize(Gui.getScaledDimension(0, 100)); + this.setOpaque(true); + this.setBackground(Color.WHITE); + this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); + this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + + titleLabel = new QLabel(title); + messageLabel = new QLabel(message); + titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD)); + titleLabel.setForeground(Color.BLACK); + messageLabel.setForeground(Color.BLACK); + messageLabel.setHorizontalTextPosition(SwingConstants.RIGHT); + + this.add(titleLabel); + this.add(messageLabel); + + JPanel headerWrapper = new JPanel(); + GridManager grid = new GridManager(headerWrapper, 1, false); + grid.add(this).expand(true, false).fill(true, false); + grid.add(new JSeparator()).expand(true, false).fill(true, false); + grid.finish(false); + contentPane.add(headerWrapper, BorderLayout.PAGE_START); + } + + + + public void updateHeader(String pageTitle, String pageDesc, Icon icon, Color color) { + titleLabel.setText(pageTitle); + messageLabel.setText(pageDesc); + messageLabel.setIcon(ResourceLoader.getScaledIcon(icon, messageLabel.getHeight(), messageLabel)); + messageLabel.setForeground(color); + messageLabel.validate(); + } + + public void updateStatus(String statusMessage) { + messageLabel.setText(statusMessage); + } +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ContainerBindMountWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ContainerBindMountWindow.java index a7c141fb..62f8514e 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ContainerBindMountWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ContainerBindMountWindow.java @@ -13,7 +13,7 @@ import java.util.List; public class ContainerBindMountWindow extends ContainerBindMountWindowLayout { - private ContainerBindMountTable bindMountTable; + private final ContainerBindMountTable bindMountTable; public ContainerBindMountWindow(Window modalParent, ContainerBindMountTable bindMountTable) { super(modalParent); @@ -44,14 +44,17 @@ public class ContainerBindMountWindow extends ContainerBindMountWindowLayout { } - // TODO add text if input not finished private boolean isInputComplete() { btnSave.setEnabled(false); - if (txtBmSource == null || txtBmSource.getText().isEmpty()) + if (txtBmSource == null || txtBmSource.getText().isEmpty()) { + header.updateStatus("Source Path is Missing"); return false; + } if (txtBmTarget == null || txtBmTarget.getText().isEmpty()) { + header.updateStatus("Target Path is Missing"); return false; } + header.updateStatus("Input Completed"); btnSave.setEnabled(true); return true; } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ContainerBindMountWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ContainerBindMountWindowLayout.java index 2e5432b8..dcfe1dd4 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ContainerBindMountWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ContainerBindMountWindowLayout.java @@ -3,6 +3,7 @@ package org.openslx.dozmod.gui.window.layout; import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.control.QLabel; import org.openslx.dozmod.gui.helper.GridManager; +import org.openslx.dozmod.gui.helper.StatusHeader; import javax.swing.*; import java.awt.*; @@ -11,6 +12,7 @@ public class ContainerBindMountWindowLayout extends JDialog { private static final String title = "Add Bind Mount"; + protected final StatusHeader header; protected final QLabel lblBmSource; protected final JTextField txtBmSource; protected final QLabel lblBmTarget; @@ -21,10 +23,15 @@ public class ContainerBindMountWindowLayout extends JDialog { protected final JButton btnCancel; public ContainerBindMountWindowLayout(Window modalParent) { - super(modalParent, title, - modalParent != null ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS); + super(modalParent, title, ModalityType.APPLICATION_MODAL); - GridManager grid = new GridManager(this, 2, true, new Insets(2, 2, 2, 2)); + setLayout(new BorderLayout()); + + header = new StatusHeader(getContentPane() , "Source and Target Path Required"); + + JPanel contentPanel = new JPanel(); + add(contentPanel, BorderLayout.CENTER); + GridManager grid = new GridManager(contentPanel, 2, true, new Insets(2, 2, 2, 2)); lblBmSource = new QLabel("Source"); txtBmSource = new JTextField(); @@ -57,11 +64,8 @@ public class ContainerBindMountWindowLayout extends JDialog { grid.add(buttonPane, 2).fill(true, false).expand(true, false); grid.finish(false); - //setPreferredSize(Gui.getScaledDimension(650, 350)); - - setSize(350, 150); + setSize(350, 200); setResizable(false); - //setMinimumSize(Gui.getScaledDimension(550, 650)); if (modalParent != null) { Gui.centerShellOverShell(modalParent, this); } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/Wizard.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/Wizard.java index 2907ebc4..35a4ddad 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/Wizard.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/Wizard.java @@ -1,10 +1,11 @@ package org.openslx.dozmod.gui.wizard; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Window; +import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.helper.I18n; +import org.openslx.dozmod.gui.helper.StatusHeader; + +import javax.swing.*; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; @@ -12,27 +13,9 @@ import java.awt.event.WindowEvent; import java.util.ArrayList; import java.util.List; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.JSeparator; -import javax.swing.SwingConstants; - -import org.openslx.dozmod.gui.Gui; -import org.openslx.dozmod.gui.control.QLabel; -import org.openslx.dozmod.gui.helper.GridManager; -import org.openslx.dozmod.gui.helper.I18n; -import org.openslx.dozmod.util.ResourceLoader; +@SuppressWarnings("serial") public abstract class Wizard extends JDialog { -@SuppressWarnings("serial") -public abstract class Wizard extends JDialog { - - private final QLabel titleLabel; - private final QLabel messageLabel; + private final StatusHeader header; private final List<WizardPage> pages = new ArrayList<>(); private WizardPage postFinishPage = null; private boolean isPostFinish = false; @@ -52,28 +35,8 @@ public abstract class Wizard extends JDialog { super(parent, ModalityType.APPLICATION_MODAL); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); setLayout(new BorderLayout()); - JPanel header = new JPanel(); - header.setMinimumSize(Gui.getScaledDimension(0, 100)); - header.setOpaque(true); - header.setBackground(Color.WHITE); - header.setLayout(new BoxLayout(header, BoxLayout.PAGE_AXIS)); - header.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - // Labels in header - titleLabel = new QLabel("<title>"); - messageLabel = new QLabel("<message>"); - titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD)); - titleLabel.setForeground(Color.BLACK); - messageLabel.setForeground(Color.BLACK); - messageLabel.setHorizontalTextPosition(SwingConstants.RIGHT); - header.add(titleLabel); - header.add(messageLabel); - // Add header - JPanel headerWrapper = new JPanel(); - GridManager grid = new GridManager(headerWrapper, 1, false); - grid.add(header).expand(true, false).fill(true, false); - grid.add(new JSeparator()).expand(true, false).fill(true, false); - grid.finish(false); - getContentPane().add(headerWrapper, BorderLayout.PAGE_START); + + this.header = new StatusHeader(getContentPane(), "<titel>", "<message>"); // Buttons in footer JPanel footer = new JPanel(); footer.setLayout(new BoxLayout(footer, BoxLayout.LINE_AXIS)); @@ -104,41 +67,34 @@ public abstract class Wizard extends JDialog { // Window events addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent we) { + @Override public void windowClosing(WindowEvent we) { doCancel(); } }); // Äkschns btnNext.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { + @Override public void actionPerformed(ActionEvent e) { doNext(); } }); btnPrev.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { + @Override public void actionPerformed(ActionEvent e) { doPrevious(); } }); btnCancel.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { + @Override public void actionPerformed(ActionEvent e) { doCancel(); } }); btnFinish.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { + @Override public void actionPerformed(ActionEvent e) { doFinish(); } }); } - @SuppressWarnings("deprecation") - @Override - public void show() { + @SuppressWarnings("deprecation") @Override public void show() { if (needsLayout) { needsLayout = false; pack(); @@ -180,9 +136,8 @@ public abstract class Wizard extends JDialog { // Show an out of order page e.g. for converting an image /** - * - * @param NewPage to return to. - * @param OldPage that should be hidden. + * @param newPage to return to. + * @param oldPage that should be hidden. */ public void returnAfterOutOfOrderPage(WizardPage newPage, WizardPage oldPage) { oldPage.onPageLeave(); @@ -204,12 +159,7 @@ public abstract class Wizard extends JDialog { pageTitle = "Step " + currentPage; if (pageDesc == null) pageDesc = ""; - titleLabel.setText(pageTitle); - messageLabel.setText(pageDesc); - messageLabel.setIcon( - ResourceLoader.getScaledIcon(page.getMessageIcon(), messageLabel.getHeight(), messageLabel)); - messageLabel.setForeground(page.getMessageColor()); - messageLabel.validate(); + header.updateHeader(pageTitle, pageDesc, page.getMessageIcon(), page.getMessageColor()); setTitle(getWindowTitle() + " - " + pageTitle); } @@ -265,7 +215,7 @@ public abstract class Wizard extends JDialog { /** * Returns whether the page currently shown is the summary page. - * + * * @return whether the page currently shown is the summary page. */ protected final boolean isSummaryPage() { @@ -275,7 +225,7 @@ public abstract class Wizard extends JDialog { /** * Returns true if the wizard was cancelled. Mostly useful in onPageLeave to * distinguish what's happening. - * + * * @return true if the wizard was cancelled. */ public final boolean isCancelled() { @@ -364,7 +314,7 @@ public abstract class Wizard extends JDialog { /** * User clicked cancel or (X) - when returning false, * wizard will stay open - * + * * @return */ protected boolean onCancelRequest() { @@ -374,9 +324,9 @@ public abstract class Wizard extends JDialog { /** * Called when user clicks finish. Override to do final checks and take * appropriate actions. - * + * * @return <code>true</code> if finish is allowed, <code>false</code> - * otherwise + * otherwise */ protected boolean wantFinish() { return true; @@ -389,9 +339,9 @@ public abstract class Wizard extends JDialog { * If a wizard page is returned, it will serve as a summary page shown to * the user within the wizard frame. The prev and next buttons will * disappear, and the finish button will change to a close button. - * + * * @return A wizard page that serves as a summary page, or null if the - * wizard should just close + * wizard should just close */ protected WizardPage performFinish() { return null; |