Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Hoops with the Custom Image visual style #11

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added file.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 8 additions & 3 deletions src/main/ArrayVisualizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import utils.Writes;
import visuals.Bars;
import visuals.Circular;
import visuals.Hoops;
import visuals.CustomImage;
import visuals.Mesh;
import visuals.Pixels;
import visuals.VisualStyles;
Expand Down Expand Up @@ -269,7 +269,12 @@ public void run() {
ArrayVisualizer.this.visualClasses = new Visual[5];
ArrayVisualizer.this.visualClasses[0] = new Bars(ArrayVisualizer.this);
ArrayVisualizer.this.visualClasses[1] = new Circular(ArrayVisualizer.this);
ArrayVisualizer.this.visualClasses[2] = new Hoops(ArrayVisualizer.this);
//Image file name is set here (file will be in the main folder)
try {
ArrayVisualizer.this.visualClasses[2] = new CustomImage(ArrayVisualizer.this, "file.jpg");
} catch(Exception e) {
e.printStackTrace();
}
ArrayVisualizer.this.visualClasses[3] = new Mesh(ArrayVisualizer.this);
ArrayVisualizer.this.visualClasses[4] = new Pixels(ArrayVisualizer.this);

Expand Down Expand Up @@ -714,4 +719,4 @@ private void drawWindows() {
public static void main(String[] args) {
new ArrayVisualizer();
}
}
}
20 changes: 10 additions & 10 deletions src/prompts/ViewPrompt.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private void initComponents() {
this.disparityDots = new javax.swing.JButton();
this.spiralDots= new javax.swing.JButton();
this.rainbow = new javax.swing.JButton();
this.hoops = new javax.swing.JButton();
this.customImage = new javax.swing.JButton();
this.sineWave = new javax.swing.JButton();
this.waveDots = new javax.swing.JButton();

Expand Down Expand Up @@ -149,11 +149,11 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});

hoops.setText("Hoops");
hoops.addActionListener(new java.awt.event.ActionListener() {
customImage.setText("Custom Image");
customImage.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
hoopsActionPerformed(evt);
customImageActionPerformed(evt);
}
});

Expand Down Expand Up @@ -207,7 +207,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addComponent(dotGraph, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
.addComponent(triangleMesh, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(spiral, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
.addComponent(hoops, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
.addComponent(customImage, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
.addComponent(spiralDots, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE))
.addGap(18))
);
Expand All @@ -227,7 +227,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addPreferredGap(ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(colorCircle)
.addComponent(hoops))
.addComponent(customImage))
.addPreferredGap(ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(disparity)
Expand Down Expand Up @@ -308,9 +308,9 @@ private void disparityActionPerformed(java.awt.event.ActionEvent evt) {
UtilFrame.jButton2ResetText();
dispose();
}
private void hoopsActionPerformed(java.awt.event.ActionEvent evt) {
private void customImageActionPerformed(java.awt.event.ActionEvent evt) {
setAllFieldsFalse();
ArrayVisualizer.setVisual(VisualStyles.HOOPS);
ArrayVisualizer.setVisual(VisualStyles.IMAGE);
UtilFrame.jButton2ResetText();
dispose();
}
Expand Down Expand Up @@ -358,8 +358,8 @@ private void waveDotsActionPerformed(java.awt.event.ActionEvent evt) {
private javax.swing.JButton disparity;
private javax.swing.JButton disparityDots;
private javax.swing.JButton rainbow;
private javax.swing.JButton hoops;
private javax.swing.JButton customImage;
private javax.swing.JButton sineWave;
private javax.swing.JButton waveDots;
private javax.swing.JLabel jLabel1;
}
}
83 changes: 83 additions & 0 deletions src/visuals/CustomImage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package visuals;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.File;
import javax.imageio.ImageIO;

import main.ArrayVisualizer;
import templates.Visual;
import utils.Highlights;
import utils.Renderer;

/*
*
MIT License

Copyright (c) 2019 w0rthy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*
*/

final public class CustomImage extends Visual {
private BufferedImage img;

public CustomImage(ArrayVisualizer ArrayVisualizer, String f) throws IOException {
super(ArrayVisualizer);
this.setImage(f);
}

public void setImage(String f) throws IOException {
this.img = ImageIO.read(new File(f));
}

public void drawVisual(int[] array, ArrayVisualizer ArrayVisualizer, Renderer Renderer, Highlights Highlights) {
for(int i = 0; i < ArrayVisualizer.getCurrentLength(); i++) {
int width = (int) (Renderer.getXScale() * (i + 1)) - Renderer.getOffset();

if(i < Highlights.getFancyFinishPosition() || Highlights.containsPosition(i)) {
if(ArrayVisualizer.analysisEnabled()) mainRender.setColor(Color.WHITE);
else mainRender.setColor(Color.BLACK);

mainRender.fillRect(Renderer.getOffset() + 20, 0, width, ArrayVisualizer.windowHeight());
} else {
//Cuts the image in respect to each item in the array
mainRender.drawImage(
this.img,

Renderer.getOffset() + 20,
0,
Renderer.getOffset() + 20 + width,
ArrayVisualizer.windowHeight(),

(int) ((double) this.img.getWidth() / ArrayVisualizer.getCurrentLength() * array[i]),
0,
(int) Math.ceil((double) this.img.getWidth() / ArrayVisualizer.getCurrentLength() * (array[i] + 1)),
this.img.getHeight(),

null
);
}

Renderer.setOffset(Renderer.getOffset() + width);
}
}
}
121 changes: 0 additions & 121 deletions src/visuals/Hoops.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/visuals/VisualStyles.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void drawVisual(int[] array, ArrayVisualizer ArrayVisualizer, Renderer Re
ArrayVisualizer.getVisuals()[1].drawVisual(array, ArrayVisualizer, Renderer, Highlights);
}
},
HOOPS {
IMAGE {
@Override
public void drawVisual(int[] array, ArrayVisualizer ArrayVisualizer, Renderer Renderer, Highlights Highlights) {
ArrayVisualizer.getVisuals()[2].drawVisual(array, ArrayVisualizer, Renderer, Highlights);
Expand All @@ -67,4 +67,4 @@ public VisualStyles getCurrentVisual() {
}

public abstract void drawVisual(int[] array, ArrayVisualizer ArrayVisualizer, Renderer Renderer, Highlights Highlights);
}
}