Skip to content

Commit

Permalink
Implementation of the text, image and preview functionalities,
Browse files Browse the repository at this point in the history
among other quality of life gui changes.
  • Loading branch information
davidbuzatto committed Aug 12, 2020
1 parent 359a535 commit cd6c3d1
Show file tree
Hide file tree
Showing 63 changed files with 2,166 additions and 117 deletions.
13 changes: 10 additions & 3 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Draw pages preview
Text insertion shape
Copy/Cut/Paste for shapes
v1.4.1
Selection Tool
Duplicate selection
Alignment Tools

v1.4.2
Image resize

v1.4.3
Undo - Redo
Binary file added lib/FlatLaf-0.39/flatlaf-0.39.jar
Binary file not shown.
6 changes: 3 additions & 3 deletions lib/nblibraries.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
libs.absolutelayout.classpath=\
${base}/absolutelayout/AbsoluteLayout.jar
libs.absolutelayout.displayName=Absolute Layout
libs.CopyLibs.classpath=\
${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar
libs.CopyLibs.displayName=CopyLibs Task
libs.CopyLibs.prop-version=3.0
libs.FlatLaf-0.39.classpath=\
${base}/FlatLaf-0.39/flatlaf-0.39.jar
libs.FlatLaf-0.39.displayName=FlatLaf-0.39
libs.JTS_1.13.classpath=\
${base}/JTS_1.13/jts-1.13.jar
libs.JTS_1.13.displayName=JTS 1.13
3 changes: 2 additions & 1 deletion nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ excludes=
includes=**
jar.compress=false
javac.classpath=\
${libs.JTS_1.13.classpath}
${libs.JTS_1.13.classpath}:\
${libs.FlatLaf-0.39.classpath}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
Expand Down
26 changes: 3 additions & 23 deletions src/br/com/davidbuzatto/computersupportedclasshelper/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import br.com.davidbuzatto.computersupportedclasshelper.gui.MainWindow;
import br.com.davidbuzatto.computersupportedclasshelper.utils.DrawingConfigs;
import com.formdev.flatlaf.FlatDarkLaf;

/**
*
Expand All @@ -20,29 +21,8 @@ public class Main {
* @param args the command line arguments
*/
public static void main( String args[] ) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for ( javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels() ) {
if ( "Nimbus".equals( info.getName() ) ) {
javax.swing.UIManager.setLookAndFeel( info.getClassName() );
break;
}
}
} catch ( ClassNotFoundException ex ) {
java.util.logging.Logger.getLogger(MainWindow.class.getName() ).log( java.util.logging.Level.SEVERE, null, ex );
} catch ( InstantiationException ex ) {
java.util.logging.Logger.getLogger(MainWindow.class.getName() ).log( java.util.logging.Level.SEVERE, null, ex );
} catch ( IllegalAccessException ex ) {
java.util.logging.Logger.getLogger(MainWindow.class.getName() ).log( java.util.logging.Level.SEVERE, null, ex );
} catch ( javax.swing.UnsupportedLookAndFeelException ex ) {
java.util.logging.Logger.getLogger(MainWindow.class.getName() ).log( java.util.logging.Level.SEVERE, null, ex );
}
//</editor-fold>


FlatDarkLaf.install();

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package br.com.davidbuzatto.computersupportedclasshelper.gui;

import br.com.davidbuzatto.computersupportedclasshelper.utils.Utils;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Cursor;
Expand All @@ -14,7 +15,6 @@
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;

