Skip to content

Commit

Permalink
Display captions in the picture list.
Browse files Browse the repository at this point in the history
Save and load ready to upload albums (and save a backup before uploading, in case of a problem).
Reformatted many source files using IdeaJ.
  • Loading branch information
Pierre-Luc Paour committed May 7, 2003
1 parent dbfc3e5 commit b549dc5
Showing 1 changed file with 143 additions and 18 deletions.
161 changes: 143 additions & 18 deletions com/gallery/GalleryRemote/MainFrame.java
Expand Up @@ -20,19 +20,36 @@
*/
package com.gallery.GalleryRemote;

import HTTPClient.*;
import com.gallery.GalleryRemote.model.*;

import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.*;
import java.net.URL;
import java.net.MalformedURLException;
import java.text.*;
import java.util.*;
import java.net.URL;
import java.text.NumberFormat;
import java.util.Vector;

import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.border.BevelBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import com.gallery.GalleryRemote.model.Album;
import com.gallery.GalleryRemote.model.Gallery;
import com.gallery.GalleryRemote.model.Picture;
import com.gallery.GalleryRemote.util.ImageUtils;
import JSX.ObjOut;
import JSX.ObjIn;

/**
* Description of the Class
Expand Down Expand Up @@ -90,6 +107,8 @@ public class MainFrame extends javax.swing.JFrame
GridBagLayout gridBagLayout3 = new GridBagLayout();
JMenu jMenuFile = new JMenu();
JMenuItem jMenuItemQuit = new JMenuItem();
JMenuItem jMenuItemSave = new JMenuItem();
JMenuItem jMenuItemOpen = new JMenuItem();
JMenu jMenuHelp = new JMenu();
JMenuItem jMenuItemAbout = new JMenuItem();
JMenu jMenuOptions = new JMenu();
Expand All @@ -99,6 +118,7 @@ public class MainFrame extends javax.swing.JFrame
JScrollPane jScrollPane1 = new JScrollPane();
JList picturesList = new DroppableList();
JButton newGallery = new JButton();
public static final String FILE_TYPE = ".grg";


/**
Expand Down Expand Up @@ -211,7 +231,7 @@ void thisWindowClosing( java.awt.event.WindowEvent e ) {
p.setIntProperty( "inspectorDividerLocation", inspectorDivider.getDividerLocation() );

p.write();

setVisible( false );
dispose();

Expand Down Expand Up @@ -282,7 +302,7 @@ public void run() {

// status
if ( mAlbum == null) {
pictureInspector.setPictures( (Object[]) null );
pictureInspector.setPictures( null );

setStatus( "Select a Gallery URL and click Log in..." );
} else if ( mAlbum.sizePictures() > 0 ) {
Expand All @@ -302,7 +322,7 @@ public void run() {
+ " K" );
}
} else {
pictureInspector.setPictures( (Object[]) null );
pictureInspector.setPictures( null );

setStatus( "No selection" );
}
Expand Down Expand Up @@ -358,7 +378,7 @@ private void updatePicturesList( Album album ) {
picturesList.setModel( mAlbum );
mAlbum.setListSelectionModel(picturesList.getSelectionModel());
picturesList.getModel().addListDataListener( this );
pictureInspector.setPictures( (Object[]) null );
pictureInspector.setPictures( null );
}
}

Expand Down Expand Up @@ -549,7 +569,13 @@ public boolean equals( Object o1, Object o2 )
*/
public void uploadPictures() {
Log.log(Log.INFO, MODULE, "uploadPictures starting");


File f = new File(System.getProperty("user.home")
+ File.separator + ".GalleryRemote"
+ File.separator + "backup.grg");

saveState(f);

currentGallery.uploadFiles( this );
}

