Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Paste & ReplaceURL
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamesuta committed Nov 19, 2016
1 parent ea09a56 commit 2bb2ddd
Show file tree
Hide file tree
Showing 22 changed files with 401 additions and 182 deletions.
13 changes: 6 additions & 7 deletions src/main/java/com/kamesuta/mc/signpic/Apis.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.kamesuta.mc.signpic;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
Expand All @@ -16,9 +15,9 @@
import com.kamesuta.mc.signpic.http.upload.GyazoUpload;
import com.kamesuta.mc.signpic.http.upload.IUploader;
import com.kamesuta.mc.signpic.http.upload.ImgurUpload;
import com.kamesuta.mc.signpic.http.upload.UploadContent;
import com.kamesuta.mc.signpic.information.Info;
import com.kamesuta.mc.signpic.information.Informations;
import com.kamesuta.mc.signpic.state.State;

public class Apis {
public static final Apis instance = new Apis();
Expand Down Expand Up @@ -140,7 +139,7 @@ public E solve(final String name) {
}

public static interface ImageUploaderFactory {
IUploader create(File f, State s, String key) throws IOException;
IUploader create(UploadContent upload, String key) throws IOException;

Set<String> keys();
}
Expand All @@ -162,8 +161,8 @@ public Set<String> keys() {
}

@Override
public IUploader create(final File f, final State s, final String key) throws IOException {
return new GyazoUpload(f, s, key);
public IUploader create(final UploadContent upload, final String key) throws IOException {
return new GyazoUpload(upload, key);
}
});
registerImageUploader("Imgur", new ImageUploaderFactory() {
Expand All @@ -182,8 +181,8 @@ public Set<String> keys() {
}

@Override
public IUploader create(final File f, final State s, final String key) throws IOException {
return new ImgurUpload(f, s, key);
public IUploader create(final UploadContent upload, final String key) throws IOException {
return new ImgurUpload(upload, key);
}
});
final Pattern p = Pattern.compile("[^\\w]");
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/kamesuta/mc/signpic/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javax.swing.JOptionPane;

import com.kamesuta.mc.signpic.gui.GuiMain;
import com.kamesuta.mc.signpic.gui.OverlayFrame;
import com.kamesuta.mc.signpic.render.CustomTileEntitySignRenderer;

import cpw.mods.fml.client.FMLClientHandler;
Expand Down Expand Up @@ -57,6 +58,11 @@ public static TileEntitySign getTileSignLooking() {
return null;
}

@SuppressWarnings("deprecation")
public static void notice(final String notice, final float duration) {
OverlayFrame.instance.pane.addNotice1(notice, duration);
}

public static class MovePos {
public int x;
public int y;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/kamesuta/mc/signpic/CoreHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@ void debug() {
// Client.openEditor();
// Reference.logger.info("try to delete: "+Client.location.modFile.getName());
// Client.deleteMod();
OverlayFrame.instance.pane.addNotice1("Debug Message!", 3f);
Client.notice("Debug Message!", 3f);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ public class EntryIdBuilder {
private ImageMeta meta;
private String uri;

public EntryIdBuilder(final EntryId source) {
public EntryIdBuilder() {
}

public EntryIdBuilder load(final EntryId source) {
if (source!=null) {
this.meta = source.getMeta();
if (source.hasContentId())
this.uri = source.getContentId().getURI();
}
}

public EntryIdBuilder() {
return this;
}

public void setMeta(final ImageMeta meta) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Content implements IInitable, ICollectable {
public Content(final ContentId id) {
this.id = id;
this.location = new ContentLocation(id);
this.state = new State(id.id());
this.state = new State().setName(id.id());
if (id.isResource())
this.image = new ResourceImage(this);
else
Expand Down
149 changes: 102 additions & 47 deletions src/main/java/com/kamesuta/mc/signpic/gui/GuiMain.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.kamesuta.mc.signpic.gui;

import java.awt.Toolkit;
import java.awt.datatransfer.Transferable;
import java.util.concurrent.TimeUnit;

import org.lwjgl.input.Keyboard;
Expand All @@ -20,10 +22,12 @@
import com.kamesuta.mc.bnnwidget.var.V;
import com.kamesuta.mc.bnnwidget.var.VMotion;
import com.kamesuta.mc.signpic.Apis;
import com.kamesuta.mc.signpic.Client;
import com.kamesuta.mc.signpic.entry.Entry;
import com.kamesuta.mc.signpic.entry.EntryId;
import com.kamesuta.mc.signpic.entry.EntryIdBuilder;
import com.kamesuta.mc.signpic.entry.content.ContentManager;
import com.kamesuta.mc.signpic.gui.file.FileUtilitiy;
import com.kamesuta.mc.signpic.gui.file.McUiUpload;
import com.kamesuta.mc.signpic.information.Informations;
import com.kamesuta.mc.signpic.mode.CurrentMode;
Expand All @@ -35,8 +39,20 @@
import net.minecraft.client.resources.I18n;

public class GuiMain extends WFrame {
private final EntryIdBuilder signbuilder = new EntryIdBuilder(CurrentMode.instance.getEntryId());
private MChatTextField field;
private final EntryIdBuilder signbuilder = new EntryIdBuilder().load(CurrentMode.instance.getEntryId());

public void setURL(final String url) {
this.signbuilder.setURI(url);
final MainTextField field = getTextField();
field.setText(url);
field.apply();
}

public void export() {
CurrentMode.instance.setEntryId(GuiMain.this.signbuilder.build());
}

private MainTextField field;

public GuiMain(final GuiScreen parent) {
super(parent);
Expand Down Expand Up @@ -99,23 +115,26 @@ public boolean onClosing(final WEvent ev, final Area pgp, final Point mouse) {
@Override
protected void onUpdate() {
super.onUpdate();
CurrentMode.instance.setEntryId(GuiMain.this.signbuilder.build());
export();
;
}
});

add(new GuiOffset(new R(Coord.top(15*3+10), Coord.left(5), Coord.width(15*8), Coord.height(15*3)), GuiMain.this.signbuilder.getMeta().offset) {
@Override
protected void onUpdate() {
super.onUpdate();
CurrentMode.instance.setEntryId(GuiMain.this.signbuilder.build());
export();
;
}
});

add(new GuiRotation(new R(Coord.top(15*8), Coord.left(5), Coord.width(15*8), Coord.height(15*4)), GuiMain.this.signbuilder.getMeta().rotation) {
@Override
protected void onUpdate() {
super.onUpdate();
CurrentMode.instance.setEntryId(GuiMain.this.signbuilder.build());
export();
;
}
});

Expand Down Expand Up @@ -214,6 +233,18 @@ public boolean isHighlight() {
return McUiUpload.instance.isVisible();
}
});
add(new MButton(new R(Coord.right(5), Coord.top(top += 25), Coord.left(5), Coord.height(15)), I18n.format("signpic.gui.editor.paste")) {
@Override
protected boolean onClicked(final WEvent ev, final Area pgp, final Point p, final int button) {
try {
final Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
FileUtilitiy.transfer(transferable);
} catch (final Exception e) {
Client.notice(I18n.format("signpic.gui.notice.paste.unsupported", e), 2);
}
return true;
}
});

float bottom = 25*4+5;

Expand Down Expand Up @@ -266,7 +297,7 @@ public boolean mouseClicked(final WEvent ev, final Area pgp, final Point p, fina
if (a.pointInside(p)) {
final Entry entry = CurrentMode.instance.getEntryId().entry();
if (entry.isValid()&&!entry.id.isPlaceable())
OverlayFrame.instance.pane.addNotice1(I18n.format("signpic.gui.editor.notice.toolong"), 1f);
Client.notice(I18n.format("signpic.gui.editor.notice.toolong"), 1f);
}
return super.mouseClicked(ev, pgp, p, button);
}
Expand Down Expand Up @@ -312,46 +343,7 @@ public boolean onClosing(final WEvent ev, final Area pgp, final Point mouse) {
});

final VMotion d = V.am(-15).add(Easings.easeOutBack.move(.5f, 5)).start();
GuiMain.this.field = new MChatTextField(new R(Coord.left(5), Coord.bottom(d), Coord.right(70), Coord.height(15))) {
@Override
public void onAdded() {
super.onAdded();
setMaxStringLength(Integer.MAX_VALUE);
setWatermark(I18n.format("signpic.gui.editor.textfield"));

final EntryId id = CurrentMode.instance.getEntryId();
if (id.hasContentId())
setText(id.getContentId().getID());
}

@Override
public void onFocusChanged() {
final EntryId entryId = new EntryId(getText());
if (entryId.hasMeta())
GuiMain.this.signbuilder.setMeta(entryId.getMeta());
if (entryId.hasContentId()) {
String url = entryId.getContentId().getURI();
setText(url = Apis.instance.replaceURL(url));
GuiMain.this.signbuilder.setURI(url);
} else
GuiMain.this.signbuilder.setURI("");
CurrentMode.instance.setEntryId(GuiMain.this.signbuilder.build());
}

@Override
public boolean mouseClicked(final WEvent ev, final Area pgp, final Point p, final int button) {
final int cursor1 = getCursorPosition();
final boolean focused1 = isFocused();
final boolean b = super.mouseClicked(ev, pgp, p, button);
final int cursor2 = getCursorPosition();
final boolean focused2 = isFocused();
final Area a = getGuiPosition(pgp);
if (a.pointInside(p))
if (focused1&&focused2&&cursor1==cursor2)
setText(GuiScreen.getClipboardString());
return b;
}

GuiMain.this.field = new MainTextField(new R(Coord.left(5), Coord.bottom(d), Coord.right(70), Coord.height(15))) {
@Override
public boolean onCloseRequest() {
super.onCloseRequest();
Expand All @@ -374,7 +366,7 @@ public boolean onClosing(final WEvent ev, final Area pgp, final Point mouse) {
Informations.instance.checkInterval(TimeUnit.DAYS.toMillis(1l));
}

public MChatTextField getTextField() {
public MainTextField getTextField() {
return this.field;
}

Expand All @@ -389,4 +381,67 @@ public void onGuiClosed() {
public boolean doesGuiPauseGame() {
return super.sDoesGuiPauseGame();
}

public static boolean setContentId(final String id) {
if (Client.mc.currentScreen instanceof GuiMain) {
final GuiMain editor = (GuiMain) Client.mc.currentScreen;
editor.setURL(id);
return true;
} else {
final EntryId entryId = CurrentMode.instance.getEntryId();
final EntryIdBuilder signbuilder = new EntryIdBuilder().load(entryId);
signbuilder.setURI(id);
CurrentMode.instance.setEntryId(signbuilder.build());
return false;
}
}

public class MainTextField extends MChatTextField {
public MainTextField(final R position) {
super(position);
}

@Override
public void onAdded() {
super.onAdded();
setMaxStringLength(Integer.MAX_VALUE);
setWatermark(I18n.format("signpic.gui.editor.textfield"));

final EntryId id = CurrentMode.instance.getEntryId();
if (id.hasContentId())
setText(id.getContentId().getID());
}

@Override
public void onFocusChanged() {
apply();
}

public void apply() {
final EntryId entryId = new EntryId(getText());
if (entryId.hasMeta())
GuiMain.this.signbuilder.setMeta(entryId.getMeta());
if (entryId.hasContentId()) {
String url = entryId.getContentId().getURI();
setText(url = Apis.instance.replaceURL(url));
GuiMain.this.signbuilder.setURI(url);
} else
GuiMain.this.signbuilder.setURI("");
export();
}

@Override
public boolean mouseClicked(final WEvent ev, final Area pgp, final Point p, final int button) {
final int cursor1 = getCursorPosition();
final boolean focused1 = isFocused();
final boolean b = super.mouseClicked(ev, pgp, p, button);
final int cursor2 = getCursorPosition();
final boolean focused2 = isFocused();
final Area a = getGuiPosition(pgp);
if (a.pointInside(p))
if (focused1&&focused2&&cursor1==cursor2)
setText(GuiScreen.getClipboardString());
return b;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public boolean onClosing(final WEvent ev, final Area pgp, final Point p) {
return true;
}

@Deprecated
public void addNotice1(final String string, final float showtime) {
invokeLater(new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kamesuta.mc.signpic.gui.file;

import java.awt.datatransfer.Transferable;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -42,4 +43,9 @@ protected void close() {
protected void apply(final File f) {
Reference.logger.info(f.getAbsolutePath());
}

@Override
protected void transfer(final Transferable transferable) {
Reference.logger.info(transferable);
}
};
Loading

0 comments on commit 2bb2ddd

Please sign in to comment.