Skip to content

Commit

Permalink
Implementation of preview of draw pages and bugfixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbuzatto committed Aug 10, 2020
1 parent c9d9500 commit 359a535
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 49 deletions.
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.gui.geom.Rectangle;
import br.com.davidbuzatto.computersupportedclasshelper.gui.geom.Shape;
import br.com.davidbuzatto.computersupportedclasshelper.utils.Constants;
import java.awt.Color;
Expand Down Expand Up @@ -76,6 +77,61 @@ public void setRedoList( List<Shape> redoList ) {
this.redoList = redoList;
}

public Rectangle getRectangularBounds() {

Rectangle r = new Rectangle();

double xStart = 0;
double yStart = 0;
double xEnd = 0;
double yEnd = 0;

boolean first = true;

for ( Shape s : shapes ) {

s.calculateDrawingBounds();

if ( first ) {

xStart = s.getXStartD();
yStart = s.getYStartD();
xEnd = s.getXEndD();
yEnd = s.getYEndD();
first = false;

} else {

if ( xStart > s.getXStartD() ) {
xStart = s.getXStartD();
}

if ( yStart > s.getYStartD() ) {
yStart = s.getYStartD();
}

if ( xEnd < s.getXEndD() ) {
xEnd = s.getXEndD();
}

if ( yEnd < s.getYEndD() ) {
yEnd = s.getYEndD();
}

}

}

r.setXStart( xStart );
r.setYStart( yStart );
r.setXEnd( xEnd );
r.setYEnd( yEnd );

r.calculateDrawingBounds();
return r;

}

@Override
public DrawPage clone() throws CloneNotSupportedException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<Group type="102" attributes="0">
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="lblTitle" pref="536" max="32767" attributes="0"/>
<Component id="lblTitle" pref="532" max="32767" attributes="0"/>
<Component id="customDialogContainerPanel1" max="32767" attributes="0"/>
<Component id="pButtons" alignment="0" max="32767" attributes="0"/>
</Group>
Expand Down Expand Up @@ -126,7 +126,7 @@
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="150" max="32767" attributes="0"/>
<EmptySpace min="0" pref="90" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public void windowClosed( WindowEvent e ) {
@SuppressWarnings( "unchecked" )
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;

jPanel1 = new javax.swing.JPanel();
containerPanel = new br.com.davidbuzatto.computersupportedclasshelper.gui.CustomDialogContainerPanel();
Expand Down Expand Up @@ -129,7 +128,7 @@ private void initComponents() {
);
drawPagesPreviewPanelLayout.setVerticalGroup(
drawPagesPreviewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 150, Short.MAX_VALUE)
.addGap(0, 90, Short.MAX_VALUE)
);

