Skip to content

Commit

Permalink
Added support for high DPI displays
Browse files Browse the repository at this point in the history
  • Loading branch information
alutman committed Apr 2, 2016
1 parent 23fb4fa commit 39eb052
Show file tree
Hide file tree
Showing 9 changed files with 740 additions and 10 deletions.
Binary file removed resources/jfontchooser-1.0.5a.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions src/main/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import model.enums.CryptStatus;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.*;
import view.DPIController;

import java.io.*;
import java.util.Scanner;
Expand Down Expand Up @@ -193,6 +194,7 @@ private static void verbosePrint(String s) {
}

private static void startGUI() {
DPIController.scaleFontsToDPI();
Cryptographer crypt = new CBCCryptographer();
AppFrame app = new AppFrame();
GUIHandler mc = new GUIHandler(app, crypt);
Expand Down
11 changes: 7 additions & 4 deletions src/view/AppFrame.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package view;

import main.Program;
import view.dialogs.DialogBuilder;

import javax.swing.*;
import javax.swing.event.DocumentListener;
Expand All @@ -10,6 +11,8 @@
import java.awt.event.*;
import java.util.TooManyListenersException;

import static view.DPIController.scaleToDPI;

/**
* Created by alutman on 14/03/14.
*
Expand All @@ -27,10 +30,10 @@ public class AppFrame extends JFrame {

public ImageIcon ICON = null;


public AppFrame() {
this.setSize(500, 500);
this.setMinimumSize(new Dimension(250,200));

this.setSize(scaleToDPI(500), scaleToDPI(500));
this.setMinimumSize(new Dimension(scaleToDPI(250), scaleToDPI(200)));
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
setTextWrap(false);
Expand All @@ -44,7 +47,7 @@ public AppFrame() {
this.setVisible(true);
}

String filename = "untitled";
private String filename = "untitled";

public void setTitleFilename(String filename) {
if(filename == null || filename.length() <= 0) {
Expand Down
53 changes: 53 additions & 0 deletions src/view/DPIController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package view;

import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import java.awt.*;

/**
* Created by Alex on 02/04/2016.
*/
public class DPIController {
private static int DEFAULT_DPI = 96;

private static int DPI = java.awt.Toolkit.getDefaultToolkit().getScreenResolution();

public static int getDefaultDPI() {
return DEFAULT_DPI;
}

public static void setDefaultDPI(int i) {
DEFAULT_DPI = i;
}

public static int getDpi() {
return DPI;
}

public static int scaleToDPI(int input) {

int factor = DPI / DEFAULT_DPI;

return factor * input;
}

public static Dimension scaleToDPI(Dimension input) {

int factor = DPI / DEFAULT_DPI;

return new Dimension(factor * input.width, factor * input.height);
}

public static void scaleFontsToDPI() {

java.util.Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get (key);
if (value != null && value instanceof javax.swing.plaf.FontUIResource) {
Font f = ((FontUIResource) value);
UIManager.put(key, f.deriveFont(scaleToDPI(f.getSize())*1f));
}
}
}
}
2 changes: 1 addition & 1 deletion src/view/TextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class TextArea extends JTextArea {
private final UndoManager undoMan = new UndoManager();
private final Document thisDoc;

public static final Font DEFAULT_FONT = new Font(Font.MONOSPACED, Font.PLAIN, 12);
public static final Font DEFAULT_FONT = new Font(Font.MONOSPACED, Font.PLAIN, DPIController.scaleToDPI(12));
public static final int[] DEFAULT_FONT_SIZES =
{
8, 9, 10, 11, 12, 14, 16, 18, 20,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package view;
package view.dialogs;

import javax.swing.filechooser.FileFilter;
import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package view;
package view.dialogs;

import view.AppFrame;
import view.RequestFocusListener;
import view.data.FindParams;
import controller.exception.InputCancelledException;
import say.swing.JFontChooser;

import javax.swing.*;
import java.awt.*;
import java.io.File;


/**
* Created by alutman on 17/03/14.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package view;
package view.dialogs;


import javax.swing.*;
import java.io.File;
Expand Down
Loading

0 comments on commit 39eb052

Please sign in to comment.