Author: kono
Date: 2011-03-29 15:06:17 -0700 (Tue, 29 Mar 2011)
New Revision: 24617
Modified:
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/cellrenderer/FontCellRenderer.java
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/valueeditor/FontChooser.java
Log:
Font chooser is fixed to display correct previews.
Modified:
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/cellrenderer/FontCellRenderer.java
===================================================================
---
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/cellrenderer/FontCellRenderer.java
2011-03-29 22:01:45 UTC (rev 24616)
+++
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/cellrenderer/FontCellRenderer.java
2011-03-29 22:06:17 UTC (rev 24617)
@@ -36,58 +36,45 @@
package org.cytoscape.view.vizmap.gui.internal.cellrenderer;
+import java.awt.Color;
import java.awt.Component;
+import java.awt.Dimension;
import java.awt.Font;
-import javax.swing.JTable;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.ListCellRenderer;
-import com.l2fprod.common.swing.renderer.DefaultCellRenderer;
-
-/**
- * DOCUMENT ME!
- *
- * @author kono
- */
-public class FontCellRenderer extends DefaultCellRenderer {
+public class FontCellRenderer extends JLabel implements ListCellRenderer {
+
private final static long serialVersionUID = 120233986931967L;
+
+ private static final Dimension SIZE = new Dimension(310, 40);
+ private static final int DISPLAY_FONT_SIZE = 18;
- /**
- * DOCUMENT ME!
- *
- * @param table
- * DOCUMENT ME!
- * @param value
- * DOCUMENT ME!
- * @param isSelected
- * DOCUMENT ME!
- * @param hasFocus
- * DOCUMENT ME!
- * @param row
- * DOCUMENT ME!
- * @param column
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public Component getTableCellRendererComponent(JTable table, Object
value, boolean isSelected,
- boolean hasFocus, int
row, int column) {
+ @Override
+ public Component getListCellRendererComponent(JList list, Object value,
+ int index, boolean isSelected, boolean cellHasFocus) {
+
+ this.setPreferredSize(SIZE);
+ this.setMinimumSize(SIZE);
+
if (isSelected) {
- setBackground(table.getSelectionBackground());
- setForeground(table.getSelectionForeground());
+ setBackground(list.getSelectionBackground());
+ setForeground(Color.DARK_GRAY);
} else {
- setBackground(table.getBackground());
- setForeground(table.getForeground());
+ setBackground(list.getBackground());
+ setForeground(Color.DARK_GRAY);
}
if ((value != null) && value instanceof Font) {
final Font font = (Font) value;
- final Font modFont = new Font(font.getFontName(),
font.getStyle(), 12);
-
+ final Font modFont = new Font(font.getFontName(),
font.getStyle(), DISPLAY_FONT_SIZE);
this.setFont(modFont);
- this.setText(modFont.getFontName());
+ this.setText(modFont.getName());
} else
- this.setValue(null);
+ this.setText("? (Unknown data type)");
return this;
}
Modified:
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/valueeditor/FontChooser.java
===================================================================
---
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/valueeditor/FontChooser.java
2011-03-29 22:01:45 UTC (rev 24616)
+++
core3/vizmap-gui-impl/trunk/src/main/java/org/cytoscape/view/vizmap/gui/internal/editor/valueeditor/FontChooser.java
2011-03-29 22:06:17 UTC (rev 24617)
@@ -33,7 +33,7 @@
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-*/
+ */
//--------------------------------------------------------------------------
// $Revision: 12968 $
@@ -42,6 +42,8 @@
//--------------------------------------------------------------------------
package org.cytoscape.view.vizmap.gui.internal.editor.valueeditor;
+import java.awt.BorderLayout;
+import java.awt.Dimension;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.event.ItemEvent;
@@ -53,58 +55,58 @@
import org.cytoscape.view.vizmap.gui.internal.cellrenderer.FontCellRenderer;
-
-//--------------------------------------------------------------------------
/**
* Defines a generalized font chooser class. FontChooser contains three
* components to display font face selection.
*/
public class FontChooser extends JPanel {
+
private final static long serialVersionUID = 1202339876728781L;
+
private Font selectedFont;
+
protected DefaultComboBoxModel fontFaceModel;
- protected JComboBox face;
- protected static final float DEF_SIZE = 12F;
+ protected JComboBox fontSelector;
+
+ protected static final int DEF_SIZE = 12;
+ private static final Dimension SIZE = new Dimension(350, 40);
protected static Font[] scaledFonts;
- protected static final Font DEF_FONT = new Font("SansSerif",
Font.PLAIN, 1);
+ protected static final Font DEF_FONT = new Font("SansSerif",
Font.PLAIN, DEF_SIZE);
static {
- scaledFonts =
scaleFonts(GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(),
- DEF_SIZE);
+ scaledFonts = scaleFonts(GraphicsEnvironment
+ .getLocalGraphicsEnvironment().getAllFonts(),
DEF_SIZE);
}
/**
* Create a FontChooser to choose between all fonts available on the
system.
*/
public FontChooser() {
- this(null);
+ this(scaledFonts, DEF_FONT);
}
/**
- * Creates a new FontChooser object.
- *
- * @param def DOCUMENT ME!
- */
- public FontChooser(Font def) {
- this(scaledFonts, def);
- }
-
- /**
* Create a FontChooser to choose between the given array of fonts.
*/
public FontChooser(Font[] srcFonts, Font def) {
+ this.setLayout(new BorderLayout());
Font[] displayFonts = scaledFonts;
if (srcFonts != scaledFonts)
displayFonts = scaleFonts(srcFonts, DEF_SIZE);
this.fontFaceModel = new DefaultComboBoxModel(displayFonts);
+
+ this.fontSelector = new JComboBox(fontFaceModel);
+ this.fontSelector.setRenderer(new FontCellRenderer());
+ this.fontSelector.setPreferredSize(SIZE);
+ this.fontSelector.setMinimumSize(SIZE);
+ this.setPreferredSize(SIZE);
+ this.setMinimumSize(SIZE);
+
- this.face = new JComboBox(fontFaceModel);
- face.setRenderer(new FontCellRenderer());
-
// set the prototype display for the combo box
- face.addItemListener(new FontFaceSelectionListener());
+ fontSelector.addItemListener(new FontFaceSelectionListener());
// set the currently selected face, default if null
if (def == null)
@@ -112,31 +114,27 @@
else
this.selectedFont = def.deriveFont(1F);
- face.setEditable(true); // so that we may select the default
font
- face.setSelectedItem(this.selectedFont);
- face.setEditable(false); // so that users aren't allowed to
edit the list
+ fontSelector.setEditable(true); // so that we may select the
default font
+ fontSelector.setSelectedItem(this.selectedFont);
+ fontSelector.setEditable(false); // so that users aren't
allowed to edit the list
- add(face);
+ add(fontSelector, BorderLayout.CENTER);
}
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
+
public JComboBox getFaceComboBox() {
- return face;
+ return fontSelector;
}
/**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
*/
public Font getSelectedFont() {
return selectedFont;
}
-
+
public void setSelectedFont(Font font) {
this.selectedFont = font;
}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.