import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.filechooser.FileNameExtensionFilter;
/**
* Generated with window builder with a few edits <br />
* Screen for formating from bibTex part.
* @author cerko, mydlo
*
*/
public class SaveIntoBibView extends JFrame {
private static int windowWidth = 800;
private static int windowHeight = 630;
private static String backgroundPath = "img/screen/createBibTexScreen.jpg";
private JPanel contentPane;
private JPanel backgroundPanel;
private JTextField TeXInputField;
private JTextField inputFormatField;
private JTextField bibTexOutputField;
private File texInput;
private File bibTexOutput;
private File inputFormat;
private File formatOutput;
private File formatInput;
private JButton btnStart;
private JFrame frame;
private static JFrame home;
/**
* Create the frame.
*/
public SaveIntoBibView(JFrame home) {
SaveIntoBibView.home = home;
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = this;
setBounds(100, 100, 450, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setSize(windowWidth, windowHeight);
GraphicsConfiguration gc = getGraphicsConfiguration();
Rectangle bounds = gc.getBounds();
setLocation(
(int) ((bounds.width / 2) - (windowWidth / 2)),
(int) ((bounds.height / 2) - (windowHeight / 2))
);
//test svn
//magic to make background work
backgroundPanel = new JPanel(){
@Override
public void paintComponent(Graphics g){
Image img = null;
try {
img = ImageIO.read(new File(backgroundPath));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
g.drawImage(img, 0, 0, null);
}
};
getContentPane().setLayout(createFromBibTexView());
}
/**
* vytvori cely layout
* @return hotovy layout
*/
public GroupLayout createFromBibTexView(){
GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.TRAILING)
.addComponent(backgroundPanel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE)
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.TRAILING)
.addComponent(backgroundPanel, GroupLayout.DEFAULT_SIZE, 370, Short.MAX_VALUE)
);
JPanel panel = new JPanel();
panel.setBounds(0, 0, 794, 613);
//nastavenie priesvitneho panelu
panel.setOpaque(false);
inputFormatField = new JTextField();
inputFormatField.setBounds(310, 310, 177, 14);
inputFormatField.setColumns(10);
inputFormatField.setOpaque(false);
inputFormatField.setBorder(BorderFactory.createEmptyBorder());
TeXInputField = new JTextField();
TeXInputField.setBounds(310, 355, 177, 14);
TeXInputField.setColumns(10);
TeXInputField.setOpaque(false);
TeXInputField.setBorder(BorderFactory.createEmptyBorder());
JButton btnTeXInput = new JButton(new ImageIcon("img/buttons/browseButton.png"));
btnTeXInput.setBounds(494, 345, 85, 30);
btnTeXInput.setBorder(BorderFactory.createEmptyBorder());
btnTeXInput.setOpaque(false);
btnTeXInput.setContentAreaFilled(false);
btnTeXInput.addMouseListener(new ButtonMouseListener(new ImageIcon("img/buttons/browseButtonA.png"), new ImageIcon("img/buttons/browseButton.png"), btnTeXInput));
JButton btnBiBInput = new JButton(new ImageIcon("img/buttons/browseButton.png"));
btnBiBInput.setBounds(494, 300, 85, 30);
btnBiBInput.setBorder(BorderFactory.createEmptyBorder());
btnBiBInput.setOpaque(false);
btnBiBInput.setContentAreaFilled(false);
btnBiBInput.addMouseListener(new ButtonMouseListener(new ImageIcon("img/buttons/browseButtonA.png"), new ImageIcon("img/buttons/browseButton.png"), btnBiBInput));
btnBiBInput.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileFilter(new FileNameExtensionFilter("input format (.txt)", "txt"));
int returnVal = fileChooser.showOpenDialog(frame);
if (returnVal == JFileChooser.APPROVE_OPTION){
inputFormat = fileChooser.getSelectedFile();
inputFormatField.setText(inputFormat.getAbsolutePath());
}
}
});
bibTexOutputField = new JTextField();
bibTexOutputField.setBounds(310, 405, 177, 14);
bibTexOutputField.setColumns(10);
bibTexOutputField.setOpaque(false);
bibTexOutputField.setBorder(BorderFactory.createEmptyBorder());
JButton btnTexOutput = new JButton(new ImageIcon("img/buttons/browseButton.png"));
btnTexOutput.setBounds(494, 395, 85, 30);
btnTexOutput.setBorder(BorderFactory.createEmptyBorder());
btnTexOutput.setOpaque(false);
btnTexOutput.setContentAreaFilled(false);
btnTexOutput.addMouseListener(new ButtonMouseListener(new ImageIcon("img/buttons/browseButtonA.png"), new ImageIcon("img/buttons/browseButton.png"), btnTexOutput));
btnTexOutput.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileFilter(new FileNameExtensionFilter("BibTex file (.bib)", "bib"));
int returnVal = fileChooser.showSaveDialog(frame);
if (returnVal == JFileChooser.APPROVE_OPTION){
bibTexOutputField.setText(fileChooser.getSelectedFile().getAbsolutePath());
if (!bibTexOutputField.getText().endsWith(".bib")){
bibTexOutputField.setText(bibTexOutputField.getText() + ".bib");
}
}
}
});
btnStart = new JButton(new ImageIcon("img/buttons/startButton.png"));
btnStart.setBounds(350, 435, 102, 102);
btnStart.setBorder(BorderFactory.createEmptyBorder());
btnStart.setOpaque(false);
btnStart.setContentAreaFilled(false);
btnStart.addMouseListener(new ButtonMouseListener(new ImageIcon("img/buttons/startButtonA.png"), new ImageIcon("img/buttons/startButton.png"), btnStart));
btnStart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
//TODO odpal
bibTexOutput = new File(bibTexOutputField.getText());
new Dispatcher().saveIntoBibTex(texInput, bibTexOutput, inputFormat);
}
});
backgroundPanel.setLayout(null);
btnTeXInput.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileFilter(new FileNameExtensionFilter("tex files (.tex)", "tex"));
int returnVal = fileChooser.showOpenDialog(frame);
if (returnVal == JFileChooser.APPROVE_OPTION){
texInput = fileChooser.getSelectedFile();
TeXInputField.setText(texInput.getAbsolutePath());
}
}
});
JButton homeButton = new JButton(new ImageIcon("img/buttons/homeButton.png"));
homeButton.addMouseListener(new ButtonMouseListener(new ImageIcon("img/buttons/homeButtonA.png"), new ImageIcon("img/buttons/homeButton.png"), homeButton));
homeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
setVisible(false);
SaveIntoBibView.home.setVisible(true);
}
});
homeButton.setBounds(38, 513, 52, 52);
homeButton.setBorder(BorderFactory.createEmptyBorder());
homeButton.setOpaque(false);
homeButton.setContentAreaFilled(false);
backgroundPanel.add(panel);
panel.setLayout(null);
panel.add(inputFormatField);
panel.add(TeXInputField);
panel.add(bibTexOutputField);
panel.add(btnTexOutput);
panel.add(btnBiBInput);
panel.add(btnTeXInput);
panel.add(btnStart);
panel.add(homeButton);
return groupLayout;
}
}