Skip to content

Commit

Permalink
Code cleanup in new SVG module, addressed by the reviewers
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris2011 committed Dec 23, 2024
1 parent 9a84233 commit f01fda6
Show file tree
Hide file tree
Showing 13 changed files with 421 additions and 73 deletions.
5 changes: 1 addition & 4 deletions ide/svg/licenseinfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@
-->
<licenseinfo>
<fileset>
<file>src/org/netbeans/modules/svg/resources/svgLogo.svg</file>
<file>src/org/netbeans/modules/svg/resources/svgLogo.png</file>
<license ref="Apache-2.0-ASF" />
<comment type="COMMENT_UNSUPPORTED">
Images for the SVG filetype
</comment>
<comment type="COMMENT_UNSUPPORTED" />
</fileset>
</licenseinfo>
3 changes: 1 addition & 2 deletions ide/svg/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@
# specific language governing permissions and limitations
# under the License.

is.eager=true
javac.source=17
javac.release=17
javac.compilerargs=-Xlint -Xlint:-serial
93 changes: 75 additions & 18 deletions ide/svg/src/org/netbeans/modules/svg/SVGDataObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,92 @@
* @author Christian Lenz
*/
@NbBundle.Messages({
"LBL_Svg_LOADER=Files of SVG"
"LBL_SVG_LOADER=Files of SVG"
})
@MIMEResolver.ExtensionRegistration(
displayName = "#LBL_Svg_LOADER",
displayName = "#LBL_SVG_LOADER",
mimeType = SVGDataObject.MIME_TYPE,
extension = {"svg", "SVG"},
position = 20367
)
@DataObject.Registration(
mimeType = SVGDataObject.MIME_TYPE,
iconBase = "org/netbeans/modules/svg/resources/svgLogo.png",
displayName = "#LBL_Svg_LOADER",
displayName = "#LBL_SVG_LOADER",
position = 300
)
@ActionReferences(value = {
@ActionReference(id = @ActionID(category = "System", id = "org.openide.actions.OpenAction"), path = "Loaders/image/svg+xml/Actions", position = 100),
@ActionReference(id = @ActionID(category = "System", id = "org.openide.actions.ViewAction"), path = "Loaders/image/svg+xml/Actions", position = 200, separatorAfter = 400),
@ActionReference(id = @ActionID(category = "XML", id = "org.netbeans.modules.xml.tools.actions.CheckAction"), path = "Loaders/image/svg+xml/Actions", position = 600),
@ActionReference(id = @ActionID(category = "XML", id = "org.netbeans.modules.xml.tools.actions.ValidateAction"), path = "Loaders/image/svg+xml/Actions", position = 700, separatorAfter = 750),
@ActionReference(id = @ActionID(category = "Edit", id = "org.openide.actions.CutAction"), path = "Loaders/image/svg+xml/Actions", position = 800),
@ActionReference(id = @ActionID(category = "Edit", id = "org.openide.actions.CopyAction"), path = "Loaders/image/svg+xml/Actions", position = 900),
@ActionReference(id = @ActionID(category = "Edit", id = "org.openide.actions.PasteAction"), path = "Loaders/image/svg+xml/Actions", position = 1000, separatorAfter = 1100),
@ActionReference(id = @ActionID(category = "Edit", id = "org.openide.actions.DeleteAction"), path = "Loaders/image/svg+xml/Actions", position = 1200),
@ActionReference(id = @ActionID(category = "System", id = "org.openide.actions.RenameAction"), path = "Loaders/image/svg+xml/Actions", position = 1300, separatorAfter = 1400),
@ActionReference(id = @ActionID(category = "System", id = "org.openide.actions.SaveAsTemplateAction"), path = "Loaders/image/svg+xml/Actions", position = 1500),
@ActionReference(id = @ActionID(category = "System", id = "org.openide.actions.FileSystemAction"), path = "Loaders/image/svg+xml/Actions", position = 1550, separatorAfter = 1600),
@ActionReference(id = @ActionID(category = "System", id = "org.openide.actions.ToolsAction"), path = "Loaders/image/svg+xml/Actions", position = 1700),
@ActionReference(id = @ActionID(category = "System", id = "org.openide.actions.PropertiesAction"), path = "Loaders/image/svg+xml/Actions", position = 1800)}
)
@ActionReferences({
@ActionReference(
id = @ActionID(category = "System", id = "org.openide.actions.OpenAction"),
path = "Loaders/image/svg+xml/Actions",
position = 100
),
@ActionReference(
id = @ActionID(category = "System", id = "org.openide.actions.ViewAction"),
path = "Loaders/image/svg+xml/Actions",
position = 200,
separatorAfter = 400
),
@ActionReference(
id = @ActionID(category = "XML", id = "org.netbeans.modules.xml.tools.actions.CheckAction"),
path = "Loaders/image/svg+xml/Actions",
position = 600
),
@ActionReference(
id = @ActionID(category = "XML", id = "org.netbeans.modules.xml.tools.actions.ValidateAction"),
path = "Loaders/image/svg+xml/Actions",
position = 700,
separatorAfter = 750
),
@ActionReference(
id = @ActionID(category = "Edit", id = "org.openide.actions.CutAction"),
path = "Loaders/image/svg+xml/Actions",
position = 800
),
@ActionReference(
id = @ActionID(category = "Edit", id = "org.openide.actions.CopyAction"),
path = "Loaders/image/svg+xml/Actions",
position = 900
),
@ActionReference(
id = @ActionID(category = "Edit", id = "org.openide.actions.PasteAction"),
path = "Loaders/image/svg+xml/Actions",
position = 1000,
separatorAfter = 1100
),
@ActionReference(
id = @ActionID(category = "Edit", id = "org.openide.actions.DeleteAction"),
path = "Loaders/image/svg+xml/Actions",
position = 1200
),
@ActionReference(
id = @ActionID(category = "System", id = "org.openide.actions.RenameAction"),
path = "Loaders/image/svg+xml/Actions",
position = 1300,
separatorAfter = 1400
),
@ActionReference(
id = @ActionID(category = "System", id = "org.openide.actions.SaveAsTemplateAction"),
path = "Loaders/image/svg+xml/Actions",
position = 1500
),
@ActionReference(
id = @ActionID(category = "System", id = "org.openide.actions.FileSystemAction"),
path = "Loaders/image/svg+xml/Actions",
position = 1550,
separatorAfter = 1600
),
@ActionReference(
id = @ActionID(category = "System", id = "org.openide.actions.ToolsAction"),
path = "Loaders/image/svg+xml/Actions",
position = 1700
),
@ActionReference(
id = @ActionID(category = "System", id = "org.openide.actions.PropertiesAction"),
path = "Loaders/image/svg+xml/Actions",
position = 1800
)
})
public final class SVGDataObject extends MultiDataObject implements XMLDataObjectLook, UpdateDocumentCookie {

public static final String MIME_TYPE = "image/svg+xml";
Expand Down
20 changes: 8 additions & 12 deletions ide/svg/src/org/netbeans/modules/svg/SVGPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class SVGPanel extends JPanel {
private double scale = 1.0D;
private BackgroundMode bgMode = BackgroundMode.DEFAULT;

public void setSvgDocument(SVGDocument doc) {
public void setSVGDocument(SVGDocument doc) {
this.svgDocument = doc;

repaint();
Expand All @@ -58,25 +58,21 @@ protected void paintComponent(Graphics g) {
Rectangle visibleRect = getVisibleRectangle();

switch (bgMode) {
case BLACK:
case BLACK -> {
g.setColor(Color.BLACK);
g.fillRect(visibleRect.x, visibleRect.y, visibleRect.width, visibleRect.height);
break;

case WHITE:
}
case WHITE -> {
g.setColor(Color.WHITE);
g.fillRect(visibleRect.x, visibleRect.y, visibleRect.width, visibleRect.height);
break;
}

case TRANSPARENT:
case DARK_TRANSPARENT:
case TRANSPARENT, DARK_TRANSPARENT ->
Utils.drawChestTilePattern(g, visibleRect, 20, bgMode == BackgroundMode.DARK_TRANSPARENT);
break;

default:
case DEFAULT -> {
g.setColor(getBackground());
g.fillRect(visibleRect.x, visibleRect.y, visibleRect.width, visibleRect.height);
break;
}
}

if (svgDocument == null) {
Expand Down
6 changes: 4 additions & 2 deletions ide/svg/src/org/netbeans/modules/svg/SVGViewerElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class SVGViewerElement implements MultiViewElement {
private final SVGDataObject dataObject;
private transient JToolBar toolbar;
private transient JComponent component;
private transient MultiViewElementCallback callback;

/**
* Component showing SVG.
Expand Down Expand Up @@ -121,7 +122,7 @@ public JComponent getToolbarRepresentation() {

@Override
public Action[] getActions() {
return new Action[0];
return callback.createDefaultActions();
}

@Override
Expand Down Expand Up @@ -164,6 +165,7 @@ public UndoRedo getUndoRedo() {

@Override
public void setMultiViewCallback(MultiViewElementCallback callback) {
this.callback = callback;
}

@Override
Expand Down Expand Up @@ -244,7 +246,7 @@ private void updateView() {
viewer.setLayout(new BorderLayout());

svgPanel.setPreferredSize(new Dimension(width, height));
svgPanel.setSvgDocument(svgDocument);
svgPanel.setSVGDocument(svgDocument);

JScrollPane scrollPane = new JScrollPane(svgPanel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# under the License.

# ImageNavigatorPanel
Navigator_DisplayName=Image preview
Navigator_DisplayName=SVG preview
Navigator_DisplayHint=Thumbnail
ERR_IOFile=File is not available
ERR_DataObject=Can't find the data object
ERR_Thumbnail=Thumbnail is not available
ERR_Thumbnail=Thumbnail is not available
Loading

0 comments on commit f01fda6

Please sign in to comment.