Skip to content

Commit

Permalink
jdrafting v0.1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelalejandromorenobarrientos committed Aug 13, 2020
1 parent 2f1c231 commit 30d8c92
Show file tree
Hide file tree
Showing 38 changed files with 369 additions and 255 deletions.
Binary file removed lib/jme_3.3_lib.jar
Binary file not shown.
Binary file added lib/jme_6_1.jar
Binary file not shown.
6 changes: 3 additions & 3 deletions src/jdrafting/geom/JDMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ public static double projection( Point2D v, Point2D w )

/**
* Get incenter of a triangle
* @param a vertex
* @param b vertex
* @param c vertex
* @param A vertex
* @param B vertex
* @param C vertex
* @return the incenter
*/
public static Point2D incenter( Point2D A, Point2D B, Point2D C )
Expand Down
3 changes: 1 addition & 2 deletions src/jdrafting/geom/JDPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public Point2D.Double toPoint2Ddouble()
@Override
public Rectangle2D getBounds2D()
{
return new Rectangle2D.Double(
getX1(), getY1(), Math.ulp( 0. ), Math.ulp( 0. ) );
return new Rectangle2D.Double( getX1(), getY1(), Math.ulp( 0. ), Math.ulp( 0. ) );
}
}
35 changes: 19 additions & 16 deletions src/jdrafting/gui/Application.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package jdrafting.gui;

import static jdrafting.gui.JDUtils.getLargeIcon;
import static jdrafting.gui.JDUtils.getLocaleMnemonic;
import static jdrafting.gui.JDUtils.getLocaleText;
import static jdrafting.gui.JDUtils.getSmallIcon;
import static jdrafting.gui.JDUtils.getLocaleMnemonic;

import java.awt.BasicStroke;
import java.awt.BorderLayout;
Expand All @@ -30,6 +30,7 @@
import java.io.ObjectInputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Calendar;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -160,6 +161,7 @@
/**
* {@value #APPNAME} GUI class
* @author {@value #AUTHOR}, {@value #COPYLEFT}
* @since 0.1.0
* @version {@value #VERSION}
*/
@SuppressWarnings("serial")
Expand All @@ -170,13 +172,13 @@ public class Application extends JFrame
//////////////////////
// metainfo
public static final String APPNAME = "JDrafting";
public static final String VERSION = "0.1.9";
public static final String VERSION = "0.1.10";
public static final String AUTHOR = "Miguel Alejandro Moreno Barrientos";
public static final String COPYLEFT = "2016";
public static final String COPYLEFT = "2016,2020";
public static final String PROJECT_PAGE =
"http://miguelalejandromorenobarrientos.github.io/jdrafting";
"http://miguelalejandromorenobarrientos.github.io/jdrafting";
public static final String GITHUB_REPOSITORY =
"https://github.com/miguelalejandromorenobarrientos/jdrafting/tree/master";
"https://github.com/miguelalejandromorenobarrientos/jdrafting/tree/master";
// colors
public static Color toolMainColor = Color.BLUE;
// separators
Expand All @@ -188,9 +190,8 @@ public class Application extends JFrame
// STATIC VARS //
/////////////////
public static Locale locale = Locale.getDefault();
public static String lookAndFeelClassName =
UIManager.getSystemLookAndFeelClassName();
public static boolean jmeEnabled = false;
public static String lookAndFeelClassName = UIManager.getSystemLookAndFeelClassName();
public static boolean jmeEnabled = true;


