Skip to content

Commit

Permalink
Cleaning up some code
Browse files Browse the repository at this point in the history
  • Loading branch information
eduramiba committed Aug 15, 2017
1 parent c3379ae commit f86ed6a
Show file tree
Hide file tree
Showing 40 changed files with 115 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private void retrieve() {
Color[] colors = deserializeColors(cols);
recentPalette.addLast(new Palette(colors));
} catch (Exception e) {
e.printStackTrace();
Exceptions.printStackTrace(e);
}
} else {
break;
Expand All @@ -259,25 +259,26 @@ private void store() {
try {
prefs.putByteArray(COLORS + i, serializeColors(palette.getColors()));
} catch (Exception e) {
e.printStackTrace();
Exceptions.printStackTrace(e);
}
i++;
}
}

private byte[] serializeColors(Color[] colors) throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(colors);
out.close();
try (ObjectOutputStream out = new ObjectOutputStream(bos)) {
out.writeObject(colors);
}
return bos.toByteArray();
}

private Color[] deserializeColors(byte[] colors) throws Exception {
ByteArrayInputStream bis = new ByteArrayInputStream(colors);
ObjectInputStream in = new ObjectInputStream(bis);
Color[] array = (Color[]) in.readObject();
in.close();
Color[] array;
try (ObjectInputStream in = new ObjectInputStream(bis)) {
array = (Color[]) in.readObject();
}
return array;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public TransformerCategory getCategory() {

@Override
public String getDisplayName() {
return NbBundle.getMessage(UniqueElementColorTransformerUI.class, "Attribute.partition.name");
return NbBundle.getMessage(PartitionElementColorTransformerUI.class, "Attribute.partition.name");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public TransformerCategory getCategory() {

@Override
public String getDisplayName() {
return NbBundle.getMessage(UniqueElementColorTransformerUI.class, "Attribute.partition.name");
return NbBundle.getMessage(PartitionLabelColorTransformerUI.class, "Attribute.partition.name");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Icon getIcon() {

@Override
public String getDisplayName() {
return NbBundle.getMessage(UniqueElementColorTransformerUI.class, "Attribute.ranking.name");
return NbBundle.getMessage(RankingLabelSizeTransformerUI.class, "Attribute.ranking.name");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Development and Distribution License("CDDL") (collectively, the
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import org.gephi.appearance.plugin.RankingElementColorTransformer.LinearGradient;
import org.openide.util.Exceptions;
import org.openide.util.NbPreferences;

/**
Expand Down Expand Up @@ -104,7 +105,7 @@ private void store() {
prefs.putByteArray(COLORS + i, serializeColors(gradient.getColors()));
prefs.putByteArray(POSITIONS + i, serializePositions(gradient.getPositions()));
} catch (Exception e) {
e.printStackTrace();
Exceptions.printStackTrace(e);
}
i++;
}
Expand All @@ -124,7 +125,7 @@ private void retrieve() {
LinearGradient linearGradient = new LinearGradient(colors, posisitons);
gradients.addLast(linearGradient);
} catch (Exception e) {
e.printStackTrace();
Exceptions.printStackTrace(e);
}
} else {
break;
Expand All @@ -150,33 +151,35 @@ protected final Preferences getPreferences() {

private byte[] serializePositions(float[] positions) throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(positions);
out.close();
try (ObjectOutputStream out = new ObjectOutputStream(bos)) {
out.writeObject(positions);
}
return bos.toByteArray();
}

private float[] deserializePositions(byte[] positions) throws Exception {
ByteArrayInputStream bis = new ByteArrayInputStream(positions);
ObjectInputStream in = new ObjectInputStream(bis);
float[] array = (float[]) in.readObject();
in.close();
float[] array;
try (ObjectInputStream in = new ObjectInputStream(bis)) {
array = (float[]) in.readObject();
}
return array;
}

private byte[] serializeColors(Color[] colors) throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(colors);
out.close();
try (ObjectOutputStream out = new ObjectOutputStream(bos)) {
out.writeObject(colors);
}
return bos.toByteArray();
}

private Color[] deserializeColors(byte[] colors) throws Exception {
ByteArrayInputStream bis = new ByteArrayInputStream(colors);
ObjectInputStream in = new ObjectInputStream(bis);
Color[] array = (Color[]) in.readObject();
in.close();
Color[] array;
try (ObjectInputStream in = new ObjectInputStream(bis)) {
array = (Color[]) in.readObject();
}
return array;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -373,67 +373,4 @@ private boolean isSupportedPropertyType(Class type) {
}
return false;
}

// protected void setSelectedTransformerUI(TransformerUI transformerUI) {
// selectedTransformerUI.get(selectedElementClass).put(getSelectedCategory(), transformerUI);
// if (transformerUI instanceof SimpleTransformerUI) {
// if (selectedTransformer != null) {
// unsetupTransformer(selectedTransformer);
// }
// selectedTransformer = controller.appearanceController.getTransformer(transformerUI);
// setupTransformer(selectedTransformer);
// } else {
// //TODO
// }
// }
// public void setupTransformer(Transformer transformer) {
// for (Method m : transformer.getClass().getMethods()) {
// if (isSetter(m)) {
// Class paramClass = m.getParameterTypes()[0];
// if (paramClass.isPrimitive() || Serializable.class.isAssignableFrom(paramClass)) {
// System.out.println("Setting to method " + m.getName());
// }
// }
// }
// }
//
// public void unsetupTransformer(Transformer transformer) {
// for (Method m : transformer.getClass().getMethods()) {
// if (isGetter(m)) {
// Class returnClass = m.getReturnType();
// if (returnClass.isPrimitive() || Serializable.class.isAssignableFrom(returnClass)) {
// try {
// Object res = m.invoke(transformer);
// if (res != null) {
// System.out.println("Extracted " + res + " from method " + m.getName());
// }
// } catch (Exception ex) {
// ex.printStackTrace();
// }
// }
// }
// }
// }
//
// public static boolean isGetter(Method method) {
// if (Modifier.isPublic(method.getModifiers())
// && method.getParameterTypes().length == 0) {
// if (method.getName().matches("^get[A-Z].*")
// && !method.getReturnType().equals(void.class)) {
// return true;
// }
// if (method.getName().matches("^is[A-Z].*")
// && method.getReturnType().equals(boolean.class)) {
// return true;
// }
// }
// return false;
// }
//
// public static boolean isSetter(Method method) {
// return Modifier.isPublic(method.getModifiers())
// && method.getReturnType().equals(void.class)
// && method.getParameterTypes().length == 1
// && method.getName().matches("^set[A-Z].*");
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Development and Distribution License("CDDL") (collectively, the
import org.gephi.perspective.api.PerspectiveController;
import org.gephi.perspective.spi.Perspective;
import org.gephi.ui.utils.UIUtils;
import org.openide.util.Exceptions;
import org.openide.util.ImageUtilities;
import org.openide.util.Lookup;

Expand All @@ -60,7 +61,7 @@ Development and Distribution License("CDDL") (collectively, the
public class BannerComponent extends javax.swing.JPanel {

private transient JToggleButton[] buttons;
private transient PerspectiveController perspectiveController;
private final transient PerspectiveController perspectiveController;

public BannerComponent() {
initComponents();
Expand All @@ -81,7 +82,7 @@ public void actionPerformed(ActionEvent e) {
java.net.URI uri = new java.net.URI("http:https://gephi.org");
desktop.browse(uri);
} catch (Exception ex) {
ex.printStackTrace();
Exceptions.printStackTrace(ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Development and Distribution License("CDDL") (collectively, the
import org.openide.NotifyDescriptor;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
Expand All @@ -69,8 +70,8 @@ Development and Distribution License("CDDL") (collectively, the
@ServiceProvider(service = OptionProcessor.class)
public class CommandLineProcessor extends OptionProcessor {

private Option openOption = Option.defaultArguments();
private Option openOption2 = Option.additionalArguments('o', "open");
private final Option openOption = Option.defaultArguments();
private final Option openOption2 = Option.additionalArguments('o', "open");
private final String MEMORY_ERROR;
private static final String GEPHI_EXTENSION = "gephi";

Expand Down Expand Up @@ -114,7 +115,7 @@ public void process(Env env, Map values) throws CommandException {
try {
pc.openProject(file);
} catch (Exception ew) {
ew.printStackTrace();
Exceptions.printStackTrace(ew);
NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CommandLineProcessor.class, "CommandLineProcessor.openGephiError"), NotifyDescriptor.WARNING_MESSAGE);
DialogDisplayer.getDefault().notify(msg);
}
Expand All @@ -134,7 +135,7 @@ public void process(Env env, Map values) throws CommandException {
NotifyDescriptor nd = new NotifyDescriptor.Message(MEMORY_ERROR, NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(nd);
} catch (Exception ex) {
ex.printStackTrace();
Exceptions.printStackTrace(ex);
NotifyDescriptor nd = new NotifyDescriptor.Message("CommandLineParsing " + ex.getMessage(), NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(nd);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public boolean importData(TransferHandler.TransferSupport support) {
try {
pc.openProject(file);
} catch (Exception ew) {
ew.printStackTrace();
Exceptions.printStackTrace(ew);
NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(DragNDropFrameAdapter.class, "DragNDropFrameAdapter.openGephiError"), NotifyDescriptor.WARNING_MESSAGE);
DialogDisplayer.getDefault().notify(msg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Development and Distribution License("CDDL") (collectively, the
import org.openide.NotifyDescriptor;
import org.openide.modules.ModuleInfo;
import org.openide.modules.SpecificationVersion;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.w3c.dom.Document;
Expand Down Expand Up @@ -104,7 +105,7 @@ public void run() {
NotifyDescriptor.INFORMATION_MESSAGE));
return;
} catch (Exception e) {
e.printStackTrace();
Exceptions.printStackTrace(e);
}
handle.finish();
DialogDisplayer.getDefault().notify(
Expand Down Expand Up @@ -163,7 +164,7 @@ private Document buildXMLDocument(Report report) {
report.writeXml(document);
return document;
} catch (Exception e) {
e.printStackTrace();
Exceptions.printStackTrace(e);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Development and Distribution License("CDDL") (collectively, the
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.openide.util.Exceptions;
import org.w3c.dom.Document;

/**
Expand All @@ -68,7 +69,7 @@ public ViewDataPanel(Document document) {
String xmlString = result.getWriter().toString();
textArea.setText(xmlString);
} catch (Exception ex) {
ex.printStackTrace();
Exceptions.printStackTrace(ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Development and Distribution License("CDDL") (collectively, the
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.datatransfer.PasteType;
Expand Down Expand Up @@ -132,10 +133,8 @@ public Transferable paste() throws IOException {
return null;
}
};
} catch (UnsupportedFlavorException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Development and Distribution License("CDDL") (collectively, the
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.nodes.NodeTransfer;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.datatransfer.PasteType;
Expand Down Expand Up @@ -88,10 +89,8 @@ public Transferable paste() throws IOException {
return null;
}
};
} catch (UnsupportedFlavorException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
} else if (dropNode != null && dropNode instanceof SavedQueryNode) {
return new PasteType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,6 @@ public void fatalError(Throwable t) {
if (t instanceof OutOfMemoryError) {
return;
}
// t.printStackTrace();
// String message = t.getCause().getMessage();
// if (message == null || message.isEmpty()) {
// message = t.getMessage();
// }
// NotifyDescriptor.Message msg = new NotifyDescriptor.Message(message, NotifyDescriptor.WARNING_MESSAGE);
// DialogDisplayer.getDefault().notify(msg);
Exceptions.printStackTrace(t);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ private void openFile(FileFilter[] fileFilters, FileFilter initialFilter) {
try {
loadProject(gephiFile);
} catch (Exception ew) {
ew.printStackTrace();
Exceptions.printStackTrace(ew);
NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(ProjectControllerUIImpl.class, "OpenProject.defaulterror"), NotifyDescriptor.WARNING_MESSAGE);
DialogDisplayer.getDefault().notify(msg);
}
Expand Down
Loading

0 comments on commit f86ed6a

Please sign in to comment.