| 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.auto.add.AcAutoAddFilm; |
| 23 | |
import org.jtheque.films.view.impl.actions.film.AcAutoEdit; |
| 24 | |
import org.jtheque.films.view.impl.actions.film.AcCancel; |
| 25 | |
import org.jtheque.films.view.impl.actions.film.AcDelete; |
| 26 | |
import org.jtheque.films.view.impl.actions.film.AcExportFilm; |
| 27 | |
import org.jtheque.films.view.impl.actions.film.AcManualEdit; |
| 28 | |
import org.jtheque.films.view.impl.actions.film.AcNewFilm; |
| 29 | |
import org.jtheque.films.view.impl.actions.film.AcPrintFilm; |
| 30 | |
import org.jtheque.films.view.impl.actions.film.AcSaveFilm; |
| 31 | |
import org.jtheque.films.view.impl.actions.film.AcSendFilmByMail; |
| 32 | |
import org.jtheque.primary.view.able.ToolbarView; |
| 33 | |
import org.jtheque.primary.view.able.ViewMode; |
| 34 | |
import org.jtheque.primary.view.impl.components.JDropDownButton; |
| 35 | |
import org.jtheque.utils.ui.GridBagUtils; |
| 36 | |
|
| 37 | |
import javax.swing.Box; |
| 38 | |
import javax.swing.JButton; |
| 39 | |
import javax.swing.JPanel; |
| 40 | |
import java.awt.Color; |
| 41 | |
import java.awt.GridBagConstraints; |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
public final class JPanelFilmToolBar extends JPanel implements ToolbarView { |
| 49 | |
private final JDropDownButton buttonAdd; |
| 50 | |
private final JDropDownButton buttonEdit; |
| 51 | |
private final JDropDownButton buttonOther; |
| 52 | |
|
| 53 | |
private final JButton buttonSave; |
| 54 | |
private final JButton buttonCancel; |
| 55 | |
private final JButton buttonDelete; |
| 56 | |
|
| 57 | 0 | private ViewMode mode = ViewMode.VIEW; |
| 58 | |
|
| 59 | 0 | private final GridBagUtils gbc = new GridBagUtils(); |
| 60 | |
|
| 61 | |
public JPanelFilmToolBar() { |
| 62 | 0 | super(); |
| 63 | |
|
| 64 | 0 | setBackground(Color.white); |
| 65 | 0 | setBorder(Borders.DIALOG_BORDER); |
| 66 | |
|
| 67 | 0 | buttonSave = new JButton(new AcSaveFilm()); |
| 68 | 0 | buttonCancel = new JButton(new AcCancel()); |
| 69 | 0 | buttonDelete = new JButton(new AcDelete()); |
| 70 | |
|
| 71 | 0 | buttonAdd = new JDropDownButton(new AcNewFilm(), new AcAutoAddFilm()); |
| 72 | 0 | buttonEdit = new JDropDownButton(new AcManualEdit(), new AcAutoEdit()); |
| 73 | 0 | buttonOther = new JDropDownButton(new AcPrintFilm(), new AcSendFilmByMail(), new AcExportFilm()); |
| 74 | |
|
| 75 | 0 | add(Box.createHorizontalGlue(), gbc.gbcSet(0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.BASELINE_LEADING, 1.0, 1.0)); |
| 76 | |
|
| 77 | 0 | if (mode == ViewMode.VIEW) { |
| 78 | 0 | addViewModeButtons(); |
| 79 | |
} else { |
| 80 | 0 | addOtherModesButton(); |
| 81 | |
} |
| 82 | 0 | } |
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
void setMode(ViewMode mode) { |
| 90 | 0 | if (this.mode != mode) { |
| 91 | |
|
| 92 | 0 | this.mode = mode; |
| 93 | |
|
| 94 | 0 | remove(buttonSave); |
| 95 | 0 | remove(buttonCancel); |
| 96 | 0 | remove(buttonAdd); |
| 97 | 0 | remove(buttonEdit); |
| 98 | 0 | remove(buttonOther); |
| 99 | 0 | remove(buttonDelete); |
| 100 | |
|
| 101 | 0 | switch (mode) { |
| 102 | |
case VIEW: |
| 103 | 0 | addViewModeButtons(); |
| 104 | |
|
| 105 | 0 | break; |
| 106 | |
case NEW: |
| 107 | |
case EDIT: |
| 108 | |
case AUTO: |
| 109 | 0 | addOtherModesButton(); |
| 110 | |
|
| 111 | |
break; |
| 112 | |
} |
| 113 | |
|
| 114 | 0 | Managers.getManager(IViewManager.class).refresh(this); |
| 115 | |
} |
| 116 | 0 | } |
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
private void addViewModeButtons() { |
| 122 | 0 | add(buttonAdd, gbc.gbcSet(1, 0)); |
| 123 | 0 | add(buttonEdit, gbc.gbcSet(2, 0)); |
| 124 | 0 | add(buttonDelete, gbc.gbcSet(3, 0)); |
| 125 | 0 | add(buttonOther, gbc.gbcSet(4, 0)); |
| 126 | 0 | } |
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
private void addOtherModesButton() { |
| 132 | 0 | add(buttonSave, gbc.gbcSet(1, 0)); |
| 133 | 0 | add(buttonCancel, gbc.gbcSet(2, 0)); |
| 134 | 0 | } |
| 135 | |
|
| 136 | |
@Override |
| 137 | |
public void setDisplayMode(ViewMode mode) { |
| 138 | 0 | setMode(mode); |
| 139 | 0 | } |
| 140 | |
} |