jace/src/main/java/jace/library/MediaEditUI.java
Brendan Robert 0ccb63558f A lot of things have been deactivated to sever the link to the old Swing UI. Indicators, namely, have been commented out in many places. Ultimately the emulator is wholly unusable in this state.
The video rendering was re-written to use writableImages and is displaying (something) but keyboard input and configurations are broken so nothing much happens after the inital boot.  Basically the underlying part to make this show up in JavaFX is starting to take shape.
2015-02-03 00:55:25 -06:00

442 lines
23 KiB
Java

/*
* Copyright (C) 2013 brobert.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package jace.library;
import jace.Emulator;
import jace.EmulatorUILogic;
import static jace.EmulatorUILogic.MEDIA_MANAGER_EDIT_DIALOG_NAME;
import jace.library.MediaEntry.MediaFile;
/**
*
* @author brobert
*/
public class MediaEditUI extends javax.swing.JPanel {
public static String CREATE_TITLE = "Create media entry";
public static String EDIT_TITLE = "Edit media entry";
public static String KEYWORD_DELIMITER = ",";
public static String BOX_BACK = "Box (back)";
public static String BOX_FRONT = "Box (front)";
public static String SCREENSHOT = "Screenshot";
/**
* Creates new form MediaEditUI
*/
public MediaEditUI() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
NameLabel = new javax.swing.JLabel();
Screenshot = new javax.swing.JLabel();
SourceLabel = new javax.swing.JLabel();
DescriptionLabel = new javax.swing.JLabel();
KeywordsLabel = new javax.swing.JLabel();
CategoryLabel = new javax.swing.JLabel();
PublishedLabel = new javax.swing.JLabel();
AuthorLabel = new javax.swing.JLabel();
SourceField = new javax.swing.JTextField();
NameField = new javax.swing.JTextField();
CategoryField = new javax.swing.JTextField();
DescriptionPane = new javax.swing.JScrollPane();
DescriptionField = new javax.swing.JTextArea();
AuthorField = new javax.swing.JTextField();
YearField = new javax.swing.JComboBox();
KeywordsField = new javax.swing.JTextField();
FavoriteField = new javax.swing.JCheckBox();
SaveButton = new javax.swing.JButton();
CancellationButton = new javax.swing.JButton();
ReplaceButton = new javax.swing.JButton();
InfoLabel = new javax.swing.JLabel();
CopyDiskButton = new javax.swing.JButton();
ScreenshotCombo = new javax.swing.JComboBox();
PublisherField = new javax.swing.JTextField();
PublisherLabel = new javax.swing.JLabel();
writeProtect = new javax.swing.JCheckBox();
setPreferredSize(new java.awt.Dimension(600, 400));
NameLabel.setText("Name");
Screenshot.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
Screenshot.setText("Screenshot");
Screenshot.setBorder(javax.swing.BorderFactory.createEtchedBorder());
Screenshot.setMaximumSize(new java.awt.Dimension(140, 96));
Screenshot.setMinimumSize(new java.awt.Dimension(140, 96));
Screenshot.setPreferredSize(new java.awt.Dimension(140, 192));
SourceLabel.setText("Source (URL)");
DescriptionLabel.setText("Description");
KeywordsLabel.setText("Keywords");
CategoryLabel.setText("Category");
PublishedLabel.setText("Published");
AuthorLabel.setText("Author");
SourceField.setText("http://website/diskImage.dsk");
SourceField.setToolTipText("URL of where disk came from, can also be a local file path");
NameField.setText("Disk name");
NameField.setToolTipText("Name of disk -- if part of a series include side or disk number");
CategoryField.setText("Category > sub cat > sub cat");
CategoryField.setToolTipText("Category (use > marks to separate sub-category)");
DescriptionField.setColumns(20);
DescriptionField.setRows(5);
DescriptionField.setText("Description of disk goes here");
DescriptionPane.setViewportView(DescriptionField);
AuthorField.setText("Smith, John");
YearField.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1976", "1977", "1978", "1979", "1980", "1981", "1982", "1983", "1984", "1985", "1986", "1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015" }));
KeywordsField.setText("Keyword1, Keyword2, Keyword3");
KeywordsField.setToolTipText("Relevant keywords (use commas to separate multiple keywords)");
FavoriteField.setText("Show in favorites");
SaveButton.setText("Save");
SaveButton.setToolTipText("Save metadata changes");
SaveButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SaveButtonActionPerformed(evt);
}
});
CancellationButton.setText("Close");
CancellationButton.setToolTipText("Abandon metadata changes and close");
CancellationButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CancellationButtonActionPerformed(evt);
}
});
ReplaceButton.setText("Replace Disk");
ReplaceButton.setToolTipText("Abandon current disk image and download a new copy from the source URL");
ReplaceButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ReplaceButtonActionPerformed(evt);
}
});
InfoLabel.setText("Disk usage here");
InfoLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);
CopyDiskButton.setText("Save copy of disk");
CopyDiskButton.setToolTipText("Create a local copy of the disk image on your hard drive");
CopyDiskButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CopyDiskButtonActionPerformed(evt);
}
});
ScreenshotCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Screenshot", "Box (front)", "Box (back)" }));
ScreenshotCombo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ScreenshotComboActionPerformed(evt);
}
});
PublisherField.setText("Publisher");
PublisherLabel.setText("By");
writeProtect.setText("Write Protect");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(NameLabel)
.addComponent(KeywordsLabel)
.addComponent(SourceLabel)
.addComponent(DescriptionLabel)
.addComponent(AuthorLabel)
.addGroup(layout.createSequentialGroup()
.addGap(5, 5, 5)
.addComponent(CategoryLabel))
.addComponent(PublishedLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(SourceField)
.addComponent(NameField)
.addComponent(DescriptionPane, javax.swing.GroupLayout.DEFAULT_SIZE, 319, Short.MAX_VALUE)
.addComponent(CategoryField, javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(YearField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(PublisherLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(PublisherField))
.addComponent(KeywordsField)
.addComponent(AuthorField)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(ReplaceButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(CopyDiskButton))
.addGroup(layout.createSequentialGroup()
.addGap(112, 112, 112)
.addComponent(writeProtect, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(FavoriteField)))
.addGap(0, 56, Short.MAX_VALUE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(SaveButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(CancellationButton))
.addComponent(ScreenshotCombo, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(Screenshot, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(InfoLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(Screenshot, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ScreenshotCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(InfoLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(CancellationButton)
.addComponent(SaveButton)
.addComponent(ReplaceButton)
.addComponent(CopyDiskButton)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(NameLabel)
.addComponent(NameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(SourceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(SourceLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(DescriptionLabel)
.addComponent(DescriptionPane, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE))
.addGap(8, 8, 8)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(CategoryLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(CategoryField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(YearField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(PublishedLabel)
.addComponent(PublisherLabel)
.addComponent(PublisherField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(AuthorField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(AuthorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(KeywordsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(KeywordsLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(writeProtect)
.addComponent(FavoriteField))
.addGap(36, 36, 36)))
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
private void SaveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveButtonActionPerformed
persist();
library.refreshUI();
// Emulator.getFrame().closeDialog(MEDIA_MANAGER_EDIT_DIALOG_NAME);
}//GEN-LAST:event_SaveButtonActionPerformed
/**
* If confirmed, the current disk image will be wiped out and reloaded from
* the source if the source can still be found
*
* @param evt ignored
*/
private void ReplaceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ReplaceButtonActionPerformed
if (!EmulatorUILogic.confirm("This will wipe out your local copy permanently. Only press OK if you are sure you want this to happen.")) {
return;
}
MediaFile f = library.cache.getCurrentFile(editingEntity, true);
library.cache.downloadImage(editingEntity, f, false);
}//GEN-LAST:event_ReplaceButtonActionPerformed
private void CopyDiskButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CopyDiskButtonActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_CopyDiskButtonActionPerformed
private void CancellationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CancellationButtonActionPerformed
if (EmulatorUILogic.confirm("Abandon unsaved changes? Are you sure?")) {
// Emulator.getFrame().closeDialog(MEDIA_MANAGER_EDIT_DIALOG_NAME);
}
}//GEN-LAST:event_CancellationButtonActionPerformed
/**
* Look at what type of screenshot to show and present it if available.
*
* @param evt passed in but actually just ignored
*/
private void ScreenshotComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ScreenshotComboActionPerformed
}//GEN-LAST:event_ScreenshotComboActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField AuthorField;
private javax.swing.JLabel AuthorLabel;
private javax.swing.JButton CancellationButton;
private javax.swing.JTextField CategoryField;
private javax.swing.JLabel CategoryLabel;
private javax.swing.JButton CopyDiskButton;
private javax.swing.JTextArea DescriptionField;
private javax.swing.JLabel DescriptionLabel;
private javax.swing.JScrollPane DescriptionPane;
private javax.swing.JCheckBox FavoriteField;
private javax.swing.JLabel InfoLabel;
private javax.swing.JTextField KeywordsField;
private javax.swing.JLabel KeywordsLabel;
private javax.swing.JTextField NameField;
private javax.swing.JLabel NameLabel;
private javax.swing.JLabel PublishedLabel;
private javax.swing.JTextField PublisherField;
private javax.swing.JLabel PublisherLabel;
private javax.swing.JButton ReplaceButton;
private javax.swing.JButton SaveButton;
private javax.swing.JLabel Screenshot;
private javax.swing.JComboBox ScreenshotCombo;
private javax.swing.JTextField SourceField;
private javax.swing.JLabel SourceLabel;
private javax.swing.JComboBox YearField;
private javax.swing.JCheckBox writeProtect;
// End of variables declaration//GEN-END:variables
MediaEntry editingEntity;
void populate(MediaEntry entity) {
// TODO: Implement all fields
AuthorField.setText(entity.author);
// entity.type
// entity.auxtype
CategoryField.setText(entity.category);
DescriptionField.setText(entity.description);
FavoriteField.setSelected(entity.favorite);
KeywordsField.setText(joinKeywords(entity.keywords));
NameField.setText(entity.name);
PublisherField.setText(entity.publisher);
if (entity.boxBackURL == null) {
ScreenshotCombo.removeItem(BOX_BACK);
}
if (entity.boxFrontURL == null) {
ScreenshotCombo.removeItem(BOX_FRONT);
}
if (entity.screenshotURL == null) {
ScreenshotCombo.removeItem(SCREENSHOT);
}
if (ScreenshotCombo.getItemCount() == 0) {
Screenshot.setVisible(false);
ScreenshotCombo.setVisible(false);
}
SourceField.setText(entity.source);
writeProtect.setSelected(entity.writeProtected);
YearField.setSelectedItem(entity.year);
editingEntity = entity;
}
void persist() {
editingEntity.author = AuthorField.getText();
// entity.type
// entity.auxtype
editingEntity.category = CategoryField.getText();
editingEntity.description = DescriptionField.getText();
editingEntity.favorite = FavoriteField.isSelected();
editingEntity.keywords = splitKeywords(KeywordsField.getText());
editingEntity.name = NameField.getText();
editingEntity.publisher = PublisherField.getText();
editingEntity.source = SourceField.getText();
editingEntity.writeProtected = writeProtect.isSelected();
editingEntity.year = String.valueOf(YearField.getSelectedItem());
if (createMode) {
MediaCache.getLocalLibrary().add(editingEntity);
setCreate(false);
} else {
MediaCache.getLocalLibrary().update(editingEntity);
}
}
boolean createMode = false;
void setCreate(boolean b) {
createMode = b;
if (createMode) {
setName(CREATE_TITLE);
} else {
setName(EDIT_TITLE);
}
}
MediaLibraryUI library = null;
void setParentLibary(MediaLibraryUI library) {
this.library = library;
}
private String[] splitKeywords (String keywords) {
return keywords.split(KEYWORD_DELIMITER);
}
private String joinKeywords(String[] keywords) {
if (keywords == null) {
return "";
}
StringBuilder out = new StringBuilder();
for (String keyword : keywords) {
if (keyword.length() == 0) {
continue;
}
if (out.length() > 0) {
out.append(KEYWORD_DELIMITER);
}
out.append(keyword);
}
return out.toString();
}
}