Skip to content

Commit

Permalink
refactor: Replaced print stack trace calls with Logger (#528)
Browse files Browse the repository at this point in the history
* refactor: Replaced print stack trace calls with Logger

* replaced sysout calls

* fixed headers
  • Loading branch information
AlmasB authored Oct 3, 2022
1 parent abec246 commit 256c360
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;

import javafx.beans.value.ChangeListener;
import javafx.collections.ObservableList;
Expand Down Expand Up @@ -453,8 +455,12 @@ public MenuBar getMenuBar() {
loader.load();
controllerDidLoadFxml();
} catch (RuntimeException | IOException x) {
System.out.println("loader.getController()=" + loader.getController()); //NOI18N
System.out.println("loader.getLocation()=" + loader.getLocation()); //NOI18N
var logMessage = "Failed to load MenuBar.fxml:\n"
+ "loader.getController()=" + loader.getController() + "\n"
+ "loader.getLocation()=" + loader.getLocation() + ":";

Logger.getLogger(getClass().getName()).log(Level.WARNING, logMessage, x);

throw new RuntimeException("Failed to load " + fxmlURL.getFile(), x); //NOI18N
}
}
Expand Down Expand Up @@ -1218,7 +1224,8 @@ private void handleOnMenuValidation(Menu menu) {
final Exception xx
= new Exception(c.getClass().getSimpleName()
+ ".canPerform() did break for menu item " + i, x); //NOI18N
xx.printStackTrace();

Logger.getLogger(getClass().getName()).log(Level.WARNING, xx.getMessage(), xx);
}
disable = !canPerform;
title = c.getTitle();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Gluon and/or its affiliates.
* Copyright (c) 2016, 2022, Gluon and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
* This file is available and licensed under the following license:
Expand Down Expand Up @@ -40,6 +40,8 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Tracking {
public static final String SCENEBUILDER_TYPE = "scenebuilder";
Expand Down Expand Up @@ -71,10 +73,8 @@ public static void sendTrackingInfo(String type, String hash, String email, bool
while (in.read() > -1) {
}
}
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} catch (Exception e) {
Logger.getLogger(Tracking.class.getName()).log(Level.WARNING, "Failed to send tracking info: ", e);
}
}, "UserRegistrationThread").start();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2021, Gluon and/or its affiliates.
* Copyright (c) 2016, 2022, Gluon and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
* This file is available and licensed under the following license:
Expand Down Expand Up @@ -50,6 +50,8 @@
import java.net.URL;
import java.util.Properties;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;

public class AppSettings {
public static final String APP_ICON_16 = SceneBuilderApp.class.getResource("SceneBuilderLogo_16.png").toString();
Expand Down Expand Up @@ -81,8 +83,8 @@ private static void initSceneBuiderVersion() {
sbProps.load(in);
sceneBuilderVersion = sbProps.getProperty("build.version", "UNSET");
}
} catch (IOException ex) {
ex.printStackTrace();
} catch (IOException e) {
Logger.getLogger(AppSettings.class.getName()).log(Level.WARNING, "Cannot init SB version:", e);
}
}

Expand Down Expand Up @@ -125,15 +127,15 @@ public static void getLatestVersion(Consumer<String> consumer) {
try {
url = new URL(LATEST_VERSION_CHECK_URL);
} catch (MalformedURLException e) {
e.printStackTrace();
Logger.getLogger(AppSettings.class.getName()).log(Level.WARNING, "Failed to construct version check URL: ", e);
}

try (InputStream inputStream = url.openStream()) {
prop.load(inputStream);
onlineVersionNumber = prop.getProperty(LATEST_VERSION_NUMBER_PROPERTY);

} catch (IOException ex) {
ex.printStackTrace();
} catch (IOException e) {
Logger.getLogger(AppSettings.class.getName()).log(Level.WARNING, "Failed to load latest version number property: ", e);
}
latestVersion = onlineVersionNumber;
consumer.accept(latestVersion);
Expand All @@ -160,10 +162,10 @@ private static void updateLatestVersionInfo() {
latestVersionText = announcementObject.getString("text");
latestVersionAnnouncementURL = announcementObject.getString("url");
} catch (IOException e) {
e.printStackTrace();
Logger.getLogger(AppSettings.class.getName()).log(Level.WARNING, "Failed to read latest version json: ", e);
}
} catch (MalformedURLException e) {
e.printStackTrace();
Logger.getLogger(AppSettings.class.getName()).log(Level.WARNING, "Failed to construct latest version info URL: ", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022, Gluon and/or its affiliates.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
Expand Down Expand Up @@ -42,6 +43,8 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* This class implements an simple IPC.
Expand Down Expand Up @@ -121,9 +124,9 @@ public void release() {

try {
boxMutex.unlock();
} catch(IOException x) {
} catch(IOException e) {
// Strange
x.printStackTrace();
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to unlock message box mutex: ", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.oracle.javafx.scenebuilder.kit.i18n.I18N;
import javafx.scene.Node;
Expand Down Expand Up @@ -208,7 +210,7 @@ public Color getColor() {
}
}
} catch (IOException e) {
e.printStackTrace();
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to get color from stylesheet: ", e);
}
}
return color;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018 Gluon and/or its affiliates.
* Copyright (c) 2016, 2022, Gluon and/or its affiliates.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
Expand Down Expand Up @@ -39,6 +39,8 @@
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import javafx.beans.value.ChangeListener;
import javafx.collections.ListChangeListener;
Expand Down Expand Up @@ -1049,8 +1051,8 @@ private void traceEvent(Event e) {
sb.append(", keyCode="); //NOI18N
sb.append(ke.getCode());
}
System.out.println(sb.toString());

Logger.getLogger(getClass().getName()).log(Level.INFO, sb.toString());
}

