| 1 | |
package org.jtheque.core.managers.view.impl.components.panel; |
| 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.language.ILanguageManager; |
| 21 | |
import org.jtheque.core.managers.module.IModuleManager; |
| 22 | |
import org.jtheque.core.managers.update.repository.ModuleDescription; |
| 23 | |
import org.jtheque.core.managers.update.versions.VersionsFile; |
| 24 | |
import org.jtheque.core.managers.update.versions.VersionsFileReader; |
| 25 | |
import org.jtheque.core.managers.view.able.IViewManager; |
| 26 | |
import org.jtheque.core.managers.view.able.ViewDefaults; |
| 27 | |
import org.jtheque.core.utils.ui.PanelBuilder; |
| 28 | |
|
| 29 | |
import javax.swing.JLabel; |
| 30 | |
import javax.swing.JPanel; |
| 31 | |
import java.awt.Color; |
| 32 | |
import java.awt.Font; |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
public final class ModulePanel extends JPanel { |
| 40 | |
private final JLabel labelName; |
| 41 | |
private final JLabel labelDescription; |
| 42 | |
private final JLabel onlineLabel; |
| 43 | |
private final JLabel currentLabel; |
| 44 | |
|
| 45 | |
private final ModuleDescription module; |
| 46 | |
|
| 47 | |
private static final int TITLE_FONT_SIZE = 16; |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
public ModulePanel(Object value, boolean isSelected) { |
| 56 | 0 | super(); |
| 57 | |
|
| 58 | 0 | PanelBuilder builder = new PanelBuilder(this); |
| 59 | |
|
| 60 | 0 | module = (ModuleDescription) value; |
| 61 | |
|
| 62 | 0 | labelName = builder.add(new JLabel(module.getName()), builder.gbcSet(0, 0)); |
| 63 | 0 | labelName.setFont(labelName.getFont().deriveFont(Font.BOLD, TITLE_FONT_SIZE)); |
| 64 | |
|
| 65 | 0 | labelDescription = builder.add(new JLabel(module.getDescription().toString()), builder.gbcSet(0, 1)); |
| 66 | |
|
| 67 | 0 | onlineLabel = builder.addLabel("...", builder.gbcSet(0, 3)); |
| 68 | 0 | currentLabel = builder.addLabel("...", builder.gbcSet(0, 4)); |
| 69 | |
|
| 70 | 0 | setSelected(isSelected); |
| 71 | 0 | } |
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
public void setSelected(boolean isSelected) { |
| 79 | 0 | ViewDefaults defaults = Managers.getManager(IViewManager.class).getViewDefaults(); |
| 80 | |
|
| 81 | 0 | if (isSelected) { |
| 82 | 0 | setColors(defaults.getSelectedBackgroundColor(), defaults.getSelectedForegroundColor()); |
| 83 | |
} else { |
| 84 | 0 | setColors(defaults.getBackgroundColor(), defaults.getForegroundColor()); |
| 85 | |
} |
| 86 | 0 | } |
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
private void setColors(Color background, Color foreground) { |
| 95 | 0 | setBackground(background); |
| 96 | |
|
| 97 | 0 | labelName.setBackground(background); |
| 98 | 0 | labelDescription.setBackground(background); |
| 99 | 0 | onlineLabel.setBackground(background); |
| 100 | 0 | currentLabel.setBackground(background); |
| 101 | |
|
| 102 | 0 | labelName.setForeground(foreground); |
| 103 | 0 | labelDescription.setForeground(foreground); |
| 104 | 0 | onlineLabel.setForeground(foreground); |
| 105 | 0 | currentLabel.setForeground(foreground); |
| 106 | 0 | } |
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
public void expand() { |
| 112 | 0 | VersionsFile file = new VersionsFileReader().readURL(module.getVersionsFileURL()); |
| 113 | |
|
| 114 | 0 | onlineLabel.setText(Managers.getManager(ILanguageManager.class).getMessage( |
| 115 | |
"repository.module.online", |
| 116 | |
file.getMostRecentVersion().getStringVersion())); |
| 117 | |
|
| 118 | 0 | if (Managers.getManager(IModuleManager.class).isInstalled(module.getId())) { |
| 119 | 0 | currentLabel.setText(Managers.getManager(ILanguageManager.class).getMessage( |
| 120 | |
"repository.module.current", |
| 121 | |
Managers.getManager(IModuleManager.class).getModuleById(module.getId()).getInfos().version())); |
| 122 | |
} else { |
| 123 | 0 | currentLabel.setText(Managers.getManager(ILanguageManager.class).getMessage("repository.module.current.notinstalled")); |
| 124 | |
} |
| 125 | 0 | } |
| 126 | |
} |