private void clearDestinationSelected() { Object selected[] = destList.getSelectedValues(); for (int i = selected.length - 1; i >= 0; --i) { destListModel.removeElement(selected[i]); } destList.getSelectionModel().clearSelection(); }
private void addListeners() { myMacrosList .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { Macro macro = getSelectedMacro(); if (macro == null) { myPreviewTextarea.setText(""); setOKActionEnabled(false); } else { myPreviewTextarea.setText(macro.preview()); setOKActionEnabled(true); } } }); // doubleclick support myMacrosList.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if ((e.getClickCount() == 2) && (getSelectedMacro() != null)) { close(OK_EXIT_CODE); } } }); }
private void clearSourceSelected() { Object selected[] = sourceList.getSelectedValues(); for (int i = selected.length - 1; i >= 0; --i) { sourceListModel.removeElement(selected[i]); } sourceList.getSelectionModel().clearSelection(); }
private void setSelectedIndex(int index) { if (index == -1) { list.getSelectionModel().clearSelection(); } else if (list.getModel().getSize() != 0) { list.setSelectedIndex(index); list.ensureIndexIsVisible(index); } }
/** Constructor. */ public TilePatternsView() { super(); tilePatternIcons = new ArrayList<TilePatternIcon>(); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); // tileset properties // the tile pattern list // view of the current tile pattern // tileset properties tilesetPropertiesView = new TilesetPropertiesView(); tilesetPropertiesView.setMaximumSize(new Dimension(Integer.MAX_VALUE, 120)); tilesetPropertiesView.setAlignmentX(Component.LEFT_ALIGNMENT); // list tilePatternsListModel = new TilePatternsListModel(); tilePatternsList = new JList(tilePatternsListModel); tilePatternsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); tilePatternsList.setLayoutOrientation(JList.HORIZONTAL_WRAP); tilePatternsList.setVisibleRowCount(-1); // make the rows as wide as possible tilePatternsList .getSelectionModel() .addListSelectionListener(new TilePatternListSelectionListener()); tilePatternsList.setCellRenderer(new TilePatternListRenderer()); tilePatternsList.addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent keyEvent) { if (keyEvent.getKeyCode() == KeyEvent.VK_DELETE) { if (tileset != null && tileset.getSelectedTilePattern() != null) { tileset.removeTilePattern(); } } } }); JScrollPane listScroller = new JScrollPane(tilePatternsList); listScroller.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); listScroller.setAlignmentX(Component.LEFT_ALIGNMENT); // tile view tilePatternView = new TilePatternView(); tilePatternView.setMaximumSize(new Dimension(Integer.MAX_VALUE, 300)); tilePatternView.setAlignmentX(Component.LEFT_ALIGNMENT); add(tilesetPropertiesView); add(Box.createRigidArea(new Dimension(0, 5))); add(listScroller); add(Box.createRigidArea(new Dimension(0, 5))); add(tilePatternView); }
private void addSelectionListener() { myList .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { int selectedIndex = myList.getSelectedIndex(); if (selectedIndex < 0 || selectedIndex >= myModel.getSize()) { selectNone(); } else { CvsRootConfiguration newSelection = (CvsRootConfiguration) myModel.getElementAt(selectedIndex); if (newSelection == mySelection) return; if (!select(newSelection)) { myList.setSelectedValue(mySelection, true); } } } }); }
public void setFormEntry(ArrayList<String> fieldTitles, int numRecords) { // for(int x=0; x<fieldTitles.size(); x++){ formEntry.add(formEntry, fieldTitles, numRecords); // } for (int x = 0; x < numRecords; x++) { listModel.addElement((x + 1) + ""); } ListSelectionModel listSelectionModel = list.getSelectionModel(); listSelectionModel.addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (formEntry.getCurrentRecord() != list.getSelectedIndex()) formEntry.setCurrentRecord(list.getSelectedIndex()); } }); }
public SaveDialog(Frame parent) { super(parent, true); this.setLayout(new BorderLayout()); // gather unsaved tab Set<Tab> unsaved = new LinkedHashSet<>(); for (Tab tab : MainPanel.getAllTab()) { if (!tab.isSaved()) { unsaved.add(tab); } } if (unsaved.isEmpty()) { // close directly this.setTitle("Confirm close"); // upper labels JPanel labels = new JPanel(new FlowLayout(FlowLayout.LEFT, 11, 7)); labels.add(iconLabel); labels.add(new MyLabel(" Do you really want to close RefluxEdit?")); // buttons JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 7)); buttons.add( new MyButton("YES") { { SaveDialog.this.getRootPane().setDefaultButton(this); this.setFocusPainted(true); } @Override public void actionPerformed(ActionEvent ev) { close = true; SaveDialog.this.setVisible(false); } }); buttons.add( new MyButton("NO") { { this.setFocusPainted(true); } @Override public void actionPerformed(ActionEvent ev) { close = false; SaveDialog.this.setVisible(false); } }); buttons.setBorder(new EmptyBorder(0, 0, 5, 0)); // this.add(labels, BorderLayout.CENTER); this.add(buttons, BorderLayout.PAGE_END); } else { // ask save changes this.setTitle("Unsaved changes"); // upper components: icon and list JPanel upper = new JPanel(new GridBagLayout()); JPanel listPane = new JPanel(new BorderLayout()); final DefaultListModel<Tab> listModel = new DefaultListModel<>(); final JList<Tab> tabList = new JList<>(listModel); tabList.setFont(f13); tabList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); tabList.setCellRenderer( new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent( JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = (JLabel) (super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus)); if (value instanceof Tab) { String text = ((Tab) value).getTabLabel().getText(); label.setText(text.substring(1)); // remove "*" } return label; } }); for (Tab tab : unsaved) { listModel.addElement(tab); } tabList.getSelectionModel().setSelectionInterval(0, listModel.size() - 1); JScrollPane scrollPane = new JScrollPane(tabList); scrollPane.setPreferredSize(new Dimension(350, 170)); listPane.add(new MyLabel("The following tabs are unsaved:"), BorderLayout.PAGE_START); listPane.add(scrollPane, BorderLayout.CENTER); // setup upper GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.weightx = 0; c.weighty = 1; c.insets = new Insets(5, 5, 5, 5); c.anchor = GridBagConstraints.FIRST_LINE_START; upper.add(iconLabel, c); // c.gridx = 1; c.weightx = 1; c.fill = GridBagConstraints.BOTH; upper.add(listPane, c); // lower components: buttons JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 7)); buttons.add( new MyButton("Save") { { this.setFocusPainted(true); this.setToolTipText("Save selected tab(s)"); SaveDialog.this.getRootPane().setDefaultButton(this); if (isMetal) { this.setPreferredSize(METAL_BUTTON_DIZE); } } @Override public void actionPerformed(ActionEvent ev) { for (Tab tab : tabList.getSelectedValuesList()) { if (tab.getFile() != null) { try { tab.save(); MainPanel.close(tab); listModel.removeElement(tab); } catch (Exception ex) { exception(ex); break; } } else { File file = FileChooser.showPreferredFileDialog( RefluxEdit.getInstance(), FileChooser.SAVE, new String[0]); if (file != null) { try { tab.save(file, false); MainPanel.close(tab); listModel.removeElement(tab); } catch (Exception ex) { exception(ex); break; } } } } if (listModel.size() == 0) { RefluxEdit.getInstance().close(); } } }); buttons.add( new MyButton("Discard") { { this.setFocusPainted(true); this.setToolTipText("Discard selected tab(s)"); if (isMetal) { this.setPreferredSize(METAL_BUTTON_DIZE); } } @Override public void actionPerformed(ActionEvent ev) { for (Tab tab : tabList.getSelectedValuesList()) { MainPanel.close(tab); listModel.removeElement(tab); } if (listModel.size() == 0) { RefluxEdit.getInstance().close(); } } }); buttons.add( new MyButton("Close") { { this.setFocusPainted(true); this.setToolTipText("Close RefluxEdit"); if (isMetal) { this.setPreferredSize(METAL_BUTTON_DIZE); } } @Override public void actionPerformed(ActionEvent ev) { SaveDialog.this.close = true; SaveDialog.this.setVisible(false); } }); buttons.add( new MyButton("Cancel") { { this.setFocusPainted(true); if (isMetal) { this.setPreferredSize(METAL_BUTTON_DIZE); } } @Override public void actionPerformed(ActionEvent ev) { SaveDialog.this.close = false; SaveDialog.this.setVisible(false); } }); this.add(upper, BorderLayout.CENTER); this.add(buttons, BorderLayout.PAGE_END); } }
private void showCompletionPopup( final CompletionResult result, int position, boolean isExplicit) { if (myList == null) { myList = new JBList(); myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myList.setCellRenderer( new GroupedItemsListRenderer( new ListItemDescriptor() { public String getTextFor(final Object value) { final LookupFile file = (LookupFile) value; if (file.getMacro() != null) { return file.getMacro(); } else { return (myCurrentCompletion != null && myCurrentCompletion.myKidsAfterSeparator.contains(file) ? myFinder.getSeparator() : "") + file.getName(); } } public String getTooltipFor(final Object value) { return null; } public Icon getIconFor(final Object value) { final LookupFile file = (LookupFile) value; return file.getIcon(); } @Nullable private Separator getSeparatorAboveOf(Object value) { if (myCurrentCompletion == null) return null; final LookupFile file = (LookupFile) value; final int fileIndex = myCurrentCompletion.myToComplete.indexOf(file); if (fileIndex > 0 && !myCurrentCompletion.myMacros.contains(file)) { final LookupFile prev = myCurrentCompletion.myToComplete.get(fileIndex - 1); if (myCurrentCompletion.myMacros.contains(prev)) { return new Separator(""); } } if (myCurrentCompletion.myKidsAfterSeparator.indexOf(file) == 0 && myCurrentCompletion.mySiblings.size() > 0) { final LookupFile parent = file.getParent(); return parent == null ? new Separator("") : new Separator(parent.getName()); } if (myCurrentCompletion.myMacros.size() > 0 && fileIndex == 0) { return new Separator( IdeBundle.message("file.chooser.completion.path.variables.text")); } return null; } public boolean hasSeparatorAboveOf(final Object value) { return getSeparatorAboveOf(value) != null; } public String getCaptionAboveOf(final Object value) { final FileTextFieldImpl.Separator separator = getSeparatorAboveOf(value); return separator != null ? separator.getText() : null; } })); } if (myCurrentPopup != null) { closePopup(); } myCurrentCompletion = result; myCurrentCompletionsPos = position; if (myCurrentCompletion.myToComplete.size() == 0) { showNoSuggestions(isExplicit); return; } myList.setModel( new AbstractListModel() { public int getSize() { return myCurrentCompletion.myToComplete.size(); } public Object getElementAt(final int index) { return myCurrentCompletion.myToComplete.get(index); } }); myList.getSelectionModel().clearSelection(); final PopupChooserBuilder builder = JBPopupFactory.getInstance().createListPopupBuilder(myList); builder.addListener( new JBPopupListener() { public void beforeShown(LightweightWindowEvent event) { myPathTextField.registerKeyboardAction( myCancelAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); for (Action each : myDisabledTextActions) { each.setEnabled(false); } } public void onClosed(LightweightWindowEvent event) { myPathTextField.unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)); for (Action each : myDisabledTextActions) { each.setEnabled(true); } } }); myCurrentPopup = builder .setRequestFocus(false) .setAdText(getAdText(myCurrentCompletion)) .setAutoSelectIfEmpty(false) .setResizable(false) .setCancelCallback( new Computable<Boolean>() { public Boolean compute() { final int caret = myPathTextField.getCaretPosition(); myPathTextField.setSelectionStart(caret); myPathTextField.setSelectionEnd(caret); myPathTextField.setFocusTraversalKeysEnabled(true); SwingUtilities.invokeLater( new Runnable() { public void run() { getField().requestFocus(); } }); return Boolean.TRUE; } }) .setItemChoosenCallback( new Runnable() { public void run() { processChosenFromCompletion(false); } }) .setCancelKeyEnabled(false) .setAlpha(0.1f) .setFocusOwners(new Component[] {myPathTextField}) .createPopup(); if (result.myPreselected != null) { myList.setSelectedValue(result.myPreselected, false); } myPathTextField.setFocusTraversalKeysEnabled(false); myCurrentPopup.showInScreenCoordinates(getField(), getLocationForCaret(myPathTextField)); }
public LabFrame() throws HeadlessException { super(title); JPanel pnl, pnl1; data = new LabData(); alRootEntities.addAll(data.findRootEntities()); JMenuBar mb = new JMenuBar(); for (MenuElement e : menus) { mb.add(e.getItem()); } setJMenuBar(mb); splMain = new JSplitPane(); getContentPane().add(splMain); desktop = new JDesktopPane(); desktop.setPreferredSize(new Dimension(400, 200)); splMain.setRightComponent(desktop); lmEntities = new EntityListModel(); lstEntities = new JList(lmEntities); lstEntities.getSelectionModel().addListSelectionListener(lmEntities); lstEntities.addMouseListener(dblClickListener); JScrollPane scpList = new JScrollPane(lstEntities); pnl = new JPanel(new BorderLayout(4, 4)); pnl.add(scpList, BorderLayout.CENTER); pnl1 = new JPanel(null); pnl1.setLayout(new BoxLayout(pnl1, BoxLayout.X_AXIS)); pnl1.add(Box.createHorizontalGlue()); pnl1.add(new JButton(actNewEntity)); pnl1.add(Box.createHorizontalGlue()); pnl1.add(new JButton(actDelEntity)); pnl1.add(Box.createHorizontalGlue()); pnl.add(pnl1, BorderLayout.SOUTH); splMain.setLeftComponent(pnl); il = new InternalFrameAdapter() { @Override public void internalFrameClosed(InternalFrameEvent e) { Object sel = ((EntityFrame) e.getInternalFrame()).content; mapEntityFrames.remove(sel); } @Override public void internalFrameActivated(InternalFrameEvent e) { setTitle(title + " - " + e.getInternalFrame().getTitle()); Object sel = ((EntityFrame) e.getInternalFrame()).content; lstEntities.setSelectedValue(sel, true); } }; pack(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); updateState(); }
public ListSelectionDemo() { super(new BorderLayout()); String[] listData = {"one", "two", "three", "four", "five", "six", "seven"}; String[] columnNames = {"French", "Spanish", "Italian"}; list = new JList(listData); listSelectionModel = list.getSelectionModel(); listSelectionModel.addListSelectionListener(new SharedListSelectionHandler()); JScrollPane listPane = new JScrollPane(list); JPanel controlPane = new JPanel(); String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" }; final JComboBox comboBox = new JComboBox(modes); comboBox.setSelectedIndex(2); comboBox.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String newMode = (String) comboBox.getSelectedItem(); if (newMode.equals("SINGLE_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); } else { listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } output.append("----------" + "Mode: " + newMode + "----------" + newline); } }); controlPane.add(new JLabel("Selection mode:")); controlPane.add(comboBox); // Build output area. output = new JTextArea(1, 10); output.setEditable(false); JScrollPane outputPane = new JScrollPane( output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); // Do the layout. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); add(splitPane, BorderLayout.CENTER); JPanel topHalf = new JPanel(); topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS)); JPanel listContainer = new JPanel(new GridLayout(1, 1)); listContainer.setBorder(BorderFactory.createTitledBorder("List")); listContainer.add(listPane); topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5)); topHalf.add(listContainer); // topHalf.add(tableContainer); topHalf.setMinimumSize(new Dimension(100, 50)); topHalf.setPreferredSize(new Dimension(100, 110)); splitPane.add(topHalf); JPanel bottomHalf = new JPanel(new BorderLayout()); bottomHalf.add(controlPane, BorderLayout.PAGE_START); bottomHalf.add(outputPane, BorderLayout.CENTER); // XXX: next line needed if bottomHalf is a scroll pane: // bottomHalf.setMinimumSize(new Dimension(400, 50)); bottomHalf.setPreferredSize(new Dimension(450, 135)); splitPane.add(bottomHalf); }
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); }