| 1 | |
package org.jtheque.core.managers.view.impl.components.config; |
| 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.core.CoreConfiguration; |
| 21 | |
import org.jtheque.core.managers.error.JThequeError; |
| 22 | |
import org.jtheque.core.managers.language.ILanguageManager; |
| 23 | |
import org.jtheque.core.managers.view.able.config.IAppearanceConfigView; |
| 24 | |
import org.jtheque.core.managers.view.impl.components.model.AvailableLanguagesComboBoxModel; |
| 25 | |
import org.jtheque.core.utils.ui.Borders; |
| 26 | |
import org.jtheque.core.utils.ui.PanelBuilder; |
| 27 | |
import org.jtheque.core.utils.ui.ValidationUtils; |
| 28 | |
import org.jtheque.utils.ui.GridBagUtils; |
| 29 | |
|
| 30 | |
import javax.swing.JCheckBox; |
| 31 | |
import javax.swing.JComponent; |
| 32 | |
import javax.swing.JPanel; |
| 33 | |
import java.util.Collection; |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
public final class JPanelConfigAppearance extends JPanel implements ConfigTabComponent, IAppearanceConfigView { |
| 41 | |
private AvailableLanguagesComboBoxModel modelLanguages; |
| 42 | |
private JCheckBox boxRetainSizeAndPosition; |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
public JPanelConfigAppearance() { |
| 48 | 0 | super(); |
| 49 | |
|
| 50 | 0 | PanelBuilder builder = new PanelBuilder(this); |
| 51 | |
|
| 52 | 0 | addPanelGeneral(builder); |
| 53 | 0 | addPanelLookAndFeel(builder); |
| 54 | |
|
| 55 | 0 | fillAllFields(); |
| 56 | 0 | } |
| 57 | |
|
| 58 | |
@Override |
| 59 | |
public String getTitle() { |
| 60 | 0 | return Managers.getManager(ILanguageManager.class).getMessage("config.view.tab.appearance"); |
| 61 | |
} |
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
private void addPanelGeneral(PanelBuilder parent) { |
| 69 | 0 | PanelBuilder builder = parent.addPanel(parent.gbcSet(0, 0, GridBagUtils.HORIZONTAL, GridBagUtils.FIRST_LINE_START)); |
| 70 | 0 | builder.getPanel().setBorder(Borders.createTitledBorder("config.appearance.general.title")); |
| 71 | |
|
| 72 | 0 | builder.addI18nLabel("config.appearance.language", parent.gbcSet(0, 0)); |
| 73 | |
|
| 74 | 0 | modelLanguages = new AvailableLanguagesComboBoxModel(); |
| 75 | |
|
| 76 | 0 | builder.addComboBox(modelLanguages, parent.gbcSet(1, 0, GridBagUtils.HORIZONTAL)); |
| 77 | |
|
| 78 | 0 | boxRetainSizeAndPosition = builder.addI18nCheckBox("config.appearance.size", |
| 79 | |
parent.gbcSet(0, 1, GridBagUtils.HORIZONTAL, GridBagUtils.BASELINE_LEADING, 2, 1)); |
| 80 | 0 | } |
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
private static void addPanelLookAndFeel(PanelBuilder parent) { |
| 88 | 0 | PanelBuilder builder = parent.addPanel(parent.gbcSet(0, 1, GridBagUtils.HORIZONTAL, GridBagUtils.FIRST_LINE_START)); |
| 89 | 0 | builder.getPanel().setBorder(Borders.createTitledBorder("config.appearance.lookandfeel")); |
| 90 | 0 | } |
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
private void fillAllFields() { |
| 96 | 0 | modelLanguages.setSelectedItem(Managers.getManager(ILanguageManager.class).getCurrentLanguage()); |
| 97 | 0 | boxRetainSizeAndPosition.setSelected(Managers.getCore().getConfiguration().retainSizeAndPositionOfWindow()); |
| 98 | 0 | } |
| 99 | |
|
| 100 | |
@Override |
| 101 | |
public void apply() { |
| 102 | 0 | CoreConfiguration configuration = Managers.getCore().getConfiguration(); |
| 103 | |
|
| 104 | 0 | Managers.getManager(ILanguageManager.class).setCurrentLanguage(modelLanguages.getSelectedLanguage()); |
| 105 | 0 | configuration.setRetainSizeAndPositionOfWindow(boxRetainSizeAndPosition.isSelected()); |
| 106 | 0 | } |
| 107 | |
|
| 108 | |
@Override |
| 109 | |
public void cancel() { |
| 110 | 0 | fillAllFields(); |
| 111 | 0 | } |
| 112 | |
|
| 113 | |
@Override |
| 114 | |
public void validate(Collection<JThequeError> errors) { |
| 115 | 0 | ValidationUtils.rejectIfNothingSelected(modelLanguages, "config.appearance.language", errors); |
| 116 | 0 | } |
| 117 | |
|
| 118 | |
@Override |
| 119 | |
public JComponent getComponent() { |
| 120 | 0 | return this; |
| 121 | |
} |
| 122 | |
} |