From 52db32d864c287c890b46c2f5eb0d2bcc75258bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCrten?= Date: Sat, 3 Sep 2016 19:21:00 +0200 Subject: [PATCH] Moved some general utilites to swing-utils * BufferedImageIcon * KeyValueComboBox * SwingUtil --- project/build.gradle | 4 +- .../distanceterrain/DistanceTerrain.java | 4 +- .../distanceterrain/segment/SegmentPane.java | 4 +- .../frechet/freespace/FreeSpaceDiagram.java | 4 +- .../freespace/segment/SegmentPane.java | 6 +- .../algorithms/jts/buffer/Settings.java | 2 +- .../polygon/shortestpath/SleevePanel.java | 4 +- .../livecg/core/export/GraphicsExporter.java | 5 +- .../livecg/core/scrolling/ScenePanel.java | 4 +- .../ui/geometryeditor/GeometryEditPane.java | 4 +- .../action/FilePropertiesAction.java | 4 +- .../ui/geometryeditor/action/LoadAction.java | 4 +- .../ui/geometryeditor/action/OpenAction.java | 4 +- .../ui/geometryeditor/action/SaveAction.java | 4 +- .../ui/segmenteditor/SegmentEditPane.java | 10 +- .../livecg/util/BufferedImageIcon.java | 65 --------- .../de/topobyte/livecg/util/ImageLoader.java | 3 + .../de/topobyte/livecg/util/SwingUtil.java | 58 -------- .../livecg/util/swing/KeyValueComboBox.java | 124 ------------------ 19 files changed, 36 insertions(+), 281 deletions(-) delete mode 100644 project/src/main/java/de/topobyte/livecg/util/BufferedImageIcon.java delete mode 100644 project/src/main/java/de/topobyte/livecg/util/SwingUtil.java delete mode 100644 project/src/main/java/de/topobyte/livecg/util/swing/KeyValueComboBox.java diff --git a/project/build.gradle b/project/build.gradle index 34d6a38..3104cdc 100644 --- a/project/build.gradle +++ b/project/build.gradle @@ -20,8 +20,8 @@ dependencies { compile 'de.topobyte:commons-cli-helper:0.0.1' compile 'de.topobyte:jts2awt:0.0.1' compile 'de.topobyte:adt-tree:0.0.6' - compile 'de.topobyte:awt-utils:0.0.2' - compile 'de.topobyte:swing-utils:0.0.1' + compile 'de.topobyte:awt-utils:0.0.3' + compile 'de.topobyte:swing-utils:0.0.3' compile 'de.topobyte:no-awt:0.0.1' compile 'de.topobyte:no-awt-javagraphics-clipper:0.0.1' compile 'de.topobyte:chromaticity-core:0.0.1' diff --git a/project/src/main/java/de/topobyte/livecg/algorithms/frechet/distanceterrain/DistanceTerrain.java b/project/src/main/java/de/topobyte/livecg/algorithms/frechet/distanceterrain/DistanceTerrain.java index 277b76d..5272f4d 100644 --- a/project/src/main/java/de/topobyte/livecg/algorithms/frechet/distanceterrain/DistanceTerrain.java +++ b/project/src/main/java/de/topobyte/livecg/algorithms/frechet/distanceterrain/DistanceTerrain.java @@ -22,10 +22,10 @@ import javax.swing.JPanel; +import de.topobyte.awt.util.GraphicsUtil; import de.topobyte.livecg.core.export.SizeProvider; import de.topobyte.livecg.core.geometry.geom.Chain; import de.topobyte.livecg.core.painting.backend.awt.AwtPainter; -import de.topobyte.livecg.util.SwingUtil; public class DistanceTerrain extends JPanel implements SizeProvider { @@ -53,7 +53,7 @@ public void paint(Graphics graphics) { super.paint(graphics); Graphics2D g = (Graphics2D) graphics; - SwingUtil.useAntialiasing(g, true); + GraphicsUtil.useAntialiasing(g, true); painter.setGraphics(g); terrainPainter.setWidth(getWidth()); diff --git a/project/src/main/java/de/topobyte/livecg/algorithms/frechet/distanceterrain/segment/SegmentPane.java b/project/src/main/java/de/topobyte/livecg/algorithms/frechet/distanceterrain/segment/SegmentPane.java index 6f5b586..abb7d0d 100644 --- a/project/src/main/java/de/topobyte/livecg/algorithms/frechet/distanceterrain/segment/SegmentPane.java +++ b/project/src/main/java/de/topobyte/livecg/algorithms/frechet/distanceterrain/segment/SegmentPane.java @@ -22,13 +22,13 @@ import javax.swing.JPanel; +import de.topobyte.awt.util.GraphicsUtil; import de.topobyte.livecg.algorithms.frechet.distanceterrain.ConfigChangedListener; import de.topobyte.livecg.algorithms.frechet.distanceterrain.DistanceTerrainConfig; import de.topobyte.livecg.algorithms.frechet.distanceterrain.DistanceTerrainPainterSegments; import de.topobyte.livecg.algorithms.frechet.freespace.calc.LineSegment; import de.topobyte.livecg.core.painting.backend.awt.AwtPainter; import de.topobyte.livecg.ui.segmenteditor.SegmentChangeListener; -import de.topobyte.livecg.util.SwingUtil; public class SegmentPane extends JPanel implements SegmentChangeListener, ConfigChangedListener @@ -69,7 +69,7 @@ public void paint(Graphics graphics) { super.paint(graphics); Graphics2D g = (Graphics2D) graphics; - SwingUtil.useAntialiasing(g, true); + GraphicsUtil.useAntialiasing(g, true); painter.setGraphics(g); terrainPainter.setWidth(getWidth()); diff --git a/project/src/main/java/de/topobyte/livecg/algorithms/frechet/freespace/FreeSpaceDiagram.java b/project/src/main/java/de/topobyte/livecg/algorithms/frechet/freespace/FreeSpaceDiagram.java index 7c76736..f5c978c 100644 --- a/project/src/main/java/de/topobyte/livecg/algorithms/frechet/freespace/FreeSpaceDiagram.java +++ b/project/src/main/java/de/topobyte/livecg/algorithms/frechet/freespace/FreeSpaceDiagram.java @@ -22,10 +22,10 @@ import javax.swing.JPanel; +import de.topobyte.awt.util.GraphicsUtil; import de.topobyte.livecg.core.export.SizeProvider; import de.topobyte.livecg.core.geometry.geom.Chain; import de.topobyte.livecg.core.painting.backend.awt.AwtPainter; -import de.topobyte.livecg.util.SwingUtil; public class FreeSpaceDiagram extends JPanel implements EpsilonSettable, SizeProvider @@ -58,7 +58,7 @@ public void paint(Graphics graphics) { super.paint(graphics); Graphics2D g = (Graphics2D) graphics; - SwingUtil.useAntialiasing(g, true); + GraphicsUtil.useAntialiasing(g, true); painter.setGraphics(g); diff --git a/project/src/main/java/de/topobyte/livecg/algorithms/frechet/freespace/segment/SegmentPane.java b/project/src/main/java/de/topobyte/livecg/algorithms/frechet/freespace/segment/SegmentPane.java index 0e5a35d..80e8203 100644 --- a/project/src/main/java/de/topobyte/livecg/algorithms/frechet/freespace/segment/SegmentPane.java +++ b/project/src/main/java/de/topobyte/livecg/algorithms/frechet/freespace/segment/SegmentPane.java @@ -22,8 +22,9 @@ import javax.swing.JPanel; -import de.topobyte.livecg.algorithms.frechet.freespace.FreeSpaceConfig; +import de.topobyte.awt.util.GraphicsUtil; import de.topobyte.livecg.algorithms.frechet.freespace.EpsilonSettable; +import de.topobyte.livecg.algorithms.frechet.freespace.FreeSpaceConfig; import de.topobyte.livecg.algorithms.frechet.freespace.FreeSpacePainterSegments; import de.topobyte.livecg.algorithms.frechet.freespace.calc.FreeSpaceUtil; import de.topobyte.livecg.algorithms.frechet.freespace.calc.Interval; @@ -31,7 +32,6 @@ import de.topobyte.livecg.core.painting.backend.awt.AwtPainter; import de.topobyte.livecg.ui.segmenteditor.SegmentChangeListener; import de.topobyte.livecg.util.DoubleUtil; -import de.topobyte.livecg.util.SwingUtil; public class SegmentPane extends JPanel implements SegmentChangeListener, EpsilonSettable @@ -89,7 +89,7 @@ public void segmentChanged() public void paint(Graphics graphics) { Graphics2D g = (Graphics2D) graphics; - SwingUtil.useAntialiasing(g, true); + GraphicsUtil.useAntialiasing(g, true); painter.setGraphics(g); visualizationPainter.setSize(getWidth(), getHeight()); diff --git a/project/src/main/java/de/topobyte/livecg/algorithms/jts/buffer/Settings.java b/project/src/main/java/de/topobyte/livecg/algorithms/jts/buffer/Settings.java index 7856bb6..a812ab1 100644 --- a/project/src/main/java/de/topobyte/livecg/algorithms/jts/buffer/Settings.java +++ b/project/src/main/java/de/topobyte/livecg/algorithms/jts/buffer/Settings.java @@ -32,7 +32,7 @@ import com.vividsolutions.jts.operation.buffer.BufferParameters; import de.topobyte.livecg.util.ZoomInput; -import de.topobyte.livecg.util.swing.KeyValueComboBox; +import de.topobyte.swing.util.combobox.KeyValueComboBox; public class Settings extends JToolBar implements ItemListener, ActionListener { diff --git a/project/src/main/java/de/topobyte/livecg/algorithms/polygon/shortestpath/SleevePanel.java b/project/src/main/java/de/topobyte/livecg/algorithms/polygon/shortestpath/SleevePanel.java index 6d853f0..702b4ec 100644 --- a/project/src/main/java/de/topobyte/livecg/algorithms/polygon/shortestpath/SleevePanel.java +++ b/project/src/main/java/de/topobyte/livecg/algorithms/polygon/shortestpath/SleevePanel.java @@ -28,6 +28,7 @@ import javax.swing.JPanel; +import de.topobyte.awt.util.GraphicsUtil; import de.topobyte.livecg.algorithms.polygon.monotonepieces.SplitResult; import de.topobyte.livecg.algorithms.polygon.triangulation.generic.TriangulationOperation; import de.topobyte.livecg.algorithms.polygon.util.Diagonal; @@ -39,7 +40,6 @@ import de.topobyte.livecg.core.geometry.geom.Polygon; import de.topobyte.livecg.core.geometry.geom.PolygonHelper; import de.topobyte.livecg.util.ShapeUtilAwt; -import de.topobyte.livecg.util.SwingUtil; import de.topobyte.livecg.util.circular.IntRing; import de.topobyte.livecg.util.graph.Edge; import de.topobyte.livecg.util.graph.Graph; @@ -99,7 +99,7 @@ public SleevePanel(Polygon polygon, Node nodeStart, Node nodeTarget) public void paint(Graphics graphics) { Graphics2D g = (Graphics2D) graphics; - SwingUtil.useAntialiasing(g, true); + GraphicsUtil.useAntialiasing(g, true); Area shape = AwtHelper.toShape(polygon); g.setColor(new Color(0x66ff0000, true)); diff --git a/project/src/main/java/de/topobyte/livecg/core/export/GraphicsExporter.java b/project/src/main/java/de/topobyte/livecg/core/export/GraphicsExporter.java index 5df6f12..b6eed61 100644 --- a/project/src/main/java/de/topobyte/livecg/core/export/GraphicsExporter.java +++ b/project/src/main/java/de/topobyte/livecg/core/export/GraphicsExporter.java @@ -18,13 +18,13 @@ package de.topobyte.livecg.core.export; import java.awt.Graphics2D; -import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; +import de.topobyte.awt.util.GraphicsUtil; import de.topobyte.livecg.core.painting.VisualizationPainter; import de.topobyte.livecg.core.painting.backend.awt.AwtPainter; @@ -39,8 +39,7 @@ public static void exportPNG(File file, BufferedImage.TYPE_4BYTE_ABGR); Graphics2D graphics = image.createGraphics(); - graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); + GraphicsUtil.useAntialiasing(graphics, true); AwtPainter painter = new AwtPainter(graphics); diff --git a/project/src/main/java/de/topobyte/livecg/core/scrolling/ScenePanel.java b/project/src/main/java/de/topobyte/livecg/core/scrolling/ScenePanel.java index d88c173..8f15bdc 100644 --- a/project/src/main/java/de/topobyte/livecg/core/scrolling/ScenePanel.java +++ b/project/src/main/java/de/topobyte/livecg/core/scrolling/ScenePanel.java @@ -29,10 +29,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import de.topobyte.awt.util.GraphicsUtil; import de.topobyte.livecg.core.geometry.geom.Rectangle; import de.topobyte.livecg.core.painting.VisualizationPainter; import de.topobyte.livecg.core.painting.backend.awt.AwtPainter; -import de.topobyte.livecg.util.SwingUtil; public class ScenePanel extends JPanel implements ViewportWithSignals, HasScene, HasMargin @@ -76,7 +76,7 @@ public void paint(Graphics graphics) { super.paint(graphics); Graphics2D g = (Graphics2D) graphics; - SwingUtil.useAntialiasing(g, true); + GraphicsUtil.useAntialiasing(g, true); painter.setGraphics(g); visualizationPainter.setWidth(getWidth()); diff --git a/project/src/main/java/de/topobyte/livecg/ui/geometryeditor/GeometryEditPane.java b/project/src/main/java/de/topobyte/livecg/ui/geometryeditor/GeometryEditPane.java index dd4c166..f96cf62 100644 --- a/project/src/main/java/de/topobyte/livecg/ui/geometryeditor/GeometryEditPane.java +++ b/project/src/main/java/de/topobyte/livecg/ui/geometryeditor/GeometryEditPane.java @@ -40,6 +40,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import de.topobyte.awt.util.GraphicsUtil; import de.topobyte.livecg.core.config.LiveConfig; import de.topobyte.livecg.core.geometry.geom.Chain; import de.topobyte.livecg.core.geometry.geom.Coordinate; @@ -63,7 +64,6 @@ import de.topobyte.livecg.ui.geometryeditor.mousemode.MouseMode; import de.topobyte.livecg.ui.geometryeditor.mousemode.MouseModeListener; import de.topobyte.livecg.ui.geometryeditor.mousemode.MouseModeProvider; -import de.topobyte.livecg.util.SwingUtil; public class GeometryEditPane extends JPanel implements MouseModeProvider, ContentChangedListener, ViewportWithSignals, HasScene, HasMargin @@ -459,7 +459,7 @@ public void paint(Graphics graphics) { super.paint(graphics); Graphics2D g = (Graphics2D) graphics; - SwingUtil.useAntialiasing(g, true); + GraphicsUtil.useAntialiasing(g, true); AwtPainter painter = new AwtPainter(g); paint(painter); diff --git a/project/src/main/java/de/topobyte/livecg/ui/geometryeditor/action/FilePropertiesAction.java b/project/src/main/java/de/topobyte/livecg/ui/geometryeditor/action/FilePropertiesAction.java index 11cca23..d6337b9 100644 --- a/project/src/main/java/de/topobyte/livecg/ui/geometryeditor/action/FilePropertiesAction.java +++ b/project/src/main/java/de/topobyte/livecg/ui/geometryeditor/action/FilePropertiesAction.java @@ -30,7 +30,7 @@ import de.topobyte.livecg.ui.geometryeditor.Content; import de.topobyte.livecg.ui.geometryeditor.FilePropertiesDialog; import de.topobyte.livecg.ui.geometryeditor.GeometryEditPane; -import de.topobyte.livecg.util.SwingUtil; +import de.topobyte.swing.util.Components; public class FilePropertiesAction extends BasicAction { @@ -54,7 +54,7 @@ public FilePropertiesAction(JComponent component, GeometryEditPane editPane) @Override public void actionPerformed(ActionEvent event) { - JFrame frame = SwingUtil.getContainingFrame(component); + JFrame frame = Components.getContainingFrame(component); Content content = editPane.getContent(); FilePropertiesDialog dialog = new FilePropertiesDialog(frame, content); diff --git a/project/src/main/java/de/topobyte/livecg/ui/geometryeditor/action/LoadAction.java b/project/src/main/java/de/topobyte/livecg/ui/geometryeditor/action/LoadAction.java index d00af60..0ccb370 100644 --- a/project/src/main/java/de/topobyte/livecg/ui/geometryeditor/action/LoadAction.java +++ b/project/src/main/java/de/topobyte/livecg/ui/geometryeditor/action/LoadAction.java @@ -37,7 +37,7 @@ import de.topobyte.livecg.core.geometry.geom.Chain; import de.topobyte.livecg.ui.action.BasicAction; import de.topobyte.livecg.ui.geometryeditor.GeometryEditPane; -import de.topobyte.livecg.util.SwingUtil; +import de.topobyte.swing.util.Components; public class LoadAction extends BasicAction { @@ -60,7 +60,7 @@ public LoadAction(JComponent component, GeometryEditPane editPane) @Override public void actionPerformed(ActionEvent e) { - JFrame frame = SwingUtil.getContainingFrame(component); + JFrame frame = Components.getContainingFrame(component); JFileChooser chooser = new JFileChooser(); int value = chooser.showOpenDialog(frame); if (value == JFileChooser.APPROVE_OPTION) { diff --git a/project/src/main/java/de/topobyte/livecg/ui/geometryeditor/action/OpenAction.java b/project/src/main/java/de/topobyte/livecg/ui/geometryeditor/action/OpenAction.java index 3f412cd..1783ae4 100644 --- a/project/src/main/java/de/topobyte/livecg/ui/geometryeditor/action/OpenAction.java +++ b/project/src/main/java/de/topobyte/livecg/ui/geometryeditor/action/OpenAction.java @@ -35,7 +35,7 @@ import de.topobyte.livecg.ui.action.BasicAction; import de.topobyte.livecg.ui.geometryeditor.Content; import de.topobyte.livecg.ui.geometryeditor.GeometryEditPane; -import de.topobyte.livecg.util.SwingUtil; +import de.topobyte.swing.util.Components; public class OpenAction extends BasicAction { @@ -58,7 +58,7 @@ public OpenAction(JComponent component, GeometryEditPane editPane) @Override public void actionPerformed(ActionEvent event) { - JFrame frame = SwingUtil.getContainingFrame(component); + JFrame frame = Components.getContainingFrame(component); JFileChooser chooser = new JFileChooser(); int value = chooser.showOpenDialog(frame); if (value == JFileChooser.APPROVE_OPTION) { diff --git a/project/src/main/java/de/topobyte/livecg/ui/geometryeditor/action/SaveAction.java b/project/src/main/java/de/topobyte/livecg/ui/geometryeditor/action/SaveAction.java index c0d0942..dc2c430 100644 --- a/project/src/main/java/de/topobyte/livecg/ui/geometryeditor/action/SaveAction.java +++ b/project/src/main/java/de/topobyte/livecg/ui/geometryeditor/action/SaveAction.java @@ -33,7 +33,7 @@ import de.topobyte.livecg.ui.action.BasicAction; import de.topobyte.livecg.ui.geometryeditor.Content; import de.topobyte.livecg.ui.geometryeditor.GeometryEditPane; -import de.topobyte.livecg.util.SwingUtil; +import de.topobyte.swing.util.Components; public class SaveAction extends BasicAction { @@ -56,7 +56,7 @@ public SaveAction(JComponent component, GeometryEditPane editPane) @Override public void actionPerformed(ActionEvent event) { - JFrame frame = SwingUtil.getContainingFrame(component); + JFrame frame = Components.getContainingFrame(component); JFileChooser chooser = new JFileChooser(); int value = chooser.showSaveDialog(frame); if (value == JFileChooser.APPROVE_OPTION) { diff --git a/project/src/main/java/de/topobyte/livecg/ui/segmenteditor/SegmentEditPane.java b/project/src/main/java/de/topobyte/livecg/ui/segmenteditor/SegmentEditPane.java index 0d0aa60..3ae044e 100644 --- a/project/src/main/java/de/topobyte/livecg/ui/segmenteditor/SegmentEditPane.java +++ b/project/src/main/java/de/topobyte/livecg/ui/segmenteditor/SegmentEditPane.java @@ -26,11 +26,11 @@ import javax.swing.JPanel; +import de.topobyte.awt.util.GraphicsUtil; import de.topobyte.livecg.core.geometry.geom.Chain; import de.topobyte.livecg.core.geometry.geom.Coordinate; -import de.topobyte.livecg.core.scrolling.ViewportWithSignals; import de.topobyte.livecg.core.scrolling.ViewportListener; -import de.topobyte.livecg.util.SwingUtil; +import de.topobyte.livecg.core.scrolling.ViewportWithSignals; public class SegmentEditPane extends JPanel implements ViewportWithSignals { @@ -101,9 +101,9 @@ private void draw(Graphics2D g, Chain editable, Color colorLine, Color colorPoints, Color colorPoint0) { int n = editable.getNumberOfNodes(); - SwingUtil.useAntialiasing(g, true); + GraphicsUtil.useAntialiasing(g, true); // line segments - SwingUtil.useAntialiasing(g, true); + GraphicsUtil.useAntialiasing(g, true); g.setColor(colorLine); g.setStroke(new BasicStroke(1.0f)); Coordinate last = editable.getCoordinate(0); @@ -116,7 +116,7 @@ private void draw(Graphics2D g, Chain editable, Color colorLine, g.drawLine(x1, y1, x2, y2); last = current; } - SwingUtil.useAntialiasing(g, false); + GraphicsUtil.useAntialiasing(g, false); // points g.setStroke(new BasicStroke(1.0f)); for (int i = 0; i < n; i++) { diff --git a/project/src/main/java/de/topobyte/livecg/util/BufferedImageIcon.java b/project/src/main/java/de/topobyte/livecg/util/BufferedImageIcon.java deleted file mode 100644 index 1eaa0cf..0000000 --- a/project/src/main/java/de/topobyte/livecg/util/BufferedImageIcon.java +++ /dev/null @@ -1,65 +0,0 @@ -/* This file is part of LiveCG. - * - * Copyright (C) 2013 Sebastian Kuerten - * - * 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 3 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, see . - */ - -package de.topobyte.livecg.util; - -import java.awt.Component; -import java.awt.Graphics; -import java.awt.image.BufferedImage; - -import javax.swing.Icon; - -/** - * @author Sebastian Kuerten (sebastian.kuerten@fu-berlin.de) - * - */ -public class BufferedImageIcon implements Icon -{ - - private BufferedImage bi; - - /** - * Create a new icon from this buffered image. - * - * @param bi - * the image to wrap. - */ - public BufferedImageIcon(BufferedImage bi) - { - this.bi = bi; - } - - @Override - public void paintIcon(Component c, Graphics g, int x, int y) - { - g.drawImage(bi, x, y, null); - } - - @Override - public int getIconWidth() - { - return bi.getWidth(); - } - - @Override - public int getIconHeight() - { - return bi.getHeight(); - } - -} diff --git a/project/src/main/java/de/topobyte/livecg/util/ImageLoader.java b/project/src/main/java/de/topobyte/livecg/util/ImageLoader.java index 31bf29e..cb28666 100644 --- a/project/src/main/java/de/topobyte/livecg/util/ImageLoader.java +++ b/project/src/main/java/de/topobyte/livecg/util/ImageLoader.java @@ -27,6 +27,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import de.topobyte.swing.util.BufferedImageIcon; + /** * @author Sebastian Kuerten (sebastian.kuerten@fu-berlin.de) * @@ -70,4 +72,5 @@ public static Icon load(String filename) // unable to load image return null; } + } diff --git a/project/src/main/java/de/topobyte/livecg/util/SwingUtil.java b/project/src/main/java/de/topobyte/livecg/util/SwingUtil.java deleted file mode 100644 index 70cd41a..0000000 --- a/project/src/main/java/de/topobyte/livecg/util/SwingUtil.java +++ /dev/null @@ -1,58 +0,0 @@ -/* This file is part of LiveCG. - * - * Copyright (C) 2013 Sebastian Kuerten - * - * 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 3 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, see . - */ - -package de.topobyte.livecg.util; - -import java.awt.Component; -import java.awt.Container; -import java.awt.Graphics2D; -import java.awt.RenderingHints; - -import javax.swing.JFrame; - -public class SwingUtil -{ - - public static void useAntialiasing(Graphics2D g, boolean b) - { - if (b) { - g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - } else { - g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_OFF); - } - } - - /** - * Get the containing frame of the given component. - * - * @param component - * the component to find the frame for. - * @return the containing JFrame - */ - public static JFrame getContainingFrame(Component component) - { - Container parent = component.getParent(); - while (!(parent == null || parent instanceof JFrame)) { - parent = parent.getParent(); - } - return (JFrame) parent; - } - -} diff --git a/project/src/main/java/de/topobyte/livecg/util/swing/KeyValueComboBox.java b/project/src/main/java/de/topobyte/livecg/util/swing/KeyValueComboBox.java deleted file mode 100644 index 8e6e0e9..0000000 --- a/project/src/main/java/de/topobyte/livecg/util/swing/KeyValueComboBox.java +++ /dev/null @@ -1,124 +0,0 @@ -/* This file is part of LiveCG. - * - * Copyright (C) 2014 Sebastian Kuerten - * - * 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 3 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, see . - */ -package de.topobyte.livecg.util.swing; - -import java.awt.Component; -import java.awt.Dimension; - -import javax.swing.JComboBox; -import javax.swing.JList; -import javax.swing.plaf.basic.BasicComboBoxRenderer; - -public class KeyValueComboBox extends - JComboBox> -{ - - private static final long serialVersionUID = -1L; - - public KeyValueComboBox(K[] names, V[] values, Integer selectedValue) - { - super(buildValues(names, values)); - - setRenderer(new Renderer()); - setEditable(false); - - setSelectedIndex(-1); - for (int i = 0; i < values.length; i++) { - if (values[i] == selectedValue) { - setSelectedIndex(i); - break; - } - } - } - - public void setMinPreferredWidth(int minWidth) - { - Dimension ps = getPreferredSize(); - if (ps.width < minWidth) { - setPreferredSize(new Dimension(minWidth, ps.height)); - } - } - - private static Data[] buildValues(K[] names, V[] values) - { - Data[] data = new Data[names.length]; - for (int i = 0; i < names.length; i++) { - data[i] = new Data<>(names[i], values[i]); - } - return data; - } - - private class Renderer extends BasicComboBoxRenderer - { - private static final long serialVersionUID = 1L; - - @Override - public Component getListCellRendererComponent(JList list, Object value, - int index, boolean isSelected, boolean cellHasFocus) - { - super.getListCellRendererComponent(list, value, index, isSelected, - cellHasFocus); - - if (value != null) { - Data item = (Data) value; - setText(item.name.toString()); - } else { - setText("default"); - } - - return this; - } - } - - public V getSelectedValue() - { - int index = getSelectedIndex(); - if (index < 0) { - return null; - } - Data data = getItemAt(index); - if (data == null) { - return null; - } - return data.value; - } - - public static class Data - { - K name; - V value; - - public Data(K name, V value) - { - this.name = name; - this.value = value; - } - - public K getName() - { - return name; - } - - public V getValue() - { - return value; - } - - } - -}