Expand Down Expand Up @@ -737,6 +763,10 @@ private void jbInit()
jMenuFile.setText( "File" );
jMenuItemQuit.setText( "Quit" );
jMenuItemQuit.setActionCommand( "File.Quit" );
jMenuItemSave.setText( "Save" );
jMenuItemSave.setActionCommand( "File.Save" );
jMenuItemOpen.setText( "Open" );
jMenuItemOpen.setActionCommand( "File.Open" );
jMenuHelp.setText( "Help" );
jMenuItemAbout.setActionCommand( "Help.About" );
jMenuItemAbout.setText( "About Gallery Remote..." );
Expand Down Expand Up @@ -797,6 +827,8 @@ private void jbInit()
jMenuBar1.add( jMenuFile );
jMenuBar1.add( jMenuOptions );
jMenuBar1.add( jMenuHelp );
jMenuFile.add( jMenuItemSave );
jMenuFile.add( jMenuItemOpen );
jMenuFile.add( jMenuItemQuit );
jMenuHelp.add( jMenuItemAbout );
jMenuOptions.add( jCheckBoxMenuThumbnails );
Expand All @@ -814,6 +846,8 @@ private void jbInitEvents() {
gallery.addActionListener( this );
username.addCaretListener( this );
password.addCaretListener( this );
jMenuItemSave.addActionListener( this );
jMenuItemOpen.addActionListener( this );
jMenuItemQuit.addActionListener( this );
jMenuItemAbout.addActionListener( this );

Expand Down Expand Up @@ -864,6 +898,10 @@ public void actionPerformed( ActionEvent e ) {

if ( command.equals( "File.Quit" ) ) {
thisWindowClosing( null );
} else if ( command.equals( "File.Save" ) ) {
saveState();
} else if ( command.equals( "File.Open" ) ) {
openState();
} else if ( command.equals( "Help.About" ) ) {
showAboutBox();
} else if ( command.equals( "Fetch" ) ) {
Expand Down Expand Up @@ -920,6 +958,83 @@ public void actionPerformed( ActionEvent e ) {
}
}

static FileFilter galleryFileFilter = new FileFilter() {
public boolean accept(File f) {
return f.isDirectory() || f.getName().endsWith(FILE_TYPE);
}

public String getDescription() {
return "GalleryRemote galleries";
}
};

private void saveState() {
JFileChooser fc = new JFileChooser();
fc.setAcceptAllFileFilterUsed(false);
fc.setFileFilter(galleryFileFilter);

int returnVal = fc.showSaveDialog(this);

if(returnVal == JFileChooser.APPROVE_OPTION) {
String name = fc.getSelectedFile().getPath();

if (! name.endsWith(FILE_TYPE) ) {
name += FILE_TYPE;
}

saveState(new File(name));
}
}

private void saveState(File f) {
try {
Log.log(Log.INFO, MODULE, "Saving state to file " + f.getPath());

Gallery[] galleryArray = new Gallery[galleries.getSize()];

for (int i = 0; i < galleries.getSize(); i++) {
galleryArray[i] = (Gallery) galleries.getElementAt(i);
}

ObjOut out = new ObjOut(new BufferedWriter(new FileWriter(f)));
out.writeObject(galleryArray);
} catch (IOException e) {
Log.log(Log.ERROR, MODULE, "Exception while trying to save state");
Log.logException(Log.ERROR, MODULE, e);
}
}

private void openState() {
try {
JFileChooser fc = new JFileChooser();
fc.setAcceptAllFileFilterUsed(false);
fc.setFileFilter(galleryFileFilter);

int returnVal = fc.showOpenDialog(this);

if(returnVal == JFileChooser.APPROVE_OPTION) {
Log.log(Log.INFO, MODULE, "Opening state from file " + fc.getSelectedFile().getPath());

ObjIn in = new ObjIn(new BufferedReader(new FileReader(fc.getSelectedFile())));
Gallery[] galleryArray = (Gallery[]) in.readObject();
galleries = new DefaultComboBoxModel();
for (int i = 0; i < galleryArray.length; i++) {
galleries.addElement(galleryArray[i]);
}
gallery.setModel( galleries );
updateGalleryParams();

resetUIState();
}
} catch (IOException e) {
Log.log(Log.ERROR, MODULE, "Exception while trying to read state");
Log.logException(Log.ERROR, MODULE, e);
} catch (ClassNotFoundException e) {
Log.log(Log.ERROR, MODULE, "Exception while trying to read state (probably a version mismatch)");
Log.logException(Log.ERROR, MODULE, e);
}
}


/**
* CheckboxMenu handling
Expand Down Expand Up @@ -1005,7 +1120,7 @@ public void caretUpdate(CaretEvent e) {
public void jListKeyPressed( KeyEvent e ) {
if ( ! mInProgress) {
int vKey = e.getKeyCode();

switch ( vKey ) {
case KeyEvent.VK_DELETE:
case KeyEvent.VK_BACK_SPACE:
Expand Down Expand Up @@ -1057,11 +1172,21 @@ public Component getListCellRendererComponent(
setIconTextGap( 4 + GalleryRemote.getInstance().properties.getThumbnailSize().width - icon.getIconWidth() );
}

String text = f.getName();
StringBuffer text = new StringBuffer();
text.append("<html><p>");

text.append(f.getName());
if ( GalleryRemote.getInstance().properties.getShowPath() ) {
text += " [" + f.getParent() + "]";
text.append(" [").append(f.getParent()).append("]</p>");
}
setText( text );

if (p.getCaption() != null) {
text.append("<p><font color=\"gray\">").append(p.getEscapedCaption()).append("</font></p>");
}

text.append("</html>");
//Log.log(Log.TRACE, MODULE, text.toString());
setText( text.toString() );
} else {
setText("dummy");
}
Expand Down

0 comments on commit b549dc5

Please sign in to comment.