This commit is contained in:
Ziver Koc 2013-09-07 01:14:18 +00:00
parent 7aa5bc2a0e
commit 4256d6e7b2
12 changed files with 401 additions and 26 deletions

View file

@ -2,13 +2,13 @@
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="libs/dom4j-1.6.1.jar" sourcepath="C:/Users/Ziver/Documents/Programmering/Java/libs/dom4j-1.6.1/src"/> <classpathentry exported="true" kind="lib" path="libs/dom4j-1.6.1.jar" sourcepath="C:/Users/Ziver/Documents/Programmering/Java/libs/dom4j-1.6.1/src"/>
<classpathentry kind="lib" path="libs/wsdl4j-1.6.2.jar"/> <classpathentry exported="true" kind="lib" path="libs/javassist.jar" sourcepath="C:/Users/Ziver/Documents/Programmering/Java/libs/javassist-3.12.GA"/>
<classpathentry kind="lib" path="libs/javassist.jar" sourcepath="C:/Users/Ziver/Documents/Programmering/Java/libs/javassist-3.12.GA"/> <classpathentry kind="lib" path="libs/junit-benchmarks-0.7.0.jar"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="lib" path="libs/commons-fileupload-1.2.1.jar" sourcepath="C:/Users/Ziver/Documents/Programmering/Java/libs/commons/commons-fileupload-1.2.1-sources.jar"/> <classpathentry exported="true" kind="lib" path="libs/commons-fileupload-1.2.1.jar" sourcepath="C:/Users/Ziver/Documents/Programmering/Java/libs/commons/commons-fileupload-1.2.1-sources.jar"/>
<classpathentry kind="lib" path="libs/commons-io-1.4.jar"/> <classpathentry exported="true" kind="lib" path="libs/commons-io-1.4.jar"/>
<classpathentry kind="lib" path="libs/mysql-connector-java-5.1.14-bin.jar"/> <classpathentry exported="true" kind="lib" path="libs/mysql-connector-java-5.1.14-bin.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0"/> <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0"/>
<classpathentry kind="con" path="at.bestsolution.efxclipse.tooling.jdt.core.JAVAFX_CONTAINER"/> <classpathentry kind="con" path="at.bestsolution.efxclipse.tooling.jdt.core.JAVAFX_CONTAINER"/>

View file

