public class Main extends MYFORM{//JFRAME
private ActionListener saveas;
private JFileChooser fc ;
private ActionListener save;
private ActionListener savesettings;
private ActionListener options;
private WindowAdapter Close_Options;
private String local;
private Locale locale;
private PagePanel panel;
private Document doc;
private ActionListener open;
private ActionListener about;
private PdfFilter pdffilefilter = new PdfFilter(".pdf","[PDF]Portable Document Format");
public Main(String[] args){
super(Statics.PROJECTNAME,Statics.PROJECTNAME,"documentor",false);
//Map<String,String> setting = new HashMap<String, String>();
local = super.settings.getProperty("locale",Locale.ENGLISH.toString());
try {
locale = new Locale(local);
} catch (Exception e) {
e.printStackTrace();
locale= Locale.ENGLISH;
super.settings.put("locale",locale.toString());
super.settings.SaveSettings();
}
super.settings.setProperty("FactuurURL", args[1]);
doc = new Document(args[0],args[1]);
try {
super.add(doc.createpdf());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setLocale(locale);
setMinimumSize(new Dimension(500,700));
//settings.setfsettings(setting);
actions();
gui();
pack();
}
public static void main(final String[] args) {
java.awt.EventQueue.invokeLater(new Runnable(){
public void run(){
new Main(args).setVisible(true);
}
});
}
private void menusetup(){
Menu menu= new Menu("Documentor");
menu.addmenuitem("File","open",new JMenuItem());
menu.addmenuitem("File","exit",new JMenuItem(),savesettings);
menu.addmenuitem("File","save",new JMenuItem(),save);
menu.addmenuitem("File","saveas",new JMenuItem(),saveas);
menu.addmenuitem("Edit","underconstruction",new JMenuItem());
menu.addmenuitem("Tools","options",new JMenuItem(),options);
menu.addmenuitem("Window","underconstruction",new JMenuItem());
menu.addmenuitem("Help","&About",new JMenuItem(),about);
setJMenuBar(menu.getmenubar());
}
private void gui(){
if (Statics.DEBUG){log(Level.WARNING, "LOCAL_GUIsetup" );}
menusetup();
framesetup();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//addWindowListener(Close_Options);
}
private void framesetup(){
if (Statics.DEBUG){ log(Level.WARNING, "LOCAL_Framesetup" ); }
add(new JLabel("Documentor Lieven Roegiers =>Open source By Autosite "), BorderLayout.SOUTH);
}
private static void log(Level level, String msg ){
String tag ="<>>>>*"+Statics.LIBNAME+"-"+Statics.COPYRIGHTBY+"*<<<<>";
Logger.getLogger(Main.class.getName()).log(level, tag + msg);
}
private void actions(){
fc = new JFileChooser();
saveas = new ActionListener() {
private String Filename;
public void actionPerformed(ActionEvent evt) {
if (Statics.DEBUG){log(Level.WARNING, "saveas action, event="+evt);}
fc.addChoosableFileFilter(pdffilefilter);
int returnVal = fc.showSaveDialog(Main.this);
File file = fc.getSelectedFile();
if (returnVal == JFileChooser.APPROVE_OPTION) {
doc.savedocas(file,(MYabstractFileFilter)fc.getFileFilter());
} else {
log(Level.WARNING, "Saveas command cancelled by user.");
}
}
};
open = new ActionListener() {
private String Filename;
private File file;
public void actionPerformed(ActionEvent evt) {
if (Statics.DEBUG){log(Level.WARNING, "open action, event="+evt);}
int returnVal = fc.showOpenDialog(Main.this);
fc.addChoosableFileFilter(new PdfFilter(".pdf","[PDF]Portable Document Format"));
fc.setFileSelectionMode(JFileChooser.FILES_ONLY );
if ( returnVal == JFileChooser.CANCEL_OPTION)
file = null;
else
file = fc.getSelectedFile();
}
};
savesettings = new ActionListener() {
public void actionPerformed(ActionEvent evt) {settings.SaveSettings(); log(Level.WARNING, "settings saved.");}
};
options =new ActionListener(){
public void actionPerformed(ActionEvent evt) {
settings.SaveSettings();//this that all settings from the prog are saved
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
MYpanel pnltools = new MYpanel("Documentor");
pnltools.addpanelitem("editorpanel","ok",new JButton(),new ActionListener(){
public void actionPerformed (ActionEvent e){
settings.SaveSettings();//this wil save all settings
frame.dispose();
}});
pnltools.addpanelitem("editorpanel","cancel",new JButton(),new ActionListener(){
public void actionPerformed (ActionEvent e){
settings.LoadSettings();//this wil reload all settings
frame.dispose();
}});
frame.add(pnltools.getpanel("editorpanel"), BorderLayout.SOUTH);
JPanel editor = settings.getEditor();
editor.setBounds(100, 100, 500, 500);
frame.add(editor,BorderLayout.NORTH);
frame.setVisible(true);
frame.pack();
}
};
Close_Options = new WindowAdapter() {//sluitmessage
@Override
public void windowClosing(WindowEvent e){
int answer = JOptionPane.showConfirmDialog(null, "save settings ?", "sluiten", JOptionPane.YES_NO_OPTION);
if (answer == JOptionPane.YES_OPTION) {
savesettings.actionPerformed(null);
}else if (answer == JOptionPane.NO_OPTION){
return;
}
}
};
save = new ActionListener(){
public void actionPerformed(ActionEvent evt) {
}
};
about = new ActionListener(){
public void actionPerformed(ActionEvent evt) {
new About();
}
};
}
protected void finalize() throws Throwable{
super.finalize();
}
}