package com.it.loratek.sski.view;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;
import javax.swing.border.BevelBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import com.it.loratek.sski.model.AbstractFrame;
import com.it.loratek.sski.parser.Skier;
import com.it.loratek.sski.view.panels.EditorPanel;
import com.it.loratek.sski.view.panels.StatPanel;
public class Frame extends AbstractFrame {
/**
*
*/
private static final long serialVersionUID = -5770808067196113451L;
public Frame() {
setLayout(new BorderLayout(3, 3));
setBackground(Color.WHITE);
skiersMap = new HashMap<Integer, Skier>();
timePanel = new TimePanel();
try {
setIconImage(ImageIO.read(new File("images/Logo_Loratek.jpg")));
} catch (IOException e1) {
e1.printStackTrace();
}
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
JMenuBar menubar = new JMenuBar();
setJMenuBar(menubar);
JMenu filemenu = new JMenu("File");
JMenu computeMenu = new JMenu("Calcola");
JMenu i = new JMenu();
i.setIcon(new ImageIcon("images/Logo_Securski3.png"));
Action parse = new ParseXMLAction();
setIconImage(Toolkit.getDefaultToolkit()
.getImage("images/loratek3.png"));
computeMenu.add(parse);
computeMenu.add(new AbstractAction("Calcola applicando i filtri") {
@Override
public void actionPerformed(ActionEvent e) {
}
});
computeMenu.add(new AbstractAction("Genera scheda") {
@Override
public void actionPerformed(ActionEvent e) {
}
});
JMenu drawMenu = new JMenu("Disegna");
Action drawpoints = new DrawPointAction();
Action drawTraks = new DrawTracks();
Action drawSingle = new DrawSingleSkierTrackAction();
drawMenu.add(drawSingle);
drawMenu.add(drawTraks);
drawMenu.add(drawpoints);
drawMenu.add(new DrawStartPoints());
drawMenu.add(new DrawEndPoints());
menubar.add(filemenu);
menubar.add(computeMenu);
menubar.add(drawMenu);
Action clear = new ClearAction();
Button clearB = new Button();
clearB.addActionListener(clear);
clearB.setPreferredSize(new Dimension(50, 20));
Action quit = new QuitAction();
OpenFileAction open = new OpenFileAction();
filemenu.add(open);
filemenu.add(quit);
editContainer = new JPanel();
editPanel = new EditorPanel();
statPanel = new StatPanel();
// statPanel.setPreferredSize(new Dimension(50, 550));
matchPanel = new MatchingsPanel();
outputPanel = new OutputPanel();
leftTabPanel = new JTabbedPane();
leftTabPanel.add("Statistiche", statPanel);
leftTabPanel.add("Abbinamenti", matchPanel);
leftTabPanel.add("Generazione", outputPanel);
leftTabPanel.setEnabled(false);
opPanel = new JPanel();
opPanel.setLayout(new BorderLayout());
leftPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true,
leftTabPanel, timePanel);
leftPanel.setDividerLocation(0.5);
leftPanel.setBackground(Color.WHITE);
mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
mainSplitPane.setOneTouchExpandable(false);
mainSplitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
mainSplitPane
.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
mainSplitPane.setBackground(Color.white);
editToolbar = new MyToolBar();
editToolbar.setLayout(new FlowLayout(FlowLayout.LEFT));
// editToolbar.setPreferredSize(new Dimension(40, 28));
up.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
editPanel.encreseTickness();
}
});
down.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
editPanel.decreseTickness();
}
});
upX.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
editPanel.encreseXTrasl();
}
});
downX.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
editPanel.decreseXTrasl();
}
});
upY.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
editPanel.encreseYTrasl();
}
});
downY.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
editPanel.decreseYTrasl();
}
});
up.setBackground(Color.LIGHT_GRAY);
down.setBackground(Color.LIGHT_GRAY);
up.setForeground(Color.YELLOW);
down.setForeground(Color.YELLOW);
up.setPreferredSize(new Dimension(30, 15));
down.setPreferredSize(new Dimension(30, 15));
upX.setBackground(Color.LIGHT_GRAY);
downX.setBackground(Color.LIGHT_GRAY);
upX.setForeground(Color.YELLOW);
downX.setForeground(Color.YELLOW);
upX.setPreferredSize(new Dimension(30, 15));
downX.setPreferredSize(new Dimension(30, 15));
upY.setBackground(Color.LIGHT_GRAY);
downY.setBackground(Color.LIGHT_GRAY);
upY.setForeground(Color.YELLOW);
downY.setForeground(Color.YELLOW);
upY.setPreferredSize(new Dimension(30, 15));
downY.setPreferredSize(new Dimension(30, 15));
modeSelectionChk = new JCheckBox();
modeSelectionChk.setAction(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if (!FILE_OPENED)
return;
if (modeSelectionChk.isSelected() && MODE == 1) {
// editPanel.setBackground(new Color(207, 241, 216));
editPanel.switchMode(2);
MODE = 2;
editToolbar.add(up, BorderLayout.LINE_END);
editToolbar.add(down, BorderLayout.LINE_END);
} else if (!modeSelectionChk.isSelected() && MODE == 2) {
editPanel.setBackground(Color.WHITE);
editPanel.switchMode(1);
MODE = 1;
editToolbar.remove(up);
editToolbar.remove(down);
}
}
});
ticknesTxt.setEditable(false);
xTraslTxt.setEditable(false);
yTraslTxt.setEditable(false);
ticknesTxt.setBackground(Color.WHITE);
xTraslTxt.setBackground(Color.WHITE);
yTraslTxt.setBackground(Color.WHITE);
modeSelectionChk.setText("Modalità selezione");
editToolbar.add(clear);
JSeparator sep1 = new JSeparator(SwingConstants.VERTICAL);
sep1.setPreferredSize(new Dimension(30,30));
sep1.setMaximumSize(new Dimension(30,30));
sep1.setMinimumSize(new Dimension(30,30));
editToolbar.add(sep1);
editToolbar.add(new JLabel("Spessore"));
editToolbar.add(ticknesTxt);
editToolbar.add(up);
editToolbar.add(down);
JSeparator sep = new JSeparator(SwingConstants.VERTICAL);
sep.setPreferredSize(new Dimension(20,20));
sep.setMaximumSize(new Dimension(20,20));
sep.setMinimumSize(new Dimension(20,20));
editToolbar.add(sep);
editToolbar.add(new JLabel("Trasla X"));
editToolbar.add(xTraslTxt);
editToolbar.add(upX);
editToolbar.add(downX);
JSeparator sep2 = new JSeparator(SwingConstants.VERTICAL);
sep2.setPreferredSize(new Dimension(20,20));
sep2.setMaximumSize(new Dimension(20,20));
sep2.setMinimumSize(new Dimension(20,20));
editToolbar.add(sep2);
editToolbar.add(new JLabel("Trasla Y"));
editToolbar.add(yTraslTxt);
editToolbar.add(upY);
editToolbar.add(downY);
editToolbar.setFloatable(true);
editToolbar.setRollover(true);
//editToolbar.add(modeSelectionChk);
editToolbar.setBorder(new BevelBorder(BevelBorder.RAISED));
editContainer.setLayout(new BorderLayout());
editContainer.add(editToolbar, BorderLayout.NORTH);
editContainer.add(editPanel, BorderLayout.CENTER);
editContainer.setName(EDIT_CONTAINER_NAME);
// graphContainer = new JPanel();
//
// graphScoll = new JScrollPane(graphContainer);
//
// graphScoll.setSize(100, 100);
// GridLayout grid = new GridLayout(4, 2, 10, 15);
// grid.preferredLayoutSize(graphScoll);
// graphContainer.setLayout(grid);
//
// // graphContainer.add(new JPanel(), BorderLayout.NORTH);
// editContainer.setName(EDIT_CONTAINER_NAME);
// graphScoll.setName(GRAPH_CONTAINER_NAME);
rightTabPanel = new JTabbedPane();
rightTabPanel.add("Editor grafico", editContainer);
// rightTabPanel.add("Grafici", graphScoll);
rightTabPanel.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if(EDIT_CONTAINER_NAME.equals(rightTabPanel.getSelectedComponent().getName()))
editPanel.setSelected(true);
else
editPanel.setSelected(false);
}
});
leftTabPanel.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if("outputPanel".equals(leftTabPanel.getSelectedComponent().getName())
|| "abbinamenti".equals(leftTabPanel.getSelectedComponent().getName())){
editPanel.switchMode(2);
MODE = 2;
// editToolbar.add(up, BorderLayout.LINE_END);
// editToolbar.add(down, BorderLayout.LINE_END);
}
else{
editPanel.setBackground(Color.WHITE);
editPanel.switchMode(1);
MODE = 1;
// editToolbar.remove(up);
// editToolbar.remove(down);
}
}
});
mainSplitPane.add(leftPanel, JSplitPane.LEFT);
mainSplitPane.add(rightTabPanel, JSplitPane.RIGHT);
//mainSplitPane.setDividerLocation(0.5);
// mainSplitPane.setDividerLocation(100);
mainSplitPane.setEnabled(false);
getContentPane().add(mainSplitPane);
setExtendedState(Frame.MAXIMIZED_BOTH);
ImagePanel bottomp = new ImagePanel("images/Logo_Loratek2.jpg",
"images/Logo_Securski3.png");
bottomp.setPreferredSize(new Dimension(100, 23));
bottomp.setLayout(new BoxLayout(bottomp, BoxLayout.X_AXIS));
add(bottomp, BorderLayout.SOUTH);
pack();
}
}