1 /* 2 * @(#)CutPanel 3 * 4 * Copyright (c) 2006-2009 by dvb.matt, All Rights Reserved. 5 * 6 * This file is part of ProjectX, a free Java based demux utility. 7 * By the authors, ProjectX is intended for educational purposes only, 8 * as a non-commercial test project. 9 * 10 * 11 * This program is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; either version 2 of the License, or 14 * (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program; if not, write to the Free Software 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 * 25 */ 26 27 package net.sourceforge.dvb.projectx.gui; 28 29 import java.awt.dnd.DropTarget; 30 import java.awt.dnd.DropTargetDragEvent; 31 import java.awt.dnd.DropTargetDropEvent; 32 import java.awt.dnd.DropTargetEvent; 33 import java.awt.dnd.DropTargetListener; 34 35 import java.awt.datatransfer.DataFlavor; 36 import java.awt.datatransfer.Transferable; 37 38 import java.awt.BorderLayout; 39 import java.awt.Color; 40 import java.awt.Dimension; 41 import java.awt.Graphics; 42 import java.awt.Image; 43 import java.awt.image.MemoryImageSource; 44 import java.awt.Font; 45 import java.awt.GridLayout; 46 47 import java.awt.event.ActionEvent; 48 import java.awt.event.ActionListener; 49 import java.awt.event.MouseMotionAdapter; 50 import java.awt.event.MouseAdapter; 51 import java.awt.event.MouseEvent; 52 import java.awt.event.KeyAdapter; 53 import java.awt.event.KeyEvent; 54 55 import java.util.Arrays; 56 import java.util.ArrayList; 57 import java.util.List; 58 import java.util.Comparator; 59 60 import javax.swing.Box; 61 import javax.swing.BoxLayout; 62 import javax.swing.JPanel; 63 import javax.swing.JTextField; 64 import javax.swing.JButton; 65 import javax.swing.JComboBox; 66 import javax.swing.JFileChooser; 67 import javax.swing.JComponent; 68 import javax.swing.JLabel; 69 import javax.swing.JList; 70 import javax.swing.BorderFactory; 71 72 import javax.swing.event.ChangeListener; 73 import javax.swing.event.ChangeEvent; 74 75 // 76 import javax.swing.JSlider; 77 78 import java.io.BufferedReader; 79 import java.io.BufferedWriter; 80 import java.io.IOException; 81 import java.io.File; 82 import java.io.FileReader; 83 import java.io.FileWriter; 84 85 import net.sourceforge.dvb.projectx.common.Keys; 86 import net.sourceforge.dvb.projectx.common.Common; 87 import net.sourceforge.dvb.projectx.common.Resource; 88 import net.sourceforge.dvb.projectx.common.JobCollection; 89 90 import net.sourceforge.dvb.projectx.parser.CommonParsing; 91 92 import net.sourceforge.dvb.projectx.video.Preview; 93 import net.sourceforge.dvb.projectx.video.PreviewObject; 94 95 import net.sourceforge.dvb.projectx.xinput.XInputFile; 96 import net.sourceforge.dvb.projectx.gui.ComboBoxIndexListener; 97 98 /** 99 * 100 */ 101 public class CutPanel extends JPanel { 102 103 private int active_collection = 0; 104 private int loadSizeForward = 2560000; 105 106 private long lastPosition = 0; 107 private long divisor = 16L; 108 109 private boolean matchingPoint = false; 110 111 private boolean cut_top = true; 112 private boolean cut_bottom = false; 113 private boolean cut_match = false; 114 private boolean action = false; 115 116 private String file = " "; 117 118 private String navigation[] = { 119 "leftsteparrow1x.gif", "leftarrow3x.gif", "leftarrow2x.gif", 120 "rightarrow2x.gif", "rightarrow3x.gif", "rightsteparrow1x.gif", 121 "leftarrowstep1x.gif", "rightarrowstep1x.gif" 122 }; 123 124 private JComboBox cutIndexList; 125 private JComboBox chapterIndexList; 126 private JComboBox cutmode_combobox; 127 128 private JTextField includeField; 129 private JTextField positionField; 130 private JTextField estimatedSizeField; 131 private JTextField chapterCountField; 132 private JTextField chapterIndexField; 133 private JTextField cutCountField; 134 private JTextField cutIndexField; 135 136 private JButton cutAdd; 137 private JButton cutDelete; 138 private JButton chapterAdd; 139 private JButton chapterDelete; 140 141 private JButton[] jump; 142 143 private JSlider slider; 144 145 private X_JFileChooser chooser; 146 147 private DNDListener2 dnd2 = new DNDListener2(); 148 private JumpListener jumpAction = new JumpListener(); 149 private CutListener cutAction = new CutListener(); 150 151 private JobCollection collection; 152 153 private CutView cutview; 154 private Preview Preview = new Preview(loadSizeForward); 155 156 private List previewList = new ArrayList(); 157 158 private ComboBoxIndexListener _ComboBoxIndexListener = new ComboBoxIndexListener(); 159 160 private SlideShow cl = new SlideShow(); 161 162 private CutMatrix cm = new CutMatrix(); 163 164 private boolean slideshow = false; 165 166 private JPanel sliderPanel; 167 168 /** 169 * 170 */ 171 private class DNDListener2 implements DropTargetListener 172 { drop(DropTargetDropEvent e)173 public void drop(DropTargetDropEvent e) 174 { 175 try { 176 int dropaction = e.getDropAction(); // 1=copy, 2=move 177 178 if ( dropaction == 0 || dropaction > 2) 179 { 180 e.rejectDrop(); 181 182 return; 183 } 184 185 e.acceptDrop(dropaction); 186 187 Transferable tr = e.getTransferable(); 188 DataFlavor[] df = tr.getTransferDataFlavors(); 189 List li = (List) tr.getTransferData(df[0]); // see note about mac os x 190 191 Object[] val = li.toArray(); 192 193 if (val.length > 0) 194 loadCutList(val[0].toString()); 195 196 e.dropComplete(true); 197 198 } catch (Exception eee) { 199 200 e.dropComplete(false); 201 Common.setExceptionMessage(eee); 202 } 203 } 204 dragEnter(DropTargetDragEvent e)205 public void dragEnter(DropTargetDragEvent e) 206 {} 207 dragExit(DropTargetEvent e)208 public void dragExit(DropTargetEvent e) 209 {} 210 dragOver(DropTargetDragEvent e)211 public void dragOver(DropTargetDragEvent e) 212 {} 213 dropActionChanged(DropTargetDragEvent e)214 public void dropActionChanged(DropTargetDragEvent e) 215 {} 216 } 217 218 /** 219 * 220 */ 221 private class CutListener implements ActionListener 222 { actionPerformed(ActionEvent e)223 public void actionPerformed(ActionEvent e) 224 { 225 if (collection == null) 226 return; 227 228 if (!action) 229 return; 230 231 action = false; 232 String actName = e.getActionCommand(); 233 234 if (actName.equals("delpoint")) 235 { 236 if (cutIndexList.getItemCount() > 0) 237 removeCutpoint(cutIndexList.getSelectedIndex()); 238 } 239 240 else if (actName.equals("cutnumber") || actName.equals("addpoint")) 241 { 242 String value = positionField.getText(); 243 244 if (!value.equals("") && addCutpoint(value)) 245 { 246 if (Common.getSettings().getIntProperty(Keys.KEY_CutMode) == CommonParsing.CUTMODE_BYTE) 247 collection.setCutImage(value, Common.getMpvDecoderClass().getCutImage()); 248 } 249 } 250 251 else if (actName.equals("delchapter")) 252 { 253 if (chapterIndexList.getItemCount() > 0) 254 removeChapterpoint(chapterIndexList.getSelectedIndex()); 255 } 256 257 else if (actName.equals("addchapter")) 258 { 259 String value = positionField.getText(); 260 261 if (!value.equals("") && addChapterpoint(value)) 262 {} 263 } 264 265 else if (actName.equals("movecutleft")) 266 { 267 if (cutIndexList.getItemCount() > 0) 268 { 269 int index = cutIndexList.getSelectedIndex(); 270 271 action = true; 272 jump[6].doClick(); 273 action = false; 274 275 removeCutpoint(index); 276 addCutpoint(positionField.getText()); 277 } 278 } 279 280 else if (actName.equals("movecutright")) 281 { 282 if (cutIndexList.getItemCount() > 0) 283 { 284 int index = cutIndexList.getSelectedIndex(); 285 286 action = true; 287 jump[7].doClick(); 288 action = false; 289 290 removeCutpoint(index); 291 addCutpoint(positionField.getText()); 292 } 293 } 294 295 else if (actName.equals("movechapterleft")) 296 { 297 if (chapterIndexList.getItemCount() > 0) 298 { 299 int index = chapterIndexList.getSelectedIndex(); 300 301 action = true; 302 jump[6].doClick(); 303 action = false; 304 305 removeChapterpoint(index); 306 addChapterpoint(positionField.getText()); 307 } 308 } 309 310 else if (actName.equals("movechapterright")) 311 { 312 if (chapterIndexList.getItemCount() > 0) 313 { 314 int index = chapterIndexList.getSelectedIndex(); 315 316 action = true; 317 jump[7].doClick(); 318 action = false; 319 320 removeChapterpoint(index); 321 addChapterpoint(positionField.getText()); 322 } 323 } 324 325 /** 326 * stuff completion for add and del cutpoints 327 */ 328 if (cutIndexList.getItemCount() > 0) 329 { 330 Object[] obj = collection.getCutpoints(); 331 332 int index = cutIndexList.getSelectedIndex(); 333 334 setCutIndexField(index + 1); 335 336 showCutInfo((index & 1) == 0, obj, previewList); 337 //Common.getGuiInterface().showCutIcon((index & 1) == 0, obj, previewList); 338 339 if (actName.equals("cutbox") || actName.equals("delpoint")) 340 { 341 if (Common.getSettings().getIntProperty(Keys.KEY_CutMode) == CommonParsing.CUTMODE_BYTE) 342 preview(Long.parseLong(obj[index].toString())); 343 } 344 345 if (actName.equals("addpoint")) 346 updateCutView(String.valueOf(lastPosition)); 347 } 348 349 else 350 { 351 showCutInfo(true, null, previewList); 352 //Common.getGuiInterface().showCutIcon(true, null, previewList); 353 354 setCutIndexField(-1); 355 356 updateCutView(String.valueOf(lastPosition)); 357 } 358 359 /** 360 * stuff completion for add and del chapterpoints 361 */ 362 if (chapterIndexList.getItemCount() > 0) 363 { 364 Object[] obj = collection.getChapterpoints(); 365 366 int index = chapterIndexList.getSelectedIndex(); 367 368 setChapterIndexField(index + 1); 369 370 Common.getGuiInterface().showChapterIcon(obj, previewList); 371 372 if (actName.equals("chapterbox")) 373 { 374 if (Common.getSettings().getIntProperty(Keys.KEY_CutMode) == CommonParsing.CUTMODE_BYTE) 375 preview(Long.parseLong(obj[index].toString())); 376 } 377 } 378 379 else 380 { 381 Common.getGuiInterface().showChapterIcon(null, previewList); 382 383 setChapterIndexField(-1); 384 } 385 386 /** 387 * 388 */ 389 if (Common.getSettings().getIntProperty(Keys.KEY_CutMode) == CommonParsing.CUTMODE_BYTE) 390 slider.requestFocus(); 391 392 getExpectedSize(); 393 updatePositionField(); 394 395 if (actName.startsWith("move")) 396 updateCutView(String.valueOf(lastPosition)); 397 398 399 action = true; 400 } 401 } 402 403 /** 404 * 405 */ 406 private class JumpListener implements ActionListener 407 { actionPerformed(ActionEvent e)408 public void actionPerformed(ActionEvent e) 409 { 410 if (collection == null) 411 return; 412 413 if (!action) 414 return; 415 416 String actName = e.getActionCommand(); 417 int val = slider.getValue(); 418 419 /** 420 * prev. cut point pos. 421 */ 422 if (actName.equals(navigation[0])) 423 { 424 int i = 0; 425 int ic = cutIndexList.getItemCount(); 426 427 if (ic > 0) 428 { 429 i = ic - 1; 430 431 if (lastPosition > Long.parseLong(cutIndexList.getItemAt(0).toString())) 432 while (lastPosition <= Long.parseLong(cutIndexList.getItemAt(i).toString())) 433 i--; 434 435 cutIndexList.setSelectedIndex(i); 436 } 437 } 438 439 else if (actName.equals(navigation[1])) 440 slider.setValue(val - 3125000); 441 442 else if (actName.equals(navigation[2])) 443 slider.setValue(val - 312500); 444 445 else if (actName.equals(navigation[6])) 446 slider.setValue(val - 2); 447 448 else if (actName.equals(navigation[7])) 449 slider.setValue(val + 2); 450 451 else if (actName.equals(navigation[3])) 452 slider.setValue(val + 312500); 453 454 else if (actName.equals(navigation[4])) 455 slider.setValue(val + 3125000); 456 457 /** 458 * next cut point pos. 459 */ 460 else if (actName.equals(navigation[5])) 461 { 462 int i = 0; 463 int ic = cutIndexList.getItemCount(); 464 465 if (ic > 0) 466 { 467 if (lastPosition < Long.parseLong(cutIndexList.getItemAt(ic - 1).toString())) 468 while (lastPosition >= Long.parseLong(cutIndexList.getItemAt(i).toString())) 469 i++; 470 471 cutIndexList.setSelectedIndex(i); 472 } 473 } 474 475 else if (actName.equals("load_cutlist")) 476 loadCutList(); 477 478 else if (actName.equals("save_cutlist")) 479 saveCutList(); 480 481 else if (actName.equals("load_chapterlist")) 482 loadChapterList(); 483 484 else if (actName.equals("save_chapterlist")) 485 saveChapterList(); 486 487 else if (actName.equals("cut_scan")) 488 restartMatrix(); 489 } 490 } 491 492 /** 493 * class to control play of slideshow 494 */ 495 private class SlideShow implements Runnable { 496 497 private Thread clockThread = null; 498 499 private long value = 0; 500 private long skip = 50; 501 502 private Object[] cutpoints = null; 503 504 /** 505 * 506 */ start(long _value)507 public void start(long _value) 508 { 509 if (clockThread == null) 510 { 511 clockThread = new Thread(this, "SlideShow"); 512 // clockThread.setPriority(Thread.MIN_PRIORITY); 513 clockThread.setPriority(Thread.NORM_PRIORITY); 514 515 value = _value; 516 //skip = getLoadSize()>>>5; 517 skip = getLoadSize()>>>6; 518 519 getCutPoints(); 520 521 clockThread.start(); 522 } 523 } 524 525 /** 526 * 527 */ getCutPoints()528 private void getCutPoints() 529 { 530 cutpoints = collection == null ? null : collection.getCutpoints(); 531 } 532 533 /** 534 * 535 */ run()536 public void run() 537 { 538 Thread myThread = Thread.currentThread(); 539 540 while (clockThread == myThread) 541 { 542 try { 543 544 for (long val;; ) 545 { 546 val = update(value); 547 Thread.sleep(5); 548 549 CommonGui.getPlayerFrame().repaintPicture(1); 550 551 if (!slideshow || val < value) 552 break; 553 554 value = skipArea(val); 555 556 if (value < val) 557 break; 558 } 559 560 stop(); 561 562 } catch (InterruptedException e) {} 563 564 } 565 } 566 567 /** 568 * 569 */ update(long val)570 private long update(long val) 571 { 572 return preview(val); 573 } 574 575 /** 576 * 577 */ skipArea(long val)578 private long skipArea(long val) 579 { 580 // next gop 581 if (cutpoints == null || cutpoints.length == 0) 582 return (val + skip); 583 584 int index = getCutIndex(cutpoints, String.valueOf(val)); 585 586 // area among cutpoints 587 if (index < 0) 588 { 589 // next gop "in" area 590 if ((index & 1) == 0) 591 return (val + skip); 592 593 // stop 594 if (-index > cutpoints.length) 595 return (val - skip); 596 597 // jump to next export area (-index - 1) 598 return Long.parseLong(cutpoints[index + 1].toString()); 599 } 600 601 // exact cut point "in" area 602 if ((index & 1) == 0) 603 return (val + skip); 604 605 // stop 606 if (index + 1 >= cutpoints.length) 607 return (val - skip); 608 609 // jump to next exported area 610 return Long.parseLong(cutpoints[index + 1].toString()); 611 } 612 613 /** 614 * 615 */ stop()616 public void stop() 617 { 618 clockThread = null; 619 } 620 } 621 622 /** 623 * class to control matrix preview 624 */ 625 private class CutMatrix implements Runnable { 626 627 private Thread clockThread = null; 628 629 private boolean stopit = false; 630 631 private long tmp = 0; 632 private long value = 0; 633 private long start_value = 0; 634 private int scale = 1; 635 636 /** 637 * 638 */ restart(long value_1)639 public void restart(long value_1) 640 { 641 start(value_1); 642 scale = 1; 643 } 644 645 /** 646 * 647 */ start(long value_1)648 public void start(long value_1) 649 { 650 breakLoop(); 651 652 if (clockThread == null) 653 { 654 clockThread = new Thread(this, "CutMatrix"); 655 clockThread.setPriority(Thread.MIN_PRIORITY); 656 657 start_value = value_1; 658 stopit = false; 659 660 clockThread.start(); 661 } 662 } 663 664 /** 665 * 666 */ breakLoop()667 public void breakLoop() 668 { 669 stopit = true; 670 } 671 672 /** 673 * 674 */ run()675 public void run() 676 { 677 Thread myThread = Thread.currentThread(); 678 679 while (clockThread == myThread) 680 { 681 try { 682 683 if (!previewList.isEmpty()) 684 { 685 int[][] matrix_index = CommonGui.getPicturePanel().getMatrixTable(); 686 long end = ((PreviewObject) previewList.get(previewList.size() - 1)).getEnd(); 687 long div = end / matrix_index.length; 688 String str; 689 690 div /= scale; 691 scale <<= 1; 692 693 CommonGui.getPicturePanel().resetMatrixPositions(end); 694 695 for (int i = 0; !stopit && i < matrix_index.length; i++) 696 { 697 tmp = start_value + (i * div); 698 699 if (tmp > end) 700 break; 701 702 value = update(tmp, i); 703 str = Common.getMpvDecoderClass().getInfo_2(); 704 str = str.substring(0, str.indexOf(",")); 705 706 CommonGui.getPicturePanel().setMatrixIndexPosition(i, value, str); 707 708 Thread.sleep(5); 709 } 710 } 711 712 stop(); 713 714 } catch (InterruptedException e) {} 715 716 } 717 } 718 719 /** 720 * 721 */ update(long val, int index)722 private long update(long val, int index) 723 { 724 return previewMatrix(val, index); 725 } 726 727 /** 728 * 729 */ stop()730 public void stop() 731 { 732 clockThread = null; 733 } 734 } 735 736 737 /** 738 * 739 */ CutPanel()740 public CutPanel() 741 { 742 chooser = CommonGui.getMainFileChooser(); 743 744 // setLayout(new BorderLayout()); 745 746 sliderPanel = buildSliderPanel(); 747 748 JPanel panel = new JPanel(); 749 panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); 750 panel.add(buildPointPanel()); 751 panel.add(buildNavigationPanel()); 752 panel.add(cutview = new CutView()); 753 754 755 //cut-preview pic handling 756 cutview.addMouseListener(new MouseAdapter() 757 { 758 public void mouseClicked(MouseEvent e) 759 { 760 if (e.getClickCount() < 2) 761 return; 762 763 try { 764 if (e.getX() < cutview.getBottom() - 20 && e.getY() < 104) 765 { 766 if (cutview.getTopIndex() != null) 767 preview(Long.parseLong(cutview.getTopIndex().toString())); 768 } 769 770 else if (e.getX() > cutview.getBottom() && e.getY() < 104) 771 { 772 if (cutview.getBottomIndex() != null) 773 preview(Long.parseLong(cutview.getBottomIndex().toString())); 774 } 775 776 } catch (Exception exc) {} 777 } 778 }); 779 780 cutview.addMouseMotionListener(new MouseMotionAdapter() { 781 public void mouseDragged(MouseEvent e) 782 { 783 if (e.getY() > 104) 784 { 785 cutview.setSlider(e.getX()); 786 787 if (collection == null) 788 return; 789 790 CommonGui.getPicturePanel().setMixedPreviewPixel(collection.getCutImage(cutview.getPreviewPosition()), cutview.getTransparencyValue()); 791 CommonGui.getPicturePanel().repaint(); 792 } 793 } 794 795 public void mouseMoved(MouseEvent e) 796 { 797 } 798 }); 799 800 801 add(panel); 802 803 setVisible(true); 804 } 805 806 /** 807 * 808 */ buildSliderPanel()809 protected JPanel buildSliderPanel() 810 { 811 slider = new JSlider(0, (int)(10240000L / divisor), 0); 812 slider.setPreferredSize(new Dimension(860, 30)); 813 slider.setMaximumSize(new Dimension(860, 30)); 814 slider.setMaximum(1); 815 slider.setMajorTickSpacing(1); 816 slider.setMinorTickSpacing(1); 817 slider.setPaintTicks(true); 818 slider.setValue(0); 819 820 slider.addMouseListener(new MouseAdapter() 821 { 822 public void mouseClicked(MouseEvent e) 823 { 824 if (slideshow || previewList.isEmpty() || Common.getSettings().getIntProperty(Keys.KEY_CutMode) != CommonParsing.CUTMODE_BYTE) 825 { 826 slideshow = false; 827 return; 828 } 829 830 if (e.getClickCount() < 2) 831 return; 832 833 slideshow = true; 834 cl.start(lastPosition); 835 } 836 }); 837 838 slider.addChangeListener(new ChangeListener() 839 { 840 public void stateChanged(ChangeEvent e) 841 { 842 if (collection == null) 843 return; 844 845 if (!action) 846 return; 847 848 if (slider.getValueIsAdjusting() && !Common.getSettings().getBooleanProperty(Keys.KEY_Preview_LiveUpdate)) 849 return; 850 851 long val = (Common.getSettings().getIntProperty(Keys.KEY_CutMode) == CommonParsing.CUTMODE_BYTE ? divisor : 1L) * slider.getValue(); 852 853 if (Common.getSettings().getIntProperty(Keys.KEY_CutMode) == CommonParsing.CUTMODE_BYTE && val != (lastPosition & ~15)) 854 preview(val); 855 856 else if (Common.getSettings().getIntProperty(Keys.KEY_CutMode) != CommonParsing.CUTMODE_BYTE) 857 { 858 Common.getMpvDecoderClass().resetProcessedPosition(); 859 Common.getMpvDecoderClass().setPidAndFileInfo(Resource.getString("CollectionPanel.Preview.offline")); 860 } 861 862 getType(); 863 } 864 }); 865 866 slider.addKeyListener(new KeyAdapter() 867 { 868 public void keyPressed(KeyEvent e) 869 { 870 if (collection == null) 871 return; 872 873 int i = 0; 874 int ic = 0; 875 int offs = 0; 876 int keyval=e.getKeyCode(); 877 878 switch(e.getKeyChar()) 879 { 880 case 'p': 881 ic=cutIndexList.getItemCount(); 882 if (ic > 0) { 883 i = ic - 1; 884 if (lastPosition>Long.parseLong(cutIndexList.getItemAt(0).toString())) 885 while (lastPosition <= Long.parseLong(cutIndexList.getItemAt(i).toString())) 886 i--; 887 cutIndexList.setSelectedIndex(i); 888 } 889 return; 890 891 case 'n': 892 ic=cutIndexList.getItemCount(); 893 if (ic > 0) { 894 if (lastPosition<Long.parseLong(cutIndexList.getItemAt(ic - 1).toString())) 895 while (lastPosition >= Long.parseLong(cutIndexList.getItemAt(i).toString())) 896 i++; 897 cutIndexList.setSelectedIndex(i); 898 } 899 return; 900 901 case 'a': 902 cutAdd.doClick(); 903 return; 904 905 case 'd': 906 cutDelete.doClick(); 907 return; 908 } 909 910 if (e.isShiftDown()) 911 offs = 62500; 912 913 else if (e.isControlDown()) 914 offs = 312500; 915 916 else if (e.isAltDown()) 917 offs = 3125000; 918 919 else 920 return; 921 922 switch (keyval) 923 { 924 case KeyEvent.VK_RIGHT: 925 slider.setValue(slider.getValue() + offs); 926 break; 927 928 case KeyEvent.VK_LEFT: 929 slider.setValue(slider.getValue() - offs); 930 } 931 } 932 }); 933 934 935 JPanel panel = new JPanel(new BorderLayout()); 936 937 if (!Common.getSettings().getBooleanProperty(Keys.KEY_Preview_SliderWidth)) 938 { 939 panel.add(Box.createRigidArea(new Dimension(145, 20)), BorderLayout.WEST); 940 panel.add(slider, BorderLayout.CENTER); 941 panel.add(Box.createRigidArea(new Dimension(194, 20)), BorderLayout.EAST); 942 } 943 else 944 panel.add(slider, BorderLayout.CENTER); 945 946 947 return panel; 948 } 949 950 /** 951 * 952 */ setComponentColor(JComponent comp, Color c)953 protected void setComponentColor(JComponent comp, Color c) 954 { 955 comp.setBackground(c); 956 comp.setForeground(c); 957 } 958 959 /** 960 * 961 */ buildNavigationPanel()962 protected JPanel buildNavigationPanel() 963 { 964 JPanel panel_1 = new JPanel(); 965 panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.X_AXIS)); 966 967 JPanel panel_2 = new JPanel(); 968 panel_2.setLayout(new BoxLayout(panel_2, BoxLayout.X_AXIS)); 969 970 jump = new JButton[navigation.length]; 971 972 for (int i = 0; i < jump.length; i++) 973 { 974 jump[i] = new JButton(CommonGui.loadIcon(navigation[i])); 975 jump[i].setPreferredSize(new Dimension(34, 24)); 976 jump[i].setMaximumSize(new Dimension(34, 24)); 977 jump[i].setActionCommand(navigation[i]); 978 jump[i].addActionListener(jumpAction); 979 980 if (i < 6) 981 panel_1.add(jump[i]); 982 else 983 panel_2.add(jump[i]); 984 } 985 986 positionField = new JTextField(""); 987 positionField.setPreferredSize(new Dimension(136, 24)); 988 positionField.setMaximumSize(new Dimension(136, 24)); 989 positionField.setToolTipText(Resource.getString("CollectionPanel.CutPanel.Tip4")); 990 positionField.setActionCommand("cutnumber"); 991 positionField.addActionListener(cutAction); 992 panel_2.add(positionField); 993 994 995 cutmode_combobox = new JComboBox(Keys.ITEMS_CutMode); 996 cutmode_combobox.setPreferredSize(new Dimension(204, 24)); 997 cutmode_combobox.setMaximumSize(new Dimension(204, 24)); 998 cutmode_combobox.setActionCommand(Keys.KEY_CutMode[0]); 999 cutmode_combobox.setSelectedIndex(Common.getSettings().getIntProperty(Keys.KEY_CutMode)); 1000 cutmode_combobox.addActionListener(_ComboBoxIndexListener); 1001 1002 1003 JPanel panel_3 = new JPanel(); 1004 panel_3.setLayout(new BoxLayout(panel_3, BoxLayout.X_AXIS)); 1005 1006 estimatedSizeField = new JTextField(""); 1007 //estimatedSizeField.setToolTipText(Resource.getString("CollectionPanel.NumberOfPoints.Tip")); 1008 estimatedSizeField.setBackground(new java.awt.Color(230, 230, 230)); 1009 estimatedSizeField.setEditable(false); 1010 estimatedSizeField.setPreferredSize(new Dimension(150, 24)); 1011 estimatedSizeField.setMaximumSize(new Dimension(150, 24)); 1012 estimatedSizeField.setMinimumSize(new Dimension(150, 24)); 1013 panel_3.add(estimatedSizeField); 1014 1015 JButton play = new JButton(CommonGui.loadIcon("slidestart.gif")); 1016 play.setToolTipText("start SlideShow"); 1017 play.setPreferredSize(new Dimension(27, 24)); 1018 play.setMaximumSize(new Dimension(27, 24)); 1019 play.addActionListener(new ActionListener() { 1020 public void actionPerformed(ActionEvent e) 1021 { 1022 if (slideshow || previewList.isEmpty() || Common.getSettings().getIntProperty(Keys.KEY_CutMode) != CommonParsing.CUTMODE_BYTE) 1023 { 1024 slideshow = false; 1025 return; 1026 } 1027 1028 slideshow = true; 1029 cl.start(lastPosition); 1030 } 1031 }); 1032 1033 panel_3.add(play); 1034 1035 JButton stop = new JButton(CommonGui.loadIcon("slidestop.gif")); 1036 stop.setToolTipText("stop SlideShow"); 1037 stop.setPreferredSize(new Dimension(27, 24)); 1038 stop.setMaximumSize(new Dimension(27, 24)); 1039 stop.addActionListener(new ActionListener() { 1040 public void actionPerformed(ActionEvent e) 1041 { 1042 slideshow = false; 1043 } 1044 }); 1045 1046 panel_3.add(stop); 1047 1048 /** 1049 * 1050 */ 1051 JPanel panel = new JPanel(); 1052 panel.setLayout(new ColumnLayout()); 1053 panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Navigation")); 1054 panel.add(panel_1); 1055 panel.add(panel_2); 1056 panel.add(panel_3); 1057 panel.add(cutmode_combobox); 1058 1059 1060 return panel; 1061 } 1062 1063 /** 1064 * 1065 */ buildPointPanel()1066 protected JPanel buildPointPanel() 1067 { 1068 JPanel panel = new JPanel(); 1069 panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); 1070 1071 panel.add(buildChapterPointPanel()); 1072 panel.add(buildCutPointPanel()); 1073 1074 return panel; 1075 } 1076 1077 /** 1078 * 1079 */ buildCutPointPanel()1080 protected JPanel buildCutPointPanel() 1081 { 1082 /** 1083 * row 1 1084 */ 1085 cutIndexField = new JTextField(); 1086 cutIndexField.setBackground(new Color(230, 230, 230)); 1087 cutIndexField.setPreferredSize(new Dimension(48, 24)); 1088 cutIndexField.setMaximumSize(new Dimension(48, 24)); 1089 cutIndexField.setEditable(false); 1090 cutIndexField.setHorizontalAlignment(JTextField.CENTER); 1091 1092 JButton cutMoveLeft = new JButton(CommonGui.loadIcon("leftcut.gif")); 1093 cutMoveLeft.setActionCommand("movecutleft"); 1094 cutMoveLeft.setPreferredSize(new Dimension(36, 24)); 1095 cutMoveLeft.setMaximumSize(new Dimension(36, 24)); 1096 cutMoveLeft.addActionListener(cutAction); 1097 1098 JButton cutMoveRight = new JButton(CommonGui.loadIcon("rightcut.gif")); 1099 cutMoveRight.setActionCommand("movecutright"); 1100 cutMoveRight.setPreferredSize(new Dimension(36, 24)); 1101 cutMoveRight.setMaximumSize(new Dimension(36, 24)); 1102 cutMoveRight.addActionListener(cutAction); 1103 1104 JPanel panel_1 = new JPanel(); 1105 panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.X_AXIS)); 1106 panel_1.add(cutMoveLeft); 1107 panel_1.add(cutMoveRight); 1108 panel_1.add(cutIndexField); 1109 1110 1111 /** 1112 * row 2 1113 */ 1114 cutAdd = new JButton(CommonGui.loadIcon("addcut.gif")); 1115 cutAdd.setActionCommand("addpoint"); 1116 cutAdd.setPreferredSize(new Dimension(36, 24)); 1117 cutAdd.setMaximumSize(new Dimension(36, 24)); 1118 cutAdd.addActionListener(cutAction); 1119 1120 DropTarget dropTarget_4 = new DropTarget(cutAdd, dnd2); 1121 1122 cutDelete = new JButton(CommonGui.loadIcon("remcut.gif")); 1123 cutDelete.setActionCommand("delpoint"); 1124 cutDelete.setPreferredSize(new Dimension(36, 24)); 1125 cutDelete.setMaximumSize(new Dimension(36, 24)); 1126 cutDelete.addActionListener(cutAction); 1127 1128 cutCountField = new JTextField(); 1129 cutCountField.setToolTipText(Resource.getString("CollectionPanel.NumberOfPoints.Tip")); 1130 cutCountField.setBackground(new Color(230, 230, 230)); 1131 cutCountField.setPreferredSize(new Dimension(48, 24)); 1132 cutCountField.setMaximumSize(new Dimension(48, 24)); 1133 cutCountField.setHorizontalAlignment(JTextField.CENTER); 1134 cutCountField.setEditable(false); 1135 1136 JPanel panel_2 = new JPanel(); 1137 panel_2.setLayout(new BoxLayout(panel_2, BoxLayout.X_AXIS)); 1138 panel_2.add(cutAdd); 1139 panel_2.add(cutDelete); 1140 panel_2.add(cutCountField); 1141 1142 1143 /** 1144 * row 3 1145 */ 1146 cutIndexList = new JComboBox(); 1147 cutIndexList.setMaximumRowCount(5); 1148 cutIndexList.setPreferredSize(new Dimension(120, 24)); 1149 cutIndexList.setMaximumSize(new Dimension(120, 24)); 1150 cutIndexList.setActionCommand("cutbox"); 1151 cutIndexList.addActionListener(cutAction); 1152 1153 JPanel panel_3 = new JPanel(); 1154 panel_3.setLayout(new BoxLayout(panel_3, BoxLayout.X_AXIS)); 1155 panel_3.add(cutIndexList); 1156 1157 1158 /** 1159 * row 4 1160 */ 1161 JButton cut_loadlist = new JButton(CommonGui.loadIcon("open.gif")); 1162 cut_loadlist.setPreferredSize(new Dimension(32, 24)); 1163 cut_loadlist.setMaximumSize(new Dimension(32, 24)); 1164 cut_loadlist.setToolTipText(Resource.getString("CollectionPanel.loadCutpointList.Tip")); //DM18022004 081.6 int17 new 1165 cut_loadlist.setActionCommand("load_cutlist"); 1166 cut_loadlist.addActionListener(jumpAction); 1167 1168 // JButton cut_savelist = new JButton("save"); 1169 JButton cut_savelist = new JButton(CommonGui.loadIcon("save.gif")); 1170 cut_savelist.setPreferredSize(new Dimension(32, 24)); 1171 cut_savelist.setMaximumSize(new Dimension(32, 24)); 1172 cut_savelist.setActionCommand("save_cutlist"); 1173 cut_savelist.addActionListener(jumpAction); 1174 1175 //JButton cut_scan = new JButton("scan"); 1176 // JButton cut_scan = new JButton(CommonGui.loadIcon("scan2.gif")); 1177 JButton cut_scan = new JButton(CommonGui.loadIcon("matrix.gif")); 1178 cut_scan.setPreferredSize(new Dimension(50, 24)); 1179 cut_scan.setMaximumSize(new Dimension(50, 24)); 1180 cut_scan.setActionCommand("cut_scan"); 1181 cut_scan.addActionListener(jumpAction); 1182 cut_scan.setEnabled(true); 1183 // cut_scan.setEnabled(false); 1184 1185 JPanel panel_4 = new JPanel(); 1186 panel_4.setLayout(new BoxLayout(panel_4, BoxLayout.X_AXIS)); 1187 panel_4.add(cut_loadlist); 1188 panel_4.add(cut_savelist); 1189 panel_4.add(Box.createRigidArea(new Dimension(6, 1))); 1190 panel_4.add(cut_scan); 1191 1192 1193 /** 1194 * 1195 */ 1196 JPanel panel = new JPanel(); 1197 panel.setLayout(new ColumnLayout()); 1198 panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), Resource.getString("CollectionPanel.NumberOfPoints"))); 1199 panel.add(panel_2); 1200 panel.add(panel_1); 1201 panel.add(panel_3); 1202 panel.add(panel_4); 1203 1204 Color c = new Color(212, 175, 212); //new Color(200, 150, 200); 1205 // setComponentColor(cutAdd, c); 1206 // setComponentColor(cutDelete, c); 1207 setComponentColor(panel, c); 1208 setComponentColor(panel_4, c); 1209 1210 return panel; 1211 } 1212 1213 /** 1214 * 1215 */ buildChapterPointPanel()1216 protected JPanel buildChapterPointPanel() 1217 { 1218 /** 1219 * row 1 1220 */ 1221 chapterIndexField = new JTextField(); 1222 chapterIndexField.setBackground(new Color(230, 230, 230)); 1223 chapterIndexField.setPreferredSize(new Dimension(48, 24)); 1224 chapterIndexField.setMaximumSize(new Dimension(48, 24)); 1225 chapterIndexField.setEditable(false); 1226 chapterIndexField.setHorizontalAlignment(JTextField.CENTER); 1227 1228 JButton chapterMoveLeft = new JButton(CommonGui.loadIcon("leftchap.gif")); 1229 chapterMoveLeft.setActionCommand("movechapterleft"); 1230 chapterMoveLeft.setPreferredSize(new Dimension(36, 24)); 1231 chapterMoveLeft.setMaximumSize(new Dimension(36, 24)); 1232 chapterMoveLeft.addActionListener(cutAction); 1233 1234 JButton chapterMoveRight = new JButton(CommonGui.loadIcon("rightchap.gif")); 1235 chapterMoveRight.setActionCommand("movechapterright"); 1236 chapterMoveRight.setPreferredSize(new Dimension(36, 24)); 1237 chapterMoveRight.setMaximumSize(new Dimension(36, 24)); 1238 chapterMoveRight.addActionListener(cutAction); 1239 1240 JPanel panel_1 = new JPanel(); 1241 panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.X_AXIS)); 1242 panel_1.add(chapterMoveLeft); 1243 panel_1.add(chapterMoveRight); 1244 panel_1.add(chapterIndexField); 1245 1246 1247 /** 1248 * row 2 1249 */ 1250 chapterAdd = new JButton(CommonGui.loadIcon("addchap.gif")); 1251 chapterAdd.setActionCommand("addchapter"); 1252 chapterAdd.setPreferredSize(new Dimension(36, 24)); 1253 chapterAdd.setMaximumSize(new Dimension(36, 24)); 1254 chapterAdd.addActionListener(cutAction); 1255 1256 chapterDelete = new JButton(CommonGui.loadIcon("remchap.gif")); 1257 chapterDelete.setActionCommand("delchapter"); 1258 chapterDelete.setPreferredSize(new Dimension(36, 24)); 1259 chapterDelete.setMaximumSize(new Dimension(36, 24)); 1260 chapterDelete.addActionListener(cutAction); 1261 1262 chapterCountField = new JTextField(); 1263 chapterCountField.setToolTipText(Resource.getString("CollectionPanel.NumberOfChapters.Tip")); 1264 chapterCountField.setBackground(new Color(230, 230, 230)); 1265 chapterCountField.setPreferredSize(new Dimension(48, 24)); 1266 chapterCountField.setMaximumSize(new Dimension(48, 24)); 1267 chapterCountField.setEditable(false); 1268 chapterCountField.setHorizontalAlignment(JTextField.CENTER); 1269 chapterCountField.addActionListener(cutAction); 1270 1271 JPanel panel_2 = new JPanel(); 1272 panel_2.setLayout(new BoxLayout(panel_2, BoxLayout.X_AXIS)); 1273 panel_2.add(chapterAdd); 1274 panel_2.add(chapterDelete); 1275 panel_2.add(chapterCountField); 1276 1277 1278 /** 1279 * row 3 1280 */ 1281 chapterIndexList = new JComboBox(); 1282 chapterIndexList.setMaximumRowCount(5); 1283 chapterIndexList.setPreferredSize(new Dimension(120, 24)); 1284 chapterIndexList.setMaximumSize(new Dimension(120, 24)); 1285 chapterIndexList.setActionCommand("chapterbox"); 1286 chapterIndexList.addActionListener(cutAction); 1287 1288 JPanel panel_3 = new JPanel(); 1289 panel_3.setLayout(new BoxLayout(panel_3, BoxLayout.X_AXIS)); 1290 panel_3.add(chapterIndexList); 1291 1292 /** 1293 * row 4 1294 */ 1295 JButton chapter_loadlist = new JButton(CommonGui.loadIcon("open.gif")); 1296 chapter_loadlist.setPreferredSize(new Dimension(32, 24)); 1297 chapter_loadlist.setMaximumSize(new Dimension(32, 24)); 1298 chapter_loadlist.setToolTipText(Resource.getString("CollectionPanel.loadCutpointList.Tip")); //DM18022004 081.6 int17 new 1299 chapter_loadlist.setActionCommand("load_chapterlist"); 1300 chapter_loadlist.addActionListener(jumpAction); 1301 1302 // JButton chapter_savelist = new JButton("save"); 1303 JButton chapter_savelist = new JButton(CommonGui.loadIcon("save.gif")); 1304 chapter_savelist.setPreferredSize(new Dimension(32, 24)); 1305 chapter_savelist.setMaximumSize(new Dimension(32, 24)); 1306 chapter_savelist.setActionCommand("save_chapterlist"); 1307 chapter_savelist.addActionListener(jumpAction); 1308 1309 // JButton chapter_scan = new JButton("scan"); 1310 JButton chapter_scan = new JButton(CommonGui.loadIcon("scan2.gif")); 1311 chapter_scan.setPreferredSize(new Dimension(50, 24)); 1312 chapter_scan.setMaximumSize(new Dimension(50, 24)); 1313 chapter_scan.setActionCommand("chapter_scan"); 1314 chapter_scan.addActionListener(jumpAction); 1315 chapter_scan.setEnabled(false); 1316 1317 JPanel panel_4 = new JPanel(); 1318 panel_4.setLayout(new BoxLayout(panel_4, BoxLayout.X_AXIS)); 1319 panel_4.add(chapter_loadlist); 1320 panel_4.add(chapter_savelist); 1321 panel_4.add(Box.createRigidArea(new Dimension(6, 1))); 1322 panel_4.add(chapter_scan); 1323 1324 /** 1325 * 1326 */ 1327 JPanel panel = new JPanel(); 1328 panel.setLayout(new ColumnLayout()); 1329 panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), Resource.getString("CollectionPanel.NumberOfChapters"))); 1330 panel.add(panel_2); 1331 panel.add(panel_1); 1332 panel.add(panel_3); 1333 panel.add(panel_4); 1334 1335 Color c = new Color(210, 217, 255); //new Color(195, 205, 255); 1336 // setComponentColor(chapterAdd, c); 1337 // setComponentColor(chapterDelete, c); 1338 setComponentColor(panel, c); 1339 setComponentColor(panel_4, c); 1340 1341 return panel; 1342 } 1343 1344 1345 /** 1346 * 1347 */ getSliderPanel()1348 public JPanel getSliderPanel() 1349 { 1350 return sliderPanel; 1351 } 1352 1353 /** 1354 * 1355 */ saveCutList()1356 private void saveCutList() 1357 { 1358 Object[] object = collection.getCutpoints(); 1359 1360 if (object.length == 0) 1361 return; 1362 1363 String newfile = file + "(" + active_collection + ").Xcl"; 1364 1365 chooser.setSelectedFile(new File(newfile)); 1366 chooser.rescanCurrentDirectory(); 1367 1368 int retval = chooser.showSaveDialog(this); 1369 1370 if (retval == JFileChooser.APPROVE_OPTION) 1371 { 1372 File theFile = chooser.getSelectedFile(); 1373 1374 if (theFile != null && !theFile.isDirectory()) 1375 { 1376 newfile = theFile.getAbsolutePath(); 1377 1378 if (theFile.exists() && !CommonGui.getUserConfirmation(Resource.getString("msg.overwrite", newfile))) 1379 return; 1380 } 1381 else 1382 return; 1383 } 1384 else 1385 return; 1386 1387 try { 1388 1389 BufferedWriter listwriter = new BufferedWriter(new FileWriter(newfile)); 1390 1391 listwriter.write(Keys.KEY_CutMode[0] + "=" + Common.getSettings().getProperty(Keys.KEY_CutMode)); 1392 listwriter.newLine(); 1393 1394 for (int i = 0; i < object.length; i++) 1395 { 1396 listwriter.write(object[i].toString()); 1397 listwriter.newLine(); 1398 } 1399 1400 listwriter.close(); 1401 } 1402 1403 catch (IOException e) { 1404 1405 Common.setMessage(Resource.getString("CollectionPanel.FileAccessError") + " " + file); 1406 } 1407 } 1408 1409 /** 1410 * 1411 */ loadCutList()1412 private void loadCutList() 1413 { 1414 loadCutList(""); 1415 } 1416 1417 /** 1418 * 1419 */ loadCutList(String newfile)1420 private void loadCutList(String newfile) 1421 { 1422 List pointlist = new ArrayList(); 1423 1424 String point = ""; 1425 1426 if (!(new File(newfile).exists())) 1427 { 1428 chooser.rescanCurrentDirectory(); 1429 int retval = chooser.showOpenDialog(this); 1430 1431 if(retval == JFileChooser.APPROVE_OPTION) 1432 { 1433 File theFile = chooser.getSelectedFile(); 1434 1435 if(theFile != null && !theFile.isDirectory()) 1436 newfile = theFile.getAbsolutePath(); 1437 } 1438 else 1439 return; 1440 } 1441 1442 try { 1443 1444 BufferedReader listreader = new BufferedReader(new FileReader(newfile)); 1445 1446 while (true) 1447 { 1448 point = listreader.readLine(); 1449 1450 if (point == null) 1451 break; 1452 1453 if (point.trim().equals("")) 1454 continue; 1455 1456 if (point.startsWith(Keys.KEY_CutMode[0])) 1457 { 1458 cutmode_combobox.setSelectedIndex(Integer.parseInt(point.substring(point.indexOf("=") + 1).trim())); 1459 continue; 1460 } 1461 1462 if (point.startsWith("(")) 1463 continue; 1464 1465 pointlist.add(point); 1466 } 1467 1468 listreader.close(); 1469 1470 } catch (IOException e5) { 1471 1472 Common.setMessage(Resource.getString("CollectionPanel.loadCutpointList.Error") + " " + file); 1473 } 1474 1475 Object[] obj = pointlist.toArray(); 1476 1477 if (obj.length > 0) 1478 { 1479 long[] cutPoints = new long[obj.length]; 1480 1481 for (int i = 0; i < cutPoints.length; i++) 1482 cutPoints[i] = CommonParsing.parseCutValue(obj[i].toString(), false); 1483 1484 Arrays.sort(cutPoints); 1485 1486 for (int i = 0; i < cutPoints.length; i++) 1487 collection.addCutpoint(CommonParsing.parseCutValue(cutPoints[i])); 1488 1489 action = false; 1490 1491 reloadCutpoints(); 1492 cutIndexList.setSelectedIndex(cutIndexList.getItemCount() - 1); 1493 } 1494 1495 getExpectedSize(); 1496 getType(); 1497 1498 action = true; 1499 } 1500 1501 /** 1502 * 1503 */ saveChapterList()1504 private void saveChapterList() 1505 { 1506 Object[] object = collection.getChapterpoints(); 1507 1508 if (object.length == 0) 1509 return; 1510 1511 String newfile = file + "[" + active_collection + "].Xcp"; 1512 1513 chooser.setSelectedFile(new File(newfile)); 1514 chooser.rescanCurrentDirectory(); 1515 1516 int retval = chooser.showSaveDialog(this); 1517 1518 if(retval == JFileChooser.APPROVE_OPTION) 1519 { 1520 File theFile = chooser.getSelectedFile(); 1521 1522 if (theFile != null && !theFile.isDirectory()) 1523 { 1524 newfile = theFile.getAbsolutePath(); 1525 1526 if (theFile.exists() && !CommonGui.getUserConfirmation(Resource.getString("msg.overwrite", newfile))) 1527 return; 1528 } 1529 else 1530 return; 1531 } 1532 else 1533 return; 1534 1535 if (!CommonGui.getUserConfirmation(Resource.getString("msg.overwrite", newfile))) 1536 return; 1537 1538 try { 1539 1540 BufferedWriter listwriter = new BufferedWriter(new FileWriter(newfile)); 1541 1542 listwriter.write(Keys.KEY_CutMode[0] + "=" + Common.getSettings().getProperty(Keys.KEY_CutMode)); 1543 listwriter.newLine(); 1544 1545 for (int i = 0; i < object.length; i++) 1546 { 1547 listwriter.write(object[i].toString()); 1548 listwriter.newLine(); 1549 } 1550 1551 listwriter.close(); 1552 } 1553 1554 catch (IOException e) { 1555 1556 Common.setMessage(Resource.getString("CollectionPanel.FileAccessError") + " " + file); 1557 } 1558 } 1559 1560 /** 1561 * 1562 */ loadChapterList()1563 private void loadChapterList() 1564 { 1565 loadChapterList(""); 1566 } 1567 1568 /** 1569 * 1570 */ loadChapterList(String newfile)1571 private void loadChapterList(String newfile) 1572 { 1573 List pointlist = new ArrayList(); 1574 1575 String point = ""; 1576 1577 if (!(new File(newfile).exists())) 1578 { 1579 chooser.rescanCurrentDirectory(); 1580 int retval = chooser.showOpenDialog(this); 1581 1582 if(retval == JFileChooser.APPROVE_OPTION) 1583 { 1584 File theFile = chooser.getSelectedFile(); 1585 1586 if(theFile != null && !theFile.isDirectory()) 1587 newfile = theFile.getAbsolutePath(); 1588 } 1589 else 1590 return; 1591 } 1592 1593 try { 1594 1595 BufferedReader listreader = new BufferedReader(new FileReader(newfile)); 1596 1597 while (true) 1598 { 1599 point = listreader.readLine(); 1600 1601 if (point == null) 1602 break; 1603 1604 if (point.trim().equals("")) 1605 continue; 1606 1607 if (point.startsWith(Keys.KEY_CutMode[0])) 1608 { 1609 cutmode_combobox.setSelectedIndex(Integer.parseInt(point.substring(point.indexOf("=") + 1).trim())); 1610 continue; 1611 } 1612 1613 if (point.startsWith("(")) 1614 continue; 1615 1616 pointlist.add(point); 1617 } 1618 1619 listreader.close(); 1620 1621 } catch (IOException e5) { 1622 1623 Common.setMessage(Resource.getString("CollectionPanel.loadCutpointList.Error") + " " + file); 1624 } 1625 1626 Object[] obj = pointlist.toArray(); 1627 1628 if (obj.length > 0) 1629 { 1630 long[] chpPoints = new long[obj.length]; 1631 1632 for (int i = 0; i < chpPoints.length; i++) 1633 chpPoints[i] = CommonParsing.parseCutValue(obj[i].toString(), false); 1634 1635 Arrays.sort(chpPoints); 1636 1637 for (int i = 0; i < chpPoints.length; i++) 1638 collection.addChapterpoint(CommonParsing.parseCutValue(chpPoints[i])); 1639 1640 action = false; 1641 1642 reloadChapterpoints(); 1643 chapterIndexList.setSelectedIndex(chapterIndexList.getItemCount() - 1); 1644 } 1645 1646 getExpectedSize(); 1647 getType(); 1648 1649 action = true; 1650 } 1651 1652 /** 1653 * 1654 */ getExpectedSize()1655 private void getExpectedSize() 1656 { 1657 if (previewList.isEmpty()) 1658 { 1659 estimatedSizeField.setText(" "); 1660 return; 1661 } 1662 1663 Object[] object = collection.getCutpoints(); 1664 1665 long newSize[] = new long[object.length]; 1666 long start = 0; 1667 long diff = 0; 1668 long end = 0; 1669 1670 if (Common.getSettings().getIntProperty(Keys.KEY_CutMode) == CommonParsing.CUTMODE_BYTE) 1671 { 1672 for (int i = 0; i < newSize.length; i++) 1673 newSize[i] = Long.parseLong(object[i].toString()); 1674 1675 if (newSize.length == 0 || (newSize.length & 1) == 1) 1676 end = ((PreviewObject) previewList.get(previewList.size() - 1)).getEnd(); 1677 1678 else 1679 end = newSize[newSize.length - 1]; 1680 1681 for (int i = 0; i < newSize.length; i += 2) 1682 { 1683 diff += newSize[i] - start; 1684 start = i + 1 < newSize.length ? newSize[i + 1] : start; 1685 } 1686 } 1687 1688 String length = Common.getSettings().getIntProperty(Keys.KEY_CutMode) == CommonParsing.CUTMODE_BYTE ? (Resource.getString("CollectionPanel.expectedSize") + " " + ((end - diff) / 1048576L) + "MB") : ""; 1689 1690 estimatedSizeField.setText(length); 1691 chapterCountField.setText(String.valueOf(chapterIndexList.getItemCount())); 1692 cutCountField.setText(String.valueOf(cutIndexList.getItemCount())); 1693 } 1694 1695 /** 1696 * 1697 */ 1698 private void getType() 1699 { 1700 /** 1701 * cuts 1702 */ 1703 Object[] obj = collection != null ? collection.getCutpoints() : new Object[0]; 1704 int index; 1705 1706 if (obj.length > 0) 1707 { 1708 index = getCutIndex(obj, String.valueOf(lastPosition)); 1709 1710 showCutInfo((index & 1) == 0, obj, previewList); 1711 //Common.getGuiInterface().showCutIcon((index & 1) == 0, obj, previewList); 1712 } 1713 1714 else 1715 showCutInfo(true, null, previewList); 1716 //Common.getGuiInterface().showCutIcon(true, null, previewList); 1717 1718 /** 1719 * chapters 1720 */ 1721 obj = collection != null ? collection.getChapterpoints() : new Object[0]; 1722 1723 if (obj.length > 0) 1724 Common.getGuiInterface().showChapterIcon(obj, previewList); 1725 1726 else 1727 Common.getGuiInterface().showChapterIcon(null, previewList); 1728 1729 } 1730 1731 /** 1732 * 1733 */ getCutIndex(Object[] obj, String value)1734 private int getCutIndex(Object[] obj, String value) 1735 { 1736 class MyComparator implements Comparator 1737 { 1738 public int compare(Object o1, Object o2) 1739 { 1740 if (Common.getSettings().getIntProperty(Keys.KEY_CutMode) == CommonParsing.CUTMODE_TIME) 1741 return Long.toString(CommonParsing.parseCutValue(o1.toString(), false)).compareTo(Long.toString(CommonParsing.parseCutValue(o2.toString(), false))); 1742 1743 else 1744 return Long.valueOf(o1.toString()).compareTo(Long.valueOf(o2.toString())); 1745 } 1746 } 1747 1748 /** 1749 * handle wrong numbers 1750 */ 1751 if (Common.getSettings().getIntProperty(Keys.KEY_CutMode) == CommonParsing.CUTMODE_BYTE) 1752 if (CommonParsing.parseCutValue(value, false) < 0) 1753 return 0; 1754 1755 return Arrays.binarySearch(obj, value, new MyComparator()); // is already sorted 1756 } 1757 1758 /** 1759 * 1760 */ preview(long position)1761 public long preview(long position) 1762 { 1763 boolean backward = false; 1764 1765 try { 1766 1767 CommonGui.getPicturePanel().disableMatrix(); 1768 1769 if (Common.getSettings().getIntProperty(Keys.KEY_CutMode) != CommonParsing.CUTMODE_BYTE || previewList.isEmpty()) 1770 { 1771 Common.getMpvDecoderClass().resetProcessedPosition(); 1772 Common.getMpvDecoderClass().setPidAndFileInfo(Resource.getString("CollectionPanel.Preview.offline")); 1773 1774 return lastPosition; 1775 } 1776 1777 action = false; 1778 1779 int loadSize = getLoadSize(); // bytes for searching the next I-frame ;changed for X0.81 1780 1781 if (position / divisor >= (long)slider.getMaximum()) // last 1782 { 1783 position = position > loadSize ? position - loadSize : 0; 1784 backward = true; 1785 } 1786 1787 else if (position > 0 && position < lastPosition && ((lastPosition / divisor) - (position / divisor)) < 3L ) 1788 { 1789 if (lastPosition - position < 50) 1790 position = lastPosition; 1791 1792 position = position > loadSize ? position - loadSize : 0; 1793 backward = true; 1794 } 1795 1796 position = Preview.load(position, ((backward && position == 0) ? (int)lastPosition : loadSize), previewList, backward, Common.getSettings().getBooleanProperty(Keys.KEY_Preview_AllGops), Common.getSettings().getBooleanProperty(Keys.KEY_Preview_fastDecode), Common.getSettings().getIntProperty(Keys.KEY_Preview_YGain), collection.getPIDs(), active_collection); 1797 1798 String str = Preview.getProcessedFile(); 1799 1800 if (str.length() > 32) 1801 { 1802 int i = str.indexOf('-'); 1803 1804 String _str = str.substring(0, i + 2); 1805 str = _str + "..." + str.substring(i + 2 + (str.length() - 34 - i), str.length()); 1806 } 1807 1808 lastPosition = position; 1809 1810 slider.setValue((int)(lastPosition / divisor)); 1811 setPositionField(lastPosition); 1812 slider.requestFocus(); 1813 1814 } catch (Exception e6) { 1815 1816 Common.setExceptionMessage(e6); 1817 } 1818 1819 getExpectedSize(); 1820 1821 updateCutView(String.valueOf(lastPosition)); 1822 1823 action = true; 1824 1825 return lastPosition; 1826 } 1827 1828 /** 1829 * 1830 */ startMatrix(long from_position)1831 public void startMatrix(long from_position) 1832 { 1833 cm.start(from_position); 1834 } 1835 1836 /** 1837 * 1838 */ restartMatrix()1839 public void restartMatrix() 1840 { 1841 cm.restart(0); 1842 } 1843 1844 /** 1845 * 1846 */ stopMatrix()1847 public void stopMatrix() 1848 { 1849 cm.breakLoop(); 1850 } 1851 1852 /** 1853 * 1854 */ previewMatrix(long position, int matrix_index)1855 private long previewMatrix(long position, int matrix_index) 1856 { 1857 if (Common.getSettings().getIntProperty(Keys.KEY_CutMode) != CommonParsing.CUTMODE_BYTE || previewList.isEmpty()) 1858 return position; 1859 1860 action = false; 1861 1862 position = Preview.silentload(position, getLoadSize(), previewList, false, Common.getSettings().getBooleanProperty(Keys.KEY_Preview_AllGops), Common.getSettings().getBooleanProperty(Keys.KEY_Preview_fastDecode), Common.getSettings().getIntProperty(Keys.KEY_Preview_YGain), collection.getPIDs(), active_collection); 1863 1864 CommonGui.getPicturePanel().setMatrixPreviewPixel(matrix_index); 1865 CommonGui.getPicturePanel().repaint(); 1866 1867 action = true; 1868 1869 return position; 1870 } 1871 1872 /** 1873 * updates last and next cutpoint view 1874 */ updateCutView(String value)1875 private void updateCutView(String value) 1876 { 1877 if (Common.getSettings().getIntProperty(Keys.KEY_CutMode) != CommonParsing.CUTMODE_BYTE) 1878 { 1879 cutview.clearViews(); 1880 return; 1881 } 1882 1883 Object[] listData = collection == null ? null : collection.getCutpoints(); 1884 1885 if (listData == null || listData.length == 0) 1886 { 1887 cutview.clearViews(); 1888 return; 1889 } 1890 1891 int index = getCutIndex(listData, value); 1892 1893 if (index < 0) 1894 { 1895 int i = -index - 1; 1896 1897 cutview.setMatchingPoint(false, listData, index); 1898 cutview.setImage(i < listData.length ? collection.getCutImage(listData[i]) : null, listData, i, cutview.getBottom()); 1899 cutview.setImage(i - 1 >= 0 && i - 1 < listData.length ? collection.getCutImage(listData[i - 1]) : null, listData, i - 1, cutview.getTop()); 1900 } 1901 1902 else 1903 { 1904 if (collection.getCutImage(listData[index]) == null) 1905 collection.setCutImage(value, Common.getMpvDecoderClass().getCutImage()); 1906 1907 cutview.setMatchingPoint(true, listData, index); 1908 cutview.setImage(index + 1 < listData.length ? collection.getCutImage(listData[index + 1]) : null, listData, index + 1, cutview.getBottom()); 1909 cutview.setImage(index - 1 >= 0 ? collection.getCutImage(listData[index - 1]) : null, listData, index - 1, cutview.getTop()); 1910 } 1911 } 1912 1913 /** 1914 * 1915 */ getLoadSize()1916 private int getLoadSize() 1917 { 1918 try { 1919 int val = Common.getPreviewBufferValue(); 1920 1921 return val; 1922 } 1923 catch (Exception e) { 1924 Common.setMessage("!> wrong preview_buffer field entry", true); 1925 } 1926 1927 return loadSizeForward; 1928 } 1929 1930 /** 1931 * 1932 */ checkActiveCollection()1933 private boolean checkActiveCollection() 1934 { 1935 if (active_collection >= 0) 1936 return true; 1937 1938 collection = null; 1939 1940 action = false; 1941 1942 previewList.clear(); 1943 reloadCutpoints(); 1944 reloadChapterpoints(); 1945 showCutInfo(true, null, previewList); 1946 //Common.getGuiInterface().showCutIcon(true, null, previewList); 1947 Common.getGuiInterface().showChapterIcon(null, previewList); 1948 1949 slider.setMaximum(1); 1950 1951 Common.setOSDMessage(Resource.getString("CollectionPanel.Preview.offline")); 1952 1953 action = true; 1954 1955 return false; 1956 } 1957 1958 /** 1959 * 1960 */ entry(int _active_collection)1961 public void entry(int _active_collection) 1962 { 1963 if (active_collection != _active_collection) 1964 cutview.clearViews(); 1965 1966 active_collection = _active_collection; 1967 1968 Common.getMpvDecoderClass().clearPreviewPixel(); 1969 Common.getMpvDecoderClass().resetProcessedPosition(); 1970 Common.getMpvDecoderClass().setPidAndFileInfo(Resource.getString("CollectionPanel.Preview.offline")); 1971 1972 /** 1973 * 1974 */ 1975 if (!checkActiveCollection()) 1976 return; 1977 1978 CommonGui.getPicturePanel().showCollectionNumber(active_collection); 1979 1980 cutmode_combobox.setSelectedIndex(Common.getSettings().getIntProperty(Keys.KEY_CutMode)); 1981 1982 collection = Common.getCollection(active_collection); 1983 1984 List input_files = collection.getInputFilesAsList(); 1985 previewList.clear(); 1986 1987 file = !input_files.isEmpty() ? input_files.get(0).toString() : ""; 1988 1989 /** 1990 * determine primary file segments, scan only if changed (date modified) or not scanned 1991 */ 1992 long start = 0; 1993 long end = 0; 1994 long maximum; 1995 int size = input_files.size(); 1996 int primaryFilesCount = 1; 1997 1998 if (Common.getSettings().getBooleanProperty(Keys.KEY_Preview_disable)) 1999 size = 0; 2000 2001 filesearch: 2002 for (int a = 0, b = -1, type = -1; a < size; a++) 2003 { 2004 XInputFile xInputFile = ((XInputFile) input_files.get(a)).getNewInstance(); 2005 2006 if (xInputFile == null) 2007 continue; 2008 2009 if (xInputFile.getStreamInfo() == null) 2010 Common.getScanClass().getStreamInfo(xInputFile); //note: is a new instance 2011 2012 type = xInputFile.getStreamInfo().getStreamType(); 2013 2014 if (b != -1 && b != type) 2015 { 2016 primaryFilesCount = a; 2017 break filesearch; 2018 } 2019 2020 switch (type) 2021 { 2022 case CommonParsing.PES_AV_TYPE: 2023 case CommonParsing.MPEG1PS_TYPE: 2024 case CommonParsing.MPEG2PS_TYPE: 2025 case CommonParsing.PVA_TYPE: 2026 case CommonParsing.TS_TYPE: 2027 case CommonParsing.ES_MPV_TYPE: 2028 b = type; 2029 2030 start = end; 2031 end += xInputFile.length(); 2032 previewList.add(new PreviewObject(start, end, type, xInputFile)); 2033 break; 2034 2035 default: 2036 break filesearch; 2037 } 2038 } 2039 2040 action = false; 2041 2042 // reduce slider maximum, fit int requirements 2043 for (divisor = 16L; ; divisor += 16L) 2044 { 2045 maximum = end / divisor; 2046 2047 if (maximum < 0x7FFFFFFFL) 2048 break; 2049 } 2050 2051 if (maximum > divisor) 2052 { 2053 slider.setMaximum((int) maximum); 2054 slider.setMajorTickSpacing((int) (maximum / 10)); 2055 slider.setMinorTickSpacing((int) (maximum / 100)); 2056 slider.setPaintTicks(true); 2057 } 2058 2059 else 2060 { 2061 slider.setMaximum(1); 2062 slider.setMajorTickSpacing(1); 2063 slider.setMinorTickSpacing(1); 2064 slider.setPaintTicks(true); 2065 } 2066 2067 action = true; 2068 2069 Common.setLastPreviewBitrate(CommonParsing.MAX_SD_BITRATE_VALUE); 2070 2071 if (Common.getSettings().getIntProperty(Keys.KEY_CutMode) == CommonParsing.CUTMODE_BYTE && !previewList.isEmpty()) 2072 preview(0); 2073 2074 else 2075 { 2076 Common.getMpvDecoderClass().clearPreviewPixel(); 2077 Common.setOSDMessage(Resource.getString("CollectionPanel.Preview.offline")); 2078 } 2079 2080 action = false; 2081 2082 reloadCutpoints(); 2083 reloadChapterpoints(); 2084 cutIndexList.setSelectedIndex(cutIndexList.getItemCount() - 1); 2085 2086 getExpectedSize(); 2087 getType(); 2088 2089 action = true; 2090 } 2091 2092 /** 2093 * 2094 */ addChapterpoint(String value)2095 private boolean addChapterpoint(String value) 2096 { 2097 int index = 0; 2098 2099 index = getCutIndex(collection.getChapterpoints(), value); 2100 2101 if (index >= 0) 2102 return false; 2103 2104 collection.addChapterpoint(-index - 1, value); 2105 2106 reloadChapterpoints(); 2107 2108 chapterIndexList.setSelectedItem(value); 2109 2110 return true; 2111 } 2112 2113 /** 2114 * 2115 */ removeChapterpoint(int index)2116 private Object removeChapterpoint(int index) 2117 { 2118 Object obj = collection.removeChapterpoint(index); 2119 2120 reloadChapterpoints(); 2121 2122 Object[] objects = collection.getChapterpoints(); 2123 2124 if (objects.length > 0) 2125 { 2126 int _index = -getCutIndex(collection.getChapterpoints(), obj.toString()) - 1; 2127 2128 if (_index >= objects.length) 2129 _index = objects.length - 1; 2130 2131 chapterIndexList.setSelectedIndex(_index); 2132 } 2133 2134 return obj; 2135 } 2136 2137 /** 2138 * 2139 */ reloadChapterpoints()2140 private void reloadChapterpoints() 2141 { 2142 chapterIndexList.removeAllItems(); 2143 2144 Object[] object = collection != null ? collection.getChapterpoints() : new Object[0]; 2145 2146 for (int i = 0; i < object.length; i++) 2147 chapterIndexList.addItem(object[i]); 2148 } 2149 2150 /** 2151 * 2152 */ addCutpoint(String value)2153 private boolean addCutpoint(String value) 2154 { 2155 int index = 0; 2156 2157 index = getCutIndex(collection.getCutpoints(), value); 2158 2159 if (index >= 0) 2160 return false; 2161 2162 collection.addCutpoint(-index - 1, value); 2163 2164 reloadCutpoints(); 2165 2166 cutIndexList.setSelectedItem(value); 2167 2168 return true; 2169 } 2170 2171 /** 2172 * 2173 */ removeCutpoint(int index)2174 private Object removeCutpoint(int index) 2175 { 2176 Object obj = collection.removeCutpoint(index); 2177 2178 reloadCutpoints(); 2179 2180 Object[] objects = collection.getCutpoints(); 2181 2182 if (objects.length > 0) 2183 { 2184 int _index = -getCutIndex(collection.getCutpoints(), obj.toString()) - 1; 2185 2186 if (_index >= objects.length) 2187 _index = objects.length - 1; 2188 2189 cutIndexList.setSelectedIndex(_index); 2190 } 2191 2192 return obj; 2193 } 2194 2195 /** 2196 * 2197 */ reloadCutpoints()2198 private void reloadCutpoints() 2199 { 2200 cutIndexList.removeAllItems(); 2201 2202 Object[] object = collection != null ? collection.getCutpoints() : new Object[0]; 2203 2204 for (int i = 0; i < object.length; i++) 2205 cutIndexList.addItem(object[i]); 2206 } 2207 2208 /** 2209 * 2210 */ setCutIndexField(int value)2211 private void setCutIndexField(int value) 2212 { 2213 Object[] obj = collection != null ? collection.getCutpoints() : null; 2214 2215 cutIndexField.setText(obj == null || value < 0 ? "" : String.valueOf(value) + "/" + String.valueOf(obj.length)); 2216 } 2217 2218 /** 2219 * 2220 */ setChapterIndexField(int value)2221 private void setChapterIndexField(int value) 2222 { 2223 Object[] obj = collection != null ? collection.getChapterpoints() : null; 2224 2225 chapterIndexField.setText(obj == null || value < 0 ? "" : String.valueOf(value) + "/" + String.valueOf(obj.length)); 2226 } 2227 2228 /** 2229 * 2230 */ setPositionField(long value)2231 private void setPositionField(long value) 2232 { 2233 updatePositionField(String.valueOf(value)); 2234 } 2235 2236 /** 2237 * 2238 */ updatePositionField()2239 private void updatePositionField() 2240 { 2241 updatePositionField(positionField.getText()); 2242 } 2243 2244 /** 2245 * 2246 */ updatePositionField(String str)2247 private void updatePositionField(String str) 2248 { 2249 boolean b = action; 2250 2251 List list_1 = collection.getCutpointList(); 2252 List list_2 = collection.getChapterpointList(); 2253 2254 action = false; 2255 2256 if (list_1.contains(str)) 2257 positionField.setBackground(new Color(225, 200, 225)); 2258 2259 else if (list_2.contains(str)) 2260 positionField.setBackground(new Color(225, 230, 255)); 2261 2262 else 2263 positionField.setBackground(Color.white); 2264 2265 positionField.setText(str); 2266 2267 action = b; 2268 } 2269 2270 /** 2271 * 2272 */ showCutInfo(boolean b, Object[] obj, Object list)2273 private void showCutInfo(boolean b, Object[] obj, Object list) 2274 { 2275 boolean b1 = false; 2276 2277 if (!((List) list).isEmpty()) 2278 { 2279 if (collection.getSettings().getBooleanProperty(Keys.KEY_OptionDAR) && 2280 collection.getSettings().getIntProperty(Keys.KEY_ExportDAR) + 1 != Common.getMpvDecoderClass().getAspectRatio()) 2281 b1 = true; 2282 2283 else if (collection.getSettings().getBooleanProperty(Keys.KEY_OptionHorizontalResolution) && 2284 collection.getSettings().getIntProperty(Keys.KEY_ExportHorizontalResolution) != Common.getMpvDecoderClass().getWidth()) 2285 b1 = true; 2286 } 2287 2288 CommonGui.getPicturePanel().setFilterStatus(b1); 2289 Common.getGuiInterface().showCutIcon(b, obj, list); 2290 } 2291 } 2292