@@ -43,71 +43,79 @@ 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 ;
4848import com .itextpdf .rups .view .Language ;
49+ import com .itextpdf .rups .view .RupsDropTarget ;
50+ import com .itextpdf .rups .view .RupsMenuBar ;
51+ import com .itextpdf .rups .view .RupsTabbedPane ;
4952import com .itextpdf .rups .view .icons .FrameIconUtil ;
5053
51- import javax .swing .JFrame ;
52- import javax .swing .SwingUtilities ;
54+ import java .awt .BorderLayout ;
5355import java .awt .Dimension ;
5456import java .awt .Toolkit ;
5557import java .io .File ;
58+ import javax .swing .JFrame ;
59+ import javax .swing .SwingUtilities ;
60+ import javax .swing .UIManager ;
5661
5762public class Rups {
5863
59- private RupsController controller ;
60-
61- private volatile CompareTool .CompareResult lastCompareResult = null ;
62-
63- protected Rups () {
64- this .controller = null ;
65- }
66-
67- protected void setController (RupsController controller ) {
68- this .controller = controller ;
69- }
70-
7164 /**
7265 * Initializes the main components of the Rups application.
7366 *
7467 * @param f a file that should be opened on launch
7568 * @param onCloseOperation the close operation
7669 */
7770 public static void startNewApplication (final File f , final int onCloseOperation ) {
78- final Rups rups = new Rups ();
7971 SwingUtilities .invokeLater (() -> {
80- final JFrame frame = new JFrame ();
81- initFrameDim (frame );
82- final RupsController controller = new RupsController (frame .getSize (), frame , false );
83- initApplication (frame , controller , onCloseOperation );
84- rups .setController (controller );
85- if (null != f && f .canRead ()) {
86- rups .loadDocumentFromFile (f , false );
72+ setLookandFeel ();
73+ IRupsController rupsController = initApplication (new JFrame (), onCloseOperation );
74+ if ( f != null ) {
75+ loadDocumentFromFile (rupsController , f );
8776 }
8877 });
8978 }
9079
91- public void loadDocumentFromFile (final File f , final boolean readOnly ) {
92- SwingUtilities .invokeLater (() -> controller .loadFile (f , readOnly ));
80+ static void loadDocumentFromFile (IRupsController rupsController , File f ) {
81+ SwingUtilities .invokeLater (() -> rupsController .openNewFile (f ));
82+ }
83+
84+ static void setLookandFeel () {
85+ try {
86+ UIManager .setLookAndFeel (UIManager .getSystemLookAndFeelClassName ());
87+ } catch (Exception e ) {
88+ try {
89+ UIManager .setLookAndFeel (UIManager .getCrossPlatformLookAndFeelClassName ());
90+ } catch (Exception ex ) {
91+ // WELP IDK
92+ }
93+ }
9394 }
9495
95- static void initApplication (JFrame frame , RupsController controller , final int onCloseOperation ) {
96+ static IRupsController initApplication (JFrame frame , final int onCloseOperation ) {
97+ Dimension screen = Toolkit .getDefaultToolkit ().getScreenSize ();
98+ frame .setSize ((int ) (screen .getWidth () * .90 ), (int ) (screen .getHeight () * .90 ));
99+ frame .setLocation ((int ) (screen .getWidth () * .05 ), (int ) (screen .getHeight () * .05 ));
100+ frame .setResizable (true );
101+
96102 // title bar
97103 frame .setTitle (
98104 String .format (Language .TITLE .getString (), ITextCoreProductData .getInstance ().getVersion ()));
99105 frame .setIconImages (FrameIconUtil .loadFrameIcons ());
100106 frame .setDefaultCloseOperation (onCloseOperation );
101- // the content
102- frame .setJMenuBar (controller .getMenuBar ());
103- frame .getContentPane ().add (controller .getMasterComponent (), java .awt .BorderLayout .CENTER );
107+
108+ final RupsTabbedPane rupsTabbedPane = new RupsTabbedPane ();
109+ final RupsController rupsController = new RupsController (screen , rupsTabbedPane );
110+ final RupsMenuBar rupsMenuBar = new RupsMenuBar (rupsController );
111+ rupsController .addObserver (rupsMenuBar );
112+
113+ frame .setDropTarget (new RupsDropTarget (rupsController ));
114+ frame .setJMenuBar (rupsMenuBar );
115+
116+ frame .getContentPane ().add (rupsController .getMasterComponent (), BorderLayout .CENTER );
104117 frame .setVisible (true );
105- }
106118
107- static void initFrameDim (JFrame frame ) {
108- Dimension screen = Toolkit .getDefaultToolkit ().getScreenSize ();
109- frame .setSize ((int ) (screen .getWidth () * .90 ), (int ) (screen .getHeight () * .90 ));
110- frame .setLocation ((int ) (screen .getWidth () * .05 ), (int ) (screen .getHeight () * .05 ));
111- frame .setResizable (true );
119+ return rupsController ;
112120 }
113121}
0 commit comments