javax.swing.GroupLayout customDialogContainerPanel1Layout = new javax.swing.GroupLayout(customDialogContainerPanel1);
Expand Down Expand Up @@ -182,7 +181,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addGroup(containerPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblTitle, javax.swing.GroupLayout.DEFAULT_SIZE, 536, Short.MAX_VALUE)
.addComponent(lblTitle, javax.swing.GroupLayout.DEFAULT_SIZE, 532, Short.MAX_VALUE)
.addComponent(customDialogContainerPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pButtons, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
Expand Down Expand Up @@ -228,12 +227,10 @@ private void btnRightActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS

private void movePreviewToLeft() {
drawPagesPreviewPanel.movePreviewToLeft();
drawPagesPreviewPanel.repaint();
}

private void movePreviewToRight() {
drawPagesPreviewPanel.movePreviewToRight();
drawPagesPreviewPanel.repaint();
}

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

import br.com.davidbuzatto.computersupportedclasshelper.gui.geom.EraserCurve;
import br.com.davidbuzatto.computersupportedclasshelper.gui.geom.Rectangle;
import br.com.davidbuzatto.computersupportedclasshelper.gui.geom.Shape;
import br.com.davidbuzatto.computersupportedclasshelper.utils.Constants;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
Expand All @@ -23,7 +23,6 @@
public class DrawPagesPreviewPanel extends JPanel {

private int currentDrawPageIndex;
private DrawPage currentDrawPage;
private List<DrawPage> drawPages;

public DrawPagesPreviewPanel() {
Expand All @@ -43,35 +42,94 @@ protected void paintComponent( Graphics g ) {
g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON );

/*g2d.setPaint( currentDrawPage.getBackgroundColor() );
g2d.fillRect( 0, 0, getWidth(), getHeight() );
g2d.setFont( new Font( "dialog", Font.BOLD, 12 ) );
int max = 3;
int startTranslation = 0;

for ( Shape shape : currentDrawPage.getShapes() ) {
shape.draw( g2d );
}*/
if ( !drawPages.isEmpty() ) {

int q = drawPages.size();
if ( q > max ) {
q = max;
}

if ( q == 1 ) {
startTranslation = 180;
} else if ( q == 2 ) {
startTranslation = 90;
}

for ( int i = 0; i < q; i++ ) {
DrawPage currentDrawPage = drawPages.get( currentDrawPageIndex + i );
drawPagePreview( currentDrawPage, g2d, i, startTranslation );
}

g2d.setColor( Color.BLACK );
if ( q == 1 ) {
g2d.fillRect( 0, 0, 180, 90 );
g2d.fillRect( 340, 0, 300, 90 );
} else if ( q == 2 ) {
g2d.fillRect( 0, 0, 90, 90 );
g2d.fillRect( 250, 0, 20, 90 );
g2d.fillRect( 430, 0, 300, 90 );
} else {
g2d.fillRect( 160, 0, 20, 90 );
g2d.fillRect( 340, 0, 20, 90 );
}

}

g2d.dispose();

}

public Color getBackgroundColor() {
return currentDrawPage.getBackgroundColor();
}

public void setBackgroundColor( Color backgroundColor ) {
this.currentDrawPage.setBackgroundColor( backgroundColor );
}
private void drawPagePreview( DrawPage currentDrawPage,
Graphics2D g2d,
int i,
int startTranslation ) {

Graphics2D g2d1 = (Graphics2D) g2d.create();
g2d1.translate( startTranslation + 180 * i, 0 );

g2d1.setPaint( currentDrawPage.getBackgroundColor() );
g2d1.fillRect( 0, 0, 160, 90 );

Graphics2D g2d2 = (Graphics2D) g2d1.create();
g2d2.scale( .1, .1 );
for ( Shape shape : currentDrawPage.getShapes() ) {
shape.draw( g2d2 );
}
g2d2.dispose();

g2d1.setPaint( Color.WHITE );
g2d1.drawRect( 0, 0, 159, 89 );
g2d1.drawString( "page " + ( i + 1 + currentDrawPageIndex ), 10, 80 );
g2d1.dispose();

}

public void setDrawPages( List<DrawPage> drawPages ) {
this.drawPages = drawPages;
}

public void movePreviewToLeft() {
System.out.println( "le" );

if ( currentDrawPageIndex != 0 ) {
currentDrawPageIndex--;
}

repaint();

}

public void movePreviewToRight() {
System.out.println( "ri" );

if ( currentDrawPageIndex < drawPages.size() - 3 ) {
currentDrawPageIndex++;
}

repaint();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ public void setBackgroundColor( Color backgroundColor ) {
this.currentDrawPage.setBackgroundColor( backgroundColor );
}

public DrawPage getCurrentDrawPage() {
return currentDrawPage;
}

public void setTempShape( Shape tempShape ) {
this.currentDrawPage.setTempShape( tempShape );
}
Expand Down Expand Up @@ -173,14 +177,6 @@ public void previousDrawPage( Color backgroundColor ) {

}

/*public void previousDrawPage() {
if ( currentDrawPageIndex != 0 ) {
currentDrawPage = drawPages.get( --currentDrawPageIndex );
}
}*/

public void moveCurrentDrawPageToRight() {

if ( currentDrawPageIndex != drawPages.size()-1 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,13 @@ private void btnOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST
Shape.setIdCount( drawPanel.getMaxShapeId() + 1 );
updateLabelPages();
verifyHistory();

if ( drawPanel.getBackgroundColor().equals( Constants.TRANSPARENT_COLOR ) ) {
colorPanelBackground.setColor( null );
} else {
colorPanelBackground.setColor( drawPanel.getBackgroundColor() );
}

}

}
Expand Down Expand Up @@ -2143,7 +2150,15 @@ public boolean dispatchKeyEvent( KeyEvent e ) {
drawPanel.nextDrawPage( colorPanelBackground.getColor() );
}
} else {
drawPanel.nextDrawPage( colorPanelBackground.getColor() );

drawPanel.nextDrawPage( null );

if ( drawPanel.getBackgroundColor().equals( Constants.TRANSPARENT_COLOR ) ) {
colorPanelBackground.setColor( null );
} else {
colorPanelBackground.setColor( drawPanel.getBackgroundColor() );
}

}

drawPanel.repaint();
Expand All @@ -2159,7 +2174,15 @@ public boolean dispatchKeyEvent( KeyEvent e ) {
drawPanel.previousDrawPage( colorPanelBackground.getColor() );
}
} else {
drawPanel.previousDrawPage( colorPanelBackground.getColor() );

drawPanel.previousDrawPage( null );

if ( drawPanel.getBackgroundColor().equals( Constants.TRANSPARENT_COLOR ) ) {
colorPanelBackground.setColor( null );
} else {
colorPanelBackground.setColor( drawPanel.getBackgroundColor() );
}

}

drawPanel.repaint();
Expand Down Expand Up @@ -2463,13 +2486,7 @@ private void openNewToolConfigDialogStrokeWidthArcRadius( MouseEvent evt ) {

private void openDrawPagesPreviewDialog() {

CustomMessageAndConfirmDialog.showMessageDialog(
this,
"Under development :P",
"Under development :P",
JOptionPane.INFORMATION_MESSAGE );

/*DrawPagesPreviewDialog dppd = new DrawPagesPreviewDialog(
DrawPagesPreviewDialog dppd = new DrawPagesPreviewDialog(
this,
true,
drawPanel.getDrawPages() );
Expand All @@ -2478,7 +2495,7 @@ private void openDrawPagesPreviewDialog() {
getWidth() / 2 - dppd.getWidth() / 2,
getHeight() / 2 - dppd.getHeight() / 2);

dppd.setVisible( true );*/
dppd.setVisible( true );

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@ public class Image extends Shape implements Serializable, Cloneable {
public void draw( Graphics2D g2d ) {

if ( image != null ) {

calculateDrawingBounds();

g2d = (Graphics2D) g2d.create();
g2d.drawImage( image, (int) xStart, (int) yStart, null );
g2d.drawImage( image, (int) xStartD, (int) yStartD, null );
g2d.dispose();

}

}

@Override
public boolean intercepts( double x, double y ) {
if ( image != null ) {
return x >= xStart && x <= xEnd &&
y >= yStart && y <= yEnd;
return x >= xStartD && x <= xEndD &&
y >= yStartD && y <= yEndD;
} else {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ protected void calculate() {

for ( int i = 0; i < sideQuantity; i++ ) {

xs[i] = xCenter + Math.cos( Math.toRadians(angle ) ) * radius;
ys[i] = yCenter + Math.sin( Math.toRadians(angle ) ) * radius;
xs[i] = xCenter + Math.cos( Math.toRadians( angle ) ) * radius;
ys[i] = yCenter + Math.sin( Math.toRadians( angle ) ) * radius;
angle += angleIncrement;

if ( i == 0 ) {
Expand Down
Loading

0 comments on commit 359a535

Please sign in to comment.