diff --git a/TULIP/config/about.html b/TULIP/config/about.html index eeac1b6a948fe22096b58b86e2ca9a1c98baaf30..6365589e2f76739762206741eb4d99478174f886 100644 --- a/TULIP/config/about.html +++ b/TULIP/config/about.html @@ -1,8 +1,8 @@ -

${Title}

-

${Description}

-

Version : ${Version} Current Scenario : ${Filename} (${LastModified})

+

${Title}

+

${Description}

+

Version : ${Version} Current Scenario : ${Filename} (${LastModified})


-

Installed Tulip Packages

-

${Packages}

+

Installed Tulip Packages

+

${Packages}

\ No newline at end of file diff --git a/TULIP/config/aboutStyles.properties b/TULIP/config/aboutStyles.properties new file mode 100644 index 0000000000000000000000000000000000000000..1cca9d1b1e2f94d4d88c140b8a89c40a8264cbc1 --- /dev/null +++ b/TULIP/config/aboutStyles.properties @@ -0,0 +1,4 @@ +h1.about= { font-family: Arial, Helvetica Neue, Helvetica, sans-serif; color: #ffffff; font-size: 1.4em; text-align: left; font-style: bold; } +h2.about= { font-family: Arial, Helvetica Neue, Helvetica, sans-serif; color: #ffffff; font-size: 1.2em; text-align: left; font-style: bold; } +h3.about= { font-family: Arial, Helvetica Neue, Helvetica, sans-serif; color: #ffffff; font-size: 1.1em; text-align: left; font-style: bold; } +p.about= { font-family: Arial, Helvetica Neue, Helvetica, sans-serif; color: #b0b0b0; font-size: 1.0em; text-align: left; } \ No newline at end of file diff --git a/TULIP/config/assets/arrow-1.png b/TULIP/config/assets/arrow-1.png new file mode 100644 index 0000000000000000000000000000000000000000..8f3abbef27050dca0c369a51b532981fded898c7 Binary files /dev/null and b/TULIP/config/assets/arrow-1.png differ diff --git a/TULIP/config/assets/arrow-2.png b/TULIP/config/assets/arrow-2.png new file mode 100644 index 0000000000000000000000000000000000000000..e19f10f6ae15266b1d383899041d9509beec5316 Binary files /dev/null and b/TULIP/config/assets/arrow-2.png differ diff --git a/TULIP/config/assets/arrow-3.png b/TULIP/config/assets/arrow-3.png new file mode 100644 index 0000000000000000000000000000000000000000..dbadbdb4e5d27cf004a74ea538e2b56836297504 Binary files /dev/null and b/TULIP/config/assets/arrow-3.png differ diff --git a/TULIP/config/assets/arrow-4.png b/TULIP/config/assets/arrow-4.png new file mode 100644 index 0000000000000000000000000000000000000000..e92177d9497bc8d11cdc5b248da0187f9ec8180f Binary files /dev/null and b/TULIP/config/assets/arrow-4.png differ diff --git a/TULIP/config/assets/b.png b/TULIP/config/assets/b.png new file mode 100644 index 0000000000000000000000000000000000000000..cf1a35f34e2ea3247d6449f74d9ba8d2b403a68a Binary files /dev/null and b/TULIP/config/assets/b.png differ diff --git a/TULIP/config/assets/c.png b/TULIP/config/assets/c.png new file mode 100644 index 0000000000000000000000000000000000000000..ff014162e06ef28e4bdcd1e355ac69b190819612 Binary files /dev/null and b/TULIP/config/assets/c.png differ diff --git a/TULIP/config/assets/ctrl-2.png b/TULIP/config/assets/ctrl-2.png new file mode 100644 index 0000000000000000000000000000000000000000..545fc0fc38f8575ad5e767b4606522319999b518 Binary files /dev/null and b/TULIP/config/assets/ctrl-2.png differ diff --git a/TULIP/config/assets/ctrl.png b/TULIP/config/assets/ctrl.png new file mode 100644 index 0000000000000000000000000000000000000000..28164fdacf41c2344ae5fdb6c0ba28c5d0ab6f3e Binary files /dev/null and b/TULIP/config/assets/ctrl.png differ diff --git a/TULIP/config/assets/enter-2.png b/TULIP/config/assets/enter-2.png new file mode 100644 index 0000000000000000000000000000000000000000..4965f5b8458aa8e0828e1cf7813e7d877811ec53 Binary files /dev/null and b/TULIP/config/assets/enter-2.png differ diff --git a/TULIP/config/assets/esc.png b/TULIP/config/assets/esc.png new file mode 100644 index 0000000000000000000000000000000000000000..641ef7a7dd5899c2a7b54663a4d79f30aa6b30e5 Binary files /dev/null and b/TULIP/config/assets/esc.png differ diff --git a/TULIP/config/assets/s.png b/TULIP/config/assets/s.png new file mode 100644 index 0000000000000000000000000000000000000000..c2989033e4a1743f38061b5dee1e1d78d8017275 Binary files /dev/null and b/TULIP/config/assets/s.png differ diff --git a/TULIP/config/assets/t.png b/TULIP/config/assets/t.png new file mode 100644 index 0000000000000000000000000000000000000000..29aed61b0ec33a176e004bdf72e8d5bbf50bf74a Binary files /dev/null and b/TULIP/config/assets/t.png differ diff --git a/TULIP/config/assets/w.png b/TULIP/config/assets/w.png new file mode 100644 index 0000000000000000000000000000000000000000..45b72f02fbefb0f6075dcf5e79fdfb53ab472753 Binary files /dev/null and b/TULIP/config/assets/w.png differ diff --git a/TULIP/config/calibrationStyles.properties b/TULIP/config/calibrationStyles.properties new file mode 100644 index 0000000000000000000000000000000000000000..6db835a4a956b2339451e087c4dca79f10222164 --- /dev/null +++ b/TULIP/config/calibrationStyles.properties @@ -0,0 +1,3 @@ +h1.help= { font-family: Arial, Helvetica Neue, Helvetica, sans-serif; color: #10526f; font-size: 1.4em; text-align: left; font-style: bold; } +h2.help= { font-family: Arial, Helvetica Neue, Helvetica, sans-serif; color: #9a4a94; font-size: 1.2em; text-align: left; font-style: bold; } +p.help= { font-family: Arial, Helvetica Neue, Helvetica, sans-serif; color: #404040; font-size: 1.0em; text-align: left; } diff --git a/TULIP/config/calibration_help.html b/TULIP/config/calibration_help.html new file mode 100644 index 0000000000000000000000000000000000000000..36f19f1c2f817acd225e753b5525e5a27c191a4d --- /dev/null +++ b/TULIP/config/calibration_help.html @@ -0,0 +1,70 @@ + + + + +Calibration Screen + + +

Calibration Screen

+

The calibration screen is required to properly setup TULIP when used in conjunction with DIY tangible tables. DIY tables in general are +a combination of a camera system and a video projector, both mechanically aligned with the semi-translucent projection surface. Minor +mechanical inaccuracies affects both the projected scene which may be either cropped or not fully fill the projection surface respectively, +or the alignment of the physical objects on the table and their rendered digital counterparts. +

System Selection

+

The first step in the calibration process consists in selecting the system to be adjusted. It is in general recommended to start with the +Screen system and to adjust the Camera system subsequently.

+ + + + + + + + + +

Selects the Screen system as the system to be adjusted.

Selects the Camera system as the system to be adjusted.

+

Corner Selection

+

Once the system to be adjusted has been selected, the next step consists in selecting the corner to be adjusted.

+ + + + + + + + + +

Selects the Top Left corner as the corner to be adjusted.

Selects the Bottom Right corner as the corner to be adjusted.

+

Corner Adjustment

+ + + + + + + + + + + + +

Use the cursor keys to move the currently selected corner.

+

Exit

+

You may leave the calibration screen by pressing one of the following keys:

+ + + + + + + + + + + + + + +

Returns to the application and keeps the current adjustments without saving them.

Returns to the application and discards the current adjustments, reverting to the original calibration found in the calibration file.

Returns to the application and saves the current adjustments to the calibration file.

+ + \ No newline at end of file diff --git a/TULIP/config/tulip_package.html b/TULIP/config/tulip_package.html index 1cf14a120aeb3dd0f1be7bfe265843fe39186288..c68a92de967b7b60f070e4f772be60d8c5209f9c 100644 --- a/TULIP/config/tulip_package.html +++ b/TULIP/config/tulip_package.html @@ -1,2 +1,2 @@ -

${Name} - ${Version}

-

(Build Date : ${BuildDate} | Build Number : ${BuildNumber})

\ No newline at end of file +

${Name} - ${Version}

+

(Build Date : ${BuildDate} | Build Number : ${BuildNumber})

\ No newline at end of file diff --git a/TULIP/src/lu/list/itis/dkd/tui/ResourceLocator.java b/TULIP/src/lu/list/itis/dkd/tui/ResourceLocator.java new file mode 100644 index 0000000000000000000000000000000000000000..0a93a0d3f36e1b3d0c7c2448072789bfb2e16fac --- /dev/null +++ b/TULIP/src/lu/list/itis/dkd/tui/ResourceLocator.java @@ -0,0 +1,100 @@ +/** + * Copyright Luxembourg Institute of Science and Technology, 2018. All rights reserved. + * + * This file is part of TULIP. + * + * TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation, version 3 of the + * License. + * + * TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with TULIP. If + * not, see . + */ +package lu.list.itis.dkd.tui; + +import lu.list.itis.dkd.tui.utility.SplashScreen; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.net.URL; + +import javax.imageio.ImageIO; + +/** + * @author mack + * @since [major].[minor] + * @version [major].[minor].[micro] + */ +// *************************************************************************** +// * Class Definition and Members * +// *************************************************************************** + +public class ResourceLocator { + + // *************************************************************************** + // * Constants + // *************************************************************************** + + private static final Logger LOGGER = LoggerFactory.getLogger(SplashScreen.class.getSimpleName()); + + // --------------------------------------------------------------------------- + // *************************************************************************** + // * Constructor(s) + // *************************************************************************** + // --------------------------------------------------------------------------- + + private ResourceLocator() {} + + // --------------------------------------------------------------------------- + // *************************************************************************** + // * Class Body + // *************************************************************************** + // --------------------------------------------------------------------------- + /** + * @param imagePath + * @return + */ + // --------------------------------------------------------------------------- + + public static BufferedImage getImage(String imagePath) { + return getImage(ResourceLocator.class, imagePath); + } + + // --------------------------------------------------------------------------- + /** + * @param referenceClass + * @param imagePath + * @return + */ + // --------------------------------------------------------------------------- + + public static BufferedImage getImage(Class referenceClass, String imagePath) { + URL location = referenceClass.getResource(imagePath); + BufferedImage image = null; + + if (location != null) + try { + image = ImageIO.read(location); + } catch (IOException exception) { + LOGGER.error("I/O Error while attempting to read {}!", imagePath, exception); //$NON-NLS-1$ + } + + if ((image == null) || (image.getHeight() <= 0)) { + LOGGER.warn("Couldn't find Image {} relative to {}!", imagePath, referenceClass.getName()); //$NON-NLS-1$ + } + return image; + } + + // --------------------------------------------------------------------------- + // *************************************************************************** + // * End of Class + // *************************************************************************** + // --------------------------------------------------------------------------- +} diff --git a/TULIP/src/lu/list/itis/dkd/tui/TangibleInterfaceManager.java b/TULIP/src/lu/list/itis/dkd/tui/TangibleInterfaceManager.java index 38b296783b06e5f93aa59c7e83a9823da3a6d353..3e5f36424c6e29b2c9b54cafbfcd23389ad65d6f 100644 --- a/TULIP/src/lu/list/itis/dkd/tui/TangibleInterfaceManager.java +++ b/TULIP/src/lu/list/itis/dkd/tui/TangibleInterfaceManager.java @@ -113,6 +113,7 @@ public class TangibleInterfaceManager extends Stage { private CalibrationScreen calibrationScreen; private String aboutHtml; + private String helpHtml; // *************************************************************************** // * Constant(s) * @@ -121,6 +122,7 @@ public class TangibleInterfaceManager extends Stage { protected static final Logger LOGGER = LoggerFactory.getLogger(TangibleInterfaceManager.class.getSimpleName()); private static final String ABOUT_HTML_TEMPLATE = "/about.html"; //$NON-NLS-1$ + private static final String HELP_HTML_TEMPLATE = "/calibration_help.html"; //$NON-NLS-1$ private static final String PACKAGE_HTML_TEMPLATE = "/tulip_package.html"; //$NON-NLS-1$ private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\$\\{([a-z0-9\\-_]+)\\}", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$ // private static final Pattern URI_PATTERN = Pattern.compile("^file:(.*?)$", @@ -136,7 +138,7 @@ public class TangibleInterfaceManager extends Stage { * * @param properties * The {@link TangibleApplication} hosting this manager. - * @param properties + * @param bootstrap * The properties instance from which to load the default values from. */ // --------------------------------------------------------------------------- @@ -157,6 +159,7 @@ public class TangibleInterfaceManager extends Stage { Calibration.loadFromFile(calibrationFileURI); aboutHtml = this.renderAbout(); + helpHtml = this.renderHelp(); /** * Checks added due to missing contracts on inherited or implemented classes or interfaces. @@ -302,6 +305,16 @@ public class TangibleInterfaceManager extends Stage { // --------------------------------------------------------------------------- + private String renderHelp() { + Map helpFields = new HashMap<>(); + helpFields.put("AssetsURL", this.getClass().getResource("/assets")); + + String helpTemplate = this.readHtmlTemplate(HELP_HTML_TEMPLATE); + return (this.renderTemplate(helpTemplate, helpFields)); + } + + // --------------------------------------------------------------------------- + private void handleCalibrationScreen(CalibrationScreen.ExitAction action) { switch (action) { case REVERT: @@ -354,6 +367,7 @@ public class TangibleInterfaceManager extends Stage { splashScreen.setAbout(this.aboutHtml); calibrationScreen = new CalibrationScreen(this.bounds.width, this.bounds.height); + calibrationScreen.setHelp(helpHtml); calibrationScreen.setVisible(false); window.getContentPane().add(calibrationScreen); } @@ -371,8 +385,10 @@ public class TangibleInterfaceManager extends Stage { public void keyPressed(@Nullable KeyEvent event) { Preconditions.checkArgument(event != null, "The event is null!"); //$NON-NLS-1$ switch (event.getKeyCode()) { - case KeyEvent.VK_ESCAPE: - System.exit(0); + case KeyEvent.VK_Q: + if (event.isControlDown()) { + System.exit(0); + } break; case KeyEvent.VK_A: if (splashShown) { @@ -440,6 +456,7 @@ public class TangibleInterfaceManager extends Stage { protected void hideCalibrationScreen() { calibrationScreen.setVisible(false); calibrationShown = false; + window.requestFocus(); } // --------------------------------------------------------------------------- diff --git a/TULIP/src/lu/list/itis/dkd/tui/resources/BottomRight.png b/TULIP/src/lu/list/itis/dkd/tui/resources/BottomRight.png new file mode 100644 index 0000000000000000000000000000000000000000..898bf4097f442bba2a0e675d70f58ee9aefaddf9 Binary files /dev/null and b/TULIP/src/lu/list/itis/dkd/tui/resources/BottomRight.png differ diff --git a/TULIP/src/lu/list/itis/dkd/tui/resources/TopLeft.png b/TULIP/src/lu/list/itis/dkd/tui/resources/TopLeft.png new file mode 100644 index 0000000000000000000000000000000000000000..249ad855ecba2b507a7b051a918e6d5b5941aa1a Binary files /dev/null and b/TULIP/src/lu/list/itis/dkd/tui/resources/TopLeft.png differ diff --git a/TULIP/src/lu/list/itis/dkd/tui/utility/CalibrationScreen.java b/TULIP/src/lu/list/itis/dkd/tui/utility/CalibrationScreen.java index c3dee2a57202407d267e43adaefff8da15ed7b4a..6eed508fb86915862c97270a3390a049fb540142 100644 --- a/TULIP/src/lu/list/itis/dkd/tui/utility/CalibrationScreen.java +++ b/TULIP/src/lu/list/itis/dkd/tui/utility/CalibrationScreen.java @@ -16,6 +16,8 @@ */ package lu.list.itis.dkd.tui.utility; +import lu.list.itis.dkd.tui.ResourceLocator; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,8 +28,14 @@ import java.awt.Graphics2D; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.geom.Line2D; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.StringReader; +import javax.swing.JEditorPane; import javax.swing.JPanel; +import javax.swing.text.html.HTMLEditorKit; +import javax.swing.text.html.StyleSheet; /** * @author mack @@ -43,6 +51,9 @@ public class CalibrationScreen extends JPanel implements KeyListener { private Corner corner; private CoordinateSystem system; private ExitAction action; + private JEditorPane help; + private BufferedImage topLeftIcon; + private BufferedImage bottomRightIcon; // *************************************************************************** // * Constants * @@ -54,8 +65,13 @@ public class CalibrationScreen extends JPanel implements KeyListener { private static final long serialVersionUID = 1L; - private static final Color SCREEN_COLOUR = new Color(255, 255, 255, 80); - private static final Color GRID_COLOUR = new Color(80, 80, 80, 255); + private static final String CALIBRATION_STLES = "calibrationStyles.properties"; //$NON-NLS-1$ + + private static final String TOPLEFT_ICON = "resources/TopLeft.png"; //$NON-NLS-1$ + private static final String BOTTOMRIGHT_ICON = "resources/BottomRight.png"; //$NON-NLS-1$ + + private static final Color SCREEN_COLOUR = new Color(255, 255, 255, 127); + private static final Color GRID_COLOUR = new Color(80, 80, 80, 127); private static final int GRID_COLUMNS = 9; private static final int GRID_ROWS = 7; @@ -97,13 +113,37 @@ public class CalibrationScreen extends JPanel implements KeyListener { // --------------------------------------------------------------------------- public CalibrationScreen(int screenWidth, int screenHeight) { + this.corner = Corner.NONE; + this.system = CoordinateSystem.NONE; + this.action = ExitAction.NONE; + + this.topLeftIcon = ResourceLocator.getImage(TOPLEFT_ICON); + this.bottomRightIcon = ResourceLocator.getImage(BOTTOMRIGHT_ICON); + this.setSize(new Dimension(screenWidth, screenHeight)); this.setPreferredSize(new Dimension(screenWidth, screenHeight)); this.setOpaque(false); this.addKeyListener(this); - this.corner = Corner.NONE; - this.system = CoordinateSystem.NONE; - this.action = ExitAction.NONE; + + int helpWidth = (int) (screenWidth * 0.75); + int helpHeight = (int) (screenHeight * 0.75); + + HTMLEditorKit htmlEditor = new HTMLEditorKit(); + StyleSheet stylesheet = htmlEditor.getStyleSheet(); + stylesheet = StyleSheetReader.populateStyleSheet(stylesheet, CALIBRATION_STLES); + + help = new JEditorPane(); + help.setContentType("text/html"); //$NON-NLS-1$ + help.setEditorKit(htmlEditor); + help.setEditable(false); + help.setOpaque(true); + help.setDoubleBuffered(false); + help.setBackground(SCREEN_COLOUR); + help.setPreferredSize(new Dimension(helpWidth, helpHeight)); + help.setLocation((screenWidth - helpWidth) / 2, (screenHeight - helpHeight) / 2); + + this.add(help); + } // --------------------------------------------------------------------------- @@ -216,6 +256,19 @@ public class CalibrationScreen extends JPanel implements KeyListener { // * Class Body // *************************************************************************** // --------------------------------------------------------------------------- + /** + * @param htmlContent + */ + // --------------------------------------------------------------------------- + + public void setHelp(String htmlContent) { + try { + help.read(new StringReader(htmlContent), null); + } catch (IOException exception) { + LOGGER.error("failed to update HTML content!", exception); //$NON-NLS-1$ + } + } + // --------------------------------------------------------------------------- @Override public void setVisible(boolean showIt) { @@ -311,10 +364,12 @@ public class CalibrationScreen extends JPanel implements KeyListener { // --------------------------------------------------------------------------- @Override - public void paintComponent(Graphics canvas) { + public void paint(Graphics canvas) { + super.paint(canvas); + Graphics2D canvas2D = (Graphics2D) canvas; - canvas2D.setColor(SCREEN_COLOUR); - canvas2D.fillRect(0, 0, Calibration.getScreenWidth(), Calibration.getScreenHeight()); + // canvas2D.setColor(SCREEN_COLOUR); + // canvas2D.fillRect(0, 0, Calibration.getScreenWidth(), Calibration.getScreenHeight()); canvas2D.setColor(GRID_COLOUR); float left = Calibration.getCameraLeft(); @@ -335,6 +390,14 @@ public class CalibrationScreen extends JPanel implements KeyListener { int y = Calibration.cameraToScreenY(top) + i * height / (GRID_ROWS - 1); canvas2D.draw(new Line2D.Float(Calibration.cameraToScreenX(left), y, Calibration.cameraToScreenX(right), y)); } + + if (this.corner == Corner.TOP_LEFT) { + canvas.drawImage(topLeftIcon, Calibration.cameraToScreenX(left) + 5, Calibration.cameraToScreenY(top) + 5, null); + } else if (this.corner == Corner.BOTTOM_RIGHT) { + canvas.drawImage(bottomRightIcon, Calibration.cameraToScreenX(right) - bottomRightIcon.getWidth() - 5, + Calibration.cameraToScreenY(bottom) - bottomRightIcon.getHeight() - 5, null); + } + } // --------------------------------------------------------------------------- diff --git a/TULIP/src/lu/list/itis/dkd/tui/utility/SplashScreen.java b/TULIP/src/lu/list/itis/dkd/tui/utility/SplashScreen.java index 984d18a8704632a1786547ef3819dfe77d03b419..fb87e07ce9df30ccfca60389233da667f7c610a7 100644 --- a/TULIP/src/lu/list/itis/dkd/tui/utility/SplashScreen.java +++ b/TULIP/src/lu/list/itis/dkd/tui/utility/SplashScreen.java @@ -16,7 +16,7 @@ */ package lu.list.itis.dkd.tui.utility; -import lu.list.itis.dkd.tui.TangibleApplication; +import lu.list.itis.dkd.tui.ResourceLocator; import lu.list.itis.dkd.tui.logging.LogListener; import lu.list.itis.dkd.tui.logging.OnScreenLogAppender; @@ -33,9 +33,7 @@ import java.awt.Image; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.StringReader; -import java.net.URL; -import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JEditorPane; import javax.swing.JLabel; @@ -74,6 +72,7 @@ public class SplashScreen extends JPanel implements LogListener { private static final Logger LOGGER = LoggerFactory.getLogger(SplashScreen.class.getSimpleName()); + private static final String ABOUT_STLES = "aboutStyles.properties"; //$NON-NLS-1$ private static final String LOGO_PATH = "resources/TULIP.png"; //$NON-NLS-1$ private static final String COLUMN_SPECS = "5dlu, left:pref, 50dlu, 100dlu:grow, 5dlu"; //$NON-NLS-1$ private static final String ROW_SPECS = "5dlu, center:300dlu, 5dlu, top:pref:grow,5dlu"; //$NON-NLS-1$ @@ -85,7 +84,7 @@ public class SplashScreen extends JPanel implements LogListener { // --------------------------------------------------------------------------- public SplashScreen(int screenWidth, int screenHeight) { - logo = this.getImage(TangibleApplication.class, LOGO_PATH); + logo = ResourceLocator.getImage(LOGO_PATH); this.setLayout(new FormLayout(COLUMN_SPECS, ROW_SPECS)); this.setBackground(Color.BLACK); this.setSize(new Dimension(screenWidth, screenHeight)); @@ -123,10 +122,7 @@ public class SplashScreen extends JPanel implements LogListener { HTMLEditorKit htmlEditor = new HTMLEditorKit(); StyleSheet stylesheet = htmlEditor.getStyleSheet(); - stylesheet.addRule("h1 { font-family: Arial, Helvetica Neue, Helvetica, sans-serif; color: #ffffff; font-size: 1.4em; text-align: left; font-style: bold; }"); //$NON-NLS-1$ - stylesheet.addRule("h2 { font-family: Arial, Helvetica Neue, Helvetica, sans-serif; color: #ffffff; font-size: 1.2em; text-align: left; font-style: bold; }"); //$NON-NLS-1$ - stylesheet.addRule("h3 { font-family: Arial, Helvetica Neue, Helvetica, sans-serif; color: #ffffff; font-size: 1.1em; text-align: left; font-style: bold; }"); //$NON-NLS-1$ - stylesheet.addRule("p { font-family: Arial, Helvetica Neue, Helvetica, sans-serif; color: #b0b0b0; font-size: 1.0em; text-align: left; }"); //$NON-NLS-1$ + stylesheet = StyleSheetReader.populateStyleSheet(stylesheet, ABOUT_STLES); about = new JEditorPane(); about.setContentType("text/html"); //$NON-NLS-1$ @@ -136,14 +132,6 @@ public class SplashScreen extends JPanel implements LogListener { about.setOpaque(false); about.setDoubleBuffered(false); - // Font aboutFont = new Font("Arial", Font.BOLD, 16); - // metrics = about.getFontMetrics(aboutFont); - // columns = (int) (screenWidth / 2 * (metrics.charWidth('A') * 1.4)); - // rows = (int) ((0.8 * screenHeight) / (2 * metrics.getHeight())); - // about.setFont(aboutFont); - // about.setColumns(columns); - // about.setRows(rows); - aboutScroller = new JScrollPane(about); aboutScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); aboutScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); @@ -161,26 +149,6 @@ public class SplashScreen extends JPanel implements LogListener { // *************************************************************************** // * Primitives(s) // *************************************************************************** - - // --------------------------------------------------------------------------- - - private BufferedImage getImage(Class referenceClass, String imagePath) { - URL location = referenceClass.getResource(imagePath); - BufferedImage image = null; - - if (location != null) - try { - image = ImageIO.read(location); - } catch (IOException exception) { - LOGGER.error("I/O Error while attempting to read {}!", imagePath, exception); //$NON-NLS-1$ - } - - if ((image == null) || (image.getHeight() <= 0)) { - LOGGER.warn("Couldn't find Image {} relative to {}!", imagePath, referenceClass.getName()); //$NON-NLS-1$ - } - return image; - } - // --------------------------------------------------------------------------- /** {@inheritDoc} */ diff --git a/TULIP/src/lu/list/itis/dkd/tui/utility/StyleSheetReader.java b/TULIP/src/lu/list/itis/dkd/tui/utility/StyleSheetReader.java new file mode 100644 index 0000000000000000000000000000000000000000..9fed4438b34940a1ee9e349f06c76e3816629695 --- /dev/null +++ b/TULIP/src/lu/list/itis/dkd/tui/utility/StyleSheetReader.java @@ -0,0 +1,117 @@ +/** + * Copyright Luxembourg Institute of Science and Technology, 2018. All rights reserved. + * + * This file is part of TULIP. + * + * TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License as published by the Free Software Foundation, version 3 of the + * License. + * + * TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser + * General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with TULIP. If + * not, see . + */ +package lu.list.itis.dkd.tui.utility; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Properties; + +import javax.swing.text.html.StyleSheet; + +/** + * @author mack + * @since [major].[minor] + * @version [major].[minor].[micro] + */ +// *************************************************************************** +// * Class Definition and Members * +// *************************************************************************** + +public class StyleSheetReader { + + // *************************************************************************** + // * Constants * + // *************************************************************************** + + private static final Logger LOGGER = LoggerFactory.getLogger(StyleSheetReader.class.getSimpleName()); + + // --------------------------------------------------------------------------- + // *************************************************************************** + // * Constructor(s) + // *************************************************************************** + // --------------------------------------------------------------------------- + + private StyleSheetReader() {} + + // --------------------------------------------------------------------------- + // *************************************************************************** + // * Primitive(s) + // *************************************************************************** + // --------------------------------------------------------------------------- + /** + * Method loading a given property file. The properties must be on the class path accessible by the + * the class loader to find. + * + * @param location + * The name of the properties file to load. + * @return The property file. + */ + // --------------------------------------------------------------------------- + + private static Properties fetchProperties(final String location) { + Properties properties = new Properties(); + + try (FileInputStream inputStream = new FileInputStream(new File(location))) { + properties.load(inputStream); + return properties; + } catch (IOException e) { + LOGGER.warn("Properties file {} could not be loaded! Trying as resource...", location); //$NON-NLS-1$ + try { + properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(location)); + } catch (final IOException ioe) { + LOGGER.error("The porperties file could not be loaded!", ioe); //$NON-NLS-1$ + } + } + return properties; + } + + // --------------------------------------------------------------------------- + // *************************************************************************** + // * Class Body + // *************************************************************************** + // --------------------------------------------------------------------------- + /** + * @param styleSheet + * @param stylesLocation + * @return + */ + // --------------------------------------------------------------------------- + + public static StyleSheet populateStyleSheet(StyleSheet styleSheet, String stylesLocation) { + Properties styles = fetchProperties(stylesLocation); + + for (String property : styles.stringPropertyNames()) { + StringBuilder style = new StringBuilder(property); + style.append(styles.getProperty(property)); + styleSheet.addRule(style.toString()); + } + + return styleSheet; + } + + // --------------------------------------------------------------------------- + // *************************************************************************** + // * End of Class + // *************************************************************************** + // --------------------------------------------------------------------------- + + +}