Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple open files in RUPS #93

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 30 additions & 47 deletions src/main/java/com/itextpdf/rups/Rups.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,78 +43,61 @@ This file is part of the iText (R) project.
package com.itextpdf.rups;

import com.itextpdf.kernel.actions.data.ITextCoreProductData;
import com.itextpdf.kernel.utils.CompareTool;
import com.itextpdf.rups.controller.RupsController;
import com.itextpdf.rups.view.RupsTabbedPane;
import com.itextpdf.rups.view.icons.FrameIconUtil;

import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class Rups {

private RupsController controller;

private volatile CompareTool.CompareResult lastCompareResult = null;

protected Rups() {
this.controller = null;
}

protected void setController(RupsController controller) {
this.controller = controller;
}

/**
* Initializes the main components of the Rups application.
*
* @param f a file that should be opened on launch
* @param onCloseOperation the close operation
*/
public static void startNewApplication(final File f, final int onCloseOperation) {
final Rups rups = new Rups();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame();
// defines the size and location
initFrameDim(frame);
RupsController controller = new RupsController(frame.getSize(), frame, false);
initApplication(frame, controller, onCloseOperation);
rups.setController(controller);
if (null != f && f.canRead()) {
rups.loadDocumentFromFile(f, false);
}
}
SwingUtilities.invokeLater(() -> {
JFrame frame = new JFrame();
setLookandFeel();
initApplication(frame, onCloseOperation);
});
}

public void loadDocumentFromFile(final File f, final boolean readOnly) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
controller.loadFile(f, readOnly);
static void setLookandFeel() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception ex) {
// WELP IDK
}
});
}
}

static void initApplication(JFrame frame, RupsController controller, final int onCloseOperation) {
static void initApplication(JFrame frame, final int onCloseOperation) {
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
frame.setSize((int) (screen.getWidth() * .90), (int) (screen.getHeight() * .90));
frame.setLocation((int) (screen.getWidth() * .05), (int) (screen.getHeight() * .05));
frame.setResizable(true);

// title bar
frame.setTitle("iText RUPS " + ITextCoreProductData.getInstance().getVersion());
frame.setTitle("iText RUPS " + ITextCoreProductData.getInstance().getVersion() + " - Research Edition");
frame.setIconImages(FrameIconUtil.loadFrameIcons());
frame.setDefaultCloseOperation(onCloseOperation);

RupsTabbedPane tabbedPane = new RupsTabbedPane(screen);

// menu bar
RupsController rupsController = new RupsController(tabbedPane);
frame.setJMenuBar(rupsController.getMenuBar());
// the content
frame.setJMenuBar(controller.getMenuBar());
frame.getContentPane().add(controller.getMasterComponent(), java.awt.BorderLayout.CENTER);
frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
frame.setVisible(true);
}

static void initFrameDim(JFrame frame) {
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
frame.setSize((int) (screen.getWidth() * .90), (int) (screen.getHeight() * .90));
frame.setLocation((int) (screen.getWidth() * .05), (int) (screen.getHeight() * .05));
frame.setResizable(true);
}

}
2 changes: 1 addition & 1 deletion src/main/java/com/itextpdf/rups/RupsLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ This file is part of the iText (R) project.
*/
package com.itextpdf.rups;

import javax.swing.*;
import javax.swing.WindowConstants;
import java.io.File;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ This file is part of the iText (R) project.
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Observable;
import java.util.Observer;
import java.util.Stack;
import java.util.*;

/**
* Controls the components that get their content from iText's PdfReader.
Expand Down
Loading