@ -0,0 +1,156 @@
/*******************************************************************************
* Copyright (c) 2013 Ziver
*
* 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.
******************************************************************************/
package zutil.chart;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Line2D;
import java.util.logging.Logger;
import javax.swing.JPanel;
import zutil.log.LogUtil;
public abstract class AbstractChart extends JPanel{
private static final Logger logger = LogUtil.getLogger();
private static final long serialVersionUID = 1L;
/** The offset from the borders of the panel in pixels */
public static final int PADDING = 20;
protected ChartData data;
protected int width;
protected int height;
protected Rectangle chartBound;
protected void paintComponent(Graphics g){
Graphics2D g2 = (Graphics2D)g;
Rectangle bound = drawScale( g2 );
drawChart( g2, bound );
}
protected Rectangle drawScale(Graphics2D g2){
if( data == null )
return null;
// update values
width = this.getWidth();
height = this.getHeight();
Rectangle bound = new Rectangle();
// Values
int stepLength = 7;
/////// Temp values
// Calculate Font sizes
FontMetrics metric = g2.getFontMetrics();
int fontHeight = metric.getHeight();
int fontXWidth = 0;
int fontYWidth = 0;
for( Point p : data.getPoints() ){
int length = 0;
String tmp = data.getXString( p.x );
if( tmp != null ) length = metric.stringWidth( tmp );
else length = metric.stringWidth( ""+p.x );
fontXWidth = Math.max(length, fontXWidth);
tmp = data.getXString( p.y );
if( tmp != null ) length = metric.stringWidth( tmp );
else length = metric.stringWidth( ""+p.y );
fontYWidth = Math.max(length, fontYWidth);
}
// Calculate origo
Point origo = new Point( PADDING+fontYWidth+stepLength, height-PADDING-fontHeight-stepLength );
bound.x = (int) (origo.getX()+1);
bound.y = PADDING;
bound.width = width-bound.x-PADDING;
bound.height = (int) (origo.getY()-PADDING-1);
// Calculate Axis scales
double xScale = (double)(Math.abs(data.getMaxX())+Math.abs(data.getMinX()))/bound.width;
double yScale = (double)(Math.abs(data.getMaxY())+Math.abs(data.getMinY()))/bound.height;
/////// Draw
// Y Axis
g2.draw( new Line2D.Double( origo.getX(), PADDING, origo.getX(), origo.getY() ));
// X Axis
g2.draw( new Line2D.Double( origo.getX(), origo.getY(), width-PADDING, origo.getY() ));
// Y Axis steps and labels
g2.draw( new Line2D.Double( origo.getX(), origo.getY(), origo.getX()-stepLength, origo.getY() ));
g2.draw( new Line2D.Double( origo.getX(), PADDING, origo.getX()-stepLength, PADDING ));
// X Axis steps and labels
g2.draw( new Line2D.Double( width-PADDING, origo.getY(), width-PADDING, origo.getY()+stepLength ));
// DEBUG
/*
g2.setColor(Color.red);
g2.drawRect(bound.x, bound.y, bound.width, bound.height);
*/
return bound;
}
/**
* This method is called after the chart scale has been drawn.
* This method will draw the actual chart
*
* @param g is the Graphics object that will paint the chart
* @param bound is the bounds of the chart, the drawing should not exceed this bound
*/
protected abstract void drawChart(Graphics2D g2, Rectangle bound);
/**
* Sets the data that will be drawn.
*
* @param data is the data to draw
*/
public void setChartData(ChartData data){
this.data = data;
}
/**
* Converts a x value to ax pixel coordinate
*
* @param x is the x data value
* @return pixel coordinate, or 0 if the chart have not been drawn yet.
*/
protected int getXCoordinate(int x){
return 0;
}
/**
* Converts a y value to a y pixel coordinate
*
* @param y is the y data value
* @return pixel coordinate, or 0 if the chart have not been drawn yet.
*/
protected int getYCoordinate(int y){
return 0;
}
}

View file

@ -0,0 +1,103 @@
/*******************************************************************************
* Copyright (c) 2013 Ziver
*
* 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.
******************************************************************************/
package zutil.chart;
import java.awt.Point;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class ChartData {
private HashMap<Integer,String> xStrings;
private HashMap<Integer,String> yStrings;
private int maxx;
private int minx;
private int maxy;
private int miny;
private ArrayList<Point> points;
public ChartData(){
xStrings = new HashMap<Integer,String>();
yStrings = new HashMap<Integer,String>();
points = new ArrayList<Point>();
}
public void setXValueString(int x, String name){
xStrings.put(x, name);
}
public void setYValueString(int y, String name){
yStrings.put(y, name);
}
public void addPoint(int x, int y){
points.add( new Point( x, y));
setMaxMin(x, y);
}
public void addPoint(int y){
points.add( new Point( maxx, y));
maxx++;
setMaxMin(maxx, y);
}
public void addPoint(String x, int y){
xStrings.put(maxx, x);
points.add( new Point( maxx, y));
maxx++;
setMaxMin(maxx, y);
}
private void setMaxMin(int x, int y){
if( x > maxx ) maxx = x;
else if( x < minx ) minx = x;
if( y > maxy ) maxx = y;
else if( y < miny ) minx = y;
}
public int getMaxX(){
return maxx;
}
public int getMinX(){
return minx;
}
public int getMaxY(){
return maxy;
}
public int getMinY(){
return miny;
}
public String getXString(int x){
return xStrings.get(x);
}
public String getYString(int y){
return yStrings.get(y);
}
protected List<Point> getPoints(){
return points;
}
}

