Initial commit
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2014-2021 Thetya Team
|
||||
* Copyright (c) 2005-2011 Three Rings
|
||||
*
|
||||
* https://github.com/Thetya
|
||||
*/
|
||||
|
||||
package com.github.thetya.tools;
|
||||
|
||||
import com.threerings.media.image.ColorPository;
|
||||
import com.threerings.media.image.ColorPository.ClassRecord;
|
||||
import com.threerings.media.image.ColorPository.ColorRecord;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Iterator;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class ColorizationReader {
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length < 1) {
|
||||
System.err.println("You need to specify the path to the colordefs.dat file as an argument.");
|
||||
return;
|
||||
}
|
||||
|
||||
ColorPository colorPository;
|
||||
|
||||
try {
|
||||
colorPository = ColorPository.loadColorPository(new FileInputStream(args[0]));
|
||||
} catch (FileNotFoundException ex) {
|
||||
System.err.println("File not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
SortedMap<Integer, ColorRecord> colorRecords = new TreeMap<Integer, ColorRecord>();
|
||||
|
||||
for (Iterator<ClassRecord> it = colorPository.enumerateClasses(); it.hasNext(); ) {
|
||||
ClassRecord record = it.next();
|
||||
|
||||
for (Integer colorKey : record.colors.keySet()) {
|
||||
colorRecords.put(record.colors.get(colorKey).getColorization().colorizationId,
|
||||
record.colors.get(colorKey));
|
||||
}
|
||||
}
|
||||
|
||||
for (Integer colorizationId : colorRecords.keySet()) {
|
||||
ColorRecord colorRecord = colorRecords.get(colorizationId);
|
||||
ClassRecord classRecord = colorRecord.cclass;
|
||||
System.out.println("[" + classRecord.name + "] " + colorizationId + " = " + colorRecord.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
293
thetya-tools/src/com/github/thetya/tools/InterfaceTester.java
Normal file
293
thetya-tools/src/com/github/thetya/tools/InterfaceTester.java
Normal file
@@ -0,0 +1,293 @@
|
||||
/*
|
||||
* Copyright (c) 2014-2021 Thetya Team
|
||||
* Copyright (c) 2005-2011 Three Rings
|
||||
*
|
||||
* https://github.com/Thetya
|
||||
*/
|
||||
|
||||
package com.github.thetya.tools;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogManager;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.prefs.Preferences;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import com.google.common.collect.MapMaker;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import com.samskivert.swing.GroupLayout;
|
||||
import com.samskivert.swing.Spacer;
|
||||
import com.threerings.config.ConfigEvent;
|
||||
import com.threerings.config.ConfigReference;
|
||||
import com.threerings.config.ConfigUpdateListener;
|
||||
import com.threerings.editor.swing.DraggableSpinner;
|
||||
import com.threerings.editor.swing.EditorPanel;
|
||||
import com.threerings.util.ChangeBlock;
|
||||
import com.threerings.opengl.GlCanvasTool;
|
||||
import com.threerings.opengl.gui.CanvasRoot;
|
||||
import com.threerings.opengl.gui.Component;
|
||||
import com.threerings.opengl.gui.Root;
|
||||
import com.threerings.opengl.gui.StretchWindow;
|
||||
import com.threerings.opengl.gui.UserInterface;
|
||||
import com.threerings.opengl.gui.config.UserInterfaceConfig;
|
||||
import com.threerings.opengl.renderer.Color4f;
|
||||
|
||||
import com.threerings.expr.Scoped;
|
||||
|
||||
/**
|
||||
* Tool for testing user interfaces.
|
||||
*/
|
||||
public class InterfaceTester extends GlCanvasTool
|
||||
implements ChangeListener, ConfigUpdateListener<UserInterfaceConfig> {
|
||||
|
||||
/** The panel that holds the control bits. */
|
||||
protected JPanel _controlPanel;
|
||||
|
||||
/** The editor panel we use to edit the interface configuration. */
|
||||
protected EditorPanel _editorPanel;
|
||||
|
||||
/** The width and height controls. */
|
||||
protected DraggableSpinner _width, _height;
|
||||
|
||||
/** Indicates that we should ignore any changes, because we're the one effecting them. */
|
||||
protected ChangeBlock _changeBlock = new ChangeBlock();
|
||||
|
||||
/** The user interface root. */
|
||||
protected Root _root;
|
||||
|
||||
/** The user interface component. */
|
||||
protected UserInterface _userInterface;
|
||||
|
||||
/** Components that should be drawn highlighted. */
|
||||
protected Set<Component> _highlights = Sets.newSetFromMap(
|
||||
new MapMaker().concurrencyLevel(1).weakKeys().<Component, Boolean>makeMap());
|
||||
|
||||
/** The application preferences. */
|
||||
protected static Preferences _preferences = Preferences.userNodeForPackage(InterfaceTester.class);
|
||||
|
||||
/**
|
||||
* The program entry point.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
new InterfaceTester(args.length > 0 ? args[0] : null).startup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the interface tester with (optionally) the path to an interface to load.
|
||||
*/
|
||||
public InterfaceTester(String userInterface) {
|
||||
|
||||
super("interface");
|
||||
|
||||
Logger rootLogger = LogManager
|
||||
.getLogManager()
|
||||
.getLogger("");
|
||||
rootLogger.setLevel(Level.ALL);
|
||||
for (Handler handler : rootLogger.getHandlers()) {
|
||||
handler.setLevel(Level.ALL);
|
||||
}
|
||||
|
||||
|
||||
// Set the title
|
||||
_frame.setTitle(_msgs.get("m.title"));
|
||||
|
||||
// Populate the menu bar
|
||||
JMenuBar menubar = new JMenuBar();
|
||||
_frame.setJMenuBar(menubar);
|
||||
|
||||
JMenu file = createMenu("file", KeyEvent.VK_F);
|
||||
menubar.add(file);
|
||||
file.add(createMenuItem("quit", KeyEvent.VK_Q, KeyEvent.VK_Q));
|
||||
|
||||
JMenu edit = createMenu("edit", KeyEvent.VK_E);
|
||||
menubar.add(edit);
|
||||
edit.add(createMenuItem("configs", KeyEvent.VK_C, KeyEvent.VK_G));
|
||||
edit.add(createMenuItem("resources", KeyEvent.VK_R, KeyEvent.VK_R));
|
||||
edit.add(createMenuItem("preferences", KeyEvent.VK_P, KeyEvent.VK_P));
|
||||
|
||||
JMenu view = createMenu("view", KeyEvent.VK_V);
|
||||
menubar.add(view);
|
||||
view.add(_showStats = createCheckBoxMenuItem("stats", KeyEvent.VK_S, KeyEvent.VK_T));
|
||||
view.addSeparator();
|
||||
view.add(createMenuItem("refresh", KeyEvent.VK_F, KeyEvent.VK_F));
|
||||
|
||||
// Configure the side panel
|
||||
_controlPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||
_controlPanel.setPreferredSize(new Dimension(350, 1));
|
||||
|
||||
// Add the config editor
|
||||
_controlPanel.add(_editorPanel = new EditorPanel(this));
|
||||
|
||||
// Add the controls
|
||||
JPanel controls = new JPanel();
|
||||
_controlPanel.add(controls, GroupLayout.FIXED);
|
||||
controls.add(new JLabel(_msgs.get("m.width")));
|
||||
controls.add(_width = new DraggableSpinner(-1, -1, Integer.MAX_VALUE, 1));
|
||||
_width.setMinimumSize(_width.getPreferredSize());
|
||||
_width.setMaximumSize(_width.getPreferredSize());
|
||||
_width.addChangeListener(this);
|
||||
controls.add(new Spacer(10, 1));
|
||||
controls.add(new JLabel(_msgs.get("m.height")));
|
||||
controls.add(_height = new DraggableSpinner(-1, -1, Integer.MAX_VALUE, 1));
|
||||
_height.setMinimumSize(_height.getPreferredSize());
|
||||
_height.setMaximumSize(_height.getPreferredSize());
|
||||
_height.addChangeListener(this);
|
||||
|
||||
// Configure the config editor
|
||||
UserInterfaceConfig.Derived impl = new UserInterfaceConfig.Derived();
|
||||
if (userInterface != null) {
|
||||
String path = _rsrcmgr.getResourcePath(new File(userInterface));
|
||||
if (path != null) {
|
||||
impl.userInterface = new ConfigReference<UserInterfaceConfig>(path);
|
||||
}
|
||||
}
|
||||
_editorPanel.setObject(impl);
|
||||
_editorPanel.addChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Root createRoot() {
|
||||
if (_canvasRoot == null) {
|
||||
_canvasRoot = new CanvasRoot(this, _canvas) {
|
||||
@Override
|
||||
protected void draw ()
|
||||
{
|
||||
super.draw();
|
||||
|
||||
if (_highlights.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
_ctx.getRenderer().setTextureState(null);
|
||||
|
||||
GL11.glLineWidth(2f);
|
||||
GL11.glEnable(GL11.GL_COLOR_LOGIC_OP);
|
||||
GL11.glLogicOp(GL11.GL_XOR);
|
||||
|
||||
// Draw a box for highlighted components
|
||||
for (Component comp : _highlights) {
|
||||
if (!comp.isAdded() || !comp.isVisible()) {
|
||||
continue;
|
||||
}
|
||||
int x = comp.getAbsoluteX();
|
||||
int y = comp.getAbsoluteY();
|
||||
int w = comp.getWidth();
|
||||
int h = comp.getHeight();
|
||||
|
||||
GL11.glBegin(GL11.GL_LINE_LOOP);
|
||||
GL11.glVertex2f(x, y);
|
||||
GL11.glVertex2f(x + w, y);
|
||||
GL11.glVertex2f(x + w, y + h);
|
||||
GL11.glVertex2f(x, y + h);
|
||||
GL11.glEnd();
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_COLOR_LOGIC_OP);
|
||||
}
|
||||
};
|
||||
}
|
||||
return _canvasRoot;
|
||||
}
|
||||
|
||||
public void stateChanged(ChangeEvent event) {
|
||||
if (event.getSource() == _editorPanel) {
|
||||
// Let the config know that it was updated
|
||||
if (!_changeBlock.enter()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
_userInterface.getConfig().wasUpdated();
|
||||
} finally {
|
||||
_changeBlock.leave();
|
||||
}
|
||||
} else {
|
||||
_userInterface.setPreferredSize(_width.getIntValue(), _height.getIntValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void configUpdated(ConfigEvent<UserInterfaceConfig> event) {
|
||||
// Update the editor panel
|
||||
if (!_changeBlock.enter()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
_editorPanel.update();
|
||||
_editorPanel.validate();
|
||||
} finally {
|
||||
_changeBlock.leave();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JComponent createCanvasContainer() {
|
||||
JSplitPane pane = new JSplitPane(
|
||||
JSplitPane.HORIZONTAL_SPLIT, true, _canvas, _controlPanel = GroupLayout.makeVStretchBox(5));
|
||||
_canvas.setMinimumSize(new Dimension(1, 1));
|
||||
pane.setResizeWeight(1.0);
|
||||
pane.setOneTouchExpandable(true);
|
||||
return pane;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CanvasToolPrefs createEditablePrefs() {
|
||||
return new CanvasToolPrefs(_preferences);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void didInit() {
|
||||
super.didInit();
|
||||
|
||||
// Create the UI root
|
||||
_root = createRoot();
|
||||
_root.setModalShade(new Color4f(0f, 0f, 0f, 0.5f));
|
||||
|
||||
// And the window
|
||||
StretchWindow window = new StretchWindow(
|
||||
this, new com.threerings.opengl.gui.layout.HGroupLayout());
|
||||
_root.addWindow(window);
|
||||
|
||||
// Set up the UI
|
||||
UserInterfaceConfig config = new UserInterfaceConfig();
|
||||
config.init(_cfgmgr);
|
||||
config.implementation = (UserInterfaceConfig.Derived) _editorPanel.getObject();
|
||||
config.addListener(this);
|
||||
window.add(_userInterface = new UserInterface(this, config));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateView(float elapsed) {
|
||||
super.updateView(elapsed);
|
||||
_root.tick(elapsed);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void compositeView() {
|
||||
super.compositeView();
|
||||
_root.composite();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tracks components by their originating ComponentConfig.
|
||||
*/
|
||||
@Scoped
|
||||
@SuppressWarnings("unused")
|
||||
protected void editorHighlight(Component comp, boolean highlight) {
|
||||
if (highlight) {
|
||||
_highlights.add(comp);
|
||||
} else {
|
||||
_highlights.remove(comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
22
thetya-tools/src/com/github/thetya/tools/Log.java
Normal file
22
thetya-tools/src/com/github/thetya/tools/Log.java
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2014-2021 Thetya Team
|
||||
* Copyright (c) 2005-2011 Three Rings
|
||||
*
|
||||
* https://github.com/Thetya
|
||||
*/
|
||||
|
||||
package com.github.thetya.tools;
|
||||
|
||||
import com.samskivert.util.Logger;
|
||||
|
||||
/**
|
||||
* Contains a reference to the {@link Logger} object used by the tools package.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class Log {
|
||||
|
||||
/**
|
||||
* The {@link Logger} reference.
|
||||
*/
|
||||
public static Logger log = Logger.getLogger("com.github.thetya.tools");
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2014-2021 Thetya Team
|
||||
* Copyright (c) 2005-2011 Three Rings
|
||||
*
|
||||
* https://github.com/Thetya
|
||||
*/
|
||||
|
||||
package com.github.thetya.tools;
|
||||
|
||||
import static com.github.thetya.tools.Log.log;
|
||||
|
||||
import com.threerings.presents.util.SecureUtil;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.security.KeyPair;
|
||||
|
||||
/**
|
||||
* A simple utility to generate RSA key pairs, using the {@link SecureUtil#genRSAKeyPair(int)}
|
||||
* method. The generated keys are outputted to a plaintext file or the standard output, if saving to
|
||||
* a file is impossible.
|
||||
*/
|
||||
public class RsaKeypairGenerator {
|
||||
|
||||
/**
|
||||
* Used during the key pair generation, determines the key bits.
|
||||
*/
|
||||
private static int keyBits = 2048;
|
||||
|
||||
public static void main(final String... args) {
|
||||
if (args.length > 0) {
|
||||
try {
|
||||
keyBits = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException e) {
|
||||
log.warning(
|
||||
"The passed argument is not an integer, falling back to the default key bits value.",
|
||||
"input",
|
||||
args[0]);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("Generating a new RSA key pair...", "keyBits", keyBits);
|
||||
|
||||
// First generate the key pair itself.
|
||||
final KeyPair rsaKeyPair = SecureUtil.genRSAKeyPair(keyBits);
|
||||
|
||||
// Now get the keys
|
||||
final String privateKey = SecureUtil.RSAKeyToString(rsaKeyPair.getPrivate());
|
||||
final String publicKey = SecureUtil.RSAKeyToString(rsaKeyPair.getPublic());
|
||||
|
||||
try {
|
||||
final FileWriter writer = new FileWriter("keys.txt");
|
||||
writer.append("PUBLIC KEY\n");
|
||||
writer.append(publicKey);
|
||||
writer.append("\n\n");
|
||||
writer.append("PRIVATE KEY\n");
|
||||
writer.append(privateKey);
|
||||
|
||||
writer.flush();
|
||||
writer.close();
|
||||
|
||||
log.info("Done, see keys.txt.");
|
||||
} catch (IOException e) {
|
||||
log.warning(
|
||||
"Could not open a file writer, outputting the keys to the log instead.",
|
||||
"public",
|
||||
publicKey,
|
||||
"private",
|
||||
privateKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
thetya-tools/thetya-tools.iml
Normal file
12
thetya-tools/thetya-tools.iml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_17" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="ProjectX 2011 code jars" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
Reference in New Issue
Block a user