From fddca5ccb389facf876038720f431cf20e7a2cfa Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Wed, 19 Aug 2020 10:15:47 +0900 Subject: [PATCH] Implement basic Chart application --- Chart/.classpath | 10 + Chart/.gitignore | 1 + Chart/.project | 17 + Chart/.settings/org.eclipse.jdt.core.prefs | 14 + Chart/chart.png | Bin 0 -> 22941 bytes Chart/src/sig/Chart.java | 67 ++++ Chart/src/sig/ChartMain.java | 52 +++ Chart/src/sig/ChartPanel.java | 22 ++ Chart/src/sig/chart/BarChart.java | 67 ++++ Chart/src/sig/chart/LineChart.java | 76 ++++ Chart/src/sig/utils/Audio.java | 219 ++++++++++++ Chart/src/sig/utils/DebugUtils.java | 17 + Chart/src/sig/utils/DrawUtils.java | 147 ++++++++ Chart/src/sig/utils/FileUtils.java | 381 +++++++++++++++++++++ Chart/src/sig/utils/GithubUtils.java | 35 ++ Chart/src/sig/utils/ImageUtils.java | 114 ++++++ Chart/src/sig/utils/JavaUtils.java | 39 +++ Chart/src/sig/utils/MemoryUtils.java | 37 ++ Chart/src/sig/utils/ReflectUtils.java | 10 + Chart/src/sig/utils/SoundUtils.java | 30 ++ Chart/src/sig/utils/TextUtils.java | 137 ++++++++ Chart/src/sig/utils/TimeUtils.java | 32 ++ Chart/src/sig/utils/WebUtils.java | 69 ++++ 23 files changed, 1593 insertions(+) create mode 100644 Chart/.classpath create mode 100644 Chart/.gitignore create mode 100644 Chart/.project create mode 100644 Chart/.settings/org.eclipse.jdt.core.prefs create mode 100644 Chart/chart.png create mode 100644 Chart/src/sig/Chart.java create mode 100644 Chart/src/sig/ChartMain.java create mode 100644 Chart/src/sig/ChartPanel.java create mode 100644 Chart/src/sig/chart/BarChart.java create mode 100644 Chart/src/sig/chart/LineChart.java create mode 100644 Chart/src/sig/utils/Audio.java create mode 100644 Chart/src/sig/utils/DebugUtils.java create mode 100644 Chart/src/sig/utils/DrawUtils.java create mode 100644 Chart/src/sig/utils/FileUtils.java create mode 100644 Chart/src/sig/utils/GithubUtils.java create mode 100644 Chart/src/sig/utils/ImageUtils.java create mode 100644 Chart/src/sig/utils/JavaUtils.java create mode 100644 Chart/src/sig/utils/MemoryUtils.java create mode 100644 Chart/src/sig/utils/ReflectUtils.java create mode 100644 Chart/src/sig/utils/SoundUtils.java create mode 100644 Chart/src/sig/utils/TextUtils.java create mode 100644 Chart/src/sig/utils/TimeUtils.java create mode 100644 Chart/src/sig/utils/WebUtils.java diff --git a/Chart/.classpath b/Chart/.classpath new file mode 100644 index 0000000..c0f260f --- /dev/null +++ b/Chart/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Chart/.gitignore b/Chart/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/Chart/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/Chart/.project b/Chart/.project new file mode 100644 index 0000000..fb3ba82 --- /dev/null +++ b/Chart/.project @@ -0,0 +1,17 @@ + + + Chart + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Chart/.settings/org.eclipse.jdt.core.prefs b/Chart/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..71f736f --- /dev/null +++ b/Chart/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,14 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=12 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=12 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=12 diff --git a/Chart/chart.png b/Chart/chart.png new file mode 100644 index 0000000000000000000000000000000000000000..74ac274f6f2f4d7f629b206c99562659425e9fc9 GIT binary patch literal 22941 zcmeIad0f-S_CFl!ZS8e!Z?D&d&DO1gm0DDU06}e4ux+_fv_Te9LUwzv4R=^)&2hjMp(l*F3OZ?0d?cdD?0c49w~M z$HK2-#@C=D=B+3{PCldN2S!&*j3*M?YQAe^?^VxC*>W(*$&%dj zXiIKsFzq*=^ZgafO^QQXj>yXNGnmV&{%a;As3k068)|+_7|OBNkFy}Tr5>#dcs@Jf zJlY|_Ydw_M3FTYi|?tPn@&f)7yfF-=@tF6XKkAND3(kI zw=m&h%KWE7z{=~5NE6`B^*9$-$_-WVf62p>duMfj_sicFKvo37@62oR34{waMhM<@ zH*RXqo_jzfM zWkD5DPFak|TGDTNcV@Vvx%eL8s$1@)m=w1x&?$l<^!2ziDESoj(Nw34sDtdo_J--) z{vU4;{p-OKC?enG(?yAZ{as$1A&jD)+P<${cZ?7?VPT=PP46W$P|$}X3sI~#n=PHw zzdvE;LX1hwK)73lJEppG`N|%6S~0_o&wujP29oLIUkK@AEGg zqRfOnjMxIJGI&}%389JqD0uk#0+RqMt8|N;uD5U}e#&CRdXY-q6pMQlJ2y{LW4bgE zp~@o?H#dEq_9%)Ypt^{(E_JWgpKGk$Pxx}u@Txam>G`z&Fy*CO0T9X8K}jGjiT2mBzLrtyVzY3um6y_EUH22LAYPPb7$^`U5Se&NiWgo0CZ&l1O26X zaZLZ_ZAWYi!0*8(PY~Gh2F~Ag{vOWTXsS2FruTHs%{x_Mx;}|71U4_;L%x)NP^Jyx zxs+56n91EEXC@~sn6_o@`I>phudy~;VT{>~sW*X_z1jPt(sxn5nQ81tdU z=5rY^K74cAzC+%P*$oq6-(AC)ktmGfx=~?Qu^Ci!)y-)kWT0q9;v-wD3zviEP)>m6 zq$_ThC)t;~{hIP|q`zpGi{uU`%cve5-dm2uTs9R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Cd_yWs%n zF`;SOhn>Ki7k#TwSjbtML{lF~NJa3=a@~&r1tdQ-*(w6I?@5uap~_2xfj0XlzF5>j z2fL2hVHGBEr1YUPb^)r}zd1+u=??Hq^h^IiTX%Z`jq%CT#-Fz4xpTBv?afoP@U#Uu z8%uj-AaTz9k)QY7YNWDy-mtRMK3gb#h_GQF&-$cD-m0$uIJA5OnLNeHjv@7|?w4yo z$>SHD$M2}1jn+@Uy5-L9ZN^<+uKGHw{=CnKYwr`>^%9Tz^KD928YFPyi!e!%fw`qt z4jvk@KkBFNAUCYmfnDFvm437zv!e{z9Px`=bHm>UXZeIbTpUaBvOs?29QW~<`7*eT zdV2li#jzKee3L#I@_Io8zcKJZZt~dd7dOwi_`dn)G^RFh%WE=YH>@KSw?7(8c$~jI^@IA7RVEDD0OW4qZTJh_pZamEg($-cYu0Y#P2H zyEO%ZABy*C^>^p~zy2rRYLWIC1R_&W8m(Wx^A?2EhBUT=-xYgvtmR;MTf4_hNJd#T z*Lu+2jw>jUW9bbT1Rf)(K|%iTx?1zudyu~S2#KWBSmP(CDID!Pt{HTOj9u)hnqaXB zm&I3+-FVN8xFXU_2>EVd-nWpzGL2XoCwPV>NS#^MzQH~p$ZKrVp(XD^QX{C!M6Dlm zZ?+WX3r(L7$&jXmPmb=N%~uJut6WG*|Cta=)<2C=0DWJAQ^3wgB#mR{a`niQ`xf| z5E+lUHeeV!wK@k5R)+v2u)i6Qp=#J7`V0tRZ>ydObnv1Iw$Sz~-2N*i(Tx4Y8}h5F zRy6|4{TA{ots1r<1#()Z<9ufQ04N|zVo-nO1S#HOr~kii7ylXY|B?g#N74UU(O3`z g|3CWQA0qQCar3&64W-+!+8_pfvFCHj)~~+%Zy}DT-2eap literal 0 HcmV?d00001 diff --git a/Chart/src/sig/Chart.java b/Chart/src/sig/Chart.java new file mode 100644 index 0000000..0a18168 --- /dev/null +++ b/Chart/src/sig/Chart.java @@ -0,0 +1,67 @@ +package sig; + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Polygon; +import java.awt.Rectangle; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; + +public class Chart { + protected Point[] data; + protected int minX,maxX; + protected int minY,maxY; + protected String xLabel,yLabel; + protected int xSize,ySize; + protected int xScale,yScale; + protected int dotSize=8; + protected Rectangle chartBounds; + protected Color backCol = Color.LIGHT_GRAY, + axesCol = Color.BLACK, + plotCol = new Color(255,220,100); + protected static Font chartFont = new Font("Consolas",Font.BOLD,24); + + public Chart(Point[] data, int xSize, int ySize, String xLabel, String yLabel) { + this.data = data; + /*this.minX = minX; + this.maxX = maxX; + this.minY = minY; + this.maxY = maxY;*/ + minX=maxX=minY=maxY=0; + + for (Point p : data) { + minX=Math.min(minX,p.x); + minY=Math.min(minY,p.y); + maxX=Math.max(maxX,p.x); + maxY=Math.max(maxY,p.y); + } + + this.xSize = xSize; + this.ySize = ySize; + + xScale = xSize/(maxX-minX); + yScale = ySize/(maxY-minY); + + this.xLabel=xLabel; + this.yLabel=yLabel; + + chartBounds = new Rectangle( + ChartMain.f.getWidth()/2-xSize/2, + ChartMain.f.getHeight()/2-ySize/2, + xSize,ySize); + } + + public void render(Graphics g) throws IOException { + //System.out.println("Rendering"); + chartBounds = new Rectangle( + ChartMain.f.getWidth()/2-xSize/2, + ChartMain.f.getHeight()/2-ySize/2, + xSize,ySize); + } +} diff --git a/Chart/src/sig/ChartMain.java b/Chart/src/sig/ChartMain.java new file mode 100644 index 0000000..51f91e6 --- /dev/null +++ b/Chart/src/sig/ChartMain.java @@ -0,0 +1,52 @@ +package sig; + +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; +import javax.swing.JFrame; + +import sig.chart.BarChart; +import sig.chart.LineChart; + +public class ChartMain { + public static JFrame f; + public static ChartPanel p; + public static LineChart chart; + public static void main(String[] args) throws IOException { + f = new JFrame(); + f.setSize(1024, 800); + p = new ChartPanel(); + int i=0; + chart = new LineChart( + new Point[] { + new Point(i++,(int)(Math.random()*10)), + new Point(i++,(int)(Math.random()*10)), + new Point(i++,(int)(Math.random()*10)), + new Point(i++,(int)(Math.random()*10)), + new Point(i++,(int)(Math.random()*10)), + new Point(i++,(int)(Math.random()*10)), + new Point(i++,(int)(Math.random()*10)), + new Point(i++,(int)(Math.random()*10)), + new Point(i++,(int)(Math.random()*10)), + new Point(i++,(int)(Math.random()*10)), + new Point(i++,(int)(Math.random()*10)), + new Point(i++,(int)(Math.random()*10)), + new Point(i++,(int)(Math.random()*10)), + new Point(i++,(int)(Math.random()*10)),}, + 640,480, + "Day","Cookies"); + + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + f.add(p); + f.setVisible(true); + + BufferedImage img = new BufferedImage(ChartMain.f.getWidth(),ChartMain.f.getHeight(),BufferedImage.TYPE_INT_ARGB); + Graphics2D g2 = img.createGraphics(); + ChartMain.p.paintAll(g2); + ImageIO.write(img, "png", new File("chart.png")); + } +} diff --git a/Chart/src/sig/ChartPanel.java b/Chart/src/sig/ChartPanel.java new file mode 100644 index 0000000..1e0dcf2 --- /dev/null +++ b/Chart/src/sig/ChartPanel.java @@ -0,0 +1,22 @@ +package sig; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; +import java.io.IOException; + +import javax.swing.JPanel; + +public class ChartPanel extends JPanel{ + public void paint(Graphics g) { + g.setColor(Color.WHITE); + g.fillRect(0,0,ChartMain.f.getWidth(),ChartMain.f.getHeight()); + + try { + ChartMain.chart.render(g); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/Chart/src/sig/chart/BarChart.java b/Chart/src/sig/chart/BarChart.java new file mode 100644 index 0000000..69af08d --- /dev/null +++ b/Chart/src/sig/chart/BarChart.java @@ -0,0 +1,67 @@ +package sig.chart; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Point; +import java.awt.geom.Rectangle2D; +import java.io.IOException; + +import sig.Chart; +import sig.ChartMain; +import sig.utils.DrawUtils; +import sig.utils.TextUtils; + +public class BarChart extends Chart{ + + public BarChart(Point[] data, int xSize, int ySize, String xLabel, String yLabel) { + super(data, xSize, ySize, xLabel, yLabel); + } + + + public void render(Graphics g) throws IOException { + super.render(g); + g.setColor(backCol); + g.fillRect(chartBounds.x,chartBounds.y,chartBounds.width,chartBounds.height); + + //g.drawString(xLabel, chartBounds., y); + DrawUtils.drawCenteredText(g, chartFont, ChartMain.p, + chartBounds.x+chartBounds.width/2, chartBounds.y+chartBounds.height+8, Color.BLACK, + xLabel); + Rectangle2D bounds = TextUtils.calculateStringBoundsFont(ChartMain.p, yLabel, chartFont); + DrawUtils.drawCenteredText(g, chartFont, ChartMain.p, + (int)(chartBounds.x-bounds.getWidth()/2-4), chartBounds.y+chartBounds.height/2, Color.BLACK, + yLabel); + + + g.setColor(plotCol); + for (int i=0;i 1) + throw new IllegalArgumentException( + "Volume can only be set to a value from 0 to 1. Given value is illegal: " + value); + Line line = getMasterOutputLine(); + if (line == null) throw new RuntimeException("Master output port not found"); + boolean opened = open(line); + try { + FloatControl control = getVolumeControl(line); + if (control == null) + throw new RuntimeException("Volume control not found in master port: " + toString(line)); + control.setValue(value); + } finally { + if (opened) line.close(); + } + } + + public static Float getMasterOutputVolume() { + Line line = getMasterOutputLine(); + if (line == null) return null; + boolean opened = open(line); + try { + FloatControl control = getVolumeControl(line); + if (control == null) return null; + return control.getValue(); + } finally { + if (opened) line.close(); + } + } + + public static void setMasterOutputMute(boolean value) { + Line line = getMasterOutputLine(); + if (line == null) throw new RuntimeException("Master output port not found"); + boolean opened = open(line); + try { + BooleanControl control = getMuteControl(line); + if (control == null) + throw new RuntimeException("Mute control not found in master port: " + toString(line)); + control.setValue(value); + } finally { + if (opened) line.close(); + } + } + + public static Boolean getMasterOutputMute() { + Line line = getMasterOutputLine(); + if (line == null) return null; + boolean opened = open(line); + try { + BooleanControl control = getMuteControl(line); + if (control == null) return null; + return control.getValue(); + } finally { + if (opened) line.close(); + } + } + + public static Line getMasterOutputLine() { + for (Mixer mixer : getMixers()) { + for (Line line : getAvailableOutputLines(mixer)) { + if (line.getLineInfo().toString().contains("Master")) return line; + } + } + return null; + } + + public static FloatControl getVolumeControl(Line line) { + if (!line.isOpen()) throw new RuntimeException("Line is closed: " + toString(line)); + return (FloatControl) findControl(FloatControl.Type.VOLUME, line.getControls()); + } + + public static BooleanControl getMuteControl(Line line) { + if (!line.isOpen()) throw new RuntimeException("Line is closed: " + toString(line)); + return (BooleanControl) findControl(BooleanControl.Type.MUTE, line.getControls()); + } + + private static Control findControl(Type type, Control... controls) { + if (controls == null || controls.length == 0) return null; + for (Control control : controls) { + if (control.getType().equals(type)) return control; + if (control instanceof CompoundControl) { + CompoundControl compoundControl = (CompoundControl) control; + Control member = findControl(type, compoundControl.getMemberControls()); + if (member != null) return member; + } + } + return null; + } + + public static List getMixers() { + Info[] infos = AudioSystem.getMixerInfo(); + List mixers = new ArrayList(infos.length); + for (Info info : infos) { + Mixer mixer = AudioSystem.getMixer(info); + mixers.add(mixer); + } + return mixers; + } + + public static List getAvailableOutputLines(Mixer mixer) { + return getAvailableLines(mixer, mixer.getTargetLineInfo()); + } + + public static List getAvailableInputLines(Mixer mixer) { + return getAvailableLines(mixer, mixer.getSourceLineInfo()); + } + + private static List getAvailableLines(Mixer mixer, Line.Info[] lineInfos) { + List lines = new ArrayList(lineInfos.length); + for (Line.Info lineInfo : lineInfos) { + Line line; + line = getLineIfAvailable(mixer, lineInfo); + if (line != null) lines.add(line); + } + return lines; + } + + public static Line getLineIfAvailable(Mixer mixer, Line.Info lineInfo) { + try { + return mixer.getLine(lineInfo); + } catch (LineUnavailableException ex) { + return null; + } + } + + public static String getHierarchyInfo() { + StringBuilder sb = new StringBuilder(); + for (Mixer mixer : getMixers()) { + sb.append("Mixer: ").append(toString(mixer)).append("\n"); + + for (Line line : getAvailableOutputLines(mixer)) { + sb.append(" OUT: ").append(toString(line)).append("\n"); + boolean opened = open(line); + for (Control control : line.getControls()) { + sb.append(" Control: ").append(toString(control)).append("\n"); + if (control instanceof CompoundControl) { + CompoundControl compoundControl = (CompoundControl) control; + for (Control subControl : compoundControl.getMemberControls()) { + sb.append(" Sub-Control: ").append(toString(subControl)).append("\n"); + } + } + } + if (opened) line.close(); + } + + for (Line line : getAvailableOutputLines(mixer)) { + sb.append(" IN: ").append(toString(line)).append("\n"); + boolean opened = open(line); + for (Control control : line.getControls()) { + sb.append(" Control: ").append(toString(control)).append("\n"); + if (control instanceof CompoundControl) { + CompoundControl compoundControl = (CompoundControl) control; + for (Control subControl : compoundControl.getMemberControls()) { + sb.append(" Sub-Control: ").append(toString(subControl)).append("\n"); + } + } + } + if (opened) line.close(); + } + + sb.append("\n"); + } + return sb.toString(); + } + + public static boolean open(Line line) { + if (line.isOpen()) return false; + try { + line.open(); + } catch (LineUnavailableException ex) { + return false; + } + return true; + } + + public static String toString(Control control) { + if (control == null) return null; + return control.toString() + " (" + control.getType().toString() + ")"; + } + + public static String toString(Line line) { + if (line == null) return null; + Line.Info info = line.getLineInfo(); + return info.toString();// + " (" + line.getClass().getSimpleName() + ")"; + } + + public static String toString(Mixer mixer) { + if (mixer == null) return null; + StringBuilder sb = new StringBuilder(); + Info info = mixer.getMixerInfo(); + sb.append(info.getName()); + sb.append(" (").append(info.getDescription()).append(")"); + sb.append(mixer.isOpen() ? " [open]" : " [closed]"); + return sb.toString(); + } + +} \ No newline at end of file diff --git a/Chart/src/sig/utils/DebugUtils.java b/Chart/src/sig/utils/DebugUtils.java new file mode 100644 index 0000000..f318564 --- /dev/null +++ b/Chart/src/sig/utils/DebugUtils.java @@ -0,0 +1,17 @@ +package sig.utils; + + +public class DebugUtils { + public static void showStackTrace() { + System.out.println("Trace:"+getStackTrace()); + } + + public static String getStackTrace() { + StackTraceElement[] stacktrace = new Throwable().getStackTrace(); + StringBuilder stack = new StringBuilder("Mini stack tracer:"); + for (int i=0;i0) { + AttributedString as = new AttributedString(message); + as.addAttribute(TextAttribute.FONT, font); + as.addAttribute(TextAttribute.KERNING,TextAttribute.KERNING_ON); + as.addAttribute(TextAttribute.WIDTH,TextAttribute.WIDTH_EXTENDED); + as.addAttribute(TextAttribute.TRACKING,0.5); + g.setColor(shadow_color); + Graphics2D g2 = (Graphics2D) g; + FontRenderContext frc = g2.getFontMetrics(font).getFontRenderContext(); + GlyphVector gv = font.createGlyphVector(frc, message); + Shape shape = gv.getOutline((int)(x+xoffset),(int)(y+yoffset)); + g2.setClip(null); + g2.setStroke(new BasicStroke(font_thickness + outline_thickness*2)); + g2.setColor(shadow_color); + g2.setRenderingHint( + RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + g2.draw(shape); + GlyphVector gv2 = font.createGlyphVector(frc, message); + Shape shape2 = gv2.getOutline((int)(x+xoffset),(int)(y+yoffset)); + g2.setClip(null); + g2.setStroke(new BasicStroke(font_thickness)); + g2.setColor(text_color); + g2.setRenderingHint( + RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + g2.draw(shape2); + g2.setColor(text_color); + g2.drawString(as.getIterator(),(int)(x+xoffset),(int)(y+yoffset)); + } + } + public static void drawCenteredOutlineText(Graphics g, Font font,JPanel panel, double x, double y, int font_size, int outline_size, Color text_color, Color shadow_color, String message) { + Rectangle2D textBounds = TextUtils.calculateStringBoundsFont(panel,message, font); + drawOutlineText(g,font,x,y,-textBounds.getWidth()/2,-textBounds.getHeight()/2,font_size,outline_size,text_color,shadow_color,message); + } + public static void drawCenteredOutlineText(Graphics g, Font font,JPanel panel, double x, double y, int outline_size, Color text_color, Color shadow_color, String message) { + drawCenteredOutlineText(g,font,panel,x,y,1,outline_size,text_color,shadow_color,message); + } + public static void drawText(Graphics g, double x, double y, Color color, String message) { + if (message.length()>0) { + /*AttributedString as = new AttributedString(message); + as.addAttribute(TextAttribute.FONT, MyPanel.programFont);*/ + g.setColor(color); + g.drawString(message,(int)x,(int)y); + } + } + public static void drawTextFont(Graphics g, Font font, double x, double y, Color color, String message) { + if (message.length()>0) { + AttributedString as = new AttributedString(message); + as.addAttribute(TextAttribute.FONT, font); + g.setColor(color); + g.drawString(as.getIterator(),(int)x,(int)y); + } + } + public static void drawHealthbar(Graphics g, Rectangle bounds, double pct, Color healthbarcol) { + g.setColor(Color.BLACK); + g.draw3DRect((int)bounds.getX(), (int)bounds.getY(), (int)bounds.getWidth(), (int)bounds.getHeight(), true); + g.setColor(healthbarcol); + g.fill3DRect((int)bounds.getX()+1, (int)bounds.getY()+1, (int)(bounds.getWidth()*pct)-1, (int)bounds.getHeight()-1, true); + } + /** + * Centers the text along the X Axis. + */ + public static void drawCenteredText(Graphics g, Font font,JPanel panel, int x, int y, Color color, String text) { + AttributedString as = new AttributedString(text); + as.addAttribute(TextAttribute.FONT, font); + g.setColor(color); + Rectangle2D textBounds = TextUtils.calculateStringBoundsFont(panel,text, font); + g.drawString(as.getIterator(),(int)(x-textBounds.getWidth()/2),(int)(y+textBounds.getHeight())); + } + + public static Color convertStringToColor(String s) { + String[] split = s.split(","); + if (split.length==3) { + return new Color( + Math.min(Math.abs(Integer.parseInt(split[0])),255), + Math.min(Math.abs(Integer.parseInt(split[1])),255), + Math.min(Math.abs(Integer.parseInt(split[2])),255)); + } else + if (split.length==4) { + return new Color( + Math.min(Math.abs(Integer.parseInt(split[0])),255), + Math.min(Math.abs(Integer.parseInt(split[1])),255), + Math.min(Math.abs(Integer.parseInt(split[2])),255), + Math.min(Math.abs(Integer.parseInt(split[3])),255)); + } else { + System.out.println("WARNING! Invalid Color string specified ("+s+")."); + return null; + } + } + + public static void drawImage(Graphics g, Image img, double x, double y, Color blend_col, ImageObserver source) { + BufferedImage tmp = new BufferedImage(img.getWidth(source),img.getHeight(source),BufferedImage.TYPE_INT_ARGB); + Graphics2D g2 = tmp.createGraphics(); + g2.drawImage(img, 0, 0, null); + g2.setComposite(AlphaComposite.SrcAtop); + g2.setColor(blend_col); + g2.fillRect(0, 0, img.getWidth(source), img.getHeight(source)); + g2.dispose(); + g.drawImage(tmp,(int)x,(int)y,source); + } + + public static void drawImageScaled(Graphics g, Image img, double x, double y, double xsize, double ysize, Color blend_col, ImageObserver source) { + BufferedImage tmp = new BufferedImage(img.getWidth(source),img.getHeight(source),BufferedImage.TYPE_INT_ARGB); + Graphics2D g2 = tmp.createGraphics(); + g2.drawImage(img, 0, 0, null); + g2.setComposite(AlphaComposite.SrcAtop); + g2.setColor(blend_col); + g2.fillRect(0, 0, img.getWidth(source), img.getHeight(source)); + g2.dispose(); + g.drawImage(tmp,(int)x,(int)y,(int)xsize,(int)ysize,source); + } + + public static Color invertColor(Color c) { + return new Color(255-c.getRed(),255-c.getGreen(),255-c.getBlue(),255); + } +} diff --git a/Chart/src/sig/utils/FileUtils.java b/Chart/src/sig/utils/FileUtils.java new file mode 100644 index 0000000..9e420ee --- /dev/null +++ b/Chart/src/sig/utils/FileUtils.java @@ -0,0 +1,381 @@ +package sig.utils; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.Writer; +import java.net.ConnectException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.nio.channels.Channels; +import java.nio.channels.FileChannel; +import java.nio.channels.ReadableByteChannel; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +public class FileUtils { + public static String[] readFromFile(String filename) { + File file = new File(filename); + //System.out.println(file.getAbsolutePath()); + List contents= new ArrayList(); + if (file.exists()) { + try( + FileReader fw = new FileReader(filename); + BufferedReader bw = new BufferedReader(fw);) + { + String readline = bw.readLine(); + do { + if (readline!=null) { + //System.out.println(readline); + contents.add(readline); + readline = bw.readLine(); + }} while (readline!=null); + fw.close(); + bw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return contents.toArray(new String[contents.size()]); + } + + private static String readAll(Reader rd) throws IOException { + StringBuilder sb = new StringBuilder(); + int cp; + while ((cp = rd.read()) != -1) { + sb.append((char) cp); + } + return sb.toString(); + } + + private static String readFilter(Reader rd, HashMap channel_ids) throws IOException { + StringBuilder sb = new StringBuilder(); + boolean allowed=false; + boolean quotation_mark=false; + boolean endquotation_mark=false; + boolean foundChannel=false; + boolean nextBrace=false; + boolean outputStuff=false; + String numb = ""; + int braceCount=0; + int channelCount=0; + int vals=0; + int cp; + while ((cp = rd.read()) != -1) { + if (braceCount==0) { + allowed=true; + } else + if (braceCount==1 && !quotation_mark){ + quotation_mark=true; + numb=""; + allowed=false; + } else + if (!endquotation_mark) { + if ((char)cp >= '0' && + (char)cp <= '9') { + allowed=false; + numb+=(char)cp; + } else { + allowed=false; + endquotation_mark=true; + try { + if (channel_ids.containsKey(Long.parseLong(numb))) { + if (channelCount>=1) { + sb.append(","); + } + sb.append("\""+numb+"\""); + foundChannel=true; + System.out.println("Found channel "+numb); + outputStuff=true; + } + } catch (NumberFormatException e) { + + } + } + } else + if (!nextBrace && foundChannel) { + allowed=true; + if ((char)cp == '{') { + nextBrace=true; + } + } else + if (foundChannel) { + allowed=true; + if (braceCount==1) { + allowed=false; + channelCount++; + quotation_mark=false; + endquotation_mark=false; + foundChannel=false; + nextBrace=false; + } + } else { + allowed=false; + if (braceCount==1) { + allowed=false; + quotation_mark=false; + endquotation_mark=false; + foundChannel=false; + nextBrace=false; + } + } + + /*if (outputStuff && vals++<1000) { + System.out.print((char)cp); + }*/ + if ((char)cp == '{') { + braceCount++; + //System.out.println("Brace count is "+braceCount+"."); + } else + if ((char)cp == '}') { + braceCount--; + //System.out.println("Brace count is "+braceCount+"."); + } + + if (allowed) { + sb.append((char) cp); + } + } + sb.append("}"); + //System.out.println("============="); + //System.out.println(sb.toString()); + return sb.toString(); + } + + public static JSONObject readJsonFromUrlWithFilter(String url, HashMap filter) throws IOException, JSONException { + return readJsonFromUrlWithFilter(url,filter,null,false); + } + + public static JSONObject readJsonFromFileWithFilter(String file, HashMap filter) throws IOException, JSONException { + InputStream is = new FileInputStream(new File(file)); + try { + BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); + String jsonText = readFilter(rd,filter); + JSONObject json = new JSONObject(jsonText); + jsonText=null; + return json; + } finally { + is.close(); + } + } + + public static JSONObject readJsonFromUrlWithFilter(String url, HashMap filter, String file, boolean writeToFile) throws IOException, JSONException { + InputStream is = new URL(url).openStream(); + try { + BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); + String jsonText = readFilter(rd,filter); + if (writeToFile) { + writetoFile(new String[]{jsonText},file); + } + JSONObject json = new JSONObject(jsonText); + return json; + } finally { + is.close(); + } + } + + public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException { + return readJsonFromUrl(url,null,false); + } + + public static JSONArray readJsonArrayFromUrl(String url) throws IOException, JSONException { + return readJsonArrayFromUrl(url,null,false); + } + + public static JSONObject readJsonFromFile(String file) throws IOException, JSONException { + InputStream is = new FileInputStream(new File(file)); + try { + BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); + String jsonText = readAll(rd); + JSONObject json = new JSONObject(jsonText); + jsonText=null; + return json; + } finally { + is.close(); + } + } + + public static JSONObject readJsonFromUrl(String url, String file, boolean writeToFile) throws IOException, JSONException { + try { + InputStream is = new URL(url).openStream(); + BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); + String jsonText = readAll(rd); + if (writeToFile) { + writetoFile(new String[]{jsonText},file); + } + JSONObject json = new JSONObject(jsonText); + is.close(); + return json; + } catch (IOException e) { + return new JSONObject("{}"); + } + } + + public static JSONArray readJsonArrayFromUrl(String url, String file, boolean writeToFile) throws IOException, JSONException { + URL obj = new URL(url); + HttpURLConnection con = (HttpURLConnection) obj.openConnection(); + con.setRequestMethod("GET"); + int responseCode = con.getResponseCode(); + System.out.println("GET Response Code :: " + responseCode); + if (responseCode == HttpURLConnection.HTTP_OK) { // success + BufferedReader in = new BufferedReader(new InputStreamReader( + con.getInputStream())); + String inputLine; + StringBuffer response = new StringBuffer(); + + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + + // print result + System.out.println(response); + + return new JSONArray(response.toString()); + } else { + System.out.println("GET request not worked"); + return new JSONArray("[]"); + } + } + + public static void logToFile(String message, String filename) { + logToFile(message,filename,false); + } + + + public static void logToFile(String message, String filename, boolean outputToChatLog) { + File file = new File(filename); + try { + + if (!file.exists()) { + file.createNewFile(); + } + OutputStream out = new FileOutputStream(file,true); + Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8); + PrintWriter pw = new PrintWriter(writer); + + pw.println(message); + pw.flush(); + pw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void writetoFile(String[] data, String filename) { + File file = new File(filename); + try { + + if (!file.exists()) { + file.createNewFile(); + } + + FileWriter fw = new FileWriter(file,false); + PrintWriter pw = new PrintWriter(fw); + + for (String s : data) { + pw.println(s); + } + pw.flush(); + pw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static void copyFile(File source, File dest) throws IOException { + FileChannel sourceChannel = null; + FileChannel destChannel = null; + try { + sourceChannel = new FileInputStream(source).getChannel(); + destChannel = new FileOutputStream(dest).getChannel(); + destChannel.transferFrom(sourceChannel, 0, sourceChannel.size()); + }finally{ + sourceChannel.close(); + destChannel.close(); + } + } + + public static void copyFileDir(File sourcedir, File destdir) throws IOException { + FileChannel sourceChannel = null; + FileChannel destChannel = null; + destdir.mkdirs(); + try { + if (sourcedir.exists()) { + for (String name : sourcedir.list()) { + File f = new File(sourcedir,name); + sourceChannel = new FileInputStream(f).getChannel(); + destChannel = new FileOutputStream(new File(destdir,name)).getChannel(); + destChannel.transferFrom(sourceChannel, 0, sourceChannel.size()); + sourceChannel.close(); + destChannel.close(); + } + } + } + finally{ + + } + } + + public static void deleteFile(File filename) { + File file = filename; + if (file.exists()) { + //System.out.println("Trying to delete "+file); + if (file.isDirectory()) { + for (String name : file.list()) { + File f = new File(file,name); + deleteFile(f); + } + } + file.delete(); + //System.out.println(file+" deleted"); + } + } + + public static void deleteFile(String filename) { + File file = new File(filename); + deleteFile(file); + } + + + public static void downloadFileFromUrl(String url, String file) throws IOException, JSONException { + File filer = new File(file); + filer.createNewFile(); + + URL website = new URL(url); + HttpURLConnection connection = (HttpURLConnection) website.openConnection(); + /*for (String s : connection.getHeaderFields().keySet()) { + System.out.println(s+": "+connection.getHeaderFields().get(s)); + }*/ + connection.setRequestMethod("GET"); + //connection.setRequestProperty("Content-Type", "application/json"); + try { + ReadableByteChannel rbc = Channels.newChannel(connection.getInputStream()); + FileOutputStream fos = new FileOutputStream(file); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + } catch (ConnectException e) { + System.out.println("Failed to connect, moving on..."); + } + } +} diff --git a/Chart/src/sig/utils/GithubUtils.java b/Chart/src/sig/utils/GithubUtils.java new file mode 100644 index 0000000..7cd1579 --- /dev/null +++ b/Chart/src/sig/utils/GithubUtils.java @@ -0,0 +1,35 @@ +package sig.utils; + +import java.io.IOException; +import java.util.Arrays; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +public class GithubUtils { + public static int getSizeOfFileFromLatestGithubCommit(String filename) { + try { + JSONObject data = FileUtils.readJsonFromUrl("https://api.github.com/repos/sigonasr2/sigIRCv2"); + String url = data.getString("commits_url").replace("{/sha}", ""); + JSONArray data_array = FileUtils.readJsonArrayFromUrl(url); + JSONObject dat = data_array.getJSONObject(0); + JSONObject datapoint1 = dat.getJSONObject("commit"); + datapoint1 = datapoint1.getJSONObject("tree"); + url = datapoint1.getString("url"); + data = FileUtils.readJsonFromUrl(url); + data_array = data.getJSONArray("tree"); + for (int i=0;i=0) { + String piece1 = sourcestring.substring(0,pos); + String piece2 = sourcestring.substring(pos+findstring.length(),sourcestring.length()); + //basemsg = basemsg.replaceFirst(e.getEmoteName(),e.getSpaceFiller()); + sourcestring = piece1+replacestring+piece2; + } + return sourcestring; + } + + public static boolean isAlphanumeric(String str) { + return str.matches("^[a-zA-Z0-9!\\-.?'\":,\\+ ]+$"); + } + + public static boolean isNumeric(String str) + { + if (str.length()>0) { + return str.matches("-?\\d+(\\.\\d+)?"); //match a number with optional '-' and decimal. + } else { + return false; + } + } + + public static boolean isInteger(String s, int radix) { + if(s.isEmpty()) return false; + for(int i = 0; i < s.length(); i++) { + if(i == 0 && s.charAt(i) == '-') { + if(s.length() == 1) return false; + else continue; + } + if(Character.digit(s.charAt(i),radix) < 0) return false; + } + return true; + } + + public static String convertSecondsToTimeFormat(int seconds) { + StringBuilder sb = new StringBuilder(); + int sec = seconds%60; + int min = (seconds/60)%60; + int hrs = (seconds/3600)%24; + if (hrs>0) { + if (hrs>=10) { + sb.append(hrs); + } else { + sb.append(0); + sb.append(hrs); + } + sb.append(":"); + } + if (min>=10) { + sb.append(min); + } else { + sb.append(0); + sb.append(min); + } + sb.append(":"); + if (sec>=10) { + sb.append(sec); + } else { + sb.append(0); + sb.append(sec); + } + return sb.toString(); + } + + public static String getActualChannelName() { + return sigIRC.channel.replaceFirst("#", ""); + } + + /** + * Converts a three CSV value to RGB value. + */ + public static Color convertStringToColor(String col) { + String[] split = col.split(","); + return new Color(Integer.parseInt(split[0]),Integer.parseInt(split[1]),Integer.parseInt(split[2])); + } + + public static List WrapText(String msg, Font font, double width) { + List displayMessage = new ArrayList(); + String rawmessage = msg; + int textWidth = (int)TextUtils.calculateStringBoundsFont(rawmessage, font).getWidth(); + int maxWidth = (int)width; + do { + rawmessage = BreakTextAtNextSection(rawmessage+" ",font,displayMessage,maxWidth); + textWidth = (int)TextUtils.calculateStringBoundsFont(rawmessage, font).getWidth(); + } while (textWidth>maxWidth); + if (rawmessage.length()>0) { + displayMessage.add(rawmessage); + } + return displayMessage; + //System.out.println(displayMessage+": "+messageDisplaySize); + } + + private static String BreakTextAtNextSection(String msg, Font font, List list, int maxWidth) { + int marker = 1; + int textWidth = (int)TextUtils.calculateStringBoundsFont(msg.substring(0, marker), font).getWidth(); + while (textWidth0) { + string.append(days); + } + if (hours>0) { + string.append(((string.length()>0)?":":"")+(hours%24)); + } + if (minutes>0) { + string.append(((string.length()>0)?":":"")+df.format((minutes%60))); + } + if (seconds>0) { + string.append(((string.length()>0)?":":"")+df.format((seconds%60))); + } + return string.toString(); + } +} diff --git a/Chart/src/sig/utils/WebUtils.java b/Chart/src/sig/utils/WebUtils.java new file mode 100644 index 0000000..3d6695f --- /dev/null +++ b/Chart/src/sig/utils/WebUtils.java @@ -0,0 +1,69 @@ +package sig.utils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Scanner; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.HttpVersion; +import org.apache.http.NameValuePair; +import org.apache.http.client.HttpClient; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.mime.MultipartEntity; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.entity.mime.content.ContentBody; +import org.apache.http.entity.mime.content.FileBody; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.params.CoreProtocolPNames; +import org.apache.http.util.EntityUtils; + +public class WebUtils { + public static void POSTimage(String url,File file,Map params) { + CloseableHttpClient httpClient = HttpClients.createDefault(); + HttpPost uploadFile = new HttpPost(url); + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + for (String s : params.keySet()) { + builder.addTextBody(s, params.get(s), ContentType.TEXT_PLAIN); + } + try { + // This attaches the file to the POST: + builder.addBinaryBody( + "file", + new FileInputStream(file), + ContentType.APPLICATION_OCTET_STREAM, + file.getName() + ); + + HttpEntity multipart = builder.build(); + uploadFile.setEntity(multipart); + CloseableHttpResponse response; + response = httpClient.execute(uploadFile); + HttpEntity responseEntity = response.getEntity(); + String result = ""; + if (responseEntity != null) { + try (InputStream instream = responseEntity.getContent()) { + Scanner s = new Scanner(instream).useDelimiter("\\A"); + result = s.hasNext() ? s.next() : ""; + System.out.println(result); + instream.close(); + } catch (UnsupportedOperationException | IOException e) { + e.printStackTrace(); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } +}