1 package org.ozoneDB.adminGui.main; 9 10 import java.awt.*; 11 import javax.swing.*; 12 13 import org.ozoneDB.adminGui.feature.Feature; 14 import org.ozoneDB.adminGui.res.Images; 15 import org.ozoneDB.adminGui.res.Settings; 16 17 20 public class HeaderPanel extends JPanel { 21 22 private static final Dimension DIMENSION = new Dimension(Settings.HEADER_WIDTH, Settings.HEADER_HEIGHT); 23 private static final Font HEADER_FONT = new Font(null, Font.PLAIN, 20); 24 25 private static final String NOT_CONNECTED = "Not connected"; 26 27 private JLabel dbInfoLabel; 28 private JLabel featureLabel; 29 private JLabel dashLabel; 30 private JLabel imageLabel; 31 private JLabel connectionLabel; 32 ImageIcon connectedIcon = new ImageIcon(this.getClass().getResource(Images.IMAGE_CONNECTED)); 33 ImageIcon disconnectedIcon = new ImageIcon(this.getClass().getResource(Images.IMAGE_DISCONNECTED)); 34 35 public HeaderPanel(String featureName) { 36 initPanel(); 37 this.setLayout(new GridBagLayout()); 38 39 GridBagConstraints gbc = new GridBagConstraints(); 40 gbc.anchor = GridBagConstraints.WEST; 41 gbc.insets = new Insets(2, 2, 2, 2); 42 43 gbc.weightx = 0; 44 connectionLabel = new JLabel(new ImageIcon(this.getClass().getResource(Images.IMAGE_DISCONNECTED))); 45 this.add(connectionLabel, gbc); 46 47 gbc.weightx = 1; 48 dbInfoLabel = new JLabel(NOT_CONNECTED); 49 formatLabel(dbInfoLabel); 50 add(dbInfoLabel, gbc); 51 52 gbc.anchor = GridBagConstraints.EAST; 53 featureLabel = new JLabel(featureName); 54 formatLabel(featureLabel); 55 add(featureLabel, gbc); 56 57 58 dashLabel = new JLabel(" - "); 59 formatLabel(dashLabel); 60 add(dashLabel, gbc); 61 dashLabel.setVisible(false); 62 63 gbc.weightx = 0; 64 imageLabel = new JLabel(); 66 this.add(imageLabel, gbc); 67 } 68 69 private void initPanel() { 70 setPreferredSize(DIMENSION); 71 setMaximumSize(DIMENSION); 72 setMinimumSize(DIMENSION); 73 setBackground(Color.white); 74 setBorder(BorderFactory.createEmptyBorder()); 75 } 77 78 public void setHeader(Feature feature) { 79 setFeatureName(feature.getName()); 80 setImage(feature.getImage()); 81 } 82 83 private void setFeatureName(String featureName) { 84 dashLabel.setVisible(false); 85 featureLabel.setText(featureName); 86 } 87 88 89 public void setSearchable(String searchable) { 90 dbInfoLabel.setText(searchable); 91 } 92 93 private void setImage(ImageIcon image) { 94 imageLabel.setIcon(image); 95 } 96 97 private void formatLabel(JLabel label) { 98 label.setHorizontalAlignment(JLabel.LEFT); 99 label.setForeground(Color.darkGray); 100 label.setFont(HEADER_FONT); 101 } 102 103 public String getSearchable() { 104 return dbInfoLabel.getText(); 105 } 106 107 public void setConnected(String url) { 108 connectionLabel.setIcon(connectedIcon); 109 dbInfoLabel.setText(url); 110 } 111 112 public void setDisConnected() { 113 connectionLabel.setIcon(disconnectedIcon); 114 dbInfoLabel.setText(NOT_CONNECTED); 115 } 116 } | Popular Tags |