| 1 | |
package org.jtheque.core.managers.view.impl.components.filthy.java2d; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
import org.jdesktop.swingx.JXPanel; |
| 20 | |
import org.jtheque.core.managers.Managers; |
| 21 | |
import org.jtheque.core.managers.view.able.ICollectionView; |
| 22 | |
import org.jtheque.core.managers.view.able.IViewManager; |
| 23 | |
import org.jtheque.core.managers.view.impl.actions.collections.CancelAction; |
| 24 | |
import org.jtheque.core.managers.view.impl.actions.collections.ChooseAction; |
| 25 | |
import org.jtheque.core.managers.view.impl.actions.collections.CreateAction; |
| 26 | |
import org.jtheque.core.managers.view.impl.components.JThequeI18nLabel; |
| 27 | |
import org.jtheque.core.managers.view.impl.components.filthy.FilthyPasswordField; |
| 28 | |
import org.jtheque.core.managers.view.impl.components.filthy.FilthyTextField; |
| 29 | |
import org.jtheque.core.utils.ui.AnimationUtils; |
| 30 | |
import org.jtheque.utils.ui.GridBagUtils; |
| 31 | |
|
| 32 | |
import javax.annotation.PostConstruct; |
| 33 | |
import javax.swing.Box; |
| 34 | |
import javax.swing.JButton; |
| 35 | |
import javax.swing.JLabel; |
| 36 | |
import javax.swing.JPanel; |
| 37 | |
import java.awt.Color; |
| 38 | |
import java.awt.Component; |
| 39 | |
import java.awt.Container; |
| 40 | |
import java.awt.Font; |
| 41 | |
import java.awt.Graphics; |
| 42 | |
import java.awt.GridBagConstraints; |
| 43 | |
import java.awt.GridBagLayout; |
| 44 | |
import java.awt.Insets; |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | 0 | public final class CollectionPane extends JXPanel implements ICollectionView { |
| 50 | |
private FilthyTextField textField; |
| 51 | |
private FilthyPasswordField passwordField; |
| 52 | |
private JLabel labelError; |
| 53 | |
|
| 54 | |
private Color hintColor; |
| 55 | |
private Color backgroundColor; |
| 56 | |
private Color errorColor; |
| 57 | |
|
| 58 | |
private Font hintFont; |
| 59 | |
private static final int LEFT_MARGIN_WIDTH = 200; |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
@PostConstruct |
| 65 | |
void build() { |
| 66 | 0 | setOpaque(true); |
| 67 | 0 | setBackground(backgroundColor); |
| 68 | 0 | setAlpha(1.0f); |
| 69 | 0 | setLayout(new GridBagLayout()); |
| 70 | |
|
| 71 | 0 | GridBagUtils gbc = new GridBagUtils(); |
| 72 | |
|
| 73 | 0 | gbc.setDefaultInsets(new Insets(0, 0, 0, 0)); |
| 74 | |
|
| 75 | 0 | add(Box.createVerticalStrut(Managers.getManager(IViewManager.class).getViews().getMainView().getHeight() / 3), |
| 76 | |
gbc.gbcSet(0, 0, GridBagConstraints.NONE, GridBagConstraints.CENTER, 4, 1, 1.0, 0.0)); |
| 77 | |
|
| 78 | 0 | add(Box.createHorizontalStrut(LEFT_MARGIN_WIDTH), gbc.gbcSet(0, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, 1, 4, 0.3, 0.0)); |
| 79 | |
|
| 80 | 0 | addErrorLabel(gbc); |
| 81 | |
|
| 82 | 0 | add(Box.createHorizontalStrut(LEFT_MARGIN_WIDTH), gbc.gbcSet(3, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, 1, 4, 0.3, 0.0)); |
| 83 | |
|
| 84 | 0 | addCollectionField(gbc); |
| 85 | 0 | addPasswordField(gbc); |
| 86 | 0 | addButtonBar(gbc); |
| 87 | |
|
| 88 | 0 | add(Box.createVerticalGlue(), gbc.gbcSet(0, 5, GridBagConstraints.VERTICAL, GridBagConstraints.CENTER, 4, 1, 1.0, 1.0)); |
| 89 | 0 | } |
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
private void addErrorLabel(GridBagUtils gbc) { |
| 97 | 0 | labelError = new JLabel(); |
| 98 | 0 | labelError.setForeground(errorColor); |
| 99 | 0 | labelError.setVisible(false); |
| 100 | 0 | labelError.setFont(hintFont); |
| 101 | |
|
| 102 | 0 | add(labelError, gbc.gbcSet(1, 1, GridBagConstraints.NONE, GridBagConstraints.LINE_START, 2, 1)); |
| 103 | 0 | } |
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
private void addButtonBar(GridBagUtils gbc) { |
| 111 | 0 | Container buttonsPanel = new JPanel(); |
| 112 | |
|
| 113 | 0 | buttonsPanel.add(new JButton(new CreateAction())); |
| 114 | 0 | buttonsPanel.add(new JButton(new ChooseAction())); |
| 115 | 0 | buttonsPanel.add(new JButton(new CancelAction())); |
| 116 | |
|
| 117 | 0 | buttonsPanel.setBackground(backgroundColor); |
| 118 | |
|
| 119 | 0 | gbc.setDefaultInsets(new Insets(0, 0, 0, 0)); |
| 120 | |
|
| 121 | 0 | add(buttonsPanel, gbc.gbcSet(1, 4, GridBagConstraints.NONE, GridBagConstraints.LINE_END, 2, 1, 1.0, 0.0)); |
| 122 | 0 | } |
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
private void addPasswordField(GridBagUtils gbc) { |
| 130 | 0 | Component labelPassword = new JThequeI18nLabel("collections.password"); |
| 131 | |
|
| 132 | 0 | labelPassword.setForeground(hintColor); |
| 133 | 0 | labelPassword.setFont(hintFont); |
| 134 | |
|
| 135 | 0 | gbc.setDefaultInsets(new Insets(0, 0, 2, 6)); |
| 136 | |
|
| 137 | 0 | add(labelPassword, gbc.gbcSet(1, 3, GridBagConstraints.NONE, GridBagConstraints.LINE_START)); |
| 138 | |
|
| 139 | 0 | passwordField = new FilthyPasswordField(); |
| 140 | |
|
| 141 | 0 | gbc.setDefaultInsets(new Insets(0, 2, 6, 2)); |
| 142 | |
|
| 143 | 0 | add(passwordField, gbc.gbcSet(2, 3, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, 1.0, 0.0)); |
| 144 | 0 | } |
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
private void addCollectionField(GridBagUtils gbc) { |
| 152 | 0 | Component labelCollection = new JThequeI18nLabel("collections.name"); |
| 153 | |
|
| 154 | 0 | labelCollection.setForeground(hintColor); |
| 155 | 0 | labelCollection.setFont(hintFont); |
| 156 | |
|
| 157 | 0 | gbc.setDefaultInsets(new Insets(0, 0, 2, 6)); |
| 158 | |
|
| 159 | 0 | add(labelCollection, gbc.gbcSet(1, 2, GridBagConstraints.NONE, GridBagConstraints.LINE_START)); |
| 160 | |
|
| 161 | 0 | gbc.setDefaultInsets(new Insets(0, 0, 0, 0)); |
| 162 | |
|
| 163 | 0 | textField = new FilthyTextField(); |
| 164 | |
|
| 165 | 0 | gbc.setDefaultInsets(new Insets(0, 2, 6, 2)); |
| 166 | |
|
| 167 | 0 | add(textField, gbc.gbcSet(2, 2, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, 1.0, 0.0)); |
| 168 | 0 | } |
| 169 | |
|
| 170 | |
@Override |
| 171 | |
public void setErrorMessage(String message) { |
| 172 | 0 | labelError.setVisible(true); |
| 173 | 0 | labelError.setText(message); |
| 174 | 0 | } |
| 175 | |
|
| 176 | |
@Override |
| 177 | |
public String getCollection() { |
| 178 | 0 | return textField.getText(); |
| 179 | |
} |
| 180 | |
|
| 181 | |
@Override |
| 182 | |
public String getPassword() { |
| 183 | 0 | return passwordField.getPassword(); |
| 184 | |
} |
| 185 | |
|
| 186 | |
@Override |
| 187 | |
public void appear() { |
| 188 | 0 | AnimationUtils.startFadeIn(this); |
| 189 | 0 | } |
| 190 | |
|
| 191 | |
@Override |
| 192 | |
public void paintComponent(Graphics g) { |
| 193 | 0 | g.setColor(Color.black); |
| 194 | 0 | g.fillRect(0, 0, getWidth(), getHeight()); |
| 195 | |
|
| 196 | 0 | super.paintComponent(g); |
| 197 | 0 | } |
| 198 | |
|
| 199 | |
|
| 200 | |
|
| 201 | |
|
| 202 | |
|
| 203 | |
|
| 204 | |
public void setHintColor(Color hintColor) { |
| 205 | 0 | this.hintColor = hintColor; |
| 206 | 0 | } |
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
public void setBackgroundColor(Color backgroundColor) { |
| 214 | 0 | this.backgroundColor = backgroundColor; |
| 215 | 0 | } |
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
public void setErrorColor(Color errorColor) { |
| 223 | 0 | this.errorColor = errorColor; |
| 224 | 0 | } |
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
public void setHintFont(Font hintFont) { |
| 232 | 0 | this.hintFont = hintFont; |
| 233 | 0 | } |
| 234 | |
|
| 235 | |
@Override |
| 236 | |
public Component getImpl() { |
| 237 | 0 | return this; |
| 238 | |
} |
| 239 | |
} |