/**
Expand All @@ -31,10 +31,8 @@ public class ColorPanel extends JPanel {
private static final FontMetrics ID_FONT_METRICS;

static {
ID_FONT = new Font( "sans-serif", Font.BOLD, 12 );
BufferedImage img = new BufferedImage( 1, 1, BufferedImage.TYPE_INT_ARGB );
ID_FONT_METRICS = img.getGraphics().getFontMetrics( ID_FONT );
img = null;
ID_FONT = new Font( "Dialog", Font.BOLD, 12 );
ID_FONT_METRICS = Utils.getFontMetrics( ID_FONT );
}

public ColorPanel() {
Expand All @@ -43,7 +41,7 @@ public ColorPanel() {

public ColorPanel( Color startColor ) {

Dimension d = new Dimension( 20, 20 );
Dimension d = new Dimension( 25, 25 );

setMinimumSize( d );
setMaximumSize( d );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class Cursors {
private Cursor cPencil;
private Cursor cEraser;
private Cursor cImage;
private Cursor cText;
private Cursor cCross;

private static final Cursors INSTANCE;
Expand All @@ -36,6 +37,7 @@ public enum Type {
PENCIL,
ERASER,
IMAGE,
TEXT,
CROSS
}

Expand All @@ -53,6 +55,7 @@ private Cursors() {
BufferedImage imgPencil = new BufferedImage( 32, 32, BufferedImage.TYPE_INT_ARGB );
BufferedImage imgEraser = new BufferedImage( 32, 32, BufferedImage.TYPE_INT_ARGB );
BufferedImage imgImage = new BufferedImage( 32, 32, BufferedImage.TYPE_INT_ARGB );
BufferedImage imgText = new BufferedImage( 32, 32, BufferedImage.TYPE_INT_ARGB );

imgBucket.getGraphics().drawImage( ImageIO.read(
getClass().getResource( "/br/com/davidbuzatto/computersupportedclasshelper/gui/icons/bucket.png" ) ), 0, 0, null );
Expand All @@ -64,12 +67,15 @@ private Cursors() {
getClass().getResource( "/br/com/davidbuzatto/computersupportedclasshelper/gui/icons/eraser.png" ) ), 0, 0, null );
imgImage.getGraphics().drawImage( ImageIO.read(
getClass().getResource( "/br/com/davidbuzatto/computersupportedclasshelper/gui/icons/picture_add.png" ) ), 0, 0, null );
imgText.getGraphics().drawImage( ImageIO.read(
getClass().getResource( "/br/com/davidbuzatto/computersupportedclasshelper/gui/icons/font_add.png" ) ), 0, 0, null );

cBucket = TOOLKIT.createCustomCursor( imgBucket, new Point( 0, 12 ), "bucket" );
cMove = TOOLKIT.createCustomCursor( imgMove, new Point( 7, 7 ), "move" );
cPencil = TOOLKIT.createCustomCursor( imgPencil, new Point( 0, 14 ), "pencil" );
cEraser = TOOLKIT.createCustomCursor( imgEraser, new Point( 0, 14 ), "eraser" );
cImage = TOOLKIT.createCustomCursor( imgImage, new Point( 0, 14 ), "image" );
cText = TOOLKIT.createCustomCursor( imgText, new Point( 0, 14 ), "text" );
cCross = TOOLKIT.createCustomCursor( createCrossImage( Color.BLACK ), new Point( 11, 11 ), "cross" );

} catch ( IOException exc ) {
Expand All @@ -91,6 +97,8 @@ public static Cursor getCursor( Type type, Color c ) {
return INSTANCE.cEraser;
case IMAGE:
return INSTANCE.cImage;
case TEXT:
return INSTANCE.cText;
case CROSS:
changeCrossColor( c );
return INSTANCE.cCross;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected void paintComponent( Graphics g ) {

if ( forMessageAndInputDialogs ) {
g2d.drawLine( 0, 26, getWidth(), 26 );
g2d.drawLine( 0, getHeight() - 37, getWidth(), getHeight() - 37 );
g2d.drawLine( 0, getHeight() - 32, getWidth(), getHeight() - 32 );
}

g2d.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
</Component>
<Component class="javax.swing.JLabel" name="lblMessage">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="new Font( &quot;Dialog&quot;, Font.BOLD, 12 )" type="code"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="cc" green="cc" red="cc" type="rgb"/>
</Property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
lblTitle.setForeground(new java.awt.Color(204, 204, 204));
lblTitle.setText("title");

lblMessage.setFont(new Font( "Dialog", Font.BOLD, 12 ));
lblMessage.setForeground(new java.awt.Color(204, 204, 204));
lblMessage.setText("message");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
*/
package br.com.davidbuzatto.computersupportedclasshelper.gui;

import br.com.davidbuzatto.computersupportedclasshelper.gui.geom.Rectangle;
import br.com.davidbuzatto.computersupportedclasshelper.gui.geom.Shape;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JPanel;
Expand All @@ -25,13 +26,20 @@ public class DrawPagesPreviewPanel extends JPanel {
private int currentDrawPageIndex;
private List<DrawPage> drawPages;

private double scale;

public DrawPagesPreviewPanel() {

setBackground( new Color( 0, 0, 0, 0 ) );
setOpaque( false );

drawPages = new ArrayList<>();

// calculate the scale to 10% of the current screen dimensions
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
scale = 160 / (double) d.width;
System.out.println( scale );

}

@Override
Expand Down Expand Up @@ -95,7 +103,7 @@ private void drawPagePreview( DrawPage currentDrawPage,
g2d1.fillRect( 0, 0, 160, 90 );

Graphics2D g2d2 = (Graphics2D) g2d1.create();
g2d2.scale( .1, .1 );
g2d2.scale( scale, scale );
for ( Shape shape : currentDrawPage.getShapes() ) {
shape.draw( g2d2 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import br.com.davidbuzatto.computersupportedclasshelper.gui.geom.EraserCurve;
import br.com.davidbuzatto.computersupportedclasshelper.gui.geom.Shape;
import br.com.davidbuzatto.computersupportedclasshelper.utils.Constants;
import br.com.davidbuzatto.computersupportedclasshelper.utils.Utils;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
Expand Down Expand Up @@ -83,6 +84,67 @@ public void redo() {
}
}

public void moveFront( Shape shape ) {

List<Shape> shapes = currentDrawPage.getShapes();

int v = shapes.indexOf( shape );
int w;

while ( v < shapes.size() - 1 ) {
w = v + 1;
if ( w < shapes.size() ) {
Utils.<Shape>swap( shapes, v, w );
}
v++;
}

}

public void moveForwards( Shape shape ) {

List<Shape> shapes = currentDrawPage.getShapes();

int v = shapes.indexOf( shape );
int w = v + 1;

if ( w < shapes.size() ) {
Utils.<Shape>swap( shapes, v, w );
}

}

public void moveBack( Shape shape ) {


List<Shape> shapes = currentDrawPage.getShapes();

int v = shapes.indexOf( shape );
int w;

while ( v > 0 ) {
w = v - 1;
if ( w >= 0 ) {
Utils.<Shape>swap( shapes, v, w );
}
v--;
}

}

public void moveBackwards( Shape shape ) {

List<Shape> shapes = currentDrawPage.getShapes();

int v = shapes.indexOf( shape );
int w = v - 1;

if ( w >= 0 ) {
Utils.<Shape>swap( shapes, v, w );
}

}

public void resetRedoList() {
currentDrawPage.getRedoList().clear();
}
Expand Down Expand Up @@ -123,6 +185,14 @@ public void removeShape( Shape shape ) {
currentDrawPage.getShapes().remove( shape );
}

public void duplicateShape( Shape shape ) {
try {
currentDrawPage.getShapes().add( shape.clone() );
} catch ( CloneNotSupportedException exc ) {
exc.printStackTrace();
}
}

public void addDrawPageEnd( Color backgroundColor ) {

if ( backgroundColor == null ) {
Expand Down
Loading

0 comments on commit cd6c3d1

Please sign in to comment.