| 1 | |
package org.jtheque.films.view.impl.toolbars; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
import org.jtheque.core.managers.Managers; |
| 20 | |
import org.jtheque.core.managers.view.able.IViewManager; |
| 21 | |
import org.jtheque.core.utils.ui.Borders; |
| 22 | |
import org.jtheque.films.view.impl.actions.actor.AcCancelActor; |
| 23 | |
import org.jtheque.films.view.impl.actions.actor.AcDeleteActor; |
| 24 | |
import org.jtheque.films.view.impl.actions.actor.AcDisplayFilmography; |
| 25 | |
import org.jtheque.films.view.impl.actions.actor.AcEditActor; |
| 26 | |
import org.jtheque.films.view.impl.actions.actor.AcNewActor; |
| 27 | |
import org.jtheque.films.view.impl.actions.actor.AcSaveActor; |
| 28 | |
import org.jtheque.primary.view.able.ToolbarView; |
| 29 | |
import org.jtheque.primary.view.able.ViewMode; |
| 30 | |
import org.jtheque.utils.ui.GridBagUtils; |
| 31 | |
|
| 32 | |
import javax.swing.Box; |
| 33 | |
import javax.swing.JButton; |
| 34 | |
import javax.swing.JPanel; |
| 35 | |
import java.awt.Color; |
| 36 | |
import java.awt.GridBagConstraints; |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
public final class JPanelActorToolBar extends JPanel implements ToolbarView { |
| 44 | |
private static final long serialVersionUID = -688094676844153411L; |
| 45 | |
|
| 46 | |
private final JButton buttonAdd; |
| 47 | |
private final JButton buttonEdit; |
| 48 | |
private final JButton buttonSave; |
| 49 | |
private final JButton buttonCancel; |
| 50 | |
private final JButton buttonDelete; |
| 51 | |
private final JButton buttonFilmo; |
| 52 | |
|
| 53 | 0 | private ViewMode mode = ViewMode.VIEW; |
| 54 | |
|
| 55 | 0 | private final GridBagUtils gbc = new GridBagUtils(); |
| 56 | |
|
| 57 | |
public JPanelActorToolBar() { |
| 58 | 0 | super(); |
| 59 | |
|
| 60 | 0 | setBackground(Color.white); |
| 61 | 0 | setBorder(Borders.DIALOG_BORDER); |
| 62 | |
|
| 63 | 0 | buttonSave = new JButton(new AcSaveActor()); |
| 64 | 0 | buttonCancel = new JButton(new AcCancelActor()); |
| 65 | 0 | buttonDelete = new JButton(new AcDeleteActor()); |
| 66 | 0 | buttonAdd = new JButton(new AcNewActor()); |
| 67 | 0 | buttonEdit = new JButton(new AcEditActor()); |
| 68 | 0 | buttonFilmo = new JButton(new AcDisplayFilmography()); |
| 69 | |
|
| 70 | 0 | add(Box.createHorizontalGlue(), gbc.gbcSet(0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.BASELINE_LEADING, 1.0, 1.0)); |
| 71 | |
|
| 72 | 0 | if (mode == ViewMode.VIEW) { |
| 73 | 0 | addViewModeButtons(); |
| 74 | |
} else { |
| 75 | 0 | addOtherModesButtons(); |
| 76 | |
} |
| 77 | 0 | } |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
private void addViewModeButtons() { |
| 83 | 0 | add(buttonAdd, gbc.gbcSet(1, 0)); |
| 84 | 0 | add(buttonEdit, gbc.gbcSet(2, 0)); |
| 85 | 0 | add(buttonDelete, gbc.gbcSet(3, 0)); |
| 86 | 0 | add(buttonFilmo, gbc.gbcSet(4, 0)); |
| 87 | 0 | } |
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
private void addOtherModesButtons() { |
| 93 | 0 | add(buttonSave, gbc.gbcSet(1, 0)); |
| 94 | 0 | add(buttonCancel, gbc.gbcSet(2, 0)); |
| 95 | 0 | } |
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
void setMode(ViewMode mode) { |
| 103 | 0 | if (this.mode != mode) { |
| 104 | 0 | this.mode = mode; |
| 105 | |
|
| 106 | 0 | remove(buttonSave); |
| 107 | 0 | remove(buttonCancel); |
| 108 | 0 | remove(buttonAdd); |
| 109 | 0 | remove(buttonEdit); |
| 110 | 0 | remove(buttonFilmo); |
| 111 | 0 | remove(buttonDelete); |
| 112 | |
|
| 113 | 0 | switch (mode) { |
| 114 | |
case VIEW: |
| 115 | 0 | addViewModeButtons(); |
| 116 | |
|
| 117 | 0 | break; |
| 118 | |
case NEW: |
| 119 | |
case EDIT: |
| 120 | |
case AUTO: |
| 121 | 0 | addOtherModesButtons(); |
| 122 | |
|
| 123 | |
break; |
| 124 | |
} |
| 125 | |
|
| 126 | 0 | Managers.getManager(IViewManager.class).refresh(this); |
| 127 | |
} |
| 128 | 0 | } |
| 129 | |
|
| 130 | |
@Override |
| 131 | |
public void setDisplayMode(ViewMode mode) { |
| 132 | 0 | setMode(mode); |
| 133 | 0 | } |
| 134 | |
} |