Skip to content

Commit

Permalink
Merge pull request #563 from R87A/SPARK-1469
Browse files Browse the repository at this point in the history
SPARK-1469: Code cleanup
  • Loading branch information
wrooot authored Nov 14, 2020
2 parents 52a49be + 506e744 commit 54cc813
Show file tree
Hide file tree
Showing 64 changed files with 235 additions and 350 deletions.
2 changes: 0 additions & 2 deletions core/src/main/java/org/jivesoftware/launcher/Installer.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ public void addSparkToStartup(String sparkPath) {
*/
private void setURI(String path) {
boolean exists = WinRegistry.keyExists(RegistryRoot.HKEY_CLASSES_ROOT, "xmpp");
if (exists) {
}
// JOptionPane.showConfirmDialog(null, "Another application is currently registered to handle XMPP instant messaging. Make Spark the default XMPP instant messaging client?", "Confirmation", }
WinRegistry.deleteKey(RegistryRoot.HKEY_CLASSES_ROOT, "xmpp", true);

Expand Down
20 changes: 9 additions & 11 deletions core/src/main/java/org/jivesoftware/spark/ButtonFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,15 @@ public RolloverButton createBuzzButton() {
return new RolloverButton(SparkRes.getImageIcon(SparkRes.BUZZ_IMAGE));
}

public RolloverButton createEmoticonButton() {
final EmoticonManager emoticonManager = EmoticonManager.getInstance();
final String activeEmoticonSetName = emoticonManager.getActiveEmoticonSetName();
final Emoticon smileEmoticon = emoticonManager.getEmoticon(activeEmoticonSetName, ":)");
Emoticon firstEmoticon=(smileEmoticon == null) ? firstEmoticon=emoticonManager.getFirstEmotion(activeEmoticonSetName) : smileEmoticon;
URL emotionURL = emoticonManager.getEmoticonURL(firstEmoticon);
ImageIcon icon = new ImageIcon(emotionURL);
firstEmoticon=null;
return new RolloverButton(icon);

}
public RolloverButton createEmoticonButton() {
final EmoticonManager emoticonManager = EmoticonManager.getInstance();
final String activeEmoticonSetName = emoticonManager.getActiveEmoticonSetName();
final Emoticon smileEmoticon = emoticonManager.getEmoticon(activeEmoticonSetName, ":)");
Emoticon firstEmoticon = (smileEmoticon == null) ? emoticonManager.getFirstEmotion(activeEmoticonSetName) : smileEmoticon;
URL emotionURL = emoticonManager.getEmoticonURL(firstEmoticon);
ImageIcon icon = new ImageIcon(emotionURL);
return new RolloverButton(icon);
}

public JLabel createDivider() {
return new JLabel(SparkRes.getImageIcon("DIVIDER_IMAGE"));
Expand Down
10 changes: 0 additions & 10 deletions core/src/main/java/org/jivesoftware/spark/component/CheckTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,10 @@ public void mouseClicked(MouseEvent e) {
CheckNode node = (CheckNode)path.getLastPathComponent();
boolean isSelected = !node.isSelected();
node.setSelected(isSelected);
if (node.getSelectionMode() == CheckNode.DIG_IN_SELECTION) {
if (isSelected) {
//tree.expandPath(path);
}
else {
//tree.collapsePath(path);
}
}
((DefaultTreeModel)tree.getModel()).nodeChanged(node);
// I need revalidate if node is root. but why?

tree.revalidate();
tree.repaint();

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.jivesoftware.spark.component;

import org.jetbrains.annotations.NotNull;
import org.jivesoftware.spark.util.log.Log;

import java.awt.datatransfer.DataFlavor;
Expand Down Expand Up @@ -154,6 +155,7 @@ public boolean isDataFlavorSupported(DataFlavor flavor) {
}


@NotNull
@Override
public synchronized Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public static class JLabelRenderer extends JLabel implements TableCellRenderer {
private static final long serialVersionUID = 8670248883432881619L;
Border unselectedBorder;
Border selectedBorder;
boolean isBordered = true;
boolean isBordered;

/**
* JLabelConstructor to build ui.
Expand Down Expand Up @@ -275,9 +275,6 @@ public Component getTableCellRendererComponent(JTable table, Object color, boole
else {
setForeground(Color.black);
setBackground(Color.white);
if (row % 2 == 0) {
//setBackground( new Color( 156, 207, 255 ) );
}
}

if (isBordered) {
Expand Down Expand Up @@ -362,9 +359,6 @@ public Component getTableCellRendererComponent(JTable table, Object color, boole
else {
setForeground(Color.black);
setBackground(Color.white);
if (row % 2 == 0) {
//setBackground( new Color( 156, 207, 255 ) );
}
}

if (isBordered) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,6 @@ public Component getTableCellRendererComponent(JTable table, Object color, boole
else {
setForeground(Color.black);
setBackground(Color.white);
if (row % 2 == 0) {
//setBackground( new Color( 156, 207, 255 ) );
}
}

if (isBordered) {
Expand Down Expand Up @@ -197,9 +194,6 @@ public Component getTableCellRendererComponent(JTable table, Object color, boole
else {
setForeground(Color.black);
setBackground(Color.white);
if (row % 2 == 0) {
//setBackground( new Color( 156, 207, 255 ) );
}
}

if (isBordered) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.jivesoftware.spark.component;

import org.jetbrains.annotations.NotNull;
import org.jivesoftware.resource.SparkRes;

import javax.swing.Icon;
Expand Down Expand Up @@ -223,6 +224,7 @@ public boolean isDataFlavorSupported(DataFlavor flavor) {

}

@NotNull
@Override
public Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static void showErrorDialog( final JFrame owner, final String description
titleLabel.setFont(new Font("dialog", Font.BOLD, 11 ) );

final JLabel descriptionLabel = new JLabel(desc);
descriptionLabel.setFont(new Font("dialog", 0, 10 ) );
descriptionLabel.setFont(new Font("dialog", Font.PLAIN, 10 ) );

// The stacktrace content.
final JTextArea textPane = new JTextArea();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public static class JLabelRenderer extends JLabel implements TableCellRenderer {
private static final long serialVersionUID = 4433780600297455731L;
Border unselectedBorder;
Border selectedBorder;
boolean isBordered = true;
boolean isBordered;

/**
* JLabelConstructor to build ui.
Expand Down Expand Up @@ -304,9 +304,6 @@ public Component getTableCellRendererComponent(JTable table, Object color, boole
else {
setForeground(Color.black);
setBackground(Color.white);
if (row % 2 == 0) {
//setBackground( new Color( 156, 207, 255 ) );
}
}

if (isBordered) {
Expand Down Expand Up @@ -393,9 +390,6 @@ public Component getTableCellRendererComponent(JTable table, Object color, boole
else {
setForeground(Color.black);
setBackground(Color.white);
if (row % 2 == 0) {
//setBackground( new Color( 156, 207, 255 ) );
}
}

if (isBordered) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public TitlePanel(String title, String description, Icon icon, boolean showDescr
setBackground(Color.white);

titleLabel.setFont(new Font("dialog", Font.BOLD, 11));
descriptionLabel.setFont(new Font("dialog", 0, 10));
descriptionLabel.setFont(new Font("dialog", Font.PLAIN, 10));
}
else {
final JPanel panel = new ImagePanel();
Expand All @@ -91,7 +91,7 @@ public TitlePanel(String title, String description, Icon icon, boolean showDescr
titleLabel.setVerticalTextPosition(JLabel.CENTER);
titleLabel.setFont(new Font("dialog", Font.BOLD, 14));
titleLabel.setForeground(Color.black);
descriptionLabel.setFont(new Font("dialog", 0, 10));
descriptionLabel.setFont(new Font("dialog", Font.PLAIN, 10));
add(panel, new GridBagConstraints(0, 0, 1, 0, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 2, 2, 2), 0, 0));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
public class SparkTab extends JPanel
{
private static final long serialVersionUID = 2027267184472260195L;
private SparkTabbedPane pane = null;
private Component component = null;
private SparkTabbedPane pane;
private Component component;

public SparkTab(SparkTabbedPane pane, Component comp)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.jivesoftware.spark.component.tabbedPane;

import org.jetbrains.annotations.NotNull;
import org.jivesoftware.Spark;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.spark.SparkManager;
Expand All @@ -41,7 +42,7 @@ public class SparkTabbedPane extends JPanel {
private static final long serialVersionUID = -9007068462231539973L;
private static final String NAME = "SparkTabbedPane";
private List<SparkTabbedPaneListener> listeners = new ArrayList<>();
private JTabbedPane pane = null;
private JTabbedPane pane;
private Icon closeInactiveButtonIcon;
private Icon closeActiveButtonIcon;
private boolean closeEnabled = false;
Expand Down Expand Up @@ -507,7 +508,8 @@ public void dropActionChanged(DragSourceDragEvent event) {}

final Transferable t = new Transferable() {
private final DataFlavor FLAVOR = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType, NAME);
@Override
@NotNull
@Override
public Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException, IOException {
return pane;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.InputStreamReader;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
Expand Down Expand Up @@ -39,24 +40,20 @@ public BroadcastHistoryFrame() {
BroadcastHistoryArea.setWrapStyleWord(true);
initComponents();
}

public void readFromFile(String date) throws FileNotFoundException, IOException {
//String fileName = Spark.getSparkUserHome()+File.separator+"broadcast_history."+date+".txt";
String fileLocation=Spark.getSparkUserHome()+File.separator+"user"+File.separator+SparkManager.getSessionManager().getUsername()+"@"+SparkManager.getSessionManager().getServerAddress()+File.separator+"transcripts"+File.separator+"broadcast_history."+date+".txt";
String fileLocation = Spark.getSparkUserHome() + File.separator + "user" + File.separator + SparkManager.getSessionManager().getUsername() + "@" + SparkManager.getSessionManager().getServerAddress() + File.separator + "transcripts" + File.separator + "broadcast_history." + date + ".txt";
File myfile = new File(fileLocation);
FileInputStream fis = new FileInputStream(myfile);



BufferedReader br = new BufferedReader(new InputStreamReader(fis));

String line = null;


String line;
while ((line = br.readLine()) != null) {
BroadcastHistoryArea.append(line+"\n");
}

br.close();

BroadcastHistoryArea.append(line + "\n");
}
br.close();
}

private void initComponents() {
Expand All @@ -75,7 +72,7 @@ private void initComponents() {
try {
readFromFile(myDate);
} catch (IOException ex) {
Log.error("Couldn't read from file"+ex.getMessage()+ex.getStackTrace());
Log.error("Couldn't read from file"+ex.getMessage()+ Arrays.toString(ex.getStackTrace()));
}

SearchButton.setText((Res.getString("button.search")));
Expand Down Expand Up @@ -155,7 +152,7 @@ private void SearchButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRS
try {
readFromFile(DateField.getText());
} catch (IOException ex) {
Log.error("Couldn't read from file"+ex.getCause()+ex.getStackTrace());
Log.error("Couldn't read from file"+ex.getCause()+ Arrays.toString(ex.getStackTrace()));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
Expand Down Expand Up @@ -122,7 +123,7 @@ public void actionPerformed(ActionEvent e) {
}
};

undoKeyStroke = KeyStroke.getKeyStroke('z', ActionEvent.CTRL_MASK);
undoKeyStroke = KeyStroke.getKeyStroke('z', InputEvent.CTRL_MASK);
ctrlbackspaceKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, KeyEvent.CTRL_MASK);
escapeKeyStroke = KeyStroke.getKeyStroke("ESCAPE");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.swing.JComponent;
import javax.swing.TransferHandler;

import org.jetbrains.annotations.NotNull;
import org.jivesoftware.spark.util.log.Log;

/**
Expand Down Expand Up @@ -131,8 +132,9 @@ public boolean isDataFlavorSupported(DataFlavor flavor) {
}

// Returns Selected Text
@NotNull
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
if (!DataFlavor.stringFlavor.equals(flavor)) {
throw new UnsupportedFlavorException(flavor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.jivesoftware.spark.ui;

import org.jetbrains.annotations.NotNull;
import org.jivesoftware.resource.Res;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.roster.Roster;
Expand Down Expand Up @@ -164,6 +165,7 @@ public boolean isDataFlavorSupported(DataFlavor flavor) {
}

// Returns image
@NotNull
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (!DataFlavor.imageFlavor.equals(flavor)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,8 @@ public void customizeUI(ContactItem contactItem) {
//If user is offline or away, try to see last activity

try {
Jid client = null;
if (!status.equals(Res.getString("offline"))) {
//If user is away (not offline), last activity request is sent to client
client = contactItem.getPresence().getFrom();
} else {
client = contactItem.getJid();
}

//If user is away (not offline), last activity request is sent to client
Jid client = status.equals(Res.getString("offline")) ? contactItem.getJid() : contactItem.getPresence().getFrom();
LastActivity activity = LastActivityManager.getInstanceFor( SparkManager.getConnection() ).getLastActivity(client);

long idleTime = (activity.getIdleTime() * 1000);
Expand Down
9 changes: 4 additions & 5 deletions core/src/main/java/org/jivesoftware/spark/ui/ContactList.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class ContactList extends JPanel implements ActionListener,
ContactGroupListener, Plugin, RosterListener, ConnectionListener, ReconnectionListener {

private static final long serialVersionUID = -4391111935248627078L;
private static final String GROUP_DELIMITER = "::";
private JPanel mainPanel = new JPanel();
private JScrollPane contactListScrollPane;
private final List<ContactGroup> groupList = new ArrayList<>();
Expand Down Expand Up @@ -823,9 +824,7 @@ private synchronized void handleEntriesUpdated(final Collection<Jid> addresses)

ContactGroup unfiledGrp = getUnfiledGroup();
ContactItem unfiledItem = unfiledGrp.getContactItemByJID(jid.asBareJid());
if (unfiledItem != null) {

} else {
if (unfiledItem == null) {
ContactItem offlineItem = offlineGroup.getContactItemByJID(jid.asBareJid());
if (offlineItem != null) {
if ((rosterEntry.getType() == RosterPacket.ItemType.none || rosterEntry.getType() == RosterPacket.ItemType.from)
Expand Down Expand Up @@ -984,7 +983,7 @@ private void addContactGroup(ContactGroup group) {
* @return the newly created ContactGroup.
*/
private ContactGroup addContactGroup(String groupName) {
StringTokenizer tkn = new StringTokenizer(groupName, "::");
StringTokenizer tkn = new StringTokenizer(groupName, GROUP_DELIMITER);

ContactGroup rootGroup = null;
ContactGroup lastGroup = null;
Expand Down Expand Up @@ -1199,7 +1198,7 @@ private ContactGroup getSubContactGroup(ContactGroup group, String groupName) {
* @param visible true to show, otherwise false.
*/
public void toggleGroupVisibility(String groupName, boolean visible) {
StringTokenizer tkn = new StringTokenizer(groupName, "::");
StringTokenizer tkn = new StringTokenizer(groupName, GROUP_DELIMITER);
while (tkn.hasMoreTokens()) {
String group = tkn.nextToken();
ContactGroup contactGroup = getContactGroup(group);
Expand Down
Loading

0 comments on commit 54cc813

Please sign in to comment.