public void actionPerformed(ActionEvent e) { String cmd = (e.getActionCommand()); if (cmd.equals(aboutItem.getText())) JOptionPane.showMessageDialog( this, "Simple Image Program for DB2004\nversion 0.1\nThanks to BvS", "About imageLab", JOptionPane.INFORMATION_MESSAGE); else if (cmd.equals(quitItem.getText())) System.exit(0); else if (cmd.equals(openItem.getText())) { int returnVal = chooser.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { try { pic2 = new Picture(chooser.getSelectedFile().getName()); pic1 = new Picture(pic2.width(), pic2.height()); lab.setIcon(pic2.getJLabel().getIcon()); sliderPanel.setVisible(false); pack(); repaint(); } catch (Exception ex) { JOptionPane.showMessageDialog( this, "Could not open " + chooser.getSelectedFile().getName() + "\n" + ex.getMessage(), "Open Error", JOptionPane.INFORMATION_MESSAGE); } } } else if (cmd.equals(saveItem.getText())) { int returnVal = chooser.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { try { pic2.save(chooser.getSelectedFile().getName()); } catch (Exception ex) { JOptionPane.showMessageDialog( this, "Could not write " + chooser.getSelectedFile().getName() + "\n" + ex.getMessage(), "Save Error", JOptionPane.INFORMATION_MESSAGE); } } } }
public void loadImage(String filename) { theImage.setIcon(new MyImageIcon(filename)); }
// initializes the internal component of the translator protected void jbInit() { this.getContentPane().setLayout(new GridBagLayout()); loadButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { loadButton_actionPerformed(e); } }); loadButton.setMaximumSize(new Dimension(39, 39)); loadButton.setMinimumSize(new Dimension(39, 39)); loadButton.setPreferredSize(new Dimension(39, 39)); loadButton.setSize(new Dimension(39, 39)); loadButton.setToolTipText("Load Source File"); loadButton.setIcon(loadIcon); saveButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { saveButton_actionPerformed(e); } }); saveButton.setMaximumSize(new Dimension(39, 39)); saveButton.setMinimumSize(new Dimension(39, 39)); saveButton.setPreferredSize(new Dimension(39, 39)); saveButton.setSize(new Dimension(39, 39)); saveButton.setToolTipText("Save Destination File"); saveButton.setIcon(saveIcon); singleStepButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { singleStepButton_actionPerformed(e); } }); singleStepButton.setMaximumSize(new Dimension(39, 39)); singleStepButton.setMinimumSize(new Dimension(39, 39)); singleStepButton.setPreferredSize(new Dimension(39, 39)); singleStepButton.setSize(new Dimension(39, 39)); singleStepButton.setToolTipText("Single Step"); singleStepButton.setIcon(singleStepIcon); ffwdButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { ffwdButton_actionPerformed(e); } }); ffwdButton.setMaximumSize(new Dimension(39, 39)); ffwdButton.setMinimumSize(new Dimension(39, 39)); ffwdButton.setPreferredSize(new Dimension(39, 39)); ffwdButton.setSize(new Dimension(39, 39)); ffwdButton.setToolTipText("Fast Forward"); ffwdButton.setIcon(ffwdIcon); rewindButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { rewindButton_actionPerformed(e); } }); rewindButton.setMaximumSize(new Dimension(39, 39)); rewindButton.setMinimumSize(new Dimension(39, 39)); rewindButton.setPreferredSize(new Dimension(39, 39)); rewindButton.setSize(new Dimension(39, 39)); rewindButton.setToolTipText("Rewind"); rewindButton.setIcon(rewindIcon); stopButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { stopButton_actionPerformed(e); } }); stopButton.setMaximumSize(new Dimension(39, 39)); stopButton.setMinimumSize(new Dimension(39, 39)); stopButton.setPreferredSize(new Dimension(39, 39)); stopButton.setSize(new Dimension(39, 39)); stopButton.setToolTipText("Stop"); stopButton.setIcon(stopIcon); fullTranslationButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { fullTranslationButton_actionPerformed(e); } }); fullTranslationButton.setMaximumSize(new Dimension(39, 39)); fullTranslationButton.setMinimumSize(new Dimension(39, 39)); fullTranslationButton.setPreferredSize(new Dimension(39, 39)); fullTranslationButton.setSize(new Dimension(39, 39)); fullTranslationButton.setToolTipText("Fast Translation"); fullTranslationButton.setIcon(fullTranslationIcon); messageLbl.setFont(Utilities.statusLineFont); messageLbl.setLineWrap(true); messageLbl.setEditable(false); messageLbl.setCursor(null); messageLbl.setOpaque(false); messageLbl.setFocusable(false); messageLblPane.setBorder(BorderFactory.createLoweredBevelBorder()); // messageLblPane.setBounds(new Rectangle(0, 672, TRANSLATOR_WIDTH - 8, 20)); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.ipadx = 0; c.ipady = 0; c.weightx = 1; c.weighty = 0; c.gridwidth = 3; c.anchor = GridBagConstraints.CENTER; c.gridx = 0; c.gridy = 2; this.getContentPane().add(messageLblPane, c); // arrowLabel.setBounds(new Rectangle(290, 324, 88, 71)); arrowLabel.setIcon(arrowIcon); // source.setVisibleRows(31); // destination.setVisibleRows(31); // source.setBounds(new Rectangle(35,100,source.getWidth(),source.getHeight())); // destination.setBounds(new Rectangle(375,100,destination.getWidth(),destination.getHeight())); c.fill = GridBagConstraints.BOTH; c.ipadx = 0; c.ipady = 0; c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.anchor = GridBagConstraints.CENTER; c.gridx = 0; c.gridy = 1; this.getContentPane().add(source, c); c.fill = GridBagConstraints.NONE; c.ipadx = 0; c.ipady = 0; c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.anchor = GridBagConstraints.CENTER; c.gridx = 1; c.gridy = 1; this.getContentPane().add(arrowLabel, c); c.fill = GridBagConstraints.BOTH; c.ipadx = 0; c.ipady = 0; c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.anchor = GridBagConstraints.CENTER; c.gridx = 2; c.gridy = 1; this.getContentPane().add(destination, c); // Adding the tool bar to this container. toolBar.setFloatable(false); toolBar.setLocation(0, 0); toolBar.setLayout(new FlowLayout(FlowLayout.LEFT, 3, 0)); toolBar.setBorder(BorderFactory.createEtchedBorder()); arrangeToolBar(); c.fill = GridBagConstraints.HORIZONTAL; c.ipadx = 0; c.ipady = 0; c.weightx = 1; c.weighty = 0; c.gridwidth = 3; c.anchor = GridBagConstraints.CENTER; c.gridx = 0; c.gridy = 0; this.getContentPane().add(toolBar, c); toolBar.revalidate(); toolBar.repaint(); repaint(); // Creating the menu bar arrangeMenu(); setJMenuBar(menuBar); // initializing the window size and visibility setDefaultCloseOperation(3); setSize(new Dimension(TRANSLATOR_WIDTH, TRANSLATOR_HEIGHT)); setVisible(true); }
public void init() { areaventana = new JPanel(); areabotones = new JPanel(); imagen = new JLabel(""); presentacion = new JButton(imgPlay); siguiente = new JButton(imgSiguiente); atras = new JButton(imgAnterior); ptiempo = new JSlider(); carpeta = new JButton(imgNuevaCarpeta); grid = new JButton(imgGrid); bcomentario = new JButton(imgComentario); zoom = new JButton(imgZoom); /* Agregando los componentes */ areaventana.add(imagen); // areaventana.add(desplazamiento); areabotones.add(grid); areabotones.add(atras); areabotones.add(presentacion); areabotones.add(siguiente); areabotones.add(ptiempo); areabotones.add(carpeta); areabotones.add(bcomentario); areabotones.add(zoom); areabotones.setBackground(colorGris); areaventana.setBackground(colorGris); // desplazamiento.setVisible(false); // areaventana.add(desplazamiento); /* GUI GUI GUI GUI */ presentacion.setBackground(colorGris); atras.setBackground(colorGris); siguiente.setBackground(colorGris); carpeta.setBackground(colorGris); grid.setBackground(colorGris); ptiempo.setBackground(colorGris); bcomentario.setBackground(colorGris); zoom.setBackground(colorGris); presentacion.setPreferredSize(new Dimension(100, 80)); atras.setPreferredSize(new Dimension(100, 80)); siguiente.setPreferredSize(new Dimension(100, 80)); carpeta.setPreferredSize(new Dimension(100, 80)); grid.setPreferredSize(new Dimension(100, 80)); bcomentario.setPreferredSize(new Dimension(100, 80)); zoom.setPreferredSize(new Dimension(100, 80)); grid.setFocusPainted(false); atras.setFocusPainted(false); siguiente.setFocusPainted(false); carpeta.setFocusPainted(false); presentacion.setFocusPainted(false); bcomentario.setFocusPainted(false); zoom.setFocusPainted(false); grid.setBorder(null); atras.setBorder(null); siguiente.setBorder(null); carpeta.setBorder(null); presentacion.setBorder(null); areabotones.setBorder(null); areaventana.setBorder(null); bcomentario.setBorder(null); zoom.setBorder(null); /* GUI GUI GUI GUI */ /* Action Listeners */ siguiente.addActionListener(this); atras.addActionListener(this); presentacion.addActionListener(this); carpeta.addActionListener(this); grid.addActionListener(this); bcomentario.addActionListener(this); zoom.addActionListener(this); this.setLayout(new BorderLayout()); add(areaventana, BorderLayout.CENTER); add(areabotones, BorderLayout.SOUTH); ptiempo.setVisible(false); siguiente.setEnabled(false); atras.setEnabled(false); presentacion.setEnabled(false); grid.setEnabled(false); bcomentario.setEnabled(false); zoom.setEnabled(false); /* Abre el selector desde que inicia el programa */ chooser = new JFileChooser(); chooser.setDialogTitle("Selecciona una imagen..."); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setAcceptAllFileFilterUsed(false); // Abrir archivo es de acá... returnChooser = chooser.showOpenDialog(ArcViewer.this); if (returnChooser == 0) { imagenes = lista.Miranda(chooser, returnChooser); siguiente.setEnabled(true); atras.setEnabled(true); presentacion.setEnabled(true); grid.setEnabled(true); bcomentario.setEnabled(true); zoom.setEnabled(true); for (int asd1 = 0; asd1 < imagenes.size(); asd1++) { imagenesbean.add(new ImagenBean(imagenes.get(asd1), 0, 0)); } String getImgSelected = chooser.getSelectedFile().getPath(); for (int index = 0; index < imagenesbean.size(); index++) { if (getImgSelected.equals(imagenesbean.get(index).getIcon())) { imagen.setIcon(new ImageIcon(imagenesbean.get(index).getIcon())); indexaux = index; } } } else { System.out.println("No Selection"); carpeta.setEnabled(true); } // for (int asd1=0; asd1 < imagenes.size(); asd1++) { // imagenesbean.add(new ImagenBean(imagenes.get(asd1),0,0)); // } // String getImgSelected = chooser.getSelectedFile().getPath(); // for (int index=0; index < imagenesbean.size(); index++) { // if (getImgSelected.equals( imagenesbean.get(index).getIcon() )) { // imagen.setIcon(new ImageIcon(imagenesbean.get(index).getIcon())); // indexaux = index; // } // } }
public void actionPerformed(ActionEvent event) { if (posicion == -2) posicion = indexaux; // Abrir nueva imagen if (event.getSource() == carpeta) { siguiente.setEnabled(true); atras.setEnabled(true); presentacion.setEnabled(true); grid.setEnabled(true); bcomentario.setEnabled(true); zoom.setEnabled(true); imagenesbean.clear(); if (imagenes != null) { imagenes.clear(); } returnChooser = chooser.showOpenDialog(ArcViewer.this); imagenes = lista.Miranda(chooser, returnChooser); for (int asd1 = 0; asd1 < imagenes.size(); asd1++) { imagenesbean.add(new ImagenBean(imagenes.get(asd1), 0, 0)); } String getImgSelected = chooser.getSelectedFile().getPath(); for (int index = 0; index < imagenesbean.size(); index++) { if (getImgSelected.equals(imagenesbean.get(index).getIcon())) { imagen.setIcon(new ImageIcon(imagenesbean.get(index).getIcon())); indexaux = index; } } } // Imagen siguiente if (event.getSource() == siguiente) { posicion++; if (posicion >= imagenesbean.size()) { posicion = 0; } imagen.setIcon( ajustar.ajusteImg( new ImageIcon(imagenesbean.get(posicion).getIcon()), imagenesbean.get(posicion).getAncho(), imagenesbean.get(posicion).getAlto(), areaventana.getWidth() - 50, areaventana.getHeight())); } // Imagen anterior if (event.getSource() == atras) { posicion--; if (posicion == -1) { posicion = imagenesbean.size() - 1; } imagen.setIcon( ajustar.ajusteImg( new ImageIcon(imagenesbean.get(posicion).getIcon()), imagenesbean.get(posicion).getAncho(), imagenesbean.get(posicion).getAlto(), areaventana.getWidth() - 50, areaventana.getHeight())); } // Presentacion iniciar/detener if (event.getSource() == presentacion) { if (isPresentacion == false) { grid.setVisible(false); atras.setVisible(false); siguiente.setVisible(false); carpeta.setVisible(false); bcomentario.setVisible(false); zoom.setVisible(false); ptiempo.setVisible(true); } if (isPresentacion == true) { grid.setVisible(true); atras.setVisible(true); siguiente.setVisible(true); carpeta.setVisible(true); bcomentario.setVisible(true); zoom.setVisible(true); ptiempo.setVisible(false); } if (presentacion.getIcon() == imgPausa) { slide.detener(); posicion = slide.getPosicion(); presentacion.setIcon(imgPlay); isPresentacion = false; return; } if (presentacion.getIcon() == imgPlay) { slide.setTodo(posicion, imagen, imagenesbean, areaventana, ptiempo); new Thread(slide, "prueba").start(); presentacion.setIcon(imgPausa); isPresentacion = true; return; } } // Modo rejilla if (event.getSource() == grid) { imagen.setVisible(false); siguiente.setVisible(false); atras.setVisible(false); presentacion.setVisible(false); grid.setVisible(false); bcomentario.setVisible(false); zoom.setVisible(false); carpeta.setVisible(false); ptiempo.setVisible(false); // desplazamiento.setVisible(true); if (corrobora == true) { for (int celular = 0; celular < imgButtonArray.length; celular++) { imgButtonArray[celular].setVisible(true); } } if (corrobora == false) { imgButtonArray = new JButton[imagenesbean.size()]; for (int goku = 0; goku < imagenesbean.size(); goku++) { areaventana.add(imgButtonArray[goku] = new JButton()); imgButtonArray[goku].setPreferredSize(new Dimension(200, 200)); imgButtonArray[goku].addActionListener(this); imgButtonArray[goku].setBackground(colorGris); imgButtonArray[goku].setIcon( ajustar.ajusteCuadrado(new ImageIcon(imagenesbean.get(goku).getIcon()))); corrobora = true; } } } // Comentario if (event.getSource() == bcomentario) { new Comentario(imagenesbean.get(posicion), posicion); } // Cuando se apreta un boton de la rejilla if (corrobora == true) { for (int alice = 0; alice < imgButtonArray.length; alice++) { if (event.getSource() == imgButtonArray[alice]) { for (int wonderland = 0; wonderland < imgButtonArray.length; wonderland++) { imgButtonArray[wonderland].setVisible(false); } posicion = alice; imagen.setIcon( ajustar.ajusteImg( new ImageIcon(imagenesbean.get(posicion).getIcon()), imagenesbean.get(posicion).getAncho(), imagenesbean.get(posicion).getAlto(), areaventana.getWidth() - 50, areaventana.getHeight())); imagen.setVisible(true); siguiente.setVisible(true); atras.setVisible(true); presentacion.setVisible(true); grid.setVisible(true); bcomentario.setVisible(true); zoom.setVisible(true); carpeta.setVisible(true); } } } if (event.getSource() == zoom) { System.out.println("Haciendo un ZOOOOOOOOOOOOM"); } }
public fileBackupProgram(JFrame frame) { super(new BorderLayout()); this.frame = frame; errorDialog = new CustomDialog(frame, "Please enter a new name for the error log", this); errorDialog.pack(); moveDialog = new CustomDialog(frame, "Please enter a new name for the move log", this); moveDialog.pack(); printer = new FilePrinter(); timers = new ArrayList<>(); log = new JTextArea(5, 20); log.setMargin(new Insets(5, 5, 5, 5)); log.setEditable(false); JScrollPane logScrollPane = new JScrollPane(log); Object obj; copy = true; listModel = new DefaultListModel(); // destListModel = new DefaultListModel(); directoryList = new directoryStorage(); // Create a file chooser fc = new JFileChooser(); // Create the menu bar. menuBar = new JMenuBar(); // Build the first menu. menu = new JMenu("File"); menu.getAccessibleContext() .setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); editError = new JMenuItem("Save Error Log As..."); editError .getAccessibleContext() .setAccessibleDescription("Change the name of the error log file"); editError.addActionListener(new ErrorListener()); menu.add(editError); editMove = new JMenuItem("Save Move Log As..."); editMove .getAccessibleContext() .setAccessibleDescription("Change the name of the move log file"); editMove.addActionListener(new MoveListener()); menu.add(editMove); exit = new JMenuItem("Exit"); exit.getAccessibleContext().setAccessibleDescription("Exit the Program"); exit.addActionListener(new CloseListener()); menu.add(exit); frame.setJMenuBar(menuBar); // Uncomment one of the following lines to try a different // file selection mode. The first allows just directories // to be selected (and, at least in the Java look and feel, // shown). The second allows both files and directories // to be selected. If you leave these lines commented out, // then the default mode (FILES_ONLY) will be used. // fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); openButton = new JButton(openString); openButton.setActionCommand(openString); openButton.addActionListener(new OpenListener()); destButton = new JButton(destString); destButton.setActionCommand(destString); destButton.addActionListener(new DestListener()); // Create the save button. We use the image from the JLF // Graphics Repository (but we extracted it from the jar). saveButton = new JButton(saveString); saveButton.setActionCommand(saveString); saveButton.addActionListener(new SaveListener()); URL imageURL = getClass().getResource(greenButtonIcon); ImageIcon greenSquare = new ImageIcon(imageURL); startButton = new JButton("Start", greenSquare); startButton.setSize(60, 20); startButton.setHorizontalTextPosition(AbstractButton.LEADING); startButton.setActionCommand("Start"); startButton.addActionListener(new StartListener()); imageURL = getClass().getResource(redButtonIcon); ImageIcon redSquare = new ImageIcon(imageURL); stopButton = new JButton("Stop", redSquare); stopButton.setSize(60, 20); stopButton.setHorizontalTextPosition(AbstractButton.LEADING); stopButton.setActionCommand("Stop"); stopButton.addActionListener(new StopListener()); copyButton = new JRadioButton("Copy"); copyButton.setActionCommand("Copy"); copyButton.setSelected(true); copyButton.addActionListener(new RadioListener()); moveButton = new JRadioButton("Move"); moveButton.setActionCommand("Move"); moveButton.addActionListener(new RadioListener()); ButtonGroup group = new ButtonGroup(); group.add(copyButton); group.add(moveButton); // For layout purposes, put the buttons in a separate panel JPanel optionPanel = new JPanel(); GroupLayout layout = new GroupLayout(optionPanel); optionPanel.setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); layout.setHorizontalGroup( layout.createSequentialGroup().addComponent(copyButton).addComponent(moveButton)); layout.setVerticalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(copyButton) .addComponent(moveButton))); JPanel buttonPanel = new JPanel(); // use FlowLayout layout = new GroupLayout(buttonPanel); buttonPanel.setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); layout.setHorizontalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(openButton) .addComponent(optionPanel)) .addComponent(destButton) .addComponent(startButton) .addComponent(stopButton) // .addComponent(saveButton) ); layout.setVerticalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(openButton) .addComponent(destButton) .addComponent(startButton) .addComponent(stopButton) // .addComponent(saveButton) ) .addComponent(optionPanel)); buttonPanel.add(optionPanel); /* buttonPanel.add(openButton); buttonPanel.add(destButton); buttonPanel.add(startButton); buttonPanel.add(stopButton); buttonPanel.add(saveButton); buttonPanel.add(listLabel); buttonPanel.add(copyButton); buttonPanel.add(moveButton); */ destButton.setEnabled(false); startButton.setEnabled(false); stopButton.setEnabled(false); // Add the buttons and the log to this panel. // add(logScrollPane, BorderLayout.CENTER); JLabel listLabel = new JLabel("Monitored Directory:"); listLabel.setLabelFor(list); // Create the list and put it in a scroll pane. list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0); list.addListSelectionListener(this); list.setVisibleRowCount(8); JScrollPane listScrollPane = new JScrollPane(list); JPanel listPane = new JPanel(); listPane.setLayout(new BorderLayout()); listPane.add(listLabel, BorderLayout.PAGE_START); listPane.add(listScrollPane, BorderLayout.CENTER); listSelectionModel = list.getSelectionModel(); listSelectionModel.addListSelectionListener(new SharedListSelectionHandler()); // monitored, destination, waitInt, check destination = new JLabel("Destination Directory: "); waitField = new JFormattedTextField(); // waitField.setValue(240); waitField.setEditable(false); waitField.addPropertyChangeListener(new FormattedTextListener()); waitInt = new JLabel("Wait Interval (in minutes)"); // waitInt.setLabelFor(waitField); checkField = new JFormattedTextField(); checkField.setSize(1, 10); // checkField.setValue(60); checkField.setEditable(false); checkField.addPropertyChangeListener(new FormattedTextListener()); check = new JLabel("Check Interval (in minutes)"); // check.setLabelFor(checkField); fireButton = new JButton(fireString); fireButton.setActionCommand(fireString); fireButton.addActionListener(new FireListener()); JPanel fieldPane = new JPanel(); // fieldPane.add(destField); layout = new GroupLayout(fieldPane); fieldPane.setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); layout.setHorizontalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(waitInt) .addComponent(check)) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(waitField, 60, 60, 60) .addComponent(checkField, 60, 60, 60))); layout.setVerticalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(waitInt) .addComponent(waitField)) .addGroup( layout .createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(check) .addComponent(checkField))); JPanel labelPane = new JPanel(); labelPane.setLayout(new BorderLayout()); labelPane.add(destination, BorderLayout.PAGE_START); labelPane.add(fieldPane, BorderLayout.CENTER); layout = new GroupLayout(labelPane); labelPane.setLayout(layout); layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); layout.setHorizontalGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(destination) .addComponent(fieldPane))); layout.setVerticalGroup( layout.createSequentialGroup().addComponent(destination).addComponent(fieldPane)); // labelPane.add(destination); // labelPane.add(fieldPane); try { // Read from disk using FileInputStream FileInputStream f_in = new FileInputStream(LOG_DIRECTORY + "\\save.data"); // Read object using ObjectInputStream ObjectInputStream obj_in = new ObjectInputStream(f_in); // Read an object directoryList = (directoryStorage) obj_in.readObject(); ERROR_LOG_NAME = (String) obj_in.readObject(); MOVE_LOG_NAME = (String) obj_in.readObject(); if (ERROR_LOG_NAME instanceof String) { printer.changeErrorLogName(ERROR_LOG_NAME); } if (MOVE_LOG_NAME instanceof String) { printer.changeMoveLogName(MOVE_LOG_NAME); } if (directoryList instanceof directoryStorage) { System.out.println("found object"); // directoryList = (directoryStorage) obj; Iterator<Directory> directories = directoryList.getDirectories(); Directory d; while (directories.hasNext()) { d = directories.next(); try { listModel.addElement(d.getDirectory().toRealPath()); } catch (IOException x) { printer.printError(x.toString()); } int index = list.getSelectedIndex(); if (index == -1) { list.setSelectedIndex(0); } index = list.getSelectedIndex(); Directory dir = directoryList.getDirectory(index); destButton.setEnabled(true); checkField.setValue(dir.getInterval()); waitField.setValue(dir.getWaitInterval()); checkField.setEditable(true); waitField.setEditable(true); // directoryList.addNewDirectory(d); // try { // listModel.addElement(d.getDirectory().toString()); // } catch (IOException x) { // printer.printError(x.toString()); // } // timer = new Timer(); // timer.schedule(new CopyTask(d.directory, d.destination, d.getWaitInterval(), printer, // d.copy), 0, d.getInterval()); } } else { System.out.println("did not find object"); } obj_in.close(); } catch (ClassNotFoundException x) { printer.printError(x.getLocalizedMessage()); System.err.format("Unable to read"); } catch (IOException y) { printer.printError(y.getLocalizedMessage()); } // Layout the text fields in a panel. JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.add(fireButton); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(new JSeparator(SwingConstants.VERTICAL)); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(buttonPanel, BorderLayout.PAGE_START); add(listPane, BorderLayout.LINE_START); // add(destListScrollPane, BorderLayout.CENTER); add(fieldPane, BorderLayout.LINE_END); add(labelPane, BorderLayout.CENTER); add(buttonPane, BorderLayout.PAGE_END); }
public void installComponents(JFileChooser fc) { fc.setLayout(new BorderLayout(10, 10)); fc.setAlignmentX(JComponent.CENTER_ALIGNMENT); JPanel interior = new JPanel() { public Insets getInsets() { return insets; } }; align(interior); interior.setLayout(new BoxLayout(interior, BoxLayout.PAGE_AXIS)); fc.add(interior, BorderLayout.CENTER); // PENDING(jeff) - I18N JLabel l = new JLabel(pathLabelText); l.setDisplayedMnemonic(pathLabelMnemonic); align(l); interior.add(l); File currentDirectory = fc.getCurrentDirectory(); String curDirName = null; if (currentDirectory != null) { curDirName = currentDirectory.getPath(); } pathField = new JTextField(curDirName) { public Dimension getMaximumSize() { Dimension d = super.getMaximumSize(); d.height = getPreferredSize().height; return d; } }; l.setLabelFor(pathField); align(pathField); // Change to folder on return pathField.addActionListener(getUpdateAction()); interior.add(pathField); interior.add(Box.createRigidArea(vstrut10)); // CENTER: left, right accessory JPanel centerPanel = new JPanel(); centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.LINE_AXIS)); align(centerPanel); // left panel - Filter & folderList JPanel leftPanel = new JPanel(); leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS)); align(leftPanel); // add the filter PENDING(jeff) - I18N l = new JLabel(filterLabelText); l.setDisplayedMnemonic(filterLabelMnemonic); align(l); leftPanel.add(l); filterComboBox = new JComboBox() { public Dimension getMaximumSize() { Dimension d = super.getMaximumSize(); d.height = getPreferredSize().height; return d; } }; l.setLabelFor(filterComboBox); filterComboBoxModel = createFilterComboBoxModel(); filterComboBox.setModel(filterComboBoxModel); filterComboBox.setRenderer(createFilterComboBoxRenderer()); fc.addPropertyChangeListener(filterComboBoxModel); align(filterComboBox); leftPanel.add(filterComboBox); // leftPanel.add(Box.createRigidArea(vstrut10)); // Add the Folder List PENDING(jeff) - I18N l = new JLabel(foldersLabelText); l.setDisplayedMnemonic(foldersLabelMnemonic); align(l); leftPanel.add(l); JScrollPane sp = createDirectoryList(); sp.getVerticalScrollBar().setFocusable(false); sp.getHorizontalScrollBar().setFocusable(false); l.setLabelFor(sp.getViewport().getView()); leftPanel.add(sp); // create files list JPanel rightPanel = new JPanel(); align(rightPanel); rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.PAGE_AXIS)); l = new JLabel(filesLabelText); l.setDisplayedMnemonic(filesLabelMnemonic); align(l); rightPanel.add(l); sp = createFilesList(); l.setLabelFor(sp); rightPanel.add(sp); centerPanel.add(leftPanel); centerPanel.add(Box.createRigidArea(hstrut10)); centerPanel.add(rightPanel); JComponent accessoryPanel = getAccessoryPanel(); JComponent accessory = fc.getAccessory(); if (accessoryPanel != null) { if (accessory == null) { accessoryPanel.setPreferredSize(ZERO_ACC_SIZE); accessoryPanel.setMaximumSize(ZERO_ACC_SIZE); } else { getAccessoryPanel().add(accessory, BorderLayout.CENTER); accessoryPanel.setPreferredSize(PREF_ACC_SIZE); accessoryPanel.setMaximumSize(MAX_SIZE); } align(accessoryPanel); centerPanel.add(accessoryPanel); } interior.add(centerPanel); interior.add(Box.createRigidArea(vstrut10)); // add the filename field PENDING(jeff) - I18N l = new JLabel(enterFileNameLabelText); l.setDisplayedMnemonic(enterFileNameLabelMnemonic); align(l); interior.add(l); filenameTextField = new JTextField() { public Dimension getMaximumSize() { Dimension d = super.getMaximumSize(); d.height = getPreferredSize().height; return d; } }; l.setLabelFor(filenameTextField); filenameTextField.addActionListener(getApproveSelectionAction()); align(filenameTextField); filenameTextField.setAlignmentX(JComponent.LEFT_ALIGNMENT); interior.add(filenameTextField); bottomPanel = getBottomPanel(); bottomPanel.add(new JSeparator(), BorderLayout.NORTH); // Add buttons JPanel buttonPanel = new JPanel(); align(buttonPanel); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS)); buttonPanel.add(Box.createGlue()); approveButton = new JButton(getApproveButtonText(fc)) { public Dimension getMaximumSize() { return new Dimension(MAX_SIZE.width, this.getPreferredSize().height); } }; approveButton.setMnemonic(getApproveButtonMnemonic(fc)); approveButton.setToolTipText(getApproveButtonToolTipText(fc)); align(approveButton); approveButton.setMargin(buttonMargin); approveButton.addActionListener(getApproveSelectionAction()); buttonPanel.add(approveButton); buttonPanel.add(Box.createGlue()); JButton updateButton = new JButton(updateButtonText) { public Dimension getMaximumSize() { return new Dimension(MAX_SIZE.width, this.getPreferredSize().height); } }; updateButton.setMnemonic(updateButtonMnemonic); updateButton.setToolTipText(updateButtonToolTipText); align(updateButton); updateButton.setMargin(buttonMargin); updateButton.addActionListener(getUpdateAction()); buttonPanel.add(updateButton); buttonPanel.add(Box.createGlue()); JButton cancelButton = new JButton(cancelButtonText) { public Dimension getMaximumSize() { return new Dimension(MAX_SIZE.width, this.getPreferredSize().height); } }; cancelButton.setMnemonic(cancelButtonMnemonic); cancelButton.setToolTipText(cancelButtonToolTipText); align(cancelButton); cancelButton.setMargin(buttonMargin); cancelButton.addActionListener(getCancelSelectionAction()); buttonPanel.add(cancelButton); buttonPanel.add(Box.createGlue()); JButton helpButton = new JButton(helpButtonText) { public Dimension getMaximumSize() { return new Dimension(MAX_SIZE.width, this.getPreferredSize().height); } }; helpButton.setMnemonic(helpButtonMnemonic); helpButton.setToolTipText(helpButtonToolTipText); align(helpButton); helpButton.setMargin(buttonMargin); helpButton.setEnabled(false); buttonPanel.add(helpButton); buttonPanel.add(Box.createGlue()); bottomPanel.add(buttonPanel, BorderLayout.SOUTH); if (fc.getControlButtonsAreShown()) { fc.add(bottomPanel, BorderLayout.SOUTH); } }