///////////////////
Expand All @@ -210,7 +211,7 @@ public class Application extends JFrame
private BasicStroke stroke = JDStrokes.PLAIN_ROUND.getStroke();
private Color pointColor = Color.DARK_GRAY;
private BasicStroke pointStroke =
new BasicStroke( 8f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND );
new BasicStroke( 8f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND );
// undo/redo
public UndoManager undoManager;
public UndoableEditSupport undoSupport;
Expand Down Expand Up @@ -254,6 +255,11 @@ public class Application extends JFrame
/////////////////
public Application()
{
// easter egg joke
final int year = Calendar.getInstance().get( Calendar.YEAR );
if ( year >= 2030 )
System.out.println( "\n\tYeah! My program still running in " + year + "!!\n" );

// create app window
initUI();
createActions();
Expand Down Expand Up @@ -1168,7 +1174,7 @@ public void actionPerformed( ActionEvent e )
shapebar.add( actionMap.get( getLocaleText( "spline" ) ) );
shapebar.add( actionMap.get( getLocaleText( "free_hand" ) ) );
if ( jmeEnabled )
shapebar.add( actionMap.get( "Math function" ) );
shapebar.add( actionMap.get( getLocaleText( "func" ) ) );
// toolbar
toolbar.add( actionMap.get( getLocaleText( "perp" ) ) );
toolbar.add( actionMap.get( getLocaleText( "para" ) ) );
Expand Down Expand Up @@ -1539,8 +1545,7 @@ public class EditAddShapeToExercise extends AbstractUndoableEdit
private JDraftingShape jdshape;
private int index;

public EditAddShapeToExercise(@NotNull JDraftingShape jdshape,
int index )
public EditAddShapeToExercise( @NotNull JDraftingShape jdshape, int index )
{
this.jdshape = jdshape;
this.index = index;
Expand Down Expand Up @@ -1633,8 +1638,7 @@ public static void main( String[] args )
// (some parameters like lang, lookfeel need to be executed
// before app intantiation)
JDraftingArgs argsParser = new JDraftingArgs( null );
ParsedParameterMap parsedMap =
argsParser.parseAndExecute( args );
ParsedParameterMap parsedMap = argsParser.parseAndExecute( args );

// application instance
Application app = new Application();
Expand All @@ -1649,8 +1653,7 @@ public static void main( String[] args )
// load file from console
// (file load must be executed with a visible app)
if ( parsedMap.containsParam( "file" ) )
app.openFile(
new File( parsedMap.getValues( "file" )[0] ) );
app.openFile( new File( parsedMap.getValues( "file" )[0] ) );
}
catch ( NoSuchElementException e )
{
Expand Down
6 changes: 5 additions & 1 deletion src/jdrafting/gui/CanvasPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ public void paintComponent( Graphics g )

Graphics2D g2 = (Graphics2D) g;

// High quality render
JDUtils.setHighQualityRender( g2 );

// draw exercise shapes
drawExercise( g2, getTransform(), app.getExercise(),
app.getSelectedShapes(), app.isVisibleNames() );
Expand Down Expand Up @@ -599,7 +602,8 @@ class MoveCanvasThread extends Thread
public void stopMe() { stop = true; }

@Override
public void run() {
public void run()
{
while ( !stop )
{
try { Thread.sleep( wait < MAX_WAIT ? 20 : 200 ); }
Expand Down
22 changes: 21 additions & 1 deletion src/jdrafting/gui/JDUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.util.Locale;
Expand All @@ -26,7 +28,7 @@ public class JDUtils
private JDUtils() {}

public static int smallIconSize = 16;
public static int largeIconSize = 32;
public static int largeIconSize = 24;

/**
* Get screen size, multiplied by factor
Expand Down Expand Up @@ -146,4 +148,22 @@ public static String camelCase( String text )

return String.join( "", words );
}

public static void setHighQualityRender( Graphics2D g2 )
{
g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON );
g2.setRenderingHint( RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_QUALITY );
g2.setRenderingHint( RenderingHints.KEY_ALPHA_INTERPOLATION,
RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY );
g2.setRenderingHint( RenderingHints.KEY_COLOR_RENDERING,
RenderingHints.VALUE_COLOR_RENDER_QUALITY );
g2.setRenderingHint( RenderingHints.KEY_DITHERING,
RenderingHints.VALUE_DITHER_ENABLE );
g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
}
}
13 changes: 7 additions & 6 deletions src/jdrafting/gui/ShapeList.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ public void valueChanged( ListSelectionEvent e )
/**
* ListCellRenderer
*/
class ShapeListRenderer extends JPanel implements
ListCellRenderer<JDraftingShape>
class ShapeListRenderer extends JPanel implements ListCellRenderer<JDraftingShape>
{
@Override
public Component getListCellRendererComponent(
Expand All @@ -140,6 +139,9 @@ protected void paintComponent( Graphics g )
super.paintComponent(g);

Graphics2D g2 = (Graphics2D) g;

// High quality render
JDUtils.setHighQualityRender( g2 );

Viewport viewDest = new Viewport( 0, getWidth() - 1,
0, getHeight() - 1 );
Expand Down Expand Up @@ -168,10 +170,9 @@ protected void paintComponent( Graphics g )
mini.setMinimumSize( mini.getPreferredSize() );
// name
add( Box.createHorizontalStrut( 4 ) );
JLabel shapeName = new JLabel(
value.getName() != null && value.getName().length() > 0
? value.getName()
: "unnamed", JLabel.LEFT );
JLabel shapeName = new JLabel( value.getName() != null && value.getName().length() > 0
? value.getName()
: "", JLabel.LEFT );
add( shapeName );
shapeName.setFont( new Font( Font.SANS_SERIF, Font.BOLD, 20 ) );
shapeName.setForeground( Color.BLUE );
Expand Down
28 changes: 14 additions & 14 deletions src/jdrafting/gui/controller/actions/AboutAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import javax.swing.JEditorPane;
import javax.swing.JOptionPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

import jdrafting.gui.Application;
import jdrafting.gui.JDUtils;
Expand Down Expand Up @@ -68,24 +67,25 @@ public void actionPerformed( ActionEvent e )
+ "CLA</a>"
+ "</p>"
+ "<p>"
+ "<br/> @" + Application.COPYLEFT
+ "Math parser for functions: "
+ "<a href="
+ "'https://miguelalejandromorenobarrientos.github.io/JmeDoc/'>"
+ "JME parser</a>"
+ "</p>"
+ "<p>"
+ "<br/> (C)" + Application.COPYLEFT
+ "</p>"
+ "</html>" );
ep.setEditable( false );
ep.setOpaque( false );
ep.addHyperlinkListener( new HyperlinkListener() {
@Override
public void hyperlinkUpdate( HyperlinkEvent e )
ep.getCaret().deinstall( ep ); // non-selectable
ep.addHyperlinkListener( ev -> {
if ( ev.getEventType().equals( HyperlinkEvent.EventType.ACTIVATED )
&& Desktop.isDesktopSupported()
&& Desktop.getDesktop().isSupported( Desktop.Action.BROWSE ) )
{
if ( e.getEventType().equals(
HyperlinkEvent.EventType.ACTIVATED )
&& Desktop.isDesktopSupported()
&& Desktop.getDesktop().isSupported(
Desktop.Action.BROWSE ) )
{
try { Desktop.getDesktop().browse( e.getURL().toURI() ); }
catch ( URISyntaxException | IOException ex ) {}
}
try { Desktop.getDesktop().browse( ev.getURL().toURI() ); }
catch ( URISyntaxException | IOException ex ) {}
}
});
JOptionPane.showMessageDialog( app, ep, "About " + Application.APPNAME,
Expand Down
3 changes: 1 addition & 2 deletions src/jdrafting/gui/controller/actions/ExtremesAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public ExtremesAction( Application app )
@Override
public void actionPerformed( ActionEvent e )
{
app.getCanvas().setCanvasListener(
new ExtremesListener( app.getCanvas() ) );
app.getCanvas().setCanvasListener( new ExtremesListener( app.getCanvas() ) );
}

}
Loading

0 comments on commit 30d8c92

Please sign in to comment.