package diffstats;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.io.File;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
@SuppressWarnings("serial")
public class DiffFrame extends JFrame {
private TextPanel textPanel;
private ButtonPanel buttonPanel;
public DiffFrame(String fileName){
initComponents(fileName);
layoutDialog();
initDialog();
if(fileName != null)
new Analyze(textPanel, new File(fileName)).process();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
private void initDialog() {
this.setTitle("DiffStats");
this.setIconImage(new ImageIcon(this.getClass().getResource("/images/Code_icon.png")).getImage());
this.setResizable(false);
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
// Determine the new location of the window
int w = getSize().width;
int h = getSize().height;
int x = (dim.width-w)/2;
int y = (dim.height-h)/2;
// Move the window
setLocation(x, y);
}
private void initComponents(String fileName) {
textPanel = new TextPanel(fileName);
buttonPanel = new ButtonPanel(this);
}
private void layoutDialog() {
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(5, 5, 5, 5);
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 3;
c.anchor = GridBagConstraints.PAGE_START;
panel.add(textPanel, c);
c.gridx = 3;
c.gridwidth = 1;
c.anchor = GridBagConstraints.PAGE_START;
panel.add(buttonPanel, c);
getContentPane().add(panel);
}
public TextPanel getTextPanel() {
return textPanel;
}
}