@@ -43,78 +43,78 @@ This file is part of the iText (R) project.
4343package com .itextpdf .rups ;
4444
4545import com .itextpdf .kernel .actions .data .ITextCoreProductData ;
46- import com .itextpdf .kernel . utils . CompareTool ;
46+ import com .itextpdf .rups . controller . IRupsController ;
4747import com .itextpdf .rups .controller .RupsController ;
48+ import com .itextpdf .rups .model .LoggerHelper ;
49+ import com .itextpdf .rups .view .Language ;
50+ import com .itextpdf .rups .view .RupsDropTarget ;
51+ import com .itextpdf .rups .view .RupsMenuBar ;
52+ import com .itextpdf .rups .view .RupsTabbedPane ;
4853import com .itextpdf .rups .view .icons .FrameIconUtil ;
4954
55+ import java .awt .BorderLayout ;
5056import java .awt .Dimension ;
5157import java .awt .Toolkit ;
5258import java .io .File ;
5359import javax .swing .JFrame ;
5460import javax .swing .SwingUtilities ;
61+ import javax .swing .UIManager ;
62+ import javax .swing .UnsupportedLookAndFeelException ;
5563
5664public class Rups {
5765
58- private RupsController controller ;
59-
60- private volatile CompareTool .CompareResult lastCompareResult = null ;
61-
62- protected Rups () {
63- this .controller = null ;
64- }
65-
66- protected void setController (RupsController controller ) {
67- this .controller = controller ;
68- }
69-
7066 /**
7167 * Initializes the main components of the Rups application.
7268 *
73- * @param f a file that should be opened on launch
74- * @param onCloseOperation the close operation
69+ * @param f a file that should be opened on launch
7570 */
76- public static void startNewApplication (final File f , final int onCloseOperation ) {
77- final Rups rups = new Rups ();
78- SwingUtilities .invokeLater (new Runnable () {
79- public void run () {
80- JFrame frame = new JFrame ();
81- // defines the size and location
82- initFrameDim (frame );
83- RupsController controller = new RupsController (frame .getSize (), frame , false );
84- initApplication (frame , controller , onCloseOperation );
85- rups .setController (controller );
86- if (null != f && f .canRead ()) {
87- rups .loadDocumentFromFile (f , false );
88- }
71+ public static void startNewApplication (final File f ) {
72+ SwingUtilities .invokeLater (() -> {
73+ setLookandFeel ();
74+ final IRupsController rupsController = initApplication (new JFrame ());
75+ if (f != null ) {
76+ loadDocumentFromFile (rupsController , f );
8977 }
9078 });
9179 }
9280
93- public void loadDocumentFromFile (final File f , final boolean readOnly ) {
94- SwingUtilities .invokeLater (new Runnable () {
95- @ Override
96- public void run () {
97- controller .loadFile (f , readOnly );
98- }
99- });
81+ static void loadDocumentFromFile (IRupsController rupsController , File f ) {
82+ SwingUtilities .invokeLater (() -> rupsController .openNewFile (f ));
10083 }
10184
102- static void initApplication (JFrame frame , RupsController controller , final int onCloseOperation ) {
103- // title bar
104- frame .setTitle ("iText RUPS " + ITextCoreProductData .getInstance ().getVersion ());
105- frame .setIconImages (FrameIconUtil .loadFrameIcons ());
106- frame .setDefaultCloseOperation (onCloseOperation );
107- // the content
108- frame .setJMenuBar (controller .getMenuBar ());
109- frame .getContentPane ().add (controller .getMasterComponent (), java .awt .BorderLayout .CENTER );
110- frame .setVisible (true );
85+ static void setLookandFeel () {
86+ try {
87+ UIManager .setLookAndFeel (RupsConfiguration .INSTANCE .getLookAndFeel ());
88+ } catch (
89+ ClassNotFoundException | InstantiationException |
90+ IllegalAccessException | UnsupportedLookAndFeelException e ) {
91+ LoggerHelper .error (Language .ERROR_LOOK_AND_FEEL .getString (), e , Rups .class );
92+ }
11193 }
11294
113- static void initFrameDim (JFrame frame ) {
95+ static IRupsController initApplication (JFrame frame ) {
11496 Dimension screen = Toolkit .getDefaultToolkit ().getScreenSize ();
11597 frame .setSize ((int ) (screen .getWidth () * .90 ), (int ) (screen .getHeight () * .90 ));
11698 frame .setLocation ((int ) (screen .getWidth () * .05 ), (int ) (screen .getHeight () * .05 ));
11799 frame .setResizable (true );
118- }
119100
101+ // title bar
102+ frame .setTitle (
103+ String .format (Language .TITLE .getString (), ITextCoreProductData .getInstance ().getVersion ()));
104+ frame .setIconImages (FrameIconUtil .loadFrameIcons ());
105+ frame .setDefaultCloseOperation (RupsConfiguration .INSTANCE .getCloseOperation ());
106+
107+ final RupsTabbedPane rupsTabbedPane = new RupsTabbedPane ();
108+ final RupsController rupsController = new RupsController (screen , rupsTabbedPane );
109+ final RupsMenuBar rupsMenuBar = new RupsMenuBar (rupsController );
110+ rupsController .addObserver (rupsMenuBar );
111+
112+ frame .setDropTarget (new RupsDropTarget (rupsController ));
113+ frame .setJMenuBar (rupsMenuBar );
114+
115+ frame .getContentPane ().add (rupsController .getMasterComponent (), BorderLayout .CENTER );
116+ frame .setVisible (true );
117+
118+ return rupsController ;
119+ }
120120}
0 commit comments