Allow program to be run in an offline mode. Begin work on new sigIRC
main panel.
This commit is contained in:
parent
f07a89fe22
commit
63dfe0c60e
BIN
sigIRCv2.jar
BIN
sigIRCv2.jar
Binary file not shown.
@ -99,7 +99,7 @@ public class MyPanel extends JPanel implements MouseListener, ActionListener, Mo
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!sigIRC.overlayMode) {
|
||||
if (!sigIRC.overlayMode && sigIRC.button!=null) {
|
||||
sigIRC.button.draw(g);
|
||||
}
|
||||
}
|
||||
@ -183,19 +183,23 @@ public class MyPanel extends JPanel implements MouseListener, ActionListener, Mo
|
||||
}
|
||||
|
||||
public static void UpdateComponent(Component com) {
|
||||
sigIRC.windowX = (int)sigIRC.window.getLocationOnScreen().getX();
|
||||
sigIRC.windowY = (int)sigIRC.window.getLocationOnScreen().getY();
|
||||
sigIRC.windowWidth = sigIRC.window.getWidth();
|
||||
sigIRC.windowHeight = sigIRC.window.getHeight();
|
||||
sigIRC.config.setInteger("windowX", sigIRC.windowX);
|
||||
sigIRC.config.setInteger("windowY", sigIRC.windowY);
|
||||
sigIRC.config.setInteger("windowWidth", sigIRC.windowWidth);
|
||||
sigIRC.config.setInteger("windowHeight", sigIRC.windowHeight);
|
||||
sigIRC.button.x = sigIRC.panel.getX()+sigIRC.panel.getWidth()-96;
|
||||
sigIRC.button.y = 64+sigIRC.rowobj.size()*sigIRC.rowSpacing;
|
||||
//com.repaint();
|
||||
//sigIRC.panel.repaint();
|
||||
sigIRC.config.saveProperties();
|
||||
if (sigIRC.window!=null && sigIRC.window.getLocationOnScreen()!=null) {
|
||||
sigIRC.windowX = (int)sigIRC.window.getLocationOnScreen().getX();
|
||||
sigIRC.windowY = (int)sigIRC.window.getLocationOnScreen().getY();
|
||||
sigIRC.windowWidth = sigIRC.window.getWidth();
|
||||
sigIRC.windowHeight = sigIRC.window.getHeight();
|
||||
sigIRC.config.setInteger("windowX", sigIRC.windowX);
|
||||
sigIRC.config.setInteger("windowY", sigIRC.windowY);
|
||||
sigIRC.config.setInteger("windowWidth", sigIRC.windowWidth);
|
||||
sigIRC.config.setInteger("windowHeight", sigIRC.windowHeight);
|
||||
if (sigIRC.button!=null) {
|
||||
sigIRC.button.x = sigIRC.panel.getX()+sigIRC.panel.getWidth()-96;
|
||||
sigIRC.button.y = 64+sigIRC.rowobj.size()*sigIRC.rowSpacing;
|
||||
}
|
||||
//com.repaint();
|
||||
//sigIRC.panel.repaint();
|
||||
sigIRC.config.saveProperties();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -220,7 +224,7 @@ public class MyPanel extends JPanel implements MouseListener, ActionListener, Mo
|
||||
m.windowClosed(ev);
|
||||
}
|
||||
sigIRC.config.saveProperties();
|
||||
if (sigIRC.autoUpdateProgram==0) {
|
||||
if (sigIRC.autoUpdateProgram==0 && !sigIRC.offlineMode && sigIRC.updateAvailable) {
|
||||
try {
|
||||
FileUtils.copyFile(new File(sigIRC.PROGRAM_UPDATE_FILE), new File(sigIRC.BASEDIR+"sigIRCv2.jar"));
|
||||
} catch (IOException e) {
|
||||
|
@ -38,6 +38,7 @@ import sig.utils.MemoryUtils;
|
||||
import sig.utils.TextUtils;
|
||||
import sig.windows.IntroDialog;
|
||||
import sig.windows.LoadingDialog;
|
||||
import sig.windows.ProgramWindow;
|
||||
import sig.windows.TwitchEmoteDownload;
|
||||
|
||||
import java.awt.Color;
|
||||
@ -73,6 +74,7 @@ public class sigIRC{
|
||||
final public static String VERSION = "1.0";
|
||||
|
||||
public static MyPanel panel = null;
|
||||
public static boolean offlineMode = false;
|
||||
public static ColorPanel colorpanel = null;
|
||||
public static List<ScrollingText> textobj = new ArrayList<ScrollingText>();
|
||||
public static List<TextRow> rowobj = new ArrayList<TextRow>();
|
||||
@ -99,15 +101,16 @@ public class sigIRC{
|
||||
final public static int DINGTIMER=150;
|
||||
static boolean dingEnabled=true;
|
||||
static int dingThreshold;
|
||||
static Color backgroundcol;
|
||||
public static Color backgroundcol;
|
||||
public static BackgroundColorButton button;
|
||||
public static JFrame window;
|
||||
static boolean overlayMode=false;
|
||||
static boolean showWindowControls=false;
|
||||
static int windowX=0;
|
||||
static int windowY=0;
|
||||
static int windowWidth=0;
|
||||
static int windowHeight=0;
|
||||
public static ProgramWindow window;
|
||||
public static boolean overlayMode=false;
|
||||
public static boolean showWindowControls=false;
|
||||
public static boolean updateAvailable=false;
|
||||
public static int windowX=0;
|
||||
public static int windowY=0;
|
||||
public static int windowWidth=0;
|
||||
public static int windowHeight=0;
|
||||
static int chatRows=3;
|
||||
static int chatScrollSpd=4;
|
||||
static int rowSpacing=64;
|
||||
@ -118,7 +121,7 @@ public class sigIRC{
|
||||
public static boolean twitchmodule_enabled=true;
|
||||
public static boolean chatlogmodule_enabled=true;
|
||||
static boolean downloadsComplete=false;
|
||||
static boolean hardwareAcceleration=true;
|
||||
public static boolean hardwareAcceleration=true;
|
||||
static boolean playedoAuthSoundOnce=false;
|
||||
public static int twitchmodule_width=500;
|
||||
public static int twitchmodule_height=200;
|
||||
@ -251,7 +254,9 @@ public class sigIRC{
|
||||
|
||||
//new IntroDialog();
|
||||
loadingdialog = new LoadingDialog();
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
DownloadAllRequiredDependencies();
|
||||
@ -365,6 +370,7 @@ public class sigIRC{
|
||||
programFile.delete();
|
||||
}
|
||||
org.apache.commons.io.FileUtils.copyURLToFile(new URL(sigIRC.PROGRAM_EXECUTABLE_URL),programFile);
|
||||
sigIRC.updateAvailable=true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Reader;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
@ -207,18 +208,21 @@ public class FileUtils {
|
||||
}
|
||||
|
||||
public static JSONObject readJsonFromUrl(String url, String file, boolean writeToFile) throws IOException, JSONException {
|
||||
InputStream is = new URL(url).openStream();
|
||||
InputStream is;
|
||||
try {
|
||||
is = new URL(url).openStream();
|
||||
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
|
||||
String jsonText = readAll(rd);
|
||||
if (writeToFile) {
|
||||
writetoFile(new String[]{jsonText},file);
|
||||
}
|
||||
JSONObject json = new JSONObject(jsonText);
|
||||
return json;
|
||||
} finally {
|
||||
is.close();
|
||||
return json;
|
||||
} catch (UnknownHostException e) {
|
||||
sigIRC.offlineMode = true;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JSONArray readJsonArrayFromUrl(String url, String file, boolean writeToFile) throws IOException, JSONException {
|
||||
|
@ -4,6 +4,7 @@ import java.awt.Dimension;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -101,21 +102,26 @@ public class LoadingDialog extends JFrame{
|
||||
managers.add(new FileManager("sigIRC/rabi-ribi/items/attack_up.png"));
|
||||
}
|
||||
|
||||
JSONObject twitchemotes;
|
||||
try {
|
||||
twitchemotes = FileUtils.readJsonFromUrl("https://twitchemotes.com/api_cache/v3/global.json");
|
||||
System.out.println("Twitch emote Json read.");
|
||||
for (String emotes : twitchemotes.keySet()) {
|
||||
JSONObject emote = twitchemotes.getJSONObject(emotes);
|
||||
int id = emote.getInt("id");
|
||||
String name = emote.getString("code");
|
||||
LoadingDialog.emotes.add(new TwitchEmoteDownload(name,id));
|
||||
managers.add(new FakeFileManager("_FAKE_"));
|
||||
//emoticons.add(new Emoticon(name, new URL(TWITCHEMOTEURL+id+"/1.0")));
|
||||
System.out.println("Emote "+id+" with name "+name);
|
||||
if (!sigIRC.offlineMode) {
|
||||
JSONObject twitchemotes;
|
||||
try {
|
||||
twitchemotes = FileUtils.readJsonFromUrl("https://twitchemotes.com/api_cache/v3/global.json");
|
||||
System.out.println("Twitch emote Json read.");
|
||||
if (twitchemotes!=null) {
|
||||
for (String emotes : twitchemotes.keySet()) {
|
||||
JSONObject emote = twitchemotes.getJSONObject(emotes);
|
||||
int id = emote.getInt("id");
|
||||
String name = emote.getString("code");
|
||||
LoadingDialog.emotes.add(new TwitchEmoteDownload(name,id));
|
||||
managers.add(new FakeFileManager("_FAKE_"));
|
||||
//emoticons.add(new Emoticon(name, new URL(TWITCHEMOTEURL+id+"/1.0")));
|
||||
System.out.println("Emote "+id+" with name "+name);
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException | JSONException | IOException e) {
|
||||
sigIRC.offlineMode=true;
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (JSONException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
bar.setValue(0);
|
||||
@ -148,20 +154,25 @@ public class LoadingDialog extends JFrame{
|
||||
|
||||
for (TwitchEmoteDownload d : emotes) {
|
||||
try {
|
||||
d.download();
|
||||
if (!sigIRC.offlineMode) {
|
||||
d.download();
|
||||
}
|
||||
bar.setValue(bar.getValue()+1);
|
||||
UpdateBar();
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sigIRC.prepareTwitchEmoteUpdate();
|
||||
if (!sigIRC.offlineMode) {
|
||||
sigIRC.prepareTwitchEmoteUpdate();
|
||||
}
|
||||
twitchEmoteUpdate.setDone();
|
||||
bar.setValue(bar.getValue()+1);
|
||||
UpdateBar();
|
||||
sigIRC.DownloadProgramUpdate();
|
||||
if (!sigIRC.offlineMode) {
|
||||
sigIRC.DownloadProgramUpdate();
|
||||
}
|
||||
programUpdate.setDone();
|
||||
bar.setValue(bar.getValue()+1);
|
||||
UpdateBar();
|
||||
@ -186,6 +197,10 @@ public class LoadingDialog extends JFrame{
|
||||
sigIRC.emoticons.add(new Emoticon(":D","11"));
|
||||
sigIRC.emoticons.add(new Emoticon(">(","12"));
|
||||
sigIRC.emoticons.add(new Emoticon("<3","13"));
|
||||
|
||||
//Load is done. Start up the panel.
|
||||
sigIRC.window = new ProgramWindow();
|
||||
this.setVisible(false);
|
||||
}
|
||||
|
||||
private void UpdateBar() {
|
||||
|
104
src/sig/windows/ProgramWindow.java
Normal file
104
src/sig/windows/ProgramWindow.java
Normal file
@ -0,0 +1,104 @@
|
||||
package sig.windows;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import sig.BackgroundColorButton;
|
||||
import sig.ColorPanel;
|
||||
import sig.MyPanel;
|
||||
import sig.sigIRC;
|
||||
|
||||
public class ProgramWindow extends JFrame{
|
||||
|
||||
static Icon deselected_icon,selected_icon;
|
||||
|
||||
List<ModuleButton> buttons = new ArrayList<ModuleButton>();
|
||||
|
||||
public ProgramWindow() {
|
||||
try {
|
||||
deselected_icon = new ImageIcon(ImageIO.read(sigIRC.class.getResource("/resource/deselected_button.png")));
|
||||
selected_icon = new ImageIcon(ImageIO.read(sigIRC.class.getResource("/resource/selected_button.png")));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (sigIRC.overlayMode && sigIRC.showWindowControls) {
|
||||
JFrame.setDefaultLookAndFeelDecorated(true);
|
||||
}
|
||||
System.setProperty("sun.java2d.opengl", Boolean.toString(sigIRC.hardwareAcceleration));
|
||||
JFrame f = new JFrame("sigIRCv2");
|
||||
this.setAutoRequestFocus(true);
|
||||
this.toFront();
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
if (sigIRC.overlayMode && !sigIRC.showWindowControls) {
|
||||
this.setUndecorated(true);
|
||||
}
|
||||
sigIRC.panel = new MyPanel();
|
||||
if (sigIRC.overlayMode) {
|
||||
sigIRC.panel.setOpaque(false);
|
||||
}
|
||||
sigIRC.panel.setBackground(sigIRC.backgroundcol);
|
||||
|
||||
if (!sigIRC.disableChatMessages) {
|
||||
|
||||
}
|
||||
|
||||
//colorpanel = new ColorPanel();
|
||||
//this.add(colorpanel);
|
||||
this.add(sigIRC.panel);
|
||||
this.pack();
|
||||
this.setVisible(true);
|
||||
this.setLocation(sigIRC.windowX, sigIRC.windowY);
|
||||
this.setSize(sigIRC.windowWidth, sigIRC.windowHeight);
|
||||
|
||||
this.setIconImage(sigIRC.programIcon);
|
||||
|
||||
// button = new BackgroundColorButton(new File(sigIRC.BASEDIR+"backcolor.png"),panel.getX()+panel.getWidth()-96,64+rowobj.size()*rowSpacing);
|
||||
if (sigIRC.overlayMode) {
|
||||
this.setBackground(new Color(0,0,0,0));
|
||||
this.setAlwaysOnTop(true);
|
||||
}
|
||||
//this.setOpacity(0.5f);
|
||||
this.addWindowListener(sigIRC.panel);
|
||||
}
|
||||
}
|
||||
|
||||
class ModuleButton extends JToggleButton {
|
||||
String label = "";
|
||||
ModuleButton button;
|
||||
public ModuleButton(String label) {
|
||||
this.label=label;
|
||||
this.button=this;
|
||||
this.setBackground(Color.DARK_GRAY);
|
||||
button.setForeground(Color.GRAY);
|
||||
button.setIconTextGap(4);
|
||||
button.setIcon(IntroDialog.deselected_icon);
|
||||
button.setSelectedIcon(IntroDialog.selected_icon);
|
||||
this.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if (button.isSelected()) {
|
||||
button.setForeground(Color.BLUE);
|
||||
}
|
||||
else {
|
||||
button.setBackground(Color.DARK_GRAY);
|
||||
button.setForeground(Color.GRAY);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user