--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<fileset-config file-format-version="1.2.0" simple-config="false">\r
+ <local-check-config name="u6k Checks" location="u6k-checkstyle-20080303.xml" type="project" description="">\r
+ <additional-data name="protect-config-file" value="false"/>\r
+ </local-check-config>\r
+ <fileset name="src" enabled="true" check-config-name="u6k Checks" local="true">\r
+ <file-match-pattern match-pattern="\.java$" include-pattern="true"/>\r
+ </fileset>\r
+</fileset-config>\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<classpath>\r
+ <classpathentry kind="src" path="src/main/java"/>\r
+ <classpathentry kind="src" path="src/main/resources"/>\r
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>\r
+ <classpathentry kind="output" path="bin"/>\r
+</classpath>\r
--- /dev/null
+#FindBugs User Preferences\r
+#Sat Mar 08 04:37:39 JST 2008\r
+detectorBadAppletConstructor=BadAppletConstructor|false\r
+detectorBadResultSetAccess=BadResultSetAccess|true\r
+detectorBadSyntaxForRegularExpression=BadSyntaxForRegularExpression|true\r
+detectorBadUseOfReturnValue=BadUseOfReturnValue|true\r
+detectorBadlyOverriddenAdapter=BadlyOverriddenAdapter|true\r
+detectorCheckImmutableAnnotation=CheckImmutableAnnotation|true\r
+detectorCloneIdiom=CloneIdiom|true\r
+detectorComparatorIdiom=ComparatorIdiom|true\r
+detectorConfusedInheritance=ConfusedInheritance|true\r
+detectorConfusionBetweenInheritedAndOuterMethod=ConfusionBetweenInheritedAndOuterMethod|true\r
+detectorDoInsideDoPrivileged=DoInsideDoPrivileged|true\r
+detectorDontCatchIllegalMonitorStateException=DontCatchIllegalMonitorStateException|true\r
+detectorDontUseEnum=DontUseEnum|true\r
+detectorDroppedException=DroppedException|true\r
+detectorDumbMethodInvocations=DumbMethodInvocations|true\r
+detectorDumbMethods=DumbMethods|true\r
+detectorDuplicateBranches=DuplicateBranches|true\r
+detectorEmptyZipFileEntry=EmptyZipFileEntry|true\r
+detectorFinalizerNullsFields=FinalizerNullsFields|true\r
+detectorFindBadCast2=FindBadCast2|true\r
+detectorFindBadForLoop=FindBadForLoop|true\r
+detectorFindCircularDependencies=FindCircularDependencies|false\r
+detectorFindDeadLocalStores=FindDeadLocalStores|true\r
+detectorFindDoubleCheck=FindDoubleCheck|true\r
+detectorFindEmptySynchronizedBlock=FindEmptySynchronizedBlock|true\r
+detectorFindFieldSelfAssignment=FindFieldSelfAssignment|true\r
+detectorFindFinalizeInvocations=FindFinalizeInvocations|true\r
+detectorFindFloatEquality=FindFloatEquality|true\r
+detectorFindHEmismatch=FindHEmismatch|true\r
+detectorFindInconsistentSync2=FindInconsistentSync2|true\r
+detectorFindJSR166LockMonitorenter=FindJSR166LockMonitorenter|true\r
+detectorFindLocalSelfAssignment2=FindLocalSelfAssignment2|true\r
+detectorFindMaskedFields=FindMaskedFields|true\r
+detectorFindMismatchedWaitOrNotify=FindMismatchedWaitOrNotify|true\r
+detectorFindNakedNotify=FindNakedNotify|true\r
+detectorFindNonSerializableStoreIntoSession=FindNonSerializableStoreIntoSession|true\r
+detectorFindNonSerializableValuePassedToWriteObject=FindNonSerializableValuePassedToWriteObject|true\r
+detectorFindNonShortCircuit=FindNonShortCircuit|true\r
+detectorFindNullDeref=FindNullDeref|true\r
+detectorFindOpenStream=FindOpenStream|true\r
+detectorFindPuzzlers=FindPuzzlers|true\r
+detectorFindRefComparison=FindRefComparison|true\r
+detectorFindReturnRef=FindReturnRef|true\r
+detectorFindRunInvocations=FindRunInvocations|true\r
+detectorFindSelfComparison=FindSelfComparison|true\r
+detectorFindSelfComparison2=FindSelfComparison2|true\r
+detectorFindSleepWithLockHeld=FindSleepWithLockHeld|true\r
+detectorFindSpinLoop=FindSpinLoop|true\r
+detectorFindSqlInjection=FindSqlInjection|true\r
+detectorFindTwoLockWait=FindTwoLockWait|true\r
+detectorFindUncalledPrivateMethods=FindUncalledPrivateMethods|true\r
+detectorFindUnconditionalWait=FindUnconditionalWait|true\r
+detectorFindUninitializedGet=FindUninitializedGet|true\r
+detectorFindUnrelatedTypesInGenericContainer=FindUnrelatedTypesInGenericContainer|true\r
+detectorFindUnreleasedLock=FindUnreleasedLock|true\r
+detectorFindUnsyncGet=FindUnsyncGet|true\r
+detectorFindUselessControlFlow=FindUselessControlFlow|true\r
+detectorHugeSharedStringConstants=HugeSharedStringConstants|true\r
+detectorIDivResultCastToDouble=IDivResultCastToDouble|true\r
+detectorIncompatMask=IncompatMask|true\r
+detectorInefficientMemberAccess=InefficientMemberAccess|false\r
+detectorInefficientToArray=InefficientToArray|true\r
+detectorInfiniteLoop=InfiniteLoop|true\r
+detectorInfiniteRecursiveLoop=InfiniteRecursiveLoop|true\r
+detectorInfiniteRecursiveLoop2=InfiniteRecursiveLoop2|false\r
+detectorInheritanceUnsafeGetResource=InheritanceUnsafeGetResource|true\r
+detectorInitializationChain=InitializationChain|true\r
+detectorInstantiateStaticClass=InstantiateStaticClass|true\r
+detectorInvalidJUnitTest=InvalidJUnitTest|true\r
+detectorIteratorIdioms=IteratorIdioms|true\r
+detectorLazyInit=LazyInit|true\r
+detectorLoadOfKnownNullValue=LoadOfKnownNullValue|true\r
+detectorMethodReturnCheck=MethodReturnCheck|true\r
+detectorMultithreadedInstanceAccess=MultithreadedInstanceAccess|true\r
+detectorMutableLock=MutableLock|true\r
+detectorMutableStaticFields=MutableStaticFields|true\r
+detectorNaming=Naming|true\r
+detectorNumberConstructor=NumberConstructor|true\r
+detectorPreferZeroLengthArrays=PreferZeroLengthArrays|true\r
+detectorPublicSemaphores=PublicSemaphores|false\r
+detectorQuestionableBooleanAssignment=QuestionableBooleanAssignment|true\r
+detectorReadReturnShouldBeChecked=ReadReturnShouldBeChecked|true\r
+detectorRedundantInterfaces=RedundantInterfaces|true\r
+detectorRuntimeExceptionCapture=RuntimeExceptionCapture|true\r
+detectorSerializableIdiom=SerializableIdiom|true\r
+detectorStartInConstructor=StartInConstructor|true\r
+detectorStaticCalendarDetector=StaticCalendarDetector|true\r
+detectorStringConcatenation=StringConcatenation|true\r
+detectorSuperfluousInstanceOf=SuperfluousInstanceOf|true\r
+detectorSuspiciousThreadInterrupted=SuspiciousThreadInterrupted|true\r
+detectorSwitchFallthrough=SwitchFallthrough|true\r
+detectorSynchronizeAndNullCheckField=SynchronizeAndNullCheckField|true\r
+detectorTestASM=TestASM|false\r
+detectorURLProblems=URLProblems|true\r
+detectorUncallableMethodOfAnonymousClass=UncallableMethodOfAnonymousClass|true\r
+detectorUnnecessaryMath=UnnecessaryMath|true\r
+detectorUnreadFields=UnreadFields|true\r
+detectorUseObjectEquals=UseObjectEquals|false\r
+detectorUselessSubclassMethod=UselessSubclassMethod|false\r
+detectorVarArgsProblems=VarArgsProblems|true\r
+detectorVolatileUsage=VolatileUsage|true\r
+detectorWaitInLoop=WaitInLoop|true\r
+detectorWrongMapIterator=WrongMapIterator|true\r
+detectorXMLFactoryBypass=XMLFactoryBypass|true\r
+detector_threshold=3\r
+filter_settings=Low|PERFORMANCE,CORRECTNESS,I18N,MT_CORRECTNESS,BAD_PRACTICE,MALICIOUS_CODE,STYLE|false\r
+filter_settings_neg=|\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<projectDescription>\r
+ <name>online-stg-env</name>\r
+ <comment></comment>\r
+ <projects>\r
+ </projects>\r
+ <buildSpec>\r
+ <buildCommand>\r
+ <name>org.eclipse.jdt.core.javabuilder</name>\r
+ <arguments>\r
+ </arguments>\r
+ </buildCommand>\r
+ <buildCommand>\r
+ <name>com.atlassw.tools.eclipse.checkstyle.CheckstyleBuilder</name>\r
+ <arguments>\r
+ </arguments>\r
+ </buildCommand>\r
+ <buildCommand>\r
+ <name>edu.umd.cs.findbugs.plugin.eclipse.findbugsBuilder</name>\r
+ <arguments>\r
+ </arguments>\r
+ </buildCommand>\r
+ </buildSpec>\r
+ <natures>\r
+ <nature>org.eclipse.jdt.core.javanature</nature>\r
+ <nature>com.atlassw.tools.eclipse.checkstyle.CheckstyleNature</nature>\r
+ <nature>edu.umd.cs.findbugs.plugin.eclipse.findbugsNature</nature>\r
+ </natures>\r
+</projectDescription>\r
--- /dev/null
+/*
+ * Copyright (C) 2008 u6k.yu1@gmail.com, All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of Clarkware Consulting, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact clarkware@clarkware.com.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * CLARKWARE CONSULTING OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\r
+ <modelVersion>4.0.0</modelVersion>\r
+ <groupId>jp.gr.java_conf.u6k.online_stg_env</groupId>\r
+ <artifactId>online-stg-env</artifactId>\r
+ <packaging>jar</packaging>\r
+ <version>1.0.0-SNAPSHOT</version>\r
+ <name>Online STG Environment</name>\r
+ <description>「Online STG Environment」は、インターネット上でSTGを作成するための開発環境です。開発環境はJava Web Startで動作し、データはWebサーバに保存されます。Webサーバにアクセスできないときは、ローカルで開発し、Webサーバにアクセスできるときに同期することができます。ゲームはJava Web Startで動作しますが、Webサーバに接続しなくてもゲームをプレイできるように、スタンドアロン・アプリケーションとしてパッケージングすることもできます。</description>\r
+ <inceptionYear>2008</inceptionYear>\r
+ <developers>\r
+ <developer>\r
+ <id>u6k</id>\r
+ <name>u6k</name>\r
+ <email>u6k.yu1@gmail.com</email>\r
+ <url>http://d.hatena.ne.jp/u6k/</url>\r
+ </developer>\r
+ </developers>\r
+ <licenses>\r
+ <license>\r
+ <name>The BSD License</name>\r
+ <url>http://svn.sourceforge.jp/svnroot/filelock/trunk/filelock/LICENSE.txt</url>\r
+ <distribution>manual</distribution>\r
+ </license>\r
+ </licenses>\r
+ <build>\r
+ <plugins>\r
+ <plugin>\r
+ <artifactId>maven-compiler-plugin</artifactId>\r
+ <configuration>\r
+ <encoding>UTF-8</encoding>\r
+ <source>1.5</source>\r
+ <target>1.5</target>\r
+ </configuration>\r
+ </plugin>\r
+ <plugin>\r
+ <groupId>org.apache.maven.plugins</groupId>\r
+ <artifactId>maven-antrun-plugin</artifactId>\r
+ <executions>\r
+ <execution>\r
+ <id>replace-process-resources</id>\r
+ <phase>process-resources</phase>\r
+ <goals>\r
+ <goal>run</goal>\r
+ </goals>\r
+ <configuration>\r
+ <tasks>\r
+ <replace dir="${basedir}" value="${project.version}" token="@project.version@" encoding="UTF-8">\r
+ <include name="target/classes/**/*.properties" />\r
+ </replace>\r
+ </tasks>\r
+ </configuration>\r
+ </execution>\r
+ </executions>\r
+ </plugin>\r
+ </plugins>\r
+ </build>\r
+ <reporting>\r
+ <plugins>\r
+ <plugin>\r
+ <groupId>org.apache.maven.plugins</groupId>\r
+ <artifactId>maven-checkstyle-plugin</artifactId>\r
+ <configuration>\r
+ <configLocation>u6k-checkstyle-20080303.xml</configLocation>\r
+ <headerLocation>LICENSE.txt</headerLocation>\r
+ <propertyExpansion>basedir=.</propertyExpansion>\r
+ </configuration>\r
+ </plugin>\r
+ <plugin>\r
+ <groupId>org.apache.maven.plugins</groupId>\r
+ <artifactId>maven-pmd-plugin</artifactId>\r
+ <configuration>\r
+ <linkXref>true</linkXref>\r
+ <sourceEncoding>UTF-8</sourceEncoding>\r
+ <targetJdk>1.5</targetJdk>\r
+ </configuration>\r
+ </plugin>\r
+ <plugin>\r
+ <groupId>org.codehaus.mojo</groupId>\r
+ <artifactId>findbugs-maven-plugin</artifactId>\r
+ </plugin>\r
+ </plugins>\r
+ </reporting>\r
+</project>\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env;\r
+\r
+import java.awt.BorderLayout;\r
+import java.awt.Dimension;\r
+\r
+import javax.swing.JDialog;\r
+import javax.swing.JFrame;\r
+import javax.swing.JScrollPane;\r
+import javax.swing.JTable;\r
+import javax.swing.WindowConstants;\r
+import javax.swing.table.DefaultTableModel;\r
+\r
+import jp.gr.java_conf.u6k.online_stg_env.data.DataCommand;\r
+import jp.gr.java_conf.u6k.online_stg_env.data.DataCommandAddEvent;\r
+import jp.gr.java_conf.u6k.online_stg_env.data.DataCommandContainerListener;\r
+import jp.gr.java_conf.u6k.online_stg_env.data.DataCommandPurgeEvent;\r
+import jp.gr.java_conf.u6k.online_stg_env.data.DataContainer;\r
+\r
+public class DataCommandDialog extends JDialog {\r
+\r
+ private JTable commandTable;\r
+\r
+ public DataCommandDialog(JFrame owner, DataContainer dataContainer) {\r
+ super(owner, false);\r
+\r
+ if (dataContainer == null) {\r
+ throw new NullPointerException("dataContainer == null");\r
+ }\r
+\r
+ this.commandTable = new JTable(new DefaultTableModel(new Object[] { "ID", "コマンド詳細" }, 0));\r
+ this.commandTable.setDefaultEditor(Object.class, null);\r
+ JScrollPane commandTableScroll = new JScrollPane(this.commandTable);\r
+ this.getContentPane().add(commandTableScroll, BorderLayout.CENTER);\r
+\r
+ this.setTitle("コマンド履歴 - DrawEditor");\r
+ this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);\r
+ this.setPreferredSize(new Dimension(400, 300));\r
+ this.setLocationRelativeTo(null);\r
+\r
+ this.pack();\r
+\r
+ for (DataCommand c : dataContainer.getDataCommandContainer().getCommandList()) {\r
+ this.addDataCommand(c);\r
+ }\r
+\r
+ dataContainer.getDataCommandContainer().addListener(new DataCommandContainerListenerImpl());\r
+ }\r
+\r
+ private void addDataCommand(DataCommand c) {\r
+ int index = this.commandTable.getRowCount();\r
+\r
+ DefaultTableModel tableModel = (DefaultTableModel) this.commandTable.getModel();\r
+ tableModel.addRow(new Object[] { index, c.getDescription() });\r
+ }\r
+\r
+ private class DataCommandContainerListenerImpl implements DataCommandContainerListener {\r
+\r
+ public void commandAdd(DataCommandAddEvent event) {\r
+ DataCommandDialog.this.addDataCommand(event.getCommand());\r
+ }\r
+\r
+ public void commandPurge(DataCommandPurgeEvent event) {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env;\r
+\r
+import java.awt.Dimension;\r
+import java.awt.Graphics;\r
+import java.awt.image.BufferedImage;\r
+\r
+import javax.swing.JPanel;\r
+\r
+import jp.gr.java_conf.u6k.online_stg_env.data.CurrentShapeChangeEvent;\r
+import jp.gr.java_conf.u6k.online_stg_env.data.DataContainer;\r
+import jp.gr.java_conf.u6k.online_stg_env.data.DataContainerListener;\r
+import jp.gr.java_conf.u6k.online_stg_env.data.ShapeAddEvent;\r
+import jp.gr.java_conf.u6k.online_stg_env.data.ShapeContainerListener;\r
+import jp.gr.java_conf.u6k.online_stg_env.data.ShapeRemoveEvent;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.BackgroundShape;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.BaseShape;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.ShapePropertyChangeEvent;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.ShapePropertyChangeListener;\r
+\r
+@SuppressWarnings("serial")\r
+public class DrawCanvas extends JPanel {\r
+\r
+ private DataContainer dc;\r
+\r
+ private BufferedImage buffer;\r
+\r
+ public DrawCanvas(int width, int height, DataContainer dc) {\r
+ if (dc == null) {\r
+ throw new NullPointerException("dc == null");\r
+ }\r
+ if (width <= 0) {\r
+ throw new IllegalArgumentException("width <= 0");\r
+ }\r
+ if (height <= 0) {\r
+ throw new IllegalArgumentException("height <= 0");\r
+ }\r
+\r
+ this.buffer = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);\r
+\r
+ this.setPreferredSize(new Dimension(width, height));\r
+\r
+ this.dc = dc;\r
+ this.dc.addListener(new DataContainerListenerImpl());\r
+ this.dc.getShapeContainer().addListener(new ShapeContainerListenerImpl());\r
+\r
+ BackgroundShape bgShape = new BackgroundShape();\r
+ bgShape.setWidth(width);\r
+ bgShape.setHeight(height);\r
+ this.dc.getShapeContainer().addShape(bgShape);\r
+ }\r
+\r
+ @Override\r
+ public void paint(Graphics g) {\r
+ super.paint(g);\r
+\r
+ g.drawImage(this.buffer, 0, 0, null);\r
+ }\r
+\r
+ private class DataContainerListenerImpl implements DataContainerListener {\r
+\r
+ private ShapePropertyChangeListener shapePropertyChangeListener = new ShapePropertyChangeListenerImpl();\r
+\r
+ public void currentShapeChange(CurrentShapeChangeEvent event) {\r
+ Graphics g = DrawCanvas.this.getGraphics();\r
+ try {\r
+ g.drawImage(DrawCanvas.this.buffer, 0, 0, null);\r
+ } finally {\r
+ g.dispose();\r
+ }\r
+\r
+ if (event.getOldShape() != null) {\r
+ event.getOldShape().createEnd(DrawCanvas.this);\r
+ event.getOldShape().removeShapePropertyChangeListener(this.shapePropertyChangeListener);\r
+ }\r
+\r
+ if (event.getNewShape() != null) {\r
+ event.getNewShape().createStart(DrawCanvas.this);\r
+ event.getNewShape().addShapePropertyChangeListener(this.shapePropertyChangeListener);\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+ private class ShapeContainerListenerImpl implements ShapeContainerListener {\r
+\r
+ public void addShape(ShapeAddEvent event) {\r
+ Graphics g = buffer.getGraphics();\r
+ try {\r
+ event.getShape().draw(g);\r
+ } finally {\r
+ g.dispose();\r
+ }\r
+\r
+ g = DrawCanvas.this.getGraphics();\r
+ if (g != null) {\r
+ try {\r
+ g.drawImage(buffer, 0, 0, null);\r
+ } finally {\r
+ g.dispose();\r
+ }\r
+ }\r
+ }\r
+\r
+ public void removeShape(ShapeRemoveEvent event) {\r
+ Graphics g = buffer.getGraphics();\r
+ try {\r
+ for (BaseShape shape : dc.getShapeContainer().getShapeList()) {\r
+ shape.draw(g);\r
+ }\r
+ } finally {\r
+ g.dispose();\r
+ }\r
+\r
+ g = DrawCanvas.this.getGraphics();\r
+ if (g != null) {\r
+ try {\r
+ g.drawImage(buffer, 0, 0, null);\r
+ } finally {\r
+ g.dispose();\r
+ }\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+ private class ShapePropertyChangeListenerImpl implements ShapePropertyChangeListener {\r
+\r
+ public void propertyChange(ShapePropertyChangeEvent event) {\r
+ BaseShape shape = event.getSource();\r
+\r
+ if ("completed".equals(event.getPropertyName())) {\r
+ dc.getShapeContainer().addShape(shape);\r
+ } else {\r
+ Graphics g = DrawCanvas.this.getGraphics();\r
+ try {\r
+ g.drawImage(DrawCanvas.this.buffer, 0, 0, null);\r
+ shape.draw(g);\r
+ } finally {\r
+ g.dispose();\r
+ }\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env;\r
+\r
+import java.awt.BorderLayout;\r
+import java.awt.Container;\r
+\r
+import javax.swing.JFrame;\r
+import javax.swing.WindowConstants;\r
+\r
+import jp.gr.java_conf.u6k.online_stg_env.data.DataContainer;\r
+\r
+public class DrawEditor extends JFrame {\r
+\r
+ private DrawCanvas canvas;\r
+\r
+ public DrawEditor(DataContainer dc) {\r
+ this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);\r
+ this.setLocationRelativeTo(null);\r
+ this.setResizable(false);\r
+\r
+ Container c = this.getContentPane();\r
+ c.setLayout(new BorderLayout());\r
+\r
+ this.canvas = new DrawCanvas(640, 480, dc);\r
+ c.add(this.canvas, BorderLayout.CENTER);\r
+\r
+ this.pack();\r
+ }\r
+\r
+ public static void main(String[] args) throws Exception {\r
+ DataContainer dc = new DataContainer();\r
+\r
+ DrawEditor drawEditor = new DrawEditor(dc);\r
+ drawEditor.setVisible(true);\r
+\r
+ DataCommandDialog dataCommandDialog = new DataCommandDialog(drawEditor, dc);\r
+ dataCommandDialog.setVisible(true);\r
+\r
+ ShapeChooserDialog shapeChooserDialog = new ShapeChooserDialog(drawEditor, dc);\r
+ shapeChooserDialog.setVisible(true);\r
+\r
+ ShapePropertyDialog shapePropertyDialog = new ShapePropertyDialog(drawEditor, dc);\r
+ shapePropertyDialog.setVisible(true);\r
+\r
+ ShapeListDialog shapeListDialog = new ShapeListDialog(drawEditor, dc);\r
+ shapeListDialog.setVisible(true);\r
+\r
+ // None 8.7M\r
+ // BufferedImage image = new BufferedImage(640, 480, BufferedImage.TYPE_INT_RGB); // 10.3M\r
+ // BufferedImage image = new BufferedImage(800, 600, BufferedImage.TYPE_INT_RGB); // 12.6M\r
+ // BufferedImage image = new BufferedImage(1600, 1200, BufferedImage.TYPE_INT_RGB); // 18.2M\r
+ // BufferedImage image = new BufferedImage(10000, 10000, BufferedImage.TYPE_INT_RGB); // 403.9M\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2008 u6k.yu1@gmail.com, All Rights Reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ *\r
+ * 3. Neither the name of Clarkware Consulting, Inc. nor the names of its\r
+ * contributors may be used to endorse or promote products derived\r
+ * from this software without prior written permission. For written\r
+ * permission, please contact clarkware@clarkware.com.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\r
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\r
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL\r
+ * CLARKWARE CONSULTING OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+package jp.gr.java_conf.u6k.online_stg_env;\r
+\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.security.MessageDigest;\r
+import java.security.NoSuchAlgorithmException;\r
+\r
+/**\r
+ * <p>\r
+ * ハッシュ値を算出します。\r
+ * </p>\r
+ * \r
+ * @version $Id$\r
+ */\r
+public final class HashUtil {\r
+\r
+ /**\r
+ * <p>\r
+ * バッファの長さ。\r
+ * </p>\r
+ */\r
+ private static final int BUFFER_LENGTH = 1024;\r
+\r
+ /**\r
+ * <p>\r
+ * マスク値。\r
+ * </p>\r
+ */\r
+ private static final int MASK = 0xff;\r
+\r
+ /**\r
+ * <p>\r
+ * ハッシュ値を算出するクラス。\r
+ * </p>\r
+ */\r
+ private MessageDigest md;\r
+\r
+ /**\r
+ * <p>\r
+ * 新しいインスタンスを初期化します。\r
+ * </p>\r
+ * \r
+ * @param algorithm\r
+ * ハッシュ値算出アルゴリズム。\r
+ * @throws NoSuchAlgorithmException\r
+ * アルゴリズムをサポートしていない場合。\r
+ */\r
+ public HashUtil(String algorithm) throws NoSuchAlgorithmException {\r
+ this.md = MessageDigest.getInstance(algorithm);\r
+ }\r
+\r
+ /**\r
+ * <p>\r
+ * ストリームからデータを取得してハッシュ値を算出します。\r
+ * </p>\r
+ * \r
+ * @param in\r
+ * ハッシュ値を算出するデータのストリーム。\r
+ * @return データのハッシュ値。\r
+ * @throws NullPointerException\r
+ * in引数がnullの場合。\r
+ * @throws IOException\r
+ * データの取得に失敗した場合。\r
+ */\r
+ public String digest(InputStream in) throws IOException {\r
+ if (in == null) {\r
+ throw new NullPointerException("in == null");\r
+ }\r
+\r
+ byte[] buf = new byte[HashUtil.BUFFER_LENGTH];\r
+ int len;\r
+ while ((len = in.read(buf)) != -1) {\r
+ this.md.update(buf, 0, len);\r
+ }\r
+\r
+ byte[] hashData = this.md.digest();\r
+ String hash = this.toHexString(hashData);\r
+ return hash;\r
+ }\r
+\r
+ private String toHexString(byte[] data) {\r
+ StringBuilder hex = new StringBuilder();\r
+\r
+ for (int i = 0; i < data.length; i++) {\r
+ String b = Integer.toHexString(data[i] & HashUtil.MASK);\r
+ if (b.length() == 1) {\r
+ hex.append("0");\r
+ }\r
+ hex.append(b);\r
+ }\r
+\r
+ return hex.toString();\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env;\r
+\r
+import java.io.ByteArrayInputStream;\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.OutputStream;\r
+import java.io.UnsupportedEncodingException;\r
+import java.net.HttpURLConnection;\r
+import java.net.MalformedURLException;\r
+import java.net.URL;\r
+import java.net.URLDecoder;\r
+import java.net.URLEncoder;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+import java.util.ResourceBundle;\r
+\r
+import javax.xml.parsers.DocumentBuilderFactory;\r
+import javax.xml.parsers.ParserConfigurationException;\r
+\r
+import org.w3c.dom.DOMException;\r
+import org.w3c.dom.Document;\r
+import org.w3c.dom.Node;\r
+import org.xml.sax.SAXException;\r
+\r
+public class HttpUtil {\r
+\r
+ private static final String URL;\r
+\r
+ private static String cookie;\r
+\r
+ static {\r
+ ResourceBundle rb = ResourceBundle.getBundle("online-stg-env");\r
+ URL = rb.getString("url");\r
+ }\r
+\r
+ public static Object post(Map<String, Object> postData) throws MalformedURLException, IOException, SAXException, ParserConfigurationException {\r
+ // 引数を確認します。\r
+ if (postData == null) {\r
+ throw new NullPointerException("data == null");\r
+ }\r
+\r
+ // POST文字列を構築します。\r
+ StringBuilder postDataString = new StringBuilder();\r
+ for (Map.Entry<String, Object> entry : postData.entrySet()) {\r
+ if (postDataString.length() > 0) {\r
+ postDataString.append("&");\r
+ }\r
+ postDataString.append(URLEncoder.encode(entry.getKey(), "UTF-8"));\r
+ postDataString.append("=");\r
+ postDataString.append(URLEncoder.encode(entry.getValue().toString(), "UTF-8"));\r
+ }\r
+\r
+ // URLへ接続します。\r
+ HttpURLConnection conn = (HttpURLConnection) new URL(URL).openConnection();\r
+ try {\r
+ conn.setRequestMethod("POST");\r
+ conn.setDoOutput(true);\r
+ conn.setDoInput(true);\r
+\r
+ // 送信します。\r
+ if (cookie != null) {\r
+ conn.setRequestProperty("Cookie", cookie);\r
+ }\r
+\r
+ OutputStream out = conn.getOutputStream();\r
+ try {\r
+ out.write(postDataString.toString().getBytes());\r
+ } finally {\r
+ out.close();\r
+ }\r
+\r
+ // 受信します。\r
+ if (conn.getHeaderField("Set-Cookie") != null && !"".equals(conn.getHeaderField("Set-Cookie"))) {\r
+ cookie = conn.getHeaderField("Set-Cookie");\r
+ }\r
+\r
+ String returnString;\r
+ InputStream in = conn.getInputStream();\r
+ try {\r
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();\r
+ int c;\r
+ while ((c = in.read()) != -1) {\r
+ bout.write(c);\r
+ }\r
+ returnString = bout.toString();\r
+ } finally {\r
+ in.close();\r
+ }\r
+ return buildReturnMap(returnString);\r
+ } finally {\r
+ conn.disconnect();\r
+ }\r
+ }\r
+\r
+ public static Object buildReturnMap(String returnString) throws SAXException, IOException, ParserConfigurationException {\r
+ int returnPos = returnString.indexOf("<return type=\"");\r
+ int errorPos = returnString.indexOf("<error type=\"");\r
+\r
+ if (returnPos >= 0 && errorPos == -1) {\r
+ String returnXml = returnString.substring(returnPos, returnString.lastIndexOf("</return>") + "</return>".length());\r
+ return buildReturnMap0(returnXml);\r
+ } else if (returnPos == -1 && errorPos >= 0) {\r
+ String errorXml = returnString.substring(errorPos, returnString.lastIndexOf("</error>") + "</error>".length());\r
+ buildErrorMap0(errorXml);\r
+ return null;\r
+ } else if (returnPos >= 0 && errorPos >= 0) {\r
+ if (returnPos < errorPos) {\r
+ String returnXml = returnString.substring(returnPos, returnString.lastIndexOf("</return>") + "</return>".length());\r
+ return buildReturnMap0(returnXml);\r
+ } else {\r
+ String errorXml = returnString.substring(errorPos, returnString.lastIndexOf("</error>") + "</error>".length());\r
+ buildErrorMap0(errorXml);\r
+ return null;\r
+ }\r
+ } else {\r
+ throw new RuntimeException();\r
+ }\r
+ }\r
+\r
+ private static Object buildReturnMap0(String returnXml) throws SAXException, IOException, ParserConfigurationException {\r
+ ByteArrayInputStream bin = new ByteArrayInputStream(returnXml.getBytes());\r
+ try {\r
+ Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bin);\r
+ return buildMap(doc).get("return");\r
+ } finally {\r
+ bin.close();\r
+ }\r
+ }\r
+\r
+ @SuppressWarnings("unchecked")\r
+ private static void buildErrorMap0(String errorXml) throws SAXException, IOException, ParserConfigurationException {\r
+ ByteArrayInputStream bin = new ByteArrayInputStream(errorXml.getBytes());\r
+ try {\r
+ Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bin);\r
+ Map<String, Object> m = (Map<String, Object>) buildMap(doc).get("error");\r
+ throw new HttpException((String) m.get("type"), (String) m.get("message"), m.get("data"));\r
+ } finally {\r
+ bin.close();\r
+ }\r
+ }\r
+\r
+ private static Map<String, Object> buildMap(Node node) throws UnsupportedEncodingException, DOMException {\r
+ Map<String, Object> m = new HashMap<String, Object>();\r
+\r
+ for (int i = 0; i < node.getChildNodes().getLength(); i++) {\r
+ if (node.getChildNodes().item(i).getNodeType() == Node.ELEMENT_NODE) {\r
+ Node childElement = node.getChildNodes().item(i);\r
+ if ("string".equals(childElement.getAttributes().getNamedItem("type").getNodeValue())) {\r
+ m.put(childElement.getNodeName(), URLDecoder.decode(childElement.getTextContent(), "UTF-8"));\r
+ } else if ("integer".equals(childElement.getAttributes().getNamedItem("type").getNodeValue())) {\r
+ m.put(childElement.getNodeName(), Integer.parseInt(URLDecoder.decode(childElement.getTextContent(), "UTF-8")));\r
+ } else if ("float".equals(childElement.getAttributes().getNamedItem("type").getNodeValue())) {\r
+ m.put(childElement.getNodeName(), Double.parseDouble(URLDecoder.decode(childElement.getTextContent(), "UTF-8")));\r
+ } else if ("boolean".equals(childElement.getAttributes().getNamedItem("type").getNodeValue())) {\r
+ m.put(childElement.getNodeName(), Boolean.parseBoolean(URLDecoder.decode(childElement.getTextContent(), "UTF-8")));\r
+ } else if ("other".equals(childElement.getAttributes().getNamedItem("type").getNodeValue())) {\r
+ m.put(childElement.getNodeName(), URLDecoder.decode(childElement.getTextContent(), "UTF-8"));\r
+ } else if ("map".equals(childElement.getAttributes().getNamedItem("type").getNodeValue())) {\r
+ m.put(childElement.getNodeName(), buildMap(childElement));\r
+ } else {\r
+ throw new RuntimeException();\r
+ }\r
+ }\r
+ }\r
+\r
+ return m;\r
+ }\r
+\r
+ @SuppressWarnings("serial")\r
+ public static final class HttpException extends RuntimeException {\r
+\r
+ private String type;\r
+\r
+ private Object data;\r
+\r
+ public HttpException(String type, String message, Object data) {\r
+ super(message);\r
+\r
+ this.type = type;\r
+ this.data = data;\r
+ }\r
+\r
+ public String getType() {\r
+ return this.type;\r
+ }\r
+\r
+ public Object getData() {\r
+ return this.data;\r
+ }\r
+\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env;\r
+\r
+import java.awt.Dimension;\r
+\r
+public final class ImmutableDimension {\r
+\r
+ private int width;\r
+\r
+ private int height;\r
+\r
+ public ImmutableDimension(int width, int height) {\r
+ this.width = width;\r
+ this.height = height;\r
+ }\r
+\r
+ public ImmutableDimension(Dimension dimension) {\r
+ if (dimension == null) {\r
+ throw new NullPointerException("dimension == null");\r
+ }\r
+\r
+ this.width = dimension.width;\r
+ this.height = dimension.height;\r
+ }\r
+\r
+ public int getWidth() {\r
+ return this.width;\r
+ }\r
+\r
+ public int getHeight() {\r
+ return this.height;\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env;\r
+\r
+import java.awt.Point;\r
+\r
+public final class ImmutablePoint {\r
+\r
+ private int x;\r
+\r
+ private int y;\r
+\r
+ public ImmutablePoint(int x, int y) {\r
+ this.x = x;\r
+ this.y = y;\r
+ }\r
+\r
+ public ImmutablePoint(Point point) {\r
+ if (point == null) {\r
+ throw new NullPointerException("point == null");\r
+ }\r
+\r
+ this.x = point.x;\r
+ this.y = point.y;\r
+ }\r
+\r
+ public int getX() {\r
+ return this.x;\r
+ }\r
+\r
+ public int getY() {\r
+ return this.y;\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env;\r
+\r
+import java.awt.Rectangle;\r
+\r
+public final class ImmutableRectangle {\r
+\r
+ private int x;\r
+\r
+ private int y;\r
+\r
+ private int width;\r
+\r
+ private int height;\r
+\r
+ public ImmutableRectangle(int x, int y, int width, int height) {\r
+ this.x = x;\r
+ this.y = y;\r
+ this.width = width;\r
+ this.height = height;\r
+ }\r
+\r
+ public ImmutableRectangle(Rectangle rectangle) {\r
+ if (rectangle == null) {\r
+ throw new NullPointerException("rectangle == null");\r
+ }\r
+\r
+ this.x = rectangle.x;\r
+ this.y = rectangle.y;\r
+ this.width = rectangle.width;\r
+ this.height = rectangle.height;\r
+ }\r
+\r
+ public int getX() {\r
+ return this.x;\r
+ }\r
+\r
+ public int getY() {\r
+ return this.y;\r
+ }\r
+\r
+ public int getWidth() {\r
+ return this.width;\r
+ }\r
+\r
+ public int getHeight() {\r
+ return this.height;\r
+ }\r
+\r
+ public static ImmutableRectangle normalize(ImmutablePoint p1, ImmutablePoint p2) {\r
+ if (p1 == null) {\r
+ throw new NullPointerException("p1 == null");\r
+ }\r
+ if (p2 == null) {\r
+ throw new NullPointerException("p2 == null");\r
+ }\r
+\r
+ int x;\r
+ int y;\r
+ int width;\r
+ int height;\r
+\r
+ if (p1.getX() < p2.getX()) {\r
+ x = p1.getX();\r
+ width = p2.getX() - p1.getX();\r
+ } else {\r
+ x = p2.getX();\r
+ width = p1.getX() - p2.getX();\r
+ }\r
+ if (p1.getY() < p2.getY()) {\r
+ y = p1.getY();\r
+ height = p2.getY() - p1.getY();\r
+ } else {\r
+ y = p2.getY();\r
+ height = p1.getY() - p2.getY();\r
+ }\r
+\r
+ return new ImmutableRectangle(x, y, width, height);\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env;\r
+\r
+import java.awt.Container;\r
+import java.awt.Frame;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ActionListener;\r
+import java.io.ByteArrayInputStream;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import javax.swing.JButton;\r
+import javax.swing.JDialog;\r
+import javax.swing.JLabel;\r
+import javax.swing.JTextField;\r
+import javax.swing.SpringLayout;\r
+import javax.swing.WindowConstants;\r
+\r
+@SuppressWarnings("serial")\r
+public class LoginDialog extends JDialog {\r
+\r
+ private JTextField username;\r
+\r
+ private JTextField password;\r
+\r
+ private boolean auth;\r
+\r
+ public LoginDialog() {\r
+ super((Frame) null, true);\r
+\r
+ this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);\r
+ this.setSize(300, 150);\r
+ this.setResizable(false);\r
+ this.setTitle("Login Dialog");\r
+ this.setLocationRelativeTo(null);\r
+\r
+ Container c = this.getContentPane();\r
+ SpringLayout l = new SpringLayout();\r
+ c.setLayout(l);\r
+\r
+ JLabel usernameLabel = new JLabel("ユーザ名");\r
+ l.putConstraint(SpringLayout.NORTH, usernameLabel, 10, SpringLayout.NORTH, c);\r
+ l.putConstraint(SpringLayout.WEST, usernameLabel, 10, SpringLayout.WEST, c);\r
+ c.add(usernameLabel);\r
+\r
+ JLabel passwordLabel = new JLabel("パスワード");\r
+ l.putConstraint(SpringLayout.NORTH, passwordLabel, 10, SpringLayout.SOUTH, usernameLabel);\r
+ l.putConstraint(SpringLayout.WEST, passwordLabel, 10, SpringLayout.WEST, c);\r
+ c.add(passwordLabel);\r
+\r
+ this.username = new JTextField();\r
+ l.putConstraint(SpringLayout.NORTH, this.username, 10, SpringLayout.NORTH, c);\r
+ l.putConstraint(SpringLayout.EAST, this.username, -10, SpringLayout.EAST, c);\r
+ l.putConstraint(SpringLayout.WEST, this.username, 10, SpringLayout.EAST, usernameLabel);\r
+ c.add(this.username);\r
+\r
+ this.password = new JTextField();\r
+ l.putConstraint(SpringLayout.NORTH, this.password, 10, SpringLayout.SOUTH, this.username);\r
+ l.putConstraint(SpringLayout.EAST, this.password, -10, SpringLayout.EAST, c);\r
+ l.putConstraint(SpringLayout.WEST, this.password, 10, SpringLayout.EAST, passwordLabel);\r
+ c.add(this.password);\r
+\r
+ JButton closeButton = new JButton("閉じる");\r
+ closeButton.addActionListener(new ActionListener() {\r
+\r
+ public void actionPerformed(ActionEvent e) {\r
+ LoginDialog.this.auth = false;\r
+\r
+ LoginDialog.this.dispose();\r
+ }\r
+\r
+ });\r
+ l.putConstraint(SpringLayout.SOUTH, closeButton, -10, SpringLayout.SOUTH, c);\r
+ l.putConstraint(SpringLayout.EAST, closeButton, -10, SpringLayout.EAST, c);\r
+ c.add(closeButton);\r
+\r
+ JButton loginButton = new JButton("ログイン");\r
+ loginButton.addActionListener(new ActionListener() {\r
+\r
+ public void actionPerformed(ActionEvent event) {\r
+ try {\r
+ Map<String, Object> postData = new HashMap<String, Object>();\r
+ postData.put("method", "get_challenge");\r
+\r
+ Object returnData = HttpUtil.post(postData);\r
+\r
+ String challenge = (String) returnData;\r
+\r
+ postData.clear();\r
+ postData.put("method", "login");\r
+ postData.put("username", LoginDialog.this.username.getText());\r
+ postData.put("password", new HashUtil("MD5").digest(new ByteArrayInputStream((LoginDialog.this.password.getText() + challenge).getBytes())));\r
+\r
+ returnData = HttpUtil.post(postData);\r
+\r
+ LoginDialog.this.auth = true;\r
+\r
+ LoginDialog.this.dispose();\r
+ } catch (Throwable e) {\r
+ SimpleErrorDialog.showDialog(e);\r
+ }\r
+ }\r
+\r
+ });\r
+ l.putConstraint(SpringLayout.SOUTH, loginButton, -10, SpringLayout.SOUTH, c);\r
+ l.putConstraint(SpringLayout.EAST, loginButton, -10, SpringLayout.WEST, closeButton);\r
+ c.add(loginButton);\r
+ }\r
+\r
+ public static boolean showDialog() {\r
+ LoginDialog dialog = new LoginDialog();\r
+ dialog.setVisible(true);\r
+\r
+ return dialog.auth;\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env;\r
+\r
+import java.awt.Container;\r
+import java.awt.DisplayMode;\r
+import java.awt.GraphicsDevice;\r
+import java.awt.GraphicsEnvironment;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ActionListener;\r
+import java.io.IOException;\r
+import java.net.MalformedURLException;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import javax.swing.JButton;\r
+import javax.swing.JFrame;\r
+import javax.swing.JOptionPane;\r
+import javax.swing.JScrollPane;\r
+import javax.swing.JTextArea;\r
+import javax.swing.SpringLayout;\r
+import javax.swing.UIManager;\r
+import javax.swing.WindowConstants;\r
+import javax.xml.parsers.ParserConfigurationException;\r
+\r
+import org.xml.sax.SAXException;\r
+\r
+@SuppressWarnings("serial")\r
+public class OnlineStgEditor extends JFrame {\r
+\r
+ private JTextArea textArea;\r
+\r
+ private DisplayMode currentDisplayMode;\r
+\r
+ public OnlineStgEditor() throws MalformedURLException, IOException, SAXException, ParserConfigurationException {\r
+ this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);\r
+ this.setSize(640, 480);\r
+ this.setTitle("Online STG Editor");\r
+ this.setLocationRelativeTo(null);\r
+\r
+ Container c = this.getContentPane();\r
+ SpringLayout l = new SpringLayout();\r
+ c.setLayout(l);\r
+\r
+ JButton sendButton = new JButton("送信");\r
+ sendButton.addActionListener(new ActionListener() {\r
+\r
+ public void actionPerformed(ActionEvent event) {\r
+ try {\r
+ String text = OnlineStgEditor.this.textArea.getText();\r
+\r
+ Map<String, Object> postData = new HashMap<String, Object>();\r
+ postData.put("method", "write_data_file");\r
+ postData.put("data", text);\r
+\r
+ HttpUtil.post(postData);\r
+\r
+ JOptionPane.showMessageDialog(OnlineStgEditor.this, "文章を保存しました。", "保存", JOptionPane.INFORMATION_MESSAGE);\r
+ } catch (Throwable e) {\r
+ SimpleErrorDialog.showDialog(e);\r
+ }\r
+ }\r
+\r
+ });\r
+ l.putConstraint(SpringLayout.SOUTH, sendButton, -10, SpringLayout.SOUTH, c);\r
+ l.putConstraint(SpringLayout.EAST, sendButton, -10, SpringLayout.EAST, c);\r
+ c.add(sendButton);\r
+\r
+ JButton fullScreenButton = new JButton("フルスクリーン");\r
+ fullScreenButton.addActionListener(new ActionListener() {\r
+\r
+ public void actionPerformed(ActionEvent e) {\r
+ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();\r
+ GraphicsDevice gd = ge.getDefaultScreenDevice();\r
+\r
+ if (OnlineStgEditor.this.currentDisplayMode == null) {\r
+ gd.setFullScreenWindow(OnlineStgEditor.this);\r
+ OnlineStgEditor.this.currentDisplayMode = gd.getDisplayMode();\r
+ gd.setDisplayMode(new DisplayMode(640, 480, 32, 60));\r
+ } else {\r
+ gd.setDisplayMode(OnlineStgEditor.this.currentDisplayMode);\r
+ gd.setFullScreenWindow(null);\r
+ OnlineStgEditor.this.currentDisplayMode = null;\r
+ }\r
+ }\r
+\r
+ });\r
+ l.putConstraint(SpringLayout.SOUTH, fullScreenButton, -10, SpringLayout.SOUTH, c);\r
+ l.putConstraint(SpringLayout.EAST, fullScreenButton, -10, SpringLayout.WEST, sendButton);\r
+ c.add(fullScreenButton);\r
+\r
+ this.textArea = new JTextArea();\r
+ JScrollPane textAreaScroll = new JScrollPane(this.textArea);\r
+ l.putConstraint(SpringLayout.SOUTH, textAreaScroll, -10, SpringLayout.NORTH, sendButton);\r
+ l.putConstraint(SpringLayout.NORTH, textAreaScroll, 10, SpringLayout.NORTH, c);\r
+ l.putConstraint(SpringLayout.EAST, textAreaScroll, -10, SpringLayout.EAST, c);\r
+ l.putConstraint(SpringLayout.WEST, textAreaScroll, 10, SpringLayout.WEST, c);\r
+ c.add(textAreaScroll);\r
+\r
+ Map<String, Object> postData = new HashMap<String, Object>();\r
+ postData.put("method", "read_data_file");\r
+\r
+ Object returnData = HttpUtil.post(postData);\r
+ this.textArea.setText((String) returnData);\r
+ }\r
+\r
+ public static void main(String[] args) throws Exception {\r
+ // TODO\r
+ // Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {\r
+ //\r
+ // public void uncaughtException(Thread t, Throwable e) {\r
+ // JOptionPane.showMessageDialog(null, e.toString(), "Error", JOptionPane.ERROR_MESSAGE);\r
+ // System.exit(1);\r
+ // }\r
+ //\r
+ // });\r
+\r
+ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());\r
+\r
+ if (!LoginDialog.showDialog()) {\r
+ System.exit(0);\r
+ }\r
+\r
+ OnlineStgEditor editor = new OnlineStgEditor();\r
+ editor.setVisible(true);\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env;\r
+\r
+import java.awt.BorderLayout;\r
+import java.awt.Dimension;\r
+import java.beans.IntrospectionException;\r
+import java.lang.reflect.InvocationTargetException;\r
+import java.net.MalformedURLException;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import javax.swing.Icon;\r
+import javax.swing.JDialog;\r
+import javax.swing.JFrame;\r
+import javax.swing.JScrollPane;\r
+import javax.swing.JTable;\r
+import javax.swing.ListSelectionModel;\r
+import javax.swing.WindowConstants;\r
+import javax.swing.event.ListSelectionEvent;\r
+import javax.swing.event.ListSelectionListener;\r
+import javax.swing.event.TableModelListener;\r
+import javax.swing.table.TableModel;\r
+\r
+import jp.gr.java_conf.u6k.online_stg_env.data.DataContainer;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.BaseShape;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.ShapePropertyChangeEvent;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.ShapePropertyChangeListener;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.reflect.ShapeDescriptor;\r
+\r
+@SuppressWarnings("serial")\r
+public class ShapeChooserDialog extends JDialog {\r
+\r
+ public ShapeChooserDialog(JFrame owner, DataContainer dataContainer) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IllegalArgumentException, InvocationTargetException, MalformedURLException, IntrospectionException {\r
+ super(owner, false);\r
+\r
+ if (dataContainer == null) {\r
+ throw new NullPointerException("dataContainer == null");\r
+ }\r
+\r
+ List<Class<? extends BaseShape>> shapeClazzList = new ArrayList<Class<? extends BaseShape>>();\r
+ shapeClazzList.add(this.classForName("jp.gr.java_conf.u6k.online_stg_env.shape.FreehandLineShape"));\r
+ shapeClazzList.add(this.classForName("jp.gr.java_conf.u6k.online_stg_env.shape.LineShape"));\r
+ shapeClazzList.add(this.classForName("jp.gr.java_conf.u6k.online_stg_env.shape.OvalShape"));\r
+ shapeClazzList.add(this.classForName("jp.gr.java_conf.u6k.online_stg_env.shape.RectangleShape"));\r
+\r
+ JTable shapeTable = new JTable(new TableModelImpl(shapeClazzList));\r
+ shapeTable.getSelectionModel().addListSelectionListener(new ListSelectionListenerImpl(shapeTable, dataContainer));\r
+ shapeTable.setRowHeight(40);\r
+ shapeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r
+ JScrollPane shapeTableScroll = new JScrollPane(shapeTable);\r
+ this.getContentPane().add(shapeTableScroll, BorderLayout.CENTER);\r
+\r
+ this.setTitle("図形の選択 - DrawEditor");\r
+ this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);\r
+ this.setPreferredSize(new Dimension(400, 300));\r
+ this.setLocationRelativeTo(null);\r
+\r
+ this.pack();\r
+ }\r
+\r
+ @SuppressWarnings("unchecked")\r
+ private Class<? extends BaseShape> classForName(String className) throws ClassNotFoundException {\r
+ return (Class<? extends BaseShape>) Class.forName(className);\r
+ }\r
+\r
+ private static class ShapePropertyChangeListenerImpl implements ShapePropertyChangeListener {\r
+\r
+ private JTable shapeTable;\r
+\r
+ private DataContainer dataContainer;\r
+\r
+ public ShapePropertyChangeListenerImpl(JTable shapeTable, DataContainer dataContainer) {\r
+ if (shapeTable == null) {\r
+ throw new NullPointerException("shapeTable == null");\r
+ }\r
+ if (dataContainer == null) {\r
+ throw new NullPointerException("dataContainer != null");\r
+ }\r
+ this.shapeTable = shapeTable;\r
+ this.dataContainer = dataContainer;\r
+ }\r
+\r
+ public void propertyChange(ShapePropertyChangeEvent event) {\r
+ if ("completed".equals(event.getPropertyName())) {\r
+ TableModelImpl tableModel = (TableModelImpl) this.shapeTable.getModel();\r
+ Class<? extends BaseShape> shapeClazz = tableModel.getRowData(this.shapeTable.getSelectedRow()).getShapeClazz();\r
+ try {\r
+ BaseShape shape = shapeClazz.newInstance();\r
+ shape.addShapePropertyChangeListener(new ShapePropertyChangeListenerImpl(this.shapeTable, this.dataContainer));\r
+ this.dataContainer.setCurrentShape(shape);\r
+ } catch (InstantiationException e) {\r
+ throw new RuntimeException(e);\r
+ } catch (IllegalAccessException e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+ private static class TableModelImpl implements TableModel {\r
+\r
+ private List<TableModelListener> listenerList = new ArrayList<TableModelListener>();\r
+\r
+ private List<TableRowData> rowDataList = new ArrayList<TableRowData>();\r
+\r
+ public TableModelImpl(List<Class<? extends BaseShape>> shapeClazzList) throws MalformedURLException, IntrospectionException {\r
+ if (shapeClazzList == null) {\r
+ throw new NullPointerException("shapeClazzList == null");\r
+ }\r
+\r
+ for (Class<? extends BaseShape> shapeClazz : shapeClazzList) {\r
+ this.rowDataList.add(new TableRowData(shapeClazz));\r
+ }\r
+ }\r
+\r
+ public void addTableModelListener(TableModelListener l) {\r
+ if (l != null) {\r
+ this.listenerList.add(l);\r
+ }\r
+ }\r
+\r
+ public Class<?> getColumnClass(int columnIndex) {\r
+ switch (columnIndex) {\r
+ case 0:\r
+ return Icon.class;\r
+ case 1:\r
+ return String.class;\r
+ default:\r
+ throw new IllegalArgumentException("columnIndex != {0, 1}");\r
+ }\r
+ }\r
+\r
+ public int getColumnCount() {\r
+ return 2;\r
+ }\r
+\r
+ public String getColumnName(int columnIndex) {\r
+ switch (columnIndex) {\r
+ case 0:\r
+ return "アイコン";\r
+ case 1:\r
+ return "図形名";\r
+ default:\r
+ throw new IllegalArgumentException("columnIndex != {0, 1}");\r
+ }\r
+ }\r
+\r
+ public int getRowCount() {\r
+ return this.rowDataList.size();\r
+ }\r
+\r
+ public Object getValueAt(int rowIndex, int columnIndex) {\r
+ TableRowData rowData = this.rowDataList.get(rowIndex);\r
+\r
+ switch (columnIndex) {\r
+ case 0:\r
+ return rowData.getShapeDescriptor().getIcon();\r
+ case 1:\r
+ return rowData.getShapeDescriptor().getName();\r
+ default:\r
+ throw new IllegalArgumentException("columnIndex != {0, 1}");\r
+ }\r
+ }\r
+\r
+ public boolean isCellEditable(int rowIndex, int columnIndex) {\r
+ return false;\r
+ }\r
+\r
+ public void removeTableModelListener(TableModelListener l) {\r
+ if (l != null) {\r
+ this.listenerList.remove(l);\r
+ }\r
+ }\r
+\r
+ public void setValueAt(Object value, int rowIndex, int columnIndex) {\r
+ }\r
+\r
+ public TableRowData getRowData(int rowIndex) {\r
+ return this.rowDataList.get(rowIndex);\r
+ }\r
+\r
+ }\r
+\r
+ private static class TableRowData {\r
+\r
+ private Class<? extends BaseShape> clazz;\r
+\r
+ private ShapeDescriptor desc;\r
+\r
+ private Map<String, Object> defaultValueMap = new HashMap<String, Object>();\r
+\r
+ public TableRowData(Class<? extends BaseShape> clazz) throws MalformedURLException, IntrospectionException {\r
+ if (clazz == null) {\r
+ throw new NullPointerException("clazz == null");\r
+ }\r
+\r
+ this.clazz = clazz;\r
+ this.desc = new ShapeDescriptor(clazz);\r
+ }\r
+\r
+ public Class<? extends BaseShape> getShapeClazz() {\r
+ return this.clazz;\r
+ }\r
+\r
+ public ShapeDescriptor getShapeDescriptor() {\r
+ return this.desc;\r
+ }\r
+\r
+ public Map<String, Object> getDefaultValueMap() {\r
+ return this.defaultValueMap;\r
+ }\r
+\r
+ }\r
+\r
+ private static class ListSelectionListenerImpl implements ListSelectionListener {\r
+\r
+ private JTable shapeTable;\r
+\r
+ private DataContainer dataContainer;\r
+\r
+ public ListSelectionListenerImpl(JTable shapeTable, DataContainer dataContainer) {\r
+ if (shapeTable == null) {\r
+ throw new NullPointerException("shapeTable == null");\r
+ }\r
+ if (dataContainer == null) {\r
+ throw new NullPointerException("dataContainer == null");\r
+ }\r
+ this.shapeTable = shapeTable;\r
+ this.dataContainer = dataContainer;\r
+ }\r
+\r
+ public void valueChanged(ListSelectionEvent event) {\r
+ TableModelImpl tableModel = (TableModelImpl) this.shapeTable.getModel();\r
+ Class<? extends BaseShape> shapeClazz = tableModel.getRowData(this.shapeTable.getSelectedRow()).getShapeClazz();\r
+ try {\r
+ BaseShape shape = shapeClazz.newInstance();\r
+ shape.addShapePropertyChangeListener(new ShapePropertyChangeListenerImpl(this.shapeTable, this.dataContainer));\r
+ this.dataContainer.setCurrentShape(shape);\r
+ } catch (InstantiationException e) {\r
+ throw new RuntimeException(e);\r
+ } catch (IllegalAccessException e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+ }\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env;\r
+\r
+import java.awt.BorderLayout;\r
+import java.awt.Dimension;\r
+import java.beans.IntrospectionException;\r
+import java.net.MalformedURLException;\r
+\r
+import javax.swing.JDialog;\r
+import javax.swing.JFrame;\r
+import javax.swing.JScrollPane;\r
+import javax.swing.JTable;\r
+import javax.swing.WindowConstants;\r
+import javax.swing.event.ListSelectionEvent;\r
+import javax.swing.event.ListSelectionListener;\r
+import javax.swing.table.DefaultTableModel;\r
+\r
+import jp.gr.java_conf.u6k.online_stg_env.data.DataContainer;\r
+import jp.gr.java_conf.u6k.online_stg_env.data.ShapeAddEvent;\r
+import jp.gr.java_conf.u6k.online_stg_env.data.ShapeContainerListener;\r
+import jp.gr.java_conf.u6k.online_stg_env.data.ShapeRemoveEvent;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.BaseShape;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.reflect.ShapeDescriptor;\r
+\r
+@SuppressWarnings("serial")\r
+public class ShapeListDialog extends JDialog {\r
+\r
+ private JTable shapeTable;\r
+\r
+ private DataContainer dc;\r
+\r
+ public ShapeListDialog(JFrame owner, DataContainer dataContainer) throws MalformedURLException, IntrospectionException {\r
+ super(owner, false);\r
+\r
+ if (dataContainer == null) {\r
+ throw new NullPointerException("dataContainer == null");\r
+ }\r
+\r
+ this.dc = dataContainer;\r
+\r
+ this.shapeTable = new JTable(new DefaultTableModel(new Object[] { "ID", "図形名" }, 0));\r
+ this.shapeTable.getSelectionModel().addListSelectionListener(new ListSelectionListenerImpl());\r
+ this.shapeTable.setDefaultEditor(Object.class, null);\r
+ JScrollPane shapeTableScroll = new JScrollPane(this.shapeTable);\r
+ this.getContentPane().add(shapeTableScroll, BorderLayout.CENTER);\r
+\r
+ this.setTitle("図形リスト - DrawEditor");\r
+ this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);\r
+ this.setPreferredSize(new Dimension(400, 300));\r
+ this.setLocationRelativeTo(null);\r
+\r
+ this.pack();\r
+\r
+ for (BaseShape shape : dataContainer.getShapeContainer().getShapeList()) {\r
+ this.addShape(shape);\r
+ }\r
+\r
+ dataContainer.getShapeContainer().addListener(new ShapeContainerListenerImpl());\r
+ }\r
+\r
+ private void addShape(BaseShape shape) throws MalformedURLException, IntrospectionException {\r
+ int index = this.shapeTable.getRowCount();\r
+\r
+ ShapeDescriptor shapeDesc = new ShapeDescriptor(shape.getClass());\r
+\r
+ DefaultTableModel tableModel = (DefaultTableModel) this.shapeTable.getModel();\r
+ tableModel.addRow(new Object[] { index, shapeDesc.getName() });\r
+ }\r
+\r
+ private class ShapeContainerListenerImpl implements ShapeContainerListener {\r
+\r
+ public void addShape(ShapeAddEvent event) {\r
+ try {\r
+ ShapeListDialog.this.addShape(event.getShape());\r
+ } catch (MalformedURLException e) {\r
+ throw new RuntimeException(e);\r
+ } catch (IntrospectionException e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+ }\r
+\r
+ public void removeShape(ShapeRemoveEvent event) {\r
+ // TODO Auto-generated method stub\r
+ }\r
+\r
+ }\r
+\r
+ private class ListSelectionListenerImpl implements ListSelectionListener {\r
+\r
+ public void valueChanged(ListSelectionEvent event) {\r
+ int index = event.getFirstIndex();\r
+ BaseShape shape = ShapeListDialog.this.dc.getShapeContainer().getShapeList().get(index);\r
+ ShapeListDialog.this.dc.setCurrentShape(shape);\r
+ }\r
+\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env;\r
+\r
+import java.awt.BorderLayout;\r
+import java.awt.Color;\r
+import java.awt.Component;\r
+import java.awt.Dimension;\r
+import java.beans.IntrospectionException;\r
+import java.lang.reflect.InvocationTargetException;\r
+import java.net.MalformedURLException;\r
+import java.util.ArrayList;\r
+import java.util.EventObject;\r
+import java.util.List;\r
+\r
+import javax.swing.JColorChooser;\r
+import javax.swing.JDialog;\r
+import javax.swing.JFrame;\r
+import javax.swing.JScrollPane;\r
+import javax.swing.JTable;\r
+import javax.swing.JTextField;\r
+import javax.swing.WindowConstants;\r
+import javax.swing.event.CellEditorListener;\r
+import javax.swing.event.ChangeEvent;\r
+import javax.swing.event.TableModelEvent;\r
+import javax.swing.event.TableModelListener;\r
+import javax.swing.table.TableCellEditor;\r
+import javax.swing.table.TableModel;\r
+\r
+import jp.gr.java_conf.u6k.online_stg_env.data.CurrentShapeChangeEvent;\r
+import jp.gr.java_conf.u6k.online_stg_env.data.DataContainer;\r
+import jp.gr.java_conf.u6k.online_stg_env.data.DataContainerListener;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.BaseShape;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.reflect.ShapeDescriptor;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.reflect.ShapePropertyDescriptor;\r
+\r
+@SuppressWarnings("serial")\r
+public class ShapePropertyDialog extends JDialog {\r
+\r
+ public ShapePropertyDialog(JFrame owner, DataContainer dataContainer) {\r
+ super(owner, false);\r
+\r
+ if (dataContainer == null) {\r
+ throw new NullPointerException("dataContainer == null");\r
+ }\r
+\r
+ JTable propTable = new JTable(new TableModelImpl());\r
+ propTable.getColumnModel().getColumn(1).setCellEditor(new TableCellEditorImpl());\r
+ JScrollPane propTableScroll = new JScrollPane(propTable);\r
+ this.getContentPane().add(propTableScroll, BorderLayout.CENTER);\r
+\r
+ this.setTitle("図形のプロパティ - DrawEditor");\r
+ this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);\r
+ this.setPreferredSize(new Dimension(400, 300));\r
+ this.setLocationRelativeTo(null);\r
+\r
+ this.pack();\r
+\r
+ dataContainer.addListener(new DataContainerListenerImpl(propTable));\r
+ }\r
+\r
+ private static class TableCellEditorImpl implements TableCellEditor {\r
+\r
+ private List<CellEditorListener> listenerList = new ArrayList<CellEditorListener>();\r
+\r
+ private Object value;\r
+\r
+ public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {\r
+ // TODO Auto-generated method stub\r
+ System.out.println("* getTableCellEditorComponent: " + value + ", " + row + ", " + column);\r
+ this.value = value;\r
+ if (value instanceof Color) {\r
+ Color oldColor = (Color) value;\r
+ Color newColor = JColorChooser.showDialog(null, "色の選択", oldColor);\r
+ if (newColor != null) {\r
+ table.getModel().setValueAt(newColor, row, column);\r
+ }\r
+ return null;\r
+ } else {\r
+ return new JTextField(value.toString());\r
+ }\r
+ }\r
+\r
+ public void addCellEditorListener(CellEditorListener l) {\r
+ System.out.println("* addCellEditorListener");\r
+ if (l != null) {\r
+ this.listenerList.add(l);\r
+ }\r
+ }\r
+\r
+ public void cancelCellEditing() {\r
+ System.out.println("* cancelCellEditing");\r
+ // TODO Auto-generated method stub\r
+ ChangeEvent event = new ChangeEvent(this);\r
+ for (CellEditorListener l : this.listenerList.toArray(new CellEditorListener[0])) {\r
+ l.editingCanceled(event);\r
+ }\r
+ }\r
+\r
+ public Object getCellEditorValue() {\r
+ System.out.println("* getCellEditorValue");\r
+ // TODO Auto-generated method stub\r
+ return this.value;\r
+ }\r
+\r
+ public boolean isCellEditable(EventObject anEvent) {\r
+ System.out.println("* isCellEditable");\r
+ // TODO Auto-generated method stub\r
+ return true;\r
+ }\r
+\r
+ public void removeCellEditorListener(CellEditorListener l) {\r
+ System.out.println("* removeCellEditor");\r
+ if (l != null) {\r
+ this.listenerList.remove(l);\r
+ }\r
+ }\r
+\r
+ public boolean shouldSelectCell(EventObject anEvent) {\r
+ System.out.println("* shouldSelectCell");\r
+ // TODO Auto-generated method stub\r
+ return true;\r
+ }\r
+\r
+ public boolean stopCellEditing() {\r
+ System.out.println("* stopCellEditing");\r
+ // TODO Auto-generated method stub\r
+ ChangeEvent event = new ChangeEvent(this);\r
+ for (CellEditorListener l : this.listenerList.toArray(new CellEditorListener[0])) {\r
+ l.editingStopped(event);\r
+ }\r
+ return true;\r
+ }\r
+\r
+ }\r
+\r
+ private static class TableModelImpl implements TableModel {\r
+\r
+ private List<TableModelListener> listenerList = new ArrayList<TableModelListener>();\r
+\r
+ private BaseShape shape;\r
+\r
+ private Object[][] rowData = new Object[0][];\r
+\r
+ public void addTableModelListener(TableModelListener l) {\r
+ if (l != null) {\r
+ this.listenerList.add(l);\r
+ }\r
+ }\r
+\r
+ public Class<?> getColumnClass(int columnIndex) {\r
+ return Object.class;\r
+ }\r
+\r
+ public int getColumnCount() {\r
+ return 2;\r
+ }\r
+\r
+ public String getColumnName(int columnIndex) {\r
+ switch (columnIndex) {\r
+ case 0:\r
+ return "名称";\r
+ case 1:\r
+ return "値";\r
+ default:\r
+ throw new IllegalArgumentException("columnIndex != {0, 1}");\r
+ }\r
+ }\r
+\r
+ public int getRowCount() {\r
+ return this.rowData.length;\r
+ }\r
+\r
+ public Object getValueAt(int rowIndex, int columnIndex) {\r
+ return this.rowData[rowIndex][columnIndex];\r
+ }\r
+\r
+ public boolean isCellEditable(int rowIndex, int columnIndex) {\r
+ // TODO Auto-generated method stub\r
+ if (columnIndex == 1) {\r
+ return true;\r
+ } else {\r
+ return false;\r
+ }\r
+ }\r
+\r
+ public void removeTableModelListener(TableModelListener l) {\r
+ if (l != null) {\r
+ this.listenerList.remove(l);\r
+ }\r
+ }\r
+\r
+ public void setValueAt(Object value, int rowIndex, int columnIndex) {\r
+ this.rowData[rowIndex][columnIndex] = value;\r
+\r
+ TableModelEvent event = new TableModelEvent(this, rowIndex, columnIndex);\r
+ for (TableModelListener l : this.listenerList.toArray(new TableModelListener[0])) {\r
+ l.tableChanged(event);\r
+ }\r
+ }\r
+\r
+ public void setShape(BaseShape shape) throws MalformedURLException, IntrospectionException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {\r
+ if (shape == null) {\r
+ throw new NullPointerException("shape == null");\r
+ }\r
+ this.shape = shape;\r
+\r
+ ShapeDescriptor shapeDesc = new ShapeDescriptor(shape.getClass());\r
+ List<ShapePropertyDescriptor> propDescList = ShapePropertyDescriptor.getPropertyDescriptorList(shape.getClass());\r
+\r
+ this.rowData = new Object[3 + propDescList.size()][];\r
+\r
+ this.rowData[0] = new Object[] { "名前", shapeDesc.getName() };\r
+ this.rowData[1] = new Object[] { "詳細", shapeDesc.getDescription() };\r
+ this.rowData[2] = new Object[] { "クラス", shape.getClass().getName() };\r
+ for (int i = 0; i < propDescList.size(); i++) {\r
+ ShapePropertyDescriptor propDesc = propDescList.get(i);\r
+ Object v = propDesc.getGetterMethod().invoke(shape);\r
+ this.rowData[3 + i] = new Object[] { propDesc.getName(), v };\r
+ }\r
+\r
+ TableModelEvent event = new TableModelEvent(this);\r
+ for (TableModelListener l : this.listenerList) {\r
+ l.tableChanged(event);\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+ private class DataContainerListenerImpl implements DataContainerListener {\r
+\r
+ private JTable propTable;\r
+\r
+ public DataContainerListenerImpl(JTable propTable) {\r
+ if (propTable == null) {\r
+ throw new NullPointerException("propTable == null");\r
+ }\r
+ this.propTable = propTable;\r
+ }\r
+\r
+ public void currentShapeChange(CurrentShapeChangeEvent event) {\r
+ try {\r
+ TableModelImpl tableModel = (TableModelImpl) this.propTable.getModel();\r
+ tableModel.setShape(event.getNewShape());\r
+ } catch (MalformedURLException e) {\r
+ throw new RuntimeException(e);\r
+ } catch (IllegalArgumentException e) {\r
+ throw new RuntimeException(e);\r
+ } catch (IntrospectionException e) {\r
+ throw new RuntimeException(e);\r
+ } catch (IllegalAccessException e) {\r
+ throw new RuntimeException(e);\r
+ } catch (InvocationTargetException e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+}\r
--- /dev/null
+/*\r
+ * Copyright (C) 2008 u6k.yu1@gmail.com, All Rights Reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the distribution.\r
+ *\r
+ * 3. Neither the name of Clarkware Consulting, Inc. nor the names of its\r
+ * contributors may be used to endorse or promote products derived\r
+ * from this software without prior written permission. For written\r
+ * permission, please contact clarkware@clarkware.com.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\r
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\r
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL\r
+ * CLARKWARE CONSULTING OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+package jp.gr.java_conf.u6k.online_stg_env;\r
+\r
+import java.awt.Component;\r
+import java.awt.Container;\r
+import java.awt.Dialog;\r
+import java.awt.Frame;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ActionListener;\r
+import java.awt.event.KeyEvent;\r
+import java.io.ByteArrayOutputStream;\r
+import java.io.PrintStream;\r
+import java.util.ResourceBundle;\r
+\r
+import javax.swing.AbstractAction;\r
+import javax.swing.JButton;\r
+import javax.swing.JDialog;\r
+import javax.swing.JEditorPane;\r
+import javax.swing.JLabel;\r
+import javax.swing.JScrollPane;\r
+import javax.swing.JTextPane;\r
+import javax.swing.KeyStroke;\r
+import javax.swing.SpringLayout;\r
+import javax.swing.UIManager;\r
+import javax.swing.WindowConstants;\r
+import javax.swing.border.TitledBorder;\r
+\r
+/**\r
+ * <p>\r
+ * エラーを表示する単純なモーダル・ダイアログです。外観は以下の要素で構成されます。\r
+ * </p>\r
+ * <ul>\r
+ * <li>ユーザへエラーが発生したことを表すメッセージ。\r
+ * <li>エラーの内容を表示するメッセージ。\r
+ * <li>閉じるボタン。\r
+ * </ul>\r
+ * <p>\r
+ * 表示するメッセージ、ダイアログの初期サイズなどは外部プロパティ・ファイルで定義されており、ソースコードの修正無しに変更することが可能です。定義内容はSimpleErrorDialog.propertiesを参照してください。\r
+ * </p>\r
+ * \r
+ * @version $Id$\r
+ */\r
+@SuppressWarnings("serial")\r
+public final class SimpleErrorDialog extends JDialog {\r
+\r
+ // TODO 背景色がおかしくなる。\r
+ // TODO 配置がおかしくなる。\r
+\r
+ /**\r
+ * <p>\r
+ * Swingコンポーネント同士の間隔。\r
+ * </p>\r
+ */\r
+ private static final int COMPONENT_INTERVAL = 10;\r
+\r
+ /**\r
+ * <p>\r
+ * 外部リソース。TODO パッケージが変わると共にここも修正します。\r
+ * </p>\r
+ */\r
+ private static final ResourceBundle RB = ResourceBundle.getBundle("jp.gr.java_conf.u6k.online_stg_env.SimpleErrorDialog");\r
+\r
+ private SimpleErrorDialog(Frame owner, Throwable exception) {\r
+ super(owner, SimpleErrorDialog.RB.getString("dialog.title"), true);\r
+\r
+ this.initialize(exception);\r
+ }\r
+\r
+ private SimpleErrorDialog(Dialog owner, Throwable exception) {\r
+ super(owner, SimpleErrorDialog.RB.getString("dialog.title"), true);\r
+\r
+ this.initialize(exception);\r
+ }\r
+\r
+ private void initialize(Throwable exception) {\r
+ if (exception == null) {\r
+ throw new NullPointerException("exception == null");\r
+ }\r
+\r
+ /*\r
+ * コンポーネントを設定し、ダイアログを初期化します。\r
+ */\r
+ // コンポーネントを作成します。\r
+ Container c = this.getContentPane();\r
+\r
+ JLabel iconLabel = new JLabel(UIManager.getIcon("OptionPane.errorIcon"));\r
+ c.add(iconLabel);\r
+\r
+ JEditorPane message1 = new JEditorPane();\r
+ message1.setContentType("text/html");\r
+ message1.setText(SimpleErrorDialog.RB.getString("dialog.message1"));\r
+ message1.setEditable(false);\r
+ message1.setBackground(this.getBackground());\r
+ c.add(message1);\r
+\r
+ String exceptionString;\r
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();\r
+ exception.printStackTrace(new PrintStream(bout));\r
+ exceptionString = bout.toString();\r
+\r
+ JEditorPane message2 = new ExceptionEditorPane();\r
+ message2.setText(exceptionString);\r
+ message2.setEditable(false);\r
+ message2.setBackground(this.getBackground());\r
+ JScrollPane message2Scroll = new JScrollPane(message2);\r
+ message2Scroll.setBorder(new TitledBorder(SimpleErrorDialog.RB.getString("dialog.message2")));\r
+ c.add(message2Scroll);\r
+\r
+ JButton closeButton = new JButton(SimpleErrorDialog.RB.getString("dialog.closeButton"));\r
+ closeButton.addActionListener(new ActionListener() {\r
+\r
+ public void actionPerformed(ActionEvent e) {\r
+ SimpleErrorDialog.this.dispose();\r
+ }\r
+\r
+ });\r
+ c.add(closeButton);\r
+\r
+ // レイアウトの調整を行います。\r
+ SpringLayout l = new SpringLayout();\r
+ c.setLayout(l);\r
+\r
+ l.putConstraint(SpringLayout.NORTH, iconLabel, SimpleErrorDialog.COMPONENT_INTERVAL, SpringLayout.NORTH, c);\r
+ l.putConstraint(SpringLayout.WEST, iconLabel, SimpleErrorDialog.COMPONENT_INTERVAL, SpringLayout.WEST, c);\r
+\r
+ l.putConstraint(SpringLayout.NORTH, message1, SimpleErrorDialog.COMPONENT_INTERVAL, SpringLayout.NORTH, c);\r
+ l.putConstraint(SpringLayout.EAST, message1, -SimpleErrorDialog.COMPONENT_INTERVAL, SpringLayout.EAST, c);\r
+ l.putConstraint(SpringLayout.WEST, message1, SimpleErrorDialog.COMPONENT_INTERVAL, SpringLayout.EAST, iconLabel);\r
+\r
+ l.putConstraint(SpringLayout.SOUTH, closeButton, -SimpleErrorDialog.COMPONENT_INTERVAL, SpringLayout.SOUTH, c);\r
+ l.putConstraint(SpringLayout.EAST, closeButton, -SimpleErrorDialog.COMPONENT_INTERVAL, SpringLayout.EAST, c);\r
+\r
+ l.putConstraint(SpringLayout.SOUTH, message2Scroll, -SimpleErrorDialog.COMPONENT_INTERVAL, SpringLayout.NORTH, closeButton);\r
+ l.putConstraint(SpringLayout.NORTH, message2Scroll, SimpleErrorDialog.COMPONENT_INTERVAL, SpringLayout.SOUTH, message1);\r
+ l.putConstraint(SpringLayout.EAST, message2Scroll, -SimpleErrorDialog.COMPONENT_INTERVAL, SpringLayout.EAST, c);\r
+ l.putConstraint(SpringLayout.WEST, message2Scroll, SimpleErrorDialog.COMPONENT_INTERVAL, SpringLayout.WEST, c);\r
+\r
+ // ダイアログの設定を行います。\r
+ this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);\r
+\r
+ this.setSize(Integer.parseInt(SimpleErrorDialog.RB.getString("dialog.size.width")), Integer.parseInt(SimpleErrorDialog.RB.getString("dialog.size.height")));\r
+\r
+ this.setLocationRelativeTo(this.getOwner());\r
+\r
+ this.getRootPane().setDefaultButton(closeButton);\r
+\r
+ this.getRootPane().getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "close-it");\r
+ this.getRootPane().getActionMap().put("close-it", new AbstractAction() {\r
+\r
+ public void actionPerformed(ActionEvent e) {\r
+ SimpleErrorDialog.this.dispose();\r
+ }\r
+\r
+ });\r
+ }\r
+\r
+ /**\r
+ * <p>\r
+ * エラー・ダイアログを表示します。\r
+ * </p>\r
+ * \r
+ * @param owner\r
+ * ダイアログの親コンポーネント。{@link Frame}インスタンスか{@link Dialog}インスタンスを指定してください。それ以外のコンポーネントは無視され、nullを指定した場合と同じ動作になります。\r
+ * @param exception\r
+ * 発生したエラー。\r
+ * @throws NullPointerException\r
+ * exception引数がnullの場合。\r
+ */\r
+ public static void showDialog(Component owner, Throwable exception) {\r
+ SimpleErrorDialog d;\r
+ if (owner == null) {\r
+ d = new SimpleErrorDialog((Frame) null, exception);\r
+ } else if (owner instanceof Frame) {\r
+ d = new SimpleErrorDialog((Frame) null, exception);\r
+ } else if (owner instanceof Dialog) {\r
+ d = new SimpleErrorDialog((Dialog) null, exception);\r
+ } else {\r
+ d = new SimpleErrorDialog((Frame) null, exception);\r
+ }\r
+\r
+ d.setVisible(true);\r
+ }\r
+\r
+ /**\r
+ * <p>\r
+ * エラー・ダイアログを表示します。\r
+ * </p>\r
+ * \r
+ * @param exception\r
+ * 発生したエラー。\r
+ * @throws NullPointerException\r
+ * exception引数がnullの場合。\r
+ */\r
+ public static void showDialog(Throwable exception) {\r
+ SimpleErrorDialog.showDialog(null, exception);\r
+ }\r
+\r
+ /**\r
+ * <p>\r
+ * 例外を表示する{@link JTextPane}拡張コンポーネントです。\r
+ * </p>\r
+ */\r
+ private static final class ExceptionEditorPane extends JEditorPane {\r
+\r
+ public ExceptionEditorPane() {\r
+ super();\r
+ }\r
+\r
+ @Override\r
+ public boolean getScrollableTracksViewportHeight() {\r
+ return false;\r
+ }\r
+\r
+ @Override\r
+ public boolean getScrollableTracksViewportWidth() {\r
+ return false;\r
+ }\r
+ }\r
+\r
+}\r
--- /dev/null
+dialog.title=\u4e88\u671f\u3057\u306a\u3044\u30a8\u30e9\u30fc\r
+dialog.message1=\u4e88\u671f\u3057\u306a\u3044\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u3002\u30a8\u30e9\u30fc\u306e\u5185\u5bb9\u306f\u4e0b\u306e\u30dc\u30c3\u30af\u30b9\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002\r
+dialog.message2=\u30a8\u30e9\u30fc\u306e\u5185\u5bb9\r
+dialog.closeButton=\u9589\u3058\u308b\r
+dialog.size.width=400\r
+dialog.size.height=300\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.data;\r
+\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.BaseShape;\r
+\r
+public class CurrentShapeChangeEvent {\r
+\r
+ private BaseShape oldShape;\r
+\r
+ private BaseShape newShape;\r
+\r
+ public CurrentShapeChangeEvent(BaseShape oldShape, BaseShape newShape) {\r
+ this.oldShape = oldShape;\r
+ this.newShape = newShape;\r
+ }\r
+\r
+ public BaseShape getOldShape() {\r
+ return this.oldShape;\r
+ }\r
+\r
+ public BaseShape getNewShape() {\r
+ return this.newShape;\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.data;\r
+\r
+import java.io.Externalizable;\r
+\r
+public interface DataCommand extends Externalizable {\r
+\r
+ void replay(ShapeContainer shapeContainer);\r
+\r
+ void rollback(ShapeContainer shapeContainer);\r
+\r
+ String getDescription();\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.data;\r
+\r
+public class DataCommandAddEvent {\r
+\r
+ private DataCommand command;\r
+\r
+ public DataCommandAddEvent(DataCommand command) {\r
+ this.command = command;\r
+ }\r
+\r
+ public DataCommand getCommand() {\r
+ return this.command;\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.data;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.List;\r
+import java.util.SortedMap;\r
+import java.util.TreeMap;\r
+\r
+public class DataCommandContainer {\r
+\r
+ private List<DataCommandContainerListener> listenerList = new ArrayList<DataCommandContainerListener>();\r
+\r
+ private List<DataCommand> commandList = new ArrayList<DataCommand>();\r
+\r
+ public void addListener(DataCommandContainerListener l) {\r
+ if (l == null) {\r
+ throw new NullPointerException("l == null");\r
+ }\r
+ this.listenerList.add(l);\r
+ }\r
+\r
+ public void removeListener(DataCommandContainerListener l) {\r
+ if (l == null) {\r
+ throw new NullPointerException("l == null");\r
+ }\r
+ this.listenerList.remove(l);\r
+ }\r
+\r
+ public void addCommand(DataCommand c) {\r
+ if (c == null) {\r
+ throw new NullPointerException("c == null");\r
+ }\r
+\r
+ this.commandList.add(c);\r
+\r
+ DataCommandAddEvent event = new DataCommandAddEvent(c);\r
+ for (DataCommandContainerListener l : this.listenerList.toArray(new DataCommandContainerListener[0])) {\r
+ l.commandAdd(event);\r
+ }\r
+ }\r
+\r
+ public List<DataCommand> getCommandList() {\r
+ return Collections.unmodifiableList(this.commandList);\r
+ }\r
+\r
+ public SortedMap<Integer, DataCommand> purgeCommand(int index) {\r
+ if (index > 0 || this.commandList.size() <= index) {\r
+ throw new IndexOutOfBoundsException("index > 0 || this.commandList.size() <= index");\r
+ }\r
+\r
+ SortedMap<Integer, DataCommand> purgedCommandMap = new TreeMap<Integer, DataCommand>();\r
+ if (this.commandList.size() > 0) {\r
+ int removedIndex = index;\r
+ while (this.commandList.size() > index) {\r
+ purgedCommandMap.put(removedIndex, this.commandList.remove(index));\r
+ removedIndex++;\r
+ }\r
+ }\r
+ purgedCommandMap = Collections.unmodifiableSortedMap(purgedCommandMap);\r
+\r
+ DataCommandPurgeEvent event = new DataCommandPurgeEvent(purgedCommandMap);\r
+ for (DataCommandContainerListener l : this.listenerList.toArray(new DataCommandContainerListener[0])) {\r
+ l.commandPurge(event);\r
+ }\r
+\r
+ return purgedCommandMap;\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.data;\r
+\r
+public interface DataCommandContainerListener {\r
+\r
+ void commandAdd(DataCommandAddEvent event);\r
+\r
+ void commandPurge(DataCommandPurgeEvent event);\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.data;\r
+\r
+import java.io.IOException;\r
+import java.io.ObjectInput;\r
+\r
+public class DataCommandInput implements ObjectInput {\r
+\r
+ public int available() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public void close() throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public int read() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public int read(byte[] b) throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public int read(byte[] b, int off, int len) throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public Object readObject() throws ClassNotFoundException, IOException {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ public long skip(long n) throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public boolean readBoolean() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return false;\r
+ }\r
+\r
+ public byte readByte() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public char readChar() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public double readDouble() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public float readFloat() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public void readFully(byte[] b) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void readFully(byte[] b, int off, int len) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public int readInt() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public String readLine() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ public long readLong() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public short readShort() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public String readUTF() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ public int readUnsignedByte() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public int readUnsignedShort() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public int skipBytes(int n) throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.data;\r
+\r
+import java.io.IOException;\r
+import java.io.ObjectOutput;\r
+\r
+public class DataCommandOutput implements ObjectOutput {\r
+\r
+ public void close() throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void flush() throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void write(int b) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void write(byte[] b) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void write(byte[] b, int off, int len) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeObject(Object obj) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeBoolean(boolean v) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeByte(int v) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeBytes(String s) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeChar(int v) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeChars(String s) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeDouble(double v) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeFloat(float v) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeInt(int v) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeLong(long v) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeShort(int v) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeUTF(String str) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.data;\r
+\r
+import java.util.SortedMap;\r
+\r
+public class DataCommandPurgeEvent {\r
+\r
+ private SortedMap<Integer, DataCommand> purgedCommandMap;\r
+\r
+ public DataCommandPurgeEvent(SortedMap<Integer, DataCommand> purgedCommandMap) {\r
+ this.purgedCommandMap = purgedCommandMap;\r
+ }\r
+\r
+ public SortedMap<Integer, DataCommand> getPurgedCommandMap() {\r
+ return this.purgedCommandMap;\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.data;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.BaseShape;\r
+\r
+public class DataContainer {\r
+\r
+ private List<DataContainerListener> listenerList = new ArrayList<DataContainerListener>();\r
+\r
+ private ShapeContainer shapeContainer;\r
+\r
+ private DataCommandContainer commandContainer;\r
+\r
+ private BaseShape currentShape;\r
+\r
+ public DataContainer() {\r
+ this.commandContainer = new DataCommandContainer();\r
+ this.shapeContainer = new ShapeContainer(this.commandContainer);\r
+ }\r
+\r
+ public void addListener(DataContainerListener l) {\r
+ if (l == null) {\r
+ throw new NullPointerException("l == null");\r
+ }\r
+ this.listenerList.add(l);\r
+ }\r
+\r
+ public void removeListener(DataContainerListener l) {\r
+ if (l == null) {\r
+ throw new NullPointerException("l == null");\r
+ }\r
+ this.listenerList.remove(l);\r
+ }\r
+\r
+ public DataCommandContainer getDataCommandContainer() {\r
+ return this.commandContainer;\r
+ }\r
+\r
+ public ShapeContainer getShapeContainer() {\r
+ return this.shapeContainer;\r
+ }\r
+\r
+ public BaseShape getCurrentShape() {\r
+ return this.currentShape;\r
+ }\r
+\r
+ public void setCurrentShape(BaseShape currentShape) {\r
+ BaseShape oldShape = this.currentShape;\r
+ this.currentShape = currentShape;\r
+\r
+ CurrentShapeChangeEvent event = new CurrentShapeChangeEvent(oldShape, currentShape);\r
+ for (DataContainerListener l : this.listenerList.toArray(new DataContainerListener[0])) {\r
+ l.currentShapeChange(event);\r
+ }\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.data;\r
+\r
+public interface DataContainerListener {\r
+\r
+ void currentShapeChange(CurrentShapeChangeEvent event);\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.data;\r
+\r
+import java.beans.IntrospectionException;\r
+import java.io.IOException;\r
+import java.io.ObjectInput;\r
+import java.io.ObjectOutput;\r
+import java.net.MalformedURLException;\r
+\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.BaseShape;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.reflect.ShapeDescriptor;\r
+\r
+public class ShapeAddCommand implements DataCommand {\r
+\r
+ private BaseShape shape;\r
+\r
+ public ShapeAddCommand(BaseShape shape) {\r
+ if (shape == null) {\r
+ throw new NullPointerException("shape == null");\r
+ }\r
+\r
+ this.shape = shape;\r
+ }\r
+\r
+ public void replay(ShapeContainer shapeContainer) {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void rollback(ShapeContainer shapeContainer) {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeExternal(ObjectOutput out) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public String getDescription() {\r
+ try {\r
+ ShapeDescriptor shapeDesc = new ShapeDescriptor(this.shape.getClass());\r
+ return "図形「" + shapeDesc.getName() + "」を追加。";\r
+ } catch (MalformedURLException e) {\r
+ throw new RuntimeException(e);\r
+ } catch (IntrospectionException e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.data;\r
+\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.BaseShape;\r
+\r
+public class ShapeAddEvent {\r
+\r
+ private BaseShape shape;\r
+\r
+ public ShapeAddEvent(BaseShape shape) {\r
+ this.shape = shape;\r
+ }\r
+\r
+ public BaseShape getShape() {\r
+ return this.shape;\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.data;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.List;\r
+\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.BaseShape;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.ShapePropertyChangeEvent;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.ShapePropertyChangeListener;\r
+\r
+public class ShapeContainer {\r
+\r
+ private List<ShapeContainerListener> listenerList = new ArrayList<ShapeContainerListener>();\r
+\r
+ private List<BaseShape> shapeList = new ArrayList<BaseShape>();\r
+\r
+ private ShapePropertyChangeListener shapePropertyChangeListener = new ShapePropertyChangeListenerImpl();\r
+\r
+ private DataCommandContainer commandContainer;\r
+\r
+ public ShapeContainer(DataCommandContainer commandContainer) {\r
+ if (commandContainer == null) {\r
+ throw new NullPointerException("commandContainer == null");\r
+ }\r
+\r
+ this.commandContainer = commandContainer;\r
+ }\r
+\r
+ public void addListener(ShapeContainerListener l) {\r
+ if (l == null) {\r
+ throw new NullPointerException("l == null");\r
+ }\r
+ this.listenerList.add(l);\r
+ }\r
+\r
+ public void removeListener(ShapeContainerListener l) {\r
+ if (l == null) {\r
+ throw new NullPointerException("l == null");\r
+ }\r
+ this.listenerList.remove(l);\r
+ }\r
+\r
+ public void addShape(BaseShape shape) {\r
+ if (shape == null) {\r
+ throw new NullPointerException("shape == null");\r
+ }\r
+ if (this.shapeList.contains(shape)) {\r
+ throw new IllegalArgumentException("shape is already added.");\r
+ }\r
+\r
+ this.shapeList.add(shape);\r
+\r
+ shape.addShapePropertyChangeListener(this.shapePropertyChangeListener);\r
+\r
+ this.commandContainer.addCommand(new ShapeAddCommand(shape));\r
+\r
+ ShapeAddEvent event = new ShapeAddEvent(shape);\r
+ for (ShapeContainerListener l : this.listenerList.toArray(new ShapeContainerListener[0])) {\r
+ l.addShape(event);\r
+ }\r
+ }\r
+\r
+ public void removeShape(BaseShape shape) {\r
+ if (shape == null) {\r
+ throw new NullPointerException("shape == null");\r
+ }\r
+ if (!this.shapeList.contains(shape)) {\r
+ throw new IllegalArgumentException("shape is not contain.");\r
+ }\r
+\r
+ int removedIndex = this.getShapeIndex(shape);\r
+\r
+ shape.removeShapePropertyChangeListener(this.shapePropertyChangeListener);\r
+\r
+ this.shapeList.remove(removedIndex);\r
+\r
+ this.commandContainer.addCommand(new ShapeRemoveCommand(removedIndex, shape));\r
+\r
+ ShapeRemoveEvent event = new ShapeRemoveEvent(removedIndex, shape);\r
+ for (ShapeContainerListener l : this.listenerList.toArray(new ShapeContainerListener[0])) {\r
+ l.removeShape(event);\r
+ }\r
+ }\r
+\r
+ public List<BaseShape> getShapeList() {\r
+ return Collections.unmodifiableList(this.shapeList);\r
+ }\r
+\r
+ private int getShapeIndex(BaseShape shape) {\r
+ if (shape == null) {\r
+ throw new NullPointerException("shape == null");\r
+ }\r
+\r
+ for (int i = 0; i < this.shapeList.size(); i++) {\r
+ if (this.shapeList.get(i) == shape) {\r
+ return i;\r
+ }\r
+ }\r
+\r
+ throw new IllegalArgumentException("shape is not contain.");\r
+ }\r
+\r
+ private final class ShapePropertyChangeListenerImpl implements ShapePropertyChangeListener {\r
+\r
+ public void propertyChange(ShapePropertyChangeEvent event) {\r
+ ShapePropertyChangeCommand c = new ShapePropertyChangeCommand(ShapeContainer.this.getShapeIndex(event.getSource()), event.getSource(), event.getPropertyName(), event.getOldValue(), event.getNewValue());\r
+ ShapeContainer.this.commandContainer.addCommand(c);\r
+ }\r
+\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.data;\r
+\r
+public interface ShapeContainerListener {\r
+\r
+ void addShape(ShapeAddEvent event);\r
+\r
+ void removeShape(ShapeRemoveEvent event);\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.data;\r
+\r
+import java.io.IOException;\r
+import java.io.ObjectInput;\r
+\r
+public class ShapeInput implements ObjectInput {\r
+\r
+ public int available() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public void close() throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public int read() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public int read(byte[] b) throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public int read(byte[] b, int off, int len) throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public Object readObject() throws ClassNotFoundException, IOException {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ public long skip(long n) throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public boolean readBoolean() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return false;\r
+ }\r
+\r
+ public byte readByte() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public char readChar() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public double readDouble() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public float readFloat() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public void readFully(byte[] b) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void readFully(byte[] b, int off, int len) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public int readInt() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public String readLine() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ public long readLong() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public short readShort() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public String readUTF() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ public int readUnsignedByte() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public int readUnsignedShort() throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+ public int skipBytes(int n) throws IOException {\r
+ // TODO Auto-generated method stub\r
+ return 0;\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.data;\r
+\r
+import java.io.IOException;\r
+import java.io.ObjectOutput;\r
+\r
+public class ShapeOutput implements ObjectOutput {\r
+\r
+ public void close() throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void flush() throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void write(int b) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void write(byte[] b) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void write(byte[] b, int off, int len) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeObject(Object obj) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeBoolean(boolean v) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeByte(int v) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeBytes(String s) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeChar(int v) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeChars(String s) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeDouble(double v) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeFloat(float v) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeInt(int v) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeLong(long v) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeShort(int v) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeUTF(String str) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.data;\r
+\r
+import java.io.IOException;\r
+import java.io.ObjectInput;\r
+import java.io.ObjectOutput;\r
+\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.BaseShape;\r
+\r
+public class ShapePropertyChangeCommand implements DataCommand {\r
+\r
+ private int shapeListIndex;\r
+\r
+ private BaseShape shape;\r
+\r
+ private String propertyName;\r
+\r
+ private Object oldValue;\r
+\r
+ private Object newValue;\r
+\r
+ public ShapePropertyChangeCommand(int shapeListIndex, BaseShape shape, String propertyName, Object oldValue, Object newValue) {\r
+ this.shapeListIndex = shapeListIndex;\r
+ this.shape = shape;\r
+ this.propertyName = propertyName;\r
+ this.oldValue = oldValue;\r
+ this.newValue = newValue;\r
+ }\r
+\r
+ public void replay(ShapeContainer shapeContainer) {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void rollback(ShapeContainer shapeContainer) {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeExternal(ObjectOutput out) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public String getDescription() {\r
+ return "プロパティ「" + this.propertyName + "」を" + this.oldValue + "から" + this.newValue + "に変更。";\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.data;\r
+\r
+import java.beans.IntrospectionException;\r
+import java.io.IOException;\r
+import java.io.ObjectInput;\r
+import java.io.ObjectOutput;\r
+import java.net.MalformedURLException;\r
+\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.BaseShape;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.reflect.ShapeDescriptor;\r
+\r
+public class ShapeRemoveCommand implements DataCommand {\r
+\r
+ private int removedIndex;\r
+\r
+ private BaseShape removedShape;\r
+\r
+ public ShapeRemoveCommand(int removedIndex, BaseShape removedShape) {\r
+ this.removedIndex = removedIndex;\r
+ this.removedShape = removedShape;\r
+ }\r
+\r
+ public void replay(ShapeContainer shapeContainer) {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void rollback(ShapeContainer shapeContainer) {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public void writeExternal(ObjectOutput out) throws IOException {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public String getDescription() {\r
+ try {\r
+ ShapeDescriptor shapeDesc = new ShapeDescriptor(this.removedShape.getClass());\r
+ return "図形「" + shapeDesc.getName() + "」を削除。";\r
+ } catch (MalformedURLException e) {\r
+ throw new RuntimeException(e);\r
+ } catch (IntrospectionException e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.data;\r
+\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.BaseShape;\r
+\r
+public class ShapeRemoveEvent {\r
+\r
+ private int removedIndex;\r
+\r
+ private BaseShape shape;\r
+\r
+ public ShapeRemoveEvent(int removedIndex, BaseShape shape) {\r
+ this.removedIndex = removedIndex;\r
+ this.shape = shape;\r
+ }\r
+\r
+ public int getRemovedIndex() {\r
+ return this.removedIndex;\r
+ }\r
+\r
+ public BaseShape getShape() {\r
+ return this.shape;\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.shape;\r
+\r
+import java.awt.Color;\r
+import java.awt.Component;\r
+import java.awt.Graphics;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+@ShapeName(value = "背景")\r
+@ShapeDescription(value="キャンバスの背景です。この図形はキャンバスの作成時に自動で一度だけ作成されるもので、ユーザが作成することはできません。属性を変更することはできます。")\r
+public class BackgroundShape implements BaseShape {\r
+\r
+ private List<ShapePropertyChangeListener> listenerList = new ArrayList<ShapePropertyChangeListener>();\r
+\r
+ private boolean completed = false;\r
+\r
+ private Color color = Color.WHITE;\r
+\r
+ private int width = 0;\r
+\r
+ private int height = 0;\r
+\r
+ public void addShapePropertyChangeListener(ShapePropertyChangeListener l) {\r
+ if (l == null) {\r
+ throw new NullPointerException("l == null");\r
+ }\r
+ this.listenerList.add(l);\r
+ }\r
+\r
+ public void createEnd(Component canvas) {\r
+ throw new UnsupportedOperationException("BackgroundShape can not create.");\r
+ }\r
+\r
+ public void createStart(Component canvas) {\r
+ throw new UnsupportedOperationException("BackgroundShape can not create.");\r
+ }\r
+\r
+ public void draw(Graphics g) {\r
+ if (this.getWidth() <= 0 || this.getHeight() <= 0) {\r
+ throw new IllegalStateException("width <= 0 || height <= 0");\r
+ }\r
+ if (this.getColor() == null) {\r
+ throw new IllegalStateException("color == null");\r
+ }\r
+\r
+ g.setColor(this.color);\r
+ g.fillRect(0, 0, this.width, this.height);\r
+ }\r
+\r
+ public boolean isCompleted() {\r
+ return this.completed;\r
+ }\r
+\r
+ private void setCompleted(boolean completed) {\r
+ boolean oldCompleted = this.completed;\r
+ this.completed = completed;\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "completed", oldCompleted, completed);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+ public void removeShapePropertyChangeListener(ShapePropertyChangeListener l) {\r
+ if (l == null) {\r
+ throw new NullPointerException("l == null");\r
+ }\r
+ this.listenerList.remove(l);\r
+ }\r
+\r
+ @ShapeProperty\r
+ public Color getColor() {\r
+ return this.color;\r
+ }\r
+\r
+ @ShapeProperty\r
+ public void setColor(Color color) {\r
+ if (color == null) {\r
+ throw new NullPointerException("color == null");\r
+ }\r
+\r
+ Color oldColor = this.color;\r
+ this.color = color;\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "color", oldColor, color);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+ @ShapeProperty\r
+ public int getWidth() {\r
+ return this.width;\r
+ }\r
+\r
+ @ShapeProperty\r
+ public void setWidth(int width) {\r
+ if (width <= 0) {\r
+ throw new IllegalArgumentException("width <= 0");\r
+ }\r
+\r
+ int oldWidth = this.width;\r
+ this.width = width;\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "width", oldWidth, width);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+ @ShapeProperty\r
+ public int getHeight() {\r
+ return this.height;\r
+ }\r
+\r
+ @ShapeProperty\r
+ public void setHeight(int height) {\r
+ if (height <= 0) {\r
+ throw new IllegalArgumentException("height <= 0");\r
+ }\r
+\r
+ int oldHeight = this.height;\r
+ this.height = height;\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "height", oldHeight, height);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.shape;\r
+\r
+import java.awt.Component;\r
+import java.awt.Graphics;\r
+\r
+public interface BaseShape {\r
+\r
+ void addShapePropertyChangeListener(ShapePropertyChangeListener l);\r
+\r
+ void removeShapePropertyChangeListener(ShapePropertyChangeListener l);\r
+\r
+ void draw(Graphics g);\r
+\r
+ void createStart(Component canvas);\r
+\r
+ void createEnd(Component canvas);\r
+\r
+ boolean isCompleted();\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.shape;\r
+\r
+import java.awt.Color;\r
+import java.awt.Component;\r
+import java.awt.Graphics;\r
+import java.awt.event.MouseAdapter;\r
+import java.awt.event.MouseEvent;\r
+import java.awt.event.MouseListener;\r
+import java.awt.event.MouseMotionAdapter;\r
+import java.awt.event.MouseMotionListener;\r
+import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.List;\r
+\r
+import jp.gr.java_conf.u6k.online_stg_env.ImmutablePoint;\r
+\r
+@ShapeName(value = "自由線")\r
+@ShapeIcon(resourceName = "resources/FreehandLineShape.gif")\r
+@ShapeDescription(value = "自由な線です。マウスの軌跡に沿って線を作成できます。")\r
+public class FreehandLineShape implements BaseShape {\r
+\r
+ private List<ShapePropertyChangeListener> listenerList = new ArrayList<ShapePropertyChangeListener>();\r
+\r
+ private boolean completed;\r
+\r
+ private List<ImmutablePoint> pointList = new ArrayList<ImmutablePoint>();\r
+\r
+ private Color color = Color.BLACK;\r
+\r
+ private MouseListener l1;\r
+\r
+ private MouseMotionListener l2;\r
+\r
+ public void addShapePropertyChangeListener(ShapePropertyChangeListener l) {\r
+ if (l == null) {\r
+ throw new NullPointerException("l == null");\r
+ }\r
+ this.listenerList.add(l);\r
+ }\r
+\r
+ public void createEnd(Component canvas) {\r
+ canvas.removeMouseListener(this.l1);\r
+ canvas.removeMouseMotionListener(this.l2);\r
+ }\r
+\r
+ public void createStart(Component canvas) {\r
+ if (this.isCompleted()) {\r
+ throw new IllegalStateException("already completed.");\r
+ }\r
+\r
+ this.l1 = new MouseAdapterImpl();\r
+ this.l2 = new MouseMotionAdapterImpl();\r
+\r
+ canvas.addMouseListener(this.l1);\r
+ canvas.addMouseMotionListener(this.l2);\r
+ }\r
+\r
+ public void draw(Graphics g) {\r
+ List<ImmutablePoint> pl = this.getPointList();\r
+ if (pl.size() < 2) {\r
+ return;\r
+ }\r
+ if (this.getColor() == null) {\r
+ throw new IllegalStateException("color == null");\r
+ }\r
+\r
+ g.setColor(this.getColor());\r
+ for (int i = 0; i < (pl.size() - 1); i++) {\r
+ ImmutablePoint p1 = pl.get(i);\r
+ ImmutablePoint p2 = pl.get(i + 1);\r
+ g.drawLine(p1.getX(), p1.getY(), p2.getX(), p2.getY());\r
+ }\r
+ }\r
+\r
+ public boolean isCompleted() {\r
+ return this.completed;\r
+ }\r
+\r
+ private void setCompleted(boolean completed) {\r
+ boolean oldCompleted = this.completed;\r
+ this.completed = completed;\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "completed", oldCompleted, completed);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+ public void removeShapePropertyChangeListener(ShapePropertyChangeListener l) {\r
+ if (l == null) {\r
+ throw new NullPointerException("l == null");\r
+ }\r
+ this.listenerList.remove(l);\r
+ }\r
+\r
+ @ShapeProperty\r
+ public Color getColor() {\r
+ return this.color;\r
+ }\r
+\r
+ @ShapeProperty\r
+ public void setColor(Color color) {\r
+ if (color == null) {\r
+ throw new NullPointerException("color == null");\r
+ }\r
+\r
+ Color oldColor = this.color;\r
+ this.color = color;\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "color", oldColor, color);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+ @ShapeProperty\r
+ public List<ImmutablePoint> getPointList() {\r
+ return Collections.unmodifiableList(this.pointList);\r
+ }\r
+\r
+ public void addPoint(ImmutablePoint point) {\r
+ if (point == null) {\r
+ throw new NullPointerException("point == null");\r
+ }\r
+\r
+ this.pointList.add(point);\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "pointList", null, point);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+ private class MouseAdapterImpl extends MouseAdapter {\r
+\r
+ @Override\r
+ public void mousePressed(MouseEvent e) {\r
+ if (!FreehandLineShape.this.isCompleted()) {\r
+ FreehandLineShape.this.addPoint(new ImmutablePoint(e.getPoint()));\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void mouseReleased(MouseEvent e) {\r
+ if (!FreehandLineShape.this.isCompleted()) {\r
+ FreehandLineShape.this.addPoint(new ImmutablePoint(e.getPoint()));\r
+\r
+ FreehandLineShape.this.setCompleted(true);\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+ private class MouseMotionAdapterImpl extends MouseMotionAdapter {\r
+\r
+ @Override\r
+ public void mouseDragged(MouseEvent e) {\r
+ if (!FreehandLineShape.this.isCompleted()) {\r
+ FreehandLineShape.this.addPoint(new ImmutablePoint(e.getPoint()));\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.shape;\r
+\r
+import java.awt.Color;\r
+import java.awt.Component;\r
+import java.awt.Graphics;\r
+import java.awt.event.MouseAdapter;\r
+import java.awt.event.MouseEvent;\r
+import java.awt.event.MouseListener;\r
+import java.awt.event.MouseMotionAdapter;\r
+import java.awt.event.MouseMotionListener;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import jp.gr.java_conf.u6k.online_stg_env.ImmutablePoint;\r
+\r
+@ShapeName(value = "直線")\r
+@ShapeIcon(resourceName = "resources/LineShape.gif")\r
+@ShapeDescription(value = "直線です。")\r
+public class LineShape implements BaseShape {\r
+\r
+ private List<ShapePropertyChangeListener> listenerList = new ArrayList<ShapePropertyChangeListener>();\r
+\r
+ private boolean completed;\r
+\r
+ private ImmutablePoint point1;\r
+\r
+ private ImmutablePoint point2;\r
+\r
+ private Color color = Color.BLACK;\r
+\r
+ private MouseListener l1;\r
+\r
+ private MouseMotionListener l2;\r
+\r
+ public void addShapePropertyChangeListener(ShapePropertyChangeListener l) {\r
+ if (l == null) {\r
+ throw new NullPointerException("l == null");\r
+ }\r
+ this.listenerList.add(l);\r
+ }\r
+\r
+ public void createEnd(Component canvas) {\r
+ canvas.removeMouseListener(this.l1);\r
+ canvas.removeMouseMotionListener(this.l2);\r
+ }\r
+\r
+ public void createStart(Component canvas) {\r
+ if (this.isCompleted()) {\r
+ throw new IllegalStateException("already completed.");\r
+ }\r
+\r
+ this.l1 = new MouseAdapterImpl();\r
+ this.l2 = new MouseMotionAdapterImpl();\r
+\r
+ canvas.addMouseListener(this.l1);\r
+ canvas.addMouseMotionListener(this.l2);\r
+ }\r
+\r
+ public void draw(Graphics g) {\r
+ if (this.getPoint1() == null || this.getPoint2() == null) {\r
+ return;\r
+ }\r
+ if (this.getColor() == null) {\r
+ throw new IllegalStateException("color == null");\r
+ }\r
+\r
+ g.setColor(this.color);\r
+ g.drawLine(this.getPoint1().getX(), this.getPoint1().getY(), this.getPoint2().getX(), this.getPoint2().getY());\r
+ }\r
+\r
+ public boolean isCompleted() {\r
+ return this.completed;\r
+ }\r
+\r
+ private void setCompleted(boolean completed) {\r
+ boolean oldCompleted = this.completed;\r
+ this.completed = completed;\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "completed", oldCompleted, completed);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+ public void removeShapePropertyChangeListener(ShapePropertyChangeListener l) {\r
+ if (l == null) {\r
+ throw new NullPointerException("l == null");\r
+ }\r
+ this.listenerList.remove(l);\r
+ }\r
+\r
+ @ShapeProperty\r
+ public Color getColor() {\r
+ return this.color;\r
+ }\r
+\r
+ @ShapeProperty\r
+ public void setColor(Color color) {\r
+ if (color == null) {\r
+ throw new NullPointerException("color == null");\r
+ }\r
+\r
+ Color oldColor = this.color;\r
+ this.color = color;\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "color", oldColor, color);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+ @ShapeProperty\r
+ public ImmutablePoint getPoint1() {\r
+ return this.point1;\r
+ }\r
+\r
+ public void setPoint1(ImmutablePoint point1) {\r
+ if (point1 == null) {\r
+ throw new NullPointerException("point1 == null");\r
+ }\r
+\r
+ ImmutablePoint oldPoint1 = this.point1;\r
+ this.point1 = point1;\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "point1", oldPoint1, point1);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+ @ShapeProperty\r
+ public ImmutablePoint getPoint2() {\r
+ return this.point2;\r
+ }\r
+\r
+ public void setPoint2(ImmutablePoint point2) {\r
+ if (point2 == null) {\r
+ throw new NullPointerException("point2 == null");\r
+ }\r
+\r
+ ImmutablePoint oldPoint2 = this.point2;\r
+ this.point2 = point2;\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "point2", oldPoint2, point2);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+ private class MouseAdapterImpl extends MouseAdapter {\r
+\r
+ @Override\r
+ public void mousePressed(MouseEvent e) {\r
+ if (!LineShape.this.completed) {\r
+ LineShape.this.setPoint1(new ImmutablePoint(e.getPoint()));\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void mouseReleased(MouseEvent e) {\r
+ if (!LineShape.this.completed) {\r
+ if (LineShape.this.getPoint1() == null) {\r
+ throw new IllegalStateException("point1 == null");\r
+ }\r
+\r
+ LineShape.this.setPoint2(new ImmutablePoint(e.getPoint()));\r
+\r
+ LineShape.this.setCompleted(true);\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+ private class MouseMotionAdapterImpl extends MouseMotionAdapter {\r
+\r
+ @Override\r
+ public void mouseDragged(MouseEvent e) {\r
+ if (!LineShape.this.completed) {\r
+ if (LineShape.this.getPoint1() == null) {\r
+ throw new IllegalStateException("point1 == null");\r
+ }\r
+\r
+ LineShape.this.setPoint2(new ImmutablePoint(e.getPoint()));\r
+ }\r
+ }\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.shape;\r
+\r
+import java.awt.Color;\r
+import java.awt.Component;\r
+import java.awt.Graphics;\r
+import java.awt.event.MouseAdapter;\r
+import java.awt.event.MouseEvent;\r
+import java.awt.event.MouseListener;\r
+import java.awt.event.MouseMotionAdapter;\r
+import java.awt.event.MouseMotionListener;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import jp.gr.java_conf.u6k.online_stg_env.ImmutableDimension;\r
+import jp.gr.java_conf.u6k.online_stg_env.ImmutablePoint;\r
+import jp.gr.java_conf.u6k.online_stg_env.ImmutableRectangle;\r
+\r
+@ShapeName(value="円(楕円)")\r
+@ShapeIcon(resourceName="resources/OvalShape.gif")\r
+@ShapeDescription(value="円(楕円)です。")\r
+public class OvalShape implements BaseShape {\r
+\r
+ private List<ShapePropertyChangeListener> listenerList = new ArrayList<ShapePropertyChangeListener>();\r
+\r
+ private boolean completed;\r
+\r
+ private ImmutablePoint location;\r
+\r
+ private ImmutableDimension size;\r
+\r
+ private Color borderColor = Color.BLACK;\r
+\r
+ private Color contentColor;\r
+\r
+ private MouseListener l1;\r
+\r
+ private MouseMotionListener l2;\r
+\r
+ public void addShapePropertyChangeListener(ShapePropertyChangeListener l) {\r
+ if (l == null) {\r
+ throw new NullPointerException("l == null");\r
+ }\r
+ this.listenerList.add(l);\r
+ }\r
+\r
+ public void createEnd(Component canvas) {\r
+ canvas.removeMouseListener(this.l1);\r
+ canvas.removeMouseMotionListener(this.l2);\r
+ }\r
+\r
+ public void createStart(Component canvas) {\r
+ if (this.isCompleted()) {\r
+ throw new IllegalStateException("already completed.");\r
+ }\r
+\r
+ this.l1 = new MouseAdapterImpl();\r
+ this.l2 = new MouseMotionAdapterImpl();\r
+\r
+ canvas.addMouseListener(this.l1);\r
+ canvas.addMouseMotionListener(this.l2);\r
+ }\r
+\r
+ public void draw(Graphics g) {\r
+ if (this.getLocation() == null || this.getSize() == null) {\r
+ return;\r
+ }\r
+ if (this.getBorderColor() == null) {\r
+ throw new IllegalStateException("borderColor == null");\r
+ }\r
+\r
+ ImmutablePoint p1 = this.location;\r
+ ImmutablePoint p2 = new ImmutablePoint(p1.getX() + this.getSize().getWidth(), p1.getY() + this.getSize().getHeight());\r
+ ImmutableRectangle r = ImmutableRectangle.normalize(p1, p2);\r
+\r
+ if (this.getContentColor() != null) {\r
+ g.setColor(this.getContentColor());\r
+ g.fillOval(r.getX(), r.getY(), r.getWidth(), r.getHeight());\r
+ }\r
+\r
+ g.setColor(this.getBorderColor());\r
+ g.drawOval(r.getX(), r.getY(), r.getWidth(), r.getHeight());\r
+ }\r
+\r
+ public boolean isCompleted() {\r
+ return this.completed;\r
+ }\r
+\r
+ private void setCompleted(boolean completed) {\r
+ boolean oldCompleted = this.completed;\r
+ this.completed = completed;\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "completed", oldCompleted, completed);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+ public void removeShapePropertyChangeListener(ShapePropertyChangeListener l) {\r
+ if (l == null) {\r
+ throw new NullPointerException("l == null");\r
+ }\r
+ this.listenerList.remove(l);\r
+ }\r
+\r
+ @ShapeProperty\r
+ public ImmutablePoint getLocation() {\r
+ return this.location;\r
+ }\r
+\r
+ public void setLocation(ImmutablePoint location) {\r
+ if (location == null) {\r
+ throw new NullPointerException("location == null");\r
+ }\r
+\r
+ ImmutablePoint oldLocation = this.location;\r
+ this.location = location;\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "location", oldLocation, location);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+ @ShapeProperty\r
+ public ImmutableDimension getSize() {\r
+ return this.size;\r
+ }\r
+\r
+ public void setSize(ImmutableDimension size) {\r
+ if (size == null) {\r
+ throw new NullPointerException("size == null");\r
+ }\r
+\r
+ ImmutableDimension oldSize = this.size;\r
+ this.size = size;\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "size", oldSize, size);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+ @ShapeProperty\r
+ public Color getBorderColor() {\r
+ return this.borderColor;\r
+ }\r
+\r
+ @ShapeProperty\r
+ public void setBorderColor(Color borderColor) {\r
+ if (borderColor == null) {\r
+ throw new NullPointerException("borderColor == null");\r
+ }\r
+\r
+ Color oldBorderColor = this.borderColor;\r
+ this.borderColor = borderColor;\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "borderColor", oldBorderColor, borderColor);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+ @ShapeProperty\r
+ public Color getContentColor() {\r
+ return this.contentColor;\r
+ }\r
+\r
+ @ShapeProperty\r
+ public void setContentColor(Color contentColor) {\r
+ if (contentColor == null) {\r
+ throw new NullPointerException("contentColor == null");\r
+ }\r
+\r
+ Color oldContentColor = this.contentColor;\r
+ this.contentColor = contentColor;\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "contentColor", oldContentColor, contentColor);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+ private class MouseAdapterImpl extends MouseAdapter {\r
+\r
+ @Override\r
+ public void mousePressed(MouseEvent e) {\r
+ if (!OvalShape.this.isCompleted()) {\r
+ OvalShape.this.setLocation(new ImmutablePoint(e.getPoint()));\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void mouseReleased(MouseEvent e) {\r
+ if (!OvalShape.this.isCompleted()) {\r
+ if (OvalShape.this.getLocation() == null) {\r
+ throw new IllegalStateException("location == null");\r
+ }\r
+\r
+ OvalShape.this.setSize(new ImmutableDimension(e.getX() - OvalShape.this.getLocation().getX(), e.getY() - OvalShape.this.getLocation().getY()));\r
+\r
+ OvalShape.this.setCompleted(true);\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+ private class MouseMotionAdapterImpl extends MouseMotionAdapter {\r
+\r
+ @Override\r
+ public void mouseDragged(MouseEvent e) {\r
+ if (!OvalShape.this.isCompleted()) {\r
+ if (OvalShape.this.getLocation() == null) {\r
+ throw new IllegalStateException("location == null");\r
+ }\r
+\r
+ OvalShape.this.setSize(new ImmutableDimension(e.getX() - OvalShape.this.getLocation().getX(), e.getY() - OvalShape.this.getLocation().getY()));\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.shape;\r
+\r
+import java.awt.Color;\r
+import java.awt.Component;\r
+import java.awt.Graphics;\r
+import java.awt.event.MouseAdapter;\r
+import java.awt.event.MouseEvent;\r
+import java.awt.event.MouseListener;\r
+import java.awt.event.MouseMotionAdapter;\r
+import java.awt.event.MouseMotionListener;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import jp.gr.java_conf.u6k.online_stg_env.ImmutableDimension;\r
+import jp.gr.java_conf.u6k.online_stg_env.ImmutablePoint;\r
+import jp.gr.java_conf.u6k.online_stg_env.ImmutableRectangle;\r
+\r
+@ShapeName(value="四角形(長方形)")\r
+@ShapeIcon(resourceName="resources/RectangleShape.gif")\r
+@ShapeDescription(value="四角形(長方形)です。")\r
+public class RectangleShape implements BaseShape {\r
+\r
+ private List<ShapePropertyChangeListener> listenerList = new ArrayList<ShapePropertyChangeListener>();\r
+\r
+ private boolean completed;\r
+\r
+ private ImmutablePoint location;\r
+\r
+ private ImmutableDimension size;\r
+\r
+ private Color borderColor = Color.BLACK;\r
+\r
+ private Color contentColor = null;\r
+\r
+ private MouseListener l1;\r
+\r
+ private MouseMotionListener l2;\r
+\r
+ public void addShapePropertyChangeListener(ShapePropertyChangeListener l) {\r
+ if (l == null) {\r
+ throw new NullPointerException("l == null");\r
+ }\r
+ this.listenerList.add(l);\r
+ }\r
+\r
+ public void createEnd(Component canvas) {\r
+ canvas.removeMouseListener(this.l1);\r
+ canvas.removeMouseMotionListener(this.l2);\r
+ }\r
+\r
+ public void createStart(Component canvas) {\r
+ if (this.isCompleted()) {\r
+ throw new IllegalStateException("already completed.");\r
+ }\r
+\r
+ this.l1 = new MouseAdapterImpl();\r
+ this.l2 = new MouseMotionAdapterImpl();\r
+\r
+ canvas.addMouseListener(this.l1);\r
+ canvas.addMouseMotionListener(this.l2);\r
+ }\r
+\r
+ public void draw(Graphics g) {\r
+ if (this.getLocation() == null || this.getSize() == null) {\r
+ return;\r
+ }\r
+ if (this.getBorderColor() == null) {\r
+ throw new IllegalStateException("borderColor == null");\r
+ }\r
+\r
+ ImmutablePoint p1 = this.location;\r
+ ImmutablePoint p2 = new ImmutablePoint(p1.getX() + this.getSize().getWidth(), p1.getY() + this.getSize().getHeight());\r
+ ImmutableRectangle r = ImmutableRectangle.normalize(p1, p2);\r
+\r
+ if (this.getContentColor() != null) {\r
+ g.setColor(this.getContentColor());\r
+ g.fillRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());\r
+ }\r
+\r
+ g.setColor(this.getBorderColor());\r
+ g.drawRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());\r
+ }\r
+\r
+ public boolean isCompleted() {\r
+ return this.completed;\r
+ }\r
+\r
+ private void setCompleted(boolean completed) {\r
+ boolean oldCompleted = this.completed;\r
+ this.completed = completed;\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "completed", oldCompleted, completed);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+ public void removeShapePropertyChangeListener(ShapePropertyChangeListener l) {\r
+ if (l == null) {\r
+ throw new NullPointerException("l == null");\r
+ }\r
+ this.listenerList.remove(l);\r
+ }\r
+\r
+ @ShapeProperty\r
+ public ImmutablePoint getLocation() {\r
+ return this.location;\r
+ }\r
+\r
+ public void setLocation(ImmutablePoint location) {\r
+ if (location == null) {\r
+ throw new NullPointerException("location == null");\r
+ }\r
+\r
+ ImmutablePoint oldLocation = this.location;\r
+ this.location = location;\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "location", oldLocation, location);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+ @ShapeProperty\r
+ public ImmutableDimension getSize() {\r
+ return this.size;\r
+ }\r
+\r
+ public void setSize(ImmutableDimension size) {\r
+ if (size == null) {\r
+ throw new NullPointerException("size == null");\r
+ }\r
+\r
+ ImmutableDimension oldSize = this.size;\r
+ this.size = size;\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "size", oldSize, size);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+ @ShapeProperty\r
+ public Color getBorderColor() {\r
+ return this.borderColor;\r
+ }\r
+\r
+ @ShapeProperty\r
+ public void setBorderColor(Color borderColor) {\r
+ if (borderColor == null) {\r
+ throw new NullPointerException("borderColor == null");\r
+ }\r
+\r
+ Color oldBorderColor = this.borderColor;\r
+ this.borderColor = borderColor;\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "borderColor", oldBorderColor, borderColor);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+ @ShapeProperty\r
+ public Color getContentColor() {\r
+ return this.contentColor;\r
+ }\r
+\r
+ @ShapeProperty\r
+ public void setContentColor(Color contentColor) {\r
+ if (contentColor == null) {\r
+ throw new NullPointerException("contentColor == null");\r
+ }\r
+\r
+ Color oldContentColor = this.contentColor;\r
+ this.contentColor = contentColor;\r
+\r
+ ShapePropertyChangeEvent event = new ShapePropertyChangeEvent(this, "contentColor", oldContentColor, contentColor);\r
+ for (ShapePropertyChangeListener l : this.listenerList.toArray(new ShapePropertyChangeListener[0])) {\r
+ l.propertyChange(event);\r
+ }\r
+ }\r
+\r
+ private class MouseAdapterImpl extends MouseAdapter {\r
+\r
+ @Override\r
+ public void mousePressed(MouseEvent e) {\r
+ if (!RectangleShape.this.isCompleted()) {\r
+ RectangleShape.this.setLocation(new ImmutablePoint(e.getPoint()));\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public void mouseReleased(MouseEvent e) {\r
+ if (!RectangleShape.this.isCompleted()) {\r
+ if (RectangleShape.this.getLocation() == null) {\r
+ throw new IllegalStateException("location == null");\r
+ }\r
+\r
+ RectangleShape.this.setSize(new ImmutableDimension(e.getX() - RectangleShape.this.getLocation().getX(), e.getY() - RectangleShape.this.getLocation().getY()));\r
+\r
+ RectangleShape.this.setCompleted(true);\r
+ }\r
+ }\r
+ }\r
+\r
+ private class MouseMotionAdapterImpl extends MouseMotionAdapter {\r
+\r
+ @Override\r
+ public void mouseDragged(MouseEvent e) {\r
+ if (!RectangleShape.this.isCompleted()) {\r
+ if (RectangleShape.this.getLocation() == null) {\r
+ throw new IllegalStateException("location == null");\r
+ }\r
+\r
+ RectangleShape.this.setSize(new ImmutableDimension(e.getX() - RectangleShape.this.getLocation().getX(), e.getY() - RectangleShape.this.getLocation().getY()));\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.shape;\r
+\r
+import java.lang.annotation.ElementType;\r
+import java.lang.annotation.Retention;\r
+import java.lang.annotation.RetentionPolicy;\r
+import java.lang.annotation.Target;\r
+\r
+@Target(ElementType.TYPE)\r
+@Retention(RetentionPolicy.RUNTIME)\r
+public @interface ShapeDescription {\r
+\r
+ String value() default "";\r
+\r
+ String resourceBaseName() default "";\r
+\r
+ String resourceKey() default "";\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.shape;\r
+\r
+import java.lang.annotation.ElementType;\r
+import java.lang.annotation.Retention;\r
+import java.lang.annotation.RetentionPolicy;\r
+import java.lang.annotation.Target;\r
+\r
+@Target(ElementType.TYPE)\r
+@Retention(RetentionPolicy.RUNTIME)\r
+public @interface ShapeIcon {\r
+\r
+ String resourceName() default "";\r
+\r
+ String url() default "";\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.shape;\r
+\r
+import java.lang.annotation.ElementType;\r
+import java.lang.annotation.Retention;\r
+import java.lang.annotation.RetentionPolicy;\r
+import java.lang.annotation.Target;\r
+\r
+@Target(ElementType.TYPE)\r
+@Retention(RetentionPolicy.RUNTIME)\r
+public @interface ShapeName {\r
+\r
+ String value() default "";\r
+\r
+ String resourceBaseName() default "";\r
+\r
+ String resourceKey() default "";\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.shape;\r
+\r
+import java.lang.annotation.ElementType;\r
+import java.lang.annotation.Retention;\r
+import java.lang.annotation.RetentionPolicy;\r
+import java.lang.annotation.Target;\r
+\r
+@Retention(RetentionPolicy.RUNTIME)\r
+@Target(ElementType.METHOD)\r
+public @interface ShapeProperty {\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.shape;\r
+\r
+public class ShapePropertyChangeEvent {\r
+\r
+ private BaseShape source;\r
+\r
+ private String propertyName;\r
+\r
+ private Object oldValue;\r
+\r
+ private Object newValue;\r
+\r
+ public ShapePropertyChangeEvent(BaseShape source, String propertyName, Object oldValue, Object newValue) {\r
+ this.source = source;\r
+ this.propertyName = propertyName;\r
+ this.oldValue = oldValue;\r
+ this.newValue = newValue;\r
+ }\r
+\r
+ public BaseShape getSource() {\r
+ return this.source;\r
+ }\r
+\r
+ public String getPropertyName() {\r
+ return this.propertyName;\r
+ }\r
+\r
+ public Object getOldValue() {\r
+ return this.oldValue;\r
+ }\r
+\r
+ public Object getNewValue() {\r
+ return this.newValue;\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.shape;\r
+\r
+public interface ShapePropertyChangeListener {\r
+\r
+ void propertyChange(ShapePropertyChangeEvent event);\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.shape.reflect;\r
+\r
+import java.beans.IntrospectionException;\r
+import java.net.MalformedURLException;\r
+import java.net.URL;\r
+import java.util.ResourceBundle;\r
+\r
+import javax.swing.Icon;\r
+import javax.swing.ImageIcon;\r
+\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.BaseShape;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.ShapeDescription;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.ShapeIcon;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.ShapeName;\r
+\r
+public class ShapeDescriptor {\r
+\r
+ private String name;\r
+\r
+ private Icon icon;\r
+\r
+ private String description;\r
+\r
+ public ShapeDescriptor(Class<? extends BaseShape> shapeClazz) throws IntrospectionException, MalformedURLException {\r
+ if (shapeClazz == null) {\r
+ throw new NullPointerException("shapeClazz == null");\r
+ }\r
+\r
+ if (shapeClazz.getAnnotation(ShapeName.class) != null) {\r
+ ShapeName nameAnno = shapeClazz.getAnnotation(ShapeName.class);\r
+\r
+ if (!"".equals(nameAnno.value())) {\r
+ this.name = nameAnno.value();\r
+ } else if (!"".equals(nameAnno.resourceBaseName()) && !"".equals(nameAnno.resourceKey())) {\r
+ this.name = ResourceBundle.getBundle(nameAnno.resourceBaseName()).getString(nameAnno.resourceKey());\r
+ } else {\r
+ throw new IntrospectionException("「" + shapeClazz.getName() + "」型に対するShapeNameアノテーションの属性の指定が間違えています。");\r
+ }\r
+ } else {\r
+ this.name = shapeClazz.getSimpleName();\r
+ }\r
+\r
+ if (shapeClazz.getAnnotation(ShapeIcon.class) != null) {\r
+ ShapeIcon iconAnno = shapeClazz.getAnnotation(ShapeIcon.class);\r
+\r
+ if (!"".equals(iconAnno.resourceName())) {\r
+ this.icon = new ImageIcon(this.getClass().getClassLoader().getResource(iconAnno.resourceName()));\r
+ } else if (!"".equals(iconAnno.url())) {\r
+ this.icon = new ImageIcon(new URL(iconAnno.url()));\r
+ } else {\r
+ throw new IntrospectionException("「" + shapeClazz.getName() + "」型に対するShapeIconアノテーションの属性の指定が間違えています。");\r
+ }\r
+ } else {\r
+ this.icon = null;\r
+ }\r
+\r
+ if (shapeClazz.getAnnotation(ShapeDescription.class) != null) {\r
+ ShapeDescription descAnno = shapeClazz.getAnnotation(ShapeDescription.class);\r
+\r
+ if (!"".equals(descAnno.value())) {\r
+ this.description = descAnno.value();\r
+ } else if (!"".equals(descAnno.resourceBaseName()) && !"".equals(descAnno.resourceKey())) {\r
+ this.description = ResourceBundle.getBundle(descAnno.resourceBaseName()).getString(descAnno.resourceKey());\r
+ } else {\r
+ throw new IntrospectionException("「" + shapeClazz.getName() + "」型に対するShapeDescriptionアノテーションの属性の指定が間違えています。");\r
+ }\r
+ } else {\r
+ this.description = null;\r
+ }\r
+ }\r
+\r
+ public String getName() {\r
+ return this.name;\r
+ }\r
+\r
+ public Icon getIcon() {\r
+ return this.icon;\r
+ }\r
+\r
+ public String getDescription() {\r
+ return this.description;\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.shape.reflect;\r
+\r
+import java.beans.IntrospectionException;\r
+import java.lang.reflect.Method;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.Locale;\r
+\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.BaseShape;\r
+import jp.gr.java_conf.u6k.online_stg_env.shape.ShapeProperty;\r
+\r
+public class ShapePropertyDescriptor {\r
+\r
+ private String name;\r
+\r
+ private Class<?> type;\r
+\r
+ private Method getterMethod;\r
+\r
+ private Method setterMethod;\r
+\r
+ public ShapePropertyDescriptor(String name, Class<? extends BaseShape> shapeClazz) throws NoSuchMethodException, IntrospectionException {\r
+ if (name == null) {\r
+ throw new NullPointerException("name == null");\r
+ }\r
+ if (shapeClazz == null) {\r
+ throw new NullPointerException("shapeClazz == null");\r
+ }\r
+\r
+ String propertyBaseName = name.substring(0, 1).toUpperCase(Locale.getDefault()) + name.substring(1);\r
+ this.getterMethod = this.getMethod(shapeClazz, "get" + propertyBaseName);\r
+ if (this.getterMethod == null) {\r
+ this.getterMethod = this.getMethod(shapeClazz, "is" + propertyBaseName);\r
+ if (this.getterMethod == null) {\r
+ throw new NoSuchMethodException("「get" + propertyBaseName + "」メソッド、及び「is" + propertyBaseName + "」メソッドが見つかりませんでした。");\r
+ }\r
+ }\r
+\r
+ if (this.getterMethod.getAnnotation(ShapeProperty.class) == null) {\r
+ throw new IntrospectionException("「" + this.getterMethod.getName() + "」メソッドはShapePropertyアノテーションを付加されていません。");\r
+ }\r
+\r
+ this.name = propertyBaseName.substring(0, 1).toLowerCase(Locale.getDefault()) + propertyBaseName.substring(1);\r
+\r
+ this.type = this.getterMethod.getReturnType();\r
+\r
+ this.setterMethod = this.getMethod(shapeClazz, "set" + propertyBaseName, this.type);\r
+ if (this.setterMethod != null) {\r
+ if (this.setterMethod.getAnnotation(ShapeProperty.class) == null) {\r
+ this.setterMethod = null;\r
+ }\r
+ }\r
+ }\r
+\r
+ private Method getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) {\r
+ try {\r
+ return clazz.getMethod(methodName, parameterTypes);\r
+ } catch (SecurityException e) {\r
+ return null;\r
+ } catch (NoSuchMethodException e) {\r
+ return null;\r
+ }\r
+ }\r
+\r
+ public String getName() {\r
+ return this.name;\r
+ }\r
+\r
+ public Class<?> getType() {\r
+ return this.type;\r
+ }\r
+\r
+ public Method getGetterMethod() {\r
+ return this.getterMethod;\r
+ }\r
+\r
+ public Method getSetterMethod() {\r
+ return this.setterMethod;\r
+ }\r
+\r
+ public static List<ShapePropertyDescriptor> getPropertyDescriptorList(Class<? extends BaseShape> shapeClazz) {\r
+ if (shapeClazz == null) {\r
+ throw new NullPointerException("shapeClazz == null");\r
+ }\r
+\r
+ List<ShapePropertyDescriptor> l = new ArrayList<ShapePropertyDescriptor>();\r
+\r
+ for (Method m : shapeClazz.getMethods()) {\r
+ String n = null;\r
+ if (m.getName().startsWith("get")) {\r
+ n = m.getName().substring("get".length());\r
+ n = n.substring(0, 1).toLowerCase(Locale.getDefault()) + n.substring(1);\r
+ } else if (m.getName().startsWith("is")) {\r
+ n = m.getName().substring("is".length());\r
+ n = n.substring(0, 1).toLowerCase(Locale.getDefault()) + n.substring(1);\r
+ }\r
+ if (n != null) {\r
+ if (m.getAnnotation(ShapeProperty.class) != null) {\r
+ try {\r
+ l.add(new ShapePropertyDescriptor(n, shapeClazz));\r
+ } catch (NoSuchMethodException e) {\r
+ e.printStackTrace();\r
+ } catch (IntrospectionException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ return l;\r
+ }\r
+\r
+}\r
--- /dev/null
+\r
+package jp.gr.java_conf.u6k.online_stg_env.shape.reflect;\r
+\r
+import java.util.Comparator;\r
+\r
+public class ShapePropertyDescriptorComparator implements Comparator<ShapePropertyDescriptor> {\r
+\r
+ public int compare(ShapePropertyDescriptor o1, ShapePropertyDescriptor o2) {\r
+ return o1.getName().compareTo(o2.getName());\r
+ }\r
+\r
+}\r
--- /dev/null
+deny from all\r
--- /dev/null
+<?php\r
+/**\r
+ * $data\88ø\90\94\82Ì\92l\82ðXML\8c`\8e®\82Ì\95¶\8e\9a\97ñ\82É\95Ï\8a·\82µ\82Ü\82·\81B\r
+ * \96ß\82è\92l\82ÌXML\95¶\8e\9a\97ñ\82ÍWeb API\82Ì\96ß\82è\92l\82Æ\82µ\82Ä\8eg\97p\82³\82ê\82é\82±\82Æ\82ð\91z\92è\82µ\82Ä\82¢\82Ü\82·\81B\r
+ * \r
+ * @param mixed $data\r
+ * \95Ï\8a·\82·\82é\92l\81B\r
+ * @return \95Ï\8a·\82³\82ê\82½XML\8c`\8e®\82Ì\95¶\8e\9a\97ñ\81B\r
+ */\r
+function return_xml($data) {\r
+ $d = return_xml0($data);\r
+ $str = "<return type=\"" . $d["type"] . "\">" . $d["data"] . "</return>";\r
+ return $str;\r
+}\r
+\r
+function return_xml0($data) {\r
+ $returnData = array();\r
+ if (is_array($data)) {\r
+ $returnData["type"] = "map";\r
+ $returnData["data"] = "";\r
+ foreach ($data as $k => $v) {\r
+ $d = return_xml0($v);\r
+ $returnData["data"] .= "<" . $k . " type=\"" . $d["type"] . "\">" . $d["data"] . "</" . $k . ">";\r
+ }\r
+ } elseif (is_int($data)) {\r
+ $returnData["type"] = "integer";\r
+ $returnData["data"] = strval($data);\r
+ } elseif (is_float($data)) {\r
+ $returnData["type"] = "float";\r
+ $returnData["data"] = strval($data);\r
+ } elseif (is_bool($data)) {\r
+ $returnData["type"] = "boolean";\r
+ if ($data) {\r
+ $returnData["data"] = "true";\r
+ } else {\r
+ $returnData["data"] = "false";\r
+ }\r
+ } elseif (is_string($data)) {\r
+ $returnData["type"] = "string";\r
+ $returnData["data"] = rawurlencode($data);\r
+ } else {\r
+ $returnData["type"] = "other";\r
+ $returnData["data"] = rawurlencode(strval($data));\r
+ }\r
+ return $returnData;\r
+}\r
+\r
+/**\r
+ * \83G\83\89\81[\82ª\94\90¶\82µ\82½\82±\82Æ\82ð\95\\82·XML\8c`\8e®\82Ì\95¶\8e\9a\97ñ\82ð$g_error_xml\83O\83\8d\81[\83o\83\8b\95Ï\90\94\82É\8fo\97Í\82µ\81AFALSE\82ð\95Ô\82µ\82Ü\82·\81B\r
+ * $g_error_xml\83O\83\8d\81[\83o\83\8b\95Ï\90\94\82É\8fo\97Í\82³\82ê\82éXML\95¶\8e\9a\97ñ\82ÍWeb API\82Ì\96ß\82è\92l\82Æ\82µ\82Ä\8eg\97p\82³\82ê\82é\82±\82Æ\82ð\91z\92è\82µ\82Ä\82¢\82Ü\82·\81B\r
+ * \r
+ * @param string $errorType\r
+ * \83G\83\89\81[\82Ì\8eí\97Þ\81B\8b@\8aB\93I\82É\93Ç\82Ý\8eæ\82è\82â\82·\82¢\88ê\88Ó\82Ì\8e¯\95Ê\95¶\8e\9a\97ñ\82ð\8ew\92è\82µ\82Ä\82\82¾\82³\82¢\81B\82 \82ç\82©\82¶\82ß\92è\90\94\82É\82µ\82Ä\82¨\82\82Æ\8f®\97Ç\82¢\82Å\82·\81B\r
+ * @param string $errorMessage\r
+ * \83G\83\89\81[\82Ì\8fÚ\8d×\82È\90à\96¾\81B\r
+ * @param mixed $data\r
+ * \83G\83\89\81[\82Ì\82»\82Ì\91¼\82Ì\8fî\95ñ\81Breturn_xml()\8aÖ\90\94\82Æ\93¯\82¶\8c`\8e®\82ÌXML\95¶\8e\9a\97ñ\82É\95Ï\8a·\82³\82ê\82Ü\82·\81B\r
+ * @return \8fí\82ÉFALSE\81B\r
+ */\r
+function error_xml($errorType, $errorMessage, $data = null) {\r
+ $str = "<error type=\"map\"><type type=\"string\">" . rawurlencode($errorType) . "</type>";\r
+ if (!empty($errorMessage)) {\r
+ $str .= "<message type=\"string\">" . rawurlencode($errorMessage) . "</message>";\r
+ }\r
+ if (!empty($data)) {\r
+ $d = return_xml0($data);\r
+ $str .= "<data type=\"" . $d["type"] . "\">" . $d["data"] . "</data>";\r
+ }\r
+ $str .= "</error>";\r
+ \r
+ global $g_error_xml;\r
+ $g_error_xml = $str;\r
+ \r
+ return FALSE;\r
+}\r
+\r
+/*\r
+ * \92è\90\94\r
+ */\r
+define("ERROR_AUTH_FAIL", "auth fail");\r
+define("ERROR_NOT_CHALLENGE", "not challenge");\r
+define("ERROR_IO", "io error");\r
+define("ERROR_AUTH", "auth fail");\r
+define("ERROR_EMPTY", "empty");\r
+define("ERROR_POST_WRONG", "post is wrong");\r
+\r
+/*\r
+ * \83O\83\8d\81[\83o\83\8b\95Ï\90\94\r
+ */\r
+$g_error_xml;\r
+?>\r
--- /dev/null
+<?php\r
+require_once("./app/common.inc");\r
+require_once("./app/get_challenge.inc");\r
+require_once("./app/login.inc");\r
+require_once("./app/open_data_file.inc");\r
+require_once("./app/read_data_file.inc");\r
+require_once("./app/write_data_file.inc");\r
+\r
+session_start();\r
+\r
+$method = $_POST["method"];\r
+\r
+if ("get_challenge" == $method) {\r
+ $challenge = get_challenge();\r
+ $_SESSION["challenge"] = $challenge;\r
+ echo return_xml($challenge);\r
+} elseif ("login" == $method) {\r
+ $username = $_POST["username"];\r
+ $password = $_POST["password"];\r
+ $challenge = $_SESSION["challenge"];\r
+ $_SESSION["challenge"] = null;\r
+ \r
+ if (TRUE == login($username, $password, $challenge)) {\r
+ $_SESSION["username"] = $username;\r
+ echo return_xml(TRUE);\r
+ } else {\r
+ echo $g_error_xml;\r
+ }\r
+} else {\r
+ $username = $_SESSION["username"];\r
+ if (empty($username)) {\r
+ error_xml(ERROR_AUTH, "login first.");\r
+ echo $g_error_xml;\r
+ } else {\r
+ if ("read_data_file" == $method) {\r
+ if (FALSE === ($content = read_data_file($username))) {\r
+ echo $g_error_xml;\r
+ } else {\r
+ echo return_xml($content);\r
+ }\r
+ } elseif ("write_data_file" == $method) {\r
+ $data = rawurldecode($_POST["data"]);\r
+ if (FALSE == write_data_file($username, $data)) {\r
+ echo $g_error_xml;\r
+ } else {\r
+ echo return_xml(TRUE);\r
+ }\r
+ } else {\r
+ error_xml(ERROR_POST_WRONG, "method is wrong.");\r
+ echo $g_error_xml;\r
+ }\r
+ }\r
+}\r
+?>\r
--- /dev/null
+<?php\r
+require_once("./app/common.inc");\r
+\r
+/**\r
+ * \83`\83\83\83\8c\83\93\83W\83R\81[\83h\82ð\90¶\90¬\82µ\82Ü\82·\81B\r
+ * \83Z\83b\83V\83\87\83\93\82Ö\82Ì\8ai\94[\82Í\8cÄ\82Ñ\8fo\82µ\91¤\82ª\8ds\82Á\82Ä\82\82¾\82³\82¢\81B\r
+ * \r
+ * @return \90¶\90¬\82µ\82½\83`\83\83\83\8c\83\93\83W\83R\81[\83h\81B\r
+ */\r
+function get_challenge() {\r
+ return md5(uniqid(mt_rand(), true));\r
+}\r
+?>\r
--- /dev/null
+<?php\r
+require_once("./app/common.inc");\r
+\r
+/**\r
+ * \83\8d\83O\83C\83\93\82ð\8ds\82¢\82Ü\82·\81B\r
+ * \83`\83\83\83\8c\83\93\83W\83R\81[\83h\82Ì\94j\8aü\82Í\8cÄ\82Ñ\8fo\82µ\91¤\82ª\8ds\82Á\82Ä\82\82¾\82³\82¢\81B\r
+ * \82Ü\82½\81A\90¬\8c÷\82µ\82½\82Æ\82«\82Ì\83\86\81[\83U\96¼\82Ì\83Z\83b\83V\83\87\83\93\82Ö\82Ì\8ai\94[\82à\8cÄ\82Ñ\8fo\82µ\91¤\82ª\8ds\82Á\82Ä\82\82¾\82³\82¢\81B\r
+ * \83p\83X\83\8f\81[\83h\82Ì\88Ã\8d\86\89»\82Í\81u\83p\83X\83\8f\81[\83h + \83`\83\83\83\8c\83\93\83W\83R\81[\83h\81v\82ÌMD5\92l\82Å\82·\81B\r
+ * \r
+ * @param string $username\r
+ * \83\86\81[\83U\96¼\81B\r
+ * @param string $password\r
+ * \83`\83\83\83\8c\83\93\83W\83R\81[\83h\82É\82æ\82é\88Ã\8d\86\89»\83p\83X\83\8f\81[\83h\81B\r
+ * @param string $challenge\r
+ * \83Z\83b\83V\83\87\83\93\82É\95Û\8e\9d\82³\82ê\82Ä\82¢\82é\83`\83\83\83\8c\83\93\83W\83R\81[\83h\81B\r
+ * @return \90¬\8c÷\82µ\82½\8fê\8d\87\82ÍTRUE\81A\8e¸\94s\82µ\82½\8fê\8d\87\82ÍFALSE\81B\r
+ */\r
+function login($username, $password, $challenge) {\r
+ // \88ø\90\94\82ð\8am\94F\82µ\82Ü\82·\81B\r
+ if (empty($challenge)) {\r
+ return error_xml(ERROR_AUTH, "challenge code get first.");\r
+ }\r
+ \r
+ // \83\86\81[\83U\8fî\95ñ\83t\83@\83C\83\8b\82ª\91¶\8dÝ\82µ\82È\82¢\8fê\8d\87\81A\83f\83B\83\8c\83N\83g\83\8a\81A\8by\82Ñ\83t\83@\83C\83\8b\82ð\8dì\90¬\82µ\82Ü\82·\81B\r
+ $userDirPath = "./data";\r
+ $userFilePath = $userDirPath . "/user.txt";\r
+ \r
+ if (FALSE == @file_exists($userFilePath)) {\r
+ // \83f\83B\83\8c\83N\83g\83\8a\82ª\91¶\8dÝ\82µ\82È\82¢\8fê\8d\87\81A\83f\83B\83\8c\83N\83g\83\8a\82ð\8dì\90¬\82µ\82Ü\82·\81B\r
+ if (FALSE == @file_exists($userDirPath)) {\r
+ if (FALSE == @mkdir($userDirPath, 0700)) {\r
+ return error_xml(ERROR_IO, "user dir create fail.");\r
+ }\r
+ }\r
+ // \83t\83@\83C\83\8b\82ð\8dì\90¬\82µ\82Ü\82·\81B\r
+ if (FALSE == ($fp = @fopen($userFilePath, "w+b"))) {\r
+ return error_xml(ERROR_IO, "user file create fail.");\r
+ }\r
+ @fclose($fp);\r
+ }\r
+ \r
+ // \83\86\81[\83U\8fî\95ñ\82Æ\83\86\81[\83U\96¼\81A\83p\83X\83\8f\81[\83h\82ð\94ä\8ar\82µ\81A\94F\8fØ\82µ\82Ü\82·\81B\r
+ $userInfo = parse_ini_file($userFilePath);\r
+ \r
+ if (empty($userInfo[$username])) {\r
+ return error_xml(ERROR_AUTH, "username or password is wrong.");\r
+ }\r
+ \r
+ $dbPassword = md5($userInfo[$username] . $challenge);\r
+ if ($dbPassword === $password) {\r
+ return TRUE;\r
+ } else {\r
+ return error_xml(ERROR_AUTH, "username or password is wrong.");\r
+ }\r
+}\r
+?>\r
--- /dev/null
+<?php\r
+require_once("./app/common.inc");\r
+\r
+/**\r
+ * \83\86\81[\83U\82ª\95Û\8e\9d\82µ\82Ä\82¢\82é\83f\81[\83^\81E\83t\83@\83C\83\8b\82Ì\83|\83C\83\93\83^\82ð\95Ô\82µ\82Ü\82·\81B\r
+ * \r
+ * @param string $username\r
+ * \83\86\81[\83U\96¼\81B\r
+ * @param string $mode\r
+ * fopen()\8aÖ\90\94\82Ì$mode\88ø\90\94\81B\r
+ * @return \90¬\8c÷\82µ\82½\8fê\8d\87\82Í\83t\83@\83C\83\8b\81E\83|\83C\83\93\83^\81A\8e¸\94s\82µ\82½\8fê\8d\87\82ÍFALSE\81B\r
+ */\r
+function open_data_file($username, $mode) {\r
+ // \88ø\90\94\82ð\8am\94F\82µ\82Ü\82·\81B\r
+ if (empty($username)) {\r
+ return error_xml(ERROR_EMPTY, "$username is empty.");\r
+ }\r
+ \r
+ // \83t\83@\83C\83\8b\82ª\91¶\8dÝ\82µ\82È\82¢\8fê\8d\87\81A\83f\83B\83\8c\83N\83g\83\8a\81A\8by\82Ñ\83t\83@\83C\83\8b\82ð\8dì\90¬\82µ\82Ü\82·\81B\r
+ $dataDirPath = "./data/text";\r
+ $dataFilePath = $dataDirPath . "/" . $username . ".txt";\r
+ \r
+ if (FALSE == @file_exists($dataFilePath)) {\r
+ // \83f\83B\83\8c\83N\83g\83\8a\82ª\91¶\8dÝ\82µ\82È\82¢\8fê\8d\87\81A\83f\83B\83\8c\83N\83g\83\8a\82ð\8dì\90¬\82µ\82Ü\82·\81B\r
+ if (FALSE == @file_exists($dataDirPath)) {\r
+ if (FALSE == @mkdir($dataDirPath, 0700)) {\r
+ return error_xml(ERROR_IO, "data dir create fail.");\r
+ }\r
+ }\r
+ // \83t\83@\83C\83\8b\82ð\8dì\90¬\82µ\82Ü\82·\81B\r
+ if (FALSE == ($fp = @fopen($dataFilePath, "w+b"))) {\r
+ return error_xml(ERROR_IO, "data file create fail.");\r
+ }\r
+ @fclose($fp);\r
+ }\r
+ \r
+ // \83t\83@\83C\83\8b\82ð\8aJ\82«\82Ü\82·\81B\r
+ if (FALSE == ($fp = @fopen($dataFilePath, $mode))) {\r
+ return error_xml(ERROR_IO, "data file open fail.");\r
+ }\r
+ \r
+ return $fp;\r
+}\r
+?>\r
--- /dev/null
+<?php\r
+require_once("./app/common.inc");\r
+\r
+/**\r
+ * \83\86\81[\83U\82ª\95Û\8e\9d\82µ\82Ä\82¢\82é\83f\81[\83^\81E\83t\83@\83C\83\8b\82Ì\93à\97e\82ð\8eæ\93¾\82µ\82Ü\82·\81B\r
+ * \r
+ * @param string $username\r
+ * \83\86\81[\83U\96¼\81B\r
+ * @return \90¬\8c÷\82µ\82½\8fê\8d\87\82Í\83f\81[\83^\81E\83t\83@\83C\83\8b\82Ì\93à\97e\81A\8e¸\94s\82µ\82½\8fê\8d\87\82ÍFALSE\81B\r
+ */\r
+function read_data_file($username) {\r
+ // \88ø\90\94\82ð\8am\94F\82µ\82Ü\82·\81B\r
+ if (empty($username)) {\r
+ return error_xml(ERROR_EMPTY, "$username is empty.");\r
+ }\r
+ \r
+ // \83f\81[\83^\81E\83t\83@\83C\83\8b\82ð\93Ç\82Ý\8d\9e\82Ý\82Ü\82·\81B\r
+ if (FALSE == ($fp = open_data_file($username, "rb"))) {\r
+ return FALSE;\r
+ }\r
+ \r
+ if (FALSE == @flock($fp, LOCK_SH)) {\r
+ @fclose($fp);\r
+ return error_xml(ERROR_IO, "data file read lock fail.");\r
+ }\r
+ \r
+ $fstat = @fstat($fp);\r
+ if ($fstat["size"] > 0) {\r
+ if (FALSE == ($content = @fread($fp, $fstat["size"]))) {\r
+ @fclose($fp);\r
+ return error_xml(ERROR_IO, "data file read fail.");\r
+ }\r
+ } else {\r
+ $content = "";\r
+ }\r
+ \r
+ @fclose($fp);\r
+ \r
+ return $content;\r
+}\r
+?>\r
--- /dev/null
+<?php\r
+require_once("./app/common.inc");\r
+\r
+/**\r
+ * \83\86\81[\83U\82ª\95Û\8e\9d\82µ\82Ä\82¢\82é\83f\81[\83^\81E\83t\83@\83C\83\8b\82É\95¶\8e\9a\97ñ\82ð\8fo\97Í\82µ\82Ü\82·\81B\r
+ * \r
+ * @param string $username\r
+ * \83\86\81[\83U\96¼\81B\r
+ * @param string $data\r
+ * \8fo\97Í\82·\82é\83f\81[\83^\81B\r
+ * @return \90¬\8c÷\82µ\82½\8fê\8d\87\82ÍTRUE\81A\8e¸\94s\82µ\82½\8fê\8d\87\82ÍFALSE\81B\r
+ */\r
+function write_data_file($username, $data) {\r
+ // \88ø\90\94\82ð\8am\94F\82µ\82Ü\82·\81B\r
+ if (empty($username)) {\r
+ return error_xml(ERROR_EMPTY, "$username is empty.");\r
+ }\r
+ \r
+ // \83f\81[\83^\81E\83t\83@\83C\83\8b\82É\8fo\97Í\82µ\82Ü\82·\81B\r
+ if (FALSE == ($fp = open_data_file($username, "wb"))) {\r
+ return FALSE;\r
+ }\r
+ \r
+ if (FALSE == @flock($fp, LOCK_EX)) {\r
+ @fclose($fp);\r
+ return error_xml(ERROR_IO, "data file write lock fail.");\r
+ }\r
+ \r
+ if (!empty($data)) {\r
+ if (FALSE == @fwrite($fp, $data)) {\r
+ @fclose($fp);\r
+ return error_xml(ERROR_IO, "data file write fail.");\r
+ }\r
+ } else {\r
+ if (FALSE == @ftruncate($fp, 0)) {\r
+ @fclose($fp);\r
+ return error_xml(ERROR_IO, "data file truncate fail.");\r
+ }\r
+ }\r
+ \r
+ @fclose($fp);\r
+ \r
+ return TRUE;\r
+}\r
+?>\r
--- /dev/null
+deny from all\r
--- /dev/null
+<html><body>\r
+<a href="jws/online-stg-env.jnlp">Test JavaWebStart</a>\r
+</body></html>
\ No newline at end of file
--- /dev/null
+AddType application/x-java-jnlp-file jnlp\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<jnlp spec="1.0+" codebase="http://10.10.12.84/online-stg-env/jws/" href="online-stg-env.jnlp">\r
+ <information>\r
+ <title>Online STG Environment</title>\r
+ <vendor>u6k</vendor>\r
+ <description>オンラインでSTGを作成する開発環境です。</description>\r
+ </information>\r
+ <!-- security>\r
+ <all-permissions />\r
+ </security -->\r
+ <resources>\r
+ <j2se version="1.5.0+" />\r
+ <jar href="online-stg-env-1.0.0-SNAPSHOT.jar" />\r
+ </resources>\r
+ <application-desc main-class="jp.gr.java_conf.u6k.online_stg_env.OnlineStgEditor" />\r
+</jnlp>\r
--- /dev/null
+<?php\r
+require_once("./app/core.inc");\r
+?>\r
--- /dev/null
+url=http://10.10.12.84/online-stg-env/online-stg-env.php\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<!--\r
+ This configuration file was written by the eclipse-cs plugin configuration editor\r
+-->\r
+<!--\r
+ Checkstyle-Configuration: u6k Checks\r
+ Description: none\r
+-->\r
+<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">\r
+<module name="Checker">\r
+ <property name="severity" value="warning"/>\r
+ <module name="TreeWalker">\r
+ <property name="tabWidth" value="4"/>\r
+ <module name="FileContentsHolder"/>\r
+ <module name="ModifierOrder"/>\r
+ <module name="RedundantModifier"/>\r
+ <module name="AvoidNestedBlocks"/>\r
+ <module name="EmptyBlock"/>\r
+ <module name="LeftCurly"/>\r
+ <module name="NeedBraces"/>\r
+ <module name="RightCurly"/>\r
+ <module name="AvoidInlineConditionals"/>\r
+ <module name="DoubleCheckedLocking"/>\r
+ <module name="EmptyStatement"/>\r
+ <module name="EqualsHashCode"/>\r
+ <module name="IllegalInstantiation"/>\r
+ <module name="InnerAssignment"/>\r
+ <module name="MissingSwitchDefault"/>\r
+ <module name="RedundantThrows"/>\r
+ <module name="SimplifyBooleanExpression"/>\r
+ <module name="SimplifyBooleanReturn"/>\r
+ <module name="DesignForExtension"/>\r
+ <module name="HideUtilityClassConstructor"/>\r
+ <module name="InterfaceIsType"/>\r
+ <module name="VisibilityModifier"/>\r
+ <module name="ArrayTypeStyle"/>\r
+ <module name="GenericIllegalRegexp">\r
+ <property name="format" value="\s+$"/>\r
+ <property name="ignoreComments" value="true"/>\r
+ <property name="message" value="Line has trailing spaces."/>\r
+ </module>\r
+ <module name="TodoComment"/>\r
+ <module name="UpperEll"/>\r
+ <module name="DefaultComesLast"/>\r
+ <module name="FallThrough"/>\r
+ <module name="IllegalCatch"/>\r
+ <module name="IllegalThrows"/>\r
+ <module name="ModifiedControlVariable"/>\r
+ <module name="RequireThis"/>\r
+ <module name="StringLiteralEquality"/>\r
+ <module name="FinalClass"/>\r
+ <module name="Indentation"/>\r
+ <module name="TrailingComment"/>\r
+ <module name="JavadocStyle">\r
+ <property name="checkFirstSentence" value="false"/>\r
+ </module>\r
+ <module name="JavadocType">\r
+ <property name="versionFormat" value="^\$Id.*\$$"/>\r
+ </module>\r
+ <module name="JavadocVariable"/>\r
+ <module name="AbstractClassName"/>\r
+ <module name="ConstantName"/>\r
+ <module name="LocalFinalVariableName"/>\r
+ <module name="LocalVariableName"/>\r
+ <module name="MemberName"/>\r
+ <module name="MethodName"/>\r
+ <module name="PackageName"/>\r
+ <module name="ParameterName"/>\r
+ <module name="StaticVariableName"/>\r
+ <module name="TypeName"/>\r
+ <module name="Header">\r
+ <property name="headerFile" value="${basedir}/LICENSE.txt"/>\r
+ </module>\r
+ <module name="AvoidStarImport"/>\r
+ <module name="IllegalImport"/>\r
+ <module name="ImportOrder"/>\r
+ <module name="RedundantImport"/>\r
+ <module name="UnusedImports"/>\r
+ <module name="EmptyForInitializerPad"/>\r
+ <module name="EmptyForIteratorPad"/>\r
+ <module name="NoWhitespaceAfter"/>\r
+ <module name="NoWhitespaceBefore"/>\r
+ <module name="OperatorWrap"/>\r
+ <module name="MethodParamPad"/>\r
+ <module name="ParenPad"/>\r
+ <module name="TabCharacter"/>\r
+ <module name="TypecastParenPad">\r
+ <property name="tokens" value="RPAREN,TYPECAST"/>\r
+ </module>\r
+ <module name="WhitespaceAfter"/>\r
+ <module name="WhitespaceAround">\r
+ <property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV,DIV_ASSIGN,EQUAL,GE,GT,LAND,LCURLY,LE,LITERAL_ASSERT,LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_RETURN,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,LOR,LT,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS,PLUS_ASSIGN,QUESTION,RCURLY,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,LITERAL_ASSERT,TYPE_EXTENSION_AND"/>\r
+ </module>\r
+ <module name="CovariantEquals"/>\r
+ <module name="DeclarationOrder"/>\r
+ <module name="ExplicitInitialization"/>\r
+ <module name="IllegalType">\r
+ <property name="tokens" value="METHOD_DEF,PARAMETER_DEF,VARIABLE_DEF"/>\r
+ </module>\r
+ <module name="JUnitTestCase"/>\r
+ <module name="MagicNumber"/>\r
+ <module name="MissingCtor"/>\r
+ <module name="MultipleVariableDeclarations"/>\r
+ <module name="PackageDeclaration"/>\r
+ <module name="MutableException"/>\r
+ <module name="JavadocMethod">\r
+ <property name="scope" value="package"/>\r
+ <property name="allowUndeclaredRTE" value="true"/>\r
+ </module>\r
+ </module>\r
+ <module name="NewlineAtEndOfFile">\r
+ <property name="lineSeparator" value="lf"/>\r
+ </module>\r
+ <module name="Translation"/>\r
+ <module name="PackageHtml"/>\r
+ <module name="SuppressionCommentFilter"/>\r
+</module>\r