private final EventHandler<Event> eventTracingFilter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022, Gluon and/or its affiliates.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
Expand Down Expand Up @@ -69,6 +70,9 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.scene.Group;
Expand Down Expand Up @@ -777,7 +781,7 @@ private void handleInlineEditing(FXOMInstance hitObject) {
inlineEditController.startEditingSession(inlineEditor,
inlineEditingBounds, requestCommit, requestRevert);
} else {
System.out.println("Beep");
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Inline editing bounds object is null");
}

assert contentPanelController.getEditorController().isTextEditingSessionOnGoing()
Expand Down Expand Up @@ -825,7 +829,7 @@ private void keyPressedOnGlassLayer(KeyEvent e) {
if (RelocateSelectionJob.isSelectionMovable(contentPanelController.getEditorController())) {
activateGesture(new MoveWithKeyGesture(contentPanelController), e);
} else {
System.out.println("Selection is not movable");
Logger.getLogger(getClass().getName()).log(Level.INFO, "Selection is not movable");
}
e.consume();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
import java.net.URL;
import java.text.MessageFormat;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

import javafx.animation.FadeTransition;
import javafx.beans.property.ObjectProperty;
Expand Down Expand Up @@ -966,8 +968,8 @@ public void handle(ActionEvent event) {
EditorPlatform.open(DocumentationUrls.JAVADOC_HOME.toString()
+ "javafx.graphics/javafx/scene/doc-files/cssref.html#" + //NOI18N
item.getTarget().getClass().getSimpleName().toLowerCase(Locale.ROOT));
} catch (IOException ex) {
System.out.println(ex.getMessage());
} catch (IOException e) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to open JAVADOC_HOME: ", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017 Gluon and/or its affiliates.
* Copyright (c) 2017, 2022, Gluon and/or its affiliates.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
Expand Down Expand Up @@ -35,6 +35,9 @@
import com.oracle.javafx.scenebuilder.kit.fxom.FXOMObject;
import com.oracle.javafx.scenebuilder.kit.util.CssInternal;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import javafx.css.CssMetaData;
import javafx.css.Styleable;
import javafx.css.StyleableProperty;
Expand Down Expand Up @@ -155,8 +158,8 @@ static String getBeanPropertyName(Node node, CssMetaData<?, ?> sp) {
CssMetaData<Node, Object> raw = (CssMetaData<Node, Object>) sp;
final StyleableProperty<Object> val = raw.getStyleableProperty(node);
property = CssInternal.getBeanPropertyName(val);
} catch (RuntimeException ex) {
System.out.println("Can't retrieve property " + ex); //NOI18N
} catch (RuntimeException e) {
Logger.getLogger(CssUtils.class.getName()).log(Level.WARNING, "Failed to retrieve property: ", e);
}
return property;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import javafx.animation.FadeTransition;
import javafx.beans.property.BooleanProperty;
Expand Down Expand Up @@ -561,7 +563,7 @@ private void addCssVisual() {
try {
EditorPlatform.open(cssInfo.getMainUrl().toString());
} catch (IOException ex) {
System.out.println(ex.getMessage() + ex);
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to open css file:", ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
/*
* Copyright (c) 2022, Gluon and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
* This file is available and licensed under the following license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
* - Neither the name of Oracle Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.oracle.javafx.scenebuilder.kit.i18n;

import java.io.BufferedReader;
Expand All @@ -7,6 +39,8 @@
import java.util.Locale;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;

public class I18NControl extends ResourceBundle.Control {
@Override
Expand All @@ -17,8 +51,8 @@ public ResourceBundle newBundle(String baseName, Locale locale, String format, C
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
BufferedReader reader = new BufferedReader(isr)) {
return new PropertyResourceBundle(reader);
} catch (IOException ex) {
ex.printStackTrace();
} catch (IOException e) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to create ResourceBundle: ", e);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import java.io.IOException;
import java.net.URL;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
Expand Down Expand Up @@ -88,8 +90,8 @@ public FXOMDocument instantiate() {

try {
result = new FXOMDocument(fxmlText, null, library.getClassLoader(), null, FXOMDocumentSwitch.NORMALIZED);
} catch(Error|IOException x) {
x.printStackTrace();
} catch(Error|IOException e) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to instantiate a library item: ", e);
result = null;
}

Expand Down
Loading

0 comments on commit 256c360

Please sign in to comment.