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

Fixes for Crystal Ship and FTLFrame NPE #6

Closed
wants to merge 4 commits into from
Closed
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
14 changes: 13 additions & 1 deletion src/main/java/net/blerf/ftl/FTLProfileEditor.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package net.blerf.ftl;

import net.blerf.ftl.ui.FTLFrame;
import javax.swing.UIManager;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import net.blerf.ftl.ui.FTLFrame;


public class FTLProfileEditor {

Expand All @@ -14,6 +16,16 @@ public class FTLProfileEditor {

public static void main(String[] args) {

// Set look and feel before the GUI.
// Otherwise, some existing components might not notice without this.
// SwingUtilities.updateComponentTreeUI(someComponent);
// Maybe risks NPE if present in a JFrame constructor?
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
log.error("Failed to set a native look and feel", e);
}

try {
FTLFrame frame = new FTLFrame(VERSION);
frame.setVisible(true);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/net/blerf/ftl/parser/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ public List<Achievement> getAchievements() {
}

public ShipBlueprint getShip(String id) {
return ships.get(id);
ShipBlueprint result = ships.get(id);
if ( result == null )
log.error( "No ShipBlueprint found for id: "+ id );
return result;
}

public List<ShipBlueprint> getPlayerShips() {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/blerf/ftl/parser/MappedDatParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public Blueprints readBlueprints(InputStream stream) throws IOException, JAXBExc
sb.append("<blueprints>").append("\n"); // XML has multiple root nodes so need to wrap
boolean comment = false, inShipShields = false, inSlot = false;
while( (line = in.readLine()) != null ) {
line = line.replaceAll("^<!-- sardonyx$", "<!-- sardonyx -->"); // Error above one shipBlueprint
line = line.replaceAll("<!--.*-->", "");
line = line.replaceAll("<\\?xml[^>]*>", "");
line = line.replaceAll("<title>([^<]*)</[^>]*>", "<title>$1</title>"); // Error present in systemBlueprint and itemBlueprint
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/net/blerf/ftl/ui/FTLFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import javax.swing.JTabbedPane;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.filechooser.FileFilter;
Expand Down Expand Up @@ -119,12 +118,6 @@ public class FTLFrame extends JFrame {
public FTLFrame(int version) {

this.version = version;

try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}

// Read config file and locate FTL install
File propFile = new File("ftl-editor.cfg");
Expand Down