1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| package ocr_angel;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author Titelouve
*/
public class UserInterface {
static JFrame frame = new JFrame("OCR Angel");
static Container windowContent = new Container();
static GridBagLayout disposition = new GridBagLayout();
static GridBagConstraints contr = new GridBagConstraints();
//First window content
static JLabel pageLimitLabel = new JLabel("Enter the maximal amount of pages per subfolder :");
static JTextField pageLimitField = new JTextField(7);
static JButton enter = new JButton("Run");
//Second window content
static JTextArea processingInformation = new JTextArea("");
public UserInterface(){
enter.addActionListener(new EnterActionListener());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
windowContent = frame.getContentPane();
askForPageLimit();
}
//USER INTERFACE PART
public static void askForPageLimit(){
windowContent.removeAll();
windowContent.setLayout(disposition);
addComponent(pageLimitLabel, 0, 0, 1, 1, new Insets(20, 10, 10, 0), GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST);
addComponent(pageLimitField, 1, 0, 1, 1, new Insets(20, 10, 10, 10), GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST);
addComponent(enter, 0, 1, 1, 2, new Insets(10, 10, 20, 10), GridBagConstraints.NONE, GridBagConstraints.CENTER);
frame.setResizable(false);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void showProcessingInformation(){
windowContent.removeAll();
windowContent.setLayout(disposition);
processingInformation.setEditable(false);
addComponent(processingInformation, 0, 0, 1, 1, new Insets(20, 20, 20, 20), GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER);
frame.setResizable(false);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void updateProcessingInformation(String news){
processingInformation.setText(processingInformation.getText()+news+" \n ");
frame.pack();
frame.repaint();
}
static void addComponent(Component item, int column, int line, int height, int width, Insets ins, int fill, int anchor){
contr.gridx = column;
contr.gridy = line;
contr.gridwidth = width;
contr.gridheight = height;
contr.insets = ins;
contr.fill = fill;
contr.anchor = anchor;
disposition.setConstraints(item, contr);
windowContent.add(item);
}
//IMPLICATION OF CLICKING THE "Enter" BUTTON
static class EnterActionListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
int pl = -1;
try{
pl = Integer.parseInt(UserInterface.pageLimitField.getText());
}catch(Exception e){
}
if(pl > 0 && pl < 9999){
UserInterface.showProcessingInformation();
new PdfSorter(pl);
}else{
UserInterface.askForPageLimit();
}
}
}
} |
Partager