Skip to content

Commit

Permalink
code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
sjPlot committed Oct 14, 2015
1 parent 7c7adc5 commit b65098d
Show file tree
Hide file tree
Showing 11 changed files with 395 additions and 335 deletions.
87 changes: 45 additions & 42 deletions src/de/danielluedecke/zettelkasten/CAutoKorrekturEdit.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
* Sie sollten ein Exemplar der GNU General Public License zusammen mit diesem Programm
* erhalten haben. Falls nicht, siehe <http://www.gnu.org/licenses/>.
*/

package de.danielluedecke.zettelkasten;

import de.danielluedecke.zettelkasten.database.Settings;
Expand All @@ -57,7 +56,7 @@

/**
*
* @author danielludecke
* @author danielludecke
*/
public class CAutoKorrekturEdit extends javax.swing.JDialog {

Expand All @@ -66,7 +65,7 @@ public class CAutoKorrekturEdit extends javax.swing.JDialog {
*/
private final AutoKorrektur autoKorrekt;
/**
*
*
*/
private final Settings settingsObj;
/**
Expand All @@ -80,16 +79,15 @@ public class CAutoKorrekturEdit extends javax.swing.JDialog {
/**
* get the strings for file descriptions from the resource map
*/
private final org.jdesktop.application.ResourceMap resourceMap =
org.jdesktop.application.Application.getInstance(de.danielluedecke.zettelkasten.ZettelkastenApp.class).
getContext().getResourceMap(CAutoKorrekturEdit.class);
private final org.jdesktop.application.ResourceMap resourceMap
= org.jdesktop.application.Application.getInstance(de.danielluedecke.zettelkasten.ZettelkastenApp.class).
getContext().getResourceMap(CAutoKorrekturEdit.class);


/**
*
*
* @param parent
* @param ac
* @param st
* @param st
*/
public CAutoKorrekturEdit(java.awt.Frame parent, AutoKorrektur ac, Settings st) {
super(parent);
Expand All @@ -99,13 +97,12 @@ public CAutoKorrekturEdit(java.awt.Frame parent, AutoKorrektur ac, Settings st)
initTheRest(null);
}


/**
*
*
* @param parent
* @param ac
* @param st
* @param wrongspelling
* @param wrongspelling
*/
public CAutoKorrekturEdit(java.awt.Frame parent, AutoKorrektur ac, Settings st, String wrongspelling) {
super(parent);
Expand All @@ -115,7 +112,6 @@ public CAutoKorrekturEdit(java.awt.Frame parent, AutoKorrektur ac, Settings st,
initTheRest(wrongspelling);
}


private void initTheRest(String initvalue) {
/*
* Constructor for Matte Border
Expand All @@ -140,19 +136,19 @@ public void actionPerformed(ActionEvent evt) {
// get the default fontsize for tables and lists
int defaultsize = settingsObj.getTableFontSize();
// only set new fonts, when fontsize differs from the initial value
if (defaultsize>0) {
if (defaultsize > 0) {
// get current font
Font f = jTableAutoKorrektur.getFont();
// create new font, add fontsize-value
f = new Font(f.getName(), f.getStyle(), f.getSize()+defaultsize);
f = new Font(f.getName(), f.getStyle(), f.getSize() + defaultsize);
// set new font
jTableAutoKorrektur.setFont(f);
}
// create auto-sorter for tabel
jTableAutoKorrektur.setAutoCreateRowSorter(true);
jTableAutoKorrektur.setGridColor(settingsObj.getTableGridColor());
// make extra table-sorter for itunes-tables
if (settingsObj.isMacStyle()) {
if (settingsObj.isMacAqua()) {
TableUtils.SortDelegate sortDelegate = new TableUtils.SortDelegate() {
@Override
public void sort(int columnModelIndex, TableUtils.SortDirection sortDirection) {
Expand All @@ -164,21 +160,23 @@ public void sort(int columnModelIndex, TableUtils.SortDirection sortDirection) {
jTableAutoKorrektur.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
}
// init the table, i.e. fill it with all existing data
tm = (DefaultTableModel)jTableAutoKorrektur.getModel();
tm = (DefaultTableModel) jTableAutoKorrektur.getModel();
tm.setRowCount(0);
// add all spellchecking-entries to linked list
for (int cnt=0; cnt<autoKorrekt.getCount(); cnt++) {
for (int cnt = 0; cnt < autoKorrekt.getCount(); cnt++) {
String[] value = autoKorrekt.getElement(cnt);
if (value!=null) tm.addRow(value);
if (value != null) {
tm.addRow(value);
}
}
// add one row for editing...
tm.setRowCount(tm.getRowCount()+1);
tm.setRowCount(tm.getRowCount() + 1);
// when we have a parameter, set this valus as initial value into the table
// we do this before we init the change-event, so this does not trigger any changes
// that will be tracked...
if (initvalue!=null) {
if (initvalue != null) {
// get selected row...
int row = tm.getRowCount()-1;
int row = tm.getRowCount() - 1;
// set initial value, which typically is a word that was spelled wrong...
tm.setValueAt(initvalue, row, 0);
// select the previous cell, so the user can start editing the correct spelling...
Expand All @@ -190,43 +188,48 @@ public void sort(int columnModelIndex, TableUtils.SortDirection sortDirection) {
// add table model listener. in case we have edited a new value at the last
// column or row, automatically add a new column/row
tm.addTableModelListener(new TableModelListener() {
@Override public void tableChanged(TableModelEvent e) {
@Override
public void tableChanged(TableModelEvent e) {
// only react on updates, i.e. the user edited/inserted/changed new values
if (TableModelEvent.UPDATE == e.getType()) {
// if edited row was last row, add one row
if (e.getLastRow()==(tm.getRowCount()-1)) tm.setRowCount(tm.getRowCount()+1);
if (e.getLastRow() == (tm.getRowCount() - 1)) {
tm.setRowCount(tm.getRowCount() + 1);
}
}
// enable apply-button
jButtonApply.setEnabled(true);
}
});
// create action which should be executed when the user presses
// the delete/backspace-key
AbstractAction a_delete = new AbstractAction(){
@Override public void actionPerformed(ActionEvent e) {
AbstractAction a_delete = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
// retrieve selected row and column
int row = jTableAutoKorrektur.getSelectedRow();
int col = jTableAutoKorrektur.getSelectedColumn();
// remove row
tm.removeRow(row);
// adjust row if last row was selected
if (row>=tm.getRowCount()) row--;
if (row >= tm.getRowCount()) {
row--;
}
// select new cell
jTableAutoKorrektur.setColumnSelectionInterval(col, col);
jTableAutoKorrektur.setRowSelectionInterval(row, row);
// enable apply-button
jButtonApply.setEnabled(true);
}
};
jTableAutoKorrektur.getActionMap().put("DeleteKeyPressed",a_delete);
jTableAutoKorrektur.getActionMap().put("DeleteKeyPressed", a_delete);
// check for os, and use appropriate controlKey
KeyStroke ks = KeyStroke.getKeyStroke((System.getProperty("os.name").toLowerCase().startsWith("mac os"))?"meta BACK_SPACE":"ctrl DELETE");
KeyStroke ks = KeyStroke.getKeyStroke((System.getProperty("os.name").toLowerCase().startsWith("mac os")) ? "meta BACK_SPACE" : "ctrl DELETE");
jTableAutoKorrektur.getInputMap().put(ks, "DeleteKeyPressed");
// disable reordering of columns
jTableAutoKorrektur.getTableHeader().setReorderingAllowed(false);
}


@Action
public void cancel() {
modified = false;
Expand All @@ -239,43 +242,43 @@ public void applyChanges() {
// clear all synonyms
autoKorrekt.clear();
// retrieve all table rows
for (int row=0; row<tm.getRowCount(); row++) {
for (int row = 0; row < tm.getRowCount(); row++) {
// get table-cell-values
Object o1 = tm.getValueAt(row, 0);
Object o2 = tm.getValueAt(row, 1);
// check whether we have any valid values...
if (o1!=null && o2!=null) {
if (o1 != null && o2 != null) {
// retrieve string-content of values
String falsch = tm.getValueAt(row, 0).toString();
String richtig = tm.getValueAt(row, 1).toString();
// if we have valid values, add them to the file
if (falsch!=null && !falsch.isEmpty() && richtig!=null && !richtig.isEmpty()) autoKorrekt.addElement(falsch, richtig);
if (falsch != null && !falsch.isEmpty() && richtig != null && !richtig.isEmpty()) {
autoKorrekt.addElement(falsch, richtig);
}
}
}
// now check whether everything is ok
if (!autoKorrekt.isDocumentOK()) {
// log error
Constants.zknlogger.log(Level.WARNING,"Warning! Could not save spell correction data! The original XML document has been restored!");
Constants.zknlogger.log(Level.WARNING, "Warning! Could not save spell correction data! The original XML document has been restored!");
// if not, restore document and tell user about problem
autoKorrekt.restoreDocument();
// tell user about problem
JOptionPane.showMessageDialog(null,resourceMap.getString("errSavingDataMsg"),
resourceMap.getString("errSavingDataTitle"),
JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(null, resourceMap.getString("errSavingDataMsg"),
resourceMap.getString("errSavingDataTitle"),
JOptionPane.PLAIN_MESSAGE);
// no modifications have been made
modified = false;
}
else {
} else {
modified = true;
}
dispose();
setVisible(false);
}


/**
*
* @return
*
* @return
*/
public boolean isModified() {
return modified;
Expand Down
50 changes: 25 additions & 25 deletions src/de/danielluedecke/zettelkasten/CBiggerEditField.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
* Sie sollten ein Exemplar der GNU General Public License zusammen mit diesem Programm
* erhalten haben. Falls nicht, siehe <http://www.gnu.org/licenses/>.
*/

package de.danielluedecke.zettelkasten;

import de.danielluedecke.zettelkasten.database.Settings;
Expand All @@ -46,11 +45,12 @@
import java.util.Set;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.KeyStroke;import org.jdesktop.application.Action;
import javax.swing.KeyStroke;
import org.jdesktop.application.Action;

/**
*
* @author danielludecke
* @author danielludecke
*/
public class CBiggerEditField extends javax.swing.JDialog {

Expand All @@ -65,13 +65,14 @@ public class CBiggerEditField extends javax.swing.JDialog {

/**
* Create a new bigger input dialog for editing new authors etc.
*
*
* @param parent the parent window
* @param settings a reference to the settings class
* @param title the dialog's title
* @param val a default value which should be set to the textfield
* @param textfieldval an optional value that should be set to the bibkey-textfield. Usually only used
* when a new author is added / edited and the bibkey is set or changed
* @param textfieldval an optional value that should be set to the
* bibkey-textfield. Usually only used when a new author is added / edited
* and the bibkey is set or changed
* @param edittype indicates which kind of data is being edited.
*/
public CBiggerEditField(java.awt.Frame parent, Settings settings, String title, String val, String textfieldval, int edittype) {
Expand All @@ -89,12 +90,12 @@ public CBiggerEditField(java.awt.Frame parent, Settings settings, String title,
}
// bind our new forward focus traversal keys
Set<AWTKeyStroke> newForwardKeys = new HashSet<>(1);
newForwardKeys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,0));
jTextAreaBigEdit.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,Collections.unmodifiableSet(newForwardKeys));
newForwardKeys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0));
jTextAreaBigEdit.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.unmodifiableSet(newForwardKeys));
// bind our new backward focus traversal keys
Set<AWTKeyStroke> newBackwardKeys = new HashSet<>(1);
newBackwardKeys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,KeyEvent.SHIFT_MASK+KeyEvent.SHIFT_DOWN_MASK));
jTextAreaBigEdit.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,Collections.unmodifiableSet(newBackwardKeys));
newBackwardKeys.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_MASK + KeyEvent.SHIFT_DOWN_MASK));
jTextAreaBigEdit.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, Collections.unmodifiableSet(newBackwardKeys));
// these codelines add an escape-listener to the dialog. so, when the user
// presses the escape-key, the same action is performed as if the user
// presses the cancel button...
Expand All @@ -107,21 +108,20 @@ public void actionPerformed(ActionEvent evt) {
};
getRootPane().registerKeyboardAction(cancelAction, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
// reset return value
newValue=null;
newBibKey=null;
newValue = null;
newBibKey = null;
// set dialog's title
setTitle(title);
// fill textarea with default value
if (val!=null) {
if (val != null) {
jTextAreaBigEdit.setText(val);
}
switch (edittype) {
case Constants.EDIT_AUTHOR:
jPanel1.setVisible(true);
if (textfieldval !=null) {
if (textfieldval != null) {
jTextFieldBibKey.setText(textfieldval);
}
else {
} else {
jTextFieldBibKey.setText("");
}
break;
Expand All @@ -130,7 +130,7 @@ public void actionPerformed(ActionEvent evt) {
jTextFieldBibKey.setText("");
break;
}

}

private void initBorders(Settings settingsObj) {
Expand All @@ -140,7 +140,7 @@ private void initBorders(Settings settingsObj) {
*/
jScrollPane1.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, ColorUtil.getBorderGray(settingsObj)));
}

@Action
public void okButton() {
// get the text and leave the dialog
Expand All @@ -149,24 +149,24 @@ public void okButton() {
setVisible(false);
dispose();
}

@Action
public void cancelButton() {
// reset the value and leave dialog
newValue=null;
newBibKey=null;
newValue = null;
newBibKey = null;
setVisible(false);
dispose();
}



/**
*
* @return
*
* @return
*/
public String getNewValue() {
return newValue;
}

public String getNewBibKey() {
return newBibKey;
}
Expand Down
Loading

0 comments on commit b65098d

Please sign in to comment.