package ch.metalnet.fotouploader.view;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.util.Date;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.BevelBorder;
import org.apache.log4j.Logger;
import ch.metalnet.fotouploader.Messages;
import ch.metalnet.fotouploader.controlling.SettingsHandler;
import ch.metalnet.fotouploader.objects.Canton;
import ch.metalnet.fotouploader.view.elements.StatusBar;
import com.michaelbaranov.microba.calendar.DatePicker;
public class UserInterface extends JFrame {
private final int windowWith = 600;
private final int windowHeight = 550;
private JMenuBar menuBar;
private JMenu fileMenu;
private JMenuItem settingsMenuItem;
private JMenuItem exitMenuItem;
private JMenu helpMenu;
private JMenuItem helpMenuItem;
private JMenuItem aboutMenuItem;
private JPanel contentPanel;
private JButton openDirButton;
private JLabel dirPathLabel;
private JTextField categoryNameField;
private JLabel categoryNameLabel;
private JList fotoList;
private StatusBar statusBar;
private JScrollPane fotoListScrollPane;
private JLabel previewLabel;
private JButton startButton;
private JComboBox cantonCombo;
private JLabel cantonLabel;
private JLabel dateFromLabel;
private JLabel dateToLabel;
private DatePicker fromCalendar;
private DatePicker toCalendar;
private JCheckBox openStatusBox;
private JLabel locationLabel;
private JTextField locationField;
private JTextArea descriptionField;
private JLabel descriptionLabel;
protected static Logger logger = Logger.getLogger(UserInterface.class);
public UserInterface() {
try {
UIManager.setLookAndFeel("com.lipstikLF.LipstikLookAndFeel");
} catch (ClassNotFoundException e) {
logger.error("LookAndFeel: ", e);
} catch (InstantiationException e) {
logger.error("LookAndFeel: ", e);
} catch (IllegalAccessException e) {
logger.error("LookAndFeel: ", e);
} catch (UnsupportedLookAndFeelException e) {
logger.error("LookAndFeel: ", e);
}
SwingUtilities.updateComponentTreeUI(this);
this.setSize(windowWith, windowHeight);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle(Messages.getString("frame.userInterface.title"));
this.setResizable(false);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation((screenSize.width / 2) - (windowWith / 2),
(screenSize.height / 2) - (windowHeight / 2));
Image icon = Toolkit.getDefaultToolkit().getImage((getClass().getResource("../../../../images/icon.gif")));
this.setIconImage(icon);
this.setJMenuBar(getMyMenuBar());
this.setContentPane(getContentPanel());
getStartButton().setEnabled(false);
getCategoryNameField().setEditable(false);
}
public JMenuItem getAboutMenuItem() {
if (aboutMenuItem == null) {
aboutMenuItem = new JMenuItem();
}
return aboutMenuItem;
}
public JComboBox getCantonCombo() {
if (cantonCombo == null) {
Vector<Canton> cantons = new Vector<Canton>();
cantons.add(new Canton(1, Messages.getString("frame.userInterface.canton.unknown")));
cantons.add(new Canton(2, Messages.getString("frame.userInterface.canton.foreign")));
cantons.add(new Canton(3, Messages.getString("frame.userInterface.canton.ag")));
cantons.add(new Canton(4, Messages.getString("frame.userInterface.canton.ai")));
cantons.add(new Canton(5, Messages.getString("frame.userInterface.canton.ar")));
cantons.add(new Canton(6, Messages.getString("frame.userInterface.canton.bl")));
cantons.add(new Canton(7, Messages.getString("frame.userInterface.canton.bs")));
cantons.add(new Canton(8, Messages.getString("frame.userInterface.canton.be")));
cantons.add(new Canton(9, Messages.getString("frame.userInterface.canton.fr")));
cantons.add(new Canton(10, Messages.getString("frame.userInterface.canton.ge")));
cantons.add(new Canton(11, Messages.getString("frame.userInterface.canton.gl")));
cantons.add(new Canton(12, Messages.getString("frame.userInterface.canton.gr")));
cantons.add(new Canton(13, Messages.getString("frame.userInterface.canton.ju")));
cantons.add(new Canton(14, Messages.getString("frame.userInterface.canton.lu")));
cantons.add(new Canton(15, Messages.getString("frame.userInterface.canton.ne")));
cantons.add(new Canton(16, Messages.getString("frame.userInterface.canton.nw")));
cantons.add(new Canton(17, Messages.getString("frame.userInterface.canton.ow")));
cantons.add(new Canton(18, Messages.getString("frame.userInterface.canton.sh")));
cantons.add(new Canton(19, Messages.getString("frame.userInterface.canton.sz")));
cantons.add(new Canton(20, Messages.getString("frame.userInterface.canton.sg")));
cantons.add(new Canton(21, Messages.getString("frame.userInterface.canton.so")));
cantons.add(new Canton(22, Messages.getString("frame.userInterface.canton.ti")));
cantons.add(new Canton(23, Messages.getString("frame.userInterface.canton.tg")));
cantons.add(new Canton(24, Messages.getString("frame.userInterface.canton.ur")));
cantons.add(new Canton(25, Messages.getString("frame.userInterface.canton.vd")));
cantons.add(new Canton(26, Messages.getString("frame.userInterface.canton.vs")));
cantons.add(new Canton(27, Messages.getString("frame.userInterface.canton.zg")));
cantons.add(new Canton(28, Messages.getString("frame.userInterface.canton.zh")));
cantonCombo = new JComboBox(cantons);
cantonCombo.setSize(140, 20);
cantonCombo.setLocation(295, 70);
}
return cantonCombo;
}
private JLabel getCantonLabel() {
if (cantonLabel == null) {
cantonLabel = new JLabel();
cantonLabel.setSize(50, 20);
cantonLabel.setLocation(220, 70);
cantonLabel.setText(Messages.getString("frame.userInterface.label.canton"));
}
return cantonLabel;
}
public JTextField getCategoryNameField() {
if (categoryNameField == null) {
categoryNameField = new JTextField();
categoryNameField.setLocation(170, 40);
categoryNameField.setSize(windowWith
- getOpenDirButton().getLocation().x
- getOpenDirButton().getSize().width - 35, 20);
categoryNameField.setToolTipText(Messages.getString("frame.userINterface.tooltip.galeryname"));
}
return categoryNameField;
}
private JLabel getCategoryNameLabel() {
if (categoryNameLabel == null) {
categoryNameLabel = new JLabel();
categoryNameLabel.setText(Messages.getString("frame.userInterface.label.category"));
categoryNameLabel.setLocation(10, 40);
categoryNameLabel.setSize(140, 20);
}
return categoryNameLabel;
}
private JPanel getContentPanel() {
if (contentPanel == null) {
contentPanel = new JPanel();
contentPanel.setLayout(null);
contentPanel.add(getOpenDirButton());
contentPanel.add(getDirPathLabel());
contentPanel.add(getCategoryNameLabel());
contentPanel.add(getCategoryNameField());
contentPanel.add(getFotoListScrollPane());
contentPanel.add(getCantonLabel());
contentPanel.add(getCantonCombo());
contentPanel.add(getLocationLabel());
contentPanel.add(getLocationField());
contentPanel.add(getDateFromLabel());
contentPanel.add(getFromCalendar());
contentPanel.add(getDateToLabel());
contentPanel.add(getToCalendar());
contentPanel.add(getDescriptionLabel());
contentPanel.add(getDescriptionField());
contentPanel.add(getStatusBar());
contentPanel.add(getPreviewLabel());
contentPanel.add(getStartButton());
}
return contentPanel;
}
private JLabel getDateFromLabel() {
if (dateFromLabel == null) {
dateFromLabel = new JLabel();
dateFromLabel.setSize(70, 20);
dateFromLabel.setLocation(220, 130);
dateFromLabel.setText(Messages.getString("frame.userInterface.label.date.from"));
}
return dateFromLabel;
}
private JLabel getDateToLabel() {
if (dateToLabel == null) {
dateToLabel = new JLabel();
dateToLabel.setSize(50, 20);
dateToLabel.setLocation(410, 130);
dateToLabel.setText(Messages.getString("frame.userInterface.label.date.to"));
}
return dateToLabel;
}
public JTextArea getDescriptionField() {
if (descriptionField == null) {
descriptionField = new JTextArea();
descriptionField.setSize(310, 70);
descriptionField.setLocation(220, 175);
}
return descriptionField;
}
private JLabel getDescriptionLabel() {
if (descriptionLabel == null) {
descriptionLabel = new JLabel();
descriptionLabel.setSize(200, 70);
descriptionLabel.setLocation(220, 130);
descriptionLabel.setText(Messages.getString("frame.userInterface.label.description"));
}
return descriptionLabel;
}
public JLabel getDirPathLabel() {
if (dirPathLabel == null) {
dirPathLabel = new JLabel();
dirPathLabel.setLocation(170, 10);
dirPathLabel.setSize(windowWith
- getOpenDirButton().getLocation().x
- getOpenDirButton().getSize().width - 35, 20);
dirPathLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
}
return dirPathLabel;
}
public JMenuItem getExitMenuItem() {
if (exitMenuItem == null) {
exitMenuItem = new JMenuItem();
}
return exitMenuItem;
}
private JMenu getFileMenu() {
if (fileMenu == null) {
fileMenu = new JMenu();
fileMenu.setText(Messages.getString("frame.userInterface.menu.file"));
fileMenu.add(getSettingsMenuItem());
fileMenu.add(getExitMenuItem());
}
return fileMenu;
}
public JList getFotoList() {
if (fotoList == null) {
fotoList = new JList();
}
return fotoList;
}
private JScrollPane getFotoListScrollPane() {
if (fotoListScrollPane == null) {
fotoListScrollPane = new JScrollPane();
fotoListScrollPane.setViewportView(getFotoList());
fotoListScrollPane.setLocation(10, 70);
fotoListScrollPane.setSize(200, 400);
}
return fotoListScrollPane;
}
public DatePicker getFromCalendar() {
if (fromCalendar == null) {
Date date = new Date(System.currentTimeMillis());
fromCalendar = new DatePicker(date);
fromCalendar.setSize(90, 20);
fromCalendar.setLocation(295, 130);
}
return fromCalendar;
}
private JMenu getHelpMenu() {
if (helpMenu == null) {
helpMenu = new JMenu();
helpMenu.setText(Messages.getString("frame.userInterface.menu.help"));
helpMenu.add(getHelpMenuItem());
helpMenu.add(getAboutMenuItem());
}
return helpMenu;
}
public JMenuItem getHelpMenuItem() {
if (helpMenuItem == null) {
helpMenuItem = new JMenuItem();
}
return helpMenuItem;
}
public JTextField getLocationField() {
if (locationField == null) {
locationField = new JTextField();
locationField.setSize(140, 20);
locationField.setLocation(295, 100);
}
return locationField;
}
public JLabel getLocationLabel() {
if (locationLabel == null) {
locationLabel = new JLabel();
locationLabel.setSize(50, 20);
locationLabel.setLocation(220, 100);
locationLabel.setText(Messages.getString("frame.userInterface.label.location"));
}
return locationLabel;
}
private JMenuBar getMyMenuBar() {
if (menuBar == null) {
menuBar = new JMenuBar();
menuBar.add(getFileMenu());
menuBar.add(getHelpMenu());
}
return menuBar;
}
public JButton getOpenDirButton() {
if (openDirButton == null) {
openDirButton = new JButton();
openDirButton.setText(Messages.getString("frame.userInterface.opendir"));
openDirButton.setLocation(10, 10);
openDirButton.setSize(140, 20);
}
return openDirButton;
}
public JCheckBox getOpenStatusBox() {
if (openStatusBox == null) {
openStatusBox = new JCheckBox();
openStatusBox.setSize(200, 20);
openStatusBox.setLocation(220, 250);
openStatusBox.setText("Galerie öffentlich sichtbar");
}
return openStatusBox;
}
public JLabel getPreviewLabel() {
if (previewLabel == null) {
previewLabel = new JLabel();
previewLabel.setLocation(220, 275);
previewLabel.setSize(190, 190);
previewLabel.setBorder(BorderFactory
.createBevelBorder(BevelBorder.LOWERED));
previewLabel.setBackground(Color.LIGHT_GRAY);
previewLabel.setHorizontalAlignment(SwingConstants.CENTER);
previewLabel.setVerticalAlignment(SwingConstants.CENTER);
}
return previewLabel;
}
public JMenuItem getSettingsMenuItem() {
if (settingsMenuItem == null) {
settingsMenuItem = new JMenuItem();
}
return settingsMenuItem;
}
public JButton getStartButton() {
if (startButton == null) {
startButton = new JButton();
startButton.setLocation(430, 350);
startButton.setSize(140, 38);
startButton.setHorizontalTextPosition(SwingConstants.LEFT);
}
return startButton;
}
public StatusBar getStatusBar() {
if (statusBar == null) {
statusBar = new StatusBar(2);
statusBar.setSize(windowWith, 20);
statusBar.setLocation(0, windowHeight - 70);
statusBar.setText(0, Messages.getString("frame.userInterface.statusbar.pictures"));
statusBar.setText(1, Messages.getString("frame.userInterface.statusbar.user"));
}
return statusBar;
}
public DatePicker getToCalendar() {
if (toCalendar == null) {
Date date = new Date(System.currentTimeMillis());
toCalendar = new DatePicker(date);
toCalendar.setSize(90, 20);
toCalendar.setLocation(440, 130);
}
return toCalendar;
}
}