Author: bback
Date: 2006-03-11 17:14:29 +0000 (Sat, 11 Mar 2006)
New Revision: 8228
Added:
trunk/apps/frost-0.7/source/frost/gui/BoardsChooser.java
Modified:
trunk/apps/frost-0.7/source/frost/gui/MessageFrame.java
Log:
nicer boards chooser
Added: trunk/apps/frost-0.7/source/frost/gui/BoardsChooser.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/gui/BoardsChooser.java 2006-03-11
16:42:27 UTC (rev 8227)
+++ trunk/apps/frost-0.7/source/frost/gui/BoardsChooser.java 2006-03-11
17:14:29 UTC (rev 8228)
@@ -0,0 +1,154 @@
+/*
+ BoardsChooser.java / Frost
+ Copyright (C) 2006 Jan-Thomas Czornack <jantho at users.sourceforge.net>
+ This file is contributed by Stefan Majewski <feuerblume at
users.sourceforge.net>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+package frost.gui;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+import java.util.List;
+
+import javax.swing.*;
+import javax.swing.border.*;
+
+import frost.gui.objects.*;
+import frost.util.gui.translation.*;
+
+public class BoardsChooser extends JDialog {
+
+ private Language language = Language.getInstance();
+
+ protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
+
+ protected class BoardsCellRenderer implements ListCellRenderer {
+
+ public Component getListCellRendererComponent(
+ JList list, Object value, int index,
+ boolean isSelected, boolean cellHasFocus)
+ {
+ BoardListEntry e = (BoardListEntry)value;
+
+ JCheckBox checkbox = e.checkBox;
+
+ checkbox.setBackground(isSelected ? Lboards.getSelectionBackground()
: Lboards.getBackground());
+ checkbox.setForeground(isSelected ? Lboards.getSelectionForeground()
: Lboards.getForeground());
+ checkbox.setEnabled(isEnabled());
+ checkbox.setFont(getFont());
+ checkbox.setFocusPainted(false);
+ checkbox.setBorderPainted(true);
+ checkbox.setBorder(isSelected ?
UIManager.getBorder("List.focusCellHighlightBorder") : noFocusBorder);
+
+ return checkbox;
+ }
+ }
+
+ JButton Bcancel;
+ List boardList;
+ JButton Bok;
+ JList Lboards;
+ boolean okPressed = false;
+
+ public BoardsChooser(List boards) {
+ super();
+ setTitle(language.getString("Choose boards to attach"));
+ setModal(true);
+
+ // fill given board into our list as BoardListEntries
+ boardList = new ArrayList();
+ for(Iterator i=boards.iterator(); i.hasNext(); ) {
+ Board b = (Board)i.next();
+ BoardListEntry e = new BoardListEntry();
+ e.board = b;
+ e.checkBox = new JCheckBox(b.getName());
+ boardList.add(e);
+ }
+
+ initGui();
+ }
+
+ private void initGui() {
+ Bok = new JButton("OK");
+ Bok.addActionListener( new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ okPressed = true;
+ setVisible(false);
+ } });
+ Bcancel = new JButton("Cancel");
+ Bcancel.addActionListener( new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ okPressed = false;
+ setVisible(false);
+ } });
+ JPanel buttonsPanel = new JPanel( new FlowLayout(FlowLayout.RIGHT, 8,
8) );
+ buttonsPanel.add( Bok );
+ buttonsPanel.add( Bcancel );
+
+ ListModel boardsModel = new AbstractListModel() {
+ public int getSize() {
+ return boardList.size();
+ }
+ public Object getElementAt(int index) {
+ return boardList.get(index);
+ }
+ };
+ Lboards = new JList(boardsModel);
+ Lboards.setCellRenderer(new BoardsCellRenderer());
+ Lboards.addMouseListener(new MouseAdapter() {
+ public void mousePressed(MouseEvent e) {
+ int index = Lboards.locationToIndex(e.getPoint());
+ if (index != -1) {
+ BoardListEntry ent =
(BoardListEntry)Lboards.getModel().getElementAt(index);
+ JCheckBox checkbox = ent.checkBox;
+ checkbox.setSelected(!checkbox.isSelected());
+ repaint();
+ }
+ }
+ } );
+ Lboards.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ JScrollPane listScroller = new JScrollPane( Lboards );
+ listScroller.setBorder( new CompoundBorder( new EmptyBorder(5,5,5,5),
+ new CompoundBorder( new
EtchedBorder(),
+ new
EmptyBorder(5,5,5,5) )
+ ) );
+ getContentPane().add(listScroller, BorderLayout.CENTER);
+ getContentPane().add(buttonsPanel, BorderLayout.SOUTH);
+ setSize(300, 400);
+ }
+
+ public List runDialog()
+ {
+ setVisible(true);
+ if( okPressed == false )
+ return null;
+
+ ArrayList chosed = new ArrayList();
+ for(Iterator i=boardList.iterator(); i.hasNext(); ) {
+ BoardListEntry e = (BoardListEntry)i.next();
+ if( e.checkBox.isSelected() ) {
+ chosed.add(e.board);
+ }
+ }
+ return chosed;
+ }
+
+ private class BoardListEntry {
+ Board board = null;
+ JCheckBox checkBox = null;
+ }
+}
Modified: trunk/apps/frost-0.7/source/frost/gui/MessageFrame.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/gui/MessageFrame.java 2006-03-11
16:42:27 UTC (rev 8227)
+++ trunk/apps/frost-0.7/source/frost/gui/MessageFrame.java 2006-03-11
17:14:29 UTC (rev 8228)
@@ -27,13 +27,11 @@
import java.util.logging.*;
import javax.swing.*;
-import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.text.*;
import frost.*;
import frost.boards.*;
-import frost.fcp.*;
import frost.gui.model.*;
import frost.gui.objects.*;
import frost.identities.*;
@@ -42,87 +40,7 @@
import frost.util.gui.*;
import frost.util.gui.translation.*;
-public class MessageFrame extends JFrame
-{
- private class AttachBoardsChooser extends JDialog {
- private class AttachBoardsCellRenderer extends
DefaultListCellRenderer {
-
- public Component getListCellRendererComponent(JList
list, Object value, int index,
- boolean isSelected, boolean
cellHasFocus) {
- super.getListCellRendererComponent(list, value,
index, isSelected, cellHasFocus);
- if (value != null) {
- Board tboard = (Board) value;
- setText(tboard.getName());
- }
- return this;
- }
- }
-
- JButton Bcancel;
- List boards;
- JButton Bok;
- JList Lboards;
- boolean okPressed = false;
-
- public AttachBoardsChooser(List boards)
- {
- super();
- setTitle(language.getString("Choose boards to attach"));
- setModal(true);
- this.boards = boards;
- initGui();
- }
-
- private void initGui()
- {
- Bok = new JButton("OK");
- Bok.addActionListener( new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- okPressed = true;
- setVisible(false);
- } });
- Bcancel = new JButton("Cancel");
- Bcancel.addActionListener( new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- okPressed = false;
- setVisible(false);
- } });
- JPanel buttonsPanel = new JPanel( new FlowLayout(FlowLayout.RIGHT,
8, 8) );
- buttonsPanel.add( Bok );
- buttonsPanel.add( Bcancel );
-
- ListModel boardsModel = new AbstractListModel() {
- public int getSize() {
- return boards.size();
- }
- public Object getElementAt(int index) {
- return boards.get(index);
- }
- };
- Lboards = new JList(boardsModel);
- Lboards.setCellRenderer(new AttachBoardsCellRenderer());
-
Lboards.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
- JScrollPane listScroller = new JScrollPane( Lboards );
- listScroller.setBorder( new CompoundBorder( new
EmptyBorder(5,5,5,5),
- new CompoundBorder(
new EtchedBorder(),
-
new EmptyBorder(5,5,5,5) )
- ) );
- getContentPane().add(listScroller, BorderLayout.CENTER);
- getContentPane().add(buttonsPanel, BorderLayout.SOUTH);
- setSize(300, 400);
- }
-
- public Vector runDialog()
- {
- setVisible(true);
- if( okPressed == false )
- return null;
-
- Object[] sels = Lboards.getSelectedValues();
- Vector chosed = new Vector( Arrays.asList( sels ) );
- return chosed;
- }
- }
+public class MessageFrame extends JFrame {
class BuddyComparator implements Comparator {
/**
@@ -695,11 +613,6 @@
// modify the header of
// the message
messageTextArea.setDocument(messageDocument);
-
- // see initialze()
-// setSize((int) (parentWindow.getWidth() * 0.75),
-// (int) (parentWindow.getHeight() * 0.75));
-// setLocationRelativeTo(parentWindow);
}
private Window parentWindow;
@@ -709,15 +622,15 @@
*/
private void attachBoards_actionPerformed(ActionEvent e) {
Vector allBoards =
MainFrame.getInstance().getTofTreeModel().getAllBoards();
- if (allBoards.size() == 0)
+ if (allBoards.size() == 0) {
return;
+ }
Collections.sort(allBoards);
- AttachBoardsChooser chooser = new
AttachBoardsChooser(allBoards);
+ BoardsChooser chooser = new BoardsChooser(allBoards);
chooser.setLocationRelativeTo(this);
- Vector chosenBoards = chooser.runDialog();
- if (chosenBoards == null || chosenBoards.size() == 0) //
nothing chosed or cancelled
- {
+ List chosenBoards = chooser.runDialog();
+ if (chosenBoards == null || chosenBoards.size() == 0) { //
nothing chosed or cancelled
return;
}