mbien commented on code in PR #7938: URL: https://github.com/apache/netbeans/pull/7938#discussion_r1898763261
########## ide/svg/src/org/netbeans/modules/svg/SVGPanel.java: ########## @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.modules.svg; + +import com.github.weisj.jsvg.SVGDocument; +import com.github.weisj.jsvg.SVGRenderingHints; +import java.awt.*; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.*; + +/** + * + * @author Christian Lenz + */ +public class SVGPanel extends JPanel { + + private static final Logger LOG = Logger.getLogger(SVGViewerElement.class.getName()); + + private SVGDocument svgDocument; + private double scale = 1.0D; + private BackgroundMode bgMode = BackgroundMode.DEFAULT; + + public void setSVGDocument(SVGDocument doc) { + this.svgDocument = doc; + + repaint(); + } + + public void setScale(double scale) { + this.scale = scale; + + repaint(); + } + + public void setBackgroundMode(BackgroundMode mode) { + this.bgMode = mode; + + repaint(); + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + + Rectangle visibleRect = getVisibleRectangle(); + + switch (bgMode) { + case BLACK -> { + g.setColor(Color.BLACK); + g.fillRect(visibleRect.x, visibleRect.y, visibleRect.width, visibleRect.height); + } + case WHITE -> { + g.setColor(Color.WHITE); + g.fillRect(visibleRect.x, visibleRect.y, visibleRect.width, visibleRect.height); + } + + case TRANSPARENT, DARK_TRANSPARENT -> + Utils.drawChestTilePattern(g, visibleRect, 20, bgMode == BackgroundMode.DARK_TRANSPARENT); + case DEFAULT -> { + g.setColor(getBackground()); + g.fillRect(visibleRect.x, visibleRect.y, visibleRect.width, visibleRect.height); + } + } + + if (svgDocument == null) { + return; + } + + Graphics2D g2d = (Graphics2D) g.create(); + + try { + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + g2d.setRenderingHint(SVGRenderingHints.KEY_MASK_CLIP_RENDERING, SVGRenderingHints.VALUE_MASK_CLIP_RENDERING_ACCURACY); + + g2d.scale(scale, scale); Review Comment: move one line up so that this is no longer in the try-catch -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