View file

@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright (c) 2013 Ziver
*
* 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.
******************************************************************************/
package zutil.chart;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Line2D;
public class LineChart extends AbstractChart{
private static final long serialVersionUID = 1L;
@Override
protected void drawChart(Graphics2D g2, Rectangle bound) {
// TODO Auto-generated method stub
drawLine(g2, 50, 50,100,150);
drawLine(g2, 100,150,150,100);
drawLine(g2, 150,100,200,300);
drawLine(g2, 200,300,250,40);
}
private void drawLine(Graphics2D g2, float x1, float y1, float x2, float y2){
// Shadow
g2.setPaint(new Color(220,220,220));
g2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g2.draw( new Line2D.Float(x1, y1+2, x2, y2+2));
// Smoth shadow
g2.setPaint(new Color(230,230,230));
g2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g2.draw( new Line2D.Float(x1+1, y1+3, x2-1, y2+3));
// Line border
g2.setPaint(new Color(255,187,187));
g2.setStroke(new BasicStroke(4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g2.draw( new Line2D.Float(x1, y1, x2, y2));
// Line
g2.setPaint(new Color(237,28,36));
g2.setStroke(new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
g2.draw( new Line2D.Float(x1, y1, x2, y2));
}
}

View file

@ -23,6 +23,7 @@
package zutil.db; package zutil.db;
import java.io.Closeable; import java.io.Closeable;
import java.math.BigInteger;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -114,13 +115,13 @@ public class DBConnection implements Closeable{
/** /**
* @return the last inserted id or -1 if there was an error * @return the last inserted id or -1 if there was an error
*/ */
public Object getLastInsertID(){ public long getLastInsertID(){
try{ try{
return exec("SELECT LAST_INSERT_ID()", new SimpleSQLHandler<Object>()); return exec("SELECT LAST_INSERT_ID()", new SimpleSQLHandler<BigInteger>()).longValue();
}catch(SQLException e){ }catch(SQLException e){
logger.log(Level.WARNING, null, e); logger.log(Level.WARNING, null, e);
} }
return null; return -1;
} }
/** /**

View file

@ -266,7 +266,7 @@ public abstract class DBBean {
// Execute the SQL // Execute the SQL
DBConnection.exec(stmt); DBConnection.exec(stmt);
if( id == null ) if( id == null )
this.id = (Long) db.getLastInsertID(); this.id = db.getLastInsertID();
// Save the list, after we get the object id // Save the list, after we get the object id
for(Field field : config.fields){ for(Field field : config.fields){

View file

@ -103,7 +103,6 @@ public class NetLogGuiClientInstance implements Initializable, NetLogListener {
logTable.getItems().add(msg); logTable.getItems().add(msg);
Platform.runLater(new Runnable() { Platform.runLater(new Runnable() {
@Override
public void run() { public void run() {
logCountLabel.setText("" + (Long.parseLong(logCountLabel.getText()) + 1)); logCountLabel.setText("" + (Long.parseLong(logCountLabel.getText()) + 1));
} }

View file

@ -77,9 +77,9 @@ public class Tick {
*/ */
public static char increment(char c){ public static char increment(char c){
switch(Character.toLowerCase(c)){ switch(Character.toLowerCase(c)){
case 'z': return 'å'; case 'z': return 'å';
case 'å': return 'ä'; case 'å': return 'ä';
case 'ä': return 'ö'; case 'ä': return 'ö';
} }
c = (char)(Character.toLowerCase(c) + 1); c = (char)(Character.toLowerCase(c) + 1);
if(isAlfa(c)){ if(isAlfa(c)){
@ -123,9 +123,9 @@ public class Tick {
case 'x': case 'x':
case 'y': case 'y':
case 'z': case 'z':
case 'å': case 'å':
case 'ä': case 'ä':
case 'ö': return true; case 'ö': return true;
default: return false; default: return false;
} }
} }

View file

@ -26,8 +26,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.wsdl.WSDLException;
import javassist.CannotCompileException; import javassist.CannotCompileException;
import javassist.ClassPool; import javassist.ClassPool;
import javassist.CtClass; import javassist.CtClass;
@ -57,7 +55,7 @@ public class SOAPClientFactory {
* @return a client Object * @return a client Object
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> T getClient(Class<T> intf) throws InstantiationException, IllegalAccessException, CannotCompileException, NotFoundException, WSDLException{ public static <T> T getClient(Class<T> intf) throws InstantiationException, IllegalAccessException, CannotCompileException, NotFoundException{
if( !WSInterface.class.isAssignableFrom( intf )){ if( !WSInterface.class.isAssignableFrom( intf )){
throw new ClassCastException("The Web Service class is not a subclass of WSInterface!"); throw new ClassCastException("The Web Service class is not a subclass of WSInterface!");
} }

View file

@ -0,0 +1,60 @@
/*******************************************************************************
* Copyright (c) 2013 Ziver
*
* 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.
******************************************************************************/
package zutil.test;
import java.util.logging.Level;
import javax.swing.JFrame;
import zutil.chart.ChartData;
import zutil.chart.LineChart;
import zutil.log.LogUtil;
public class ChartTest extends JFrame{
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
LogUtil.setLevel("zutil", Level.FINEST);
ChartTest frame = new ChartTest();
frame.setVisible(true);
}
public ChartTest(){
ChartData data = new ChartData();
data.addPoint(1,1);
data.addPoint(2,1);
data.addPoint(3,1);
data.addPoint(4,1);
data.addPoint(5,1);
data.addPoint(6,1);
data.addPoint(7,1);
data.addPoint(8,1);
LineChart chart = new LineChart();
chart.setChartData( data );
this.add( chart );
this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
this.setSize(600, 400);
}
}

View file

@ -27,8 +27,6 @@ import java.util.logging.Level;
import javassist.CannotCompileException; import javassist.CannotCompileException;
import javassist.NotFoundException; import javassist.NotFoundException;
import javax.wsdl.WSDLException;
import zutil.log.CompactLogFormatter; import zutil.log.CompactLogFormatter;
import zutil.log.LogUtil; import zutil.log.LogUtil;
import zutil.net.http.soap.SOAPClientFactory; import zutil.net.http.soap.SOAPClientFactory;
@ -36,7 +34,7 @@ import zutil.net.ws.WSInterface;
public class SOAPClientTest { public class SOAPClientTest {
public static void main(String[] args) throws InstantiationException, IllegalAccessException, CannotCompileException, NotFoundException, WSDLException{ public static void main(String[] args) throws InstantiationException, IllegalAccessException, CannotCompileException, NotFoundException{
LogUtil.setGlobalLevel(Level.ALL); LogUtil.setGlobalLevel(Level.ALL);
LogUtil.setFormatter("", new CompactLogFormatter()); LogUtil.setFormatter("", new CompactLogFormatter());

View file

@ -25,8 +25,6 @@ package zutil.test;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import javax.wsdl.WSDLException;
import zutil.io.MultiPrintStream; import zutil.io.MultiPrintStream;
import zutil.net.http.HttpServer; import zutil.net.http.HttpServer;
import zutil.net.http.soap.SOAPHttpPage; import zutil.net.http.soap.SOAPHttpPage;
@ -37,7 +35,7 @@ import zutil.net.ws.WebServiceDef;
public class UPnPServerTest { public class UPnPServerTest {
public static void main(String[] args) throws IOException, WSDLException{ public static void main(String[] args) throws IOException{
UPnPMediaServer upnp = new UPnPMediaServer("http://192.168.0.60:8080/"); UPnPMediaServer upnp = new UPnPMediaServer("http://192.168.0.60:8080/");
MultiPrintStream.out.println("UPNP Server running"); MultiPrintStream.out.println("UPNP Server running");