Skip to content

Commit

Permalink
8239138: StyleManager should use a BufferedInputStream
Browse files Browse the repository at this point in the history
Reviewed-by: kcr, pbansal
  • Loading branch information
arapte committed Jun 1, 2021
1 parent 5e6d442 commit 526f990
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 1 deletion.
Expand Up @@ -923,7 +923,8 @@ static byte[] calculateCheckSum(String fname) {
try (final InputStream stream = url.openStream();
final DigestInputStream dis = new DigestInputStream(stream, MessageDigest.getInstance("MD5")); ) {
dis.getMessageDigest().reset();
while (dis.read() != -1) { /* empty loop body is intentional */ }
byte[] buffer = new byte[4096];
while (dis.read(buffer) != -1) { /* empty loop body is intentional */ }
return dis.getMessageDigest().digest();
}

Expand Down
Expand Up @@ -161,6 +161,10 @@ public StyleMap findMatchingStyles(Node node, SubScene subScene, Set<PseudoClass
return sm.findMatchingStyles(node, subScene, triggerStates);
}

public byte[] calculateCheckSum(String fname) {
return sm.calculateCheckSum(fname);
}

public boolean stylesheetContainerMap_containsKey(String k) {
return sm.stylesheetContainerMap.containsKey(k);
}
Expand Down
Expand Up @@ -47,6 +47,7 @@

import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -1109,4 +1110,14 @@ public void testConcurrentAccess() {
assertFalse("Exception during CSS processing on BG thread", err.get());
}

@Test
public void testCalculateCheckSum() {
StyleManagerShim sm = StyleManagerShim.getInstance();
byte[] checksum = sm.calculateCheckSum(getClass().getResource("checksum.css").toExternalForm());

byte[] expectedChecksum = {60, 26, 67, 14, 103, -63, -62, 42, 14, 40, -44, -103, 1, -60, -90, 18};
// "3c1a430e67c1c22a0e28d49901c4a612" // Generated using command 'md5sum checksum.css'

assertTrue(Arrays.equals(expectedChecksum, checksum));
}
}
@@ -0,0 +1,164 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

.root {
/***************************************************************************
* *
* The main color palette from which the rest of the colors are derived. *
* *
**************************************************************************/

/* A light grey that is the base color for objects. Instead of using
* -fx-base directly, the sections in this file will typically use -fx-color.
*/
-fx-base: #ececec;

/* A very light grey used for the background of windows. See also
* -fx-text-background-color, which should be used as the -fx-text-fill
* value for text painted on top of backgrounds colored with -fx-background.
*/
-fx-background: derive(-fx-base,26.4%);

/* Used for the inside of text boxes, password boxes, lists, trees, and
* tables. See also -fx-text-inner-color, which should be used as the
* -fx-text-fill value for text painted on top of backgrounds colored
* with -fx-control-inner-background.
*/
-fx-control-inner-background: derive(-fx-base,80%);
/* Version of -fx-control-inner-background for alternative rows */
-fx-control-inner-background-alt: derive(-fx-control-inner-background,-2%);

/* One of these colors will be chosen based upon a ladder calculation
* that uses the brightness of a background color. Instead of using these
* colors directly as -fx-text-fill values, the sections in this file should
* use a derived color to match the background in use. See also:
*
* -fx-text-base-color for text on top of -fx-base, -fx-color, and -fx-body-color
* -fx-text-background-color for text on top of -fx-background
* -fx-text-inner-color for text on top of -fx-control-inner-color
* -fx-selection-bar-text for text on top of -fx-selection-bar
*/
-fx-dark-text-color: black;
-fx-mid-text-color: #333;
-fx-light-text-color: white;

/* A bright blue for highlighting/accenting objects. For example: selected
* text; selected items in menus, lists, trees, and tables; progress bars */
-fx-accent: #0096C9;

/* Default buttons color, this is similar to accent but more subtle */
-fx-default-button: #ABD8ED;

/* A bright blue for the focus indicator of objects. Typically used as the
* first color in -fx-background-color for the "focused" pseudo-class. Also
* typically used with insets of -1.4 to provide a glowing effect.
*/
-fx-focus-color: #039ED3;
-fx-faint-focus-color: #039ED322;

/* The color that is used in styling controls. The default value is based
* on -fx-base, but is changed by pseudoclasses to change the base color.
* For example, the "hover" pseudoclass will typically set -fx-color to
* -fx-hover-base (see below) and the "armed" pseudoclass will typically
* set -fx-color to -fx-pressed-base.
*/
-fx-color: -fx-base;

/* Chart Color Palette */
CHART_COLOR_1: #f3622d;
CHART_COLOR_2: #fba71b;
CHART_COLOR_3: #57b757;
CHART_COLOR_4: #41a9c9;
CHART_COLOR_5: #4258c9;
CHART_COLOR_6: #9a42c8;
CHART_COLOR_7: #c84164;
CHART_COLOR_8: #888888;
/* Chart Color Palette Semi-Transparent
* These are used by charts that need semi transparent versions of the above colors, such as BubbleChart. They
* are exactly the same colors as above just with alpha
*
* 20% opacity
*/
CHART_COLOR_1_TRANS_20: #f3622d33;
CHART_COLOR_2_TRANS_20: #fba71b33;
CHART_COLOR_3_TRANS_20: #57b75733;
CHART_COLOR_4_TRANS_20: #41a9c933;
CHART_COLOR_5_TRANS_20: #4258c933;
CHART_COLOR_6_TRANS_20: #9a42c833;
CHART_COLOR_7_TRANS_20: #c8416433;
CHART_COLOR_8_TRANS_20: #88888833;
/* 70% opacity */
CHART_COLOR_1_TRANS_70: #f3622db3;
CHART_COLOR_2_TRANS_70: #fba71bb3;
CHART_COLOR_3_TRANS_70: #57b757b3;
CHART_COLOR_4_TRANS_70: #41a9c9b3;
CHART_COLOR_5_TRANS_70: #4258c9b3;
CHART_COLOR_6_TRANS_70: #9a42c8b3;
CHART_COLOR_7_TRANS_70: #c84164b3;
CHART_COLOR_8_TRANS_70: #888888b3;

/***************************************************************************
* *
* Colors that are derived from the main color palette. *
* *
**************************************************************************/

/* A little lighter than -fx-base and used as the -fx-color for the
* "hovered" pseudoclass state.
*/
-fx-hover-base: ladder(
-fx-base,
derive(-fx-base,20%) 20%,
derive(-fx-base,30%) 35%,
derive(-fx-base,40%) 50%
);

/* A little darker than -fx-base and used as the -fx-color for the
* "armed" pseudoclass state.
*
* TODO: should this be renamed to -fx-armed-base?
*/
-fx-pressed-base: derive(-fx-base,-6%);

/* The color to use for -fx-text-fill when text is to be painted on top of
* a background filled with the -fx-background color.
*/
-fx-text-background-color: ladder(
-fx-background,
-fx-light-text-color 45%,
-fx-dark-text-color 46%,
-fx-dark-text-color 59%,
-fx-mid-text-color 60%
);

/* A little darker than -fx-color and used to draw boxes around objects such
* as progress bars, scroll bars, scroll panes, trees, tables, and lists.
*/
-fx-box-border: ladder(
-fx-color,
black 20%,
derive(-fx-color,-15%) 30%
);
}

1 comment on commit 526f990

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.