Added icon image, and dialog class.

This commit is contained in:
Andrew Lalis 2018-08-28 21:28:49 +02:00
parent 244a0d08d9
commit 667a11d69b
9 changed files with 80 additions and 57 deletions

View File

@ -34,12 +34,7 @@ public class Main {
Map<String, String> userOptions = CommandLine.parseArgs(args);
// Initialize logger.
try {
Logging.setup(true); // TODO: Replace true with command line arg.
} catch (IOException e) {
logger.severe("Unable to save log to file.");
}
Logging.setup();
// Command executor which will be used by all actions the user can do.
CommandExecutor executor = new CommandExecutor();
@ -47,6 +42,7 @@ public class Main {
// Initialize User Interface.
InitializerApp app = new InitializerApp(executor);
app.begin();
app.setAccessToken(userOptions.get("token"));
Database db = new Database("database/initializer.sqlite");
db.initialize();
@ -56,28 +52,6 @@ public class Main {
executor.registerCommand("generateassignments", new GenerateAssignmentsRepo());
logger.info("GithubManager for Github Repositories in Educational Organizations. Program initialized.");
// Get studentTeams from CSV file.
// List<StudentTeam> studentTeams = getStudentTeamsFromCSV(userOptions.get("input"), Integer.parseInt(userOptions.get("teamsize")));
//
// GithubManager githubManager = new GithubManager(
// userOptions.get("organization"),
// userOptions.get("token"),
// "assignments_2018",
// "teaching-assistants",
// "advoop_2018"
// );
try {
//githubManager.initializeGithubRepos(studentTeams);
//githubManager.archiveAllRepositories("team");
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -6,6 +6,7 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
/**
@ -26,11 +27,19 @@ public class OutputTextHandler extends Handler {
public void publish(LogRecord logRecord) {
DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
String dateString = df.format(new Date(logRecord.getMillis()));
String sourceLocationString = logRecord.getSourceClassName() + "::" + logRecord.getSourceMethodName();
this.outputPane.printStyled(dateString + ' ', "gray_italics");
this.outputPane.printStyled(logRecord.getLevel().getName() + ": ", "bold");
this.outputPane.printStyled(sourceLocationString + "\n\t", "bold");
this.outputPane.printStyled(logRecord.getMessage() + '\n', "smaller");
String style = "default";
Level level = logRecord.getLevel();
if (level == Level.SEVERE) {
style = "error_red";
} else if (level == Level.FINE
|| level == Level.FINER
|| level == Level.FINEST) {
style = "smaller";
} else if (level == Level.WARNING) {
style = "warning_orange";
}
this.outputPane.printStyled(logRecord.getMessage() + '\n', style);
}
@Override

View File

@ -63,8 +63,10 @@ public class CommandExecutor {
*/
public void executeCommand(String commandName, String[] args) {
if (this.commands.containsKey(commandName)) {
logger.info(commandName + ' ' + Arrays.toString(args));
this.commands.get(commandName).execute(args);
logger.info("Command executed: " + commandName + ' ' + Arrays.toString(args));
if (!this.commands.get(commandName).execute(args)) {
logger.warning("Command did not execute successfully.");
}
} else {
logger.warning(commandName + " is not a valid command.");
}

View File

@ -4,7 +4,9 @@ import nl.andrewlalis.ui.control.command.CommandExecutor;
import nl.andrewlalis.ui.view.InitializerApp;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import java.awt.event.ActionEvent;
import java.io.File;
/**
* Listens for when the user performs an action to read all students from a file, and output the contents to a database.
@ -18,6 +20,21 @@ public class ReadStudentsFileListener extends ExecutableListener {
@Override
public void actionPerformed(ActionEvent actionEvent) {
JFileChooser chooser = new JFileChooser();
chooser.setAcceptAllFileFilterUsed(false);
chooser.addChoosableFileFilter(new FileFilter() {
@Override
public boolean accept(File file) {
if (file.isDirectory()) {
return true;
}
return file.getName().toLowerCase().endsWith(".csv");
}
@Override
public String getDescription() {
return "CSV Files (*.csv)";
}
});
int fileResponse = chooser.showOpenDialog(this.app);
if (fileResponse == JFileChooser.APPROVE_OPTION) {

View File

@ -0,0 +1,13 @@
package nl.andrewlalis.ui.view;
import nl.andrewlalis.ui.control.command.executables.DefineTaTeams;
import javax.swing.*;
public class DefineTaTeamsDialog extends JDialog {
public DefineTaTeamsDialog(InitializerApp parentApp) {
super(parentApp);
}
}

View File

@ -2,11 +2,7 @@ package nl.andrewlalis.ui.view;
import nl.andrewlalis.ui.control.OutputTextHandler;
import nl.andrewlalis.ui.control.command.CommandExecutor;
import nl.andrewlalis.ui.control.command.executables.ArchiveRepos;
import nl.andrewlalis.ui.control.listeners.ArchiveAllListener;
import nl.andrewlalis.ui.control.listeners.CommandFieldKeyListener;
import nl.andrewlalis.ui.control.listeners.GenerateAssignmentsRepoListener;
import nl.andrewlalis.ui.control.listeners.ReadStudentsFileListener;
import nl.andrewlalis.ui.control.listeners.*;
import javax.swing.*;
import java.awt.*;
@ -45,6 +41,8 @@ public class InitializerApp extends JFrame {
this.executor = executor;
// UI initialization.
ImageIcon icon = new ImageIcon(getClass().getResource("/image/icon.png"));
this.setIconImage(icon.getImage());
this.initFrame();
}
@ -120,6 +118,7 @@ public class InitializerApp extends JFrame {
commonActionsPanel.add(generateAssignmentsRepoButton);
JButton defineTaTeamsButton = new JButton("Define TA Teams");
defineTaTeamsButton.addActionListener(new DefineTaTeamsListener(this.executor, this));
commonActionsPanel.add(defineTaTeamsButton);
githubManagerPanel.add(commonActionsPanel, BorderLayout.CENTER);
@ -194,4 +193,8 @@ public class InitializerApp extends JFrame {
return this.accessTokenField.getText().trim();
}
public void setAccessToken(String accessToken) {
this.accessTokenField.setText(accessToken);
}
}

View File

@ -1,10 +1,7 @@
package nl.andrewlalis.ui.view;
import javax.swing.*;
import javax.swing.text.BadLocationException;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import javax.swing.text.*;
import java.awt.*;
import java.util.HashMap;
import java.util.Map;
@ -26,6 +23,9 @@ public class OutputTextPane extends JTextPane {
this.initStyles();
this.setEditable(false);
this.setAutoscrolls(true);
DefaultCaret caret = (DefaultCaret) this.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
}
private void initStyles() {
@ -47,6 +47,14 @@ public class OutputTextPane extends JTextPane {
Style smaller = this.addStyle("smaller", defaultStyle);
smaller.addAttribute(StyleConstants.FontSize, 11);
this.styles.put("smaller", smaller);
Style errorRed = this.addStyle("error_red", bold);
errorRed.addAttribute(StyleConstants.Foreground, new Color(255, 0, 0));
this.styles.put("error_red", errorRed);
Style warningOrange = this.addStyle("warning_orange", defaultStyle);
warningOrange.addAttribute(StyleConstants.Foreground, new Color(255, 127, 0));
this.styles.put("warning_orange", warningOrange);
}
/**

View File

@ -11,24 +11,21 @@ public class Logging {
private static FileHandler outputFile;
private static SimpleFormatter formatter;
public static void setup(boolean verbose) throws IOException {
public static void setup() {
Logger logger = Logger.getGlobal();
outputFile = new FileHandler("log/latest.log");
formatter = new SimpleFormatter();
outputFile.setFormatter(formatter);
outputFile.setLevel(Level.FINEST);
if (verbose) {
Handler systemOut = new ConsoleHandler();
systemOut.setLevel(Level.ALL);
logger.addHandler(systemOut);
try {
outputFile = new FileHandler("log/latest.log");
formatter = new SimpleFormatter();
outputFile.setFormatter(formatter);
outputFile.setLevel(Level.FINEST);
logger.addHandler(outputFile);
} catch (IOException e) {
logger.warning("Unable to save log to output file.");
e.printStackTrace();
}
logger.addHandler(outputFile);
logger.setLevel(Level.ALL);
logger.setLevel(Level.ALL);
Logger.getLogger("").setLevel(Level.OFF);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB