Added image preview.
Base64 encoding is now done thru a temporary file.
This commit is contained in:
parent
891603dea2
commit
3f61e9b35b
5 changed files with 380 additions and 193 deletions
|
@ -40,18 +40,19 @@ import thinlet.FrameLauncher;
|
|||
import thinlet.Thinlet;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.sql.*;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
|
||||
|
@ -225,66 +226,74 @@ public class LifeBlogger extends Thinlet
|
|||
}
|
||||
}
|
||||
|
||||
final Connection con = DriverManager.getConnection(JDBC_PREFIX + _homeDir.getAbsolutePath() + DATABASE);
|
||||
Connection con = null;
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
final Statement st = con.createStatement();
|
||||
final ResultSet rs =
|
||||
st.executeQuery("SELECT * FROM HooverObject WHERE MobileFavourite = 'true' ORDER BY TimeStamp DESC");
|
||||
|
||||
Object row;
|
||||
Object cell;
|
||||
String ts;
|
||||
String name;
|
||||
|
||||
boolean first = true;
|
||||
int found = 0;
|
||||
|
||||
while (rs.next())
|
||||
try
|
||||
{
|
||||
ts = rs.getString("TimeStamp");
|
||||
name = rs.getString("name");
|
||||
con = DriverManager.getConnection(JDBC_PREFIX + _homeDir.getAbsolutePath() + DATABASE);
|
||||
|
||||
row = Thinlet.create("row");
|
||||
st = con.createStatement();
|
||||
rs = st.executeQuery("SELECT * FROM HooverObject WHERE MobileFavourite = 'true' ORDER BY TimeStamp DESC");
|
||||
|
||||
cell = Thinlet.create("cell");
|
||||
thinlet.setString(cell, "text", name);
|
||||
Object row;
|
||||
Object cell;
|
||||
String ts;
|
||||
String name;
|
||||
|
||||
if (name.toLowerCase().endsWith("jpg"))
|
||||
boolean first = true;
|
||||
int found = 0;
|
||||
|
||||
while (rs.next())
|
||||
{
|
||||
thinlet.setIcon(cell, "icon", getIcon("/icon/image.gif"));
|
||||
}
|
||||
else if (name.toLowerCase().endsWith("3gp"))
|
||||
{
|
||||
thinlet.setIcon(cell, "icon", getIcon("/icon/movie.gif"));
|
||||
}
|
||||
else
|
||||
{
|
||||
thinlet.setIcon(cell, "icon", getIcon("/icon/text.gif"));
|
||||
ts = rs.getString("TimeStamp");
|
||||
name = rs.getString("name");
|
||||
|
||||
row = Thinlet.create("row");
|
||||
|
||||
cell = Thinlet.create("cell");
|
||||
thinlet.setString(cell, "text", name);
|
||||
|
||||
if (name.toLowerCase().endsWith("jpg"))
|
||||
{
|
||||
thinlet.setIcon(cell, "icon", getIcon("/icon/image.gif"));
|
||||
}
|
||||
else if (name.toLowerCase().endsWith("3gp"))
|
||||
{
|
||||
thinlet.setIcon(cell, "icon", getIcon("/icon/movie.gif"));
|
||||
}
|
||||
else
|
||||
{
|
||||
thinlet.setIcon(cell, "icon", getIcon("/icon/text.gif"));
|
||||
}
|
||||
|
||||
thinlet.putProperty(cell, "oid", rs.getString("HooverObjectID"));
|
||||
thinlet.add(row, cell);
|
||||
|
||||
cell = Thinlet.create("cell");
|
||||
thinlet.setString(cell, "text", ts.substring(0, ts.lastIndexOf(':')));
|
||||
thinlet.add(row, cell);
|
||||
|
||||
if (first)
|
||||
{
|
||||
thinlet.setBoolean(row, "selected", true);
|
||||
first = false;
|
||||
}
|
||||
|
||||
thinlet.add(table, row);
|
||||
|
||||
found++;
|
||||
}
|
||||
|
||||
thinlet.putProperty(cell, "oid", rs.getString("HooverObjectID"));
|
||||
thinlet.add(row, cell);
|
||||
|
||||
cell = Thinlet.create("cell");
|
||||
thinlet.setString(cell, "text", ts.substring(0, ts.lastIndexOf(':')));
|
||||
thinlet.add(row, cell);
|
||||
|
||||
if (first)
|
||||
{
|
||||
thinlet.setBoolean(row, "selected", true);
|
||||
first = false;
|
||||
}
|
||||
|
||||
thinlet.add(table, row);
|
||||
|
||||
found++;
|
||||
thinlet.setString(find(buttonsPanel, "favslbl"), "text", "Favorites: " + found);
|
||||
}
|
||||
finally
|
||||
{
|
||||
st.close();
|
||||
rs.close();
|
||||
con.close();
|
||||
}
|
||||
|
||||
thinlet.setString(find(buttonsPanel, "favslbl"), "text", "Favorites: " + found);
|
||||
|
||||
st.close();
|
||||
rs.close();
|
||||
con.close();
|
||||
|
||||
toggleButton(table, find(buttonsPanel, "blogbtn"));
|
||||
}
|
||||
|
@ -304,30 +313,21 @@ public class LifeBlogger extends Thinlet
|
|||
if (selected != -1)
|
||||
{
|
||||
final Object row = getItem(table, selected);
|
||||
final String name = String.valueOf(getProperty(getItem(row, 0), "oid"));
|
||||
final String oid = String.valueOf(getProperty(getItem(row, 0), "oid"));
|
||||
|
||||
final Connection con = DriverManager.getConnection(JDBC_PREFIX + _homeDir.getAbsolutePath() + DATABASE);
|
||||
final String[] info = fileInfo(oid);
|
||||
|
||||
final Statement st = con.createStatement();
|
||||
final ResultSet rs = st.executeQuery("SELECT * FROM BinaryItem WHERE HooverObjectID = " + name);
|
||||
|
||||
if (rs.next())
|
||||
if (info[0].length() > 0)
|
||||
{
|
||||
if ("ftp".equals(_action))
|
||||
{
|
||||
ftpDialog(_homeDir.getAbsolutePath() + "\\DataStore" + rs.getString("Pathname") +
|
||||
rs.getString("Filename"));
|
||||
ftpDialog(info[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
mwDialog(_homeDir.getAbsolutePath() + "\\DataStore" + rs.getString("Pathname") +
|
||||
rs.getString("Filename"), rs.getString("ObjectMimeType"));
|
||||
mwDialog(info[1], info[2]);
|
||||
}
|
||||
}
|
||||
|
||||
st.close();
|
||||
rs.close();
|
||||
con.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -484,6 +484,76 @@ public class LifeBlogger extends Thinlet
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Previews a JPEG image.
|
||||
*
|
||||
* @param table The data table.
|
||||
*
|
||||
* @throws Exception If an error occurs while previewing the image.
|
||||
*/
|
||||
public final void preview(Object table)
|
||||
throws Exception
|
||||
{
|
||||
final int selected = getSelectedIndex(table);
|
||||
|
||||
if (selected != -1)
|
||||
{
|
||||
final Object row = getItem(table, selected);
|
||||
final String oid = String.valueOf(getProperty(getItem(row, 0), "oid"));
|
||||
|
||||
final String[] info = fileInfo(oid);
|
||||
|
||||
if (info[0].length() > 0)
|
||||
{
|
||||
if ((info[2].length() > 0) && info[2].endsWith("jpeg"))
|
||||
{
|
||||
// Retrieve the jpg image
|
||||
final BufferedImage in = ImageIO.read(new File(info[1]));
|
||||
|
||||
final int maxDim = 200;
|
||||
|
||||
final int height = in.getHeight();
|
||||
final int width = in.getWidth();
|
||||
|
||||
// Determine the scale.
|
||||
double scale = (double) maxDim / (double) height;
|
||||
|
||||
if (in.getWidth() > in.getHeight())
|
||||
{
|
||||
scale = (double) maxDim / (double) width;
|
||||
}
|
||||
|
||||
int scaledW = (int) (scale * (double) width);
|
||||
int scaledH = (int) (scale * (double) height);
|
||||
|
||||
// Set the scale.
|
||||
final AffineTransform tx = new AffineTransform();
|
||||
|
||||
if (scale <= 1.0d)
|
||||
{
|
||||
tx.scale(scale, scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
scaledW = width;
|
||||
scaledH = height;
|
||||
}
|
||||
|
||||
final BufferedImage out = new BufferedImage(scaledW, scaledH, BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
final Graphics2D g2d = out.createGraphics();
|
||||
g2d.drawImage(in, tx, null);
|
||||
g2d.dispose();
|
||||
|
||||
final Object preview = parse("preview.xml");
|
||||
setString(preview, "text", info[0]);
|
||||
setIcon(find(preview, "image"), "icon", out);
|
||||
add(preview);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an exception stacktrace.
|
||||
*
|
||||
|
@ -534,6 +604,50 @@ public class LifeBlogger extends Thinlet
|
|||
}
|
||||
}
|
||||
|
||||
// Returns an array containg the file name, location and mime type.
|
||||
private String[] fileInfo(String objectID)
|
||||
throws SQLException
|
||||
{
|
||||
final String[] info = new String[] { "", "", "" };
|
||||
Connection con = null;
|
||||
Statement st = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
try
|
||||
{
|
||||
con = DriverManager.getConnection(JDBC_PREFIX + _homeDir.getAbsolutePath() + DATABASE);
|
||||
|
||||
st = con.createStatement();
|
||||
rs = st.executeQuery("SELECT * FROM BinaryItem WHERE HooverObjectID = " + objectID);
|
||||
|
||||
if (rs.next())
|
||||
{
|
||||
info[0] = rs.getString("Filename");
|
||||
info[1] = _homeDir.getAbsolutePath() + "\\DataStore" + rs.getString("Pathname") + info[0];
|
||||
info[2] = rs.getString("ObjectMimeType");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (st != null)
|
||||
{
|
||||
st.close();
|
||||
}
|
||||
|
||||
if (rs != null)
|
||||
{
|
||||
rs.close();
|
||||
}
|
||||
|
||||
if (con != null)
|
||||
{
|
||||
con.close();
|
||||
}
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
// Display the FTP dialog.
|
||||
private void ftpDialog(String file)
|
||||
{
|
||||
|
|
|
@ -91,7 +91,9 @@ public class LifeMediaObject extends LifeBlog
|
|||
public final void run()
|
||||
{
|
||||
FileInputStream fis = null;
|
||||
final BufferedReader input = null;
|
||||
FileOutputStream fos = null;
|
||||
BufferedOutputStream bos = null;
|
||||
Base64.OutputStream out = null;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -104,31 +106,23 @@ public class LifeMediaObject extends LifeBlog
|
|||
throw new IOException("Unsupported URL protocol: " + url.getProtocol());
|
||||
}
|
||||
|
||||
// The following is a little hackish.
|
||||
// A better way would be to generate the request to a temporary file.
|
||||
final long len = getFile().length();
|
||||
|
||||
if (len > Integer.MAX_VALUE)
|
||||
{
|
||||
throw new IOException("Sorry. The file is too large.");
|
||||
}
|
||||
final File tmpFile = File.createTempFile(ReleaseInfo.getProject(), ".b64");
|
||||
tmpFile.deleteOnExit();
|
||||
|
||||
fis = new FileInputStream(getFile());
|
||||
fos = new FileOutputStream(tmpFile);
|
||||
bos = new BufferedOutputStream(fos);
|
||||
out = new Base64.OutputStream(bos, Base64.ENCODE | Base64.DONT_BREAK_LINES);
|
||||
|
||||
final byte[] bytes = new byte[(int) getFile().length()];
|
||||
final byte[] buf = new byte[1024];
|
||||
int len;
|
||||
|
||||
int offset = 0;
|
||||
int numRead = 0;
|
||||
|
||||
while ((offset < bytes.length) && ((numRead = fis.read(bytes, offset, bytes.length - offset)) >= 0))
|
||||
while ((len = fis.read(buf)) > 0)
|
||||
{
|
||||
offset += numRead;
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
|
||||
if (offset < bytes.length)
|
||||
{
|
||||
throw new IOException("Could not completely read file: " + getFile().getName());
|
||||
}
|
||||
fis.close();
|
||||
|
||||
final StringBuffer start =
|
||||
new StringBuffer("<?xml version=\"1.0\"?><methodCall><methodName>metaWeblog.newMediaObject</methodName><params><param><value><string>").append(_blogID)
|
||||
|
@ -137,7 +131,6 @@ public class LifeMediaObject extends LifeBlog
|
|||
.append("</string></value></param><param><value><string>")
|
||||
.append(getPassword())
|
||||
.append("</string></value></param><param><value><struct><member><name>bits</name><value><base64>");
|
||||
final String bits = Base64.encodeBytes(bytes);
|
||||
|
||||
final StringBuffer end =
|
||||
new StringBuffer("</base64></value></member><member><name>name</name><value><string>").append(getFilename())
|
||||
|
@ -149,18 +142,28 @@ public class LifeMediaObject extends LifeBlog
|
|||
urlConn.setDoInput(true);
|
||||
urlConn.setDoOutput(true);
|
||||
urlConn.setUseCaches(false);
|
||||
urlConn.setRequestProperty("Content-Length", String.valueOf(start.length() + bits.length() + end.length()));
|
||||
urlConn.setRequestProperty("Content-Length",
|
||||
String.valueOf(start.length() + tmpFile.length() + end.length()));
|
||||
urlConn.setRequestProperty("Content-Type", "text/xml");
|
||||
|
||||
final DataOutputStream output = new DataOutputStream(urlConn.getOutputStream());
|
||||
output.write(start.toString().getBytes());
|
||||
output.flush();
|
||||
output.write(bits.getBytes());
|
||||
output.flush();
|
||||
output.write(end.toString().getBytes());
|
||||
output.flush();
|
||||
final DataOutputStream dos = new DataOutputStream(urlConn.getOutputStream());
|
||||
dos.write(start.toString().getBytes());
|
||||
dos.flush();
|
||||
|
||||
output.close();
|
||||
fis = new FileInputStream(tmpFile);
|
||||
|
||||
while ((len = fis.read(buf)) > 0)
|
||||
{
|
||||
dos.write(buf, 0, len);
|
||||
dos.flush();
|
||||
}
|
||||
|
||||
fis.close();
|
||||
|
||||
dos.write(end.toString().getBytes());
|
||||
dos.flush();
|
||||
|
||||
dos.close();
|
||||
|
||||
final LifeMediaObjResponse xmlrpc = new LifeMediaObjResponse(urlConn.getInputStream());
|
||||
|
||||
|
@ -188,18 +191,6 @@ public class LifeMediaObject extends LifeBlog
|
|||
}
|
||||
finally
|
||||
{
|
||||
if (input != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
input.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
; // Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
if (fis != null)
|
||||
{
|
||||
try
|
||||
|
@ -211,6 +202,42 @@ public class LifeMediaObject extends LifeBlog
|
|||
; // Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
if (bos != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
bos.close();
|
||||
}
|
||||
catch (IOException ignore)
|
||||
{
|
||||
; // Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
if (fos != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
fos.close();
|
||||
}
|
||||
catch (IOException ignore)
|
||||
{
|
||||
; // Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
if (out != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
out.close();
|
||||
}
|
||||
catch (IOException ignore)
|
||||
{
|
||||
; // Do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Created by JReleaseInfo AntTask from Open Source Competence Group */
|
||||
/* Creation date Thu Jul 22 16:15:30 PDT 2004 */
|
||||
/* Creation date Thu Jul 22 22:36:26 PDT 2004 */
|
||||
package net.thauvin.lifeblogger;
|
||||
|
||||
import java.util.Date;
|
||||
|
@ -12,21 +12,21 @@ import java.util.Date;
|
|||
public class ReleaseInfo {
|
||||
|
||||
|
||||
/** buildDate (set during build process to 1090538130250L). */
|
||||
private static Date buildDate = new Date(1090538130250L);
|
||||
/** buildDate (set during build process to 1090560986937L). */
|
||||
private static Date buildDate = new Date(1090560986937L);
|
||||
|
||||
/**
|
||||
* Get buildDate (set during build process to Thu Jul 22 16:15:30 PDT 2004).
|
||||
* Get buildDate (set during build process to Thu Jul 22 22:36:26 PDT 2004).
|
||||
* @return Date buildDate
|
||||
*/
|
||||
public static final Date getBuildDate() { return buildDate; }
|
||||
|
||||
|
||||
/**
|
||||
* Get buildNumber (set during build process to 95).
|
||||
* Get buildNumber (set during build process to 97).
|
||||
* @return int buildNumber
|
||||
*/
|
||||
public static final int getBuildNumber() { return 95; }
|
||||
public static final int getBuildNumber() { return 97; }
|
||||
|
||||
|
||||
/** version (set during build process to "0.1.0"). */
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
</menubar>
|
||||
<panel gap="4" top="3" left="3" bottom="3" right="3" columns="1" weighty="1">
|
||||
|
||||
<table name="table" weightx="1" weighty="1" init="addTableRows(thinlet, table, btns)" action="toggleButton(this, blogbtn)">
|
||||
<table name="table" weightx="1" weighty="1" init="addTableRows(thinlet, table, btns)" action="toggleButton(this, blogbtn)" perform="preview(this)">
|
||||
<header>
|
||||
<column text="Name" width="270"/>
|
||||
<column text="Date"/>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue