forked from kazzmir/paintown
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e33b97
commit 9752633
Showing
68 changed files
with
15,027 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
build | ||
mingw-bin | ||
paintown | ||
/paintown | ||
.scon* | ||
.tmp | ||
peg_*.py | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.rafkind.paintown; | ||
|
||
import java.awt.event.WindowListener; | ||
import java.awt.event.WindowEvent; | ||
|
||
public class CloseHook implements WindowListener { | ||
|
||
private Lambda0 function; | ||
|
||
public CloseHook( Lambda0 _function ){ | ||
function = _function; | ||
} | ||
|
||
public void windowActivated( WindowEvent e ){ | ||
} | ||
|
||
public void windowClosed( WindowEvent e ){ | ||
} | ||
|
||
public void windowClosing( WindowEvent e ){ | ||
try{ | ||
this.function.invoke(); | ||
} catch (Exception ex){ | ||
} | ||
} | ||
|
||
public void windowDeactivated( WindowEvent e ){ | ||
} | ||
|
||
public void windowDeiconified( WindowEvent e ){ | ||
} | ||
|
||
public void windowIconified( WindowEvent e ){ | ||
} | ||
|
||
public void windowOpened( WindowEvent e ){ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.rafkind.paintown; | ||
|
||
public abstract class Closer{ | ||
private static int opened = 0; | ||
|
||
public static void open(){ | ||
opened += 1; | ||
} | ||
|
||
public static void close(){ | ||
opened -= 1; | ||
if (opened <= 0){ | ||
System.exit(0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.rafkind.paintown; | ||
|
||
import java.util.HashMap; | ||
import java.io.*; | ||
|
||
/* saves arbitrary data to a file so it can be loaded in between program instances */ | ||
public class Config{ | ||
private HashMap<String, Serializable> config = new HashMap<String, Serializable>(); | ||
private static Object lock = new Object(); | ||
private static Config instance = null; | ||
private static final String savedFile = "editor-config.obj"; | ||
|
||
private Config(){ | ||
config = loadData(); | ||
} | ||
|
||
private void saveData(){ | ||
try{ | ||
ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(savedFile)); | ||
try{ | ||
output.writeObject(config); | ||
} finally { | ||
output.close(); | ||
} | ||
} catch (IOException fail){ | ||
System.err.println(fail); | ||
} | ||
} | ||
|
||
private HashMap<String, Serializable> loadData(){ | ||
try{ | ||
ObjectInputStream input = new ObjectInputStream(new FileInputStream(savedFile)); | ||
try{ | ||
Object in = input.readObject(); | ||
if (in instanceof HashMap){ | ||
return (HashMap<String, Serializable>) in; | ||
} | ||
return new HashMap<String, Serializable>(); | ||
} finally { | ||
input.close(); | ||
} | ||
} catch (ClassNotFoundException fail){ | ||
return new HashMap<String, Serializable>(); | ||
} catch (IOException fail){ | ||
System.err.println(fail); | ||
return new HashMap<String, Serializable>(); | ||
} | ||
} | ||
|
||
public static Config getConfig(){ | ||
synchronized (lock){ | ||
if (instance == null){ | ||
instance = new Config(); | ||
} | ||
|
||
return instance; | ||
} | ||
} | ||
|
||
public synchronized Serializable get(String name){ | ||
return config.get(name); | ||
} | ||
|
||
public synchronized void set(String name, Serializable what){ | ||
config.put(name, what); | ||
saveData(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.rafkind.paintown; | ||
|
||
import java.io.File; | ||
|
||
public class Data{ | ||
private static File dataPath = new File( "data" ); | ||
|
||
private Data(){ | ||
} | ||
|
||
public static File getDataPath(){ | ||
return dataPath; | ||
} | ||
|
||
public static void setDataPath(File file){ | ||
dataPath = file; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
editor/src/main/java/com/rafkind/paintown/DirectoryModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.rafkind.paintown; | ||
|
||
import java.io.File; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.ArrayList; | ||
|
||
import javax.swing.ListModel; | ||
import javax.swing.event.ListDataListener; | ||
import javax.swing.event.ListDataEvent; | ||
|
||
public class DirectoryModel implements ListModel { | ||
|
||
private List files; | ||
private List listeners; | ||
|
||
public DirectoryModel( String dir ){ | ||
listeners = new ArrayList(); | ||
files = new ArrayList(); | ||
setDirectory( dir ); | ||
} | ||
|
||
public void setDirectory( File dir ){ | ||
if ( dir.isDirectory() ){ | ||
files.clear(); | ||
files.add( new File( dir.getPath() + "/.." ) ); | ||
File[] fs = dir.listFiles(); | ||
for ( int i = 0; i < fs.length; i++ ){ | ||
files.add( fs[ i ] ); | ||
} | ||
|
||
ListDataEvent event = new ListDataEvent( this, ListDataEvent.CONTENTS_CHANGED, 0, 999999 ); | ||
for ( Iterator it = listeners.iterator(); it.hasNext(); ){ | ||
ListDataListener l = (ListDataListener) it.next(); | ||
l.contentsChanged( event ); | ||
} | ||
} | ||
} | ||
|
||
public void setDirectory( String dir ){ | ||
setDirectory( new File( dir ) ); | ||
} | ||
|
||
public void addListDataListener( ListDataListener listener ){ | ||
listeners.add( listener ); | ||
} | ||
|
||
public Object getElementAt( int index ){ | ||
return this.files.get( index ); | ||
} | ||
|
||
public int getSize(){ | ||
return this.files.size(); | ||
} | ||
|
||
public void removeListDataListener( ListDataListener listener ){ | ||
listeners.remove( listener ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.rafkind.paintown; | ||
|
||
public abstract class Lambda0{ | ||
public abstract Object invoke() throws Exception; | ||
|
||
public Object invoke_(){ | ||
try{ | ||
return invoke(); | ||
} catch ( Exception e ){ | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.rafkind.paintown; | ||
|
||
import java.util.List; | ||
import java.util.Iterator; | ||
|
||
public abstract class Lambda1{ | ||
public abstract Object invoke( Object x ) throws Exception; | ||
|
||
public static void foreach( List list, Lambda1 lambda ) throws Exception { | ||
for ( Iterator iterator = list.iterator(); iterator.hasNext(); ){ | ||
lambda.invoke( iterator.next() ); | ||
} | ||
} | ||
|
||
public static void foreach_( List list, Lambda1 lambda ){ | ||
try{ | ||
foreach( list, lambda ); | ||
} catch ( Exception e ){ | ||
} | ||
} | ||
|
||
public Object invoke_( Object x ){ | ||
try{ | ||
return invoke( x ); | ||
} catch ( Exception e ){ | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.rafkind.paintown; | ||
|
||
public abstract class Lambda2{ | ||
public abstract Object invoke( Object x, Object y ) throws Exception; | ||
|
||
public Object invoke_( Object x, Object y ){ | ||
try{ | ||
return invoke( x, y ); | ||
} catch ( Exception e ){ | ||
} | ||
return null; | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
editor/src/main/java/com/rafkind/paintown/MaskedImage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.rafkind.paintown; | ||
|
||
import java.awt.*; | ||
import java.awt.image.*; | ||
import java.io.*; | ||
import javax.imageio.*; | ||
import java.util.HashMap; | ||
|
||
public class MaskedImage extends BufferedImage { | ||
|
||
private static HashMap images = new HashMap(); | ||
|
||
public MaskedImage( int w, int h ){ | ||
super( w, h, BufferedImage.TYPE_INT_ARGB ); | ||
} | ||
|
||
public MaskedImage( BufferedImage image ){ | ||
this( image.getWidth(), image.getHeight() ); | ||
for ( int x = 0; x < image.getWidth(); x++ ){ | ||
for ( int y = 0; y < image.getHeight(); y++ ){ | ||
int pixel = image.getRGB( x, y ); | ||
this.setRGB( x, y, pixel ); | ||
} | ||
} | ||
} | ||
|
||
public static void clearCache(){ | ||
synchronized( images ){ | ||
images.clear(); | ||
} | ||
} | ||
|
||
public static MaskedImage load(String s) throws IOException { | ||
synchronized (images){ | ||
if (images.get(s) != null){ | ||
return (MaskedImage) images.get(s); | ||
} | ||
} | ||
BufferedImage temp = ImageIO.read( new File( s ) ); | ||
MaskedImage image = new MaskedImage( temp.getWidth(), temp.getHeight() ); | ||
for ( int x = 0; x < temp.getWidth(); x++ ){ | ||
for ( int y = 0; y < temp.getHeight(); y++ ){ | ||
int pixel = temp.getRGB( x, y ); | ||
if ( (pixel & 0x00ffffff) == 0x00ff00ff ){ | ||
/* convert masking color into an alpha channel that is translucent */ | ||
pixel = 0x00ffffff; | ||
} | ||
image.setRGB( x, y, pixel ); | ||
} | ||
} | ||
synchronized (images){ | ||
images.put(s, image); | ||
} | ||
return image; | ||
} | ||
|
||
public static MaskedImage load( String s, HashMap remap ) throws IOException { | ||
String full = s + "\n" + String.valueOf( remap.hashCode() ); | ||
synchronized (images){ | ||
if (images.containsKey(full)){ | ||
return (MaskedImage) images.get(full); | ||
} | ||
} | ||
|
||
MaskedImage image = new MaskedImage(load(s)); | ||
for (int x = 0; x < image.getWidth(); x++){ | ||
for (int y = 0; y < image.getHeight(); y++){ | ||
int pixel = image.getRGB( x, y ); | ||
if ( remap.containsKey( new Integer( pixel ) ) ){ | ||
Integer mapped = (Integer) remap.get( new Integer( pixel ) ); | ||
image.setRGB( x, y, mapped.intValue() ); | ||
} | ||
} | ||
} | ||
|
||
synchronized (images){ | ||
images.put(full, image); | ||
} | ||
|
||
return image; | ||
} | ||
} |
Oops, something went wrong.