| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.gui; |
| 22 |
|
|
| 23 |
|
import java.awt.BorderLayout; |
| 24 |
|
import java.awt.Color; |
| 25 |
|
import java.awt.Dimension; |
| 26 |
|
import java.awt.Font; |
| 27 |
|
import java.awt.Graphics; |
| 28 |
|
import java.awt.Graphics2D; |
| 29 |
|
import java.awt.RenderingHints; |
| 30 |
|
import java.io.File; |
| 31 |
|
import java.util.List; |
| 32 |
|
import java.util.Locale; |
| 33 |
|
import java.util.Map; |
| 34 |
|
import java.util.concurrent.Executors; |
| 35 |
|
|
| 36 |
|
import javax.swing.JPanel; |
| 37 |
|
import javax.swing.JSplitPane; |
| 38 |
|
import javax.swing.SwingUtilities; |
| 39 |
|
import javax.swing.event.InternalFrameAdapter; |
| 40 |
|
import javax.swing.event.InternalFrameEvent; |
| 41 |
|
|
| 42 |
|
import jalview.api.AlignmentViewPanel; |
| 43 |
|
import jalview.bin.Console; |
| 44 |
|
import jalview.datamodel.PDBEntry; |
| 45 |
|
import jalview.datamodel.SequenceI; |
| 46 |
|
import jalview.datamodel.StructureViewerModel; |
| 47 |
|
import jalview.datamodel.StructureViewerModel.StructureData; |
| 48 |
|
import jalview.ext.jmol.JmolCommands; |
| 49 |
|
import jalview.gui.ImageExporter.ImageWriterI; |
| 50 |
|
import jalview.gui.StructureViewer.ViewerType; |
| 51 |
|
import jalview.io.exceptions.ImageOutputException; |
| 52 |
|
import jalview.structure.StructureCommand; |
| 53 |
|
import jalview.structures.models.AAStructureBindingModel; |
| 54 |
|
import jalview.util.BrowserLauncher; |
| 55 |
|
import jalview.util.ImageMaker; |
| 56 |
|
import jalview.util.ImageMaker.TYPE; |
| 57 |
|
import jalview.util.MessageManager; |
| 58 |
|
import jalview.util.Platform; |
| 59 |
|
import jalview.util.imagemaker.BitmapImageSizing; |
| 60 |
|
|
| |
|
| 68.4% |
Uncovered Elements: 85 (269) |
Complexity: 64 |
Complexity Density: 0.32 |
|
| 61 |
|
public class AppJmol extends StructureViewerBase |
| 62 |
|
{ |
| 63 |
|
|
| 64 |
|
private static final int JMOL_LOAD_TIMEOUT = 20000; |
| 65 |
|
|
| 66 |
|
private static final String SPACE = " "; |
| 67 |
|
|
| 68 |
|
private static final String QUOTE = "\""; |
| 69 |
|
|
| 70 |
|
AppJmolBinding jmb; |
| 71 |
|
|
| 72 |
|
JPanel scriptWindow; |
| 73 |
|
|
| 74 |
|
JSplitPane splitPane; |
| 75 |
|
|
| 76 |
|
RenderPanel renderPanel; |
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
@param |
| 81 |
|
@param |
| 82 |
|
@param |
| 83 |
|
@param |
| 84 |
|
@param |
| 85 |
|
|
| 86 |
|
|
| 87 |
|
@param |
| 88 |
|
|
| 89 |
|
|
| 90 |
|
@param |
| 91 |
|
|
| 92 |
|
|
| 93 |
|
@param |
| 94 |
|
@param |
| 95 |
|
@param |
| 96 |
|
|
| |
|
| 74.4% |
Uncovered Elements: 10 (39) |
Complexity: 5 |
Complexity Density: 0.15 |
|
| 97 |
7 |
public AppJmol(StructureViewerModel viewerModel, AlignmentPanel ap,... |
| 98 |
|
String sessionFile, String viewid) |
| 99 |
|
{ |
| 100 |
7 |
Map<File, StructureData> pdbData = viewerModel.getFileData(); |
| 101 |
7 |
PDBEntry[] pdbentrys = new PDBEntry[pdbData.size()]; |
| 102 |
7 |
SequenceI[][] seqs = new SequenceI[pdbData.size()][]; |
| 103 |
7 |
int i = 0; |
| 104 |
7 |
for (StructureData data : pdbData.values()) |
| 105 |
|
{ |
| 106 |
7 |
PDBEntry pdbentry = new PDBEntry(data.getPdbId(), null, |
| 107 |
|
PDBEntry.Type.PDB, data.getFilePath()); |
| 108 |
7 |
pdbentrys[i] = pdbentry; |
| 109 |
7 |
List<SequenceI> sequencesForPdb = data.getSeqList(); |
| 110 |
7 |
seqs[i] = sequencesForPdb |
| 111 |
|
.toArray(new SequenceI[sequencesForPdb.size()]); |
| 112 |
7 |
i++; |
| 113 |
|
} |
| 114 |
|
|
| 115 |
|
|
| 116 |
|
|
| 117 |
7 |
jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(), |
| 118 |
|
pdbentrys, seqs, null); |
| 119 |
|
|
| 120 |
7 |
jmb.setLoadingFromArchive(true); |
| 121 |
7 |
addAlignmentPanel(ap); |
| 122 |
7 |
if (viewerModel.isAlignWithPanel()) |
| 123 |
|
{ |
| 124 |
0 |
useAlignmentPanelForSuperposition(ap); |
| 125 |
|
} |
| 126 |
7 |
initMenus(); |
| 127 |
7 |
boolean useToColour = viewerModel.isColourWithAlignPanel(); |
| 128 |
7 |
boolean leaveColouringToJmol = viewerModel.isColourByViewer(); |
| 129 |
7 |
if (leaveColouringToJmol || !useToColour) |
| 130 |
|
{ |
| 131 |
7 |
jmb.setColourBySequence(false); |
| 132 |
7 |
seqColour.setSelected(false); |
| 133 |
7 |
viewerColour.setSelected(true); |
| 134 |
|
} |
| 135 |
0 |
else if (useToColour) |
| 136 |
|
{ |
| 137 |
0 |
useAlignmentPanelForColourbyseq(ap); |
| 138 |
0 |
jmb.setColourBySequence(true); |
| 139 |
0 |
seqColour.setSelected(true); |
| 140 |
0 |
viewerColour.setSelected(false); |
| 141 |
|
} |
| 142 |
|
|
| 143 |
7 |
this.setBounds(viewerModel.getX(), viewerModel.getY(), |
| 144 |
|
viewerModel.getWidth(), viewerModel.getHeight()); |
| 145 |
7 |
setViewId(viewid); |
| 146 |
|
|
| 147 |
7 |
this.addInternalFrameListener(new InternalFrameAdapter() |
| 148 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 149 |
7 |
@Override... |
| 150 |
|
public void internalFrameClosing( |
| 151 |
|
InternalFrameEvent internalFrameEvent) |
| 152 |
|
{ |
| 153 |
7 |
closeViewer(false); |
| 154 |
|
} |
| 155 |
|
}); |
| 156 |
7 |
StringBuilder cmd = new StringBuilder(); |
| 157 |
7 |
cmd.append(jmb.getCommandGenerator().loadFile(sessionFile)); |
| 158 |
7 |
initJmol(cmd.toString()); |
| 159 |
|
} |
| 160 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 161 |
62 |
@Override... |
| 162 |
|
protected void initMenus() |
| 163 |
|
{ |
| 164 |
62 |
super.initMenus(); |
| 165 |
|
|
| 166 |
62 |
viewerColour |
| 167 |
|
.setText(MessageManager.getString("label.colour_with_jmol")); |
| 168 |
62 |
viewerColour.setToolTipText(MessageManager |
| 169 |
|
.getString("label.let_jmol_manage_structure_colours")); |
| 170 |
|
} |
| 171 |
|
|
| 172 |
|
|
| 173 |
|
|
| 174 |
|
|
| 175 |
|
@param |
| 176 |
|
@param |
| 177 |
|
@param |
| 178 |
|
@param |
| 179 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 180 |
50 |
public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,... |
| 181 |
|
final AlignmentPanel ap) |
| 182 |
|
{ |
| 183 |
50 |
setProgressIndicator(ap.alignFrame); |
| 184 |
|
|
| 185 |
50 |
openNewJmol(ap, alignAddedStructures, new PDBEntry[] { pdbentry }, |
| 186 |
|
new SequenceI[][] |
| 187 |
|
{ seq }); |
| 188 |
|
} |
| 189 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 2 |
Complexity Density: 0.14 |
|
| 190 |
55 |
private void openNewJmol(AlignmentPanel ap, boolean alignAdded,... |
| 191 |
|
PDBEntry[] pdbentrys, SequenceI[][] seqs) |
| 192 |
|
{ |
| 193 |
55 |
setProgressIndicator(ap.alignFrame); |
| 194 |
55 |
jmb = new AppJmolBinding(this, ap.getStructureSelectionManager(), |
| 195 |
|
pdbentrys, seqs, null); |
| 196 |
55 |
addAlignmentPanel(ap); |
| 197 |
55 |
useAlignmentPanelForColourbyseq(ap); |
| 198 |
|
|
| 199 |
55 |
alignAddedStructures = alignAdded; |
| 200 |
55 |
if (pdbentrys.length > 1) |
| 201 |
|
{ |
| 202 |
5 |
useAlignmentPanelForSuperposition(ap); |
| 203 |
|
} |
| 204 |
|
|
| 205 |
55 |
jmb.setColourBySequence(true); |
| 206 |
55 |
setSize(400, 400); |
| 207 |
55 |
initMenus(); |
| 208 |
55 |
addingStructures = false; |
| 209 |
55 |
worker = new Thread(this); |
| 210 |
55 |
worker.start(); |
| 211 |
|
|
| 212 |
55 |
this.addInternalFrameListener(new InternalFrameAdapter() |
| 213 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 214 |
31 |
@Override... |
| 215 |
|
public void internalFrameClosing( |
| 216 |
|
InternalFrameEvent internalFrameEvent) |
| 217 |
|
{ |
| 218 |
31 |
closeViewer(false); |
| 219 |
|
} |
| 220 |
|
}); |
| 221 |
|
|
| 222 |
|
} |
| 223 |
|
|
| 224 |
|
|
| 225 |
|
|
| 226 |
|
|
| 227 |
|
|
| 228 |
|
@param |
| 229 |
|
@param |
| 230 |
|
|
| 231 |
|
@param |
| 232 |
|
@param |
| 233 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 234 |
5 |
public AppJmol(AlignmentPanel ap, boolean alignAdded, PDBEntry[] pe,... |
| 235 |
|
SequenceI[][] seqs) |
| 236 |
|
{ |
| 237 |
5 |
openNewJmol(ap, alignAdded, pe, seqs); |
| 238 |
|
} |
| 239 |
|
|
| |
|
| 85.7% |
Uncovered Elements: 3 (21) |
Complexity: 3 |
Complexity Density: 0.18 |
|
| 240 |
62 |
void initJmol(String command)... |
| 241 |
|
{ |
| 242 |
62 |
jmb.setFinishedInit(false); |
| 243 |
62 |
renderPanel = new RenderPanel(); |
| 244 |
|
|
| 245 |
|
|
| 246 |
62 |
this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER); |
| 247 |
62 |
jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(), |
| 248 |
|
getBounds().width, getBounds().height); |
| 249 |
62 |
if (scriptWindow == null) |
| 250 |
|
{ |
| 251 |
62 |
BorderLayout bl = new BorderLayout(); |
| 252 |
62 |
bl.setHgap(0); |
| 253 |
62 |
bl.setVgap(0); |
| 254 |
62 |
scriptWindow = new JPanel(bl); |
| 255 |
62 |
scriptWindow.setVisible(false); |
| 256 |
|
} |
| 257 |
|
|
| 258 |
62 |
jmb.allocateViewer(renderPanel, true, "", null, null, "", scriptWindow, |
| 259 |
|
null); |
| 260 |
|
|
| 261 |
62 |
if (command == null) |
| 262 |
|
{ |
| 263 |
0 |
command = ""; |
| 264 |
|
} |
| 265 |
62 |
jmb.executeCommand(new StructureCommand(command), false); |
| 266 |
62 |
jmb.executeCommand(new StructureCommand("set hoverDelay=0.1"), false); |
| 267 |
62 |
jmb.executeCommand(new StructureCommand("set antialiasdisplay on"), |
| 268 |
|
false); |
| 269 |
62 |
jmb.setFinishedInit(true); |
| 270 |
|
} |
| 271 |
|
|
| |
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 272 |
60 |
@Override... |
| 273 |
|
public void run() |
| 274 |
|
{ |
| 275 |
60 |
_started = true; |
| 276 |
60 |
try |
| 277 |
|
{ |
| 278 |
60 |
List<String> files = jmb.fetchPdbFiles(this); |
| 279 |
60 |
if (files.size() > 0) |
| 280 |
|
{ |
| 281 |
60 |
showFilesInViewer(files); |
| 282 |
|
} |
| 283 |
|
} finally |
| 284 |
|
{ |
| 285 |
60 |
_started = false; |
| 286 |
60 |
worker = null; |
| 287 |
|
} |
| 288 |
|
} |
| 289 |
|
|
| 290 |
|
|
| 291 |
|
|
| 292 |
|
|
| 293 |
|
|
| 294 |
|
@param |
| 295 |
|
|
| 296 |
|
|
| |
|
| 72.2% |
Uncovered Elements: 15 (54) |
Complexity: 13 |
Complexity Density: 0.3 |
|
| 297 |
60 |
void showFilesInViewer(List<String> files)... |
| 298 |
|
{ |
| 299 |
60 |
long lastnotify = jmb.getLoadNotifiesHandled(); |
| 300 |
60 |
StringBuilder fileList = new StringBuilder(); |
| 301 |
60 |
for (String s : files) |
| 302 |
|
{ |
| 303 |
70 |
fileList.append(SPACE).append(QUOTE) |
| 304 |
|
.append(JmolCommands.escapeQuotedFilename(s)).append(QUOTE); |
| 305 |
|
} |
| 306 |
60 |
String filesString = fileList.toString(); |
| 307 |
|
|
| 308 |
60 |
if (!addingStructures) |
| 309 |
|
{ |
| 310 |
55 |
try |
| 311 |
|
{ |
| 312 |
55 |
initJmol("load FILES " + filesString); |
| 313 |
|
} catch (OutOfMemoryError oomerror) |
| 314 |
|
{ |
| 315 |
0 |
new OOMWarning("When trying to open the Jmol viewer!", oomerror); |
| 316 |
0 |
Console.debug("File locations are " + filesString); |
| 317 |
|
} catch (Exception ex) |
| 318 |
|
{ |
| 319 |
0 |
Console.error("Couldn't open Jmol viewer!", ex); |
| 320 |
0 |
ex.printStackTrace(); |
| 321 |
0 |
return; |
| 322 |
|
} |
| 323 |
|
} |
| 324 |
|
else |
| 325 |
|
{ |
| 326 |
5 |
StringBuilder cmd = new StringBuilder(); |
| 327 |
5 |
cmd.append("loadingJalviewdata=true\nload APPEND "); |
| 328 |
5 |
cmd.append(filesString); |
| 329 |
5 |
cmd.append("\nloadingJalviewdata=null"); |
| 330 |
5 |
final StructureCommand command = new StructureCommand(cmd.toString()); |
| 331 |
5 |
lastnotify = jmb.getLoadNotifiesHandled(); |
| 332 |
|
|
| 333 |
5 |
try |
| 334 |
|
{ |
| 335 |
5 |
jmb.executeCommand(command, false); |
| 336 |
|
} catch (OutOfMemoryError oomerror) |
| 337 |
|
{ |
| 338 |
0 |
new OOMWarning("When trying to add structures to the Jmol viewer!", |
| 339 |
|
oomerror); |
| 340 |
0 |
Console.debug("File locations are " + filesString); |
| 341 |
0 |
return; |
| 342 |
|
} catch (Exception ex) |
| 343 |
|
{ |
| 344 |
0 |
Console.error("Couldn't add files to Jmol viewer!", ex); |
| 345 |
0 |
ex.printStackTrace(); |
| 346 |
0 |
return; |
| 347 |
|
} |
| 348 |
|
} |
| 349 |
|
|
| 350 |
|
|
| 351 |
60 |
int waitMax = JMOL_LOAD_TIMEOUT; |
| 352 |
60 |
int waitFor = 35; |
| 353 |
60 |
int waitTotal = 0; |
| 354 |
223 |
while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled() |
| 355 |
|
: !(jmb.isFinishedInit() && jmb.getStructureFiles() != null |
| 356 |
|
&& jmb.getStructureFiles().length == files.size())) |
| 357 |
|
{ |
| 358 |
163 |
try |
| 359 |
|
{ |
| 360 |
163 |
Console.debug("Waiting around for jmb notify."); |
| 361 |
163 |
waitTotal += waitFor; |
| 362 |
|
|
| 363 |
|
|
| 364 |
163 |
Thread.sleep(waitFor); |
| 365 |
|
} catch (Exception e) |
| 366 |
|
{ |
| 367 |
|
} |
| 368 |
163 |
if (waitTotal > waitMax) |
| 369 |
|
{ |
| 370 |
0 |
jalview.bin.Console.errPrintln( |
| 371 |
|
"Timed out waiting for Jmol to load files after " |
| 372 |
|
+ waitTotal + "ms"); |
| 373 |
|
|
| 374 |
|
|
| 375 |
|
|
| 376 |
0 |
jmb.getStructureFiles(); |
| 377 |
0 |
break; |
| 378 |
|
} |
| 379 |
|
} |
| 380 |
|
|
| 381 |
|
|
| 382 |
60 |
for (AlignmentViewPanel ap : _colourwith) |
| 383 |
|
{ |
| 384 |
59 |
jmb.updateColours(ap); |
| 385 |
|
} |
| 386 |
|
|
| 387 |
58 |
if (alignAddedStructures) |
| 388 |
|
{ |
| 389 |
3 |
alignAddedStructures(); |
| 390 |
|
} |
| 391 |
58 |
addingStructures = false; |
| 392 |
|
} |
| 393 |
|
|
| 394 |
|
|
| 395 |
|
|
| 396 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 397 |
3 |
void alignAddedStructures()... |
| 398 |
|
{ |
| 399 |
3 |
javax.swing.SwingUtilities.invokeLater(new Runnable() |
| 400 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 401 |
5 |
@Override... |
| 402 |
|
public void run() |
| 403 |
|
{ |
| 404 |
5 |
if (jmb.jmolViewer.isScriptExecuting()) |
| 405 |
|
{ |
| 406 |
2 |
SwingUtilities.invokeLater(this); |
| 407 |
2 |
try |
| 408 |
|
{ |
| 409 |
2 |
Thread.sleep(5); |
| 410 |
|
} catch (InterruptedException q) |
| 411 |
|
{ |
| 412 |
|
} |
| 413 |
2 |
return; |
| 414 |
|
} |
| 415 |
|
else |
| 416 |
|
{ |
| 417 |
3 |
alignStructsWithAllAlignPanels(); |
| 418 |
|
} |
| 419 |
|
} |
| 420 |
|
}); |
| 421 |
|
|
| 422 |
|
} |
| 423 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
| 424 |
0 |
public boolean isRepainting()... |
| 425 |
|
{ |
| 426 |
0 |
if (renderPanel != null && renderPanel.isVisible()) |
| 427 |
|
{ |
| 428 |
0 |
return renderPanel.repainting; |
| 429 |
|
} |
| 430 |
0 |
return false; |
| 431 |
|
} |
| 432 |
|
|
| 433 |
|
|
| 434 |
|
|
| 435 |
|
|
| 436 |
|
|
| 437 |
|
|
| 438 |
|
@param |
| 439 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 440 |
0 |
@Override... |
| 441 |
|
public void makePDBImage(ImageMaker.TYPE type) |
| 442 |
|
{ |
| 443 |
0 |
Runnable exporter = new Runnable() |
| 444 |
|
{ |
| |
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 4 |
Complexity Density: 0.67 |
|
| 445 |
0 |
@Override... |
| 446 |
|
public void run() |
| 447 |
|
{ |
| 448 |
0 |
while (!isRepainting()) |
| 449 |
|
{ |
| 450 |
0 |
try |
| 451 |
|
{ |
| 452 |
0 |
Thread.sleep(2); |
| 453 |
|
} catch (Exception q) |
| 454 |
|
{ |
| 455 |
|
} |
| 456 |
|
} |
| 457 |
0 |
try |
| 458 |
|
{ |
| 459 |
0 |
makePDBImage(null, type, null, |
| 460 |
|
BitmapImageSizing.defaultBitmapImageSizing()); |
| 461 |
|
} catch (ImageOutputException ioex) |
| 462 |
|
{ |
| 463 |
0 |
Console.error( |
| 464 |
|
"Unexpected error whilst writing " + type.toString(), |
| 465 |
|
ioex); |
| 466 |
|
} |
| 467 |
|
} |
| 468 |
|
}; |
| 469 |
|
|
| 470 |
0 |
Executors.newCachedThreadPool().execute(exporter); |
| 471 |
|
} |
| 472 |
|
|
| |
|
| 70.6% |
Uncovered Elements: 10 (34) |
Complexity: 7 |
Complexity Density: 0.27 |
|
| 473 |
10 |
public void makePDBImage(File file, ImageMaker.TYPE type, String renderer,... |
| 474 |
|
BitmapImageSizing userBis) throws ImageOutputException |
| 475 |
|
{ |
| 476 |
10 |
int width = getWidth(); |
| 477 |
10 |
int height = getHeight(); |
| 478 |
|
|
| 479 |
10 |
BitmapImageSizing bis = ImageMaker.getScaleWidthHeight(width, height, |
| 480 |
|
userBis); |
| 481 |
10 |
float usescale = bis.scale(); |
| 482 |
10 |
int usewidth = bis.width(); |
| 483 |
10 |
int useheight = bis.height(); |
| 484 |
|
|
| 485 |
10 |
ImageWriterI writer = new ImageWriterI() |
| 486 |
|
{ |
| |
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
| 487 |
10 |
@Override... |
| 488 |
|
public void exportImage(Graphics g) throws Exception |
| 489 |
|
{ |
| 490 |
10 |
Graphics2D ig2 = (Graphics2D) g; |
| 491 |
10 |
ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
| 492 |
|
RenderingHints.VALUE_ANTIALIAS_ON); |
| 493 |
10 |
if (type == TYPE.PNG && usescale > 0.0f) |
| 494 |
|
{ |
| 495 |
|
|
| 496 |
|
|
| 497 |
4 |
if (usescale > 0.0f) |
| 498 |
|
{ |
| 499 |
4 |
ig2.scale(1 / usescale, 1 / usescale); |
| 500 |
|
} |
| 501 |
|
} |
| 502 |
|
|
| 503 |
10 |
jmb.jmolViewer.requestRepaintAndWait("image export"); |
| 504 |
10 |
jmb.jmolViewer.renderScreenImage(ig2, usewidth, useheight); |
| 505 |
|
} |
| 506 |
|
}; |
| 507 |
10 |
String view = MessageManager.getString("action.view") |
| 508 |
|
.toLowerCase(Locale.ROOT); |
| 509 |
10 |
final ImageExporter exporter = new ImageExporter(writer, |
| 510 |
|
getProgressIndicator(), type, getTitle()); |
| 511 |
|
|
| 512 |
10 |
final Throwable[] exceptions = new Throwable[1]; |
| 513 |
10 |
exceptions[0] = null; |
| 514 |
10 |
final AppJmol us = this; |
| 515 |
10 |
try |
| 516 |
|
{ |
| 517 |
10 |
Thread runner = Executors.defaultThreadFactory() |
| 518 |
|
.newThread(new Runnable() |
| 519 |
|
{ |
| |
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 520 |
10 |
@Override... |
| 521 |
|
public void run() |
| 522 |
|
{ |
| 523 |
10 |
try |
| 524 |
|
{ |
| 525 |
10 |
exporter.doExport(file, us, width, height, view, |
| 526 |
|
renderer, userBis); |
| 527 |
|
} catch (Throwable t) |
| 528 |
|
{ |
| 529 |
0 |
exceptions[0] = t; |
| 530 |
|
} |
| 531 |
|
} |
| 532 |
|
}); |
| 533 |
10 |
runner.start(); |
| 534 |
10 |
long time = 0; |
| 535 |
10 |
do |
| 536 |
|
{ |
| 537 |
402 |
Thread.sleep(25); |
| 538 |
402 |
} while (runner.isAlive() && time++ < 4000); |
| 539 |
10 |
if (time >= 4000) |
| 540 |
|
{ |
| 541 |
0 |
runner.interrupt(); |
| 542 |
0 |
throw new ImageOutputException( |
| 543 |
|
"Jmol took too long to export. Waited for 100 seconds."); |
| 544 |
|
} |
| 545 |
|
} catch (Throwable e) |
| 546 |
|
{ |
| 547 |
0 |
throw new ImageOutputException( |
| 548 |
|
"Unexpected error when generating image", e); |
| 549 |
|
} |
| 550 |
10 |
if (exceptions[0] != null) |
| 551 |
|
{ |
| 552 |
0 |
if (exceptions[0] instanceof ImageOutputException) |
| 553 |
|
{ |
| 554 |
0 |
throw ((ImageOutputException) exceptions[0]); |
| 555 |
|
} |
| 556 |
|
else |
| 557 |
|
{ |
| 558 |
0 |
throw new ImageOutputException( |
| 559 |
|
"Unexpected error when generating image", exceptions[0]); |
| 560 |
|
} |
| 561 |
|
} |
| 562 |
|
} |
| 563 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 564 |
0 |
@Override... |
| 565 |
|
public void showHelp_actionPerformed() |
| 566 |
|
{ |
| 567 |
0 |
try |
| 568 |
|
{ |
| 569 |
0 |
BrowserLauncher |
| 570 |
|
.openURL("http://wiki.jmol.org"); |
| 571 |
|
} catch (Exception ex) |
| 572 |
|
{ |
| 573 |
0 |
jalview.bin.Console |
| 574 |
|
.errPrintln("Show Jmol help failed with: " + ex.getMessage()); |
| 575 |
|
} |
| 576 |
|
} |
| 577 |
|
|
| |
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 4 |
Complexity Density: 0.27 |
|
| 578 |
0 |
@Override... |
| 579 |
|
public void showConsole(boolean showConsole) |
| 580 |
|
{ |
| 581 |
0 |
if (showConsole) |
| 582 |
|
{ |
| 583 |
0 |
if (splitPane == null) |
| 584 |
|
{ |
| 585 |
0 |
splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
| 586 |
0 |
splitPane.setTopComponent(renderPanel); |
| 587 |
0 |
splitPane.setBottomComponent(scriptWindow); |
| 588 |
0 |
this.getContentPane().add(splitPane, BorderLayout.CENTER); |
| 589 |
0 |
splitPane.setDividerLocation(getHeight() - 200); |
| 590 |
0 |
scriptWindow.setVisible(true); |
| 591 |
0 |
scriptWindow.validate(); |
| 592 |
0 |
splitPane.validate(); |
| 593 |
|
} |
| 594 |
|
|
| 595 |
|
} |
| 596 |
|
else |
| 597 |
|
{ |
| 598 |
0 |
if (splitPane != null) |
| 599 |
|
{ |
| 600 |
0 |
splitPane.setVisible(false); |
| 601 |
|
} |
| 602 |
|
|
| 603 |
0 |
splitPane = null; |
| 604 |
|
|
| 605 |
0 |
this.getContentPane().add(renderPanel, BorderLayout.CENTER); |
| 606 |
|
} |
| 607 |
|
|
| 608 |
0 |
validate(); |
| 609 |
|
} |
| 610 |
|
|
| |
|
| 43.2% |
Uncovered Elements: 21 (37) |
Complexity: 10 |
Complexity Density: 0.38 |
|
| 611 |
|
class RenderPanel extends JPanel |
| 612 |
|
{ |
| 613 |
|
final Dimension currentSize = new Dimension(); |
| 614 |
|
|
| |
|
| 41.7% |
Uncovered Elements: 21 (36) |
Complexity: 10 |
Complexity Density: 0.38 |
|
| 615 |
624 |
@Override... |
| 616 |
|
public void paintComponent(Graphics g) |
| 617 |
|
{ |
| 618 |
624 |
getSize(currentSize); |
| 619 |
|
|
| 620 |
624 |
if (jmb != null && jmb.hasFileLoadingError()) |
| 621 |
|
{ |
| 622 |
0 |
g.setColor(Color.black); |
| 623 |
0 |
g.fillRect(0, 0, currentSize.width, currentSize.height); |
| 624 |
0 |
g.setColor(Color.white); |
| 625 |
0 |
g.setFont(new Font("Verdana", Font.BOLD, 14)); |
| 626 |
0 |
g.drawString(MessageManager.getString("label.error_loading_file") |
| 627 |
|
+ "...", 20, currentSize.height / 2); |
| 628 |
0 |
StringBuffer sb = new StringBuffer(); |
| 629 |
0 |
int lines = 0; |
| 630 |
0 |
for (int e = 0; e < jmb.getPdbCount(); e++) |
| 631 |
|
{ |
| 632 |
0 |
sb.append(jmb.getPdbEntry(e).getId()); |
| 633 |
0 |
if (e < jmb.getPdbCount() - 1) |
| 634 |
|
{ |
| 635 |
0 |
sb.append(","); |
| 636 |
|
} |
| 637 |
|
|
| 638 |
0 |
if (e == jmb.getPdbCount() - 1 || sb.length() > 20) |
| 639 |
|
{ |
| 640 |
0 |
lines++; |
| 641 |
0 |
g.drawString(sb.toString(), 20, currentSize.height / 2 |
| 642 |
|
- lines * g.getFontMetrics().getHeight()); |
| 643 |
|
} |
| 644 |
|
} |
| 645 |
|
} |
| 646 |
624 |
else if (jmb == null || jmb.jmolViewer == null |
| 647 |
|
|| !jmb.isFinishedInit()) |
| 648 |
|
{ |
| 649 |
52 |
g.setColor(Color.black); |
| 650 |
52 |
g.fillRect(0, 0, currentSize.width, currentSize.height); |
| 651 |
52 |
g.setColor(Color.white); |
| 652 |
52 |
g.setFont(new Font("Verdana", Font.BOLD, 14)); |
| 653 |
52 |
g.drawString(MessageManager.getString("label.retrieving_pdb_data"), |
| 654 |
|
20, currentSize.height / 2); |
| 655 |
|
} |
| 656 |
|
else |
| 657 |
|
{ |
| 658 |
572 |
repainting = true; |
| 659 |
572 |
synchronized (jmb) |
| 660 |
|
{ |
| 661 |
572 |
jmb.jmolViewer.renderScreenImage(g, currentSize.width, |
| 662 |
|
currentSize.height); |
| 663 |
|
|
| 664 |
|
} |
| 665 |
572 |
repainting = false; |
| 666 |
|
} |
| 667 |
|
} |
| 668 |
|
|
| 669 |
|
volatile boolean repainting = false; |
| 670 |
|
} |
| 671 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 672 |
2534 |
@Override... |
| 673 |
|
public AAStructureBindingModel getBinding() |
| 674 |
|
{ |
| 675 |
2534 |
return this.jmb; |
| 676 |
|
} |
| 677 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 678 |
68 |
@Override... |
| 679 |
|
public ViewerType getViewerType() |
| 680 |
|
{ |
| 681 |
68 |
return ViewerType.JMOL; |
| 682 |
|
} |
| 683 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 684 |
202 |
@Override... |
| 685 |
|
protected String getViewerName() |
| 686 |
|
{ |
| 687 |
202 |
return "Jmol"; |
| 688 |
|
} |
| 689 |
|
} |