/** Method to find and add the roots of the machine to the list. Called for WBFile.computer */ public void dispDrives() { // Fill window with root directories File[] f = File.listRoots(); for (int i = 0; i < f.length; i++) { WBFile tmpFile = new WBFile(scene, f[i]); fileSelector.addListElement(tmpFile); currDispFiles.add(tmpFile); tmpFile.setIcon("directory"); } lookInText.setText(" Computer"); }
/** Method to refresh the file list when a new filter is selected. */ public void refreshDirectory() { changeDirectory(currDir); typeText.setText(currFilter.getTextBox().getText()); if (currFilter.isNoFill()) { currFilter.setNoFill(false); currFilter.setStrokeColor(new MTColor(0, 0, 0, 150)); currFilter.setStrokeWeight(2); currFilter.setNoStroke(false); } types.setVisible(false); typesShown = false; }
/** * Method that opens the currently selected file -- triggered by tapping the "Open" button or * finishing the tap+hold gesture */ public void openSelected() { File file = currFile.getFile(); if (!file.exists() && !FileSystemView.getFileSystemView().isDrive(currFile.getFile())) { scene .getGuiOverlay() .addChild(new WBErrorMessage(scene.getMTApplication(), "File does not exist!")); } else if (file.isDirectory()) { // Set whether the up button will disable when it reaches desktop if (currFile.isBelowComp()) stopAtDesktop = false; if (currFile == top || currFile.isDesktopLookIn()) stopAtDesktop = true; // Up should always be disabled when the back button stack is empty // and obviously if we are at the top if (prevDirs.size() == 0 && currFile == top) { currFile.setStrokeColor(new MTColor(0, 0, 0, 0)); currFile.setNoFill(true); if (lookInDropDown.isVisible()) lookInDropDown.setVisible(false); } else { prevDirs.push(currDir); changeDirectory(currFile); if (lookInDropDown.isVisible()) lookInDropDown.setVisible(false); currFile.setStrokeColor(new MTColor(0, 0, 0, 0)); currFile.setNoFill(true); // Disable up button if at top if (currFile == top) { upButton.setEnabled(false); upButton.setTexture( scene .getMTApplication() .loadImage( System.getProperty("user.dir") + File.separator + "ktsi" + File.separator + "ch" + File.separator + "mitoco" + File.separator + "data" + File.separator + "filechooser" + File.separator + "noUpFolder.png")); } else { upButton.setEnabled(true); upButton.setTexture( scene .getMTApplication() .loadImage( System.getProperty("user.dir") + File.separator + "ktsi" + File.separator + "ch" + File.separator + "mitoco" + File.separator + "data" + File.separator + "filechooser" + File.separator + "upFolder.png")); } } } else { // Add video if (videos.accept(file) && !file.isDirectory()) { MTMovieClip clip = new MTMovieClip(file.getPath(), new Vertex(20, 20, 0), scene); clip.setName(file.getName()); clip.setUseDirectGL(true); clip.setHeightXYGlobal(300); clip.addGestureListener(DragProcessor.class, new InertiaDragAction()); // scene.getLassoProcessor().addClusterable(clip); //make clip lasso-able scene.getCanvas().addChild(clip); System.out.println("Opening: " + file.getName() + "."); // Update settings // scene.updateSettings(clip); toggleFileChooser(); } // Add image else if (images.accept(file) && !file.isDirectory()) { System.out.println("FileChooser: ImageLoad: " + MitocoScene.getImageload()); if (MitocoScene.getImageload()) { PImage texture = scene.getMTApplication().loadImage(file.getPath()); WBImage photo = new WBImage(texture, scene); photo.setName(file.getName()); photo.setNoFill(true); photo.setNoStroke(true); photo.setDisplayCloseButton(true); photo.setHeightXYGlobal(300); photo.addGestureListener(DragProcessor.class, new InertiaDragAction()); // scene.getLassoProcessor().addClusterable(photo); //make photo lasso-able scene.getCanvas().addChild(photo); MitocoScene.setImageload(false); } else { selectionPath = file.getPath(); } toggleFileChooser(); System.out.println("Opening: " + file.getName() + "."); // Update settings // scene.updateSettings(photo); } // Add xml else if (xml.accept(file) && !file.isDirectory()) { selectionPath = file.getPath(); scene.drawXMLload(getSelectionPath()); MitocoScene.setImageload(false); toggleFileChooser(); } else if (pdf.accept(file) && !file.isDirectory()) { selectionPath = file.getPath(); PDFViewer testpdf = new PDFViewer((MTApplication) (scene.getMTApplication()), "Test", selectionPath); scene.getCanvas().addChild(testpdf); testpdf.setVisible(true); testpdf.sendToFront(); MitocoScene.setImageload(false); // scene.drawXMLload(getSelectionPath()); toggleFileChooser(); } else if (powerpoints.accept(file) && !file.isDirectory()) { /* // Run powerpoint to image conversion thread. int numberOfSlides = 0; try{ numberOfSlides = PowerpointToImageConverter.powerPointToImageConversion(file.getCanonicalPath()); }catch(Exception e){} // Add powerpoint images to scene. ArrayList<File> slides = new ArrayList<File>(); for(int i = 0; i < numberOfSlides; i++) { slides.add(new File("slide-" + (i+1) + ".png")); } WBSlideShow photo = new WBSlideShow(scene, slides); photo.setName(file.getName()); photo.setNoFill(true); photo.setNoStroke(true); photo.setDisplayCloseButton(true); photo.setHeightXYGlobal(300); photo.addGestureListener(DragProcessor.class, new InertiaDragAction()); scene.getLassoProcessor().addClusterable(photo); //make photo lasso-able scene.addToMediaLayer(photo); */ selectionPath = file.getPath(); // scene.drawXMLload(getSelectionPath()); toggleFileChooser(); } // FIXME see WBSlideShow and WBImage for needed changes // Add slideshow /*else if(file.length == 1 && file[0].isDirectory()){ //Remove all non-image files File[] holder = file[0].listFiles(); ArrayList<File> dir = createArrayList(holder); for(int index=0; index<dir.size(); index++) { System.out.println("List contains: "+dir.get(index).getName()); if(!dir.get(index).canExecute() || !images.accept(dir.get(index)) || dir.get(index).isDirectory()){ System.out.println("removing "+dir.get(index).getName()); dir.remove(index); } } if(dir.size() > 0) { WBSlideShow show = new WBSlideShow(scene.getApp(),dir); scene.getMediaLayer().addChild(show); show.setName(file[i].getName()); show.setNoFill(true); show.setDisplayCloseButton(true); show.setHeightXYGlobal(300); show.addGestureListener(DragProcessor.class, new InertiaDragAction()); scene.getLassoProcessor().addClusterable(show); //make show lasso-able System.out.println("Opening: " + file[i].getName() + "."); //Update settings scene.updateSettings(show); } else { scene.getCanvas().addChild(new WBErrorMessage(scene, "There weren't any images in that folder!")); } } */ else { // Unreadable drive if (FileSystemView.getFileSystemView().isDrive(currFile.getFile())) { scene .getGuiOverlay() .addChild(new WBErrorMessage(scene.getMTApplication(), "Drive cannot be read from!")); currFile.setStrokeColor(new MTColor(0, 0, 0, 0)); currFile.setNoFill(true); if (lookInDropDown.isVisible()) lookInDropDown.setVisible(false); } // Unsupported file type else { scene .getGuiOverlay() .addChild( new WBErrorMessage(scene.getMTApplication(), "Can't open file of that type!")); } } } }
/** * Method to remove all currently displayed files and show the specified directory's contents * * @param dir */ public void changeDirectory(WBFile dir) { for (WBFile target : currDispFiles) { fileSelector.removeListElement(target); } if (dir.isComputer()) { dispDrives(); currDir = dir; currLookInIcon.setTexture( scene .getMTApplication() .loadImage( System.getProperty("user.dir") + File.separator + "ktsi" + File.separator + "ch" + File.separator + "mitoco" + File.separator + "data" + File.separator + "filechooser" + File.separator + "computer.png")); } else { // Fill window with directory contents if (dir.getFile().getPath() != null) { if (dir.getFile().isDirectory()) { boolean allFiles = false; if (currFilter.getFilter() == null) allFiles = true; ArrayList<File> list = new ArrayList<File>(Arrays.asList(dir.getFile().listFiles())); int target = 0; int size = list.size(); // First add directories for (int i = 0; i < size; i++) { if (list.get(target).isDirectory()) { WBFile tmpDir = new WBFile(scene, list.get(target)); fileSelector.addListElement(tmpDir); tmpDir.setIcon("directory"); currDispFiles.add(tmpDir); list.remove(list.get(target)); } else target++; } target = 0; size = list.size(); // Then add images if (allFiles || currFilter.getFilter() == images) { for (int i = 0; i < size; i++) { if (images.accept(list.get(target))) { WBFile tmpImage = new WBFile(scene, list.get(target)); fileSelector.addListElement(tmpImage); tmpImage.setIcon("image"); currDispFiles.add(tmpImage); list.remove(list.get(target)); } else target++; } } target = 0; size = list.size(); // Then add videos if (allFiles || currFilter.getFilter() == videos) { for (int i = 0; i < size; i++) { if (videos.accept(list.get(target))) { WBFile tmpMovie = new WBFile(scene, list.get(target)); fileSelector.addListElement(tmpMovie); tmpMovie.setIcon("video"); currDispFiles.add(tmpMovie); list.remove(list.get(target)); } else target++; } } target = 0; size = list.size(); if (allFiles || currFilter.getFilter() == xml) { for (int i = 0; i < size; i++) { if (xml.accept(list.get(target))) { WBFile tmpXml = new WBFile(scene, list.get(target)); fileSelector.addListElement(tmpXml); tmpXml.setIcon("xml"); currDispFiles.add(tmpXml); list.remove(list.get(target)); } else target++; } } target = 0; size = list.size(); if (allFiles || currFilter.getFilter() == pdf) { for (int i = 0; i < size; i++) { if (pdf.accept(list.get(target))) { WBFile tmpPdf = new WBFile(scene, list.get(target)); fileSelector.addListElement(tmpPdf); tmpPdf.setIcon("pdf"); currDispFiles.add(tmpPdf); list.remove(list.get(target)); } else target++; } } if (allFiles) { for (File file : list) { WBFile tmpFile = new WBFile(scene, file); fileSelector.addListElement(tmpFile); tmpFile.setIcon(""); currDispFiles.add(tmpFile); } } } currDir = dir; // File system root if (currDir.getFile().getParent() == null) { lookInText.setText(" " + currDir.getFile().getAbsolutePath()); currLookInIcon.setTexture( scene .getMTApplication() .loadImage( System.getProperty("user.dir") + File.separator + "ktsi" + File.separator + "ch" + File.separator + "mitoco" + File.separator + "data" + File.separator + "filechooser" + File.separator + "drive.png")); } // Top desktop else if (stopAtDesktop && currDir.getFile().getPath().toString().compareTo(top.getFile().getPath().toString()) == 0) { lookInText.setText(" " + currDir.getName()); currLookInIcon.setTexture( scene .getMTApplication() .loadImage( System.getProperty("user.dir") + File.separator + "ktsi" + File.separator + "ch" + File.separator + "mitoco" + File.separator + "data" + File.separator + "filechooser" + File.separator + "desktop.png")); } // Normal desktop else { lookInText.setText(" " + currDir.getName()); currLookInIcon.setTexture( scene .getMTApplication() .loadImage( System.getProperty("user.dir") + File.separator + "ktsi" + File.separator + "ch" + File.separator + "mitoco" + File.separator + "data" + File.separator + "filechooser" + File.separator + "folder.png")); } } } // Enable back button if (prevDirs.size() == 1) { // Minimize the times the image is loaded backButton.setEnabled(true); backButton.setTexture( scene .getMTApplication() .loadImage( System.getProperty("user.dir") + File.separator + "ktsi" + File.separator + "ch" + File.separator + "mitoco" + File.separator + "data" + File.separator + "filechooser" + File.separator + "back.png")); } }
public void Make(AbstractMTApplication mtApplication, String name) { /// Create map provider menu \\\ IFont font = FontManager.getInstance() .createFont(mtApplication, "SansSerif.Bold", 15, MTColor.WHITE, MTColor.WHITE); MTRoundRectangle mapMenu = new MTRoundRectangle(0, 0, 0, 220, 335, 20, 20, mtApplication); mapMenu.setFillColor(new MTColor(35, 35, 35, 180)); mapMenu.setStrokeColor(new MTColor(35, 35, 35, 180)); mapMenu.setPositionGlobal(new Vector3D(mtApplication.width / 2f, mtApplication.height / 2f)); mapMenu.translateGlobal(new Vector3D(-mtApplication.width / 2f - 80, 0)); MTRectangle drawing = new MTRectangle(0, 0, 200, 200, mtApplication); StartTiamat.general.addChild(mapMenu); System.out.println("added menu"); float cellWidth = 155; float cellHeight = 40; MTColor cellFillColor = new MTColor(new MTColor(0, 0, 0, 210)); MTColor cellPressedFillColor = new MTColor(new MTColor(20, 20, 20, 220)); MTList list = new MTList(0, 0, 152, 4 * cellHeight + 4 * 3, mtApplication); list.setChildClip(null); list.setNoFill(true); list.setNoStroke(true); list.unregisterAllInputProcessors(); list.setAnchor(PositionAnchor.CENTER); list.setPositionRelativeToParent(mapMenu.getCenterPointLocal()); mapMenu.addChild(list); for (int i = 0; i < StartTiamat.functions.size(); i++) { Tiamat.Templates template = StartTiamat.functions.get(i); list.addListElement( this.createListCell( mtApplication, template.getName(), template.getFunction(), font, cellWidth, cellHeight, cellFillColor, cellPressedFillColor)); } ; MultiPurposeInterpolator in = new MultiPurposeInterpolator(0, 170, 700, 0.1f, 0.7f, 1); final Animation slideOut = new Animation("slide out animation", in, mapMenu); slideOut.addAnimationListener( new IAnimationListener() { public void processAnimationEvent(AnimationEvent ae) { float delta = ae.getCurrentStepDelta(); ((IMTComponent3D) ae.getTargetObject()).translateGlobal(new Vector3D(delta, 0, 0)); switch (ae.getId()) { case AnimationEvent.ANIMATION_ENDED: doSlideIn = true; animationRunning = false; break; } } }); final Animation slideIn = new Animation("slide out animation", in, mapMenu); slideIn.addAnimationListener( new IAnimationListener() { public void processAnimationEvent(AnimationEvent ae) { float delta = -ae.getCurrentStepDelta(); ((IMTComponent3D) ae.getTargetObject()).translateGlobal(new Vector3D(delta, 0, 0)); switch (ae.getId()) { case AnimationEvent.ANIMATION_ENDED: doSlideIn = false; animationRunning = false; break; } } }); mapMenu.unregisterAllInputProcessors(); mapMenu.registerInputProcessor(new TapProcessor(mtApplication, 50)); mapMenu.addGestureListener( TapProcessor.class, new IGestureEventListener() { public boolean processGestureEvent(MTGestureEvent ge) { if (((TapEvent) ge).getTapID() == TapEvent.BUTTON_CLICKED) { if (!animationRunning) { animationRunning = true; if (doSlideIn) { slideIn.start(); } else { slideOut.start(); } } } return false; } }); }