Skip to content

Commit

Permalink
Single-file operations change the button text to explain action, adde…
Browse files Browse the repository at this point in the history
…d safeguard against Extract with zero files selected.
  • Loading branch information
crashdemons committed Mar 28, 2015
1 parent 515f533 commit 178f30c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/xorj/Common.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package xorj;

import java.util.Random;
import javax.swing.JOptionPane;

/**
*
* @author crashdemons <crashdemons -at- github.com>
*/
public class Common {
public static Random rand=new Random();
public static void msgbox(int type,String title, String text){
JOptionPane.showMessageDialog(null, text, title, type);
}
public static long stol(String s){
try{ return Long.valueOf(s); }catch(Exception e){ return 0l; }
}
Expand Down
10 changes: 5 additions & 5 deletions src/xorj/UI.form
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<EmptySpace pref="224" max="32767" attributes="0"/>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="36" max="-2" attributes="0"/>
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
Expand All @@ -63,11 +63,11 @@
<Component id="jButton2" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jProgressBar1" min="-2" pref="456" max="-2" attributes="0"/>
<EmptySpace type="separate" max="32767" attributes="0"/>
<Component id="jProgressBar1" min="-2" pref="342" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="jbScan" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jbExtract" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="jbExtract" min="-2" pref="153" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
Expand Down
31 changes: 20 additions & 11 deletions src/xorj/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
*/
package xorj;

import java.io.File;
import java.util.ArrayList;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;
import static xorj.Common.msgbox;

/**
*
Expand Down Expand Up @@ -115,7 +116,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addComponent(jButton1)
.addGap(18, 18, 18)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 224, Short.MAX_VALUE)
.addComponent(jLabel2)
.addGap(36, 36, 36)
.addComponent(jLabel3)
Expand All @@ -132,11 +133,11 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton2))
.addGroup(layout.createSequentialGroup()
.addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 456, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, Short.MAX_VALUE)
.addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 342, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jbScan)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jbExtract)))))
.addGap(18, 18, 18)
.addComponent(jbExtract, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addContainerGap())
);
layout.setVerticalGroup(
Expand Down Expand Up @@ -173,7 +174,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
addFileTest();
addFile();
updateGraph();
}//GEN-LAST:event_jButton1ActionPerformed

Expand All @@ -197,6 +198,7 @@ private void deprep(){
}

private void jbExtractActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbExtractActionPerformed
if(files.size()==0){ msgbox(JOptionPane.ERROR_MESSAGE,"File Error","You must add at least 1 file to extract/xor from."); return; }
prep();
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(FileEntry.dir);
Expand Down Expand Up @@ -280,7 +282,15 @@ private void repaintFiles(){
jsFiles.repaint();
}

public void addFileTest(){
private void onFilesUpdated(){
repaintFiles();
updateGraph();
if(files.size()==1) jbExtract.setText("Extract section");
if(files.size()>1) jbExtract.setText("XOR sections");
}


public void addFile(){
jScrollPane1.setViewportView(graphPanel1);
FileEntry fe = new FileEntry();
boolean check=fe.select();
Expand All @@ -290,14 +300,13 @@ public void addFileTest(){
filePanel1.add(fe);
files.add(fe);
jsFiles.setViewportView(filePanel1);
repaintFiles();
onFilesUpdated();
}
public void removeFileEntry(FileEntry fe){
filePanel1.remove(fe);
files.remove(fe);
fe=null;
repaintFiles();
updateGraph();
onFilesUpdated();
}
public void updateGraph(){
ArrayList<FileBar> bars=new ArrayList<FileBar>();
Expand Down

0 comments on commit 178f30c

Please sign in to comment.