Skip to content

Commit

Permalink
Refactoring PDFValidationApplication
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximPlusov committed May 6, 2024
1 parent 2da16df commit ba2d870
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;

/**
* This class holds all command-line options used by VeraPDF application.
Expand Down Expand Up @@ -634,6 +635,7 @@ public static List<String> getBaseVeraPDFParameters(VeraCliArgParser cliArgParse
veraPDFParameters.add(SERVER_MODE);
if (cliArgParser.extractFeatures()) {
veraPDFParameters.add(EXTRACT_FLAG);
veraPDFParameters.add(cliArgParser.features.stream().map(FeatureObjectType::toString).collect(Collectors.joining(",")));
}
if (cliArgParser.fixMetadata()) {
veraPDFParameters.add(FIX_METADATA);
Expand Down
1 change: 0 additions & 1 deletion gui/src/main/java/org/verapdf/gui/FeaturesConfigPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ boolean showDialog(Component parent, String title, FeatureExtractorConfig featur

for (FeatureObjectType type : FeatureObjectType.values()) {
if (type != FeatureObjectType.ERROR) {
this.featureGrid.get(type).setSelected(true);
this.featureGrid.get(type).setSelected(featureExtractorConfig.isFeatureEnabled(type));
}
}
Expand Down
176 changes: 105 additions & 71 deletions gui/src/main/java/org/verapdf/gui/PDFValidationApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,56 @@ private PDFValidationApplication(double frameScale) {
logger.log(Level.SEVERE, "Exception in initialising settings panel", e);
}

file.add(getSettings());

file.addSeparator();

file.add(getQuit());

final JMenu configs = new JMenu("Configs");

this.featuresPanel = new FeaturesConfigPanel();

menuBar.add(configs);
configs.add(getFeatures());

this.policyConfig = new PolicyPanel();

configs.add(getPolicyPanel());

configs.add(getShowConfigLocation());

JMenu help = new JMenu("Help");
help.add(getGuiHelp());
help.add(getValidationHelp());
help.add(getPolicyHelp());
help.addSeparator();
help.add(getCheckForUpdates());
help.add(getAbout());

menuBar.add(help);

JPanel contentPanel = new JPanel();
contentPanel.setBorder(new EmptyBorder(GUIConstants.EMPTY_BORDER_INSETS, GUIConstants.EMPTY_BORDER_INSETS,
GUIConstants.EMPTY_BORDER_INSETS, GUIConstants.EMPTY_BORDER_INSETS));
contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
setContentPane(contentPanel);

contentPanel.add(getLogoPanel());

this.checkerPanel = null;
try {
this.checkerPanel = new CheckerPanel(configManager);
} catch (IOException e) {
JOptionPane.showMessageDialog(PDFValidationApplication.this, "Error in loading xml or html image.",
GUIConstants.ERROR, JOptionPane.ERROR_MESSAGE);
logger.log(Level.WARNING, "Exception in loading xml or html image", e);
}
contentPanel.add(this.checkerPanel);

}

private JMenuItem getSettings() {
final JMenuItem sett = new JMenuItem("Settings");
sett.addActionListener(new ActionListener() {
@Override
Expand Down Expand Up @@ -162,11 +212,10 @@ public void actionPerformed(ActionEvent e) {
}
}
});
return sett;
}

file.add(sett);

file.addSeparator();

private JMenuItem getQuit() {
final JMenuItem quit = new JMenuItem("Quit");
quit.addActionListener(new ActionListener() {
@Override
Expand All @@ -177,13 +226,10 @@ public void actionPerformed(ActionEvent actionEvent) {
});

quit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_MASK));
return quit;
}

file.add(quit);

final JMenu configs = new JMenu("Configs");

this.featuresPanel = new FeaturesConfigPanel();

private JMenuItem getFeatures() {
final JMenuItem features = new JMenuItem("Features Config");
features.addActionListener(new ActionListener() {
@Override
Expand All @@ -200,11 +246,10 @@ public void actionPerformed(ActionEvent e) {
}
}
});
return features;
}

menuBar.add(configs);
configs.add(features);

this.policyConfig = new PolicyPanel();
private JMenuItem getPolicyPanel() {
final JMenuItem policyPanel = new JMenuItem("Policy Config");
policyPanel.addActionListener(new ActionListener() {
@Override
Expand Down Expand Up @@ -232,9 +277,10 @@ public void actionPerformed(ActionEvent e) {
}
}
});
return policyPanel;
}

configs.add(policyPanel);

private static JMenuItem getShowConfigLocation() {
final JMenuItem showConfigLocation = new JMenuItem(GUIConstants.SHOW_CONFIG_LOCATION);
showConfigLocation.addActionListener(new ActionListener() {
@Override
Expand All @@ -246,19 +292,43 @@ public void actionPerformed(ActionEvent e) {
}
}
});

configs.add(showConfigLocation);
return showConfigLocation;
}

JMenuItem about = new JMenuItem("About");
about.addActionListener(new ActionListener() {
private JMenuItem getGuiHelp() {
JMenuItem guiHelp = new JMenuItem("GUI");
guiHelp.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (PDFValidationApplication.this.aboutPanel != null) {
PDFValidationApplication.this.aboutPanel.showDialog(PDFValidationApplication.this, "About veraPDF");
}
PDFValidationApplication.this.attemptURIOpen(GUIConstants.DOCS_GUI_LINK_URL);
}
});
return guiHelp;
}

private JMenuItem getValidationHelp() {
JMenuItem validationHelp = new JMenuItem("Validation");
validationHelp.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
PDFValidationApplication.this.attemptURIOpen(GUIConstants.DOCS_VALIDATION_LINK_URL);
}
});
return validationHelp;
}

private JMenuItem getPolicyHelp() {
JMenuItem policyHelp = new JMenuItem("Policy");
policyHelp.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
PDFValidationApplication.this.attemptURIOpen(GUIConstants.DOCS_POLICY_LINK_URL);
}
});
return policyHelp;
}

private JMenuItem getCheckForUpdates() {
JMenuItem checkForUpdates = new JMenuItem(GUIConstants.CHECK_FOR_UPDATES_TEXT);
checkForUpdates.addActionListener(new ActionListener() {
@Override
Expand Down Expand Up @@ -296,47 +366,23 @@ public void actionPerformed(ActionEvent e) {
}
}
});
return checkForUpdates;
}

JMenuItem guiHelp = new JMenuItem("GUI");
guiHelp.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
PDFValidationApplication.this.attemptURIOpen(GUIConstants.DOCS_GUI_LINK_URL);
}
});

JMenuItem validationHelp = new JMenuItem("Validation");
validationHelp.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
PDFValidationApplication.this.attemptURIOpen(GUIConstants.DOCS_VALIDATION_LINK_URL);
}
});

JMenuItem policyHelp = new JMenuItem("Policy");
policyHelp.addActionListener(new ActionListener() {
private JMenuItem getAbout() {
JMenuItem about = new JMenuItem("About");
about.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
PDFValidationApplication.this.attemptURIOpen(GUIConstants.DOCS_POLICY_LINK_URL);
if (PDFValidationApplication.this.aboutPanel != null) {
PDFValidationApplication.this.aboutPanel.showDialog(PDFValidationApplication.this, "About veraPDF");
}
}
});
return about;
}

JMenu help = new JMenu("Help");
help.add(guiHelp);
help.add(validationHelp);
help.add(policyHelp);
help.addSeparator();
help.add(checkForUpdates);
help.add(about);

menuBar.add(help);

JPanel contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(GUIConstants.EMPTY_BORDER_INSETS, GUIConstants.EMPTY_BORDER_INSETS,
GUIConstants.EMPTY_BORDER_INSETS, GUIConstants.EMPTY_BORDER_INSETS));
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
setContentPane(contentPane);

private MiniLogoPanel getLogoPanel() {
MiniLogoPanel logoPanel = null;
try {
logoPanel = new MiniLogoPanel(GUIConstants.LOGO_NAME);
Expand All @@ -345,19 +391,7 @@ public void actionPerformed(ActionEvent e) {
GUIConstants.ERROR, JOptionPane.ERROR_MESSAGE);
logger.log(Level.WARNING, "Exception in creating mini logo", e);
}

contentPane.add(logoPanel);

this.checkerPanel = null;
try {
this.checkerPanel = new CheckerPanel(configManager);
} catch (IOException e) {
JOptionPane.showMessageDialog(PDFValidationApplication.this, "Error in loading xml or html image.",
GUIConstants.ERROR, JOptionPane.ERROR_MESSAGE);
logger.log(Level.WARNING, "Exception in loading xml or html image", e);
}
contentPane.add(this.checkerPanel);

return logoPanel;
}

private void attemptURIOpen(String uri) {
Expand Down

0 comments on commit ba2d870

Please sign in to comment.