Skip to content

Commit

Permalink
Merge pull request #17 from sweat-tek/viewpalette
Browse files Browse the repository at this point in the history
Add error fix for view palette
  • Loading branch information
samuelnjri authored Dec 8, 2021
2 parents fd695b9 + cf45f4a commit 51f5bdd
Show file tree
Hide file tree
Showing 38 changed files with 178 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

/JHotDraw/target/

# Netbeans
nbactions.xml
nb-configuration.xml
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
55 changes: 55 additions & 0 deletions JHotDraw/nbactions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>run</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:3.0.0:exec</goal>
</goals>
<properties>
<exec.vmArgs>-javaagent:/Users/Samuel/.m2/repository/org/aspectj/aspectjweaver/1.8.6/aspectjweaver-1.8.6.jar</exec.vmArgs>
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
<exec.appArgs></exec.appArgs>
<exec.mainClass>org.jhotdraw.samples.svg.Main</exec.mainClass>
<exec.executable>java</exec.executable>
</properties>
</action>
<action>
<actionName>debug</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:3.0.0:exec</goal>
</goals>
<properties>
<exec.vmArgs>-javaagent:/Users/Samuel/.m2/repository/org/aspectj/aspectjweaver/1.8.6/aspectjweaver-1.8.6.jar -agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</exec.vmArgs>
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
<exec.appArgs></exec.appArgs>
<exec.mainClass>org.jhotdraw.samples.svg.Main</exec.mainClass>
<exec.executable>java</exec.executable>
<jpda.listen>true</jpda.listen>
</properties>
</action>
<action>
<actionName>profile</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:3.0.0:exec</goal>
</goals>
<properties>
<exec.vmArgs>-javaagent:/Users/Samuel/.m2/repository/org/aspectj/aspectjweaver/1.8.6/aspectjweaver-1.8.6.jar</exec.vmArgs>
<exec.args>${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}</exec.args>
<exec.mainClass>org.jhotdraw.samples.svg.Main</exec.mainClass>
<exec.executable>java</exec.executable>
<exec.appArgs></exec.appArgs>
</properties>
</action>
</actions>
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@
* <br>2.0 2006-01-14 Changed to support double precision coordinates.
* <br>1.0 2003-12-01 Derived from JHotDraw 5.4b1.
*/
public class DefaultDrawingView
extends JComponent
implements DrawingView, EditableComponent {
public class DefaultDrawingView extends JComponent implements DrawingView, EditableComponent {

/**
* Set this to true to turn on debugging output on System.out.
Expand Down Expand Up @@ -130,6 +128,10 @@ public void repaintHandles() {
}
}

@Override
public void setView(DrawingView view) {
}

private class EventHandler implements FigureListener, CompositeFigureListener, HandleListener, FocusListener {

public void figureAdded(CompositeFigureEvent evt) {
Expand Down
2 changes: 2 additions & 0 deletions JHotDraw/src/main/java/org/jhotdraw/draw/DrawingView.java
Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,6 @@ public interface DrawingView {
* @param l the listener.
*/
public void removeMouseMotionListener(MouseMotionListener l);

public void setView(DrawingView view);
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public void itemStateChanged(ItemEvent evt) {
}

/** Prevent instance creation. */
private ButtonFactory() {
public ButtonFactory() {
}

public static Collection<Action> createDrawingActions(DrawingEditor editor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected String getID() {
/** This should be an abstract method, but the NetBeans GUI builder
* doesn't support abstract beans.
*/
protected void init() {
public void init() {
}

protected PropertyChangeListener getEventHandler() {
Expand Down Expand Up @@ -100,7 +100,7 @@ public DrawingEditor getEditor() {
}

@Override
final protected JComponent getDisclosedComponent(int state) {
public final JComponent getDisclosedComponent(int state) {
if (panels == null) {
panels = new JPanel[getDisclosureStateCount()];
for (int i = 0; i < panels.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void setView(DrawingView view) {

@Override
@FeatureEntryPoint(JHotDrawFeatures.VIEW_PALETTE)
protected JComponent createDisclosedComponent(int state) {
public JComponent createDisclosedComponent(int state) {
JPanel p = null;
ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.samples.svg.Labels");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.jhotdraw.samples.svg.gui.viewtoolbar.junitTest;

import java.awt.Component;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeListener;
import javax.swing.*;
import javax.swing.JPanel;
import org.jhotdraw.draw.DefaultDrawingView;
import org.jhotdraw.samples.svg.gui.AbstractToolBar;
import org.jhotdraw.samples.svg.gui.ViewToolBar;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
*
* @author Samuel
*/

public class viewtoolbarTest {
JPanel resultParent;
JPanel expResParent;
JFrame rootPane;
BufferedImage image;
Graphics2D graphics2d;
AbstractToolBar abstractToolBar;

public viewtoolbarTest() {
}

@BeforeClass
public static void setUpClass() {
}

@AfterClass
public static void tearDownClass() {
}

@Before
public void setUp() {
this.abstractToolBar = new AbstractToolBar();
this.rootPane = new JFrame();
this.resultParent = new JPanel(new GridBagLayout());
this.expResParent = new JPanel(new GridBagLayout());
this.image = new BufferedImage(100,100, BufferedImage.TYPE_INT_ARGB);
this.graphics2d= image.createGraphics();

}

@After
public void tearDown() {
}

@Test
public void testInit() {
System.out.println("Init");
ViewToolBar instance = new ViewToolBar();
instance.init();
}


@Test
public void testJPanel() {
System.out.println("Test JPanel components");

int resultInt = resultParent.getComponentCount();
int expResult = expResParent.getComponentCount();;
int result = resultInt;

System.out.println("Expected: " + resultInt);
assertEquals(expResult, result);
}

@Test
public void testViewPalette() {
System.out.println("Test View Palette states as components");

rootPane.add(resultParent);
rootPane.add(expResParent);

JComponent result = abstractToolBar.getDisclosedComponent(1);
resultParent.add(result);
result.paint(graphics2d);
int resultInt = resultParent.getComponentCount();
System.out.println("result:" + resultInt);

JComponent expResult = new JPanel();
expResParent.add(expResult);
expResult.paint(graphics2d);
int expResultInt = expResParent.getComponentCount();

System.out.println("expresult:" + expResultInt);
assertEquals("expects parent to have one component", 1, resultInt);
assertEquals(expResultInt, resultInt);
}

}

0 comments on commit 51f5bdd

Please sign in to comment.